+63
-1
lines changedFilter options
+63
-1
lines changed Original file line number Diff line number Diff line change
@@ -275,6 +275,31 @@ t.test('packs from git spec', async t => {
275
275
const exists = await fs.stat(path.join(npm.prefix, 'npm-exec-test-success'))
276
276
t.ok(exists.isFile(), 'bin ran, creating file')
277
277
} catch (err) {
278
-
t.fail(err, "shouldn't throw")
278
+
t.fail(err, 'should not throw')
279
+
}
280
+
})
281
+
282
+
t.test('can run packages with keywords', async t => {
283
+
const { npm } = await loadMockNpm(t, {
284
+
prefixDir: {
285
+
'package.json': JSON.stringify({
286
+
name: '@npmcli/npx-package-test',
287
+
bin: { select: 'index.js' },
288
+
}),
289
+
'index.js': `#!/usr/bin/env node
290
+
require('fs').writeFileSync('npm-exec-test-success', (process.argv.length).toString())`,
291
+
},
292
+
})
293
+
294
+
try {
295
+
await npm.exec('exec', ['select'])
296
+
297
+
const testFilePath = path.join(npm.prefix, 'npm-exec-test-success')
298
+
const exists = await fs.stat(testFilePath)
299
+
t.ok(exists.isFile(), 'bin ran, creating file')
300
+
const noExtraArgumentCount = await fs.readFile(testFilePath, 'utf8')
301
+
t.equal(+noExtraArgumentCount, 2, 'should have no extra arguments')
302
+
} catch (err) {
303
+
t.fail(err, 'should not throw')
279
304
}
280
305
})
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ const runScript = require('@npmcli/run-script')
3
3
const readPackageJson = require('read-package-json-fast')
4
4
const { log, output } = require('proc-log')
5
5
const noTTY = require('./no-tty.js')
6
+
const isWindowsShell = require('./is-windows.js')
6
7
7
8
const run = async ({
8
9
args,
@@ -14,6 +15,14 @@ const run = async ({
14
15
runPath,
15
16
scriptShell,
16
17
}) => {
18
+
// escape executable path
19
+
// necessary for preventing bash/cmd keywords from overriding
20
+
if (!isWindowsShell) {
21
+
if (args.length > 0) {
22
+
args[0] = '"' + args[0] + '"'
23
+
}
24
+
}
25
+
17
26
// turn list of args into command string
18
27
const script = call || args.shift() || scriptShell
19
28
Original file line number Diff line number Diff line change
@@ -115,3 +115,31 @@ t.test('ci env', async t => {
115
115
116
116
t.equal(logs[0], 'warn exec Interactive mode disabled in CI environment')
117
117
})
118
+
119
+
t.test('isWindows', async t => {
120
+
const { runScript } = await mockRunScript(t, {
121
+
'ci-info': { isCI: true },
122
+
'@npmcli/run-script': async () => {
123
+
t.ok('should call run-script')
124
+
},
125
+
'../lib/is-windows.js': true,
126
+
})
127
+
128
+
await runScript({ args: ['test'] })
129
+
// need both arguments and no arguments for code coverage
130
+
await runScript()
131
+
})
132
+
133
+
t.test('isNotWindows', async t => {
134
+
const { runScript } = await mockRunScript(t, {
135
+
'ci-info': { isCI: true },
136
+
'@npmcli/run-script': async () => {
137
+
t.ok('should call run-script')
138
+
},
139
+
'../lib/is-windows.js': false,
140
+
})
141
+
142
+
await runScript({ args: ['test'] })
143
+
// need both arguments and no arguments for code coverage
144
+
await runScript()
145
+
})
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4