@karmaniverous/get-dotenv 3.1.19 → 4.0.0-1
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 +26501 -0
- package/dist/index.cjs +26506 -0
- package/dist/index.d.cts +244 -0
- package/dist/index.d.mts +244 -0
- package/dist/index.d.ts +244 -0
- package/dist/index.mjs +26499 -0
- package/package.json +98 -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
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getDotenvCli = void 0;
|
|
7
|
-
var _commander = require("commander");
|
|
8
|
-
var _execa = require("execa");
|
|
9
|
-
var _os = _interopRequireDefault(require("os"));
|
|
10
|
-
var _dotenvExpand = require("./dotenvExpand.js");
|
|
11
|
-
var _getDotenv = require("./getDotenv.js");
|
|
12
|
-
var _options = require("./options.js");
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
// npm imports
|
|
15
|
-
|
|
16
|
-
// lib imports
|
|
17
|
-
|
|
18
|
-
// Discover platform.
|
|
19
|
-
const platform = _os.default.platform();
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* GetDotenv CLI Pre-hook Callback type. Transforms inbound options & executes side effects.
|
|
23
|
-
*
|
|
24
|
-
* @async
|
|
25
|
-
* @callback GetDotenvPreHookCallback
|
|
26
|
-
* @param {GetDotenvCliOptions} options - inbound GetDotenv CLI Options object
|
|
27
|
-
* @returns {GetDotenvCliOptions} transformed GetDotenv CLI Options object (undefined return value is ignored)
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* GetDotenv CLI Post-hook Callback type. Executes side effects within getdotenv context.
|
|
32
|
-
*
|
|
33
|
-
* @async
|
|
34
|
-
* @callback GetDotenvPostHookCallback
|
|
35
|
-
* @param {object} dotenv - dotenv object
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Generate a CLI for get-dotenv.
|
|
40
|
-
*
|
|
41
|
-
* @function getDotenvCli
|
|
42
|
-
* @param {object} [options] - options object
|
|
43
|
-
* @param {string} [options.alias] - cli alias (used for cli help)
|
|
44
|
-
* @param {string} [options.command] - {@link https://github.com/motdotla/dotenv-expand/blob/master/tests/.env dotenv-expanded} shell command string
|
|
45
|
-
* @param {bool} [options.debug] - debug mode
|
|
46
|
-
* @param {string} [options.defaultEnv] - default target environment
|
|
47
|
-
* @param {string} [options.description] - cli description (used for cli help)
|
|
48
|
-
* @param {string} [options.dotenvToken] - {@link https://github.com/motdotla/dotenv-expand/blob/master/tests/.env dotenv-expanded} token indicating a dotenv file
|
|
49
|
-
* @param {string} [options.dynamicPath] - path to file exporting an object keyed to dynamic variable functions
|
|
50
|
-
* @param {bool} [options.excludeDynamic] - exclude dynamic dotenv variables
|
|
51
|
-
* @param {bool} [options.excludeEnv] - exclude environment-specific dotenv variables
|
|
52
|
-
* @param {bool} [options.excludeGlobal] - exclude global dotenv variables
|
|
53
|
-
* @param {bool} [options.excludePrivate] - exclude private dotenv variables
|
|
54
|
-
* @param {bool} [options.excludePublic] - exclude public dotenv variables
|
|
55
|
-
* @param {bool} [options.loadProcess] - load variables to process.env
|
|
56
|
-
* @param {bool} [options.log] - log result to console
|
|
57
|
-
* @param {function} [options.logger] - logger function
|
|
58
|
-
* @param {string} [options.outputPath] - consolidated output file, {@link https://github.com/motdotla/dotenv-expand/blob/master/tests/.env dotenv-expanded} using loaded env vars
|
|
59
|
-
* @param {string} [options.paths] - {@link https://github.com/motdotla/dotenv-expand/blob/master/tests/.env dotenv-expanded} delimited list of input directory paths
|
|
60
|
-
* @param {string} [options.pathsDelimiter] - paths delimiter string
|
|
61
|
-
* @param {string} [options.pathsDelimiterPattern] - paths delimiter regex pattern
|
|
62
|
-
* @param {GetDotenvPreHookCallback} [config.preHook] - transforms cli options & executes side effects
|
|
63
|
-
* @param {string} [options.privateToken] - {@link https://github.com/motdotla/dotenv-expand/blob/master/tests/.env dotenv-expanded} token indicating private variables
|
|
64
|
-
* @param {GetDotenvPostHookCallback} [config.postHook] - executes side effects within getdotenv context
|
|
65
|
-
* @param {string} [options.vars] - {@link https://github.com/motdotla/dotenv-expand/blob/master/tests/.env dotenv-expanded} delimited list of explicit environment variable key-value pairs
|
|
66
|
-
* @param {string} [options.varsAssignor] - variable key-value assignor string
|
|
67
|
-
* @param {string} [options.varsAssignorPattern] - variable key-value assignor regex pattern
|
|
68
|
-
* @param {string} [options.varsDelimiter] - variable key-value pair delimiter string
|
|
69
|
-
* @param {string} [options.varsDelimiterPattern] - variable key-value pair delimiter regex pattern
|
|
70
|
-
* @returns {object} The CLI command.
|
|
71
|
-
*/
|
|
72
|
-
const getDotenvCli = function () {
|
|
73
|
-
let {
|
|
74
|
-
logger = console,
|
|
75
|
-
preHook,
|
|
76
|
-
postHook,
|
|
77
|
-
...cliOptionsCustom
|
|
78
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
79
|
-
const {
|
|
80
|
-
alias,
|
|
81
|
-
command,
|
|
82
|
-
debug,
|
|
83
|
-
defaultEnv,
|
|
84
|
-
description,
|
|
85
|
-
dotenvToken,
|
|
86
|
-
dynamicPath,
|
|
87
|
-
env,
|
|
88
|
-
excludeDynamic,
|
|
89
|
-
excludeEnv,
|
|
90
|
-
excludeGlobal,
|
|
91
|
-
excludePrivate,
|
|
92
|
-
excludePublic,
|
|
93
|
-
loadProcess,
|
|
94
|
-
log,
|
|
95
|
-
outputPath,
|
|
96
|
-
paths,
|
|
97
|
-
pathsDelimiter,
|
|
98
|
-
pathsDelimiterPattern,
|
|
99
|
-
privateToken,
|
|
100
|
-
varsAssignor,
|
|
101
|
-
varsAssignorPattern,
|
|
102
|
-
varsDelimiter,
|
|
103
|
-
varsDelimiterPattern
|
|
104
|
-
} = {
|
|
105
|
-
..._options.cliDefaultOptionsGlobal,
|
|
106
|
-
...cliOptionsCustom,
|
|
107
|
-
..._options.cliDefaultOptionsLocal
|
|
108
|
-
};
|
|
109
|
-
const excludeAll = excludeDynamic && (excludeEnv && excludeGlobal || excludePrivate && excludePublic);
|
|
110
|
-
return new _commander.Command().name(alias).description(description).enablePositionalOptions().passThroughOptions().option('-e, --env <string>', 'target environment', _dotenvExpand.dotenvExpand, env).option('-v, --vars <string>', `dotenv-expanded delimited key-value pairs: ${[['KEY1', 'VAL1'], ['KEY2', 'VAL2']].map(v => v.join(varsAssignor)).join(varsDelimiter)}`, _dotenvExpand.dotenvExpand).option('-c, --command <string>', 'dotenv-expanded shell command string', _dotenvExpand.dotenvExpand, command).option('-o, --output-path <string>', 'consolidated output file, follows dotenv-expand rules using loaded env vars', _dotenvExpand.dotenvExpand, outputPath).addOption(new _commander.Option('-p, --load-process', `load variables to process.env ON${loadProcess ? ' (default)' : ''}`).conflicts('loadProcessOff')).addOption(new _commander.Option('-P, --load-process-off', `load variables to process.env OFF${!loadProcess ? ' (default)' : ''}`).conflicts('loadProcess')).addOption(new _commander.Option('-a, --exclude-all', `exclude all dotenv variables from loading ON${excludeAll ? ' (default)' : ''}`).conflicts('excludeAllOff')).addOption(new _commander.Option('-A, --exclude-all-off', `exclude all dotenv variables from loading OFF${!excludeAll ? ' (default)' : ''}`).conflicts('excludeAll')).addOption(new _commander.Option('-z, --exclude-dynamic', `exclude dynamic dotenv variables from loading ON${excludeDynamic ? ' (default)' : ''}`).conflicts('excludeDynamicOff')).addOption(new _commander.Option('-Z, --exclude-dynamic-off', `exclude dynamic dotenv variables from loading OFF${!excludeDynamic ? ' (default)' : ''}`).conflicts('excludeDynamic')).addOption(new _commander.Option('-n, --exclude-env', `exclude environment-specific dotenv variables from loading${excludeEnv ? ' (default)' : ''}`).conflicts('excludeEnvOff')).addOption(new _commander.Option('-N, --exclude-env-off', `exclude environment-specific dotenv variables from loading OFF${!excludeEnv ? ' (default)' : ''}`).conflicts('excludeEnv')).addOption(new _commander.Option('-g, --exclude-global', `exclude global dotenv variables from loading ON${excludeGlobal ? ' (default)' : ''}`).conflicts('excludeGlobalOff')).addOption(new _commander.Option('-G, --exclude-global-off', `exclude global dotenv variables from loading OFF${!excludeGlobal ? ' (default)' : ''}`).conflicts('excludeGlobal')).addOption(new _commander.Option('-r, --exclude-private', `exclude private dotenv variables from loading ON${excludePrivate ? ' (default)' : ''}`).conflicts('excludePrivateOff')).addOption(new _commander.Option('-R, --exclude-private-off', `exclude private dotenv variables from loading OFF${!excludePrivate ? ' (default)' : ''}`).conflicts('excludePrivate')).addOption(new _commander.Option('-u, --exclude-public', `exclude public dotenv variables from loading ON${excludePublic ? ' (default)' : ''}`).conflicts('excludePublicOff')).addOption(new _commander.Option('-U, --exclude-public-off', `exclude public dotenv variables from loading OFF${!excludePublic ? ' (default)' : ''}`).conflicts('excludePublic')).addOption(new _commander.Option('-l, --log', `console log loaded variables ON${log ? ' (default)' : ''}`).conflicts('logOff')).addOption(new _commander.Option('-L, --log-off', `console log loaded variables OFF${!log ? ' (default)' : ''}`).conflicts('log')).addOption(new _commander.Option('-d, --debug', `debug mode ON${debug ? ' (default)' : ''}`).conflicts('debugOff')).addOption(new _commander.Option('-D, --debug-off', `debug mode OFF${!debug ? ' (default)' : ''}`).conflicts('debug')).option('--default-env <string>', 'default target environment', _dotenvExpand.dotenvExpand, defaultEnv).option('--dotenv-token <string>', 'dotenv-expanded token indicating a dotenv file', _dotenvExpand.dotenvExpand, dotenvToken).option('--dynamic-path <string>', 'dynamic variables path', _dotenvExpand.dotenvExpand, dynamicPath).option('--paths <string>', 'dotenv-expanded delimited list of paths to dotenv directory', _dotenvExpand.dotenvExpand, paths).option('--paths-delimiter <string>', 'paths delimiter string', pathsDelimiter).option('--paths-delimiter-pattern <string>', 'paths delimiter regex pattern', pathsDelimiterPattern).option('--private-token <string>', 'dotenv-expanded token indicating private variables', _dotenvExpand.dotenvExpand, privateToken).option('--vars-delimiter <string>', 'vars delimiter string', varsDelimiter).option('--vars-delimiter-pattern <string>', 'vars delimiter regex pattern', varsDelimiterPattern).option('--vars-assignor <string>', 'vars assignment operator string', varsAssignor).option('--vars-assignor-pattern <string>', 'vars assignment operator regex pattern', varsAssignorPattern).addCommand(new _commander.Command().name('cmd').description('execute shell command string (default command)').configureHelp({
|
|
111
|
-
showGlobalOptions: true
|
|
112
|
-
}).enablePositionalOptions().passThroughOptions().action(async (options, command) => {
|
|
113
|
-
const {
|
|
114
|
-
args
|
|
115
|
-
} = command;
|
|
116
|
-
if (args.length) await (0, _execa.execaCommand)(args.join(platform === 'win32' ? '\\ ' : ' '), {
|
|
117
|
-
stdio: 'inherit',
|
|
118
|
-
shell: true
|
|
119
|
-
});
|
|
120
|
-
}), {
|
|
121
|
-
isDefault: true
|
|
122
|
-
}).hook('preSubcommand', async thisCommand => {
|
|
123
|
-
const rawOptions = thisCommand.opts();
|
|
124
|
-
if (rawOptions.debug) logger.log('\n*** raw cli options ***\n', {
|
|
125
|
-
rawOptions
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// Load options.
|
|
129
|
-
let {
|
|
130
|
-
command,
|
|
131
|
-
debugOff,
|
|
132
|
-
excludeAll,
|
|
133
|
-
excludeAllOff,
|
|
134
|
-
excludeDynamicOff,
|
|
135
|
-
excludeEnvOff,
|
|
136
|
-
excludeGlobalOff,
|
|
137
|
-
excludePrivateOff,
|
|
138
|
-
excludePublicOff,
|
|
139
|
-
loadProcessOff,
|
|
140
|
-
logOff,
|
|
141
|
-
...cliOptions
|
|
142
|
-
} = rawOptions;
|
|
143
|
-
|
|
144
|
-
// Resolve flags.
|
|
145
|
-
const resolveExclusion = (exclude, excludeOff, defaultValue) => exclude ? true : excludeOff ? false : defaultValue;
|
|
146
|
-
const resolveExclusionAll = (exclude, excludeOff, defaultValue) => excludeAll && !excludeOff ? true : excludeAllOff && !exclude ? false : defaultValue;
|
|
147
|
-
cliOptions.debug = resolveExclusion(cliOptions.debug, debugOff, debug);
|
|
148
|
-
cliOptions.excludeDynamic = resolveExclusionAll(cliOptions.excludeDynamic, excludeDynamicOff, excludeDynamic);
|
|
149
|
-
cliOptions.excludeEnv = resolveExclusionAll(cliOptions.excludeEnv, excludeEnvOff, excludeEnv);
|
|
150
|
-
cliOptions.excludeGlobal = resolveExclusionAll(cliOptions.excludeGlobal, excludeGlobalOff, excludeGlobal);
|
|
151
|
-
cliOptions.excludePrivate = resolveExclusionAll(cliOptions.excludePrivate, excludePrivateOff, excludePrivate);
|
|
152
|
-
cliOptions.excludePublic = resolveExclusionAll(cliOptions.excludePublic, excludePublicOff, excludePublic);
|
|
153
|
-
cliOptions.log = resolveExclusion(cliOptions.log, logOff, log);
|
|
154
|
-
cliOptions.loadProcess = resolveExclusion(cliOptions.loadProcess, loadProcessOff, loadProcess);
|
|
155
|
-
if (cliOptions.debug) logger.log('\n*** cli options after default resolution ***\n', {
|
|
156
|
-
cliOptions
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
// Execute pre-hook.
|
|
160
|
-
if (preHook) {
|
|
161
|
-
cliOptions = (await preHook(cliOptions)) ?? cliOptions;
|
|
162
|
-
if (cliOptions.debug) logger.log('\n*** cli options after pre-hook ***\n', cliOptions);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Get getdotenv options from parent command.
|
|
166
|
-
const parentGetdotenvOptions = process.env.getdotenvOptions ? JSON.parse(process.env.getdotenvOptions) : {};
|
|
167
|
-
const cliGetdotenvOptions = (0, _options.cli2getdotenvOptions)(cliOptions);
|
|
168
|
-
const getdotenvOptions = {
|
|
169
|
-
...parentGetdotenvOptions,
|
|
170
|
-
...cliGetdotenvOptions
|
|
171
|
-
};
|
|
172
|
-
if (cliOptions.debug) logger.log('\n*** getdotenv option resolution ***\n', {
|
|
173
|
-
parentGetdotenvOptions,
|
|
174
|
-
cliGetdotenvOptions,
|
|
175
|
-
getdotenvOptions
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
// Execute getdotenv.
|
|
179
|
-
thisCommand.getdotenvOptions = {
|
|
180
|
-
...getdotenvOptions,
|
|
181
|
-
logger
|
|
182
|
-
};
|
|
183
|
-
const dotenv = await (0, _getDotenv.getDotenv)(thisCommand.getdotenvOptions);
|
|
184
|
-
if (cliOptions.debug) logger.log('\n*** resulting dotenv values ***\n', {
|
|
185
|
-
dotenv
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
// Execute post-hook.
|
|
189
|
-
if (postHook) await postHook(dotenv);
|
|
190
|
-
|
|
191
|
-
// Execute shell command.
|
|
192
|
-
if (command) await (0, _execa.execaCommand)(platform === 'win32' ? command.replace(/ /g, '\\ ') : command, {
|
|
193
|
-
env: {
|
|
194
|
-
...process.env,
|
|
195
|
-
getdotenvOptions: JSON.stringify(getdotenvOptions)
|
|
196
|
-
},
|
|
197
|
-
shell: true,
|
|
198
|
-
stdio: 'inherit'
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
exports.getDotenvCli = getDotenvCli;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "dotenvExpand", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _dotenvExpand.dotenvExpand;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "dotenvExpandAll", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _dotenvExpand.dotenvExpandAll;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "getDotenv", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _getDotenv.getDotenv;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "getDotenvCli", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return _getDotenvCli.getDotenvCli;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(exports, "getDotenvSync", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function () {
|
|
33
|
-
return _getDotenv.getDotenvSync;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
var _dotenvExpand = require("./dotenvExpand.js");
|
|
37
|
-
var _getDotenv = require("./getDotenv.js");
|
|
38
|
-
var _getDotenvCli = require("./getDotenvCli.js");
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getdotenvDefaultOptions = exports.cliDefaultOptionsLocal = exports.cliDefaultOptionsGlobal = exports.cli2getdotenvOptions = void 0;
|
|
7
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
8
|
-
var _lodash = _interopRequireDefault(require("lodash.frompairs"));
|
|
9
|
-
var _lodash2 = _interopRequireDefault(require("lodash.pick"));
|
|
10
|
-
var _pkgDir = require("pkg-dir");
|
|
11
|
-
var _path = require("path");
|
|
12
|
-
var _url = require("url");
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
// npm imports
|
|
15
|
-
|
|
16
|
-
const _dirname = (0, _path.dirname)((0, _url.fileURLToPath)(import.meta.url));
|
|
17
|
-
|
|
18
|
-
// Load default options.
|
|
19
|
-
const cliDefaultOptionsGlobalPath = (0, _path.resolve)(_dirname, '../getdotenv.config.json');
|
|
20
|
-
const cliDefaultOptionsGlobal = exports.cliDefaultOptionsGlobal = (await _fsExtra.default.exists(cliDefaultOptionsGlobalPath)) ? JSON.parse(await _fsExtra.default.readFile(cliDefaultOptionsGlobalPath)) : {};
|
|
21
|
-
const cliDefaultOptionsLocalPath = (0, _path.resolve)(await (0, _pkgDir.packageDirectory)(), 'getdotenv.config.json');
|
|
22
|
-
const cliDefaultOptionsLocal = exports.cliDefaultOptionsLocal = (await _fsExtra.default.exists(cliDefaultOptionsLocalPath)) ? JSON.parse(await _fsExtra.default.readFile(cliDefaultOptionsLocalPath)) : {};
|
|
23
|
-
const cli2getdotenvOptions = function () {
|
|
24
|
-
let {
|
|
25
|
-
paths,
|
|
26
|
-
pathsDelimiter,
|
|
27
|
-
pathsDelimiterPattern,
|
|
28
|
-
vars,
|
|
29
|
-
varsAssignor,
|
|
30
|
-
varsAssignorPattern,
|
|
31
|
-
varsDelimiter,
|
|
32
|
-
varsDelimiterPattern,
|
|
33
|
-
...rest
|
|
34
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
35
|
-
return {
|
|
36
|
-
...(0, _lodash2.default)(rest, ['defaultEnv', 'dotenvToken', 'dynamicPath', 'env', 'excludeDynamic', 'excludeEnv', 'excludeGlobal', 'excludePrivate', 'excludePublic', 'loadProcess', 'log', 'outputPath', 'privateToken']),
|
|
37
|
-
paths: paths?.split(pathsDelimiterPattern ? RegExp(pathsDelimiterPattern) : pathsDelimiter) ?? [],
|
|
38
|
-
vars: (0, _lodash.default)(vars?.split(varsDelimiterPattern ? RegExp(varsDelimiterPattern) : varsDelimiter).map(v => v.split(varsAssignorPattern ? RegExp(varsAssignorPattern) : varsAssignor)))
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
exports.cli2getdotenvOptions = cli2getdotenvOptions;
|
|
42
|
-
const getdotenvDefaultOptions = exports.getdotenvDefaultOptions = cli2getdotenvOptions({
|
|
43
|
-
...cliDefaultOptionsGlobal,
|
|
44
|
-
...cliDefaultOptionsLocal
|
|
45
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.readDotenvSync = exports.readDotenv = void 0;
|
|
7
|
-
var _dotenv = require("dotenv");
|
|
8
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
/**
|
|
11
|
-
* Asynchronously read a dotenv file & parse it into an object.
|
|
12
|
-
*
|
|
13
|
-
* @async
|
|
14
|
-
* @private
|
|
15
|
-
* @function readDotenv
|
|
16
|
-
*
|
|
17
|
-
* @param {string} path - Any value.
|
|
18
|
-
*
|
|
19
|
-
* @returns {Object} The parsed dotenv object.
|
|
20
|
-
*/
|
|
21
|
-
const readDotenv = async path => {
|
|
22
|
-
try {
|
|
23
|
-
return (await _fsExtra.default.exists(path)) ? (0, _dotenv.parse)(await _fsExtra.default.readFile(path)) : {};
|
|
24
|
-
} catch {
|
|
25
|
-
return {};
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Synchronously reads a dotenv file & parses it into an object.
|
|
31
|
-
*
|
|
32
|
-
* @private
|
|
33
|
-
* @function readDotenvSync
|
|
34
|
-
*
|
|
35
|
-
* @param {string} path - Any value.
|
|
36
|
-
*
|
|
37
|
-
* @returns {Object} The parsed dotenv object.
|
|
38
|
-
*/
|
|
39
|
-
exports.readDotenv = readDotenv;
|
|
40
|
-
const readDotenvSync = path => {
|
|
41
|
-
try {
|
|
42
|
-
return _fsExtra.default.existsSync(path) ? (0, _dotenv.parse)(_fsExtra.default.readFileSync(path)) : {};
|
|
43
|
-
} catch {
|
|
44
|
-
return {};
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
exports.readDotenvSync = readDotenvSync;
|
package/dist/package.json
DELETED
package/getdotenv.config.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"alias": "getdotenv",
|
|
3
|
-
"debug": false,
|
|
4
|
-
"defaultEnv": "dev",
|
|
5
|
-
"description": "Base CLI.",
|
|
6
|
-
"dotenvToken": ".env",
|
|
7
|
-
"dynamicPath": "./env/dynamic.js",
|
|
8
|
-
"excludeDynamic": false,
|
|
9
|
-
"excludeEnv": false,
|
|
10
|
-
"excludeGlobal": false,
|
|
11
|
-
"excludePrivate": false,
|
|
12
|
-
"excludePublic": false,
|
|
13
|
-
"loadProcess": true,
|
|
14
|
-
"log": false,
|
|
15
|
-
"paths": "./ ./env",
|
|
16
|
-
"pathsDelimiter": " ",
|
|
17
|
-
"pathsDelimiterPattern": "\\s+",
|
|
18
|
-
"privateToken": "local",
|
|
19
|
-
"vars": "",
|
|
20
|
-
"varsAssignor": "=",
|
|
21
|
-
"varsAssignorPattern": "=",
|
|
22
|
-
"varsDelimiter": " ",
|
|
23
|
-
"varsDelimiterPattern": "\\s+"
|
|
24
|
-
}
|
package/lib/dotenvExpand.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
// like String.prototype.search but returns the last index
|
|
2
|
-
const _searchLast = (str, rgx) => {
|
|
3
|
-
const matches = Array.from(str.matchAll(rgx));
|
|
4
|
-
return matches.length > 0 ? matches.slice(-1)[0].index : -1;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
const _interpolate = (envValue, ref) => {
|
|
8
|
-
// find the last unescaped dollar sign in the
|
|
9
|
-
// value so that we can evaluate it
|
|
10
|
-
const lastUnescapedDollarSignIndex = _searchLast(envValue, /(?!(?<=\\))\$/g);
|
|
11
|
-
|
|
12
|
-
// If we couldn't match any unescaped dollar sign
|
|
13
|
-
// let's return the string as is
|
|
14
|
-
if (lastUnescapedDollarSignIndex === -1) return envValue;
|
|
15
|
-
|
|
16
|
-
// This is the right-most group of variables in the string
|
|
17
|
-
const rightMostGroup = envValue.slice(lastUnescapedDollarSignIndex);
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* This finds the inner most variable/group divided
|
|
21
|
-
* by variable name and default value (if present)
|
|
22
|
-
* (
|
|
23
|
-
* (?!(?<=\\))\$ // only match dollar signs that are not escaped
|
|
24
|
-
* {? // optional opening curly brace
|
|
25
|
-
* ([\w]+) // match the variable name
|
|
26
|
-
* (?::-([^}\\]*))? // match an optional default value
|
|
27
|
-
* }? // optional closing curly brace
|
|
28
|
-
* )
|
|
29
|
-
*/
|
|
30
|
-
const matchGroup = /((?!(?<=\\))\${?([\w]+)(?::-([^}\\]*))?}?)/;
|
|
31
|
-
const match = rightMostGroup.match(matchGroup);
|
|
32
|
-
|
|
33
|
-
if (match != null) {
|
|
34
|
-
const [, group, variableName, defaultValue] = match;
|
|
35
|
-
|
|
36
|
-
return _interpolate(
|
|
37
|
-
envValue.replace(group, ref[variableName] || defaultValue || ''),
|
|
38
|
-
ref
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return envValue;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const _resolveEscapeSequences = (value) => {
|
|
46
|
-
return value.replace(/\\\$/g, '$');
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const dotenvExpand = (value, ref = process.env) => {
|
|
50
|
-
if (!value || value === 'undefined') return;
|
|
51
|
-
const result = _resolveEscapeSequences(_interpolate(value, ref));
|
|
52
|
-
return result.length ? result : undefined;
|
|
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
|
-
}, {});
|