@stryke/env 0.4.0 → 0.4.2

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.
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getEnvPaths = getEnvPaths;
7
- var _joinPaths = require("@stryke/path/utilities/join-paths");
7
+ var _joinPaths = require("@stryke/path/join-paths");
8
8
  var _titleCase = require("@stryke/string-format/title-case");
9
- var _isString = require("@stryke/types/type-checks/is-string");
9
+ var _isString = require("@stryke/type-checks/is-string");
10
10
  var _nodeOs = _interopRequireDefault(require("node:os"));
11
11
  var _nodePath = _interopRequireDefault(require("node:path"));
12
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Options for the `getEnvPaths` function.
3
3
  */
4
- export type GetEnvPathsOptions = {
4
+ export interface GetEnvPathsOptions {
5
5
  /**
6
6
  * The name of the organization
7
7
  *
@@ -36,14 +36,14 @@ export type GetEnvPathsOptions = {
36
36
  * The root directory of the workspace that is used for determining the `cache` and `tmp` paths if they were not already set by other means.
37
37
  */
38
38
  workspaceRoot?: string;
39
- };
40
- export type EnvPaths = {
39
+ }
40
+ export interface EnvPaths {
41
41
  data: string;
42
42
  config: string;
43
43
  cache: string;
44
44
  log: string;
45
45
  temp: string;
46
- };
46
+ }
47
47
  /**
48
48
  * Get paths for storing things like data, config, logs, and cache in the current runtime environment.
49
49
  *
@@ -1 +1 @@
1
- import{joinPaths as s}from"@stryke/path/utilities/join-paths";import{titleCase as f}from"@stryke/string-format/title-case";import{isString as R}from"@stryke/types/type-checks/is-string";import p from"node:os";import g from"node:path";const n=p.homedir(),o=p.tmpdir(),l=e=>{const r=s(n,"Library");return{data:s(r,"Application Support",e),config:s(r,"Preferences",e),cache:s(r,"Caches",e),log:s(r,"Logs",e),temp:s(o,e)}},E=e=>{const r=process.env.APPDATA||s(n,"AppData","Roaming"),t=process.env.LOCALAPPDATA||s(n,"AppData","Local"),a=f(e).trim().replace(/\s+/g,"");return{data:s(t,a,"Data"),config:s(r,a,"Config"),cache:s(t,"Cache",e),log:s(t,a,"Log"),temp:s(o,e)}},O=e=>{const r=g.basename(n);return{data:s(process.env.XDG_DATA_HOME||s(n,".local","share"),e),config:s(process.env.XDG_CONFIG_HOME||s(n,".config"),e),cache:s(process.env.XDG_CACHE_HOME||s(n,".cache"),e),log:s(process.env.XDG_STATE_HOME||s(n,".local","state"),e),temp:s(o,r,e)}};export function getEnvPaths(e={}){let r=e.orgId||"storm-software";if(!r)throw new Error("You need to provide an orgId to the `getEnvPaths` function");e.suffix&&(r+=`-${R(e.suffix)?e.suffix:"nodejs"}`);let t={};return process.platform==="darwin"?t=l(r):process.platform==="win32"?t=E(r):t=O(r),process.env.STORM_DATA_DIRECTORY?t.data=process.env.STORM_DATA_DIRECTORY:process.env.STORM_CONFIG_DIRECTORY?t.config=process.env.STORM_CONFIG_DIRECTORY:process.env.STORM_CACHE_DIRECTORY?t.cache=process.env.STORM_CACHE_DIRECTORY:process.env.STORM_LOG_DIRECTORY?t.log=process.env.STORM_LOG_DIRECTORY:process.env.STORM_TEMP_DIRECTORY&&(t.temp=process.env.STORM_TEMP_DIRECTORY),e.workspaceRoot&&(t.cache??=s(e.workspaceRoot,"node_modules",".cache",r),t.temp??=s(e.workspaceRoot,"tmp",r),t.log??=s(t.temp,"logs"),t.config??=s(e.workspaceRoot,".config",r)),Object.keys(t).reduce((a,c)=>{if(t[c]){const i=t[c];a[c]=e.appId&&e.appId!==e.orgId&&e.appId!==e.nestedDir?s(i,e.appId):i,e.nestedDir&&e.nestedDir!==e.orgId&&e.nestedDir!==e.appId&&(a[c]=s(a[c],e.nestedDir))}return a},{})}
1
+ import{joinPaths as s}from"@stryke/path/join-paths";import{titleCase as f}from"@stryke/string-format/title-case";import{isString as R}from"@stryke/type-checks/is-string";import p from"node:os";import g from"node:path";const n=p.homedir(),o=p.tmpdir(),l=e=>{const r=s(n,"Library");return{data:s(r,"Application Support",e),config:s(r,"Preferences",e),cache:s(r,"Caches",e),log:s(r,"Logs",e),temp:s(o,e)}},E=e=>{const r=process.env.APPDATA||s(n,"AppData","Roaming"),t=process.env.LOCALAPPDATA||s(n,"AppData","Local"),a=f(e).trim().replace(/\s+/g,"");return{data:s(t,a,"Data"),config:s(r,a,"Config"),cache:s(t,"Cache",e),log:s(t,a,"Log"),temp:s(o,e)}},O=e=>{const r=g.basename(n);return{data:s(process.env.XDG_DATA_HOME||s(n,".local","share"),e),config:s(process.env.XDG_CONFIG_HOME||s(n,".config"),e),cache:s(process.env.XDG_CACHE_HOME||s(n,".cache"),e),log:s(process.env.XDG_STATE_HOME||s(n,".local","state"),e),temp:s(o,r,e)}};export function getEnvPaths(e={}){let r=e.orgId||"storm-software";if(!r)throw new Error("You need to provide an orgId to the `getEnvPaths` function");e.suffix&&(r+=`-${R(e.suffix)?e.suffix:"nodejs"}`);let t={};return process.platform==="darwin"?t=l(r):process.platform==="win32"?t=E(r):t=O(r),process.env.STORM_DATA_DIRECTORY?t.data=process.env.STORM_DATA_DIRECTORY:process.env.STORM_CONFIG_DIRECTORY?t.config=process.env.STORM_CONFIG_DIRECTORY:process.env.STORM_CACHE_DIRECTORY?t.cache=process.env.STORM_CACHE_DIRECTORY:process.env.STORM_LOG_DIRECTORY?t.log=process.env.STORM_LOG_DIRECTORY:process.env.STORM_TEMP_DIRECTORY&&(t.temp=process.env.STORM_TEMP_DIRECTORY),e.workspaceRoot&&(t.cache??=s(e.workspaceRoot,"node_modules",".cache",r),t.temp??=s(e.workspaceRoot,"tmp",r),t.log??=s(t.temp,"logs"),t.config??=s(e.workspaceRoot,".config",r)),Object.keys(t).reduce((a,c)=>{if(t[c]){const i=t[c];a[c]=e.appId&&e.appId!==e.orgId&&e.appId!==e.nestedDir?s(i,e.appId):i,e.nestedDir&&e.nestedDir!==e.orgId&&e.nestedDir!==e.appId&&(a[c]=s(a[c],e.nestedDir))}return a},{})}
package/dist/load-env.cjs CHANGED
@@ -9,47 +9,47 @@ exports.loadEnv = loadEnv;
9
9
  exports.loadEnvFile = loadEnvFile;
10
10
  exports.loadServerEnv = loadServerEnv;
11
11
  var _dotenvx = require("@dotenvx/dotenvx");
12
- var _readFile = require("@stryke/fs/files/read-file");
12
+ var _readFile = require("@stryke/fs/read-file");
13
13
  var _json = require("@stryke/json");
14
14
  var _path = require("@stryke/path");
15
15
  var _defu = _interopRequireDefault(require("defu"));
16
16
  var _types = require("./types.cjs");
17
17
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
- function getEnvFilesForMode(n, r = "production") {
19
- return [".env", ".env.local", `.env.${r}`, `.env.${r}.local`, `.env.local.${r}`].map(s => (0, _path.joinPaths)(n, s));
18
+ function getEnvFilesForMode(t, r = "production") {
19
+ return [".env", ".env.local", `.env.${r}`, `.env.${r}.local`, `.env.local.${r}`].map(s => (0, _path.joinPaths)(t, s));
20
20
  }
21
- async function loadEnvFile(n, r = []) {
21
+ async function loadEnvFile(t, r = []) {
22
22
  const s = Array.isArray(r) ? r : [r];
23
- return (await Promise.all((r.length > 0 ? s.map(t => (0, _path.joinPaths)(t, n)) : [n]).map(t => {
24
- if ((0, _path.existsSync)(t)) return (0, _readFile.readFile)(t);
25
- }))).reduce((t, u) => {
26
- if (!u) return t;
23
+ return (await Promise.all((r.length > 0 ? s.map(n => (0, _path.joinPaths)(n, t)) : [t]).map(n => {
24
+ if ((0, _path.existsSync)(n)) return (0, _readFile.readFile)(n);
25
+ }))).reduce((n, u) => {
26
+ if (!u) return n;
27
27
  const a = (0, _dotenvx.parse)(u, {
28
28
  processEnv: {
29
29
  ...process.env
30
30
  },
31
31
  privateKey: process.env.DOTENV_PRIVATE_KEY || process.env.STORM_PRIVATE_KEY
32
32
  });
33
- return (0, _defu.default)(a, t);
33
+ return (0, _defu.default)(a, n);
34
34
  }, {});
35
35
  }
36
- async function loadEnv(n, r, s) {
36
+ async function loadEnv(t, r, s) {
37
37
  if (r === "local") throw new Error('"local" cannot be used as a mode name because it conflicts with the .local postfix for .env files.');
38
- const t = s ? Array.isArray(s) ? s : [s] : [],
39
- u = Array.isArray(n) ? n : [n],
38
+ const n = s ? Array.isArray(s) ? s : [s] : [],
39
+ u = Array.isArray(t) ? t : [t],
40
40
  a = {},
41
- l = u.reduce((e, i) => (e.push(...getEnvFilesForMode(i, r).filter(c => !e.includes(c))), e), []);
42
- let o = (await Promise.all(l.map(e => loadEnvFile(e)))).reduce((e, i) => (0, _defu.default)(i, e), {});
41
+ v = u.reduce((e, i) => (e.push(...getEnvFilesForMode(i, r).filter(c => !e.includes(c))), e), []);
42
+ let o = (await Promise.all(v.map(async e => loadEnvFile(e)))).reduce((e, i) => (0, _defu.default)(i, e), {});
43
43
  if (o.NODE_ENV && process.env.VITE_USER_NODE_ENV === void 0 && (process.env.VITE_USER_NODE_ENV = _json.StormJSON.stringify(o.NODE_ENV)), o.BROWSER && process.env.BROWSER === void 0 && (process.env.BROWSER = _json.StormJSON.stringify(o.BROWSER)), o.BROWSER_ARGS && process.env.BROWSER_ARGS === void 0 && (process.env.BROWSER_ARGS = _json.StormJSON.stringify(o.BROWSER_ARGS)), o = (0, _defu.default)({
44
44
  ...process.env
45
- }, o), t.length === 0) return o;
46
- for (const [e, i] of Object.entries(o)) t.some(c => e.startsWith(c)) && (a[e] = String(i));
47
- for (const e in process.env) t.some(i => e.startsWith(i)) && (a[e] = process.env[e]);
45
+ }, o), n.length === 0) return o;
46
+ for (const [e, i] of Object.entries(o)) n.some(c => e.startsWith(c)) && (a[e] = String(i));
47
+ for (const e in process.env) n.some(i => e.startsWith(i)) && (a[e] = process.env[e]);
48
48
  return a;
49
49
  }
50
- async function loadClientEnv(n, r, s = _types.ENV_PREFIXES) {
51
- return loadEnv(n, r, s);
50
+ async function loadClientEnv(t, r, s = _types.ENV_PREFIXES) {
51
+ return loadEnv(t, r, s);
52
52
  }
53
- async function loadServerEnv(n, r) {
54
- return loadEnv(n, r);
53
+ async function loadServerEnv(t, r) {
54
+ return loadEnv(t, r);
55
55
  }
@@ -1,4 +1,4 @@
1
- import { type DotenvParseOutput } from "./types";
1
+ import type { DotenvParseOutput } from "./types";
2
2
  export declare function getEnvFilesForMode(envDir: string, mode?: string): string[];
3
3
  /**
4
4
  * Load environment variables from a .env file.
package/dist/load-env.mjs CHANGED
@@ -1 +1 @@
1
- import{parse as v}from"@dotenvx/dotenvx";import{readFile as g}from"@stryke/fs/files/read-file";import{StormJSON as p}from"@stryke/json";import{existsSync as R,joinPaths as f}from"@stryke/path";import E from"defu";import{ENV_PREFIXES as m}from"./types";export function getEnvFilesForMode(n,r="production"){return[".env",".env.local",`.env.${r}`,`.env.${r}.local`,`.env.local.${r}`].map(s=>f(n,s))}export async function loadEnvFile(n,r=[]){const s=Array.isArray(r)?r:[r];return(await Promise.all((r.length>0?s.map(t=>f(t,n)):[n]).map(t=>{if(R(t))return g(t)}))).reduce((t,u)=>{if(!u)return t;const a=v(u,{processEnv:{...process.env},privateKey:process.env.DOTENV_PRIVATE_KEY||process.env.STORM_PRIVATE_KEY});return E(a,t)},{})}export async function loadEnv(n,r,s){if(r==="local")throw new Error('"local" cannot be used as a mode name because it conflicts with the .local postfix for .env files.');const t=s?Array.isArray(s)?s:[s]:[],u=Array.isArray(n)?n:[n],a={},l=u.reduce((e,i)=>(e.push(...getEnvFilesForMode(i,r).filter(c=>!e.includes(c))),e),[]);let o=(await Promise.all(l.map(e=>loadEnvFile(e)))).reduce((e,i)=>E(i,e),{});if(o.NODE_ENV&&process.env.VITE_USER_NODE_ENV===void 0&&(process.env.VITE_USER_NODE_ENV=p.stringify(o.NODE_ENV)),o.BROWSER&&process.env.BROWSER===void 0&&(process.env.BROWSER=p.stringify(o.BROWSER)),o.BROWSER_ARGS&&process.env.BROWSER_ARGS===void 0&&(process.env.BROWSER_ARGS=p.stringify(o.BROWSER_ARGS)),o=E({...process.env},o),t.length===0)return o;for(const[e,i]of Object.entries(o))t.some(c=>e.startsWith(c))&&(a[e]=String(i));for(const e in process.env)t.some(i=>e.startsWith(i))&&(a[e]=process.env[e]);return a}export async function loadClientEnv(n,r,s=m){return loadEnv(n,r,s)}export async function loadServerEnv(n,r){return loadEnv(n,r)}
1
+ import{parse as l}from"@dotenvx/dotenvx";import{readFile as m}from"@stryke/fs/read-file";import{StormJSON as p}from"@stryke/json";import{existsSync as g,joinPaths as E}from"@stryke/path";import f from"defu";import{ENV_PREFIXES as R}from"./types";export function getEnvFilesForMode(t,r="production"){return[".env",".env.local",`.env.${r}`,`.env.${r}.local`,`.env.local.${r}`].map(s=>E(t,s))}export async function loadEnvFile(t,r=[]){const s=Array.isArray(r)?r:[r];return(await Promise.all((r.length>0?s.map(n=>E(n,t)):[t]).map(n=>{if(g(n))return m(n)}))).reduce((n,u)=>{if(!u)return n;const a=l(u,{processEnv:{...process.env},privateKey:process.env.DOTENV_PRIVATE_KEY||process.env.STORM_PRIVATE_KEY});return f(a,n)},{})}export async function loadEnv(t,r,s){if(r==="local")throw new Error('"local" cannot be used as a mode name because it conflicts with the .local postfix for .env files.');const n=s?Array.isArray(s)?s:[s]:[],u=Array.isArray(t)?t:[t],a={},v=u.reduce((e,i)=>(e.push(...getEnvFilesForMode(i,r).filter(c=>!e.includes(c))),e),[]);let o=(await Promise.all(v.map(async e=>loadEnvFile(e)))).reduce((e,i)=>f(i,e),{});if(o.NODE_ENV&&process.env.VITE_USER_NODE_ENV===void 0&&(process.env.VITE_USER_NODE_ENV=p.stringify(o.NODE_ENV)),o.BROWSER&&process.env.BROWSER===void 0&&(process.env.BROWSER=p.stringify(o.BROWSER)),o.BROWSER_ARGS&&process.env.BROWSER_ARGS===void 0&&(process.env.BROWSER_ARGS=p.stringify(o.BROWSER_ARGS)),o=f({...process.env},o),n.length===0)return o;for(const[e,i]of Object.entries(o))n.some(c=>e.startsWith(c))&&(a[e]=String(i));for(const e in process.env)n.some(i=>e.startsWith(i))&&(a[e]=process.env[e]);return a}export async function loadClientEnv(t,r,s=R){return loadEnv(t,r,s)}export async function loadServerEnv(t,r){return loadEnv(t,r)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/env",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "description": "A package containing utility functions to handle environment specific processes",
6
6
  "repository": {
@@ -12,11 +12,11 @@
12
12
  "dependencies": {
13
13
  "@dotenvx/dotenvx": "1.35.0",
14
14
  "defu": "^6.1.4",
15
- "@stryke/fs": ">=0.2.0",
16
- "@stryke/json": ">=0.2.0",
17
- "@stryke/path": ">=0.2.0",
18
- "@stryke/string-format": ">=0.2.0",
19
- "@stryke/types": ">=0.4.0"
15
+ "@stryke/fs": ">=0.9.2",
16
+ "@stryke/json": ">=0.4.3",
17
+ "@stryke/path": ">=0.3.4",
18
+ "@stryke/string-format": ">=0.2.1",
19
+ "@stryke/type-checks": ">=0.0.1"
20
20
  },
21
21
  "devDependencies": { "@types/node": "^22.13.1" },
22
22
  "publishConfig": { "access": "public" },
@@ -32,7 +32,6 @@
32
32
  "stryke",
33
33
  "typescript",
34
34
  "utilities",
35
- "storm-stack",
36
35
  "storm-software",
37
36
  "storm",
38
37
  "storm-ops",