@karmaniverous/get-dotenv 3.1.19 → 4.0.0-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 +55 -190
- package/dist/getdotenv.cli.mjs +26495 -0
- package/dist/index.cjs +26499 -0
- package/dist/index.d.cts +234 -0
- package/dist/index.d.mts +234 -0
- package/dist/index.d.ts +234 -0
- package/dist/index.mjs +26493 -0
- package/package.json +103 -64
- package/bin/getdotenv/index.js +0 -8
- package/dist/default/lib/dotenvExpand.js +0 -67
- package/dist/default/lib/getDotenv.js +0 -228
- package/dist/default/lib/getDotenvCli.js +0 -202
- package/dist/default/lib/index.js +0 -38
- package/dist/default/lib/options.js +0 -45
- package/dist/default/lib/readDotenv.js +0 -47
- package/dist/package.json +0 -3
- package/getdotenv.config.json +0 -24
- package/lib/dotenvExpand.js +0 -63
- package/lib/getDotenv.js +0 -280
- package/lib/getDotenvCli.js +0 -475
- package/lib/index.js +0 -3
- package/lib/options.js +0 -80
- package/lib/readDotenv.js +0 -39
package/package.json
CHANGED
|
@@ -1,100 +1,139 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"author": "Jason Williscroft",
|
|
3
3
|
"bin": {
|
|
4
|
-
"getdotenv": "
|
|
5
|
-
},
|
|
6
|
-
"version": "3.1.19",
|
|
7
|
-
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
},
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "https://github.com/karmaniverous/get-dotenv"
|
|
4
|
+
"getdotenv": "./dist/getdotenv.cli.mjs"
|
|
13
5
|
},
|
|
14
|
-
"author": "Jason G. Williscroft",
|
|
15
6
|
"bugs": {
|
|
16
7
|
"url": "https://github.com/karmaniverous/get-dotenv/issues"
|
|
17
8
|
},
|
|
18
|
-
"description": "Process dotenv files in an arbitrary location & optionally populate environment variables.",
|
|
19
|
-
"homepage": "https://github.com/karmaniverous/get-dotenv#readme",
|
|
20
|
-
"keywords": [
|
|
21
|
-
"dotenv-management",
|
|
22
|
-
"environment-variables",
|
|
23
|
-
"configuration",
|
|
24
|
-
"devops",
|
|
25
|
-
"developer-tools",
|
|
26
|
-
"json",
|
|
27
|
-
"yaml",
|
|
28
|
-
"cli",
|
|
29
|
-
"async-programming",
|
|
30
|
-
"nodejs",
|
|
31
|
-
"javascript",
|
|
32
|
-
"development-environment",
|
|
33
|
-
"software-development",
|
|
34
|
-
"programming",
|
|
35
|
-
"sync-programming"
|
|
36
|
-
],
|
|
37
|
-
"license": "BSD-3-Clause",
|
|
38
9
|
"dependencies": {
|
|
39
10
|
"commander": "^12.0.0",
|
|
40
11
|
"dotenv": "^16.4.5",
|
|
41
12
|
"execa": "^8.0.1",
|
|
42
13
|
"fs-extra": "^11.2.0",
|
|
43
|
-
"lodash
|
|
44
|
-
"lodash.pick": "^4.4.0",
|
|
45
|
-
"lodash.pickby": "^4.6.0",
|
|
14
|
+
"lodash": "^4.17.21",
|
|
46
15
|
"nanoid": "^5.0.6",
|
|
47
|
-
"pkg-dir": "^8.0.0"
|
|
16
|
+
"pkg-dir": "^8.0.0",
|
|
17
|
+
"tslog": "^4.9.2"
|
|
48
18
|
},
|
|
19
|
+
"description": "Process dotenv files in an arbitrary location & optionally populate environment variables.",
|
|
49
20
|
"devDependencies": {
|
|
50
|
-
"@
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"@
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
21
|
+
"@commander-js/extra-typings": "^12.0.1",
|
|
22
|
+
"@eslint/js": "^9.1.1",
|
|
23
|
+
"@rollup/plugin-alias": "^5.1.0",
|
|
24
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
25
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
26
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
27
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
28
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
29
|
+
"@types/chai": "^4.3.14",
|
|
30
|
+
"@types/eslint__js": "^8.42.3",
|
|
31
|
+
"@types/eslint-config-prettier": "^6.11.3",
|
|
32
|
+
"@types/eslint-plugin-mocha": "^10.4.0",
|
|
33
|
+
"@types/fs-extra": "^11.0.4",
|
|
34
|
+
"@types/lodash": "^4.17.0",
|
|
35
|
+
"@types/mocha": "^10.0.6",
|
|
36
|
+
"@types/node": "^20.12.7",
|
|
37
|
+
"auto-changelog": "^2.4.0",
|
|
56
38
|
"chai": "^5.1.0",
|
|
57
|
-
"
|
|
39
|
+
"cross-env": "^7.0.3",
|
|
58
40
|
"eslint": "^8.57.0",
|
|
59
|
-
"eslint-
|
|
60
|
-
"eslint-plugin-
|
|
61
|
-
"
|
|
41
|
+
"eslint-config-prettier": "^9.1.0",
|
|
42
|
+
"eslint-plugin-mocha": "^10.4.3",
|
|
43
|
+
"eslint-plugin-simple-import-sort": "^12.1.0",
|
|
44
|
+
"eslint-plugin-tsdoc": "^0.2.17",
|
|
45
|
+
"fs-extra": "^11.2.0",
|
|
46
|
+
"jsdom-global": "^3.0.2",
|
|
47
|
+
"lefthook": "^1.6.10",
|
|
62
48
|
"mocha": "^10.4.0",
|
|
63
|
-
"
|
|
49
|
+
"nyc": "^15.1.0",
|
|
50
|
+
"prettier": "^3.2.5",
|
|
51
|
+
"release-it": "^17.2.0",
|
|
52
|
+
"rimraf": "^5.0.5",
|
|
53
|
+
"rollup": "^4.16.4",
|
|
54
|
+
"rollup-plugin-dts": "^6.1.0",
|
|
55
|
+
"source-map-support": "^0.5.21",
|
|
56
|
+
"ts-node": "^10.9.2",
|
|
57
|
+
"tslib": "^2.6.2",
|
|
58
|
+
"typescript": "^5.4.5",
|
|
59
|
+
"typescript-eslint": "^7.7.1"
|
|
64
60
|
},
|
|
65
61
|
"exports": {
|
|
66
62
|
".": {
|
|
67
|
-
"import":
|
|
68
|
-
|
|
63
|
+
"import": {
|
|
64
|
+
"default": "./dist/index.mjs",
|
|
65
|
+
"types": "./dist/index.d.mts"
|
|
66
|
+
},
|
|
67
|
+
"require": {
|
|
68
|
+
"default": "./dist/index.cjs",
|
|
69
|
+
"types": "./dist/index.d.cts"
|
|
70
|
+
}
|
|
69
71
|
}
|
|
70
72
|
},
|
|
73
|
+
"files": [
|
|
74
|
+
"dist"
|
|
75
|
+
],
|
|
76
|
+
"homepage": "https://github.com/karmaniverous/get-dotenv#readme",
|
|
77
|
+
"keywords": [
|
|
78
|
+
"async-programming",
|
|
79
|
+
"cli",
|
|
80
|
+
"configuration",
|
|
81
|
+
"developer-tools",
|
|
82
|
+
"development-environment",
|
|
83
|
+
"devops",
|
|
84
|
+
"dotenv-management",
|
|
85
|
+
"environment-variables",
|
|
86
|
+
"json",
|
|
87
|
+
"nodejs",
|
|
88
|
+
"programming",
|
|
89
|
+
"software-development",
|
|
90
|
+
"sync-programming",
|
|
91
|
+
"typescript",
|
|
92
|
+
"yaml"
|
|
93
|
+
],
|
|
94
|
+
"license": "BSD-3-Clause",
|
|
71
95
|
"main": "./lib/index.js",
|
|
72
|
-
"
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
"./node_modules/**"
|
|
76
|
-
],
|
|
77
|
-
"require": [
|
|
78
|
-
"@babel/register"
|
|
79
|
-
],
|
|
80
|
-
"spec": "./**/*.test.!(*.*)"
|
|
96
|
+
"name": "@karmaniverous/get-dotenv",
|
|
97
|
+
"publishConfig": {
|
|
98
|
+
"access": "public"
|
|
81
99
|
},
|
|
82
100
|
"release-it": {
|
|
101
|
+
"git": {
|
|
102
|
+
"changelog": "npx auto-changelog --stdout --commit-limit false -u --template https://raw.githubusercontent.com/release-it/release-it/main/templates/changelog-compact.hbs",
|
|
103
|
+
"commitMessage": "chore: release v${version}",
|
|
104
|
+
"requireBranch": "main"
|
|
105
|
+
},
|
|
83
106
|
"github": {
|
|
84
107
|
"release": true
|
|
85
108
|
},
|
|
109
|
+
"hooks": {
|
|
110
|
+
"after:init": [
|
|
111
|
+
"npm run lint",
|
|
112
|
+
"npm run test",
|
|
113
|
+
"npm run build"
|
|
114
|
+
],
|
|
115
|
+
"after:release": [
|
|
116
|
+
"git switch -c release/${version}",
|
|
117
|
+
"git push -u origin release/${version}",
|
|
118
|
+
"git switch main"
|
|
119
|
+
]
|
|
120
|
+
},
|
|
86
121
|
"npm": {
|
|
87
122
|
"publish": true
|
|
88
123
|
}
|
|
89
124
|
},
|
|
125
|
+
"repository": {
|
|
126
|
+
"type": "git",
|
|
127
|
+
"url": "https://github.com/karmaniverous/get-dotenv"
|
|
128
|
+
},
|
|
90
129
|
"scripts": {
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"lint": "eslint lib/** bin/**",
|
|
95
|
-
"prerelease": "npm run lint && npm run test && npm run build && npm run doc",
|
|
130
|
+
"build": "rimraf dist && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
|
|
131
|
+
"lint": "eslint src/** && prettier -c src",
|
|
132
|
+
"lint:fix": "eslint --fix src/** && prettier --write src",
|
|
96
133
|
"release": "release-it",
|
|
97
|
-
"test": "mocha"
|
|
134
|
+
"test": "cross-env LOG_LEVEL=debug nyc mocha"
|
|
98
135
|
},
|
|
99
|
-
"type": "module"
|
|
136
|
+
"type": "module",
|
|
137
|
+
"types": "dist/index.d.ts",
|
|
138
|
+
"version": "4.0.0-0"
|
|
100
139
|
}
|
package/bin/getdotenv/index.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.dotenvExpandAll = exports.dotenvExpand = void 0;
|
|
7
|
-
// like String.prototype.search but returns the last index
|
|
8
|
-
const _searchLast = (str, rgx) => {
|
|
9
|
-
const matches = Array.from(str.matchAll(rgx));
|
|
10
|
-
return matches.length > 0 ? matches.slice(-1)[0].index : -1;
|
|
11
|
-
};
|
|
12
|
-
const _interpolate = (envValue, ref) => {
|
|
13
|
-
// find the last unescaped dollar sign in the
|
|
14
|
-
// value so that we can evaluate it
|
|
15
|
-
const lastUnescapedDollarSignIndex = _searchLast(envValue, /(?!(?<=\\))\$/g);
|
|
16
|
-
|
|
17
|
-
// If we couldn't match any unescaped dollar sign
|
|
18
|
-
// let's return the string as is
|
|
19
|
-
if (lastUnescapedDollarSignIndex === -1) return envValue;
|
|
20
|
-
|
|
21
|
-
// This is the right-most group of variables in the string
|
|
22
|
-
const rightMostGroup = envValue.slice(lastUnescapedDollarSignIndex);
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* This finds the inner most variable/group divided
|
|
26
|
-
* by variable name and default value (if present)
|
|
27
|
-
* (
|
|
28
|
-
* (?!(?<=\\))\$ // only match dollar signs that are not escaped
|
|
29
|
-
* {? // optional opening curly brace
|
|
30
|
-
* ([\w]+) // match the variable name
|
|
31
|
-
* (?::-([^}\\]*))? // match an optional default value
|
|
32
|
-
* }? // optional closing curly brace
|
|
33
|
-
* )
|
|
34
|
-
*/
|
|
35
|
-
const matchGroup = /((?!(?<=\\))\${?([\w]+)(?::-([^}\\]*))?}?)/;
|
|
36
|
-
const match = rightMostGroup.match(matchGroup);
|
|
37
|
-
if (match != null) {
|
|
38
|
-
const [, group, variableName, defaultValue] = match;
|
|
39
|
-
return _interpolate(envValue.replace(group, ref[variableName] || defaultValue || ''), ref);
|
|
40
|
-
}
|
|
41
|
-
return envValue;
|
|
42
|
-
};
|
|
43
|
-
const _resolveEscapeSequences = value => {
|
|
44
|
-
return value.replace(/\\\$/g, '$');
|
|
45
|
-
};
|
|
46
|
-
const dotenvExpand = function (value) {
|
|
47
|
-
let ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : process.env;
|
|
48
|
-
if (!value || value === 'undefined') return;
|
|
49
|
-
const result = _resolveEscapeSequences(_interpolate(value, ref));
|
|
50
|
-
return result.length ? result : undefined;
|
|
51
|
-
};
|
|
52
|
-
exports.dotenvExpand = dotenvExpand;
|
|
53
|
-
const dotenvExpandAll = _ref => {
|
|
54
|
-
let {
|
|
55
|
-
vars = {},
|
|
56
|
-
progressive = false,
|
|
57
|
-
ref = process.env
|
|
58
|
-
} = _ref;
|
|
59
|
-
return Object.keys(vars).reduce((acc, key) => {
|
|
60
|
-
acc[key] = dotenvExpand(vars[key], {
|
|
61
|
-
...ref,
|
|
62
|
-
...(progressive ? acc : {})
|
|
63
|
-
});
|
|
64
|
-
return acc;
|
|
65
|
-
}, {});
|
|
66
|
-
};
|
|
67
|
-
exports.dotenvExpandAll = dotenvExpandAll;
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getDotenvSync = exports.getDotenv = void 0;
|
|
7
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
8
|
-
var _lodash = _interopRequireDefault(require("lodash.pickby"));
|
|
9
|
-
var _path = _interopRequireDefault(require("path"));
|
|
10
|
-
var _nanoid = require("nanoid");
|
|
11
|
-
var _dotenvExpand = require("./dotenvExpand.js");
|
|
12
|
-
var _options = require("./options.js");
|
|
13
|
-
var _readDotenv = require("./readDotenv.js");
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
// npm imports
|
|
16
|
-
|
|
17
|
-
// lib imports
|
|
18
|
-
|
|
19
|
-
const pruneVars = (getdotenvDefaultOptions, options) => (0, _lodash.default)({
|
|
20
|
-
...(getdotenvDefaultOptions.vars ?? {}),
|
|
21
|
-
...(options.vars ?? {})
|
|
22
|
-
}, v => v?.length);
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* get-dotenv options type
|
|
26
|
-
*
|
|
27
|
-
* @typedef {Object} GetDotenvOptions
|
|
28
|
-
* @property {string} [defaultEnv] - default target environment
|
|
29
|
-
* @property {string} [dotenvToken] - token indicating a dotenv file
|
|
30
|
-
* @property {string} [dynamicPath] - path to file exporting an object keyed to dynamic variable functions
|
|
31
|
-
* @property {string} [env] - target environment
|
|
32
|
-
* @property {bool} [excludeDynamic] - exclude dynamic variables
|
|
33
|
-
* @property {bool} [excludeEnv] - exclude environment-specific variables
|
|
34
|
-
* @property {bool} [excludeGlobal] - exclude global & dynamic variables
|
|
35
|
-
* @property {bool} [excludePrivate] - exclude private variables
|
|
36
|
-
* @property {bool} [excludePublic] - exclude public variables
|
|
37
|
-
* @property {bool} [loadProcess] - load dotenv to process.env
|
|
38
|
-
* @property {bool} [log] - log result to logger
|
|
39
|
-
* @property {function} [logger] - logger object (defaults to console)
|
|
40
|
-
* @property {string} [outputPath] - if populated, writes consolidated .env file to this path (follows {@link https://github.com/motdotla/dotenv-expand/blob/master/tests/.env dotenv-expand rules})
|
|
41
|
-
* @property {string[]} [paths] - array of input directory paths
|
|
42
|
-
* @property {string} [privateToken] - token indicating private variables
|
|
43
|
-
* @property {object} [vars] - explicit variables to include
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Asynchronously process dotenv files of the form .env[.<ENV>][.<PRIVATE_TOKEN>]
|
|
48
|
-
*
|
|
49
|
-
* @async
|
|
50
|
-
* @function getDotenv
|
|
51
|
-
*
|
|
52
|
-
* @param {GetDotenvOptions} [options] - options object
|
|
53
|
-
*
|
|
54
|
-
* @returns {Promise<object>} The combined parsed dotenv object.
|
|
55
|
-
*/
|
|
56
|
-
const getDotenv = async function () {
|
|
57
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
58
|
-
// Apply defaults.
|
|
59
|
-
let {
|
|
60
|
-
defaultEnv,
|
|
61
|
-
dotenvToken,
|
|
62
|
-
dynamicPath,
|
|
63
|
-
env,
|
|
64
|
-
excludeDynamic,
|
|
65
|
-
excludeEnv,
|
|
66
|
-
excludeGlobal,
|
|
67
|
-
excludePrivate,
|
|
68
|
-
excludePublic,
|
|
69
|
-
loadProcess,
|
|
70
|
-
log,
|
|
71
|
-
logger = console,
|
|
72
|
-
outputPath,
|
|
73
|
-
paths,
|
|
74
|
-
privateToken
|
|
75
|
-
} = {
|
|
76
|
-
..._options.getdotenvDefaultOptions,
|
|
77
|
-
...options
|
|
78
|
-
};
|
|
79
|
-
const vars = pruneVars(_options.getdotenvDefaultOptions, options);
|
|
80
|
-
|
|
81
|
-
// Read .env files.
|
|
82
|
-
const loaded = await paths.reduce(async (e, p) => {
|
|
83
|
-
let publicGlobal = excludePublic || excludeGlobal ? {} : (0, _readDotenv.readDotenv)(_path.default.resolve(p, dotenvToken));
|
|
84
|
-
let publicEnv = excludePublic || excludeEnv ? {} : (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${env ?? defaultEnv}`));
|
|
85
|
-
let privateGlobal = excludePrivate || excludeGlobal ? {} : (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${privateToken}`));
|
|
86
|
-
let privateEnv = excludePrivate || excludeEnv ? {} : (0, _readDotenv.readDotenv)(_path.default.resolve(p, `${dotenvToken}.${env ?? defaultEnv}.${privateToken}`));
|
|
87
|
-
[e, publicGlobal, publicEnv, privateGlobal, privateEnv] = await Promise.all([e, publicGlobal, publicEnv, privateGlobal, privateEnv]);
|
|
88
|
-
return {
|
|
89
|
-
...e,
|
|
90
|
-
...publicGlobal,
|
|
91
|
-
...publicEnv,
|
|
92
|
-
...privateGlobal,
|
|
93
|
-
...privateEnv
|
|
94
|
-
};
|
|
95
|
-
}, {});
|
|
96
|
-
const outputKey = (0, _nanoid.nanoid)();
|
|
97
|
-
const dotenv = (0, _dotenvExpand.dotenvExpandAll)({
|
|
98
|
-
vars: {
|
|
99
|
-
...loaded,
|
|
100
|
-
...vars,
|
|
101
|
-
...(outputPath ? {
|
|
102
|
-
[outputKey]: outputPath
|
|
103
|
-
} : {})
|
|
104
|
-
},
|
|
105
|
-
progressive: true
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// Process dynamic variables.
|
|
109
|
-
if (dynamicPath && !excludeDynamic && (await _fsExtra.default.exists(dynamicPath))) {
|
|
110
|
-
const dynamic = new Function(`return ${(await _fsExtra.default.readFile(dynamicPath)).toString()}`)()(dotenv);
|
|
111
|
-
Object.keys(dynamic).forEach(key => {
|
|
112
|
-
Object.assign(dotenv, {
|
|
113
|
-
[key]: typeof dynamic[key] === 'function' ? dynamic[key](dotenv) : dynamic[key]
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Write output file.
|
|
119
|
-
if (outputPath) {
|
|
120
|
-
outputPath = dotenv[outputKey];
|
|
121
|
-
delete dotenv[outputKey];
|
|
122
|
-
await _fsExtra.default.writeFile(outputPath, Object.keys(dotenv).reduce((contents, key) => {
|
|
123
|
-
const value = dotenv[key] ?? '';
|
|
124
|
-
return `${contents}${key}=${value.includes('\n') ? `"${value}"` : value}\n`;
|
|
125
|
-
}, ''), {
|
|
126
|
-
encoding: 'utf-8'
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Log result.
|
|
131
|
-
if (log) logger.log(dotenv);
|
|
132
|
-
|
|
133
|
-
// Load process.env.
|
|
134
|
-
if (loadProcess) Object.assign(process.env, dotenv);
|
|
135
|
-
return dotenv;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Synchronously process dotenv files of the form .env[.<ENV>][.<PRIVATETOKEN>]
|
|
140
|
-
*
|
|
141
|
-
* @function getDotenvSync
|
|
142
|
-
*
|
|
143
|
-
* @param {GetDotenvOptions} [options] - options object
|
|
144
|
-
*
|
|
145
|
-
* @returns {Object} The combined parsed dotenv object.
|
|
146
|
-
*/
|
|
147
|
-
exports.getDotenv = getDotenv;
|
|
148
|
-
const getDotenvSync = function () {
|
|
149
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
150
|
-
// Apply defaults.
|
|
151
|
-
let {
|
|
152
|
-
defaultEnv,
|
|
153
|
-
dotenvToken,
|
|
154
|
-
dynamicPath,
|
|
155
|
-
env,
|
|
156
|
-
excludeDynamic,
|
|
157
|
-
excludeEnv,
|
|
158
|
-
excludeGlobal,
|
|
159
|
-
excludePrivate,
|
|
160
|
-
excludePublic,
|
|
161
|
-
loadProcess,
|
|
162
|
-
log,
|
|
163
|
-
logger = console,
|
|
164
|
-
outputPath,
|
|
165
|
-
paths,
|
|
166
|
-
privateToken
|
|
167
|
-
} = {
|
|
168
|
-
..._options.getdotenvDefaultOptions,
|
|
169
|
-
...options
|
|
170
|
-
};
|
|
171
|
-
const vars = pruneVars(_options.getdotenvDefaultOptions, options);
|
|
172
|
-
|
|
173
|
-
// Read .env files.
|
|
174
|
-
const loaded = paths.reduce((e, p) => {
|
|
175
|
-
let publicGlobal = excludePublic || excludeGlobal ? {} : (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, dotenvToken));
|
|
176
|
-
let publicEnv = excludePublic || excludeEnv ? {} : (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${env ?? defaultEnv}`));
|
|
177
|
-
let privateGlobal = excludePrivate || excludeGlobal ? {} : (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${privateToken}`));
|
|
178
|
-
let privateEnv = excludePrivate || excludeEnv ? {} : (0, _readDotenv.readDotenvSync)(_path.default.resolve(p, `${dotenvToken}.${env ?? defaultEnv}.${privateToken}`));
|
|
179
|
-
return {
|
|
180
|
-
...e,
|
|
181
|
-
...publicGlobal,
|
|
182
|
-
...publicEnv,
|
|
183
|
-
...privateGlobal,
|
|
184
|
-
...privateEnv
|
|
185
|
-
};
|
|
186
|
-
}, {});
|
|
187
|
-
const outputKey = (0, _nanoid.nanoid)();
|
|
188
|
-
const dotenv = (0, _dotenvExpand.dotenvExpandAll)({
|
|
189
|
-
vars: {
|
|
190
|
-
...loaded,
|
|
191
|
-
...vars,
|
|
192
|
-
...(outputPath ? {
|
|
193
|
-
[outputKey]: outputPath
|
|
194
|
-
} : {})
|
|
195
|
-
},
|
|
196
|
-
progressive: true
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
// Process dynamic variables.
|
|
200
|
-
if (dynamicPath && !excludeDynamic && _fsExtra.default.existsSync(dynamicPath)) {
|
|
201
|
-
const dynamic = new Function(`return ${_fsExtra.default.readFileSync(dynamicPath).toString()}`)()(dotenv);
|
|
202
|
-
Object.keys(dynamic).forEach(key => {
|
|
203
|
-
Object.assign(dotenv, {
|
|
204
|
-
[key]: typeof dynamic[key] === 'function' ? dynamic[key](dotenv) : dynamic[key]
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Write output file.
|
|
210
|
-
if (outputPath) {
|
|
211
|
-
outputPath = dotenv[outputKey];
|
|
212
|
-
delete dotenv[outputKey];
|
|
213
|
-
_fsExtra.default.writeFileSync(outputPath, Object.keys(dotenv).reduce((contents, key) => {
|
|
214
|
-
const value = dotenv[key] ?? '';
|
|
215
|
-
return `${contents}${key}=${value.includes('\n') ? `"${value}"` : value}\n`;
|
|
216
|
-
}, ''), {
|
|
217
|
-
encoding: 'utf-8'
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Log result.
|
|
222
|
-
if (log) logger.log(dotenv);
|
|
223
|
-
|
|
224
|
-
// Load process.env.
|
|
225
|
-
if (loadProcess) Object.assign(process.env, dotenv);
|
|
226
|
-
return dotenv;
|
|
227
|
-
};
|
|
228
|
-
exports.getDotenvSync = getDotenvSync;
|