@vite-hub/env 0.0.0 → 0.0.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 +66 -1
- package/dist/declarations-DIq2gG-8.d.ts +17 -0
- package/dist/declarations-DgJVnQyx.js +111 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/module-C74wPcKe.js +1302 -0
- package/dist/nitro.d.ts +26 -0
- package/dist/nitro.js +4 -0
- package/dist/nuxt.d.ts +59427 -0
- package/dist/nuxt.js +38 -0
- package/dist/presets.d.ts +11 -0
- package/dist/presets.js +25 -0
- package/dist/resolve-QQjHpio7.js +400 -0
- package/dist/runtime/server.d.ts +10 -0
- package/dist/runtime/server.js +98 -0
- package/dist/schema.d.ts +16 -0
- package/dist/schema.js +37 -0
- package/dist/secret.d.ts +11 -0
- package/dist/secret.js +26 -0
- package/dist/types-DnbiD9KN.d.ts +119 -0
- package/dist/virtual.d.ts +7 -0
- package/dist/virtual.js +1 -0
- package/dist/vite.d.ts +21 -0
- package/dist/vite.js +80 -0
- package/package.json +96 -5
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type EnvDiagnostics = "off" | "summary" | "trace";
|
|
3
|
+
type EnvMode = "build" | "runtime";
|
|
4
|
+
interface EnvIntegrationOptions {
|
|
5
|
+
diagnostics?: EnvDiagnostics;
|
|
6
|
+
prefix?: string;
|
|
7
|
+
}
|
|
8
|
+
interface EnvSourceContext {
|
|
9
|
+
env: Record<string, string | undefined>;
|
|
10
|
+
git: {
|
|
11
|
+
branch: () => Promise<string>;
|
|
12
|
+
commit: (options?: {
|
|
13
|
+
short?: boolean;
|
|
14
|
+
}) => Promise<string>;
|
|
15
|
+
};
|
|
16
|
+
mode: EnvMode;
|
|
17
|
+
packageJson: () => Promise<Record<string, unknown>>;
|
|
18
|
+
rootDir: string;
|
|
19
|
+
}
|
|
20
|
+
type EnvSourceResolver = (context: EnvSourceContext) => unknown | Promise<unknown>;
|
|
21
|
+
type EnvSource = {
|
|
22
|
+
kind: "custom";
|
|
23
|
+
label: string;
|
|
24
|
+
resolver: EnvSourceResolver;
|
|
25
|
+
serializable: false;
|
|
26
|
+
} | {
|
|
27
|
+
kind: "env";
|
|
28
|
+
label: string;
|
|
29
|
+
name: string;
|
|
30
|
+
names?: string[];
|
|
31
|
+
serializable: true;
|
|
32
|
+
} | {
|
|
33
|
+
kind: "git-branch";
|
|
34
|
+
label: "git:branch";
|
|
35
|
+
serializable: true;
|
|
36
|
+
} | {
|
|
37
|
+
kind: "git-commit";
|
|
38
|
+
label: "git:commit";
|
|
39
|
+
serializable: true;
|
|
40
|
+
short?: boolean;
|
|
41
|
+
} | {
|
|
42
|
+
kind: "package-json";
|
|
43
|
+
label: string;
|
|
44
|
+
path: string;
|
|
45
|
+
serializable: true;
|
|
46
|
+
};
|
|
47
|
+
interface EnvVariableDeclaration {
|
|
48
|
+
default?: unknown;
|
|
49
|
+
kind: "env-variable";
|
|
50
|
+
mode: EnvMode;
|
|
51
|
+
required: boolean;
|
|
52
|
+
schema: unknown;
|
|
53
|
+
secret: boolean;
|
|
54
|
+
source?: EnvSource;
|
|
55
|
+
type?: string;
|
|
56
|
+
}
|
|
57
|
+
interface EnvVariableOptions {
|
|
58
|
+
default?: unknown;
|
|
59
|
+
mode?: EnvMode;
|
|
60
|
+
optional?: boolean;
|
|
61
|
+
required?: boolean;
|
|
62
|
+
schema?: unknown;
|
|
63
|
+
secret?: boolean;
|
|
64
|
+
source?: EnvSource | EnvSourceResolver;
|
|
65
|
+
type?: string;
|
|
66
|
+
}
|
|
67
|
+
interface EnvViteConfigOptions {
|
|
68
|
+
define?: Record<string, EnvVariableDeclaration>;
|
|
69
|
+
public?: Record<string, EnvVariableDeclaration>;
|
|
70
|
+
}
|
|
71
|
+
type EnvNitroStaticValue = null | string | number | boolean | EnvNitroStaticValue[];
|
|
72
|
+
type EnvNitroConfigValue = EnvNitroConfigOptions | EnvNitroStaticValue | EnvVariableDeclaration;
|
|
73
|
+
interface EnvNitroConfigOptions {
|
|
74
|
+
[key: string]: EnvNitroConfigValue;
|
|
75
|
+
}
|
|
76
|
+
type EnvConfigOptions = EnvViteConfigOptions | EnvNitroConfigOptions;
|
|
77
|
+
interface EnvViteUserConfig {
|
|
78
|
+
env?: EnvViteConfigOptions;
|
|
79
|
+
}
|
|
80
|
+
interface EnvNitroUserConfig {
|
|
81
|
+
env?: EnvNitroConfigOptions;
|
|
82
|
+
}
|
|
83
|
+
interface EnvDiagnosticEntry {
|
|
84
|
+
exposed: string;
|
|
85
|
+
key: string;
|
|
86
|
+
masked: boolean;
|
|
87
|
+
mode: EnvMode;
|
|
88
|
+
source: string;
|
|
89
|
+
status: "defaulted" | "missing" | "valid";
|
|
90
|
+
timing: string;
|
|
91
|
+
type?: string;
|
|
92
|
+
}
|
|
93
|
+
interface EnvRegistryEntry {
|
|
94
|
+
default?: unknown;
|
|
95
|
+
required: boolean;
|
|
96
|
+
schema?: EnvRuntimeSchema;
|
|
97
|
+
secret: boolean;
|
|
98
|
+
source: Extract<EnvSource, {
|
|
99
|
+
kind: "env";
|
|
100
|
+
}>;
|
|
101
|
+
type?: string;
|
|
102
|
+
}
|
|
103
|
+
interface EnvRuntimeSchema {
|
|
104
|
+
kind: "string";
|
|
105
|
+
}
|
|
106
|
+
interface EnvRuntimeLiteralEntry {
|
|
107
|
+
kind: "literal";
|
|
108
|
+
value: EnvNitroStaticValue;
|
|
109
|
+
}
|
|
110
|
+
type EnvRuntimeRegistryValue = EnvRegistryEntry | EnvRuntimeLiteralEntry | EnvRuntimeRegistry;
|
|
111
|
+
interface EnvRuntimeRegistry {
|
|
112
|
+
[key: string]: EnvRuntimeRegistryValue;
|
|
113
|
+
}
|
|
114
|
+
interface ServerEnv {
|
|
115
|
+
[key: string]: unknown;
|
|
116
|
+
}
|
|
117
|
+
type PublicEnv = Record<string, unknown>;
|
|
118
|
+
//#endregion
|
|
119
|
+
export { ServerEnv as _, EnvMode as a, EnvRuntimeRegistry as c, EnvSourceResolver as d, EnvVariableDeclaration as f, PublicEnv as g, EnvViteUserConfig as h, EnvIntegrationOptions as i, EnvSource as l, EnvViteConfigOptions as m, EnvDiagnosticEntry as n, EnvNitroConfigOptions as o, EnvVariableOptions as p, EnvDiagnostics as r, EnvNitroUserConfig as s, EnvConfigOptions as t, EnvSourceContext as u };
|
package/dist/virtual.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { i as EnvIntegrationOptions, m as EnvViteConfigOptions } from "./types-DnbiD9KN.js";
|
|
2
|
+
import { t as env } from "./declarations-DIq2gG-8.js";
|
|
3
|
+
import { Plugin } from "vite";
|
|
4
|
+
|
|
5
|
+
//#region src/vite.d.ts
|
|
6
|
+
declare const ENV_VITE_PLUGIN_NAME = "@vite-hub/env/vite";
|
|
7
|
+
declare const ENV_PUBLIC_ID = "#vitehub/env/public";
|
|
8
|
+
interface EnvVitePluginAPI {
|
|
9
|
+
getPublicEnv: () => Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
type EnvVitePlugin = Plugin & {
|
|
12
|
+
api: EnvVitePluginAPI;
|
|
13
|
+
};
|
|
14
|
+
declare function envVite(options?: EnvIntegrationOptions): EnvVitePlugin;
|
|
15
|
+
declare module "vite" {
|
|
16
|
+
interface UserConfig {
|
|
17
|
+
env?: EnvViteConfigOptions;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { ENV_PUBLIC_ID, ENV_VITE_PLUGIN_NAME, EnvVitePlugin, EnvVitePluginAPI, env, envVite };
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { n as env } from "./declarations-DgJVnQyx.js";
|
|
2
|
+
import { c as writeFileIfChanged, i as resolveEnvEntries, n as createSourceContext, o as validateEnvConfigShape, s as formatDiagnostics } from "./resolve-QQjHpio7.js";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { loadEnv } from "vite";
|
|
5
|
+
//#region src/vite.ts
|
|
6
|
+
const ENV_VITE_PLUGIN_NAME = "@vite-hub/env/vite";
|
|
7
|
+
const ENV_PUBLIC_ID = "#vitehub/env/public";
|
|
8
|
+
const RESOLVED_PUBLIC_ID = `\0${ENV_PUBLIC_ID}`;
|
|
9
|
+
function envVite(options = {}) {
|
|
10
|
+
let buildPublicConfig = {};
|
|
11
|
+
let diagnosticsText;
|
|
12
|
+
const getPublicEnv = () => buildPublicConfig;
|
|
13
|
+
return {
|
|
14
|
+
name: ENV_VITE_PLUGIN_NAME,
|
|
15
|
+
api: { getPublicEnv },
|
|
16
|
+
async config(config, env) {
|
|
17
|
+
const envConfig = config.env;
|
|
18
|
+
validateEnvConfigShape(envConfig, "vite");
|
|
19
|
+
if (!envConfig) return;
|
|
20
|
+
const root = resolve(config.root || process.cwd());
|
|
21
|
+
const context = createSourceContext({
|
|
22
|
+
env: {
|
|
23
|
+
...loadEnv(env.mode, root, ""),
|
|
24
|
+
...process.env
|
|
25
|
+
},
|
|
26
|
+
mode: "build",
|
|
27
|
+
rootDir: root
|
|
28
|
+
});
|
|
29
|
+
const publicResult = await resolveEnvEntries(envConfig.public, {
|
|
30
|
+
context,
|
|
31
|
+
exposure: "build public",
|
|
32
|
+
prefix: options.prefix,
|
|
33
|
+
section: "env.public",
|
|
34
|
+
timing: "Vite config/dev/build"
|
|
35
|
+
});
|
|
36
|
+
const defineResult = await resolveEnvEntries(envConfig.define, {
|
|
37
|
+
context,
|
|
38
|
+
exposure: "compile-time replacement",
|
|
39
|
+
prefix: options.prefix,
|
|
40
|
+
section: "env.define",
|
|
41
|
+
timing: "Vite transform/build"
|
|
42
|
+
});
|
|
43
|
+
buildPublicConfig = Object.fromEntries(publicResult.entries.map((entry) => [entry.key, entry.value]));
|
|
44
|
+
diagnosticsText = formatDiagnostics([...publicResult.diagnostics, ...defineResult.diagnostics], options.diagnostics);
|
|
45
|
+
return { define: {
|
|
46
|
+
...Object.fromEntries(defineResult.entries.map((entry) => [entry.key, JSON.stringify(entry.value)])),
|
|
47
|
+
...config.define
|
|
48
|
+
} };
|
|
49
|
+
},
|
|
50
|
+
async configResolved(config) {
|
|
51
|
+
if (diagnosticsText) config.logger.info(diagnosticsText);
|
|
52
|
+
await writeFileIfChanged(resolve(config.root, ".vitehub/env/vite.d.ts"), createViteTypes(buildPublicConfig));
|
|
53
|
+
},
|
|
54
|
+
load(id) {
|
|
55
|
+
if (id === RESOLVED_PUBLIC_ID) return [
|
|
56
|
+
`const publicEnv = ${JSON.stringify(buildPublicConfig, null, 2)};`,
|
|
57
|
+
"export function usePublicEnv() { return publicEnv; }",
|
|
58
|
+
"export { publicEnv };"
|
|
59
|
+
].join("\n");
|
|
60
|
+
},
|
|
61
|
+
resolveId(id) {
|
|
62
|
+
if (id === "#vitehub/env/public") return RESOLVED_PUBLIC_ID;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function createViteTypes(config) {
|
|
67
|
+
return [
|
|
68
|
+
"declare module \"#vitehub/env/public\" {",
|
|
69
|
+
" export interface PublicEnv {",
|
|
70
|
+
...Object.entries(config).map(([key, value]) => ` ${JSON.stringify(key)}: ${typeof value}`),
|
|
71
|
+
" }",
|
|
72
|
+
" export const publicEnv: PublicEnv",
|
|
73
|
+
" export function usePublicEnv(): PublicEnv",
|
|
74
|
+
"}",
|
|
75
|
+
"export {}",
|
|
76
|
+
""
|
|
77
|
+
].join("\n");
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
export { ENV_PUBLIC_ID, ENV_VITE_PLUGIN_NAME, env, envVite };
|
package/package.json
CHANGED
|
@@ -1,9 +1,100 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/env",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Safe build and runtime environment variables for Vite and Nitro.",
|
|
5
|
+
"author": "onmax <maximogarciamtnez@gmail.com>",
|
|
5
6
|
"license": "Apache-2.0",
|
|
6
|
-
"
|
|
7
|
-
|
|
7
|
+
"homepage": "https://github.com/vite-hub/vitehub#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/vite-hub/vitehub.git",
|
|
11
|
+
"directory": "packages/env"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/vite-hub/vitehub/issues",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"vitehub",
|
|
16
|
+
"vite",
|
|
17
|
+
"nitro",
|
|
18
|
+
"env",
|
|
19
|
+
"environment-variables",
|
|
20
|
+
"runtime-config"
|
|
21
|
+
],
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"type": "module",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./nitro": {
|
|
31
|
+
"types": "./dist/nitro.d.ts",
|
|
32
|
+
"import": "./dist/nitro.js"
|
|
33
|
+
},
|
|
34
|
+
"./nuxt": {
|
|
35
|
+
"types": "./dist/nuxt.d.ts",
|
|
36
|
+
"import": "./dist/nuxt.js"
|
|
37
|
+
},
|
|
38
|
+
"./presets": {
|
|
39
|
+
"types": "./dist/presets.d.ts",
|
|
40
|
+
"import": "./dist/presets.js"
|
|
41
|
+
},
|
|
42
|
+
"./runtime/server": {
|
|
43
|
+
"types": "./dist/runtime/server.d.ts",
|
|
44
|
+
"import": "./dist/runtime/server.js"
|
|
45
|
+
},
|
|
46
|
+
"./schema": {
|
|
47
|
+
"types": "./dist/schema.d.ts",
|
|
48
|
+
"import": "./dist/schema.js"
|
|
49
|
+
},
|
|
50
|
+
"./secret": {
|
|
51
|
+
"types": "./dist/secret.d.ts",
|
|
52
|
+
"import": "./dist/secret.js"
|
|
53
|
+
},
|
|
54
|
+
"./virtual": {
|
|
55
|
+
"types": "./dist/virtual.d.ts",
|
|
56
|
+
"import": "./dist/virtual.js"
|
|
57
|
+
},
|
|
58
|
+
"./vite": {
|
|
59
|
+
"types": "./dist/vite.d.ts",
|
|
60
|
+
"import": "./dist/vite.js"
|
|
61
|
+
},
|
|
62
|
+
"./package.json": "./package.json"
|
|
63
|
+
},
|
|
64
|
+
"files": [
|
|
65
|
+
"dist",
|
|
66
|
+
"package.json"
|
|
67
|
+
],
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"@nuxt/kit": "^4.4.6"
|
|
70
|
+
},
|
|
71
|
+
"peerDependencies": {
|
|
72
|
+
"nitro": "^3.0.0-0",
|
|
73
|
+
"vite": ">=6.0.0"
|
|
74
|
+
},
|
|
75
|
+
"peerDependenciesMeta": {
|
|
76
|
+
"nitro": {
|
|
77
|
+
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"vite": {
|
|
80
|
+
"optional": true
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"devDependencies": {
|
|
84
|
+
"@nuxt/schema": "^4.4.6",
|
|
85
|
+
"nitro": "3.0.260311-beta",
|
|
86
|
+
"publint": "^0.3.15",
|
|
87
|
+
"tsdown": "^0.21.8",
|
|
88
|
+
"tsx": "^4.21.0",
|
|
89
|
+
"typescript": "^6.0.2",
|
|
90
|
+
"vite": "^8.0.8",
|
|
91
|
+
"vitest": "^4.1.4",
|
|
92
|
+
"@vite-hub/internal": "0.0.1"
|
|
93
|
+
},
|
|
94
|
+
"scripts": {
|
|
95
|
+
"build": "tsdown --tsconfig tsconfig.build.json",
|
|
96
|
+
"dev": "tsdown --watch",
|
|
97
|
+
"typecheck": "tsc --noEmit -p ./tsconfig.json",
|
|
98
|
+
"test": "pnpm --filter @vite-hub/env build && vitest run"
|
|
8
99
|
}
|
|
9
|
-
}
|
|
100
|
+
}
|