@intlayer/chokidar 7.0.3 → 7.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_virtual/_utils_asset.cjs +1 -1
- package/dist/cjs/index.cjs +4 -2
- package/dist/cjs/utils/runParallel/bin.cjs +55 -0
- package/dist/cjs/utils/runParallel/bin.cjs.map +1 -0
- package/dist/cjs/utils/runParallel/bootstrap.cjs +24 -0
- package/dist/cjs/utils/runParallel/bootstrap.cjs.map +1 -0
- package/dist/cjs/utils/runParallel/index.cjs +111 -0
- package/dist/cjs/utils/runParallel/index.cjs.map +1 -0
- package/dist/cjs/utils/runParallel/pidTree.cjs +145 -0
- package/dist/cjs/utils/runParallel/pidTree.cjs.map +1 -0
- package/dist/cjs/utils/runParallel/ps.cjs +49 -0
- package/dist/cjs/utils/runParallel/ps.cjs.map +1 -0
- package/dist/cjs/utils/runParallel/runTask.cjs +155 -0
- package/dist/cjs/utils/runParallel/runTask.cjs.map +1 -0
- package/dist/cjs/utils/runParallel/spawnPosix.cjs +60 -0
- package/dist/cjs/utils/runParallel/spawnPosix.cjs.map +1 -0
- package/dist/cjs/utils/runParallel/spawnWin32.cjs +44 -0
- package/dist/cjs/utils/runParallel/spawnWin32.cjs.map +1 -0
- package/dist/cjs/utils/runParallel/wmic.cjs +52 -0
- package/dist/cjs/utils/runParallel/wmic.cjs.map +1 -0
- package/dist/esm/_virtual/_utils_asset.mjs +1 -1
- package/dist/esm/index.mjs +3 -2
- package/dist/esm/utils/runParallel/bin.mjs +53 -0
- package/dist/esm/utils/runParallel/bin.mjs.map +1 -0
- package/dist/esm/utils/runParallel/bootstrap.mjs +23 -0
- package/dist/esm/utils/runParallel/bootstrap.mjs.map +1 -0
- package/dist/esm/utils/runParallel/index.mjs +109 -0
- package/dist/esm/utils/runParallel/index.mjs.map +1 -0
- package/dist/esm/utils/runParallel/pidTree.mjs +143 -0
- package/dist/esm/utils/runParallel/pidTree.mjs.map +1 -0
- package/dist/esm/utils/runParallel/ps.mjs +47 -0
- package/dist/esm/utils/runParallel/ps.mjs.map +1 -0
- package/dist/esm/utils/runParallel/runTask.mjs +153 -0
- package/dist/esm/utils/runParallel/runTask.mjs.map +1 -0
- package/dist/esm/utils/runParallel/spawnPosix.mjs +58 -0
- package/dist/esm/utils/runParallel/spawnPosix.mjs.map +1 -0
- package/dist/esm/utils/runParallel/spawnWin32.mjs +42 -0
- package/dist/esm/utils/runParallel/spawnWin32.mjs.map +1 -0
- package/dist/esm/utils/runParallel/wmic.mjs +50 -0
- package/dist/esm/utils/runParallel/wmic.mjs.map +1 -0
- package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts +2 -2
- package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts +3 -3
- package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts +3 -3
- package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts +2 -2
- package/dist/types/buildIntlayerDictionary/writeRemoteDictionary.d.ts +2 -2
- package/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts +2 -2
- package/dist/types/createDictionaryEntryPoint/generateDictionaryListContent.d.ts +2 -2
- package/dist/types/index.d.ts +3 -2
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +2 -2
- package/dist/types/utils/chunkJSON.d.ts.map +1 -1
- package/dist/types/utils/runParallel/bin.d.ts +15 -0
- package/dist/types/utils/runParallel/bin.d.ts.map +1 -0
- package/dist/types/utils/runParallel/bootstrap.d.ts +5 -0
- package/dist/types/utils/runParallel/bootstrap.d.ts.map +1 -0
- package/dist/types/utils/runParallel/index.d.ts +14 -0
- package/dist/types/utils/runParallel/index.d.ts.map +1 -0
- package/dist/types/utils/runParallel/pidTree.d.ts +24 -0
- package/dist/types/utils/runParallel/pidTree.d.ts.map +1 -0
- package/dist/types/utils/runParallel/ps.d.ts +11 -0
- package/dist/types/utils/runParallel/ps.d.ts.map +1 -0
- package/dist/types/utils/runParallel/runTask.d.ts +26 -0
- package/dist/types/utils/runParallel/runTask.d.ts.map +1 -0
- package/dist/types/utils/runParallel/spawnPosix.d.ts +21 -0
- package/dist/types/utils/runParallel/spawnPosix.d.ts.map +1 -0
- package/dist/types/utils/runParallel/spawnWin32.d.ts +21 -0
- package/dist/types/utils/runParallel/spawnWin32.d.ts.map +1 -0
- package/dist/types/utils/runParallel/wmic.d.ts +11 -0
- package/dist/types/utils/runParallel/wmic.d.ts.map +1 -0
- package/package.json +18 -18
|
@@ -64,7 +64,7 @@ const getCallerDir = () => {
|
|
|
64
64
|
* - './' or '../' is resolved relative to the *caller module's* emitted directory.
|
|
65
65
|
* - otherwise, treat as src-relative.
|
|
66
66
|
*
|
|
67
|
-
* @param {string} relPath - e.g. './PROMPT.md' or 'utils/AI/askDocQuestion/embeddings
|
|
67
|
+
* @param {string} relPath - e.g. './PROMPT.md' or 'utils/AI/askDocQuestion/embeddings/<fileKey>.json'
|
|
68
68
|
* @param {BufferEncoding} [encoding='utf8']
|
|
69
69
|
*/
|
|
70
70
|
const readAsset = (relPath, encoding = "utf8") => {
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -37,12 +37,13 @@ const require_utils_chunkJSON = require('./utils/chunkJSON.cjs');
|
|
|
37
37
|
const require_utils_getFormatFromExtension = require('./utils/getFormatFromExtension.cjs');
|
|
38
38
|
const require_utils_parallelizeGlobal = require('./utils/parallelizeGlobal.cjs');
|
|
39
39
|
const require_utils_reduceObjectFormat = require('./utils/reduceObjectFormat.cjs');
|
|
40
|
-
const
|
|
40
|
+
const require_utils_runParallel_index = require('./utils/runParallel/index.cjs');
|
|
41
41
|
const require_utils_verifyIdenticObjectFormat = require('./utils/verifyIdenticObjectFormat.cjs');
|
|
42
42
|
const require_watcher = require('./watcher.cjs');
|
|
43
43
|
const require_writeContentDeclaration_detectExportedComponentName = require('./writeContentDeclaration/detectExportedComponentName.cjs');
|
|
44
44
|
const require_writeContentDeclaration_transformJSFile = require('./writeContentDeclaration/transformJSFile.cjs');
|
|
45
45
|
const require_writeContentDeclaration_processContentDeclarationContent = require('./writeContentDeclaration/processContentDeclarationContent.cjs');
|
|
46
|
+
const require_writeContentDeclaration_detectFormatCommand = require('./writeContentDeclaration/detectFormatCommand.cjs');
|
|
46
47
|
const require_writeContentDeclaration_writeJSFile = require('./writeContentDeclaration/writeJSFile.cjs');
|
|
47
48
|
const require_writeContentDeclaration_writeContentDeclaration = require('./writeContentDeclaration/writeContentDeclaration.cjs');
|
|
48
49
|
|
|
@@ -55,6 +56,7 @@ exports.createDictionaryEntryPoint = require_createDictionaryEntryPoint_createDi
|
|
|
55
56
|
exports.createModuleAugmentation = require_createType_createModuleAugmentation.createModuleAugmentation;
|
|
56
57
|
exports.createTypes = require_createType_createType.createTypes;
|
|
57
58
|
exports.detectExportedComponentName = require_writeContentDeclaration_detectExportedComponentName.detectExportedComponentName;
|
|
59
|
+
exports.detectFormatCommand = require_writeContentDeclaration_detectFormatCommand.detectFormatCommand;
|
|
58
60
|
exports.fetchDistantDictionaries = require_fetchDistantDictionaries.fetchDistantDictionaries;
|
|
59
61
|
exports.formatLocale = require_utils_formatter.formatLocale;
|
|
60
62
|
exports.formatPath = require_utils_formatter.formatPath;
|
|
@@ -93,7 +95,7 @@ exports.reduceDictionaryContent = require_reduceDictionaryContent_reduceDictiona
|
|
|
93
95
|
exports.reduceObjectFormat = require_utils_reduceObjectFormat.reduceObjectFormat;
|
|
94
96
|
exports.resolveObjectPromises = require_utils_resolveObjectPromises.resolveObjectPromises;
|
|
95
97
|
exports.runOnce = require_utils_runOnce.runOnce;
|
|
96
|
-
exports.runParallel =
|
|
98
|
+
exports.runParallel = require_utils_runParallel_index.runParallel;
|
|
97
99
|
exports.sortAlphabetically = require_utils_sortAlphabetically.sortAlphabetically;
|
|
98
100
|
exports.splitTextByLines = require_utils_splitTextByLine.splitTextByLines;
|
|
99
101
|
exports.transformJSFile = require_writeContentDeclaration_transformJSFile.transformJSFile;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_child_process = require("node:child_process");
|
|
3
|
+
node_child_process = require_rolldown_runtime.__toESM(node_child_process);
|
|
4
|
+
|
|
5
|
+
//#region src/utils/runParallel/bin.ts
|
|
6
|
+
const stripStderr = (stderr) => {
|
|
7
|
+
if (!stderr) return;
|
|
8
|
+
let cleaned = stderr.trim();
|
|
9
|
+
cleaned = cleaned.replace(/your \d+x\d+ screen size is bogus\. expect trouble/gi, "");
|
|
10
|
+
return cleaned.trim() || void 0;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Spawn a binary and read its stdout.
|
|
14
|
+
* @param cmd The name of the binary to spawn.
|
|
15
|
+
* @param args The arguments for the binary.
|
|
16
|
+
* @param options Optional option for the spawn function.
|
|
17
|
+
* @param done Callback function.
|
|
18
|
+
*/
|
|
19
|
+
const run = (cmd, args, options, done) => {
|
|
20
|
+
let normalizedOptions;
|
|
21
|
+
let normalizedDone;
|
|
22
|
+
if (typeof options === "function") {
|
|
23
|
+
normalizedDone = options;
|
|
24
|
+
normalizedOptions = void 0;
|
|
25
|
+
} else {
|
|
26
|
+
normalizedDone = done;
|
|
27
|
+
normalizedOptions = options;
|
|
28
|
+
}
|
|
29
|
+
let executed = false;
|
|
30
|
+
const ch = (0, node_child_process.spawn)(cmd, args, normalizedOptions ?? {});
|
|
31
|
+
let stdout = "";
|
|
32
|
+
let stderr = "";
|
|
33
|
+
if (ch.stdout) ch.stdout.on("data", (d) => {
|
|
34
|
+
stdout += d.toString();
|
|
35
|
+
});
|
|
36
|
+
if (ch.stderr) ch.stderr.on("data", (d) => {
|
|
37
|
+
stderr += d.toString();
|
|
38
|
+
});
|
|
39
|
+
ch.on("error", (err) => {
|
|
40
|
+
if (executed) return;
|
|
41
|
+
executed = true;
|
|
42
|
+
normalizedDone(new Error(String(err)));
|
|
43
|
+
});
|
|
44
|
+
ch.on("close", (code) => {
|
|
45
|
+
if (executed) return;
|
|
46
|
+
executed = true;
|
|
47
|
+
const cleanedStderr = stripStderr(stderr);
|
|
48
|
+
if (cleanedStderr) return normalizedDone(new Error(cleanedStderr));
|
|
49
|
+
normalizedDone(null, stdout, code ?? void 0);
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
exports.run = run;
|
|
55
|
+
//# sourceMappingURL=bin.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.cjs","names":["normalizedOptions: SpawnOptions | undefined","normalizedDone: BinCallback","ch: ChildProcess"],"sources":["../../../../src/utils/runParallel/bin.ts"],"sourcesContent":["import type { ChildProcess } from 'node:child_process';\nimport { type SpawnOptions, spawn } from 'node:child_process';\n\ntype BinCallback = (err: Error | null, stdout?: string, code?: number) => void;\n\nconst stripStderr = (stderr: string | undefined): string | undefined => {\n if (!stderr) return;\n let cleaned = stderr.trim();\n // Strip bogus screen size error.\n // See https://github.com/microsoft/vscode/issues/98590\n const regex = /your \\d+x\\d+ screen size is bogus\\. expect trouble/gi;\n cleaned = cleaned.replace(regex, '');\n\n return cleaned.trim() || undefined;\n};\n\n/**\n * Spawn a binary and read its stdout.\n * @param cmd The name of the binary to spawn.\n * @param args The arguments for the binary.\n * @param options Optional option for the spawn function.\n * @param done Callback function.\n */\nexport const run = (\n cmd: string,\n args: string[],\n options: SpawnOptions | BinCallback | undefined,\n done?: BinCallback\n): void => {\n let normalizedOptions: SpawnOptions | undefined;\n let normalizedDone: BinCallback;\n\n if (typeof options === 'function') {\n normalizedDone = options;\n normalizedOptions = undefined;\n } else {\n normalizedDone = done!;\n normalizedOptions = options;\n }\n\n let executed = false;\n const ch: ChildProcess = spawn(cmd, args, normalizedOptions ?? {});\n let stdout = '';\n let stderr = '';\n\n if (ch.stdout) {\n ch.stdout.on('data', (d: Buffer) => {\n stdout += d.toString();\n });\n }\n\n if (ch.stderr) {\n ch.stderr.on('data', (d: Buffer) => {\n stderr += d.toString();\n });\n }\n\n ch.on('error', (err: Error) => {\n if (executed) return;\n executed = true;\n normalizedDone(new Error(String(err)));\n });\n\n ch.on('close', (code: number | null) => {\n if (executed) return;\n executed = true;\n\n const cleanedStderr = stripStderr(stderr);\n if (cleanedStderr) {\n return normalizedDone(new Error(cleanedStderr));\n }\n\n normalizedDone(null, stdout, code ?? undefined);\n });\n};\n"],"mappings":";;;;;AAKA,MAAM,eAAe,WAAmD;AACtE,KAAI,CAAC,OAAQ;CACb,IAAI,UAAU,OAAO,MAAM;AAI3B,WAAU,QAAQ,QADJ,wDACmB,GAAG;AAEpC,QAAO,QAAQ,MAAM,IAAI;;;;;;;;;AAU3B,MAAa,OACX,KACA,MACA,SACA,SACS;CACT,IAAIA;CACJ,IAAIC;AAEJ,KAAI,OAAO,YAAY,YAAY;AACjC,mBAAiB;AACjB,sBAAoB;QACf;AACL,mBAAiB;AACjB,sBAAoB;;CAGtB,IAAI,WAAW;CACf,MAAMC,mCAAyB,KAAK,MAAM,qBAAqB,EAAE,CAAC;CAClE,IAAI,SAAS;CACb,IAAI,SAAS;AAEb,KAAI,GAAG,OACL,IAAG,OAAO,GAAG,SAAS,MAAc;AAClC,YAAU,EAAE,UAAU;GACtB;AAGJ,KAAI,GAAG,OACL,IAAG,OAAO,GAAG,SAAS,MAAc;AAClC,YAAU,EAAE,UAAU;GACtB;AAGJ,IAAG,GAAG,UAAU,QAAe;AAC7B,MAAI,SAAU;AACd,aAAW;AACX,iBAAe,IAAI,MAAM,OAAO,IAAI,CAAC,CAAC;GACtC;AAEF,IAAG,GAAG,UAAU,SAAwB;AACtC,MAAI,SAAU;AACd,aAAW;EAEX,MAAM,gBAAgB,YAAY,OAAO;AACzC,MAAI,cACF,QAAO,eAAe,IAAI,MAAM,cAAc,CAAC;AAGjD,iBAAe,MAAM,QAAQ,QAAQ,OAAU;GAC/C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/runParallel/bootstrap.ts
|
|
3
|
+
const bootstrap = (_name) => {
|
|
4
|
+
switch (process.argv.slice(2)[0]) {
|
|
5
|
+
case void 0:
|
|
6
|
+
case "-h":
|
|
7
|
+
case "--help":
|
|
8
|
+
console.log("Help not implemented");
|
|
9
|
+
return;
|
|
10
|
+
case "-v":
|
|
11
|
+
case "--version":
|
|
12
|
+
console.log("Version not implemented");
|
|
13
|
+
return;
|
|
14
|
+
default:
|
|
15
|
+
process.stdout.setMaxListeners(0);
|
|
16
|
+
process.stderr.setMaxListeners(0);
|
|
17
|
+
process.stdin.setMaxListeners(0);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.bootstrap = bootstrap;
|
|
24
|
+
//# sourceMappingURL=bootstrap.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.cjs","names":[],"sources":["../../../../src/utils/runParallel/bootstrap.ts"],"sourcesContent":["//------------------------------------------------------------------------------\n// Public Interface\n//------------------------------------------------------------------------------\n\nexport const bootstrap = (_name: string): void | Promise<void> => {\n const argv = process.argv.slice(2);\n\n switch (argv[0]) {\n case undefined:\n case '-h':\n case '--help':\n // Not needed for our use case\n console.log('Help not implemented');\n return;\n\n case '-v':\n case '--version':\n // Not needed for our use case\n console.log('Version not implemented');\n return;\n\n default:\n // https://github.com/mysticatea/npm-run-all/issues/105\n // Avoid MaxListenersExceededWarnings.\n process.stdout.setMaxListeners(0);\n process.stderr.setMaxListeners(0);\n process.stdin.setMaxListeners(0);\n return;\n }\n};\n"],"mappings":";;AAIA,MAAa,aAAa,UAAwC;AAGhE,SAFa,QAAQ,KAAK,MAAM,EAAE,CAErB,IAAb;EACE,KAAK;EACL,KAAK;EACL,KAAK;AAEH,WAAQ,IAAI,uBAAuB;AACnC;EAEF,KAAK;EACL,KAAK;AAEH,WAAQ,IAAI,0BAA0B;AACtC;EAEF;AAGE,WAAQ,OAAO,gBAAgB,EAAE;AACjC,WAAQ,OAAO,gBAAgB,EAAE;AACjC,WAAQ,MAAM,gBAAgB,EAAE;AAChC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_utils_runParallel_spawnPosix = require('./spawnPosix.cjs');
|
|
3
|
+
const require_utils_runParallel_spawnWin32 = require('./spawnWin32.cjs');
|
|
4
|
+
let node_path = require("node:path");
|
|
5
|
+
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
6
|
+
|
|
7
|
+
//#region src/utils/runParallel/index.ts
|
|
8
|
+
/**
|
|
9
|
+
* Start a cross-platform parallel process using npm-run-all approach.
|
|
10
|
+
* Accepts either a single string (e.g., 'next start') or an array of tokens (e.g., ['next', 'start']).
|
|
11
|
+
*/
|
|
12
|
+
const runParallel = (proc) => {
|
|
13
|
+
if (!proc || Array.isArray(proc) && proc.length === 0) throw new Error("Invalid command");
|
|
14
|
+
const commandText = Array.isArray(proc) ? proc.join(" ") : proc;
|
|
15
|
+
const isArray = Array.isArray(proc);
|
|
16
|
+
const command = isArray ? proc[0] : commandText;
|
|
17
|
+
const args = isArray ? proc.slice(1) : [];
|
|
18
|
+
const cwdBin = (0, node_path.join)(process.cwd(), "node_modules", ".bin");
|
|
19
|
+
const PATH_KEY = Object.keys(process.env).find((key) => key.toLowerCase() === "path") ?? "PATH";
|
|
20
|
+
const extendedPath = [cwdBin, process.env[PATH_KEY] ?? ""].filter(Boolean).join(node_path.delimiter);
|
|
21
|
+
const childEnv = {
|
|
22
|
+
...process.env,
|
|
23
|
+
[PATH_KEY]: extendedPath
|
|
24
|
+
};
|
|
25
|
+
const isWin = process.platform === "win32";
|
|
26
|
+
const spawnFunc = isWin ? require_utils_runParallel_spawnWin32.spawnWin32 : require_utils_runParallel_spawnPosix.spawnPosix;
|
|
27
|
+
const spawnOptions = {
|
|
28
|
+
cwd: process.cwd(),
|
|
29
|
+
stdio: "inherit",
|
|
30
|
+
env: childEnv,
|
|
31
|
+
shell: false
|
|
32
|
+
};
|
|
33
|
+
const child = isArray ? args.length === 0 && /\s/.test(command) ? isWin ? spawnFunc(process.env.ComSpec ?? "cmd.exe", [
|
|
34
|
+
"/d",
|
|
35
|
+
"/s",
|
|
36
|
+
"/c",
|
|
37
|
+
command
|
|
38
|
+
], spawnOptions) : spawnFunc(process.env.SHELL ?? "/bin/sh", ["-c", command], spawnOptions) : spawnFunc(command, args, spawnOptions) : isWin ? spawnFunc(process.env.ComSpec ?? "cmd.exe", [
|
|
39
|
+
"/d",
|
|
40
|
+
"/s",
|
|
41
|
+
"/c",
|
|
42
|
+
commandText
|
|
43
|
+
], spawnOptions) : spawnFunc(process.env.SHELL ?? "/bin/sh", ["-c", commandText], spawnOptions);
|
|
44
|
+
const result = new Promise((resolve, reject) => {
|
|
45
|
+
child.on("error", (err) => {
|
|
46
|
+
try {
|
|
47
|
+
console.error(`[runParallel] Failed to start: ${err?.message ?? String(err)}`);
|
|
48
|
+
} catch {}
|
|
49
|
+
cleanupHandlers();
|
|
50
|
+
reject(err);
|
|
51
|
+
});
|
|
52
|
+
child.on("exit", (code, signal) => {
|
|
53
|
+
cleanupHandlers();
|
|
54
|
+
if (code === 0 || signal && [
|
|
55
|
+
"SIGINT",
|
|
56
|
+
"SIGTERM",
|
|
57
|
+
"SIGQUIT",
|
|
58
|
+
"SIGHUP"
|
|
59
|
+
].includes(signal)) resolve();
|
|
60
|
+
else reject(Object.assign(/* @__PURE__ */ new Error("Parallel process failed"), {
|
|
61
|
+
code,
|
|
62
|
+
signal
|
|
63
|
+
}));
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
const cleanup = () => {
|
|
67
|
+
try {
|
|
68
|
+
child.kill("SIGTERM");
|
|
69
|
+
} catch {}
|
|
70
|
+
};
|
|
71
|
+
const signalHandlers = [
|
|
72
|
+
{
|
|
73
|
+
event: "SIGINT",
|
|
74
|
+
handler: cleanup
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
event: "SIGTERM",
|
|
78
|
+
handler: cleanup
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
event: "SIGQUIT",
|
|
82
|
+
handler: cleanup
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
event: "SIGHUP",
|
|
86
|
+
handler: cleanup
|
|
87
|
+
}
|
|
88
|
+
];
|
|
89
|
+
signalHandlers.forEach(({ event, handler }) => {
|
|
90
|
+
process.on(event, handler);
|
|
91
|
+
});
|
|
92
|
+
const cleanupHandlers = () => {
|
|
93
|
+
signalHandlers.forEach(({ event, handler }) => {
|
|
94
|
+
process.off(event, handler);
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
const kill = () => {
|
|
98
|
+
try {
|
|
99
|
+
child.kill("SIGTERM");
|
|
100
|
+
} catch {}
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
kill,
|
|
104
|
+
result,
|
|
105
|
+
commandText
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
exports.runParallel = runParallel;
|
|
111
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["delimiter","spawnWin32","spawnPosix","signalHandlers: { event: string; handler: (...args: any[]) => void }[]"],"sources":["../../../../src/utils/runParallel/index.ts"],"sourcesContent":["import { delimiter, join } from 'node:path';\nimport { spawnPosix } from './spawnPosix';\nimport { spawnWin32 } from './spawnWin32';\n\nexport type ParallelHandle = {\n kill: () => void;\n result: Promise<any>;\n commandText: string;\n};\n\n/**\n * Start a cross-platform parallel process using npm-run-all approach.\n * Accepts either a single string (e.g., 'next start') or an array of tokens (e.g., ['next', 'start']).\n */\nexport const runParallel = (proc?: string | string[]): ParallelHandle => {\n if (!proc || (Array.isArray(proc) && proc.length === 0))\n throw new Error('Invalid command');\n\n const commandText = Array.isArray(proc) ? proc.join(' ') : proc;\n\n const isArray = Array.isArray(proc);\n const command = isArray ? (proc as string[])[0] : commandText;\n const args = isArray ? (proc as string[]).slice(1) : [];\n\n // Ensure local binaries (node_modules/.bin) are resolvable\n const cwdBin = join(process.cwd(), 'node_modules', '.bin');\n const PATH_KEY =\n Object.keys(process.env).find((key) => key.toLowerCase() === 'path') ??\n 'PATH';\n\n const extendedPath = [cwdBin, process.env[PATH_KEY] ?? '']\n .filter(Boolean)\n .join(delimiter);\n\n const childEnv = {\n ...process.env,\n [PATH_KEY]: extendedPath,\n } as NodeJS.ProcessEnv;\n\n const isWin = process.platform === 'win32';\n const spawnFunc = isWin ? spawnWin32 : spawnPosix;\n\n // Spawn options\n const spawnOptions = {\n cwd: process.cwd(),\n stdio: 'inherit' as const,\n env: childEnv,\n shell: false,\n };\n\n // Spawn the child process\n const child = isArray\n ? // If provided as a single string element that includes spaces, treat it like a shell command\n args.length === 0 && /\\s/.test(command)\n ? isWin\n ? spawnFunc(\n process.env.ComSpec ?? 'cmd.exe',\n ['/d', '/s', '/c', command],\n spawnOptions\n )\n : spawnFunc(\n process.env.SHELL ?? '/bin/sh',\n ['-c', command],\n spawnOptions\n )\n : spawnFunc(command, args, spawnOptions)\n : isWin\n ? spawnFunc(\n process.env.ComSpec ?? 'cmd.exe',\n ['/d', '/s', '/c', commandText],\n spawnOptions\n )\n : spawnFunc(\n process.env.SHELL ?? '/bin/sh',\n ['-c', commandText],\n spawnOptions\n );\n\n const result = new Promise<void>((resolve, reject) => {\n child.on('error', (err) => {\n try {\n console.error(\n `[runParallel] Failed to start: ${err?.message ?? String(err)}`\n );\n } catch {}\n cleanupHandlers();\n reject(err);\n });\n\n child.on('exit', (code, signal) => {\n cleanupHandlers();\n\n // Treat common termination signals as graceful exits, not failures\n const gracefulSignals = ['SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGHUP'];\n if (code === 0 || (signal && gracefulSignals.includes(signal))) {\n resolve();\n } else {\n reject(\n Object.assign(new Error('Parallel process failed'), { code, signal })\n );\n }\n });\n });\n\n const cleanup = () => {\n try {\n child.kill('SIGTERM');\n } catch {\n // Best effort\n }\n };\n\n const signalHandlers: { event: string; handler: (...args: any[]) => void }[] =\n [\n { event: 'SIGINT', handler: cleanup },\n { event: 'SIGTERM', handler: cleanup },\n { event: 'SIGQUIT', handler: cleanup },\n { event: 'SIGHUP', handler: cleanup },\n ];\n\n // Register signal handlers\n signalHandlers.forEach(({ event, handler }) => {\n process.on(event as any, handler as any);\n });\n\n const cleanupHandlers = () => {\n signalHandlers.forEach(({ event, handler }) => {\n process.off(event as any, handler as any);\n });\n };\n\n const kill = () => {\n try {\n child.kill('SIGTERM');\n } catch {\n // Best effort\n }\n };\n\n return { kill, result, commandText };\n};\n"],"mappings":";;;;;;;;;;;AAcA,MAAa,eAAe,SAA6C;AACvE,KAAI,CAAC,QAAS,MAAM,QAAQ,KAAK,IAAI,KAAK,WAAW,EACnD,OAAM,IAAI,MAAM,kBAAkB;CAEpC,MAAM,cAAc,MAAM,QAAQ,KAAK,GAAG,KAAK,KAAK,IAAI,GAAG;CAE3D,MAAM,UAAU,MAAM,QAAQ,KAAK;CACnC,MAAM,UAAU,UAAW,KAAkB,KAAK;CAClD,MAAM,OAAO,UAAW,KAAkB,MAAM,EAAE,GAAG,EAAE;CAGvD,MAAM,6BAAc,QAAQ,KAAK,EAAE,gBAAgB,OAAO;CAC1D,MAAM,WACJ,OAAO,KAAK,QAAQ,IAAI,CAAC,MAAM,QAAQ,IAAI,aAAa,KAAK,OAAO,IACpE;CAEF,MAAM,eAAe,CAAC,QAAQ,QAAQ,IAAI,aAAa,GAAG,CACvD,OAAO,QAAQ,CACf,KAAKA,oBAAU;CAElB,MAAM,WAAW;EACf,GAAG,QAAQ;GACV,WAAW;EACb;CAED,MAAM,QAAQ,QAAQ,aAAa;CACnC,MAAM,YAAY,QAAQC,kDAAaC;CAGvC,MAAM,eAAe;EACnB,KAAK,QAAQ,KAAK;EAClB,OAAO;EACP,KAAK;EACL,OAAO;EACR;CAGD,MAAM,QAAQ,UAEV,KAAK,WAAW,KAAK,KAAK,KAAK,QAAQ,GACrC,QACE,UACE,QAAQ,IAAI,WAAW,WACvB;EAAC;EAAM;EAAM;EAAM;EAAQ,EAC3B,aACD,GACD,UACE,QAAQ,IAAI,SAAS,WACrB,CAAC,MAAM,QAAQ,EACf,aACD,GACH,UAAU,SAAS,MAAM,aAAa,GACxC,QACE,UACE,QAAQ,IAAI,WAAW,WACvB;EAAC;EAAM;EAAM;EAAM;EAAY,EAC/B,aACD,GACD,UACE,QAAQ,IAAI,SAAS,WACrB,CAAC,MAAM,YAAY,EACnB,aACD;CAEP,MAAM,SAAS,IAAI,SAAe,SAAS,WAAW;AACpD,QAAM,GAAG,UAAU,QAAQ;AACzB,OAAI;AACF,YAAQ,MACN,kCAAkC,KAAK,WAAW,OAAO,IAAI,GAC9D;WACK;AACR,oBAAiB;AACjB,UAAO,IAAI;IACX;AAEF,QAAM,GAAG,SAAS,MAAM,WAAW;AACjC,oBAAiB;AAIjB,OAAI,SAAS,KAAM,UADK;IAAC;IAAU;IAAW;IAAW;IAAS,CACrB,SAAS,OAAO,CAC3D,UAAS;OAET,QACE,OAAO,uBAAO,IAAI,MAAM,0BAA0B,EAAE;IAAE;IAAM;IAAQ,CAAC,CACtE;IAEH;GACF;CAEF,MAAM,gBAAgB;AACpB,MAAI;AACF,SAAM,KAAK,UAAU;UACf;;CAKV,MAAMC,iBACJ;EACE;GAAE,OAAO;GAAU,SAAS;GAAS;EACrC;GAAE,OAAO;GAAW,SAAS;GAAS;EACtC;GAAE,OAAO;GAAW,SAAS;GAAS;EACtC;GAAE,OAAO;GAAU,SAAS;GAAS;EACtC;AAGH,gBAAe,SAAS,EAAE,OAAO,cAAc;AAC7C,UAAQ,GAAG,OAAc,QAAe;GACxC;CAEF,MAAM,wBAAwB;AAC5B,iBAAe,SAAS,EAAE,OAAO,cAAc;AAC7C,WAAQ,IAAI,OAAc,QAAe;IACzC;;CAGJ,MAAM,aAAa;AACjB,MAAI;AACF,SAAM,KAAK,UAAU;UACf;;AAKV,QAAO;EAAE;EAAM;EAAQ;EAAa"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_utils_runParallel_ps = require('./ps.cjs');
|
|
3
|
+
const require_utils_runParallel_wmic = require('./wmic.cjs');
|
|
4
|
+
let node_os = require("node:os");
|
|
5
|
+
node_os = require_rolldown_runtime.__toESM(node_os);
|
|
6
|
+
|
|
7
|
+
//#region src/utils/runParallel/pidTree.ts
|
|
8
|
+
const platformToMethod = {
|
|
9
|
+
darwin: "ps",
|
|
10
|
+
sunos: "ps",
|
|
11
|
+
freebsd: "ps",
|
|
12
|
+
netbsd: "ps",
|
|
13
|
+
win: "wmic",
|
|
14
|
+
linux: "ps",
|
|
15
|
+
aix: "ps"
|
|
16
|
+
};
|
|
17
|
+
const methodToFn = {
|
|
18
|
+
ps: require_utils_runParallel_ps.ps,
|
|
19
|
+
wmic: require_utils_runParallel_wmic.wmic
|
|
20
|
+
};
|
|
21
|
+
let platform = node_os.platform();
|
|
22
|
+
if (platform.startsWith("win")) platform = "win";
|
|
23
|
+
const method = platformToMethod[platform];
|
|
24
|
+
/**
|
|
25
|
+
* Gets the list of all the pids of the system.
|
|
26
|
+
*/
|
|
27
|
+
const getAll = (callback) => {
|
|
28
|
+
if (method === void 0) {
|
|
29
|
+
callback(/* @__PURE__ */ new Error(node_os.platform() + " is not supported yet, please open an issue (https://github.com/simonepri/pidtree)"), void 0);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const listFn = methodToFn[method];
|
|
33
|
+
listFn(callback);
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Get the list of children and grandchildren pids of the given PID.
|
|
37
|
+
* @param PID A PID. If -1 will return all the pids.
|
|
38
|
+
* @param options Optional options object.
|
|
39
|
+
* @param callback Called when the list is ready.
|
|
40
|
+
*/
|
|
41
|
+
const pidtree = (PID, options, callback) => {
|
|
42
|
+
let normalizedOptions;
|
|
43
|
+
let normalizedCallback;
|
|
44
|
+
if (typeof options === "function") {
|
|
45
|
+
normalizedCallback = options;
|
|
46
|
+
normalizedOptions = {};
|
|
47
|
+
} else {
|
|
48
|
+
normalizedCallback = callback;
|
|
49
|
+
normalizedOptions = typeof options === "object" ? options : {};
|
|
50
|
+
}
|
|
51
|
+
const parsedPID = parseInt(String(PID), 10);
|
|
52
|
+
if (Number.isNaN(parsedPID) || parsedPID < -1) {
|
|
53
|
+
normalizedCallback(/* @__PURE__ */ new TypeError("The pid provided is invalid"), void 0);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
getAll((err, processList) => {
|
|
57
|
+
if (err) {
|
|
58
|
+
normalizedCallback(err, void 0);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!processList) {
|
|
62
|
+
normalizedCallback(/* @__PURE__ */ new Error("Failed to get process list"), void 0);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (parsedPID === -1) {
|
|
66
|
+
const result = processList.map(([ppid, pid]) => normalizedOptions.advanced ? {
|
|
67
|
+
ppid,
|
|
68
|
+
pid
|
|
69
|
+
} : pid);
|
|
70
|
+
normalizedCallback(null, result);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
let root;
|
|
74
|
+
for (let l = 0; l < processList.length; l++) {
|
|
75
|
+
if (processList[l][1] === parsedPID) {
|
|
76
|
+
root = normalizedOptions.advanced ? {
|
|
77
|
+
ppid: processList[l][0],
|
|
78
|
+
pid: parsedPID
|
|
79
|
+
} : parsedPID;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
if (processList[l][0] === parsedPID) root = normalizedOptions.advanced ? { pid: parsedPID } : parsedPID;
|
|
83
|
+
}
|
|
84
|
+
if (root === void 0) {
|
|
85
|
+
normalizedCallback(/* @__PURE__ */ new Error("No matching pid found"), void 0);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const tree = {};
|
|
89
|
+
const listCopy = [...processList];
|
|
90
|
+
while (listCopy.length > 0) {
|
|
91
|
+
const element = listCopy.pop();
|
|
92
|
+
if (tree[element[0]]) tree[element[0]].push(element[1]);
|
|
93
|
+
else tree[element[0]] = [element[1]];
|
|
94
|
+
}
|
|
95
|
+
let idx = 0;
|
|
96
|
+
const pids = [root];
|
|
97
|
+
while (idx < pids.length) {
|
|
98
|
+
const curpid = normalizedOptions.advanced ? pids[idx++].pid : pids[idx++];
|
|
99
|
+
if (!tree[curpid]) continue;
|
|
100
|
+
const length = tree[curpid].length;
|
|
101
|
+
for (let j = 0; j < length; j++) pids.push(normalizedOptions.advanced ? {
|
|
102
|
+
ppid: curpid,
|
|
103
|
+
pid: tree[curpid][j]
|
|
104
|
+
} : tree[curpid][j]);
|
|
105
|
+
delete tree[curpid];
|
|
106
|
+
}
|
|
107
|
+
if (!normalizedOptions.root) pids.shift();
|
|
108
|
+
normalizedCallback(null, pids);
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
const pify = (fn, arg1, arg2) => {
|
|
112
|
+
return new Promise((resolve, reject) => {
|
|
113
|
+
fn(arg1, arg2, (err, data) => {
|
|
114
|
+
if (err) return reject(err);
|
|
115
|
+
if (data === void 0) return reject(/* @__PURE__ */ new Error("No data returned"));
|
|
116
|
+
resolve(data);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
/* istanbul ignore if */
|
|
121
|
+
if (!String.prototype.startsWith) String.prototype.startsWith = function(suffix) {
|
|
122
|
+
return this.substring(0, suffix.length) === suffix;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Get the list of children pids of the given pid.
|
|
126
|
+
* @param pid A PID. If -1 will return all the pids.
|
|
127
|
+
* @param options Optional options object.
|
|
128
|
+
* @param callback Called when the list is ready. If not provided a promise is returned instead.
|
|
129
|
+
* @returns Only when the callback is not provided.
|
|
130
|
+
*/
|
|
131
|
+
const list = (pid, options, callback) => {
|
|
132
|
+
if (typeof options === "function") {
|
|
133
|
+
pidtree(pid, void 0, options);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (typeof callback === "function") {
|
|
137
|
+
pidtree(pid, options, callback);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
return pify(pidtree, pid, options);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
//#endregion
|
|
144
|
+
exports.list = list;
|
|
145
|
+
//# sourceMappingURL=pidTree.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pidTree.cjs","names":["platformToMethod: Record<Platform, Method>","methodToFn: Record<Method, ProcessListFn>","platform: string","os","method: Method | undefined","normalizedOptions: ListOptions","normalizedCallback: ListCallback<T>","root: ProcessInfo | number | undefined","tree: Record<number, number[]>","pids: (ProcessInfo | number)[]"],"sources":["../../../../src/utils/runParallel/pidTree.ts"],"sourcesContent":["import * as os from 'node:os';\nimport { ps } from './ps';\nimport { wmic } from './wmic';\n\ntype Platform =\n | 'darwin'\n | 'sunos'\n | 'freebsd'\n | 'netbsd'\n | 'win'\n | 'linux'\n | 'aix';\ntype Method = 'ps' | 'wmic';\n\ntype ProcessList = [number, number][]; // [PPID, PID][]\n\ninterface ListOptions {\n root?: boolean;\n advanced?: boolean;\n}\n\ntype ProcessInfo = { pid: number; ppid?: number };\ntype ResultType<T extends ListOptions | undefined> = T extends {\n advanced: true;\n}\n ? ProcessInfo[]\n : number[];\n\ntype ProcessListCallback = (err: Error | null, list?: ProcessList) => void;\ntype ListCallback<T extends ListOptions | undefined> = (\n err: Error | null,\n list?: ResultType<T>\n) => void;\n\ntype ProcessListFn = (callback: ProcessListCallback) => void;\n\nconst platformToMethod: Record<Platform, Method> = {\n darwin: 'ps',\n sunos: 'ps',\n freebsd: 'ps',\n netbsd: 'ps',\n win: 'wmic',\n linux: 'ps',\n aix: 'ps',\n};\n\nconst methodToFn: Record<Method, ProcessListFn> = {\n ps,\n wmic,\n};\n\nlet platform: string = os.platform();\nif (platform.startsWith('win')) {\n platform = 'win';\n}\n\nconst method: Method | undefined = platformToMethod[platform as Platform];\n\n/**\n * Gets the list of all the pids of the system.\n */\nconst getAll = (callback: ProcessListCallback): void => {\n if (method === undefined) {\n callback(\n new Error(\n os.platform() +\n ' is not supported yet, please open an issue (https://github.com/simonepri/pidtree)'\n ),\n undefined\n );\n return;\n }\n\n const listFn = methodToFn[method];\n listFn(callback);\n};\n\n/**\n * Get the list of children and grandchildren pids of the given PID.\n * @param PID A PID. If -1 will return all the pids.\n * @param options Optional options object.\n * @param callback Called when the list is ready.\n */\nconst pidtree = <T extends ListOptions | undefined>(\n PID: number | string,\n options: T | ListCallback<T> | undefined,\n callback?: ListCallback<T>\n): void => {\n let normalizedOptions: ListOptions;\n let normalizedCallback: ListCallback<T>;\n\n if (typeof options === 'function') {\n normalizedCallback = options;\n normalizedOptions = {};\n } else {\n normalizedCallback = callback!;\n normalizedOptions = typeof options === 'object' ? options : {};\n }\n\n const parsedPID = parseInt(String(PID), 10);\n if (Number.isNaN(parsedPID) || parsedPID < -1) {\n normalizedCallback(\n new TypeError('The pid provided is invalid') as Error,\n undefined\n );\n return;\n }\n\n getAll((err, processList) => {\n if (err) {\n normalizedCallback(err, undefined);\n return;\n }\n\n if (!processList) {\n normalizedCallback(new Error('Failed to get process list'), undefined);\n return;\n }\n\n // If the user wants the whole list just return it\n if (parsedPID === -1) {\n const result = processList.map(([ppid, pid]) =>\n normalizedOptions.advanced ? { ppid, pid } : pid\n ) as ResultType<T>;\n\n normalizedCallback(null, result);\n return;\n }\n\n let root: ProcessInfo | number | undefined;\n for (let l = 0; l < processList.length; l++) {\n if (processList[l][1] === parsedPID) {\n root = normalizedOptions.advanced\n ? { ppid: processList[l][0], pid: parsedPID }\n : parsedPID;\n break;\n }\n\n if (processList[l][0] === parsedPID) {\n root = normalizedOptions.advanced ? { pid: parsedPID } : parsedPID; // Special pids like 0 on *nix\n }\n }\n\n if (root === undefined) {\n normalizedCallback(new Error('No matching pid found'), undefined);\n return;\n }\n\n // Build the adjacency Hash Map (pid -> [children of pid])\n const tree: Record<number, number[]> = {};\n const listCopy = [...processList];\n while (listCopy.length > 0) {\n const element = listCopy.pop()!;\n if (tree[element[0]]) {\n tree[element[0]].push(element[1]);\n } else {\n tree[element[0]] = [element[1]];\n }\n }\n\n // Starting by the PID provided by the user, traverse the tree using the\n // adjacency Hash Map until the whole subtree is visited.\n // Each pid encountered while visiting is added to the pids array.\n let idx = 0;\n const pids: (ProcessInfo | number)[] = [root];\n while (idx < pids.length) {\n const curpid = normalizedOptions.advanced\n ? (pids[idx++] as ProcessInfo).pid\n : (pids[idx++] as number);\n if (!tree[curpid]) continue;\n const length = tree[curpid].length;\n for (let j = 0; j < length; j++) {\n pids.push(\n normalizedOptions.advanced\n ? { ppid: curpid, pid: tree[curpid][j] }\n : tree[curpid][j]\n );\n }\n\n delete tree[curpid];\n }\n\n if (!normalizedOptions.root) {\n pids.shift(); // Remove root\n }\n\n normalizedCallback(null, pids as ResultType<T>);\n });\n};\n\nconst pify = <T extends ListOptions | undefined>(\n fn: typeof pidtree,\n arg1: number | string,\n arg2: T | undefined\n): Promise<ResultType<T>> => {\n return new Promise((resolve, reject) => {\n fn(arg1, arg2, (err, data) => {\n if (err) return reject(err);\n if (data === undefined) {\n return reject(new Error('No data returned'));\n }\n resolve(data);\n });\n });\n};\n\n// Node versions prior to 4.0.0 do not define have `startsWith`.\n/* istanbul ignore if */\nif (!String.prototype.startsWith) {\n String.prototype.startsWith = function (suffix: string): boolean {\n return this.substring(0, suffix.length) === suffix;\n };\n}\n\n/**\n * Get the list of children pids of the given pid.\n * @param pid A PID. If -1 will return all the pids.\n * @param options Optional options object.\n * @param callback Called when the list is ready. If not provided a promise is returned instead.\n * @returns Only when the callback is not provided.\n */\nexport const list = <T extends ListOptions | undefined>(\n pid: number | string,\n options?: T | ListCallback<T>,\n callback?: ListCallback<T>\n): Promise<ResultType<T>> | undefined => {\n if (typeof options === 'function') {\n pidtree(pid, undefined, options);\n return;\n }\n\n if (typeof callback === 'function') {\n pidtree(pid, options, callback);\n return;\n }\n\n return pify(pidtree, pid, options);\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_utils_runParallel_bin = require('./bin.cjs');
|
|
3
|
+
let node_os = require("node:os");
|
|
4
|
+
node_os = require_rolldown_runtime.__toESM(node_os);
|
|
5
|
+
|
|
6
|
+
//#region src/utils/runParallel/ps.ts
|
|
7
|
+
/**
|
|
8
|
+
* Gets the list of all the pids of the system through the ps command.
|
|
9
|
+
* @param callback Callback function with error and process list.
|
|
10
|
+
*/
|
|
11
|
+
const ps = (callback) => {
|
|
12
|
+
require_utils_runParallel_bin.run("ps", [
|
|
13
|
+
"-A",
|
|
14
|
+
"-o",
|
|
15
|
+
"ppid,pid"
|
|
16
|
+
], (err, stdout, code) => {
|
|
17
|
+
if (err) {
|
|
18
|
+
callback(err);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (code !== 0) {
|
|
22
|
+
callback(/* @__PURE__ */ new Error(`pidtree ps command exited with code ${code}`));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!stdout) {
|
|
26
|
+
callback(/* @__PURE__ */ new Error("No stdout received from ps command"));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
const lines = stdout.split(node_os.EOL);
|
|
31
|
+
const list = [];
|
|
32
|
+
for (let i = 1; i < lines.length; i++) {
|
|
33
|
+
const trimmed = lines[i].trim();
|
|
34
|
+
if (!trimmed) continue;
|
|
35
|
+
const parts = trimmed.split(/\s+/);
|
|
36
|
+
const ppid = parseInt(parts[0], 10);
|
|
37
|
+
const pid = parseInt(parts[1], 10);
|
|
38
|
+
if (!Number.isNaN(ppid) && !Number.isNaN(pid)) list.push([ppid, pid]);
|
|
39
|
+
}
|
|
40
|
+
callback(null, list);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
callback(error instanceof Error ? error : new Error(String(error)));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
exports.ps = ps;
|
|
49
|
+
//# sourceMappingURL=ps.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ps.cjs","names":["os","list: ProcessList"],"sources":["../../../../src/utils/runParallel/ps.ts"],"sourcesContent":["import * as os from 'node:os';\nimport { run } from './bin';\n\ntype ProcessList = [number, number][]; // [PPID, PID][]\ntype ProcessListCallback = (err: Error | null, list?: ProcessList) => void;\n\n/**\n * Gets the list of all the pids of the system through the ps command.\n * @param callback Callback function with error and process list.\n */\nexport const ps = (callback: ProcessListCallback): void => {\n const args = ['-A', '-o', 'ppid,pid'];\n\n run('ps', args, (err, stdout, code) => {\n if (err) {\n callback(err);\n return;\n }\n if (code !== 0) {\n callback(new Error(`pidtree ps command exited with code ${code}`));\n return;\n }\n\n // Example of stdout\n //\n // PPID PID\n // 1 430\n // 430 432\n // 1 727\n // 1 7166\n\n if (!stdout) {\n callback(new Error('No stdout received from ps command'));\n return;\n }\n\n try {\n const lines = stdout.split(os.EOL);\n\n const list: ProcessList = [];\n for (let i = 1; i < lines.length; i++) {\n const trimmed = lines[i].trim();\n if (!trimmed) continue;\n const parts = trimmed.split(/\\s+/);\n const ppid = parseInt(parts[0], 10); // PPID\n const pid = parseInt(parts[1], 10); // PID\n if (!Number.isNaN(ppid) && !Number.isNaN(pid)) {\n list.push([ppid, pid]);\n }\n }\n\n callback(null, list);\n } catch (error) {\n callback(error instanceof Error ? error : new Error(String(error)));\n }\n });\n};\n"],"mappings":";;;;;;;;;;AAUA,MAAa,MAAM,aAAwC;AAGzD,mCAAI,MAFS;EAAC;EAAM;EAAM;EAAW,GAEpB,KAAK,QAAQ,SAAS;AACrC,MAAI,KAAK;AACP,YAAS,IAAI;AACb;;AAEF,MAAI,SAAS,GAAG;AACd,4BAAS,IAAI,MAAM,uCAAuC,OAAO,CAAC;AAClE;;AAWF,MAAI,CAAC,QAAQ;AACX,4BAAS,IAAI,MAAM,qCAAqC,CAAC;AACzD;;AAGF,MAAI;GACF,MAAM,QAAQ,OAAO,MAAMA,QAAG,IAAI;GAElC,MAAMC,OAAoB,EAAE;AAC5B,QAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;IACrC,MAAM,UAAU,MAAM,GAAG,MAAM;AAC/B,QAAI,CAAC,QAAS;IACd,MAAM,QAAQ,QAAQ,MAAM,MAAM;IAClC,MAAM,OAAO,SAAS,MAAM,IAAI,GAAG;IACnC,MAAM,MAAM,SAAS,MAAM,IAAI,GAAG;AAClC,QAAI,CAAC,OAAO,MAAM,KAAK,IAAI,CAAC,OAAO,MAAM,IAAI,CAC3C,MAAK,KAAK,CAAC,MAAM,IAAI,CAAC;;AAI1B,YAAS,MAAM,KAAK;WACb,OAAO;AACd,YAAS,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC,CAAC;;GAErE"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_stream = require("node:stream");
|
|
3
|
+
node_stream = require_rolldown_runtime.__toESM(node_stream);
|
|
4
|
+
|
|
5
|
+
//#region src/utils/runParallel/runTask.ts
|
|
6
|
+
/**
|
|
7
|
+
* Remove the given value from the array.
|
|
8
|
+
*/
|
|
9
|
+
const remove = (array, x) => {
|
|
10
|
+
const index = array.indexOf(x);
|
|
11
|
+
if (index !== -1) array.splice(index, 1);
|
|
12
|
+
};
|
|
13
|
+
const signals = {
|
|
14
|
+
SIGABRT: 6,
|
|
15
|
+
SIGALRM: 14,
|
|
16
|
+
SIGBUS: 10,
|
|
17
|
+
SIGCHLD: 20,
|
|
18
|
+
SIGCONT: 19,
|
|
19
|
+
SIGFPE: 8,
|
|
20
|
+
SIGHUP: 1,
|
|
21
|
+
SIGILL: 4,
|
|
22
|
+
SIGINT: 2,
|
|
23
|
+
SIGKILL: 9,
|
|
24
|
+
SIGPIPE: 13,
|
|
25
|
+
SIGQUIT: 3,
|
|
26
|
+
SIGSEGV: 11,
|
|
27
|
+
SIGSTOP: 17,
|
|
28
|
+
SIGTERM: 15,
|
|
29
|
+
SIGTRAP: 5,
|
|
30
|
+
SIGTSTP: 18,
|
|
31
|
+
SIGTTIN: 21,
|
|
32
|
+
SIGTTOU: 22,
|
|
33
|
+
SIGUSR1: 30,
|
|
34
|
+
SIGUSR2: 31
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Converts a signal name to a number.
|
|
38
|
+
*/
|
|
39
|
+
const convert = (signal) => {
|
|
40
|
+
return signals[signal] || 0;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Simple in-memory writable stream
|
|
44
|
+
*/
|
|
45
|
+
var MemoryStream = class extends node_stream.Writable {
|
|
46
|
+
chunks = [];
|
|
47
|
+
_write(chunk, _encoding, callback) {
|
|
48
|
+
this.chunks.push(chunk);
|
|
49
|
+
callback();
|
|
50
|
+
}
|
|
51
|
+
toString() {
|
|
52
|
+
return Buffer.concat(this.chunks).toString("utf8");
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Run npm-scripts of given names in parallel.
|
|
57
|
+
*
|
|
58
|
+
* If a npm-script exited with a non-zero code, this aborts other all npm-scripts.
|
|
59
|
+
*
|
|
60
|
+
* Note: This is a simplified version for our use case.
|
|
61
|
+
* The full implementation would require the actual runTask function from npm-run-all.
|
|
62
|
+
*/
|
|
63
|
+
const runTasks = (tasks, options) => {
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
if (tasks.length === 0) {
|
|
66
|
+
resolve([]);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const results = tasks.map((task) => ({
|
|
70
|
+
name: task,
|
|
71
|
+
code: void 0
|
|
72
|
+
}));
|
|
73
|
+
const queue = tasks.map((task, index) => ({
|
|
74
|
+
name: task,
|
|
75
|
+
index
|
|
76
|
+
}));
|
|
77
|
+
const promises = [];
|
|
78
|
+
let error = null;
|
|
79
|
+
let aborted = false;
|
|
80
|
+
/**
|
|
81
|
+
* Done.
|
|
82
|
+
*/
|
|
83
|
+
const done = () => {
|
|
84
|
+
if (error == null) resolve(results);
|
|
85
|
+
else reject(error);
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Aborts all tasks.
|
|
89
|
+
*/
|
|
90
|
+
const abort = () => {
|
|
91
|
+
if (aborted) return;
|
|
92
|
+
aborted = true;
|
|
93
|
+
if (promises.length === 0) done();
|
|
94
|
+
else {
|
|
95
|
+
for (const p of promises) p.abort?.();
|
|
96
|
+
Promise.all(promises).then(done, reject);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Runs a next task.
|
|
101
|
+
*/
|
|
102
|
+
const next = () => {
|
|
103
|
+
if (aborted) return;
|
|
104
|
+
if (queue.length === 0) {
|
|
105
|
+
if (promises.length === 0) done();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const originalOutputStream = options.stdout;
|
|
109
|
+
const optionsClone = { ...options };
|
|
110
|
+
const writer = new MemoryStream();
|
|
111
|
+
if (options.aggregateOutput) optionsClone.stdout = writer;
|
|
112
|
+
const task = queue.shift();
|
|
113
|
+
const promise = Promise.resolve({
|
|
114
|
+
name: task.name,
|
|
115
|
+
code: 0,
|
|
116
|
+
signal: null
|
|
117
|
+
});
|
|
118
|
+
promises.push(promise);
|
|
119
|
+
promise.then((result) => {
|
|
120
|
+
remove(promises, promise);
|
|
121
|
+
if (aborted) return;
|
|
122
|
+
if (options.aggregateOutput) originalOutputStream.write(writer.toString());
|
|
123
|
+
if (result.code === null && result.signal !== null && result.signal !== void 0) result.code = 128 + convert(result.signal);
|
|
124
|
+
results[task.index].code = result.code;
|
|
125
|
+
if (result.code) {
|
|
126
|
+
error = /* @__PURE__ */ new Error(`Task ${result.name} failed with code ${result.code}`);
|
|
127
|
+
if (!options.continueOnError) {
|
|
128
|
+
abort();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (options.race && !result.code) {
|
|
133
|
+
abort();
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
next();
|
|
137
|
+
}, (thisError) => {
|
|
138
|
+
remove(promises, promise);
|
|
139
|
+
if (!options.continueOnError || options.race) {
|
|
140
|
+
error = thisError;
|
|
141
|
+
abort();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
next();
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
const max = options.maxParallel;
|
|
148
|
+
const end = typeof max === "number" && max > 0 ? Math.min(tasks.length, max) : tasks.length;
|
|
149
|
+
for (let i = 0; i < end; ++i) next();
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
//#endregion
|
|
154
|
+
exports.runTasks = runTasks;
|
|
155
|
+
//# sourceMappingURL=runTask.cjs.map
|