@vite-env/core 0.5.4 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -17
- 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 +1 -1
- 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 +11 -10
- package/dist/leak.cjs.map +1 -1
- package/dist/leak.d.cts +4 -7
- package/dist/leak.d.mts +4 -7
- package/dist/leak.mjs +11 -10
- 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 +1 -1
- package/dist/presets/index.cjs.map +1 -1
- package/dist/presets/index.mjs.map +1 -1
- package/dist/schema.cjs +1 -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.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-B61nsO8q.d.cts → types-Ctg8aeXQ.d.mts} +4 -4
- package/dist/{types-KniR_Oqf.d.mts → types-DudMh278.d.cts} +4 -4
- package/package.json +47 -36
- package/dist/dts-BX0Cnqo-.cjs +0 -139
- package/dist/dts-BX0Cnqo-.cjs.map +0 -1
package/dist/schema.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.mjs","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import type { EnvDefinition, EnvPreset, ValidationResult } from
|
|
1
|
+
{"version":3,"file":"schema.mjs","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import type { EnvDefinition, EnvPreset, ValidationResult } from \"./types\";\nimport { z } from \"zod\";\n\ntype DefineEnvInput = {\n presets?: EnvPreset[];\n} & EnvDefinition;\n\nfunction warnSideConflicts(\n keys: string[],\n seen: Set<string>,\n userKeys: Set<string>,\n side: \"server\" | \"client\",\n): void {\n for (const key of keys) {\n const duplicate = seen.has(key);\n if (duplicate)\n console.warn(`[vite-env] \"${key}\" is defined in multiple presets. The last preset wins.`);\n seen.add(key);\n if (!duplicate && userKeys.has(key))\n console.warn(\n `[vite-env] \"${key}\" is defined in both a preset and your ${side} config. Your definition wins.`,\n );\n }\n}\n\nfunction warnConflicts(\n presets: EnvPreset[],\n userServerKeys: Set<string>,\n userClientKeys: Set<string>,\n): void {\n const seenServerKeys = new Set<string>();\n const seenClientKeys = new Set<string>();\n\n for (const preset of presets) {\n warnSideConflicts(Object.keys(preset.server ?? {}), seenServerKeys, userServerKeys, \"server\");\n warnSideConflicts(Object.keys(preset.client ?? {}), seenClientKeys, userClientKeys, \"client\");\n }\n}\n\nexport function defineEnv<T extends DefineEnvInput>(\n definition: T,\n): Omit<T, \"presets\"> & Pick<EnvDefinition, \"server\" | \"client\" | \"presets\"> {\n const { presets = [], server, client, ...rest } = definition;\n // ...rest intentionally forwarded — T may carry extra keys beyond EnvDefinition\n\n const mergedServer: z.ZodRawShape = Object.assign(\n {},\n ...presets.map((p) => p.server ?? {}),\n server,\n );\n const mergedClient: z.ZodRawShape = Object.assign(\n {},\n ...presets.map((p) => p.client ?? {}),\n client,\n );\n\n warnConflicts(presets, new Set(Object.keys(server ?? {})), new Set(Object.keys(client ?? {})));\n\n for (const key of Object.keys(mergedClient)) {\n if (!key.startsWith(\"VITE_\")) {\n throw new Error(\n `[vite-env] Client env var \"${key}\" must be prefixed with VITE_.\\n` +\n ` Rename it to \"VITE_${key}\" or move it to \"server\" if it's secret.`,\n );\n }\n }\n\n const result: Record<string, unknown> = { ...rest };\n if (Object.keys(mergedServer).length > 0 || server !== undefined) result.server = mergedServer;\n if (Object.keys(mergedClient).length > 0 || client !== undefined) result.client = mergedClient;\n if (presets.length > 0) result.presets = presets;\n\n return result as Omit<T, \"presets\"> & Pick<EnvDefinition, \"presets\">;\n}\n\nexport function validateEnv(def: EnvDefinition, rawEnv: Record<string, string>): ValidationResult {\n const combinedShape: Record<string, z.ZodType> = {\n ...def.server,\n ...def.client,\n } as Record<string, z.ZodType>;\n\n // Undetected-platform preset vars validate as optional — they only exist on\n // the platform; requiring them would break local dev. User overrides stay strict.\n // Mutating combinedShape also prevents double-wrapping when two undetected\n // presets share a key: after the first wrap, the identity check fails.\n for (const preset of def.presets ?? []) {\n if (!preset.detect || preset.detect(rawEnv)) continue;\n for (const side of [preset.server, preset.client]) {\n for (const [key, presetSchema] of Object.entries(side ?? {})) {\n if (combinedShape[key] === presetSchema)\n combinedShape[key] = z.optional(combinedShape[key]);\n }\n }\n }\n\n const schema = z.object(combinedShape);\n const result = schema.safeParse(rawEnv);\n\n if (result.success) {\n return { success: true, data: result.data, errors: [] as const };\n }\n\n return {\n success: false,\n data: null,\n errors: result.error.issues,\n };\n}\n"],"mappings":";;AAOA,SAAS,kBACP,MACA,MACA,UACA,MACM;AACN,MAAK,MAAM,OAAO,MAAM;EACtB,MAAM,YAAY,KAAK,IAAI,IAAI;AAC/B,MAAI,UACF,SAAQ,KAAK,eAAe,IAAI,yDAAyD;AAC3F,O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,KAAoB,QAAkD;CAChG,MAAM,gBAA2C;EAC/C,GAAG,IAAI;EACP,GAAG,IAAI;EACR;AAMD,MAAK,MAAM,UAAU,IAAI,WAAW,EAAE,EAAE;AACtC,MAAI,CAAC,OAAO,UAAU,OAAO,OAAO,OAAO,CAAE;AAC7C,OAAK,MAAM,QAAQ,CAAC,OAAO,QAAQ,OAAO,OAAO,CAC/C,MAAK,MAAM,CAAC,KAAK,iBAAiB,OAAO,QAAQ,QAAQ,EAAE,CAAC,CAC1D,KAAI,cAAc,SAAS,aACzB,eAAc,OAAO,EAAE,SAAS,cAAc,KAAK;;CAM3D,MAAM,SADS,EAAE,OAAO,cACH,CAAC,UAAU,OAAO;AAEvC,KAAI,OAAO,QACT,QAAO;EAAE,SAAS;EAAM,MAAM,OAAO;EAAM,QAAQ,EAAE;EAAW;AAGlE,QAAO;EACL,SAAS;EACT,MAAM;EACN,QAAQ,OAAO,MAAM;EACtB"}
|
package/dist/standard.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard.cjs","names":[],"sources":["../src/standard.ts"],"sourcesContent":["import type { StandardSchemaV1 } from
|
|
1
|
+
{"version":3,"file":"standard.cjs","names":[],"sources":["../src/standard.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type {\n StandardEnvDefinition,\n StandardValidationIssue,\n StandardValidationResult,\n} from \"./types\";\n\nexport function defineStandardEnv<T extends Omit<StandardEnvDefinition, \"_standard\">>(\n definition: T,\n): T & { readonly _standard: true } {\n if (definition.client) {\n for (const key of Object.keys(definition.client)) {\n if (!key.startsWith(\"VITE_\")) {\n throw new Error(\n `[vite-env] Client env var \"${key}\" must be prefixed with VITE_.\\n` +\n ` Rename it to \"VITE_${key}\" or move it to \"server\" if it's secret.`,\n );\n }\n }\n }\n\n return { ...definition, _standard: true as const };\n}\n\nexport function isStandardEnvDefinition(def: unknown): def is StandardEnvDefinition {\n return (\n def != null &&\n typeof def === \"object\" &&\n \"_standard\" in def &&\n (def as Record<string, unknown>)._standard === true\n );\n}\n\nexport async function validateStandardEnv(\n def: StandardEnvDefinition,\n rawEnv: Record<string, string>,\n): Promise<StandardValidationResult> {\n const combinedShape: Record<string, StandardSchemaV1> = {\n ...def.server,\n ...def.client,\n };\n\n const errors: StandardValidationIssue[] = [];\n const data: Record<string, unknown> = {};\n\n for (const [key, schema] of Object.entries(combinedShape)) {\n const result = await schema[\"~standard\"].validate(rawEnv[key]);\n\n if (\"issues\" in result && result.issues) {\n for (const issue of result.issues) {\n errors.push({\n message: issue.message,\n path: [key, ...(issue.path ?? [])],\n });\n }\n } else {\n data[key] = (result as { value: unknown }).value;\n }\n }\n\n if (errors.length > 0) {\n return { success: false, data: null, errors };\n }\n\n return { success: true, data, errors: [] as const };\n}\n"],"mappings":";;AAOA,SAAgB,kBACd,YACkC;AAClC,KAAI,WAAW;OACR,MAAM,OAAO,OAAO,KAAK,WAAW,OAAO,CAC9C,KAAI,CAAC,IAAI,WAAW,QAAQ,CAC1B,OAAM,IAAI,MACR,8BAA8B,IAAI,uDACR,IAAI,0CAC/B;;AAKP,QAAO;EAAE,GAAG;EAAY,WAAW;EAAe;;AAGpD,SAAgB,wBAAwB,KAA4C;AAClF,QACE,OAAO,QACP,OAAO,QAAQ,YACf,eAAe,OACd,IAAgC,cAAc;;AAInD,eAAsB,oBACpB,KACA,QACmC;CACnC,MAAM,gBAAkD;EACtD,GAAG,IAAI;EACP,GAAG,IAAI;EACR;CAED,MAAM,SAAoC,EAAE;CAC5C,MAAM,OAAgC,EAAE;AAExC,MAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,cAAc,EAAE;EACzD,MAAM,SAAS,MAAM,OAAO,aAAa,SAAS,OAAO,KAAK;AAE9D,MAAI,YAAY,UAAU,OAAO,OAC/B,MAAK,MAAM,SAAS,OAAO,OACzB,QAAO,KAAK;GACV,SAAS,MAAM;GACf,MAAM,CAAC,KAAK,GAAI,MAAM,QAAQ,EAAE,CAAE;GACnC,CAAC;MAGJ,MAAK,OAAQ,OAA8B;;AAI/C,KAAI,OAAO,SAAS,EAClB,QAAO;EAAE,SAAS;EAAO,MAAM;EAAM;EAAQ;AAG/C,QAAO;EAAE,SAAS;EAAM;EAAM,QAAQ,EAAE;EAAW"}
|
package/dist/standard.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { c as StandardValidationResult, o as StandardEnvDefinition } from "./types-
|
|
1
|
+
import { c as StandardValidationResult, o as StandardEnvDefinition } from "./types-DudMh278.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/standard.d.ts
|
|
4
|
-
declare function defineStandardEnv<T extends Omit<StandardEnvDefinition,
|
|
4
|
+
declare function defineStandardEnv<T extends Omit<StandardEnvDefinition, "_standard">>(definition: T): T & {
|
|
5
5
|
readonly _standard: true;
|
|
6
6
|
};
|
|
7
7
|
declare function isStandardEnvDefinition(def: unknown): def is StandardEnvDefinition;
|
package/dist/standard.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { c as StandardValidationResult, o as StandardEnvDefinition } from "./types-
|
|
1
|
+
import { c as StandardValidationResult, o as StandardEnvDefinition } from "./types-Ctg8aeXQ.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/standard.d.ts
|
|
4
|
-
declare function defineStandardEnv<T extends Omit<StandardEnvDefinition,
|
|
4
|
+
declare function defineStandardEnv<T extends Omit<StandardEnvDefinition, "_standard">>(definition: T): T & {
|
|
5
5
|
readonly _standard: true;
|
|
6
6
|
};
|
|
7
7
|
declare function isStandardEnvDefinition(def: unknown): def is StandardEnvDefinition;
|
package/dist/standard.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard.mjs","names":[],"sources":["../src/standard.ts"],"sourcesContent":["import type { StandardSchemaV1 } from
|
|
1
|
+
{"version":3,"file":"standard.mjs","names":[],"sources":["../src/standard.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type {\n StandardEnvDefinition,\n StandardValidationIssue,\n StandardValidationResult,\n} from \"./types\";\n\nexport function defineStandardEnv<T extends Omit<StandardEnvDefinition, \"_standard\">>(\n definition: T,\n): T & { readonly _standard: true } {\n if (definition.client) {\n for (const key of Object.keys(definition.client)) {\n if (!key.startsWith(\"VITE_\")) {\n throw new Error(\n `[vite-env] Client env var \"${key}\" must be prefixed with VITE_.\\n` +\n ` Rename it to \"VITE_${key}\" or move it to \"server\" if it's secret.`,\n );\n }\n }\n }\n\n return { ...definition, _standard: true as const };\n}\n\nexport function isStandardEnvDefinition(def: unknown): def is StandardEnvDefinition {\n return (\n def != null &&\n typeof def === \"object\" &&\n \"_standard\" in def &&\n (def as Record<string, unknown>)._standard === true\n );\n}\n\nexport async function validateStandardEnv(\n def: StandardEnvDefinition,\n rawEnv: Record<string, string>,\n): Promise<StandardValidationResult> {\n const combinedShape: Record<string, StandardSchemaV1> = {\n ...def.server,\n ...def.client,\n };\n\n const errors: StandardValidationIssue[] = [];\n const data: Record<string, unknown> = {};\n\n for (const [key, schema] of Object.entries(combinedShape)) {\n const result = await schema[\"~standard\"].validate(rawEnv[key]);\n\n if (\"issues\" in result && result.issues) {\n for (const issue of result.issues) {\n errors.push({\n message: issue.message,\n path: [key, ...(issue.path ?? [])],\n });\n }\n } else {\n data[key] = (result as { value: unknown }).value;\n }\n }\n\n if (errors.length > 0) {\n return { success: false, data: null, errors };\n }\n\n return { success: true, data, errors: [] as const };\n}\n"],"mappings":";AAOA,SAAgB,kBACd,YACkC;AAClC,KAAI,WAAW;OACR,MAAM,OAAO,OAAO,KAAK,WAAW,OAAO,CAC9C,KAAI,CAAC,IAAI,WAAW,QAAQ,CAC1B,OAAM,IAAI,MACR,8BAA8B,IAAI,uDACR,IAAI,0CAC/B;;AAKP,QAAO;EAAE,GAAG;EAAY,WAAW;EAAe;;AAGpD,SAAgB,wBAAwB,KAA4C;AAClF,QACE,OAAO,QACP,OAAO,QAAQ,YACf,eAAe,OACd,IAAgC,cAAc;;AAInD,eAAsB,oBACpB,KACA,QACmC;CACnC,MAAM,gBAAkD;EACtD,GAAG,IAAI;EACP,GAAG,IAAI;EACR;CAED,MAAM,SAAoC,EAAE;CAC5C,MAAM,OAAgC,EAAE;AAExC,MAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,cAAc,EAAE;EACzD,MAAM,SAAS,MAAM,OAAO,aAAa,SAAS,OAAO,KAAK;AAE9D,MAAI,YAAY,UAAU,OAAO,OAC/B,MAAK,MAAM,SAAS,OAAO,OACzB,QAAO,KAAK;GACV,SAAS,MAAM;GACf,MAAM,CAAC,KAAK,GAAI,MAAM,QAAQ,EAAE,CAAE;GACnC,CAAC;MAGJ,MAAK,OAAQ,OAA8B;;AAI/C,KAAI,OAAO,SAAS,EAClB,QAAO;EAAE,SAAS;EAAO,MAAM;EAAM;EAAQ;AAG/C,QAAO;EAAE,SAAS;EAAM;EAAM,QAAQ,EAAE;EAAW"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
1
|
import { z } from "zod";
|
|
2
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
3
|
|
|
4
4
|
//#region src/types.d.ts
|
|
5
5
|
type EnvDefinition = {
|
|
@@ -51,8 +51,8 @@ type StandardValidationResult = {
|
|
|
51
51
|
errors: StandardValidationIssue[];
|
|
52
52
|
};
|
|
53
53
|
type OrEmptyShape<T> = T extends z.ZodRawShape ? T : Record<string, never>;
|
|
54
|
-
type InferClientEnv<T extends EnvDefinition> = z.infer<z.ZodObject<OrEmptyShape<T[
|
|
55
|
-
type InferServerEnv<T extends EnvDefinition> = z.infer<z.ZodObject<OrEmptyShape<T[
|
|
54
|
+
type InferClientEnv<T extends EnvDefinition> = z.infer<z.ZodObject<OrEmptyShape<T["client"]>>>;
|
|
55
|
+
type InferServerEnv<T extends EnvDefinition> = z.infer<z.ZodObject<OrEmptyShape<T["server"]> & OrEmptyShape<T["client"]>>>;
|
|
56
56
|
//#endregion
|
|
57
57
|
export { InferServerEnv as a, StandardValidationResult as c, InferClientEnv as i, ValidationResult as l, EnvDefinition as n, StandardEnvDefinition as o, EnvPreset as r, StandardValidationIssue as s, AnyEnvDefinition as t };
|
|
58
|
-
//# sourceMappingURL=types-
|
|
58
|
+
//# sourceMappingURL=types-Ctg8aeXQ.d.mts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
1
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
import { z } from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/types.d.ts
|
|
5
5
|
type EnvDefinition = {
|
|
@@ -51,8 +51,8 @@ type StandardValidationResult = {
|
|
|
51
51
|
errors: StandardValidationIssue[];
|
|
52
52
|
};
|
|
53
53
|
type OrEmptyShape<T> = T extends z.ZodRawShape ? T : Record<string, never>;
|
|
54
|
-
type InferClientEnv<T extends EnvDefinition> = z.infer<z.ZodObject<OrEmptyShape<T[
|
|
55
|
-
type InferServerEnv<T extends EnvDefinition> = z.infer<z.ZodObject<OrEmptyShape<T[
|
|
54
|
+
type InferClientEnv<T extends EnvDefinition> = z.infer<z.ZodObject<OrEmptyShape<T["client"]>>>;
|
|
55
|
+
type InferServerEnv<T extends EnvDefinition> = z.infer<z.ZodObject<OrEmptyShape<T["server"]> & OrEmptyShape<T["client"]>>>;
|
|
56
56
|
//#endregion
|
|
57
57
|
export { InferServerEnv as a, StandardValidationResult as c, InferClientEnv as i, ValidationResult as l, EnvDefinition as n, StandardEnvDefinition as o, EnvPreset as r, StandardValidationIssue as s, AnyEnvDefinition as t };
|
|
58
|
-
//# sourceMappingURL=types-
|
|
58
|
+
//# sourceMappingURL=types-DudMh278.d.cts.map
|
package/package.json
CHANGED
|
@@ -1,28 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/vitejs/vite-plugin-registry/refs/heads/main/data/schema/extended-package-json.schema.json",
|
|
3
3
|
"name": "@vite-env/core",
|
|
4
|
-
"
|
|
5
|
-
"version": "0.5.4",
|
|
4
|
+
"version": "0.6.1",
|
|
6
5
|
"description": "The env.ts layer for Vite — define once, validate everywhere, import with types",
|
|
7
|
-
"
|
|
6
|
+
"keywords": [
|
|
7
|
+
"dotenv",
|
|
8
|
+
"env",
|
|
9
|
+
"environment-variables",
|
|
10
|
+
"rolldown",
|
|
11
|
+
"standard-schema",
|
|
12
|
+
"typescript",
|
|
13
|
+
"validation",
|
|
14
|
+
"vite",
|
|
15
|
+
"vite-plugin",
|
|
16
|
+
"zod"
|
|
17
|
+
],
|
|
8
18
|
"homepage": "https://github.com/pyyupsk/vite-env#readme",
|
|
19
|
+
"license": "MIT",
|
|
9
20
|
"repository": {
|
|
10
21
|
"type": "git",
|
|
11
22
|
"url": "git+https://github.com/pyyupsk/vite-env.git",
|
|
12
23
|
"directory": "packages/core"
|
|
13
24
|
},
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"environment-variables",
|
|
18
|
-
"env",
|
|
19
|
-
"typescript",
|
|
20
|
-
"zod",
|
|
21
|
-
"validation",
|
|
22
|
-
"rolldown",
|
|
23
|
-
"dotenv",
|
|
24
|
-
"standard-schema"
|
|
25
|
+
"files": [
|
|
26
|
+
"README.md",
|
|
27
|
+
"dist"
|
|
25
28
|
],
|
|
29
|
+
"type": "module",
|
|
30
|
+
"main": "./dist/index.cjs",
|
|
31
|
+
"module": "./dist/index.mjs",
|
|
32
|
+
"types": "./dist/index.d.cts",
|
|
26
33
|
"exports": {
|
|
27
34
|
".": {
|
|
28
35
|
"import": {
|
|
@@ -64,6 +71,16 @@
|
|
|
64
71
|
"default": "./dist/format.cjs"
|
|
65
72
|
}
|
|
66
73
|
},
|
|
74
|
+
"./load": {
|
|
75
|
+
"import": {
|
|
76
|
+
"types": "./dist/load.d.mts",
|
|
77
|
+
"default": "./dist/load.mjs"
|
|
78
|
+
},
|
|
79
|
+
"require": {
|
|
80
|
+
"types": "./dist/load.d.cts",
|
|
81
|
+
"default": "./dist/load.cjs"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
67
84
|
"./leak": {
|
|
68
85
|
"import": {
|
|
69
86
|
"types": "./dist/leak.d.mts",
|
|
@@ -116,35 +133,17 @@
|
|
|
116
133
|
},
|
|
117
134
|
"./package.json": "./package.json"
|
|
118
135
|
},
|
|
119
|
-
"main": "./dist/index.cjs",
|
|
120
|
-
"module": "./dist/index.mjs",
|
|
121
|
-
"types": "./dist/index.d.cts",
|
|
122
|
-
"files": [
|
|
123
|
-
"README.md",
|
|
124
|
-
"dist"
|
|
125
|
-
],
|
|
126
|
-
"engines": {
|
|
127
|
-
"node": ">=20.19.0"
|
|
128
|
-
},
|
|
129
136
|
"scripts": {
|
|
130
137
|
"build": "tsdown",
|
|
131
138
|
"dev": "tsdown --watch",
|
|
132
|
-
"
|
|
139
|
+
"postpack": "bun ../../scripts/rewrite-deps.ts restore",
|
|
140
|
+
"prepack": "bun run build && bun ../../scripts/rewrite-deps.ts rewrite",
|
|
133
141
|
"test": "vitest run",
|
|
134
142
|
"typecheck": "tsc --noEmit"
|
|
135
143
|
},
|
|
136
|
-
"peerDependencies": {
|
|
137
|
-
"vite": ">=8.0.0",
|
|
138
|
-
"zod": "^4.0.0"
|
|
139
|
-
},
|
|
140
|
-
"peerDependenciesMeta": {
|
|
141
|
-
"zod": {
|
|
142
|
-
"optional": true
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
144
|
"dependencies": {
|
|
146
|
-
"@standard-schema/spec": "
|
|
147
|
-
"jiti": "
|
|
145
|
+
"@standard-schema/spec": "^1.1.0",
|
|
146
|
+
"jiti": "^2.6.1"
|
|
148
147
|
},
|
|
149
148
|
"devDependencies": {
|
|
150
149
|
"@types/node": "catalog:dev",
|
|
@@ -154,5 +153,17 @@
|
|
|
154
153
|
"vite": "catalog:dev",
|
|
155
154
|
"vitest": "catalog:dev",
|
|
156
155
|
"zod": "catalog:dev"
|
|
156
|
+
},
|
|
157
|
+
"peerDependencies": {
|
|
158
|
+
"vite": ">=8.0.0",
|
|
159
|
+
"zod": "^4.0.0"
|
|
160
|
+
},
|
|
161
|
+
"peerDependenciesMeta": {
|
|
162
|
+
"zod": {
|
|
163
|
+
"optional": true
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
"engines": {
|
|
167
|
+
"node": ">=20.19.0"
|
|
157
168
|
}
|
|
158
169
|
}
|
package/dist/dts-BX0Cnqo-.cjs
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
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, 1);
|
|
25
|
-
let node_fs_promises = require("node:fs/promises");
|
|
26
|
-
node_fs_promises = __toESM(node_fs_promises, 1);
|
|
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
|
-
const gatedKeys = gatedPresetKeys(def);
|
|
36
|
-
await writeDts(root, zodShapeToTsFields(z, { ...def.client }, gatedKeys), zodShapeToTsFields(z, {
|
|
37
|
-
...def.server,
|
|
38
|
-
...def.client
|
|
39
|
-
}, gatedKeys));
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Detection-gated preset keys (not user-overridden) validate as optional
|
|
43
|
-
* off-platform — typing them required would lie during local dev.
|
|
44
|
-
*/
|
|
45
|
-
function gatedPresetKeys(def) {
|
|
46
|
-
const keys = /* @__PURE__ */ new Set();
|
|
47
|
-
for (const preset of def.presets ?? []) {
|
|
48
|
-
if (!preset.detect) continue;
|
|
49
|
-
for (const side of ["server", "client"]) for (const [key, schema] of Object.entries(preset[side] ?? {})) if (def[side]?.[key] === schema) keys.add(key);
|
|
50
|
-
}
|
|
51
|
-
return keys;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Writes vite-env.d.ts for Standard Schema definitions.
|
|
55
|
-
* All fields are typed as `string` — Standard Schema has no runtime type introspection.
|
|
56
|
-
*/
|
|
57
|
-
async function generateStandardDts(def, root) {
|
|
58
|
-
const clientKeys = Object.keys(def.client ?? {});
|
|
59
|
-
const serverKeys = [...Object.keys(def.server ?? {}), ...clientKeys];
|
|
60
|
-
await writeDts(root, keysToTsFields(clientKeys), keysToTsFields(serverKeys), "(Standard Schema)");
|
|
61
|
-
}
|
|
62
|
-
function buildHeader(tag = "") {
|
|
63
|
-
const lines = [
|
|
64
|
-
"/* oxlint-disable */",
|
|
65
|
-
"/* eslint-disable */",
|
|
66
|
-
"// @ts-nocheck",
|
|
67
|
-
"// biome-ignore-all lint: auto-generated",
|
|
68
|
-
`// Auto-generated by @vite-env/core${tag ? ` ${tag}` : ""}`,
|
|
69
|
-
"// Do not edit manually — re-generated on every dev server start and build"
|
|
70
|
-
];
|
|
71
|
-
if (tag) lines.push("// Tip: for richer types, use defineEnv() with Zod instead of defineStandardEnv()");
|
|
72
|
-
return lines.join("\n");
|
|
73
|
-
}
|
|
74
|
-
async function writeDts(root, clientFields, serverFields, tag = "") {
|
|
75
|
-
const dts = `${buildHeader(tag)}
|
|
76
|
-
|
|
77
|
-
declare module 'virtual:env/client' {
|
|
78
|
-
const env: {
|
|
79
|
-
${clientFields}
|
|
80
|
-
}
|
|
81
|
-
export { env }
|
|
82
|
-
export default env
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
declare module 'virtual:env/server' {
|
|
86
|
-
const env: {
|
|
87
|
-
${serverFields}
|
|
88
|
-
}
|
|
89
|
-
export { env }
|
|
90
|
-
export default env
|
|
91
|
-
}
|
|
92
|
-
`;
|
|
93
|
-
const filePath = node_path.default.join(root, "vite-env.d.ts");
|
|
94
|
-
try {
|
|
95
|
-
await node_fs_promises.default.writeFile(filePath, dts, "utf-8");
|
|
96
|
-
} catch (e) {
|
|
97
|
-
throw new Error(`[vite-env] Failed to write vite-env.d.ts to ${root}. Check file permissions.`, { cause: e });
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
function keysToTsFields(keys) {
|
|
101
|
-
return keys.map((key) => ` readonly ${key}: string`).join("\n");
|
|
102
|
-
}
|
|
103
|
-
function zodShapeToTsFields(z, shape, gatedKeys) {
|
|
104
|
-
return Object.entries(shape).map(([key, schema]) => {
|
|
105
|
-
const tsType = zodToTs(z, schema);
|
|
106
|
-
return ` readonly ${key}${schema instanceof z.ZodOptional || gatedKeys.has(key) ? "?" : ""}: ${tsType}`;
|
|
107
|
-
}).join("\n");
|
|
108
|
-
}
|
|
109
|
-
function zodToTs(z, schema) {
|
|
110
|
-
if (schema instanceof z.ZodOptional) return zodToTs(z, schema.unwrap());
|
|
111
|
-
if (schema instanceof z.ZodDefault) return zodToTs(z, schema.def.innerType);
|
|
112
|
-
if (schema instanceof z.ZodString) return "string";
|
|
113
|
-
if (schema instanceof z.ZodNumber) return "number";
|
|
114
|
-
if (schema instanceof z.ZodBoolean) return "boolean";
|
|
115
|
-
if (schema instanceof z.ZodEnum) return schema.options.map((o) => `'${o}'`).join(" | ");
|
|
116
|
-
if (schema instanceof z.ZodPipe) return zodToTs(z, schema.def.out);
|
|
117
|
-
return "string";
|
|
118
|
-
}
|
|
119
|
-
//#endregion
|
|
120
|
-
Object.defineProperty(exports, "__toESM", {
|
|
121
|
-
enumerable: true,
|
|
122
|
-
get: function() {
|
|
123
|
-
return __toESM;
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
Object.defineProperty(exports, "generateDts", {
|
|
127
|
-
enumerable: true,
|
|
128
|
-
get: function() {
|
|
129
|
-
return generateDts;
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
Object.defineProperty(exports, "generateStandardDts", {
|
|
133
|
-
enumerable: true,
|
|
134
|
-
get: function() {
|
|
135
|
-
return generateStandardDts;
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
//# sourceMappingURL=dts-BX0Cnqo-.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dts-BX0Cnqo-.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(\n def: EnvDefinition,\n root: string,\n): 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)\n 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)\n 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(\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\nfunction buildHeader(tag = ''): string {\n const lines = [\n '/* oxlint-disable */',\n '/* eslint-disable */',\n '// @ts-nocheck',\n '// biome-ignore-all lint: auto-generated',\n `// Auto-generated by @vite-env/core${tag ? ` ${tag}` : ''}`,\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 }\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: typeof ZodNs, shape: Record<string, unknown>, gatedKeys: Set<string>): 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)\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,eAAsB,YACpB,KACA,MACe;CACf,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,E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