@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.
Files changed (50) hide show
  1. package/lib/asyncLoad.d.ts +1 -0
  2. package/lib/asyncLoad.d.ts.map +1 -1
  3. package/lib/asyncLoad.js +3 -2
  4. package/lib/asyncLoad.js.map +1 -1
  5. package/lib/autoindex.d.ts +16 -28
  6. package/lib/autoindex.d.ts.map +1 -1
  7. package/lib/autoindex.js +29 -45
  8. package/lib/autoindex.js.map +1 -1
  9. package/lib/child_process/respawn.d.ts +2 -0
  10. package/lib/child_process/respawn.d.ts.map +1 -1
  11. package/lib/child_process/respawn.js +2 -0
  12. package/lib/child_process/respawn.js.map +1 -1
  13. package/lib/fs/exists.js +1 -1
  14. package/lib/fs/exists.js.map +1 -1
  15. package/lib/lifecycle/register.d.ts +6 -2
  16. package/lib/lifecycle/register.d.ts.map +1 -1
  17. package/lib/lifecycle/register.js +127 -74
  18. package/lib/lifecycle/register.js.map +1 -1
  19. package/lib/lifecycle/workingDirectory.d.ts +11 -0
  20. package/lib/lifecycle/workingDirectory.d.ts.map +1 -0
  21. package/lib/lifecycle/workingDirectory.js +40 -0
  22. package/lib/lifecycle/workingDirectory.js.map +1 -0
  23. package/lib/tsconfig.tsbuildinfo +1 -1
  24. package/package.json +7 -8
  25. package/src/asyncLoad.ts +3 -2
  26. package/src/autoindex.ts +33 -52
  27. package/src/child_process/respawn.ts +2 -0
  28. package/src/fs/exists.ts +1 -1
  29. package/src/lifecycle/register.ts +127 -77
  30. package/src/lifecycle/workingDirectory.ts +45 -0
  31. package/lib/error/linux.d.ts +0 -125
  32. package/lib/error/linux.d.ts.map +0 -1
  33. package/lib/error/linux.js +0 -126
  34. package/lib/error/linux.js.map +0 -1
  35. package/lib/error/types.d.ts +0 -24
  36. package/lib/error/types.d.ts.map +0 -1
  37. package/lib/error/types.js +0 -25
  38. package/lib/error/types.js.map +0 -1
  39. package/lib/lifecycle/internal-errors.d.ts +0 -23
  40. package/lib/lifecycle/internal-errors.d.ts.map +0 -1
  41. package/lib/lifecycle/internal-errors.js +0 -60
  42. package/lib/lifecycle/internal-errors.js.map +0 -1
  43. package/lib/preload.d.ts +0 -2
  44. package/lib/preload.d.ts.map +0 -1
  45. package/lib/preload.js +0 -2
  46. package/lib/preload.js.map +0 -1
  47. package/src/error/linux.ts +0 -124
  48. package/src/error/types.ts +0 -39
  49. package/src/lifecycle/internal-errors.ts +0 -66
  50. package/src/preload.ts +0 -1
package/src/autoindex.ts CHANGED
@@ -6,8 +6,6 @@
6
6
  // Identifiers
7
7
  export type { AsyncMainFunction } from "./asyncLoad.js";
8
8
  export { executeMainFunction } from "./asyncLoad.js";
9
- /* preload.ts */
10
- // Identifiers
11
9
  /* child_process/error.ts */
12
10
  // Identifiers
13
11
  export { checkChildProcessResult } from "./child_process/error.js";
@@ -19,60 +17,41 @@
19
17
  export { spawnGetOutputSync } from "./child_process/execa.js";
20
18
  export { spawnGetOutput } from "./child_process/execa.js";
21
19
  export { spawnGetEverything } from "./child_process/execa.js";
22
- /* cli-io/output.ts */
23
- // Identifiers
24
- export { printLine } from "./cli-io/output.js";
25
20
  /* child_process/lateError.ts */
26
21
  // Identifiers
27
22
  export type { ISpawnOptions } from "./child_process/lateError.js";
28
23
  export type { ExecaReturnValue } from "./child_process/lateError.js";
29
24
  export { execLazyError } from "./child_process/lateError.js";
