Skip to content

Commit

Permalink
deps: @npmcli/run-script@4.2.1
Browse files Browse the repository at this point in the history
 * add arguments back to the logged banner
 * remove the temp file entirely
  • Loading branch information
wraithgar committed Aug 10, 2022
1 parent 4e5dd73 commit d0f5995
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 62 deletions.
13 changes: 2 additions & 11 deletions node_modules/@npmcli/run-script/lib/escape.js
Expand Up @@ -36,14 +36,11 @@ const cmd = (input, doubleEscape) => {
}

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

// except for % which is escaped with another %, and only once
result = result.replace(/%/g, '%%')

return result
}

Expand All @@ -65,13 +62,7 @@ const sh = (input) => {
return result
}

// disabling the no-control-regex rule for this line as we very specifically _do_ want to
// replace those characters if they somehow exist at this point, which is highly unlikely
// eslint-disable-next-line no-control-regex
const filename = (input) => input.replace(/[<>:"/\\|?*\x00-\x1F]/g, '')

module.exports = {
cmd,
sh,
filename,
}
51 changes: 11 additions & 40 deletions node_modules/@npmcli/run-script/lib/make-spawn-args.js
@@ -1,19 +1,10 @@
/* eslint camelcase: "off" */
const isWindows = require('./is-windows.js')
const setPATH = require('./set-path.js')
const { unlinkSync: unlink, writeFileSync: writeFile } = require('fs')
const { tmpdir } = require('os')
const { resolve } = require('path')
const which = require('which')
const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
const escape = require('./escape.js')
const { randomBytes } = require('crypto')

const translateWinPathToPosix = (path) => {
return path
.replace(/^([A-z]):/, '/$1')
.replace(/\\/g, '/')
}

const makeSpawnArgs = options => {
const {
Expand All @@ -38,10 +29,7 @@ const makeSpawnArgs = options => {
npm_config_node_gyp,
})

const fileName = escape.filename(`${event}-${randomBytes(4).toString('hex')}`)
let scriptFile
let script = ''

let doubleEscape = false
const isCmd = /(?:^|\\)cmd(?:\.exe)?$/i.test(scriptShell)
if (isCmd) {
let initialCmd = ''
Expand All @@ -68,26 +56,18 @@ const makeSpawnArgs = options => {
pathToInitial = initialCmd.toLowerCase()
}

const doubleEscape = pathToInitial.endsWith('.cmd') || pathToInitial.endsWith('.bat')

scriptFile = resolve(tmpdir(), `${fileName}.cmd`)
script += '@echo off\n'
script += cmd
if (args.length) {
script += ` ${args.map((arg) => escape.cmd(arg, doubleEscape)).join(' ')}`
}
} else {
scriptFile = resolve(tmpdir(), `${fileName}.sh`)
script = cmd
if (args.length) {
script += ` ${args.map((arg) => escape.sh(arg)).join(' ')}`
}
doubleEscape = pathToInitial.endsWith('.cmd') || pathToInitial.endsWith('.bat')
}

writeFile(scriptFile, script)
let script = cmd
for (const arg of args) {
script += isCmd
? ` ${escape.cmd(arg, doubleEscape)}`
: ` ${escape.sh(arg)}`
}
const spawnArgs = isCmd
? ['/d', '/s', '/c', escape.cmd(scriptFile)]
: [isWindows ? translateWinPathToPosix(scriptFile) : scriptFile]
? ['/d', '/s', '/c', script]
: ['-c', '--', script]

const spawnOpts = {
env: spawnEnv,
Expand All @@ -97,16 +77,7 @@ const makeSpawnArgs = options => {
...(isCmd ? { windowsVerbatimArguments: true } : {}),
}

const cleanup = () => {
// delete the script, this is just a best effort
try {
unlink(scriptFile)
} catch (err) {
// ignore errors
}
}

return [scriptShell, spawnArgs, spawnOpts, cleanup]
return [scriptShell, spawnArgs, spawnOpts]
}

module.exports = makeSpawnArgs
19 changes: 14 additions & 5 deletions node_modules/@npmcli/run-script/lib/run-script-pkg.js
Expand Up @@ -6,8 +6,17 @@ const signalManager = require('./signal-manager.js')
const isServerPackage = require('./is-server-package.js')

// you wouldn't like me when I'm angry...
const bruce = (id, event, cmd) =>
`\n> ${id ? id + ' ' : ''}${event}\n> ${cmd.trim().replace(/\n/g, '\n> ')}\n`
const bruce = (id, event, cmd, args) => {
let banner = id
? `\n> ${id} ${event}\n`
: `\n> ${event}\n`
banner += `> ${cmd.trim().replace(/\n/g, '\n> ')}`
if (args.length) {
banner += ` ${args.join(' ')}`
}
banner += '\n'
return banner
}

const runScriptPkg = async options => {
const {
Expand Down Expand Up @@ -52,10 +61,10 @@ const runScriptPkg = async options => {

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

const [spawnShell, spawnArgs, spawnOpts, cleanup] = makeSpawnArgs({
const [spawnShell, spawnArgs, spawnOpts] = makeSpawnArgs({
event,
path,
scriptShell,
Expand Down Expand Up @@ -93,7 +102,7 @@ const runScriptPkg = async options => {
} else {
throw er
}
}).finally(cleanup)
})
}

module.exports = runScriptPkg
2 changes: 1 addition & 1 deletion node_modules/@npmcli/run-script/package.json
@@ -1,6 +1,6 @@
{
"name": "@npmcli/run-script",
"version": "4.2.0",
"version": "4.2.1",
"description": "Run a lifecycle script for a package (descendant of npm-lifecycle)",
"author": "GitHub Inc.",
"license": "ISC",
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json
Expand Up @@ -94,7 +94,7 @@
"@npmcli/fs": "^2.1.0",
"@npmcli/map-workspaces": "^2.0.3",
"@npmcli/package-json": "^2.0.0",
"@npmcli/run-script": "^4.2.0",
"@npmcli/run-script": "^4.2.1",
"abbrev": "~1.1.1",
"archy": "~1.0.0",
"cacache": "^16.1.1",
Expand Down Expand Up @@ -1057,9 +1057,9 @@
}
},
"node_modules/@npmcli/run-script": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/@npmcli/run-script/-/run-script-4.2.0.tgz",
"integrity": "sha512-e/QgLg7j2wSJp1/7JRl0GC8c7PMX+uYlA/1Tb+IDOLdSM4T7K1VQ9mm9IGU3WRtY5vEIObpqCLb3aCNCug18DA==",
"version": "4.2.1",
"resolved": "https://registry.npmjs.org/@npmcli/run-script/-/run-script-4.2.1.tgz",
"integrity": "sha512-7dqywvVudPSrRCW5nTHpHgeWnbBtz8cFkOuKrecm6ih+oO9ciydhWt6OF7HlqupRRmB8Q/gECVdB9LMfToJbRg==",
"inBundle": true,
"dependencies": {
"@npmcli/node-gyp": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -62,7 +62,7 @@
"@npmcli/fs": "^2.1.0",
"@npmcli/map-workspaces": "^2.0.3",
"@npmcli/package-json": "^2.0.0",
"@npmcli/run-script": "^4.2.0",
"@npmcli/run-script": "^4.2.1",
"abbrev": "~1.1.1",
"archy": "~1.0.0",
"cacache": "^16.1.1",
Expand Down

0 comments on commit d0f5995

Please sign in to comment.