@vite-env/core 0.3.0 → 0.5.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 +18 -0
- package/dist/config.d.cts +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/dts.d.cts +1 -1
- package/dist/dts.d.mts +1 -1
- package/dist/format.cjs +82 -0
- package/dist/format.cjs.map +1 -1
- package/dist/format.d.cts +41 -2
- package/dist/format.d.mts +41 -2
- package/dist/format.mjs +78 -1
- package/dist/format.mjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/leak.d.cts +1 -1
- package/dist/leak.d.mts +1 -1
- package/dist/plugin.cjs +101 -4
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +22 -0
- package/dist/plugin.d.mts +22 -0
- package/dist/plugin.mjs +101 -5
- package/dist/plugin.mjs.map +1 -1
- package/dist/presets/index.cjs +75 -0
- package/dist/presets/index.cjs.map +1 -0
- package/dist/presets/index.d.cts +85 -0
- package/dist/presets/index.d.mts +85 -0
- package/dist/presets/index.mjs +71 -0
- package/dist/presets/index.mjs.map +1 -0
- package/dist/schema.cjs +25 -4
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +5 -2
- package/dist/schema.d.mts +5 -2
- package/dist/schema.mjs +25 -4
- package/dist/schema.mjs.map +1 -1
- package/dist/standard.d.cts +1 -1
- package/dist/standard.d.mts +1 -1
- package/dist/{types-1okexcwM.d.cts → types-Bl3YdPck.d.cts} +6 -2
- package/dist/{types-DuWT_251.d.mts → types-CUF5RARc.d.mts} +6 -2
- package/package.json +11 -1
package/dist/plugin.d.cts
CHANGED
|
@@ -7,6 +7,28 @@ interface ViteEnvOptions {
|
|
|
7
7
|
* @default './env.ts' (resolved from project root)
|
|
8
8
|
*/
|
|
9
9
|
configFile?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Vite 8 environment names that are allowed to import virtual:env/server.
|
|
12
|
+
* Use this to allow edge runtimes (Cloudflare Workers → 'workerd', Deno Deploy → 'ssr').
|
|
13
|
+
* @default ['ssr']
|
|
14
|
+
*/
|
|
15
|
+
serverEnvironments?: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Behavior when virtual:env/server is imported from a disallowed environment.
|
|
18
|
+
*
|
|
19
|
+
* - 'warn' — Deprecation warning printed to terminal + vite-env-warnings.log written.
|
|
20
|
+
* Build succeeds but exits with code 1. Default in 0.x releases.
|
|
21
|
+
* The default will change to 'error' in 1.0.0.
|
|
22
|
+
*
|
|
23
|
+
* - 'error' — Hard build error. No artifacts emitted.
|
|
24
|
+
*
|
|
25
|
+
* - 'stub' — Returns a module that throws at runtime if the import executes.
|
|
26
|
+
* Use for testing environments (Vitest jsdom) or framework isomorphic files
|
|
27
|
+
* where the import exists but the code path is never reached in a server context.
|
|
28
|
+
*
|
|
29
|
+
* @default 'warn'
|
|
30
|
+
*/
|
|
31
|
+
onClientAccessOfServerModule?: 'error' | 'stub' | 'warn';
|
|
10
32
|
}
|
|
11
33
|
declare function ViteEnv(options?: ViteEnvOptions): Plugin;
|
|
12
34
|
//#endregion
|
package/dist/plugin.d.mts
CHANGED
|
@@ -7,6 +7,28 @@ interface ViteEnvOptions {
|
|
|
7
7
|
* @default './env.ts' (resolved from project root)
|
|
8
8
|
*/
|
|
9
9
|
configFile?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Vite 8 environment names that are allowed to import virtual:env/server.
|
|
12
|
+
* Use this to allow edge runtimes (Cloudflare Workers → 'workerd', Deno Deploy → 'ssr').
|
|
13
|
+
* @default ['ssr']
|
|
14
|
+
*/
|
|
15
|
+
serverEnvironments?: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Behavior when virtual:env/server is imported from a disallowed environment.
|
|
18
|
+
*
|
|
19
|
+
* - 'warn' — Deprecation warning printed to terminal + vite-env-warnings.log written.
|
|
20
|
+
* Build succeeds but exits with code 1. Default in 0.x releases.
|
|
21
|
+
* The default will change to 'error' in 1.0.0.
|
|
22
|
+
*
|
|
23
|
+
* - 'error' — Hard build error. No artifacts emitted.
|
|
24
|
+
*
|
|
25
|
+
* - 'stub' — Returns a module that throws at runtime if the import executes.
|
|
26
|
+
* Use for testing environments (Vitest jsdom) or framework isomorphic files
|
|
27
|
+
* where the import exists but the code path is never reached in a server context.
|
|
28
|
+
*
|
|
29
|
+
* @default 'warn'
|
|
30
|
+
*/
|
|
31
|
+
onClientAccessOfServerModule?: 'error' | 'stub' | 'warn';
|
|
10
32
|
}
|
|
11
33
|
declare function ViteEnv(options?: ViteEnvOptions): Plugin;
|
|
12
34
|
//#endregion
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,11 +1,75 @@
|
|
|
1
1
|
import { isStandardEnvDefinition, validateStandardEnv } from "./standard.mjs";
|
|
2
2
|
import { loadEnvConfig } from "./config.mjs";
|
|
3
3
|
import { generateStandardDts } from "./dts.mjs";
|
|
4
|
-
import { formatStandardSchemaError } from "./format.mjs";
|
|
4
|
+
import { formatGuardLogEntry, formatGuardWarning, formatHardError, formatStandardSchemaError } from "./format.mjs";
|
|
5
5
|
import { detectServerLeak } from "./leak.mjs";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import process from "node:process";
|
|
8
|
+
import fs from "node:fs/promises";
|
|
8
9
|
import { loadEnv } from "vite";
|
|
10
|
+
//#region src/guard.ts
|
|
11
|
+
/**
|
|
12
|
+
* Determines whether the given Vite environment is allowed to import virtual:env/server.
|
|
13
|
+
* Returns a GuardResult discriminated union — allowed or fail with context.
|
|
14
|
+
* When this.environment is undefined (should not occur with Vite ≥ 8), callers default
|
|
15
|
+
* envName to 'client' — failing closed (restrictive) is safer than failing open.
|
|
16
|
+
*/
|
|
17
|
+
function checkServerModuleAccess(envName, serverEnvironments, mode, importer) {
|
|
18
|
+
if (serverEnvironments.includes(envName)) return { allowed: true };
|
|
19
|
+
return {
|
|
20
|
+
allowed: false,
|
|
21
|
+
mode,
|
|
22
|
+
envName,
|
|
23
|
+
importer
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generates the stub virtual module returned when onClientAccessOfServerModule is 'stub'.
|
|
28
|
+
* The stub throws at runtime if executed — its message reflects that this import was
|
|
29
|
+
* expected to be unreachable and the assumption was wrong.
|
|
30
|
+
*/
|
|
31
|
+
function buildServerStubModule(envName) {
|
|
32
|
+
return {
|
|
33
|
+
moduleType: "js",
|
|
34
|
+
code: `// Auto-generated by @vite-env/core — server-only module stub
|
|
35
|
+
throw new Error(
|
|
36
|
+
'[vite-env] virtual:env/server was imported in the "${envName}" environment. ' +
|
|
37
|
+
'This module is server-only and was replaced with a stub. ' +
|
|
38
|
+
'To allow this environment: add it to serverEnvironments. ' +
|
|
39
|
+
'To suppress this stub: ensure this import never executes in the "${envName}" environment.'
|
|
40
|
+
);`
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/log.ts
|
|
45
|
+
const LOG_HEADER = `# vite-env warnings — generated by @vite-env/core
|
|
46
|
+
# These warnings will become hard errors in 1.0.0.
|
|
47
|
+
# To enforce immediately: ViteEnv({ onClientAccessOfServerModule: 'error' })
|
|
48
|
+
# To acknowledge and suppress: ViteEnv({ onClientAccessOfServerModule: 'stub' })
|
|
49
|
+
# To allow specific environments: ViteEnv({ serverEnvironments: ['ssr', 'workerd'] })`;
|
|
50
|
+
/**
|
|
51
|
+
* Writes accumulated GuardFail entries to vite-env-warnings.log in the project root.
|
|
52
|
+
* Overwrites on each build — stale entries from previous builds must not persist.
|
|
53
|
+
* Called only in 'warn' mode from buildEnd, after verifying the build succeeded.
|
|
54
|
+
*/
|
|
55
|
+
async function writeWarningsLog(fails, root) {
|
|
56
|
+
const seen = /* @__PURE__ */ new Set();
|
|
57
|
+
const unique = fails.filter((fail) => {
|
|
58
|
+
const key = `${fail.envName}::${fail.importer ?? ""}`;
|
|
59
|
+
if (seen.has(key)) return false;
|
|
60
|
+
seen.add(key);
|
|
61
|
+
return true;
|
|
62
|
+
});
|
|
63
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
64
|
+
const content = `${LOG_HEADER}\n\n${unique.map((fail) => formatGuardLogEntry(fail, timestamp)).join("\n\n")}\n`;
|
|
65
|
+
const filePath = path.join(root, "vite-env-warnings.log");
|
|
66
|
+
try {
|
|
67
|
+
await fs.writeFile(filePath, content, "utf-8");
|
|
68
|
+
} catch (e) {
|
|
69
|
+
throw new Error(`[vite-env] Failed to write vite-env-warnings.log to ${root}. Check file permissions.`, { cause: e });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
9
73
|
//#region src/sources.ts
|
|
10
74
|
/**
|
|
11
75
|
* Merge priority (highest → lowest):
|
|
@@ -69,6 +133,10 @@ function ViteEnv(options = {}) {
|
|
|
69
133
|
let resolvedConfig;
|
|
70
134
|
let envDefinition;
|
|
71
135
|
let lastValidated = {};
|
|
136
|
+
let serverModuleGuardFails = [];
|
|
137
|
+
let didSetExitCode = false;
|
|
138
|
+
const serverEnvs = options.serverEnvironments ?? ["ssr"];
|
|
139
|
+
const guardMode = options.onClientAccessOfServerModule ?? "warn";
|
|
72
140
|
return {
|
|
73
141
|
name: "vite-env",
|
|
74
142
|
enforce: "pre",
|
|
@@ -82,6 +150,11 @@ function ViteEnv(options = {}) {
|
|
|
82
150
|
}
|
|
83
151
|
},
|
|
84
152
|
async buildStart() {
|
|
153
|
+
serverModuleGuardFails = [];
|
|
154
|
+
if (didSetExitCode) {
|
|
155
|
+
process.exitCode = 0;
|
|
156
|
+
didSetExitCode = false;
|
|
157
|
+
}
|
|
85
158
|
const rawEnv = await loadEnvSources(resolvedConfig);
|
|
86
159
|
const result = await validateAndFormat(envDefinition, rawEnv);
|
|
87
160
|
if ("error" in result) throw new Error(`[vite-env] Environment validation failed:\n\n${result.error}`);
|
|
@@ -94,13 +167,35 @@ function ViteEnv(options = {}) {
|
|
|
94
167
|
const count = Object.keys(lastValidated).length;
|
|
95
168
|
resolvedConfig.logger.info(` \x1B[32m✓\x1B[0m \x1B[36m[vite-env]\x1B[0m ${count} variables validated`);
|
|
96
169
|
},
|
|
97
|
-
resolveId(
|
|
98
|
-
if (
|
|
99
|
-
if (
|
|
170
|
+
resolveId(source, importer) {
|
|
171
|
+
if (source === "virtual:env/client") return "\0virtual:env/client";
|
|
172
|
+
if (source === "virtual:env/server") {
|
|
173
|
+
const result = checkServerModuleAccess(this.environment?.name ?? "client", serverEnvs, guardMode, importer);
|
|
174
|
+
if (!result.allowed) serverModuleGuardFails.push(result);
|
|
175
|
+
return "\0virtual:env/server";
|
|
176
|
+
}
|
|
100
177
|
},
|
|
101
178
|
load(id) {
|
|
102
179
|
if (id === "\0virtual:env/client") return buildClientModule(envDefinition, lastValidated);
|
|
103
|
-
if (id === "\0virtual:env/server")
|
|
180
|
+
if (id === "\0virtual:env/server") {
|
|
181
|
+
const envName = this.environment?.name ?? "client";
|
|
182
|
+
const envFails = serverModuleGuardFails.filter((f) => f.envName === envName);
|
|
183
|
+
if (envFails.length > 0) {
|
|
184
|
+
const latest = envFails.at(-1);
|
|
185
|
+
if (latest.mode === "error") throw new Error(formatHardError(latest));
|
|
186
|
+
if (latest.mode === "stub") return buildServerStubModule(envName);
|
|
187
|
+
resolvedConfig.logger.warn(`\n${formatGuardWarning(latest)}`);
|
|
188
|
+
}
|
|
189
|
+
return buildServerModule(envDefinition, lastValidated);
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
async buildEnd(error) {
|
|
193
|
+
if (error) return;
|
|
194
|
+
if (serverModuleGuardFails.length === 0) return;
|
|
195
|
+
if (guardMode !== "warn") return;
|
|
196
|
+
await writeWarningsLog(serverModuleGuardFails, resolvedConfig.root);
|
|
197
|
+
process.exitCode = 1;
|
|
198
|
+
didSetExitCode = true;
|
|
104
199
|
},
|
|
105
200
|
generateBundle(_options, bundle) {
|
|
106
201
|
if (resolvedConfig.build.ssr) return;
|
|
@@ -133,6 +228,7 @@ function ViteEnv(options = {}) {
|
|
|
133
228
|
if (clientMod) server.moduleGraph.invalidateModule(clientMod);
|
|
134
229
|
if (serverMod) server.moduleGraph.invalidateModule(serverMod);
|
|
135
230
|
if (clientMod || serverMod) {
|
|
231
|
+
serverModuleGuardFails = [];
|
|
136
232
|
server.hot.send({ type: "full-reload" });
|
|
137
233
|
resolvedConfig.logger.info(` \x1B[32m✓\x1B[0m \x1B[36m[vite-env]\x1B[0m Env revalidated`);
|
|
138
234
|
}
|
package/dist/plugin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/sources.ts","../src/virtual.ts","../src/plugin.ts"],"sourcesContent":["// @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 } from 'vite'\nimport type { AnyEnvDefinition } from './types'\nimport path from 'node:path'\nimport { loadEnvConfig } from './config'\nimport { generateStandardDts } from './dts'\nimport { formatStandardSchemaError } from './format'\nimport { detectServerLeak } from './leak'\nimport { loadEnvSources } from './sources'\nimport { isStandardEnvDefinition, validateStandardEnv } from './standard'\nimport { buildClientModule, buildServerModule } from './virtual'\n\nexport interface ViteEnvOptions {\n /**\n * Path to env definition file.\n * @default './env.ts' (resolved from project root)\n */\n configFile?: string\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\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 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(id) {\n if (id === 'virtual:env/client')\n return '\\0virtual:env/client'\n if (id === 'virtual:env/server')\n return '\\0virtual:env/server'\n },\n\n load(id) {\n if (id === '\\0virtual:env/client')\n return buildClientModule(envDefinition, lastValidated)\n if (id === '\\0virtual:env/server')\n return buildServerModule(envDefinition, lastValidated)\n },\n\n generateBundle(_options, bundle) {\n if (resolvedConfig.build.ssr)\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 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) // 150ms debounce\n })\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAeA,eAAsB,eACpB,QACiC;AAOjC,QAAO;EACL,GAPc,QACd,OAAO,MACP,OAAO,UAAU,OAAO,MACxB,GACD;EAIC,GAAG,cAAc,QAAQ,IAAI;EAC9B;;AAGH,SAAS,cAAc,KAAgD;AACrE,QAAO,OAAO,YACZ,OAAO,QAAQ,IAAI,CAAC,QACjB,UAAqC,OAAO,MAAM,OAAO,SAC3D,CACF;;;;ACjCH,SAAgB,kBACd,KACA,MACoC;CACpC,MAAM,aAAa,IAAI,IAAI,OAAO,KAAK,IAAI,UAAU,EAAE,CAAC,CAAC;CAEzD,MAAM,aAAa,OAAO,YACxB,OAAO,QAAQ,KAAK,CAAC,QAAQ,CAAC,OAAO,WAAW,IAAI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AAgB,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,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))\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 interface 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(_options, bundle) {\n if (resolvedConfig.build.ssr)\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(\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AI,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"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../dts-BgHTl6hC.cjs");
|
|
3
|
+
let zod = require("zod");
|
|
4
|
+
//#region src/presets/netlify.ts
|
|
5
|
+
const netlify = { server: {
|
|
6
|
+
NETLIFY: zod.z.enum(["true"]),
|
|
7
|
+
BUILD_ID: zod.z.string().min(1),
|
|
8
|
+
CONTEXT: zod.z.enum([
|
|
9
|
+
"production",
|
|
10
|
+
"deploy-preview",
|
|
11
|
+
"branch-deploy",
|
|
12
|
+
"dev"
|
|
13
|
+
]),
|
|
14
|
+
DEPLOY_ID: zod.z.string().min(1),
|
|
15
|
+
DEPLOY_URL: zod.z.url(),
|
|
16
|
+
DEPLOY_PRIME_URL: zod.z.url(),
|
|
17
|
+
URL: zod.z.url(),
|
|
18
|
+
BRANCH: zod.z.string().min(1),
|
|
19
|
+
COMMIT_REF: zod.z.string().min(1),
|
|
20
|
+
PULL_REQUEST: zod.z.enum(["true"]).optional(),
|
|
21
|
+
REVIEW_ID: zod.z.string().optional(),
|
|
22
|
+
REPOSITORY_URL: zod.z.url().optional(),
|
|
23
|
+
INCOMING_HOOK_TITLE: zod.z.string().optional(),
|
|
24
|
+
INCOMING_HOOK_URL: zod.z.url().optional()
|
|
25
|
+
} };
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/presets/railway.ts
|
|
28
|
+
const railway = { server: {
|
|
29
|
+
RAILWAY_ENVIRONMENT_ID: zod.z.string().min(1),
|
|
30
|
+
RAILWAY_ENVIRONMENT_NAME: zod.z.string().min(1),
|
|
31
|
+
RAILWAY_SERVICE_ID: zod.z.string().min(1),
|
|
32
|
+
RAILWAY_SERVICE_NAME: zod.z.string().min(1),
|
|
33
|
+
RAILWAY_PROJECT_ID: zod.z.string().min(1),
|
|
34
|
+
RAILWAY_PROJECT_NAME: zod.z.string().min(1),
|
|
35
|
+
RAILWAY_DEPLOYMENT_ID: zod.z.string().min(1),
|
|
36
|
+
RAILWAY_REPLICA_ID: zod.z.string().optional(),
|
|
37
|
+
RAILWAY_GIT_COMMIT_SHA: zod.z.string().optional(),
|
|
38
|
+
RAILWAY_GIT_BRANCH: zod.z.string().optional(),
|
|
39
|
+
RAILWAY_GIT_REPO_NAME: zod.z.string().optional(),
|
|
40
|
+
RAILWAY_GIT_REPO_OWNER: zod.z.string().optional(),
|
|
41
|
+
RAILWAY_PUBLIC_DOMAIN: zod.z.string().min(1).optional(),
|
|
42
|
+
RAILWAY_PRIVATE_DOMAIN: zod.z.string().min(1).optional(),
|
|
43
|
+
RAILWAY_TCP_PROXY_DOMAIN: zod.z.string().min(1).optional(),
|
|
44
|
+
RAILWAY_TCP_PROXY_PORT: zod.z.coerce.number().int().min(1).max(65535).optional()
|
|
45
|
+
} };
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/presets/vercel.ts
|
|
48
|
+
const vercel = { server: {
|
|
49
|
+
VERCEL: zod.z.enum(["1"]),
|
|
50
|
+
VERCEL_ENV: zod.z.enum([
|
|
51
|
+
"production",
|
|
52
|
+
"preview",
|
|
53
|
+
"development"
|
|
54
|
+
]),
|
|
55
|
+
VERCEL_URL: zod.z.string().min(1),
|
|
56
|
+
VERCEL_BRANCH_URL: zod.z.string().min(1).optional(),
|
|
57
|
+
VERCEL_PROJECT_PRODUCTION_URL: zod.z.string().min(1),
|
|
58
|
+
VERCEL_DEPLOYMENT_ID: zod.z.string().min(1),
|
|
59
|
+
VERCEL_REGION: zod.z.string().optional(),
|
|
60
|
+
VERCEL_GIT_PROVIDER: zod.z.string().optional(),
|
|
61
|
+
VERCEL_GIT_REPO_SLUG: zod.z.string().optional(),
|
|
62
|
+
VERCEL_GIT_REPO_OWNER: zod.z.string().optional(),
|
|
63
|
+
VERCEL_GIT_COMMIT_REF: zod.z.string().optional(),
|
|
64
|
+
VERCEL_GIT_COMMIT_SHA: zod.z.string().optional(),
|
|
65
|
+
VERCEL_GIT_COMMIT_MESSAGE: zod.z.string().optional(),
|
|
66
|
+
VERCEL_GIT_COMMIT_AUTHOR_LOGIN: zod.z.string().optional(),
|
|
67
|
+
VERCEL_GIT_PULL_REQUEST_ID: zod.z.string().optional(),
|
|
68
|
+
VERCEL_SKEW_PROTECTION_ENABLED: zod.z.enum(["1"]).optional()
|
|
69
|
+
} };
|
|
70
|
+
//#endregion
|
|
71
|
+
exports.netlify = netlify;
|
|
72
|
+
exports.railway = railway;
|
|
73
|
+
exports.vercel = vercel;
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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 '../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} 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} 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} satisfies EnvPreset\n"],"mappings":";;;;AAGA,MAAa,UAAU,EACrB,QAAQ;CAEN,SAASA,IAAAA,EAAE,KAAK,CAAC,OAAO,CAAC;CACzB,UAAUA,IAAAA,EAAE,QAAQ,CAAC,IAAI,EAAE;CAC3B,SAASA,IAAAA,EAAE,KAAK;EAAC;EAAc;EAAkB;EAAiB;EAAM,CAAC;CACzE,WAAWA,IAAAA,EAAE,QAAQ,CAAC,IAAI,EAAE;CAE5B,YAAYA,IAAAA,EAAE,KAAK;CACnB,kBAAkBA,IAAAA,EAAE,KAAK;CACzB,KAAKA,IAAAA,EAAE,KAAK;CACZ,QAAQA,IAAAA,EAAE,QAAQ,CAAC,IAAI,EAAE;CACzB,YAAYA,IAAAA,EAAE,QAAQ,CAAC,IAAI,EAAE;CAE7B,cAAcA,IAAAA,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,UAAU;CACzC,WAAWA,IAAAA,EAAE,QAAQ,CAAC,UAAU;CAChC,gBAAgBA,IAAAA,EAAE,KAAK,CAAC,UAAU;CAClC,qBAAqBA,IAAAA,EAAE,QAAQ,CAAC,UAAU;CAC1C,mBAAmBA,IAAAA,EAAE,KAAK,CAAC,UAAU;CACtC,EACF;;;ACpBD,MAAa,UAAU,EACrB,QAAQ;CACN,wBAAwBC,IAAAA,EAAE,QAAQ,CAAC,IAAI,EAAE;CACzC,0BAA0BA,IAAAA,EAAE,QAA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C,eAAeA,IAAAA,EAAE,QAAQ,CAAC,UAAU;CAEpC,qBAAqBA,IAAAA,EAAE,QAAQ,CAAC,UAAU;CAC1C,sBAAsBA,IAAAA,EAAE,QAAQ,CAAC,UAAU;CAC3C,uBAAuBA,IAAAA,EAAE,QAAQ,CAAC,UAAU;CAC5C,uBAAuBA,IAAAA,EAAE,QAAQ,CAAC,UAAU;CAC5C,uBAAuBA,IAAAA,EAAE,QAAQ,CAAC,UAAU;CAC5C,2BAA2BA,IAAAA,EAAE,QAAQ,CAAC,UAAU;CAChD,gCAAgCA,IAAAA,EAAE,QAAQ,CAAC,UAAU;CACrD,4BAA4BA,IAAAA,EAAE,QAAQ,CAAC,UAAU;CACjD,gCAAgCA,IAAAA,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,UAAU;CACzD,EACF"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/presets/netlify.d.ts
|
|
4
|
+
declare const netlify: {
|
|
5
|
+
server: {
|
|
6
|
+
NETLIFY: z.ZodEnum<{
|
|
7
|
+
true: "true";
|
|
8
|
+
}>;
|
|
9
|
+
BUILD_ID: z.ZodString;
|
|
10
|
+
CONTEXT: z.ZodEnum<{
|
|
11
|
+
production: "production";
|
|
12
|
+
"deploy-preview": "deploy-preview";
|
|
13
|
+
"branch-deploy": "branch-deploy";
|
|
14
|
+
dev: "dev";
|
|
15
|
+
}>;
|
|
16
|
+
DEPLOY_ID: z.ZodString;
|
|
17
|
+
DEPLOY_URL: z.ZodURL;
|
|
18
|
+
DEPLOY_PRIME_URL: z.ZodURL;
|
|
19
|
+
URL: z.ZodURL;
|
|
20
|
+
BRANCH: z.ZodString;
|
|
21
|
+
COMMIT_REF: z.ZodString;
|
|
22
|
+
PULL_REQUEST: z.ZodOptional<z.ZodEnum<{
|
|
23
|
+
true: "true";
|
|
24
|
+
}>>;
|
|
25
|
+
REVIEW_ID: z.ZodOptional<z.ZodString>;
|
|
26
|
+
REPOSITORY_URL: z.ZodOptional<z.ZodURL>;
|
|
27
|
+
INCOMING_HOOK_TITLE: z.ZodOptional<z.ZodString>;
|
|
28
|
+
INCOMING_HOOK_URL: z.ZodOptional<z.ZodURL>;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/presets/railway.d.ts
|
|
33
|
+
declare const railway: {
|
|
34
|
+
server: {
|
|
35
|
+
RAILWAY_ENVIRONMENT_ID: z.ZodString;
|
|
36
|
+
RAILWAY_ENVIRONMENT_NAME: z.ZodString;
|
|
37
|
+
RAILWAY_SERVICE_ID: z.ZodString;
|
|
38
|
+
RAILWAY_SERVICE_NAME: z.ZodString;
|
|
39
|
+
RAILWAY_PROJECT_ID: z.ZodString;
|
|
40
|
+
RAILWAY_PROJECT_NAME: z.ZodString;
|
|
41
|
+
RAILWAY_DEPLOYMENT_ID: z.ZodString;
|
|
42
|
+
RAILWAY_REPLICA_ID: z.ZodOptional<z.ZodString>;
|
|
43
|
+
RAILWAY_GIT_COMMIT_SHA: z.ZodOptional<z.ZodString>;
|
|
44
|
+
RAILWAY_GIT_BRANCH: z.ZodOptional<z.ZodString>;
|
|
45
|
+
RAILWAY_GIT_REPO_NAME: z.ZodOptional<z.ZodString>;
|
|
46
|
+
RAILWAY_GIT_REPO_OWNER: z.ZodOptional<z.ZodString>;
|
|
47
|
+
RAILWAY_PUBLIC_DOMAIN: z.ZodOptional<z.ZodString>;
|
|
48
|
+
RAILWAY_PRIVATE_DOMAIN: z.ZodOptional<z.ZodString>;
|
|
49
|
+
RAILWAY_TCP_PROXY_DOMAIN: z.ZodOptional<z.ZodString>;
|
|
50
|
+
RAILWAY_TCP_PROXY_PORT: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/presets/vercel.d.ts
|
|
55
|
+
declare const vercel: {
|
|
56
|
+
server: {
|
|
57
|
+
VERCEL: z.ZodEnum<{
|
|
58
|
+
1: "1";
|
|
59
|
+
}>;
|
|
60
|
+
VERCEL_ENV: z.ZodEnum<{
|
|
61
|
+
production: "production";
|
|
62
|
+
preview: "preview";
|
|
63
|
+
development: "development";
|
|
64
|
+
}>;
|
|
65
|
+
VERCEL_URL: z.ZodString;
|
|
66
|
+
VERCEL_BRANCH_URL: z.ZodOptional<z.ZodString>;
|
|
67
|
+
VERCEL_PROJECT_PRODUCTION_URL: z.ZodString;
|
|
68
|
+
VERCEL_DEPLOYMENT_ID: z.ZodString;
|
|
69
|
+
VERCEL_REGION: z.ZodOptional<z.ZodString>;
|
|
70
|
+
VERCEL_GIT_PROVIDER: z.ZodOptional<z.ZodString>;
|
|
71
|
+
VERCEL_GIT_REPO_SLUG: z.ZodOptional<z.ZodString>;
|
|
72
|
+
VERCEL_GIT_REPO_OWNER: z.ZodOptional<z.ZodString>;
|
|
73
|
+
VERCEL_GIT_COMMIT_REF: z.ZodOptional<z.ZodString>;
|
|
74
|
+
VERCEL_GIT_COMMIT_SHA: z.ZodOptional<z.ZodString>;
|
|
75
|
+
VERCEL_GIT_COMMIT_MESSAGE: z.ZodOptional<z.ZodString>;
|
|
76
|
+
VERCEL_GIT_COMMIT_AUTHOR_LOGIN: z.ZodOptional<z.ZodString>;
|
|
77
|
+
VERCEL_GIT_PULL_REQUEST_ID: z.ZodOptional<z.ZodString>;
|
|
78
|
+
VERCEL_SKEW_PROTECTION_ENABLED: z.ZodOptional<z.ZodEnum<{
|
|
79
|
+
1: "1";
|
|
80
|
+
}>>;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
//#endregion
|
|
84
|
+
export { netlify, railway, vercel };
|
|
85
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/presets/netlify.d.ts
|
|
4
|
+
declare const netlify: {
|
|
5
|
+
server: {
|
|
6
|
+
NETLIFY: z.ZodEnum<{
|
|
7
|
+
true: "true";
|
|
8
|
+
}>;
|
|
9
|
+
BUILD_ID: z.ZodString;
|
|
10
|
+
CONTEXT: z.ZodEnum<{
|
|
11
|
+
production: "production";
|
|
12
|
+
"deploy-preview": "deploy-preview";
|
|
13
|
+
"branch-deploy": "branch-deploy";
|
|
14
|
+
dev: "dev";
|
|
15
|
+
}>;
|
|
16
|
+
DEPLOY_ID: z.ZodString;
|
|
17
|
+
DEPLOY_URL: z.ZodURL;
|
|
18
|
+
DEPLOY_PRIME_URL: z.ZodURL;
|
|
19
|
+
URL: z.ZodURL;
|
|
20
|
+
BRANCH: z.ZodString;
|
|
21
|
+
COMMIT_REF: z.ZodString;
|
|
22
|
+
PULL_REQUEST: z.ZodOptional<z.ZodEnum<{
|
|
23
|
+
true: "true";
|
|
24
|
+
}>>;
|
|
25
|
+
REVIEW_ID: z.ZodOptional<z.ZodString>;
|
|
26
|
+
REPOSITORY_URL: z.ZodOptional<z.ZodURL>;
|
|
27
|
+
INCOMING_HOOK_TITLE: z.ZodOptional<z.ZodString>;
|
|
28
|
+
INCOMING_HOOK_URL: z.ZodOptional<z.ZodURL>;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/presets/railway.d.ts
|
|
33
|
+
declare const railway: {
|
|
34
|
+
server: {
|
|
35
|
+
RAILWAY_ENVIRONMENT_ID: z.ZodString;
|
|
36
|
+
RAILWAY_ENVIRONMENT_NAME: z.ZodString;
|
|
37
|
+
RAILWAY_SERVICE_ID: z.ZodString;
|
|
38
|
+
RAILWAY_SERVICE_NAME: z.ZodString;
|
|
39
|
+
RAILWAY_PROJECT_ID: z.ZodString;
|
|
40
|
+
RAILWAY_PROJECT_NAME: z.ZodString;
|
|
41
|
+
RAILWAY_DEPLOYMENT_ID: z.ZodString;
|
|
42
|
+
RAILWAY_REPLICA_ID: z.ZodOptional<z.ZodString>;
|
|
43
|
+
RAILWAY_GIT_COMMIT_SHA: z.ZodOptional<z.ZodString>;
|
|
44
|
+
RAILWAY_GIT_BRANCH: z.ZodOptional<z.ZodString>;
|
|
45
|
+
RAILWAY_GIT_REPO_NAME: z.ZodOptional<z.ZodString>;
|
|
46
|
+
RAILWAY_GIT_REPO_OWNER: z.ZodOptional<z.ZodString>;
|
|
47
|
+
RAILWAY_PUBLIC_DOMAIN: z.ZodOptional<z.ZodString>;
|
|
48
|
+
RAILWAY_PRIVATE_DOMAIN: z.ZodOptional<z.ZodString>;
|
|
49
|
+
RAILWAY_TCP_PROXY_DOMAIN: z.ZodOptional<z.ZodString>;
|
|
50
|
+
RAILWAY_TCP_PROXY_PORT: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/presets/vercel.d.ts
|
|
55
|
+
declare const vercel: {
|
|
56
|
+
server: {
|
|
57
|
+
VERCEL: z.ZodEnum<{
|
|
58
|
+
1: "1";
|
|
59
|
+
}>;
|
|
60
|
+
VERCEL_ENV: z.ZodEnum<{
|
|
61
|
+
production: "production";
|
|
62
|
+
preview: "preview";
|
|
63
|
+
development: "development";
|
|
64
|
+
}>;
|
|
65
|
+
VERCEL_URL: z.ZodString;
|
|
66
|
+
VERCEL_BRANCH_URL: z.ZodOptional<z.ZodString>;
|
|
67
|
+
VERCEL_PROJECT_PRODUCTION_URL: z.ZodString;
|
|
68
|
+
VERCEL_DEPLOYMENT_ID: z.ZodString;
|
|
69
|
+
VERCEL_REGION: z.ZodOptional<z.ZodString>;
|
|
70
|
+
VERCEL_GIT_PROVIDER: z.ZodOptional<z.ZodString>;
|
|
71
|
+
VERCEL_GIT_REPO_SLUG: z.ZodOptional<z.ZodString>;
|
|
72
|
+
VERCEL_GIT_REPO_OWNER: z.ZodOptional<z.ZodString>;
|
|
73
|
+
VERCEL_GIT_COMMIT_REF: z.ZodOptional<z.ZodString>;
|
|
74
|
+
VERCEL_GIT_COMMIT_SHA: z.ZodOptional<z.ZodString>;
|
|
75
|
+
VERCEL_GIT_COMMIT_MESSAGE: z.ZodOptional<z.ZodString>;
|
|
76
|
+
VERCEL_GIT_COMMIT_AUTHOR_LOGIN: z.ZodOptional<z.ZodString>;
|
|
77
|
+
VERCEL_GIT_PULL_REQUEST_ID: z.ZodOptional<z.ZodString>;
|
|
78
|
+
VERCEL_SKEW_PROTECTION_ENABLED: z.ZodOptional<z.ZodEnum<{
|
|
79
|
+
1: "1";
|
|
80
|
+
}>>;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
//#endregion
|
|
84
|
+
export { netlify, railway, vercel };
|
|
85
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/presets/netlify.ts
|
|
3
|
+
const netlify = { server: {
|
|
4
|
+
NETLIFY: z.enum(["true"]),
|
|
5
|
+
BUILD_ID: z.string().min(1),
|
|
6
|
+
CONTEXT: z.enum([
|
|
7
|
+
"production",
|
|
8
|
+
"deploy-preview",
|
|
9
|
+
"branch-deploy",
|
|
10
|
+
"dev"
|
|
11
|
+
]),
|
|
12
|
+
DEPLOY_ID: z.string().min(1),
|
|
13
|
+
DEPLOY_URL: z.url(),
|
|
14
|
+
DEPLOY_PRIME_URL: z.url(),
|
|
15
|
+
URL: z.url(),
|
|
16
|
+
BRANCH: z.string().min(1),
|
|
17
|
+
COMMIT_REF: z.string().min(1),
|
|
18
|
+
PULL_REQUEST: z.enum(["true"]).optional(),
|
|
19
|
+
REVIEW_ID: z.string().optional(),
|
|
20
|
+
REPOSITORY_URL: z.url().optional(),
|
|
21
|
+
INCOMING_HOOK_TITLE: z.string().optional(),
|
|
22
|
+
INCOMING_HOOK_URL: z.url().optional()
|
|
23
|
+
} };
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/presets/railway.ts
|
|
26
|
+
const railway = { server: {
|
|
27
|
+
RAILWAY_ENVIRONMENT_ID: z.string().min(1),
|
|
28
|
+
RAILWAY_ENVIRONMENT_NAME: z.string().min(1),
|
|
29
|
+
RAILWAY_SERVICE_ID: z.string().min(1),
|
|
30
|
+
RAILWAY_SERVICE_NAME: z.string().min(1),
|
|
31
|
+
RAILWAY_PROJECT_ID: z.string().min(1),
|
|
32
|
+
RAILWAY_PROJECT_NAME: z.string().min(1),
|
|
33
|
+
RAILWAY_DEPLOYMENT_ID: z.string().min(1),
|
|
34
|
+
RAILWAY_REPLICA_ID: z.string().optional(),
|
|
35
|
+
RAILWAY_GIT_COMMIT_SHA: z.string().optional(),
|
|
36
|
+
RAILWAY_GIT_BRANCH: z.string().optional(),
|
|
37
|
+
RAILWAY_GIT_REPO_NAME: z.string().optional(),
|
|
38
|
+
RAILWAY_GIT_REPO_OWNER: z.string().optional(),
|
|
39
|
+
RAILWAY_PUBLIC_DOMAIN: z.string().min(1).optional(),
|
|
40
|
+
RAILWAY_PRIVATE_DOMAIN: z.string().min(1).optional(),
|
|
41
|
+
RAILWAY_TCP_PROXY_DOMAIN: z.string().min(1).optional(),
|
|
42
|
+
RAILWAY_TCP_PROXY_PORT: z.coerce.number().int().min(1).max(65535).optional()
|
|
43
|
+
} };
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/presets/vercel.ts
|
|
46
|
+
const vercel = { server: {
|
|
47
|
+
VERCEL: z.enum(["1"]),
|
|
48
|
+
VERCEL_ENV: z.enum([
|
|
49
|
+
"production",
|
|
50
|
+
"preview",
|
|
51
|
+
"development"
|
|
52
|
+
]),
|
|
53
|
+
VERCEL_URL: z.string().min(1),
|
|
54
|
+
VERCEL_BRANCH_URL: z.string().min(1).optional(),
|
|
55
|
+
VERCEL_PROJECT_PRODUCTION_URL: z.string().min(1),
|
|
56
|
+
VERCEL_DEPLOYMENT_ID: z.string().min(1),
|
|
57
|
+
VERCEL_REGION: z.string().optional(),
|
|
58
|
+
VERCEL_GIT_PROVIDER: z.string().optional(),
|
|
59
|
+
VERCEL_GIT_REPO_SLUG: z.string().optional(),
|
|
60
|
+
VERCEL_GIT_REPO_OWNER: z.string().optional(),
|
|
61
|
+
VERCEL_GIT_COMMIT_REF: z.string().optional(),
|
|
62
|
+
VERCEL_GIT_COMMIT_SHA: z.string().optional(),
|
|
63
|
+
VERCEL_GIT_COMMIT_MESSAGE: z.string().optional(),
|
|
64
|
+
VERCEL_GIT_COMMIT_AUTHOR_LOGIN: z.string().optional(),
|
|
65
|
+
VERCEL_GIT_PULL_REQUEST_ID: z.string().optional(),
|
|
66
|
+
VERCEL_SKEW_PROTECTION_ENABLED: z.enum(["1"]).optional()
|
|
67
|
+
} };
|
|
68
|
+
//#endregion
|
|
69
|
+
export { netlify, railway, vercel };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"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} 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} 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_CO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