@mono-labs/project 0.1.289 → 0.1.292
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/README.md +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/project/index.d.ts +1 -1
- package/dist/project/index.d.ts.map +1 -1
- package/dist/project/index.js +3 -1
- package/dist/project/merge-env.d.ts +21 -1
- package/dist/project/merge-env.d.ts.map +1 -1
- package/dist/project/merge-env.js +54 -3
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/project/index.ts +2 -0
- package/src/project/merge-env.ts +55 -2
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ import {
|
|
|
57
57
|
import { loadMergedEnv } from "@mono-labs/project";
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
- **`loadMergedEnv(files?)`** -- Loads env files from the project root, merges them (later files take precedence), and injects into `process.env` without overwriting existing variables. The file list is `files` if given, else `MONOLABS_ENV_FILES` (set by `mono` for its child processes), else `.env` + `.env.local`. A missing `.env`/`.env.local` is skipped; any other missing file throws.
|
|
60
|
+
- **`loadMergedEnv(files?)`** -- Loads env files from the project root, merges them (later files take precedence), and injects into `process.env` without overwriting existing variables. The file list is `files` if given, else `MONOLABS_ENV_FILES` (set by `mono` for its child processes), else `.env` + `.env.local`. A missing `.env`/`.env.local` is skipped; any other missing file throws. Values injected earlier (by a previous call, or by a parent `mono` per `MONOLABS_INJECTED_KEYS`) are replaced rather than treated as shell variables, and afterwards `MONOLABS_ENV_FILES`/`MONOLABS_INJECTED_KEYS` in `process.env` describe this load.
|
|
61
61
|
- **`readEnvFiles(files?)`** -- Same merge as above but returns the values without touching `process.env`.
|
|
62
62
|
- **`getInjectedEnvKeys()`** / **`getLoadedEnvFiles()`** -- Keys injected and files considered by the last `loadMergedEnv()` call.
|
|
63
63
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { findProjectRoot, getRootDirectory, getRootJson, resolveMonoDirectory, getMonoFiles, getMonoConfig, clearMonoConfigCache, } from './loadFromRoot';
|
|
2
2
|
export type { MonoWorkspaceConfig, MonoProjectConfig, MonoFiles, MonoConfig, } from './loadFromRoot';
|
|
3
|
-
export { loadAppConfig, loadProjectConfig, loadMergedEnv, readEnvFiles, resolveEnvFiles, envFilesFromEnv, getInjectedEnvKeys, getLoadedEnvFiles, DEFAULT_ENV_FILES, ENV_FILES_VAR, INJECTED_KEYS_VAR, filterEnvByPrefixes, filterEnvByConfig, } from './project/index';
|
|
3
|
+
export { loadAppConfig, loadProjectConfig, loadMergedEnv, readEnvFiles, resolveEnvFiles, envFilesFromEnv, getInjectedEnvKeys, injectedKeysFromEnv, getLoadedEnvFiles, DEFAULT_ENV_FILES, ENV_FILES_VAR, INJECTED_KEYS_VAR, ENV_FILES_LOCKED_VAR, filterEnvByPrefixes, filterEnvByConfig, } from './project/index';
|
|
4
4
|
export type { ResolvedEnvFile } from './project/index';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,oBAAoB,GACrB,MAAM,gBAAgB,CAAA;AAEvB,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,SAAS,EACT,UAAU,GACX,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,iBAAiB,CAAA;AACxB,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,oBAAoB,GACrB,MAAM,gBAAgB,CAAA;AAEvB,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,SAAS,EACT,UAAU,GACX,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,iBAAiB,CAAA;AACxB,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// @mono-labs/project barrel export
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.filterEnvByConfig = exports.filterEnvByPrefixes = exports.INJECTED_KEYS_VAR = exports.ENV_FILES_VAR = exports.DEFAULT_ENV_FILES = exports.getLoadedEnvFiles = exports.getInjectedEnvKeys = exports.envFilesFromEnv = exports.resolveEnvFiles = exports.readEnvFiles = exports.loadMergedEnv = exports.loadProjectConfig = exports.loadAppConfig = exports.clearMonoConfigCache = exports.getMonoConfig = exports.getMonoFiles = exports.resolveMonoDirectory = exports.getRootJson = exports.getRootDirectory = exports.findProjectRoot = void 0;
|
|
4
|
+
exports.filterEnvByConfig = exports.filterEnvByPrefixes = exports.ENV_FILES_LOCKED_VAR = exports.INJECTED_KEYS_VAR = exports.ENV_FILES_VAR = exports.DEFAULT_ENV_FILES = exports.getLoadedEnvFiles = exports.injectedKeysFromEnv = exports.getInjectedEnvKeys = exports.envFilesFromEnv = exports.resolveEnvFiles = exports.readEnvFiles = exports.loadMergedEnv = exports.loadProjectConfig = exports.loadAppConfig = exports.clearMonoConfigCache = exports.getMonoConfig = exports.getMonoFiles = exports.resolveMonoDirectory = exports.getRootJson = exports.getRootDirectory = exports.findProjectRoot = void 0;
|
|
5
5
|
var loadFromRoot_1 = require("./loadFromRoot");
|
|
6
6
|
Object.defineProperty(exports, "findProjectRoot", { enumerable: true, get: function () { return loadFromRoot_1.findProjectRoot; } });
|
|
7
7
|
Object.defineProperty(exports, "getRootDirectory", { enumerable: true, get: function () { return loadFromRoot_1.getRootDirectory; } });
|
|
@@ -18,9 +18,11 @@ Object.defineProperty(exports, "readEnvFiles", { enumerable: true, get: function
|
|
|
18
18
|
Object.defineProperty(exports, "resolveEnvFiles", { enumerable: true, get: function () { return index_1.resolveEnvFiles; } });
|
|
19
19
|
Object.defineProperty(exports, "envFilesFromEnv", { enumerable: true, get: function () { return index_1.envFilesFromEnv; } });
|
|
20
20
|
Object.defineProperty(exports, "getInjectedEnvKeys", { enumerable: true, get: function () { return index_1.getInjectedEnvKeys; } });
|
|
21
|
+
Object.defineProperty(exports, "injectedKeysFromEnv", { enumerable: true, get: function () { return index_1.injectedKeysFromEnv; } });
|
|
21
22
|
Object.defineProperty(exports, "getLoadedEnvFiles", { enumerable: true, get: function () { return index_1.getLoadedEnvFiles; } });
|
|
22
23
|
Object.defineProperty(exports, "DEFAULT_ENV_FILES", { enumerable: true, get: function () { return index_1.DEFAULT_ENV_FILES; } });
|
|
23
24
|
Object.defineProperty(exports, "ENV_FILES_VAR", { enumerable: true, get: function () { return index_1.ENV_FILES_VAR; } });
|
|
24
25
|
Object.defineProperty(exports, "INJECTED_KEYS_VAR", { enumerable: true, get: function () { return index_1.INJECTED_KEYS_VAR; } });
|
|
26
|
+
Object.defineProperty(exports, "ENV_FILES_LOCKED_VAR", { enumerable: true, get: function () { return index_1.ENV_FILES_LOCKED_VAR; } });
|
|
25
27
|
Object.defineProperty(exports, "filterEnvByPrefixes", { enumerable: true, get: function () { return index_1.filterEnvByPrefixes; } });
|
|
26
28
|
Object.defineProperty(exports, "filterEnvByConfig", { enumerable: true, get: function () { return index_1.filterEnvByConfig; } });
|
package/dist/project/index.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export declare function loadAppConfig<TCustom = unknown, TType extends string =
|
|
|
38
38
|
meta: WorkspaceDetectResult;
|
|
39
39
|
};
|
|
40
40
|
export declare const loadProjectConfig: typeof loadAppConfig;
|
|
41
|
-
export { loadMergedEnv, readEnvFiles, resolveEnvFiles, envFilesFromEnv, getInjectedEnvKeys, getLoadedEnvFiles, DEFAULT_ENV_FILES, ENV_FILES_VAR, INJECTED_KEYS_VAR, } from './merge-env';
|
|
41
|
+
export { loadMergedEnv, readEnvFiles, resolveEnvFiles, envFilesFromEnv, getInjectedEnvKeys, injectedKeysFromEnv, getLoadedEnvFiles, DEFAULT_ENV_FILES, ENV_FILES_VAR, INJECTED_KEYS_VAR, ENV_FILES_LOCKED_VAR, } from './merge-env';
|
|
42
42
|
export type { ResolvedEnvFile } from './merge-env';
|
|
43
43
|
export { filterEnvByPrefixes, filterEnvByConfig } from './filter-env';
|
|
44
44
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/project/index.ts"],"names":[],"mappings":"AAQA,KAAK,qBAAqB,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,eAAe,EAAE,OAAO,CAAA;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,KAAK,gBAAgB,GAAG;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB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AAC,IAAI,EAAE,qBAAqB,CAAA;CAAE,CA6CxE;AAED,eAAO,MAAM,iBAAiB,sBAAgB,CAAA;AAE9C,OAAO,EACL,aAAa,EACb,YAAY,EACZ,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,aAAa,CAAA;AACpB,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/project/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.filterEnvByConfig = exports.filterEnvByPrefixes = exports.INJECTED_KEYS_VAR = exports.ENV_FILES_VAR = exports.DEFAULT_ENV_FILES = exports.getLoadedEnvFiles = exports.getInjectedEnvKeys = exports.envFilesFromEnv = exports.resolveEnvFiles = exports.readEnvFiles = exports.loadMergedEnv = exports.loadProjectConfig = void 0;
|
|
6
|
+
exports.filterEnvByConfig = exports.filterEnvByPrefixes = exports.ENV_FILES_LOCKED_VAR = exports.INJECTED_KEYS_VAR = exports.ENV_FILES_VAR = exports.DEFAULT_ENV_FILES = exports.getLoadedEnvFiles = exports.injectedKeysFromEnv = exports.getInjectedEnvKeys = exports.envFilesFromEnv = exports.resolveEnvFiles = exports.readEnvFiles = exports.loadMergedEnv = exports.loadProjectConfig = void 0;
|
|
7
7
|
exports.loadAppConfig = loadAppConfig;
|
|
8
8
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
@@ -102,10 +102,12 @@ Object.defineProperty(exports, "readEnvFiles", { enumerable: true, get: function
|
|
|
102
102
|
Object.defineProperty(exports, "resolveEnvFiles", { enumerable: true, get: function () { return merge_env_1.resolveEnvFiles; } });
|
|
103
103
|
Object.defineProperty(exports, "envFilesFromEnv", { enumerable: true, get: function () { return merge_env_1.envFilesFromEnv; } });
|
|
104
104
|
Object.defineProperty(exports, "getInjectedEnvKeys", { enumerable: true, get: function () { return merge_env_1.getInjectedEnvKeys; } });
|
|
105
|
+
Object.defineProperty(exports, "injectedKeysFromEnv", { enumerable: true, get: function () { return merge_env_1.injectedKeysFromEnv; } });
|
|
105
106
|
Object.defineProperty(exports, "getLoadedEnvFiles", { enumerable: true, get: function () { return merge_env_1.getLoadedEnvFiles; } });
|
|
106
107
|
Object.defineProperty(exports, "DEFAULT_ENV_FILES", { enumerable: true, get: function () { return merge_env_1.DEFAULT_ENV_FILES; } });
|
|
107
108
|
Object.defineProperty(exports, "ENV_FILES_VAR", { enumerable: true, get: function () { return merge_env_1.ENV_FILES_VAR; } });
|
|
108
109
|
Object.defineProperty(exports, "INJECTED_KEYS_VAR", { enumerable: true, get: function () { return merge_env_1.INJECTED_KEYS_VAR; } });
|
|
110
|
+
Object.defineProperty(exports, "ENV_FILES_LOCKED_VAR", { enumerable: true, get: function () { return merge_env_1.ENV_FILES_LOCKED_VAR; } });
|
|
109
111
|
var filter_env_1 = require("./filter-env");
|
|
110
112
|
Object.defineProperty(exports, "filterEnvByPrefixes", { enumerable: true, get: function () { return filter_env_1.filterEnvByPrefixes; } });
|
|
111
113
|
Object.defineProperty(exports, "filterEnvByConfig", { enumerable: true, get: function () { return filter_env_1.filterEnvByConfig; } });
|
|
@@ -4,6 +4,11 @@ export declare const DEFAULT_ENV_FILES: string[];
|
|
|
4
4
|
export declare const ENV_FILES_VAR = "MONOLABS_ENV_FILES";
|
|
5
5
|
/** Env var carrying the comma-separated list of keys mono injected from env files. */
|
|
6
6
|
export declare const INJECTED_KEYS_VAR = "MONOLABS_INJECTED_KEYS";
|
|
7
|
+
/**
|
|
8
|
+
* Set to "1" by a mono command that picked its env files with `envFiles`. Nested mono commands
|
|
9
|
+
* then keep MONOLABS_ENV_FILES and ignore their own `envFiles`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const ENV_FILES_LOCKED_VAR = "MONOLABS_ENV_FILES_LOCKED";
|
|
7
12
|
export type ResolvedEnvFile = {
|
|
8
13
|
path: string;
|
|
9
14
|
optional: boolean;
|
|
@@ -20,13 +25,28 @@ export declare function resolveEnvFiles(files?: string[], cwd?: string): Resolve
|
|
|
20
25
|
export declare function readEnvFiles(files?: string[], cwd?: string): Record<string, string>;
|
|
21
26
|
/** Parse the MONOLABS_ENV_FILES value; returns undefined when unset. Empty string means "no files". */
|
|
22
27
|
export declare function envFilesFromEnv(env?: NodeJS.ProcessEnv): string[] | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Keys in `env` that were injected from env files (by an earlier load in this process or by a
|
|
30
|
+
* parent mono process), as opposed to real shell variables.
|
|
31
|
+
*
|
|
32
|
+
* Provenance travels in MONOLABS_INJECTED_KEYS, together with MONOLABS_ENV_FILES naming the
|
|
33
|
+
* files the values came from. A listed key whose current value no longer matches those files
|
|
34
|
+
* was overridden after injection (e.g. `DB_HOST=x mono ...` in a parent's action), so it
|
|
35
|
+
* counts as a real variable again.
|
|
36
|
+
*/
|
|
37
|
+
export declare function injectedKeysFromEnv(env?: NodeJS.ProcessEnv): string[];
|
|
23
38
|
/** Keys the last loadMergedEnv() call injected into process.env (i.e. not real shell vars). */
|
|
24
39
|
export declare function getInjectedEnvKeys(): string[];
|
|
25
40
|
/** Absolute paths of the files the last loadMergedEnv() call considered. */
|
|
26
41
|
export declare function getLoadedEnvFiles(): string[];
|
|
27
42
|
/**
|
|
28
|
-
* Load env files into process.env without overwriting
|
|
43
|
+
* Load env files into process.env without overwriting real variables.
|
|
29
44
|
* File list: `files` arg → MONOLABS_ENV_FILES (set by a parent mono process) → .env + .env.local.
|
|
45
|
+
*
|
|
46
|
+
* Values injected earlier (by a previous call or a parent mono process, per
|
|
47
|
+
* MONOLABS_INJECTED_KEYS) are not real variables: they are removed first, so the selected files
|
|
48
|
+
* replace them. Afterwards MONOLABS_ENV_FILES and MONOLABS_INJECTED_KEYS in process.env describe
|
|
49
|
+
* this load, so later loads and child processes keep the provenance.
|
|
30
50
|
*/
|
|
31
51
|
export declare function loadMergedEnv(files?: string[]): NodeJS.ProcessEnv;
|
|
32
52
|
//# sourceMappingURL=merge-env.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge-env.d.ts","sourceRoot":"","sources":["../../src/project/merge-env.ts"],"names":[],"mappings":"AAIA,2FAA2F;AAC3F,eAAO,MAAM,iBAAiB,UAAyB,CAAC;AAExD,iGAAiG;AACjG,eAAO,MAAM,aAAa,uBAAuB,CAAC;AAElD,sFAAsF;AACtF,eAAO,MAAM,iBAAiB,2BAA2B,CAAC;AAE1D,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAElE;;;GAGG;AACH,wBAAgB,eAAe,CAC9B,KAAK,GAAE,MAAM,EAAsB,EACnC,GAAG,GAAE,MAAsB,GACzB,eAAe,EAAE,CAOnB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC3B,KAAK,GAAE,MAAM,EAAsB,EACnC,GAAG,GAAE,MAAsB,GACzB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAUxB;AAED,uGAAuG;AACvG,wBAAgB,eAAe,CAC9B,GAAG,GAAE,MAAM,CAAC,UAAwB,GAClC,MAAM,EAAE,GAAG,SAAS,CAItB;
|
|
1
|
+
{"version":3,"file":"merge-env.d.ts","sourceRoot":"","sources":["../../src/project/merge-env.ts"],"names":[],"mappings":"AAIA,2FAA2F;AAC3F,eAAO,MAAM,iBAAiB,UAAyB,CAAC;AAExD,iGAAiG;AACjG,eAAO,MAAM,aAAa,uBAAuB,CAAC;AAElD,sFAAsF;AACtF,eAAO,MAAM,iBAAiB,2BAA2B,CAAC;AAE1D;;;GAGG;AACH,eAAO,MAAM,oBAAoB,8BAA8B,CAAC;AAEhE,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAElE;;;GAGG;AACH,wBAAgB,eAAe,CAC9B,KAAK,GAAE,MAAM,EAAsB,EACnC,GAAG,GAAE,MAAsB,GACzB,eAAe,EAAE,CAOnB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC3B,KAAK,GAAE,MAAM,EAAsB,EACnC,GAAG,GAAE,MAAsB,GACzB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAUxB;AAED,uGAAuG;AACvG,wBAAgB,eAAe,CAC9B,GAAG,GAAE,MAAM,CAAC,UAAwB,GAClC,MAAM,EAAE,GAAG,SAAS,CAItB;AA0BD;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,EAAE,CAKlF;AAED,+FAA+F;AAC/F,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAE7C;AAED,4EAA4E;AAC5E,wBAAgB,iBAAiB,IAAI,MAAM,EAAE,CAE5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,UAAU,CAmBjE"}
|
|
@@ -3,10 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.INJECTED_KEYS_VAR = exports.ENV_FILES_VAR = exports.DEFAULT_ENV_FILES = void 0;
|
|
6
|
+
exports.ENV_FILES_LOCKED_VAR = exports.INJECTED_KEYS_VAR = exports.ENV_FILES_VAR = exports.DEFAULT_ENV_FILES = void 0;
|
|
7
7
|
exports.resolveEnvFiles = resolveEnvFiles;
|
|
8
8
|
exports.readEnvFiles = readEnvFiles;
|
|
9
9
|
exports.envFilesFromEnv = envFilesFromEnv;
|
|
10
|
+
exports.injectedKeysFromEnv = injectedKeysFromEnv;
|
|
10
11
|
exports.getInjectedEnvKeys = getInjectedEnvKeys;
|
|
11
12
|
exports.getLoadedEnvFiles = getLoadedEnvFiles;
|
|
12
13
|
exports.loadMergedEnv = loadMergedEnv;
|
|
@@ -19,6 +20,11 @@ exports.DEFAULT_ENV_FILES = ['.env', '.env.local'];
|
|
|
19
20
|
exports.ENV_FILES_VAR = 'MONOLABS_ENV_FILES';
|
|
20
21
|
/** Env var carrying the comma-separated list of keys mono injected from env files. */
|
|
21
22
|
exports.INJECTED_KEYS_VAR = 'MONOLABS_INJECTED_KEYS';
|
|
23
|
+
/**
|
|
24
|
+
* Set to "1" by a mono command that picked its env files with `envFiles`. Nested mono commands
|
|
25
|
+
* then keep MONOLABS_ENV_FILES and ignore their own `envFiles`.
|
|
26
|
+
*/
|
|
27
|
+
exports.ENV_FILES_LOCKED_VAR = 'MONOLABS_ENV_FILES_LOCKED';
|
|
22
28
|
/**
|
|
23
29
|
* Resolve env file names to absolute paths. The default names (.env, .env.local) are optional;
|
|
24
30
|
* any other explicitly listed file is required and must exist.
|
|
@@ -56,6 +62,42 @@ function envFilesFromEnv(env = process.env) {
|
|
|
56
62
|
}
|
|
57
63
|
let injectedKeys = [];
|
|
58
64
|
let loadedFiles = [];
|
|
65
|
+
/** Parse the MONOLABS_INJECTED_KEYS value into a key list. */
|
|
66
|
+
function parseKeyList(raw) {
|
|
67
|
+
return (raw ?? '')
|
|
68
|
+
.split(',')
|
|
69
|
+
.map((k) => k.trim())
|
|
70
|
+
.filter(Boolean);
|
|
71
|
+
}
|
|
72
|
+
/** Like readEnvFiles, but skips files that are missing or unreadable instead of throwing. */
|
|
73
|
+
function readEnvFilesLenient(files) {
|
|
74
|
+
const merged = {};
|
|
75
|
+
for (const file of files) {
|
|
76
|
+
try {
|
|
77
|
+
Object.assign(merged, dotenv_1.default.parse(fs_1.default.readFileSync(file)));
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// provenance check only: an unreadable file just can't confirm its values
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return merged;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Keys in `env` that were injected from env files (by an earlier load in this process or by a
|
|
87
|
+
* parent mono process), as opposed to real shell variables.
|
|
88
|
+
*
|
|
89
|
+
* Provenance travels in MONOLABS_INJECTED_KEYS, together with MONOLABS_ENV_FILES naming the
|
|
90
|
+
* files the values came from. A listed key whose current value no longer matches those files
|
|
91
|
+
* was overridden after injection (e.g. `DB_HOST=x mono ...` in a parent's action), so it
|
|
92
|
+
* counts as a real variable again.
|
|
93
|
+
*/
|
|
94
|
+
function injectedKeysFromEnv(env = process.env) {
|
|
95
|
+
const listed = parseKeyList(env[exports.INJECTED_KEYS_VAR]).filter((k) => env[k] !== undefined);
|
|
96
|
+
if (listed.length === 0)
|
|
97
|
+
return [];
|
|
98
|
+
const sourceValues = readEnvFilesLenient(envFilesFromEnv(env) ?? []);
|
|
99
|
+
return listed.filter((k) => !(k in sourceValues) || sourceValues[k] === env[k]);
|
|
100
|
+
}
|
|
59
101
|
/** Keys the last loadMergedEnv() call injected into process.env (i.e. not real shell vars). */
|
|
60
102
|
function getInjectedEnvKeys() {
|
|
61
103
|
return [...injectedKeys];
|
|
@@ -65,12 +107,19 @@ function getLoadedEnvFiles() {
|
|
|
65
107
|
return [...loadedFiles];
|
|
66
108
|
}
|
|
67
109
|
/**
|
|
68
|
-
* Load env files into process.env without overwriting
|
|
110
|
+
* Load env files into process.env without overwriting real variables.
|
|
69
111
|
* File list: `files` arg → MONOLABS_ENV_FILES (set by a parent mono process) → .env + .env.local.
|
|
112
|
+
*
|
|
113
|
+
* Values injected earlier (by a previous call or a parent mono process, per
|
|
114
|
+
* MONOLABS_INJECTED_KEYS) are not real variables: they are removed first, so the selected files
|
|
115
|
+
* replace them. Afterwards MONOLABS_ENV_FILES and MONOLABS_INJECTED_KEYS in process.env describe
|
|
116
|
+
* this load, so later loads and child processes keep the provenance.
|
|
70
117
|
*/
|
|
71
118
|
function loadMergedEnv(files) {
|
|
72
119
|
const list = files ?? envFilesFromEnv() ?? exports.DEFAULT_ENV_FILES;
|
|
73
|
-
const merged = readEnvFiles(list);
|
|
120
|
+
const merged = readEnvFiles(list); // may throw: do it before touching process.env
|
|
121
|
+
for (const key of injectedKeysFromEnv(process.env))
|
|
122
|
+
delete process.env[key];
|
|
74
123
|
loadedFiles = resolveEnvFiles(list).map((f) => f.path);
|
|
75
124
|
injectedKeys = [];
|
|
76
125
|
for (const [key, value] of Object.entries(merged)) {
|
|
@@ -79,5 +128,7 @@ function loadMergedEnv(files) {
|
|
|
79
128
|
injectedKeys.push(key);
|
|
80
129
|
}
|
|
81
130
|
}
|
|
131
|
+
process.env[exports.ENV_FILES_VAR] = loadedFiles.join(path_1.default.delimiter);
|
|
132
|
+
process.env[exports.INJECTED_KEYS_VAR] = injectedKeys.join(',');
|
|
82
133
|
return process.env;
|
|
83
134
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mono-labs/project",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.292",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"description": "Project configuration utilities for mono-labs",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@mono-labs/shared": "0.1.
|
|
35
|
+
"@mono-labs/shared": "0.1.292",
|
|
36
36
|
"dotenv": "^17.2.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -25,10 +25,12 @@ export {
|
|
|
25
25
|
resolveEnvFiles,
|
|
26
26
|
envFilesFromEnv,
|
|
27
27
|
getInjectedEnvKeys,
|
|
28
|
+
injectedKeysFromEnv,
|
|
28
29
|
getLoadedEnvFiles,
|
|
29
30
|
DEFAULT_ENV_FILES,
|
|
30
31
|
ENV_FILES_VAR,
|
|
31
32
|
INJECTED_KEYS_VAR,
|
|
33
|
+
ENV_FILES_LOCKED_VAR,
|
|
32
34
|
filterEnvByPrefixes,
|
|
33
35
|
filterEnvByConfig,
|
|
34
36
|
} from './project/index'
|
package/src/project/index.ts
CHANGED
|
@@ -170,10 +170,12 @@ export {
|
|
|
170
170
|
resolveEnvFiles,
|
|
171
171
|
envFilesFromEnv,
|
|
172
172
|
getInjectedEnvKeys,
|
|
173
|
+
injectedKeysFromEnv,
|
|
173
174
|
getLoadedEnvFiles,
|
|
174
175
|
DEFAULT_ENV_FILES,
|
|
175
176
|
ENV_FILES_VAR,
|
|
176
177
|
INJECTED_KEYS_VAR,
|
|
178
|
+
ENV_FILES_LOCKED_VAR,
|
|
177
179
|
} from './merge-env'
|
|
178
180
|
export type { ResolvedEnvFile } from './merge-env'
|
|
179
181
|
export { filterEnvByPrefixes, filterEnvByConfig } from './filter-env'
|
package/src/project/merge-env.ts
CHANGED
|
@@ -11,6 +11,12 @@ export const ENV_FILES_VAR = 'MONOLABS_ENV_FILES';
|
|
|
11
11
|
/** Env var carrying the comma-separated list of keys mono injected from env files. */
|
|
12
12
|
export const INJECTED_KEYS_VAR = 'MONOLABS_INJECTED_KEYS';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Set to "1" by a mono command that picked its env files with `envFiles`. Nested mono commands
|
|
16
|
+
* then keep MONOLABS_ENV_FILES and ignore their own `envFiles`.
|
|
17
|
+
*/
|
|
18
|
+
export const ENV_FILES_LOCKED_VAR = 'MONOLABS_ENV_FILES_LOCKED';
|
|
19
|
+
|
|
14
20
|
export type ResolvedEnvFile = { path: string; optional: boolean };
|
|
15
21
|
|
|
16
22
|
/**
|
|
@@ -60,6 +66,43 @@ export function envFilesFromEnv(
|
|
|
60
66
|
let injectedKeys: string[] = [];
|
|
61
67
|
let loadedFiles: string[] = [];
|
|
62
68
|
|
|
69
|
+
/** Parse the MONOLABS_INJECTED_KEYS value into a key list. */
|
|
70
|
+
function parseKeyList(raw: string | undefined): string[] {
|
|
71
|
+
return (raw ?? '')
|
|
72
|
+
.split(',')
|
|
73
|
+
.map((k) => k.trim())
|
|
74
|
+
.filter(Boolean);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Like readEnvFiles, but skips files that are missing or unreadable instead of throwing. */
|
|
78
|
+
function readEnvFilesLenient(files: string[]): Record<string, string> {
|
|
79
|
+
const merged: Record<string, string> = {};
|
|
80
|
+
for (const file of files) {
|
|
81
|
+
try {
|
|
82
|
+
Object.assign(merged, dotenv.parse(fs.readFileSync(file)));
|
|
83
|
+
} catch {
|
|
84
|
+
// provenance check only: an unreadable file just can't confirm its values
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return merged;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Keys in `env` that were injected from env files (by an earlier load in this process or by a
|
|
92
|
+
* parent mono process), as opposed to real shell variables.
|
|
93
|
+
*
|
|
94
|
+
* Provenance travels in MONOLABS_INJECTED_KEYS, together with MONOLABS_ENV_FILES naming the
|
|
95
|
+
* files the values came from. A listed key whose current value no longer matches those files
|
|
96
|
+
* was overridden after injection (e.g. `DB_HOST=x mono ...` in a parent's action), so it
|
|
97
|
+
* counts as a real variable again.
|
|
98
|
+
*/
|
|
99
|
+
export function injectedKeysFromEnv(env: NodeJS.ProcessEnv = process.env): string[] {
|
|
100
|
+
const listed = parseKeyList(env[INJECTED_KEYS_VAR]).filter((k) => env[k] !== undefined);
|
|
101
|
+
if (listed.length === 0) return [];
|
|
102
|
+
const sourceValues = readEnvFilesLenient(envFilesFromEnv(env) ?? []);
|
|
103
|
+
return listed.filter((k) => !(k in sourceValues) || sourceValues[k] === env[k]);
|
|
104
|
+
}
|
|
105
|
+
|
|
63
106
|
/** Keys the last loadMergedEnv() call injected into process.env (i.e. not real shell vars). */
|
|
64
107
|
export function getInjectedEnvKeys(): string[] {
|
|
65
108
|
return [...injectedKeys];
|
|
@@ -71,12 +114,19 @@ export function getLoadedEnvFiles(): string[] {
|
|
|
71
114
|
}
|
|
72
115
|
|
|
73
116
|
/**
|
|
74
|
-
* Load env files into process.env without overwriting
|
|
117
|
+
* Load env files into process.env without overwriting real variables.
|
|
75
118
|
* File list: `files` arg → MONOLABS_ENV_FILES (set by a parent mono process) → .env + .env.local.
|
|
119
|
+
*
|
|
120
|
+
* Values injected earlier (by a previous call or a parent mono process, per
|
|
121
|
+
* MONOLABS_INJECTED_KEYS) are not real variables: they are removed first, so the selected files
|
|
122
|
+
* replace them. Afterwards MONOLABS_ENV_FILES and MONOLABS_INJECTED_KEYS in process.env describe
|
|
123
|
+
* this load, so later loads and child processes keep the provenance.
|
|
76
124
|
*/
|
|
77
125
|
export function loadMergedEnv(files?: string[]): NodeJS.ProcessEnv {
|
|
78
126
|
const list = files ?? envFilesFromEnv() ?? DEFAULT_ENV_FILES;
|
|
79
|
-
const merged = readEnvFiles(list);
|
|
127
|
+
const merged = readEnvFiles(list); // may throw: do it before touching process.env
|
|
128
|
+
|
|
129
|
+
for (const key of injectedKeysFromEnv(process.env)) delete process.env[key];
|
|
80
130
|
|
|
81
131
|
loadedFiles = resolveEnvFiles(list).map((f) => f.path);
|
|
82
132
|
injectedKeys = [];
|
|
@@ -87,5 +137,8 @@ export function loadMergedEnv(files?: string[]): NodeJS.ProcessEnv {
|
|
|
87
137
|
injectedKeys.push(key);
|
|
88
138
|
}
|
|
89
139
|
}
|
|
140
|
+
|
|
141
|
+
process.env[ENV_FILES_VAR] = loadedFiles.join(path.delimiter);
|
|
142
|
+
process.env[INJECTED_KEYS_VAR] = injectedKeys.join(',');
|
|
90
143
|
return process.env;
|
|
91
144
|
}
|