@stryke/env 0.20.49 → 0.20.50

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.
Files changed (77) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -1
  3. package/dist/ci-checks.cjs +23 -1
  4. package/dist/ci-checks.mjs +21 -1
  5. package/dist/ci-checks.mjs.map +1 -1
  6. package/dist/convert/src/to-array.cjs +15 -1
  7. package/dist/convert/src/to-array.mjs +14 -1
  8. package/dist/convert/src/to-array.mjs.map +1 -1
  9. package/dist/environment-checks.cjs +156 -1
  10. package/dist/environment-checks.mjs +139 -1
  11. package/dist/environment-checks.mjs.map +1 -1
  12. package/dist/fs/src/exists.cjs +17 -1
  13. package/dist/fs/src/exists.mjs +15 -1
  14. package/dist/fs/src/exists.mjs.map +1 -1
  15. package/dist/fs/src/read-file.cjs +17 -1
  16. package/dist/fs/src/read-file.mjs +16 -1
  17. package/dist/fs/src/read-file.mjs.map +1 -1
  18. package/dist/get-env-paths.cjs +87 -1
  19. package/dist/get-env-paths.mjs +84 -1
  20. package/dist/get-env-paths.mjs.map +1 -1
  21. package/dist/index.cjs +48 -1
  22. package/dist/index.mjs +9 -1
  23. package/dist/load-env.cjs +124 -1
  24. package/dist/load-env.mjs +118 -1
  25. package/dist/load-env.mjs.map +1 -1
  26. package/dist/path/src/is-type.cjs +28 -1
  27. package/dist/path/src/is-type.mjs +28 -1
  28. package/dist/path/src/is-type.mjs.map +1 -1
  29. package/dist/path/src/join-paths.cjs +106 -1
  30. package/dist/path/src/join-paths.mjs +106 -1
  31. package/dist/path/src/join-paths.mjs.map +1 -1
  32. package/dist/path/src/regex.cjs +12 -1
  33. package/dist/path/src/regex.mjs +8 -1
  34. package/dist/path/src/regex.mjs.map +1 -1
  35. package/dist/path/src/slash.cjs +15 -1
  36. package/dist/path/src/slash.mjs +14 -1
  37. package/dist/path/src/slash.mjs.map +1 -1
  38. package/dist/providers.cjs +112 -1
  39. package/dist/providers.mjs +110 -1
  40. package/dist/providers.mjs.map +1 -1
  41. package/dist/runtime-checks.cjs +71 -1
  42. package/dist/runtime-checks.mjs +60 -1
  43. package/dist/runtime-checks.mjs.map +1 -1
  44. package/dist/string-format/src/acronyms.cjs +408 -1
  45. package/dist/string-format/src/acronyms.mjs +407 -1
  46. package/dist/string-format/src/acronyms.mjs.map +1 -1
  47. package/dist/string-format/src/articles.cjs +10 -1
  48. package/dist/string-format/src/articles.mjs +9 -1
  49. package/dist/string-format/src/articles.mjs.map +1 -1
  50. package/dist/string-format/src/combine.cjs +15 -1
  51. package/dist/string-format/src/combine.mjs +14 -1
  52. package/dist/string-format/src/combine.mjs.map +1 -1
  53. package/dist/string-format/src/conjunctions.cjs +32 -1
  54. package/dist/string-format/src/conjunctions.mjs +31 -1
  55. package/dist/string-format/src/conjunctions.mjs.map +1 -1
  56. package/dist/string-format/src/decamelize.cjs +14 -1
  57. package/dist/string-format/src/decamelize.mjs +13 -1
  58. package/dist/string-format/src/decamelize.mjs.map +1 -1
  59. package/dist/string-format/src/format-special-cases.cjs +33 -1
  60. package/dist/string-format/src/format-special-cases.mjs +33 -1
  61. package/dist/string-format/src/format-special-cases.mjs.map +1 -1
  62. package/dist/string-format/src/prepositions.cjs +68 -1
  63. package/dist/string-format/src/prepositions.mjs +67 -1
  64. package/dist/string-format/src/prepositions.mjs.map +1 -1
  65. package/dist/string-format/src/special-cases.cjs +53 -1
  66. package/dist/string-format/src/special-cases.mjs +52 -1
  67. package/dist/string-format/src/special-cases.mjs.map +1 -1
  68. package/dist/string-format/src/title-case.cjs +19 -1
  69. package/dist/string-format/src/title-case.mjs +19 -1
  70. package/dist/string-format/src/title-case.mjs.map +1 -1
  71. package/dist/string-format/src/upper-case-first.cjs +17 -1
  72. package/dist/string-format/src/upper-case-first.mjs +16 -1
  73. package/dist/string-format/src/upper-case-first.mjs.map +1 -1
  74. package/dist/types.cjs +13 -1
  75. package/dist/types.mjs +12 -1
  76. package/dist/types.mjs.map +1 -1
  77. package/package.json +6 -6
