@veryfront/ext-observability-opentelemetry 0.1.1032 → 0.1.1035
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/esm/_dnt.polyfills.d.ts +7 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +1 -0
- package/esm/deno.d.ts +440 -0
- package/esm/deno.d.ts.map +1 -0
- package/esm/deno.js +526 -0
- package/esm/{index.d.ts → extensions/ext-observability-opentelemetry/src/index.d.ts} +21 -0
- package/esm/extensions/ext-observability-opentelemetry/src/index.d.ts.map +1 -0
- package/esm/{index.js → extensions/ext-observability-opentelemetry/src/index.js} +255 -28
- package/esm/src/config/defaults.d.ts +39 -0
- package/esm/src/config/defaults.d.ts.map +1 -0
- package/esm/src/config/defaults.js +65 -0
- package/esm/src/errors/error-registry/agent.d.ts +18 -0
- package/esm/src/errors/error-registry/agent.d.ts.map +1 -0
- package/esm/src/errors/error-registry/agent.js +60 -0
- package/esm/src/errors/error-registry/boundary.d.ts +16 -0
- package/esm/src/errors/error-registry/boundary.d.ts.map +1 -0
- package/esm/src/errors/error-registry/boundary.js +52 -0
- package/esm/src/errors/error-registry/build.d.ts +20 -0
- package/esm/src/errors/error-registry/build.d.ts.map +1 -0
- package/esm/src/errors/error-registry/build.js +68 -0
- package/esm/src/errors/error-registry/config.d.ts +22 -0
- package/esm/src/errors/error-registry/config.d.ts.map +1 -0
- package/esm/src/errors/error-registry/config.js +70 -0
- package/esm/src/errors/error-registry/deploy.d.ts +12 -0
- package/esm/src/errors/error-registry/deploy.d.ts.map +1 -0
- package/esm/src/errors/error-registry/deploy.js +36 -0
- package/esm/src/errors/error-registry/dev.d.ts +14 -0
- package/esm/src/errors/error-registry/dev.d.ts.map +1 -0
- package/esm/src/errors/error-registry/dev.js +44 -0
- package/esm/src/errors/error-registry/general.d.ts +29 -0
- package/esm/src/errors/error-registry/general.d.ts.map +1 -0
- package/esm/src/errors/error-registry/general.js +92 -0
- package/esm/src/errors/error-registry/module.d.ts +16 -0
- package/esm/src/errors/error-registry/module.d.ts.map +1 -0
- package/esm/src/errors/error-registry/module.js +52 -0
- package/esm/src/errors/error-registry/route.d.ts +16 -0
- package/esm/src/errors/error-registry/route.d.ts.map +1 -0
- package/esm/src/errors/error-registry/route.js +52 -0
- package/esm/src/errors/error-registry/runtime.d.ts +18 -0
- package/esm/src/errors/error-registry/runtime.d.ts.map +1 -0
- package/esm/src/errors/error-registry/runtime.js +60 -0
- package/esm/src/errors/error-registry/server.d.ts +39 -0
- package/esm/src/errors/error-registry/server.d.ts.map +1 -0
- package/esm/src/errors/error-registry/server.js +129 -0
- package/esm/src/errors/error-registry-helpers.d.ts +6 -0
- package/esm/src/errors/error-registry-helpers.d.ts.map +1 -0
- package/esm/src/errors/error-registry-helpers.js +9 -0
- package/esm/src/errors/error-registry.d.ts +114 -0
- package/esm/src/errors/error-registry.d.ts.map +1 -0
- package/esm/src/errors/error-registry.js +60 -0
- package/esm/src/errors/types.d.ts +84 -0
- package/esm/src/errors/types.d.ts.map +1 -0
- package/esm/src/errors/types.js +69 -0
- package/esm/src/errors/veryfront-error.d.ts +149 -0
- package/esm/src/errors/veryfront-error.d.ts.map +1 -0
- package/esm/src/errors/veryfront-error.js +61 -0
- package/esm/src/modules/react-loader/ssr-module-loader/concurrency/semaphore.d.ts +13 -0
- package/esm/src/modules/react-loader/ssr-module-loader/concurrency/semaphore.d.ts.map +1 -0
- package/esm/src/modules/react-loader/ssr-module-loader/concurrency/semaphore.js +55 -0
- package/esm/src/observability/tracing/api-shim.d.ts +191 -0
- package/esm/src/observability/tracing/api-shim.d.ts.map +1 -0
- package/esm/src/observability/tracing/api-shim.js +281 -0
- package/esm/src/observability/tracing/otlp-setup.d.ts +61 -0
- package/esm/src/observability/tracing/otlp-setup.d.ts.map +1 -0
- package/esm/src/observability/tracing/otlp-setup.js +213 -0
- package/esm/src/observability/tracing/telemetry-env.d.ts +3 -0
- package/esm/src/observability/tracing/telemetry-env.d.ts.map +1 -0
- package/esm/src/observability/tracing/telemetry-env.js +10 -0
- package/esm/src/platform/adapters/base.d.ts +193 -0
- package/esm/src/platform/adapters/base.d.ts.map +1 -0
- package/esm/src/platform/adapters/base.js +15 -0
- package/esm/src/platform/compat/constants.d.ts +13 -0
- package/esm/src/platform/compat/constants.d.ts.map +1 -0
- package/esm/src/platform/compat/constants.js +12 -0
- package/esm/src/platform/compat/dynamic-import.d.ts +11 -0
- package/esm/src/platform/compat/dynamic-import.d.ts.map +1 -0
- package/esm/src/platform/compat/dynamic-import.js +10 -0
- package/esm/src/platform/compat/fs.d.ts +71 -0
- package/esm/src/platform/compat/fs.d.ts.map +1 -0
- package/esm/src/platform/compat/fs.js +277 -0
- package/esm/src/platform/compat/path/resolution.d.ts +6 -0
- package/esm/src/platform/compat/path/resolution.d.ts.map +1 -0
- package/esm/src/platform/compat/path/resolution.js +121 -0
- package/esm/src/platform/compat/path/runtime.d.ts +8 -0
- package/esm/src/platform/compat/path/runtime.d.ts.map +1 -0
- package/esm/src/platform/compat/path/runtime.js +20 -0
- package/esm/src/platform/compat/path/types.d.ts +22 -0
- package/esm/src/platform/compat/path/types.d.ts.map +1 -0
- package/esm/src/platform/compat/path/types.js +1 -0
- package/esm/src/platform/compat/process/command.d.ts +31 -0
- package/esm/src/platform/compat/process/command.d.ts.map +1 -0
- package/esm/src/platform/compat/process/command.js +194 -0
- package/esm/src/platform/compat/process/env.d.ts +35 -0
- package/esm/src/platform/compat/process/env.d.ts.map +1 -0
- package/esm/src/platform/compat/process/env.js +194 -0
- package/esm/src/platform/compat/process/lifecycle.d.ts +99 -0
- package/esm/src/platform/compat/process/lifecycle.d.ts.map +1 -0
- package/esm/src/platform/compat/process/lifecycle.js +327 -0
- package/esm/src/platform/compat/process/runtime-process.d.ts +10 -0
- package/esm/src/platform/compat/process/runtime-process.d.ts.map +1 -0
- package/esm/src/platform/compat/process/runtime-process.js +25 -0
- package/esm/src/platform/compat/process.d.ts +5 -0
- package/esm/src/platform/compat/process.d.ts.map +1 -0
- package/esm/src/platform/compat/process.js +4 -0
- package/esm/src/platform/compat/runtime.d.ts +51 -0
- package/esm/src/platform/compat/runtime.d.ts.map +1 -0
- package/esm/src/platform/compat/runtime.js +101 -0
- package/esm/src/transforms/import-rewriter/url-builder.d.ts +70 -0
- package/esm/src/transforms/import-rewriter/url-builder.d.ts.map +1 -0
- package/esm/src/transforms/import-rewriter/url-builder.js +152 -0
- package/esm/src/utils/base64url.d.ts +6 -0
- package/esm/src/utils/base64url.d.ts.map +1 -0
- package/esm/src/utils/base64url.js +12 -0
- package/esm/src/utils/bundle-manifest.d.ts +63 -0
- package/esm/src/utils/bundle-manifest.d.ts.map +1 -0
- package/esm/src/utils/bundle-manifest.js +96 -0
- package/esm/src/utils/constants/buffers.d.ts +24 -0
- package/esm/src/utils/constants/buffers.d.ts.map +1 -0
- package/esm/src/utils/constants/buffers.js +23 -0
- package/esm/src/utils/constants/build.d.ts +8 -0
- package/esm/src/utils/constants/build.d.ts.map +1 -0
- package/esm/src/utils/constants/build.js +7 -0
- package/esm/src/utils/constants/cache.d.ts +74 -0
- package/esm/src/utils/constants/cache.d.ts.map +1 -0
- package/esm/src/utils/constants/cache.js +133 -0
- package/esm/src/utils/constants/cdn.d.ts +29 -0
- package/esm/src/utils/constants/cdn.d.ts.map +1 -0
- package/esm/src/utils/constants/cdn.js +58 -0
- package/esm/src/utils/constants/crypto.d.ts +10 -0
- package/esm/src/utils/constants/crypto.d.ts.map +1 -0
- package/esm/src/utils/constants/crypto.js +9 -0
- package/esm/src/utils/constants/env.d.ts +16 -0
- package/esm/src/utils/constants/env.d.ts.map +1 -0
- package/esm/src/utils/constants/env.js +20 -0
- package/esm/src/utils/constants/hash.d.ts +5 -0
- package/esm/src/utils/constants/hash.d.ts.map +1 -0
- package/esm/src/utils/constants/hash.js +4 -0
- package/esm/src/utils/constants/hmr.d.ts +24 -0
- package/esm/src/utils/constants/hmr.d.ts.map +1 -0
- package/esm/src/utils/constants/hmr.js +26 -0
- package/esm/src/utils/constants/html.d.ts +13 -0
- package/esm/src/utils/constants/html.d.ts.map +1 -0
- package/esm/src/utils/constants/html.js +12 -0
- package/esm/src/utils/constants/http.d.ts +77 -0
- package/esm/src/utils/constants/http.d.ts.map +1 -0
- package/esm/src/utils/constants/http.js +76 -0
- package/esm/src/utils/constants/index.d.ts +23 -0
- package/esm/src/utils/constants/index.d.ts.map +1 -0
- package/esm/src/utils/constants/index.js +22 -0
- package/esm/src/utils/constants/limits.d.ts +27 -0
- package/esm/src/utils/constants/limits.d.ts.map +1 -0
- package/esm/src/utils/constants/limits.js +26 -0
- package/esm/src/utils/constants/metrics.d.ts +10 -0
- package/esm/src/utils/constants/metrics.d.ts.map +1 -0
- package/esm/src/utils/constants/metrics.js +34 -0
- package/esm/src/utils/constants/network.d.ts +23 -0
- package/esm/src/utils/constants/network.d.ts.map +1 -0
- package/esm/src/utils/constants/network.js +27 -0
- package/esm/src/utils/constants/priorities.d.ts +31 -0
- package/esm/src/utils/constants/priorities.d.ts.map +1 -0
- package/esm/src/utils/constants/priorities.js +30 -0
- package/esm/src/utils/constants/retry.d.ts +14 -0
- package/esm/src/utils/constants/retry.d.ts.map +1 -0
- package/esm/src/utils/constants/retry.js +13 -0
- package/esm/src/utils/constants/security.d.ts +16 -0
- package/esm/src/utils/constants/security.d.ts.map +1 -0
- package/esm/src/utils/constants/security.js +15 -0
- package/esm/src/utils/constants/server.d.ts +107 -0
- package/esm/src/utils/constants/server.d.ts.map +1 -0
- package/esm/src/utils/constants/server.js +120 -0
- package/esm/src/utils/feature-flags.d.ts +7 -0
- package/esm/src/utils/feature-flags.d.ts.map +1 -0
- package/esm/src/utils/feature-flags.js +8 -0
- package/esm/src/utils/hash-utils.d.ts +19 -0
- package/esm/src/utils/hash-utils.d.ts.map +1 -0
- package/esm/src/utils/hash-utils.js +42 -0
- package/esm/src/utils/import-lockfile.d.ts +52 -0
- package/esm/src/utils/import-lockfile.d.ts.map +1 -0
- package/esm/src/utils/import-lockfile.js +187 -0
- package/esm/src/utils/index.d.ts +27 -0
- package/esm/src/utils/index.d.ts.map +1 -0
- package/esm/src/utils/index.js +25 -0
- package/esm/src/utils/logger/components.d.ts +73 -0
- package/esm/src/utils/logger/components.d.ts.map +1 -0
- package/esm/src/utils/logger/components.js +81 -0
- package/esm/src/utils/logger/core.d.ts +73 -0
- package/esm/src/utils/logger/core.d.ts.map +1 -0
- package/esm/src/utils/logger/core.js +143 -0
- package/esm/src/utils/logger/index.d.ts +10 -0
- package/esm/src/utils/logger/index.d.ts.map +1 -0
- package/esm/src/utils/logger/index.js +9 -0
- package/esm/src/utils/logger/logger.d.ts +179 -0
- package/esm/src/utils/logger/logger.d.ts.map +1 -0
- package/esm/src/utils/logger/logger.js +490 -0
- package/esm/src/utils/logger/redact.d.ts +74 -0
- package/esm/src/utils/logger/redact.d.ts.map +1 -0
- package/esm/src/utils/logger/redact.js +294 -0
- package/esm/src/utils/logger/request-context.d.ts +27 -0
- package/esm/src/utils/logger/request-context.d.ts.map +1 -0
- package/esm/src/utils/logger/request-context.js +28 -0
- package/esm/src/utils/memoize.d.ts +19 -0
- package/esm/src/utils/memoize.d.ts.map +1 -0
- package/esm/src/utils/memoize.js +72 -0
- package/esm/src/utils/parallel.d.ts +25 -0
- package/esm/src/utils/parallel.d.ts.map +1 -0
- package/esm/src/utils/parallel.js +91 -0
- package/esm/src/utils/path-utils.d.ts +34 -0
- package/esm/src/utils/path-utils.d.ts.map +1 -0
- package/esm/src/utils/path-utils.js +138 -0
- package/esm/src/utils/perf-timer.d.ts +11 -0
- package/esm/src/utils/perf-timer.d.ts.map +1 -0
- package/esm/src/utils/perf-timer.js +114 -0
- package/esm/src/utils/platform.d.ts +9 -0
- package/esm/src/utils/platform.d.ts.map +1 -0
- package/esm/src/utils/platform.js +20 -0
- package/esm/src/utils/runtime-guards.d.ts +29 -0
- package/esm/src/utils/runtime-guards.d.ts.map +1 -0
- package/esm/src/utils/runtime-guards.js +23 -0
- package/esm/src/utils/version-constant.d.ts +3 -0
- package/esm/src/utils/version-constant.d.ts.map +1 -0
- package/esm/src/utils/version-constant.js +4 -0
- package/esm/src/utils/version.d.ts +17 -0
- package/esm/src/utils/version.d.ts.map +1 -0
- package/esm/src/utils/version.js +36 -0
- package/package.json +25 -7
- package/esm/index.d.ts.map +0 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
2
|
+
/** Get command-line arguments (cross-runtime: Deno.args or process.argv). */
|
|
3
|
+
export declare function getArgs(): string[];
|
|
4
|
+
/** Exit the process with an optional code (cross-runtime: Deno.exit or process.exit). */
|
|
5
|
+
export declare function exit(code?: number): never;
|
|
6
|
+
/** Return the current working directory. */
|
|
7
|
+
export declare function cwd(): string;
|
|
8
|
+
export declare function chdir(directory: string): void;
|
|
9
|
+
export declare function pid(): number;
|
|
10
|
+
export declare function memoryUsage(): {
|
|
11
|
+
rss: number;
|
|
12
|
+
heapTotal: number;
|
|
13
|
+
heapUsed: number;
|
|
14
|
+
external: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Check if stdin is a TTY (terminal)
|
|
18
|
+
*/
|
|
19
|
+
export declare function isInteractive(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Check if stdout is a TTY (terminal)
|
|
22
|
+
*/
|
|
23
|
+
export declare function isStdoutTTY(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Get terminal size (columns and rows)
|
|
26
|
+
* Returns default fallback values if terminal size cannot be determined
|
|
27
|
+
*/
|
|
28
|
+
export declare function getTerminalSize(): {
|
|
29
|
+
columns: number;
|
|
30
|
+
rows: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Get runtime version string
|
|
34
|
+
*/
|
|
35
|
+
export declare function getRuntimeVersion(): string;
|
|
36
|
+
/**
|
|
37
|
+
* Get the operating system type
|
|
38
|
+
* Returns: "darwin" (macOS), "linux", "windows", or the raw platform string
|
|
39
|
+
*/
|
|
40
|
+
export declare function getOsType(): string;
|
|
41
|
+
/**
|
|
42
|
+
* Register a signal handler (SIGINT, SIGTERM) for graceful shutdown
|
|
43
|
+
*/
|
|
44
|
+
export declare function onSignal(signal: "SIGINT" | "SIGTERM", handler: () => void): void;
|
|
45
|
+
/**
|
|
46
|
+
* Register global error handlers for uncaught exceptions and unhandled promise rejections.
|
|
47
|
+
* These handlers prevent the process from crashing due to application code errors.
|
|
48
|
+
*
|
|
49
|
+
* IMPORTANT: These handlers should be registered early in the application lifecycle
|
|
50
|
+
* to catch errors that escape try/catch blocks.
|
|
51
|
+
*
|
|
52
|
+
* @param onError - Callback invoked with the error. Return true to prevent process exit.
|
|
53
|
+
*/
|
|
54
|
+
export declare function onGlobalError(onError: (error: Error, type: "uncaughtException" | "unhandledRejection") => boolean | void): void;
|
|
55
|
+
/**
|
|
56
|
+
* Unreference a timer to prevent it from keeping the process alive
|
|
57
|
+
*/
|
|
58
|
+
export declare function unrefTimer(timerId: ReturnType<typeof dntShim.setInterval>): void;
|
|
59
|
+
/**
|
|
60
|
+
* Get the executable path of the current runtime
|
|
61
|
+
*/
|
|
62
|
+
export declare function execPath(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Get process uptime in seconds
|
|
65
|
+
* Returns OS uptime on Deno, process uptime on Node.js
|
|
66
|
+
*/
|
|
67
|
+
export declare function uptime(): number;
|
|
68
|
+
/**
|
|
69
|
+
* Get stdout stream for writing
|
|
70
|
+
* Returns null if not available (e.g., in browser/workers)
|
|
71
|
+
*/
|
|
72
|
+
export declare function getStdout(): {
|
|
73
|
+
write: (data: string) => void;
|
|
74
|
+
} | null;
|
|
75
|
+
/**
|
|
76
|
+
* Write text directly to stdout (sync)
|
|
77
|
+
* No-op if stdout is not available
|
|
78
|
+
*/
|
|
79
|
+
export declare function writeStdout(text: string): void;
|
|
80
|
+
/**
|
|
81
|
+
* Write data to stdout asynchronously
|
|
82
|
+
* Returns a promise that resolves when the write is complete
|
|
83
|
+
*/
|
|
84
|
+
export declare function writeStdoutAsync(data: Uint8Array): Promise<number>;
|
|
85
|
+
/**
|
|
86
|
+
* Synchronous prompt function that works across Deno and Bun.
|
|
87
|
+
* Displays a message and reads user input from stdin.
|
|
88
|
+
*
|
|
89
|
+
* Note: This relies on globalThis.prompt which is available in Deno and Bun.
|
|
90
|
+
* Returns null in environments where prompt is not available (e.g., Node.js ESM).
|
|
91
|
+
*/
|
|
92
|
+
export declare function promptSync(message?: string): string | null;
|
|
93
|
+
/**
|
|
94
|
+
* Read a single byte from stdin synchronously.
|
|
95
|
+
* Requires raw mode to be enabled for character-by-character reading.
|
|
96
|
+
* Returns null on EOF or if stdin is not available.
|
|
97
|
+
*/
|
|
98
|
+
export declare function readStdinByteSync(): number | null;
|
|
99
|
+
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../../../../src/src/platform/compat/process/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,2BAA2B,CAAC;AAIrD,6EAA6E;AAC7E,wBAAgB,OAAO,IAAI,MAAM,EAAE,CAKlC;AAED,yFAAyF;AACzF,wBAAgB,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAKzC;AAED,4CAA4C;AAC5C,wBAAgB,GAAG,IAAI,MAAM,CAK5B;AAED,wBAAgB,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAW7C;AAED,wBAAgB,GAAG,IAAI,MAAM,CAK5B;AAED,wBAAgB,WAAW,IAAI;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAaA;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAKvC;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,OAAO,CAKrC;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAqBnE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAQ1C;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,MAAM,CASlC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,QAAQ,GAAG,SAAS,EAC5B,OAAO,EAAE,MAAM,IAAI,GAClB,IAAI,CAON;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,mBAAmB,GAAG,oBAAoB,KAAK,OAAO,GAAG,IAAI,GAC1F,IAAI,CAiDN;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI,CAahF;AAED;;GAEG;AACH,wBAAgB,QAAQ,IAAI,MAAM,CAKjC;AAED;;;GAGG;AACH,wBAAgB,MAAM,IAAI,MAAM,CAW/B;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI;IAAE,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,GAAG,IAAI,CAWpE;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE9C;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAexE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG1D;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,IAAI,CAuBjD"}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
2
|
+
import { getDenoRuntime, isBun as IS_BUN, isDeno as IS_DENO } from "../runtime.js";
|
|
3
|
+
import { runtimeProcess } from "./runtime-process.js";
|
|
4
|
+
/** Get command-line arguments (cross-runtime: Deno.args or process.argv). */
|
|
5
|
+
export function getArgs() {
|
|
6
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
7
|
+
if (deno)
|
|
8
|
+
return deno.args;
|
|
9
|
+
if (runtimeProcess)
|
|
10
|
+
return runtimeProcess.argv.slice(2);
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
/** Exit the process with an optional code (cross-runtime: Deno.exit or process.exit). */
|
|
14
|
+
export function exit(code) {
|
|
15
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
16
|
+
if (deno)
|
|
17
|
+
deno.exit(code);
|
|
18
|
+
if (runtimeProcess)
|
|
19
|
+
runtimeProcess.exit(code);
|
|
20
|
+
throw new Error("exit() is not supported in this runtime");
|
|
21
|
+
}
|
|
22
|
+
/** Return the current working directory. */
|
|
23
|
+
export function cwd() {
|
|
24
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
25
|
+
if (deno)
|
|
26
|
+
return deno.cwd();
|
|
27
|
+
if (runtimeProcess)
|
|
28
|
+
return runtimeProcess.cwd();
|
|
29
|
+
throw new Error("cwd() is not supported in this runtime");
|
|
30
|
+
}
|
|
31
|
+
export function chdir(directory) {
|
|
32
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
33
|
+
if (deno) {
|
|
34
|
+
deno.chdir(directory);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (runtimeProcess) {
|
|
38
|
+
runtimeProcess.chdir(directory);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
throw new Error("chdir() is not supported in this runtime");
|
|
42
|
+
}
|
|
43
|
+
export function pid() {
|
|
44
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
45
|
+
if (deno)
|
|
46
|
+
return deno.pid;
|
|
47
|
+
if (runtimeProcess)
|
|
48
|
+
return runtimeProcess.pid;
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
export function memoryUsage() {
|
|
52
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
53
|
+
if (deno) {
|
|
54
|
+
const { rss, heapTotal, heapUsed, external } = deno.memoryUsage();
|
|
55
|
+
return { rss, heapTotal, heapUsed, external };
|
|
56
|
+
}
|
|
57
|
+
if (!runtimeProcess) {
|
|
58
|
+
throw new Error("memoryUsage() is not supported in this runtime");
|
|
59
|
+
}
|
|
60
|
+
const { rss, heapTotal, heapUsed, external } = runtimeProcess.memoryUsage();
|
|
61
|
+
return { rss, heapTotal, heapUsed, external: external || 0 };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Check if stdin is a TTY (terminal)
|
|
65
|
+
*/
|
|
66
|
+
export function isInteractive() {
|
|
67
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
68
|
+
if (deno)
|
|
69
|
+
return deno.stdin.isTerminal();
|
|
70
|
+
if (runtimeProcess)
|
|
71
|
+
return runtimeProcess.stdin.isTTY ?? false;
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Check if stdout is a TTY (terminal)
|
|
76
|
+
*/
|
|
77
|
+
export function isStdoutTTY() {
|
|
78
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
79
|
+
if (deno)
|
|
80
|
+
return deno.stdout.isTerminal();
|
|
81
|
+
if (runtimeProcess)
|
|
82
|
+
return runtimeProcess.stdout.isTTY ?? false;
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get terminal size (columns and rows)
|
|
87
|
+
* Returns default fallback values if terminal size cannot be determined
|
|
88
|
+
*/
|
|
89
|
+
export function getTerminalSize() {
|
|
90
|
+
const defaultSize = { columns: 80, rows: 24 };
|
|
91
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
92
|
+
if (deno) {
|
|
93
|
+
try {
|
|
94
|
+
const { columns, rows } = deno.consoleSize();
|
|
95
|
+
return { columns, rows };
|
|
96
|
+
}
|
|
97
|
+
catch (_) {
|
|
98
|
+
/* expected: Deno.consoleSize() fails when not attached to a terminal */
|
|
99
|
+
return defaultSize;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (!runtimeProcess)
|
|
103
|
+
return defaultSize;
|
|
104
|
+
const columns = runtimeProcess.stdout?.columns;
|
|
105
|
+
const rows = runtimeProcess.stdout?.rows;
|
|
106
|
+
if (columns && rows)
|
|
107
|
+
return { columns, rows };
|
|
108
|
+
return defaultSize;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get runtime version string
|
|
112
|
+
*/
|
|
113
|
+
export function getRuntimeVersion() {
|
|
114
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
115
|
+
if (deno)
|
|
116
|
+
return `Deno ${deno.version.deno}`;
|
|
117
|
+
if ("Bun" in dntShim.dntGlobalThis) {
|
|
118
|
+
return `Bun ${dntShim.dntGlobalThis.Bun.version}`;
|
|
119
|
+
}
|
|
120
|
+
if (runtimeProcess)
|
|
121
|
+
return `Node.js ${runtimeProcess.version}`;
|
|
122
|
+
return "unknown";
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Get the operating system type
|
|
126
|
+
* Returns: "darwin" (macOS), "linux", "windows", or the raw platform string
|
|
127
|
+
*/
|
|
128
|
+
export function getOsType() {
|
|
129
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
130
|
+
if (deno)
|
|
131
|
+
return deno.build.os;
|
|
132
|
+
if (runtimeProcess) {
|
|
133
|
+
// Node/Bun uses process.platform which returns "win32" for Windows
|
|
134
|
+
const platform = runtimeProcess.platform;
|
|
135
|
+
return platform === "win32" ? "windows" : platform;
|
|
136
|
+
}
|
|
137
|
+
return "unknown";
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Register a signal handler (SIGINT, SIGTERM) for graceful shutdown
|
|
141
|
+
*/
|
|
142
|
+
export function onSignal(signal, handler) {
|
|
143
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
144
|
+
if (deno) {
|
|
145
|
+
deno.addSignalListener(signal, handler);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (runtimeProcess)
|
|
149
|
+
runtimeProcess.on(signal, handler);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Register global error handlers for uncaught exceptions and unhandled promise rejections.
|
|
153
|
+
* These handlers prevent the process from crashing due to application code errors.
|
|
154
|
+
*
|
|
155
|
+
* IMPORTANT: These handlers should be registered early in the application lifecycle
|
|
156
|
+
* to catch errors that escape try/catch blocks.
|
|
157
|
+
*
|
|
158
|
+
* @param onError - Callback invoked with the error. Return true to prevent process exit.
|
|
159
|
+
*/
|
|
160
|
+
export function onGlobalError(onError) {
|
|
161
|
+
if (IS_DENO) {
|
|
162
|
+
// Intentionally permanent: process-level handlers must persist for the entire runtime
|
|
163
|
+
globalThis.addEventListener("error", (event) => {
|
|
164
|
+
const error = event.error instanceof Error ? event.error : new Error(String(event.error));
|
|
165
|
+
if (onError(error, "uncaughtException"))
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
});
|
|
168
|
+
globalThis.addEventListener("unhandledrejection", (event) => {
|
|
169
|
+
const error = event.reason instanceof Error ? event.reason : new Error(String(event.reason));
|
|
170
|
+
if (onError(error, "unhandledRejection"))
|
|
171
|
+
event.preventDefault();
|
|
172
|
+
});
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (!runtimeProcess)
|
|
176
|
+
return;
|
|
177
|
+
const process = runtimeProcess;
|
|
178
|
+
const handleNodeGlobalError = (error, type) => {
|
|
179
|
+
let shouldPreventExit = false;
|
|
180
|
+
try {
|
|
181
|
+
shouldPreventExit = onError(error, type) === true;
|
|
182
|
+
}
|
|
183
|
+
catch (handlerError) {
|
|
184
|
+
const handlerException = handlerError instanceof Error
|
|
185
|
+
? handlerError
|
|
186
|
+
: new Error(String(handlerError));
|
|
187
|
+
console.error("Global error handler threw while processing", type, handlerException);
|
|
188
|
+
}
|
|
189
|
+
if (shouldPreventExit)
|
|
190
|
+
return;
|
|
191
|
+
// Node/Bun suppress default fatal behavior when a listener is registered.
|
|
192
|
+
// If the callback did not explicitly handle the error, exit to preserve
|
|
193
|
+
// expected fatal semantics for uncaught exceptions and unhandled rejections.
|
|
194
|
+
process.exit(1);
|
|
195
|
+
};
|
|
196
|
+
runtimeProcess.on("uncaughtException", (error) => {
|
|
197
|
+
handleNodeGlobalError(error, "uncaughtException");
|
|
198
|
+
});
|
|
199
|
+
runtimeProcess.on("unhandledRejection", (reason) => {
|
|
200
|
+
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
201
|
+
handleNodeGlobalError(error, "unhandledRejection");
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Unreference a timer to prevent it from keeping the process alive
|
|
206
|
+
*/
|
|
207
|
+
export function unrefTimer(timerId) {
|
|
208
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
209
|
+
if (deno && typeof deno.unrefTimer === "function" && typeof timerId === "number") {
|
|
210
|
+
deno.unrefTimer(timerId);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (timerId && typeof timerId === "object") {
|
|
214
|
+
const unref = timerId.unref;
|
|
215
|
+
if (typeof unref === "function") {
|
|
216
|
+
unref.call(timerId);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Get the executable path of the current runtime
|
|
222
|
+
*/
|
|
223
|
+
export function execPath() {
|
|
224
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
225
|
+
if (deno)
|
|
226
|
+
return deno.execPath();
|
|
227
|
+
if (runtimeProcess)
|
|
228
|
+
return runtimeProcess.execPath;
|
|
229
|
+
return "";
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Get process uptime in seconds
|
|
233
|
+
* Returns OS uptime on Deno, process uptime on Node.js
|
|
234
|
+
*/
|
|
235
|
+
export function uptime() {
|
|
236
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
237
|
+
if (deno) {
|
|
238
|
+
// Deno.osUptime() returns system uptime in seconds
|
|
239
|
+
return deno.osUptime?.() ?? 0;
|
|
240
|
+
}
|
|
241
|
+
if (runtimeProcess) {
|
|
242
|
+
// process.uptime() returns process uptime in seconds
|
|
243
|
+
return runtimeProcess.uptime?.() ?? 0;
|
|
244
|
+
}
|
|
245
|
+
return 0;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Get stdout stream for writing
|
|
249
|
+
* Returns null if not available (e.g., in browser/workers)
|
|
250
|
+
*/
|
|
251
|
+
export function getStdout() {
|
|
252
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
253
|
+
if (deno) {
|
|
254
|
+
const encoder = new TextEncoder();
|
|
255
|
+
return { write: (data) => deno.stdout.writeSync(encoder.encode(data)) };
|
|
256
|
+
}
|
|
257
|
+
const stdout = runtimeProcess?.stdout;
|
|
258
|
+
if (stdout) {
|
|
259
|
+
return { write: (data) => stdout.write(data) };
|
|
260
|
+
}
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Write text directly to stdout (sync)
|
|
265
|
+
* No-op if stdout is not available
|
|
266
|
+
*/
|
|
267
|
+
export function writeStdout(text) {
|
|
268
|
+
getStdout()?.write(text);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Write data to stdout asynchronously
|
|
272
|
+
* Returns a promise that resolves when the write is complete
|
|
273
|
+
*/
|
|
274
|
+
export async function writeStdoutAsync(data) {
|
|
275
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
276
|
+
if (deno)
|
|
277
|
+
return await deno.stdout.write(data);
|
|
278
|
+
const stdout = runtimeProcess?.stdout;
|
|
279
|
+
if (stdout) {
|
|
280
|
+
return await new Promise((resolve, reject) => {
|
|
281
|
+
stdout.write(data, (error) => {
|
|
282
|
+
if (error)
|
|
283
|
+
reject(error);
|
|
284
|
+
else
|
|
285
|
+
resolve(data.length);
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
return 0;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Synchronous prompt function that works across Deno and Bun.
|
|
293
|
+
* Displays a message and reads user input from stdin.
|
|
294
|
+
*
|
|
295
|
+
* Note: This relies on globalThis.prompt which is available in Deno and Bun.
|
|
296
|
+
* Returns null in environments where prompt is not available (e.g., Node.js ESM).
|
|
297
|
+
*/
|
|
298
|
+
export function promptSync(message) {
|
|
299
|
+
if (typeof globalThis.prompt !== "function")
|
|
300
|
+
return null;
|
|
301
|
+
return globalThis.prompt(message ?? "") ?? null;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Read a single byte from stdin synchronously.
|
|
305
|
+
* Requires raw mode to be enabled for character-by-character reading.
|
|
306
|
+
* Returns null on EOF or if stdin is not available.
|
|
307
|
+
*/
|
|
308
|
+
export function readStdinByteSync() {
|
|
309
|
+
const buf = new Uint8Array(1);
|
|
310
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
311
|
+
if (deno) {
|
|
312
|
+
const n = deno.stdin.readSync(buf);
|
|
313
|
+
return n ? buf[0] ?? null : null;
|
|
314
|
+
}
|
|
315
|
+
if (IS_BUN) {
|
|
316
|
+
// Bun: read one byte from the file descriptor directly
|
|
317
|
+
const BunGlobal = dntShim.dntGlobalThis
|
|
318
|
+
.Bun;
|
|
319
|
+
const chunk = BunGlobal?.stdin?.read?.(1);
|
|
320
|
+
if (chunk && chunk.length > 0) {
|
|
321
|
+
const first = chunk.at(0);
|
|
322
|
+
return first ?? null;
|
|
323
|
+
}
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type RuntimeProcess = typeof import("node:process");
|
|
2
|
+
/**
|
|
3
|
+
* Detect a real Node/Bun process object.
|
|
4
|
+
* Browser bundles may inject `window.process = { env: {} }`, which is not enough
|
|
5
|
+
* to safely call process APIs like cwd(), exit(), or on().
|
|
6
|
+
*/
|
|
7
|
+
export declare function testHasRuntimeProcess(processLike: unknown): processLike is RuntimeProcess;
|
|
8
|
+
export declare const runtimeProcess: RuntimeProcess | null;
|
|
9
|
+
export declare function isWindowsPlatform(): boolean;
|
|
10
|
+
//# sourceMappingURL=runtime-process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-process.d.ts","sourceRoot":"","sources":["../../../../../src/src/platform/compat/process/runtime-process.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,cAAc,GAAG,cAAc,cAAc,CAAC,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,OAAO,GAAG,WAAW,IAAI,cAAc,CAIzF;AAED,eAAO,MAAM,cAAc,EAAE,cAAc,GAAG,IAEtC,CAAC;AAET,wBAAgB,iBAAiB,IAAI,OAAO,CAM3C"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
2
|
+
import { getDenoRuntime, isDeno as IS_DENO } from "../runtime.js";
|
|
3
|
+
const nodeProcess = dntShim.dntGlobalThis.process;
|
|
4
|
+
/**
|
|
5
|
+
* Detect a real Node/Bun process object.
|
|
6
|
+
* Browser bundles may inject `window.process = { env: {} }`, which is not enough
|
|
7
|
+
* to safely call process APIs like cwd(), exit(), or on().
|
|
8
|
+
*/
|
|
9
|
+
export function testHasRuntimeProcess(processLike) {
|
|
10
|
+
if (!processLike || typeof processLike !== "object")
|
|
11
|
+
return false;
|
|
12
|
+
const versions = processLike.versions;
|
|
13
|
+
return typeof versions?.node === "string" && versions.node.length > 0;
|
|
14
|
+
}
|
|
15
|
+
export const runtimeProcess = testHasRuntimeProcess(nodeProcess)
|
|
16
|
+
? nodeProcess
|
|
17
|
+
: null;
|
|
18
|
+
export function isWindowsPlatform() {
|
|
19
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
20
|
+
if (deno)
|
|
21
|
+
return deno.build.os === "windows";
|
|
22
|
+
const platform = runtimeProcess?.platform ??
|
|
23
|
+
dntShim.dntGlobalThis.process?.platform;
|
|
24
|
+
return platform === "win32";
|
|
25
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { deleteEnv, env, type EnvBooleanOptions, getEnv, getEnvBoolean, getEnvNumber, getEnvOverlayStorage, getEnvString, getHostEnv, setEnv, } from "./process/env.js";
|
|
2
|
+
export { chdir, cwd, execPath, exit, getArgs, getOsType, getRuntimeVersion, getStdout, getTerminalSize, isInteractive, isStdoutTTY, memoryUsage, onGlobalError, onSignal, pid, promptSync, readStdinByteSync, unrefTimer, uptime, writeStdout, writeStdoutAsync, } from "./process/lifecycle.js";
|
|
3
|
+
export { testHasRuntimeProcess } from "./process/runtime-process.js";
|
|
4
|
+
export { type CommandOptions, type CommandResult, runCommand } from "./process/command.js";
|
|
5
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../../../src/src/platform/compat/process.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,GAAG,EACH,KAAK,iBAAiB,EACtB,MAAM,EACN,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,UAAU,EACV,MAAM,GACP,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,KAAK,EACL,GAAG,EACH,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,aAAa,EACb,WAAW,EACX,WAAW,EACX,aAAa,EACb,QAAQ,EACR,GAAG,EACH,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,MAAM,EACN,WAAW,EACX,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { deleteEnv, env, getEnv, getEnvBoolean, getEnvNumber, getEnvOverlayStorage, getEnvString, getHostEnv, setEnv, } from "./process/env.js";
|
|
2
|
+
export { chdir, cwd, execPath, exit, getArgs, getOsType, getRuntimeVersion, getStdout, getTerminalSize, isInteractive, isStdoutTTY, memoryUsage, onGlobalError, onSignal, pid, promptSync, readStdinByteSync, unrefTimer, uptime, writeStdout, writeStdoutAsync, } from "./process/lifecycle.js";
|
|
3
|
+
export { testHasRuntimeProcess } from "./process/runtime-process.js";
|
|
4
|
+
export { runCommand } from "./process/command.js";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as dntShim from "../../../_dnt.shims.js";
|
|
2
|
+
export declare function getDenoRuntime(): typeof dntShim.Deno | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* Check if an executable path is a compiled Deno binary.
|
|
5
|
+
* Detects by binary name: "deno" or "deno.exe" = standard runtime, anything else = compiled.
|
|
6
|
+
* @internal Exported for testing only.
|
|
7
|
+
*/
|
|
8
|
+
export declare function testDenoCompiledDetection(execPath: string): boolean;
|
|
9
|
+
/** True if running in Bun runtime (check first since Bun has process.versions.node) */
|
|
10
|
+
export declare const isBun: boolean;
|
|
11
|
+
/** True if running in Node.js runtime (has process.versions.node, not Bun, not shimmed Deno) */
|
|
12
|
+
export declare const isNode: boolean;
|
|
13
|
+
/** True if running in real Deno runtime (not dnt shim) */
|
|
14
|
+
export declare const isDeno: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* True if running in a compiled Deno binary.
|
|
17
|
+
* Compiled binaries cannot dynamically import HTTP URLs - they must use local file:// paths.
|
|
18
|
+
* This is evaluated once at module load time.
|
|
19
|
+
*/
|
|
20
|
+
export declare const isDenoCompiled: boolean;
|
|
21
|
+
/** True if running in Cloudflare Workers runtime */
|
|
22
|
+
export declare const isCloudflare: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Detect if running in Node.js (vs Deno) at call time.
|
|
25
|
+
* Use this function instead of the constant when runtime detection needs to happen
|
|
26
|
+
* at call time (e.g., when bundled with esbuild's __esm lazy initialization pattern).
|
|
27
|
+
*/
|
|
28
|
+
export declare function isNodeRuntime(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Detect if code is executing in a server environment (SSR).
|
|
31
|
+
*
|
|
32
|
+
* This function provides consistent SSR detection that works correctly even when
|
|
33
|
+
* SSR globals stub the window/document objects. It should be used instead of
|
|
34
|
+
* `typeof window === "undefined"` checks to avoid hydration mismatches.
|
|
35
|
+
*
|
|
36
|
+
* Priority:
|
|
37
|
+
* 1. Check __VERYFRONT_SSR__ flag (set by ssr-globals/index.ts) - most reliable
|
|
38
|
+
* 2. Check if window is undefined (fallback for non-veryfront environments)
|
|
39
|
+
*
|
|
40
|
+
* @returns true if executing on server, false if in browser
|
|
41
|
+
* @see plans/architecture-audit/006.1-ssr-detection-inconsistencies.md
|
|
42
|
+
*/
|
|
43
|
+
export declare function isServerEnvironment(): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Detect if code is executing in a browser environment.
|
|
46
|
+
* Inverse of isServerEnvironment() - use this instead of `typeof window !== "undefined"`.
|
|
47
|
+
*
|
|
48
|
+
* @returns true if executing in browser, false if on server
|
|
49
|
+
*/
|
|
50
|
+
export declare function isBrowserEnvironment(): boolean;
|
|
51
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../../src/src/platform/compat/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AAelD,wBAAgB,cAAc,IAAI,OAAO,OAAO,CAAC,IAAI,GAAG,SAAS,CAWhE;AAMD;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAOnE;AAmBD,uFAAuF;AACvF,eAAO,MAAM,KAAK,EAAE,OAAwB,CAAC;AAE7C,gGAAgG;AAChG,eAAO,MAAM,MAAM,EAAE,OAAoC,CAAC;AAE1D,0DAA0D;AAC1D,eAAO,MAAM,MAAM,EAAE,OAA4C,CAAC;AAElE;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,OAA0C,CAAC;AAExE,oDAAoD;AACpD,eAAO,MAAM,YAAY,EAAE,OAAgC,CAAC;AAE5D;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAK7C;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,OAAO,CAE9C"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import * as dntShim from "../../../_dnt.shims.js";
|
|
2
|
+
function hasNodeProcess() {
|
|
3
|
+
const global = dntShim.dntGlobalThis;
|
|
4
|
+
return global.process?.versions?.node != null && !global.process?.versions?.deno;
|
|
5
|
+
}
|
|
6
|
+
function hasBunGlobal() {
|
|
7
|
+
return dntShim.dntGlobalThis.Bun != null;
|
|
8
|
+
}
|
|
9
|
+
export function getDenoRuntime() {
|
|
10
|
+
const deno = Reflect.get(dntShim.dntGlobalThis, "Deno");
|
|
11
|
+
if (deno &&
|
|
12
|
+
typeof deno.version === "object" &&
|
|
13
|
+
typeof deno.build === "object" &&
|
|
14
|
+
typeof deno.build.os === "string") {
|
|
15
|
+
return deno;
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
function hasRealDeno() {
|
|
20
|
+
return getDenoRuntime() != null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Check if an executable path is a compiled Deno binary.
|
|
24
|
+
* Detects by binary name: "deno" or "deno.exe" = standard runtime, anything else = compiled.
|
|
25
|
+
* @internal Exported for testing only.
|
|
26
|
+
*/
|
|
27
|
+
export function testDenoCompiledDetection(execPath) {
|
|
28
|
+
if (!execPath)
|
|
29
|
+
return false;
|
|
30
|
+
const binaryName = execPath.split(/[/\\]/).pop()?.toLowerCase();
|
|
31
|
+
if (!binaryName)
|
|
32
|
+
return false;
|
|
33
|
+
return binaryName !== "deno" && binaryName !== "deno.exe";
|
|
34
|
+
}
|
|
35
|
+
/** Compiled Deno binaries cannot dynamically import HTTP URLs at runtime. */
|
|
36
|
+
function isDenoCompiledBinary() {
|
|
37
|
+
const deno = getDenoRuntime();
|
|
38
|
+
if (!deno)
|
|
39
|
+
return false;
|
|
40
|
+
try {
|
|
41
|
+
return testDenoCompiledDetection(deno.execPath());
|
|
42
|
+
}
|
|
43
|
+
catch (_) {
|
|
44
|
+
/* expected: Deno.execPath() may not be available in all environments */
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function hasCloudflareGlobals() {
|
|
49
|
+
return "caches" in dntShim.dntGlobalThis && "WebSocketPair" in dntShim.dntGlobalThis;
|
|
50
|
+
}
|
|
51
|
+
/** True if running in Bun runtime (check first since Bun has process.versions.node) */
|
|
52
|
+
export const isBun = hasBunGlobal();
|
|
53
|
+
/** True if running in Node.js runtime (has process.versions.node, not Bun, not shimmed Deno) */
|
|
54
|
+
export const isNode = !isBun && hasNodeProcess();
|
|
55
|
+
/** True if running in real Deno runtime (not dnt shim) */
|
|
56
|
+
export const isDeno = !isNode && !isBun && hasRealDeno();
|
|
57
|
+
/**
|
|
58
|
+
* True if running in a compiled Deno binary.
|
|
59
|
+
* Compiled binaries cannot dynamically import HTTP URLs - they must use local file:// paths.
|
|
60
|
+
* This is evaluated once at module load time.
|
|
61
|
+
*/
|
|
62
|
+
export const isDenoCompiled = isDeno && isDenoCompiledBinary();
|
|
63
|
+
/** True if running in Cloudflare Workers runtime */
|
|
64
|
+
export const isCloudflare = hasCloudflareGlobals();
|
|
65
|
+
/**
|
|
66
|
+
* Detect if running in Node.js (vs Deno) at call time.
|
|
67
|
+
* Use this function instead of the constant when runtime detection needs to happen
|
|
68
|
+
* at call time (e.g., when bundled with esbuild's __esm lazy initialization pattern).
|
|
69
|
+
*/
|
|
70
|
+
export function isNodeRuntime() {
|
|
71
|
+
return !hasBunGlobal() && hasNodeProcess();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Detect if code is executing in a server environment (SSR).
|
|
75
|
+
*
|
|
76
|
+
* This function provides consistent SSR detection that works correctly even when
|
|
77
|
+
* SSR globals stub the window/document objects. It should be used instead of
|
|
78
|
+
* `typeof window === "undefined"` checks to avoid hydration mismatches.
|
|
79
|
+
*
|
|
80
|
+
* Priority:
|
|
81
|
+
* 1. Check __VERYFRONT_SSR__ flag (set by ssr-globals/index.ts) - most reliable
|
|
82
|
+
* 2. Check if window is undefined (fallback for non-veryfront environments)
|
|
83
|
+
*
|
|
84
|
+
* @returns true if executing on server, false if in browser
|
|
85
|
+
* @see plans/architecture-audit/006.1-ssr-detection-inconsistencies.md
|
|
86
|
+
*/
|
|
87
|
+
export function isServerEnvironment() {
|
|
88
|
+
const ssrFlag = dntShim.dntGlobalThis.__VERYFRONT_SSR__;
|
|
89
|
+
if (ssrFlag === true)
|
|
90
|
+
return true;
|
|
91
|
+
return typeof dntShim.dntGlobalThis === "undefined";
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Detect if code is executing in a browser environment.
|
|
95
|
+
* Inverse of isServerEnvironment() - use this instead of `typeof window !== "undefined"`.
|
|
96
|
+
*
|
|
97
|
+
* @returns true if executing in browser, false if on server
|
|
98
|
+
*/
|
|
99
|
+
export function isBrowserEnvironment() {
|
|
100
|
+
return !isServerEnvironment();
|
|
101
|
+
}
|