@idlebox/node 1.4.11 → 1.4.13
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/lib/asyncLoad.d.ts +1 -0
- package/lib/asyncLoad.d.ts.map +1 -1
- package/lib/asyncLoad.js +3 -2
- package/lib/asyncLoad.js.map +1 -1
- package/lib/autoindex.d.ts +73 -76
- package/lib/autoindex.d.ts.map +1 -1
- package/lib/autoindex.js +65 -68
- package/lib/autoindex.js.map +1 -1
- package/lib/child_process/respawn.d.ts +2 -0
- package/lib/child_process/respawn.d.ts.map +1 -1
- package/lib/child_process/respawn.js +2 -0
- package/lib/child_process/respawn.js.map +1 -1
- package/lib/fs/exists.js +1 -1
- package/lib/fs/exists.js.map +1 -1
- package/lib/lifecycle/register.d.ts +11 -1
- package/lib/lifecycle/register.d.ts.map +1 -1
- package/lib/lifecycle/register.js +152 -51
- package/lib/lifecycle/register.js.map +1 -1
- package/lib/lifecycle/workingDirectory.d.ts +11 -0
- package/lib/lifecycle/workingDirectory.d.ts.map +1 -0
- package/lib/lifecycle/workingDirectory.js +40 -0
- package/lib/lifecycle/workingDirectory.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -11
- package/src/asyncLoad.ts +3 -2
- package/src/autoindex.ts +109 -115
- package/src/child_process/respawn.ts +2 -0
- package/src/fs/exists.ts +1 -1
- package/src/lifecycle/register.ts +152 -53
- package/src/lifecycle/workingDirectory.ts +45 -0
- package/lib/autoindex.generated.d.ts +0 -80
- package/lib/autoindex.generated.d.ts.map +0 -1
- package/lib/autoindex.generated.js +0 -132
- package/lib/autoindex.generated.js.map +0 -1
- package/lib/error/linux.d.ts +0 -125
- package/lib/error/linux.d.ts.map +0 -1
- package/lib/error/linux.js +0 -126
- package/lib/error/linux.js.map +0 -1
- package/lib/error/types.d.ts +0 -24
- package/lib/error/types.d.ts.map +0 -1
- package/lib/error/types.js +0 -25
- package/lib/error/types.js.map +0 -1
- package/src/autoindex.generated.ts +0 -159
- package/src/error/linux.ts +0 -124
- package/src/error/types.ts +0 -39
|
@@ -1,92 +1,193 @@
|
|
|
1
1
|
/** biome-ignore-all lint/suspicious/noDebugger: debug file */
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ensureDisposeGlobal, ensureGlobalObject, functionName, isProductionMode, prettyPrintError } from '@idlebox/common';
|
|
3
|
+
import { ErrorWithCode, Exit, ExitCode, InterruptError, UncaughtException, UnhandledRejection } from '@idlebox/errors';
|
|
4
|
+
import assert from 'node:assert';
|
|
5
|
+
import { syncBuiltinESMExports } from 'node:module';
|
|
4
6
|
import { basename } from 'node:path';
|
|
5
7
|
import process from 'node:process';
|
|
8
|
+
import { inspect } from 'node:util';
|
|
6
9
|
const originalExit = process.exit;
|
|
7
10
|
const prefix = process.stderr.isTTY ? '' : `<${title()} ${process.pid}> `;
|
|
8
|
-
const hasInspect = process.argv.some((arg) => arg.startsWith('--inspect=') || arg.startsWith('--inspect-brk=') || arg === '--inspect' || arg === '--inspect-brk');
|
|
9
11
|
function title() {
|
|
10
12
|
if (process.title && process.title !== 'node') {
|
|
11
13
|
return process.title;
|
|
12
14
|
}
|
|
13
15
|
return basename(process.argv[1] || '') || 'node';
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
function getCurrentCode() {
|
|
18
|
+
return typeof process.exitCode === 'string' ? parseInt(process.exitCode) : process.exitCode || 0;
|
|
19
|
+
}
|
|
20
|
+
export function setExitCodeIfNot(exitCode) {
|
|
21
|
+
if (exitCode || typeof process.exitCode !== 'number') {
|
|
22
|
+
process.exitCode = exitCode;
|
|
23
|
+
globalThis.process.exitCode = exitCode;
|
|
18
24
|
}
|
|
19
25
|
}
|
|
20
|
-
|
|
26
|
+
let shuttingDown = 0;
|
|
21
27
|
export function shutdown(exitCode) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
_shutdown(exitCode);
|
|
29
|
+
throw new Exit(getCurrentCode());
|
|
30
|
+
}
|
|
31
|
+
function _shutdown(exitCode) {
|
|
32
|
+
setExitCodeIfNot(exitCode);
|
|
33
|
+
if (!shuttingDown) {
|
|
34
|
+
shuttingDown = 1;
|
|
35
|
+
ensureDisposeGlobal().finally(() => {
|
|
36
|
+
originalExit(getCurrentCode());
|
|
37
|
+
});
|
|
26
38
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
throw new Exit(code);
|
|
39
|
+
else {
|
|
40
|
+
shuttingDown++;
|
|
30
41
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
42
|
+
}
|
|
43
|
+
const typed_error_handlers = new WeakMap();
|
|
44
|
+
const inherit_error_handlers = new Map();
|
|
45
|
+
export function registerNodejsGlobalTypedErrorHandlerWithInheritance(ErrorCls, fn) {
|
|
46
|
+
if (typed_error_handlers.has(ErrorCls)) {
|
|
47
|
+
throw new ErrorCls(`conflict register of error type ${ErrorCls.name}`);
|
|
48
|
+
}
|
|
49
|
+
assert.notEqual(ErrorCls, Error, 'cannot register basic Error type');
|
|
50
|
+
inherit_error_handlers.set(ErrorCls, fn);
|
|
51
|
+
}
|
|
52
|
+
export function registerNodejsGlobalTypedErrorHandler(ErrorCls, fn) {
|
|
53
|
+
if (typed_error_handlers.has(ErrorCls)) {
|
|
54
|
+
throw new ErrorCls(`conflict register of error type ${ErrorCls.name}`);
|
|
55
|
+
}
|
|
56
|
+
assert.notEqual(ErrorCls, Error, 'cannot register basic Error type');
|
|
57
|
+
typed_error_handlers.set(ErrorCls, fn);
|
|
58
|
+
}
|
|
59
|
+
function uniqueErrorHandler(e, logger) {
|
|
60
|
+
if (!isProductionMode)
|
|
61
|
+
logger.verbose?.(`uniqueErrorHandler:`);
|
|
62
|
+
if (!(e instanceof Error)) {
|
|
63
|
+
prettyPrintError(`${prefix}catch unexpect object`, new Error(`error object is ${typeof e} ${e ? e.constructor?.name : 'unknown'}`));
|
|
64
|
+
throw originalExit(ExitCode.PROGRAM);
|
|
65
|
+
}
|
|
66
|
+
if (e instanceof Exit) {
|
|
67
|
+
if (!isProductionMode)
|
|
68
|
+
logger.verbose?.(` - skip exit object`);
|
|
69
|
+
if (!shuttingDown) {
|
|
70
|
+
_shutdown(e.code);
|
|
71
|
+
}
|
|
72
|
+
throw e;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const catcher = typed_error_handlers.get(e.constructor);
|
|
76
|
+
if (catcher) {
|
|
77
|
+
if (!isProductionMode)
|
|
78
|
+
logger.verbose?.(` - call catcher ${functionName(catcher)}`);
|
|
79
|
+
catcher(e);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
for (const [Cls, fn] of inherit_error_handlers) {
|
|
83
|
+
if (!isProductionMode)
|
|
84
|
+
logger.verbose?.(` - call inherited catcher ${functionName(fn)}`);
|
|
85
|
+
if (e instanceof Cls) {
|
|
86
|
+
fn(e);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (ee) {
|
|
92
|
+
prettyPrintError(`${prefix}error while handle error`, {
|
|
93
|
+
message: ee.message,
|
|
94
|
+
stack: ee.stack,
|
|
95
|
+
cause: e,
|
|
96
|
+
});
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (e instanceof InterruptError) {
|
|
100
|
+
if (!isProductionMode)
|
|
101
|
+
logger.verbose?.(` - shuttingDown = ${shuttingDown}`);
|
|
102
|
+
if (shuttingDown > 5) {
|
|
103
|
+
logger.output(`${prefix}Exiting immediately.`);
|
|
104
|
+
originalExit(ExitCode.INTERRUPT);
|
|
105
|
+
}
|
|
106
|
+
shutdown(ExitCode.INTERRUPT);
|
|
107
|
+
}
|
|
108
|
+
if (e instanceof UnhandledRejection) {
|
|
109
|
+
if (!isProductionMode)
|
|
110
|
+
logger.verbose?.(` - UnhandledRejection`);
|
|
111
|
+
if (e.cause instanceof Error) {
|
|
112
|
+
prettyPrintError(`${prefix}Unhandled Rejection`, e.cause);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
logger.output(`${prefix}Unhandled Rejection / error type unknown: ${inspect(e.cause)}`);
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (e instanceof UncaughtException) {
|
|
120
|
+
if (!isProductionMode)
|
|
121
|
+
logger.verbose?.(` - UncaughtException`);
|
|
122
|
+
prettyPrintError(`${prefix}Uncaught Exception`, e.cause);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (!isProductionMode)
|
|
126
|
+
logger.verbose?.(` - common error`);
|
|
127
|
+
prettyPrintError(`${prefix}unhandled global exception`, e);
|
|
128
|
+
shutdown(ExitCode.PROGRAM);
|
|
35
129
|
}
|
|
36
130
|
/**
|
|
37
131
|
* 注册nodejs退出处理器
|
|
38
132
|
*/
|
|
39
|
-
export function registerNodejsExitHandler() {
|
|
40
|
-
ensureGlobalObject('exithandler/register', _real_register);
|
|
133
|
+
export function registerNodejsExitHandler(logger = { output: console.error }) {
|
|
134
|
+
ensureGlobalObject('exithandler/register', () => _real_register(logger));
|
|
41
135
|
}
|
|
42
|
-
function _real_register() {
|
|
136
|
+
function _real_register(logger) {
|
|
137
|
+
logger.verbose?.(`register nodejs exit handler: production=${isProductionMode}`);
|
|
43
138
|
process.on('SIGINT', () => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
console.error(`Exiting immediately.`);
|
|
47
|
-
originalExit(1);
|
|
48
|
-
}
|
|
49
|
-
shutdown(0);
|
|
139
|
+
logger.output(`\n${prefix}Received SIGINT. Exiting gracefully...`);
|
|
140
|
+
uniqueErrorHandler(new InterruptError('SIGINT'), logger);
|
|
50
141
|
});
|
|
51
142
|
process.on('SIGTERM', () => {
|
|
52
|
-
|
|
53
|
-
|
|
143
|
+
logger.output(`${prefix}Received SIGTERM. Exiting gracefully...`);
|
|
144
|
+
uniqueErrorHandler(new InterruptError('SIGTERM'), logger);
|
|
54
145
|
});
|
|
55
146
|
process.on('beforeExit', (code) => {
|
|
56
|
-
|
|
57
|
-
|
|
147
|
+
// empty handler prevent real exit
|
|
148
|
+
if (!isProductionMode)
|
|
149
|
+
logger.verbose?.(`process: beforeExit: ${code}`);
|
|
150
|
+
if (process.exitCode === undefined || process.exitCode === '') {
|
|
151
|
+
code = ExitCode.EXECUTION;
|
|
152
|
+
logger.output(`${prefix}beforeExit called, but process.exitCode has not been set, switch to ${code}`);
|
|
153
|
+
}
|
|
154
|
+
_shutdown(code);
|
|
58
155
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
156
|
+
function finalThrow(e) {
|
|
157
|
+
try {
|
|
158
|
+
uniqueErrorHandler(e, logger);
|
|
159
|
+
if (e.cause instanceof ErrorWithCode) {
|
|
160
|
+
if (!isProductionMode)
|
|
161
|
+
logger.verbose?.(`finalThrow: got code: ${e.cause.code}`);
|
|
162
|
+
_shutdown(e.cause.code);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
if (!isProductionMode)
|
|
166
|
+
logger.verbose?.(`finalThrow: not got code: ${e.cause} `);
|
|
167
|
+
_shutdown(ExitCode.PROGRAM);
|
|
65
168
|
}
|
|
66
|
-
prettyPrintError(`${prefix}Unhandled Rejection`, reason);
|
|
67
169
|
}
|
|
68
|
-
|
|
69
|
-
|
|
170
|
+
catch (e) {
|
|
171
|
+
if (e instanceof Exit) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
prettyPrintError('Exception while handling error', e);
|
|
175
|
+
_shutdown(ExitCode.PROGRAM);
|
|
70
176
|
}
|
|
71
|
-
|
|
177
|
+
}
|
|
178
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
179
|
+
finalThrow(new UnhandledRejection(reason, promise));
|
|
72
180
|
});
|
|
73
|
-
const processMdl = createRequire(import.meta.url)('node:process');
|
|
74
|
-
processMdl.exit = shutdown;
|
|
75
|
-
syncBuiltinESMExports();
|
|
76
181
|
function uncaughtException(error) {
|
|
77
|
-
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (hasInspect)
|
|
81
|
-
debugger;
|
|
82
|
-
prettyPrintError(`${prefix}Uncaught Exception`, error);
|
|
83
|
-
shutdown(1);
|
|
182
|
+
finalThrow(new UncaughtException(error));
|
|
84
183
|
}
|
|
85
184
|
if (process.hasUncaughtExceptionCaptureCallback()) {
|
|
86
185
|
process.on('uncaughtException', uncaughtException);
|
|
87
186
|
throw new Error(`${prefix} [uncaught exception capture] callback already registered by other module`);
|
|
88
187
|
}
|
|
89
188
|
process.setUncaughtExceptionCaptureCallback(uncaughtException);
|
|
189
|
+
process.exit = shutdown;
|
|
190
|
+
syncBuiltinESMExports();
|
|
90
191
|
return true;
|
|
91
192
|
}
|
|
92
193
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/lifecycle/register.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAE9D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/lifecycle/register.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAE9D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAmB,MAAM,iBAAiB,CAAC;AAC7I,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACvH,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,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D,OAAO,CAAC,mCAAmC,CAAC,iBAAiB,CAAC,CAAC;IAE/D,OAAO,CAAC,IAAI,GAAG,QAAQ,CAAC;IACxB,qBAAqB,EAAE,CAAC;IAExB,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,GAAG,CAAC,OAAe;IAClC,QAAQ,CAAC;IACT,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const wd: {
|
|
2
|
+
cwd(): string;
|
|
3
|
+
chdir(dir: string): void;
|
|
4
|
+
patchGlobal(): void;
|
|
5
|
+
escapeVscodeCwd: typeof escapeVscodeCwd;
|
|
6
|
+
isVscodeShellIntegration: string | undefined;
|
|
7
|
+
};
|
|
8
|
+
export declare const workingDirectory: Readonly<typeof wd>;
|
|
9
|
+
declare function escapeVscodeCwd(path: string): string;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=workingDirectory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workingDirectory.d.ts","sourceRoot":"","sources":["../../src/lifecycle/workingDirectory.ts"],"names":[],"mappings":"AAWA,QAAA,MAAM,EAAE;;eAII,MAAM;;;;CAWjB,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAM,CAAC;AAExD,iBAAS,eAAe,CAAC,IAAI,EAAE,MAAM,UAEpC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { noop, vscEscapeValue } from '@idlebox/common';
|
|
2
|
+
import { syncBuiltinESMExports } from 'node:module';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
const originalChdir = process.chdir;
|
|
5
|
+
const originalCwd = process.cwd;
|
|
6
|
+
let currentEnvironmentChdir = originalChdir;
|
|
7
|
+
const currentEnvironmentCwd = originalCwd;
|
|
8
|
+
let patch = noop;
|
|
9
|
+
const wd = {
|
|
10
|
+
cwd() {
|
|
11
|
+
return currentEnvironmentCwd();
|
|
12
|
+
},
|
|
13
|
+
chdir(dir) {
|
|
14
|
+
currentEnvironmentChdir(dir);
|
|
15
|
+
},
|
|
16
|
+
patchGlobal() {
|
|
17
|
+
patch();
|
|
18
|
+
wd.cwd = currentEnvironmentCwd;
|
|
19
|
+
wd.chdir = currentEnvironmentChdir;
|
|
20
|
+
wd.patchGlobal = noop;
|
|
21
|
+
},
|
|
22
|
+
escapeVscodeCwd,
|
|
23
|
+
isVscodeShellIntegration: process.env.VSCODE_SHELL_INTEGRATION || process.env.VSCODE_SHELL_INTEGRATION_SHELL_SCRIPT,
|
|
24
|
+
};
|
|
25
|
+
export const workingDirectory = wd;
|
|
26
|
+
function escapeVscodeCwd(path) {
|
|
27
|
+
return `\x1B]633;P;Cwd=${vscEscapeValue(path)}\x07`;
|
|
28
|
+
}
|
|
29
|
+
if (wd.isVscodeShellIntegration) {
|
|
30
|
+
currentEnvironmentChdir = (newRoot) => {
|
|
31
|
+
process.stderr.write(escapeVscodeCwd(newRoot));
|
|
32
|
+
originalChdir(newRoot);
|
|
33
|
+
};
|
|
34
|
+
patch = () => {
|
|
35
|
+
process.chdir = currentEnvironmentChdir;
|
|
36
|
+
globalThis.process.chdir = currentEnvironmentChdir;
|
|
37
|
+
syncBuiltinESMExports();
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=workingDirectory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workingDirectory.js","sourceRoot":"","sources":["../../src/lifecycle/workingDirectory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,MAAM,a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