@@ -1 +1 @@
1
- {"version":3,"file":"read-file.mjs","names":["readFile","readFileFs"],"sources":["../../../../fs/src/read-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { existsSync, readFileSync as readFileSyncFs } from \"node:fs\";\nimport { readFile as readFileFs } from \"node:fs/promises\";\n\n/**\n * Read the given content to the given file path\n *\n * @param filePath - The file path to write to\n */\nexport const readFileSync = (filePath: string): string => {\n if (!filePath) {\n throw new Error(\"No file path provided to read data\");\n }\n\n return readFileSyncFs(filePath, { encoding: \"utf8\" });\n};\n\n/**\n * Read the given content to the given file path\n *\n * @param filePath - The file path to read to\n */\nexport const readFile = async (filePath: string): Promise<string> => {\n if (!filePath) {\n throw new Error(\"No file path provided to read data\");\n }\n\n return readFileFs(filePath, { encoding: \"utf8\" });\n};\n\n/**\n * Reads a file if it exists, otherwise returns an empty string.\n *\n * @param path - The path to the file to read.\n * @returns The content of the file if it exists, otherwise an empty string.\n */\nexport function readFileIfExistingSync(path: string) {\n return existsSync(path) ? readFileSync(path) : \"\";\n}\n\n/**\n * Reads a file if it exists, otherwise returns an empty string.\n *\n * @param path - The path to the file to read.\n * @returns The content of the file if it exists, otherwise an empty string.\n */\nexport async function readFileIfExisting(path: string) {\n return existsSync(path) ? readFile(path) : \"\";\n}\n"],"mappings":"iFAuCA,MAAaA,EAAW,KAAO,IAAsC,CACnE,GAAI,CAAC,EACH,MAAU,MAAM,qCAAqC,CAGvD,OAAOC,EAAW,EAAU,CAAE,SAAU,OAAQ,CAAC"}
1
+ {"version":3,"file":"read-file.mjs","names":["readFile","readFileFs"],"sources":["../../../../fs/src/read-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { existsSync, readFileSync as readFileSyncFs } from \"node:fs\";\nimport { readFile as readFileFs } from \"node:fs/promises\";\n\n/**\n * Read the given content to the given file path\n *\n * @param filePath - The file path to write to\n */\nexport const readFileSync = (filePath: string): string => {\n if (!filePath) {\n throw new Error(\"No file path provided to read data\");\n }\n\n return readFileSyncFs(filePath, { encoding: \"utf8\" });\n};\n\n/**\n * Read the given content to the given file path\n *\n * @param filePath - The file path to read to\n */\nexport const readFile = async (filePath: string): Promise<string> => {\n if (!filePath) {\n throw new Error(\"No file path provided to read data\");\n }\n\n return readFileFs(filePath, { encoding: \"utf8\" });\n};\n\n/**\n * Reads a file if it exists, otherwise returns an empty string.\n *\n * @param path - The path to the file to read.\n * @returns The content of the file if it exists, otherwise an empty string.\n */\nexport function readFileIfExistingSync(path: string) {\n return existsSync(path) ? readFileSync(path) : \"\";\n}\n\n/**\n * Reads a file if it exists, otherwise returns an empty string.\n *\n * @param path - The path to the file to read.\n * @returns The content of the file if it exists, otherwise an empty string.\n */\nexport async function readFileIfExisting(path: string) {\n return existsSync(path) ? readFile(path) : \"\";\n}\n"],"mappings":";;;;;;;;;AAuCA,MAAaA,aAAW,OAAO,aAAsC;AACnE,KAAI,CAAC,SACH,OAAM,IAAI,MAAM,qCAAqC;AAGvD,QAAOC,SAAW,UAAU,EAAE,UAAU,QAAQ,CAAC"}
@@ -1 +1,87 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./path/src/join-paths.cjs`),n=require(`./string-format/src/title-case.cjs`);let r=require(`node:os`);r=e.__toESM(r);let i=require(`node:path`);i=e.__toESM(i);const a=r.default.homedir(),o=r.default.tmpdir(),s=e=>{let n=t.joinPaths(a,`Library`);return{data:t.joinPaths(n,`Application Support`,e),config:t.joinPaths(n,`Preferences`,e),cache:t.joinPaths(n,`Caches`,e),log:t.joinPaths(n,`Logs`,e),temp:t.joinPaths(o,e)}},c=e=>{let r=process.env.APPDATA||t.joinPaths(a,`AppData`,`Roaming`),i=process.env.LOCALAPPDATA||t.joinPaths(a,`AppData`,`Local`),s=n.titleCase(e).trim().replace(/\s+/g,``);return{data:t.joinPaths(i,s,`Data`),config:t.joinPaths(r,s,`Config`),cache:t.joinPaths(i,`Cache`,e),log:t.joinPaths(i,s,`Log`),temp:t.joinPaths(o,e)}},l=e=>{let n=i.default.basename(a);return{data:t.joinPaths(process.env.XDG_DATA_HOME||t.joinPaths(a,`.local`,`share`),e),config:t.joinPaths(process.env.XDG_CONFIG_HOME||t.joinPaths(a,`.config`),e),cache:t.joinPaths(process.env.XDG_CACHE_HOME||t.joinPaths(a,`.cache`),e),log:t.joinPaths(process.env.XDG_STATE_HOME||t.joinPaths(a,`.local`,`state`),e),temp:process.env.DEVENV_RUNTIME||process.env.XDG_RUNTIME_DIR?t.joinPaths(process.env.DEVENV_RUNTIME||process.env.XDG_RUNTIME_DIR,e):t.joinPaths(o,n,e)}};function u(e={}){let n=e.orgId||`storm-software`;if(!n)throw Error("You need to provide an orgId to the `getEnvPaths` function");e.suffix&&(n+=`-${typeof e.suffix==`string`?e.suffix:`nodejs`}`);let r={};return r=process.platform===`darwin`?s(n):process.platform===`win32`?c(n):l(n),process.env.STORM_DATA_DIR?r.data=process.env.STORM_DATA_DIR:process.env.STORM_CONFIG_DIR?r.config=process.env.STORM_CONFIG_DIR:process.env.STORM_CACHE_DIR?r.cache=process.env.STORM_CACHE_DIR:process.env.STORM_LOG_DIR?r.log=process.env.STORM_LOG_DIR:process.env.STORM_TEMP_DIR&&(r.temp=process.env.STORM_TEMP_DIR),e.workspaceRoot&&(r.cache??=t.joinPaths(e.workspaceRoot,`node_modules`,`.cache`,n),r.temp??=t.joinPaths(e.workspaceRoot,`tmp`,n),r.log??=t.joinPaths(r.temp,`logs`),r.config??=t.joinPaths(e.workspaceRoot,`.config`,n)),Object.keys(r).reduce((n,i)=>{if(r[i]){let a=r[i];n[i]=e.appId&&e.appId!==e.orgId&&e.appId!==e.nestedDir?t.joinPaths(a,e.appId):a,e.nestedDir&&e.nestedDir!==e.orgId&&e.nestedDir!==e.appId&&(n[i]=t.joinPaths(n[i],e.nestedDir))}return n},{})}exports.getEnvPaths=u;
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_join_paths = require('./path/src/join-paths.cjs');
3
+ const require_title_case = require('./string-format/src/title-case.cjs');
4
+ let node_os = require("node:os");
5
+ node_os = require_rolldown_runtime.__toESM(node_os);
6
+ let node_path = require("node:path");
7
+ node_path = require_rolldown_runtime.__toESM(node_path);
8
+
9
+ //#region src/get-env-paths.ts
10
+ const homedir = node_os.default.homedir();
11
+ const tmpdir = node_os.default.tmpdir();
12
+ const macos = (orgId) => {
13
+ const library = require_join_paths.joinPaths(homedir, "Library");
14
+ return {
15
+ data: require_join_paths.joinPaths(library, "Application Support", orgId),
16
+ config: require_join_paths.joinPaths(library, "Preferences", orgId),
17
+ cache: require_join_paths.joinPaths(library, "Caches", orgId),
18
+ log: require_join_paths.joinPaths(library, "Logs", orgId),
19
+ temp: require_join_paths.joinPaths(tmpdir, orgId)
20
+ };
21
+ };
22
+ const windows = (orgId) => {
23
+ const appData = process.env.APPDATA || require_join_paths.joinPaths(homedir, "AppData", "Roaming");
24
+ const localAppData = process.env.LOCALAPPDATA || require_join_paths.joinPaths(homedir, "AppData", "Local");
25
+ const windowsFormattedOrgId = require_title_case.titleCase(orgId).trim().replace(/\s+/g, "");
26
+ return {
27
+ data: require_join_paths.joinPaths(localAppData, windowsFormattedOrgId, "Data"),
28
+ config: require_join_paths.joinPaths(appData, windowsFormattedOrgId, "Config"),
29
+ cache: require_join_paths.joinPaths(localAppData, "Cache", orgId),
30
+ log: require_join_paths.joinPaths(localAppData, windowsFormattedOrgId, "Log"),
31
+ temp: require_join_paths.joinPaths(tmpdir, orgId)
32
+ };
33
+ };
34
+ const linux = (orgId) => {
35
+ const username = node_path.default.basename(homedir);
36
+ return {
37
+ data: require_join_paths.joinPaths(process.env.XDG_DATA_HOME || require_join_paths.joinPaths(homedir, ".local", "share"), orgId),
38
+ config: require_join_paths.joinPaths(process.env.XDG_CONFIG_HOME || require_join_paths.joinPaths(homedir, ".config"), orgId),
39
+ cache: require_join_paths.joinPaths(process.env.XDG_CACHE_HOME || require_join_paths.joinPaths(homedir, ".cache"), orgId),
40
+ log: require_join_paths.joinPaths(process.env.XDG_STATE_HOME || require_join_paths.joinPaths(homedir, ".local", "state"), orgId),
41
+ temp: process.env.DEVENV_RUNTIME || process.env.XDG_RUNTIME_DIR ? require_join_paths.joinPaths(process.env.DEVENV_RUNTIME || process.env.XDG_RUNTIME_DIR, orgId) : require_join_paths.joinPaths(tmpdir, username, orgId)
42
+ };
43
+ };
44
+ /**
45
+ * Get paths for storing things like data, config, logs, and cache in the current runtime environment.
46
+ *
47
+ * @remarks
48
+ * On macOS, directories are generally created in `~/Library/Application Support/<name>`.
49
+ * On Windows, directories are generally created in `%AppData%/<name>`.
50
+ * On Linux, directories are generally created in `~/.config/<name>` - this is determined via the [XDG Base Directory spec](https://specifications.freedesktop.org/basedir-spec/latest/).
51
+ *
52
+ * If the `STORM_DATA_DIR`, `STORM_CONFIG_DIR`, `STORM_CACHE_DIR`, `STORM_LOG_DIR`, or `STORM_TEMP_DIR` environment variables are set, they will be used instead of the default paths.
53
+ *
54
+ * @param options - Parameters used to determine the specific paths for the current project/runtime environment
55
+ * @returns An object containing the various paths for the runtime environment
56
+ */
57
+ function getEnvPaths(options = {}) {
58
+ let orgId = options.orgId || "storm-software";
59
+ if (!orgId) throw new Error("You need to provide an orgId to the `getEnvPaths` function");
60
+ if (options.suffix) orgId += `-${typeof options.suffix === "string" ? options.suffix : "nodejs"}`;
61
+ let result = {};
62
+ if (process.platform === "darwin") result = macos(orgId);
63
+ else if (process.platform === "win32") result = windows(orgId);
64
+ else result = linux(orgId);
65
+ if (process.env.STORM_DATA_DIR) result.data = process.env.STORM_DATA_DIR;
66
+ else if (process.env.STORM_CONFIG_DIR) result.config = process.env.STORM_CONFIG_DIR;
67
+ else if (process.env.STORM_CACHE_DIR) result.cache = process.env.STORM_CACHE_DIR;
68
+ else if (process.env.STORM_LOG_DIR) result.log = process.env.STORM_LOG_DIR;
69
+ else if (process.env.STORM_TEMP_DIR) result.temp = process.env.STORM_TEMP_DIR;
70
+ if (options.workspaceRoot) {
71
+ result.cache ??= require_join_paths.joinPaths(options.workspaceRoot, "node_modules", ".cache", orgId);
72
+ result.temp ??= require_join_paths.joinPaths(options.workspaceRoot, "tmp", orgId);
73
+ result.log ??= require_join_paths.joinPaths(result.temp, "logs");
74
+ result.config ??= require_join_paths.joinPaths(options.workspaceRoot, ".config", orgId);
75
+ }
76
+ return Object.keys(result).reduce((ret, key) => {
77
+ if (result[key]) {
78
+ const filePath = result[key];
79
+ ret[key] = options.appId && options.appId !== options.orgId && options.appId !== options.nestedDir ? require_join_paths.joinPaths(filePath, options.appId) : filePath;
80
+ if (options.nestedDir && options.nestedDir !== options.orgId && options.nestedDir !== options.appId) ret[key] = require_join_paths.joinPaths(ret[key], options.nestedDir);
81
+ }
82
+ return ret;
83
+ }, {});
84
+ }
85
+
86
+ //#endregion
87
+ exports.getEnvPaths = getEnvPaths;
@@ -1,2 +1,85 @@
1
- import{joinPaths as e}from"./path/src/join-paths.mjs";import{titleCase as t}from"./string-format/src/title-case.mjs";import n from"node:os";import r from"node:path";const i=n.homedir(),a=n.tmpdir(),o=t=>{let n=e(i,`Library`);return{data:e(n,`Application Support`,t),config:e(n,`Preferences`,t),cache:e(n,`Caches`,t),log:e(n,`Logs`,t),temp:e(a,t)}},s=n=>{let r=process.env.APPDATA||e(i,`AppData`,`Roaming`),o=process.env.LOCALAPPDATA||e(i,`AppData`,`Local`),s=t(n).trim().replace(/\s+/g,``);return{data:e(o,s,`Data`),config:e(r,s,`Config`),cache:e(o,`Cache`,n),log:e(o,s,`Log`),temp:e(a,n)}},c=t=>{let n=r.basename(i);return{data:e(process.env.XDG_DATA_HOME||e(i,`.local`,`share`),t),config:e(process.env.XDG_CONFIG_HOME||e(i,`.config`),t),cache:e(process.env.XDG_CACHE_HOME||e(i,`.cache`),t),log:e(process.env.XDG_STATE_HOME||e(i,`.local`,`state`),t),temp:process.env.DEVENV_RUNTIME||process.env.XDG_RUNTIME_DIR?e(process.env.DEVENV_RUNTIME||process.env.XDG_RUNTIME_DIR,t):e(a,n,t)}};function l(t={}){let n=t.orgId||`storm-software`;if(!n)throw Error("You need to provide an orgId to the `getEnvPaths` function");t.suffix&&(n+=`-${typeof t.suffix==`string`?t.suffix:`nodejs`}`);let r={};return r=process.platform===`darwin`?o(n):process.platform===`win32`?s(n):c(n),process.env.STORM_DATA_DIR?r.data=process.env.STORM_DATA_DIR:process.env.STORM_CONFIG_DIR?r.config=process.env.STORM_CONFIG_DIR:process.env.STORM_CACHE_DIR?r.cache=process.env.STORM_CACHE_DIR:process.env.STORM_LOG_DIR?r.log=process.env.STORM_LOG_DIR:process.env.STORM_TEMP_DIR&&(r.temp=process.env.STORM_TEMP_DIR),t.workspaceRoot&&(r.cache??=e(t.workspaceRoot,`node_modules`,`.cache`,n),r.temp??=e(t.workspaceRoot,`tmp`,n),r.log??=e(r.temp,`logs`),r.config??=e(t.workspaceRoot,`.config`,n)),Object.keys(r).reduce((n,i)=>{if(r[i]){let a=r[i];n[i]=t.appId&&t.appId!==t.orgId&&t.appId!==t.nestedDir?e(a,t.appId):a,t.nestedDir&&t.nestedDir!==t.orgId&&t.nestedDir!==t.appId&&(n[i]=e(n[i],t.nestedDir))}return n},{})}export{l as getEnvPaths};
1
+ import { joinPaths } from "./path/src/join-paths.mjs";
2
+ import { titleCase } from "./string-format/src/title-case.mjs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+
6
+ //#region src/get-env-paths.ts
7
+ const homedir = os.homedir();
8
+ const tmpdir = os.tmpdir();
9
+ const macos = (orgId) => {
10
+ const library = joinPaths(homedir, "Library");
11
+ return {
12
+ data: joinPaths(library, "Application Support", orgId),
13
+ config: joinPaths(library, "Preferences", orgId),
14
+ cache: joinPaths(library, "Caches", orgId),
15
+ log: joinPaths(library, "Logs", orgId),
16
+ temp: joinPaths(tmpdir, orgId)
17
+ };
18
+ };
19
+ const windows = (orgId) => {
20
+ const appData = process.env.APPDATA || joinPaths(homedir, "AppData", "Roaming");
21
+ const localAppData = process.env.LOCALAPPDATA || joinPaths(homedir, "AppData", "Local");
22
+ const windowsFormattedOrgId = titleCase(orgId).trim().replace(/\s+/g, "");
23
+ return {
24
+ data: joinPaths(localAppData, windowsFormattedOrgId, "Data"),
25
+ config: joinPaths(appData, windowsFormattedOrgId, "Config"),
26
+ cache: joinPaths(localAppData, "Cache", orgId),
27
+ log: joinPaths(localAppData, windowsFormattedOrgId, "Log"),
28
+ temp: joinPaths(tmpdir, orgId)
29
+ };
30
+ };
31
+ const linux = (orgId) => {
32
+ const username = path.basename(homedir);
33
+ return {
34
+ data: joinPaths(process.env.XDG_DATA_HOME || joinPaths(homedir, ".local", "share"), orgId),
35
+ config: joinPaths(process.env.XDG_CONFIG_HOME || joinPaths(homedir, ".config"), orgId),
36
+ cache: joinPaths(process.env.XDG_CACHE_HOME || joinPaths(homedir, ".cache"), orgId),
37
+ log: joinPaths(process.env.XDG_STATE_HOME || joinPaths(homedir, ".local", "state"), orgId),
38
+ temp: process.env.DEVENV_RUNTIME || process.env.XDG_RUNTIME_DIR ? joinPaths(process.env.DEVENV_RUNTIME || process.env.XDG_RUNTIME_DIR, orgId) : joinPaths(tmpdir, username, orgId)
39
+ };
40
+ };
41
+ /**
42
+ * Get paths for storing things like data, config, logs, and cache in the current runtime environment.
43
+ *
44
+ * @remarks
45
+ * On macOS, directories are generally created in `~/Library/Application Support/<name>`.
46
+ * On Windows, directories are generally created in `%AppData%/<name>`.
47
+ * On Linux, directories are generally created in `~/.config/<name>` - this is determined via the [XDG Base Directory spec](https://specifications.freedesktop.org/basedir-spec/latest/).
48
+ *
49
+ * If the `STORM_DATA_DIR`, `STORM_CONFIG_DIR`, `STORM_CACHE_DIR`, `STORM_LOG_DIR`, or `STORM_TEMP_DIR` environment variables are set, they will be used instead of the default paths.
50
+ *
51
+ * @param options - Parameters used to determine the specific paths for the current project/runtime environment
52
+ * @returns An object containing the various paths for the runtime environment
53
+ */
54
+ function getEnvPaths(options = {}) {
55
+ let orgId = options.orgId || "storm-software";
56
+ if (!orgId) throw new Error("You need to provide an orgId to the `getEnvPaths` function");
57
+ if (options.suffix) orgId += `-${typeof options.suffix === "string" ? options.suffix : "nodejs"}`;
58
+ let result = {};
59
+ if (process.platform === "darwin") result = macos(orgId);
60
+ else if (process.platform === "win32") result = windows(orgId);
61
+ else result = linux(orgId);
62
+ if (process.env.STORM_DATA_DIR) result.data = process.env.STORM_DATA_DIR;
63
+ else if (process.env.STORM_CONFIG_DIR) result.config = process.env.STORM_CONFIG_DIR;
64
+ else if (process.env.STORM_CACHE_DIR) result.cache = process.env.STORM_CACHE_DIR;
65
+ else if (process.env.STORM_LOG_DIR) result.log = process.env.STORM_LOG_DIR;
66
+ else if (process.env.STORM_TEMP_DIR) result.temp = process.env.STORM_TEMP_DIR;
67
+ if (options.workspaceRoot) {
68
+ result.cache ??= joinPaths(options.workspaceRoot, "node_modules", ".cache", orgId);
69
+ result.temp ??= joinPaths(options.workspaceRoot, "tmp", orgId);
70
+ result.log ??= joinPaths(result.temp, "logs");
71
+ result.config ??= joinPaths(options.workspaceRoot, ".config", orgId);
72
+ }
73
+ return Object.keys(result).reduce((ret, key) => {
74
+ if (result[key]) {
75
+ const filePath = result[key];
76
+ ret[key] = options.appId && options.appId !== options.orgId && options.appId !== options.nestedDir ? joinPaths(filePath, options.appId) : filePath;
77
+ if (options.nestedDir && options.nestedDir !== options.orgId && options.nestedDir !== options.appId) ret[key] = joinPaths(ret[key], options.nestedDir);
78
+ }
79
+ return ret;
80
+ }, {});
81
+ }
82
+
83
+ //#endregion
84
+ export { getEnvPaths };
2
85
  //# sourceMappingURL=get-env-paths.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-env-paths.mjs","names":[],"sources":["../src/get-env-paths.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\n// Forked from https://www.npmjs.com/package/env-paths\n\nconst homedir = os.homedir();\nconst tmpdir = os.tmpdir();\n\n/**\n * Options for the `getEnvPaths` function.\n */\nexport interface GetEnvPathsOptions {\n /**\n * The name of the organization\n *\n * @defaultValue \"storm-software\"\n */\n orgId?: string;\n\n /**\n * The name of the specific application to use as a nested folder inside the organization's folder\n *\n * For example: `~/ ... /storm-software/Log/<appId>`\n */\n appId?: string;\n\n /**\n * The name of the specific application to use as a nested folder inside the organization's folder\n *\n * When a value is provided, it will use `~/ ... /storm-software/Log/<appId>/<nestedDir>`\n *\n * @remarks\n * If no child is provided, it will use `~/ ... /storm-software/Log/<appId>`\n */\n nestedDir?: string;\n\n /**\n * The suffix to append to the project name.\n *\n * @remarks\n * If `suffix` is `true`, the project name will be suffixed with `\"nodejs\"`.\n *\n * @defaultValue false\n */\n suffix?: string | boolean | null;\n\n /**\n * 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.\n */\n workspaceRoot?: string;\n}\n\nexport interface EnvPaths {\n data: string;\n config: string;\n cache: string;\n log: string;\n temp: string;\n}\n\nconst macos = (orgId: string): EnvPaths => {\n const library = joinPaths(homedir, \"Library\");\n\n return {\n data: joinPaths(library, \"Application Support\", orgId),\n config: joinPaths(library, \"Preferences\", orgId),\n cache: joinPaths(library, \"Caches\", orgId),\n log: joinPaths(library, \"Logs\", orgId),\n temp: joinPaths(tmpdir, orgId)\n };\n};\n\nconst windows = (orgId: string): EnvPaths => {\n const appData =\n process.env.APPDATA || joinPaths(homedir, \"AppData\", \"Roaming\");\n const localAppData =\n process.env.LOCALAPPDATA || joinPaths(homedir, \"AppData\", \"Local\");\n\n const windowsFormattedOrgId = titleCase(orgId).trim().replace(/\\s+/g, \"\");\n\n return {\n // Data/config/cache/log are invented by me as Windows isn't opinionated about this\n data: joinPaths(localAppData, windowsFormattedOrgId, \"Data\"),\n config: joinPaths(appData, windowsFormattedOrgId, \"Config\"),\n cache: joinPaths(localAppData, \"Cache\", orgId),\n log: joinPaths(localAppData, windowsFormattedOrgId, \"Log\"),\n temp: joinPaths(tmpdir, orgId)\n };\n};\n\n// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html\nconst linux = (orgId: string): EnvPaths => {\n const username = path.basename(homedir);\n\n return {\n data: joinPaths(\n process.env.XDG_DATA_HOME || joinPaths(homedir, \".local\", \"share\"),\n orgId\n ),\n config: joinPaths(\n process.env.XDG_CONFIG_HOME || joinPaths(homedir, \".config\"),\n orgId\n ),\n cache: joinPaths(\n process.env.XDG_CACHE_HOME || joinPaths(homedir, \".cache\"),\n orgId\n ),\n // https://wiki.debian.org/XDGBaseDirectorySpecification#state\n log: joinPaths(\n process.env.XDG_STATE_HOME || joinPaths(homedir, \".local\", \"state\"),\n orgId\n ),\n // https://devenv.sh/files-and-variables/#devenv_root\n temp:\n process.env.DEVENV_RUNTIME || process.env.XDG_RUNTIME_DIR\n ? joinPaths(\n (process.env.DEVENV_RUNTIME || process.env.XDG_RUNTIME_DIR)!,\n orgId\n )\n : joinPaths(tmpdir, username, orgId)\n };\n};\n\n/**\n * Get paths for storing things like data, config, logs, and cache in the current runtime environment.\n *\n * @remarks\n * On macOS, directories are generally created in `~/Library/Application Support/<name>`.\n * On Windows, directories are generally created in `%AppData%/<name>`.\n * On Linux, directories are generally created in `~/.config/<name>` - this is determined via the [XDG Base Directory spec](https://specifications.freedesktop.org/basedir-spec/latest/).\n *\n * If the `STORM_DATA_DIR`, `STORM_CONFIG_DIR`, `STORM_CACHE_DIR`, `STORM_LOG_DIR`, or `STORM_TEMP_DIR` environment variables are set, they will be used instead of the default paths.\n *\n * @param options - Parameters used to determine the specific paths for the current project/runtime environment\n * @returns An object containing the various paths for the runtime environment\n */\nexport function getEnvPaths(options: GetEnvPathsOptions = {}): EnvPaths {\n let orgId = options.orgId || \"storm-software\";\n if (!orgId) {\n throw new Error(\n \"You need to provide an orgId to the `getEnvPaths` function\"\n );\n }\n\n if (options.suffix) {\n // Add suffix to prevent possible conflict with native apps\n orgId += `-${typeof options.suffix === \"string\" ? options.suffix : \"nodejs\"}`;\n }\n\n let result = {} as EnvPaths;\n\n if (process.platform === \"darwin\") {\n result = macos(orgId);\n } else if (process.platform === \"win32\") {\n result = windows(orgId);\n } else {\n result = linux(orgId);\n }\n\n if (process.env.STORM_DATA_DIR) {\n result.data = process.env.STORM_DATA_DIR;\n } else if (process.env.STORM_CONFIG_DIR) {\n result.config = process.env.STORM_CONFIG_DIR;\n } else if (process.env.STORM_CACHE_DIR) {\n result.cache = process.env.STORM_CACHE_DIR;\n } else if (process.env.STORM_LOG_DIR) {\n result.log = process.env.STORM_LOG_DIR;\n } else if (process.env.STORM_TEMP_DIR) {\n result.temp = process.env.STORM_TEMP_DIR;\n }\n\n if (options.workspaceRoot) {\n result.cache ??= joinPaths(\n options.workspaceRoot,\n \"node_modules\",\n \".cache\",\n orgId\n );\n result.temp ??= joinPaths(options.workspaceRoot, \"tmp\", orgId);\n result.log ??= joinPaths(result.temp, \"logs\");\n result.config ??= joinPaths(options.workspaceRoot, \".config\", orgId);\n }\n\n return Object.keys(result).reduce((ret, key) => {\n if (result[key as keyof EnvPaths]) {\n const filePath = result[key as keyof EnvPaths];\n\n ret[key as keyof EnvPaths] =\n options.appId &&\n options.appId !== options.orgId &&\n options.appId !== options.nestedDir\n ? joinPaths(filePath, options.appId)\n : filePath;\n\n if (\n options.nestedDir &&\n options.nestedDir !== options.orgId &&\n options.nestedDir !== options.appId\n ) {\n ret[key as keyof EnvPaths] = joinPaths(\n ret[key as keyof EnvPaths],\n options.nestedDir\n );\n }\n }\n\n return ret;\n }, {} as EnvPaths);\n}\n"],"mappings":"qKAyBA,MAAM,EAAU,EAAG,SAAS,CACtB,EAAS,EAAG,QAAQ,CAsDpB,EAAS,GAA4B,CACzC,IAAM,EAAU,EAAU,EAAS,UAAU,CAE7C,MAAO,CACL,KAAM,EAAU,EAAS,sBAAuB,EAAM,CACtD,OAAQ,EAAU,EAAS,cAAe,EAAM,CAChD,MAAO,EAAU,EAAS,SAAU,EAAM,CAC1C,IAAK,EAAU,EAAS,OAAQ,EAAM,CACtC,KAAM,EAAU,EAAQ,EAAM,CAC/B,EAGG,EAAW,GAA4B,CAC3C,IAAM,EACJ,QAAQ,IAAI,SAAW,EAAU,EAAS,UAAW,UAAU,CAC3D,EACJ,QAAQ,IAAI,cAAgB,EAAU,EAAS,UAAW,QAAQ,CAE9D,EAAwB,EAAU,EAAM,CAAC,MAAM,CAAC,QAAQ,OAAQ,GAAG,CAEzE,MAAO,CAEL,KAAM,EAAU,EAAc,EAAuB,OAAO,CAC5D,OAAQ,EAAU,EAAS,EAAuB,SAAS,CAC3D,MAAO,EAAU,EAAc,QAAS,EAAM,CAC9C,IAAK,EAAU,EAAc,EAAuB,MAAM,CAC1D,KAAM,EAAU,EAAQ,EAAM,CAC/B,EAIG,EAAS,GAA4B,CACzC,IAAM,EAAW,EAAK,SAAS,EAAQ,CAEvC,MAAO,CACL,KAAM,EACJ,QAAQ,IAAI,eAAiB,EAAU,EAAS,SAAU,QAAQ,CAClE,EACD,CACD,OAAQ,EACN,QAAQ,IAAI,iBAAmB,EAAU,EAAS,UAAU,CAC5D,EACD,CACD,MAAO,EACL,QAAQ,IAAI,gBAAkB,EAAU,EAAS,SAAS,CAC1D,EACD,CAED,IAAK,EACH,QAAQ,IAAI,gBAAkB,EAAU,EAAS,SAAU,QAAQ,CACnE,EACD,CAED,KACE,QAAQ,IAAI,gBAAkB,QAAQ,IAAI,gBACtC,EACG,QAAQ,IAAI,gBAAkB,QAAQ,IAAI,gBAC3C,EACD,CACD,EAAU,EAAQ,EAAU,EAAM,CACzC,EAgBH,SAAgB,EAAY,EAA8B,EAAE,CAAY,CACtE,IAAI,EAAQ,EAAQ,OAAS,iBAC7B,GAAI,CAAC,EACH,MAAU,MACR,6DACD,CAGC,EAAQ,SAEV,GAAS,IAAI,OAAO,EAAQ,QAAW,SAAW,EAAQ,OAAS,YAGrE,IAAI,EAAS,EAAE,CAkCf,MAhCA,CAKE,EALE,QAAQ,WAAa,SACd,EAAM,EAAM,CACZ,QAAQ,WAAa,QACrB,EAAQ,EAAM,CAEd,EAAM,EAAM,CAGnB,QAAQ,IAAI,eACd,EAAO,KAAO,QAAQ,IAAI,eACjB,QAAQ,IAAI,iBACrB,EAAO,OAAS,QAAQ,IAAI,iBACnB,QAAQ,IAAI,gBACrB,EAAO,MAAQ,QAAQ,IAAI,gBAClB,QAAQ,IAAI,cACrB,EAAO,IAAM,QAAQ,IAAI,cAChB,QAAQ,IAAI,iBACrB,EAAO,KAAO,QAAQ,IAAI,gBAGxB,EAAQ,gBACV,EAAO,QAAU,EACf,EAAQ,cACR,eACA,SACA,EACD,CACD,EAAO,OAAS,EAAU,EAAQ,cAAe,MAAO,EAAM,CAC9D,EAAO,MAAQ,EAAU,EAAO,KAAM,OAAO,CAC7C,EAAO,SAAW,EAAU,EAAQ,cAAe,UAAW,EAAM,EAG/D,OAAO,KAAK,EAAO,CAAC,QAAQ,EAAK,IAAQ,CAC9C,GAAI,EAAO,GAAwB,CACjC,IAAM,EAAW,EAAO,GAExB,EAAI,GACF,EAAQ,OACR,EAAQ,QAAU,EAAQ,OAC1B,EAAQ,QAAU,EAAQ,UACtB,EAAU,EAAU,EAAQ,MAAM,CAClC,EAGJ,EAAQ,WACR,EAAQ,YAAc,EAAQ,OAC9B,EAAQ,YAAc,EAAQ,QAE9B,EAAI,GAAyB,EAC3B,EAAI,GACJ,EAAQ,UACT,EAIL,OAAO,GACN,EAAE,CAAa"}
