@vezham/env 26.0.0-alpha.5 → 26.0.0-alpha.7
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 +19 -0
- package/dist/lib/base.d.ts +26 -0
- package/dist/lib/base.d.ts.map +1 -0
- package/dist/lib/base.js +45 -0
- package/dist/lib/next/env.d.ts +15 -0
- package/dist/lib/next/env.d.ts.map +1 -0
- package/dist/lib/next/env.js +16 -0
- package/dist/lib/next/index.d.ts +4 -0
- package/dist/lib/next/index.d.ts.map +1 -0
- package/dist/lib/next/index.js +5 -0
- package/dist/lib/vite/env.d.ts +2 -0
- package/dist/lib/vite/env.d.ts.map +1 -0
- package/dist/lib/vite/env.js +4 -0
- package/dist/lib/vite/index.d.ts +2 -0
- package/dist/lib/vite/index.d.ts.map +1 -0
- package/dist/lib/vite/index.js +5 -0
- package/package.json +20 -1
package/README.md
CHANGED
|
@@ -1 +1,20 @@
|
|
|
1
1
|
# @vezham/env
|
|
2
|
+
|
|
3
|
+
Validated app environment settings with Vite and Next.js adapters.
|
|
4
|
+
|
|
5
|
+
## Vite environment handling
|
|
6
|
+
|
|
7
|
+
The Vite adapter must use the consuming app's environment. Resolving
|
|
8
|
+
`import.meta.env` during the package build would bake the package's build
|
|
9
|
+
environment into the published JavaScript.
|
|
10
|
+
|
|
11
|
+
The `vezham:consumer-env` plugin in `vite.config.ts` preserves that expression:
|
|
12
|
+
|
|
13
|
+
1. Its early `transform` hook replaces `import.meta.env` with the temporary
|
|
14
|
+
`__VEZHAM_CONSUMER_ENV__` identifier, only in `src/lib/vite/env.ts`.
|
|
15
|
+
2. Its `renderChunk` hook restores `import.meta.env` in the emitted JavaScript.
|
|
16
|
+
3. The consuming app's Vite dev server or build supplies its own environment
|
|
17
|
+
values, including `MODE` and `V_APP_ID`.
|
|
18
|
+
|
|
19
|
+
The placeholder is internal to the package build; consumers do not configure it.
|
|
20
|
+
The plugin adds no browser runtime overhead.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type BaseApiMode = 'api' | 'mock' | 'local';
|
|
2
|
+
type Props = {
|
|
3
|
+
MODE?: string;
|
|
4
|
+
V_APP_ENV?: string;
|
|
5
|
+
V_RELEASE_CHANNEL?: string;
|
|
6
|
+
V_APP_ID?: string;
|
|
7
|
+
V_APP_NAME?: string;
|
|
8
|
+
V_APP_VER?: string;
|
|
9
|
+
V_IS_DEBUG?: string;
|
|
10
|
+
V_BASE_API_MODE?: BaseApiMode;
|
|
11
|
+
V_MOCK_LOCAL_API_URL?: string;
|
|
12
|
+
V_MOCK_API_URL?: string;
|
|
13
|
+
V_APP_API_URL?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare const createEnv: (__ENV__: Props) => {
|
|
16
|
+
__DEV__: boolean;
|
|
17
|
+
__PRODUCTION__: boolean;
|
|
18
|
+
APP_ENV: "local" | "dev" | "qa" | "preview" | "production";
|
|
19
|
+
RELEASE_CHANNEL: "canary" | "beta" | "stable";
|
|
20
|
+
APP_ID: string;
|
|
21
|
+
APP_NAME: string;
|
|
22
|
+
APP_VER: string;
|
|
23
|
+
__DEBUG__: boolean;
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/lib/base.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,CAAA;AAOlD,KAAK,KAAK,GAAG;IACX,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAE1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB,eAAe,CAAC,EAAE,WAAW,CAAA;IAC7B,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB,CAAA;AAuBD,eAAO,MAAM,SAAS,GAAI,SAAS,KAAK;;;;;;;;;CA8CvC,CAAA"}
|
package/dist/lib/base.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/lib/base.ts
|
|
2
|
+
var environments = [
|
|
3
|
+
"local",
|
|
4
|
+
"dev",
|
|
5
|
+
"qa",
|
|
6
|
+
"preview",
|
|
7
|
+
"production"
|
|
8
|
+
];
|
|
9
|
+
var releaseChannels = [
|
|
10
|
+
"canary",
|
|
11
|
+
"beta",
|
|
12
|
+
"stable"
|
|
13
|
+
];
|
|
14
|
+
var parseSetting = (name, value, allowed) => {
|
|
15
|
+
const setting = allowed.find((option) => option === value);
|
|
16
|
+
if (setting === void 0) throw new Error(`${name} must be one of: ${allowed.join(", ")}`);
|
|
17
|
+
return setting;
|
|
18
|
+
};
|
|
19
|
+
var requireSetting = (name, value) => {
|
|
20
|
+
if (value === void 0 || value.trim() === "") throw new Error(`${name} is required`);
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var createEnv = (__ENV__) => {
|
|
24
|
+
const __DEV__ = __ENV__.MODE === "development";
|
|
25
|
+
const __PRODUCTION__ = __ENV__.MODE === "production";
|
|
26
|
+
const APP_ENV = parseSetting("V_APP_ENV", __ENV__.V_APP_ENV || "local", environments);
|
|
27
|
+
const RELEASE_CHANNEL = parseSetting("V_RELEASE_CHANNEL", __ENV__.V_RELEASE_CHANNEL || "stable", releaseChannels);
|
|
28
|
+
const APP_ID = requireSetting("V_APP_ID", __ENV__.V_APP_ID);
|
|
29
|
+
const APP_NAME = requireSetting("V_APP_NAME", __ENV__.V_APP_NAME);
|
|
30
|
+
const APP_VER = requireSetting("V_APP_VER", __ENV__.V_APP_VER);
|
|
31
|
+
const __DEBUG__ = __ENV__.V_IS_DEBUG === "true";
|
|
32
|
+
if (__DEV__ && __DEBUG__) console.table(__ENV__);
|
|
33
|
+
return {
|
|
34
|
+
__DEV__,
|
|
35
|
+
__PRODUCTION__,
|
|
36
|
+
APP_ENV,
|
|
37
|
+
RELEASE_CHANNEL,
|
|
38
|
+
APP_ID,
|
|
39
|
+
APP_NAME,
|
|
40
|
+
APP_VER,
|
|
41
|
+
__DEBUG__
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
export { createEnv };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type BaseApiMode } from '../base';
|
|
2
|
+
export declare const configEnv: {
|
|
3
|
+
MODE: string | undefined;
|
|
4
|
+
V_APP_ENV: string | undefined;
|
|
5
|
+
V_RELEASE_CHANNEL: string | undefined;
|
|
6
|
+
V_APP_ID: string | undefined;
|
|
7
|
+
V_APP_NAME: string | undefined;
|
|
8
|
+
V_APP_VER: string | undefined;
|
|
9
|
+
V_IS_DEBUG: string | undefined;
|
|
10
|
+
V_BASE_API_MODE: BaseApiMode;
|
|
11
|
+
V_MOCK_LOCAL_API_URL: string | undefined;
|
|
12
|
+
V_MOCK_API_URL: string | undefined;
|
|
13
|
+
V_APP_API_URL: string | undefined;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/lib/next/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,eAAO,MAAM,SAAS;;;;;;;;qBAW4B,WAAW;;;;CAI5D,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/lib/next/env.ts
|
|
2
|
+
var configEnv = {
|
|
3
|
+
MODE: process.env.NODE_ENV,
|
|
4
|
+
V_APP_ENV: process.env.V_APP_ENV,
|
|
5
|
+
V_RELEASE_CHANNEL: process.env.V_RELEASE_CHANNEL,
|
|
6
|
+
V_APP_ID: process.env.V_APP_ID,
|
|
7
|
+
V_APP_NAME: process.env.V_APP_NAME,
|
|
8
|
+
V_APP_VER: process.env.V_APP_VER,
|
|
9
|
+
V_IS_DEBUG: process.env.V_IS_DEBUG,
|
|
10
|
+
V_BASE_API_MODE: process.env.V_BASE_API_MODE,
|
|
11
|
+
V_MOCK_LOCAL_API_URL: process.env.V_MOCK_LOCAL_API_URL,
|
|
12
|
+
V_MOCK_API_URL: process.env.V_MOCK_API_URL,
|
|
13
|
+
V_APP_API_URL: process.env.V_APP_API_URL
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { configEnv };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { configEnv } from './env';
|
|
2
|
+
export { configEnv };
|
|
3
|
+
export declare const __DEV__: boolean, __PRODUCTION__: boolean, APP_ENV: "local" | "dev" | "qa" | "preview" | "production", RELEASE_CHANNEL: "canary" | "beta" | "stable", APP_ID: string, APP_NAME: string, APP_VER: string, __DEBUG__: boolean;
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/next/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGjC,OAAO,EAAE,SAAS,EAAE,CAAA;AAIpB,eAAO,MACL,OAAO,WACP,cAAc,WACd,OAAO,qDACP,eAAe,gCAEf,MAAM,UACN,QAAQ,UACR,OAAO,UAEP,SAAS,SAGA,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createEnv } from "../base.js";
|
|
2
|
+
import { configEnv } from "./env.js";
|
|
3
|
+
var { __DEV__, __PRODUCTION__, APP_ENV, RELEASE_CHANNEL, APP_ID, APP_NAME, APP_VER, __DEBUG__ } = createEnv(configEnv);
|
|
4
|
+
//#endregion
|
|
5
|
+
export { APP_ENV, APP_ID, APP_NAME, APP_VER, RELEASE_CHANNEL, __DEBUG__, __DEV__, __PRODUCTION__, configEnv };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/lib/vite/env.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,eAAkB,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const __DEV__: boolean, __PRODUCTION__: boolean, APP_ENV: "local" | "dev" | "qa" | "preview" | "production", RELEASE_CHANNEL: "canary" | "beta" | "stable", APP_ID: string, APP_NAME: string, APP_VER: string, __DEBUG__: boolean;
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/vite/index.ts"],"names":[],"mappings":"AAKA,eAAO,MACL,OAAO,WACP,cAAc,WACd,OAAO,qDACP,eAAe,gCAEf,MAAM,UACN,QAAQ,UACR,OAAO,UAEP,SAAS,SAGA,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createEnv } from "../base.js";
|
|
2
|
+
import { configEnv } from "./env.js";
|
|
3
|
+
var { __DEV__, __PRODUCTION__, APP_ENV, RELEASE_CHANNEL, APP_ID, APP_NAME, APP_VER, __DEBUG__ } = createEnv(configEnv);
|
|
4
|
+
//#endregion
|
|
5
|
+
export { APP_ENV, APP_ID, APP_NAME, APP_VER, RELEASE_CHANNEL, __DEBUG__, __DEV__, __PRODUCTION__ };
|
package/package.json
CHANGED
|
@@ -1,13 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vezham/env",
|
|
3
|
-
"version": "26.0.0-alpha.
|
|
3
|
+
"version": "26.0.0-alpha.7",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/vezham/vx-fe-pkgs.git",
|
|
7
7
|
"directory": "packages/core/env"
|
|
8
8
|
},
|
|
9
|
+
"sideEffects": true,
|
|
9
10
|
"type": "module",
|
|
10
11
|
"exports": {
|
|
12
|
+
"./vite": {
|
|
13
|
+
"@vx/fe-kit": "./src/lib/vite/index.ts",
|
|
14
|
+
"types": "./dist/lib/vite/index.d.ts",
|
|
15
|
+
"import": "./dist/lib/vite/index.js",
|
|
16
|
+
"default": "./dist/lib/vite/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./next/config": {
|
|
19
|
+
"@vx/fe-kit": "./src/lib/next/env.ts",
|
|
20
|
+
"types": "./dist/lib/next/env.d.ts",
|
|
21
|
+
"import": "./dist/lib/next/env.js",
|
|
22
|
+
"default": "./dist/lib/next/env.js"
|
|
23
|
+
},
|
|
24
|
+
"./next": {
|
|
25
|
+
"@vx/fe-kit": "./src/lib/next/index.ts",
|
|
26
|
+
"types": "./dist/lib/next/index.d.ts",
|
|
27
|
+
"import": "./dist/lib/next/index.js",
|
|
28
|
+
"default": "./dist/lib/next/index.js"
|
|
29
|
+
},
|
|
11
30
|
".": {
|
|
12
31
|
"@vx/fe-kit": "./src/index.ts",
|
|
13
32
|
"types": "./dist/index.d.ts",
|