@arkenv/vite-plugin 0.0.16 → 0.0.17
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 +36 -48
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -2,28 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
[Vite](https://vite.dev/) plugin to validate environment variables at build-time with ArkEnv.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<br/>
|
|
6
|
+
<br/>
|
|
7
|
+
<br/>
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
npm install @arkenv/vite-plugin arkenv arktype
|
|
9
|
-
```
|
|
9
|
+
## [Read the docs →](https://arkenv.js.org/docs/vite-plugin)
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
```typescript title="vite.config.ts"
|
|
14
|
-
import arkenv from "@arkenv/vite-plugin";
|
|
15
|
-
import { defineConfig } from "vite";
|
|
16
|
-
|
|
17
|
-
export default defineConfig({
|
|
18
|
-
plugins: [
|
|
19
|
-
arkenv({
|
|
20
|
-
VITE_API_URL: "string",
|
|
21
|
-
VITE_APP_NAME: "'MyApp' | 'TestApp'",
|
|
22
|
-
"VITE_DEBUG?": 'boolean = false'
|
|
23
|
-
}),
|
|
24
|
-
],
|
|
25
|
-
});
|
|
26
|
-
```
|
|
11
|
+
<br/>
|
|
12
|
+
<br/>
|
|
27
13
|
|
|
28
14
|
## Features
|
|
29
15
|
|
|
@@ -31,37 +17,39 @@ export default defineConfig({
|
|
|
31
17
|
- Typesafe environment variables backed by TypeScript
|
|
32
18
|
- Access to ArkType's powerful type system
|
|
33
19
|
|
|
34
|
-
##
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"VITE_ALLOWED_ORIGINS?": 'string[] = []'
|
|
50
|
-
}),
|
|
51
|
-
],
|
|
52
|
-
});
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
<details open>
|
|
23
|
+
<summary>npm</summary>
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
npm install @arkenv/vite-plugin arktype
|
|
27
|
+
```
|
|
28
|
+
</details>
|
|
29
|
+
|
|
30
|
+
<details>
|
|
31
|
+
<summary>pnpm</summary>
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
pnpm add @arkenv/vite-plugin arktype
|
|
53
35
|
```
|
|
36
|
+
</details>
|
|
54
37
|
|
|
55
|
-
|
|
38
|
+
<details>
|
|
39
|
+
<summary>Yarn</summary>
|
|
56
40
|
|
|
57
|
-
|
|
41
|
+
```sh
|
|
42
|
+
yarn add @arkenv/vite-plugin arktype
|
|
43
|
+
```
|
|
44
|
+
</details>
|
|
58
45
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
46
|
+
<details>
|
|
47
|
+
<summary>Bun</summary>
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
bun add @arkenv/vite-plugin arktype
|
|
64
51
|
```
|
|
52
|
+
</details>
|
|
65
53
|
|
|
66
54
|
## FAQ
|
|
67
55
|
|
|
@@ -69,9 +57,9 @@ VITE_ALLOWED_ORIGINS=http://localhost:3000,https://example.com
|
|
|
69
57
|
|
|
70
58
|
This plugin uses [the Vite specific `config` hook](https://vite.dev/guide/api-plugin.html#config), which is not available in Rollup.
|
|
71
59
|
|
|
72
|
-
##
|
|
60
|
+
## Playground
|
|
73
61
|
|
|
74
|
-
* [
|
|
62
|
+
* [vite-playground](https://github.com/yamcodes/arkenv/tree/main/apps/playgrounds/vite)
|
|
75
63
|
|
|
76
64
|
## Related
|
|
77
65
|
|
package/dist/index.cjs
CHANGED
|
@@ -1 +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,(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;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EnvSchema } from "arkenv";
|
|
2
|
+
import { type } from "arktype";
|
|
2
3
|
import { Plugin } from "vite";
|
|
3
4
|
|
|
4
5
|
//#region src/index.d.ts
|
|
@@ -8,5 +9,6 @@ import { Plugin } from "vite";
|
|
|
8
9
|
* and be as close as possible to the type accepted by ArkType's `type`.
|
|
9
10
|
*/
|
|
10
11
|
declare function arkenv<const T extends Record<string, unknown>>(options: EnvSchema<T>): Plugin;
|
|
12
|
+
declare function arkenv(options: type.Any): Plugin;
|
|
11
13
|
export = arkenv;
|
|
12
14
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAG4C;;AAQxB,iBADI,MACJ,CAAA,gBAD2B,MAC3B,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,CAAA,OAAA,EAAV,SAAU,CAAA,CAAA,CAAA,CAAA,EACjB,MADiB;AAAV,iBAEc,MAAA,CAFd,OAAA,EAE8B,IAAA,CAAK,GAFnC,CAAA,EAEyC,MAFzC;AAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EnvSchema } from "arkenv";
|
|
2
2
|
import { Plugin } from "vite";
|
|
3
|
+
import { type } from "arktype";
|
|
3
4
|
|
|
4
5
|
//#region src/index.d.ts
|
|
5
6
|
|
|
@@ -8,6 +9,7 @@ import { Plugin } from "vite";
|
|
|
8
9
|
* and be as close as possible to the type accepted by ArkType's `type`.
|
|
9
10
|
*/
|
|
10
11
|
declare function arkenv<const T extends Record<string, unknown>>(options: EnvSchema<T>): Plugin;
|
|
12
|
+
declare function arkenv(options: type.Any): Plugin;
|
|
11
13
|
//#endregion
|
|
12
14
|
export { arkenv as default };
|
|
13
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAG4C;;AAQxB,iBADI,MACJ,CAAA,gBAD2B,MAC3B,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,CAAA,OAAA,EAAV,SAAU,CAAA,CAAA,CAAA,CAAA,EACjB,MADiB;AAAV,iBAEc,MAAA,CAFd,OAAA,EAE8B,IAAA,CAAK,GAFnC,CAAA,EAEyC,MAFzC"}
|
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=e(n,t(i,process.cwd(),``));return{define:Object.fromEntries(Object.entries(
|
|
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,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};
|
|
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 { EnvSchema } from \"arkenv\";\nimport { createEnv } from \"arkenv\";\nimport { loadEnv, type Plugin } from \"vite\";\n\n/**\n * TODO: If possible, find a better type than \"const T extends Record<string, unknown>\",\n * and be as close as possible to the type accepted by ArkType's `type`.\n */\n\nexport default function arkenv<const T extends Record<string, unknown>>(\n\toptions: EnvSchema<T>,\n): Plugin {\n\treturn {\n\t\tname: \"@arkenv/vite-plugin\",\n\t\tconfig(
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { EnvSchema } from \"arkenv\";\nimport { createEnv } from \"arkenv\";\nimport type { type } from \"arktype\";\nimport { loadEnv, type Plugin } from \"vite\";\n\n/**\n * TODO: If possible, find a better type than \"const T extends Record<string, unknown>\",\n * and be as close as possible to the type accepted by ArkType's `type`.\n */\n\nexport default function arkenv<const T extends Record<string, unknown>>(\n\toptions: EnvSchema<T>,\n): Plugin;\nexport default function arkenv(options: type.Any): Plugin;\nexport default function arkenv<const T extends Record<string, unknown>>(\n\toptions: EnvSchema<T> | type.Any,\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// createEnv accepts both EnvSchema and type.Any at runtime\n\t\t\t// We use overloads above to provide external type precision\n\t\t\tconst env = createEnv(options, loadEnv(mode, process.cwd(), \"\"));\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(<Record<string, unknown>>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":"kEAcA,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,CAI7D,EAAM,EAAU,EAAS,EAAQ,EAAM,QAAQ,KAAK,CAAE,GAAG,CAAC,CAI1D,EAAc,OAAO,YAC1B,OAAO,QAAiC,EAAI,CAAC,QAAQ,CAAC,KACrD,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.17",
|
|
4
4
|
"author": "Yam Borodetsky <yam@yam.codes>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,17 +9,17 @@
|
|
|
9
9
|
"main": "./dist/index.cjs",
|
|
10
10
|
"module": "./dist/index.js",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"arkenv": "0.7.
|
|
12
|
+
"arkenv": "0.7.6"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@size-limit/preset-small-lib": "11.2.0",
|
|
16
|
-
"arktype": "2.1.
|
|
16
|
+
"arktype": "2.1.26",
|
|
17
17
|
"size-limit": "11.2.0",
|
|
18
|
-
"tsdown": "0.
|
|
18
|
+
"tsdown": "0.16.1",
|
|
19
19
|
"typescript": "5.9.3",
|
|
20
|
-
"vite": "7.
|
|
20
|
+
"vite": "^7.2.4",
|
|
21
21
|
"vite-tsconfig-paths": "5.1.4",
|
|
22
|
-
"vitest": "4.0.
|
|
22
|
+
"vitest": "4.0.9"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"arktype": "^2.1.22",
|