1
+ {"version":3,"file":"get-env-paths.mjs","names":[],"sources":["../src/get-env-paths.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\n// Forked from https://www.npmjs.com/package/env-paths\n\nconst homedir = os.homedir();\nconst tmpdir = os.tmpdir();\n\n/**\n * Options for the `getEnvPaths` function.\n */\nexport interface GetEnvPathsOptions {\n /**\n * The name of the organization\n *\n * @defaultValue \"storm-software\"\n */\n orgId?: string;\n\n /**\n * The name of the specific application to use as a nested folder inside the organization's folder\n *\n * For example: `~/ ... /storm-software/Log/<appId>`\n */\n appId?: string;\n\n /**\n * The name of the specific application to use as a nested folder inside the organization's folder\n *\n * When a value is provided, it will use `~/ ... /storm-software/Log/<appId>/<nestedDir>`\n *\n * @remarks\n * If no child is provided, it will use `~/ ... /storm-software/Log/<appId>`\n */\n nestedDir?: string;\n\n /**\n * The suffix to append to the project name.\n *\n * @remarks\n * If `suffix` is `true`, the project name will be suffixed with `\"nodejs\"`.\n *\n * @defaultValue false\n */\n suffix?: string | boolean | null;\n\n /**\n * 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.\n */\n workspaceRoot?: string;\n}\n\nexport interface EnvPaths {\n data: string;\n config: string;\n cache: string;\n log: string;\n temp: string;\n}\n\nconst macos = (orgId: string): EnvPaths => {\n const library = joinPaths(homedir, \"Library\");\n\n return {\n data: joinPaths(library, \"Application Support\", orgId),\n config: joinPaths(library, \"Preferences\", orgId),\n cache: joinPaths(library, \"Caches\", orgId),\n log: joinPaths(library, \"Logs\", orgId),\n temp: joinPaths(tmpdir, orgId)\n };\n};\n\nconst windows = (orgId: string): EnvPaths => {\n const appData =\n process.env.APPDATA || joinPaths(homedir, \"AppData\", \"Roaming\");\n const localAppData =\n process.env.LOCALAPPDATA || joinPaths(homedir, \"AppData\", \"Local\");\n\n const windowsFormattedOrgId = titleCase(orgId).trim().replace(/\\s+/g, \"\");\n\n return {\n // Data/config/cache/log are invented by me as Windows isn't opinionated about this\n data: joinPaths(localAppData, windowsFormattedOrgId, \"Data\"),\n config: joinPaths(appData, windowsFormattedOrgId, \"Config\"),\n cache: joinPaths(localAppData, \"Cache\", orgId),\n log: joinPaths(localAppData, windowsFormattedOrgId, \"Log\"),\n temp: joinPaths(tmpdir, orgId)\n };\n};\n\n// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html\nconst linux = (orgId: string): EnvPaths => {\n const username = path.basename(homedir);\n\n return {\n data: joinPaths(\n process.env.XDG_DATA_HOME || joinPaths(homedir, \".local\", \"share\"),\n orgId\n ),\n config: joinPaths(\n process.env.XDG_CONFIG_HOME || joinPaths(homedir, \".config\"),\n orgId\n ),\n cache: joinPaths(\n process.env.XDG_CACHE_HOME || joinPaths(homedir, \".cache\"),\n orgId\n ),\n // https://wiki.debian.org/XDGBaseDirectorySpecification#state\n log: joinPaths(\n process.env.XDG_STATE_HOME || joinPaths(homedir, \".local\", \"state\"),\n orgId\n ),\n // https://devenv.sh/files-and-variables/#devenv_root\n temp:\n process.env.DEVENV_RUNTIME || process.env.XDG_RUNTIME_DIR\n ? joinPaths(\n (process.env.DEVENV_RUNTIME || process.env.XDG_RUNTIME_DIR)!,\n orgId\n )\n : joinPaths(tmpdir, username, orgId)\n };\n};\n\n/**\n * Get paths for storing things like data, config, logs, and cache in the current runtime environment.\n *\n * @remarks\n * On macOS, directories are generally created in `~/Library/Application Support/<name>`.\n * On Windows, directories are generally created in `%AppData%/<name>`.\n * On Linux, directories are generally created in `~/.config/<name>` - this is determined via the [XDG Base Directory spec](https://specifications.freedesktop.org/basedir-spec/latest/).\n *\n * If the `STORM_DATA_DIR`, `STORM_CONFIG_DIR`, `STORM_CACHE_DIR`, `STORM_LOG_DIR`, or `STORM_TEMP_DIR` environment variables are set, they will be used instead of the default paths.\n *\n * @param options - Parameters used to determine the specific paths for the current project/runtime environment\n * @returns An object containing the various paths for the runtime environment\n */\nexport function getEnvPaths(options: GetEnvPathsOptions = {}): EnvPaths {\n let orgId = options.orgId || \"storm-software\";\n if (!orgId) {\n throw new Error(\n \"You need to provide an orgId to the `getEnvPaths` function\"\n );\n }\n\n if (options.suffix) {\n // Add suffix to prevent possible conflict with native apps\n orgId += `-${typeof options.suffix === \"string\" ? options.suffix : \"nodejs\"}`;\n }\n\n let result = {} as EnvPaths;\n\n if (process.platform === \"darwin\") {\n result = macos(orgId);\n } else if (process.platform === \"win32\") {\n result = windows(orgId);\n } else {\n result = linux(orgId);\n }\n\n if (process.env.STORM_DATA_DIR) {\n result.data = process.env.STORM_DATA_DIR;\n } else if (process.env.STORM_CONFIG_DIR) {\n result.config = process.env.STORM_CONFIG_DIR;\n } else if (process.env.STORM_CACHE_DIR) {\n result.cache = process.env.STORM_CACHE_DIR;\n } else if (process.env.STORM_LOG_DIR) {\n result.log = process.env.STORM_LOG_DIR;\n } else if (process.env.STORM_TEMP_DIR) {\n result.temp = process.env.STORM_TEMP_DIR;\n }\n\n if (options.workspaceRoot) {\n result.cache ??= joinPaths(\n options.workspaceRoot,\n \"node_modules\",\n \".cache\",\n orgId\n );\n result.temp ??= joinPaths(options.workspaceRoot, \"tmp\", orgId);\n result.log ??= joinPaths(result.temp, \"logs\");\n result.config ??= joinPaths(options.workspaceRoot, \".config\", orgId);\n }\n\n return Object.keys(result).reduce((ret, key) => {\n if (result[key as keyof EnvPaths]) {\n const filePath = result[key as keyof EnvPaths];\n\n ret[key as keyof EnvPaths] =\n options.appId &&\n options.appId !== options.orgId &&\n options.appId !== options.nestedDir\n ? joinPaths(filePath, options.appId)\n : filePath;\n\n if (\n options.nestedDir &&\n options.nestedDir !== options.orgId &&\n options.nestedDir !== options.appId\n ) {\n ret[key as keyof EnvPaths] = joinPaths(\n ret[key as keyof EnvPaths],\n options.nestedDir\n );\n }\n }\n\n return ret;\n }, {} as EnvPaths);\n}\n"],"mappings":";;;;;;AAyBA,MAAM,UAAU,GAAG,SAAS;AAC5B,MAAM,SAAS,GAAG,QAAQ;AAsD1B,MAAM,SAAS,UAA4B;CACzC,MAAM,UAAU,UAAU,SAAS,UAAU;AAE7C,QAAO;EACL,MAAM,UAAU,SAAS,uBAAuB,MAAM;EACtD,QAAQ,UAAU,SAAS,eAAe,MAAM;EAChD,OAAO,UAAU,SAAS,UAAU,MAAM;EAC1C,KAAK,UAAU,SAAS,QAAQ,MAAM;EACtC,MAAM,UAAU,QAAQ,MAAM;EAC/B;;AAGH,MAAM,WAAW,UAA4B;CAC3C,MAAM,UACJ,QAAQ,IAAI,WAAW,UAAU,SAAS,WAAW,UAAU;CACjE,MAAM,eACJ,QAAQ,IAAI,gBAAgB,UAAU,SAAS,WAAW,QAAQ;CAEpE,MAAM,wBAAwB,UAAU,MAAM,CAAC,MAAM,CAAC,QAAQ,QAAQ,GAAG;AAEzE,QAAO;EAEL,MAAM,UAAU,cAAc,uBAAuB,OAAO;EAC5D,QAAQ,UAAU,SAAS,uBAAuB,SAAS;EAC3D,OAAO,UAAU,cAAc,SAAS,MAAM;EAC9C,KAAK,UAAU,cAAc,uBAAuB,MAAM;EAC1D,MAAM,UAAU,QAAQ,MAAM;EAC/B;;AAIH,MAAM,SAAS,UAA4B;CACzC,MAAM,WAAW,KAAK,SAAS,QAAQ;AAEvC,QAAO;EACL,MAAM,UACJ,QAAQ,IAAI,iBAAiB,UAAU,SAAS,UAAU,QAAQ,EAClE,MACD;EACD,QAAQ,UACN,QAAQ,IAAI,mBAAmB,UAAU,SAAS,UAAU,EAC5D,MACD;EACD,OAAO,UACL,QAAQ,IAAI,kBAAkB,UAAU,SAAS,SAAS,EAC1D,MACD;EAED,KAAK,UACH,QAAQ,IAAI,kBAAkB,UAAU,SAAS,UAAU,QAAQ,EACnE,MACD;EAED,MACE,QAAQ,IAAI,kBAAkB,QAAQ,IAAI,kBACtC,UACG,QAAQ,IAAI,kBAAkB,QAAQ,IAAI,iBAC3C,MACD,GACD,UAAU,QAAQ,UAAU,MAAM;EACzC;;;;;;;;;;;;;;;AAgBH,SAAgB,YAAY,UAA8B,EAAE,EAAY;CACtE,IAAI,QAAQ,QAAQ,SAAS;AAC7B,KAAI,CAAC,MACH,OAAM,IAAI,MACR,6DACD;AAGH,KAAI,QAAQ,OAEV,UAAS,IAAI,OAAO,QAAQ,WAAW,WAAW,QAAQ,SAAS;CAGrE,IAAI,SAAS,EAAE;AAEf,KAAI,QAAQ,aAAa,SACvB,UAAS,MAAM,MAAM;UACZ,QAAQ,aAAa,QAC9B,UAAS,QAAQ,MAAM;KAEvB,UAAS,MAAM,MAAM;AAGvB,KAAI,QAAQ,IAAI,eACd,QAAO,OAAO,QAAQ,IAAI;UACjB,QAAQ,IAAI,iBACrB,QAAO,SAAS,QAAQ,IAAI;UACnB,QAAQ,IAAI,gBACrB,QAAO,QAAQ,QAAQ,IAAI;UAClB,QAAQ,IAAI,cACrB,QAAO,MAAM,QAAQ,IAAI;UAChB,QAAQ,IAAI,eACrB,QAAO,OAAO,QAAQ,IAAI;AAG5B,KAAI,QAAQ,eAAe;AACzB,SAAO,UAAU,UACf,QAAQ,eACR,gBACA,UACA,MACD;AACD,SAAO,SAAS,UAAU,QAAQ,eAAe,OAAO,MAAM;AAC9D,SAAO,QAAQ,UAAU,OAAO,MAAM,OAAO;AAC7C,SAAO,WAAW,UAAU,QAAQ,eAAe,WAAW,MAAM;;AAGtE,QAAO,OAAO,KAAK,OAAO,CAAC,QAAQ,KAAK,QAAQ;AAC9C,MAAI,OAAO,MAAwB;GACjC,MAAM,WAAW,OAAO;AAExB,OAAI,OACF,QAAQ,SACR,QAAQ,UAAU,QAAQ,SAC1B,QAAQ,UAAU,QAAQ,YACtB,UAAU,UAAU,QAAQ,MAAM,GAClC;AAEN,OACE,QAAQ,aACR,QAAQ,cAAc,QAAQ,SAC9B,QAAQ,cAAc,QAAQ,MAE9B,KAAI,OAAyB,UAC3B,IAAI,MACJ,QAAQ,UACT;;AAIL,SAAO;IACN,EAAE,CAAa"}
package/dist/index.cjs CHANGED
@@ -1 +1,48 @@
1
- const e=require(`./ci-checks.cjs`),t=require(`./environment-checks.cjs`),n=require(`./get-env-paths.cjs`),r=require(`./types.cjs`),i=require(`./load-env.cjs`),a=require(`./providers.cjs`),o=require(`./runtime-checks.cjs`);exports.ENV_PREFIXES=r.ENV_PREFIXES,exports.getEnvFilesForMode=i.getEnvFilesForMode,exports.getEnvPaths=n.getEnvPaths,exports.hasTTY=t.hasTTY,exports.isBun=o.isBun,exports.isCI=e.isCI,exports.isColorSupported=t.isColorSupported,exports.isDebug=t.isDebug,exports.isDeno=o.isDeno,exports.isDevelopment=t.isDevelopment,exports.isDevelopmentMode=t.isDevelopmentMode,exports.isEdgeLight=o.isEdgeLight,exports.isFastly=o.isFastly,exports.isHyperlinkSupported=t.isHyperlinkSupported,exports.isInteractive=e.isInteractive,exports.isLinux=t.isLinux,exports.isMacOS=t.isMacOS,exports.isMinimal=t.isMinimal,exports.isNetlify=o.isNetlify,exports.isNode=o.isNode,exports.isProduction=t.isProduction,exports.isProductionMode=t.isProductionMode,exports.isRuntimeClient=o.isRuntimeClient,exports.isRuntimeServer=o.isRuntimeServer,exports.isStaging=t.isStaging,exports.isTest=t.isTest,exports.isTestMode=t.isTestMode,exports.isWindows=t.isWindows,exports.isWorkerd=o.isWorkerd,exports.loadClientEnv=i.loadClientEnv,exports.loadEnv=i.loadEnv,exports.loadEnvFile=i.loadEnvFile,exports.loadServerEnv=i.loadServerEnv,exports.nodeMajorVersion=t.nodeMajorVersion,exports.nodeVersion=t.nodeVersion,exports.platform=t.platform,exports.provider=a.provider,exports.providerInfo=a.providerInfo,exports.runtime=o.runtime,exports.runtimeInfo=o.runtimeInfo;
1
+ const require_ci_checks = require('./ci-checks.cjs');
2
+ const require_environment_checks = require('./environment-checks.cjs');
3
+ const require_get_env_paths = require('./get-env-paths.cjs');
4
+ const require_types = require('./types.cjs');
5
+ const require_load_env = require('./load-env.cjs');
6
+ const require_providers = require('./providers.cjs');
7
+ const require_runtime_checks = require('./runtime-checks.cjs');
8
+
9
+ exports.ENV_PREFIXES = require_types.ENV_PREFIXES;
10
+ exports.getEnvFilesForMode = require_load_env.getEnvFilesForMode;
11
+ exports.getEnvPaths = require_get_env_paths.getEnvPaths;
12
+ exports.hasTTY = require_environment_checks.hasTTY;
13
+ exports.isBun = require_runtime_checks.isBun;
14
+ exports.isCI = require_ci_checks.isCI;
15
+ exports.isColorSupported = require_environment_checks.isColorSupported;
16
+ exports.isDebug = require_environment_checks.isDebug;
17
+ exports.isDeno = require_runtime_checks.isDeno;
18
+ exports.isDevelopment = require_environment_checks.isDevelopment;
19
+ exports.isDevelopmentMode = require_environment_checks.isDevelopmentMode;
20
+ exports.isEdgeLight = require_runtime_checks.isEdgeLight;
21
+ exports.isFastly = require_runtime_checks.isFastly;
22
+ exports.isHyperlinkSupported = require_environment_checks.isHyperlinkSupported;
23
+ exports.isInteractive = require_ci_checks.isInteractive;
24
+ exports.isLinux = require_environment_checks.isLinux;
25
+ exports.isMacOS = require_environment_checks.isMacOS;
26
+ exports.isMinimal = require_environment_checks.isMinimal;
27
+ exports.isNetlify = require_runtime_checks.isNetlify;
28
+ exports.isNode = require_runtime_checks.isNode;
29
+ exports.isProduction = require_environment_checks.isProduction;
30
+ exports.isProductionMode = require_environment_checks.isProductionMode;
31
+ exports.isRuntimeClient = require_runtime_checks.isRuntimeClient;
32
+ exports.isRuntimeServer = require_runtime_checks.isRuntimeServer;
33
+ exports.isStaging = require_environment_checks.isStaging;
34
+ exports.isTest = require_environment_checks.isTest;
35
+ exports.isTestMode = require_environment_checks.isTestMode;
36
+ exports.isWindows = require_environment_checks.isWindows;
37
+ exports.isWorkerd = require_runtime_checks.isWorkerd;
38
+ exports.loadClientEnv = require_load_env.loadClientEnv;
39
+ exports.loadEnv = require_load_env.loadEnv;
40
+ exports.loadEnvFile = require_load_env.loadEnvFile;
41
+ exports.loadServerEnv = require_load_env.loadServerEnv;
42
+ exports.nodeMajorVersion = require_environment_checks.nodeMajorVersion;
43
+ exports.nodeVersion = require_environment_checks.nodeVersion;
44
+ exports.platform = require_environment_checks.platform;
45
+ exports.provider = require_providers.provider;
46
+ exports.providerInfo = require_providers.providerInfo;
47
+ exports.runtime = require_runtime_checks.runtime;
48
+ exports.runtimeInfo = require_runtime_checks.runtimeInfo;
package/dist/index.mjs CHANGED
@@ -1 +1,9 @@
1
- import{isCI as e,isInteractive as t}from"./ci-checks.mjs";import{hasTTY as n,isColorSupported as r,isDebug as i,isDevelopment as a,isDevelopmentMode as o,isHyperlinkSupported as s,isLinux as c,isMacOS as l,isMinimal as u,isProduction as d,isProductionMode as f,isStaging as p,isTest as m,isTestMode as h,isWindows as g,nodeMajorVersion as _,nodeVersion as v,platform as y}from"./environment-checks.mjs";import{getEnvPaths as b}from"./get-env-paths.mjs";import{ENV_PREFIXES as x}from"./types.mjs";import{getEnvFilesForMode as S,loadClientEnv as C,loadEnv as w,loadEnvFile as T,loadServerEnv as E}from"./load-env.mjs";import{provider as D,providerInfo as O}from"./providers.mjs";import{isBun as k,isDeno as A,isEdgeLight as j,isFastly as M,isNetlify as N,isNode as P,isRuntimeClient as F,isRuntimeServer as I,isWorkerd as L,runtime as R,runtimeInfo as z}from"./runtime-checks.mjs";export{x as ENV_PREFIXES,S as getEnvFilesForMode,b as getEnvPaths,n as hasTTY,k as isBun,e as isCI,r as isColorSupported,i as isDebug,A as isDeno,a as isDevelopment,o as isDevelopmentMode,j as isEdgeLight,M as isFastly,s as isHyperlinkSupported,t as isInteractive,c as isLinux,l as isMacOS,u as isMinimal,N as isNetlify,P as isNode,d as isProduction,f as isProductionMode,F as isRuntimeClient,I as isRuntimeServer,p as isStaging,m as isTest,h as isTestMode,g as isWindows,L as isWorkerd,C as loadClientEnv,w as loadEnv,T as loadEnvFile,E as loadServerEnv,_ as nodeMajorVersion,v as nodeVersion,y as platform,D as provider,O as providerInfo,R as runtime,z as runtimeInfo};
1
+ import { isCI, isInteractive } from "./ci-checks.mjs";
2
+ import { hasTTY, isColorSupported, isDebug, isDevelopment, isDevelopmentMode, isHyperlinkSupported, isLinux, isMacOS, isMinimal, isProduction, isProductionMode, isStaging, isTest, isTestMode, isWindows, nodeMajorVersion, nodeVersion, platform } from "./environment-checks.mjs";
3
+ import { getEnvPaths } from "./get-env-paths.mjs";
4
+ import { ENV_PREFIXES } from "./types.mjs";
5
+ import { getEnvFilesForMode, loadClientEnv, loadEnv, loadEnvFile, loadServerEnv } from "./load-env.mjs";
6
+ import { provider, providerInfo } from "./providers.mjs";
7
+ import { isBun, isDeno, isEdgeLight, isFastly, isNetlify, isNode, isRuntimeClient, isRuntimeServer, isWorkerd, runtime, runtimeInfo } from "./runtime-checks.mjs";
8
+
9
+ export { ENV_PREFIXES, getEnvFilesForMode, getEnvPaths, hasTTY, isBun, isCI, isColorSupported, isDebug, isDeno, isDevelopment, isDevelopmentMode, isEdgeLight, isFastly, isHyperlinkSupported, isInteractive, isLinux, isMacOS, isMinimal, isNetlify, isNode, isProduction, isProductionMode, isRuntimeClient, isRuntimeServer, isStaging, isTest, isTestMode, isWindows, isWorkerd, loadClientEnv, loadEnv, loadEnvFile, loadServerEnv, nodeMajorVersion, nodeVersion, platform, provider, providerInfo, runtime, runtimeInfo };
package/dist/load-env.cjs CHANGED
@@ -1 +1,124 @@
1
- const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./path/src/join-paths.cjs`),n=require(`./convert/src/to-array.cjs`),r=require(`./fs/src/exists.cjs`),i=require(`./fs/src/read-file.cjs`),a=require(`./types.cjs`);let o=require(`@dotenvx/dotenvx`),s=require(`defu`);s=e.__toESM(s);function c(e,n=`production`){return[`.env`,`.env.local`,`.env.${n}`,`.env.${n}.local`,`.env.local.${n}`].map(n=>t.joinPaths(e,n))}async function l(e,n=[]){let a=Array.isArray(n)?n:[n];return(await Promise.all((n.length>0?a.map(n=>t.joinPaths(n,e)):[e]).map(async e=>{if(r.existsSync(e))return i.readFile(e)}))).reduce((e,t)=>t?(0,s.default)((0,o.parse)(t,{processEnv:{...process.env},privateKey:process.env.DOTENV_PRIVATE_KEY||process.env.STORM_PRIVATE_KEY}),e):e,{})}async function u(e,t,r){if(t===`local`)throw Error(`"local" cannot be used as a mode name because it conflicts with the .local postfix for .env files.`);let i=n.toArray(r).reduce((e,t)=>t?(e.includes(t.endsWith(`_`)?t:`${t}_`)||e.push(t.endsWith(`_`)?t:`${t}_`),e.includes(`${t.endsWith(`_`)?t:`${t}_`}PUBLIC_`)||e.push(`${t.endsWith(`_`)?t:`${t}_`}PUBLIC_`),e):e,[]),a=Array.isArray(e)?e:[e],o={},u=a.reduce((e,n)=>(e.push(...c(n,t).filter(t=>!e.includes(t))),e),[]),d=(await Promise.all(u.map(async e=>l(e)))).reduce((e,t)=>(0,s.default)(t,e),{});if(d.NODE_ENV&&process.env.VITE_USER_NODE_ENV===void 0&&(process.env.VITE_USER_NODE_ENV=JSON.stringify(d.NODE_ENV)),d.BROWSER&&process.env.BROWSER===void 0&&(process.env.BROWSER=JSON.stringify(d.BROWSER)),d.BROWSER_ARGS&&process.env.BROWSER_ARGS===void 0&&(process.env.BROWSER_ARGS=JSON.stringify(d.BROWSER_ARGS)),d=(0,s.default)({...process.env},d),i.length===0)return d;for(let[e,t]of Object.entries(d))i.some(t=>e.startsWith(t))&&(o[e]=String(t));for(let e in process.env)i.some(t=>e.startsWith(t))&&(o[e]=process.env[e]);return o}async function d(e,t,n=a.ENV_PREFIXES){return u(e,t,n)}async function f(e,t){return u(e,t)}exports.getEnvFilesForMode=c,exports.loadClientEnv=d,exports.loadEnv=u,exports.loadEnvFile=l,exports.loadServerEnv=f;
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_join_paths = require('./path/src/join-paths.cjs');
3
+ const require_to_array = require('./convert/src/to-array.cjs');
4
+ const require_exists = require('./fs/src/exists.cjs');
5
+ const require_read_file = require('./fs/src/read-file.cjs');
6
+ const require_types = require('./types.cjs');
7
+ let __dotenvx_dotenvx = require("@dotenvx/dotenvx");
8
+ let defu = require("defu");
9
+ defu = require_rolldown_runtime.__toESM(defu);
10
+
11
+ //#region src/load-env.ts
12
+ function getEnvFilesForMode(envDir, mode = "production") {
13
+ return [
14
+ ".env",
15
+ ".env.local",
16
+ `.env.${mode}`,
17
+ `.env.${mode}.local`,
18
+ `.env.local.${mode}`
19
+ ].map((file) => require_join_paths.joinPaths(envDir, file));
20
+ }
21
+ /**
22
+ * Load environment variables from a .env file.
23
+ *
24
+ * @param envFile - The path to the .env file.
25
+ * @returns The environment variables.
26
+ */
27
+ async function loadEnvFile(envFile, envDir = []) {
28
+ const envDirs = Array.isArray(envDir) ? envDir : [envDir];
29
+ return (await Promise.all((envDir.length > 0 ? envDirs.map((envDir$1) => require_join_paths.joinPaths(envDir$1, envFile)) : [envFile]).map(async (envFilePath) => {
30
+ if (!require_exists.existsSync(envFilePath)) return;
31
+ return require_read_file.readFile(envFilePath);
32
+ }))).reduce((ret, envFileContent) => {
33
+ if (!envFileContent) return ret;
34
+ return (0, defu.default)((0, __dotenvx_dotenvx.parse)(envFileContent, {
35
+ processEnv: { ...process.env },
36
+ privateKey: process.env.DOTENV_PRIVATE_KEY || process.env.STORM_PRIVATE_KEY
37
+ }), ret);
38
+ }, {});
39
+ }
40
+ /**
41
+ * Load environment variables from .env files.
42
+ *
43
+ * @remarks
44
+ * This function loads environment variables from .env files based on the mode. For the `production` mode, it will load:
45
+ * - `.env`
46
+ * - `.env.local`
47
+ * - `.env.production`
48
+ * - `.env.production.local`
49
+ *
50
+ * @param envDir - The directory/directories to load the environment variables from.
51
+ * @param mode - The mode to load the environment variables for.
52
+ * @param prefix - The prefix or prefixes to use for the environment variables.
53
+ * @returns The environment variables.
54
+ */
55
+ async function loadEnv(envDir, mode, prefix) {
56
+ if (mode === "local") throw new Error("\"local\" cannot be used as a mode name because it conflicts with the .local postfix for .env files.");
57
+ const prefixes = require_to_array.toArray(prefix).reduce((ret, pre) => {
58
+ if (!pre) return ret;
59
+ if (!ret.includes(pre.endsWith("_") ? pre : `${pre}_`)) ret.push(pre.endsWith("_") ? pre : `${pre}_`);
60
+ if (!ret.includes(`${pre.endsWith("_") ? pre : `${pre}_`}PUBLIC_`)) ret.push(`${pre.endsWith("_") ? pre : `${pre}_`}PUBLIC_`);
61
+ return ret;
62
+ }, []);
63
+ const envDirs = Array.isArray(envDir) ? envDir : [envDir];
64
+ const env = {};
65
+ const envFiles = envDirs.reduce((ret, envFilePath) => {
66
+ ret.push(...getEnvFilesForMode(envFilePath, mode).filter((envFile) => !ret.includes(envFile)));
67
+ return ret;
68
+ }, []);
69
+ let envParsed = (await Promise.all(envFiles.map(async (filePath) => {
70
+ return loadEnvFile(filePath);
71
+ }))).reduce((ret, result) => {
72
+ return (0, defu.default)(result, ret);
73
+ }, {});
74
+ if (envParsed.NODE_ENV && process.env.VITE_USER_NODE_ENV === void 0) process.env.VITE_USER_NODE_ENV = JSON.stringify(envParsed.NODE_ENV);
75
+ if (envParsed.BROWSER && process.env.BROWSER === void 0) process.env.BROWSER = JSON.stringify(envParsed.BROWSER);
76
+ if (envParsed.BROWSER_ARGS && process.env.BROWSER_ARGS === void 0) process.env.BROWSER_ARGS = JSON.stringify(envParsed.BROWSER_ARGS);
77
+ envParsed = (0, defu.default)({ ...process.env }, envParsed);
78
+ if (prefixes.length === 0) return envParsed;
79
+ for (const [key, value] of Object.entries(envParsed)) if (prefixes.some((prefix$1) => key.startsWith(prefix$1))) env[key] = String(value);
80
+ for (const key in process.env) if (prefixes.some((prefix$1) => key.startsWith(prefix$1))) env[key] = process.env[key];
81
+ return env;
82
+ }
83
+ /**
84
+ * Load environment variables from .env files for a client-side environment.
85
+ *
86
+ * @remarks
87
+ * This function loads environment variables from .env files based on the mode. For the `production` mode, it will load:
88
+ * - `.env`
89
+ * - `.env.local`
90
+ * - `.env.production`
91
+ * - `.env.production.local`
92
+ *
93
+ * @param envDir - The directory/directories to load the environment variables from.
94
+ * @param mode - The mode to load the environment variables for.
95
+ * @param prefix - The prefix or prefixes to use for the environment variables.
96
+ * @returns The environment variables.
97
+ */
98
+ async function loadClientEnv(envDir, mode, prefix = require_types.ENV_PREFIXES) {
99
+ return loadEnv(envDir, mode, prefix);
100
+ }
101
+ /**
102
+ * Load environment variables from .env files for a server-side environment.
103
+ *
104
+ * @remarks
105
+ * This function loads environment variables from .env files based on the mode. For the `production` mode, it will load:
106
+ * - `.env`
107
+ * - `.env.local`
108
+ * - `.env.production`
109
+ * - `.env.production.local`
110
+ *
111
+ * @param envDir - The directory/directories to load the environment variables from.
112
+ * @param mode - The mode to load the environment variables for.
113
+ * @returns The environment variables.
114
+ */
115
+ async function loadServerEnv(envDir, mode) {
116
+ return loadEnv(envDir, mode);
117
+ }
118
+
119
+ //#endregion
120
+ exports.getEnvFilesForMode = getEnvFilesForMode;
121
+ exports.loadClientEnv = loadClientEnv;
122
+ exports.loadEnv = loadEnv;
123
+ exports.loadEnvFile = loadEnvFile;
124
+ exports.loadServerEnv = loadServerEnv;
package/dist/load-env.mjs CHANGED
@@ -1,2 +1,119 @@
1
- import{joinPaths as e}from"./path/src/join-paths.mjs";import{toArray as t}from"./convert/src/to-array.mjs";import{existsSync as n}from"./fs/src/exists.mjs";import{readFile as r}from"./fs/src/read-file.mjs";import{ENV_PREFIXES as i}from"./types.mjs";import{parse as a}from"@dotenvx/dotenvx";import o from"defu";function s(t,n=`production`){return[`.env`,`.env.local`,`.env.${n}`,`.env.${n}.local`,`.env.local.${n}`].map(n=>e(t,n))}async function c(t,i=[]){let s=Array.isArray(i)?i:[i];return(await Promise.all((i.length>0?s.map(n=>e(n,t)):[t]).map(async e=>{if(n(e))return r(e)}))).reduce((e,t)=>t?o(a(t,{processEnv:{...process.env},privateKey:process.env.DOTENV_PRIVATE_KEY||process.env.STORM_PRIVATE_KEY}),e):e,{})}async function l(e,n,r){if(n===`local`)throw Error(`"local" cannot be used as a mode name because it conflicts with the .local postfix for .env files.`);let i=t(r).reduce((e,t)=>t?(e.includes(t.endsWith(`_`)?t:`${t}_`)||e.push(t.endsWith(`_`)?t:`${t}_`),e.includes(`${t.endsWith(`_`)?t:`${t}_`}PUBLIC_`)||e.push(`${t.endsWith(`_`)?t:`${t}_`}PUBLIC_`),e):e,[]),a=Array.isArray(e)?e:[e],l={},u=a.reduce((e,t)=>(e.push(...s(t,n).filter(t=>!e.includes(t))),e),[]),d=(await Promise.all(u.map(async e=>c(e)))).reduce((e,t)=>o(t,e),{});if(d.NODE_ENV&&process.env.VITE_USER_NODE_ENV===void 0&&(process.env.VITE_USER_NODE_ENV=JSON.stringify(d.NODE_ENV)),d.BROWSER&&process.env.BROWSER===void 0&&(process.env.BROWSER=JSON.stringify(d.BROWSER)),d.BROWSER_ARGS&&process.env.BROWSER_ARGS===void 0&&(process.env.BROWSER_ARGS=JSON.stringify(d.BROWSER_ARGS)),d=o({...process.env},d),i.length===0)return d;for(let[e,t]of Object.entries(d))i.some(t=>e.startsWith(t))&&(l[e]=String(t));for(let e in process.env)i.some(t=>e.startsWith(t))&&(l[e]=process.env[e]);return l}async function u(e,t,n=i){return l(e,t,n)}async function d(e,t){return l(e,t)}export{s as getEnvFilesForMode,u as loadClientEnv,l as loadEnv,c as loadEnvFile,d as loadServerEnv};
1
+ import { joinPaths } from "./path/src/join-paths.mjs";
2
+ import { toArray } from "./convert/src/to-array.mjs";
3
+ import { existsSync } from "./fs/src/exists.mjs";
4
+ import { readFile } from "./fs/src/read-file.mjs";
5
+ import { ENV_PREFIXES } from "./types.mjs";
6
+ import { parse } from "@dotenvx/dotenvx";
7
+ import defu from "defu";
8
+
9
+ //#region src/load-env.ts
10
+ function getEnvFilesForMode(envDir, mode = "production") {
11
+ return [
12
+ ".env",
13
+ ".env.local",
14
+ `.env.${mode}`,
15
+ `.env.${mode}.local`,
16
+ `.env.local.${mode}`
17
+ ].map((file) => joinPaths(envDir, file));
18
+ }
19
+ /**
20
+ * Load environment variables from a .env file.
21
+ *
22
+ * @param envFile - The path to the .env file.
23
+ * @returns The environment variables.
24
+ */
25
+ async function loadEnvFile(envFile, envDir = []) {
26
+ const envDirs = Array.isArray(envDir) ? envDir : [envDir];
27
+ return (await Promise.all((envDir.length > 0 ? envDirs.map((envDir$1) => joinPaths(envDir$1, envFile)) : [envFile]).map(async (envFilePath) => {
28
+ if (!existsSync(envFilePath)) return;
29
+ return readFile(envFilePath);
30
+ }))).reduce((ret, envFileContent) => {
31
+ if (!envFileContent) return ret;
32
+ return defu(parse(envFileContent, {
33
+ processEnv: { ...process.env },
34
+ privateKey: process.env.DOTENV_PRIVATE_KEY || process.env.STORM_PRIVATE_KEY
35
+ }), ret);
36
+ }, {});
37
+ }
38
+ /**
39
+ * Load environment variables from .env files.
40
+ *
41
+ * @remarks
42
+ * This function loads environment variables from .env files based on the mode. For the `production` mode, it will load:
43
+ * - `.env`
44
+ * - `.env.local`
45
+ * - `.env.production`
46
+ * - `.env.production.local`
47
+ *
48
+ * @param envDir - The directory/directories to load the environment variables from.
49
+ * @param mode - The mode to load the environment variables for.
50
+ * @param prefix - The prefix or prefixes to use for the environment variables.
51
+ * @returns The environment variables.
52
+ */
53
+ async function loadEnv(envDir, mode, prefix) {
54
+ if (mode === "local") throw new Error("\"local\" cannot be used as a mode name because it conflicts with the .local postfix for .env files.");
55
+ const prefixes = toArray(prefix).reduce((ret, pre) => {
56
+ if (!pre) return ret;
57
+ if (!ret.includes(pre.endsWith("_") ? pre : `${pre}_`)) ret.push(pre.endsWith("_") ? pre : `${pre}_`);
58
+ if (!ret.includes(`${pre.endsWith("_") ? pre : `${pre}_`}PUBLIC_`)) ret.push(`${pre.endsWith("_") ? pre : `${pre}_`}PUBLIC_`);
59
+ return ret;
60
+ }, []);
61
+ const envDirs = Array.isArray(envDir) ? envDir : [envDir];
62
+ const env = {};
63
+ const envFiles = envDirs.reduce((ret, envFilePath) => {
64
+ ret.push(...getEnvFilesForMode(envFilePath, mode).filter((envFile) => !ret.includes(envFile)));
65
+ return ret;
66
+ }, []);
67
+ let envParsed = (await Promise.all(envFiles.map(async (filePath) => {
68
+ return loadEnvFile(filePath);
69
+ }))).reduce((ret, result) => {
70
+ return defu(result, ret);
71
+ }, {});
72
+ if (envParsed.NODE_ENV && process.env.VITE_USER_NODE_ENV === void 0) process.env.VITE_USER_NODE_ENV = JSON.stringify(envParsed.NODE_ENV);
73
+ if (envParsed.BROWSER && process.env.BROWSER === void 0) process.env.BROWSER = JSON.stringify(envParsed.BROWSER);
74
+ if (envParsed.BROWSER_ARGS && process.env.BROWSER_ARGS === void 0) process.env.BROWSER_ARGS = JSON.stringify(envParsed.BROWSER_ARGS);
75
+ envParsed = defu({ ...process.env }, envParsed);
76
+ if (prefixes.length === 0) return envParsed;
77
+ for (const [key, value] of Object.entries(envParsed)) if (prefixes.some((prefix$1) => key.startsWith(prefix$1))) env[key] = String(value);
78
+ for (const key in process.env) if (prefixes.some((prefix$1) => key.startsWith(prefix$1))) env[key] = process.env[key];
79
+ return env;
80
+ }
81
+ /**
82
+ * Load environment variables from .env files for a client-side environment.
83
+ *
84
+ * @remarks
85
+ * This function loads environment variables from .env files based on the mode. For the `production` mode, it will load:
86
+ * - `.env`
87
+ * - `.env.local`
88
+ * - `.env.production`
89
+ * - `.env.production.local`
90
+ *
91
+ * @param envDir - The directory/directories to load the environment variables from.
92
+ * @param mode - The mode to load the environment variables for.
93
+ * @param prefix - The prefix or prefixes to use for the environment variables.
94
+ * @returns The environment variables.
95
+ */
96
+ async function loadClientEnv(envDir, mode, prefix = ENV_PREFIXES) {
97
+ return loadEnv(envDir, mode, prefix);
98
+ }
99
+ /**
100
+ * Load environment variables from .env files for a server-side environment.
101
+ *
102
+ * @remarks
103
+ * This function loads environment variables from .env files based on the mode. For the `production` mode, it will load:
104
+ * - `.env`
105
+ * - `.env.local`
106
+ * - `.env.production`
107
+ * - `.env.production.local`
108
+ *
109
+ * @param envDir - The directory/directories to load the environment variables from.
110
+ * @param mode - The mode to load the environment variables for.
111
+ * @returns The environment variables.
112
+ */
113
+ async function loadServerEnv(envDir, mode) {
114
+ return loadEnv(envDir, mode);
115
+ }
116
+
117
+ //#endregion
118
+ export { getEnvFilesForMode, loadClientEnv, loadEnv, loadEnvFile, loadServerEnv };
2
119
  //# sourceMappingURL=load-env.mjs.map