Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornlf <quitlahok@gmail.com>2022-06-23 22:46:21 +0300
committerGitHub <noreply@github.com>2022-06-23 22:46:21 +0300
commitf59a114ffe3d1f86ccb2e52a4432292ab76852cc (patch)
treef05386d91c72ec239de011129c574dc8d0e9c954 /node_modules
parent69fa5ff515982d3bfee65f1dbadc71090c1796c9 (diff)
deps: @npmcli/run-script@4.1.3 (#5064)
* deps: @npmcli/run-script@4.1.3
Diffstat (limited to 'node_modules')
-rw-r--r--node_modules/@npmcli/run-script/lib/escape.js10
-rw-r--r--node_modules/@npmcli/run-script/lib/make-spawn-args.js70
-rw-r--r--node_modules/@npmcli/run-script/package.json2
3 files changed, 63 insertions, 19 deletions
diff --git a/node_modules/@npmcli/run-script/lib/escape.js b/node_modules/@npmcli/run-script/lib/escape.js
index 29d24a8bc..5254be24b 100644
--- a/node_modules/@npmcli/run-script/lib/escape.js
+++ b/node_modules/@npmcli/run-script/lib/escape.js
@@ -2,7 +2,7 @@
// eslint-disable-next-line max-len
// this code adapted from: https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
-const cmd = (input) => {
+const cmd = (input, doubleEscape) => {
if (!input.length) {
return '""'
}
@@ -36,8 +36,12 @@ const cmd = (input) => {
}
// and finally, prefix shell meta chars with a ^
- result = result.replace(/[!^&()<>|"]/g, '^$&')
- // except for % which is escaped with another %
+ result = result.replace(/[ !^&()<>|"]/g, '^$&')
+ if (doubleEscape) {
+ result = result.replace(/[ !^&()<>|"]/g, '^$&')
+ }
+
+ // except for % which is escaped with another %, and only once
result = result.replace(/%/g, '%%')
return result
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 6f3aa4c00..660588e3e 100644
--- a/node_modules/@npmcli/run-script/lib/make-spawn-args.js
+++ b/node_modules/@npmcli/run-script/lib/make-spawn-args.js
@@ -3,7 +3,7 @@ const isWindows = require('./is-windows.js')
const setPATH = require('./set-path.js')
const { chmodSync: chmod, unlinkSync: unlink, writeFileSync: writeFile } = require('fs')
const { tmpdir } = require('os')
-const { resolve } = require('path')
+const { isAbsolute, 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')
@@ -20,35 +20,75 @@ const makeSpawnArgs = options => {
stdioString = false,
} = options
+ const spawnEnv = setPATH(path, {
+ // we need to at least save the PATH environment var
+ ...process.env,
+ ...env,
+ npm_package_json: resolve(path, 'package.json'),
+ npm_lifecycle_event: event,
+ npm_lifecycle_script: cmd,
+ npm_config_node_gyp,
+ })
+
let scriptFile
let script = ''
+
const isCmd = /(?:^|\\)cmd(?:\.exe)?$/i.test(scriptShell)
if (isCmd) {
+ let initialCmd = ''
+ let insideQuotes = false
+ for (let i = 0; i < cmd.length; ++i) {
+ const char = cmd.charAt(i)
+ if (char === ' ' && !insideQuotes) {
+ break
+ }
+
+ initialCmd += char
+ if (char === '"' || char === "'") {
+ insideQuotes = !insideQuotes
+ }
+ }
+
+ let pathToInitial
+ try {
+ pathToInitial = which.sync(initialCmd, {
+ path: spawnEnv.path,
+ pathext: spawnEnv.pathext,
+ }).toLowerCase()
+ } catch (err) {
+ pathToInitial = initialCmd.toLowerCase()
+ }
+
+ const doubleEscape = pathToInitial.endsWith('.cmd') || pathToInitial.endsWith('.bat')
+
scriptFile = resolve(tmpdir(), `${event}-${Date.now()}.cmd`)
script += '@echo off\n'
- script += `${cmd} ${args.map((arg) => escape.cmd(arg)).join(' ')}`
+ script += cmd
+ if (args.length) {
+ script += ` ${args.map((arg) => escape.cmd(arg, doubleEscape)).join(' ')}`
+ }
} else {
- const shellPath = which.sync(scriptShell)
+ const shebang = isAbsolute(scriptShell)
+ ? `#!${scriptShell}`
+ : `#!/usr/bin/env ${scriptShell}`
scriptFile = resolve(tmpdir(), `${event}-${Date.now()}.sh`)
- script += `#!${shellPath}\n`
- script += `${cmd} ${args.map((arg) => escape.sh(arg)).join(' ')}`
+ script += `${shebang}\n`
+ script += cmd
+ if (args.length) {
+ script += ` ${args.map((arg) => escape.sh(arg)).join(' ')}`
+ }
}
+
writeFile(scriptFile, script)
if (!isCmd) {
chmod(scriptFile, '0775')
}
- const spawnArgs = isCmd ? ['/d', '/s', '/c', scriptFile] : ['-c', scriptFile]
+ const spawnArgs = isCmd
+ ? ['/d', '/s', '/c', escape.cmd(scriptFile)]
+ : ['-c', escape.sh(scriptFile)]
const spawnOpts = {
- env: setPATH(path, {
- // we need to at least save the PATH environment var
- ...process.env,
- ...env,
- npm_package_json: resolve(path, 'package.json'),
- npm_lifecycle_event: event,
- npm_lifecycle_script: cmd,
- npm_config_node_gyp,
- }),
+ env: spawnEnv,
stdioString,
stdio,
cwd: path,
diff --git a/node_modules/@npmcli/run-script/package.json b/node_modules/@npmcli/run-script/package.json
index 38c4862e1..ef8b43f77 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.1.0",
+ "version": "4.1.3",
"description": "Run a lifecycle script for a package (descendant of npm-lifecycle)",
"author": "GitHub Inc.",
"license": "ISC",