@vite-env/core 0.5.3 → 0.6.0
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 +34 -18
- package/dist/chunk-CKQMccvm.cjs +28 -0
- package/dist/config.cjs +1 -1
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs.map +1 -1
- package/dist/dts.cjs +102 -3
- package/dist/dts.cjs.map +1 -0
- package/dist/dts.d.cts +1 -1
- package/dist/dts.d.mts +1 -1
- package/dist/dts.mjs +18 -5
- package/dist/dts.mjs.map +1 -1
- package/dist/format.cjs.map +1 -1
- package/dist/format.d.cts +2 -2
- package/dist/format.d.mts +2 -2
- package/dist/format.mjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/leak.cjs.map +1 -1
- package/dist/leak.d.cts +1 -1
- package/dist/leak.d.mts +1 -1
- package/dist/leak.mjs.map +1 -1
- package/dist/load.cjs +50 -0
- package/dist/load.cjs.map +1 -0
- package/dist/load.d.cts +29 -0
- package/dist/load.d.mts +29 -0
- package/dist/load.mjs +46 -0
- package/dist/load.mjs.map +1 -0
- package/dist/plugin.cjs +5 -4
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +1 -1
- package/dist/plugin.d.mts +1 -1
- package/dist/plugin.mjs.map +1 -1
- package/dist/presets/index.cjs +71 -62
- package/dist/presets/index.cjs.map +1 -1
- package/dist/presets/index.d.cts +3 -0
- package/dist/presets/index.d.mts +3 -0
- package/dist/presets/index.mjs +70 -61
- package/dist/presets/index.mjs.map +1 -1
- package/dist/schema.cjs +6 -1
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +2 -2
- package/dist/schema.d.mts +2 -2
- package/dist/schema.mjs +5 -0
- package/dist/schema.mjs.map +1 -1
- package/dist/standard.cjs.map +1 -1
- package/dist/standard.d.cts +2 -2
- package/dist/standard.d.mts +2 -2
- package/dist/standard.mjs.map +1 -1
- package/dist/{types--Km3TAdJ.d.mts → types-Ctg8aeXQ.d.mts} +15 -3
- package/dist/{types-CpYkRwLM.d.cts → types-DudMh278.d.cts} +15 -3
- package/package.json +43 -33
- package/dist/dts-CJcj6BIn.cjs +0 -126
- package/dist/dts-CJcj6BIn.cjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.cjs","names":["process","path","isStandardEnvDefinition","validateStandardEnv","validateEnv"],"sources":["../src/load.ts"],"sourcesContent":["import type { EnvPreset, StandardEnvDefinition } from \"./types\";\nimport type { z } from \"zod\";\nimport process from \"node:process\";\nimport path from \"node:path\";\nimport { loadEnv as viteLoadEnv } from \"vite\";\nimport { isStandardEnvDefinition, validateStandardEnv } from \"./standard\";\nimport { validateEnv } from \"./schema\";\n\nexport type LoadEnvOptions = {\n mode?: string;\n envDir?: string;\n};\n\ntype ZodShape = z.ZodRawShape;\n\ntype KnownKeys<T> = keyof { [K in keyof T as string extends K ? never : K]: T[K] };\ntype StripIndex<T extends ZodShape> = Pick<T, KnownKeys<T>>;\n\ntype InferShape<TServer extends ZodShape, TClient extends ZodShape> = {\n server: z.infer<z.ZodObject<StripIndex<TServer> & StripIndex<TClient>>>;\n client: z.infer<z.ZodObject<StripIndex<TClient>>>;\n all: z.infer<z.ZodObject<StripIndex<TServer> & StripIndex<TClient>>>;\n};\n\nexport async function loadEnv<\n TServer extends ZodShape = Record<never, never>,\n TClient extends ZodShape = Record<never, never>,\n>(\n config: { server?: TServer; client?: TClient; presets?: EnvPreset[] },\n options?: LoadEnvOptions,\n): Promise<InferShape<TServer, TClient>>;\n\nexport async function loadEnv(\n config: StandardEnvDefinition,\n options?: LoadEnvOptions,\n): Promise<{\n server: Record<string, unknown>;\n client: Record<string, unknown>;\n all: Record<string, unknown>;\n}>;\n\nexport async function loadEnv(\n config: { server?: ZodShape; client?: ZodShape; presets?: EnvPreset[] } | StandardEnvDefinition,\n options: LoadEnvOptions = {},\n): Promise<{\n server: Record<string, unknown>;\n client: Record<string, unknown>;\n all: Record<string, unknown>;\n}> {\n const mode = options.mode ?? process.env[\"NODE_ENV\"] ?? \"development\";\n const envDir = options.envDir ? path.resolve(options.envDir) : process.cwd();\n\n const fileEnv = viteLoadEnv(mode, envDir, \"\");\n const rawEnv: Record<string, string> = {\n ...fileEnv,\n ...filterStrings(process.env),\n };\n\n if (isStandardEnvDefinition(config)) {\n const result = await validateStandardEnv(config, rawEnv);\n if (!result.success) throwValidationError(result.errors.map((e) => e.message));\n\n const server = Object.freeze(result.data);\n const clientKeys = new Set(Object.keys(config.client ?? {}));\n const client = Object.freeze(filterByKeys(server, clientKeys));\n\n return { server, client, all: server };\n }\n\n const result = validateEnv(config, rawEnv);\n if (!result.success) throwValidationError(result.errors.map((e) => e.message));\n\n const server = Object.freeze(result.data);\n const clientKeys = new Set(Object.keys(config.client ?? {}));\n const client = Object.freeze(filterByKeys(server, clientKeys));\n\n return { server, client, all: server };\n}\n\nfunction filterByKeys(data: Record<string, unknown>, keys: Set<string>): Record<string, unknown> {\n return Object.fromEntries(Object.entries(data).filter(([k]) => keys.has(k)));\n}\n\nfunction filterStrings(env: NodeJS.ProcessEnv): Record<string, string> {\n return Object.fromEntries(\n Object.entries(env).filter((e): e is [string, string] => typeof e[1] === \"string\"),\n );\n}\n\nfunction throwValidationError(messages: string[]): never {\n const lines = messages.map((m) => \" - \" + m).join(\"\\n\");\n throw new Error(\"[vite-env] Validation failed:\\n\" + lines);\n}\n"],"mappings":";;;;;;;;;;AAyCA,eAAsB,QACpB,QACA,UAA0B,EAAE,EAK3B;CAKD,MAAM,SAAiC;EACrC,IAAA,GAAA,KAAA,SALW,QAAQ,QAAQA,aAAAA,QAAQ,IAAI,eAAe,eACzC,QAAQ,SAASC,UAAAA,QAAK,QAAQ,QAAQ,OAAO,GAAGD,aAAAA,QAAQ,KAAK,EAElC,GAE9B;EACV,GAAG,cAAcA,aAAAA,QAAQ,IAAI;EAC9B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
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/load.d.ts
|
|
5
|
+
type LoadEnvOptions = {
|
|
6
|
+
mode?: string;
|
|
7
|
+
envDir?: string;
|
|
8
|
+
};
|
|
9
|
+
type ZodShape = z.ZodRawShape;
|
|
10
|
+
type KnownKeys<T> = keyof { [K in keyof T as string extends K ? never : K]: T[K] };
|
|
11
|
+
type StripIndex<T extends ZodShape> = Pick<T, KnownKeys<T>>;
|
|
12
|
+
type InferShape<TServer extends ZodShape, TClient extends ZodShape> = {
|
|
13
|
+
server: z.infer<z.ZodObject<StripIndex<TServer> & StripIndex<TClient>>>;
|
|
14
|
+
client: z.infer<z.ZodObject<StripIndex<TClient>>>;
|
|
15
|
+
all: z.infer<z.ZodObject<StripIndex<TServer> & StripIndex<TClient>>>;
|
|
16
|
+
};
|
|
17
|
+
declare function loadEnv<TServer extends ZodShape = Record<never, never>, TClient extends ZodShape = Record<never, never>>(config: {
|
|
18
|
+
server?: TServer;
|
|
19
|
+
client?: TClient;
|
|
20
|
+
presets?: EnvPreset[];
|
|
21
|
+
}, options?: LoadEnvOptions): Promise<InferShape<TServer, TClient>>;
|
|
22
|
+
declare function loadEnv(config: StandardEnvDefinition, options?: LoadEnvOptions): Promise<{
|
|
23
|
+
server: Record<string, unknown>;
|
|
24
|
+
client: Record<string, unknown>;
|
|
25
|
+
all: Record<string, unknown>;
|
|
26
|
+
}>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { LoadEnvOptions, loadEnv };
|
|
29
|
+
//# sourceMappingURL=load.d.cts.map
|
package/dist/load.d.mts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { o as StandardEnvDefinition, r as EnvPreset } from "./types-Ctg8aeXQ.mjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/load.d.ts
|
|
5
|
+
type LoadEnvOptions = {
|
|
6
|
+
mode?: string;
|
|
7
|
+
envDir?: string;
|
|
8
|
+
};
|
|
9
|
+
type ZodShape = z.ZodRawShape;
|
|
10
|
+
type KnownKeys<T> = keyof { [K in keyof T as string extends K ? never : K]: T[K] };
|
|
11
|
+
type StripIndex<T extends ZodShape> = Pick<T, KnownKeys<T>>;
|
|
12
|
+
type InferShape<TServer extends ZodShape, TClient extends ZodShape> = {
|
|
13
|
+
server: z.infer<z.ZodObject<StripIndex<TServer> & StripIndex<TClient>>>;
|
|
14
|
+
client: z.infer<z.ZodObject<StripIndex<TClient>>>;
|
|
15
|
+
all: z.infer<z.ZodObject<StripIndex<TServer> & StripIndex<TClient>>>;
|
|
16
|
+
};
|
|
17
|
+
declare function loadEnv<TServer extends ZodShape = Record<never, never>, TClient extends ZodShape = Record<never, never>>(config: {
|
|
18
|
+
server?: TServer;
|
|
19
|
+
client?: TClient;
|
|
20
|
+
presets?: EnvPreset[];
|
|
21
|
+
}, options?: LoadEnvOptions): Promise<InferShape<TServer, TClient>>;
|
|
22
|
+
declare function loadEnv(config: StandardEnvDefinition, options?: LoadEnvOptions): Promise<{
|
|
23
|
+
server: Record<string, unknown>;
|
|
24
|
+
client: Record<string, unknown>;
|
|
25
|
+
all: Record<string, unknown>;
|
|
26
|
+
}>;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { LoadEnvOptions, loadEnv };
|
|
29
|
+
//# sourceMappingURL=load.d.mts.map
|
package/dist/load.mjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { validateEnv } from "./schema.mjs";
|
|
2
|
+
import { isStandardEnvDefinition, validateStandardEnv } from "./standard.mjs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { loadEnv as loadEnv$1 } from "vite";
|
|
6
|
+
//#region src/load.ts
|
|
7
|
+
async function loadEnv(config, options = {}) {
|
|
8
|
+
const rawEnv = {
|
|
9
|
+
...loadEnv$1(options.mode ?? process.env["NODE_ENV"] ?? "development", options.envDir ? path.resolve(options.envDir) : process.cwd(), ""),
|
|
10
|
+
...filterStrings(process.env)
|
|
11
|
+
};
|
|
12
|
+
if (isStandardEnvDefinition(config)) {
|
|
13
|
+
const result = await validateStandardEnv(config, rawEnv);
|
|
14
|
+
if (!result.success) throwValidationError(result.errors.map((e) => e.message));
|
|
15
|
+
const server = Object.freeze(result.data);
|
|
16
|
+
const clientKeys = new Set(Object.keys(config.client ?? {}));
|
|
17
|
+
return {
|
|
18
|
+
server,
|
|
19
|
+
client: Object.freeze(filterByKeys(server, clientKeys)),
|
|
20
|
+
all: server
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const result = validateEnv(config, rawEnv);
|
|
24
|
+
if (!result.success) throwValidationError(result.errors.map((e) => e.message));
|
|
25
|
+
const server = Object.freeze(result.data);
|
|
26
|
+
const clientKeys = new Set(Object.keys(config.client ?? {}));
|
|
27
|
+
return {
|
|
28
|
+
server,
|
|
29
|
+
client: Object.freeze(filterByKeys(server, clientKeys)),
|
|
30
|
+
all: server
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function filterByKeys(data, keys) {
|
|
34
|
+
return Object.fromEntries(Object.entries(data).filter(([k]) => keys.has(k)));
|
|
35
|
+
}
|
|
36
|
+
function filterStrings(env) {
|
|
37
|
+
return Object.fromEntries(Object.entries(env).filter((e) => typeof e[1] === "string"));
|
|
38
|
+
}
|
|
39
|
+
function throwValidationError(messages) {
|
|
40
|
+
const lines = messages.map((m) => " - " + m).join("\n");
|
|
41
|
+
throw new Error("[vite-env] Validation failed:\n" + lines);
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { loadEnv };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=load.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.mjs","names":["viteLoadEnv"],"sources":["../src/load.ts"],"sourcesContent":["import type { EnvPreset, StandardEnvDefinition } from \"./types\";\nimport type { z } from \"zod\";\nimport process from \"node:process\";\nimport path from \"node:path\";\nimport { loadEnv as viteLoadEnv } from \"vite\";\nimport { isStandardEnvDefinition, validateStandardEnv } from \"./standard\";\nimport { validateEnv } from \"./schema\";\n\nexport type LoadEnvOptions = {\n mode?: string;\n envDir?: string;\n};\n\ntype ZodShape = z.ZodRawShape;\n\ntype KnownKeys<T> = keyof { [K in keyof T as string extends K ? never : K]: T[K] };\ntype StripIndex<T extends ZodShape> = Pick<T, KnownKeys<T>>;\n\ntype InferShape<TServer extends ZodShape, TClient extends ZodShape> = {\n server: z.infer<z.ZodObject<StripIndex<TServer> & StripIndex<TClient>>>;\n client: z.infer<z.ZodObject<StripIndex<TClient>>>;\n all: z.infer<z.ZodObject<StripIndex<TServer> & StripIndex<TClient>>>;\n};\n\nexport async function loadEnv<\n TServer extends ZodShape = Record<never, never>,\n TClient extends ZodShape = Record<never, never>,\n>(\n config: { server?: TServer; client?: TClient; presets?: EnvPreset[] },\n options?: LoadEnvOptions,\n): Promise<InferShape<TServer, TClient>>;\n\nexport async function loadEnv(\n config: StandardEnvDefinition,\n options?: LoadEnvOptions,\n): Promise<{\n server: Record<string, unknown>;\n client: Record<string, unknown>;\n all: Record<string, unknown>;\n}>;\n\nexport async function loadEnv(\n config: { server?: ZodShape; client?: ZodShape; presets?: EnvPreset[] } | StandardEnvDefinition,\n options: LoadEnvOptions = {},\n): Promise<{\n server: Record<string, unknown>;\n client: Record<string, unknown>;\n all: Record<string, unknown>;\n}> {\n const mode = options.mode ?? process.env[\"NODE_ENV\"] ?? \"development\";\n const envDir = options.envDir ? path.resolve(options.envDir) : process.cwd();\n\n const fileEnv = viteLoadEnv(mode, envDir, \"\");\n const rawEnv: Record<string, string> = {\n ...fileEnv,\n ...filterStrings(process.env),\n };\n\n if (isStandardEnvDefinition(config)) {\n const result = await validateStandardEnv(config, rawEnv);\n if (!result.success) throwValidationError(result.errors.map((e) => e.message));\n\n const server = Object.freeze(result.data);\n const clientKeys = new Set(Object.keys(config.client ?? {}));\n const client = Object.freeze(filterByKeys(server, clientKeys));\n\n return { server, client, all: server };\n }\n\n const result = validateEnv(config, rawEnv);\n if (!result.success) throwValidationError(result.errors.map((e) => e.message));\n\n const server = Object.freeze(result.data);\n const clientKeys = new Set(Object.keys(config.client ?? {}));\n const client = Object.freeze(filterByKeys(server, clientKeys));\n\n return { server, client, all: server };\n}\n\nfunction filterByKeys(data: Record<string, unknown>, keys: Set<string>): Record<string, unknown> {\n return Object.fromEntries(Object.entries(data).filter(([k]) => keys.has(k)));\n}\n\nfunction filterStrings(env: NodeJS.ProcessEnv): Record<string, string> {\n return Object.fromEntries(\n Object.entries(env).filter((e): e is [string, string] => typeof e[1] === \"string\"),\n );\n}\n\nfunction throwValidationError(messages: string[]): never {\n const lines = messages.map((m) => \" - \" + m).join(\"\\n\");\n throw new Error(\"[vite-env] Validation failed:\\n\" + lines);\n}\n"],"mappings":";;;;;;AAyCA,eAAsB,QACpB,QACA,UAA0B,EAAE,EAK3B;CAKD,MAAM,SAAiC;EACrC,GAFcA,UAHH,QAAQ,QAAQ,QAAQ,IAAI,eAAe,eACzC,QAAQ,SAAS,KAAK,QAAQ,QAAQ,OAAO,GAAG,QAAQ,KAAK,EAElC,GAE9B;EACV,GAAG,cAAc,QAAQ,IAAI;EAC9B;AAED,KAAI,wBAAwB,OAAO,EAAE;EACnC,MAAM,SAAS,MAAM,oBAAoB,QAAQ,OAAO;AACxD,MAAI,CAAC,OAAO,QAAS,sBAAqB,OAAO,OAAO,KAAK,MAAM,EAAE,QAAQ,CAAC;EAE9E,MAAM,SAAS,OAAO,OAAO,OAAO,KAAK;EACzC,MAAM,aAAa,IAAI,IAAI,OAAO,KAAK,OAAO,UAAU,EAAE,CAAC,CAAC;AAG5D,SAAO;GAAE;GAAQ,QAFF,OAAO,OAAO,aAAa,QAAQ,WAAW,CAEtC;GAAE,KAAK;GAAQ;;CAGxC,MAAM,SAAS,YAAY,QAAQ,OAAO;AAC1C,KAAI,CAAC,OAAO,QAAS,sBAAqB,OAAO,OAAO,KAAK,MAAM,EAAE,QAAQ,CAAC;CAE9E,MAAM,SAAS,OAAO,OAAO,OAAO,KAAK;CACzC,MAAM,aAAa,IAAI,IAAI,OAAO,KAAK,OAAO,UAAU,EAAE,CAAC,CAAC;AAG5D,QAAO;EAAE;EAAQ,QAFF,OAAO,OAAO,aAAa,QAAQ,WAAW,CAEtC;EAAE,KAAK;EAAQ;;AAGxC,SAAS,aAAa,MAA+B,MAA4C;AAC/F,QAAO,OAAO,YAAY,OAAO,QAAQ,KAAK,CAAC,QAAQ,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC,CAAC;;AAG9E,SAAS,cAAc,KAAgD;AACrE,QAAO,OAAO,YACZ,OAAO,QAAQ,IAAI,CAAC,QAAQ,MAA6B,OAAO,EAAE,OAAO,SAAS,CACnF;;AAGH,SAAS,qBAAqB,UAA2B;CACvD,MAAM,QAAQ,SAAS,KAAK,MAAM,SAAS,EAAE,CAAC,KAAK,KAAK;AACxD,OAAM,IAAI,MAAM,oCAAoC,MAAM"}
|
package/dist/plugin.cjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_chunk = require("./chunk-CKQMccvm.cjs");
|
|
2
2
|
const require_standard = require("./standard.cjs");
|
|
3
3
|
const require_config = require("./config.cjs");
|
|
4
|
+
const require_dts = require("./dts.cjs");
|
|
4
5
|
const require_format = require("./format.cjs");
|
|
5
6
|
const require_leak = require("./leak.cjs");
|
|
6
7
|
let node_path = require("node:path");
|
|
7
|
-
node_path =
|
|
8
|
+
node_path = require_chunk.__toESM(node_path, 1);
|
|
8
9
|
let node_process = require("node:process");
|
|
9
|
-
node_process =
|
|
10
|
+
node_process = require_chunk.__toESM(node_process, 1);
|
|
10
11
|
let node_fs_promises = require("node:fs/promises");
|
|
11
|
-
node_fs_promises =
|
|
12
|
+
node_fs_promises = require_chunk.__toESM(node_fs_promises, 1);
|
|
12
13
|
let vite = require("vite");
|
|
13
14
|
//#region src/guard.ts
|
|
14
15
|
/**
|
package/dist/plugin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs","names":["formatGuardLogEntry","path","fs","process","isStandardEnvDefinition","validateStandardEnv","formatStandardSchemaError","path","loadEnvConfig","generateStandardDts","formatHardError","formatGuardWarning","detectServerLeak"],"sources":["../src/guard.ts","../src/log.ts","../src/sources.ts","../src/virtual.ts","../src/plugin.ts"],"sourcesContent":["export type GuardMode = 'error' | 'stub' | 'warn'\n\nexport type GuardResult\n = | { allowed: true }\n | { allowed: false, mode: GuardMode, envName: string, importer: string | undefined }\n\nexport type GuardFail = Extract<GuardResult, { allowed: false }>\n\n/**\n * Determines whether the given Vite environment is allowed to import virtual:env/server.\n * Returns a GuardResult discriminated union — allowed or fail with context.\n * When this.environment is undefined (should not occur with Vite ≥ 8), callers default\n * envName to 'client' — failing closed (restrictive) is safer than failing open.\n */\nexport function checkServerModuleAccess(\n envName: string,\n serverEnvironments: string[],\n mode: GuardMode,\n importer: string | undefined,\n): GuardResult {\n if (serverEnvironments.includes(envName))\n return { allowed: true }\n return { allowed: false, mode, envName, importer }\n}\n\n/**\n * Generates the stub virtual module returned when onClientAccessOfServerModule is 'stub'.\n * The stub throws at runtime if executed — its message reflects that this import was\n * expected to be unreachable and the assumption was wrong.\n */\nexport function buildServerStubModule(envName: string): { code: string, moduleType: 'js' } {\n return {\n moduleType: 'js',\n code: `// Auto-generated by @vite-env/core — server-only module stub\nthrow new Error(\n '[vite-env] virtual:env/server was imported in the \"${envName}\" environment. ' +\n 'This module is server-only and was replaced with a stub. ' +\n 'To allow this environment: add it to serverEnvironments. ' +\n 'To suppress this stub: ensure this import never executes in the \"${envName}\" environment.'\n);`,\n }\n}\n","// @env node\nimport type { GuardFail } from './guard'\nimport fs from 'node:fs/promises'\nimport path from 'node:path'\nimport { formatGuardLogEntry } from './format'\n\nconst LOG_HEADER = `# vite-env warnings — generated by @vite-env/core\n# These warnings will become hard errors in 1.0.0.\n# To enforce immediately: ViteEnv({ onClientAccessOfServerModule: 'error' })\n# To acknowledge and suppress: ViteEnv({ onClientAccessOfServerModule: 'stub' })\n# To allow specific environments: ViteEnv({ serverEnvironments: ['ssr', 'workerd'] })`\n\n/**\n * Writes accumulated GuardFail entries to vite-env-warnings.log in the project root.\n * Overwrites on each build — stale entries from previous builds must not persist.\n * Called only in 'warn' mode from buildEnd, after verifying the build succeeded.\n */\nexport async function writeWarningsLog(fails: GuardFail[], root: string): Promise<void> {\n const seen = new Set<string>()\n const unique = fails.filter((fail) => {\n const key = `${fail.envName}::${fail.importer ?? ''}`\n if (seen.has(key))\n return false\n seen.add(key)\n return true\n })\n const timestamp = new Date().toISOString()\n const entries = unique.map(fail => formatGuardLogEntry(fail, timestamp)).join('\\n\\n')\n const content = `${LOG_HEADER}\\n\\n${entries}\\n`\n const filePath = path.join(root, 'vite-env-warnings.log')\n try {\n await fs.writeFile(filePath, content, 'utf-8')\n }\n catch (e) {\n throw new Error(\n `[vite-env] Failed to write vite-env-warnings.log to ${root}. Check file permissions.`,\n { cause: e },\n )\n }\n}\n","// @env node\nimport type { ResolvedConfig } from 'vite'\nimport process from 'node:process'\nimport { loadEnv } from 'vite'\n\n/**\n * Merge priority (highest → lowest):\n * 1. process.env (CI pipeline secrets win)\n * 2. .env.[mode].local\n * 3. .env.[mode]\n * 4. .env.local\n * 5. .env\n *\n * Prefix '' = load everything, schema decides what's valid.\n */\nexport async function loadEnvSources(\n config: ResolvedConfig,\n): Promise<Record<string, string>> {\n const fileEnv = loadEnv(\n config.mode,\n config.envDir || config.root,\n '', // no prefix filter — schema is the filter\n )\n\n return {\n ...fileEnv,\n ...filterStrings(process.env),\n }\n}\n\nfunction filterStrings(env: NodeJS.ProcessEnv): Record<string, string> {\n return Object.fromEntries(\n Object.entries(env).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string',\n ),\n )\n}\n","import type { AnyEnvDefinition } from './types'\n\nexport function buildClientModule(\n def: AnyEnvDefinition,\n data: Record<string, unknown>,\n): { code: string, moduleType: 'js' } {\n const clientKeys = new Set(Object.keys(def.client ?? {}))\n\n const clientData = Object.fromEntries(\n Object.entries(data).filter(([k]) => clientKeys.has(k)),\n )\n\n return {\n moduleType: 'js', // Required: Vite 8 / Rolldown explicit moduleType\n code: `// Auto-generated by @vite-env/core — do not edit\nexport const env = Object.freeze(${JSON.stringify(clientData, null, 2)});\nexport default env;`,\n }\n}\n\nexport function buildServerModule(\n _def: AnyEnvDefinition,\n data: Record<string, unknown>,\n): { code: string, moduleType: 'js' } {\n return {\n moduleType: 'js',\n code: `// Auto-generated by @vite-env/core — do not edit\nexport const env = Object.freeze(${JSON.stringify(data, null, 2)});\nexport default env;`,\n }\n}\n","// @env node\nimport type { Plugin, ResolvedConfig, Rollup } from 'vite'\nimport type { GuardFail } from './guard'\nimport type { AnyEnvDefinition } from './types'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { loadEnvConfig } from './config'\nimport { generateStandardDts } from './dts'\nimport { formatGuardWarning, formatHardError, formatStandardSchemaError } from './format'\nimport { buildServerStubModule, checkServerModuleAccess } from './guard'\nimport { detectServerLeak } from './leak'\nimport { writeWarningsLog } from './log'\nimport { loadEnvSources } from './sources'\nimport { isStandardEnvDefinition, validateStandardEnv } from './standard'\nimport { buildClientModule, buildServerModule } from './virtual'\n\nexport type ViteEnvOptions = {\n /**\n * Path to env definition file.\n * @default './env.ts' (resolved from project root)\n */\n configFile?: string\n\n /**\n * Vite 8 environment names that are allowed to import virtual:env/server.\n * Use this to allow edge runtimes (Cloudflare Workers → 'workerd', Deno Deploy → 'ssr').\n * @default ['ssr']\n */\n serverEnvironments?: string[]\n\n /**\n * Behavior when virtual:env/server is imported from a disallowed environment.\n *\n * - 'warn' — Deprecation warning printed to terminal + vite-env-warnings.log written.\n * Build succeeds but exits with code 1. Default in 0.x releases.\n * The default will change to 'error' in 1.0.0.\n *\n * - 'error' — Hard build error. No artifacts emitted.\n *\n * - 'stub' — Returns a module that throws at runtime if the import executes.\n * Use for testing environments (Vitest jsdom) or framework isomorphic files\n * where the import exists but the code path is never reached in a server context.\n *\n * @default 'warn'\n */\n onClientAccessOfServerModule?: 'error' | 'stub' | 'warn'\n}\n\n/**\n * Validates environment variables against the definition.\n * Routes to Zod or Standard Schema path based on definition type.\n * Zod modules are loaded dynamically to avoid requiring zod for Standard Schema users.\n */\nasync function validateAndFormat(\n def: AnyEnvDefinition,\n rawEnv: Record<string, string>,\n): Promise<{ data: Record<string, unknown> } | { error: string }> {\n if (isStandardEnvDefinition(def)) {\n const result = await validateStandardEnv(def, rawEnv)\n if (!result.success) {\n return { error: formatStandardSchemaError(result.errors) }\n }\n return { data: result.data }\n }\n\n const { validateEnv } = await import('./schema')\n const { formatZodError } = await import('./format')\n const result = validateEnv(def, rawEnv)\n if (!result.success) {\n return { error: formatZodError(result.errors) }\n }\n return { data: result.data }\n}\n\nexport default function ViteEnv(options: ViteEnvOptions = {}): Plugin {\n let resolvedConfig: ResolvedConfig\n let envDefinition: AnyEnvDefinition\n let lastValidated: Record<string, unknown> = {}\n let serverModuleGuardFails: GuardFail[] = []\n let didSetExitCode = false\n\n const serverEnvs = options.serverEnvironments ?? ['ssr']\n const guardMode = options.onClientAccessOfServerModule ?? 'warn'\n\n return {\n name: 'vite-env',\n enforce: 'pre',\n\n async configResolved(config) {\n resolvedConfig = config\n\n const configPath = path.resolve(\n config.root,\n options.configFile ?? 'env.ts',\n )\n\n try {\n envDefinition = await loadEnvConfig(configPath)\n }\n catch (e) {\n throw new Error(\n `[vite-env] Could not load env definition file at: ${configPath}\\n`\n + ` Create an env.ts file and export default defineEnv({ ... })`,\n { cause: e },\n )\n }\n },\n\n async buildStart() {\n serverModuleGuardFails = []\n if (didSetExitCode) {\n process.exitCode = 0\n didSetExitCode = false\n }\n\n const rawEnv = await loadEnvSources(resolvedConfig)\n const result = await validateAndFormat(envDefinition, rawEnv)\n\n if ('error' in result) {\n throw new Error(\n `[vite-env] Environment validation failed:\\n\\n${result.error}`,\n )\n }\n\n lastValidated = result.data\n\n if (isStandardEnvDefinition(envDefinition)) {\n await generateStandardDts(envDefinition, resolvedConfig.root)\n }\n else {\n const { generateDts } = await import('./dts')\n await generateDts(envDefinition, resolvedConfig.root)\n }\n\n const count = Object.keys(lastValidated).length\n resolvedConfig.logger.info(\n ` \\x1B[32m✓\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m ${count} variables validated`,\n )\n },\n\n resolveId(this: Rollup.PluginContext, source, importer) {\n if (source === 'virtual:env/client')\n return '\\0virtual:env/client'\n if (source === 'virtual:env/server') {\n const envName = this.environment?.name ?? 'client'\n const result = checkServerModuleAccess(envName, serverEnvs, guardMode, importer)\n if (!result.allowed)\n serverModuleGuardFails.push(result)\n return '\\0virtual:env/server'\n }\n },\n\n load(this: Rollup.PluginContext, id) {\n if (id === '\\0virtual:env/client')\n return buildClientModule(envDefinition, lastValidated)\n if (id === '\\0virtual:env/server') {\n const envName = this.environment?.name ?? 'client'\n // Filter to fails from this environment only — other envs may have recorded fails for their own loads\n const envFails = serverModuleGuardFails.filter(f => f.envName === envName)\n if (envFails.length > 0) {\n // warn once per load cycle using the last recorded fail; unique importers are written to the log file\n const latest = envFails.at(-1)!\n if (latest.mode === 'error')\n throw new Error(formatHardError(latest))\n if (latest.mode === 'stub')\n return buildServerStubModule(envName)\n resolvedConfig.logger.warn(`\\n${formatGuardWarning(latest)}`)\n }\n return buildServerModule(envDefinition, lastValidated)\n }\n },\n\n async buildEnd(error) {\n if (error)\n return\n if (serverModuleGuardFails.length === 0)\n return\n if (guardMode !== 'warn')\n return\n await writeWarningsLog(serverModuleGuardFails, resolvedConfig.root)\n process.exitCode = 1\n didSetExitCode = true\n },\n\n generateBundle(this: Rollup.PluginContext, _options, bundle) {\n if (resolvedConfig.build.ssr)\n return\n\n const envName = this.environment?.name ?? 'client'\n if (serverEnvs.includes(envName))\n return\n\n const leaks = detectServerLeak(\n envDefinition,\n lastValidated,\n bundle as Record<string, { type: string, code?: string }>,\n (keys) => {\n resolvedConfig.logger.warn(\n ` \\x1B[33m⚠\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m Leak detection skipped ${keys.length} server variable(s) with values shorter than 8 chars: ${keys.join(', ')}`,\n )\n },\n )\n\n if (leaks.length > 0) {\n const details = leaks.map(l => ` ✗ ${l.key} found in ${l.chunk}`).join('\\n')\n throw new Error(\n `[vite-env] Server environment variables detected in client bundle!\\n\\n${details}\\n\\n These variables are marked as server-only and must never reach the browser.`,\n )\n }\n },\n\n configureServer(server) {\n const envDir = resolvedConfig.envDir || resolvedConfig.root\n server.watcher.add(path.join(envDir, '.env*'))\n\n let debounceTimer: ReturnType<typeof setTimeout>\n\n server.watcher.on('change', async (file) => {\n if (!path.basename(file).startsWith('.env'))\n return\n\n clearTimeout(debounceTimer)\n debounceTimer = setTimeout(async () => {\n try {\n const rawEnv = await loadEnvSources(resolvedConfig)\n const result = await validateAndFormat(envDefinition, rawEnv)\n\n if ('error' in result) {\n resolvedConfig.logger.warn(\n `\\n \\x1B[33m⚠\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m Env revalidation failed:\\n${result.error}`,\n )\n return\n }\n\n lastValidated = result.data\n\n const clientMod = server.moduleGraph.getModuleById('\\0virtual:env/client')\n const serverMod = server.moduleGraph.getModuleById('\\0virtual:env/server')\n if (clientMod)\n server.moduleGraph.invalidateModule(clientMod)\n if (serverMod)\n server.moduleGraph.invalidateModule(serverMod)\n if (clientMod || serverMod) {\n serverModuleGuardFails = []\n server.hot.send({ type: 'full-reload' })\n resolvedConfig.logger.info(\n ` \\x1B[32m✓\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m Env revalidated`,\n )\n }\n }\n catch (e) {\n resolvedConfig.logger.error(\n `\\n \\x1B[31m✗\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m Failed to reload env files: ${e instanceof Error ? e.message : String(e)}`,\n )\n }\n }, 150)\n })\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAcA,SAAgB,wBACd,SACA,oBACA,MACA,UACa;AACb,KAAI,mBAAmB,SAAS,QAA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ACpF;AACD;;AAGF,sBAAgB,OAAO;MAEvB,MAAM,YAAY,OAAO,YAAY,cAAc,uBAAuB;MAC1E,MAAM,YAAY,OAAO,YAAY,cAAc,uBAAuB;AAC1E,UAAI,UACF,QAAO,YAAY,iBAAiB,UAAU;AAChD,UAAI,UACF,QAAO,YAAY,iBAAiB,UAAU;AAChD,UAAI,aAAa,WAAW;AAC1B,gCAAyB,EAAE;AAC3B,cAAO,IAAI,KAAK,EAAE,MAAM,eAAe,CAAC;AACxC,sBAAe,OAAO,KACpB,+DACD;;cAGE,GAAG;AACR,qBAAe,OAAO,MACpB,8EAA8E,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE,GACzH;;OAEF,IAAI;KACP;;EAEL"}
|
|
1
|
+
{"version":3,"file":"plugin.cjs","names":["formatGuardLogEntry","path","fs","process","isStandardEnvDefinition","validateStandardEnv","formatStandardSchemaError","path","loadEnvConfig","generateStandardDts","formatHardError","formatGuardWarning","detectServerLeak"],"sources":["../src/guard.ts","../src/log.ts","../src/sources.ts","../src/virtual.ts","../src/plugin.ts"],"sourcesContent":["export type GuardMode = \"error\" | \"stub\" | \"warn\";\n\nexport type GuardResult =\n | { allowed: true }\n | { allowed: false; mode: GuardMode; envName: string; importer: string | undefined };\n\nexport type GuardFail = Extract<GuardResult, { allowed: false }>;\n\n/**\n * Determines whether the given Vite environment is allowed to import virtual:env/server.\n * Returns a GuardResult discriminated union — allowed or fail with context.\n * When this.environment is undefined (should not occur with Vite ≥ 8), callers default\n * envName to 'client' — failing closed (restrictive) is safer than failing open.\n */\nexport function checkServerModuleAccess(\n envName: string,\n serverEnvironments: string[],\n mode: GuardMode,\n importer: string | undefined,\n): GuardResult {\n if (serverEnvironments.includes(envName)) return { allowed: true };\n return { allowed: false, mode, envName, importer };\n}\n\n/**\n * Generates the stub virtual module returned when onClientAccessOfServerModule is 'stub'.\n * The stub throws at runtime if executed — its message reflects that this import was\n * expected to be unreachable and the assumption was wrong.\n */\nexport function buildServerStubModule(envName: string): { code: string; moduleType: \"js\" } {\n return {\n moduleType: \"js\",\n code: `// Auto-generated by @vite-env/core — server-only module stub\nthrow new Error(\n '[vite-env] virtual:env/server was imported in the \"${envName}\" environment. ' +\n 'This module is server-only and was replaced with a stub. ' +\n 'To allow this environment: add it to serverEnvironments. ' +\n 'To suppress this stub: ensure this import never executes in the \"${envName}\" environment.'\n);`,\n };\n}\n","// @env node\nimport type { GuardFail } from \"./guard\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { formatGuardLogEntry } from \"./format\";\n\nconst LOG_HEADER = `# vite-env warnings — generated by @vite-env/core\n# These warnings will become hard errors in 1.0.0.\n# To enforce immediately: ViteEnv({ onClientAccessOfServerModule: 'error' })\n# To acknowledge and suppress: ViteEnv({ onClientAccessOfServerModule: 'stub' })\n# To allow specific environments: ViteEnv({ serverEnvironments: ['ssr', 'workerd'] })`;\n\n/**\n * Writes accumulated GuardFail entries to vite-env-warnings.log in the project root.\n * Overwrites on each build — stale entries from previous builds must not persist.\n * Called only in 'warn' mode from buildEnd, after verifying the build succeeded.\n */\nexport async function writeWarningsLog(fails: GuardFail[], root: string): Promise<void> {\n const seen = new Set<string>();\n const unique = fails.filter((fail) => {\n const key = `${fail.envName}::${fail.importer ?? \"\"}`;\n if (seen.has(key)) return false;\n seen.add(key);\n return true;\n });\n const timestamp = new Date().toISOString();\n const entries = unique.map((fail) => formatGuardLogEntry(fail, timestamp)).join(\"\\n\\n\");\n const content = `${LOG_HEADER}\\n\\n${entries}\\n`;\n const filePath = path.join(root, \"vite-env-warnings.log\");\n try {\n await fs.writeFile(filePath, content, \"utf-8\");\n } catch (e) {\n throw new Error(\n `[vite-env] Failed to write vite-env-warnings.log to ${root}. Check file permissions.`,\n { cause: e },\n );\n }\n}\n","// @env node\nimport type { ResolvedConfig } from \"vite\";\nimport process from \"node:process\";\nimport { loadEnv } from \"vite\";\n\n/**\n * Merge priority (highest → lowest):\n * 1. process.env (CI pipeline secrets win)\n * 2. .env.[mode].local\n * 3. .env.[mode]\n * 4. .env.local\n * 5. .env\n *\n * Prefix '' = load everything, schema decides what's valid.\n */\nexport async function loadEnvSources(config: ResolvedConfig): Promise<Record<string, string>> {\n const fileEnv = loadEnv(\n config.mode,\n config.envDir || config.root,\n \"\", // no prefix filter — schema is the filter\n );\n\n return {\n ...fileEnv,\n ...filterStrings(process.env),\n };\n}\n\nfunction filterStrings(env: NodeJS.ProcessEnv): Record<string, string> {\n return Object.fromEntries(\n Object.entries(env).filter((entry): entry is [string, string] => typeof entry[1] === \"string\"),\n );\n}\n","import type { AnyEnvDefinition } from \"./types\";\n\nexport function buildClientModule(\n def: AnyEnvDefinition,\n data: Record<string, unknown>,\n): { code: string; moduleType: \"js\" } {\n const clientKeys = new Set(Object.keys(def.client ?? {}));\n\n const clientData = Object.fromEntries(Object.entries(data).filter(([k]) => clientKeys.has(k)));\n\n return {\n moduleType: \"js\", // Required: Vite 8 / Rolldown explicit moduleType\n code: `// Auto-generated by @vite-env/core — do not edit\nexport const env = Object.freeze(${JSON.stringify(clientData, null, 2)});\nexport default env;`,\n };\n}\n\nexport function buildServerModule(\n _def: AnyEnvDefinition,\n data: Record<string, unknown>,\n): { code: string; moduleType: \"js\" } {\n return {\n moduleType: \"js\",\n code: `// Auto-generated by @vite-env/core — do not edit\nexport const env = Object.freeze(${JSON.stringify(data, null, 2)});\nexport default env;`,\n };\n}\n","// @env node\nimport type { Plugin, ResolvedConfig, Rollup } from \"vite\";\nimport type { GuardFail } from \"./guard\";\nimport type { AnyEnvDefinition } from \"./types\";\nimport path from \"node:path\";\nimport process from \"node:process\";\nimport { loadEnvConfig } from \"./config\";\nimport { generateStandardDts } from \"./dts\";\nimport { formatGuardWarning, formatHardError, formatStandardSchemaError } from \"./format\";\nimport { buildServerStubModule, checkServerModuleAccess } from \"./guard\";\nimport { detectServerLeak } from \"./leak\";\nimport { writeWarningsLog } from \"./log\";\nimport { loadEnvSources } from \"./sources\";\nimport { isStandardEnvDefinition, validateStandardEnv } from \"./standard\";\nimport { buildClientModule, buildServerModule } from \"./virtual\";\n\nexport type ViteEnvOptions = {\n /**\n * Path to env definition file.\n * @default './env.ts' (resolved from project root)\n */\n configFile?: string;\n\n /**\n * Vite 8 environment names that are allowed to import virtual:env/server.\n * Use this to allow edge runtimes (Cloudflare Workers → 'workerd', Deno Deploy → 'ssr').\n * @default ['ssr']\n */\n serverEnvironments?: string[];\n\n /**\n * Behavior when virtual:env/server is imported from a disallowed environment.\n *\n * - 'warn' — Deprecation warning printed to terminal + vite-env-warnings.log written.\n * Build succeeds but exits with code 1. Default in 0.x releases.\n * The default will change to 'error' in 1.0.0.\n *\n * - 'error' — Hard build error. No artifacts emitted.\n *\n * - 'stub' — Returns a module that throws at runtime if the import executes.\n * Use for testing environments (Vitest jsdom) or framework isomorphic files\n * where the import exists but the code path is never reached in a server context.\n *\n * @default 'warn'\n */\n onClientAccessOfServerModule?: \"error\" | \"stub\" | \"warn\";\n};\n\n/**\n * Validates environment variables against the definition.\n * Routes to Zod or Standard Schema path based on definition type.\n * Zod modules are loaded dynamically to avoid requiring zod for Standard Schema users.\n */\nasync function validateAndFormat(\n def: AnyEnvDefinition,\n rawEnv: Record<string, string>,\n): Promise<{ data: Record<string, unknown> } | { error: string }> {\n if (isStandardEnvDefinition(def)) {\n const result = await validateStandardEnv(def, rawEnv);\n if (!result.success) {\n return { error: formatStandardSchemaError(result.errors) };\n }\n return { data: result.data };\n }\n\n const { validateEnv } = await import(\"./schema\");\n const { formatZodError } = await import(\"./format\");\n const result = validateEnv(def, rawEnv);\n if (!result.success) {\n return { error: formatZodError(result.errors) };\n }\n return { data: result.data };\n}\n\nexport default function ViteEnv(options: ViteEnvOptions = {}): Plugin {\n let resolvedConfig: ResolvedConfig;\n let envDefinition: AnyEnvDefinition;\n let lastValidated: Record<string, unknown> = {};\n let serverModuleGuardFails: GuardFail[] = [];\n let didSetExitCode = false;\n\n const serverEnvs = options.serverEnvironments ?? [\"ssr\"];\n const guardMode = options.onClientAccessOfServerModule ?? \"warn\";\n\n return {\n name: \"vite-env\",\n enforce: \"pre\",\n\n async configResolved(config) {\n resolvedConfig = config;\n\n const configPath = path.resolve(config.root, options.configFile ?? \"env.ts\");\n\n try {\n envDefinition = await loadEnvConfig(configPath);\n } catch (e) {\n throw new Error(\n `[vite-env] Could not load env definition file at: ${configPath}\\n` +\n ` Create an env.ts file and export default defineEnv({ ... })`,\n { cause: e },\n );\n }\n },\n\n async buildStart() {\n serverModuleGuardFails = [];\n if (didSetExitCode) {\n process.exitCode = 0;\n didSetExitCode = false;\n }\n\n const rawEnv = await loadEnvSources(resolvedConfig);\n const result = await validateAndFormat(envDefinition, rawEnv);\n\n if (\"error\" in result) {\n throw new Error(`[vite-env] Environment validation failed:\\n\\n${result.error}`);\n }\n\n lastValidated = result.data;\n\n if (isStandardEnvDefinition(envDefinition)) {\n await generateStandardDts(envDefinition, resolvedConfig.root);\n } else {\n const { generateDts } = await import(\"./dts\");\n await generateDts(envDefinition, resolvedConfig.root);\n }\n\n const count = Object.keys(lastValidated).length;\n resolvedConfig.logger.info(\n ` \\x1B[32m✓\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m ${count} variables validated`,\n );\n },\n\n resolveId(this: Rollup.PluginContext, source, importer) {\n if (source === \"virtual:env/client\") return \"\\0virtual:env/client\";\n if (source === \"virtual:env/server\") {\n const envName = this.environment?.name ?? \"client\";\n const result = checkServerModuleAccess(envName, serverEnvs, guardMode, importer);\n if (!result.allowed) serverModuleGuardFails.push(result);\n return \"\\0virtual:env/server\";\n }\n },\n\n load(this: Rollup.PluginContext, id) {\n if (id === \"\\0virtual:env/client\") return buildClientModule(envDefinition, lastValidated);\n if (id === \"\\0virtual:env/server\") {\n const envName = this.environment?.name ?? \"client\";\n // Filter to fails from this environment only — other envs may have recorded fails for their own loads\n const envFails = serverModuleGuardFails.filter((f) => f.envName === envName);\n if (envFails.length > 0) {\n // warn once per load cycle using the last recorded fail; unique importers are written to the log file\n const latest = envFails.at(-1)!;\n if (latest.mode === \"error\") throw new Error(formatHardError(latest));\n if (latest.mode === \"stub\") return buildServerStubModule(envName);\n resolvedConfig.logger.warn(`\\n${formatGuardWarning(latest)}`);\n }\n return buildServerModule(envDefinition, lastValidated);\n }\n },\n\n async buildEnd(error) {\n if (error) return;\n if (serverModuleGuardFails.length === 0) return;\n if (guardMode !== \"warn\") return;\n await writeWarningsLog(serverModuleGuardFails, resolvedConfig.root);\n process.exitCode = 1;\n didSetExitCode = true;\n },\n\n generateBundle(this: Rollup.PluginContext, _options, bundle) {\n if (resolvedConfig.build.ssr) return;\n\n const envName = this.environment?.name ?? \"client\";\n if (serverEnvs.includes(envName)) return;\n\n const leaks = detectServerLeak(\n envDefinition,\n lastValidated,\n bundle as Record<string, { type: string; code?: string }>,\n (keys) => {\n resolvedConfig.logger.warn(\n ` \\x1B[33m⚠\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m Leak detection skipped ${keys.length} server variable(s) with values shorter than 8 chars: ${keys.join(\", \")}`,\n );\n },\n );\n\n if (leaks.length > 0) {\n const details = leaks.map((l) => ` ✗ ${l.key} found in ${l.chunk}`).join(\"\\n\");\n throw new Error(\n `[vite-env] Server environment variables detected in client bundle!\\n\\n${details}\\n\\n These variables are marked as server-only and must never reach the browser.`,\n );\n }\n },\n\n configureServer(server) {\n const envDir = resolvedConfig.envDir || resolvedConfig.root;\n server.watcher.add(path.join(envDir, \".env*\"));\n\n let debounceTimer: ReturnType<typeof setTimeout>;\n\n server.watcher.on(\"change\", async (file) => {\n if (!path.basename(file).startsWith(\".env\")) return;\n\n clearTimeout(debounceTimer);\n debounceTimer = setTimeout(async () => {\n try {\n const rawEnv = await loadEnvSources(resolvedConfig);\n const result = await validateAndFormat(envDefinition, rawEnv);\n\n if (\"error\" in result) {\n resolvedConfig.logger.warn(\n `\\n \\x1B[33m⚠\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m Env revalidation failed:\\n${result.error}`,\n );\n return;\n }\n\n lastValidated = result.data;\n\n const clientMod = server.moduleGraph.getModuleById(\"\\0virtual:env/client\");\n const serverMod = server.moduleGraph.getModuleById(\"\\0virtual:env/server\");\n if (clientMod) server.moduleGraph.invalidateModule(clientMod);\n if (serverMod) server.moduleGraph.invalidateModule(serverMod);\n if (clientMod || serverMod) {\n serverModuleGuardFails = [];\n server.hot.send({ type: \"full-reload\" });\n resolvedConfig.logger.info(\n ` \\x1B[32m✓\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m Env revalidated`,\n );\n }\n } catch (e) {\n resolvedConfig.logger.error(\n `\\n \\x1B[31m✗\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m Failed to reload env files: ${e instanceof Error ? e.message : String(e)}`,\n );\n }\n }, 150);\n });\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAcA,SAAgB,wBACd,SACA,oBACA,MACA,UACa;AACb,KAAI,mBAAmB,SAAS,QAAQ,CAAE,QAAO,EAAE,SAAS,MAAM;AAClE,QAAO;EAAE,SAAS;EAAO;EAAM;EAAS;EAAU;;;;;;;AAQpD,SAAgB,sBAAsB,SAAqD;AACzF,QAAO;EACL,YAAY;EACZ,MAAM;;wDAE8C,QAAQ;;;sEAGM,QAAQ;;EAE3E;;;;ACjCH,MAAM,aAAa;;;;;;;;;;AAWnB,eAAsB,iBAAiB,OAAoB,MAA6B;CACtF,MAAM,uBAAO,IAAI,KAAa;CAC9B,MAAM,SAAS,MAAM,QAAQ,SAAS;EACpC,MAAM,MAAM,GAAG,KAAK,QAAQ,IAAI,KAAK,YAAY;AACjD,MAAI,KAAK,IAAI,IAAI,CAAE,QAAO;AAC1B,OAAK,IAAI,IAAI;AACb,SAAO;GACP;CACF,MAAM,6BAAY,IAAI,MAAM,EAAC,aAAa;CAE1C,MAAM,UAAU,GAAG,WAAW,MADd,OAAO,KAAK,SAASA,eAAAA,oBAAoB,MAAM,UAAU,CAAC,CAAC,KAAK,OACrC,CAAC;CAC5C,MAAM,WAAWC,UAAAA,QAAK,KAAK,MAAM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ub" | "warn";
|
|
32
32
|
};
|
|
33
33
|
declare function ViteEnv(options?: ViteEnvOptions): Plugin;
|
|
34
34
|
//#endregion
|
package/dist/plugin.d.mts
CHANGED
|
@@ -28,7 +28,7 @@ type ViteEnvOptions = {
|
|
|
28
28
|
*
|
|
29
29
|
* @default 'warn'
|
|
30
30
|
*/
|
|
31
|
-
onClientAccessOfServerModule?:
|
|
31
|
+
onClientAccessOfServerModule?: "error" | "stub" | "warn";
|
|
32
32
|
};
|
|
33
33
|
declare function ViteEnv(options?: ViteEnvOptions): Plugin;
|
|
34
34
|
//#endregion
|
package/dist/plugin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/guard.ts","../src/log.ts","../src/sources.ts","../src/virtual.ts","../src/plugin.ts"],"sourcesContent":["export type GuardMode = 'error' | 'stub' | 'warn'\n\nexport type GuardResult\n = | { allowed: true }\n | { allowed: false, mode: GuardMode, envName: string, importer: string | undefined }\n\nexport type GuardFail = Extract<GuardResult, { allowed: false }>\n\n/**\n * Determines whether the given Vite environment is allowed to import virtual:env/server.\n * Returns a GuardResult discriminated union — allowed or fail with context.\n * When this.environment is undefined (should not occur with Vite ≥ 8), callers default\n * envName to 'client' — failing closed (restrictive) is safer than failing open.\n */\nexport function checkServerModuleAccess(\n envName: string,\n serverEnvironments: string[],\n mode: GuardMode,\n importer: string | undefined,\n): GuardResult {\n if (serverEnvironments.includes(envName))\n return { allowed: true }\n return { allowed: false, mode, envName, importer }\n}\n\n/**\n * Generates the stub virtual module returned when onClientAccessOfServerModule is 'stub'.\n * The stub throws at runtime if executed — its message reflects that this import was\n * expected to be unreachable and the assumption was wrong.\n */\nexport function buildServerStubModule(envName: string): { code: string, moduleType: 'js' } {\n return {\n moduleType: 'js',\n code: `// Auto-generated by @vite-env/core — server-only module stub\nthrow new Error(\n '[vite-env] virtual:env/server was imported in the \"${envName}\" environment. ' +\n 'This module is server-only and was replaced with a stub. ' +\n 'To allow this environment: add it to serverEnvironments. ' +\n 'To suppress this stub: ensure this import never executes in the \"${envName}\" environment.'\n);`,\n }\n}\n","// @env node\nimport type { GuardFail } from './guard'\nimport fs from 'node:fs/promises'\nimport path from 'node:path'\nimport { formatGuardLogEntry } from './format'\n\nconst LOG_HEADER = `# vite-env warnings — generated by @vite-env/core\n# These warnings will become hard errors in 1.0.0.\n# To enforce immediately: ViteEnv({ onClientAccessOfServerModule: 'error' })\n# To acknowledge and suppress: ViteEnv({ onClientAccessOfServerModule: 'stub' })\n# To allow specific environments: ViteEnv({ serverEnvironments: ['ssr', 'workerd'] })`\n\n/**\n * Writes accumulated GuardFail entries to vite-env-warnings.log in the project root.\n * Overwrites on each build — stale entries from previous builds must not persist.\n * Called only in 'warn' mode from buildEnd, after verifying the build succeeded.\n */\nexport async function writeWarningsLog(fails: GuardFail[], root: string): Promise<void> {\n const seen = new Set<string>()\n const unique = fails.filter((fail) => {\n const key = `${fail.envName}::${fail.importer ?? ''}`\n if (seen.has(key))\n return false\n seen.add(key)\n return true\n })\n const timestamp = new Date().toISOString()\n const entries = unique.map(fail => formatGuardLogEntry(fail, timestamp)).join('\\n\\n')\n const content = `${LOG_HEADER}\\n\\n${entries}\\n`\n const filePath = path.join(root, 'vite-env-warnings.log')\n try {\n await fs.writeFile(filePath, content, 'utf-8')\n }\n catch (e) {\n throw new Error(\n `[vite-env] Failed to write vite-env-warnings.log to ${root}. Check file permissions.`,\n { cause: e },\n )\n }\n}\n","// @env node\nimport type { ResolvedConfig } from 'vite'\nimport process from 'node:process'\nimport { loadEnv } from 'vite'\n\n/**\n * Merge priority (highest → lowest):\n * 1. process.env (CI pipeline secrets win)\n * 2. .env.[mode].local\n * 3. .env.[mode]\n * 4. .env.local\n * 5. .env\n *\n * Prefix '' = load everything, schema decides what's valid.\n */\nexport async function loadEnvSources(\n config: ResolvedConfig,\n): Promise<Record<string, string>> {\n const fileEnv = loadEnv(\n config.mode,\n config.envDir || config.root,\n '', // no prefix filter — schema is the filter\n )\n\n return {\n ...fileEnv,\n ...filterStrings(process.env),\n }\n}\n\nfunction filterStrings(env: NodeJS.ProcessEnv): Record<string, string> {\n return Object.fromEntries(\n Object.entries(env).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string',\n ),\n )\n}\n","import type { AnyEnvDefinition } from './types'\n\nexport function buildClientModule(\n def: AnyEnvDefinition,\n data: Record<string, unknown>,\n): { code: string, moduleType: 'js' } {\n const clientKeys = new Set(Object.keys(def.client ?? {}))\n\n const clientData = Object.fromEntries(\n Object.entries(data).filter(([k]) => clientKeys.has(k)),\n )\n\n return {\n moduleType: 'js', // Required: Vite 8 / Rolldown explicit moduleType\n code: `// Auto-generated by @vite-env/core — do not edit\nexport const env = Object.freeze(${JSON.stringify(clientData, null, 2)});\nexport default env;`,\n }\n}\n\nexport function buildServerModule(\n _def: AnyEnvDefinition,\n data: Record<string, unknown>,\n): { code: string, moduleType: 'js' } {\n return {\n moduleType: 'js',\n code: `// Auto-generated by @vite-env/core — do not edit\nexport const env = Object.freeze(${JSON.stringify(data, null, 2)});\nexport default env;`,\n }\n}\n","// @env node\nimport type { Plugin, ResolvedConfig, Rollup } from 'vite'\nimport type { GuardFail } from './guard'\nimport type { AnyEnvDefinition } from './types'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { loadEnvConfig } from './config'\nimport { generateStandardDts } from './dts'\nimport { formatGuardWarning, formatHardError, formatStandardSchemaError } from './format'\nimport { buildServerStubModule, checkServerModuleAccess } from './guard'\nimport { detectServerLeak } from './leak'\nimport { writeWarningsLog } from './log'\nimport { loadEnvSources } from './sources'\nimport { isStandardEnvDefinition, validateStandardEnv } from './standard'\nimport { buildClientModule, buildServerModule } from './virtual'\n\nexport type ViteEnvOptions = {\n /**\n * Path to env definition file.\n * @default './env.ts' (resolved from project root)\n */\n configFile?: string\n\n /**\n * Vite 8 environment names that are allowed to import virtual:env/server.\n * Use this to allow edge runtimes (Cloudflare Workers → 'workerd', Deno Deploy → 'ssr').\n * @default ['ssr']\n */\n serverEnvironments?: string[]\n\n /**\n * Behavior when virtual:env/server is imported from a disallowed environment.\n *\n * - 'warn' — Deprecation warning printed to terminal + vite-env-warnings.log written.\n * Build succeeds but exits with code 1. Default in 0.x releases.\n * The default will change to 'error' in 1.0.0.\n *\n * - 'error' — Hard build error. No artifacts emitted.\n *\n * - 'stub' — Returns a module that throws at runtime if the import executes.\n * Use for testing environments (Vitest jsdom) or framework isomorphic files\n * where the import exists but the code path is never reached in a server context.\n *\n * @default 'warn'\n */\n onClientAccessOfServerModule?: 'error' | 'stub' | 'warn'\n}\n\n/**\n * Validates environment variables against the definition.\n * Routes to Zod or Standard Schema path based on definition type.\n * Zod modules are loaded dynamically to avoid requiring zod for Standard Schema users.\n */\nasync function validateAndFormat(\n def: AnyEnvDefinition,\n rawEnv: Record<string, string>,\n): Promise<{ data: Record<string, unknown> } | { error: string }> {\n if (isStandardEnvDefinition(def)) {\n const result = await validateStandardEnv(def, rawEnv)\n if (!result.success) {\n return { error: formatStandardSchemaError(result.errors) }\n }\n return { data: result.data }\n }\n\n const { validateEnv } = await import('./schema')\n const { formatZodError } = await import('./format')\n const result = validateEnv(def, rawEnv)\n if (!result.success) {\n return { error: formatZodError(result.errors) }\n }\n return { data: result.data }\n}\n\nexport default function ViteEnv(options: ViteEnvOptions = {}): Plugin {\n let resolvedConfig: ResolvedConfig\n let envDefinition: AnyEnvDefinition\n let lastValidated: Record<string, unknown> = {}\n let serverModuleGuardFails: GuardFail[] = []\n let didSetExitCode = false\n\n const serverEnvs = options.serverEnvironments ?? ['ssr']\n const guardMode = options.onClientAccessOfServerModule ?? 'warn'\n\n return {\n name: 'vite-env',\n enforce: 'pre',\n\n async configResolved(config) {\n resolvedConfig = config\n\n const configPath = path.resolve(\n config.root,\n options.configFile ?? 'env.ts',\n )\n\n try {\n envDefinition = await loadEnvConfig(configPath)\n }\n catch (e) {\n throw new Error(\n `[vite-env] Could not load env definition file at: ${configPath}\\n`\n + ` Create an env.ts file and export default defineEnv({ ... })`,\n { cause: e },\n )\n }\n },\n\n async buildStart() {\n serverModuleGuardFails = []\n if (didSetExitCode) {\n process.exitCode = 0\n didSetExitCode = false\n }\n\n const rawEnv = await loadEnvSources(resolvedConfig)\n const result = await validateAndFormat(envDefinition, rawEnv)\n\n if ('error' in result) {\n throw new Error(\n `[vite-env] Environment validation failed:\\n\\n${result.error}`,\n )\n }\n\n lastValidated = result.data\n\n if (isStandardEnvDefinition(envDefinition)) {\n await generateStandardDts(envDefinition, resolvedConfig.root)\n }\n else {\n const { generateDts } = await import('./dts')\n await generateDts(envDefinition, resolvedConfig.root)\n }\n\n const count = Object.keys(lastValidated).length\n resolvedConfig.logger.info(\n ` \\x1B[32m✓\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m ${count} variables validated`,\n )\n },\n\n resolveId(this: Rollup.PluginContext, source, importer) {\n if (source === 'virtual:env/client')\n return '\\0virtual:env/client'\n if (source === 'virtual:env/server') {\n const envName = this.environment?.name ?? 'client'\n const result = checkServerModuleAccess(envName, serverEnvs, guardMode, importer)\n if (!result.allowed)\n serverModuleGuardFails.push(result)\n return '\\0virtual:env/server'\n }\n },\n\n load(this: Rollup.PluginContext, id) {\n if (id === '\\0virtual:env/client')\n return buildClientModule(envDefinition, lastValidated)\n if (id === '\\0virtual:env/server') {\n const envName = this.environment?.name ?? 'client'\n // Filter to fails from this environment only — other envs may have recorded fails for their own loads\n const envFails = serverModuleGuardFails.filter(f => f.envName === envName)\n if (envFails.length > 0) {\n // warn once per load cycle using the last recorded fail; unique importers are written to the log file\n const latest = envFails.at(-1)!\n if (latest.mode === 'error')\n throw new Error(formatHardError(latest))\n if (latest.mode === 'stub')\n return buildServerStubModule(envName)\n resolvedConfig.logger.warn(`\\n${formatGuardWarning(latest)}`)\n }\n return buildServerModule(envDefinition, lastValidated)\n }\n },\n\n async buildEnd(error) {\n if (error)\n return\n if (serverModuleGuardFails.length === 0)\n return\n if (guardMode !== 'warn')\n return\n await writeWarningsLog(serverModuleGuardFails, resolvedConfig.root)\n process.exitCode = 1\n didSetExitCode = true\n },\n\n generateBundle(this: Rollup.PluginContext, _options, bundle) {\n if (resolvedConfig.build.ssr)\n return\n\n const envName = this.environment?.name ?? 'client'\n if (serverEnvs.includes(envName))\n return\n\n const leaks = detectServerLeak(\n envDefinition,\n lastValidated,\n bundle as Record<string, { type: string, code?: string }>,\n (keys) => {\n resolvedConfig.logger.warn(\n ` \\x1B[33m⚠\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m Leak detection skipped ${keys.length} server variable(s) with values shorter than 8 chars: ${keys.join(', ')}`,\n )\n },\n )\n\n if (leaks.length > 0) {\n const details = leaks.map(l => ` ✗ ${l.key} found in ${l.chunk}`).join('\\n')\n throw new Error(\n `[vite-env] Server environment variables detected in client bundle!\\n\\n${details}\\n\\n These variables are marked as server-only and must never reach the browser.`,\n )\n }\n },\n\n configureServer(server) {\n const envDir = resolvedConfig.envDir || resolvedConfig.root\n server.watcher.add(path.join(envDir, '.env*'))\n\n let debounceTimer: ReturnType<typeof setTimeout>\n\n server.watcher.on('change', async (file) => {\n if (!path.basename(file).startsWith('.env'))\n return\n\n clearTimeout(debounceTimer)\n debounceTimer = setTimeout(async () => {\n try {\n const rawEnv = await loadEnvSources(resolvedConfig)\n const result = await validateAndFormat(envDefinition, rawEnv)\n\n if ('error' in result) {\n resolvedConfig.logger.warn(\n `\\n \\x1B[33m⚠\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m Env revalidation failed:\\n${result.error}`,\n )\n return\n }\n\n lastValidated = result.data\n\n const clientMod = server.moduleGraph.getModuleById('\\0virtual:env/client')\n const serverMod = server.moduleGraph.getModuleById('\\0virtual:env/server')\n if (clientMod)\n server.moduleGraph.invalidateModule(clientMod)\n if (serverMod)\n server.moduleGraph.invalidateModule(serverMod)\n if (clientMod || serverMod) {\n serverModuleGuardFails = []\n server.hot.send({ type: 'full-reload' })\n resolvedConfig.logger.info(\n ` \\x1B[32m✓\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m Env revalidated`,\n )\n }\n }\n catch (e) {\n resolvedConfig.logger.error(\n `\\n \\x1B[31m✗\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m Failed to reload env files: ${e instanceof Error ? e.message : String(e)}`,\n )\n }\n }, 150)\n })\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAcA,SAAgB,wBACd,SACA,oBACA,MACA,UACa;AACb,KAAI,mBAAmB,SAAS,QAAQ,CACtC,QAAO,EAAE,SAAS,MAAM;AAC1B,QAAO;EAAE,SAAS;EAAO;EAAM;EAAS;EAAU;;;;;;;AAQpD,SAAgB,sBAAsB,SAAqD;AACzF,QAAO;EACL,YAAY;EACZ,MAAM;;wDAE8C,QAAQ;;;sEAGM,QAAQ;;EAE3E;;;;AClCH,MAAM,aAAa;;;;;;;;;;AAWnB,eAAsB,iBAAiB,OAAoB,MAA6B;CACtF,MAAM,uBAAO,IAAI,KAAa;CAC9B,MAAM,SAAS,MAAM,QAAQ,SAAS;EACpC,MAAM,MAAM,GAAG,KAAK,QAAQ,IAAI,KAAK,YAAY;AACjD,MAAI,KAAK,IAAI,IAAI,CACf,QAAO;AACT,OAAK,IAAI,IAAI;AACb,SAAO;GACP;CACF,MAAM,6BAAY,IAAI,MAAM,EAAC,aAAa;CAE1C,MAAM,UAAU,GAAG,WAAW,MADd,OAAO,KAAI,SAAQ,oBAAoB,MAAM,UAAU,CAAC,CAAC,KAAK,OACnC,CAAC;CAC5C,MAAM,WAAW,KAAK,KAAK,MAAM,wBAAwB;AACzD,KAAI;AACF,QAAM,GAAG,UAAU,UAAU,SAAS,QAAQ;UAEzC,GAAG;AACR,QAAM,IAAI,MACR,uDAAuD,KAAK,4BAC5D,EAAE,OAAO,GAAG,CACb;;;;;;;;;;;;;;;ACtBL,eAAsB,eACpB,QACiC;AAOjC,QAAO;EACL,GAPc,QACd,OAAO,MACP,OAAO,UAAU,OAAO,MACxB,GAIU;EACV,GAAG,cAAc,QAAQ,IAAI;EA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A4E,OAAO,QACpF;AACD;;AAGF,sBAAgB,OAAO;MAEvB,MAAM,YAAY,OAAO,YAAY,cAAc,uBAAuB;MAC1E,MAAM,YAAY,OAAO,YAAY,cAAc,uBAAuB;AAC1E,UAAI,UACF,QAAO,YAAY,iBAAiB,UAAU;AAChD,UAAI,UACF,QAAO,YAAY,iBAAiB,UAAU;AAChD,UAAI,aAAa,WAAW;AAC1B,gCAAyB,EAAE;AAC3B,cAAO,IAAI,KAAK,EAAE,MAAM,eAAe,CAAC;AACxC,sBAAe,OAAO,KACpB,+DACD;;cAGE,GAAG;AACR,qBAAe,OAAO,MACpB,8EAA8E,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE,GACzH;;OAEF,IAAI;KACP;;EAEL"}
|
|
1
|
+
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/guard.ts","../src/log.ts","../src/sources.ts","../src/virtual.ts","../src/plugin.ts"],"sourcesContent":["export type GuardMode = \"error\" | \"stub\" | \"warn\";\n\nexport type GuardResult =\n | { allowed: true }\n | { allowed: false; mode: GuardMode; envName: string; importer: string | undefined };\n\nexport type GuardFail = Extract<GuardResult, { allowed: false }>;\n\n/**\n * Determines whether the given Vite environment is allowed to import virtual:env/server.\n * Returns a GuardResult discriminated union — allowed or fail with context.\n * When this.environment is undefined (should not occur with Vite ≥ 8), callers default\n * envName to 'client' — failing closed (restrictive) is safer than failing open.\n */\nexport function checkServerModuleAccess(\n envName: string,\n serverEnvironments: string[],\n mode: GuardMode,\n importer: string | undefined,\n): GuardResult {\n if (serverEnvironments.includes(envName)) return { allowed: true };\n return { allowed: false, mode, envName, importer };\n}\n\n/**\n * Generates the stub virtual module returned when onClientAccessOfServerModule is 'stub'.\n * The stub throws at runtime if executed — its message reflects that this import was\n * expected to be unreachable and the assumption was wrong.\n */\nexport function buildServerStubModule(envName: string): { code: string; moduleType: \"js\" } {\n return {\n moduleType: \"js\",\n code: `// Auto-generated by @vite-env/core — server-only module stub\nthrow new Error(\n '[vite-env] virtual:env/server was imported in the \"${envName}\" environment. ' +\n 'This module is server-only and was replaced with a stub. ' +\n 'To allow this environment: add it to serverEnvironments. ' +\n 'To suppress this stub: ensure this import never executes in the \"${envName}\" environment.'\n);`,\n };\n}\n","// @env node\nimport type { GuardFail } from \"./guard\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { formatGuardLogEntry } from \"./format\";\n\nconst LOG_HEADER = `# vite-env warnings — generated by @vite-env/core\n# These warnings will become hard errors in 1.0.0.\n# To enforce immediately: ViteEnv({ onClientAccessOfServerModule: 'error' })\n# To acknowledge and suppress: ViteEnv({ onClientAccessOfServerModule: 'stub' })\n# To allow specific environments: ViteEnv({ serverEnvironments: ['ssr', 'workerd'] })`;\n\n/**\n * Writes accumulated GuardFail entries to vite-env-warnings.log in the project root.\n * Overwrites on each build — stale entries from previous builds must not persist.\n * Called only in 'warn' mode from buildEnd, after verifying the build succeeded.\n */\nexport async function writeWarningsLog(fails: GuardFail[], root: string): Promise<void> {\n const seen = new Set<string>();\n const unique = fails.filter((fail) => {\n const key = `${fail.envName}::${fail.importer ?? \"\"}`;\n if (seen.has(key)) return false;\n seen.add(key);\n return true;\n });\n const timestamp = new Date().toISOString();\n const entries = unique.map((fail) => formatGuardLogEntry(fail, timestamp)).join(\"\\n\\n\");\n const content = `${LOG_HEADER}\\n\\n${entries}\\n`;\n const filePath = path.join(root, \"vite-env-warnings.log\");\n try {\n await fs.writeFile(filePath, content, \"utf-8\");\n } catch (e) {\n throw new Error(\n `[vite-env] Failed to write vite-env-warnings.log to ${root}. Check file permissions.`,\n { cause: e },\n );\n }\n}\n","// @env node\nimport type { ResolvedConfig } from \"vite\";\nimport process from \"node:process\";\nimport { loadEnv } from \"vite\";\n\n/**\n * Merge priority (highest → lowest):\n * 1. process.env (CI pipeline secrets win)\n * 2. .env.[mode].local\n * 3. .env.[mode]\n * 4. .env.local\n * 5. .env\n *\n * Prefix '' = load everything, schema decides what's valid.\n */\nexport async function loadEnvSources(config: ResolvedConfig): Promise<Record<string, string>> {\n const fileEnv = loadEnv(\n config.mode,\n config.envDir || config.root,\n \"\", // no prefix filter — schema is the filter\n );\n\n return {\n ...fileEnv,\n ...filterStrings(process.env),\n };\n}\n\nfunction filterStrings(env: NodeJS.ProcessEnv): Record<string, string> {\n return Object.fromEntries(\n Object.entries(env).filter((entry): entry is [string, string] => typeof entry[1] === \"string\"),\n );\n}\n","import type { AnyEnvDefinition } from \"./types\";\n\nexport function buildClientModule(\n def: AnyEnvDefinition,\n data: Record<string, unknown>,\n): { code: string; moduleType: \"js\" } {\n const clientKeys = new Set(Object.keys(def.client ?? {}));\n\n const clientData = Object.fromEntries(Object.entries(data).filter(([k]) => clientKeys.has(k)));\n\n return {\n moduleType: \"js\", // Required: Vite 8 / Rolldown explicit moduleType\n code: `// Auto-generated by @vite-env/core — do not edit\nexport const env = Object.freeze(${JSON.stringify(clientData, null, 2)});\nexport default env;`,\n };\n}\n\nexport function buildServerModule(\n _def: AnyEnvDefinition,\n data: Record<string, unknown>,\n): { code: string; moduleType: \"js\" } {\n return {\n moduleType: \"js\",\n code: `// Auto-generated by @vite-env/core — do not edit\nexport const env = Object.freeze(${JSON.stringify(data, null, 2)});\nexport default env;`,\n };\n}\n","// @env node\nimport type { Plugin, ResolvedConfig, Rollup } from \"vite\";\nimport type { GuardFail } from \"./guard\";\nimport type { AnyEnvDefinition } from \"./types\";\nimport path from \"node:path\";\nimport process from \"node:process\";\nimport { loadEnvConfig } from \"./config\";\nimport { generateStandardDts } from \"./dts\";\nimport { formatGuardWarning, formatHardError, formatStandardSchemaError } from \"./format\";\nimport { buildServerStubModule, checkServerModuleAccess } from \"./guard\";\nimport { detectServerLeak } from \"./leak\";\nimport { writeWarningsLog } from \"./log\";\nimport { loadEnvSources } from \"./sources\";\nimport { isStandardEnvDefinition, validateStandardEnv } from \"./standard\";\nimport { buildClientModule, buildServerModule } from \"./virtual\";\n\nexport type ViteEnvOptions = {\n /**\n * Path to env definition file.\n * @default './env.ts' (resolved from project root)\n */\n configFile?: string;\n\n /**\n * Vite 8 environment names that are allowed to import virtual:env/server.\n * Use this to allow edge runtimes (Cloudflare Workers → 'workerd', Deno Deploy → 'ssr').\n * @default ['ssr']\n */\n serverEnvironments?: string[];\n\n /**\n * Behavior when virtual:env/server is imported from a disallowed environment.\n *\n * - 'warn' — Deprecation warning printed to terminal + vite-env-warnings.log written.\n * Build succeeds but exits with code 1. Default in 0.x releases.\n * The default will change to 'error' in 1.0.0.\n *\n * - 'error' — Hard build error. No artifacts emitted.\n *\n * - 'stub' — Returns a module that throws at runtime if the import executes.\n * Use for testing environments (Vitest jsdom) or framework isomorphic files\n * where the import exists but the code path is never reached in a server context.\n *\n * @default 'warn'\n */\n onClientAccessOfServerModule?: \"error\" | \"stub\" | \"warn\";\n};\n\n/**\n * Validates environment variables against the definition.\n * Routes to Zod or Standard Schema path based on definition type.\n * Zod modules are loaded dynamically to avoid requiring zod for Standard Schema users.\n */\nasync function validateAndFormat(\n def: AnyEnvDefinition,\n rawEnv: Record<string, string>,\n): Promise<{ data: Record<string, unknown> } | { error: string }> {\n if (isStandardEnvDefinition(def)) {\n const result = await validateStandardEnv(def, rawEnv);\n if (!result.success) {\n return { error: formatStandardSchemaError(result.errors) };\n }\n return { data: result.data };\n }\n\n const { validateEnv } = await import(\"./schema\");\n const { formatZodError } = await import(\"./format\");\n const result = validateEnv(def, rawEnv);\n if (!result.success) {\n return { error: formatZodError(result.errors) };\n }\n return { data: result.data };\n}\n\nexport default function ViteEnv(options: ViteEnvOptions = {}): Plugin {\n let resolvedConfig: ResolvedConfig;\n let envDefinition: AnyEnvDefinition;\n let lastValidated: Record<string, unknown> = {};\n let serverModuleGuardFails: GuardFail[] = [];\n let didSetExitCode = false;\n\n const serverEnvs = options.serverEnvironments ?? [\"ssr\"];\n const guardMode = options.onClientAccessOfServerModule ?? \"warn\";\n\n return {\n name: \"vite-env\",\n enforce: \"pre\",\n\n async configResolved(config) {\n resolvedConfig = config;\n\n const configPath = path.resolve(config.root, options.configFile ?? \"env.ts\");\n\n try {\n envDefinition = await loadEnvConfig(configPath);\n } catch (e) {\n throw new Error(\n `[vite-env] Could not load env definition file at: ${configPath}\\n` +\n ` Create an env.ts file and export default defineEnv({ ... })`,\n { cause: e },\n );\n }\n },\n\n async buildStart() {\n serverModuleGuardFails = [];\n if (didSetExitCode) {\n process.exitCode = 0;\n didSetExitCode = false;\n }\n\n const rawEnv = await loadEnvSources(resolvedConfig);\n const result = await validateAndFormat(envDefinition, rawEnv);\n\n if (\"error\" in result) {\n throw new Error(`[vite-env] Environment validation failed:\\n\\n${result.error}`);\n }\n\n lastValidated = result.data;\n\n if (isStandardEnvDefinition(envDefinition)) {\n await generateStandardDts(envDefinition, resolvedConfig.root);\n } else {\n const { generateDts } = await import(\"./dts\");\n await generateDts(envDefinition, resolvedConfig.root);\n }\n\n const count = Object.keys(lastValidated).length;\n resolvedConfig.logger.info(\n ` \\x1B[32m✓\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m ${count} variables validated`,\n );\n },\n\n resolveId(this: Rollup.PluginContext, source, importer) {\n if (source === \"virtual:env/client\") return \"\\0virtual:env/client\";\n if (source === \"virtual:env/server\") {\n const envName = this.environment?.name ?? \"client\";\n const result = checkServerModuleAccess(envName, serverEnvs, guardMode, importer);\n if (!result.allowed) serverModuleGuardFails.push(result);\n return \"\\0virtual:env/server\";\n }\n },\n\n load(this: Rollup.PluginContext, id) {\n if (id === \"\\0virtual:env/client\") return buildClientModule(envDefinition, lastValidated);\n if (id === \"\\0virtual:env/server\") {\n const envName = this.environment?.name ?? \"client\";\n // Filter to fails from this environment only — other envs may have recorded fails for their own loads\n const envFails = serverModuleGuardFails.filter((f) => f.envName === envName);\n if (envFails.length > 0) {\n // warn once per load cycle using the last recorded fail; unique importers are written to the log file\n const latest = envFails.at(-1)!;\n if (latest.mode === \"error\") throw new Error(formatHardError(latest));\n if (latest.mode === \"stub\") return buildServerStubModule(envName);\n resolvedConfig.logger.warn(`\\n${formatGuardWarning(latest)}`);\n }\n return buildServerModule(envDefinition, lastValidated);\n }\n },\n\n async buildEnd(error) {\n if (error) return;\n if (serverModuleGuardFails.length === 0) return;\n if (guardMode !== \"warn\") return;\n await writeWarningsLog(serverModuleGuardFails, resolvedConfig.root);\n process.exitCode = 1;\n didSetExitCode = true;\n },\n\n generateBundle(this: Rollup.PluginContext, _options, bundle) {\n if (resolvedConfig.build.ssr) return;\n\n const envName = this.environment?.name ?? \"client\";\n if (serverEnvs.includes(envName)) return;\n\n const leaks = detectServerLeak(\n envDefinition,\n lastValidated,\n bundle as Record<string, { type: string; code?: string }>,\n (keys) => {\n resolvedConfig.logger.warn(\n ` \\x1B[33m⚠\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m Leak detection skipped ${keys.length} server variable(s) with values shorter than 8 chars: ${keys.join(\", \")}`,\n );\n },\n );\n\n if (leaks.length > 0) {\n const details = leaks.map((l) => ` ✗ ${l.key} found in ${l.chunk}`).join(\"\\n\");\n throw new Error(\n `[vite-env] Server environment variables detected in client bundle!\\n\\n${details}\\n\\n These variables are marked as server-only and must never reach the browser.`,\n );\n }\n },\n\n configureServer(server) {\n const envDir = resolvedConfig.envDir || resolvedConfig.root;\n server.watcher.add(path.join(envDir, \".env*\"));\n\n let debounceTimer: ReturnType<typeof setTimeout>;\n\n server.watcher.on(\"change\", async (file) => {\n if (!path.basename(file).startsWith(\".env\")) return;\n\n clearTimeout(debounceTimer);\n debounceTimer = setTimeout(async () => {\n try {\n const rawEnv = await loadEnvSources(resolvedConfig);\n const result = await validateAndFormat(envDefinition, rawEnv);\n\n if (\"error\" in result) {\n resolvedConfig.logger.warn(\n `\\n \\x1B[33m⚠\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m Env revalidation failed:\\n${result.error}`,\n );\n return;\n }\n\n lastValidated = result.data;\n\n const clientMod = server.moduleGraph.getModuleById(\"\\0virtual:env/client\");\n const serverMod = server.moduleGraph.getModuleById(\"\\0virtual:env/server\");\n if (clientMod) server.moduleGraph.invalidateModule(clientMod);\n if (serverMod) server.moduleGraph.invalidateModule(serverMod);\n if (clientMod || serverMod) {\n serverModuleGuardFails = [];\n server.hot.send({ type: \"full-reload\" });\n resolvedConfig.logger.info(\n ` \\x1B[32m✓\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m Env revalidated`,\n );\n }\n } catch (e) {\n resolvedConfig.logger.error(\n `\\n \\x1B[31m✗\\x1B[0m \\x1B[36m[vite-env]\\x1B[0m Failed to reload env files: ${e instanceof Error ? e.message : String(e)}`,\n );\n }\n }, 150);\n });\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAcA,SAAgB,wBACd,SACA,oBACA,MACA,UACa;AACb,KAAI,mBAAmB,SAAS,QAAQ,CAAE,QAAO,EAAE,SAAS,MAAM;AAClE,QAAO;EAAE,SAAS;EAAO;EAAM;EAAS;EAAU;;;;;;;AAQpD,SAAgB,sBAAsB,SAAqD;AACzF,QAAO;EACL,YAAY;EACZ,MAAM;;wDAE8C,QAAQ;;;sEAGM,QAAQ;;EAE3E;;;;ACjCH,MAAM,aAAa;;;;;;;;;;AAWnB,eAAsB,iBAAiB,OAAoB,MAA6B;CACtF,MAAM,uBAAO,IAAI,KAAa;CAC9B,MAAM,SAAS,MAAM,QAAQ,SAAS;EACpC,MAAM,MAAM,GAAG,KAAK,QAAQ,IAAI,KAAK,YAAY;AACjD,MAAI,KAAK,IAAI,IAAI,CAAE,QAAO;AAC1B,OAAK,IAAI,IAAI;AACb,SAAO;GACP;CACF,MAAM,6BAAY,IAAI,MAAM,EAAC,aAAa;CAE1C,MAAM,UAAU,GAAG,WAAW,MADd,OAAO,KAAK,SAAS,oBAAoB,MAAM,UAAU,CAAC,CAAC,KAAK,OACrC,CAAC;CAC5C,MAAM,WAAW,KAAK,KAAK,MAAM,wBAAwB;AACzD,KAAI;AACF,QAAM,GAAG,UAAU,UAAU,SAAS,QAAQ;UACvC,GAAG;AACV,QAAM,IAAI,MACR,uDAAuD,KAAK,4BAC5D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AE;AAE7C,iBAAa,cAAc;AAC3B,oBAAgB,WAAW,YAAY;AACrC,SAAI;MACF,MAAM,SAAS,MAAM,eAAe,eAAe;MACnD,MAAM,SAAS,MAAM,kBAAkB,eAAe,OAAO;AAE7D,UAAI,WAAW,QAAQ;AACrB,sBAAe,OAAO,KACpB,4EAA4E,OAAO,QACpF;AACD;;AAGF,sBAAgB,OAAO;MAEvB,MAAM,YAAY,OAAO,YAAY,cAAc,uBAAuB;MAC1E,MAAM,YAAY,OAAO,YAAY,cAAc,uBAAuB;AAC1E,UAAI,UAAW,QAAO,YAAY,iBAAiB,UAAU;AAC7D,UAAI,UAAW,QAAO,YAAY,iBAAiB,UAAU;AAC7D,UAAI,aAAa,WAAW;AAC1B,gCAAyB,EAAE;AAC3B,cAAO,IAAI,KAAK,EAAE,MAAM,eAAe,CAAC;AACxC,sBAAe,OAAO,KACpB,+DACD;;cAEI,GAAG;AACV,qBAAe,OAAO,MACpB,8EAA8E,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE,GACzH;;OAEF,IAAI;KACP;;EAEL"}
|
package/dist/presets/index.cjs
CHANGED
|
@@ -1,72 +1,81 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("../
|
|
2
|
+
require("../chunk-CKQMccvm.cjs");
|
|
3
3
|
let zod = require("zod");
|
|
4
4
|
//#region src/presets/netlify.ts
|
|
5
|
-
const netlify = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
const netlify = {
|
|
6
|
+
server: {
|
|
7
|
+
NETLIFY: zod.z.enum(["true"]),
|
|
8
|
+
BUILD_ID: zod.z.string().min(1),
|
|
9
|
+
CONTEXT: zod.z.enum([
|
|
10
|
+
"production",
|
|
11
|
+
"deploy-preview",
|
|
12
|
+
"branch-deploy",
|
|
13
|
+
"dev"
|
|
14
|
+
]),
|
|
15
|
+
DEPLOY_ID: zod.z.string().min(1),
|
|
16
|
+
DEPLOY_URL: zod.z.url(),
|
|
17
|
+
DEPLOY_PRIME_URL: zod.z.url(),
|
|
18
|
+
URL: zod.z.url(),
|
|
19
|
+
BRANCH: zod.z.string().min(1),
|
|
20
|
+
COMMIT_REF: zod.z.string().min(1),
|
|
21
|
+
PULL_REQUEST: zod.z.enum(["true"]).optional(),
|
|
22
|
+
REVIEW_ID: zod.z.string().optional(),
|
|
23
|
+
REPOSITORY_URL: zod.z.url().optional(),
|
|
24
|
+
INCOMING_HOOK_TITLE: zod.z.string().optional(),
|
|
25
|
+
INCOMING_HOOK_URL: zod.z.url().optional()
|
|
26
|
+
},
|
|
27
|
+
detect: (env) => env.NETLIFY === "true"
|
|
28
|
+
};
|
|
26
29
|
//#endregion
|
|
27
30
|
//#region src/presets/railway.ts
|
|
28
|
-
const railway = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
const railway = {
|
|
32
|
+
server: {
|
|
33
|
+
RAILWAY_ENVIRONMENT_ID: zod.z.string().min(1),
|
|
34
|
+
RAILWAY_ENVIRONMENT_NAME: zod.z.string().min(1),
|
|
35
|
+
RAILWAY_SERVICE_ID: zod.z.string().min(1),
|
|
36
|
+
RAILWAY_SERVICE_NAME: zod.z.string().min(1),
|
|
37
|
+
RAILWAY_PROJECT_ID: zod.z.string().min(1),
|
|
38
|
+
RAILWAY_PROJECT_NAME: zod.z.string().min(1),
|
|
39
|
+
RAILWAY_DEPLOYMENT_ID: zod.z.string().min(1),
|
|
40
|
+
RAILWAY_REPLICA_ID: zod.z.string().optional(),
|
|
41
|
+
RAILWAY_GIT_COMMIT_SHA: zod.z.string().optional(),
|
|
42
|
+
RAILWAY_GIT_BRANCH: zod.z.string().optional(),
|
|
43
|
+
RAILWAY_GIT_REPO_NAME: zod.z.string().optional(),
|
|
44
|
+
RAILWAY_GIT_REPO_OWNER: zod.z.string().optional(),
|
|
45
|
+
RAILWAY_PUBLIC_DOMAIN: zod.z.string().min(1).optional(),
|
|
46
|
+
RAILWAY_PRIVATE_DOMAIN: zod.z.string().min(1).optional(),
|
|
47
|
+
RAILWAY_TCP_PROXY_DOMAIN: zod.z.string().min(1).optional(),
|
|
48
|
+
RAILWAY_TCP_PROXY_PORT: zod.z.coerce.number().int().min(1).max(65535).optional()
|
|
49
|
+
},
|
|
50
|
+
detect: (env) => !!env.RAILWAY_ENVIRONMENT_ID
|
|
51
|
+
};
|
|
46
52
|
//#endregion
|
|
47
53
|
//#region src/presets/vercel.ts
|
|
48
|
-
const vercel = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
54
|
+
const vercel = {
|
|
55
|
+
server: {
|
|
56
|
+
VERCEL: zod.z.enum(["1"]),
|
|
57
|
+
VERCEL_ENV: zod.z.enum([
|
|
58
|
+
"production",
|
|
59
|
+
"preview",
|
|
60
|
+
"development"
|
|
61
|
+
]),
|
|
62
|
+
VERCEL_URL: zod.z.string().min(1),
|
|
63
|
+
VERCEL_BRANCH_URL: zod.z.string().min(1).optional(),
|
|
64
|
+
VERCEL_PROJECT_PRODUCTION_URL: zod.z.string().min(1),
|
|
65
|
+
VERCEL_DEPLOYMENT_ID: zod.z.string().min(1),
|
|
66
|
+
VERCEL_REGION: zod.z.string().optional(),
|
|
67
|
+
VERCEL_GIT_PROVIDER: zod.z.string().optional(),
|
|
68
|
+
VERCEL_GIT_REPO_SLUG: zod.z.string().optional(),
|
|
69
|
+
VERCEL_GIT_REPO_OWNER: zod.z.string().optional(),
|
|
70
|
+
VERCEL_GIT_COMMIT_REF: zod.z.string().optional(),
|
|
71
|
+
VERCEL_GIT_COMMIT_SHA: zod.z.string().optional(),
|
|
72
|
+
VERCEL_GIT_COMMIT_MESSAGE: zod.z.string().optional(),
|
|
73
|
+
VERCEL_GIT_COMMIT_AUTHOR_LOGIN: zod.z.string().optional(),
|
|
74
|
+
VERCEL_GIT_PULL_REQUEST_ID: zod.z.string().optional(),
|
|
75
|
+
VERCEL_SKEW_PROTECTION_ENABLED: zod.z.enum(["1"]).optional()
|
|
76
|
+
},
|
|
77
|
+
detect: (env) => env.VERCEL === "1"
|
|
78
|
+
};
|
|
70
79
|
//#endregion
|
|
71
80
|
exports.netlify = netlify;
|
|
72
81
|
exports.railway = railway;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["z","z","z"],"sources":["../../src/presets/netlify.ts","../../src/presets/railway.ts","../../src/presets/vercel.ts"],"sourcesContent":["import type { EnvPreset } from
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["z","z","z"],"sources":["../../src/presets/netlify.ts","../../src/presets/railway.ts","../../src/presets/vercel.ts"],"sourcesContent":["import type { EnvPreset } from \"../types\";\nimport { z } from \"zod\";\n\nexport const netlify = {\n server: {\n // Set to 'true' by Netlify to indicate a Netlify build (note: Vercel uses '1', not 'true')\n NETLIFY: z.enum([\"true\"]),\n BUILD_ID: z.string().min(1),\n CONTEXT: z.enum([\"production\", \"deploy-preview\", \"branch-deploy\", \"dev\"]),\n DEPLOY_ID: z.string().min(1),\n // Full https:// URLs — z.url() is correct here unlike VERCEL_URL\n DEPLOY_URL: z.url(),\n DEPLOY_PRIME_URL: z.url(),\n URL: z.url(),\n BRANCH: z.string().min(1),\n COMMIT_REF: z.string().min(1),\n // Netlify sets this to 'true' on PR deploys; absent (not 'false') on non-PR builds\n PULL_REQUEST: z.enum([\"true\"]).optional(),\n REVIEW_ID: z.string().optional(),\n REPOSITORY_URL: z.url().optional(),\n INCOMING_HOOK_TITLE: z.string().optional(),\n INCOMING_HOOK_URL: z.url().optional(),\n },\n // Netlify sets NETLIFY=true during builds and under `netlify dev`\n detect: (env) => env.NETLIFY === \"true\",\n} satisfies EnvPreset;\n","import type { EnvPreset } from \"../types\";\nimport { z } from \"zod\";\n\nexport const railway = {\n server: {\n RAILWAY_ENVIRONMENT_ID: z.string().min(1),\n RAILWAY_ENVIRONMENT_NAME: z.string().min(1),\n RAILWAY_SERVICE_ID: z.string().min(1),\n RAILWAY_SERVICE_NAME: z.string().min(1),\n RAILWAY_PROJECT_ID: z.string().min(1),\n RAILWAY_PROJECT_NAME: z.string().min(1),\n RAILWAY_DEPLOYMENT_ID: z.string().min(1),\n RAILWAY_REPLICA_ID: z.string().optional(),\n RAILWAY_GIT_COMMIT_SHA: z.string().optional(),\n RAILWAY_GIT_BRANCH: z.string().optional(),\n RAILWAY_GIT_REPO_NAME: z.string().optional(),\n RAILWAY_GIT_REPO_OWNER: z.string().optional(),\n RAILWAY_PUBLIC_DOMAIN: z.string().min(1).optional(),\n RAILWAY_PRIVATE_DOMAIN: z.string().min(1).optional(),\n RAILWAY_TCP_PROXY_DOMAIN: z.string().min(1).optional(),\n RAILWAY_TCP_PROXY_PORT: z.coerce.number().int().min(1).max(65535).optional(),\n // PORT excluded: generic name set by many tools independently; handle it in your own server config\n },\n // Railway always injects the environment id at runtime\n detect: (env) => !!env.RAILWAY_ENVIRONMENT_ID,\n} satisfies EnvPreset;\n","import type { EnvPreset } from \"../types\";\nimport { z } from \"zod\";\n\nexport const vercel = {\n server: {\n // Set to '1' by Vercel to indicate a Vercel environment\n VERCEL: z.enum([\"1\"]),\n VERCEL_ENV: z.enum([\"production\", \"preview\", \"development\"]),\n // Bare hostname (e.g. myapp-abc123.vercel.app) — no scheme, z.url() would reject it\n VERCEL_URL: z.string().min(1),\n VERCEL_BRANCH_URL: z.string().min(1).optional(),\n VERCEL_PROJECT_PRODUCTION_URL: z.string().min(1),\n VERCEL_DEPLOYMENT_ID: z.string().min(1),\n VERCEL_REGION: z.string().optional(),\n // z.string() not enum — Vercel may add providers (Azure DevOps, self-hosted GitLab) without notice\n VERCEL_GIT_PROVIDER: z.string().optional(),\n VERCEL_GIT_REPO_SLUG: z.string().optional(),\n VERCEL_GIT_REPO_OWNER: z.string().optional(),\n VERCEL_GIT_COMMIT_REF: z.string().optional(),\n VERCEL_GIT_COMMIT_SHA: z.string().optional(),\n VERCEL_GIT_COMMIT_MESSAGE: z.string().optional(),\n VERCEL_GIT_COMMIT_AUTHOR_LOGIN: z.string().optional(),\n VERCEL_GIT_PULL_REQUEST_ID: z.string().optional(),\n VERCEL_SKEW_PROTECTION_ENABLED: z.enum([\"1\"]).optional(),\n },\n // Vercel sets VERCEL=1 on builds and under `vercel dev`\n detect: (env) => env.VERCEL === \"1\",\n} satisfies EnvPreset;\n"],"mappings":";;;;AAGA,MAAa,UAAU;CACrB,QAAQ;EAEN,SAASA,IAAAA,EAAE,KAAK,CAAC,OAAO,CAAC;EACzB,UAAUA,IAAAA,EAAE,QAAQ,CAAC,IAAI,EAAE;EAC3B,SAASA,IAAAA,EAAE,KAAK;GAAC;GAAc;GAAkB;GAAiB;GAAM,CAAC;EACzE,WAAWA,IAAAA,EAAE,QAAQ,CAAC,IAAI,EAAE;EAE5B,YAAYA,IAAAA,EAAE,KAAK;EACnB,kBAAkBA,IAAAA,EAAE,KAAK;EACzB,KAAKA,IAAAA,EAAE,KAAK;EACZ,QAAQA,IAAAA,EAAE,QAAQ,CAAC,IAAI,EAAE;EACzB,YAAYA,IAAAA,EAAE,QAAQ,CAAC,IAAI,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AC,IAAI,MAAM,CAAC,UAAU;EAE7E;CAED,SAAS,QAAQ,CAAC,CAAC,IAAI;CACxB;;;ACtBD,MAAa,SAAS;CACpB,QAAQ;EAEN,QAAQC,IAAAA,EAAE,KAAK,CAAC,IAAI,CAAC;EACrB,YAAYA,IAAAA,EAAE,KAAK;GAAC;GAAc;GAAW;GAAc,CAAC;EAE5D,YAAYA,IAAAA,EAAE,QAAQ,CAAC,IAAI,EAAE;EAC7B,mBAAmBA,IAAAA,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,UAAU;EAC/C,+BAA+BA,IAAAA,EAAE,QAAQ,CAAC,IAAI,EAAE;EAChD,sBAAsBA,IAAAA,EAAE,QAAQ,CAAC,IAAI,EAAE;EACvC,eAAeA,IAAAA,EAAE,QAAQ,CAAC,UAAU;EAEpC,qBAAqBA,IAAAA,EAAE,QAAQ,CAAC,UAAU;EAC1C,sBAAsBA,IAAAA,EAAE,QAAQ,CAAC,UAAU;EAC3C,uBAAuBA,IAAAA,EAAE,QAAQ,CAAC,UAAU;EAC5C,uBAAuBA,IAAAA,EAAE,QAAQ,CAAC,UAAU;EAC5C,uBAAuBA,IAAAA,EAAE,QAAQ,CAAC,UAAU;EAC5C,2BAA2BA,IAAAA,EAAE,QAAQ,CAAC,UAAU;EAChD,gCAAgCA,IAAAA,EAAE,QAAQ,CAAC,UAAU;EACrD,4BAA4BA,IAAAA,EAAE,QAAQ,CAAC,UAAU;EACjD,gCAAgCA,IAAAA,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,UAAU;EACzD;CAED,SAAS,QAAQ,IAAI,WAAW;CACjC"}
|
package/dist/presets/index.d.cts
CHANGED
|
@@ -27,6 +27,7 @@ declare const netlify: {
|
|
|
27
27
|
INCOMING_HOOK_TITLE: z.ZodOptional<z.ZodString>;
|
|
28
28
|
INCOMING_HOOK_URL: z.ZodOptional<z.ZodURL>;
|
|
29
29
|
};
|
|
30
|
+
detect: (env: Record<string, string | undefined>) => boolean;
|
|
30
31
|
};
|
|
31
32
|
//#endregion
|
|
32
33
|
//#region src/presets/railway.d.ts
|
|
@@ -49,6 +50,7 @@ declare const railway: {
|
|
|
49
50
|
RAILWAY_TCP_PROXY_DOMAIN: z.ZodOptional<z.ZodString>;
|
|
50
51
|
RAILWAY_TCP_PROXY_PORT: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
51
52
|
};
|
|
53
|
+
detect: (env: Record<string, string | undefined>) => boolean;
|
|
52
54
|
};
|
|
53
55
|
//#endregion
|
|
54
56
|
//#region src/presets/vercel.d.ts
|
|
@@ -79,6 +81,7 @@ declare const vercel: {
|
|
|
79
81
|
1: "1";
|
|
80
82
|
}>>;
|
|
81
83
|
};
|
|
84
|
+
detect: (env: Record<string, string | undefined>) => boolean;
|
|
82
85
|
};
|
|
83
86
|
//#endregion
|
|
84
87
|
export { netlify, railway, vercel };
|
package/dist/presets/index.d.mts
CHANGED
|
@@ -27,6 +27,7 @@ declare const netlify: {
|
|
|
27
27
|
INCOMING_HOOK_TITLE: z.ZodOptional<z.ZodString>;
|
|
28
28
|
INCOMING_HOOK_URL: z.ZodOptional<z.ZodURL>;
|
|
29
29
|
};
|
|
30
|
+
detect: (env: Record<string, string | undefined>) => boolean;
|
|
30
31
|
};
|
|
31
32
|
//#endregion
|
|
32
33
|
//#region src/presets/railway.d.ts
|
|
@@ -49,6 +50,7 @@ declare const railway: {
|
|
|
49
50
|
RAILWAY_TCP_PROXY_DOMAIN: z.ZodOptional<z.ZodString>;
|
|
50
51
|
RAILWAY_TCP_PROXY_PORT: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
51
52
|
};
|
|
53
|
+
detect: (env: Record<string, string | undefined>) => boolean;
|
|
52
54
|
};
|
|
53
55
|
//#endregion
|
|
54
56
|
//#region src/presets/vercel.d.ts
|
|
@@ -79,6 +81,7 @@ declare const vercel: {
|
|
|
79
81
|
1: "1";
|
|
80
82
|
}>>;
|
|
81
83
|
};
|
|
84
|
+
detect: (env: Record<string, string | undefined>) => boolean;
|
|
82
85
|
};
|
|
83
86
|
//#endregion
|
|
84
87
|
export { netlify, railway, vercel };
|