Skip to content

Commit d0f5995

Browse files
committed
deps: @npmcli/run-script@4.2.1
* add arguments back to the logged banner * remove the temp file entirely
1 parent 4e5dd73 commit d0f5995

File tree

6 files changed

+33
-62
lines changed

6 files changed

+33
-62
lines changed

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,11 @@ const cmd = (input, doubleEscape) => {
3636
}
3737

3838
// and finally, prefix shell meta chars with a ^
39-
result = result.replace(/[ !^&()<>|"]/g, '^$&')
39+
result = result.replace(/[ !%^&()<>|"]/g, '^$&')
4040
if (doubleEscape) {
41-
result = result.replace(/[ !^&()<>|"]/g, '^$&')
41+
result = result.replace(/[ !%^&()<>|"]/g, '^$&')
4242
}
4343

44-
// except for % which is escaped with another %, and only once
45-
result = result.replace(/%/g, '%%')
46-
4744
return result
4845
}
4946

@@ -65,13 +62,7 @@ const sh = (input) => {
6562
return result
6663
}
6764

68-
// disabling the no-control-regex rule for this line as we very specifically _do_ want to
69-
// replace those characters if they somehow exist at this point, which is highly unlikely
70-
// eslint-disable-next-line no-control-regex
71-
const filename = (input) => input.replace(/[<>:"/\\|?*\x00-\x1F]/g, '')
72-
7365
module.exports = {
7466
cmd,
7567
sh,
76-
filename,
7768
}
Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
/* eslint camelcase: "off" */
22
const isWindows = require('./is-windows.js')
33
const setPATH = require('./set-path.js')
4-
const { unlinkSync: unlink, writeFileSync: writeFile } = require('fs')
5-
const { tmpdir } = require('os')
64
const { resolve } = require('path')
75
const which = require('which')
86
const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
97
const escape = require('./escape.js')
10-
const { randomBytes } = require('crypto')
11-
12-
const translateWinPathToPosix = (path) => {
13-
return path
14-
.replace(/^([A-z]):/, '/$1')
15-
.replace(/\\/g, '/')
16-
}
178

189
const makeSpawnArgs = options => {
1910
const {
@@ -38,10 +29,7 @@ const makeSpawnArgs = options => {
3829
npm_config_node_gyp,
3930
})
4031

41-
const fileName = escape.filename(`${event}-${randomBytes(4).toString('hex')}`)
42-
let scriptFile
43-
let script = ''
44-
32+
let doubleEscape = false
4533
const isCmd = /(?:^|\\)cmd(?:\.exe)?$/i.test(scriptShell)
4634
if (isCmd) {
4735
let initialCmd = ''
@@ -68,26 +56,18 @@ const makeSpawnArgs = options => {
6856
pathToInitial = initialCmd.toLowerCase()
6957
}
7058

71-
const doubleEscape = pathToInitial.endsWith('.cmd') || pathToInitial.endsWith('.bat')
72-
73-
scriptFile = resolve(tmpdir(), `${fileName}.cmd`)
74-
script += '@echo off\n'
75-
script += cmd
76-
if (args.length) {
77-
script += ` ${args.map((arg) => escape.cmd(arg, doubleEscape)).join(' ')}`
78-
}
79-
} else {
80-
scriptFile = resolve(tmpdir(), `${fileName}.sh`)
81-
script = cmd
82-
if (args.length) {
83-
script += ` ${args.map((arg) => escape.sh(arg)).join(' ')}`
84-
}
59+
doubleEscape = pathToInitial.endsWith('.cmd') || pathToInitial.endsWith('.bat')
8560
}
8661

87-
writeFile(scriptFile, script)
62+
let script = cmd
63+
for (const arg of args) {
64+
script += isCmd
65+
? ` ${escape.cmd(arg, doubleEscape)}`
66+
: ` ${escape.sh(arg)}`
67+
}
8868
const spawnArgs = isCmd
89-
? ['/d', '/s', '/c', escape.cmd(scriptFile)]
90-
: [isWindows ? translateWinPathToPosix(scriptFile) : scriptFile]
69+
? ['/d', '/s', '/c', script]
70+
: ['-c', '--', script]
9171

9272
const spawnOpts = {
9373
env: spawnEnv,
@@ -97,16 +77,7 @@ const makeSpawnArgs = options => {
9777
...(isCmd ? { windowsVerbatimArguments: true } : {}),
9878
}
9979

100-
const cleanup = () => {
101-
// delete the script, this is just a best effort
102-
try {
103-
unlink(scriptFile)
104-
} catch (err) {
105-
// ignore errors
106-
}
107-
}
108-
109-
return [scriptShell, spawnArgs, spawnOpts, cleanup]
80+
return [scriptShell, spawnArgs, spawnOpts]
11081
}
11182

11283
module.exports = makeSpawnArgs

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@ const signalManager = require('./signal-manager.js')
66
const isServerPackage = require('./is-server-package.js')
77

88
// you wouldn't like me when I'm angry...
9-
const bruce = (id, event, cmd) =>
10-
`\n> ${id ? id + ' ' : ''}${event}\n> ${cmd.trim().replace(/\n/g, '\n> ')}\n`
9+
const bruce = (id, event, cmd, args) => {
10+
let banner = id
11+
? `\n> ${id} ${event}\n`
12+
: `\n> ${event}\n`
13+
banner += `> ${cmd.trim().replace(/\n/g, '\n> ')}`
14+
if (args.length) {
15+
banner += ` ${args.join(' ')}`
16+
}
17+
banner += '\n'
18+
return banner
19+
}
1120

1221
const runScriptPkg = async options => {
1322
const {
@@ -52,10 +61,10 @@ const runScriptPkg = async options => {
5261

5362
if (stdio === 'inherit' && banner !== false) {
5463
// we're dumping to the parent's stdout, so print the banner
55-
console.log(bruce(pkg._id, event, cmd))
64+
console.log(bruce(pkg._id, event, cmd, args))
5665
}
5766

58-
const [spawnShell, spawnArgs, spawnOpts, cleanup] = makeSpawnArgs({
67+
const [spawnShell, spawnArgs, spawnOpts] = makeSpawnArgs({
5968
event,
6069
path,
6170
scriptShell,
@@ -93,7 +102,7 @@ const runScriptPkg = async options => {
93102
} else {
94103
throw er
95104
}
96-
}).finally(cleanup)
105+
})
97106
}
98107

99108
module.exports = runScriptPkg

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

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

package-lock.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"@npmcli/fs": "^2.1.0",
9595
"@npmcli/map-workspaces": "^2.0.3",
9696
"@npmcli/package-json": "^2.0.0",
97-
"@npmcli/run-script": "^4.2.0",
97+
"@npmcli/run-script": "^4.2.1",
9898
"abbrev": "~1.1.1",
9999
"archy": "~1.0.0",
100100
"cacache": "^16.1.1",
@@ -1057,9 +1057,9 @@
10571057
}
10581058
},
10591059
"node_modules/@npmcli/run-script": {
1060-
"version": "4.2.0",
1061-
"resolved": "https://registry.npmjs.org/@npmcli/run-script/-/run-script-4.2.0.tgz",
1062-
"integrity": "sha512-e/QgLg7j2wSJp1/7JRl0GC8c7PMX+uYlA/1Tb+IDOLdSM4T7K1VQ9mm9IGU3WRtY5vEIObpqCLb3aCNCug18DA==",
1060+
"version": "4.2.1",
1061+
"resolved": "https://registry.npmjs.org/@npmcli/run-script/-/run-script-4.2.1.tgz",
1062+
"integrity": "sha512-7dqywvVudPSrRCW5nTHpHgeWnbBtz8cFkOuKrecm6ih+oO9ciydhWt6OF7HlqupRRmB8Q/gECVdB9LMfToJbRg==",
10631063
"inBundle": true,
10641064
"dependencies": {
10651065
"@npmcli/node-gyp": "^2.0.0",

package.json

Lines changed: 1 addition & 1 deletion
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.2.0",
65+
"@npmcli/run-script": "^4.2.1",
6666
"abbrev": "~1.1.1",
6767
"archy": "~1.0.0",
6868
"cacache": "^16.1.1",

0 commit comments

Comments
 (0)