30
- /* error/linux.ts */
31
- // Identifiers
32
- export { LinuxError } from "./error/linux.js";
33
- /* error/types.ts */
34
- // Identifiers
35
- export type { OpenSSLException } from "./error/types.js";
36
- export { isModuleResolutionError } from "./error/types.js";
37
- export { isNotExistsError } from "./error/types.js";
38
- export { isExistsError } from "./error/types.js";
39
- export { isTypeError } from "./error/types.js";
40
- export { isFileTypeError } from "./error/types.js";
41
- export { isNodeError } from "./error/types.js";
42
- // References
43
- export * from "@idlebox/node-error-codes";
44
- /* fs/exists.ts */
45
- // Identifiers
46
- export { existsSync } from "./fs/exists.js";
47
- export { exists } from "./fs/exists.js";
48
- export { readFileIfExists } from "./fs/exists.js";
49
- /* environment/getEnvironment.ts */
50
- // Identifiers
51
- export type { IEnvironmentResult } from "./environment/getEnvironment.js";
52
- export { getEnvironment } from "./environment/getEnvironment.js";
53
- export { deleteEnvironment } from "./environment/getEnvironment.js";
54
- export { cleanupEnvironment } from "./environment/getEnvironment.js";
55
- /* environment/pathEnvironment.ts */
56
- // Identifiers
57
- export { PATH_SEPARATOR } from "./environment/pathEnvironment.js";
58
- export { PathEnvironment } from "./environment/pathEnvironment.js";
59
- /* environment/findBinary.ts */
60
- // Identifiers
61
- export { findBinary } from "./environment/findBinary.js";
62
25
  /* child_process/respawn.ts */
63
26
  // Identifiers
64
27
  export { spawnRecreateEventHandlers } from "./child_process/respawn.js";
65
28
  export { trySpawnInScope } from "./child_process/respawn.js";
66
29
  export { respawnInScope } from "./child_process/respawn.js";
30
+ /* cli-io/output.ts */
31
+ // Identifiers
32
+ export { printLine } from "./cli-io/output.js";
67
33
  /* crypto/md5.ts */
68
34
  // Identifiers
69
35
  export { md5 } from "./crypto/md5.js";
70
36
  /* crypto/sha256.ts */
71
37
  // Identifiers
72
38
  export { sha256 } from "./crypto/sha256.js";
39
+ /* environment/findBinary.ts */
40
+ // Identifiers
41
+ export { findBinary } from "./environment/findBinary.js";
42
+ /* environment/getEnvironment.ts */
43
+ // Identifiers
44
+ export type { IEnvironmentResult } from "./environment/getEnvironment.js";
45
+ export { getEnvironment } from "./environment/getEnvironment.js";
46
+ export { deleteEnvironment } from "./environment/getEnvironment.js";
47
+ export { cleanupEnvironment } from "./environment/getEnvironment.js";
73
48
  /* environment/npmConfig.ts */
74
49
  // Identifiers
75
50
  export { getNpmConfigValue } from "./environment/npmConfig.js";
51
+ /* environment/pathEnvironment.ts */
52
+ // Identifiers
53
+ export { PATH_SEPARATOR } from "./environment/pathEnvironment.js";
54
+ export { PathEnvironment } from "./environment/pathEnvironment.js";
76
55
  /* events/dumpEventEmitter.ts */
77
56
  // Identifiers
78
57
  export { dumpEventEmitterEmit } from "./events/dumpEventEmitter.js";
@@ -87,6 +66,11 @@
87
66
  // Identifiers
88
67
  export { ensureDirExists } from "./fs/ensureDir.js";
89
68
  export { ensureParentExists } from "./fs/ensureDir.js";
69
+ /* fs/exists.ts */
70
+ // Identifiers
71
+ export { existsSync } from "./fs/exists.js";
72
+ export { exists } from "./fs/exists.js";
73
+ export { readFileIfExists } from "./fs/exists.js";
90
74
  /* fs/tempFolder.ts */
91
75
  // Identifiers
92
76
  export { createTempFolder } from "./fs/tempFolder.js";
@@ -94,23 +78,23 @@
94
78
  // Identifiers
95
79
  export { writeFileIfChangeSync } from "./fs/weiteChanged.js";
96
80
  export { writeFileIfChange } from "./fs/weiteChanged.js";
97
- /* lifecycle/internal-errors.ts */
98
- // Identifiers
99
- export { Exit } from "./lifecycle/internal-errors.js";
100
- export { InterruptError } from "./lifecycle/internal-errors.js";
101
- export { UnhandledRejection } from "./lifecycle/internal-errors.js";
102
- export { UncaughtException } from "./lifecycle/internal-errors.js";
103
81
  /* lifecycle/register.ts */
104
82
  // Identifiers
