@vite-hub/env 0.5.0 → 0.5.1
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/README.md +1 -1
- package/dist/{access-C5sPO6C2.js → access-DIErLk3w.js} +2 -3
- package/dist/{bridge-Cs9YfQWk.d.ts → bridge-BWwIooe0.d.ts} +0 -12
- package/dist/{bridge-error-t9bc6xvE.js → bridge-error-DEqzARPJ.js} +1 -2
- package/dist/bridge.d.ts +1 -1
- package/dist/bridge.js +6 -9
- package/dist/{cli-DJtQF4Wi.d.ts → cli-B-LW6l_J.d.ts} +0 -6
- package/dist/{cli-BctSFldY.js → cli-CAlHK5nn.js} +12 -21
- package/dist/cli.d.ts +3 -6
- package/dist/cli.js +1 -2
- package/dist/database.d.ts +2 -4
- package/dist/database.js +2 -3
- package/dist/{declarations-BEL0yvEY.d.ts → declarations-DNjO52_s.d.ts} +1 -3
- package/dist/{schema-CnCp0Muw.js → declarations-meg4Rmgd.js} +6 -71
- package/dist/{object-DICxAEoH.js → error-diagnostics-5BceFRdD.js} +52 -13
- package/dist/{error-diagnostics-CwQGNVnK.js → error-diagnostics-BFzFaXcH.js} +1 -2
- package/dist/index.d.ts +3 -13
- package/dist/index.js +8 -12
- package/dist/internal/agent.d.ts +2 -4
- package/dist/internal/agent.js +3 -4
- package/dist/internal/connections.d.ts +2 -4
- package/dist/internal/connections.js +3 -4
- package/dist/internal/server.d.ts +2 -2
- package/dist/internal/server.js +1 -2
- package/dist/{operation-definition-CI2PJGqu.d.ts → operation-definition-CqZkx1Rm.d.ts} +0 -4
- package/dist/{operations-LVaCzpR0.js → operations-BftegDMd.js} +2 -3
- package/dist/operations.d.ts +2 -6
- package/dist/operations.js +6 -40
- package/dist/runtime/public-env.d.ts +2 -4
- package/dist/runtime/public-env.js +2 -3
- package/dist/runtime/server-env.d.ts +2 -3
- package/dist/runtime/server-env.js +2 -3
- package/dist/seal.d.ts +1 -3
- package/dist/seal.js +1 -2
- package/dist/{secret-DJd-fy5T.js → secret-VhbE53Vm.js} +1 -2
- package/dist/{server-OvARy_y9.d.ts → server-CPEywepM.d.ts} +1 -11
- package/dist/{server-Ct3uvhf9.js → server-pTqnkM7n.js} +209 -152
- package/dist/server.d.ts +2 -2
- package/dist/server.js +1 -2
- package/dist/vite.d.ts +4 -16
- package/dist/vite.js +20 -21
- package/package.json +11 -10
|
@@ -1,13 +1,196 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { t as
|
|
3
|
-
import {
|
|
1
|
+
import { a as isRecordOrFunction, i as isRecord, r as standardResultIssues, t as internalErrorDiagnostics } from "./error-diagnostics-5BceFRdD.js";
|
|
2
|
+
import { t as envErrorDiagnostics } from "./error-diagnostics-BFzFaXcH.js";
|
|
3
|
+
import { t as SecretEnv } from "./secret-VhbE53Vm.js";
|
|
4
4
|
import { defineDiagnostics } from "nostics";
|
|
5
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
6
5
|
import { ViteHubError, defineErrors, isViteHubError, parseDuration } from "@vite-hub/runtime";
|
|
6
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
7
|
import { getViteHubTestMode } from "@vite-hub/runtime/internal/test-mode";
|
|
8
8
|
import { getStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
9
9
|
import * as v from "valibot";
|
|
10
|
-
|
|
10
|
+
// src/core/errors.ts
|
|
11
|
+
const envErrorMessages = {
|
|
12
|
+
ENV_DECLARATION_INVALID: "[vitehub] Env declaration is invalid.",
|
|
13
|
+
ENV_ASYNC_REQUIRED: "[vitehub] Server Env requires asynchronous loading.",
|
|
14
|
+
ENV_REQUIRED_MISSING: "[vitehub] Required Env value is missing.",
|
|
15
|
+
ENV_RUNTIME_VALUE_INVALID: "[vitehub] Runtime Env value is invalid.",
|
|
16
|
+
ENV_SOURCE_FAILED: "[vitehub] Env source resolution failed."
|
|
17
|
+
};
|
|
18
|
+
const envSourceIdentifierSet = /* @__PURE__ */ new Set([
|
|
19
|
+
"custom",
|
|
20
|
+
"env",
|
|
21
|
+
"git:branch",
|
|
22
|
+
"git:commit",
|
|
23
|
+
"git:tag",
|
|
24
|
+
"package.json",
|
|
25
|
+
"provider"
|
|
26
|
+
]);
|
|
27
|
+
function createEnvError(options, message = envErrorMessages[options.code]) {
|
|
28
|
+
const { code, cause, details } = options;
|
|
29
|
+
return new ViteHubError(code, message, {
|
|
30
|
+
...cause === void 0 ? {} : { cause },
|
|
31
|
+
...details === void 0 || Object.keys(details).length === 0 ? {} : { details }
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function invalidEnvDeclaration(path, diagnostic, cause) {
|
|
35
|
+
return createEnvError({
|
|
36
|
+
cause: envErrorDiagnostics.ENV_R0008({
|
|
37
|
+
message: diagnostic,
|
|
38
|
+
...cause === void 0 ? {} : { cause }
|
|
39
|
+
}),
|
|
40
|
+
code: "ENV_DECLARATION_INVALID",
|
|
41
|
+
details: optionalPath(path)
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function asyncServerEnvRequired(path) {
|
|
45
|
+
return createEnvError({
|
|
46
|
+
cause: envErrorDiagnostics.ENV_R0009({ message: `Server Env at ${path} uses env.provider(). Use loadServerEnv() or runWithServerEnv().` }),
|
|
47
|
+
code: "ENV_ASYNC_REQUIRED",
|
|
48
|
+
details: optionalPath(path)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The message and details name the declaration path and the variables that can supply it, so the operator
|
|
53
|
+
* knows what to set. Names are not secret; the value never appears because there is none.
|
|
54
|
+
*/
|
|
55
|
+
function missingRequiredEnv(source, diagnostic, path, names = []) {
|
|
56
|
+
const pathDetails = optionalPath(path);
|
|
57
|
+
const variables = names.filter(isEnvVariableName).slice(0, 8);
|
|
58
|
+
const subject = pathDetails.path ? `Required Env value ${pathDetails.path} is missing.` : "Required Env value is missing.";
|
|
59
|
+
const supply = variables.length ? ` Set ${variables.join(" or ")}.` : "";
|
|
60
|
+
return createEnvError({
|
|
61
|
+
cause: envErrorDiagnostics.ENV_R0010({ message: diagnostic }),
|
|
62
|
+
code: "ENV_REQUIRED_MISSING",
|
|
63
|
+
details: {
|
|
64
|
+
...variables.length ? { names: variables } : {},
|
|
65
|
+
...pathDetails,
|
|
66
|
+
source: publicSourceIdentifier(source)
|
|
67
|
+
}
|
|
68
|
+
}, `[vitehub] ${subject}${supply}`);
|
|
69
|
+
}
|
|
70
|
+
function isEnvVariableName(name) {
|
|
71
|
+
return /^[A-Za-z_][A-Za-z0-9_]{0,127}$/.test(name);
|
|
72
|
+
}
|
|
73
|
+
function invalidRuntimeEnvValue(source, diagnostic, path) {
|
|
74
|
+
return createEnvError({
|
|
75
|
+
cause: envErrorDiagnostics.ENV_R0011({ message: diagnostic }),
|
|
76
|
+
code: "ENV_RUNTIME_VALUE_INVALID",
|
|
77
|
+
details: {
|
|
78
|
+
...optionalPath(path),
|
|
79
|
+
source: publicSourceIdentifier(source)
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function envSourceFailed(source, cause) {
|
|
84
|
+
return createEnvError({
|
|
85
|
+
cause,
|
|
86
|
+
code: "ENV_SOURCE_FAILED",
|
|
87
|
+
details: { source: publicSourceIdentifier(source) }
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function isAbortError(value) {
|
|
91
|
+
if ((typeof value !== "object" || value === null) && typeof value !== "function") return false;
|
|
92
|
+
try {
|
|
93
|
+
return value.name === "AbortError";
|
|
94
|
+
} catch {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function publicSourceIdentifier(source) {
|
|
99
|
+
if (envSourceIdentifierSet.has(source)) return source;
|
|
100
|
+
if (source.startsWith("env:")) return "env";
|
|
101
|
+
if (source.startsWith("package.json:")) return "package.json";
|
|
102
|
+
return "custom";
|
|
103
|
+
}
|
|
104
|
+
function optionalPath(path) {
|
|
105
|
+
const normalized = safePath(path);
|
|
106
|
+
return normalized ? { path: normalized } : {};
|
|
107
|
+
}
|
|
108
|
+
function safePath(path) {
|
|
109
|
+
if (typeof path !== "string" || path.length > 256) return void 0;
|
|
110
|
+
return /^(?:env|runtime)(?:\.[A-Za-z_$][A-Za-z0-9_$-]{0,63}){0,8}$/.test(path) ? path : void 0;
|
|
111
|
+
}
|
|
112
|
+
// src/schema.ts
|
|
113
|
+
function parseSchema(schema, value, label) {
|
|
114
|
+
if (isSchemaModuleReference(schema)) throw envErrorDiagnostics.ENV_R0029({ message: `[vitehub] ${label} uses env.schemaFrom(), which only env.server supports. Pass the schema object itself.` });
|
|
115
|
+
const validate = readStandardValidate(schema, label);
|
|
116
|
+
if (validate) {
|
|
117
|
+
const result = validate(value);
|
|
118
|
+
if (isPromiseLike$1(result)) throw envErrorDiagnostics.ENV_R0014({ message: `[vitehub] ${label} uses an async schema. Env validation currently requires sync schemas.` });
|
|
119
|
+
const issues = standardResultIssues(result);
|
|
120
|
+
if (issues) throw envErrorDiagnostics.ENV_R0015({ message: `[vitehub] Invalid ${label}: ${formatStandardIssues(issues)}` });
|
|
121
|
+
if (!hasResultValue(result)) throw envErrorDiagnostics.ENV_R0016({ message: `[vitehub] Invalid ${label}: the schema returned no value.` });
|
|
122
|
+
return result.value;
|
|
123
|
+
}
|
|
124
|
+
if (isZodLike(schema) && hasSchemaMethod(schema, "safeParse") && typeof schema.safeParse === "function") {
|
|
125
|
+
const result = schema.safeParse(value);
|
|
126
|
+
if (!result.success) throw envErrorDiagnostics.ENV_R0017({ message: `[vitehub] Invalid ${label}: ${formatIssues(result.error)}` });
|
|
127
|
+
return result.data;
|
|
128
|
+
}
|
|
129
|
+
if (isZodLike(schema) && hasSchemaMethod(schema, "parse") && typeof schema.parse === "function") try {
|
|
130
|
+
return schema.parse(value);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
throw envErrorDiagnostics.ENV_R0018({ message: `[vitehub] Invalid ${label}: ${formatIssues(error)}` });
|
|
133
|
+
}
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
function readStandardValidate(schema, label) {
|
|
137
|
+
if (!isRecordOrFunction(schema)) return void 0;
|
|
138
|
+
try {
|
|
139
|
+
const standard = Reflect.get(schema, "~standard");
|
|
140
|
+
if (!isRecordOrFunction(standard)) return void 0;
|
|
141
|
+
const validate = Reflect.get(standard, "validate");
|
|
142
|
+
if (typeof validate !== "function") return void 0;
|
|
143
|
+
return (input) => Reflect.apply(validate, standard, [input]);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
throw invalidEnvDeclaration(label, `${label} has a schema that threw while ViteHub read its \`~standard\` validator.`, error);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function isSchemaModuleReference(schema) {
|
|
149
|
+
return typeof schema === "object" && schema !== null && !Array.isArray(schema) && schema.kind === "schema-module";
|
|
150
|
+
}
|
|
151
|
+
function isPromiseLike$1(value) {
|
|
152
|
+
return isRecordOrFunction(value) && typeof value.then === "function";
|
|
153
|
+
}
|
|
154
|
+
function hasResultValue(result) {
|
|
155
|
+
return isRecordOrFunction(result) && "value" in result;
|
|
156
|
+
}
|
|
157
|
+
function formatStandardIssues(issues) {
|
|
158
|
+
return issues.map((issue) => {
|
|
159
|
+
if (typeof issue === "string") return issue;
|
|
160
|
+
const message = isRecordOrFunction(issue) && typeof issue.message === "string" ? issue.message : "Invalid value.";
|
|
161
|
+
const segments = isRecordOrFunction(issue) && Array.isArray(issue.path) ? Array.from(issue.path, issuePathKey).filter((segment) => typeof segment === "string" || typeof segment === "number") : [];
|
|
162
|
+
return segments.length ? `${segments.join(".")}: ${message}` : message;
|
|
163
|
+
}).join("; ");
|
|
164
|
+
}
|
|
165
|
+
function issuePathKey(segment) {
|
|
166
|
+
return isRecordOrFunction(segment) ? segment.key : segment;
|
|
167
|
+
}
|
|
168
|
+
function isZodLike(schema) {
|
|
169
|
+
return typeof schema === "object" && schema !== null;
|
|
170
|
+
}
|
|
171
|
+
function hasSchemaMethod(schema, method) {
|
|
172
|
+
return Object.hasOwn(schema, method) || isZodSchemaMethod(schema, method);
|
|
173
|
+
}
|
|
174
|
+
function isZodSchemaMethod(schema, method) {
|
|
175
|
+
if (!Object.hasOwn(schema, "_zod")) return false;
|
|
176
|
+
const metadata = schema._zod;
|
|
177
|
+
if (!metadata) return false;
|
|
178
|
+
const constructor = metadata?.constr;
|
|
179
|
+
return hasSetValue(metadata?.traits, "ZodType") && Object.hasOwn(metadata, "constr") && typeof constructor === "function" && Object.getPrototypeOf(schema) === constructor.prototype && Object.hasOwn(constructor.prototype, method);
|
|
180
|
+
}
|
|
181
|
+
function hasSetValue(value, entry) {
|
|
182
|
+
try {
|
|
183
|
+
return Set.prototype.has.call(value, entry);
|
|
184
|
+
} catch {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function formatIssues(issues) {
|
|
189
|
+
if (Array.isArray(issues)) return issues.map((issue) => typeof issue === "string" ? issue : JSON.stringify(issue)).join("; ");
|
|
190
|
+
if (issues instanceof Error) return issues.message;
|
|
191
|
+
return typeof issues === "string" ? issues : JSON.stringify(issues);
|
|
192
|
+
}
|
|
193
|
+
// src/core/json-value.ts
|
|
11
194
|
/** JSON values accepted at the environment boundary, without prototype or internal keys. */
|
|
12
195
|
function isEnvSchemaValue(value, depth = 0) {
|
|
13
196
|
if (depth > 64) return false;
|
|
@@ -22,8 +205,7 @@ function isEnvSchemaValue(value, depth = 0) {
|
|
|
22
205
|
"__envSchemaUnset"
|
|
23
206
|
].includes(key) && isEnvSchemaValue(item, depth + 1));
|
|
24
207
|
}
|
|
25
|
-
|
|
26
|
-
//#region src/core/values.ts
|
|
208
|
+
// src/core/values.ts
|
|
27
209
|
const stringValueSchema = Object.freeze({ kind: "string" });
|
|
28
210
|
/** Parse one host, provider, or default value with a serializable Server Env value schema. */
|
|
29
211
|
function parseEnvValue(schema, input) {
|
|
@@ -191,8 +373,7 @@ function schemaContainsEnum(schema) {
|
|
|
191
373
|
default: return false;
|
|
192
374
|
}
|
|
193
375
|
}
|
|
194
|
-
|
|
195
|
-
//#region ../internal/src/runtime/cloudflare-env-lookup.ts
|
|
376
|
+
// ../internal/src/runtime/cloudflare-env-lookup.ts
|
|
196
377
|
/** The key of the AsyncLocalStorage store on `globalThis`. Every bundled copy of this module shares the store. */
|
|
197
378
|
const activeEnvStorageKey = Symbol.for("vitehub.cloudflare.env-storage");
|
|
198
379
|
let activeEnv;
|
|
@@ -206,15 +387,13 @@ function getActiveCloudflareEnv() {
|
|
|
206
387
|
const host = globalThis;
|
|
207
388
|
return Object.hasOwn(host, "__env__") && host.__env__ !== void 0 ? host.__env__ : activeEnv;
|
|
208
389
|
}
|
|
209
|
-
|
|
210
|
-
//#region ../internal/src/runtime/cloudflare-env.ts
|
|
390
|
+
// ../internal/src/runtime/cloudflare-env.ts
|
|
211
391
|
const runtimeGlobal = globalThis;
|
|
212
392
|
const activeEnvStorage = runtimeGlobal[activeEnvStorageKey] ||= new AsyncLocalStorage();
|
|
213
393
|
function runWithActiveCloudflareEnv(env, callback) {
|
|
214
394
|
return activeEnvStorage.run({ env }, callback);
|
|
215
395
|
}
|
|
216
|
-
|
|
217
|
-
//#region ../internal/src/secret.ts
|
|
396
|
+
// ../internal/src/secret.ts
|
|
218
397
|
const secretEncoder = new TextEncoder();
|
|
219
398
|
/**
|
|
220
399
|
* Compares a request value with an expected secret in constant time for the length of `expected`. Returns `false`
|
|
@@ -336,111 +515,7 @@ async function verifyViteHubStripeSignature(secret, header, body, options = {})
|
|
|
336
515
|
for (const signature of signatures) verified = isViteHubSecretEqual(signature, expected) || verified;
|
|
337
516
|
return verified;
|
|
338
517
|
}
|
|
339
|
-
|
|
340
|
-
//#region src/core/errors.ts
|
|
341
|
-
const envErrorMessages = {
|
|
342
|
-
ENV_DECLARATION_INVALID: "[vitehub] Env declaration is invalid.",
|
|
343
|
-
ENV_ASYNC_REQUIRED: "[vitehub] Server Env requires asynchronous loading.",
|
|
344
|
-
ENV_REQUIRED_MISSING: "[vitehub] Required Env value is missing.",
|
|
345
|
-
ENV_RUNTIME_VALUE_INVALID: "[vitehub] Runtime Env value is invalid.",
|
|
346
|
-
ENV_SOURCE_FAILED: "[vitehub] Env source resolution failed."
|
|
347
|
-
};
|
|
348
|
-
const envSourceIdentifierSet = /* @__PURE__ */ new Set([
|
|
349
|
-
"custom",
|
|
350
|
-
"env",
|
|
351
|
-
"git:branch",
|
|
352
|
-
"git:commit",
|
|
353
|
-
"git:tag",
|
|
354
|
-
"package.json",
|
|
355
|
-
"provider"
|
|
356
|
-
]);
|
|
357
|
-
function createEnvError(options, message = envErrorMessages[options.code]) {
|
|
358
|
-
const { code, cause, details } = options;
|
|
359
|
-
return new ViteHubError(code, message, {
|
|
360
|
-
...cause === void 0 ? {} : { cause },
|
|
361
|
-
...details === void 0 || Object.keys(details).length === 0 ? {} : { details }
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
function invalidEnvDeclaration(path, diagnostic, cause) {
|
|
365
|
-
return createEnvError({
|
|
366
|
-
cause: envErrorDiagnostics.ENV_R0008({
|
|
367
|
-
message: diagnostic,
|
|
368
|
-
...cause === void 0 ? {} : { cause }
|
|
369
|
-
}),
|
|
370
|
-
code: "ENV_DECLARATION_INVALID",
|
|
371
|
-
details: optionalPath(path)
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
function asyncServerEnvRequired(path) {
|
|
375
|
-
return createEnvError({
|
|
376
|
-
cause: envErrorDiagnostics.ENV_R0009({ message: `Server Env at ${path} uses env.provider(). Use loadServerEnv() or runWithServerEnv().` }),
|
|
377
|
-
code: "ENV_ASYNC_REQUIRED",
|
|
378
|
-
details: optionalPath(path)
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* The message and details name the declaration path and the variables that can supply it, so the operator
|
|
383
|
-
* knows what to set. Names are not secret; the value never appears because there is none.
|
|
384
|
-
*/
|
|
385
|
-
function missingRequiredEnv(source, diagnostic, path, names = []) {
|
|
386
|
-
const pathDetails = optionalPath(path);
|
|
387
|
-
const variables = names.filter(isEnvVariableName).slice(0, 8);
|
|
388
|
-
const subject = pathDetails.path ? `Required Env value ${pathDetails.path} is missing.` : "Required Env value is missing.";
|
|
389
|
-
const supply = variables.length ? ` Set ${variables.join(" or ")}.` : "";
|
|
390
|
-
return createEnvError({
|
|
391
|
-
cause: envErrorDiagnostics.ENV_R0010({ message: diagnostic }),
|
|
392
|
-
code: "ENV_REQUIRED_MISSING",
|
|
393
|
-
details: {
|
|
394
|
-
...variables.length ? { names: variables } : {},
|
|
395
|
-
...pathDetails,
|
|
396
|
-
source: publicSourceIdentifier(source)
|
|
397
|
-
}
|
|
398
|
-
}, `[vitehub] ${subject}${supply}`);
|
|
399
|
-
}
|
|
400
|
-
function isEnvVariableName(name) {
|
|
401
|
-
return /^[A-Za-z_][A-Za-z0-9_]{0,127}$/.test(name);
|
|
402
|
-
}
|
|
403
|
-
function invalidRuntimeEnvValue(source, diagnostic, path) {
|
|
404
|
-
return createEnvError({
|
|
405
|
-
cause: envErrorDiagnostics.ENV_R0011({ message: diagnostic }),
|
|
406
|
-
code: "ENV_RUNTIME_VALUE_INVALID",
|
|
407
|
-
details: {
|
|
408
|
-
...optionalPath(path),
|
|
409
|
-
source: publicSourceIdentifier(source)
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
function envSourceFailed(source, cause) {
|
|
414
|
-
return createEnvError({
|
|
415
|
-
cause,
|
|
416
|
-
code: "ENV_SOURCE_FAILED",
|
|
417
|
-
details: { source: publicSourceIdentifier(source) }
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
function isAbortError(value) {
|
|
421
|
-
if ((typeof value !== "object" || value === null) && typeof value !== "function") return false;
|
|
422
|
-
try {
|
|
423
|
-
return value.name === "AbortError";
|
|
424
|
-
} catch {
|
|
425
|
-
return false;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
function publicSourceIdentifier(source) {
|
|
429
|
-
if (envSourceIdentifierSet.has(source)) return source;
|
|
430
|
-
if (source.startsWith("env:")) return "env";
|
|
431
|
-
if (source.startsWith("package.json:")) return "package.json";
|
|
432
|
-
return "custom";
|
|
433
|
-
}
|
|
434
|
-
function optionalPath(path) {
|
|
435
|
-
const normalized = safePath(path);
|
|
436
|
-
return normalized ? { path: normalized } : {};
|
|
437
|
-
}
|
|
438
|
-
function safePath(path) {
|
|
439
|
-
if (typeof path !== "string" || path.length > 256) return void 0;
|
|
440
|
-
return /^(?:env|runtime)(?:\.[A-Za-z_$][A-Za-z0-9_$-]{0,63}){0,8}$/.test(path) ? path : void 0;
|
|
441
|
-
}
|
|
442
|
-
//#endregion
|
|
443
|
-
//#region src/internal/runtime-env.ts
|
|
518
|
+
// src/internal/runtime-env.ts
|
|
444
519
|
function processEnv() {
|
|
445
520
|
return typeof process === "object" && process && process.env ? process.env : {};
|
|
446
521
|
}
|
|
@@ -473,8 +548,7 @@ function standardSource(event) {
|
|
|
473
548
|
if ("~standard" in event) return event;
|
|
474
549
|
return event instanceof Request ? event : event.req;
|
|
475
550
|
}
|
|
476
|
-
|
|
477
|
-
//#region src/core/registry.ts
|
|
551
|
+
// src/core/registry.ts
|
|
478
552
|
const envEntrySchema = v.object({
|
|
479
553
|
required: v.boolean(),
|
|
480
554
|
secret: v.boolean(),
|
|
@@ -513,8 +587,7 @@ function* runtimeRegistryEntries(value, path = "env.server") {
|
|
|
513
587
|
if (!isRecord(value)) return;
|
|
514
588
|
for (const [key, child] of Object.entries(value)) yield* runtimeRegistryEntries(child, `${path}.${key.includes(".") ? "!" : ""}${key}`);
|
|
515
589
|
}
|
|
516
|
-
|
|
517
|
-
//#region ../internal/src/invariant.ts
|
|
590
|
+
// ../internal/src/invariant.ts
|
|
518
591
|
const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
519
592
|
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
520
593
|
codes: { INTERNAL_INVARIANT_FAILED: {
|
|
@@ -533,8 +606,7 @@ function invariantError(what) {
|
|
|
533
606
|
function invariant(condition, what) {
|
|
534
607
|
if (!condition) throw invariantError(what);
|
|
535
608
|
}
|
|
536
|
-
|
|
537
|
-
//#region src/seal-uses.ts
|
|
609
|
+
// src/seal-uses.ts
|
|
538
610
|
function isSealUseCount(value) {
|
|
539
611
|
return typeof value === "number" && Number.isSafeInteger(value) && value >= 1;
|
|
540
612
|
}
|
|
@@ -576,8 +648,7 @@ async function deleteSealUses(db, id) {
|
|
|
576
648
|
await initialize(db);
|
|
577
649
|
await db.all(`DELETE FROM ${table} WHERE id = '${checkId(id)}'`);
|
|
578
650
|
}
|
|
579
|
-
|
|
580
|
-
//#region src/seal-value.ts
|
|
651
|
+
// src/seal-value.ts
|
|
581
652
|
const sealErrors = /*#__PURE__*/ defineErrors({
|
|
582
653
|
docs: "https://vitehub.dev/docs/env/diagnostics",
|
|
583
654
|
codes: {
|
|
@@ -788,8 +859,7 @@ function seal(purpose, value, options) {
|
|
|
788
859
|
function unseal(purpose, sealed, options) {
|
|
789
860
|
return sealing.unseal(purpose, sealed, options);
|
|
790
861
|
}
|
|
791
|
-
|
|
792
|
-
//#region src/server.ts
|
|
862
|
+
// src/server.ts
|
|
793
863
|
/**
|
|
794
864
|
* Run `callback` with `env` as the active Cloudflare bindings. Server Env reads them when a call gets no request
|
|
795
865
|
* event, such as for the module bindings of `cloudflare:workers` outside a request.
|
|
@@ -850,20 +920,15 @@ function bindServerEnvSchemas(registry, modules) {
|
|
|
850
920
|
if (!(isRuntimeEnvEntry(entry) || isRuntimeProviderEntry(entry)) || !entry.schemaModule) continue;
|
|
851
921
|
const reference = entry.schemaModule;
|
|
852
922
|
const module = Object.hasOwn(modules, reference.module) ? modules[reference.module] : void 0;
|
|
853
|
-
const
|
|
854
|
-
if (!
|
|
855
|
-
boundSchemas.set(entry,
|
|
923
|
+
const validate = readStandardValidate(module && Object.hasOwn(module, reference.export) ? module[reference.export] : void 0, path);
|
|
924
|
+
if (!validate) throw invalidEnvDeclaration(path, `${path} uses env.schemaFrom(${JSON.stringify(reference.module)}, ${JSON.stringify(reference.export)}), but that export is not a Standard Schema.`);
|
|
925
|
+
boundSchemas.set(entry, validate);
|
|
856
926
|
}
|
|
857
927
|
}
|
|
858
|
-
function isBoundStandardSchema(value) {
|
|
859
|
-
if (typeof value !== "object" && typeof value !== "function" || value === null) return false;
|
|
860
|
-
const standard = value["~standard"];
|
|
861
|
-
return typeof standard === "object" && standard !== null && typeof standard.validate === "function";
|
|
862
|
-
}
|
|
863
928
|
function parseRuntimeValue(entry, value, path) {
|
|
864
929
|
if (!entry.schemaModule) return parseEnvValue(entry.schema ?? stringValueSchema, value);
|
|
865
|
-
const
|
|
866
|
-
if (!
|
|
930
|
+
const validate = boundSchemas.get(entry);
|
|
931
|
+
if (!validate) throw invalidEnvDeclaration(path, `${path} uses env.schemaFrom(), but no schema module was loaded for it. Only env.server declarations of hubEnv() support env.schemaFrom().`);
|
|
867
932
|
let input = value;
|
|
868
933
|
if (entry.schemaModule.input === "json") {
|
|
869
934
|
const json = readJsonInput(value);
|
|
@@ -872,7 +937,7 @@ function parseRuntimeValue(entry, value, path) {
|
|
|
872
937
|
}
|
|
873
938
|
let result;
|
|
874
939
|
try {
|
|
875
|
-
result =
|
|
940
|
+
result = validate(input);
|
|
876
941
|
} catch (error) {
|
|
877
942
|
return {
|
|
878
943
|
message: `The schema threw: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -886,12 +951,12 @@ function parseRuntimeValue(entry, value, path) {
|
|
|
886
951
|
success: false
|
|
887
952
|
};
|
|
888
953
|
}
|
|
889
|
-
const issues =
|
|
890
|
-
if (
|
|
891
|
-
message:
|
|
954
|
+
const issues = standardResultIssues(result);
|
|
955
|
+
if (issues) return {
|
|
956
|
+
message: formatStandardIssues(issues),
|
|
892
957
|
success: false
|
|
893
958
|
};
|
|
894
|
-
if (!
|
|
959
|
+
if (!hasResultValue(result)) return {
|
|
895
960
|
message: "The schema returned no value.",
|
|
896
961
|
success: false
|
|
897
962
|
};
|
|
@@ -903,13 +968,6 @@ function parseRuntimeValue(entry, value, path) {
|
|
|
903
968
|
function isPromiseLike(value) {
|
|
904
969
|
return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
|
|
905
970
|
}
|
|
906
|
-
function formatSchemaIssues(issues) {
|
|
907
|
-
return issues.map((issue) => {
|
|
908
|
-
const message = isRecord(issue) && typeof issue.message === "string" ? issue.message : "Invalid value.";
|
|
909
|
-
const segments = isRecord(issue) && Array.isArray(issue.path) ? issue.path.map((segment) => isRecord(segment) ? segment.key : segment).filter((segment) => typeof segment === "string" || typeof segment === "number") : [];
|
|
910
|
-
return segments.length ? `${segments.join(".")}: ${message}` : message;
|
|
911
|
-
}).join("; ");
|
|
912
|
-
}
|
|
913
971
|
function resolvedRuntimeValue(entry, value, found, path, snapshot = false) {
|
|
914
972
|
const resolved = found ? value : entry.default;
|
|
915
973
|
if (typeof resolved === "undefined") {
|
|
@@ -1274,5 +1332,4 @@ async function inspectServerEnv(registry, event, options = {}) {
|
|
|
1274
1332
|
if (options.signal?.aborted) throw abortReason(options.signal);
|
|
1275
1333
|
return Object.freeze({ entries: Object.freeze(entries.map((entry) => Object.freeze(entry))) });
|
|
1276
1334
|
}
|
|
1277
|
-
|
|
1278
|
-
export { envValueTypeName as A, deriveViteHubSecret as C, verifyViteHubHmacSignature as D, readViteHubSecret as E, stringValueSchema as F, isEnvSchemaValue as I, parseEnvValue as M, readJsonInput as N, verifyViteHubStripeSignature as O, schemaContainsEnum as P, missingRequiredEnv as S, isViteHubBearerSecretEqual as T, runtimeEnv as _, isBlockingServerEnvEntry as a, invalidEnvDeclaration as b, runWithCloudflareEnv as c, unseal as d, invariant as f, runtimeRegistryEntries as g, isRuntimeProviderEntry as h, inspectServerEnv as i, listItemKinds as j, viteHubHmacSha256 as k, createSealing as l, isRuntimeLiteralEntry as m, deriveSecret as n, loadServerEnv as o, isRuntimeEnvEntry as p, describeServerEnv as r, resolveServerEnv as s, bindServerEnvSchemas as t, seal as u, standardSource as v, githubHmacSignatureFormat as w, isAbortError as x, envSourceFailed as y };
|
|
1335
|
+
export { schemaContainsEnum as A, verifyViteHubHmacSignature as C, listItemKinds as D, envValueTypeName as E, envSourceFailed as F, invalidEnvDeclaration as I, isAbortError as L, isEnvSchemaValue as M, parseSchema as N, parseEnvValue as O, readStandardValidate as P, missingRequiredEnv as R, readViteHubSecret as S, viteHubHmacSha256 as T, runtimeEnv as _, isBlockingServerEnvEntry as a, githubHmacSignatureFormat as b, runWithCloudflareEnv as c, unseal as d, invariant as f, runtimeRegistryEntries as g, isRuntimeProviderEntry as h, inspectServerEnv as i, stringValueSchema as j, readJsonInput as k, createSealing as l, isRuntimeLiteralEntry as m, deriveSecret as n, loadServerEnv as o, isRuntimeEnvEntry as p, describeServerEnv as r, resolveServerEnv as s, bindServerEnvSchemas as t, seal as u, standardSource as v, verifyViteHubStripeSignature as w, isViteHubBearerSecretEqual as x, deriveViteHubSecret as y };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { G as ServerEnvInspection, K as ServerEnvInspectionEntry, q as ServerEnvInspectionStatus, t as EnvAccessContext } from "./bridge-
|
|
2
|
-
import { _ as unseal, a as describeServerEnv, c as loadServerEnv, d as SealOptions, f as UnsealErrorCode, g as seal, h as createSealing, i as deriveSecret, l as resolveServerEnv, m as UnsealSchemaOptions, n as ViteHubContext, o as inspectServerEnv, p as UnsealOptions, r as bindServerEnvSchemas, s as isBlockingServerEnvEntry, t as DeriveSecretOptions, u as runWithCloudflareEnv } from "./server-
|
|
1
|
+
import { G as ServerEnvInspection, K as ServerEnvInspectionEntry, q as ServerEnvInspectionStatus, t as EnvAccessContext } from "./bridge-BWwIooe0.js";
|
|
2
|
+
import { _ as unseal, a as describeServerEnv, c as loadServerEnv, d as SealOptions, f as UnsealErrorCode, g as seal, h as createSealing, i as deriveSecret, l as resolveServerEnv, m as UnsealSchemaOptions, n as ViteHubContext, o as inspectServerEnv, p as UnsealOptions, r as bindServerEnvSchemas, s as isBlockingServerEnvEntry, t as DeriveSecretOptions, u as runWithCloudflareEnv } from "./server-CPEywepM.js";
|
|
3
3
|
export { DeriveSecretOptions, type EnvAccessContext, type SealOptions, type ServerEnvInspection, type ServerEnvInspectionEntry, type ServerEnvInspectionStatus, type UnsealErrorCode, type UnsealOptions, type UnsealSchemaOptions, type ViteHubContext, bindServerEnvSchemas, createSealing, deriveSecret, describeServerEnv, inspectServerEnv, isBlockingServerEnvEntry, loadServerEnv, resolveServerEnv, runWithCloudflareEnv, seal, unseal };
|
package/dist/server.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { bindServerEnvSchemas, createSealing, deriveSecret, describeServerEnv, inspectServerEnv, isBlockingServerEnvEntry, loadServerEnv, resolveServerEnv, runWithCloudflareEnv, seal, unseal };
|
|
1
|
+
export { t as bindServerEnvSchemas, l as createSealing, n as deriveSecret, r as describeServerEnv, i as inspectServerEnv, a as isBlockingServerEnvEntry, o as loadServerEnv, s as resolveServerEnv, c as runWithCloudflareEnv, u as seal, d as unseal } from "./server-pTqnkM7n.js";
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { n as OperationContributionEntry } from "./operation-definition-
|
|
1
|
+
import { t as env } from "./declarations-DNjO52_s.js";
|
|
2
|
+
import { A as EnvRuntimeRegistry, b as EnvDeclarations, k as EnvRuntimeConfigOptions, w as EnvOptions } from "./bridge-BWwIooe0.js";
|
|
3
|
+
import { n as ViteHubCliContributor } from "./cli-B-LW6l_J.js";
|
|
4
|
+
import { n as OperationContributionEntry } from "./operation-definition-CqZkx1Rm.js";
|
|
5
5
|
import { Plugin, UserConfig } from "vite";
|
|
6
|
-
//#region ../internal/src/deployment.d.ts
|
|
7
6
|
/** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
|
|
8
7
|
type ViteHubHost = "cloudflare" | "deno" | "netlify" | "node" | "vercel";
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region ../internal/src/build/deployment-plan-output.d.ts
|
|
11
8
|
/**
|
|
12
9
|
* One set of host variables that the deployed app reads, as `deployment.json` lists it: a Server Env declaration, or
|
|
13
10
|
* a variable that a primitive reads itself, such as `VITEHUB_SECRET` or `BLOB_READ_WRITE_TOKEN`.
|
|
@@ -37,12 +34,8 @@ interface DeploymentEnvContext {
|
|
|
37
34
|
* Return names only, never values.
|
|
38
35
|
*/
|
|
39
36
|
type DeploymentEnvContribution = (context: DeploymentEnvContext) => readonly DeploymentEnvEntry[];
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region ../internal/src/build/vite.d.ts
|
|
42
37
|
declare const VITEHUB_ENV_PUBLIC_ID: "#vitehub/env/public";
|
|
43
38
|
declare const VITEHUB_ENV_SERVER_ID: "#vitehub/env/server";
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/core/resolve.d.ts
|
|
46
39
|
interface RuntimeRegistryOptions {
|
|
47
40
|
path?: string;
|
|
48
41
|
prefix?: string | false;
|
|
@@ -50,8 +43,6 @@ interface RuntimeRegistryOptions {
|
|
|
50
43
|
schemaModules?: boolean;
|
|
51
44
|
}
|
|
52
45
|
declare function createRuntimeRegistry(declarations: EnvRuntimeConfigOptions | undefined, options?: RuntimeRegistryOptions): EnvRuntimeRegistry;
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/env-schema/importer.d.ts
|
|
55
46
|
interface EnvSchemaOptions {
|
|
56
47
|
prefix?: string;
|
|
57
48
|
/** Exact schema key to output path. Only Server Env supports nested paths. */
|
|
@@ -59,8 +50,6 @@ interface EnvSchemaOptions {
|
|
|
59
50
|
}
|
|
60
51
|
/** Import a committed env-spec-v1 contract. Reads schema metadata, never developer env files. */
|
|
61
52
|
export declare function envSchema(file: string | URL, options?: EnvSchemaOptions): EnvDeclarations;
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/vite.d.ts
|
|
64
53
|
export declare const ENV_VITE_PLUGIN_NAME = "@vite-hub/env/vite";
|
|
65
54
|
export declare const ENV_PUBLIC_ID: typeof VITEHUB_ENV_PUBLIC_ID;
|
|
66
55
|
export declare const ENV_SERVER_ID: typeof VITEHUB_ENV_SERVER_ID;
|
|
@@ -97,5 +86,4 @@ export declare function createEnvTypeScriptPaths(options?: EnvGeneratedPathOptio
|
|
|
97
86
|
*/
|
|
98
87
|
export declare function createEnvTypes(config: EnvDeclarations | undefined, options?: Pick<EnvOptions, "prefix" | "runtimeImports" | "projectRoot">): string;
|
|
99
88
|
export declare function hubEnv(options?: EnvOptions): EnvVitePlugin;
|
|
100
|
-
//#endregion
|
|
101
89
|
export { type EnvSchemaOptions, createRuntimeRegistry as createRuntimeEnvRegistry, env };
|
package/dist/vite.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { A as schemaContainsEnum, E as envValueTypeName, F as envSourceFailed, I as invalidEnvDeclaration, L as isAbortError, M as isEnvSchemaValue, N as parseSchema, O as parseEnvValue, R as missingRequiredEnv, S as readViteHubSecret, f as invariant, g as runtimeRegistryEntries, h as isRuntimeProviderEntry, j as stringValueSchema, m as isRuntimeLiteralEntry, p as isRuntimeEnvEntry, r as describeServerEnv } from "./server-pTqnkM7n.js";
|
|
2
|
+
import { a as VITEHUB_ENV_SERVER, c as createViteHubEnvImportAliases, d as viteHubEnvAmbientTypesPath, f as viteHubEnvDescriptionModulePath, g as viteHubEnvServerModuleTypesPath, h as viteHubEnvServerModulePath, i as VITEHUB_ENV_PUBLIC_ID, l as isServerEnvironment, m as viteHubEnvPublicModuleTypesPath, o as VITEHUB_ENV_SERVER_ID, p as viteHubEnvPublicModulePath, r as loadAllEnv, s as createNoExternalAddition, t as createEnvCliContributor, u as resolveViteHubProjectRoot } from "./cli-CAlHK5nn.js";
|
|
3
|
+
import { i as schemaModuleReference, n as env, r as runtimeValueSchema, t as descriptorVariable } from "./declarations-meg4Rmgd.js";
|
|
4
|
+
import { t as envErrorDiagnostics } from "./error-diagnostics-BFzFaXcH.js";
|
|
5
5
|
import { Diagnostic } from "nostics";
|
|
6
6
|
import { isViteHubError } from "@vite-hub/runtime";
|
|
7
7
|
import { existsSync, readFileSync } from "node:fs";
|
|
@@ -9,11 +9,12 @@ import { dirname, isAbsolute, relative, resolve, win32 } from "node:path";
|
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
import { chmod, mkdir, open, readFile, rename, stat, unlink, writeFile } from "node:fs/promises";
|
|
11
11
|
import { createHash, randomBytes } from "node:crypto";
|
|
12
|
+
import MagicString from "magic-string";
|
|
12
13
|
import { loadEnv } from "vite";
|
|
13
14
|
import { execFile } from "node:child_process";
|
|
14
15
|
import { promisify } from "node:util";
|
|
15
16
|
import { ParsedEnvSpecFunctionCall, ParsedEnvSpecKeyValuePair, ParsedEnvSpecStaticValue, parseEnvSpecDotEnvFile } from "@env-spec/parser";
|
|
16
|
-
|
|
17
|
+
// ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
17
18
|
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
18
19
|
function normalizeWindowsPath(input = "") {
|
|
19
20
|
if (!input) return input;
|
|
@@ -97,8 +98,7 @@ const dirname$1 = function(p) {
|
|
|
97
98
|
if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
|
|
98
99
|
return segments.join("/") || (isAbsolute$1(p) ? "/" : ".");
|
|
99
100
|
};
|
|
100
|
-
|
|
101
|
-
//#region ../internal/src/build/paths.ts
|
|
101
|
+
// ../internal/src/build/paths.ts
|
|
102
102
|
function resolveRuntimeModule(packageDir, modulePath) {
|
|
103
103
|
const distFile = resolve$1(packageDir, "dist", `${modulePath}.js`);
|
|
104
104
|
return existsSync(distFile) ? distFile : resolve$1(packageDir, "src", `${modulePath}.ts`);
|
|
@@ -125,16 +125,14 @@ function findPackageDir(file) {
|
|
|
125
125
|
function ownModule(importMetaUrl, modulePath) {
|
|
126
126
|
return resolveRuntimeModule(findPackageDir(fileURLToPath(importMetaUrl)), modulePath);
|
|
127
127
|
}
|
|
128
|
-
|
|
129
|
-
//#region ../internal/src/definition-catalog.ts
|
|
128
|
+
// ../internal/src/definition-catalog.ts
|
|
130
129
|
/** `writeFileIfChangedSync` for async callers. */
|
|
131
130
|
async function writeFileIfChanged(file, contents) {
|
|
132
131
|
if (await readFile(file, "utf8").catch(() => void 0) === contents) return;
|
|
133
132
|
await mkdir(resolve$1(file, ".."), { recursive: true });
|
|
134
133
|
await writeFile(file, contents, "utf8");
|
|
135
134
|
}
|
|
136
|
-
|
|
137
|
-
//#region src/core/diagnostics.ts
|
|
135
|
+
// src/core/diagnostics.ts
|
|
138
136
|
function shouldTraceDiagnostics(option) {
|
|
139
137
|
return option === "trace" || process.env.VITEHUB_ENV_TRACE === "true";
|
|
140
138
|
}
|
|
@@ -152,8 +150,7 @@ function formatDiagnostics(entries, option = "summary") {
|
|
|
152
150
|
entry.masked ? " value: ********" : void 0
|
|
153
151
|
].filter(Boolean))].join("\n");
|
|
154
152
|
}
|
|
155
|
-
|
|
156
|
-
//#region src/core/resolve.ts
|
|
153
|
+
// src/core/resolve.ts
|
|
157
154
|
const execFileAsync = promisify(execFile);
|
|
158
155
|
const envOptionKeys = /* @__PURE__ */ new Set([
|
|
159
156
|
"define",
|
|
@@ -638,8 +635,7 @@ function readPath(value, path) {
|
|
|
638
635
|
return current[segment];
|
|
639
636
|
}, value);
|
|
640
637
|
}
|
|
641
|
-
|
|
642
|
-
//#region src/env-schema/profile.ts
|
|
638
|
+
// src/env-schema/profile.ts
|
|
643
639
|
function fail$1(context, reason) {
|
|
644
640
|
throw envErrorDiagnostics.ENV_B0006({ message: `${context.file}:${context.line}${context.key ? ` (${context.key})` : ""}: ${reason}` });
|
|
645
641
|
}
|
|
@@ -931,8 +927,7 @@ function parseEnvSchema(source, filename) {
|
|
|
931
927
|
return field;
|
|
932
928
|
});
|
|
933
929
|
}
|
|
934
|
-
|
|
935
|
-
//#region src/env-schema/importer.ts
|
|
930
|
+
// src/env-schema/importer.ts
|
|
936
931
|
function fail(field, reason) {
|
|
937
932
|
const path = field ? `${field.source.file}:${field.source.line} (${field.key})` : "envSchema";
|
|
938
933
|
throw invalidEnvDeclaration(path, `${path}: ${reason}`);
|
|
@@ -1052,8 +1047,7 @@ function envSchema(file, options = {}) {
|
|
|
1052
1047
|
server: serverConfig(server)
|
|
1053
1048
|
};
|
|
1054
1049
|
}
|
|
1055
|
-
|
|
1056
|
-
//#region src/vite.ts
|
|
1050
|
+
// src/vite.ts
|
|
1057
1051
|
const ENV_VITE_PLUGIN_NAME = "@vite-hub/env/vite";
|
|
1058
1052
|
const envNoExternal = createNoExternalAddition("@vite-hub/env");
|
|
1059
1053
|
const ENV_PUBLIC_ID = VITEHUB_ENV_PUBLIC_ID;
|
|
@@ -1340,7 +1334,13 @@ function hubEnv(options = {}) {
|
|
|
1340
1334
|
filter: { code: "/* @vitehub-env */" },
|
|
1341
1335
|
handler(code) {
|
|
1342
1336
|
if (!code.includes("/* @vitehub-env */") || !code.includes(ENV_SERVER_ID)) return;
|
|
1343
|
-
|
|
1337
|
+
const output = new MagicString(code);
|
|
1338
|
+
output.replaceAll(/\/\* @vite-ignore \*\/\s*\/\* @vitehub-env \*\/\s*[\w$]+/g, JSON.stringify(ENV_SERVER_ID));
|
|
1339
|
+
if (!output.hasChanged()) return;
|
|
1340
|
+
return {
|
|
1341
|
+
code: output.toString(),
|
|
1342
|
+
map: output.generateMap({ hires: "boundary" })
|
|
1343
|
+
};
|
|
1344
1344
|
}
|
|
1345
1345
|
}
|
|
1346
1346
|
};
|
|
@@ -1755,5 +1755,4 @@ function literalType(value) {
|
|
|
1755
1755
|
default: return "unknown";
|
|
1756
1756
|
}
|
|
1757
1757
|
}
|
|
1758
|
-
//#endregion
|
|
1759
1758
|
export { ENV_PUBLIC_ID, ENV_SERVER_ID, ENV_VITE_PLUGIN_NAME, createEnvImportAliases, createEnvTypeScriptPaths, createEnvTypes, createRuntimeRegistry as createRuntimeEnvRegistry, env, envSchema, hubEnv };
|