Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion test/lib/commands/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,31 @@ t.test('packs from git spec', async t => {
const exists = await fs.stat(path.join(npm.prefix, 'npm-exec-test-success'))
t.ok(exists.isFile(), 'bin ran, creating file')
} catch (err) {
t.fail(err, "shouldn't throw")
t.fail(err, 'should not throw')
}
})

t.test('can run packages with keywords', async t => {
const { npm } = await loadMockNpm(t, {
prefixDir: {
'package.json': JSON.stringify({
name: '@npmcli/npx-package-test',
bin: { select: 'index.js' },
}),
'index.js': `#!/usr/bin/env node
require('fs').writeFileSync('npm-exec-test-success', (process.argv.length).toString())`,
},
})

try {
await npm.exec('exec', ['select'])

const testFilePath = path.join(npm.prefix, 'npm-exec-test-success')
const exists = await fs.stat(testFilePath)
t.ok(exists.isFile(), 'bin ran, creating file')
const noExtraArgumentCount = await fs.readFile(testFilePath, 'utf8')
t.equal(+noExtraArgumentCount, 2, 'should have no extra arguments')
} catch (err) {
t.fail(err, 'should not throw')
}
})
9 changes: 9 additions & 0 deletions workspaces/libnpmexec/lib/run-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const runScript = require('@npmcli/run-script')
const readPackageJson = require('read-package-json-fast')
const { log, output } = require('proc-log')
const noTTY = require('./no-tty.js')
const isWindowsShell = require('./is-windows.js')

const run = async ({
args,
Expand All @@ -14,6 +15,14 @@ const run = async ({
runPath,
scriptShell,
}) => {
// escape executable path
// necessary for preventing bash/cmd keywords from overriding
if (!isWindowsShell) {
if (args.length > 0) {
args[0] = '"' + args[0] + '"'
}
}

// turn list of args into command string
const script = call || args.shift() || scriptShell

Expand Down
28 changes: 28 additions & 0 deletions workspaces/libnpmexec/test/run-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,31 @@ t.test('ci env', async t => {

t.equal(logs[0], 'warn exec Interactive mode disabled in CI environment')
})

t.test('isWindows', async t => {
const { runScript } = await mockRunScript(t, {
'ci-info': { isCI: true },
'@npmcli/run-script': async () => {
t.ok('should call run-script')
},
'../lib/is-windows.js': true,
})

await runScript({ args: ['test'] })
// need both arguments and no arguments for code coverage
await runScript()
})

t.test('isNotWindows', async t => {
const { runScript } = await mockRunScript(t, {
'ci-info': { isCI: true },
'@npmcli/run-script': async () => {
t.ok('should call run-script')
},
'../lib/is-windows.js': false,
})

await runScript({ args: ['test'] })
// need both arguments and no arguments for code coverage
await runScript()
})
Loading