diff options
author | Gar <gar+gh@danger.computer> | 2022-08-10 18:30:32 +0300 |
---|---|---|
committer | Gar <wraithgar@github.com> | 2022-08-10 19:44:06 +0300 |
commit | d0f5995e0399a093c8037057150a922e56b1d7ca (patch) | |
tree | 555683162a551ac35ebd6a2fe14af5337c8353af /node_modules | |
parent | 4e5dd732d7fe39490be1d9f8e81cbdba602c67fe (diff) |
deps: @npmcli/run-script@4.2.1
* add arguments back to the logged banner
* remove the temp file entirely
Diffstat (limited to 'node_modules')
-rw-r--r-- | node_modules/@npmcli/run-script/lib/escape.js | 13 | ||||
-rw-r--r-- | node_modules/@npmcli/run-script/lib/make-spawn-args.js | 51 | ||||
-rw-r--r-- | node_modules/@npmcli/run-script/lib/run-script-pkg.js | 19 | ||||
-rw-r--r-- | node_modules/@npmcli/run-script/package.json | 2 |
4 files changed, 28 insertions, 57 deletions
diff --git a/node_modules/@npmcli/run-script/lib/escape.js b/node_modules/@npmcli/run-script/lib/escape.js index 303100d33..9aca8bde7 100644 --- a/node_modules/@npmcli/run-script/lib/escape.js +++ b/node_modules/@npmcli/run-script/lib/escape.js @@ -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 } @@ -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, } diff --git a/node_modules/@npmcli/run-script/lib/make-spawn-args.js b/node_modules/@npmcli/run-script/lib/make-spawn-args.js index 7725fd976..5b06db3c1 100644 --- a/node_modules/@npmcli/run-script/lib/make-spawn-args.js +++ b/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 { @@ -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 = '' @@ -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, @@ -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 diff --git a/node_modules/@npmcli/run-script/lib/run-script-pkg.js b/node_modules/@npmcli/run-script/lib/run-script-pkg.js index ec6ef31e5..c10d20bb7 100644 --- a/node_modules/@npmcli/run-script/lib/run-script-pkg.js +++ b/node_modules/@npmcli/run-script/lib/run-script-pkg.js @@ -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 { @@ -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, @@ -93,7 +102,7 @@ const runScriptPkg = async options => { } else { throw er } - }).finally(cleanup) + }) } module.exports = runScriptPkg diff --git a/node_modules/@npmcli/run-script/package.json b/node_modules/@npmcli/run-script/package.json index a6629826d..551dc610f 100644 --- a/node_modules/@npmcli/run-script/package.json +++ b/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", |