@vite-hub/env 0.0.3 → 0.0.4
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/LICENSE +201 -0
- package/README.md +119 -24
- package/dist/{declarations-Cy5XamUA.js → declarations-CoMmvRqH.js} +16 -1
- package/dist/{declarations-BIBfEwer.d.ts → declarations-U6P3rvxC.d.ts} +2 -1
- package/dist/{errors-RUmAFDJn.js → errors-C4Xcs6Fi.js} +13 -4
- package/dist/index.d.ts +11 -6
- package/dist/index.js +4 -3
- package/dist/presets.d.ts +1 -1
- package/dist/presets.js +1 -1
- package/dist/provider.d.ts +6 -0
- package/dist/provider.js +7 -0
- package/dist/secret-C2191nAa.d.ts +11 -0
- package/dist/secret.d.ts +1 -10
- package/dist/server-C16sFc1E.js +303 -0
- package/dist/server.d.ts +5 -3
- package/dist/server.js +2 -2
- package/dist/{types-FcnPKias.d.ts → types-CsB6DTGE.d.ts} +40 -3
- package/dist/virtual-module.d.ts +30 -0
- package/dist/virtual.d.ts +2 -15
- package/dist/vite.d.ts +14 -4
- package/dist/vite.js +295 -96
- package/package.json +6 -2
- package/dist/server-B2Dp8Nc0.js +0 -59
package/dist/server-B2Dp8Nc0.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { SecretEnv } from "./secret.js";
|
|
2
|
-
import { a as missingRequiredEnv, r as invalidRuntimeEnvValue } from "./errors-RUmAFDJn.js";
|
|
3
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
|
-
const activeEnvStorage = new AsyncLocalStorage();
|
|
5
|
-
function getActiveCloudflareEnv() {
|
|
6
|
-
const scoped = activeEnvStorage.getStore();
|
|
7
|
-
return scoped ? scoped.env : globalThis.__env__;
|
|
8
|
-
}
|
|
9
|
-
function getCloudflareEnv(event) {
|
|
10
|
-
const target = event;
|
|
11
|
-
return target?.env || target?.context?.cloudflare?.env || target?.context?._platform?.cloudflare?.env || target?.req?.runtime?.cloudflare?.env || getActiveCloudflareEnv();
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/server.ts
|
|
15
|
-
function isRecord(value) {
|
|
16
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17
|
-
}
|
|
18
|
-
function isRuntimeLiteralEntry(value) {
|
|
19
|
-
return isRecord(value) && value.kind === "literal";
|
|
20
|
-
}
|
|
21
|
-
function isRuntimeEnvEntry(value) {
|
|
22
|
-
return isRecord(value) && isRecord(value.source) && typeof value.source.name === "string" && typeof value.required === "boolean" && typeof value.secret === "boolean";
|
|
23
|
-
}
|
|
24
|
-
function processEnv() {
|
|
25
|
-
return typeof process === "object" && process && process.env ? process.env : {};
|
|
26
|
-
}
|
|
27
|
-
function runtimeEnv(event) {
|
|
28
|
-
return {
|
|
29
|
-
...processEnv(),
|
|
30
|
-
...getCloudflareEnv(event)
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function readRuntimeSource(entry, env) {
|
|
34
|
-
for (const name of entry.source.names || [entry.source.name]) if (Object.hasOwn(env, name) && typeof env[name] !== "undefined") return {
|
|
35
|
-
found: true,
|
|
36
|
-
value: env[name]
|
|
37
|
-
};
|
|
38
|
-
return { found: false };
|
|
39
|
-
}
|
|
40
|
-
function resolveRegistryValue(value, env) {
|
|
41
|
-
if (isRuntimeLiteralEntry(value)) return value.value;
|
|
42
|
-
if (isRuntimeEnvEntry(value)) {
|
|
43
|
-
const source = readRuntimeSource(value, env);
|
|
44
|
-
const resolved = source.found ? source.value : value.default;
|
|
45
|
-
if (typeof resolved === "undefined") {
|
|
46
|
-
if (value.required) throw missingRequiredEnv(value.source.label, `Missing Runtime Env from ${value.source.label}.`);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
if (typeof resolved !== "string") throw invalidRuntimeEnvValue(value.source.label, `Runtime Env from ${value.source.label} must resolve to a string.`);
|
|
50
|
-
return value.secret ? new SecretEnv(resolved) : resolved;
|
|
51
|
-
}
|
|
52
|
-
if (!isRecord(value)) return;
|
|
53
|
-
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, resolveRegistryValue(child, env)]));
|
|
54
|
-
}
|
|
55
|
-
function resolveServerEnv(registry, event) {
|
|
56
|
-
return resolveRegistryValue(registry, runtimeEnv(event));
|
|
57
|
-
}
|
|
58
|
-
//#endregion
|
|
59
|
-
export { resolveServerEnv as t };
|