Skip to content

Commit bb63bf9

Browse files
committed
deps: @npmcli/[email protected]
1 parent 75642c6 commit bb63bf9

File tree

21 files changed

+453
-20
lines changed

21 files changed

+453
-20
lines changed

node_modules/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
!/pacote/node_modules/@npmcli/
235235
/pacote/node_modules/@npmcli/*
236236
!/pacote/node_modules/@npmcli/promise-spawn
237+
!/pacote/node_modules/@npmcli/run-script
237238
!/pacote/node_modules/which
238239
!/parse-conflict-json
239240
!/path-is-absolute

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@npmcli/run-script",
3-
"version": "6.0.2",
3+
"version": "7.0.0",
44
"description": "Run a lifecycle script for a package (descendant of npm-lifecycle)",
55
"author": "GitHub Inc.",
66
"license": "ISC",
@@ -16,7 +16,7 @@
1616
},
1717
"devDependencies": {
1818
"@npmcli/eslint-config": "^4.0.0",
19-
"@npmcli/template-oss": "4.15.1",
19+
"@npmcli/template-oss": "4.18.0",
2020
"require-inject": "^1.4.4",
2121
"tap": "^16.0.1"
2222
},
@@ -25,7 +25,7 @@
2525
"@npmcli/promise-spawn": "^6.0.0",
2626
"node-gyp": "^9.0.0",
2727
"read-package-json-fast": "^3.0.0",
28-
"which": "^3.0.0"
28+
"which": "^4.0.0"
2929
},
3030
"files": [
3131
"bin/",
@@ -37,11 +37,17 @@
3737
"url": "https://github.com/npm/run-script.git"
3838
},
3939
"engines": {
40-
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
40+
"node": "^16.14.0 || >=18.0.0"
4141
},
4242
"templateOSS": {
4343
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
44-
"version": "4.15.1",
44+
"ciVersions": [
45+
"16.14.0",
46+
"16.x",
47+
"18.0.0",
48+
"18.x"
49+
],
50+
"version": "4.18.0",
4551
"publish": "true"
4652
},
4753
"tap": {
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,112 @@
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+
// by the time we reach here, the child has already exited. we send the
98+
// signal back to ourselves again so that npm will exit with the same
99+
// status as the child
100+
process.kill(process.pid, signal)
101+
102+
// just in case we don't die, reject after 500ms
103+
// this also keeps the node process open long enough to actually
104+
// get the signal, rather than terminating gracefully.
105+
return new Promise((res, rej) => setTimeout(() => rej(er), signalTimeout))
106+
} else {
107+
throw er
108+
}
109+
})
110+
}
111+
112+
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,49 @@
1+
const runningProcs = new Set()
2+
let handlersInstalled = false
3+
4+
// NOTE: these signals aren't actually forwarded anywhere. they're trapped and
5+
// ignored until all child processes have exited. in our next breaking change
6+
// we should rename this
7+
const forwardedSignals = [
8+
'SIGINT',
9+
'SIGTERM',
10+
]
11+
12+
// no-op, this is so receiving the signal doesn't cause us to exit immediately
13+
// instead, we exit after all children have exited when we re-send the signal
14+
// to ourselves. see the catch handler at the bottom of run-script-pkg.js
15+
// istanbul ignore next - this function does nothing
16+
const handleSignal = () => {}
17+
const setupListeners = () => {
18+
for (const signal of forwardedSignals) {
19+
process.on(signal, handleSignal)
20+
}
21+
handlersInstalled = true
22+
}
23+
24+
const cleanupListeners = () => {
25+
if (runningProcs.size === 0) {
26+
for (const signal of forwardedSignals) {
27+
process.removeListener(signal, handleSignal)
28+
}
29+
handlersInstalled = false
30+
}
31+
}
32+
33+
const add = proc => {
34+
runningProcs.add(proc)
35+
if (!handlersInstalled) {
36+
setupListeners()
37+
}
38+
39+
proc.once('exit', () => {
40+
runningProcs.delete(proc)
41+
cleanupListeners()
42+
})
43+
}
44+
45+
module.exports = {
46+
add,
47+
handleSignal,
48+
forwardedSignals,
49+
}

0 commit comments

Comments
 (0)