105
- export { setAbnormalExitCode } from "./lifecycle/register.js";
83
+ export { setExitCodeIfNot } from "./lifecycle/register.js";
106
84
  export { shutdown } from "./lifecycle/register.js";
107
85
  export { registerNodejsGlobalTypedErrorHandlerWithInheritance } from "./lifecycle/register.js";
108
86
  export { registerNodejsGlobalTypedErrorHandler } from "./lifecycle/register.js";
109
87
  export { registerNodejsExitHandler } from "./lifecycle/register.js";
110
88
  export { die } from "./lifecycle/register.js";
89
+ /* lifecycle/workingDirectory.ts */
90
+ // Identifiers
91
+ export { workingDirectory } from "./lifecycle/workingDirectory.js";
111
92
  /* log/terminal.ts */
112
93
  // Identifiers
113
94
  export { WrappedTerminalConsole } from "./log/terminal.js";
95
+ /* path-resolve/findPackageRoot.ts */
96
+ // Identifiers
97
+ export { findPackageRoot } from "./path-resolve/findPackageRoot.js";
114
98
  /* path-resolve/findUp.ts */
115
99
  // Identifiers
116
100
  export type { IFindOptions } from "./path-resolve/findUp.js";
@@ -118,9 +102,6 @@
118
102
  export { findUp } from "./path-resolve/findUp.js";
119
103
  export { findUpUntilSync } from "./path-resolve/findUp.js";
120
104
  export { findUpSync } from "./path-resolve/findUp.js";
121
- /* path-resolve/findPackageRoot.ts */
122
- // Identifiers
123
- export { findPackageRoot } from "./path-resolve/findPackageRoot.js";
124
105
  /* path-resolve/getAllUp.ts */
125
106
  // Identifiers
126
107
  export { getAllPathUpToRoot } from "./path-resolve/getAllUp.js";
@@ -142,10 +123,6 @@
142
123
  /* stream/blackHoleStream.ts */
143
124
  // Identifiers
144
125
  export { BlackHoleStream } from "./stream/blackHoleStream.js";
145
- /* stream/streamPromise.ts */
146
- // Identifiers
147
- export { streamPromise } from "./stream/streamPromise.js";
148
- export { streamHasEnd } from "./stream/streamPromise.js";
149
126
  /* stream/collectingStream.ts */
150
127
  // Identifiers
151
128
  export { streamToBuffer } from "./stream/collectingStream.js";
@@ -161,4 +138,8 @@
161
138
  // Identifiers
162
139
  export type { LogFunction } from "./stream/loggerStream.js";
163
140
  export { LoggerStream } from "./stream/loggerStream.js";
164
- export { HexDumpLoggerStream } from "./stream/loggerStream.js";
141
+ export { HexDumpLoggerStream } from "./stream/loggerStream.js";
142
+ /* stream/streamPromise.ts */
143
+ // Identifiers
144
+ export { streamPromise } from "./stream/streamPromise.js";
145
+ export { streamHasEnd } from "./stream/streamPromise.js";
@@ -9,6 +9,7 @@ if (platform() === 'linux' && process.getuid?.() !== 0) {
9
9
  unshareArgs.push('--map-root-user');
10
10
  }
11
11
 
