diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 4b27ab53c7de179ba8a4a55e5de4df63929012a5..a5a4284607bdc9c39b3f94f085d1c49168a9879a 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -14,6 +14,7 @@ For a detailed view of what's changed, refer to the {url-repo}/commits[commit hi * account for null value on env key or env entry * account for `on_failure` key name (snake_case) on run entry when using Antora 3.2.0 +* preserve command with absolute path when run.local option is true (#34) == 1.0.0-beta.1 (2024-08-08) diff --git a/docs/modules/ROOT/pages/configuration-keys.adoc b/docs/modules/ROOT/pages/configuration-keys.adoc index 2d691c10ef9cd6a574aa61ecacf0558ecc03d54b..ae3c5e6b36ff9bddf1523574c75defaffe431dfa 100644 --- a/docs/modules/ROOT/pages/configuration-keys.adoc +++ b/docs/modules/ROOT/pages/configuration-keys.adoc @@ -224,7 +224,7 @@ run: If the command begins with `$NODE` (or `${{env.NODE}}`) followed by a space, that token will be replaced with the value of the `NODE` environment variable set on the Antora process, which defaults to the path of the Node.js executable used to run Antora. Similarly, if the command begins with the path of a JavaScript file, the value of the `NODE` environment variable is inserted as the first command argument. -If the `local` key is specified with the value `true` (default: `false`), the command must be located relative to where the command is run. +If the `local` key is specified with the value `true` (default: `false`) and the command is relative, the command is resolved relative to where the command is run. This key can be set implicitly by prepending the command with `./`. This setting effectively disables looking for a global command on the current user's PATH. @@ -439,7 +439,7 @@ If the value is null, the existing environment variable is unset. |`run.local` |Prevents system from resolving global command on the user's PATH. -In this case, the command must be located at the location relative to where the command is run. +In this case, if the command is relative, it will be resolved from the where the command is run. This key can be set implicitly by prepending the command with `./`. |Not set (false) |Boolean diff --git a/packages/collector-extension/lib/util/run-command.js b/packages/collector-extension/lib/util/run-command.js index b0c57bd79e6ab71e7a177beedd9f030f8dc9ce15..74baf42603aeb8188f9239d943475611d0f74f45 100644 --- a/packages/collector-extension/lib/util/run-command.js +++ b/packages/collector-extension/lib/util/run-command.js @@ -14,12 +14,12 @@ const ENV_NAME_RX = /\$(\w+)/g async function runCommand (cmd = '', opts = {}) { let cmdv = parseCommand(String(cmd), { preserveQuotes: opts.shell }) if (!cmdv.length) throw new TypeError('Command not specified') + const cmd0 = cmdv[0] const { quiet, local, ...spawnOpts } = opts if (IS_WIN) { if (local) { - const cmd0 = cmdv[0] if (!(cmd0.endsWith('.bat') || cmd0.endsWith('.cmd'))) { - const absCmd0 = ospath.join(opts.cwd || '', cmd0) + const absCmd0 = ospath.isAbsolute(cmd0) ? ospath.normalize(cmd0) : ospath.join(opts.cwd || '', cmd0) if (await fsp.access(absCmd0 + '.bat').then(invariably.true, invariably.false)) { cmdv[0] = absCmd0 + '.bat' } else if (await fsp.access(absCmd0 + '.cmd').then(invariably.true, invariably.false)) { @@ -27,10 +27,10 @@ async function runCommand (cmd = '', opts = {}) { } } } - if (spawnOpts.shell) cmdv = cmdv.map((it) => (~it.indexOf('$') ? it.replace(ENV_NAME_RX, '%$1%') : it)) + if (opts.shell) cmdv = cmdv.map((it) => (~it.indexOf('$') ? it.replace(ENV_NAME_RX, '%$1%') : it)) Object.assign(spawnOpts, { windowsHide: true, windowsVerbatimArguments: false }) - } else if (local) { - cmdv[0] = `./${cmdv[0]}` + } else if (local && !~cmd0.indexOf('/')) { + cmdv[0] = `./${cmd0}` } return new Promise((resolve, reject) => { const stderr = [] diff --git a/packages/collector-extension/test/collector-extension-test.js b/packages/collector-extension/test/collector-extension-test.js index 9b4c48a51eb42c325de3a9f790502cbfeac648ce..8656b39b3c48872d8e9c8d27cbf40fcd17220ac8 100644 --- a/packages/collector-extension/test/collector-extension-test.js +++ b/packages/collector-extension/test/collector-extension-test.js @@ -701,6 +701,21 @@ describe('collector extension', () => { }) }) + it('should run specified local executable command with absolute path if local option is true', async () => { + const collectorConfig = { + run: { command: '$' + '{{origin.collectorWorktree}}/.gen-start-page', local: true }, + scan: { dir: 'build' }, + } + await runScenario({ + repoName: 'test-at-root', + collectorConfig, + after: (contentAggregate) => { + expect(contentAggregate[0].files).to.have.lengthOf(1) + expect(contentAggregate[0].files[0].path).to.equal('modules/ROOT/pages/index.adoc') + }, + }) + }) + if (windows) { it('should run batch script on Windows', async () => { await runScenario({