Skip to content

Commit 1b95e73

Browse files
committed
1 parent 6927fd3 commit 1b95e73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+11343
-11
lines changed

node_modules/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,14 @@
270270
!/read-cmd-shim
271271
!/read-package-json-fast
272272
!/read-package-json
273+
!/read-package-json/node_modules/
274+
/read-package-json/node_modules/*
275+
!/read-package-json/node_modules/foreground-child
276+
!/read-package-json/node_modules/glob
277+
!/read-package-json/node_modules/jackspeak
278+
!/read-package-json/node_modules/minimatch
279+
!/read-package-json/node_modules/minipass
280+
!/read-package-json/node_modules/signal-exit
273281
!/read
274282
!/readable-stream
275283
!/retry

node_modules/read-package-json/lib/read-json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var fs = require('fs')
22

33
var path = require('path')
44

5-
var glob = require('glob')
5+
var { glob } = require('glob')
66
var normalizeData = require('normalize-package-data')
77
var safeJSON = require('json-parse-even-better-errors')
88
var util = require('util')
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
The ISC License
2+
3+
Copyright (c) 2015-2023 Isaac Z. Schlueter and Contributors
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.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.allSignals = void 0;
7+
const node_constants_1 = __importDefault(require("node:constants"));
8+
exports.allSignals =
9+
// this is the full list of signals that Node will let us do anything with
10+
Object.keys(node_constants_1.default).filter(k => k.startsWith('SIG') &&
11+
// https://github.com/tapjs/signal-exit/issues/21
12+
k !== 'SIGPROF' &&
13+
// no sense trying to listen for SIGKILL, it's impossible
14+
k !== 'SIGKILL');
15+
// These are some obscure signals that are reported by kill -l
16+
// on macOS, Linux, or Windows, but which don't have any mapping
17+
// in Node.js. No sense trying if they're just going to throw
18+
// every time on every platform.
19+
//
20+
// 'SIGEMT',
21+
// 'SIGLOST',
22+
// 'SIGPOLL',
23+
// 'SIGRTMAX',
24+
// 'SIGRTMAX-1',
25+
// 'SIGRTMAX-10',
26+
// 'SIGRTMAX-11',
27+
// 'SIGRTMAX-12',
28+
// 'SIGRTMAX-13',
29+
// 'SIGRTMAX-14',
30+
// 'SIGRTMAX-15',
31+
// 'SIGRTMAX-2',
32+
// 'SIGRTMAX-3',
33+
// 'SIGRTMAX-4',
34+
// 'SIGRTMAX-5',
35+
// 'SIGRTMAX-6',
36+
// 'SIGRTMAX-7',
37+
// 'SIGRTMAX-8',
38+
// 'SIGRTMAX-9',
39+
// 'SIGRTMIN',
40+
// 'SIGRTMIN+1',
41+
// 'SIGRTMIN+10',
42+
// 'SIGRTMIN+11',
43+
// 'SIGRTMIN+12',
44+
// 'SIGRTMIN+13',
45+
// 'SIGRTMIN+14',
46+
// 'SIGRTMIN+15',
47+
// 'SIGRTMIN+16',
48+
// 'SIGRTMIN+2',
49+
// 'SIGRTMIN+3',
50+
// 'SIGRTMIN+4',
51+
// 'SIGRTMIN+5',
52+
// 'SIGRTMIN+6',
53+
// 'SIGRTMIN+7',
54+
// 'SIGRTMIN+8',
55+
// 'SIGRTMIN+9',
56+
// 'SIGSTKFLT',
57+
// 'SIGUNUSED',
58+
//# sourceMappingURL=all-signals.js.map
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.foregroundChild = exports.normalizeFgArgs = void 0;
7+
const child_process_1 = require("child_process");
8+
const cross_spawn_1 = __importDefault(require("cross-spawn"));
9+
const signal_exit_1 = require("signal-exit");
10+
const all_signals_js_1 = require("./all-signals.js");
11+
const watchdog_js_1 = require("./watchdog.js");
12+
/* c8 ignore start */
13+
const spawn = process?.platform === 'win32' ? cross_spawn_1.default : child_process_1.spawn;
14+
/**
15+
* Normalizes the arguments passed to `foregroundChild`.
16+
*
17+
* Exposed for testing.
18+
*
19+
* @internal
20+
*/
21+
const normalizeFgArgs = (fgArgs) => {
22+
let [program, args = [], spawnOpts = {}, cleanup = () => { }] = fgArgs;
23+
if (typeof args === 'function') {
24+
cleanup = args;
25+
spawnOpts = {};
26+
args = [];
27+
}
28+
else if (!!args && typeof args === 'object' && !Array.isArray(args)) {
29+
if (typeof spawnOpts === 'function')
30+
cleanup = spawnOpts;
31+
spawnOpts = args;
32+
args = [];
33+
}
34+
else if (typeof spawnOpts === 'function') {
35+
cleanup = spawnOpts;
36+
spawnOpts = {};
37+
}
38+
if (Array.isArray(program)) {
39+
const [pp, ...pa] = program;
40+
program = pp;
41+
args = pa;
42+
}
43+
return [program, args, { ...spawnOpts }, cleanup];
44+
};
45+
exports.normalizeFgArgs = normalizeFgArgs;
46+
function foregroundChild(...fgArgs) {
47+
const [program, args, spawnOpts, cleanup] = (0, exports.normalizeFgArgs)(fgArgs);
48+
spawnOpts.stdio = [0, 1, 2];
49+
if (process.send) {
50+
spawnOpts.stdio.push('ipc');
51+
}
52+
const child = spawn(program, args, spawnOpts);
53+
const unproxySignals = proxySignals(child);
54+
const childHangup = () => {
55+
try {
56+
child.kill('SIGHUP');
57+
/* c8 ignore start */
58+
}
59+
catch (_) {
60+
// SIGHUP is weird on windows
61+
child.kill('SIGTERM');
62+
}
63+
/* c8 ignore stop */
64+
};
65+
const removeOnExit = (0, signal_exit_1.onExit)(childHangup);
66+
const dog = (0, watchdog_js_1.watchdog)(child);
67+
let done = false;
68+
child.on('close', async (code, signal) => {
69+
dog.kill('SIGKILL');
70+
/* c8 ignore start */
71+
if (done) {
72+
return;
73+
}
74+
/* c8 ignore stop */
75+
done = true;
76+
const result = cleanup(code, signal);
77+
const res = isPromise(result) ? await result : result;
78+
removeOnExit();
79+
unproxySignals();
80+
if (res === false)
81+
return;
82+
else if (typeof res === 'string') {
83+
signal = res;
84+
code = null;
85+
}
86+
else if (typeof res === 'number') {
87+
code = res;
88+
signal = null;
89+
}
90+
if (signal) {
91+
// If there is nothing else keeping the event loop alive,
92+
// then there's a race between a graceful exit and getting
93+
// the signal to this process. Put this timeout here to
94+
// make sure we're still alive to get the signal, and thus
95+
// exit with the intended signal code.
96+
/* istanbul ignore next */
97+
setTimeout(() => { }, 2000);
98+
try {
99+
process.kill(process.pid, signal);
100+
/* c8 ignore start */
101+
}
102+
catch (_) {
103+
process.kill(process.pid, 'SIGTERM');
104+
}
105+
/* c8 ignore stop */
106+
}
107+
else {
108+
process.exit(code || 0);
109+
}
110+
});
111+
if (process.send) {
112+
process.removeAllListeners('message');
113+
child.on('message', (message, sendHandle) => {
114+
process.send?.(message, sendHandle);
115+
});
116+
process.on('message', (message, sendHandle) => {
117+
child.send(message, sendHandle);
118+
});
119+
}
120+
return child;
121+
}
122+
exports.foregroundChild = foregroundChild;
123+
/**
124+
* Starts forwarding signals to `child` through `parent`.
125+
*/
126+
const proxySignals = (child) => {
127+
const listeners = new Map();
128+
for (const sig of all_signals_js_1.allSignals) {
129+
const listener = () => {
130+
// some signals can only be received, not sent
131+
try {
132+
child.kill(sig);
133+
/* c8 ignore start */
134+
}
135+
catch (_) { }
136+
/* c8 ignore stop */
137+
};
138+
try {
139+
// if it's a signal this system doesn't recognize, skip it
140+
process.on(sig, listener);
141+
listeners.set(sig, listener);
142+
/* c8 ignore start */
143+
}
144+
catch (_) { }
145+
/* c8 ignore stop */
146+
}
147+
return () => {
148+
for (const [sig, listener] of listeners) {
149+
process.removeListener(sig, listener);
150+
}
151+
};
152+
};
153+
const isPromise = (o) => !!o && typeof o === 'object' && typeof o.then === 'function';
154+
//# sourceMappingURL=index.js.map
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"use strict";
2+
// this spawns a child process that listens for SIGHUP when the
3+
// parent process exits, and after 200ms, sends a SIGKILL to the
4+
// child, in case it did not terminate.
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.watchdog = void 0;
7+
const child_process_1 = require("child_process");
8+
const watchdogCode = String.raw `
9+
const pid = parseInt(process.argv[1], 10)
10+
process.title = 'node (foreground-child watchdog pid=' + pid + ')'
11+
if (!isNaN(pid)) {
12+
let barked = false
13+
// keepalive
14+
const interval = setInterval(() => {}, 60000)
15+
const bark = () => {
16+
clearInterval(interval)
17+
if (barked) return
18+
barked = true
19+
process.removeListener('SIGHUP', bark)
20+
setTimeout(() => {
21+
try {
22+
process.kill(pid, 'SIGKILL')
23+
setTimeout(() => process.exit(), 200)
24+
} catch (_) {}
25+
}, 500)
26+
})
27+
process.on('SIGHUP', bark)
28+
}
29+
`;
30+
const watchdog = (child) => {
31+
let dogExited = false;
32+
const dog = (0, child_process_1.spawn)(process.execPath, ['-e', watchdogCode, String(child.pid)], {
33+
stdio: 'ignore',
34+
});
35+
dog.on('exit', () => (dogExited = true));
36+
child.on('exit', () => {
37+
if (!dogExited)
38+
dog.kill('SIGTERM');
39+
});
40+
return dog;
41+
};
42+
exports.watchdog = watchdog;
43+
//# sourceMappingURL=watchdog.js.map
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import constants from 'node:constants';
2+
export const allSignals =
3+
// this is the full list of signals that Node will let us do anything with
4+
Object.keys(constants).filter(k => k.startsWith('SIG') &&
5+
// https://github.com/tapjs/signal-exit/issues/21
6+
k !== 'SIGPROF' &&
7+
// no sense trying to listen for SIGKILL, it's impossible
8+
k !== 'SIGKILL');
9+
// These are some obscure signals that are reported by kill -l
10+
// on macOS, Linux, or Windows, but which don't have any mapping
11+
// in Node.js. No sense trying if they're just going to throw
12+
// every time on every platform.
13+
//
14+
// 'SIGEMT',
15+
// 'SIGLOST',
16+
// 'SIGPOLL',
17+
// 'SIGRTMAX',
18+
// 'SIGRTMAX-1',
19+
// 'SIGRTMAX-10',
20+
// 'SIGRTMAX-11',
21+
// 'SIGRTMAX-12',
22+
// 'SIGRTMAX-13',
23+
// 'SIGRTMAX-14',
24+
// 'SIGRTMAX-15',
25+
// 'SIGRTMAX-2',
26+
// 'SIGRTMAX-3',
27+
// 'SIGRTMAX-4',
28+
// 'SIGRTMAX-5',
29+
// 'SIGRTMAX-6',
30+
// 'SIGRTMAX-7',
31+
// 'SIGRTMAX-8',
32+
// 'SIGRTMAX-9',
33+
// 'SIGRTMIN',
34+
// 'SIGRTMIN+1',
35+
// 'SIGRTMIN+10',
36+
// 'SIGRTMIN+11',
37+
// 'SIGRTMIN+12',
38+
// 'SIGRTMIN+13',
39+
// 'SIGRTMIN+14',
40+
// 'SIGRTMIN+15',
41+
// 'SIGRTMIN+16',
42+
// 'SIGRTMIN+2',
43+
// 'SIGRTMIN+3',
44+
// 'SIGRTMIN+4',
45+
// 'SIGRTMIN+5',
46+
// 'SIGRTMIN+6',
47+
// 'SIGRTMIN+7',
48+
// 'SIGRTMIN+8',
49+
// 'SIGRTMIN+9',
50+
// 'SIGSTKFLT',
51+
// 'SIGUNUSED',
52+
//# sourceMappingURL=all-signals.js.map

0 commit comments

Comments
 (0)