@rpcbase/env 0.20.0 → 0.22.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,QAAA,IAAI,GAAG,KAAA,CAAA;AAkBP,eAAe,GAAG,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,QAAA,IAAI,GAAG,KAAA,CAAA;AAaP,eAAe,GAAG,CAAA"}
package/dist/index.js CHANGED
@@ -1,11 +1,8 @@
1
+ import { l as loadProcessEnv } from "./loadProcessEnv-C2ldVaD0.js";
1
2
  let env;
2
- if (typeof window === "undefined" || globalThis.__rb_env__.SSR) {
3
- const [dotenv, dotenvExpand] = await Promise.all([
4
- import("dotenv"),
5
- import("./main-BjcmORtn.js").then((n) => n.m)
6
- ]);
7
- const result = dotenv.config({ quiet: true });
8
- dotenvExpand.expand(result);
3
+ const isServer = typeof window === "undefined" || typeof import.meta !== "undefined" && Boolean(false);
4
+ if (isServer) {
5
+ loadProcessEnv();
9
6
  env = process.env;
10
7
  } else {
11
8
  env = globalThis.__rb_env__;
@@ -1,29 +1,8 @@
1
- function _mergeNamespaces(n, m) {
2
- for (var i = 0; i < m.length; i++) {
3
- const e = m[i];
4
- if (typeof e !== "string" && !Array.isArray(e)) {
5
- for (const k in e) {
6
- if (k !== "default" && !(k in n)) {
7
- const d = Object.getOwnPropertyDescriptor(e, k);
8
- if (d) {
9
- Object.defineProperty(n, k, d.get ? d : {
10
- enumerable: true,
11
- get: () => e[k]
12
- });
13
- }
14
- }
15
- }
16
- }
17
- }
18
- return Object.freeze(Object.defineProperty(n, Symbol.toStringTag, { value: "Module" }));
19
- }
20
- function getDefaultExportFromCjs(x) {
21
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
22
- }
23
- var main$2 = {};
1
+ import dotenv from "dotenv";
2
+ var main = {};
24
3
  var hasRequiredMain;
25
4
  function requireMain() {
26
- if (hasRequiredMain) return main$2;
5
+ if (hasRequiredMain) return main;
27
6
  hasRequiredMain = 1;
28
7
  function _resolveEscapeSequences(value) {
29
8
  return value.replace(/\\\$/g, "$");
@@ -89,15 +68,22 @@ function requireMain() {
89
68
  }
90
69
  return options;
91
70
  }
92
- main$2.expand = expand;
93
- return main$2;
71
+ main.expand = expand;
72
+ return main;
94
73
  }
95
74
  var mainExports = requireMain();
96
- const main = /* @__PURE__ */ getDefaultExportFromCjs(mainExports);
97
- const main$1 = /* @__PURE__ */ _mergeNamespaces({
98
- __proto__: null,
99
- default: main
100
- }, [mainExports]);
75
+ let hasLoaded = false;
76
+ const loadProcessEnv = () => {
77
+ if (typeof process === "undefined") {
78
+ return void 0;
79
+ }
80
+ if (!hasLoaded) {
81
+ const result = dotenv.config({ quiet: true });
82
+ mainExports.expand(result);
83
+ hasLoaded = true;
84
+ }
85
+ return process.env;
86
+ };
101
87
  export {
102
- main$1 as m
88
+ loadProcessEnv as l
103
89
  };
@@ -0,0 +1,2 @@
1
+ export declare const loadProcessEnv: () => NodeJS.ProcessEnv | undefined;
2
+ //# sourceMappingURL=loadProcessEnv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadProcessEnv.d.ts","sourceRoot":"","sources":["../src/loadProcessEnv.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,cAAc,qCAY1B,CAAA"}
@@ -1,5 +1,2 @@
1
- declare global {
2
- var __rb_env__: Record<string, unknown> | undefined;
3
- }
4
1
  export {};
5
2
  //# sourceMappingURL=polyfill.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;CACpD;AAqBD,OAAO,EAAE,CAAA"}
1
+ {"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,CAAA"}
package/dist/polyfill.js CHANGED
@@ -1,13 +1,10 @@
1
+ import { h as hasRbEnv, a as hasWindow, c as cloneEnv } from "./polyfillShared-Cr5QEVF7.js";
1
2
  const __vite_import_meta_env__ = { "BASE_URL": "/", "DEV": false, "MODE": "production", "PROD": true, "SSR": false };
2
- const clone = (source) => ({
3
- ...source ?? {}
4
- });
5
3
  const ensureRbEnv = () => {
6
- if (typeof globalThis.__rb_env__ !== "undefined" && globalThis.__rb_env__ !== null) {
4
+ if (hasRbEnv()) {
7
5
  return;
8
6
  }
9
- const hasWindow = typeof globalThis === "object" && "window" in globalThis;
10
- const sourceEnv = hasWindow ? clone(typeof import.meta === "undefined" ? void 0 : __vite_import_meta_env__) : clone(typeof process === "undefined" ? void 0 : process.env);
7
+ const sourceEnv = hasWindow() ? cloneEnv(typeof import.meta === "undefined" ? void 0 : __vite_import_meta_env__) : cloneEnv(typeof process === "undefined" ? void 0 : process.env);
11
8
  globalThis.__rb_env__ = sourceEnv;
12
9
  };
13
10
  ensureRbEnv();
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=polyfill.node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polyfill.node.d.ts","sourceRoot":"","sources":["../src/polyfill.node.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { l as loadProcessEnv } from "./loadProcessEnv-C2ldVaD0.js";
2
+ import { h as hasRbEnv, c as cloneEnv } from "./polyfillShared-Cr5QEVF7.js";
3
+ const ensureServerEnv = () => {
4
+ if (hasRbEnv()) {
5
+ return;
6
+ }
7
+ loadProcessEnv();
8
+ globalThis.__rb_env__ = cloneEnv(typeof process === "undefined" ? void 0 : process.env);
9
+ };
10
+ ensureServerEnv();
@@ -0,0 +1,10 @@
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
+ };
@@ -0,0 +1,8 @@
1
+ declare global {
2
+ var __rb_env__: Record<string, unknown> | undefined;
3
+ }
4
+ export declare const cloneEnv: <T extends Record<string, unknown> | undefined>(source: T) => {};
5
+ export declare const hasWindow: () => boolean;
6
+ export declare const hasRbEnv: () => boolean;
7
+ export {};
8
+ //# sourceMappingURL=polyfillShared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polyfillShared.d.ts","sourceRoot":"","sources":["../src/polyfillShared.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;CACpD;AAED,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAAE,QAAQ,CAAC,OAE/E,CAAA;AAEF,eAAO,MAAM,SAAS,eAAiE,CAAA;AAEvF,eAAO,MAAM,QAAQ,eAAuF,CAAA;AAE5G,OAAO,EAAE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/env",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -15,8 +15,14 @@
15
15
  },
16
16
  "./polyfill": {
17
17
  "types": "./dist/polyfill.d.ts",
18
- "import": "./dist/polyfill.js",
19
- "default": "./dist/polyfill.js"
18
+ "browser": "./dist/polyfill.js",
19
+ "import": "./dist/polyfill.node.js",
20
+ "default": "./dist/polyfill.node.js"
21
+ },
22
+ "./polyfill/node": {
23
+ "types": "./dist/polyfill.node.d.ts",
24
+ "import": "./dist/polyfill.node.js",
25
+ "default": "./dist/polyfill.node.js"
20
26
  }
21
27
  },
22
28
  "scripts": {