@karmaniverous/get-dotenv 3.1.13 → 3.1.15
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/dist/default/lib/dotenvExpand.js +22 -6
- package/dist/default/lib/getDotenv.js +9 -13
- package/dist/default/lib/index.js +6 -0
- package/lib/dotenvExpand.js +15 -4
- package/lib/getDotenv.js +9 -7
- package/lib/index.js +1 -1
- package/package.json +10 -11
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.dotenvExpand = void 0;
|
|
6
|
+
exports.dotenvExpandAll = exports.dotenvExpand = void 0;
|
|
7
7
|
// like String.prototype.search but returns the last index
|
|
8
8
|
const _searchLast = (str, rgx) => {
|
|
9
9
|
const matches = Array.from(str.matchAll(rgx));
|
|
10
10
|
return matches.length > 0 ? matches.slice(-1)[0].index : -1;
|
|
11
11
|
};
|
|
12
|
-
const _interpolate = envValue => {
|
|
12
|
+
const _interpolate = (envValue, ref) => {
|
|
13
13
|
// find the last unescaped dollar sign in the
|
|
14
14
|
// value so that we can evaluate it
|
|
15
15
|
const lastUnescapedDollarSignIndex = _searchLast(envValue, /(?!(?<=\\))\$/g);
|
|
@@ -36,16 +36,32 @@ const _interpolate = envValue => {
|
|
|
36
36
|
const match = rightMostGroup.match(matchGroup);
|
|
37
37
|
if (match != null) {
|
|
38
38
|
const [, group, variableName, defaultValue] = match;
|
|
39
|
-
return _interpolate(envValue.replace(group,
|
|
39
|
+
return _interpolate(envValue.replace(group, ref[variableName] || defaultValue || ''), ref);
|
|
40
40
|
}
|
|
41
41
|
return envValue;
|
|
42
42
|
};
|
|
43
43
|
const _resolveEscapeSequences = value => {
|
|
44
44
|
return value.replace(/\\\$/g, '$');
|
|
45
45
|
};
|
|
46
|
-
const dotenvExpand = value
|
|
46
|
+
const dotenvExpand = function (value) {
|
|
47
|
+
let ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : process.env;
|
|
47
48
|
if (!value || value === 'undefined') return;
|
|
48
|
-
const result = _resolveEscapeSequences(_interpolate(value));
|
|
49
|
+
const result = _resolveEscapeSequences(_interpolate(value, ref));
|
|
49
50
|
return result.length ? result : undefined;
|
|
50
51
|
};
|
|
51
|
-
exports.dotenvExpand = dotenvExpand;
|
|
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;
|
|
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getDotenvSync = exports.getDotenv = void 0;
|
|
7
|
-
var _dotenvExpand = require("dotenv-expand");
|
|
8
7
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
8
|
var _lodash = _interopRequireDefault(require("lodash.pickby"));
|
|
10
9
|
var _path = _interopRequireDefault(require("path"));
|
|
11
10
|
var _nanoid = require("nanoid");
|
|
11
|
+
var _dotenvExpand = require("./dotenvExpand.js");
|
|
12
12
|
var _options = require("./options.js");
|
|
13
13
|
var _readDotenv = require("./readDotenv.js");
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -94,17 +94,15 @@ const getDotenv = async function () {
|
|
|
94
94
|
};
|
|
95
95
|
}, {});
|
|
96
96
|
const outputKey = (0, _nanoid.nanoid)();
|
|
97
|
-
const {
|
|
98
|
-
|
|
99
|
-
} = (0, _dotenvExpand.expand)({
|
|
100
|
-
ignoreProcessEnv: true,
|
|
101
|
-
parsed: {
|
|
97
|
+
const dotenv = (0, _dotenvExpand.dotenvExpandAll)({
|
|
98
|
+
vars: {
|
|
102
99
|
...loaded,
|
|
103
100
|
...vars,
|
|
104
101
|
...(outputPath ? {
|
|
105
102
|
[outputKey]: outputPath
|
|
106
103
|
} : {})
|
|
107
|
-
}
|
|
104
|
+
},
|
|
105
|
+
progressive: true
|
|
108
106
|
});
|
|
109
107
|
|
|
110
108
|
// Process dynamic variables.
|
|
@@ -187,17 +185,15 @@ const getDotenvSync = function () {
|
|
|
187
185
|
};
|
|
188
186
|
}, {});
|
|
189
187
|
const outputKey = (0, _nanoid.nanoid)();
|
|
190
|
-
const {
|
|
191
|
-
|
|
192
|
-
} = (0, _dotenvExpand.expand)({
|
|
193
|
-
ignoreProcessEnv: true,
|
|
194
|
-
parsed: {
|
|
188
|
+
const dotenv = (0, _dotenvExpand.dotenvExpandAll)({
|
|
189
|
+
vars: {
|
|
195
190
|
...loaded,
|
|
196
191
|
...vars,
|
|
197
192
|
...(outputPath ? {
|
|
198
193
|
[outputKey]: outputPath
|
|
199
194
|
} : {})
|
|
200
|
-
}
|
|
195
|
+
},
|
|
196
|
+
progressive: true
|
|
201
197
|
});
|
|
202
198
|
|
|
203
199
|
// Process dynamic variables.
|
|
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "dotenvExpand", {
|
|
|
9
9
|
return _dotenvExpand.dotenvExpand;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "dotenvExpandAll", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _dotenvExpand.dotenvExpandAll;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
12
18
|
Object.defineProperty(exports, "getDotenv", {
|
|
13
19
|
enumerable: true,
|
|
14
20
|
get: function () {
|
package/lib/dotenvExpand.js
CHANGED
|
@@ -4,7 +4,7 @@ const _searchLast = (str, rgx) => {
|
|
|
4
4
|
return matches.length > 0 ? matches.slice(-1)[0].index : -1;
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
const _interpolate = (envValue) => {
|
|
7
|
+
const _interpolate = (envValue, ref) => {
|
|
8
8
|
// find the last unescaped dollar sign in the
|
|
9
9
|
// value so that we can evaluate it
|
|
10
10
|
const lastUnescapedDollarSignIndex = _searchLast(envValue, /(?!(?<=\\))\$/g);
|
|
@@ -34,7 +34,8 @@ const _interpolate = (envValue) => {
|
|
|
34
34
|
const [, group, variableName, defaultValue] = match;
|
|
35
35
|
|
|
36
36
|
return _interpolate(
|
|
37
|
-
envValue.replace(group,
|
|
37
|
+
envValue.replace(group, ref[variableName] || defaultValue || ''),
|
|
38
|
+
ref
|
|
38
39
|
);
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -45,8 +46,18 @@ const _resolveEscapeSequences = (value) => {
|
|
|
45
46
|
return value.replace(/\\\$/g, '$');
|
|
46
47
|
};
|
|
47
48
|
|
|
48
|
-
export const dotenvExpand = (value) => {
|
|
49
|
+
export const dotenvExpand = (value, ref = process.env) => {
|
|
49
50
|
if (!value || value === 'undefined') return;
|
|
50
|
-
const result = _resolveEscapeSequences(_interpolate(value));
|
|
51
|
+
const result = _resolveEscapeSequences(_interpolate(value, ref));
|
|
51
52
|
return result.length ? result : undefined;
|
|
52
53
|
};
|
|
54
|
+
|
|
55
|
+
export const dotenvExpandAll = ({
|
|
56
|
+
vars = {},
|
|
57
|
+
progressive = false,
|
|
58
|
+
ref = process.env,
|
|
59
|
+
}) =>
|
|
60
|
+
Object.keys(vars).reduce((acc, key) => {
|
|
61
|
+
acc[key] = dotenvExpand(vars[key], { ...ref, ...(progressive ? acc : {}) });
|
|
62
|
+
return acc;
|
|
63
|
+
}, {});
|
package/lib/getDotenv.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// npm imports
|
|
2
|
-
import { expand } from 'dotenv-expand';
|
|
3
2
|
import fs from 'fs-extra';
|
|
4
3
|
import pickBy from 'lodash.pickby';
|
|
5
4
|
import path from 'path';
|
|
6
5
|
import { nanoid } from 'nanoid';
|
|
7
6
|
|
|
8
7
|
// lib imports
|
|
8
|
+
import { dotenvExpandAll } from './dotenvExpand.js';
|
|
9
9
|
import { getdotenvDefaultOptions } from './options.js';
|
|
10
10
|
import { readDotenv, readDotenvSync } from './readDotenv.js';
|
|
11
11
|
|
|
@@ -110,13 +110,14 @@ export const getDotenv = async (options = {}) => {
|
|
|
110
110
|
}, {});
|
|
111
111
|
|
|
112
112
|
const outputKey = nanoid();
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
|
|
114
|
+
const dotenv = dotenvExpandAll({
|
|
115
|
+
vars: {
|
|
116
116
|
...loaded,
|
|
117
117
|
...vars,
|
|
118
118
|
...(outputPath ? { [outputKey]: outputPath } : {}),
|
|
119
119
|
},
|
|
120
|
+
progressive: true,
|
|
120
121
|
});
|
|
121
122
|
|
|
122
123
|
// Process dynamic variables.
|
|
@@ -227,13 +228,14 @@ export const getDotenvSync = (options = {}) => {
|
|
|
227
228
|
}, {});
|
|
228
229
|
|
|
229
230
|
const outputKey = nanoid();
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
231
|
+
|
|
232
|
+
const dotenv = dotenvExpandAll({
|
|
233
|
+
vars: {
|
|
233
234
|
...loaded,
|
|
234
235
|
...vars,
|
|
235
236
|
...(outputPath ? { [outputKey]: outputPath } : {}),
|
|
236
237
|
},
|
|
238
|
+
progressive: true,
|
|
237
239
|
});
|
|
238
240
|
|
|
239
241
|
// Process dynamic variables.
|
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"bin": {
|
|
4
4
|
"getdotenv": "bin/getdotenv/index.js"
|
|
5
5
|
},
|
|
6
|
-
"version": "3.1.
|
|
6
|
+
"version": "3.1.15",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -38,8 +38,7 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"commander": "^11.0.0",
|
|
40
40
|
"dotenv": "^16.3.1",
|
|
41
|
-
"
|
|
42
|
-
"execa": "^7.2.0",
|
|
41
|
+
"execa": "^8.0.1",
|
|
43
42
|
"fs-extra": "^11.1.1",
|
|
44
43
|
"lodash.frompairs": "^4.0.1",
|
|
45
44
|
"lodash.pick": "^4.4.0",
|
|
@@ -48,15 +47,15 @@
|
|
|
48
47
|
"pkg-dir": "^7.0.0"
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
|
-
"@babel/cli": "^7.22.
|
|
52
|
-
"@babel/core": "^7.22.
|
|
53
|
-
"@babel/eslint-parser": "^7.22.
|
|
54
|
-
"@babel/preset-env": "^7.22.
|
|
55
|
-
"@babel/register": "^7.22.
|
|
56
|
-
"@types/node": "^20.5.
|
|
57
|
-
"chai": "^4.3.
|
|
50
|
+
"@babel/cli": "^7.22.15",
|
|
51
|
+
"@babel/core": "^7.22.15",
|
|
52
|
+
"@babel/eslint-parser": "^7.22.15",
|
|
53
|
+
"@babel/preset-env": "^7.22.15",
|
|
54
|
+
"@babel/register": "^7.22.15",
|
|
55
|
+
"@types/node": "^20.5.9",
|
|
56
|
+
"chai": "^4.3.8",
|
|
58
57
|
"concat-md": "^0.5.1",
|
|
59
|
-
"eslint": "^8.
|
|
58
|
+
"eslint": "^8.48.0",
|
|
60
59
|
"eslint-plugin-mocha": "^10.1.0",
|
|
61
60
|
"eslint-plugin-promise": "^6.1.1",
|
|
62
61
|
"jsdoc-to-markdown": "^8.0.0",
|