@stryke/env 0.20.49 → 0.20.51
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/CHANGELOG.md +16 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -1
- package/dist/ci-checks.cjs +23 -1
- package/dist/ci-checks.mjs +21 -1
- package/dist/ci-checks.mjs.map +1 -1
- package/dist/convert/src/to-array.cjs +15 -1
- package/dist/convert/src/to-array.mjs +14 -1
- package/dist/convert/src/to-array.mjs.map +1 -1
- package/dist/environment-checks.cjs +156 -1
- package/dist/environment-checks.mjs +139 -1
- package/dist/environment-checks.mjs.map +1 -1
- package/dist/fs/src/exists.cjs +17 -1
- package/dist/fs/src/exists.mjs +15 -1
- package/dist/fs/src/exists.mjs.map +1 -1
- package/dist/fs/src/read-file.cjs +17 -1
- package/dist/fs/src/read-file.mjs +16 -1
- package/dist/fs/src/read-file.mjs.map +1 -1
- package/dist/get-env-paths.cjs +87 -1
- package/dist/get-env-paths.mjs +84 -1
- package/dist/get-env-paths.mjs.map +1 -1
- package/dist/index.cjs +48 -1
- package/dist/index.mjs +9 -1
- package/dist/load-env.cjs +124 -1
- package/dist/load-env.mjs +118 -1
- package/dist/load-env.mjs.map +1 -1
- package/dist/path/src/is-type.cjs +28 -1
- package/dist/path/src/is-type.mjs +28 -1
- package/dist/path/src/is-type.mjs.map +1 -1
- package/dist/path/src/join-paths.cjs +106 -1
- package/dist/path/src/join-paths.mjs +106 -1
- package/dist/path/src/join-paths.mjs.map +1 -1
- package/dist/path/src/regex.cjs +12 -1
- package/dist/path/src/regex.mjs +8 -1
- package/dist/path/src/regex.mjs.map +1 -1
- package/dist/path/src/slash.cjs +15 -1
- package/dist/path/src/slash.mjs +14 -1
- package/dist/path/src/slash.mjs.map +1 -1
- package/dist/providers.cjs +112 -1
- package/dist/providers.mjs +110 -1
- package/dist/providers.mjs.map +1 -1
- package/dist/runtime-checks.cjs +71 -1
- package/dist/runtime-checks.mjs +60 -1
- package/dist/runtime-checks.mjs.map +1 -1
- package/dist/string-format/src/acronyms.cjs +408 -1
- package/dist/string-format/src/acronyms.mjs +407 -1
- package/dist/string-format/src/acronyms.mjs.map +1 -1
- package/dist/string-format/src/articles.cjs +10 -1
- package/dist/string-format/src/articles.mjs +9 -1
- package/dist/string-format/src/articles.mjs.map +1 -1
- package/dist/string-format/src/combine.cjs +15 -1
- package/dist/string-format/src/combine.mjs +14 -1
- package/dist/string-format/src/combine.mjs.map +1 -1
- package/dist/string-format/src/conjunctions.cjs +32 -1
- package/dist/string-format/src/conjunctions.mjs +31 -1
- package/dist/string-format/src/conjunctions.mjs.map +1 -1
- package/dist/string-format/src/decamelize.cjs +14 -1
- package/dist/string-format/src/decamelize.mjs +13 -1
- package/dist/string-format/src/decamelize.mjs.map +1 -1
- package/dist/string-format/src/format-special-cases.cjs +33 -1
- package/dist/string-format/src/format-special-cases.mjs +33 -1
- package/dist/string-format/src/format-special-cases.mjs.map +1 -1
- package/dist/string-format/src/prepositions.cjs +68 -1
- package/dist/string-format/src/prepositions.mjs +67 -1
- package/dist/string-format/src/prepositions.mjs.map +1 -1
- package/dist/string-format/src/special-cases.cjs +53 -1
- package/dist/string-format/src/special-cases.mjs +52 -1
- package/dist/string-format/src/special-cases.mjs.map +1 -1
- package/dist/string-format/src/title-case.cjs +19 -1
- package/dist/string-format/src/title-case.mjs +19 -1
- package/dist/string-format/src/title-case.mjs.map +1 -1
- package/dist/string-format/src/upper-case-first.cjs +17 -1
- package/dist/string-format/src/upper-case-first.mjs +16 -1
- package/dist/string-format/src/upper-case-first.mjs.map +1 -1
- package/dist/types.cjs +13 -1
- package/dist/types.mjs +12 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +6 -6
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
import{existsSync
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
//#region ../fs/src/read-file.ts
|
|
5
|
+
/**
|
|
6
|
+
* Read the given content to the given file path
|
|
7
|
+
*
|
|
8
|
+
* @param filePath - The file path to read to
|
|
9
|
+
*/
|
|
10
|
+
const readFile$1 = async (filePath) => {
|
|
11
|
+
if (!filePath) throw new Error("No file path provided to read data");
|
|
12
|
+
return readFile(filePath, { encoding: "utf8" });
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { readFile$1 as readFile };
|
|
2
17
|
//# sourceMappingURL=read-file.mjs.map
|
|
@@ -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":"
|
|
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"}
|
package/dist/get-env-paths.cjs
CHANGED
|
@@ -1 +1,87 @@
|
|
|
1
|
-
const
|
|
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;
|
package/dist/get-env-paths.mjs
CHANGED
|
@@ -1,2 +1,85 @@
|
|
|
1
|
-
import{joinPaths
|
|
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":"
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|