@idlebox/node 1.4.12 → 1.4.14
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 +16 -28
- package/lib/autoindex.d.ts.map +1 -1
- package/lib/autoindex.js +29 -45
- 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 +6 -2
- package/lib/lifecycle/register.d.ts.map +1 -1
- package/lib/lifecycle/register.js +127 -74
- 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 +7 -8
- package/src/asyncLoad.ts +3 -2
- package/src/autoindex.ts +33 -52
- package/src/child_process/respawn.ts +2 -0
- package/src/fs/exists.ts +1 -1
- package/src/lifecycle/register.ts +127 -77
- package/src/lifecycle/workingDirectory.ts +45 -0
- 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/lib/lifecycle/internal-errors.d.ts +0 -23
- package/lib/lifecycle/internal-errors.d.ts.map +0 -1
- package/lib/lifecycle/internal-errors.js +0 -60
- package/lib/lifecycle/internal-errors.js.map +0 -1
- package/lib/preload.d.ts +0 -2
- package/lib/preload.d.ts.map +0 -1
- package/lib/preload.js +0 -2
- package/lib/preload.js.map +0 -1
- package/src/error/linux.ts +0 -124
- package/src/error/types.ts +0 -39
- package/src/lifecycle/internal-errors.ts +0 -66
- package/src/preload.ts +0 -1
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
/** biome-ignore-all lint/suspicious/noDebugger: debug file */
|
|
2
|
-
import {
|
|
2
|
+
import { ensureDisposeGlobal, ensureGlobalObject, functionName, isProductionMode, prettyPrintError } from '@idlebox/common';
|
|
3
|
+
import { ErrorWithCode, Exit, ExitCode, InterruptError, UncaughtException, UnhandledRejection } from '@idlebox/errors';
|
|
3
4
|
import assert from 'node:assert';
|
|
4
|
-
import {
|
|
5
|
+
import { syncBuiltinESMExports } from 'node:module';
|
|
5
6
|
import { basename } from 'node:path';
|
|
6
7
|
import process from 'node:process';
|
|
7
|
-
import {
|
|
8
|
-
const
|
|
8
|
+
import { inspect } from 'node:util';
|
|
9
|
+
const shutdown_immediate = process.exit;
|
|
9
10
|
const prefix = process.stderr.isTTY ? '' : `<${title()} ${process.pid}> `;
|
|
10
|
-
const hasInspect = process.argv.some((arg) => arg.startsWith('--inspect=') || arg.startsWith('--inspect-brk=') || arg === '--inspect' || arg === '--inspect-brk');
|
|
11
|
-
let abnormalExitCode = 1;
|
|
12
|
-
export function setAbnormalExitCode(code) {
|
|
13
|
-
if (code < 1) {
|
|
14
|
-
throw new TypeError(`abnormal exit code must be greater than 0, got ${code}`);
|
|
15
|
-
}
|
|
16
|
-
abnormalExitCode = code;
|
|
17
|
-
}
|
|
18
11
|
function title() {
|
|
19
12
|
if (process.title && process.title !== 'node') {
|
|
20
13
|
return process.title;
|
|
@@ -24,20 +17,28 @@ function title() {
|
|
|
24
17
|
function getCurrentCode() {
|
|
25
18
|
return typeof process.exitCode === 'string' ? parseInt(process.exitCode) : process.exitCode || 0;
|
|
26
19
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (hasInspect)
|
|
30
|
-
debugger;
|
|
31
|
-
if (exitCode) {
|
|
20
|
+
export function setExitCodeIfNot(exitCode) {
|
|
21
|
+
if (exitCode || typeof process.exitCode !== 'number') {
|
|
32
22
|
process.exitCode = exitCode;
|
|
23
|
+
globalThis.process.exitCode = exitCode;
|
|
33
24
|
}
|
|
25
|
+
}
|
|
26
|
+
let shuttingDown = 0;
|
|
27
|
+
export function shutdown(exitCode) {
|
|
28
|
+
_shutdown_graceful(exitCode);
|
|
29
|
+
throw new Exit(getCurrentCode());
|
|
30
|
+
}
|
|
31
|
+
function _shutdown_graceful(exitCode) {
|
|
32
|
+
setExitCodeIfNot(exitCode);
|
|
34
33
|
if (!shuttingDown) {
|
|
35
|
-
shuttingDown =
|
|
34
|
+
shuttingDown = 1;
|
|
36
35
|
ensureDisposeGlobal().finally(() => {
|
|
37
|
-
|
|
36
|
+
shutdown_immediate(getCurrentCode());
|
|
38
37
|
});
|
|
39
38
|
}
|
|
40
|
-
|
|
39
|
+
else {
|
|
40
|
+
shuttingDown++;
|
|
41
|
+
}
|
|
41
42
|
}
|
|
42
43
|
const typed_error_handlers = new WeakMap();
|
|
43
44
|
const inherit_error_handlers = new Map();
|
|
@@ -55,20 +56,40 @@ export function registerNodejsGlobalTypedErrorHandler(ErrorCls, fn) {
|
|
|
55
56
|
assert.notEqual(ErrorCls, Error, 'cannot register basic Error type');
|
|
56
57
|
typed_error_handlers.set(ErrorCls, fn);
|
|
57
58
|
}
|
|
58
|
-
function
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
function _root_cause(e) {
|
|
60
|
+
if (e.cause instanceof Error) {
|
|
61
|
+
return _root_cause(e.cause);
|
|
62
|
+
}
|
|
63
|
+
return e;
|
|
64
|
+
}
|
|
65
|
+
function uniqueErrorHandler(currentError, logger) {
|
|
66
|
+
if (!isProductionMode)
|
|
67
|
+
logger.verbose?.(`uniqueErrorHandler:`);
|
|
68
|
+
if (!(currentError instanceof Error)) {
|
|
69
|
+
prettyPrintError(`${prefix}catch unexpect object`, new Error(`error object is ${typeof currentError} ${currentError ? currentError.constructor?.name : 'unknown'}`));
|
|
70
|
+
throw shutdown_immediate(ExitCode.PROGRAM);
|
|
71
|
+
}
|
|
72
|
+
const rootCause = _root_cause(currentError);
|
|
73
|
+
if (rootCause instanceof Exit) {
|
|
74
|
+
if (!isProductionMode)
|
|
75
|
+
logger.verbose?.(` - skip exit object`);
|
|
76
|
+
if (!shuttingDown)
|
|
77
|
+
_shutdown_graceful(rootCause.code);
|
|
78
|
+
throw rootCause;
|
|
62
79
|
}
|
|
63
80
|
try {
|
|
64
|
-
const catcher = typed_error_handlers.get(
|
|
81
|
+
const catcher = typed_error_handlers.get(rootCause.constructor);
|
|
65
82
|
if (catcher) {
|
|
66
|
-
|
|
83
|
+
if (!isProductionMode)
|
|
84
|
+
logger.verbose?.(` - call catcher ${functionName(catcher)}`);
|
|
85
|
+
catcher(rootCause);
|
|
67
86
|
return;
|
|
68
87
|
}
|
|
69
88
|
for (const [Cls, fn] of inherit_error_handlers) {
|
|
70
|
-
if (
|
|
71
|
-
fn
|
|
89
|
+
if (!isProductionMode)
|
|
90
|
+
logger.verbose?.(` - call inherited catcher ${functionName(fn)}`);
|
|
91
|
+
if (rootCause instanceof Cls) {
|
|
92
|
+
fn(rootCause);
|
|
72
93
|
return;
|
|
73
94
|
}
|
|
74
95
|
}
|
|
@@ -77,79 +98,111 @@ function callErrorHandler(e) {
|
|
|
77
98
|
prettyPrintError(`${prefix}error while handle error`, {
|
|
78
99
|
message: ee.message,
|
|
79
100
|
stack: ee.stack,
|
|
80
|
-
cause:
|
|
101
|
+
cause: rootCause,
|
|
81
102
|
});
|
|
82
103
|
return;
|
|
83
104
|
}
|
|
84
|
-
if (
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
105
|
+
if (rootCause instanceof InterruptError) {
|
|
106
|
+
if (!isProductionMode)
|
|
107
|
+
logger.verbose?.(` - shuttingDown = ${shuttingDown}`);
|
|
108
|
+
const signal = rootCause.signal;
|
|
109
|
+
if (signal === 'SIGINT') {
|
|
110
|
+
process.stderr.write(shuttingDown === 0 ? '\n' : '\r');
|
|
88
111
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
112
|
+
if (shuttingDown > 4) {
|
|
113
|
+
logger.output(`${prefix}Received ${signal} more than 5 times. Exiting immediately.`);
|
|
114
|
+
shutdown_immediate(ExitCode.INTERRUPT);
|
|
115
|
+
}
|
|
116
|
+
else if (shuttingDown > 0) {
|
|
117
|
+
logger.output(`${prefix}Received ${signal} ${shuttingDown + 1} times.`);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
logger.output(`${prefix}Received ${signal}. Exiting gracefully...`);
|
|
121
|
+
}
|
|
122
|
+
shutdown(ExitCode.INTERRUPT);
|
|
95
123
|
}
|
|
96
|
-
if (
|
|
97
|
-
if (
|
|
98
|
-
|
|
124
|
+
if (currentError instanceof UnhandledRejection) {
|
|
125
|
+
if (!isProductionMode)
|
|
126
|
+
logger.verbose?.(` - UnhandledRejection`);
|
|
127
|
+
if (rootCause !== currentError) {
|
|
128
|
+
prettyPrintError(`${prefix}Unhandled Rejection`, currentError.cause);
|
|
99
129
|
}
|
|
100
130
|
else {
|
|
101
|
-
|
|
131
|
+
logger.output(`${prefix}Unhandled Rejection / error type unknown: ${inspect(currentError.cause)}`);
|
|
102
132
|
}
|
|
103
|
-
|
|
133
|
+
return;
|
|
104
134
|
}
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
135
|
+
if (currentError instanceof UncaughtException) {
|
|
136
|
+
if (!isProductionMode)
|
|
137
|
+
logger.verbose?.(` - UncaughtException`);
|
|
138
|
+
prettyPrintError(`${prefix}Uncaught Exception`, rootCause);
|
|
139
|
+
return;
|
|
108
140
|
}
|
|
141
|
+
if (!isProductionMode)
|
|
142
|
+
logger.verbose?.(` - common error`);
|
|
143
|
+
prettyPrintError(`${prefix}unhandled global exception`, currentError);
|
|
144
|
+
shutdown(ExitCode.PROGRAM);
|
|
109
145
|
}
|
|
110
146
|
/**
|
|
111
147
|
* 注册nodejs退出处理器
|
|
112
148
|
*/
|
|
113
|
-
export function registerNodejsExitHandler() {
|
|
114
|
-
ensureGlobalObject('exithandler/register', _real_register);
|
|
149
|
+
export function registerNodejsExitHandler(logger = { output: console.error }) {
|
|
150
|
+
ensureGlobalObject('exithandler/register', () => _real_register(logger));
|
|
115
151
|
}
|
|
116
|
-
function _real_register() {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
152
|
+
function _real_register(logger) {
|
|
153
|
+
logger.verbose?.(`register nodejs exit handler: production=${isProductionMode}`);
|
|
154
|
+
process.on('SIGINT', () => signal_handler('SIGINT'));
|
|
155
|
+
process.on('SIGTERM', () => signal_handler('SIGTERM'));
|
|
156
|
+
function signal_handler(signal) {
|
|
157
|
+
setImmediate(() => {
|
|
158
|
+
uniqueErrorHandler(new InterruptError(signal, signal_handler), logger);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
125
161
|
process.on('beforeExit', (code) => {
|
|
126
162
|
// empty handler prevent real exit
|
|
127
|
-
|
|
163
|
+
if (!isProductionMode)
|
|
164
|
+
logger.verbose?.(`process: beforeExit: ${code}`);
|
|
165
|
+
if (process.exitCode === undefined || process.exitCode === '') {
|
|
166
|
+
code = ExitCode.EXECUTION;
|
|
167
|
+
logger.output(`${prefix}beforeExit called, but process.exitCode has not been set, switch to ${code}`);
|
|
168
|
+
}
|
|
169
|
+
_shutdown_graceful(code);
|
|
128
170
|
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
171
|
+
function finalThrow(e) {
|
|
172
|
+
try {
|
|
173
|
+
uniqueErrorHandler(e, logger);
|
|
174
|
+
if (e.cause instanceof ErrorWithCode) {
|
|
175
|
+
if (!isProductionMode)
|
|
176
|
+
logger.verbose?.(`finalThrow: got code: ${e.cause.code}`);
|
|
177
|
+
_shutdown_graceful(e.cause.code);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
if (!isProductionMode)
|
|
181
|
+
logger.verbose?.(`finalThrow: not got code: ${e.cause} `);
|
|
182
|
+
_shutdown_graceful(ExitCode.PROGRAM);
|
|
183
|
+
}
|
|
132
184
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
185
|
+
catch (ee) {
|
|
186
|
+
if (ee instanceof Exit) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
prettyPrintError('Exception while handling error', ee);
|
|
190
|
+
shutdown_immediate(ExitCode.PROGRAM);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
194
|
+
finalThrow(new UnhandledRejection(reason, promise));
|
|
136
195
|
});
|
|
137
|
-
const processMdl = createRequire(import.meta.url)('node:process');
|
|
138
|
-
processMdl.exit = shutdown;
|
|
139
|
-
syncBuiltinESMExports();
|
|
140
196
|
function uncaughtException(error) {
|
|
141
|
-
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
if (hasInspect)
|
|
145
|
-
debugger;
|
|
146
|
-
callErrorHandler(new UncaughtException(error));
|
|
197
|
+
finalThrow(new UncaughtException(error));
|
|
147
198
|
}
|
|
148
199
|
if (process.hasUncaughtExceptionCaptureCallback()) {
|
|
149
200
|
process.on('uncaughtException', uncaughtException);
|
|
150
201
|
throw new Error(`${prefix} [uncaught exception capture] callback already registered by other module`);
|
|
151
202
|
}
|
|
152
203
|
process.setUncaughtExceptionCaptureCallback(uncaughtException);
|
|
204
|
+
process.exit = shutdown;
|
|
205
|
+
syncBuiltinESMExports();
|
|
153
206
|
return true;
|
|
154
207
|
}
|
|
155
208
|
/**
|
|
@@ -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,kBAAkB,GAA6B,OAAO,CAAC,IAAI,CAAC;AAClE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,EAAE,IAAI,OAAO,CAAC,GAAG,IAAI,CAAC;AAE1E,SAAS,KAAK;IACb,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,KAAK,MAAM,EAAE,CAAC;QAC/C,OAAO,OAAO,CAAC,KAAK,CAAC;IACtB,CAAC;IACD,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,MAAM,CAAC;AAClD,CAAC;AAED,SAAS,cAAc;IACtB,OAAO,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ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AAG,MAAM,2EAA2E,CAAC,CAAC;IACvG,CAAC;IACD,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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