12
+ /** @deprecated */
12
13
  export function spawnRecreateEventHandlers() {
13
14
  process.on('SIGINT', () => shutdown_quit('SIGINT', 130));
14
15
  process.on('SIGTERM', () => shutdown_quit('SIGTERM', 143));
@@ -26,6 +27,7 @@ function shutdown_quit(signal: string, code: number) {
26
27
  /**
27
28
  * Spawn a command, replace current node process
28
29
  * If can't do that (eg. on Windows), spawn as normal, but quit self after it quit.
30
+ * @deprecated
29
31
  */
30
32
  export function trySpawnInScope(cmds: string[]): never {
31
33
  if (process.env.NEVER_UNSHARE || !process.execve || insideScope() || !supportScope()) {
package/src/fs/exists.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { ObjectEncodingOptions } from 'node:fs';
2
2
  import { access, readFile } from 'node:fs/promises';
3
- import { isNotExistsError } from '../error/types.js';
3
+ import { isNotExistsError } from '@idlebox/errors';
4
4
  export { existsSync } from 'node:fs';
5
5
 
6
6
  export async function exists(path: string) {
@@ -1,23 +1,15 @@
1
1
  /** biome-ignore-all lint/suspicious/noDebugger: debug file */
2
2
 
3
- import { AppExit, ensureDisposeGlobal, ensureGlobalObject, prettyPrintError, type MyCallback } from '@idlebox/common';
3
+ import { ensureDisposeGlobal, ensureGlobalObject, functionName, isProductionMode, prettyPrintError, type MyCallback } from '@idlebox/common';
4
+ import { ErrorWithCode, Exit, ExitCode, InterruptError, UncaughtException, UnhandledRejection } from '@idlebox/errors';
4
5
  import assert from 'node:assert';
5
- import { createRequire, syncBuiltinESMExports } from 'node:module';
6
+ import { syncBuiltinESMExports } from 'node:module';
6
7
  import { basename } from 'node:path';
7
8
  import process from 'node:process';
8
- import { Exit, InterruptError, UncaughtException, UnhandledRejection } from './internal-errors.js';
9
+ import { inspect } from 'node:util';
9
10
 
10
- const originalExit: (code?: number) => never = process.exit;
11
+ const shutdown_immediate: (code?: number) => never = process.exit;
11
12
  const prefix = process.stderr.isTTY ? '' : `<${title()} ${process.pid}> `;
12
- const hasInspect = process.argv.some((arg) => arg.startsWith('--inspect=') || arg.startsWith('--inspect-brk=') || arg === '--inspect' || arg === '--inspect-brk');
13
-
14
- let abnormalExitCode = 1;
15
- export function setAbnormalExitCode(code: number) {
16
- if (code < 1) {
17
- throw new TypeError(`abnormal exit code must be greater than 0, got ${code}`);
18
- }
19
- abnormalExitCode = code;
20
- }
21
13
 
22
14
  function title() {
23
15
  if (process.title && process.title !== 'node') {
@@ -30,22 +22,29 @@ function getCurrentCode() {
30
22
  return typeof process.exitCode === 'string' ? parseInt(process.exitCode) : process.exitCode || 0;
31
23
  }
32
24
 
33
- let shuttingDown = false;
34
- export function shutdown(exitCode: number): never {
35
- if (hasInspect) debugger;
36
-
37
- if (exitCode) {
25
+ export function setExitCodeIfNot(exitCode: number) {
26
+ if (exitCode || typeof process.exitCode !== 'number') {
38
27
  process.exitCode = exitCode;
28
+ globalThis.process.exitCode = exitCode;
39
29
  }
30
+ }
31
+
32
+ let shuttingDown = 0;
33
+ export function shutdown(exitCode: number): never {
34
+ _shutdown_graceful(exitCode);
35
+ throw new Exit(getCurrentCode());
36
+ }
37
+ function _shutdown_graceful(exitCode: number) {
38
+ setExitCodeIfNot(exitCode);
40
39
 
41
40
  if (!shuttingDown) {
42
- shuttingDown = true;
41
+ shuttingDown = 1;
43
42
  ensureDisposeGlobal().finally(() => {
44
- originalExit(getCurrentCode());
43
+ shutdown_immediate(getCurrentCode());
45
44
  });
45
+ } else {
46
+ shuttingDown++;
46
47
  }
47
-
48
- throw new Exit(getCurrentCode());
49
48
  }
50
49
 
51
50
  const typed_error_handlers = new WeakMap<ErrorConstructor, MyCallback<[Error]>>();
@@ -68,21 +67,41 @@ export function registerNodejsGlobalTypedErrorHandler(ErrorCls: ErrorConstructor
68
67
  typed_error_handlers.set(ErrorCls, fn);
69
68
  }
70
69
 
71
- function callErrorHandler(e: unknown) {
72
- if (!(e instanceof Error)) {
73
- prettyPrintError(`${prefix}catch unexpect object`, new Error(`error object is ${typeof e} ${e ? (e as any).constructor?.name : 'unknown'}`));
74
- throw originalExit(abnormalExitCode);
70
+ function _root_cause(e: Error) {
71
+ if (e.cause instanceof Error) {
72
+ return _root_cause(e.cause);
73
+ }
74
+ return e;
75
+ }
76
+
77
+ function uniqueErrorHandler(currentError: unknown, logger: IDebugOutput) {
78
+ if (!isProductionMode) logger.verbose?.(`uniqueErrorHandler:`);
79
+ if (!(currentError instanceof Error)) {
80
+ prettyPrintError(
81
+ `${prefix}catch unexpect object`,
82
+ new Error(`error object is ${typeof currentError} ${currentError ? (currentError as any).constructor?.name : 'unknown'}`),
83
+ );
84
+ throw shutdown_immediate(ExitCode.PROGRAM);
85
+ }
86
+
87
+ const rootCause = _root_cause(currentError);
88
+ if (rootCause instanceof Exit) {
89
+ if (!isProductionMode) logger.verbose?.(` - skip exit object`);
90
+ if (!shuttingDown) _shutdown_graceful(rootCause.code);
91
+ throw rootCause;
75
92
  }
76
93
 
77
94
  try {
78
- const catcher = typed_error_handlers.get(e.constructor as ErrorConstructor);
95
+ const catcher = typed_error_handlers.get(rootCause.constructor as ErrorConstructor);
79
96
  if (catcher) {
80
- catcher(e);
97
+ if (!isProductionMode) logger.verbose?.(` - call catcher ${functionName(catcher)}`);
98
+ catcher(rootCause);
81
99
  return;
82
100
  }
83
101
  for (const [Cls, fn] of inherit_error_handlers) {
84
- if (e instanceof Cls) {
85
- fn(e);
102
+ if (!isProductionMode) logger.verbose?.(` - call inherited catcher ${functionName(fn)}`);
103
+ if (rootCause instanceof Cls) {
104
+ fn(rootCause);
86
105
  return;
87
106
  }
88
107
  }
@@ -90,79 +109,107 @@ function callErrorHandler(e: unknown) {
90
109
  prettyPrintError(`${prefix}error while handle error`, {
91
110
  message: ee.message,
92
111
  stack: ee.stack,
93
- cause: e,
112
+ cause: rootCause,
94
113
  });
95
114
  return;
96
115
  }
97
116
 
98
- if (e instanceof InterruptError) {
99
- if (shuttingDown) {
100
- console.error(`${prefix}Exiting immediately.`);
101
- originalExit(1);
102
- }
117
+ if (rootCause instanceof InterruptError) {
118
+ if (!isProductionMode) logger.verbose?.(` - shuttingDown = ${shuttingDown}`);
103
119
 
104
- shutdown(0);
105
- }
106
- if (e instanceof AppExit) {
107
- ensureDisposeGlobal().finally(() => {
108
- originalExit(getCurrentCode());
109
- });
120
+ const signal = rootCause.signal;
121
+ if (signal === 'SIGINT') {
122
+ process.stderr.write(shuttingDown === 0 ? '\n' : '\r');
123
+ }
124
+ if (shuttingDown > 4) {
125
+ logger.output(`${prefix}Received ${signal} more than 5 times. Exiting immediately.`);
126
+ shutdown_immediate(ExitCode.INTERRUPT);
127
+ } else if (shuttingDown > 0) {
128
+ logger.output(`${prefix}Received ${signal} ${shuttingDown + 1} times.`);
129
+ } else {
130
+ logger.output(`${prefix}Received ${signal}. Exiting gracefully...`);
131
+ }
132
+ shutdown(ExitCode.INTERRUPT);
110
133
  }
111
- if (e instanceof UncaughtException) {
112
- if (e.cause instanceof Error) {
113
- prettyPrintError(`${prefix}Unhandled Rejection`, e.cause);
134
+ if (currentError instanceof UnhandledRejection) {
135
+ if (!isProductionMode) logger.verbose?.(` - UnhandledRejection`);
136
+ if (rootCause !== currentError) {
137
+ prettyPrintError(`${prefix}Unhandled Rejection`, currentError.cause);
114
138
  } else {
115
- console.error(`${prefix}Unhandled Rejection / error type unknown:`, e.cause);
139
+ logger.output(`${prefix}Unhandled Rejection / error type unknown: ${inspect(currentError.cause)}`);
116
140
  }
117
- shutdown(abnormalExitCode);
141
+ return;
118
142
  }
119
- if (e instanceof UncaughtException) {
120
- prettyPrintError(`${prefix}Uncaught Exception`, e.cause);
121
- shutdown(abnormalExitCode);
143
+ if (currentError instanceof UncaughtException) {
144
+ if (!isProductionMode) logger.verbose?.(` - UncaughtException`);
145
+ prettyPrintError(`${prefix}Uncaught Exception`, rootCause);
146
+ return;
122
147
  }
148
+
149
+ if (!isProductionMode) logger.verbose?.(` - common error`);
150
+ prettyPrintError(`${prefix}unhandled global exception`, currentError);
151
+ shutdown(ExitCode.PROGRAM);
152
+ }
153
+
154
+ interface IDebugOutput {
155
+ output(message: string): void;
156
+ verbose?(message: string): void;
123
157
  }
124
158
 
125
159
  /**
126
160
  * 注册nodejs退出处理器
127
161
  */
128
- export function registerNodejsExitHandler() {
129
- ensureGlobalObject('exithandler/register', _real_register);
162
+ export function registerNodejsExitHandler(logger: IDebugOutput = { output: console.error }) {
163
+ ensureGlobalObject('exithandler/register', () => _real_register(logger));
130
164
  }
131
- function _real_register() {
132
- process.on('SIGINT', () => {
133
- console.error(`\n${prefix}Received SIGINT. Exiting gracefully...`);
134
- callErrorHandler(new InterruptError('SIGINT'));
135
- });
165
+ function _real_register(logger: IDebugOutput) {
166
+ logger.verbose?.(`register nodejs exit handler: production=${isProductionMode}`);
136
167
 
137
- process.on('SIGTERM', () => {
138
- console.error(`${prefix}Received SIGTERM. Exiting gracefully...`);
139
- callErrorHandler(new InterruptError('SIGTERM'));
140
- });
168
+ process.on('SIGINT', () => signal_handler('SIGINT'));
169
+ process.on('SIGTERM', () => signal_handler('SIGTERM'));
170
+
171
+ function signal_handler(signal: 'SIGINT' | 'SIGTERM') {
172
+ setImmediate(() => {
173
+ uniqueErrorHandler(new InterruptError(signal, signal_handler), logger);
174
+ });
175
+ }
141
176
 
142
177
  process.on('beforeExit', (code) => {
143
178
  // empty handler prevent real exit
144
- shutdown(code);
145
- });
146
-
147
- process.on('unhandledRejection', (reason, promise) => {
148
- if (reason instanceof AppExit) {
149
- return;
179
+ if (!isProductionMode) logger.verbose?.(`process: beforeExit: ${code}`);
180
+ if (process.exitCode === undefined || process.exitCode === '') {
181
+ code = ExitCode.EXECUTION;
182
+ logger.output(`${prefix}beforeExit called, but process.exitCode has not been set, switch to ${code}`);
150
183
  }
151
- if (hasInspect) debugger;
152
- callErrorHandler(new UnhandledRejection(reason, promise));
184
+ _shutdown_graceful(code);
153
185
  });
154
186
 
155
- const processMdl = createRequire(import.meta.url)('node:process');
156
- processMdl.exit = shutdown;
157
- syncBuiltinESMExports();
187
+ function finalThrow(e: UnhandledRejection | UncaughtException) {
188
+ try {
189
+ uniqueErrorHandler(e, logger);
158
190
 
159
- function uncaughtException(error: Error): void {
160
- if (error instanceof AppExit) {
161
- return;
191
+ if (e.cause instanceof ErrorWithCode) {
192
+ if (!isProductionMode) logger.verbose?.(`finalThrow: got code: ${e.cause.code}`);
193
+ _shutdown_graceful(e.cause.code);
194
+ } else {
195
+ if (!isProductionMode) logger.verbose?.(`finalThrow: not got code: ${e.cause} `);
196
+ _shutdown_graceful(ExitCode.PROGRAM);
197
+ }
198
+ } catch (ee: any) {
199
+ if (ee instanceof Exit) {
200
+ return;
201
+ }
202
+ prettyPrintError('Exception while handling error', ee);
203
+ shutdown_immediate(ExitCode.PROGRAM);
162
204
  }
163
- if (hasInspect) debugger;
205
+ }
164
206
 
165
- callErrorHandler(new UncaughtException(error));
207
+ process.on('unhandledRejection', (reason, promise) => {
208
+ finalThrow(new UnhandledRejection(reason, promise));
209
+ });
210
+
211
+ function uncaughtException(error: Error): void {
212
+ finalThrow(new UncaughtException(error));
166
213
  }
167
214
 
168
215
  if (process.hasUncaughtExceptionCaptureCallback()) {
@@ -171,6 +218,9 @@ function _real_register() {
171
218
  }
172
219
  process.setUncaughtExceptionCaptureCallback(uncaughtException);
173
220
 
221
+ process.exit = shutdown;
222
+ syncBuiltinESMExports();
223
+
174
224
  return true;
175
225
  }
176
226
 
@@ -0,0 +1,45 @@
1
+ import { noop, vscEscapeValue } from '@idlebox/common';
2
+ import { syncBuiltinESMExports } from 'node:module';
3
+ import process from 'node:process';
4
+
5
+ const originalChdir = process.chdir;
6
+ const originalCwd = process.cwd;
7
+
8
+ let currentEnvironmentChdir = originalChdir;
9
+ const currentEnvironmentCwd = originalCwd;
10
+ let patch = noop;
11
+
12
+ const wd = {
13
+ cwd() {
14
+ return currentEnvironmentCwd();
15
+ },
16
+ chdir(dir: string) {
17
+ currentEnvironmentChdir(dir);
18
+ },
19
+ patchGlobal() {
20
+ patch();
21
+ wd.cwd = currentEnvironmentCwd;
22
+ wd.chdir = currentEnvironmentChdir;
23
+ wd.patchGlobal = noop;
24
+ },
25
+ escapeVscodeCwd,
26
+ isVscodeShellIntegration: process.env.VSCODE_SHELL_INTEGRATION || process.env.VSCODE_SHELL_INTEGRATION_SHELL_SCRIPT,
27
+ };
28
+
29
+ export const workingDirectory: Readonly<typeof wd> = wd;
30
+
31
+ function escapeVscodeCwd(path: string) {
32
+ return `\x1B]633;P;Cwd=${vscEscapeValue(path)}\x07`;
33
+ }
34
+
35
+ if (wd.isVscodeShellIntegration) {
36
+ currentEnvironmentChdir = (newRoot: string) => {
37
+ process.stderr.write(escapeVscodeCwd(newRoot));
38
+ originalChdir(newRoot);
39
+ };
40
+ patch = () => {
41
+ process.chdir = currentEnvironmentChdir;
42
+ globalThis.process.chdir = currentEnvironmentChdir;
43
+ syncBuiltinESMExports();
44
+ };
45
+ }
@@ -1,125 +0,0 @@
1
- export declare enum LinuxError {
2
- EPERM = "EPERM",
3
- ENOENT = "ENOENT",
4
- ESRCH = "ESRCH",
5
- EINTR = "EINTR",
6
- EIO = "EIO",
7
- ENXIO = "ENXIO",
8
- E2BIG = "E2BIG",
9
- ENOEXEC = "ENOEXEC",
10
- EBADF = "EBADF",
11
- ECHILD = "ECHILD",
12
- EAGAIN = "EAGAIN",
13
- ENOMEM = "ENOMEM",
14
- EACCES = "EACCES",
15
- EFAULT = "EFAULT",
16
- ENOTBLK = "ENOTBLK",
17
- EBUSY = "EBUSY",
18
- EEXIST = "EEXIST",
19
- EXDEV = "EXDEV",
20
- ENODEV = "ENODEV",
21
- ENOTDIR = "ENOTDIR",
22
- EISDIR = "EISDIR",
23
- EINVAL = "EINVAL",
24
- ENFILE = "ENFILE",
25
- EMFILE = "EMFILE",
26
- ENOTTY = "ENOTTY",
27
- ETXTBSY = "ETXTBSY",
28
- EFBIG = "EFBIG",
29
- ENOSPC = "ENOSPC",
30
- ESPIPE = "ESPIPE",
31
- EROFS = "EROFS",
32
- EMLINK = "EMLINK",
33
- EPIPE = "EPIPE",
34
- EDOM = "EDOM",
35
- ERANGE = "ERANGE",
36
- ENOMSG = "ENOMSG",
37
- EIDRM = "EIDRM",
38
- ECHRNG = "ECHRNG",
39
- EL2NSYNC = "EL2NSYNC",
40
- EL3HLT = "EL3HLT",
41
- EL3RST = "EL3RST",
42
- ELNRNG = "ELNRNG",
43
- EUNATCH = "EUNATCH",
44
- ENOCSI = "ENOCSI",
45
- EL2HLT = "EL2HLT",
46
- EDEADLK = "EDEADLK",
47
- ENOLCK = "ENOLCK",
48
- EBADE = "EBADE",
49
- EBADR = "EBADR",
50
- EXFULL = "EXFULL",
51
- ENOANO = "ENOANO",
52
- EBADRQC = "EBADRQC",
53
- EBADSLT = "EBADSLT",
54
- EDEADLOCK = "EDEADLOCK",
55
- EBFONT = "EBFONT",
56
- ENOSTR = "ENOSTR",
57
- ENODATA = "ENODATA",
58
- ETIME = "ETIME",
59
- ENOSR = "ENOSR",
60
- ENONET = "ENONET",
61
- ENOPKG = "ENOPKG",
62
- EREMOTE = "EREMOTE",
63
- ENOLINK = "ENOLINK",
64
- EADV = "EADV",
65
- ESRMNT = "ESRMNT",
66
- ECOMM = "ECOMM",
67
- EPROTO = "EPROTO",
68
- EMULTIHOP = "EMULTIHOP",
69
- ELBIN = "ELBIN",
70
- EDOTDOT = "EDOTDOT",
71
- EBADMSG = "EBADMSG",
72
- EFTYPE = "EFTYPE",
73
- ENOTUNIQ = "ENOTUNIQ",
74
- EBADFD = "EBADFD",
75
- EREMCHG = "EREMCHG",
76
- ELIBACC = "ELIBACC",
77
- ELIBBAD = "ELIBBAD",
78
- ELIBSCN = "ELIBSCN",
79
- ELIBMAX = "ELIBMAX",
80
- ELIBEXEC = "ELIBEXEC",
81
- ENOSYS = "ENOSYS",
82
- ENMFILE = "ENMFILE",
83
- ENOTEMPTY = "ENOTEMPTY",
84
- ENAMETOOLONG = "ENAMETOOLONG",
85
- ELOOP = "ELOOP",
86
- EOPNOTSUPP = "EOPNOTSUPP",
87
- EPFNOSUPPORT = "EPFNOSUPPORT",
88
- ECONNRESET = "ECONNRESET",
89
- ENOBUFS = "ENOBUFS",
90
- EAFNOSUPPORT = "EAFNOSUPPORT",
91
- EPROTOTYPE = "EPROTOTYPE",
92
- ENOTSOCK = "ENOTSOCK",
93
- ENOPROTOOPT = "ENOPROTOOPT",
94
- ESHUTDOWN = "ESHUTDOWN",
95
- ECONNREFUSED = "ECONNREFUSED",
96
- EADDRINUSE = "EADDRINUSE",
97
- ECONNABORTED = "ECONNABORTED",
98
- ENETUNREACH = "ENETUNREACH",
99
- ENETDOWN = "ENETDOWN",
100
- ETIMEDOUT = "ETIMEDOUT",
101
- EHOSTDOWN = "EHOSTDOWN",
102
- EHOSTUNREACH = "EHOSTUNREACH",
103
- EINPROGRESS = "EINPROGRESS",
104
- EALREADY = "EALREADY",
105
- EDESTADDRREQ = "EDESTADDRREQ",
106
- EMSGSIZE = "EMSGSIZE",
107
- EPROTONOSUPPORT = "EPROTONOSUPPORT",
108
- ESOCKTNOSUPPORT = "ESOCKTNOSUPPORT",
109
- EADDRNOTAVAIL = "EADDRNOTAVAIL",
110
- ENETRESET = "ENETRESET",
111
- EISCONN = "EISCONN",
112
- ENOTCONN = "ENOTCONN",
113
- ETOOMANYREFS = "ETOOMANYREFS",
114
- EPROCLIM = "EPROCLIM",
115
- EUSERS = "EUSERS",
116
- EDQUOT = "EDQUOT",
117
- ESTALE = "ESTALE",
118
- ENOTSUP = "ENOTSUP",
119
- ENOMEDIUM = "ENOMEDIUM",
120
- ENOSHARE = "ENOSHARE",
121
- ECASECLASH = "ECASECLASH",
122
- EILSEQ = "EILSEQ",
123
- EOVERFLOW = "EOVERFLOW"
124
- }
125
- //# sourceMappingURL=linux.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"linux.d.ts","sourceRoot":"","sources":["../../src/error/linux.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IACrB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,GAAG,QAAQ;IACX,KAAK,UAAU;IACf,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,MAAM,WAAW;IACjB,SAAS,cAAc;IACvB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,YAAY,iBAAiB;IAC7B,KAAK,UAAU;IACf,UAAU,eAAe;IACzB,YAAY,iBAAiB;IAC7B,UAAU,eAAe;IACzB,OAAO,YAAY;IACnB,YAAY,iBAAiB;IAC7B,UAAU,eAAe;IACzB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,SAAS,cAAc;IACvB,YAAY,iBAAiB;IAC7B,UAAU,eAAe;IACzB,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAC3B,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;IAC3B,QAAQ,aAAa;IACrB,YAAY,iBAAiB;IAC7B,QAAQ,aAAa;IACrB,eAAe,oBAAoB;IACnC,eAAe,oBAAoB;IACnC,aAAa,kBAAkB;IAC/B,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,YAAY,iBAAiB;IAC7B,QAAQ,aAAa;IACrB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,UAAU,eAAe;IACzB,MAAM,WAAW;IACjB,SAAS,cAAc;CACvB"}