Skip to content

Commit f59a114

Browse files
authored
deps: @npmcli/[email protected] (#5064)
* deps: @npmcli/[email protected]
1 parent 69fa5ff commit f59a114

File tree

15 files changed

+91
-44
lines changed

15 files changed

+91
-44
lines changed

node_modules/@npmcli/run-script/lib/escape.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// eslint-disable-next-line max-len
44
// this code adapted from: https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
5-
const cmd = (input) => {
5+
const cmd = (input, doubleEscape) => {
66
if (!input.length) {
77
return '""'
88
}
@@ -36,8 +36,12 @@ const cmd = (input) => {
3636
}
3737

3838
// and finally, prefix shell meta chars with a ^
39-
result = result.replace(/[!^&()<>|"]/g, '^$&')
40-
// except for % which is escaped with another %
39+
result = result.replace(/[ !^&()<>|"]/g, '^$&')
40+
if (doubleEscape) {
41+
result = result.replace(/[ !^&()<>|"]/g, '^$&')
42+
}
43+
44+
// except for % which is escaped with another %, and only once
4145
result = result.replace(/%/g, '%%')
4246

4347
return result

node_modules/@npmcli/run-script/lib/make-spawn-args.js

+55-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const isWindows = require('./is-windows.js')
33
const setPATH = require('./set-path.js')
44
const { chmodSync: chmod, unlinkSync: unlink, writeFileSync: writeFile } = require('fs')
55
const { tmpdir } = require('os')
6-
const { resolve } = require('path')
6+
const { isAbsolute, resolve } = require('path')
77
const which = require('which')
88
const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
99
const escape = require('./escape.js')
@@ -20,35 +20,75 @@ const makeSpawnArgs = options => {
2020
stdioString = false,
2121
} = options
2222

23+
const spawnEnv = setPATH(path, {
24+
// we need to at least save the PATH environment var
25+
...process.env,
26+
...env,
27+
npm_package_json: resolve(path, 'package.json'),
28+
npm_lifecycle_event: event,
29+
npm_lifecycle_script: cmd,
30+
npm_config_node_gyp,
31+
})
32+
2333
let scriptFile
2434
let script = ''
35+
2536
const isCmd = /(?:^|\\)cmd(?:\.exe)?$/i.test(scriptShell)
2637
if (isCmd) {
38+
let initialCmd = ''
39+
let insideQuotes = false
40+
for (let i = 0; i < cmd.length; ++i) {
41+
const char = cmd.charAt(i)
42+
if (char === ' ' && !insideQuotes) {
43+
break
44+
}
45+
46+
initialCmd += char
47+
if (char === '"' || char === "'") {
48+
insideQuotes = !insideQuotes
49+
}
50+
}
51+
52+
let pathToInitial
53+
try {
54+
pathToInitial = which.sync(initialCmd, {
55+
path: spawnEnv.path,
56+
pathext: spawnEnv.pathext,
57+
}).toLowerCase()
58+
} catch (err) {
59+
pathToInitial = initialCmd.toLowerCase()
60+
}
61+
62+
const doubleEscape = pathToInitial.endsWith('.cmd') || pathToInitial.endsWith('.bat')
63+
2764
scriptFile = resolve(tmpdir(), `${event}-${Date.now()}.cmd`)
2865
script += '@echo off\n'
29-
script += `${cmd} ${args.map((arg) => escape.cmd(arg)).join(' ')}`
66+
script += cmd
67+
if (args.length) {
68+
script += ` ${args.map((arg) => escape.cmd(arg, doubleEscape)).join(' ')}`
69+
}
3070
} else {
31-
const shellPath = which.sync(scriptShell)
71+
const shebang = isAbsolute(scriptShell)
72+
? `#!${scriptShell}`
73+
: `#!/usr/bin/env ${scriptShell}`
3274
scriptFile = resolve(tmpdir(), `${event}-${Date.now()}.sh`)
33-
script += `#!${shellPath}\n`
34-
script += `${cmd} ${args.map((arg) => escape.sh(arg)).join(' ')}`
75+
script += `${shebang}\n`
76+
script += cmd
77+
if (args.length) {
78+
script += ` ${args.map((arg) => escape.sh(arg)).join(' ')}`
79+
}
3580
}
81+
3682
writeFile(scriptFile, script)
3783
if (!isCmd) {
3884
chmod(scriptFile, '0775')
3985
}
40-
const spawnArgs = isCmd ? ['/d', '/s', '/c', scriptFile] : ['-c', scriptFile]
86+
const spawnArgs = isCmd
87+
? ['/d', '/s', '/c', escape.cmd(scriptFile)]
88+
: ['-c', escape.sh(scriptFile)]
4189

4290
const spawnOpts = {
43-
env: setPATH(path, {
44-
// we need to at least save the PATH environment var
45-
...process.env,
46-
...env,
47-
npm_package_json: resolve(path, 'package.json'),
48-
npm_lifecycle_event: event,
49-
npm_lifecycle_script: cmd,
50-
npm_config_node_gyp,
51-
}),
91+
env: spawnEnv,
5292
stdioString,
5393
stdio,
5494
cwd: path,

node_modules/@npmcli/run-script/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@npmcli/run-script",
3-
"version": "4.1.0",
3+
"version": "4.1.3",
44
"description": "Run a lifecycle script for a package (descendant of npm-lifecycle)",
55
"author": "GitHub Inc.",
66
"license": "ISC",

package-lock.json

+15-15
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"@npmcli/fs": "^2.1.0",
9494
"@npmcli/map-workspaces": "^2.0.3",
9595
"@npmcli/package-json": "^2.0.0",
96-
"@npmcli/run-script": "^4.1.0",
96+
"@npmcli/run-script": "^4.1.3",
9797
"abbrev": "~1.1.1",
9898
"archy": "~1.0.0",
9999
"cacache": "^16.1.1",
@@ -1042,9 +1042,9 @@
10421042
}
10431043
},
10441044
"node_modules/@npmcli/run-script": {
1045-
"version": "4.1.0",
1046-
"resolved": "https://registry.npmjs.org/@npmcli/run-script/-/run-script-4.1.0.tgz",
1047-
"integrity": "sha512-bVX9/2YhQscdlC5WEDQ8HH7bw32klCiAvOSvUHJcmeUTUuaQ7z42KiwmnkXWqhVKKhbWPBp+5H0kN6WDyfknzw==",
1045+
"version": "4.1.3",
1046+
"resolved": "https://registry.npmjs.org/@npmcli/run-script/-/run-script-4.1.3.tgz",
1047+
"integrity": "sha512-xb47c2KMkn6ERw2AwPPGKIITbWoXOT1yDV5rU3SYeC1vksYOodbgN0pnOptIVnRgS2e9G8R7BVDVm8lWp92unQ==",
10481048
"inBundle": true,
10491049
"dependencies": {
10501050
"@npmcli/node-gyp": "^2.0.0",
@@ -10004,7 +10004,7 @@
1000410004
"@npmcli/name-from-folder": "^1.0.1",
1000510005
"@npmcli/node-gyp": "^2.0.0",
1000610006
"@npmcli/package-json": "^2.0.0",
10007-
"@npmcli/run-script": "^4.1.0",
10007+
"@npmcli/run-script": "^4.1.3",
1000810008
"bin-links": "^3.0.0",
1000910009
"cacache": "^16.0.6",
1001010010
"common-ancestor-path": "^1.0.1",
@@ -10095,7 +10095,7 @@
1009510095
"dependencies": {
1009610096
"@npmcli/arborist": "^5.0.0",
1009710097
"@npmcli/ci-detect": "^2.0.0",
10098-
"@npmcli/run-script": "^4.1.0",
10098+
"@npmcli/run-script": "^4.1.3",
1009910099
"chalk": "^4.1.0",
1010010100
"mkdirp-infer-owner": "^2.0.0",
1010110101
"npm-package-arg": "^9.0.1",
@@ -10170,7 +10170,7 @@
1017010170
"version": "4.1.1",
1017110171
"license": "ISC",
1017210172
"dependencies": {
10173-
"@npmcli/run-script": "^4.1.0",
10173+
"@npmcli/run-script": "^4.1.3",
1017410174
"npm-package-arg": "^9.0.1",
1017510175
"pacote": "^13.6.1"
1017610176
},
@@ -10244,7 +10244,7 @@
1024410244
"license": "ISC",
1024510245
"dependencies": {
1024610246
"@npmcli/git": "^3.0.0",
10247-
"@npmcli/run-script": "^4.1.0",
10247+
"@npmcli/run-script": "^4.1.3",
1024810248
"json-parse-even-better-errors": "^2.3.1",
1024910249
"proc-log": "^2.0.0",
1025010250
"semver": "^7.3.7"
@@ -10725,7 +10725,7 @@
1072510725
"@npmcli/name-from-folder": "^1.0.1",
1072610726
"@npmcli/node-gyp": "^2.0.0",
1072710727
"@npmcli/package-json": "^2.0.0",
10728-
"@npmcli/run-script": "^4.1.0",
10728+
"@npmcli/run-script": "^4.1.3",
1072910729
"@npmcli/template-oss": "3.5.0",
1073010730
"benchmark": "^2.1.4",
1073110731
"bin-links": "^3.0.0",
@@ -10883,9 +10883,9 @@
1088310883
}
1088410884
},
1088510885
"@npmcli/run-script": {
10886-
"version": "4.1.0",
10887-
"resolved": "https://registry.npmjs.org/@npmcli/run-script/-/run-script-4.1.0.tgz",
10888-
"integrity": "sha512-bVX9/2YhQscdlC5WEDQ8HH7bw32klCiAvOSvUHJcmeUTUuaQ7z42KiwmnkXWqhVKKhbWPBp+5H0kN6WDyfknzw==",
10886+
"version": "4.1.3",
10887+
"resolved": "https://registry.npmjs.org/@npmcli/run-script/-/run-script-4.1.3.tgz",
10888+
"integrity": "sha512-xb47c2KMkn6ERw2AwPPGKIITbWoXOT1yDV5rU3SYeC1vksYOodbgN0pnOptIVnRgS2e9G8R7BVDVm8lWp92unQ==",
1088910889
"requires": {
1089010890
"@npmcli/node-gyp": "^2.0.0",
1089110891
"@npmcli/promise-spawn": "^3.0.0",
@@ -13067,7 +13067,7 @@
1306713067
"@npmcli/arborist": "^5.0.0",
1306813068
"@npmcli/ci-detect": "^2.0.0",
1306913069
"@npmcli/eslint-config": "^3.0.1",
13070-
"@npmcli/run-script": "^4.1.0",
13070+
"@npmcli/run-script": "^4.1.3",
1307113071
"@npmcli/template-oss": "3.5.0",
1307213072
"bin-links": "^3.0.0",
1307313073
"chalk": "^4.1.0",
@@ -13118,7 +13118,7 @@
1311813118
"version": "file:workspaces/libnpmpack",
1311913119
"requires": {
1312013120
"@npmcli/eslint-config": "^3.0.1",
13121-
"@npmcli/run-script": "^4.1.0",
13121+
"@npmcli/run-script": "^4.1.3",
1312213122
"@npmcli/template-oss": "3.5.0",
1312313123
"nock": "^13.0.7",
1312413124
"npm-package-arg": "^9.0.1",
@@ -13168,7 +13168,7 @@
1316813168
"requires": {
1316913169
"@npmcli/eslint-config": "^3.0.1",
1317013170
"@npmcli/git": "^3.0.0",
13171-
"@npmcli/run-script": "^4.1.0",
13171+
"@npmcli/run-script": "^4.1.3",
1317213172
"@npmcli/template-oss": "3.5.0",
1317313173
"json-parse-even-better-errors": "^2.3.1",
1317413174
"proc-log": "^2.0.0",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"@npmcli/fs": "^2.1.0",
6363
"@npmcli/map-workspaces": "^2.0.3",
6464
"@npmcli/package-json": "^2.0.0",
65-
"@npmcli/run-script": "^4.1.0",
65+
"@npmcli/run-script": "^4.1.3",
6666
"abbrev": "~1.1.1",
6767
"archy": "~1.0.0",
6868
"cacache": "^16.1.1",

test/lib/commands/edit.js

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ t.test('npm edit', async t => {
4242
const [scriptShell] = makeSpawnArgs({
4343
event: 'install',
4444
path: npm.prefix,
45+
cmd: 'testinstall',
4546
})
4647
spawk.spawn('testeditor', [semverPath])
4748
spawk.spawn(
@@ -66,6 +67,7 @@ t.test('rebuild failure', async t => {
6667
const [scriptShell] = makeSpawnArgs({
6768
event: 'install',
6869
path: npm.prefix,
70+
cmd: 'testinstall',
6971
})
7072
spawk.spawn('testeditor', [semverPath])
7173
spawk.spawn(
@@ -109,6 +111,7 @@ t.test('npm edit editor has flags', async t => {
109111
const [scriptShell] = makeSpawnArgs({
110112
event: 'install',
111113
path: npm.prefix,
114+
cmd: 'testinstall',
112115
})
113116
spawk.spawn('testeditor', ['--flag', semverPath])
114117
spawk.spawn(

test/lib/commands/restart.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ t.test('should run restart script from package.json', async t => {
2626
loglevel: 'silent',
2727
},
2828
})
29-
const [scriptShell] = makeSpawnArgs({ path: npm.prefix })
29+
const [scriptShell] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-restart.js' })
3030
const script = spawk.spawn(scriptShell, (args) => {
3131
const lastArg = args[args.length - 1]
3232
const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')

test/lib/commands/start.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ t.test('should run start script from package.json', async t => {
2626
loglevel: 'silent',
2727
},
2828
})
29-
const [scriptShell] = makeSpawnArgs({ path: npm.prefix })
29+
const [scriptShell] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-start.js' })
3030
const script = spawk.spawn(scriptShell, (args) => {
3131
const lastArg = args[args.length - 1]
3232
const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')

test/lib/commands/stop.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ t.test('should run stop script from package.json', async t => {
2626
loglevel: 'silent',
2727
},
2828
})
29-
const [scriptShell] = makeSpawnArgs({ path: npm.prefix })
29+
const [scriptShell] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-stop.js' })
3030
const script = spawk.spawn(scriptShell, (args) => {
3131
const lastArg = args[args.length - 1]
3232
const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')

test/lib/commands/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ t.test('should run test script from package.json', async t => {
2626
loglevel: 'silent',
2727
},
2828
})
29-
const [scriptShell] = makeSpawnArgs({ path: npm.prefix })
29+
const [scriptShell] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-test.js' })
3030
const script = spawk.spawn(scriptShell, (args) => {
3131
const lastArg = args[args.length - 1]
3232
const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')

workspaces/arborist/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@npmcli/name-from-folder": "^1.0.1",
1212
"@npmcli/node-gyp": "^2.0.0",
1313
"@npmcli/package-json": "^2.0.0",
14-
"@npmcli/run-script": "^4.1.0",
14+
"@npmcli/run-script": "^4.1.3",
1515
"bin-links": "^3.0.0",
1616
"cacache": "^16.0.6",
1717
"common-ancestor-path": "^1.0.1",

workspaces/libnpmexec/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"dependencies": {
5858
"@npmcli/arborist": "^5.0.0",
5959
"@npmcli/ci-detect": "^2.0.0",
60-
"@npmcli/run-script": "^4.1.0",
60+
"@npmcli/run-script": "^4.1.3",
6161
"chalk": "^4.1.0",
6262
"mkdirp-infer-owner": "^2.0.0",
6363
"npm-package-arg": "^9.0.1",

workspaces/libnpmexec/test/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ t.test('run multiple from registry', async t => {
372372
await libexec({
373373
...baseOpts,
374374
packages: ['@ruyadorno/create-test', '@ruyadorno/create-index'],
375-
call: ['create-test && create-index'],
375+
call: 'create-test && create-index',
376376
cache,
377377
npxCache,
378378
path,

workspaces/libnpmpack/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"bugs": "https://github.com/npm/libnpmpack/issues",
3939
"homepage": "https://npmjs.com/package/libnpmpack",
4040
"dependencies": {
41-
"@npmcli/run-script": "^4.1.0",
41+
"@npmcli/run-script": "^4.1.3",
4242
"npm-package-arg": "^9.0.1",
4343
"pacote": "^13.6.1"
4444
},

workspaces/libnpmversion/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"dependencies": {
3939
"@npmcli/git": "^3.0.0",
40-
"@npmcli/run-script": "^4.1.0",
40+
"@npmcli/run-script": "^4.1.3",
4141
"json-parse-even-better-errors": "^2.3.1",
4242
"proc-log": "^2.0.0",
4343
"semver": "^7.3.7"

0 commit comments

Comments
 (0)