Skip to content

Commit

Permalink
Ensure installation path is resolved correctly (#1)
Browse files Browse the repository at this point in the history
Node.js doesn't resolve `~` automatically.
  • Loading branch information
mglaman authored Apr 19, 2021
1 parent 8efffaa commit 4420514
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ on:
paths-ignore:
- '**.md'
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 15.x
- run: npm ci
- run: npm test

run:
name: Run
runs-on: ${{ matrix.operating-system }}
Expand Down Expand Up @@ -55,6 +67,5 @@ jobs:
with:
version: ${{ matrix.drupal-version }}
path: ~/drupal

- name: Verify build
run: test -f ~/drupal/web/index.php
4 changes: 4 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const utils = require ('../src/utils')

test('resolved path', () => {
expect(utils.resolvePath('~/drupal')).toBe(`${process.env.HOME}/drupal`);
});

test('can find major version from constraint', () => {
expect(utils.getMajorVersionFromConstraint('^9.1')).toBe(9);
expect(utils.getMajorVersionFromConstraint('^9.2@alpha')).toBe(9);
Expand Down
12 changes: 11 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2240,7 +2240,7 @@ const utils = __nccwpck_require__ (608)

async function doScript() {
const drupalVersion = core.getInput('version');
const drupalPath = core.getInput('path');
const drupalPath = utils.resolvePath(core.getInput('path') || '~/drupal');
const extraDependencies = core.getInput('dependencies')

await exec.exec('composer', [
Expand Down Expand Up @@ -2282,14 +2282,24 @@ doScript().catch(error => core.setFailed(error.message));
/***/ 608:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const path = __nccwpck_require__(622);
const semverMajor = __nccwpck_require__(688)
const smeverCoerce = __nccwpck_require__(466)

function resolvePath(filepath) {
if (filepath[0] === '~') {
return path.join(process.env.HOME, filepath.slice(1));
}
return path.resolve(filepath)
}

function getMajorVersionFromConstraint(constraint) {
return semverMajor(smeverCoerce(constraint))
}


module.exports = {
resolvePath,
getMajorVersionFromConstraint
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const utils = require ('./utils')

async function doScript() {
const drupalVersion = core.getInput('version');
const drupalPath = core.getInput('path');
const drupalPath = utils.resolvePath(core.getInput('path') || '~/drupal');
const extraDependencies = core.getInput('dependencies')

await exec.exec('composer', [
Expand Down
10 changes: 10 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
const path = require('path');
const semverMajor = require('semver/functions/major')
const smeverCoerce = require('semver/functions/coerce')

function resolvePath(filepath) {
if (filepath[0] === '~') {
return path.join(process.env.HOME, filepath.slice(1));
}
return path.resolve(filepath)
}

function getMajorVersionFromConstraint(constraint) {
return semverMajor(smeverCoerce(constraint))
}


module.exports = {
resolvePath,
getMajorVersionFromConstraint
}

0 comments on commit 4420514

Please sign in to comment.