@vite-env/core 0.2.2 → 0.3.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 +3 -1
- package/dist/config.cjs +1 -1
- package/dist/config.d.cts +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/dts-BgHTl6hC.cjs +114 -0
- package/dist/dts-BgHTl6hC.cjs.map +1 -0
- package/dist/dts.cjs +2 -1
- package/dist/dts.d.cts +10 -5
- package/dist/dts.d.mts +10 -5
- package/dist/dts.mjs +31 -23
- package/dist/dts.mjs.map +1 -1
- package/dist/format.cjs +6 -0
- package/dist/format.cjs.map +1 -1
- package/dist/format.d.cts +3 -1
- package/dist/format.d.mts +3 -1
- package/dist/format.mjs +6 -1
- package/dist/format.mjs.map +1 -1
- package/dist/index.cjs +2 -8
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/leak.cjs.map +1 -1
- package/dist/leak.d.cts +2 -2
- package/dist/leak.d.mts +2 -2
- package/dist/leak.mjs.map +1 -1
- package/dist/plugin.cjs +30 -13
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.mjs +31 -14
- package/dist/plugin.mjs.map +1 -1
- package/dist/schema.cjs +1 -1
- package/dist/schema.d.cts +1 -1
- package/dist/schema.d.mts +1 -1
- package/dist/standard.cjs +46 -0
- package/dist/standard.cjs.map +1 -0
- package/dist/standard.d.cts +11 -0
- package/dist/standard.d.mts +11 -0
- package/dist/standard.mjs +43 -0
- package/dist/standard.mjs.map +1 -0
- package/dist/types-1okexcwM.d.cts +43 -0
- package/dist/types-DuWT_251.d.mts +43 -0
- package/package.json +19 -2
- package/dist/dts-DF71HNdJ.cjs +0 -100
- package/dist/dts-DF71HNdJ.cjs.map +0 -1
- package/dist/types-CluiDKAQ.d.mts +0 -22
- package/dist/types-DqTMuWwc.d.cts +0 -22
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
|
- Auto-coercion via Zod v4 (`z.stringbool()`, `z.coerce.number()`)
|
|
10
|
+
- Standard Schema support — use Valibot, ArkType, or any compliant validator
|
|
10
11
|
- Auto `.d.ts` generation
|
|
11
12
|
- Vite 8 / Rolldown native
|
|
12
13
|
|
|
@@ -21,7 +22,8 @@ pnpm add @vite-env/core zod
|
|
|
21
22
|
**1. Define your schema** — `env.ts`
|
|
22
23
|
|
|
23
24
|
```ts
|
|
24
|
-
import { defineEnv
|
|
25
|
+
import { defineEnv } from '@vite-env/core'
|
|
26
|
+
import { z } from 'zod'
|
|
25
27
|
|
|
26
28
|
export default defineEnv({
|
|
27
29
|
server: {
|
package/dist/config.cjs
CHANGED
package/dist/config.d.cts
CHANGED
package/dist/config.d.mts
CHANGED
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
let node_path = require("node:path");
|
|
24
|
+
node_path = __toESM(node_path);
|
|
25
|
+
let node_fs_promises = require("node:fs/promises");
|
|
26
|
+
node_fs_promises = __toESM(node_fs_promises);
|
|
27
|
+
//#region src/dts.ts
|
|
28
|
+
/**
|
|
29
|
+
* Writes vite-env.d.ts for Zod definitions.
|
|
30
|
+
* Uses instanceof checks to infer TypeScript types from Zod schemas.
|
|
31
|
+
* Zod is loaded dynamically so this module can be imported without zod installed.
|
|
32
|
+
*/
|
|
33
|
+
async function generateDts(def, root) {
|
|
34
|
+
const { z } = await import("zod");
|
|
35
|
+
await writeDts(root, zodShapeToTsFields(z, { ...def.client }), zodShapeToTsFields(z, {
|
|
36
|
+
...def.server,
|
|
37
|
+
...def.client
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Writes vite-env.d.ts for Standard Schema definitions.
|
|
42
|
+
* All fields are typed as `string` — Standard Schema has no runtime type introspection.
|
|
43
|
+
*/
|
|
44
|
+
async function generateStandardDts(def, root) {
|
|
45
|
+
const clientKeys = Object.keys(def.client ?? {});
|
|
46
|
+
const serverKeys = [...Object.keys(def.server ?? {}), ...clientKeys];
|
|
47
|
+
await writeDts(root, keysToTsFields(clientKeys), keysToTsFields(serverKeys), "(Standard Schema)");
|
|
48
|
+
}
|
|
49
|
+
async function writeDts(root, clientFields, serverFields, tag = "") {
|
|
50
|
+
const dts = `${tag ? `// Auto-generated by @vite-env/core ${tag}\n// Do not edit manually — re-generated on every dev server start and build\n// Tip: for richer types, use defineEnv() with Zod instead of defineStandardEnv()` : `// Auto-generated by @vite-env/core\n// Do not edit manually — re-generated on every dev server start and build`}
|
|
51
|
+
|
|
52
|
+
declare module 'virtual:env/client' {
|
|
53
|
+
const env: {
|
|
54
|
+
${clientFields}
|
|
55
|
+
}
|
|
56
|
+
export { env }
|
|
57
|
+
export default env
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
declare module 'virtual:env/server' {
|
|
61
|
+
const env: {
|
|
62
|
+
${serverFields}
|
|
63
|
+
}
|
|
64
|
+
export { env }
|
|
65
|
+
export default env
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
const filePath = node_path.default.join(root, "vite-env.d.ts");
|
|
69
|
+
try {
|
|
70
|
+
await node_fs_promises.default.writeFile(filePath, dts, "utf-8");
|
|
71
|
+
} catch (e) {
|
|
72
|
+
throw new Error(`[vite-env] Failed to write vite-env.d.ts to ${root}. Check file permissions.`, { cause: e });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function keysToTsFields(keys) {
|
|
76
|
+
return keys.map((key) => ` readonly ${key}: string`).join("\n");
|
|
77
|
+
}
|
|
78
|
+
function zodShapeToTsFields(z, shape) {
|
|
79
|
+
return Object.entries(shape).map(([key, schema]) => {
|
|
80
|
+
const tsType = zodToTs(z, schema);
|
|
81
|
+
return ` readonly ${key}${schema instanceof z.ZodOptional ? "?" : ""}: ${tsType}`;
|
|
82
|
+
}).join("\n");
|
|
83
|
+
}
|
|
84
|
+
function zodToTs(z, schema) {
|
|
85
|
+
if (schema instanceof z.ZodOptional) return zodToTs(z, schema.unwrap());
|
|
86
|
+
if (schema instanceof z.ZodDefault) return zodToTs(z, schema.def.innerType);
|
|
87
|
+
if (schema instanceof z.ZodString) return "string";
|
|
88
|
+
if (schema instanceof z.ZodNumber) return "number";
|
|
89
|
+
if (schema instanceof z.ZodBoolean) return "boolean";
|
|
90
|
+
if (schema instanceof z.ZodEnum) return schema.options.map((o) => `'${o}'`).join(" | ");
|
|
91
|
+
if (schema instanceof z.ZodPipe) return zodToTs(z, schema.def.out);
|
|
92
|
+
return "string";
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
Object.defineProperty(exports, "__toESM", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function() {
|
|
98
|
+
return __toESM;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(exports, "generateDts", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
get: function() {
|
|
104
|
+
return generateDts;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(exports, "generateStandardDts", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
get: function() {
|
|
110
|
+
return generateStandardDts;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=dts-BgHTl6hC.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dts-BgHTl6hC.cjs","names":["path","fs"],"sources":["../src/dts.ts"],"sourcesContent":["// @env node\nimport type { EnvDefinition, StandardEnvDefinition } from './types'\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(\n def: EnvDefinition,\n root: string,\n): Promise<void> {\n const { z } = await import('zod')\n\n const clientFields = zodShapeToTsFields(z, { ...def.client })\n const serverFields = zodShapeToTsFields(z, { ...def.server, ...def.client })\n\n await writeDts(root, clientFields, serverFields)\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(\n def: StandardEnvDefinition,\n root: string,\n): 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\nasync function writeDts(\n root: string,\n clientFields: string,\n serverFields: string,\n tag = '',\n): Promise<void> {\n const header = tag\n ? `// Auto-generated by @vite-env/core ${tag}\\n// Do not edit manually — re-generated on every dev server start and build\\n// Tip: for richer types, use defineEnv() with Zod instead of defineStandardEnv()`\n : `// Auto-generated by @vite-env/core\\n// Do not edit manually — re-generated on every dev server start and build`\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 }\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\n .map(key => ` readonly ${key}: string`)\n .join('\\n')\n}\n\nfunction zodShapeToTsFields(z: any, shape: Record<string, unknown>): string {\n return Object.entries(shape)\n .map(([key, schema]) => {\n const tsType = zodToTs(z, schema)\n const optional = schema instanceof z.ZodOptional\n return ` readonly ${key}${optional ? '?' : ''}: ${tsType}`\n })\n .join('\\n')\n}\n\nfunction zodToTs(z: any, schema: any): string {\n if (schema instanceof z.ZodOptional)\n return zodToTs(z, schema.unwrap())\n if (schema instanceof z.ZodDefault)\n return zodToTs(z, schema.def.innerType)\n if (schema instanceof z.ZodString)\n return 'string'\n if (schema instanceof z.ZodNumber)\n return 'number'\n if (schema instanceof z.ZodBoolean)\n return 'boolean'\n if (schema instanceof z.ZodEnum)\n return (schema.options as string[]).map(o => `'${o}'`).join(' | ')\n if (schema instanceof z.ZodPipe)\n return zodToTs(z, schema.def.out)\n return 'string'\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,eAAsB,YACpB,KACA,MACe;CACf,MAAM,EAAE,MAAM,MAAM,OAAO;AAK3B,OAAM,SAAS,MAHM,mBAAmB,GAAG,EAAE,GAAG,IAAI,QAAQ,CAAC,EACxC,mBAAmB,GAAG;EAAE,GAAG,IAAI;EAAQ,GAAG,IAAI;EAAQ,CAAC,CAE5B;;;;;;AAOlD,eAAsB,oBACpB,KACA,MACe;CACf,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,WAAW,EAC1B,eAAe,WAAW,EAEE,oBAAoB;;AAGvE,eAAe,SACb,MACA,cACA,cACA,MAAM,IACS;CAKf,MAAM,MAAM,GAJG,MACX,uCAAuC,IAAI,mKAC3C,kHAEkB;;;;EAItB,aAAa;;;;;;;;EAQb,aAAa;;;;;;CAOb,MAAM,WAAWA,UAAAA,QAAK,KAAK,MAAM,gBAAgB;AACjD,KAAI;AACF,QAAMC,iBAAAA,QAAG,UAAU,UAAU,KAAK,QAAQ;UAErC,GAAG;AACR,QAAM,IAAI,MACR,+CAA+C,KAAK,4BACpD,EAAE,OAAO,GAAG,CACb;;;AAIL,SAAS,eAAe,MAAwB;AAC9C,QAAO,KACJ,KAAI,QAAO,gBAAgB,IAAI,UAAU,CACzC,KAAK,KAAK;;AAGf,SAAS,mBAAmB,GAAQ,OAAwC;AAC1E,QAAO,OAAO,QAAQ,MAAM,CACzB,KAAK,CAAC,KAAK,YAAY;EACtB,MAAM,SAAS,QAAQ,GAAG,OAAO;AAEjC,SAAO,gBAAgB,MADN,kBAAkB,EAAE,cACG,MAAM,GAAG,IAAI;GACrD,CACD,KAAK,KAAK;;AAGf,SAAS,QAAQ,GAAQ,QAAqB;AAC5C,KAAI,kBAAkB,EAAE,YACtB,QAAO,QAAQ,GAAG,OAAO,QAAQ,CAAC;AACpC,KAAI,kBAAkB,EAAE,WACtB,QAAO,QAAQ,GAAG,OAAO,IAAI,UAAU;AACzC,KAAI,kBAAkB,EAAE,UACtB,QAAO;AACT,KAAI,kBAAkB,EAAE,UACtB,QAAO;AACT,KAAI,kBAAkB,EAAE,WACtB,QAAO;AACT,KAAI,kBAAkB,EAAE,QACtB,QAAQ,OAAO,QAAqB,KAAI,MAAK,IAAI,EAAE,GAAG,CAAC,KAAK,MAAM;AACpE,KAAI,kBAAkB,EAAE,QACtB,QAAO,QAAQ,GAAG,OAAO,IAAI,IAAI;AACnC,QAAO"}
|
package/dist/dts.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_dts = require("./dts-
|
|
2
|
+
const require_dts = require("./dts-BgHTl6hC.cjs");
|
|
3
3
|
exports.generateDts = require_dts.generateDts;
|
|
4
|
+
exports.generateStandardDts = require_dts.generateStandardDts;
|
package/dist/dts.d.cts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as StandardEnvDefinition, n as EnvDefinition } from "./types-1okexcwM.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/dts.d.ts
|
|
4
4
|
/**
|
|
5
|
-
* Writes vite-env.d.ts
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Writes vite-env.d.ts for Zod definitions.
|
|
6
|
+
* Uses instanceof checks to infer TypeScript types from Zod schemas.
|
|
7
|
+
* Zod is loaded dynamically so this module can be imported without zod installed.
|
|
8
8
|
*/
|
|
9
9
|
declare function generateDts(def: EnvDefinition, root: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Writes vite-env.d.ts for Standard Schema definitions.
|
|
12
|
+
* All fields are typed as `string` — Standard Schema has no runtime type introspection.
|
|
13
|
+
*/
|
|
14
|
+
declare function generateStandardDts(def: StandardEnvDefinition, root: string): Promise<void>;
|
|
10
15
|
//#endregion
|
|
11
|
-
export { generateDts };
|
|
16
|
+
export { generateDts, generateStandardDts };
|
|
12
17
|
//# sourceMappingURL=dts.d.cts.map
|
package/dist/dts.d.mts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as StandardEnvDefinition, n as EnvDefinition } from "./types-DuWT_251.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/dts.d.ts
|
|
4
4
|
/**
|
|
5
|
-
* Writes vite-env.d.ts
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Writes vite-env.d.ts for Zod definitions.
|
|
6
|
+
* Uses instanceof checks to infer TypeScript types from Zod schemas.
|
|
7
|
+
* Zod is loaded dynamically so this module can be imported without zod installed.
|
|
8
8
|
*/
|
|
9
9
|
declare function generateDts(def: EnvDefinition, root: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Writes vite-env.d.ts for Standard Schema definitions.
|
|
12
|
+
* All fields are typed as `string` — Standard Schema has no runtime type introspection.
|
|
13
|
+
*/
|
|
14
|
+
declare function generateStandardDts(def: StandardEnvDefinition, root: string): Promise<void>;
|
|
10
15
|
//#endregion
|
|
11
|
-
export { generateDts };
|
|
16
|
+
export { generateDts, generateStandardDts };
|
|
12
17
|
//# sourceMappingURL=dts.d.mts.map
|
package/dist/dts.mjs
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import fs from "node:fs/promises";
|
|
4
3
|
//#region src/dts.ts
|
|
5
4
|
/**
|
|
6
|
-
* Writes vite-env.d.ts
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Writes vite-env.d.ts for Zod definitions.
|
|
6
|
+
* Uses instanceof checks to infer TypeScript types from Zod schemas.
|
|
7
|
+
* Zod is loaded dynamically so this module can be imported without zod installed.
|
|
9
8
|
*/
|
|
10
9
|
async function generateDts(def, root) {
|
|
11
|
-
const
|
|
12
|
-
|
|
10
|
+
const { z } = await import("zod");
|
|
11
|
+
await writeDts(root, zodShapeToTsFields(z, { ...def.client }), zodShapeToTsFields(z, {
|
|
13
12
|
...def.server,
|
|
14
13
|
...def.client
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Writes vite-env.d.ts for Standard Schema definitions.
|
|
18
|
+
* All fields are typed as `string` — Standard Schema has no runtime type introspection.
|
|
19
|
+
*/
|
|
20
|
+
async function generateStandardDts(def, root) {
|
|
21
|
+
const clientKeys = Object.keys(def.client ?? {});
|
|
22
|
+
const serverKeys = [...Object.keys(def.server ?? {}), ...clientKeys];
|
|
23
|
+
await writeDts(root, keysToTsFields(clientKeys), keysToTsFields(serverKeys), "(Standard Schema)");
|
|
24
|
+
}
|
|
25
|
+
async function writeDts(root, clientFields, serverFields, tag = "") {
|
|
26
|
+
const dts = `${tag ? `// Auto-generated by @vite-env/core ${tag}\n// Do not edit manually — re-generated on every dev server start and build\n// Tip: for richer types, use defineEnv() with Zod instead of defineStandardEnv()` : `// Auto-generated by @vite-env/core\n// Do not edit manually — re-generated on every dev server start and build`}
|
|
18
27
|
|
|
19
28
|
declare module 'virtual:env/client' {
|
|
20
29
|
const env: {
|
|
21
|
-
${
|
|
30
|
+
${clientFields}
|
|
22
31
|
}
|
|
23
32
|
export { env }
|
|
24
33
|
export default env
|
|
@@ -26,7 +35,7 @@ ${zodShapeToTsFields(clientKeys)}
|
|
|
26
35
|
|
|
27
36
|
declare module 'virtual:env/server' {
|
|
28
37
|
const env: {
|
|
29
|
-
${
|
|
38
|
+
${serverFields}
|
|
30
39
|
}
|
|
31
40
|
export { env }
|
|
32
41
|
export default env
|
|
@@ -39,27 +48,26 @@ ${zodShapeToTsFields(serverKeys)}
|
|
|
39
48
|
throw new Error(`[vite-env] Failed to write vite-env.d.ts to ${root}. Check file permissions.`, { cause: e });
|
|
40
49
|
}
|
|
41
50
|
}
|
|
42
|
-
function
|
|
51
|
+
function keysToTsFields(keys) {
|
|
52
|
+
return keys.map((key) => ` readonly ${key}: string`).join("\n");
|
|
53
|
+
}
|
|
54
|
+
function zodShapeToTsFields(z, shape) {
|
|
43
55
|
return Object.entries(shape).map(([key, schema]) => {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
return ` readonly ${key}${isOptional(s) ? "?" : ""}: ${tsType}`;
|
|
56
|
+
const tsType = zodToTs(z, schema);
|
|
57
|
+
return ` readonly ${key}${schema instanceof z.ZodOptional ? "?" : ""}: ${tsType}`;
|
|
47
58
|
}).join("\n");
|
|
48
59
|
}
|
|
49
|
-
function zodToTs(schema) {
|
|
50
|
-
if (schema instanceof z.ZodOptional) return zodToTs(schema.unwrap());
|
|
51
|
-
if (schema instanceof z.ZodDefault) return zodToTs(schema.def.innerType);
|
|
60
|
+
function zodToTs(z, schema) {
|
|
61
|
+
if (schema instanceof z.ZodOptional) return zodToTs(z, schema.unwrap());
|
|
62
|
+
if (schema instanceof z.ZodDefault) return zodToTs(z, schema.def.innerType);
|
|
52
63
|
if (schema instanceof z.ZodString) return "string";
|
|
53
64
|
if (schema instanceof z.ZodNumber) return "number";
|
|
54
65
|
if (schema instanceof z.ZodBoolean) return "boolean";
|
|
55
66
|
if (schema instanceof z.ZodEnum) return schema.options.map((o) => `'${o}'`).join(" | ");
|
|
56
|
-
if (schema instanceof z.ZodPipe) return zodToTs(schema.def.out);
|
|
67
|
+
if (schema instanceof z.ZodPipe) return zodToTs(z, schema.def.out);
|
|
57
68
|
return "string";
|
|
58
69
|
}
|
|
59
|
-
function isOptional(schema) {
|
|
60
|
-
return schema instanceof z.ZodOptional;
|
|
61
|
-
}
|
|
62
70
|
//#endregion
|
|
63
|
-
export { generateDts };
|
|
71
|
+
export { generateDts, generateStandardDts };
|
|
64
72
|
|
|
65
73
|
//# sourceMappingURL=dts.mjs.map
|
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 } from './types'\nimport fs from 'node:fs/promises'\nimport path from 'node:path'\
|
|
1
|
+
{"version":3,"file":"dts.mjs","names":[],"sources":["../src/dts.ts"],"sourcesContent":["// @env node\nimport type { EnvDefinition, StandardEnvDefinition } from './types'\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(\n def: EnvDefinition,\n root: string,\n): Promise<void> {\n const { z } = await import('zod')\n\n const clientFields = zodShapeToTsFields(z, { ...def.client })\n const serverFields = zodShapeToTsFields(z, { ...def.server, ...def.client })\n\n await writeDts(root, clientFields, serverFields)\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(\n def: StandardEnvDefinition,\n root: string,\n): 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\nasync function writeDts(\n root: string,\n clientFields: string,\n serverFields: string,\n tag = '',\n): Promise<void> {\n const header = tag\n ? `// Auto-generated by @vite-env/core ${tag}\\n// Do not edit manually — re-generated on every dev server start and build\\n// Tip: for richer types, use defineEnv() with Zod instead of defineStandardEnv()`\n : `// Auto-generated by @vite-env/core\\n// Do not edit manually — re-generated on every dev server start and build`\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 }\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\n .map(key => ` readonly ${key}: string`)\n .join('\\n')\n}\n\nfunction zodShapeToTsFields(z: any, shape: Record<string, unknown>): string {\n return Object.entries(shape)\n .map(([key, schema]) => {\n const tsType = zodToTs(z, schema)\n const optional = schema instanceof z.ZodOptional\n return ` readonly ${key}${optional ? '?' : ''}: ${tsType}`\n })\n .join('\\n')\n}\n\nfunction zodToTs(z: any, schema: any): string {\n if (schema instanceof z.ZodOptional)\n return zodToTs(z, schema.unwrap())\n if (schema instanceof z.ZodDefault)\n return zodToTs(z, schema.def.innerType)\n if (schema instanceof z.ZodString)\n return 'string'\n if (schema instanceof z.ZodNumber)\n return 'number'\n if (schema instanceof z.ZodBoolean)\n return 'boolean'\n if (schema instanceof z.ZodEnum)\n return (schema.options as string[]).map(o => `'${o}'`).join(' | ')\n if (schema instanceof z.ZodPipe)\n return zodToTs(z, schema.def.out)\n return 'string'\n}\n"],"mappings":";;;;;;;;AAUA,eAAsB,YACpB,KACA,MACe;CACf,MAAM,EAAE,MAAM,MAAM,OAAO;AAK3B,OAAM,SAAS,MAHM,mBAAmB,GAAG,EAAE,GAAG,IAAI,QAAQ,CAAC,EACxC,mBAAmB,GAAG;EAAE,GAAG,IAAI;EAAQ,GAAG,IAAI;EAAQ,CAAC,CAE5B;;;;;;AAOlD,eAAsB,oBACpB,KACA,MACe;CACf,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,WAAW,EAC1B,eAAe,WAAW,EAEE,oBAAoB;;AAGvE,eAAe,SACb,MACA,cACA,cACA,MAAM,IACS;CAKf,MAAM,MAAM,GAJG,MACX,uCAAuC,IAAI,mKAC3C,kHAEkB;;;;EAItB,aAAa;;;;;;;;EAQb,aAAa;;;;;;CAOb,MAAM,WAAW,KAAK,KAAK,MAAM,gBAAgB;AACjD,KAAI;AACF,QAAM,GAAG,UAAU,UAAU,KAAK,QAAQ;UAErC,GAAG;AACR,QAAM,IAAI,MACR,+CAA+C,KAAK,4BACpD,EAAE,OAAO,GAAG,CACb;;;AAIL,SAAS,eAAe,MAAwB;AAC9C,QAAO,KACJ,KAAI,QAAO,gBAAgB,IAAI,UAAU,CACzC,KAAK,KAAK;;AAGf,SAAS,mBAAmB,GAAQ,OAAwC;AAC1E,QAAO,OAAO,QAAQ,MAAM,CACzB,KAAK,CAAC,KAAK,YAAY;EACtB,MAAM,SAAS,QAAQ,GAAG,OAAO;AAEjC,SAAO,gBAAgB,MADN,kBAAkB,EAAE,cACG,MAAM,GAAG,IAAI;GACrD,CACD,KAAK,KAAK;;AAGf,SAAS,QAAQ,GAAQ,QAAqB;AAC5C,KAAI,kBAAkB,EAAE,YACtB,QAAO,QAAQ,GAAG,OAAO,QAAQ,CAAC;AACpC,KAAI,kBAAkB,EAAE,WACtB,QAAO,QAAQ,GAAG,OAAO,IAAI,UAAU;AACzC,KAAI,kBAAkB,EAAE,UACtB,QAAO;AACT,KAAI,kBAAkB,EAAE,UACtB,QAAO;AACT,KAAI,kBAAkB,EAAE,WACtB,QAAO;AACT,KAAI,kBAAkB,EAAE,QACtB,QAAQ,OAAO,QAAqB,KAAI,MAAK,IAAI,EAAE,GAAG,CAAC,KAAK,MAAM;AACpE,KAAI,kBAAkB,EAAE,QACtB,QAAO,QAAQ,GAAG,OAAO,IAAI,IAAI;AACnC,QAAO"}
|
package/dist/format.cjs
CHANGED
|
@@ -5,7 +5,13 @@ function formatZodError(issues) {
|
|
|
5
5
|
return ` \x1B[31m✗\x1B[0m ${(issue.path.length > 0 ? issue.path.join(".") : "(root)").padEnd(28)} ${issue.message}`;
|
|
6
6
|
}).join("\n");
|
|
7
7
|
}
|
|
8
|
+
function formatStandardSchemaError(issues) {
|
|
9
|
+
return issues.map((issue) => {
|
|
10
|
+
return ` \x1B[31m✗\x1B[0m ${(issue.path.length > 0 ? issue.path.map((seg) => typeof seg === "object" && seg !== null && "key" in seg ? String(seg.key) : String(seg)).join(".") : "(root)").padEnd(28)} ${issue.message}`;
|
|
11
|
+
}).join("\n");
|
|
12
|
+
}
|
|
8
13
|
//#endregion
|
|
14
|
+
exports.formatStandardSchemaError = formatStandardSchemaError;
|
|
9
15
|
exports.formatZodError = formatZodError;
|
|
10
16
|
|
|
11
17
|
//# sourceMappingURL=format.cjs.map
|
package/dist/format.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.cjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["import type { core } from 'zod'\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"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"format.cjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["import type { core } from 'zod'\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 = issue.path.length > 0\n ? issue.path.map(seg => typeof seg === 'object' && seg !== null && 'key' in seg ? String(seg.key) : String(seg)).join('.')\n : '(root)'\n return ` \\x1B[31m✗\\x1B[0m ${path.padEnd(28)} ${issue.message}`\n })\n .join('\\n')\n}\n"],"mappings":";;AAGA,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;AAId,SAAO,uBAHM,MAAM,KAAK,SAAS,IAC7B,MAAM,KAAK,KAAI,QAAO,OAAO,QAAQ,YAAY,QAAQ,QAAQ,SAAS,MAAM,OAAO,IAAI,IAAI,GAAG,OAAO,IAAI,CAAC,CAAC,KAAK,IAAI,GACxH,UAC8B,OAAO,GAAG,CAAC,GAAG,MAAM;GACtD,CACD,KAAK,KAAK"}
|
package/dist/format.d.cts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { o as StandardValidationIssue } from "./types-1okexcwM.cjs";
|
|
1
2
|
import { core } from "zod";
|
|
2
3
|
|
|
3
4
|
//#region src/format.d.ts
|
|
4
5
|
declare function formatZodError(issues: core.$ZodIssue[]): string;
|
|
6
|
+
declare function formatStandardSchemaError(issues: StandardValidationIssue[]): string;
|
|
5
7
|
//#endregion
|
|
6
|
-
export { formatZodError };
|
|
8
|
+
export { formatStandardSchemaError, formatZodError };
|
|
7
9
|
//# sourceMappingURL=format.d.cts.map
|
package/dist/format.d.mts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { o as StandardValidationIssue } from "./types-DuWT_251.mjs";
|
|
1
2
|
import { core } from "zod";
|
|
2
3
|
|
|
3
4
|
//#region src/format.d.ts
|
|
4
5
|
declare function formatZodError(issues: core.$ZodIssue[]): string;
|
|
6
|
+
declare function formatStandardSchemaError(issues: StandardValidationIssue[]): string;
|
|
5
7
|
//#endregion
|
|
6
|
-
export { formatZodError };
|
|
8
|
+
export { formatStandardSchemaError, formatZodError };
|
|
7
9
|
//# sourceMappingURL=format.d.mts.map
|
package/dist/format.mjs
CHANGED
|
@@ -4,7 +4,12 @@ function formatZodError(issues) {
|
|
|
4
4
|
return ` \x1B[31m✗\x1B[0m ${(issue.path.length > 0 ? issue.path.join(".") : "(root)").padEnd(28)} ${issue.message}`;
|
|
5
5
|
}).join("\n");
|
|
6
6
|
}
|
|
7
|
+
function formatStandardSchemaError(issues) {
|
|
8
|
+
return issues.map((issue) => {
|
|
9
|
+
return ` \x1B[31m✗\x1B[0m ${(issue.path.length > 0 ? issue.path.map((seg) => typeof seg === "object" && seg !== null && "key" in seg ? String(seg.key) : String(seg)).join(".") : "(root)").padEnd(28)} ${issue.message}`;
|
|
10
|
+
}).join("\n");
|
|
11
|
+
}
|
|
7
12
|
//#endregion
|
|
8
|
-
export { formatZodError };
|
|
13
|
+
export { formatStandardSchemaError, formatZodError };
|
|
9
14
|
|
|
10
15
|
//# sourceMappingURL=format.mjs.map
|
package/dist/format.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.mjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["import type { core } from 'zod'\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"],"mappings":";
|
|
1
|
+
{"version":3,"file":"format.mjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["import type { core } from 'zod'\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 = issue.path.length > 0\n ? issue.path.map(seg => typeof seg === 'object' && seg !== null && 'key' in seg ? String(seg.key) : String(seg)).join('.')\n : '(root)'\n return ` \\x1B[31m✗\\x1B[0m ${path.padEnd(28)} ${issue.message}`\n })\n .join('\\n')\n}\n"],"mappings":";AAGA,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;AAId,SAAO,uBAHM,MAAM,KAAK,SAAS,IAC7B,MAAM,KAAK,KAAI,QAAO,OAAO,QAAQ,YAAY,QAAQ,QAAQ,SAAS,MAAM,OAAO,IAAI,IAAI,GAAG,OAAO,IAAI,CAAC,CAAC,KAAK,IAAI,GACxH,UAC8B,OAAO,GAAG,CAAC,GAAG,MAAM;GACtD,CACD,KAAK,KAAK"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("./dts-DF71HNdJ.cjs");
|
|
3
2
|
const require_schema = require("./schema.cjs");
|
|
4
|
-
|
|
3
|
+
const require_standard = require("./standard.cjs");
|
|
5
4
|
exports.defineEnv = require_schema.defineEnv;
|
|
6
|
-
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function() {
|
|
9
|
-
return zod.z;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
5
|
+
exports.defineStandardEnv = require_standard.defineStandardEnv;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { a as StandardEnvDefinition, i as InferServerEnv, n as EnvDefinition, r as InferClientEnv, t as AnyEnvDefinition } from "./types-1okexcwM.cjs";
|
|
2
2
|
import { defineEnv } from "./schema.cjs";
|
|
3
|
-
import {
|
|
4
|
-
export { type EnvDefinition, type InferClientEnv, type InferServerEnv, defineEnv,
|
|
3
|
+
import { defineStandardEnv } from "./standard.cjs";
|
|
4
|
+
export { type AnyEnvDefinition, type EnvDefinition, type InferClientEnv, type InferServerEnv, type StandardEnvDefinition, defineEnv, defineStandardEnv };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { a as StandardEnvDefinition, i as InferServerEnv, n as EnvDefinition, r as InferClientEnv, t as AnyEnvDefinition } from "./types-DuWT_251.mjs";
|
|
2
2
|
import { defineEnv } from "./schema.mjs";
|
|
3
|
-
import {
|
|
4
|
-
export { type EnvDefinition, type InferClientEnv, type InferServerEnv, defineEnv,
|
|
3
|
+
import { defineStandardEnv } from "./standard.mjs";
|
|
4
|
+
export { type AnyEnvDefinition, type EnvDefinition, type InferClientEnv, type InferServerEnv, type StandardEnvDefinition, defineEnv, defineStandardEnv };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { defineEnv } from "./schema.mjs";
|
|
2
|
-
import {
|
|
3
|
-
export { defineEnv,
|
|
2
|
+
import { defineStandardEnv } from "./standard.mjs";
|
|
3
|
+
export { defineEnv, defineStandardEnv };
|
package/dist/leak.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"leak.cjs","names":[],"sources":["../src/leak.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"leak.cjs","names":[],"sources":["../src/leak.ts"],"sourcesContent":["import type { AnyEnvDefinition } from './types'\n\ninterface 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])\n && typeof entry[1] === 'string'\n && 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])\n && typeof entry[1] === 'string'\n && 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,IACrB,OAAO,MAAM,OAAO,YACpB,MAAM,GAAG,SAAS,EACxB;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,IACrB,OAAO,MAAM,OAAO,YACpB,MAAM,GAAG,UAAU,EACzB;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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as AnyEnvDefinition } from "./types-1okexcwM.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/leak.d.ts
|
|
4
4
|
interface LeakReport {
|
|
@@ -13,7 +13,7 @@ interface LeakReport {
|
|
|
13
13
|
* appears as a literal string in any output chunk's source code.
|
|
14
14
|
* Short/common values (< 8 chars) are skipped to avoid false positives.
|
|
15
15
|
*/
|
|
16
|
-
declare function detectServerLeak(def:
|
|
16
|
+
declare function detectServerLeak(def: AnyEnvDefinition, data: Record<string, unknown>, bundle: Record<string, {
|
|
17
17
|
type: string;
|
|
18
18
|
code?: string;
|
|
19
19
|
}>, onSkipped?: (keys: string[]) => void): LeakReport[];
|
package/dist/leak.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as AnyEnvDefinition } from "./types-DuWT_251.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/leak.d.ts
|
|
4
4
|
interface LeakReport {
|
|
@@ -13,7 +13,7 @@ interface LeakReport {
|
|
|
13
13
|
* appears as a literal string in any output chunk's source code.
|
|
14
14
|
* Short/common values (< 8 chars) are skipped to avoid false positives.
|
|
15
15
|
*/
|
|
16
|
-
declare function detectServerLeak(def:
|
|
16
|
+
declare function detectServerLeak(def: AnyEnvDefinition, data: Record<string, unknown>, bundle: Record<string, {
|
|
17
17
|
type: string;
|
|
18
18
|
code?: string;
|
|
19
19
|
}>, onSkipped?: (keys: string[]) => void): LeakReport[];
|
package/dist/leak.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"leak.mjs","names":[],"sources":["../src/leak.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"leak.mjs","names":[],"sources":["../src/leak.ts"],"sourcesContent":["import type { AnyEnvDefinition } from './types'\n\ninterface 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])\n && typeof entry[1] === 'string'\n && 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])\n && typeof entry[1] === 'string'\n && 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,IACrB,OAAO,MAAM,OAAO,YACpB,MAAM,GAAG,SAAS,EACxB;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,IACrB,OAAO,MAAM,OAAO,YACpB,MAAM,GAAG,UAAU,EACzB;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/plugin.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_dts = require("./dts-
|
|
2
|
-
const
|
|
1
|
+
const require_dts = require("./dts-BgHTl6hC.cjs");
|
|
2
|
+
const require_standard = require("./standard.cjs");
|
|
3
3
|
const require_config = require("./config.cjs");
|
|
4
4
|
const require_format = require("./format.cjs");
|
|
5
5
|
const require_leak = require("./leak.cjs");
|
|
@@ -50,6 +50,23 @@ export default env;`
|
|
|
50
50
|
}
|
|
51
51
|
//#endregion
|
|
52
52
|
//#region src/plugin.ts
|
|
53
|
+
/**
|
|
54
|
+
* Validates environment variables against the definition.
|
|
55
|
+
* Routes to Zod or Standard Schema path based on definition type.
|
|
56
|
+
* Zod modules are loaded dynamically to avoid requiring zod for Standard Schema users.
|
|
57
|
+
*/
|
|
58
|
+
async function validateAndFormat(def, rawEnv) {
|
|
59
|
+
if (require_standard.isStandardEnvDefinition(def)) {
|
|
60
|
+
const result = await require_standard.validateStandardEnv(def, rawEnv);
|
|
61
|
+
if (!result.success) return { error: require_format.formatStandardSchemaError(result.errors) };
|
|
62
|
+
return { data: result.data };
|
|
63
|
+
}
|
|
64
|
+
const { validateEnv } = await Promise.resolve().then(() => require("./schema.cjs"));
|
|
65
|
+
const { formatZodError } = await Promise.resolve().then(() => require("./format.cjs"));
|
|
66
|
+
const result = validateEnv(def, rawEnv);
|
|
67
|
+
if (!result.success) return { error: formatZodError(result.errors) };
|
|
68
|
+
return { data: result.data };
|
|
69
|
+
}
|
|
53
70
|
function ViteEnv(options = {}) {
|
|
54
71
|
let resolvedConfig;
|
|
55
72
|
let envDefinition;
|
|
@@ -68,14 +85,15 @@ function ViteEnv(options = {}) {
|
|
|
68
85
|
},
|
|
69
86
|
async buildStart() {
|
|
70
87
|
const rawEnv = await loadEnvSources(resolvedConfig);
|
|
71
|
-
const result =
|
|
72
|
-
if (
|
|
73
|
-
const formatted = require_format.formatZodError(result.errors);
|
|
74
|
-
throw new Error(`[vite-env] Environment validation failed:\n\n${formatted}`);
|
|
75
|
-
}
|
|
88
|
+
const result = await validateAndFormat(envDefinition, rawEnv);
|
|
89
|
+
if ("error" in result) throw new Error(`[vite-env] Environment validation failed:\n\n${result.error}`);
|
|
76
90
|
lastValidated = result.data;
|
|
77
|
-
await require_dts.
|
|
78
|
-
|
|
91
|
+
if (require_standard.isStandardEnvDefinition(envDefinition)) await require_dts.generateStandardDts(envDefinition, resolvedConfig.root);
|
|
92
|
+
else {
|
|
93
|
+
const { generateDts } = await Promise.resolve().then(() => require("./dts.cjs"));
|
|
94
|
+
await generateDts(envDefinition, resolvedConfig.root);
|
|
95
|
+
}
|
|
96
|
+
const count = Object.keys(lastValidated).length;
|
|
79
97
|
resolvedConfig.logger.info(` \x1B[32m✓\x1B[0m \x1B[36m[vite-env]\x1B[0m ${count} variables validated`);
|
|
80
98
|
},
|
|
81
99
|
resolveId(id) {
|
|
@@ -106,10 +124,9 @@ function ViteEnv(options = {}) {
|
|
|
106
124
|
debounceTimer = setTimeout(async () => {
|
|
107
125
|
try {
|
|
108
126
|
const rawEnv = await loadEnvSources(resolvedConfig);
|
|
109
|
-
const result =
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
resolvedConfig.logger.warn(`\n \x1B[33m⚠\x1B[0m \x1B[36m[vite-env]\x1B[0m Env revalidation failed:\n${formatted}`);
|
|
127
|
+
const result = await validateAndFormat(envDefinition, rawEnv);
|
|
128
|
+
if ("error" in result) {
|
|
129
|
+
resolvedConfig.logger.warn(`\n \x1B[33m⚠\x1B[0m \x1B[36m[vite-env]\x1B[0m Env revalidation failed:\n${result.error}`);
|
|
113
130
|
return;
|
|
114
131
|
}
|
|
115
132
|
lastValidated = result.data;
|