Skip to content

Commit 205e2fd

Browse files
lukekarryswraithgar
authored andcommitted
deps: pacote@15.0.6
1 parent 8fd614a commit 205e2fd

19 files changed

+434
-10
lines changed

node_modules/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@
192192
!/once
193193
!/p-map
194194
!/pacote
195+
!/pacote/node_modules/
196+
/pacote/node_modules/*
197+
!/pacote/node_modules/@npmcli/
198+
/pacote/node_modules/@npmcli/*
199+
!/pacote/node_modules/@npmcli/run-script
195200
!/parse-conflict-json
196201
!/path-is-absolute
197202
!/postcss-selector-parser

node_modules/pacote/lib/dir.js

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class DirFetcher extends Fetcher {
4949
pkg: mani,
5050
event: 'prepare',
5151
path: this.resolved,
52-
stdioString: true,
5352
stdio,
5453
banner,
5554
env: {

node_modules/pacote/lib/util/npm.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ module.exports = (npmBin, npmCommand, cwd, env, extra) => {
1010
// in temp directories. this lets us link previously-seen repos that
1111
// are also being prepared.
1212

13-
return spawn(cmd, args, { cwd, stdioString: true, env }, extra)
13+
return spawn(cmd, args, { cwd, env }, extra)
1414
}
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,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,40 @@
1+
/* eslint camelcase: "off" */
2+
const setPATH = require('./set-path.js')
3+
const { resolve } = require('path')
4+
const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
5+
6+
const makeSpawnArgs = options => {
7+
const {
8+
event,
9+
path,
10+
scriptShell = true,
11+
binPaths,
12+
env = {},
13+
stdio,
14+
cmd,
15+
args = [],
16+
stdioString,
17+
} = options
18+
19+
const spawnEnv = setPATH(path, binPaths, {
20+
// we need to at least save the PATH environment var
21+
...process.env,
22+
...env,
23+
npm_package_json: resolve(path, 'package.json'),
24+
npm_lifecycle_event: event,
25+
npm_lifecycle_script: cmd,
26+
npm_config_node_gyp,
27+
})
28+
29+
const spawnOpts = {
30+
env: spawnEnv,
31+
stdioString,
32+
stdio,
33+
cwd: path,
34+
shell: scriptShell,
35+
}
36+
37+
return [cmd, args, spawnOpts]
38+
}
39+
40+
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,108 @@
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, 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+
}
20+
21+
const runScriptPkg = async options => {
22+
const {
23+
event,
24+
path,
25+
scriptShell,
26+
binPaths = false,
27+
env = {},
28+
stdio = 'pipe',
29+
pkg,
30+
args = [],
31+
stdioString,
32+
// note: only used when stdio:inherit
33+
banner = true,
34+
// how long to wait for a process.kill signal
35+
// only exposed here so that we can make the test go a bit faster.
36+
signalTimeout = 500,
37+
} = options
38+
39+
const { scripts = {}, gypfile } = pkg
40+
let cmd = null
41+
if (options.cmd) {
42+
cmd = options.cmd
43+
} else if (pkg.scripts && pkg.scripts[event]) {
44+
cmd = pkg.scripts[event]
45+
} else if (
46+
// If there is no preinstall or install script, default to rebuilding node-gyp packages.
47+
event === 'install' &&
48+
!scripts.install &&
49+
!scripts.preinstall &&
50+
gypfile !== false &&
51+
await isNodeGypPackage(path)
52+
) {
53+
cmd = defaultGypInstallScript
54+
} else if (event === 'start' && await isServerPackage(path)) {
55+
cmd = 'node server.js'
56+
}
57+
58+
if (!cmd) {
59+
return { code: 0, signal: null }
60+
}
61+
62+
if (stdio === 'inherit' && banner !== false) {
63+
// we're dumping to the parent's stdout, so print the banner
64+
console.log(bruce(pkg._id, event, cmd, args))
65+
}
66+
67+
const [spawnShell, spawnArgs, spawnOpts] = makeSpawnArgs({
68+
event,
69+
path,
70+
scriptShell,
71+
binPaths,
72+
env: packageEnvs(env, pkg),
73+
stdio,
74+
cmd,
75+
args,
76+
stdioString,
77+
})
78+
79+
const p = promiseSpawn(spawnShell, spawnArgs, spawnOpts, {
80+
event,
81+
script: cmd,
82+
pkgid: pkg._id,
83+
path,
84+
})
85+
86+
if (stdio === 'inherit') {
87+
signalManager.add(p.process)
88+
}
89+
90+
if (p.stdin) {
91+
p.stdin.end()
92+
}
93+
94+
return p.catch(er => {
95+
const { signal } = er
96+
if (stdio === 'inherit' && signal) {
97+
process.kill(process.pid, signal)
98+
// just in case we don't die, reject after 500ms
99+
// this also keeps the node process open long enough to actually
100+
// get the signal, rather than terminating gracefully.
101+
return new Promise((res, rej) => setTimeout(() => rej(er), signalTimeout))
102+
} else {
103+
throw er
104+
}
105+
})
106+
}
107+
108+
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, delimiter } = require('path')
2+
// the path here is relative, even though it does not need to be
3+
// in order to make the posix tests pass in windows
4+
const nodeGypPath = resolve(__dirname, '../lib/node-gyp-bin')
5+
6+
// Windows typically calls its PATH environ 'Path', but this is not
7+
// guaranteed, nor is it guaranteed to be the only one. Merge them
8+
// all together in the order they appear in the object.
9+
const setPATH = (projectPath, binPaths, env) => {
10+
const PATH = Object.keys(env).filter(p => /^path$/i.test(p) && env[p])
11+
.map(p => env[p].split(delimiter))
12+
.reduce((set, p) => set.concat(p.filter(concatted => !set.includes(concatted))), [])
13+
.join(delimiter)
14+
15+
const pathArr = []
16+
if (binPaths) {
17+
pathArr.push(...binPaths)
18+
}
19+
// unshift the ./node_modules/.bin from every folder
20+
// walk up until dirname() does nothing, at the root
21+
// XXX we should 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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const runningProcs = new Set()
2+
let handlersInstalled = false
3+
4+
const forwardedSignals = [
5+
'SIGINT',
6+
'SIGTERM',
7+
]
8+
9+
const handleSignal = signal => {
10+
for (const proc of runningProcs) {
11+
proc.kill(signal)
12+
}
13+
}
14+
15+
const setupListeners = () => {
16+
for (const signal of forwardedSignals) {
17+
process.on(signal, handleSignal)
18+
}
19+
handlersInstalled = true
20+
}
21+
22+
const cleanupListeners = () => {
23+
if (runningProcs.size === 0) {
24+
for (const signal of forwardedSignals) {
25+
process.removeListener(signal, handleSignal)
26+
}
27+
handlersInstalled = false
28+
}
29+
}
30+
31+
const add = proc => {
32+
runningProcs.add(proc)
33+
if (!handlersInstalled) {
34+
setupListeners()
35+
}
36+
37+
proc.once('exit', () => {
38+
runningProcs.delete(proc)
39+
cleanupListeners()
40+
})
41+
}
42+
43+
module.exports = {
44+
add,
45+
handleSignal,
46+
forwardedSignals,
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const validateOptions = options => {
2+
if (typeof options !== 'object' || !options) {
3+
throw new TypeError('invalid options object provided to runScript')
4+
}
5+
6+
const {
7+
event,
8+
path,
9+
scriptShell,
10+
env = {},
11+
stdio = 'pipe',
12+
args = [],
13+
cmd,
14+
} = options
15+
16+
if (!event || typeof event !== 'string') {
17+
throw new TypeError('valid event not provided to runScript')
18+
}
19+
if (!path || typeof path !== 'string') {
20+
throw new TypeError('valid path not provided to runScript')
21+
}
22+
if (scriptShell !== undefined && typeof scriptShell !== 'string') {
23+
throw new TypeError('invalid scriptShell option provided to runScript')
24+
}
25+
if (typeof env !== 'object' || !env) {
26+
throw new TypeError('invalid env option provided to runScript')
27+
}
28+
if (typeof stdio !== 'string' && !Array.isArray(stdio)) {
29+
throw new TypeError('invalid stdio option provided to runScript')
30+
}
31+
if (!Array.isArray(args) || args.some(a => typeof a !== 'string')) {
32+
throw new TypeError('invalid args option provided to runScript')
33+
}
34+
if (cmd !== undefined && typeof cmd !== 'string') {
35+
throw new TypeError('invalid cmd option provided to runScript')
36+
}
37+
}
38+
39+
module.exports = validateOptions

0 commit comments

Comments
 (0)