@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
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@ The `env.ts` layer for Vite — define once, validate everywhere, import with ty
|
|
|
7
7
|
- Typed virtual modules (`virtual:env/client`, `virtual:env/server`)
|
|
8
8
|
- Server/client split with build-time leak detection
|
|
9
9
|
- Runtime access protection — warns or errors when `virtual:env/server` is imported from a client environment
|
|
10
|
+
- Standalone runtime loader — `loadEnv(config)` from `@vite-env/core/load` for scripts outside Vite
|
|
10
11
|
- Auto-coercion via Zod v4 (`z.stringbool()`, `z.coerce.number()`)
|
|
11
12
|
- Standard Schema support — use Valibot, ArkType, or any compliant validator
|
|
12
13
|
- Platform presets — pre-built schemas for Vercel, Railway, and Netlify
|
|
@@ -16,7 +17,7 @@ The `env.ts` layer for Vite — define once, validate everywhere, import with ty
|
|
|
16
17
|
## Install
|
|
17
18
|
|
|
18
19
|
```bash
|
|
19
|
-
|
|
20
|
+
npm install @vite-env/core zod
|
|
20
21
|
```
|
|
21
22
|
|
|
22
23
|
## Usage
|
|
@@ -24,8 +25,8 @@ pnpm add @vite-env/core zod
|
|
|
24
25
|
**1. Define your schema** — `env.ts`
|
|
25
26
|
|
|
26
27
|
```ts
|
|
27
|
-
import { defineEnv } from
|
|
28
|
-
import { z } from
|
|
28
|
+
import { defineEnv } from "@vite-env/core";
|
|
29
|
+
import { z } from "zod";
|
|
29
30
|
|
|
30
31
|
export default defineEnv({
|
|
31
32
|
server: {
|
|
@@ -35,50 +36,65 @@ export default defineEnv({
|
|
|
35
36
|
client: {
|
|
36
37
|
VITE_API_URL: z.url(),
|
|
37
38
|
VITE_DARK_MODE: z.stringbool().default(false),
|
|
38
|
-
VITE_NODE_ENV: z
|
|
39
|
-
.enum(['development', 'test', 'production'])
|
|
40
|
-
.default('development'),
|
|
39
|
+
VITE_NODE_ENV: z.enum(["development", "test", "production"]).default("development"),
|
|
41
40
|
},
|
|
42
|
-
})
|
|
41
|
+
});
|
|
43
42
|
```
|
|
44
43
|
|
|
45
44
|
**2. Add the plugin** — `vite.config.ts`
|
|
46
45
|
|
|
47
46
|
```ts
|
|
48
|
-
import ViteEnv from
|
|
49
|
-
import { defineConfig } from
|
|
47
|
+
import ViteEnv from "@vite-env/core/plugin";
|
|
48
|
+
import { defineConfig } from "vite";
|
|
50
49
|
|
|
51
50
|
export default defineConfig({
|
|
52
51
|
plugins: [ViteEnv()],
|
|
53
|
-
})
|
|
52
|
+
});
|
|
54
53
|
```
|
|
55
54
|
|
|
56
55
|
**3. Import typed env**
|
|
57
56
|
|
|
58
57
|
```ts
|
|
59
|
-
import { env } from
|
|
58
|
+
import { env } from "virtual:env/client";
|
|
60
59
|
|
|
61
|
-
env.VITE_API_URL // string
|
|
62
|
-
env.VITE_DARK_MODE // boolean
|
|
63
|
-
env.VITE_NODE_ENV // 'development' | 'test' | 'production'
|
|
60
|
+
env.VITE_API_URL; // string
|
|
61
|
+
env.VITE_DARK_MODE; // boolean
|
|
62
|
+
env.VITE_NODE_ENV; // 'development' | 'test' | 'production'
|
|
64
63
|
```
|
|
65
64
|
|
|
66
65
|
### Platform presets
|
|
67
66
|
|
|
68
67
|
```ts
|
|
69
|
-
import { defineEnv } from
|
|
70
|
-
import { vercel } from
|
|
71
|
-
import { z } from
|
|
68
|
+
import { defineEnv } from "@vite-env/core";
|
|
69
|
+
import { vercel } from "@vite-env/core/presets";
|
|
70
|
+
import { z } from "zod";
|
|
72
71
|
|
|
73
72
|
export default defineEnv({
|
|
74
73
|
presets: [vercel],
|
|
75
74
|
server: { DATABASE_URL: z.url() },
|
|
76
75
|
client: { VITE_API_URL: z.url() },
|
|
77
|
-
})
|
|
76
|
+
});
|
|
78
77
|
```
|
|
79
78
|
|
|
80
79
|
Available presets: `vercel`, `railway`, `netlify`.
|
|
81
80
|
|
|
81
|
+
### Standalone runtime loader
|
|
82
|
+
|
|
83
|
+
Use the same validated env in Node/Bun scripts outside of Vite:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
// scripts/seed.ts
|
|
87
|
+
import { loadEnv } from "@vite-env/core/load";
|
|
88
|
+
import config from "../env";
|
|
89
|
+
|
|
90
|
+
const { server, client } = await loadEnv(config);
|
|
91
|
+
|
|
92
|
+
server.DATABASE_URL; // string
|
|
93
|
+
client.VITE_API_URL; // string
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Returns `{ server, client, all }`. Accepts an optional second argument `{ mode?, envDir? }`.
|
|
97
|
+
|
|
82
98
|
See the [full documentation](https://pyyupsk.github.io/vite-env/) for server/client split details, CLI tools, and more.
|
|
83
99
|
|
|
84
100
|
## License
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
Object.defineProperty(exports, "__toESM", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function() {
|
|
26
|
+
return __toESM;
|
|
27
|
+
}
|
|
28
|
+
});
|
package/dist/config.cjs
CHANGED
package/dist/config.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.cjs","names":[],"sources":["../src/config.ts"],"sourcesContent":["import type { EnvDefinition } from
|
|
1
|
+
{"version":3,"file":"config.cjs","names":[],"sources":["../src/config.ts"],"sourcesContent":["import type { EnvDefinition } from \"./types\";\nimport { createJiti } from \"jiti\";\n\nexport async function loadEnvConfig(configPath: string): Promise<EnvDefinition> {\n const jiti = createJiti(configPath);\n const mod = await jiti.import<Record<string, unknown>>(configPath);\n const def: unknown = mod.default ?? mod;\n\n if (!def || typeof def !== \"object\") {\n throw new Error(\n `[vite-env] env config at ${configPath} must export an object (got ${typeof def}).\\n` +\n ` Use: export default defineEnv({ ... })`,\n );\n }\n\n return def as EnvDefinition;\n}\n"],"mappings":";;;;AAGA,eAAsB,cAAc,YAA4C;CAE9E,MAAM,MAAM,OAAA,GAAA,KAAA,YADY,WACF,CAAC,OAAgC,WAAW;CAClE,MAAM,MAAe,IAAI,WAAW;AAEpC,KAAI,CAAC,OAAO,OAAO,QAAQ,SACzB,OAAM,IAAI,MACR,4BAA4B,WAAW,8BAA8B,OAAO,IAAI,8CAEjF;AAGH,QAAO"}
|
package/dist/config.d.cts
CHANGED
package/dist/config.d.mts
CHANGED
package/dist/config.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.mjs","names":[],"sources":["../src/config.ts"],"sourcesContent":["import type { EnvDefinition } from
|
|
1
|
+
{"version":3,"file":"config.mjs","names":[],"sources":["../src/config.ts"],"sourcesContent":["import type { EnvDefinition } from \"./types\";\nimport { createJiti } from \"jiti\";\n\nexport async function loadEnvConfig(configPath: string): Promise<EnvDefinition> {\n const jiti = createJiti(configPath);\n const mod = await jiti.import<Record<string, unknown>>(configPath);\n const def: unknown = mod.default ?? mod;\n\n if (!def || typeof def !== \"object\") {\n throw new Error(\n `[vite-env] env config at ${configPath} must export an object (got ${typeof def}).\\n` +\n ` Use: export default defineEnv({ ... })`,\n );\n }\n\n return def as EnvDefinition;\n}\n"],"mappings":";;AAGA,eAAsB,cAAc,YAA4C;CAE9E,MAAM,MAAM,MADC,WAAW,WACF,CAAC,OAAgC,WAAW;CAClE,MAAM,MAAe,IAAI,WAAW;AAEpC,KAAI,CAAC,OAAO,OAAO,QAAQ,SACzB,OAAM,IAAI,MACR,4BAA4B,WAAW,8BAA8B,OAAO,IAAI,8CAEjF;AAGH,QAAO"}
|
package/dist/dts.cjs
CHANGED
|
@@ -1,4 +1,103 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const require_chunk = require("./chunk-CKQMccvm.cjs");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
node_path = require_chunk.__toESM(node_path, 1);
|
|
5
|
+
let node_fs_promises = require("node:fs/promises");
|
|
6
|
+
node_fs_promises = require_chunk.__toESM(node_fs_promises, 1);
|
|
7
|
+
//#region src/dts.ts
|
|
8
|
+
/**
|
|
9
|
+
* Writes vite-env.d.ts for Zod definitions.
|
|
10
|
+
* Uses instanceof checks to infer TypeScript types from Zod schemas.
|
|
11
|
+
* Zod is loaded dynamically so this module can be imported without zod installed.
|
|
12
|
+
*/
|
|
13
|
+
async function generateDts(def, root) {
|
|
14
|
+
const { z } = await import("zod");
|
|
15
|
+
const gatedKeys = gatedPresetKeys(def);
|
|
16
|
+
await writeDts(root, zodShapeToTsFields(z, { ...def.client }, gatedKeys), zodShapeToTsFields(z, {
|
|
17
|
+
...def.server,
|
|
18
|
+
...def.client
|
|
19
|
+
}, gatedKeys));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Detection-gated preset keys (not user-overridden) validate as optional
|
|
23
|
+
* off-platform — typing them required would lie during local dev.
|
|
24
|
+
*/
|
|
25
|
+
function gatedPresetKeys(def) {
|
|
26
|
+
const keys = /* @__PURE__ */ new Set();
|
|
27
|
+
for (const preset of def.presets ?? []) {
|
|
28
|
+
if (!preset.detect) continue;
|
|
29
|
+
for (const side of ["server", "client"]) for (const [key, schema] of Object.entries(preset[side] ?? {})) if (def[side]?.[key] === schema) keys.add(key);
|
|
30
|
+
}
|
|
31
|
+
return keys;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Writes vite-env.d.ts for Standard Schema definitions.
|
|
35
|
+
* All fields are typed as `string` — Standard Schema has no runtime type introspection.
|
|
36
|
+
*/
|
|
37
|
+
async function generateStandardDts(def, root) {
|
|
38
|
+
const clientKeys = Object.keys(def.client ?? {});
|
|
39
|
+
const serverKeys = [...Object.keys(def.server ?? {}), ...clientKeys];
|
|
40
|
+
await writeDts(root, keysToTsFields(clientKeys), keysToTsFields(serverKeys), "(Standard Schema)");
|
|
41
|
+
}
|
|
42
|
+
function buildHeader(tag = "") {
|
|
43
|
+
const lines = [
|
|
44
|
+
"/* oxlint-disable */",
|
|
45
|
+
"/* eslint-disable */",
|
|
46
|
+
"// @ts-nocheck",
|
|
47
|
+
"// biome-ignore-all lint: auto-generated",
|
|
48
|
+
tag ? `// Auto-generated by @vite-env/core ${tag}` : "// Auto-generated by @vite-env/core",
|
|
49
|
+
"// Do not edit manually — re-generated on every dev server start and build"
|
|
50
|
+
];
|
|
51
|
+
if (tag) lines.push("// Tip: for richer types, use defineEnv() with Zod instead of defineStandardEnv()");
|
|
52
|
+
return lines.join("\n");
|
|
53
|
+
}
|
|
54
|
+
async function writeDts(root, clientFields, serverFields, tag = "") {
|
|
55
|
+
const dts = `${buildHeader(tag)}
|
|
56
|
+
|
|
57
|
+
declare module 'virtual:env/client' {
|
|
58
|
+
const env: {
|
|
59
|
+
${clientFields}
|
|
60
|
+
}
|
|
61
|
+
export { env }
|
|
62
|
+
export default env
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
declare module 'virtual:env/server' {
|
|
66
|
+
const env: {
|
|
67
|
+
${serverFields}
|
|
68
|
+
}
|
|
69
|
+
export { env }
|
|
70
|
+
export default env
|
|
71
|
+
}
|
|
72
|
+
`;
|
|
73
|
+
const filePath = node_path.default.join(root, "vite-env.d.ts");
|
|
74
|
+
try {
|
|
75
|
+
await node_fs_promises.default.writeFile(filePath, dts, "utf-8");
|
|
76
|
+
} catch (e) {
|
|
77
|
+
throw new Error(`[vite-env] Failed to write vite-env.d.ts to ${root}. Check file permissions.`, { cause: e });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function keysToTsFields(keys) {
|
|
81
|
+
return keys.map((key) => ` readonly ${key}: string`).join("\n");
|
|
82
|
+
}
|
|
83
|
+
function zodShapeToTsFields(z, shape, gatedKeys) {
|
|
84
|
+
return Object.entries(shape).map(([key, schema]) => {
|
|
85
|
+
const tsType = zodToTs(z, schema);
|
|
86
|
+
return ` readonly ${key}${schema instanceof z.ZodOptional || gatedKeys.has(key) ? "?" : ""}: ${tsType}`;
|
|
87
|
+
}).join("\n");
|
|
88
|
+
}
|
|
89
|
+
function zodToTs(z, schema) {
|
|
90
|
+
if (schema instanceof z.ZodOptional) return zodToTs(z, schema.unwrap());
|
|
91
|
+
if (schema instanceof z.ZodDefault) return zodToTs(z, schema.def.innerType);
|
|
92
|
+
if (schema instanceof z.ZodString) return "string";
|
|
93
|
+
if (schema instanceof z.ZodNumber) return "number";
|
|
94
|
+
if (schema instanceof z.ZodBoolean) return "boolean";
|
|
95
|
+
if (schema instanceof z.ZodEnum) return schema.options.map((o) => `'${o}'`).join(" | ");
|
|
96
|
+
if (schema instanceof z.ZodPipe) return zodToTs(z, schema.def.out);
|
|
97
|
+
return "string";
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
exports.generateDts = generateDts;
|
|
101
|
+
exports.generateStandardDts = generateStandardDts;
|
|
102
|
+
|
|
103
|
+
//# sourceMappingURL=dts.cjs.map
|
package/dist/dts.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dts.cjs","names":["path","fs"],"sources":["../src/dts.ts"],"sourcesContent":["// @env node\nimport type { EnvDefinition, StandardEnvDefinition } from \"./types\";\nimport type { z as ZodNs } from \"zod\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\n/**\n * Writes vite-env.d.ts for Zod definitions.\n * Uses instanceof checks to infer TypeScript types from Zod schemas.\n * Zod is loaded dynamically so this module can be imported without zod installed.\n */\nexport async function generateDts(def: EnvDefinition, root: string): Promise<void> {\n const { z } = await import(\"zod\");\n\n const gatedKeys = gatedPresetKeys(def);\n const clientFields = zodShapeToTsFields(z, { ...def.client }, gatedKeys);\n const serverFields = zodShapeToTsFields(z, { ...def.server, ...def.client }, gatedKeys);\n\n await writeDts(root, clientFields, serverFields);\n}\n\n/**\n * Detection-gated preset keys (not user-overridden) validate as optional\n * off-platform — typing them required would lie during local dev.\n */\nfunction gatedPresetKeys(def: EnvDefinition): Set<string> {\n const keys = new Set<string>();\n for (const preset of def.presets ?? []) {\n if (!preset.detect) continue;\n for (const side of [\"server\", \"client\"] as const) {\n for (const [key, schema] of Object.entries(preset[side] ?? {})) {\n if (def[side]?.[key] === schema) keys.add(key);\n }\n }\n }\n return keys;\n}\n\n/**\n * Writes vite-env.d.ts for Standard Schema definitions.\n * All fields are typed as `string` — Standard Schema has no runtime type introspection.\n */\nexport async function generateStandardDts(def: StandardEnvDefinition, root: string): Promise<void> {\n const clientKeys = Object.keys(def.client ?? {});\n const serverKeys = [...Object.keys(def.server ?? {}), ...clientKeys];\n\n const clientFields = keysToTsFields(clientKeys);\n const serverFields = keysToTsFields(serverKeys);\n\n await writeDts(root, clientFields, serverFields, \"(Standard Schema)\");\n}\n\nfunction buildHeader(tag = \"\"): string {\n const lines = [\n \"/* oxlint-disable */\",\n \"/* eslint-disable */\",\n \"// @ts-nocheck\",\n \"// biome-ignore-all lint: auto-generated\",\n tag ? `// Auto-generated by @vite-env/core ${tag}` : \"// Auto-generated by @vite-env/core\",\n \"// Do not edit manually — re-generated on every dev server start and build\",\n ];\n if (tag) {\n lines.push(\"// Tip: for richer types, use defineEnv() with Zod instead of defineStandardEnv()\");\n }\n return lines.join(\"\\n\");\n}\n\nasync function writeDts(\n root: string,\n clientFields: string,\n serverFields: string,\n tag = \"\",\n): Promise<void> {\n const header = buildHeader(tag);\n\n const dts = `${header}\n\ndeclare module 'virtual:env/client' {\n const env: {\n${clientFields}\n }\n export { env }\n export default env\n}\n\ndeclare module 'virtual:env/server' {\n const env: {\n${serverFields}\n }\n export { env }\n export default env\n}\n`;\n\n const filePath = path.join(root, \"vite-env.d.ts\");\n try {\n await fs.writeFile(filePath, dts, \"utf-8\");\n } catch (e) {\n throw new Error(\n `[vite-env] Failed to write vite-env.d.ts to ${root}. Check file permissions.`,\n { cause: e },\n );\n }\n}\n\nfunction keysToTsFields(keys: string[]): string {\n return keys.map((key) => ` readonly ${key}: string`).join(\"\\n\");\n}\n\nfunction zodShapeToTsFields(\n z: typeof ZodNs,\n shape: Record<string, unknown>,\n gatedKeys: Set<string>,\n): string {\n return Object.entries(shape)\n .map(([key, schema]) => {\n const tsType = zodToTs(z, schema);\n const optional = schema instanceof z.ZodOptional || gatedKeys.has(key);\n return ` readonly ${key}${optional ? \"?\" : \"\"}: ${tsType}`;\n })\n .join(\"\\n\");\n}\n\nfunction zodToTs(z: typeof ZodNs, schema: unknown): string {\n if (schema instanceof z.ZodOptional) return zodToTs(z, schema.unwrap());\n if (schema instanceof z.ZodDefault) return zodToTs(z, schema.def.innerType);\n if (schema instanceof z.ZodString) return \"string\";\n if (schema instanceof z.ZodNumber) return \"number\";\n if (schema instanceof z.ZodBoolean) return \"boolean\";\n if (schema instanceof z.ZodEnum)\n return (schema.options as string[]).map((o) => `'${o}'`).join(\" | \");\n if (schema instanceof z.ZodPipe) return zodToTs(z, schema.def.out);\n return \"string\";\n}\n"],"mappings":";;;;;;;;;;;;AAWA,eAAsB,YAAY,KAAoB,MAA6B;CACjF,MAAM,EAAE,MAAM,MAAM,OAAO;CAE3B,MAAM,YAAY,gBAAgB,IAAI;AAItC,OAAM,SAAS,MAHM,mBAAmB,GAAG,EAAE,GAAG,IAAI,QAAQ,EAAE,UAG7B,EAFZ,mBAAmB,GAAG;EAAE,GAAG,IAAI;EAAQ,GAAG,IAAI;EAAQ,EAAE,UAE9B,CAAC;;;;;;AAOlD,SAAS,gBAAgB,KAAiC;CACxD,MAAM,uBAAO,IAAI,KAAa;AAC9B,MAAK,MAAM,UAAU,IAAI,WAAW,EAAE,EAAE;AACtC,MAAI,CAAC,OAAO,OAAQ;AACpB,OAAK,MAAM,QAAQ,CAAC,UAAU,SAAS,CACrC,MAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,OAAO,SAAS,EAAE,CAAC,CAC5D,KAAI,IAAI,QAAQ,SAAS,OAAQ,MAAK,IAAI,IAAI;;AAIpD,QAAO;;;;;;AAOT,eAAsB,oBAAoB,KAA4B,MAA6B;CACjG,MAAM,aAAa,OAAO,KAAK,IAAI,UAAU,EAAE,CAAC;CAChD,MAAM,aAAa,CAAC,GAAG,OAAO,KAAK,IAAI,UAAU,EAAE,CAAC,EAAE,GAAG,WAAW;AAKpE,OAAM,SAAS,MAHM,eAAe,WAGH,EAFZ,eAAe,WAEW,EAAE,oBAAoB;;AAGvE,SAAS,YAAY,MAAM,IAAY;CACrC,MAAM,QAAQ;EACZ;EACA;EACA;EACA;EACA,MAAM,uCAAuC,QAAQ;EACrD;EACD;AACD,KAAI,IACF,OAAM,KAAK,oFAAoF;AAEjG,QAAO,MAAM,KAAK,KAAK;;AAGzB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@ import fs from "node:fs/promises";
|
|
|
8
8
|
*/
|
|
9
9
|
async function generateDts(def, root) {
|
|
10
10
|
const { z } = await import("zod");
|
|
11
|
-
|
|
11
|
+
const gatedKeys = gatedPresetKeys(def);
|
|
12
|
+
await writeDts(root, zodShapeToTsFields(z, { ...def.client }, gatedKeys), zodShapeToTsFields(z, {
|
|
12
13
|
...def.server,
|
|
13
14
|
...def.client
|
|
14
|
-
}));
|
|
15
|
+
}, gatedKeys));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Detection-gated preset keys (not user-overridden) validate as optional
|
|
19
|
+
* off-platform — typing them required would lie during local dev.
|
|
20
|
+
*/
|
|
21
|
+
function gatedPresetKeys(def) {
|
|
22
|
+
const keys = /* @__PURE__ */ new Set();
|
|
23
|
+
for (const preset of def.presets ?? []) {
|
|
24
|
+
if (!preset.detect) continue;
|
|
25
|
+
for (const side of ["server", "client"]) for (const [key, schema] of Object.entries(preset[side] ?? {})) if (def[side]?.[key] === schema) keys.add(key);
|
|
26
|
+
}
|
|
27
|
+
return keys;
|
|
15
28
|
}
|
|
16
29
|
/**
|
|
17
30
|
* Writes vite-env.d.ts for Standard Schema definitions.
|
|
@@ -28,7 +41,7 @@ function buildHeader(tag = "") {
|
|
|
28
41
|
"/* eslint-disable */",
|
|
29
42
|
"// @ts-nocheck",
|
|
30
43
|
"// biome-ignore-all lint: auto-generated",
|
|
31
|
-
`// Auto-generated by @vite-env/core
|
|
44
|
+
tag ? `// Auto-generated by @vite-env/core ${tag}` : "// Auto-generated by @vite-env/core",
|
|
32
45
|
"// Do not edit manually — re-generated on every dev server start and build"
|
|
33
46
|
];
|
|
34
47
|
if (tag) lines.push("// Tip: for richer types, use defineEnv() with Zod instead of defineStandardEnv()");
|
|
@@ -63,10 +76,10 @@ ${serverFields}
|
|
|
63
76
|
function keysToTsFields(keys) {
|
|
64
77
|
return keys.map((key) => ` readonly ${key}: string`).join("\n");
|
|
65
78
|
}
|
|
66
|
-
function zodShapeToTsFields(z, shape) {
|
|
79
|
+
function zodShapeToTsFields(z, shape, gatedKeys) {
|
|
67
80
|
return Object.entries(shape).map(([key, schema]) => {
|
|
68
81
|
const tsType = zodToTs(z, schema);
|
|
69
|
-
return ` readonly ${key}${schema instanceof z.ZodOptional ? "?" : ""}: ${tsType}`;
|
|
82
|
+
return ` readonly ${key}${schema instanceof z.ZodOptional || gatedKeys.has(key) ? "?" : ""}: ${tsType}`;
|
|
70
83
|
}).join("\n");
|
|
71
84
|
}
|
|
72
85
|
function zodToTs(z, schema) {
|
package/dist/dts.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dts.mjs","names":[],"sources":["../src/dts.ts"],"sourcesContent":["// @env node\nimport type { EnvDefinition, StandardEnvDefinition } from
|
|
1
|
+
{"version":3,"file":"dts.mjs","names":[],"sources":["../src/dts.ts"],"sourcesContent":["// @env node\nimport type { EnvDefinition, StandardEnvDefinition } from \"./types\";\nimport type { z as ZodNs } from \"zod\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\n/**\n * Writes vite-env.d.ts for Zod definitions.\n * Uses instanceof checks to infer TypeScript types from Zod schemas.\n * Zod is loaded dynamically so this module can be imported without zod installed.\n */\nexport async function generateDts(def: EnvDefinition, root: string): Promise<void> {\n const { z } = await import(\"zod\");\n\n const gatedKeys = gatedPresetKeys(def);\n const clientFields = zodShapeToTsFields(z, { ...def.client }, gatedKeys);\n const serverFields = zodShapeToTsFields(z, { ...def.server, ...def.client }, gatedKeys);\n\n await writeDts(root, clientFields, serverFields);\n}\n\n/**\n * Detection-gated preset keys (not user-overridden) validate as optional\n * off-platform — typing them required would lie during local dev.\n */\nfunction gatedPresetKeys(def: EnvDefinition): Set<string> {\n const keys = new Set<string>();\n for (const preset of def.presets ?? []) {\n if (!preset.detect) continue;\n for (const side of [\"server\", \"client\"] as const) {\n for (const [key, schema] of Object.entries(preset[side] ?? {})) {\n if (def[side]?.[key] === schema) keys.add(key);\n }\n }\n }\n return keys;\n}\n\n/**\n * Writes vite-env.d.ts for Standard Schema definitions.\n * All fields are typed as `string` — Standard Schema has no runtime type introspection.\n */\nexport async function generateStandardDts(def: StandardEnvDefinition, root: string): Promise<void> {\n const clientKeys = Object.keys(def.client ?? {});\n const serverKeys = [...Object.keys(def.server ?? {}), ...clientKeys];\n\n const clientFields = keysToTsFields(clientKeys);\n const serverFields = keysToTsFields(serverKeys);\n\n await writeDts(root, clientFields, serverFields, \"(Standard Schema)\");\n}\n\nfunction buildHeader(tag = \"\"): string {\n const lines = [\n \"/* oxlint-disable */\",\n \"/* eslint-disable */\",\n \"// @ts-nocheck\",\n \"// biome-ignore-all lint: auto-generated\",\n tag ? `// Auto-generated by @vite-env/core ${tag}` : \"// Auto-generated by @vite-env/core\",\n \"// Do not edit manually — re-generated on every dev server start and build\",\n ];\n if (tag) {\n lines.push(\"// Tip: for richer types, use defineEnv() with Zod instead of defineStandardEnv()\");\n }\n return lines.join(\"\\n\");\n}\n\nasync function writeDts(\n root: string,\n clientFields: string,\n serverFields: string,\n tag = \"\",\n): Promise<void> {\n const header = buildHeader(tag);\n\n const dts = `${header}\n\ndeclare module 'virtual:env/client' {\n const env: {\n${clientFields}\n }\n export { env }\n export default env\n}\n\ndeclare module 'virtual:env/server' {\n const env: {\n${serverFields}\n }\n export { env }\n export default env\n}\n`;\n\n const filePath = path.join(root, \"vite-env.d.ts\");\n try {\n await fs.writeFile(filePath, dts, \"utf-8\");\n } catch (e) {\n throw new Error(\n `[vite-env] Failed to write vite-env.d.ts to ${root}. Check file permissions.`,\n { cause: e },\n );\n }\n}\n\nfunction keysToTsFields(keys: string[]): string {\n return keys.map((key) => ` readonly ${key}: string`).join(\"\\n\");\n}\n\nfunction zodShapeToTsFields(\n z: typeof ZodNs,\n shape: Record<string, unknown>,\n gatedKeys: Set<string>,\n): string {\n return Object.entries(shape)\n .map(([key, schema]) => {\n const tsType = zodToTs(z, schema);\n const optional = schema instanceof z.ZodOptional || gatedKeys.has(key);\n return ` readonly ${key}${optional ? \"?\" : \"\"}: ${tsType}`;\n })\n .join(\"\\n\");\n}\n\nfunction zodToTs(z: typeof ZodNs, schema: unknown): string {\n if (schema instanceof z.ZodOptional) return zodToTs(z, schema.unwrap());\n if (schema instanceof z.ZodDefault) return zodToTs(z, schema.def.innerType);\n if (schema instanceof z.ZodString) return \"string\";\n if (schema instanceof z.ZodNumber) return \"number\";\n if (schema instanceof z.ZodBoolean) return \"boolean\";\n if (schema instanceof z.ZodEnum)\n return (schema.options as string[]).map((o) => `'${o}'`).join(\" | \");\n if (schema instanceof z.ZodPipe) return zodToTs(z, schema.def.out);\n return \"string\";\n}\n"],"mappings":";;;;;;;;AAWA,eAAsB,YAAY,KAAoB,MAA6B;CACjF,MAAM,EAAE,MAAM,MAAM,OAAO;CAE3B,MAAM,YAAY,gBAAgB,IAAI;AAItC,OAAM,SAAS,MAHM,mBAAmB,GAAG,EAAE,GAAG,IAAI,QAAQ,EAAE,UAG7B,EAFZ,mBAAmB,GAAG;EAAE,GAAG,IAAI;EAAQ,GAAG,IAAI;EAAQ,EAAE,UAE9B,CAAC;;;;;;AAOlD,SAAS,gBAAgB,KAAiC;CACxD,MAAM,uBAAO,IAAI,KAAa;AAC9B,MAAK,MAAM,UAAU,IAAI,WAAW,EAAE,EAAE;AACtC,MAAI,CAAC,OAAO,OAAQ;AACpB,OAAK,MAAM,QAAQ,CAAC,UAAU,SAAS,CACrC,MAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,OAAO,SAAS,EAAE,CAAC,CAC5D,KAAI,IAAI,QAAQ,SAAS,OAAQ,MAAK,IAAI,IAAI;;AAIpD,QAAO;;;;;;AAOT,eAAsB,oBAAoB,KAA4B,MAA6B;CACjG,MAAM,aAAa,OAAO,KAAK,IAAI,UAAU,EAAE,CAAC;CAChD,MAAM,aAAa,CAAC,GAAG,OAAO,KAAK,IAAI,UAAU,EAAE,CAAC,EAAE,GAAG,WAAW;AAKpE,OAAM,SAAS,MAHM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AM,IAAI,EAAE,GAAG,CAAC,KAAK,MAAM;AACtE,KAAI,kBAAkB,EAAE,QAAS,QAAO,QAAQ,GAAG,OAAO,IAAI,IAAI;AAClE,QAAO"}
|
package/dist/format.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.cjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["import type { core } from
|
|
1
|
+
{"version":3,"file":"format.cjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["import type { core } from \"zod\";\nimport type { GuardFail } from \"./guard\";\nimport type { StandardValidationIssue } from \"./types\";\n\nexport function formatZodError(issues: core.$ZodIssue[]): string {\n return issues\n .map((issue) => {\n const path = issue.path.length > 0 ? issue.path.join(\".\") : \"(root)\";\n return ` \\x1B[31m✗\\x1B[0m ${path.padEnd(28)} ${issue.message}`;\n })\n .join(\"\\n\");\n}\n\nexport function formatStandardSchemaError(issues: StandardValidationIssue[]): string {\n return issues\n .map((issue) => {\n const path =\n issue.path.length > 0\n ? issue.path\n .map((seg) =>\n typeof seg === \"object\" && seg !== null && \"key\" in seg\n ? String(seg.key)\n : String(seg),\n )\n .join(\".\")\n : \"(root)\";\n return ` \\x1B[31m✗\\x1B[0m ${path.padEnd(28)} ${issue.message}`;\n })\n .join(\"\\n\");\n}\n\nconst YELLOW = \"\\x1B[33m\";\nconst BOLD_YELLOW = \"\\x1B[1;33m\";\nconst CYAN = \"\\x1B[36m\";\nconst RESET = \"\\x1B[0m\";\n\nconst BOX_WIDTH = 66;\n// 1 left border + 2 left spaces + content + 1 right border = BOX_WIDTH\n// content area = BOX_WIDTH - 4\nconst CONTENT_AREA = BOX_WIDTH - 4;\n\n/** Maximum visible character length for an importer path inside the warning box. */\nexport const IMPORTER_MAX_LEN = CONTENT_AREA - \"Found in: \".length;\n\n/**\n * Truncates an importer path to fit within maxLen visible characters.\n * Adds a leading '…' when truncation occurs so the rightmost (most specific) part is preserved.\n */\nexport function truncateImporter(importerPath: string, maxLen: number): string {\n if (importerPath.length <= maxLen) return importerPath;\n return `\\u2026${importerPath.slice(-(maxLen - 1))}`;\n}\n\nfunction boxTop(): string {\n return `${YELLOW}\\u250C${\"─\".repeat(BOX_WIDTH - 2)}\\u2510${RESET}`;\n}\n\nfunction boxBottom(): string {\n return `${YELLOW}\\u2514${\"─\".repeat(BOX_WIDTH - 2)}\\u2518${RESET}`;\n}\n\nfunction boxLine(visibleText: string, renderedText = visibleText): string {\n const rightPad = \" \".repeat(Math.max(0, CONTENT_AREA - visibleText.length));\n return `${YELLOW}\\u2502${RESET} ${renderedText}${rightPad}${YELLOW}\\u2502${RESET}`;\n}\n\n/**\n * Renders the colored terminal warning box for 'warn' mode.\n * Every line is exactly 66 characters wide (visible chars, excluding ANSI codes),\n * assuming Vite environment names are short (≤19 chars). Longer names will extend\n * the line beyond 66 chars without crashing — Math.max(0) prevents negative padding.\n * Use in logger.warn() calls — not in log files.\n */\nexport function formatGuardWarning(fail: GuardFail): string {\n const importerDisplay =\n fail.importer === undefined ? \"(unknown)\" : truncateImporter(fail.importer, IMPORTER_MAX_LEN);\n\n const warnTitle = \"To enforce now: onClientAccessOfServerModule: 'error'\";\n const stubTitle = \"To silence: onClientAccessOfServerModule: 'stub'\";\n\n return [\n boxTop(),\n boxLine(\n \"[vite-env] DEPRECATION WARNING\",\n `${BOLD_YELLOW}[vite-env] DEPRECATION WARNING${RESET}`,\n ),\n boxLine(\"\"),\n boxLine(`virtual:env/server was imported from the \"${fail.envName}\"`),\n boxLine(\"environment. This will be a hard build error in 1.0.0.\"),\n boxLine(\"\"),\n boxLine(warnTitle, `To enforce now: ${CYAN}onClientAccessOfServerModule: 'error'${RESET}`),\n boxLine(stubTitle, `To silence: ${CYAN}onClientAccessOfServerModule: 'stub'${RESET}`),\n boxLine(\"\"),\n boxLine(`Found in: ${importerDisplay}`),\n boxBottom(),\n ].join(\"\\n\");\n}\n\n/**\n * Renders the plain-text hard error message thrown in 'error' mode.\n * No ANSI — thrown as an Error message, not printed via logger.\n */\nexport function formatHardError(fail: GuardFail): string {\n const importerLine = fail.importer ?? \"(unknown)\";\n return [\n `[vite-env] virtual:env/server is not available in the \"${fail.envName}\" environment.`,\n ``,\n ` Server-only modules cannot be imported from client code.`,\n ` Add this environment to serverEnvironments if intentional:`,\n ``,\n ` ViteEnv({ serverEnvironments: ['ssr', '${fail.envName}'] })`,\n ``,\n ` Or change enforcement:`,\n ``,\n ` ViteEnv({ onClientAccessOfServerModule: 'stub' })`,\n ``,\n ` Imported from: ${importerLine}`,\n ].join(\"\\n\");\n}\n\n/**\n * Renders a single ANSI-free log entry for vite-env-warnings.log.\n * Uses the same (unknown) convention as formatGuardWarning for missing importers.\n */\nexport function formatGuardLogEntry(fail: GuardFail, timestamp: string): string {\n const importerLine = fail.importer ?? \"(unknown)\";\n return [\n `[${timestamp}] virtual:env/server accessed from \"${fail.envName}\" environment`,\n ` Importer: ${importerLine}`,\n ].join(\"\\n\");\n}\n"],"mappings":";;AAIA,SAAgB,eAAe,QAAkC;AAC/D,QAAO,OACJ,KAAK,UAAU;AAEd,SAAO,uBADM,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,KAAK,IAAI,GAAG,UAC1B,OAAO,GAAG,CAAC,GAAG,MAAM;GACtD,CACD,KAAK,KAAK;;AAGf,SAAgB,0BAA0B,QAA2C;AACnF,QAAO,OACJ,KAAK,UAAU;AAWd,SAAO,uBATL,MAAM,KAAK,SAAS,IAChB,MAAM,KACH,KAAK,QACJ,OAAO,QAAQ,YAAY,QAAQ,QAAQ,SAAS,MAChD,OAAO,IAAI,IAAI,GACf,OAAO,IAAI,CAChB,CACA,KAAK,IAAI,GACZ,UAC4B,OAAO,GAAG,CAAC,GAAG,MAAM;GACtD,CACD,KAAK,KAAK;;AAGf,MAAM,SAAS;AACf,MAAM,cAAc;AACpB,MAAM,OAAO;AACb,MAAM,QAAQ;AAEd,MAAM,YAAY;AAGlB,MAAM,eAAe,YAAY;;AAGjC,MAAa,mBAAmB,eAAe;;;;;AAM/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O,CACL,IAAI,UAAU,sCAAsC,KAAK,QAAQ,gBACjE,eAAe,eAChB,CAAC,KAAK,KAAK"}
|
package/dist/format.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { s as StandardValidationIssue } from "./types-
|
|
1
|
+
import { s as StandardValidationIssue } from "./types-DudMh278.cjs";
|
|
2
2
|
import { core } from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/guard.d.ts
|
|
5
|
-
type GuardMode =
|
|
5
|
+
type GuardMode = "error" | "stub" | "warn";
|
|
6
6
|
type GuardResult = {
|
|
7
7
|
allowed: true;
|
|
8
8
|
} | {
|
package/dist/format.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { s as StandardValidationIssue } from "./types
|
|
1
|
+
import { s as StandardValidationIssue } from "./types-Ctg8aeXQ.mjs";
|
|
2
2
|
import { core } from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/guard.d.ts
|
|
5
|
-
type GuardMode =
|
|
5
|
+
type GuardMode = "error" | "stub" | "warn";
|
|
6
6
|
type GuardResult = {
|
|
7
7
|
allowed: true;
|
|
8
8
|
} | {
|
package/dist/format.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.mjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["import type { core } from
|
|
1
|
+
{"version":3,"file":"format.mjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["import type { core } from \"zod\";\nimport type { GuardFail } from \"./guard\";\nimport type { StandardValidationIssue } from \"./types\";\n\nexport function formatZodError(issues: core.$ZodIssue[]): string {\n return issues\n .map((issue) => {\n const path = issue.path.length > 0 ? issue.path.join(\".\") : \"(root)\";\n return ` \\x1B[31m✗\\x1B[0m ${path.padEnd(28)} ${issue.message}`;\n })\n .join(\"\\n\");\n}\n\nexport function formatStandardSchemaError(issues: StandardValidationIssue[]): string {\n return issues\n .map((issue) => {\n const path =\n issue.path.length > 0\n ? issue.path\n .map((seg) =>\n typeof seg === \"object\" && seg !== null && \"key\" in seg\n ? String(seg.key)\n : String(seg),\n )\n .join(\".\")\n : \"(root)\";\n return ` \\x1B[31m✗\\x1B[0m ${path.padEnd(28)} ${issue.message}`;\n })\n .join(\"\\n\");\n}\n\nconst YELLOW = \"\\x1B[33m\";\nconst BOLD_YELLOW = \"\\x1B[1;33m\";\nconst CYAN = \"\\x1B[36m\";\nconst RESET = \"\\x1B[0m\";\n\nconst BOX_WIDTH = 66;\n// 1 left border + 2 left spaces + content + 1 right border = BOX_WIDTH\n// content area = BOX_WIDTH - 4\nconst CONTENT_AREA = BOX_WIDTH - 4;\n\n/** Maximum visible character length for an importer path inside the warning box. */\nexport const IMPORTER_MAX_LEN = CONTENT_AREA - \"Found in: \".length;\n\n/**\n * Truncates an importer path to fit within maxLen visible characters.\n * Adds a leading '…' when truncation occurs so the rightmost (most specific) part is preserved.\n */\nexport function truncateImporter(importerPath: string, maxLen: number): string {\n if (importerPath.length <= maxLen) return importerPath;\n return `\\u2026${importerPath.slice(-(maxLen - 1))}`;\n}\n\nfunction boxTop(): string {\n return `${YELLOW}\\u250C${\"─\".repeat(BOX_WIDTH - 2)}\\u2510${RESET}`;\n}\n\nfunction boxBottom(): string {\n return `${YELLOW}\\u2514${\"─\".repeat(BOX_WIDTH - 2)}\\u2518${RESET}`;\n}\n\nfunction boxLine(visibleText: string, renderedText = visibleText): string {\n const rightPad = \" \".repeat(Math.max(0, CONTENT_AREA - visibleText.length));\n return `${YELLOW}\\u2502${RESET} ${renderedText}${rightPad}${YELLOW}\\u2502${RESET}`;\n}\n\n/**\n * Renders the colored terminal warning box for 'warn' mode.\n * Every line is exactly 66 characters wide (visible chars, excluding ANSI codes),\n * assuming Vite environment names are short (≤19 chars). Longer names will extend\n * the line beyond 66 chars without crashing — Math.max(0) prevents negative padding.\n * Use in logger.warn() calls — not in log files.\n */\nexport function formatGuardWarning(fail: GuardFail): string {\n const importerDisplay =\n fail.importer === undefined ? \"(unknown)\" : truncateImporter(fail.importer, IMPORTER_MAX_LEN);\n\n const warnTitle = \"To enforce now: onClientAccessOfServerModule: 'error'\";\n const stubTitle = \"To silence: onClientAccessOfServerModule: 'stub'\";\n\n return [\n boxTop(),\n boxLine(\n \"[vite-env] DEPRECATION WARNING\",\n `${BOLD_YELLOW}[vite-env] DEPRECATION WARNING${RESET}`,\n ),\n boxLine(\"\"),\n boxLine(`virtual:env/server was imported from the \"${fail.envName}\"`),\n boxLine(\"environment. This will be a hard build error in 1.0.0.\"),\n boxLine(\"\"),\n boxLine(warnTitle, `To enforce now: ${CYAN}onClientAccessOfServerModule: 'error'${RESET}`),\n boxLine(stubTitle, `To silence: ${CYAN}onClientAccessOfServerModule: 'stub'${RESET}`),\n boxLine(\"\"),\n boxLine(`Found in: ${importerDisplay}`),\n boxBottom(),\n ].join(\"\\n\");\n}\n\n/**\n * Renders the plain-text hard error message thrown in 'error' mode.\n * No ANSI — thrown as an Error message, not printed via logger.\n */\nexport function formatHardError(fail: GuardFail): string {\n const importerLine = fail.importer ?? \"(unknown)\";\n return [\n `[vite-env] virtual:env/server is not available in the \"${fail.envName}\" environment.`,\n ``,\n ` Server-only modules cannot be imported from client code.`,\n ` Add this environment to serverEnvironments if intentional:`,\n ``,\n ` ViteEnv({ serverEnvironments: ['ssr', '${fail.envName}'] })`,\n ``,\n ` Or change enforcement:`,\n ``,\n ` ViteEnv({ onClientAccessOfServerModule: 'stub' })`,\n ``,\n ` Imported from: ${importerLine}`,\n ].join(\"\\n\");\n}\n\n/**\n * Renders a single ANSI-free log entry for vite-env-warnings.log.\n * Uses the same (unknown) convention as formatGuardWarning for missing importers.\n */\nexport function formatGuardLogEntry(fail: GuardFail, timestamp: string): string {\n const importerLine = fail.importer ?? \"(unknown)\";\n return [\n `[${timestamp}] virtual:env/server accessed from \"${fail.envName}\" environment`,\n ` Importer: ${importerLine}`,\n ].join(\"\\n\");\n}\n"],"mappings":";AAIA,SAAgB,eAAe,QAAkC;AAC/D,QAAO,OACJ,KA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AgC,QAChD;EACD,QAAQ,GAAG;EACX,QAAQ,6CAA6C,KAAK,QAAQ,GAAG;EACrE,QAAQ,yDAAyD;EACjE,QAAQ,GAAG;EACX,QAAQ,0DAAW,oBAAoB,KAAK,uCAAuC,QAAQ;EAC3F,QAAQ,yDAAW,oBAAoB,KAAK,sCAAsC,QAAQ;EAC1F,QAAQ,GAAG;EACX,QAAQ,aAAa,kBAAkB;EACvC,WAAW;EACZ,CAAC,KAAK,KAAK;;;;;;AAOd,SAAgB,gBAAgB,MAAyB;CACvD,MAAM,eAAe,KAAK,YAAY;AACtC,QAAO;EACL,0DAA0D,KAAK,QAAQ;EACvE;EACA;EACA;EACA;EACA,8CAA8C,KAAK,QAAQ;EAC3D;EACA;EACA;EACA;EACA;EACA,oBAAoB;EACrB,CAAC,KAAK,KAAK;;;;;;AAOd,SAAgB,oBAAoB,MAAiB,WAA2B;CAC9E,MAAM,eAAe,KAAK,YAAY;AACtC,QAAO,CACL,IAAI,UAAU,sCAAsC,KAAK,QAAQ,gBACjE,eAAe,eAChB,CAAC,KAAK,KAAK"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as InferServerEnv, i as InferClientEnv, n as EnvDefinition, o as StandardEnvDefinition, r as EnvPreset, t as AnyEnvDefinition } from "./types-
|
|
1
|
+
import { a as InferServerEnv, i as InferClientEnv, n as EnvDefinition, o as StandardEnvDefinition, r as EnvPreset, t as AnyEnvDefinition } from "./types-DudMh278.cjs";
|
|
2
2
|
import { defineEnv } from "./schema.cjs";
|
|
3
3
|
import { defineStandardEnv } from "./standard.cjs";
|
|
4
4
|
export { type AnyEnvDefinition, type EnvDefinition, type EnvPreset, type InferClientEnv, type InferServerEnv, type StandardEnvDefinition, defineEnv, defineStandardEnv };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as InferServerEnv, i as InferClientEnv, n as EnvDefinition, o as StandardEnvDefinition, r as EnvPreset, t as AnyEnvDefinition } from "./types
|
|
1
|
+
import { a as InferServerEnv, i as InferClientEnv, n as EnvDefinition, o as StandardEnvDefinition, r as EnvPreset, t as AnyEnvDefinition } from "./types-Ctg8aeXQ.mjs";
|
|
2
2
|
import { defineEnv } from "./schema.mjs";
|
|
3
3
|
import { defineStandardEnv } from "./standard.mjs";
|
|
4
4
|
export { type AnyEnvDefinition, type EnvDefinition, type EnvPreset, type InferClientEnv, type InferServerEnv, type StandardEnvDefinition, defineEnv, defineStandardEnv };
|
package/dist/leak.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"leak.cjs","names":[],"sources":["../src/leak.ts"],"sourcesContent":["import type { AnyEnvDefinition } from
|
|
1
|
+
{"version":3,"file":"leak.cjs","names":[],"sources":["../src/leak.ts"],"sourcesContent":["import type { AnyEnvDefinition } from \"./types\";\n\ntype LeakReport = {\n key: string;\n chunk: string;\n};\n\n/**\n * Scans all client-destined chunks for literal values of server-only vars.\n * Fires in generateBundle() — Rolldown sequential hook, safe.\n *\n * Strategy: for each server-only key, check if its actual runtime value\n * appears as a literal string in any output chunk's source code.\n * Short/common values (< 8 chars) are skipped to avoid false positives.\n */\nexport function detectServerLeak(\n def: AnyEnvDefinition,\n data: Record<string, unknown>,\n bundle: Record<string, { type: string; code?: string }>,\n onSkipped?: (keys: string[]) => void,\n): LeakReport[] {\n const serverKeys = new Set(Object.keys(def.server ?? {}));\n\n const shortSecrets = Object.entries(data).filter(\n (entry): entry is [string, string] =>\n serverKeys.has(entry[0]) && typeof entry[1] === \"string\" && entry[1].length < 8,\n );\n\n if (shortSecrets.length > 0 && onSkipped) {\n onSkipped(shortSecrets.map(([k]) => k));\n }\n\n const serverSecrets = Object.entries(data).filter(\n (entry): entry is [string, string] =>\n serverKeys.has(entry[0]) && typeof entry[1] === \"string\" && entry[1].length >= 8,\n );\n\n const chunks = Object.entries(bundle).filter(\n ([, chunk]) => chunk.type === \"chunk\" && !!chunk.code,\n );\n\n const leaks: LeakReport[] = [];\n for (const [key, value] of serverSecrets) {\n for (const [chunkName, chunk] of chunks) {\n if (chunk.code!.includes(value)) {\n leaks.push({ key, chunk: chunkName });\n }\n }\n }\n\n return leaks;\n}\n"],"mappings":";;;;;;;;;;AAeA,SAAgB,iBACd,KACA,MACA,QACA,WACc;CACd,MAAM,aAAa,IAAI,IAAI,OAAO,KAAK,IAAI,UAAU,EAAE,CAAC,CAAC;CAEzD,MAAM,eAAe,OAAO,QAAQ,KAAK,CAAC,QACvC,UACC,WAAW,IAAI,MAAM,GAAG,IAAI,OAAO,MAAM,OAAO,YAAY,MAAM,GAAG,SAAS,EACjF;AAED,KAAI,aAAa,SAAS,KAAK,UAC7B,WAAU,aAAa,KAAK,CAAC,OAAO,EAAE,CAAC;CAGzC,MAAM,gBAAgB,OAAO,QAAQ,KAAK,CAAC,QACxC,UACC,WAAW,IAAI,MAAM,GAAG,IAAI,OAAO,MAAM,OAAO,YAAY,MAAM,GAAG,UAAU,EAClF;CAED,MAAM,SAAS,OAAO,QAAQ,OAAO,CAAC,QACnC,GAAG,WAAW,MAAM,SAAS,WAAW,CAAC,CAAC,MAAM,KAClD;CAED,MAAM,QAAsB,EAAE;AAC9B,MAAK,MAAM,CAAC,KAAK,UAAU,cACzB,MAAK,MAAM,CAAC,WAAW,UAAU,OAC/B,KAAI,MAAM,KAAM,SAAS,MAAM,CAC7B,OAAM,KAAK;EAAE;EAAK,OAAO;EAAW,CAAC;AAK3C,QAAO"}
|
package/dist/leak.d.cts
CHANGED
package/dist/leak.d.mts
CHANGED
package/dist/leak.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"leak.mjs","names":[],"sources":["../src/leak.ts"],"sourcesContent":["import type { AnyEnvDefinition } from
|
|
1
|
+
{"version":3,"file":"leak.mjs","names":[],"sources":["../src/leak.ts"],"sourcesContent":["import type { AnyEnvDefinition } from \"./types\";\n\ntype LeakReport = {\n key: string;\n chunk: string;\n};\n\n/**\n * Scans all client-destined chunks for literal values of server-only vars.\n * Fires in generateBundle() — Rolldown sequential hook, safe.\n *\n * Strategy: for each server-only key, check if its actual runtime value\n * appears as a literal string in any output chunk's source code.\n * Short/common values (< 8 chars) are skipped to avoid false positives.\n */\nexport function detectServerLeak(\n def: AnyEnvDefinition,\n data: Record<string, unknown>,\n bundle: Record<string, { type: string; code?: string }>,\n onSkipped?: (keys: string[]) => void,\n): LeakReport[] {\n const serverKeys = new Set(Object.keys(def.server ?? {}));\n\n const shortSecrets = Object.entries(data).filter(\n (entry): entry is [string, string] =>\n serverKeys.has(entry[0]) && typeof entry[1] === \"string\" && entry[1].length < 8,\n );\n\n if (shortSecrets.length > 0 && onSkipped) {\n onSkipped(shortSecrets.map(([k]) => k));\n }\n\n const serverSecrets = Object.entries(data).filter(\n (entry): entry is [string, string] =>\n serverKeys.has(entry[0]) && typeof entry[1] === \"string\" && entry[1].length >= 8,\n );\n\n const chunks = Object.entries(bundle).filter(\n ([, chunk]) => chunk.type === \"chunk\" && !!chunk.code,\n );\n\n const leaks: LeakReport[] = [];\n for (const [key, value] of serverSecrets) {\n for (const [chunkName, chunk] of chunks) {\n if (chunk.code!.includes(value)) {\n leaks.push({ key, chunk: chunkName });\n }\n }\n }\n\n return leaks;\n}\n"],"mappings":";;;;;;;;;AAeA,SAAgB,iBACd,KACA,MACA,QACA,WACc;CACd,MAAM,aAAa,IAAI,IAAI,OAAO,KAAK,IAAI,UAAU,EAAE,CAAC,CAAC;CAEzD,MAAM,eAAe,OAAO,QAAQ,KAAK,CAAC,QACvC,UACC,WAAW,IAAI,MAAM,GAAG,IAAI,OAAO,MAAM,OAAO,YAAY,MAAM,GAAG,SAAS,EACjF;AAED,KAAI,aAAa,SAAS,KAAK,UAC7B,WAAU,aAAa,KAAK,CAAC,OAAO,EAAE,CAAC;CAGzC,MAAM,gBAAgB,OAAO,QAAQ,KAAK,CAAC,QACxC,UACC,WAAW,IAAI,MAAM,GAAG,IAAI,OAAO,MAAM,OAAO,YAAY,MAAM,GAAG,UAAU,EAClF;CAED,MAAM,SAAS,OAAO,QAAQ,OAAO,CAAC,QACnC,GAAG,WAAW,MAAM,SAAS,WAAW,CAAC,CAAC,MAAM,KAClD;CAED,MAAM,QAAsB,EAAE;AAC9B,MAAK,MAAM,CAAC,KAAK,UAAU,cACzB,MAAK,MAAM,CAAC,WAAW,UAAU,OAC/B,KAAI,MAAM,KAAM,SAAS,MAAM,CAC7B,OAAM,KAAK;EAAE;EAAK,OAAO;EAAW,CAAC;AAK3C,QAAO"}
|
package/dist/load.cjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_chunk = require("./chunk-CKQMccvm.cjs");
|
|
3
|
+
const require_schema = require("./schema.cjs");
|
|
4
|
+
const require_standard = require("./standard.cjs");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
node_path = require_chunk.__toESM(node_path, 1);
|
|
7
|
+
let node_process = require("node:process");
|
|
8
|
+
node_process = require_chunk.__toESM(node_process, 1);
|
|
9
|
+
let vite = require("vite");
|
|
10
|
+
//#region src/load.ts
|
|
11
|
+
async function loadEnv(config, options = {}) {
|
|
12
|
+
const rawEnv = {
|
|
13
|
+
...(0, vite.loadEnv)(options.mode ?? node_process.default.env["NODE_ENV"] ?? "development", options.envDir ? node_path.default.resolve(options.envDir) : node_process.default.cwd(), ""),
|
|
14
|
+
...filterStrings(node_process.default.env)
|
|
15
|
+
};
|
|
16
|
+
if (require_standard.isStandardEnvDefinition(config)) {
|
|
17
|
+
const result = await require_standard.validateStandardEnv(config, rawEnv);
|
|
18
|
+
if (!result.success) throwValidationError(result.errors.map((e) => e.message));
|
|
19
|
+
const server = Object.freeze(result.data);
|
|
20
|
+
const clientKeys = new Set(Object.keys(config.client ?? {}));
|
|
21
|
+
return {
|
|
22
|
+
server,
|
|
23
|
+
client: Object.freeze(filterByKeys(server, clientKeys)),
|
|
24
|
+
all: server
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const result = require_schema.validateEnv(config, rawEnv);
|
|
28
|
+
if (!result.success) throwValidationError(result.errors.map((e) => e.message));
|
|
29
|
+
const server = Object.freeze(result.data);
|
|
30
|
+
const clientKeys = new Set(Object.keys(config.client ?? {}));
|
|
31
|
+
return {
|
|
32
|
+
server,
|
|
33
|
+
client: Object.freeze(filterByKeys(server, clientKeys)),
|
|
34
|
+
all: server
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function filterByKeys(data, keys) {
|
|
38
|
+
return Object.fromEntries(Object.entries(data).filter(([k]) => keys.has(k)));
|
|
39
|
+
}
|
|
40
|
+
function filterStrings(env) {
|
|
41
|
+
return Object.fromEntries(Object.entries(env).filter((e) => typeof e[1] === "string"));
|
|
42
|
+
}
|
|
43
|
+
function throwValidationError(messages) {
|
|
44
|
+
const lines = messages.map((m) => " - " + m).join("\n");
|
|
45
|
+
throw new Error("[vite-env] Validation failed:\n" + lines);
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
exports.loadEnv = loadEnv;
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=load.cjs.map
|