@rpcbase/env 0.19.0 → 0.21.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.
@@ -0,0 +1,3 @@
1
+ declare let env: any;
2
+ export default env;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ 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);
9
+ env = process.env;
10
+ } else {
11
+ env = globalThis.__rb_env__;
12
+ }
13
+ const env_default = env;
14
+ export {
15
+ env_default as default
16
+ };
@@ -0,0 +1,103 @@
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 = {};
24
+ var hasRequiredMain;
25
+ function requireMain() {
26
+ if (hasRequiredMain) return main$2;
27
+ hasRequiredMain = 1;
28
+ function _resolveEscapeSequences(value) {
29
+ return value.replace(/\\\$/g, "$");
30
+ }
31
+ function expandValue(value, processEnv, runningParsed) {
32
+ const env = { ...runningParsed, ...processEnv };
33
+ const regex = new RegExp("(?<!\\\\)\\${([^{}]+)}|(?<!\\\\)\\$([A-Za-z_][A-Za-z0-9_]*)", "g");
34
+ let result = value;
35
+ let match;
36
+ const seen = /* @__PURE__ */ new Set();
37
+ while ((match = regex.exec(result)) !== null) {
38
+ seen.add(result);
39
+ const [template, bracedExpression, unbracedExpression] = match;
40
+ const expression = bracedExpression || unbracedExpression;
41
+ const opRegex = /(:\+|\+|:-|-)/;
42
+ const opMatch = expression.match(opRegex);
43
+ const splitter = opMatch ? opMatch[0] : null;
44
+ const r = expression.split(splitter);
45
+ let defaultValue;
46
+ let value2;
47
+ const key = r.shift();
48
+ if ([":+", "+"].includes(splitter)) {
49
+ defaultValue = env[key] ? r.join(splitter) : "";
50
+ value2 = null;
51
+ } else {
52
+ defaultValue = r.join(splitter);
53
+ value2 = env[key];
54
+ }
55
+ if (value2) {
56
+ if (seen.has(value2)) {
57
+ result = result.replace(template, defaultValue);
58
+ } else {
59
+ result = result.replace(template, value2);
60
+ }
61
+ } else {
62
+ result = result.replace(template, defaultValue);
63
+ }
64
+ if (result === runningParsed[key]) {
65
+ break;
66
+ }
67
+ regex.lastIndex = 0;
68
+ }
69
+ return result;
70
+ }
71
+ function expand(options) {
72
+ const runningParsed = {};
73
+ let processEnv = process.env;
74
+ if (options && options.processEnv != null) {
75
+ processEnv = options.processEnv;
76
+ }
77
+ for (const key in options.parsed) {
78
+ let value = options.parsed[key];
79
+ if (processEnv[key] && processEnv[key] !== value) {
80
+ value = processEnv[key];
81
+ } else {
82
+ value = expandValue(value, processEnv, runningParsed);
83
+ }
84
+ options.parsed[key] = _resolveEscapeSequences(value);
85
+ runningParsed[key] = _resolveEscapeSequences(value);
86
+ }
87
+ for (const processKey in options.parsed) {
88
+ processEnv[processKey] = options.parsed[processKey];
89
+ }
90
+ return options;
91
+ }
92
+ main$2.expand = expand;
93
+ return main$2;
94
+ }
95
+ var mainExports = requireMain();
96
+ const main = /* @__PURE__ */ getDefaultExportFromCjs(mainExports);
97
+ const main$1 = /* @__PURE__ */ _mergeNamespaces({
98
+ __proto__: null,
99
+ default: main
100
+ }, [mainExports]);
101
+ export {
102
+ main$1 as m
103
+ };
@@ -0,0 +1,5 @@
1
+ declare global {
2
+ var __rb_env__: Record<string, unknown> | undefined;
3
+ }
4
+ export {};
5
+ //# sourceMappingURL=polyfill.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,13 @@
1
+ const __vite_import_meta_env__ = { "BASE_URL": "/", "DEV": false, "MODE": "production", "PROD": true, "SSR": false };
2
+ const clone = (source) => ({
3
+ ...source ?? {}
4
+ });
5
+ const ensureRbEnv = () => {
6
+ if (typeof globalThis.__rb_env__ !== "undefined" && globalThis.__rb_env__ !== null) {
7
+ return;
8
+ }
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);
11
+ globalThis.__rb_env__ = sourceEnv;
12
+ };
13
+ ensureRbEnv();
package/package.json CHANGED
@@ -1,18 +1,48 @@
1
1
  {
2
2
  "name": "@rpcbase/env",
3
- "version": "0.19.0",
3
+ "version": "0.21.0",
4
4
  "type": "module",
5
- "main": "./src/index.js",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
6
10
  "exports": {
7
- ".": "./src/index.js"
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "./polyfill": {
17
+ "types": "./dist/polyfill.d.ts",
18
+ "import": "./dist/polyfill.js",
19
+ "default": "./dist/polyfill.js"
20
+ }
8
21
  },
9
22
  "scripts": {
23
+ "build": "wireit",
10
24
  "release": "wireit"
11
25
  },
12
26
  "wireit": {
27
+ "build": {
28
+ "command": "../../node_modules/.bin/vite build",
29
+ "files": [
30
+ "src/**/*",
31
+ "../../tsconfig.json",
32
+ "../../scripts/tsconfig.pkg.json",
33
+ "./tsconfig.json",
34
+ "./vite.config.js",
35
+ "../../scripts/vite.config-pkg.js"
36
+ ],
37
+ "output": [
38
+ "dist/"
39
+ ]
40
+ },
13
41
  "release": {
14
42
  "command": "../../scripts/publish.js",
15
- "dependencies": [],
43
+ "dependencies": [
44
+ "build"
45
+ ],
16
46
  "files": [
17
47
  "package.json",
18
48
  "src/**/*"
@@ -26,8 +56,9 @@
26
56
  }
27
57
  },
28
58
  "dependencies": {
29
- "dotenv": "17.0.0",
30
- "dotenv-expand": "12.0.2"
59
+ "dotenv": "17.2.3"
31
60
  },
32
- "devDependencies": {}
61
+ "devDependencies": {
62
+ "dotenv-expand": "12.0.3"
63
+ }
33
64
  }
package/src/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import type { DotenvConfigOptions, DotenvConfigOutput } from "dotenv"
2
-
3
-
4
- declare const env: {
5
- config: (options?: DotenvConfigOptions) => DotenvConfigOutput
6
- }
7
-
8
- export default env
package/src/index.js DELETED
@@ -1,17 +0,0 @@
1
- import dotenv from "dotenv"
2
- import dotenvExpand from "dotenv-expand"
3
-
4
-
5
- const config = (opts = {quiet: true}) => {
6
- if (typeof opts.quiet === "undefined") {
7
- opts.quiet = true
8
- }
9
-
10
- const dotenvResult = dotenv.config(opts)
11
- dotenvExpand.expand(dotenvResult)
12
-
13
- return dotenvResult
14
- }
15
-
16
-
17
- export default {config}