@arkenv/vite-plugin 0.0.23 → 0.0.24
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/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let e=require(`arkenv`),t=require(`vite`);function n(n){return{name:`@arkenv/vite-plugin`,config(r,{mode:i}){let a=r.envPrefix??`VITE_`,o=Array.isArray(a)?a:[a],s=(0,e.createEnv)(n,{env:(0,t.loadEnv)(i,process.cwd(),``)}),c=Object.fromEntries(Object.entries(s).filter(([e])=>o.some(t=>e.startsWith(t))));return{define:Object.fromEntries(Object.entries(c).map(([e,t])=>[`import.meta.env.${e}`,JSON.stringify(t)]))}}}}module.exports=n;
|
|
1
|
+
let e=require(`arkenv`),t=require(`vite`);function n(n){return{name:`@arkenv/vite-plugin`,config(r,{mode:i}){let a=r.envPrefix??`VITE_`,o=Array.isArray(a)?a:[a],s=(0,e.createEnv)(n,{env:(0,t.loadEnv)(i,r.envDir??r.root??process.cwd(),``)}),c=Object.fromEntries(Object.entries(s).filter(([e])=>o.some(t=>e.startsWith(t))));return{define:Object.fromEntries(Object.entries(c).map(([e,t])=>[`import.meta.env.${e}`,JSON.stringify(t)]))}}}}module.exports=n;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createEnv as e}from"arkenv";import{loadEnv as t}from"vite";function n(n){return{name:`@arkenv/vite-plugin`,config(r,{mode:i}){let a=r.envPrefix??`VITE_`,o=Array.isArray(a)?a:[a],s=e(n,{env:t(i,process.cwd(),``)}),c=Object.fromEntries(Object.entries(s).filter(([e])=>o.some(t=>e.startsWith(t))));return{define:Object.fromEntries(Object.entries(c).map(([e,t])=>[`import.meta.env.${e}`,JSON.stringify(t)]))}}}}export{n as default};
|
|
1
|
+
import{createEnv as e}from"arkenv";import{loadEnv as t}from"vite";function n(n){return{name:`@arkenv/vite-plugin`,config(r,{mode:i}){let a=r.envPrefix??`VITE_`,o=Array.isArray(a)?a:[a],s=e(n,{env:t(i,r.envDir??r.root??process.cwd(),``)}),c=Object.fromEntries(Object.entries(s).filter(([e])=>o.some(t=>e.startsWith(t))));return{define:Object.fromEntries(Object.entries(c).map(([e,t])=>[`import.meta.env.${e}`,JSON.stringify(t)]))}}}}export{n as default};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { EnvSchemaWithType, SchemaShape } from \"@repo/types\";\nimport { createEnv, type EnvSchema } from \"arkenv\";\nimport { loadEnv, type Plugin } from \"vite\";\n\nexport type { ImportMetaEnvAugmented } from \"./types\";\n\n/**\n * TODO: If possible, find a better type than \"const T extends SchemaShape\",\n * and be as close as possible to the type accepted by ArkType's `type`.\n */\n\n/**\n * Vite plugin to validate environment variables using ArkEnv and expose them to client code.\n *\n * The plugin validates environment variables using ArkEnv's schema validation and\n * automatically filters them based on Vite's `envPrefix` configuration (defaults to `\"VITE_\"`).\n * Only environment variables matching the prefix are exposed to client code via `import.meta.env.*`.\n *\n * @param options - The environment variable schema definition. Can be an `EnvSchema` object\n * for typesafe validation or an ArkType `EnvSchemaWithType` for dynamic schemas.\n * @returns A Vite plugin that validates environment variables and exposes them to the client.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { defineConfig } from 'vite';\n * import arkenv from '@arkenv/vite-plugin';\n *\n * export default defineConfig({\n * plugins: [\n * arkenv({\n * VITE_API_URL: 'string',\n * VITE_API_KEY: 'string',\n * }),\n * ],\n * });\n * ```\n *\n * @example\n * ```ts\n * // In your client code\n * console.log(import.meta.env.VITE_API_URL); // Typesafe access\n * ```\n */\nexport default function arkenv(options: EnvSchemaWithType): Plugin;\nexport default function arkenv<const T extends SchemaShape>(\n\toptions: EnvSchema<T>,\n): Plugin;\nexport default function arkenv<const T extends SchemaShape>(\n\toptions: EnvSchema<T> | EnvSchemaWithType,\n): Plugin {\n\treturn {\n\t\tname: \"@arkenv/vite-plugin\",\n\t\tconfig(config, { mode }) {\n\t\t\t// Get the Vite prefix for client-exposed environment variables\n\t\t\t// Defaults to \"VITE_\" if not specified\n\t\t\t// Vite allows envPrefix to be a string or array of strings\n\t\t\tconst envPrefix = config.envPrefix ?? \"VITE_\";\n\t\t\tconst prefixes = Array.isArray(envPrefix) ? envPrefix : [envPrefix];\n\n\t\t\t// TODO: We're using type assertions and explicitly pass in the type arguments here to avoid\n\t\t\t// \"Type instantiation is excessively deep and possibly infinite\" errors.\n\t\t\t// Ideally, we should find a way to avoid these assertions while maintaining type safety.\n\t\t\tconst env = createEnv<T>(options, {\n\t\t\t\tenv: loadEnv(mode,
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { EnvSchemaWithType, SchemaShape } from \"@repo/types\";\nimport { createEnv, type EnvSchema } from \"arkenv\";\nimport { loadEnv, type Plugin } from \"vite\";\n\nexport type { ImportMetaEnvAugmented } from \"./types\";\n\n/**\n * TODO: If possible, find a better type than \"const T extends SchemaShape\",\n * and be as close as possible to the type accepted by ArkType's `type`.\n */\n\n/**\n * Vite plugin to validate environment variables using ArkEnv and expose them to client code.\n *\n * The plugin validates environment variables using ArkEnv's schema validation and\n * automatically filters them based on Vite's `envPrefix` configuration (defaults to `\"VITE_\"`).\n * Only environment variables matching the prefix are exposed to client code via `import.meta.env.*`.\n *\n * @param options - The environment variable schema definition. Can be an `EnvSchema` object\n * for typesafe validation or an ArkType `EnvSchemaWithType` for dynamic schemas.\n * @returns A Vite plugin that validates environment variables and exposes them to the client.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { defineConfig } from 'vite';\n * import arkenv from '@arkenv/vite-plugin';\n *\n * export default defineConfig({\n * plugins: [\n * arkenv({\n * VITE_API_URL: 'string',\n * VITE_API_KEY: 'string',\n * }),\n * ],\n * });\n * ```\n *\n * @example\n * ```ts\n * // In your client code\n * console.log(import.meta.env.VITE_API_URL); // Typesafe access\n * ```\n */\nexport default function arkenv(options: EnvSchemaWithType): Plugin;\nexport default function arkenv<const T extends SchemaShape>(\n\toptions: EnvSchema<T>,\n): Plugin;\nexport default function arkenv<const T extends SchemaShape>(\n\toptions: EnvSchema<T> | EnvSchemaWithType,\n): Plugin {\n\treturn {\n\t\tname: \"@arkenv/vite-plugin\",\n\t\tconfig(config, { mode }) {\n\t\t\t// Get the Vite prefix for client-exposed environment variables\n\t\t\t// Defaults to \"VITE_\" if not specified\n\t\t\t// Vite allows envPrefix to be a string or array of strings\n\t\t\tconst envPrefix = config.envPrefix ?? \"VITE_\";\n\t\t\tconst prefixes = Array.isArray(envPrefix) ? envPrefix : [envPrefix];\n\n\t\t\t// Load environment based on the custom config\n\t\t\tconst envDir = config.envDir ?? config.root ?? process.cwd();\n\t\t\t// TODO: We're using type assertions and explicitly pass in the type arguments here to avoid\n\t\t\t// \"Type instantiation is excessively deep and possibly infinite\" errors.\n\t\t\t// Ideally, we should find a way to avoid these assertions while maintaining type safety.\n\t\t\tconst env = createEnv<T>(options, {\n\t\t\t\tenv: loadEnv(mode, envDir, \"\"),\n\t\t\t});\n\n\t\t\t// Filter to only include environment variables matching the prefix\n\t\t\t// This prevents server-only variables from being exposed to client code\n\t\t\tconst filteredEnv = Object.fromEntries(\n\t\t\t\tObject.entries(<SchemaShape>env).filter(([key]) =>\n\t\t\t\t\tprefixes.some((prefix) => key.startsWith(prefix)),\n\t\t\t\t),\n\t\t\t);\n\n\t\t\t// Expose transformed environment variables through Vite's define option\n\t\t\t// Only prefixed variables are exposed to client code\n\t\t\tconst define = Object.fromEntries(\n\t\t\t\tObject.entries(filteredEnv).map(([key, value]) => [\n\t\t\t\t\t`import.meta.env.${key}`,\n\t\t\t\t\tJSON.stringify(value),\n\t\t\t\t]),\n\t\t\t);\n\n\t\t\treturn { define };\n\t\t},\n\t};\n}\n"],"mappings":"kEAgDA,SAAwB,EACvB,EACS,CACT,MAAO,CACN,KAAM,sBACN,OAAO,EAAQ,CAAE,QAAQ,CAIxB,IAAM,EAAY,EAAO,WAAa,QAChC,EAAW,MAAM,QAAQ,EAAU,CAAG,EAAY,CAAC,EAAU,CAO7D,EAAM,EAAa,EAAS,CACjC,IAAK,EAAQ,EALC,EAAO,QAAU,EAAO,MAAQ,QAAQ,KAAK,CAKhC,GAAG,CAC9B,CAAC,CAII,EAAc,OAAO,YAC1B,OAAO,QAAqB,EAAI,CAAC,QAAQ,CAAC,KACzC,EAAS,KAAM,GAAW,EAAI,WAAW,EAAO,CAAC,CACjD,CACD,CAWD,MAAO,CAAE,OAPM,OAAO,YACrB,OAAO,QAAQ,EAAY,CAAC,KAAK,CAAC,EAAK,KAAW,CACjD,mBAAmB,IACnB,KAAK,UAAU,EAAM,CACrB,CAAC,CACF,CAEgB,EAElB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkenv/vite-plugin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"author": "Yam Borodetsky <yam@yam.codes>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"vite": "7.3.0",
|
|
22
22
|
"vite-tsconfig-paths": "5.1.4",
|
|
23
23
|
"vitest": "4.0.16",
|
|
24
|
-
"@repo/types": "
|
|
24
|
+
"@repo/types": "0.0.4"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"arktype": "^2.1.22",
|