@stryke/env 0.17.6 → 0.18.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/load-env.cjs +26 -25
- package/dist/load-env.mjs +1 -1
- package/dist/types.cjs +1 -1
- package/dist/types.mjs +1 -1
- package/package.json +3 -2
package/dist/load-env.cjs
CHANGED
|
@@ -9,47 +9,48 @@ exports.loadEnv = loadEnv;
|
|
|
9
9
|
exports.loadEnvFile = loadEnvFile;
|
|
10
10
|
exports.loadServerEnv = loadServerEnv;
|
|
11
11
|
var _dotenvx = require("@dotenvx/dotenvx");
|
|
12
|
+
var _toArray = require("@stryke/convert/to-array");
|
|
12
13
|
var _readFile = require("@stryke/fs/read-file");
|
|
13
14
|
var _exists = require("@stryke/path/exists");
|
|
14
15
|
var _joinPaths = require("@stryke/path/join-paths");
|
|
15
16
|
var _defu = _interopRequireDefault(require("defu"));
|
|
16
17
|
var _types = require("./types.cjs");
|
|
17
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
-
function getEnvFilesForMode(
|
|
19
|
-
return [".env", ".env.local", `.env.${
|
|
19
|
+
function getEnvFilesForMode(r, s = "production") {
|
|
20
|
+
return [".env", ".env.local", `.env.${s}`, `.env.${s}.local`, `.env.local.${s}`].map(i => (0, _joinPaths.joinPaths)(r, i));
|
|
20
21
|
}
|
|
21
|
-
async function loadEnvFile(
|
|
22
|
-
const
|
|
23
|
-
return (await Promise.all((
|
|
24
|
-
if ((0, _exists.existsSync)(
|
|
25
|
-
}))).reduce((
|
|
26
|
-
if (!
|
|
27
|
-
const
|
|
22
|
+
async function loadEnvFile(r, s = []) {
|
|
23
|
+
const i = Array.isArray(s) ? s : [s];
|
|
24
|
+
return (await Promise.all((s.length > 0 ? i.map(e => (0, _joinPaths.joinPaths)(e, r)) : [r]).map(async e => {
|
|
25
|
+
if ((0, _exists.existsSync)(e)) return (0, _readFile.readFile)(e);
|
|
26
|
+
}))).reduce((e, a) => {
|
|
27
|
+
if (!a) return e;
|
|
28
|
+
const u = (0, _dotenvx.parse)(a, {
|
|
28
29
|
processEnv: {
|
|
29
30
|
...process.env
|
|
30
31
|
},
|
|
31
32
|
privateKey: process.env.DOTENV_PRIVATE_KEY || process.env.STORM_PRIVATE_KEY
|
|
32
33
|
});
|
|
33
|
-
return (0, _defu.default)(
|
|
34
|
+
return (0, _defu.default)(u, e);
|
|
34
35
|
}, {});
|
|
35
36
|
}
|
|
36
|
-
async function loadEnv(
|
|
37
|
-
if (
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
let o = (await Promise.all(
|
|
37
|
+
async function loadEnv(r, s, i) {
|
|
38
|
+
if (s === "local") throw new Error('"local" cannot be used as a mode name because it conflicts with the .local postfix for .env files.');
|
|
39
|
+
const e = (0, _toArray.toArray)(i).reduce((n, t) => (t && (n.includes(t.endsWith("_") ? t : `${t}_`) || n.push(t.endsWith("_") ? t : `${t}_`), n.includes(`${t.endsWith("_") ? t : `${t}_`}PUBLIC_`) || n.push(`${t.endsWith("_") ? t : `${t}_`}PUBLIC_`)), n), []),
|
|
40
|
+
a = Array.isArray(r) ? r : [r],
|
|
41
|
+
u = {},
|
|
42
|
+
l = a.reduce((n, t) => (n.push(...getEnvFilesForMode(t, s).filter(c => !n.includes(c))), n), []);
|
|
43
|
+
let o = (await Promise.all(l.map(async n => loadEnvFile(n)))).reduce((n, t) => (0, _defu.default)(t, n), {});
|
|
43
44
|
if (o.NODE_ENV && process.env.VITE_USER_NODE_ENV === void 0 && (process.env.VITE_USER_NODE_ENV = JSON.stringify(o.NODE_ENV)), o.BROWSER && process.env.BROWSER === void 0 && (process.env.BROWSER = JSON.stringify(o.BROWSER)), o.BROWSER_ARGS && process.env.BROWSER_ARGS === void 0 && (process.env.BROWSER_ARGS = JSON.stringify(o.BROWSER_ARGS)), o = (0, _defu.default)({
|
|
44
45
|
...process.env
|
|
45
|
-
}, o),
|
|
46
|
-
for (const [
|
|
47
|
-
for (const
|
|
48
|
-
return
|
|
46
|
+
}, o), e.length === 0) return o;
|
|
47
|
+
for (const [n, t] of Object.entries(o)) e.some(c => n.startsWith(c)) && (u[n] = String(t));
|
|
48
|
+
for (const n in process.env) e.some(t => n.startsWith(t)) && (u[n] = process.env[n]);
|
|
49
|
+
return u;
|
|
49
50
|
}
|
|
50
|
-
async function loadClientEnv(
|
|
51
|
-
return loadEnv(
|
|
51
|
+
async function loadClientEnv(r, s, i = _types.ENV_PREFIXES) {
|
|
52
|
+
return loadEnv(r, s, i);
|
|
52
53
|
}
|
|
53
|
-
async function loadServerEnv(
|
|
54
|
-
return loadEnv(
|
|
54
|
+
async function loadServerEnv(r, s) {
|
|
55
|
+
return loadEnv(r, s);
|
|
55
56
|
}
|
package/dist/load-env.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parse as
|
|
1
|
+
import{parse as E}from"@dotenvx/dotenvx";import{toArray as v}from"@stryke/convert/to-array";import{readFile as d}from"@stryke/fs/read-file";import{existsSync as m}from"@stryke/path/exists";import{joinPaths as p}from"@stryke/path/join-paths";import f from"defu";import{ENV_PREFIXES as g}from"./types";export function getEnvFilesForMode(r,s="production"){return[".env",".env.local",`.env.${s}`,`.env.${s}.local`,`.env.local.${s}`].map(i=>p(r,i))}export async function loadEnvFile(r,s=[]){const i=Array.isArray(s)?s:[s];return(await Promise.all((s.length>0?i.map(e=>p(e,r)):[r]).map(async e=>{if(m(e))return d(e)}))).reduce((e,a)=>{if(!a)return e;const u=E(a,{processEnv:{...process.env},privateKey:process.env.DOTENV_PRIVATE_KEY||process.env.STORM_PRIVATE_KEY});return f(u,e)},{})}export async function loadEnv(r,s,i){if(s==="local")throw new Error('"local" cannot be used as a mode name because it conflicts with the .local postfix for .env files.');const e=v(i).reduce((n,t)=>(t&&(n.includes(t.endsWith("_")?t:`${t}_`)||n.push(t.endsWith("_")?t:`${t}_`),n.includes(`${t.endsWith("_")?t:`${t}_`}PUBLIC_`)||n.push(`${t.endsWith("_")?t:`${t}_`}PUBLIC_`)),n),[]),a=Array.isArray(r)?r:[r],u={},l=a.reduce((n,t)=>(n.push(...getEnvFilesForMode(t,s).filter(c=>!n.includes(c))),n),[]);let o=(await Promise.all(l.map(async n=>loadEnvFile(n)))).reduce((n,t)=>f(t,n),{});if(o.NODE_ENV&&process.env.VITE_USER_NODE_ENV===void 0&&(process.env.VITE_USER_NODE_ENV=JSON.stringify(o.NODE_ENV)),o.BROWSER&&process.env.BROWSER===void 0&&(process.env.BROWSER=JSON.stringify(o.BROWSER)),o.BROWSER_ARGS&&process.env.BROWSER_ARGS===void 0&&(process.env.BROWSER_ARGS=JSON.stringify(o.BROWSER_ARGS)),o=f({...process.env},o),e.length===0)return o;for(const[n,t]of Object.entries(o))e.some(c=>n.startsWith(c))&&(u[n]=String(t));for(const n in process.env)e.some(t=>n.startsWith(t))&&(u[n]=process.env[n]);return u}export async function loadClientEnv(r,s,i=g){return loadEnv(r,s,i)}export async function loadServerEnv(r,s){return loadEnv(r,s)}
|
package/dist/types.cjs
CHANGED
|
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.ENV_PREFIXES = void 0;
|
|
7
|
-
const ENV_PREFIXES = exports.ENV_PREFIXES = ["VITE_", "ONE_", "
|
|
7
|
+
const ENV_PREFIXES = exports.ENV_PREFIXES = ["VITE_", "ONE_", "STORM_", "STORM_STACK_", "NEXT_", "VERCEL_"];
|
package/dist/types.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const ENV_PREFIXES=["VITE_","ONE_","
|
|
1
|
+
export const ENV_PREFIXES=["VITE_","ONE_","STORM_","STORM_STACK_","NEXT_","VERCEL_"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/env",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing utility functions to handle environment specific processes",
|
|
6
6
|
"repository": {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"private": false,
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@dotenvx/dotenvx": "1.35.0",
|
|
14
|
+
"@stryke/convert": "^0.3.1",
|
|
14
15
|
"@stryke/fs": "^0.25.0",
|
|
15
16
|
"@stryke/path": "^0.12.5",
|
|
16
17
|
"@stryke/string-format": "^0.10.0",
|
|
@@ -174,5 +175,5 @@
|
|
|
174
175
|
"main": "./dist/index.cjs",
|
|
175
176
|
"module": "./dist/index.mjs",
|
|
176
177
|
"types": "./dist/index.d.ts",
|
|
177
|
-
"gitHead": "
|
|
178
|
+
"gitHead": "3326ca10ce43fd782ffb2fa29d49bf152e1dac05"
|
|
178
179
|
}
|