ccjk 12.0.0 → 12.0.2
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/chunks/agent-teams.mjs +17 -18
- package/dist/chunks/agent.mjs +105 -102
- package/dist/chunks/agents.mjs +87 -77
- package/dist/chunks/api-cli.mjs +41 -27
- package/dist/chunks/api-providers.mjs +2 -4
- package/dist/chunks/api.mjs +22 -11
- package/dist/chunks/auto-bootstrap.mjs +3 -5
- package/dist/chunks/auto-init.mjs +3 -4
- package/dist/chunks/auto-updater.mjs +103 -91
- package/dist/chunks/banner.mjs +41 -42
- package/dist/chunks/boost.mjs +30 -31
- package/dist/chunks/ccjk-agents.mjs +6 -9
- package/dist/chunks/ccjk-all.mjs +703 -85
- package/dist/chunks/ccjk-config.mjs +6 -6
- package/dist/chunks/ccjk-hooks.mjs +20 -9
- package/dist/chunks/ccjk-mcp.mjs +64 -52
- package/dist/chunks/ccjk-setup.mjs +35 -25
- package/dist/chunks/ccjk-skills.mjs +51 -41
- package/dist/chunks/ccr.mjs +42 -32
- package/dist/chunks/ccu.mjs +16 -12
- package/dist/chunks/check-updates.mjs +30 -19
- package/dist/chunks/claude-code-config-manager.mjs +25 -10
- package/dist/chunks/claude-code-incremental-manager.mjs +65 -51
- package/dist/chunks/claude-config.mjs +2 -2
- package/dist/chunks/claude-wrapper.mjs +9 -6
- package/dist/chunks/cleanup-migration.mjs +1 -1
- package/dist/chunks/cli-hook.mjs +10 -3
- package/dist/chunks/cloud-sync.mjs +1 -1
- package/dist/chunks/codex-config-switch.mjs +58 -45
- package/dist/chunks/codex-provider-manager.mjs +29 -16
- package/dist/chunks/codex-uninstaller.mjs +5 -6
- package/dist/chunks/codex.mjs +89 -89
- package/dist/chunks/commands.mjs +28 -29
- package/dist/chunks/commands2.mjs +4 -3
- package/dist/chunks/commit.mjs +42 -23
- package/dist/chunks/completion.mjs +46 -47
- package/dist/chunks/config-consolidator.mjs +12 -13
- package/dist/chunks/config-switch.mjs +66 -53
- package/dist/chunks/config.mjs +10 -10
- package/dist/chunks/config2.mjs +53 -42
- package/dist/chunks/config3.mjs +107 -93
- package/dist/chunks/constants.mjs +2 -4
- package/dist/chunks/context-loader.mjs +5 -4
- package/dist/chunks/context.mjs +77 -76
- package/dist/chunks/convoy-manager.mjs +4 -4
- package/dist/chunks/dashboard.mjs +28 -29
- package/dist/chunks/doctor.mjs +68 -54
- package/dist/chunks/evolution.mjs +37 -38
- package/dist/chunks/features.mjs +103 -92
- package/dist/chunks/fs-operations.mjs +1 -1
- package/dist/chunks/health-alerts.mjs +1 -1
- package/dist/chunks/health-check.mjs +1 -1
- package/dist/chunks/help.mjs +117 -116
- package/dist/chunks/hook-installer.mjs +3 -2
- package/dist/chunks/index.mjs +20 -6
- package/dist/chunks/index10.mjs +1171 -0
- package/dist/chunks/index11.mjs +1008 -0
- package/dist/chunks/index12.mjs +193 -0
- package/dist/chunks/index13.mjs +218 -0
- package/dist/chunks/index14.mjs +663 -0
- package/dist/chunks/index2.mjs +19 -10
- package/dist/chunks/index3.mjs +19079 -164
- package/dist/chunks/index4.mjs +8 -1171
- package/dist/chunks/index5.mjs +7479 -884
- package/dist/chunks/index6.mjs +160 -184
- package/dist/chunks/index7.mjs +3573 -653
- package/dist/chunks/index8.mjs +19 -0
- package/dist/chunks/index9.mjs +616 -0
- package/dist/chunks/init.mjs +173 -173
- package/dist/chunks/installer.mjs +92 -82
- package/dist/chunks/installer2.mjs +3 -2
- package/dist/chunks/interview.mjs +118 -107
- package/dist/chunks/json-config.mjs +3 -2
- package/dist/chunks/linux.mjs +3863 -0
- package/dist/chunks/macos.mjs +69 -0
- package/dist/chunks/main.mjs +635 -0
- package/dist/chunks/marketplace.mjs +69 -66
- package/dist/chunks/mcp-cli.mjs +61 -48
- package/dist/chunks/mcp.mjs +140 -127
- package/dist/chunks/menu.mjs +85 -85
- package/dist/chunks/metrics-display.mjs +41 -40
- package/dist/chunks/migrator.mjs +4 -5
- package/dist/chunks/monitor.mjs +95 -95
- package/dist/chunks/notification.mjs +151 -141
- package/dist/chunks/onboarding.mjs +26 -15
- package/dist/chunks/package.mjs +1 -1
- package/dist/chunks/paradigm.mjs +24 -23
- package/dist/chunks/permission-manager.mjs +10 -11
- package/dist/chunks/permissions.mjs +72 -57
- package/dist/chunks/persistence-manager.mjs +97 -84
- package/dist/chunks/persistence.mjs +1 -1
- package/dist/chunks/platform.mjs +29 -29
- package/dist/chunks/plugin.mjs +104 -105
- package/dist/chunks/prompts.mjs +36 -25
- package/dist/chunks/providers.mjs +68 -69
- package/dist/chunks/quick-actions.mjs +71 -72
- package/dist/chunks/quick-provider.mjs +56 -40
- package/dist/chunks/quick-setup.mjs +71 -60
- package/dist/chunks/remote.mjs +21 -12
- package/dist/chunks/session.mjs +116 -103
- package/dist/chunks/sessions.mjs +29 -28
- package/dist/chunks/silent-updater.mjs +8 -10
- package/dist/chunks/simple-config.mjs +13 -10
- package/dist/chunks/skill.mjs +8560 -103
- package/dist/chunks/skills-sync.mjs +5212 -79
- package/dist/chunks/skills.mjs +105 -94
- package/dist/chunks/slash-commands.mjs +36 -37
- package/dist/chunks/smart-defaults.mjs +7 -3
- package/dist/chunks/smart-guide.mjs +1 -1
- package/dist/chunks/startup.mjs +2 -4
- package/dist/chunks/stats.mjs +41 -42
- package/dist/chunks/status.mjs +49 -50
- package/dist/chunks/team.mjs +24 -12
- package/dist/chunks/thinking.mjs +74 -63
- package/dist/chunks/trace.mjs +20 -19
- package/dist/chunks/uninstall.mjs +69 -56
- package/dist/chunks/update.mjs +39 -28
- package/dist/chunks/upgrade-manager.mjs +24 -18
- package/dist/chunks/version-checker.mjs +45 -41
- package/dist/chunks/vim.mjs +81 -69
- package/dist/chunks/windows.mjs +14 -0
- package/dist/chunks/workflows.mjs +15 -15
- package/dist/chunks/wsl.mjs +129 -0
- package/dist/chunks/zero-config.mjs +45 -34
- package/dist/cli.mjs +20 -20
- package/dist/index.mjs +41 -31
- package/dist/shared/ccjk.BAGoDD49.mjs +36 -0
- package/dist/shared/ccjk.BBtCGd_g.mjs +899 -0
- package/dist/shared/{ccjk.CGcy7cNM.mjs → ccjk.BDKUdmLk.mjs} +1 -1
- package/dist/shared/{ccjk.DtMBiwVG.mjs → ccjk.BFxsJM0k.mjs} +1 -1
- package/dist/shared/{ccjk.j4uut26D.mjs → ccjk.BIxuVL3_.mjs} +5 -5
- package/dist/shared/ccjk.BRZ9ww8S.mjs +142 -0
- package/dist/shared/{ccjk.CN0edl87.mjs → ccjk.BSYWk9ML.mjs} +1 -1
- package/dist/shared/{ccjk.Dk1HDseQ.mjs → ccjk.BnpWvs9V.mjs} +75 -75
- package/dist/shared/ccjk.BoApaI4j.mjs +28 -0
- package/dist/shared/{ccjk.DKojSRzw.mjs → ccjk.BrPUmTqm.mjs} +1 -1
- package/dist/shared/{ccjk.C10pepYx.mjs → ccjk.BxSmJ8B7.mjs} +1 -1
- package/dist/shared/ccjk.Bx_rmYfN.mjs +69 -0
- package/dist/shared/ccjk.COweQ1RR.mjs +5 -0
- package/dist/shared/{ccjk.BN90X6oc.mjs → ccjk.CePkJq2S.mjs} +17 -17
- package/dist/shared/{ccjk.Bvoex4TZ.mjs → ccjk.CfKKcvWy.mjs} +1 -1
- package/dist/shared/ccjk.Cjgrln_h.mjs +297 -0
- package/dist/shared/ccjk.CxpGa6MC.mjs +2724 -0
- package/dist/shared/{ccjk.DfwJOEok.mjs → ccjk.D5MFQT7w.mjs} +1 -1
- package/dist/shared/{ccjk.cChAaGgT.mjs → ccjk.DG_o24cZ.mjs} +6 -6
- package/dist/shared/{ccjk.bhFAMRyc.mjs → ccjk.DLLw-h4Y.mjs} +32 -32
- package/dist/shared/ccjk.DOwtZMk8.mjs +4019 -0
- package/dist/shared/{ccjk.BsXQugfY.mjs → ccjk.DTdjs-qK.mjs} +13 -13
- package/dist/shared/{ccjk.Bdhyg3X-.mjs → ccjk.DsYaCCx4.mjs} +1 -1
- package/dist/shared/ccjk.KfSWcGlE.mjs +38 -0
- package/dist/shared/ccjk.RyizuzOI.mjs +21 -0
- package/dist/shared/{ccjk.h7_W-wTs.mjs → ccjk.SPoXMvZD.mjs} +1 -1
- package/dist/shared/ccjk.T_cX87dY.mjs +15 -0
- package/dist/shared/{ccjk.CrB6OYHv.mjs → ccjk._dESH4Rk.mjs} +2 -2
- package/dist/shared/ccjk.bQ7Dh1g4.mjs +249 -0
- package/dist/shared/{ccjk.CBhIZiPz.mjs → ccjk.hoqrwWdN.mjs} +1 -1
- package/dist/shared/{ccjk.BNwRnWYx.mjs → ccjk.s7OCVzdd.mjs} +1230 -33
- package/dist/shared/{ccjk.BOIUTf5z.mjs → ccjk.waa2ikKJ.mjs} +8 -9
- package/package.json +31 -30
- package/dist/shared/ccjk.DHbrGcgg.mjs +0 -13
- package/dist/shared/ccjk.DntgA8fQ.mjs +0 -42
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import process__default from 'node:process';
|
|
2
|
+
import path__default from 'node:path';
|
|
3
|
+
import fs__default, { promises } from 'node:fs';
|
|
4
|
+
|
|
5
|
+
const resolvePath = (cwd, sourcePath, destinationPath) => {
|
|
6
|
+
sourcePath = path__default.resolve(cwd, sourcePath);
|
|
7
|
+
destinationPath = path__default.resolve(cwd, destinationPath);
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
sourcePath,
|
|
11
|
+
destinationPath,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const validatePathsExist = (sourcePath, destinationPath, suffix = 'Path') => {
|
|
16
|
+
if (!sourcePath || !destinationPath) {
|
|
17
|
+
throw new TypeError(`\`source${suffix}\` and \`destination${suffix}\` required`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const validateSameDirectory = (source, destination) => {
|
|
22
|
+
if (path__default.dirname(source) !== path__default.dirname(destination)) {
|
|
23
|
+
throw new Error('`source` and `destination` must be in the same directory');
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const _moveFile = async (sourcePath, destinationPath, {overwrite = true, cwd = process__default.cwd(), directoryMode, validateDirectory = false} = {}) => {
|
|
28
|
+
if (cwd) {
|
|
29
|
+
({sourcePath, destinationPath} = resolvePath(cwd, sourcePath, destinationPath));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (validateDirectory) {
|
|
33
|
+
validateSameDirectory(sourcePath, destinationPath);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!overwrite && fs__default.existsSync(destinationPath)) {
|
|
37
|
+
throw new Error(`The destination file exists: ${destinationPath}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
await promises.mkdir(path__default.dirname(destinationPath), {
|
|
41
|
+
recursive: true,
|
|
42
|
+
mode: directoryMode,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
await promises.rename(sourcePath, destinationPath);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
if (error.code === 'EXDEV') {
|
|
49
|
+
const stats = await promises.lstat(sourcePath);
|
|
50
|
+
if (stats.isSymbolicLink()) {
|
|
51
|
+
const target = await promises.readlink(sourcePath);
|
|
52
|
+
await promises.symlink(target, destinationPath);
|
|
53
|
+
await promises.unlink(sourcePath);
|
|
54
|
+
} else {
|
|
55
|
+
await promises.cp(sourcePath, destinationPath, {recursive: true, preserveTimestamps: true});
|
|
56
|
+
await promises.rm(sourcePath, {recursive: true});
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
async function moveFile(sourcePath, destinationPath, options) {
|
|
65
|
+
validatePathsExist(sourcePath, destinationPath);
|
|
66
|
+
return _moveFile(sourcePath, destinationPath, options);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { moveFile as m };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
function commonjsRequire(path) {
|
|
2
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export { commonjsRequire as c };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import a from '../chunks/index2.mjs';
|
|
2
2
|
|
|
3
3
|
class ExecutionTracer {
|
|
4
4
|
traces = /* @__PURE__ */ new Map();
|
|
@@ -139,16 +139,16 @@ class ExecutionTracer {
|
|
|
139
139
|
visualizeTrace(sessionId) {
|
|
140
140
|
const trace = this.traces.get(sessionId);
|
|
141
141
|
if (!trace) {
|
|
142
|
-
return
|
|
142
|
+
return a.red(`Trace not found: ${sessionId}`);
|
|
143
143
|
}
|
|
144
144
|
const lines = [];
|
|
145
|
-
lines.push(
|
|
145
|
+
lines.push(a.cyan.bold(`
|
|
146
146
|
\u{1F4CA} Execution Trace: ${sessionId}`));
|
|
147
|
-
lines.push(
|
|
147
|
+
lines.push(a.gray(`Started: ${new Date(trace.startTime).toISOString()}`));
|
|
148
148
|
if (trace.endTime) {
|
|
149
|
-
lines.push(
|
|
149
|
+
lines.push(a.gray(`Duration: ${trace.endTime - trace.startTime}ms`));
|
|
150
150
|
}
|
|
151
|
-
lines.push(
|
|
151
|
+
lines.push(a.gray(`Events: ${trace.metadata.totalEvents}`));
|
|
152
152
|
lines.push("");
|
|
153
153
|
const agentEvents = /* @__PURE__ */ new Map();
|
|
154
154
|
for (const event of trace.events) {
|
|
@@ -159,7 +159,7 @@ class ExecutionTracer {
|
|
|
159
159
|
agentEvents.get(agentId).push(event);
|
|
160
160
|
}
|
|
161
161
|
for (const [agentId, events] of agentEvents) {
|
|
162
|
-
lines.push(
|
|
162
|
+
lines.push(a.yellow(`\u{1F916} ${agentId}`));
|
|
163
163
|
for (const event of events) {
|
|
164
164
|
const time = new Date(event.timestamp).toLocaleTimeString();
|
|
165
165
|
const icon = this.getEventIcon(event.type);
|
|
@@ -178,7 +178,7 @@ class ExecutionTracer {
|
|
|
178
178
|
}
|
|
179
179
|
lines.push("");
|
|
180
180
|
}
|
|
181
|
-
lines.push(
|
|
181
|
+
lines.push(a.cyan("\u{1F4C8} Summary"));
|
|
182
182
|
lines.push(` Agents: ${trace.metadata.agentCount}`);
|
|
183
183
|
lines.push(` Tool Calls: ${trace.metadata.toolCallCount}`);
|
|
184
184
|
lines.push(` Errors: ${trace.metadata.errorCount}`);
|
|
@@ -206,16 +206,16 @@ class ExecutionTracer {
|
|
|
206
206
|
*/
|
|
207
207
|
getEventColor(type) {
|
|
208
208
|
const colors = {
|
|
209
|
-
"agent-start":
|
|
210
|
-
"agent-end":
|
|
211
|
-
"decision":
|
|
212
|
-
"tool-call":
|
|
213
|
-
"tool-result":
|
|
214
|
-
"error":
|
|
215
|
-
"context-load":
|
|
216
|
-
"context-save":
|
|
209
|
+
"agent-start": a.green,
|
|
210
|
+
"agent-end": a.gray,
|
|
211
|
+
"decision": a.cyan,
|
|
212
|
+
"tool-call": a.blue,
|
|
213
|
+
"tool-result": a.green,
|
|
214
|
+
"error": a.red,
|
|
215
|
+
"context-load": a.yellow,
|
|
216
|
+
"context-save": a.yellow
|
|
217
217
|
};
|
|
218
|
-
return colors[type] ||
|
|
218
|
+
return colors[type] || a.white;
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
const executionTracer = new ExecutionTracer();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'pathe';
|
|
3
2
|
import { CLAUDE_AGENTS_DIR, CCJK_CONFIG_DIR } from '../chunks/constants.mjs';
|
|
3
|
+
import { j as join } from './ccjk.bQ7Dh1g4.mjs';
|
|
4
4
|
|
|
5
5
|
const getProjectAgentsDir = (projectDir) => join(projectDir || process.cwd(), ".claude", "agents");
|
|
6
6
|
const GLOBAL_AGENTS_DIR = CLAUDE_AGENTS_DIR;
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is not the set of all possible signals.
|
|
3
|
+
*
|
|
4
|
+
* It IS, however, the set of all signals that trigger
|
|
5
|
+
* an exit on either Linux or BSD systems. Linux is a
|
|
6
|
+
* superset of the signal names supported on BSD, and
|
|
7
|
+
* the unknown signals just fail to register, so we can
|
|
8
|
+
* catch that easily enough.
|
|
9
|
+
*
|
|
10
|
+
* Windows signals are a different set, since there are
|
|
11
|
+
* signals that terminate Windows processes, but don't
|
|
12
|
+
* terminate (or don't even exist) on Posix systems.
|
|
13
|
+
*
|
|
14
|
+
* Don't bother with SIGKILL. It's uncatchable, which
|
|
15
|
+
* means that we can't fire any callbacks anyway.
|
|
16
|
+
*
|
|
17
|
+
* If a user does happen to register a handler on a non-
|
|
18
|
+
* fatal signal like SIGWINCH or something, and then
|
|
19
|
+
* exit, it'll end up firing `process.emit('exit')`, so
|
|
20
|
+
* the handler will be fired anyway.
|
|
21
|
+
*
|
|
22
|
+
* SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised
|
|
23
|
+
* artificially, inherently leave the process in a
|
|
24
|
+
* state from which it is not safe to try and enter JS
|
|
25
|
+
* listeners.
|
|
26
|
+
*/
|
|
27
|
+
const signals = [];
|
|
28
|
+
signals.push('SIGHUP', 'SIGINT', 'SIGTERM');
|
|
29
|
+
if (process.platform !== 'win32') {
|
|
30
|
+
signals.push('SIGALRM', 'SIGABRT', 'SIGVTALRM', 'SIGXCPU', 'SIGXFSZ', 'SIGUSR2', 'SIGTRAP', 'SIGSYS', 'SIGQUIT', 'SIGIOT'
|
|
31
|
+
// should detect profiler and enable/disable accordingly.
|
|
32
|
+
// see #21
|
|
33
|
+
// 'SIGPROF'
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
if (process.platform === 'linux') {
|
|
37
|
+
signals.push('SIGIO', 'SIGPOLL', 'SIGPWR', 'SIGSTKFLT');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Note: since nyc uses this module to output coverage, any lines
|
|
41
|
+
// that are in the direct sync flow of nyc's outputCoverage are
|
|
42
|
+
// ignored, since we can never get coverage for them.
|
|
43
|
+
// grab a reference to node's real process object right away
|
|
44
|
+
const processOk = (process) => !!process &&
|
|
45
|
+
typeof process === 'object' &&
|
|
46
|
+
typeof process.removeListener === 'function' &&
|
|
47
|
+
typeof process.emit === 'function' &&
|
|
48
|
+
typeof process.reallyExit === 'function' &&
|
|
49
|
+
typeof process.listeners === 'function' &&
|
|
50
|
+
typeof process.kill === 'function' &&
|
|
51
|
+
typeof process.pid === 'number' &&
|
|
52
|
+
typeof process.on === 'function';
|
|
53
|
+
const kExitEmitter = Symbol.for('signal-exit emitter');
|
|
54
|
+
const global = globalThis;
|
|
55
|
+
const ObjectDefineProperty = Object.defineProperty.bind(Object);
|
|
56
|
+
// teeny special purpose ee
|
|
57
|
+
class Emitter {
|
|
58
|
+
emitted = {
|
|
59
|
+
afterExit: false,
|
|
60
|
+
exit: false,
|
|
61
|
+
};
|
|
62
|
+
listeners = {
|
|
63
|
+
afterExit: [],
|
|
64
|
+
exit: [],
|
|
65
|
+
};
|
|
66
|
+
count = 0;
|
|
67
|
+
id = Math.random();
|
|
68
|
+
constructor() {
|
|
69
|
+
if (global[kExitEmitter]) {
|
|
70
|
+
return global[kExitEmitter];
|
|
71
|
+
}
|
|
72
|
+
ObjectDefineProperty(global, kExitEmitter, {
|
|
73
|
+
value: this,
|
|
74
|
+
writable: false,
|
|
75
|
+
enumerable: false,
|
|
76
|
+
configurable: false,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
on(ev, fn) {
|
|
80
|
+
this.listeners[ev].push(fn);
|
|
81
|
+
}
|
|
82
|
+
removeListener(ev, fn) {
|
|
83
|
+
const list = this.listeners[ev];
|
|
84
|
+
const i = list.indexOf(fn);
|
|
85
|
+
/* c8 ignore start */
|
|
86
|
+
if (i === -1) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
/* c8 ignore stop */
|
|
90
|
+
if (i === 0 && list.length === 1) {
|
|
91
|
+
list.length = 0;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
list.splice(i, 1);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
emit(ev, code, signal) {
|
|
98
|
+
if (this.emitted[ev]) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
this.emitted[ev] = true;
|
|
102
|
+
let ret = false;
|
|
103
|
+
for (const fn of this.listeners[ev]) {
|
|
104
|
+
ret = fn(code, signal) === true || ret;
|
|
105
|
+
}
|
|
106
|
+
if (ev === 'exit') {
|
|
107
|
+
ret = this.emit('afterExit', code, signal) || ret;
|
|
108
|
+
}
|
|
109
|
+
return ret;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
class SignalExitBase {
|
|
113
|
+
}
|
|
114
|
+
const signalExitWrap = (handler) => {
|
|
115
|
+
return {
|
|
116
|
+
onExit(cb, opts) {
|
|
117
|
+
return handler.onExit(cb, opts);
|
|
118
|
+
},
|
|
119
|
+
load() {
|
|
120
|
+
return handler.load();
|
|
121
|
+
},
|
|
122
|
+
unload() {
|
|
123
|
+
return handler.unload();
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
class SignalExitFallback extends SignalExitBase {
|
|
128
|
+
onExit() {
|
|
129
|
+
return () => { };
|
|
130
|
+
}
|
|
131
|
+
load() { }
|
|
132
|
+
unload() { }
|
|
133
|
+
}
|
|
134
|
+
class SignalExit extends SignalExitBase {
|
|
135
|
+
// "SIGHUP" throws an `ENOSYS` error on Windows,
|
|
136
|
+
// so use a supported signal instead
|
|
137
|
+
/* c8 ignore start */
|
|
138
|
+
#hupSig = process$1.platform === 'win32' ? 'SIGINT' : 'SIGHUP';
|
|
139
|
+
/* c8 ignore stop */
|
|
140
|
+
#emitter = new Emitter();
|
|
141
|
+
#process;
|
|
142
|
+
#originalProcessEmit;
|
|
143
|
+
#originalProcessReallyExit;
|
|
144
|
+
#sigListeners = {};
|
|
145
|
+
#loaded = false;
|
|
146
|
+
constructor(process) {
|
|
147
|
+
super();
|
|
148
|
+
this.#process = process;
|
|
149
|
+
// { <signal>: <listener fn>, ... }
|
|
150
|
+
this.#sigListeners = {};
|
|
151
|
+
for (const sig of signals) {
|
|
152
|
+
this.#sigListeners[sig] = () => {
|
|
153
|
+
// If there are no other listeners, an exit is coming!
|
|
154
|
+
// Simplest way: remove us and then re-send the signal.
|
|
155
|
+
// We know that this will kill the process, so we can
|
|
156
|
+
// safely emit now.
|
|
157
|
+
const listeners = this.#process.listeners(sig);
|
|
158
|
+
let { count } = this.#emitter;
|
|
159
|
+
// This is a workaround for the fact that signal-exit v3 and signal
|
|
160
|
+
// exit v4 are not aware of each other, and each will attempt to let
|
|
161
|
+
// the other handle it, so neither of them do. To correct this, we
|
|
162
|
+
// detect if we're the only handler *except* for previous versions
|
|
163
|
+
// of signal-exit, and increment by the count of listeners it has
|
|
164
|
+
// created.
|
|
165
|
+
/* c8 ignore start */
|
|
166
|
+
const p = process;
|
|
167
|
+
if (typeof p.__signal_exit_emitter__ === 'object' &&
|
|
168
|
+
typeof p.__signal_exit_emitter__.count === 'number') {
|
|
169
|
+
count += p.__signal_exit_emitter__.count;
|
|
170
|
+
}
|
|
171
|
+
/* c8 ignore stop */
|
|
172
|
+
if (listeners.length === count) {
|
|
173
|
+
this.unload();
|
|
174
|
+
const ret = this.#emitter.emit('exit', null, sig);
|
|
175
|
+
/* c8 ignore start */
|
|
176
|
+
const s = sig === 'SIGHUP' ? this.#hupSig : sig;
|
|
177
|
+
if (!ret)
|
|
178
|
+
process.kill(process.pid, s);
|
|
179
|
+
/* c8 ignore stop */
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
this.#originalProcessReallyExit = process.reallyExit;
|
|
184
|
+
this.#originalProcessEmit = process.emit;
|
|
185
|
+
}
|
|
186
|
+
onExit(cb, opts) {
|
|
187
|
+
/* c8 ignore start */
|
|
188
|
+
if (!processOk(this.#process)) {
|
|
189
|
+
return () => { };
|
|
190
|
+
}
|
|
191
|
+
/* c8 ignore stop */
|
|
192
|
+
if (this.#loaded === false) {
|
|
193
|
+
this.load();
|
|
194
|
+
}
|
|
195
|
+
const ev = opts?.alwaysLast ? 'afterExit' : 'exit';
|
|
196
|
+
this.#emitter.on(ev, cb);
|
|
197
|
+
return () => {
|
|
198
|
+
this.#emitter.removeListener(ev, cb);
|
|
199
|
+
if (this.#emitter.listeners['exit'].length === 0 &&
|
|
200
|
+
this.#emitter.listeners['afterExit'].length === 0) {
|
|
201
|
+
this.unload();
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
load() {
|
|
206
|
+
if (this.#loaded) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
this.#loaded = true;
|
|
210
|
+
// This is the number of onSignalExit's that are in play.
|
|
211
|
+
// It's important so that we can count the correct number of
|
|
212
|
+
// listeners on signals, and don't wait for the other one to
|
|
213
|
+
// handle it instead of us.
|
|
214
|
+
this.#emitter.count += 1;
|
|
215
|
+
for (const sig of signals) {
|
|
216
|
+
try {
|
|
217
|
+
const fn = this.#sigListeners[sig];
|
|
218
|
+
if (fn)
|
|
219
|
+
this.#process.on(sig, fn);
|
|
220
|
+
}
|
|
221
|
+
catch (_) { }
|
|
222
|
+
}
|
|
223
|
+
this.#process.emit = (ev, ...a) => {
|
|
224
|
+
return this.#processEmit(ev, ...a);
|
|
225
|
+
};
|
|
226
|
+
this.#process.reallyExit = (code) => {
|
|
227
|
+
return this.#processReallyExit(code);
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
unload() {
|
|
231
|
+
if (!this.#loaded) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
this.#loaded = false;
|
|
235
|
+
signals.forEach(sig => {
|
|
236
|
+
const listener = this.#sigListeners[sig];
|
|
237
|
+
/* c8 ignore start */
|
|
238
|
+
if (!listener) {
|
|
239
|
+
throw new Error('Listener not defined for signal: ' + sig);
|
|
240
|
+
}
|
|
241
|
+
/* c8 ignore stop */
|
|
242
|
+
try {
|
|
243
|
+
this.#process.removeListener(sig, listener);
|
|
244
|
+
/* c8 ignore start */
|
|
245
|
+
}
|
|
246
|
+
catch (_) { }
|
|
247
|
+
/* c8 ignore stop */
|
|
248
|
+
});
|
|
249
|
+
this.#process.emit = this.#originalProcessEmit;
|
|
250
|
+
this.#process.reallyExit = this.#originalProcessReallyExit;
|
|
251
|
+
this.#emitter.count -= 1;
|
|
252
|
+
}
|
|
253
|
+
#processReallyExit(code) {
|
|
254
|
+
/* c8 ignore start */
|
|
255
|
+
if (!processOk(this.#process)) {
|
|
256
|
+
return 0;
|
|
257
|
+
}
|
|
258
|
+
this.#process.exitCode = code || 0;
|
|
259
|
+
/* c8 ignore stop */
|
|
260
|
+
this.#emitter.emit('exit', this.#process.exitCode, null);
|
|
261
|
+
return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
|
|
262
|
+
}
|
|
263
|
+
#processEmit(ev, ...args) {
|
|
264
|
+
const og = this.#originalProcessEmit;
|
|
265
|
+
if (ev === 'exit' && processOk(this.#process)) {
|
|
266
|
+
if (typeof args[0] === 'number') {
|
|
267
|
+
this.#process.exitCode = args[0];
|
|
268
|
+
/* c8 ignore start */
|
|
269
|
+
}
|
|
270
|
+
/* c8 ignore start */
|
|
271
|
+
const ret = og.call(this.#process, ev, ...args);
|
|
272
|
+
/* c8 ignore start */
|
|
273
|
+
this.#emitter.emit('exit', this.#process.exitCode, null);
|
|
274
|
+
/* c8 ignore stop */
|
|
275
|
+
return ret;
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
return og.call(this.#process, ev, ...args);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const process$1 = globalThis.process;
|
|
283
|
+
// wrap so that we call the method on the actual handler, without
|
|
284
|
+
// exporting it directly.
|
|
285
|
+
const {
|
|
286
|
+
/**
|
|
287
|
+
* Called when the process is exiting, whether via signal, explicit
|
|
288
|
+
* exit, or running out of stuff to do.
|
|
289
|
+
*
|
|
290
|
+
* If the global process object is not suitable for instrumentation,
|
|
291
|
+
* then this will be a no-op.
|
|
292
|
+
*
|
|
293
|
+
* Returns a function that may be used to unload signal-exit.
|
|
294
|
+
*/
|
|
295
|
+
onExit} = signalExitWrap(processOk(process$1) ? new SignalExit(process$1) : new SignalExitFallback());
|
|
296
|
+
|
|
297
|
+
export { onExit as o };
|