@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,121 @@
|
|
|
1
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
2
|
+
import { isDeno, nodePath } from "./runtime.js";
|
|
3
|
+
function hasWindowsLikePath(path) {
|
|
4
|
+
return path.includes("\\") || /^[A-Za-z]:/.test(path) || path.startsWith("\\\\");
|
|
5
|
+
}
|
|
6
|
+
/** Normalize backslashes to forward slashes (for Deno on Windows). */
|
|
7
|
+
function normSep(p) {
|
|
8
|
+
return p.includes("\\") ? p.replace(/\\/g, "/") : p;
|
|
9
|
+
}
|
|
10
|
+
/** Match Windows drive letter prefix like "C:/" */
|
|
11
|
+
const DRIVE_LETTER = /^[A-Za-z]:\//;
|
|
12
|
+
/** Resolve path segments to an absolute path. */
|
|
13
|
+
export function resolve(...paths) {
|
|
14
|
+
if (!isDeno && nodePath && !paths.some(hasWindowsLikePath))
|
|
15
|
+
return nodePath.resolve(...paths);
|
|
16
|
+
let resolvedPath = normSep(dntShim.dntGlobalThis.Deno?.cwd?.() ?? "/");
|
|
17
|
+
for (const rawPath of paths) {
|
|
18
|
+
if (!rawPath)
|
|
19
|
+
continue;
|
|
20
|
+
const path = normSep(rawPath);
|
|
21
|
+
if (path.startsWith("/") || DRIVE_LETTER.test(path)) {
|
|
22
|
+
resolvedPath = path;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
resolvedPath = `${resolvedPath}/${path}`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// Preserve drive letter prefix (e.g. "D:/") if present
|
|
29
|
+
let prefix = "/";
|
|
30
|
+
const driveMatch = resolvedPath.match(DRIVE_LETTER);
|
|
31
|
+
if (driveMatch) {
|
|
32
|
+
prefix = driveMatch[0]; // e.g. "D:/"
|
|
33
|
+
resolvedPath = resolvedPath.slice(prefix.length);
|
|
34
|
+
}
|
|
35
|
+
else if (resolvedPath.startsWith("/")) {
|
|
36
|
+
resolvedPath = resolvedPath.slice(1);
|
|
37
|
+
}
|
|
38
|
+
const parts = resolvedPath.split("/").filter(Boolean);
|
|
39
|
+
const resolved = [];
|
|
40
|
+
for (const part of parts) {
|
|
41
|
+
if (part === "..") {
|
|
42
|
+
resolved.pop();
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (part !== ".")
|
|
46
|
+
resolved.push(part);
|
|
47
|
+
}
|
|
48
|
+
return `${prefix}${resolved.join("/")}`;
|
|
49
|
+
}
|
|
50
|
+
export function isAbsolute(path) {
|
|
51
|
+
if (!isDeno && nodePath && !hasWindowsLikePath(path) && nodePath.isAbsolute(path))
|
|
52
|
+
return true;
|
|
53
|
+
// Cross-platform fallback: Unix, Windows drive letters, and UNC paths
|
|
54
|
+
if (path.startsWith("/"))
|
|
55
|
+
return true;
|
|
56
|
+
if (/^[A-Za-z]:[/\\]/.test(path))
|
|
57
|
+
return true;
|
|
58
|
+
return /^\\\\[^\\]+\\[^\\]+/.test(path);
|
|
59
|
+
}
|
|
60
|
+
export function relative(from, to) {
|
|
61
|
+
if (!isDeno && nodePath && !hasWindowsLikePath(from) && !hasWindowsLikePath(to)) {
|
|
62
|
+
const relativePath = nodePath.relative(from, to);
|
|
63
|
+
return relativePath || ".";
|
|
64
|
+
}
|
|
65
|
+
const resolvedFrom = resolve(from);
|
|
66
|
+
const resolvedTo = resolve(to);
|
|
67
|
+
// Strip drive prefix for comparison (both will share the same drive after resolve)
|
|
68
|
+
const fromDrive = resolvedFrom.match(DRIVE_LETTER);
|
|
69
|
+
const fromBase = fromDrive ? resolvedFrom.slice(fromDrive[0].length) : resolvedFrom.slice(1);
|
|
70
|
+
const toDrive = resolvedTo.match(DRIVE_LETTER);
|
|
71
|
+
const toBase = toDrive ? resolvedTo.slice(toDrive[0].length) : resolvedTo.slice(1);
|
|
72
|
+
const fromParts = fromBase.split("/").filter(Boolean);
|
|
73
|
+
const toParts = toBase.split("/").filter(Boolean);
|
|
74
|
+
let common = 0;
|
|
75
|
+
const minLen = Math.min(fromParts.length, toParts.length);
|
|
76
|
+
for (let i = 0; i < minLen; i++) {
|
|
77
|
+
if (fromParts[i] !== toParts[i])
|
|
78
|
+
break;
|
|
79
|
+
common++;
|
|
80
|
+
}
|
|
81
|
+
const ups = fromParts.length - common;
|
|
82
|
+
const result = [...new Array(ups).fill(".."), ...toParts.slice(common)];
|
|
83
|
+
return result.join("/") || ".";
|
|
84
|
+
}
|
|
85
|
+
export function normalize(path) {
|
|
86
|
+
if (!isDeno && nodePath && !hasWindowsLikePath(path))
|
|
87
|
+
return nodePath.normalize(path);
|
|
88
|
+
if (path === "")
|
|
89
|
+
return ".";
|
|
90
|
+
const p = normSep(path);
|
|
91
|
+
const abs = isAbsolute(p);
|
|
92
|
+
// Preserve drive letter prefix
|
|
93
|
+
let prefix = "";
|
|
94
|
+
const driveMatch = p.match(DRIVE_LETTER);
|
|
95
|
+
if (driveMatch) {
|
|
96
|
+
prefix = driveMatch[0];
|
|
97
|
+
}
|
|
98
|
+
else if (abs) {
|
|
99
|
+
prefix = "/";
|
|
100
|
+
}
|
|
101
|
+
const pathWithoutPrefix = driveMatch ? p.slice(prefix.length) : abs ? p.slice(1) : p;
|
|
102
|
+
const parts = pathWithoutPrefix.split("/").filter((s) => s && s !== ".");
|
|
103
|
+
const normalized = [];
|
|
104
|
+
for (const part of parts) {
|
|
105
|
+
if (part !== "..") {
|
|
106
|
+
normalized.push(part);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const last = normalized[normalized.length - 1];
|
|
110
|
+
if (normalized.length > 0 && last !== "..") {
|
|
111
|
+
normalized.pop();
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (!abs)
|
|
115
|
+
normalized.push("..");
|
|
116
|
+
}
|
|
117
|
+
const result = normalized.join("/");
|
|
118
|
+
if (abs)
|
|
119
|
+
return result ? `${prefix}${result}` : prefix || "/";
|
|
120
|
+
return result || ".";
|
|
121
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NodePathModule } from "./types.js";
|
|
2
|
+
export declare const isDeno: boolean;
|
|
3
|
+
declare let nodePath: NodePathModule | null;
|
|
4
|
+
export { nodePath };
|
|
5
|
+
export declare const sep: string;
|
|
6
|
+
export declare const delimiter: string;
|
|
7
|
+
export declare const hasNodePath: boolean;
|
|
8
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../../../src/src/platform/compat/path/runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAKjD,eAAO,MAAM,MAAM,SAAsC,CAAC;AAE1D,QAAA,IAAI,QAAQ,EAAE,cAAc,GAAG,IAAW,CAAC;AAa3C,OAAO,EAAE,QAAQ,EAAE,CAAC;AAEpB,eAAO,MAAM,GAAG,QAAuB,CAAC;AACxC,eAAO,MAAM,SAAS,QAA6B,CAAC;AACpD,eAAO,MAAM,WAAW,SAAoB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
2
|
+
const globalProcess = dntShim.dntGlobalThis.process;
|
|
3
|
+
const hasNodeApis = !!globalProcess?.versions?.node || "Bun" in dntShim.dntGlobalThis;
|
|
4
|
+
export const isDeno = typeof dntShim.Deno !== "undefined";
|
|
5
|
+
let nodePath = null;
|
|
6
|
+
if (hasNodeApis) {
|
|
7
|
+
try {
|
|
8
|
+
const nodeRequire = typeof require !== "undefined" ? require : null;
|
|
9
|
+
if (nodeRequire) {
|
|
10
|
+
nodePath = nodeRequire("node:path");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
catch (_) {
|
|
14
|
+
/* expected: node:path require may fail in non-Node runtimes */
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export { nodePath };
|
|
18
|
+
export const sep = nodePath?.sep ?? "/";
|
|
19
|
+
export const delimiter = nodePath?.delimiter ?? ":";
|
|
20
|
+
export const hasNodePath = nodePath !== null;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface PathObject {
|
|
2
|
+
root?: string;
|
|
3
|
+
dir?: string;
|
|
4
|
+
base?: string;
|
|
5
|
+
ext?: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface NodePathModule {
|
|
9
|
+
sep: string;
|
|
10
|
+
delimiter: string;
|
|
11
|
+
join(...paths: string[]): string;
|
|
12
|
+
resolve(...paths: string[]): string;
|
|
13
|
+
dirname(path: string): string;
|
|
14
|
+
basename(path: string, ext?: string): string;
|
|
15
|
+
extname(path: string): string;
|
|
16
|
+
isAbsolute(path: string): boolean;
|
|
17
|
+
relative(from: string, to: string): string;
|
|
18
|
+
normalize(path: string): string;
|
|
19
|
+
parse(path: string): PathObject;
|
|
20
|
+
format(pathObject: PathObject): string;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/src/platform/compat/path/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACjC,OAAO,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACpC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7C,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3C,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;IAChC,MAAM,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAAC;CACxC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface CommandResult {
|
|
2
|
+
success: boolean;
|
|
3
|
+
code: number;
|
|
4
|
+
stdout?: string;
|
|
5
|
+
stderr?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CommandOptions {
|
|
8
|
+
args?: string[];
|
|
9
|
+
cwd?: string;
|
|
10
|
+
env?: Record<string, string>;
|
|
11
|
+
/** Capture stdout/stderr to return in result */
|
|
12
|
+
capture?: boolean;
|
|
13
|
+
/** Inherit stdio from parent process (shows output in terminal) */
|
|
14
|
+
inherit?: boolean;
|
|
15
|
+
/** Use shell to run the command (needed for .cmd files on Windows) */
|
|
16
|
+
shell?: boolean;
|
|
17
|
+
/** Kill the command if it exceeds this duration (milliseconds) */
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Run a command and return the result.
|
|
22
|
+
* Works across Deno, Node.js, and Bun.
|
|
23
|
+
*
|
|
24
|
+
* @param cmd - Command to run
|
|
25
|
+
* @param options - Command options
|
|
26
|
+
* @param options.capture - Capture stdout/stderr to return in result
|
|
27
|
+
* @param options.inherit - Inherit stdio from parent (shows output in terminal)
|
|
28
|
+
* @param options.shell - Use shell to run command (needed for .cmd on Windows)
|
|
29
|
+
*/
|
|
30
|
+
export declare function runCommand(cmd: string, options?: CommandOptions): Promise<CommandResult>;
|
|
31
|
+
//# sourceMappingURL=command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../../src/src/platform/compat/process/command.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,gDAAgD;IAChD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,mEAAmE;IACnE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,sEAAsE;IACtE,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA6ED;;;;;;;;;GASG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,aAAa,CAAC,CAuLxB"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
2
|
+
import { dynamicImport } from "../dynamic-import.js";
|
|
3
|
+
import { getDenoRuntime, isBun as IS_BUN, isDeno as IS_DENO } from "../runtime.js";
|
|
4
|
+
import { isWindowsPlatform, runtimeProcess } from "./runtime-process.js";
|
|
5
|
+
const COMMAND_TIMEOUT_EXIT_CODE = 124;
|
|
6
|
+
const FORCE_KILL_GRACE_MS = 250;
|
|
7
|
+
function createTimeoutResult(timeoutMs, stdout, stderr) {
|
|
8
|
+
return {
|
|
9
|
+
success: false,
|
|
10
|
+
code: COMMAND_TIMEOUT_EXIT_CODE,
|
|
11
|
+
stdout,
|
|
12
|
+
stderr: `${stderr ?? ""}\nCommand timed out after ${timeoutMs}ms`.trim(),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function createProcessTimeout(timeoutMs, terminate, forceTerminate) {
|
|
16
|
+
let timedOut = false;
|
|
17
|
+
let timeoutId;
|
|
18
|
+
let forceKillId;
|
|
19
|
+
if (timeoutMs && timeoutMs > 0) {
|
|
20
|
+
timeoutId = dntShim.setTimeout(() => {
|
|
21
|
+
timedOut = true;
|
|
22
|
+
try {
|
|
23
|
+
terminate();
|
|
24
|
+
}
|
|
25
|
+
catch (_) {
|
|
26
|
+
/* expected: best-effort terminate may fail if process already exited */
|
|
27
|
+
}
|
|
28
|
+
forceKillId = dntShim.setTimeout(() => {
|
|
29
|
+
try {
|
|
30
|
+
forceTerminate();
|
|
31
|
+
}
|
|
32
|
+
catch (_) {
|
|
33
|
+
/* expected: best-effort force terminate may fail if process already exited */
|
|
34
|
+
}
|
|
35
|
+
}, FORCE_KILL_GRACE_MS);
|
|
36
|
+
}, timeoutMs);
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
hasTimedOut: () => timedOut,
|
|
40
|
+
clear: () => {
|
|
41
|
+
if (timeoutId)
|
|
42
|
+
clearTimeout(timeoutId);
|
|
43
|
+
if (forceKillId)
|
|
44
|
+
clearTimeout(forceKillId);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async function readStreamToString(stream) {
|
|
49
|
+
const reader = stream.getReader();
|
|
50
|
+
const chunks = [];
|
|
51
|
+
while (true) {
|
|
52
|
+
const { done, value } = await reader.read();
|
|
53
|
+
if (done)
|
|
54
|
+
break;
|
|
55
|
+
if (value)
|
|
56
|
+
chunks.push(value);
|
|
57
|
+
}
|
|
58
|
+
const total = chunks.reduce((acc, c) => acc + c.length, 0);
|
|
59
|
+
const merged = new Uint8Array(total);
|
|
60
|
+
let offset = 0;
|
|
61
|
+
for (const chunk of chunks) {
|
|
62
|
+
merged.set(chunk, offset);
|
|
63
|
+
offset += chunk.length;
|
|
64
|
+
}
|
|
65
|
+
return new TextDecoder().decode(merged);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Run a command and return the result.
|
|
69
|
+
* Works across Deno, Node.js, and Bun.
|
|
70
|
+
*
|
|
71
|
+
* @param cmd - Command to run
|
|
72
|
+
* @param options - Command options
|
|
73
|
+
* @param options.capture - Capture stdout/stderr to return in result
|
|
74
|
+
* @param options.inherit - Inherit stdio from parent (shows output in terminal)
|
|
75
|
+
* @param options.shell - Use shell to run command (needed for .cmd on Windows)
|
|
76
|
+
*/
|
|
77
|
+
export async function runCommand(cmd, options = {}) {
|
|
78
|
+
const { args = [], cwd: cmdCwd, env: cmdEnv, capture = false, inherit = false, shell = false, timeoutMs, } = options;
|
|
79
|
+
const effectiveTimeoutMs = timeoutMs && timeoutMs > 0 ? Math.floor(timeoutMs) : undefined;
|
|
80
|
+
// Determine stdio mode: inherit > capture > null
|
|
81
|
+
const stdioMode = inherit ? "inherit" : capture ? "piped" : "null";
|
|
82
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
83
|
+
if (deno) {
|
|
84
|
+
const command = new deno.Command(cmd, {
|
|
85
|
+
args,
|
|
86
|
+
cwd: cmdCwd,
|
|
87
|
+
env: cmdEnv,
|
|
88
|
+
stdin: inherit ? "inherit" : "null",
|
|
89
|
+
stdout: stdioMode,
|
|
90
|
+
stderr: stdioMode,
|
|
91
|
+
});
|
|
92
|
+
const child = command.spawn();
|
|
93
|
+
const timeout = createProcessTimeout(effectiveTimeoutMs, () => child.kill("SIGTERM"), () => child.kill("SIGKILL"));
|
|
94
|
+
try {
|
|
95
|
+
const [status, stdout, stderr] = await Promise.all([
|
|
96
|
+
child.status,
|
|
97
|
+
capture && child.stdout ? readStreamToString(child.stdout) : Promise.resolve(undefined),
|
|
98
|
+
capture && child.stderr ? readStreamToString(child.stderr) : Promise.resolve(undefined),
|
|
99
|
+
]);
|
|
100
|
+
if (timeout.hasTimedOut()) {
|
|
101
|
+
return createTimeoutResult(effectiveTimeoutMs ?? 0, stdout, stderr);
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
success: status.success,
|
|
105
|
+
code: status.code,
|
|
106
|
+
stdout,
|
|
107
|
+
stderr,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
timeout.clear();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (IS_BUN) {
|
|
115
|
+
const bunGlobal = dntShim.dntGlobalThis;
|
|
116
|
+
const bunStdio = inherit ? "inherit" : capture ? "pipe" : "ignore";
|
|
117
|
+
const isWindows = isWindowsPlatform();
|
|
118
|
+
const bunCmd = shell
|
|
119
|
+
? args.length === 0
|
|
120
|
+
? isWindows ? ["cmd", "/c", cmd] : ["sh", "-c", cmd]
|
|
121
|
+
: isWindows
|
|
122
|
+
? ["cmd", "/c", cmd, ...args]
|
|
123
|
+
: ["sh", "-c", 'exec "$@"', "sh", cmd, ...args]
|
|
124
|
+
: [cmd, ...args];
|
|
125
|
+
const proc = bunGlobal.Bun.spawn({
|
|
126
|
+
cmd: bunCmd,
|
|
127
|
+
cwd: cmdCwd,
|
|
128
|
+
env: cmdEnv,
|
|
129
|
+
stdout: bunStdio,
|
|
130
|
+
stderr: bunStdio,
|
|
131
|
+
});
|
|
132
|
+
const timeout = createProcessTimeout(effectiveTimeoutMs, () => proc.kill?.("SIGTERM"), () => proc.kill?.("SIGKILL"));
|
|
133
|
+
try {
|
|
134
|
+
const [code, stdout, stderr] = await Promise.all([
|
|
135
|
+
proc.exited,
|
|
136
|
+
capture && proc.stdout ? readStreamToString(proc.stdout) : Promise.resolve(undefined),
|
|
137
|
+
capture && proc.stderr ? readStreamToString(proc.stderr) : Promise.resolve(undefined),
|
|
138
|
+
]);
|
|
139
|
+
if (timeout.hasTimedOut()) {
|
|
140
|
+
return createTimeoutResult(effectiveTimeoutMs ?? 0, stdout, stderr);
|
|
141
|
+
}
|
|
142
|
+
return { success: code === 0, code, stdout, stderr };
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
timeout.clear();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (!runtimeProcess)
|
|
149
|
+
return { success: false, code: 1 };
|
|
150
|
+
const process = runtimeProcess;
|
|
151
|
+
const { spawn } = await dynamicImport("node:child_process");
|
|
152
|
+
const nodeStdio = inherit
|
|
153
|
+
? ["inherit", "inherit", "inherit"]
|
|
154
|
+
: capture
|
|
155
|
+
? ["ignore", "pipe", "pipe"]
|
|
156
|
+
: ["ignore", "ignore", "ignore"];
|
|
157
|
+
return await new Promise((resolve) => {
|
|
158
|
+
const child = spawn(cmd, args, {
|
|
159
|
+
cwd: cmdCwd,
|
|
160
|
+
env: cmdEnv ? { ...process.env, ...cmdEnv } : undefined,
|
|
161
|
+
stdio: nodeStdio,
|
|
162
|
+
shell,
|
|
163
|
+
});
|
|
164
|
+
let stdout = "";
|
|
165
|
+
let stderr = "";
|
|
166
|
+
const decoder = new TextDecoder();
|
|
167
|
+
const timeout = createProcessTimeout(effectiveTimeoutMs, () => child.kill("SIGTERM"), () => child.kill("SIGKILL"));
|
|
168
|
+
if (capture) {
|
|
169
|
+
child.stdout?.on("data", (data) => {
|
|
170
|
+
stdout += decoder.decode(data);
|
|
171
|
+
});
|
|
172
|
+
child.stderr?.on("data", (data) => {
|
|
173
|
+
stderr += decoder.decode(data);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
child.on("close", (code) => {
|
|
177
|
+
timeout.clear();
|
|
178
|
+
if (timeout.hasTimedOut()) {
|
|
179
|
+
resolve(createTimeoutResult(effectiveTimeoutMs ?? 0, capture ? stdout : undefined, capture ? stderr : undefined));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
resolve({
|
|
183
|
+
success: code === 0,
|
|
184
|
+
code: code ?? 1,
|
|
185
|
+
stdout: capture ? stdout : undefined,
|
|
186
|
+
stderr: capture ? stderr : undefined,
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
child.on("error", () => {
|
|
190
|
+
timeout.clear();
|
|
191
|
+
resolve({ success: false, code: 1 });
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type EnvOverlayStorage = {
|
|
2
|
+
getStore: () => unknown;
|
|
3
|
+
run?: <T>(store: unknown, fn: () => T) => T;
|
|
4
|
+
enterWith?: (store: unknown) => void;
|
|
5
|
+
};
|
|
6
|
+
/** Read and write process environment variables. */
|
|
7
|
+
export declare function env(): Record<string, string>;
|
|
8
|
+
/**
|
|
9
|
+
* Read a host-level environment variable without consulting any project env overlay.
|
|
10
|
+
* Use this for framework-owned runtime configuration that should not be shadowed by tenant env.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getHostEnv(key: string): string | undefined;
|
|
13
|
+
/** Read an environment variable from the active project scope. */
|
|
14
|
+
export declare function getEnv(key: string): string | undefined;
|
|
15
|
+
export interface EnvBooleanOptions {
|
|
16
|
+
trueValues?: readonly string[];
|
|
17
|
+
falseValues?: readonly string[];
|
|
18
|
+
trim?: boolean;
|
|
19
|
+
caseSensitive?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare function getEnvString(key: string): string | undefined;
|
|
22
|
+
export declare function getEnvString(key: string, fallback: string): string;
|
|
23
|
+
export declare function getEnvNumber(key: string): number | undefined;
|
|
24
|
+
export declare function getEnvNumber(key: string, fallback: number): number;
|
|
25
|
+
export declare function getEnvBoolean(key: string, fallback?: boolean, options?: EnvBooleanOptions): boolean;
|
|
26
|
+
/** Sets env. */
|
|
27
|
+
export declare function setEnv(key: string, value: string): void;
|
|
28
|
+
/** Delete a process environment variable. */
|
|
29
|
+
export declare function deleteEnv(key: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Get an AsyncLocalStorage-based env overlay storage if installed.
|
|
32
|
+
* This enables per-async-context env isolation (e.g., in tests).
|
|
33
|
+
*/
|
|
34
|
+
export declare function getEnvOverlayStorage(): EnvOverlayStorage | null;
|
|
35
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../../../src/src/platform/compat/process/env.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,MAAM,OAAO,CAAC;IACxB,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5C,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACtC,CAAC;AAoBF,oDAAoD;AACpD,wBAAgB,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAoB5C;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAqB1D;AAqCD,kEAAkE;AAClE,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAWtD;AAKD,MAAM,WAAW,iBAAiB;IAChC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAUD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAC9D,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;AAOpE,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAC9D,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;AAUpE,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,QAAQ,UAAQ,EAChB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAmBT;AAED,gBAAgB;AAChB,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAiBvD;AAED,6CAA6C;AAC7C,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAiB3C;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,iBAAiB,GAAG,IAAI,CAS/D"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
2
|
+
import { getDenoRuntime, isDeno as IS_DENO } from "../runtime.js";
|
|
3
|
+
import { runtimeProcess } from "./runtime-process.js";
|
|
4
|
+
function getEnvOverlayStore() {
|
|
5
|
+
const storage = getEnvOverlayStorage();
|
|
6
|
+
const store = storage?.getStore();
|
|
7
|
+
return store instanceof Map ? store : null;
|
|
8
|
+
}
|
|
9
|
+
function getOverlayEnvValue(store, key) {
|
|
10
|
+
if (!store?.has(key)) {
|
|
11
|
+
return { hasValue: false, value: undefined };
|
|
12
|
+
}
|
|
13
|
+
const value = store.get(key);
|
|
14
|
+
return { hasValue: true, value: value ?? undefined };
|
|
15
|
+
}
|
|
16
|
+
/** Read and write process environment variables. */
|
|
17
|
+
export function env() {
|
|
18
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
19
|
+
const base = deno
|
|
20
|
+
? deno.env.toObject()
|
|
21
|
+
: runtimeProcess
|
|
22
|
+
? { ...runtimeProcess.env }
|
|
23
|
+
: {};
|
|
24
|
+
const overlay = getEnvOverlayStore();
|
|
25
|
+
if (!overlay)
|
|
26
|
+
return base;
|
|
27
|
+
for (const [key, value] of overlay.entries()) {
|
|
28
|
+
if (value === null) {
|
|
29
|
+
delete base[key];
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
base[key] = value;
|
|
33
|
+
}
|
|
34
|
+
return base;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Read a host-level environment variable without consulting any project env overlay.
|
|
38
|
+
* Use this for framework-owned runtime configuration that should not be shadowed by tenant env.
|
|
39
|
+
*/
|
|
40
|
+
export function getHostEnv(key) {
|
|
41
|
+
const overlayResult = getOverlayEnvValue(getEnvOverlayStore(), key);
|
|
42
|
+
if (overlayResult.hasValue) {
|
|
43
|
+
return overlayResult.value;
|
|
44
|
+
}
|
|
45
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
46
|
+
if (deno) {
|
|
47
|
+
try {
|
|
48
|
+
return deno.env.get(key);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Under a tightened env permission allowlist (project isolation workers),
|
|
52
|
+
// reading a non-allowlisted variable throws NotCapable. Treat it as absent
|
|
53
|
+
// to match the prior `env: true` behavior where reads never threw, so
|
|
54
|
+
// optional-variable lookups degrade to undefined instead of crashing the
|
|
55
|
+
// request.
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (runtimeProcess)
|
|
60
|
+
return runtimeProcess.env[key];
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
// Lazy-loaded references to project-env/storage.ts functions.
|
|
64
|
+
// Uses globalThis to avoid circular imports (process compat is low-level, project-env is high-level).
|
|
65
|
+
// IMPORTANT: Only cache when the real getter is found. If storage.ts hasn't loaded yet,
|
|
66
|
+
// re-check globalThis on every call to avoid permanently caching the fallback.
|
|
67
|
+
let _getProjectEnv = null;
|
|
68
|
+
let _isProjectEnvActive = null;
|
|
69
|
+
function getProjectEnvSafe(key) {
|
|
70
|
+
if (_getProjectEnv === null) {
|
|
71
|
+
const mod = dntShim.dntGlobalThis.__vfProjectEnvGetter;
|
|
72
|
+
if (mod) {
|
|
73
|
+
_getProjectEnv = mod;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return _getProjectEnv(key);
|
|
80
|
+
}
|
|
81
|
+
function isProjectEnvActiveSafe() {
|
|
82
|
+
if (_isProjectEnvActive === null) {
|
|
83
|
+
const mod = dntShim.dntGlobalThis.__vfProjectEnvActiveChecker;
|
|
84
|
+
if (mod) {
|
|
85
|
+
_isProjectEnvActive = mod;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return _isProjectEnvActive();
|
|
92
|
+
}
|
|
93
|
+
/** Read an environment variable from the active project scope. */
|
|
94
|
+
export function getEnv(key) {
|
|
95
|
+
// Check per-request project env overlay first (AsyncLocalStorage)
|
|
96
|
+
const projectValue = getProjectEnvSafe(key);
|
|
97
|
+
if (projectValue !== undefined)
|
|
98
|
+
return projectValue;
|
|
99
|
+
// When a project env overlay is active (remote project request), do NOT
|
|
100
|
+
// fall through to host process env. This prevents remote projects from
|
|
101
|
+
// reading host-level secrets like AWS_SECRET_ACCESS_KEY, DATABASE_URL, etc.
|
|
102
|
+
if (isProjectEnvActiveSafe())
|
|
103
|
+
return undefined;
|
|
104
|
+
return getHostEnv(key);
|
|
105
|
+
}
|
|
106
|
+
const DEFAULT_ENV_TRUE_VALUES = ["1", "true", "yes"];
|
|
107
|
+
const DEFAULT_ENV_FALSE_VALUES = ["0", "false", "no"];
|
|
108
|
+
function normalizeEnvToken(value, options) {
|
|
109
|
+
const normalized = options.trim ? value.trim() : value;
|
|
110
|
+
return options.caseSensitive ? normalized : normalized.toLowerCase();
|
|
111
|
+
}
|
|
112
|
+
export function getEnvString(key, fallback) {
|
|
113
|
+
const value = getEnv(key);
|
|
114
|
+
if (value === undefined)
|
|
115
|
+
return fallback;
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
export function getEnvNumber(key, fallback) {
|
|
119
|
+
const value = getEnvString(key);
|
|
120
|
+
if (value === undefined)
|
|
121
|
+
return fallback;
|
|
122
|
+
const parsed = Number.parseInt(value, 10);
|
|
123
|
+
if (Number.isNaN(parsed))
|
|
124
|
+
return fallback ?? Number.NaN;
|
|
125
|
+
return parsed;
|
|
126
|
+
}
|
|
127
|
+
export function getEnvBoolean(key, fallback = false, options = {}) {
|
|
128
|
+
const value = getEnvString(key);
|
|
129
|
+
if (value === undefined)
|
|
130
|
+
return fallback;
|
|
131
|
+
const trim = options.trim ?? true;
|
|
132
|
+
const caseSensitive = options.caseSensitive ?? false;
|
|
133
|
+
const normalized = normalizeEnvToken(value, { trim, caseSensitive });
|
|
134
|
+
const trueValues = options.trueValues ?? DEFAULT_ENV_TRUE_VALUES;
|
|
135
|
+
for (const trueValue of trueValues) {
|
|
136
|
+
if (normalized === normalizeEnvToken(trueValue, { trim, caseSensitive }))
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
const falseValues = options.falseValues ?? DEFAULT_ENV_FALSE_VALUES;
|
|
140
|
+
for (const falseValue of falseValues) {
|
|
141
|
+
if (normalized === normalizeEnvToken(falseValue, { trim, caseSensitive }))
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
return fallback;
|
|
145
|
+
}
|
|
146
|
+
/** Sets env. */
|
|
147
|
+
export function setEnv(key, value) {
|
|
148
|
+
const overlay = getEnvOverlayStore();
|
|
149
|
+
if (overlay) {
|
|
150
|
+
overlay.set(key, value);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
154
|
+
if (deno) {
|
|
155
|
+
deno.env.set(key, value);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (runtimeProcess) {
|
|
159
|
+
runtimeProcess.env[key] = value;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
throw new Error("setEnv() is not supported in this runtime");
|
|
163
|
+
}
|
|
164
|
+
/** Delete a process environment variable. */
|
|
165
|
+
export function deleteEnv(key) {
|
|
166
|
+
const overlay = getEnvOverlayStore();
|
|
167
|
+
if (overlay) {
|
|
168
|
+
overlay.set(key, null);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const deno = IS_DENO ? getDenoRuntime() : undefined;
|
|
172
|
+
if (deno) {
|
|
173
|
+
deno.env.delete(key);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (runtimeProcess) {
|
|
177
|
+
delete runtimeProcess.env[key];
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
throw new Error("deleteEnv() is not supported in this runtime");
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Get an AsyncLocalStorage-based env overlay storage if installed.
|
|
184
|
+
* This enables per-async-context env isolation (e.g., in tests).
|
|
185
|
+
*/
|
|
186
|
+
export function getEnvOverlayStorage() {
|
|
187
|
+
const globalAny = dntShim.dntGlobalThis;
|
|
188
|
+
const overlay = globalAny["__vfTestDenoEnvOverlay"] ??
|
|
189
|
+
globalAny["__vfTestEnvOverlay"];
|
|
190
|
+
const storage = overlay?.storage;
|
|
191
|
+
if (!storage || typeof storage.getStore !== "function")
|
|
192
|
+
return null;
|
|
193
|
+
return storage;
|
|
194
|
+
}
|