Skip to content

Commit 2e50cb8

Browse files
nlffritzy
authored andcommittedJun 22, 2022
deps: pacote@13.6.1
1 parent 69b5a96 commit 2e50cb8

21 files changed

+536
-20
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
The ISC License
2+
3+
Copyright (c) npm, Inc.
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
'use strict'
2+
3+
// eslint-disable-next-line max-len
4+
// 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) => {
6+
if (!input.length) {
7+
return '""'
8+
}
9+
10+
let result
11+
if (!/[ \t\n\v"]/.test(input)) {
12+
result = input
13+
} else {
14+
result = '"'
15+
for (let i = 0; i <= input.length; ++i) {
16+
let slashCount = 0
17+
while (input[i] === '\\') {
18+
++i
19+
++slashCount
20+
}
21+
22+
if (i === input.length) {
23+
result += '\\'.repeat(slashCount * 2)
24+
break
25+
}
26+
27+
if (input[i] === '"') {
28+
result += '\\'.repeat(slashCount * 2 + 1)
29+
result += input[i]
30+
} else {
31+
result += '\\'.repeat(slashCount)
32+
result += input[i]
33+
}
34+
}
35+
result += '"'
36+
}
37+
38+
// and finally, prefix shell meta chars with a ^
39+
result = result.replace(/[!^&()<>|"]/g, '^$&')
40+
// except for % which is escaped with another %
41+
result = result.replace(/%/g, '%%')
42+
43+
return result
44+
}
45+
46+
const sh = (input) => {
47+
if (!input.length) {
48+
return `''`
49+
}
50+
51+
if (!/[\t\n\r "#$&'()*;<>?\\`|~]/.test(input)) {
52+
return input
53+
}
54+
55+
// replace single quotes with '\'' and wrap the whole result in a fresh set of quotes
56+
const result = `'${input.replace(/'/g, `'\\''`)}'`
57+
// if the input string already had single quotes around it, clean those up
58+
.replace(/^(?:'')+(?!$)/, '')
59+
.replace(/\\'''/g, `\\'`)
60+
61+
return result
62+
}
63+
64+
module.exports = {
65+
cmd,
66+
sh,
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const util = require('util')
2+
const fs = require('fs')
3+
const { stat } = fs.promises || { stat: util.promisify(fs.stat) }
4+
const { resolve } = require('path')
5+
module.exports = async path => {
6+
try {
7+
const st = await stat(resolve(path, 'server.js'))
8+
return st.isFile()
9+
} catch (er) {
10+
return false
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const platform = process.env.__FAKE_TESTING_PLATFORM__ || process.platform
2+
module.exports = platform === 'win32'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* eslint camelcase: "off" */
2+
const isWindows = require('./is-windows.js')
3+
const setPATH = require('./set-path.js')
4+
const { chmodSync: chmod, unlinkSync: unlink, writeFileSync: writeFile } = require('fs')
5+
const { tmpdir } = require('os')
6+
const { resolve } = require('path')
7+
const which = require('which')
8+
const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
9+
const escape = require('./escape.js')
10+
11+
const makeSpawnArgs = options => {
12+
const {
13+
event,
14+
path,
15+
scriptShell = isWindows ? process.env.ComSpec || 'cmd' : 'sh',
16+
env = {},
17+
stdio,
18+
cmd,
19+
args = [],
20+
stdioString = false,
21+
} = options
22+
23+
let scriptFile
24+
let script = ''
25+
const isCmd = /(?:^|\\)cmd(?:\.exe)?$/i.test(scriptShell)
26+
if (isCmd) {
27+
scriptFile = resolve(tmpdir(), `${event}-${Date.now()}.cmd`)
28+
script += '@echo off\n'
29+
script += `${cmd} ${args.map((arg) => escape.cmd(arg)).join(' ')}`
30+
} else {
31+
const shellPath = which.sync(scriptShell)
32+
scriptFile = resolve(tmpdir(), `${event}-${Date.now()}.sh`)
33+
script += `#!${shellPath}\n`
34+
script += `${cmd} ${args.map((arg) => escape.sh(arg)).join(' ')}`
35+
}
36+
writeFile(scriptFile, script)
37+
if (!isCmd) {
38+
chmod(scriptFile, '0775')
39+
}
40+
const spawnArgs = isCmd ? ['/d', '/s', '/c', scriptFile] : ['-c', scriptFile]
41+
42+
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+
}),
52+
stdioString,
53+
stdio,
54+
cwd: path,
55+
...(isCmd ? { windowsVerbatimArguments: true } : {}),
56+
}
57+
58+
const cleanup = () => {
59+
// delete the script, this is just a best effort
60+
try {
61+
unlink(scriptFile)
62+
} catch (err) {}
63+
}
64+
65+
return [scriptShell, spawnArgs, spawnOpts, cleanup]
66+
}
67+
68+
module.exports = makeSpawnArgs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env sh
2+
node "$npm_config_node_gyp" "$@"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@node "%npm_config_node_gyp%" %*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// https://github.com/npm/rfcs/pull/183
2+
3+
const envVal = val => Array.isArray(val) ? val.map(v => envVal(v)).join('\n\n')
4+
: val === null || val === false ? ''
5+
: String(val)
6+
7+
const packageEnvs = (env, vals, prefix) => {
8+
for (const [key, val] of Object.entries(vals)) {
9+
if (val === undefined) {
10+
continue
11+
} else if (val && !Array.isArray(val) && typeof val === 'object') {
12+
packageEnvs(env, val, `${prefix}${key}_`)
13+
} else {
14+
env[`${prefix}${key}`] = envVal(val)
15+
}
16+
}
17+
return env
18+
}
19+
20+
module.exports = (env, pkg) => packageEnvs({ ...env }, {
21+
name: pkg.name,
22+
version: pkg.version,
23+
config: pkg.config,
24+
engines: pkg.engines,
25+
bin: pkg.bin,
26+
}, 'npm_package_')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
const makeSpawnArgs = require('./make-spawn-args.js')
2+
const promiseSpawn = require('@npmcli/promise-spawn')
3+
const packageEnvs = require('./package-envs.js')
4+
const { isNodeGypPackage, defaultGypInstallScript } = require('@npmcli/node-gyp')
5+
const signalManager = require('./signal-manager.js')
6+
const isServerPackage = require('./is-server-package.js')
7+
8+
// 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`
11+
12+
const runScriptPkg = async options => {
13+
const {
14+
event,
15+
path,
16+
scriptShell,
17+
env = {},
18+
stdio = 'pipe',
19+
pkg,
20+
args = [],
21+
stdioString = false,
22+
// note: only used when stdio:inherit
23+
banner = true,
24+
// how long to wait for a process.kill signal
25+
// only exposed here so that we can make the test go a bit faster.
26+
signalTimeout = 500,
27+
} = options
28+
29+
const { scripts = {}, gypfile } = pkg
30+
let cmd = null
31+
if (options.cmd) {
32+
cmd = options.cmd
33+
} else if (pkg.scripts && pkg.scripts[event]) {
34+
cmd = pkg.scripts[event]
35+
} else if (
36+
// If there is no preinstall or install script, default to rebuilding node-gyp packages.
37+
event === 'install' &&
38+
!scripts.install &&
39+
!scripts.preinstall &&
40+
gypfile !== false &&
41+
await isNodeGypPackage(path)
42+
) {
43+
cmd = defaultGypInstallScript
44+
} else if (event === 'start' && await isServerPackage(path)) {
45+
cmd = 'node server.js'
46+
}
47+
48+
if (!cmd) {
49+
return { code: 0, signal: null }
50+
}
51+
52+
if (stdio === 'inherit' && banner !== false) {
53+
// we're dumping to the parent's stdout, so print the banner
54+
console.log(bruce(pkg._id, event, cmd))
55+
}
56+
57+
const [spawnShell, spawnArgs, spawnOpts, cleanup] = makeSpawnArgs({
58+
event,
59+
path,
60+
scriptShell,
61+
env: packageEnvs(env, pkg),
62+
stdio,
63+
cmd,
64+
args,
65+
stdioString,
66+
})
67+
68+
const p = promiseSpawn(spawnShell, spawnArgs, spawnOpts, {
69+
event,
70+
script: cmd,
71+
pkgid: pkg._id,
72+
path,
73+
})
74+
75+
if (stdio === 'inherit') {
76+
signalManager.add(p.process)
77+
}
78+
79+
if (p.stdin) {
80+
p.stdin.end()
81+
}
82+
83+
return p.catch(er => {
84+
const { signal } = er
85+
if (stdio === 'inherit' && signal) {
86+
process.kill(process.pid, signal)
87+
// just in case we don't die, reject after 500ms
88+
// this also keeps the node process open long enough to actually
89+
// get the signal, rather than terminating gracefully.
90+
return new Promise((res, rej) => setTimeout(() => rej(er), signalTimeout))
91+
} else {
92+
throw er
93+
}
94+
}).finally(cleanup)
95+
}
96+
97+
module.exports = runScriptPkg
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const rpj = require('read-package-json-fast')
2+
const runScriptPkg = require('./run-script-pkg.js')
3+
const validateOptions = require('./validate-options.js')
4+
const isServerPackage = require('./is-server-package.js')
5+
6+
const runScript = options => {
7+
validateOptions(options)
8+
const { pkg, path } = options
9+
return pkg ? runScriptPkg(options)
10+
: rpj(path + '/package.json')
11+
.then(readPackage => runScriptPkg({ ...options, pkg: readPackage }))
12+
}
13+
14+
module.exports = Object.assign(runScript, { isServerPackage })
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const { resolve, dirname } = require('path')
2+
const isWindows = require('./is-windows.js')
3+
// the path here is relative, even though it does not need to be
4+
// in order to make the posix tests pass in windows
5+
const nodeGypPath = resolve(__dirname, '../lib/node-gyp-bin')
6+
7+
// Windows typically calls its PATH environ 'Path', but this is not
8+
// guaranteed, nor is it guaranteed to be the only one. Merge them
9+
// all together in the order they appear in the object.
10+
const setPATH = (projectPath, env) => {
11+
// not require('path').delimiter, because we fake this for testing
12+
const delimiter = isWindows ? ';' : ':'
13+
const PATH = Object.keys(env).filter(p => /^path$/i.test(p) && env[p])
14+
.map(p => env[p].split(delimiter))
15+
.reduce((set, p) => set.concat(p.filter(concatted => !set.includes(concatted))), [])
16+
.join(delimiter)
17+
18+
const pathArr = []
19+
// unshift the ./node_modules/.bin from every folder
20+
// walk up until dirname() does nothing, at the root
21+
// XXX should we specify a cwd that we don't go above?
22+
let p = projectPath
23+
let pp
24+
do {
25+
pathArr.push(resolve(p, 'node_modules', '.bin'))
26+
pp = p
27+
p = dirname(p)
28+
} while (p !== pp)
29+
pathArr.push(nodeGypPath, PATH)
30+
31+
const pathVal = pathArr.join(delimiter)
32+
33+
// XXX include the node-gyp-bin path somehow? Probably better for
34+
// npm or arborist or whoever to just provide that by putting it in
35+
// the PATH environ, since that's preserved anyway.
36+
for (const key of Object.keys(env)) {
37+
if (/^path$/i.test(key)) {
38+
env[key] = pathVal
39+
}
40+
}
41+
42+
return env
43+
}
44+
45+
module.exports = setPATH

‎node_modules/pacote/node_modules/@npmcli/run-script/lib/signal-manager.js

+47
Original file line numberDiff line numberDiff line change

‎node_modules/pacote/node_modules/@npmcli/run-script/lib/validate-options.js

+39
Original file line numberDiff line numberDiff line change

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

+53
Original file line numberDiff line numberDiff line change

‎node_modules/pacote/package.json

+2-2
Original file line numberDiff line numberDiff line change

‎package-lock.json

+41-13
Original file line numberDiff line numberDiff line change

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"npm-user-validate": "^1.0.1",
108108
"npmlog": "^6.0.2",
109109
"opener": "^1.5.2",
110-
"pacote": "^13.6.0",
110+
"pacote": "^13.6.1",
111111
"parse-conflict-json": "^2.0.2",
112112
"proc-log": "^2.0.1",
113113
"qrcode-terminal": "^0.12.0",

‎workspaces/arborist/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"npm-pick-manifest": "^7.0.0",
2626
"npm-registry-fetch": "^13.0.0",
2727
"npmlog": "^6.0.2",
28-
"pacote": "^13.0.5",
28+
"pacote": "^13.6.1",
2929
"parse-conflict-json": "^2.0.1",
3030
"proc-log": "^2.0.0",
3131
"promise-all-reject-late": "^1.0.0",

‎workspaces/libnpmdiff/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"diff": "^5.0.0",
5757
"minimatch": "^5.0.1",
5858
"npm-package-arg": "^9.0.1",
59-
"pacote": "^13.0.5",
59+
"pacote": "^13.6.1",
6060
"tar": "^6.1.0"
6161
},
6262
"templateOSS": {

‎workspaces/libnpmexec/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"mkdirp-infer-owner": "^2.0.0",
6363
"npm-package-arg": "^9.0.1",
6464
"npmlog": "^6.0.2",
65-
"pacote": "^13.0.5",
65+
"pacote": "^13.6.1",
6666
"proc-log": "^2.0.0",
6767
"read": "^1.0.7",
6868
"read-package-json-fast": "^2.0.2",

‎workspaces/libnpmpack/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"dependencies": {
4141
"@npmcli/run-script": "^3.0.0",
4242
"npm-package-arg": "^9.0.1",
43-
"pacote": "^13.5.0"
43+
"pacote": "^13.6.1"
4444
},
4545
"engines": {
4646
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"

0 commit comments

Comments
 (0)
Please sign in to comment.