@rpcbase/env 0.29.0 → 0.30.0
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/{ensureDefaultEnvFlags-Cn364E_C.js → ensureDefaultEnvFlags-C1vDaR9V.js} +10 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +35 -12
- package/dist/polyfill.js +1 -2
- package/dist/polyfill.node.js +1 -2
- package/package.json +1 -1
- package/dist/polyfillShared-Cr5QEVF7.js +0 -10
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
const cloneEnv = (source) => ({
|
|
2
|
+
...source ?? {}
|
|
3
|
+
});
|
|
4
|
+
const hasWindow = () => typeof globalThis === "object" && "window" in globalThis;
|
|
5
|
+
const hasRbEnv = () => typeof globalThis.__rb_env__ !== "undefined" && globalThis.__rb_env__ !== null;
|
|
1
6
|
const pickMode = (modeHint, isServer) => {
|
|
2
7
|
if (typeof modeHint === "string" && modeHint.length > 0) {
|
|
3
8
|
return modeHint;
|
|
@@ -12,9 +17,7 @@ const ensureDefaultEnvFlags = (env, hints) => {
|
|
|
12
17
|
return;
|
|
13
18
|
}
|
|
14
19
|
const target = env;
|
|
15
|
-
|
|
16
|
-
target.SSR = hints.isServer;
|
|
17
|
-
}
|
|
20
|
+
target.SSR = hints.isServer;
|
|
18
21
|
if (typeof target.MODE !== "string" || target.MODE.length === 0) {
|
|
19
22
|
target.MODE = pickMode(hints.modeHint, hints.isServer);
|
|
20
23
|
}
|
|
@@ -29,5 +32,8 @@ const ensureDefaultEnvFlags = (env, hints) => {
|
|
|
29
32
|
}
|
|
30
33
|
};
|
|
31
34
|
export {
|
|
32
|
-
|
|
35
|
+
hasWindow as a,
|
|
36
|
+
cloneEnv as c,
|
|
37
|
+
ensureDefaultEnvFlags as e,
|
|
38
|
+
hasRbEnv as h
|
|
33
39
|
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAA;AAiD7D,QAAA,MAAM,GAAG,EAAoB,SAAS,CAAA;AAEtC,eAAe,GAAG,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,40 @@
|
|
|
1
1
|
import { l as loadProcessEnv } from "./loadProcessEnv-C2ldVaD0.js";
|
|
2
|
-
import { h as hasRbEnv } from "./
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { h as hasRbEnv, e as ensureDefaultEnvFlags, c as cloneEnv, a as hasWindow } from "./ensureDefaultEnvFlags-C1vDaR9V.js";
|
|
3
|
+
const __vite_import_meta_env__ = { "BASE_URL": "/", "DEV": false, "MODE": "production", "PROD": true, "SSR": false };
|
|
4
|
+
const resolveModeHint = () => {
|
|
5
|
+
if (typeof import.meta !== "undefined") {
|
|
6
|
+
const mode = "production";
|
|
7
|
+
if (mode.length > 0) {
|
|
8
|
+
return mode;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
if (typeof process !== "undefined" && typeof process.env?.NODE_ENV === "string") {
|
|
12
|
+
return process.env.NODE_ENV;
|
|
13
|
+
}
|
|
14
|
+
return void 0;
|
|
15
|
+
};
|
|
16
|
+
const ensureRbEnv = () => {
|
|
17
|
+
const isServer = !hasWindow();
|
|
18
|
+
const modeHint = resolveModeHint();
|
|
8
19
|
if (hasRbEnv()) {
|
|
9
|
-
|
|
20
|
+
ensureDefaultEnvFlags(globalThis.__rb_env__, {
|
|
21
|
+
isServer,
|
|
22
|
+
modeHint
|
|
23
|
+
});
|
|
24
|
+
return globalThis.__rb_env__;
|
|
10
25
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
const
|
|
26
|
+
if (isServer) {
|
|
27
|
+
loadProcessEnv();
|
|
28
|
+
}
|
|
29
|
+
const sourceEnv = isServer ? cloneEnv(typeof process === "undefined" ? void 0 : process.env) : cloneEnv(typeof import.meta === "undefined" ? void 0 : __vite_import_meta_env__);
|
|
30
|
+
ensureDefaultEnvFlags(sourceEnv, {
|
|
31
|
+
isServer,
|
|
32
|
+
modeHint
|
|
33
|
+
});
|
|
34
|
+
globalThis.__rb_env__ = sourceEnv;
|
|
35
|
+
return globalThis.__rb_env__;
|
|
36
|
+
};
|
|
37
|
+
const env = ensureRbEnv();
|
|
15
38
|
export {
|
|
16
|
-
|
|
39
|
+
env as default
|
|
17
40
|
};
|
package/dist/polyfill.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { h as hasRbEnv, c as cloneEnv, a as hasWindow } from "./
|
|
2
|
-
import { e as ensureDefaultEnvFlags } from "./ensureDefaultEnvFlags-Cn364E_C.js";
|
|
1
|
+
import { h as hasRbEnv, e as ensureDefaultEnvFlags, c as cloneEnv, a as hasWindow } from "./ensureDefaultEnvFlags-C1vDaR9V.js";
|
|
3
2
|
const resolveViteEnv = () => {
|
|
4
3
|
if (typeof __vite_env__ === "undefined") {
|
|
5
4
|
return void 0;
|
package/dist/polyfill.node.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { l as loadProcessEnv } from "./loadProcessEnv-C2ldVaD0.js";
|
|
2
|
-
import { h as hasRbEnv, c as cloneEnv } from "./
|
|
3
|
-
import { e as ensureDefaultEnvFlags } from "./ensureDefaultEnvFlags-Cn364E_C.js";
|
|
2
|
+
import { h as hasRbEnv, e as ensureDefaultEnvFlags, c as cloneEnv } from "./ensureDefaultEnvFlags-C1vDaR9V.js";
|
|
4
3
|
const resolveModeHint = () => {
|
|
5
4
|
if (typeof process === "undefined") {
|
|
6
5
|
return void 0;
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const cloneEnv = (source) => ({
|
|
2
|
-
...source ?? {}
|
|
3
|
-
});
|
|
4
|
-
const hasWindow = () => typeof globalThis === "object" && "window" in globalThis;
|
|
5
|
-
const hasRbEnv = () => typeof globalThis.__rb_env__ !== "undefined" && globalThis.__rb_env__ !== null;
|
|
6
|
-
export {
|
|
7
|
-
hasWindow as a,
|
|
8
|
-
cloneEnv as c,
|
|
9
|
-
hasRbEnv as h
|
|
10
|
-
};
|