@cogs/config 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -2
- package/dist/cjs/correct-env.js +44 -0
- package/dist/cjs/dotenv-checkers.js +114 -0
- package/dist/cjs/dotenv-fixers.js +88 -0
- package/dist/cjs/dotenv-with-expand.js +123 -0
- package/dist/cjs/envs.js +66 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/preload.js +18 -0
- package/dist/cjs/process-env.js +39 -0
- package/dist/cjs/utils.js +65 -0
- package/dist/correct-env.d.ts.map +1 -1
- package/dist/correct-env.js.map +1 -1
- package/dist/dotenv-checkers.d.ts.map +1 -1
- package/dist/dotenv-checkers.js +6 -6
- package/dist/dotenv-checkers.js.map +1 -1
- package/dist/dotenv-fixers.d.ts.map +1 -1
- package/dist/dotenv-fixers.js +5 -5
- package/dist/dotenv-fixers.js.map +1 -1
- package/dist/dotenv-with-expand.d.ts +1 -1
- package/dist/dotenv-with-expand.d.ts.map +1 -1
- package/dist/dotenv-with-expand.js +5 -5
- package/dist/dotenv-with-expand.js.map +1 -1
- package/dist/envs.d.ts.map +1 -1
- package/dist/envs.js +10 -10
- package/dist/envs.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/preload.js +3 -3
- package/dist/preload.js.map +1 -1
- package/dist/process-env.d.ts.map +1 -1
- package/dist/process-env.js.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -2
- package/dist/utils.js.map +1 -1
- package/package.json +15 -7
package/README.md
CHANGED
|
@@ -5,8 +5,11 @@ resolves the layered `.env` file chain, expands `${VAR}` references, and folds
|
|
|
5
5
|
the result into `process.env` — with deploy-injected variables staying
|
|
6
6
|
authoritative by default. One loader, one precedence, no per-repo forks.
|
|
7
7
|
|
|
8
|
-
Runtime dependencies: `dotenv`, `dotenv-expand`.
|
|
9
|
-
|
|
8
|
+
Runtime dependencies: `dotenv`, `dotenv-expand`. Ships **dual ESM + CJS** so it
|
|
9
|
+
works from an ESM `--import` preload, a CJS `--require` hook (dd-trace and other
|
|
10
|
+
one-off tools that must load before anything else), and a plain
|
|
11
|
+
`require('@cogs/config')`. Node 20+ (the ESM `--import` preload needs ≥ 20.6;
|
|
12
|
+
the CJS `--require` path works on any Node 20).
|
|
10
13
|
|
|
11
14
|
See [`docs/ENVIRONMENT-CONFIG.md`](../../../next-starters/docs/ENVIRONMENT-CONFIG.md)
|
|
12
15
|
for the full spec and [ADR 0001](../../../next-starters/docs/adr/0001-canonical-env-schema.md)
|
|
@@ -85,6 +88,32 @@ The `./preload` entry side-effect-calls `correctEnv()` then
|
|
|
85
88
|
`SECRETS_PATH` (`${SECRETS_PATH}secrets.json`, or `''` when unset). Requires
|
|
86
89
|
Node ≥ 20.6.
|
|
87
90
|
|
|
91
|
+
### CJS preload (`--require`) — dd-trace and one-off tools
|
|
92
|
+
|
|
93
|
+
For a CJS `--require` hook (or an app `server-preload.cjs`), use the `./register`
|
|
94
|
+
subpath — same side effect, loaded via CommonJS so it can sit alongside
|
|
95
|
+
`dd-trace/init` and other tools that must run before the app:
|
|
96
|
+
|
|
97
|
+
```jsonc
|
|
98
|
+
// package.json — order matters: env first, then tracer
|
|
99
|
+
{
|
|
100
|
+
"scripts": {
|
|
101
|
+
"start": "NODE_OPTIONS=\"--require @cogs/config/register --require dd-trace/init\" node server.js"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Or from a `server-preload.cjs` that also does other CJS bootstrap:
|
|
107
|
+
|
|
108
|
+
```cjs
|
|
109
|
+
// server-preload.cjs
|
|
110
|
+
require("@cogs/config/register"); // folds the .env chain into process.env
|
|
111
|
+
require("dd-trace").init();
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`require('@cogs/config')` also exposes the full API (`correctEnv`, `envs`, …)
|
|
115
|
+
from the CJS build for scripts that need to call the loader directly.
|
|
116
|
+
|
|
88
117
|
### `next.config.ts` (build time)
|
|
89
118
|
|
|
90
119
|
Load env at the top of the config so the build sees resolved values:
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.correctEnv = void 0;
|
|
4
|
+
// please note that `process.env` is not exported so only this process has the
|
|
5
|
+
// values for anything set in `process.env`
|
|
6
|
+
function existy(x) {
|
|
7
|
+
return x != null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Corrects and sets various environment variables based on provided values or
|
|
11
|
+
* defaults. Do this as the first thing so that any code reading it knows the
|
|
12
|
+
* right env. Existing `process.env` values always win over the provided options.
|
|
13
|
+
*
|
|
14
|
+
* @param options - An optional object containing environment-related options.
|
|
15
|
+
* @param options.nodeEnv - The desired Node.js environment (NODE_ENV).
|
|
16
|
+
* @param options.babelEnv - The desired Babel environment (BABEL_ENV).
|
|
17
|
+
* @param options.browserslistEnv - The desired Browserslist environment (BROWSERSLIST_ENV).
|
|
18
|
+
* @param options.env - The desired environment (ENV).
|
|
19
|
+
* @param options.browser - The desired browser environment (__BROWSER__).
|
|
20
|
+
*/
|
|
21
|
+
const correctEnv = ({ nodeEnv, babelEnv, browserslistEnv, env, browser, } = {}) => {
|
|
22
|
+
const nEnv = process.env.NODE_ENV || nodeEnv;
|
|
23
|
+
const bEnv = process.env.BABEL_ENV || babelEnv;
|
|
24
|
+
const blEnv = process.env.BROWSERSLIST_ENV || browserslistEnv || nEnv;
|
|
25
|
+
const aEnv = process.env.ENV || env;
|
|
26
|
+
let browserEnv = process.env.__BROWSER__;
|
|
27
|
+
if (!existy(browserEnv) && existy(browser)) {
|
|
28
|
+
browserEnv = browser;
|
|
29
|
+
}
|
|
30
|
+
if (existy(bEnv)) {
|
|
31
|
+
process.env.BABEL_ENV = bEnv;
|
|
32
|
+
}
|
|
33
|
+
if (existy(aEnv)) {
|
|
34
|
+
process.env.ENV = aEnv;
|
|
35
|
+
}
|
|
36
|
+
if (existy(blEnv)) {
|
|
37
|
+
process.env.BROWSERSLIST_ENV = blEnv;
|
|
38
|
+
}
|
|
39
|
+
if (existy(browserEnv)) {
|
|
40
|
+
process.env.__BROWSER__ = browserEnv;
|
|
41
|
+
}
|
|
42
|
+
process.env = Object.assign(process.env, { NODE_ENV: nEnv });
|
|
43
|
+
};
|
|
44
|
+
exports.correctEnv = correctEnv;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dotenvCheckers = exports.valueWithoutQuotesChecker = exports.trailingWhitespaceChecker = exports.quoteCharacterChecker = exports.lowercaseKeyChecker = exports.leadingCharacterChecker = exports.incorrectDelimiterChecker = void 0;
|
|
4
|
+
const utils_js_1 = require("./utils.js");
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a given key has incorrect delimiters. Delimiters should occur
|
|
7
|
+
* between characters, not as the initial character. This function removes
|
|
8
|
+
* any invalid leading characters before checking for incorrect delimiters.
|
|
9
|
+
*
|
|
10
|
+
* @param key - The key to be checked for incorrect delimiters.
|
|
11
|
+
* @param line - The line of text where the key is found (for logging purposes).
|
|
12
|
+
* @returns True if incorrect delimiters are found, undefined otherwise.
|
|
13
|
+
*/
|
|
14
|
+
const incorrectDelimiterChecker = (key, line) => {
|
|
15
|
+
// delimiters occur /between/ characters, not as the initial character, so
|
|
16
|
+
// we should remove all invalid leading characters before checking for
|
|
17
|
+
// incorrect delimiters
|
|
18
|
+
const cleanedKey = (0, utils_js_1.removeInvalidLeadingChars)(key);
|
|
19
|
+
const chars = cleanedKey.trim().split('');
|
|
20
|
+
if (chars.some((char) => !/[a-z0-9_]/i.test(char))) {
|
|
21
|
+
console.log(`warning: '${key}' incorrect delimiter`);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.incorrectDelimiterChecker = incorrectDelimiterChecker;
|
|
26
|
+
/**
|
|
27
|
+
* Checks if a key starts with an unallowed character. Only characters from A to
|
|
28
|
+
* Z and _(underscore) are allowed as the initial character.
|
|
29
|
+
*
|
|
30
|
+
* @param key - The key to be checked for an unallowed leading character.
|
|
31
|
+
* @returns True if an unallowed leading character is found, undefined otherwise.
|
|
32
|
+
*/
|
|
33
|
+
const leadingCharacterChecker = (key) => {
|
|
34
|
+
if (/^[a-z_]/i.test(key)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
console.log(`warning: '${key}' starts with an unallowed character. (characters from A to Z and _(underscore) are allowed)`);
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
40
|
+
exports.leadingCharacterChecker = leadingCharacterChecker;
|
|
41
|
+
/**
|
|
42
|
+
* Checks if a key contains lowercase characters.
|
|
43
|
+
*
|
|
44
|
+
* @param key - The key to be checked for lowercase characters.
|
|
45
|
+
* @returns True if lowercase characters are found in the key, undefined otherwise.
|
|
46
|
+
*/
|
|
47
|
+
const lowercaseKeyChecker = (key) => {
|
|
48
|
+
if (key.toUpperCase() === key) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
console.log(`warning: '${key}' has lowercase characters.`);
|
|
52
|
+
return true;
|
|
53
|
+
};
|
|
54
|
+
exports.lowercaseKeyChecker = lowercaseKeyChecker;
|
|
55
|
+
/**
|
|
56
|
+
* Checks if a value contains quote characters (`'` or `"`), but skips if the
|
|
57
|
+
* value is multiline, contains whitespaces, newline characters, or hash signs.
|
|
58
|
+
*
|
|
59
|
+
* @param line - The value to be checked for quote characters.
|
|
60
|
+
* @returns True if quote characters are found in the value, undefined otherwise.
|
|
61
|
+
*/
|
|
62
|
+
const quoteCharacterChecker = (line) => {
|
|
63
|
+
if (line.includes('\n') ||
|
|
64
|
+
/[ \t\r\n\f]/.test(line) ||
|
|
65
|
+
line.includes('$') ||
|
|
66
|
+
line.includes('#')) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (line.includes('"') || line.includes("'")) {
|
|
70
|
+
console.log(`warning: '${line}' contains quote characters.`);
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
exports.quoteCharacterChecker = quoteCharacterChecker;
|
|
75
|
+
/**
|
|
76
|
+
* Checks if a line has trailing whitespace characters (spaces or tabs).
|
|
77
|
+
*
|
|
78
|
+
* @param line - The line to be checked for trailing whitespace.
|
|
79
|
+
* @returns True if trailing whitespace is found in the line, undefined otherwise.
|
|
80
|
+
*/
|
|
81
|
+
const trailingWhitespaceChecker = (line) => {
|
|
82
|
+
if (line.endsWith(' ')) {
|
|
83
|
+
console.log(`warning: '${line}' has a trailing whitespace.`);
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
exports.trailingWhitespaceChecker = trailingWhitespaceChecker;
|
|
88
|
+
/**
|
|
89
|
+
* Checks if a value contains whitespaces and doesn't contain quote characters
|
|
90
|
+
* (`'` / `"`).
|
|
91
|
+
*
|
|
92
|
+
* @param line - The value to be checked for whitespaces and lack of quotes.
|
|
93
|
+
* @returns True if the value has whitespaces without quotes, undefined otherwise.
|
|
94
|
+
*/
|
|
95
|
+
const valueWithoutQuotesChecker = (line) => {
|
|
96
|
+
line = line.trim();
|
|
97
|
+
if (/[ \t\r\n\f]/.test(line) &&
|
|
98
|
+
!(line.startsWith("'") && line.endsWith("'")) &&
|
|
99
|
+
!(line.startsWith('"') && line.endsWith('"'))) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
exports.valueWithoutQuotesChecker = valueWithoutQuotesChecker;
|
|
104
|
+
/**
|
|
105
|
+
* An array of functions for checking various aspects of .env file entries.
|
|
106
|
+
*/
|
|
107
|
+
exports.dotenvCheckers = [
|
|
108
|
+
exports.incorrectDelimiterChecker,
|
|
109
|
+
exports.leadingCharacterChecker,
|
|
110
|
+
exports.lowercaseKeyChecker,
|
|
111
|
+
exports.quoteCharacterChecker,
|
|
112
|
+
exports.trailingWhitespaceChecker,
|
|
113
|
+
exports.valueWithoutQuotesChecker,
|
|
114
|
+
];
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dotenvLineFixers = exports.dotenvKeyFixers = exports.valueWithoutQuotesFixer = exports.trailingWhitespaceFixer = exports.quoteCharacterFixer = exports.lowercaseKeyFixer = exports.leadingCharacterFixer = exports.incorrectDelimiterFixer = void 0;
|
|
4
|
+
const dotenv_checkers_js_1 = require("./dotenv-checkers.js");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
/**
|
|
7
|
+
* Fixes incorrect delimiters by replacing non-alphanumeric characters with
|
|
8
|
+
* underscores ('_'). Also ensures that an underscore separates words in the key.
|
|
9
|
+
*
|
|
10
|
+
* @param key - The key to fix.
|
|
11
|
+
* @param line - The corresponding line from the .env file.
|
|
12
|
+
* @returns An array containing the fixed key and the original line.
|
|
13
|
+
*/
|
|
14
|
+
const incorrectDelimiterFixer = (key, line) => {
|
|
15
|
+
if (!(0, dotenv_checkers_js_1.incorrectDelimiterChecker)(key, line)) {
|
|
16
|
+
return [key, line];
|
|
17
|
+
}
|
|
18
|
+
let cleanedKey = (0, utils_js_1.removeInvalidLeadingChars)(key);
|
|
19
|
+
const startIdx = key.length - cleanedKey.length;
|
|
20
|
+
cleanedKey = key.slice(startIdx).replace(/[^a-z0-9]/gi, '_');
|
|
21
|
+
return [`${key.substring(0, startIdx)}${cleanedKey}`, line];
|
|
22
|
+
};
|
|
23
|
+
exports.incorrectDelimiterFixer = incorrectDelimiterFixer;
|
|
24
|
+
// Fixes key that starts with an unallowed character.
|
|
25
|
+
const leadingCharacterFixer = (key, line) => {
|
|
26
|
+
if (!(0, dotenv_checkers_js_1.leadingCharacterChecker)(key)) {
|
|
27
|
+
return [key, line];
|
|
28
|
+
}
|
|
29
|
+
const cleanedKey = (0, utils_js_1.removeInvalidLeadingChars)(key);
|
|
30
|
+
return [cleanedKey, line];
|
|
31
|
+
};
|
|
32
|
+
exports.leadingCharacterFixer = leadingCharacterFixer;
|
|
33
|
+
// Fixes lowercase key by upper casing it.
|
|
34
|
+
const lowercaseKeyFixer = (key, line) => {
|
|
35
|
+
if (!(0, dotenv_checkers_js_1.lowercaseKeyChecker)(key)) {
|
|
36
|
+
return [key, line];
|
|
37
|
+
}
|
|
38
|
+
return [key.toUpperCase(), line];
|
|
39
|
+
};
|
|
40
|
+
exports.lowercaseKeyFixer = lowercaseKeyFixer;
|
|
41
|
+
// Quote character: Fixes when a value contains quote characters(`'` / `"`) but
|
|
42
|
+
// skips if the value is multiline, contains whitespaces, newline characters or
|
|
43
|
+
// hash signs:
|
|
44
|
+
const quoteCharacterFixer = (key, line) => {
|
|
45
|
+
if (!(0, dotenv_checkers_js_1.quoteCharacterChecker)(line)) {
|
|
46
|
+
return [key, line];
|
|
47
|
+
}
|
|
48
|
+
const pureVal = line.replace(/"|'/g, '');
|
|
49
|
+
return [key, pureVal];
|
|
50
|
+
};
|
|
51
|
+
exports.quoteCharacterFixer = quoteCharacterFixer;
|
|
52
|
+
// Fixes trailing whitespace.
|
|
53
|
+
const trailingWhitespaceFixer = (key, line) => {
|
|
54
|
+
if (!(0, dotenv_checkers_js_1.trailingWhitespaceChecker)(line)) {
|
|
55
|
+
return [key, line];
|
|
56
|
+
}
|
|
57
|
+
return [key, line.trimEnd()];
|
|
58
|
+
};
|
|
59
|
+
exports.trailingWhitespaceFixer = trailingWhitespaceFixer;
|
|
60
|
+
// Value without quotes: Detects if a value contains whitespaces and at the
|
|
61
|
+
// same time doesn't contain quote characters (`'` / `"`):
|
|
62
|
+
const valueWithoutQuotesFixer = (key, line) => {
|
|
63
|
+
if (!(0, dotenv_checkers_js_1.valueWithoutQuotesChecker)(line)) {
|
|
64
|
+
return [key, line];
|
|
65
|
+
}
|
|
66
|
+
let pureVal = '';
|
|
67
|
+
if (line.includes("'")) {
|
|
68
|
+
pureVal = `"${line}"`;
|
|
69
|
+
}
|
|
70
|
+
else if (line.includes('"')) {
|
|
71
|
+
pureVal = `'${line}'`;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
pureVal = `'${line}'`;
|
|
75
|
+
}
|
|
76
|
+
return [key, pureVal];
|
|
77
|
+
};
|
|
78
|
+
exports.valueWithoutQuotesFixer = valueWithoutQuotesFixer;
|
|
79
|
+
exports.dotenvKeyFixers = [
|
|
80
|
+
exports.incorrectDelimiterFixer,
|
|
81
|
+
exports.leadingCharacterFixer,
|
|
82
|
+
exports.lowercaseKeyFixer,
|
|
83
|
+
];
|
|
84
|
+
exports.dotenvLineFixers = [
|
|
85
|
+
exports.quoteCharacterFixer,
|
|
86
|
+
exports.trailingWhitespaceFixer,
|
|
87
|
+
exports.valueWithoutQuotesFixer,
|
|
88
|
+
];
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.config = exports.parseJSON = exports.parse = void 0;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
9
|
+
const dotenv_expand_1 = __importDefault(require("dotenv-expand"));
|
|
10
|
+
const dotenvExpandOverrideFix = (parsed) => {
|
|
11
|
+
const obj = {};
|
|
12
|
+
dotenv_expand_1.default.expand({ parsed, processEnv: obj });
|
|
13
|
+
const source = Object.keys(obj).length > 0 ? obj : parsed;
|
|
14
|
+
// Set process.env
|
|
15
|
+
for (const key of Object.keys(source)) {
|
|
16
|
+
if (Object.hasOwn(process.env, key)) {
|
|
17
|
+
const upcoming = source[key];
|
|
18
|
+
const prior = process.env[key];
|
|
19
|
+
if (prior !== upcoming) {
|
|
20
|
+
console.log(`"${key}" is already defined as ${prior}, and WAS overwritten with ${upcoming}`);
|
|
21
|
+
}
|
|
22
|
+
process.env[key] = source[key];
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
process.env[key] = source[key];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Parse and expand environment variables from a .env file.
|
|
31
|
+
*
|
|
32
|
+
* @param src - The raw .env contents.
|
|
33
|
+
* @param override - Whether file values override existing process.env values.
|
|
34
|
+
* @param processEnv - The object expansion resolves references against.
|
|
35
|
+
* @returns An object containing the parsed and expanded environment variables.
|
|
36
|
+
*/
|
|
37
|
+
const parse = (src, override, processEnv) => {
|
|
38
|
+
const parsed = dotenv_1.default.parse(src.toString());
|
|
39
|
+
if (override) {
|
|
40
|
+
dotenvExpandOverrideFix(parsed);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
dotenv_expand_1.default.expand({ parsed, processEnv });
|
|
44
|
+
}
|
|
45
|
+
return parsed;
|
|
46
|
+
};
|
|
47
|
+
exports.parse = parse;
|
|
48
|
+
/**
|
|
49
|
+
* Parse and expand environment variables from a JSON secrets file.
|
|
50
|
+
*
|
|
51
|
+
* @param src - The raw JSON contents.
|
|
52
|
+
* @param override - Whether file values override existing process.env values.
|
|
53
|
+
* @param processEnv - The object expansion resolves references against.
|
|
54
|
+
* @returns An object containing the parsed and expanded environment variables.
|
|
55
|
+
*/
|
|
56
|
+
const parseJSON = (src, override, processEnv) => {
|
|
57
|
+
// Convert buffer to string
|
|
58
|
+
const parsed = JSON.parse(src.toString());
|
|
59
|
+
if (override) {
|
|
60
|
+
dotenvExpandOverrideFix(parsed);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
dotenv_expand_1.default.expand({ parsed, processEnv });
|
|
64
|
+
}
|
|
65
|
+
return parsed;
|
|
66
|
+
};
|
|
67
|
+
exports.parseJSON = parseJSON;
|
|
68
|
+
/**
|
|
69
|
+
* Configure and expand environment variables from a .env file.
|
|
70
|
+
*
|
|
71
|
+
* @param args - Configuration options passed to the loader.
|
|
72
|
+
* @returns An object containing the parsed and expanded environment variables.
|
|
73
|
+
*/
|
|
74
|
+
const config = (args) => {
|
|
75
|
+
const { parsed: envs } = configHelper(args);
|
|
76
|
+
return { parsed: envs };
|
|
77
|
+
};
|
|
78
|
+
exports.config = config;
|
|
79
|
+
const configHelper = (options) => {
|
|
80
|
+
let optionPaths = [];
|
|
81
|
+
if (options?.path) {
|
|
82
|
+
if (!Array.isArray(options.path)) {
|
|
83
|
+
optionPaths = [options.path];
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
optionPaths = []; // reset default
|
|
87
|
+
for (const filepath of options.path) {
|
|
88
|
+
optionPaths.push(filepath);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Build the parsed data in a temporary object (because we need to return it).
|
|
93
|
+
// Once we have the final parsed data, we will combine it with process.env (or
|
|
94
|
+
// options.processEnv if provided).
|
|
95
|
+
let lastError;
|
|
96
|
+
const parsedAll = {};
|
|
97
|
+
for (const optPath of optionPaths) {
|
|
98
|
+
try {
|
|
99
|
+
let parsed;
|
|
100
|
+
const contents = (0, node_fs_1.readFileSync)(optPath, { encoding: 'utf8' });
|
|
101
|
+
if (optPath?.endsWith('.json')) {
|
|
102
|
+
parsed = (0, exports.parseJSON)(contents, options?.override);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
// Specifying an encoding returns a string instead of a buffer
|
|
106
|
+
parsed = (0, exports.parse)(contents, options?.override);
|
|
107
|
+
}
|
|
108
|
+
dotenv_1.default.populate(parsedAll, parsed, options);
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
lastError = e;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
let processEnv = process.env;
|
|
115
|
+
if (options?.processEnv != null) {
|
|
116
|
+
processEnv = options.processEnv;
|
|
117
|
+
}
|
|
118
|
+
dotenv_1.default.populate(processEnv, parsedAll, options);
|
|
119
|
+
if (lastError) {
|
|
120
|
+
return { parsed: parsedAll, error: lastError };
|
|
121
|
+
}
|
|
122
|
+
return { parsed: parsedAll };
|
|
123
|
+
};
|
package/dist/cjs/envs.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.envs = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const dotenv_checkers_js_1 = require("./dotenv-checkers.js");
|
|
7
|
+
const dotenv_with_expand_js_1 = require("./dotenv-with-expand.js");
|
|
8
|
+
const utils_js_1 = require("./utils.js");
|
|
9
|
+
/**
|
|
10
|
+
* Load environment variables from .env* files and optionally perform linting.
|
|
11
|
+
* Suppress warnings using silent if this file is missing. Dotenv files are
|
|
12
|
+
* merged in precedence order before filling process.env, so `.env.<env>.local`
|
|
13
|
+
* wins over lower-priority dotenv files while inherited runtime variables remain
|
|
14
|
+
* authoritative unless `override` is enabled. Variable expansion is supported in
|
|
15
|
+
* .env files.
|
|
16
|
+
*
|
|
17
|
+
* @param options - Configuration options.
|
|
18
|
+
* @param options.appDirectory - The directory of the app.
|
|
19
|
+
* @param options.secretsPath - The path to an injected secrets file.
|
|
20
|
+
* @param options.lint - Whether to perform linting on the loaded variables.
|
|
21
|
+
* @param options.override - Whether file values override existing process.env values.
|
|
22
|
+
* @returns An object containing the loaded environment variables.
|
|
23
|
+
*/
|
|
24
|
+
const envs = ({ appDirectory = '', lint = true, secretsPath = '', override = false, } = {}) => {
|
|
25
|
+
let absDotenvFiles = [];
|
|
26
|
+
const NODE_ENV = process.env.NODE_ENV;
|
|
27
|
+
const ENV = process.env.ENV;
|
|
28
|
+
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
|
|
29
|
+
const dotenvFiles = [
|
|
30
|
+
'.env',
|
|
31
|
+
// Don't include `.env.local` for `test` environment since normally you
|
|
32
|
+
// expect tests to produce the same results for everyone
|
|
33
|
+
NODE_ENV !== 'test' && '.env.local',
|
|
34
|
+
ENV && `.env.${ENV}`,
|
|
35
|
+
secretsPath,
|
|
36
|
+
ENV && `.env.${ENV}.local`,
|
|
37
|
+
].filter(Boolean);
|
|
38
|
+
if (appDirectory) {
|
|
39
|
+
absDotenvFiles = dotenvFiles.reduce((acc, dotenvFile) => {
|
|
40
|
+
return (0, node_path_1.isAbsolute)(dotenvFile)
|
|
41
|
+
? acc.concat(dotenvFile)
|
|
42
|
+
: acc.concat((0, utils_js_1.resolveApp)(dotenvFile, appDirectory));
|
|
43
|
+
}, []);
|
|
44
|
+
}
|
|
45
|
+
const resolvedEnv = absDotenvFiles.reduce((acc, dotenvFile) => {
|
|
46
|
+
if (!(0, node_fs_1.existsSync)(dotenvFile)) {
|
|
47
|
+
return acc;
|
|
48
|
+
}
|
|
49
|
+
const contents = (0, node_fs_1.readFileSync)(dotenvFile, { encoding: 'utf8' });
|
|
50
|
+
const envs = dotenvFile.endsWith('.json')
|
|
51
|
+
? (0, dotenv_with_expand_js_1.parseJSON)(contents, false, {})
|
|
52
|
+
: (0, dotenv_with_expand_js_1.parse)(contents, false, {});
|
|
53
|
+
if (lint && envs) {
|
|
54
|
+
Object.entries(envs).forEach(([key, value]) => {
|
|
55
|
+
dotenv_checkers_js_1.dotenvCheckers.forEach((checker) => {
|
|
56
|
+
checker(key, value);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return (0, utils_js_1.mergeAssign)(acc, envs);
|
|
61
|
+
}, {});
|
|
62
|
+
return override
|
|
63
|
+
? (0, utils_js_1.mergeAssign)(process.env, resolvedEnv)
|
|
64
|
+
: (0, utils_js_1.mergeDefaults)(process.env, resolvedEnv);
|
|
65
|
+
};
|
|
66
|
+
exports.envs = envs;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./correct-env.js"), exports);
|
|
18
|
+
__exportStar(require("./dotenv-checkers.js"), exports);
|
|
19
|
+
__exportStar(require("./dotenv-fixers.js"), exports);
|
|
20
|
+
__exportStar(require("./dotenv-with-expand.js"), exports);
|
|
21
|
+
__exportStar(require("./envs.js"), exports);
|
|
22
|
+
__exportStar(require("./process-env.js"), exports);
|
|
23
|
+
__exportStar(require("./utils.js"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// Preload entry for `dev` / `start` scripts and any process that must have the
|
|
4
|
+
// dotenv chain folded into `process.env` before a single application module is
|
|
5
|
+
// evaluated. Wire it via `NODE_OPTIONS="--import @cogs/config/preload"` (Node
|
|
6
|
+
// >= 20.6, ESM). Importing this module runs `correctEnv()` and then `envs()` as
|
|
7
|
+
// a side effect.
|
|
8
|
+
const correct_env_js_1 = require("./correct-env.js");
|
|
9
|
+
const envs_js_1 = require("./envs.js");
|
|
10
|
+
(0, correct_env_js_1.correctEnv)();
|
|
11
|
+
(0, envs_js_1.envs)({
|
|
12
|
+
appDirectory: process.cwd(),
|
|
13
|
+
// Guard the concat: an unset SECRETS_PATH must yield '' rather than the
|
|
14
|
+
// literal string 'undefinedsecrets.json'.
|
|
15
|
+
secretsPath: process.env.SECRETS_PATH
|
|
16
|
+
? `${process.env.SECRETS_PATH}secrets.json`
|
|
17
|
+
: '',
|
|
18
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processEnv = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Process environment variables based on specific rules.
|
|
6
|
+
*
|
|
7
|
+
* @param config - The configuration object.
|
|
8
|
+
* @returns An object containing processed environment variables.
|
|
9
|
+
*/
|
|
10
|
+
const processEnv = (config) => {
|
|
11
|
+
// node env should be DEVELOPMENT | PRODUCTION as these are commonly used in
|
|
12
|
+
// node land this variable is used inside webpack
|
|
13
|
+
const nodeEnv = process.env.NODE_ENV;
|
|
14
|
+
// config env is dependent on the env that it's run, this can be anything from
|
|
15
|
+
// stage-prod this allows you to set use different .env environments
|
|
16
|
+
const configEnv = process.env.ENV;
|
|
17
|
+
const envObject = Object.keys(config).reduce((acc, key) => {
|
|
18
|
+
acc[key] = config[key];
|
|
19
|
+
return acc;
|
|
20
|
+
}, {});
|
|
21
|
+
const processEnvObj = Object.keys(process.env).reduce((acc, key) => {
|
|
22
|
+
acc[key] = process.env[key];
|
|
23
|
+
return acc;
|
|
24
|
+
}, {});
|
|
25
|
+
// Don't allow overwriting of NODE_ENV
|
|
26
|
+
envObject.NODE_ENV = nodeEnv;
|
|
27
|
+
// anything from dev, qa, prive and prod
|
|
28
|
+
envObject.ENV = configEnv;
|
|
29
|
+
let mergedEnvVars = Object.assign(envObject, processEnvObj);
|
|
30
|
+
mergedEnvVars = Object.keys(mergedEnvVars).reduce((acc, key) => {
|
|
31
|
+
acc[key] = mergedEnvVars[key];
|
|
32
|
+
return acc;
|
|
33
|
+
}, {});
|
|
34
|
+
return Object.keys(mergedEnvVars).reduce((acc, key) => {
|
|
35
|
+
acc[key] = mergedEnvVars[key];
|
|
36
|
+
return acc;
|
|
37
|
+
}, {});
|
|
38
|
+
};
|
|
39
|
+
exports.processEnv = processEnv;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isEmpty = exports.removeInvalidLeadingChars = exports.resolveApp = exports.mergeAssign = exports.mergeDefaults = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const mergeDefaults = (target, source) => {
|
|
9
|
+
const targetRecord = target;
|
|
10
|
+
if (!source) {
|
|
11
|
+
return target;
|
|
12
|
+
}
|
|
13
|
+
Object.entries(source).forEach(([key, value]) => {
|
|
14
|
+
if (targetRecord[key] === undefined) {
|
|
15
|
+
targetRecord[key] = value;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
exports.mergeDefaults = mergeDefaults;
|
|
21
|
+
const mergeAssign = (target, source) => {
|
|
22
|
+
const targetRecord = target;
|
|
23
|
+
if (!source) {
|
|
24
|
+
return target;
|
|
25
|
+
}
|
|
26
|
+
Object.entries(source).forEach(([key, value]) => {
|
|
27
|
+
targetRecord[key] = value;
|
|
28
|
+
});
|
|
29
|
+
return target;
|
|
30
|
+
};
|
|
31
|
+
exports.mergeAssign = mergeAssign;
|
|
32
|
+
/**
|
|
33
|
+
* Resolve an absolute path by combining the `appDirectory` and `relativePath`.
|
|
34
|
+
*
|
|
35
|
+
* @param relativePath - The relative path to resolve.
|
|
36
|
+
* @param appDirectory - The base directory for the resolution.
|
|
37
|
+
* @returns The resolved absolute path.
|
|
38
|
+
*/
|
|
39
|
+
const resolveApp = (relativePath, appDirectory) => node_path_1.default.resolve(appDirectory, relativePath);
|
|
40
|
+
exports.resolveApp = resolveApp;
|
|
41
|
+
/**
|
|
42
|
+
* Removes invalid leading characters (characters from A to Z and _(underscore)
|
|
43
|
+
* are allowed) from the given string.
|
|
44
|
+
*
|
|
45
|
+
* @param str - The input string.
|
|
46
|
+
* @returns The string with invalid leading characters removed.
|
|
47
|
+
*/
|
|
48
|
+
const removeInvalidLeadingChars = (str) => {
|
|
49
|
+
const chars = str.split('');
|
|
50
|
+
let notFound = true;
|
|
51
|
+
let i = 0;
|
|
52
|
+
while (notFound && i < chars.length) {
|
|
53
|
+
const currentChar = chars[i];
|
|
54
|
+
if (currentChar !== undefined && /[a-z_]/i.test(currentChar)) {
|
|
55
|
+
notFound = false;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
i++;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return str.slice(i);
|
|
62
|
+
};
|
|
63
|
+
exports.removeInvalidLeadingChars = removeInvalidLeadingChars;
|
|
64
|
+
const isEmpty = (str) => str == null || str.length === 0;
|
|
65
|
+
exports.isEmpty = isEmpty;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"correct-env.d.ts","sourceRoot":"","sources":["../src/correct-env.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,GAAI,wDAMxB;IACD,OAAO,CAAC,EAAE,aAAa,GAAG,YAAY,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"correct-env.d.ts","sourceRoot":"","sources":["../src/correct-env.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,GAAI,wDAMxB;IACD,OAAO,CAAC,EAAE,aAAa,GAAG,YAAY,GAAG,MAAM,CAAA;IAC/C,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;IACxB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;CACZ,SA4BL,CAAA"}
|
package/dist/correct-env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"correct-env.js","sourceRoot":"","sources":["../src/correct-env.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,2CAA2C;AAC3C,SAAS,MAAM,CAAC,CAAU;IACxB,OAAO,CAAC,IAAI,IAAI,
|
|
1
|
+
{"version":3,"file":"correct-env.js","sourceRoot":"","sources":["../src/correct-env.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,2CAA2C;AAC3C,SAAS,MAAM,CAAC,CAAU;IACxB,OAAO,CAAC,IAAI,IAAI,CAAA;AAClB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EACzB,OAAO,EACP,QAAQ,EACR,eAAe,EACf,GAAG,EACH,OAAO,MAOL,EAAE,EAAE,EAAE;IACR,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,OAAO,CAAA;IAC5C,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,QAAQ,CAAA;IAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,eAAe,IAAI,IAAI,CAAA;IACrE,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,CAAA;IAEnC,IAAI,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;IACxC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3C,UAAU,GAAG,OAAO,CAAA;IACtB,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QACjB,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,IAAI,CAAA;IAC9B,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QACjB,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI,CAAA;IACxB,CAAC;IAED,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAClB,OAAO,CAAC,GAAG,CAAC,gBAAgB,GAAG,KAAK,CAAA;IACtC,CAAC;IAED,IAAI,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,UAAU,CAAA;IACtC,CAAC;IAED,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;AAC9D,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dotenv-checkers.d.ts","sourceRoot":"","sources":["../src/dotenv-checkers.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,qBAUlE,
|
|
1
|
+
{"version":3,"file":"dotenv-checkers.d.ts","sourceRoot":"","sources":["../src/dotenv-checkers.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,qBAUlE,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,GAAI,KAAK,MAAM,qBASlD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,KAAK,MAAM,qBAO9C,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAAI,MAAM,MAAM,qBAcjD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,GAAI,MAAM,MAAM,qBAKrD,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,GAAI,MAAM,MAAM,qBASrD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,SAtGoB,MAAM,QAAQ,MAAM,wBA6GlE,CAAA"}
|
package/dist/dotenv-checkers.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { removeInvalidLeadingChars } from
|
|
1
|
+
import { removeInvalidLeadingChars } from './utils.js';
|
|
2
2
|
/**
|
|
3
3
|
* Checks if a given key has incorrect delimiters. Delimiters should occur
|
|
4
4
|
* between characters, not as the initial character. This function removes
|
|
@@ -13,7 +13,7 @@ export const incorrectDelimiterChecker = (key, line) => {
|
|
|
13
13
|
// we should remove all invalid leading characters before checking for
|
|
14
14
|
// incorrect delimiters
|
|
15
15
|
const cleanedKey = removeInvalidLeadingChars(key);
|
|
16
|
-
const chars = cleanedKey.trim().split(
|
|
16
|
+
const chars = cleanedKey.trim().split('');
|
|
17
17
|
if (chars.some((char) => !/[a-z0-9_]/i.test(char))) {
|
|
18
18
|
console.log(`warning: '${key}' incorrect delimiter`);
|
|
19
19
|
return true;
|
|
@@ -54,10 +54,10 @@ export const lowercaseKeyChecker = (key) => {
|
|
|
54
54
|
* @returns True if quote characters are found in the value, undefined otherwise.
|
|
55
55
|
*/
|
|
56
56
|
export const quoteCharacterChecker = (line) => {
|
|
57
|
-
if (line.includes(
|
|
57
|
+
if (line.includes('\n') ||
|
|
58
58
|
/[ \t\r\n\f]/.test(line) ||
|
|
59
|
-
line.includes(
|
|
60
|
-
line.includes(
|
|
59
|
+
line.includes('$') ||
|
|
60
|
+
line.includes('#')) {
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
if (line.includes('"') || line.includes("'")) {
|
|
@@ -72,7 +72,7 @@ export const quoteCharacterChecker = (line) => {
|
|
|
72
72
|
* @returns True if trailing whitespace is found in the line, undefined otherwise.
|
|
73
73
|
*/
|
|
74
74
|
export const trailingWhitespaceChecker = (line) => {
|
|
75
|
-
if (line.endsWith(
|
|
75
|
+
if (line.endsWith(' ')) {
|
|
76
76
|
console.log(`warning: '${line}' has a trailing whitespace.`);
|
|
77
77
|
return true;
|
|
78
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dotenv-checkers.js","sourceRoot":"","sources":["../src/dotenv-checkers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"dotenv-checkers.js","sourceRoot":"","sources":["../src/dotenv-checkers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAEtD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,GAAW,EAAE,IAAY,EAAE,EAAE;IACrE,0EAA0E;IAC1E,sEAAsE;IACtE,uBAAuB;IACvB,MAAM,UAAU,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAAA;IACjD,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IACzC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QACnD,OAAO,CAAC,GAAG,CAAC,aAAa,GAAG,uBAAuB,CAAC,CAAA;QACpD,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,GAAW,EAAE,EAAE;IACrD,IAAI,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,OAAM;IACR,CAAC;IAED,OAAO,CAAC,GAAG,CACT,aAAa,GAAG,8FAA8F,CAC/G,CAAA;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,C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,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC7C,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAC7C,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,yBAAyB;IACzB,uBAAuB;IACvB,mBAAmB;IACnB,qBAAqB;IACrB,yBAAyB;IACzB,yBAAyB;CAC1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dotenv-fixers.d.ts","sourceRoot":"","sources":["../src/dotenv-fixers.ts"],"names":[],"mappings":"AAUA;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,aAUhE,
|
|
1
|
+
{"version":3,"file":"dotenv-fixers.d.ts","sourceRoot":"","sources":["../src/dotenv-fixers.ts"],"names":[],"mappings":"AAUA;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,aAUhE,CAAA;AAGD,eAAO,MAAM,qBAAqB,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,aAO9D,CAAA;AAGD,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,aAM1D,CAAA;AAKD,eAAO,MAAM,mBAAmB,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,aAO5D,CAAA;AAGD,eAAO,MAAM,uBAAuB,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,aAMhE,CAAA;AAID,eAAO,MAAM,uBAAuB,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,aAehE,CAAA;AAED,eAAO,MAAM,eAAe,SAvEiB,MAAM,QAAQ,MAAM,gBA2EhE,CAAA;AAED,eAAO,MAAM,gBAAgB,SA3CY,MAAM,QAAQ,MAAM,gBA+C5D,CAAA"}
|
package/dist/dotenv-fixers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { incorrectDelimiterChecker, leadingCharacterChecker, lowercaseKeyChecker, quoteCharacterChecker, trailingWhitespaceChecker, valueWithoutQuotesChecker, } from
|
|
2
|
-
import { removeInvalidLeadingChars } from
|
|
1
|
+
import { incorrectDelimiterChecker, leadingCharacterChecker, lowercaseKeyChecker, quoteCharacterChecker, trailingWhitespaceChecker, valueWithoutQuotesChecker, } from './dotenv-checkers.js';
|
|
2
|
+
import { removeInvalidLeadingChars } from './utils.js';
|
|
3
3
|
/**
|
|
4
4
|
* Fixes incorrect delimiters by replacing non-alphanumeric characters with
|
|
5
5
|
* underscores ('_'). Also ensures that an underscore separates words in the key.
|
|
@@ -14,7 +14,7 @@ export const incorrectDelimiterFixer = (key, line) => {
|
|
|
14
14
|
}
|
|
15
15
|
let cleanedKey = removeInvalidLeadingChars(key);
|
|
16
16
|
const startIdx = key.length - cleanedKey.length;
|
|
17
|
-
cleanedKey = key.slice(startIdx).replace(/[^a-z0-9]/gi,
|
|
17
|
+
cleanedKey = key.slice(startIdx).replace(/[^a-z0-9]/gi, '_');
|
|
18
18
|
return [`${key.substring(0, startIdx)}${cleanedKey}`, line];
|
|
19
19
|
};
|
|
20
20
|
// Fixes key that starts with an unallowed character.
|
|
@@ -39,7 +39,7 @@ export const quoteCharacterFixer = (key, line) => {
|
|
|
39
39
|
if (!quoteCharacterChecker(line)) {
|
|
40
40
|
return [key, line];
|
|
41
41
|
}
|
|
42
|
-
const pureVal = line.replace(/"|'/g,
|
|
42
|
+
const pureVal = line.replace(/"|'/g, '');
|
|
43
43
|
return [key, pureVal];
|
|
44
44
|
};
|
|
45
45
|
// Fixes trailing whitespace.
|
|
@@ -55,7 +55,7 @@ export const valueWithoutQuotesFixer = (key, line) => {
|
|
|
55
55
|
if (!valueWithoutQuotesChecker(line)) {
|
|
56
56
|
return [key, line];
|
|
57
57
|
}
|
|
58
|
-
let pureVal =
|
|
58
|
+
let pureVal = '';
|
|
59
59
|
if (line.includes("'")) {
|
|
60
60
|
pureVal = `"${line}"`;
|
|
61
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dotenv-fixers.js","sourceRoot":"","sources":["../src/dotenv-fixers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"dotenv-fixers.js","sourceRoot":"","sources":["../src/dotenv-fixers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAEtD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,GAAW,EAAE,IAAY,EAAE,EAAE;IACnE,IAAI,CAAC,yBAAyB,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;QAC1C,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACpB,CAAC;IAED,IAAI,UAAU,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAAA;IAC/C,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAA;IAE/C,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAAA;IAC5D,OAAO,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,UAAU,EAAE,EAAE,IAAI,CAAC,CAAA;AAC7D,CAAC,CAAA;AAED,qDAAqD;AACrD,MAAM,CAAC,MAAM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C9B,CAAC,CAAA;AAED,2EAA2E;AAC3E,0DAA0D;AAC1D,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,GAAW,EAAE,IAAY,EAAE,EAAE;IACnE,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACpB,CAAC;IAED,IAAI,OAAO,GAAG,EAAE,CAAA;IAChB,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,GAAG,IAAI,IAAI,GAAG,CAAA;IACvB,CAAC;SAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9B,OAAO,GAAG,IAAI,IAAI,GAAG,CAAA;IACvB,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,IAAI,IAAI,GAAG,CAAA;IACvB,CAAC;IAED,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;AACvB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,uBAAuB;IACvB,qBAAqB;IACrB,iBAAiB;CAClB,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,mBAAmB;IACnB,uBAAuB;IACvB,uBAAuB;CACxB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dotenv-with-expand.d.ts","sourceRoot":"","sources":["../src/dotenv-with-expand.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"dotenv-with-expand.d.ts","sourceRoot":"","sources":["../src/dotenv-with-expand.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAIpE,MAAM,WAAW,aAAa;IAC5B;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAExB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,mBAAmB,CAAA;CACjC;AA0BD;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,GAChB,KAAK,MAAM,GAAG,MAAM,EACpB,WAAW,OAAO,EAClB,aAAa,mBAAmB,KAC/B,iBAUF,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,GACpB,KAAK,MAAM,GAAG,MAAM,EACpB,WAAW,OAAO,EAClB,aAAa,mBAAmB,KAC/B,iBAWF,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GACjB,OAAO,aAAa,KACnB;IACD,MAAM,EAAE,iBAAiB,GAAG,SAAS,CAAA;CAItC,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { readFileSync } from
|
|
2
|
-
import dotenv from
|
|
3
|
-
import dotenvExpand from
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import dotenv from 'dotenv';
|
|
3
|
+
import dotenvExpand from 'dotenv-expand';
|
|
4
4
|
const dotenvExpandOverrideFix = (parsed) => {
|
|
5
5
|
const obj = {};
|
|
6
6
|
dotenvExpand.expand({ parsed, processEnv: obj });
|
|
@@ -88,8 +88,8 @@ const configHelper = (options) => {
|
|
|
88
88
|
for (const optPath of optionPaths) {
|
|
89
89
|
try {
|
|
90
90
|
let parsed;
|
|
91
|
-
const contents = readFileSync(optPath, { encoding:
|
|
92
|
-
if (optPath?.endsWith(
|
|
91
|
+
const contents = readFileSync(optPath, { encoding: 'utf8' });
|
|
92
|
+
if (optPath?.endsWith('.json')) {
|
|
93
93
|
parsed = parseJSON(contents, options?.override);
|
|
94
94
|
}
|
|
95
95
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dotenv-with-expand.js","sourceRoot":"","sources":["../src/dotenv-with-expand.ts"],"names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AE,SAAS,EAAE,OAAO,CAAC,CAAA;IAE/C,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAA;IAChD,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAA;AAC9B,CAAC,CAAA"}
|
package/dist/envs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envs.d.ts","sourceRoot":"","sources":["../src/envs.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,IAAI,GAAI,iDAKlB;IACD,YAAY,CAAC,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"envs.d.ts","sourceRoot":"","sources":["../src/envs.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,IAAI,GAAI,iDAKlB;IACD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;CACd,KAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CAmD5C,CAAA"}
|
package/dist/envs.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from
|
|
2
|
-
import { isAbsolute } from
|
|
3
|
-
import { dotenvCheckers } from
|
|
4
|
-
import { parse, parseJSON } from
|
|
5
|
-
import { mergeAssign, mergeDefaults, resolveApp } from
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute } from 'node:path';
|
|
3
|
+
import { dotenvCheckers } from './dotenv-checkers.js';
|
|
4
|
+
import { parse, parseJSON } from './dotenv-with-expand.js';
|
|
5
|
+
import { mergeAssign, mergeDefaults, resolveApp } from './utils.js';
|
|
6
6
|
/**
|
|
7
7
|
* Load environment variables from .env* files and optionally perform linting.
|
|
8
8
|
* Suppress warnings using silent if this file is missing. Dotenv files are
|
|
@@ -18,16 +18,16 @@ import { mergeAssign, mergeDefaults, resolveApp } from "./utils.js";
|
|
|
18
18
|
* @param options.override - Whether file values override existing process.env values.
|
|
19
19
|
* @returns An object containing the loaded environment variables.
|
|
20
20
|
*/
|
|
21
|
-
export const envs = ({ appDirectory =
|
|
21
|
+
export const envs = ({ appDirectory = '', lint = true, secretsPath = '', override = false, } = {}) => {
|
|
22
22
|
let absDotenvFiles = [];
|
|
23
23
|
const NODE_ENV = process.env.NODE_ENV;
|
|
24
24
|
const ENV = process.env.ENV;
|
|
25
25
|
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
|
|
26
26
|
const dotenvFiles = [
|
|
27
|
-
|
|
27
|
+
'.env',
|
|
28
28
|
// Don't include `.env.local` for `test` environment since normally you
|
|
29
29
|
// expect tests to produce the same results for everyone
|
|
30
|
-
NODE_ENV !==
|
|
30
|
+
NODE_ENV !== 'test' && '.env.local',
|
|
31
31
|
ENV && `.env.${ENV}`,
|
|
32
32
|
secretsPath,
|
|
33
33
|
ENV && `.env.${ENV}.local`,
|
|
@@ -43,8 +43,8 @@ export const envs = ({ appDirectory = "", lint = true, secretsPath = "", overrid
|
|
|
43
43
|
if (!existsSync(dotenvFile)) {
|
|
44
44
|
return acc;
|
|
45
45
|
}
|
|
46
|
-
const contents = readFileSync(dotenvFile, { encoding:
|
|
47
|
-
const envs = dotenvFile.endsWith(
|
|
46
|
+
const contents = readFileSync(dotenvFile, { encoding: 'utf8' });
|
|
47
|
+
const envs = dotenvFile.endsWith('.json')
|
|
48
48
|
? parseJSON(contents, false, {})
|
|
49
49
|
: parse(contents, false, {});
|
|
50
50
|
if (lint && envs) {
|
package/dist/envs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envs.js","sourceRoot":"","sources":["../src/envs.ts"],"names":[],"mappings":"AAAA,OAAO,EA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
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
1
|
+
export * from './correct-env.js';
|
|
2
|
+
export * from './dotenv-checkers.js';
|
|
3
|
+
export * from './dotenv-fixers.js';
|
|
4
|
+
export * from './dotenv-with-expand.js';
|
|
5
|
+
export * from './envs.js';
|
|
6
|
+
export * from './process-env.js';
|
|
7
|
+
export * from './utils.js';
|
|
8
8
|
//# 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":"AAAA,cAAc,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,yBAAyB,CAAA;AACvC,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
1
|
+
export * from './correct-env.js';
|
|
2
|
+
export * from './dotenv-checkers.js';
|
|
3
|
+
export * from './dotenv-fixers.js';
|
|
4
|
+
export * from './dotenv-with-expand.js';
|
|
5
|
+
export * from './envs.js';
|
|
6
|
+
export * from './process-env.js';
|
|
7
|
+
export * from './utils.js';
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,yBAAyB,CAAA;AACvC,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
|
package/dist/preload.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// evaluated. Wire it via `NODE_OPTIONS="--import @cogs/config/preload"` (Node
|
|
4
4
|
// >= 20.6, ESM). Importing this module runs `correctEnv()` and then `envs()` as
|
|
5
5
|
// a side effect.
|
|
6
|
-
import { correctEnv } from
|
|
7
|
-
import { envs } from
|
|
6
|
+
import { correctEnv } from './correct-env.js';
|
|
7
|
+
import { envs } from './envs.js';
|
|
8
8
|
correctEnv();
|
|
9
9
|
envs({
|
|
10
10
|
appDirectory: process.cwd(),
|
|
@@ -12,6 +12,6 @@ envs({
|
|
|
12
12
|
// literal string 'undefinedsecrets.json'.
|
|
13
13
|
secretsPath: process.env.SECRETS_PATH
|
|
14
14
|
? `${process.env.SECRETS_PATH}secrets.json`
|
|
15
|
-
:
|
|
15
|
+
: '',
|
|
16
16
|
});
|
|
17
17
|
//# sourceMappingURL=preload.js.map
|
package/dist/preload.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preload.js","sourceRoot":"","sources":["../src/preload.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,+EAA+E;AAC/E,8EAA8E;AAC9E,gFAAgF;AAChF,iBAAiB;AACjB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"preload.js","sourceRoot":"","sources":["../src/preload.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,+EAA+E;AAC/E,8EAA8E;AAC9E,gFAAgF;AAChF,iBAAiB;AACjB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,UAAU,EAAE,CAAA;AAEZ,IAAI,CAAC;IACH,YAAY,EAAE,OAAO,CAAC,GAAG,EAAE;IAC3B,wEAAwE;IACxE,0CAA0C;IAC1C,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;QACnC,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,cAAc;QAC3C,CAAC,CAAC,EAAE;CACP,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-env.d.ts","sourceRoot":"","sources":["../src/process-env.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ;IACjC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"process-env.d.ts","sourceRoot":"","sources":["../src/process-env.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ;IACjC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CACnC,KAAG;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CA6CvC,CAAA"}
|
package/dist/process-env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-env.js","sourceRoot":"","sources":["../src/process-env.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAE1B,EAA0C,EAAE;IAC3C,4EAA4E;IAC5E,iDAAiD;IACjD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"process-env.js","sourceRoot":"","sources":["../src/process-env.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,M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,MAAM,CACtC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACX,GAAG,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;QAC7B,OAAO,GAAG,CAAA;IACZ,CAAC,EACD,EAA4C,CAC7C,CAAA;AACH,CAAC,CAAA"}
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7D,QAAQ,CAAC,EACT,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC/B,CAcF,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7D,QAAQ,CAAC,EACT,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC/B,CAcF,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,QAAQ,CAAC,EACT,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC/B,CAYF,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GACrB,cAAc,MAAM,EACpB,cAAc,MAAM,KACnB,MAAkD,CAAA;AAErD;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,GAAI,KAAK,MAAM,KAAG,MAavD,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,OACxB,CAAA"}
|
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import path from
|
|
1
|
+
import path from 'node:path';
|
|
2
2
|
export const mergeDefaults = (target, source) => {
|
|
3
3
|
const targetRecord = target;
|
|
4
4
|
if (!source) {
|
|
@@ -37,7 +37,7 @@ export const resolveApp = (relativePath, appDirectory) => path.resolve(appDirect
|
|
|
37
37
|
* @returns The string with invalid leading characters removed.
|
|
38
38
|
*/
|
|
39
39
|
export const removeInvalidLeadingChars = (str) => {
|
|
40
|
-
const chars = str.split(
|
|
40
|
+
const chars = str.split('');
|
|
41
41
|
let notFound = true;
|
|
42
42
|
let i = 0;
|
|
43
43
|
while (notFound && i < chars.length) {
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,MAAS,EACT,MAAgC,EAC7B,EAAE;IACL,MAAM,YAAY,GAAG,MAAiC,CAAA;IAEtD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,MAAM,CAAA;IACf,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC9C,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;YACpC,YAAY,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QAC3B,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,MAAS,EACT,MAAgC,EAC7B,EAAE;IACL,MAAM,YAAY,GAAG,MAAiC,CAAA;IAEtD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,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
|
-
"description": "Framework-agnostic layered-dotenv loader — resolves the canonical .env file chain, expands ${VAR} references, and folds values into process.env with deploy-injected variables staying authoritative",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Framework-agnostic layered-dotenv loader — resolves the canonical .env file chain, expands ${VAR} references, and folds values into process.env with deploy-injected variables staying authoritative. Dual ESM+CJS so it works from an ESM --import preload or a CJS --require hook (dd-trace and other one-offs)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -9,22 +9,30 @@
|
|
|
9
9
|
"directory": "packages/config"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
|
-
"main": "./dist/index.js",
|
|
12
|
+
"main": "./dist/cjs/index.js",
|
|
13
|
+
"module": "./dist/index.js",
|
|
13
14
|
"types": "./dist/index.d.ts",
|
|
14
15
|
"exports": {
|
|
15
16
|
".": {
|
|
16
17
|
"types": "./dist/index.d.ts",
|
|
17
|
-
"import": "./dist/index.js"
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"require": "./dist/cjs/index.js"
|
|
18
20
|
},
|
|
19
21
|
"./preload": {
|
|
20
22
|
"types": "./dist/preload.d.ts",
|
|
21
|
-
"import": "./dist/preload.js"
|
|
23
|
+
"import": "./dist/preload.js",
|
|
24
|
+
"require": "./dist/cjs/preload.js"
|
|
25
|
+
},
|
|
26
|
+
"./register": {
|
|
27
|
+
"require": "./dist/cjs/preload.js",
|
|
28
|
+
"default": "./dist/cjs/preload.js"
|
|
22
29
|
},
|
|
23
30
|
"./package.json": "./package.json"
|
|
24
31
|
},
|
|
25
32
|
"files": [
|
|
26
33
|
"dist",
|
|
27
|
-
"!dist/tsconfig.tsbuildinfo"
|
|
34
|
+
"!dist/tsconfig.tsbuildinfo",
|
|
35
|
+
"!dist/cjs/tsconfig.tsbuildinfo"
|
|
28
36
|
],
|
|
29
37
|
"publishConfig": {
|
|
30
38
|
"access": "public"
|
|
@@ -37,7 +45,7 @@
|
|
|
37
45
|
"vitest": "^3.0.0"
|
|
38
46
|
},
|
|
39
47
|
"scripts": {
|
|
40
|
-
"build": "tsc -p tsconfig.json",
|
|
48
|
+
"build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node ./scripts/postbuild-cjs.mjs",
|
|
41
49
|
"lint": "biome check .",
|
|
42
50
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
43
51
|
"test": "vitest run"
|