@karmaniverous/get-dotenv 4.2.1 → 4.2.2
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/getdotenv.cli.mjs +113 -185
- package/dist/index.cjs +110 -183
- package/dist/index.d.cts +22 -22
- package/dist/index.d.mts +22 -22
- package/dist/index.d.ts +22 -22
- package/dist/index.mjs +112 -184
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,18 +4,10 @@ import { Command } from '@commander-js/extra-typings';
|
|
|
4
4
|
* Options passed programmatically to `getDotenvCli`.
|
|
5
5
|
*/
|
|
6
6
|
interface GetDotenvCliOptions extends Omit<GetDotenvOptions, 'paths' | 'vars'> {
|
|
7
|
-
/**
|
|
8
|
-
* CLI alias. Should align with the `bin` property in `package.json`.
|
|
9
|
-
*/
|
|
10
|
-
alias?: string;
|
|
11
7
|
/**
|
|
12
8
|
* Logs CLI internals when true.
|
|
13
9
|
*/
|
|
14
10
|
debug?: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* Cli description (appears in CLI help).
|
|
17
|
-
*/
|
|
18
|
-
description?: string;
|
|
19
11
|
/**
|
|
20
12
|
* A delimited string of paths to dotenv files.
|
|
21
13
|
*/
|
|
@@ -30,6 +22,10 @@ interface GetDotenvCliOptions extends Omit<GetDotenvOptions, 'paths' | 'vars'> {
|
|
|
30
22
|
* `pathsDelimiter`.
|
|
31
23
|
*/
|
|
32
24
|
pathsDelimiterPattern?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Shell scripts that can be executed from the CLI, either individually or via the batch subcommand.
|
|
27
|
+
*/
|
|
28
|
+
shellScripts?: Record<string, string>;
|
|
33
29
|
/**
|
|
34
30
|
* A delimited string of key-value pairs declaratively specifying variables &
|
|
35
31
|
* values to be loaded in addition to any dotenv files.
|
|
@@ -62,13 +58,9 @@ type GetDotenvDynamicFunction = (vars: ProcessEnv) => string | undefined;
|
|
|
62
58
|
type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
|
|
63
59
|
type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
|
|
64
60
|
/**
|
|
65
|
-
* Options passed programmatically to `getDotenv
|
|
61
|
+
* Options passed programmatically to `getDotenv`.
|
|
66
62
|
*/
|
|
67
63
|
interface GetDotenvOptions {
|
|
68
|
-
/**
|
|
69
|
-
* log internals to logger
|
|
70
|
-
*/
|
|
71
|
-
debug?: boolean;
|
|
72
64
|
/**
|
|
73
65
|
* default target environment (used if `env` is not provided)
|
|
74
66
|
*/
|
|
@@ -76,7 +68,7 @@ interface GetDotenvOptions {
|
|
|
76
68
|
/**
|
|
77
69
|
* token indicating a dotenv file
|
|
78
70
|
*/
|
|
79
|
-
dotenvToken
|
|
71
|
+
dotenvToken: string;
|
|
80
72
|
/**
|
|
81
73
|
* path to JS module default-exporting an object keyed to dynamic variable functions
|
|
82
74
|
*/
|
|
@@ -129,10 +121,6 @@ interface GetDotenvOptions {
|
|
|
129
121
|
* filename token indicating private variables
|
|
130
122
|
*/
|
|
131
123
|
privateToken?: string;
|
|
132
|
-
/**
|
|
133
|
-
* Shell scripts that can be executed from the CLI, either individually or via the batch subcommand.
|
|
134
|
-
*/
|
|
135
|
-
shellScripts?: Record<string, string>;
|
|
136
124
|
/**
|
|
137
125
|
* explicit variables to include
|
|
138
126
|
*/
|
|
@@ -190,11 +178,23 @@ type GetDotenvCliPostHookCallback = (dotenv: ProcessEnv) => Promise<void>;
|
|
|
190
178
|
* sets defaults that can be overridden by local `getdotenv.config.json` in
|
|
191
179
|
* projects that import the CLI.
|
|
192
180
|
*/
|
|
193
|
-
interface GetDotenvCliGenerateOptions extends
|
|
181
|
+
interface GetDotenvCliGenerateOptions extends GetDotenvCliOptions {
|
|
182
|
+
/**
|
|
183
|
+
* CLI alias. Should align with the `bin` property in `package.json`.
|
|
184
|
+
*/
|
|
185
|
+
alias: string;
|
|
186
|
+
/**
|
|
187
|
+
* Cli description (appears in CLI help).
|
|
188
|
+
*/
|
|
189
|
+
description: string;
|
|
190
|
+
/**
|
|
191
|
+
* The `import.meta.url` of the module generating the CLI.
|
|
192
|
+
*/
|
|
193
|
+
importMetaUrl: string;
|
|
194
194
|
/**
|
|
195
195
|
* Logger object (defaults to console)
|
|
196
196
|
*/
|
|
197
|
-
logger
|
|
197
|
+
logger: Logger;
|
|
198
198
|
/**
|
|
199
199
|
* Mutates inbound options & executes side effects within the `getDotenv`
|
|
200
200
|
* context before executing CLI commands.
|
|
@@ -210,7 +210,7 @@ interface GetDotenvCliGenerateOptions extends Omit<GetDotenvCliOptions, 'env'> {
|
|
|
210
210
|
/**
|
|
211
211
|
* Generate a Commander CLI Command for get-dotenv.
|
|
212
212
|
*/
|
|
213
|
-
declare const generateGetDotenvCli: (
|
|
213
|
+
declare const generateGetDotenvCli: (customOptions: Pick<GetDotenvCliGenerateOptions, 'importMetaUrl'> & Partial<Omit<GetDotenvCliGenerateOptions, 'importMetaUrl'>>) => Promise<Command>;
|
|
214
214
|
|
|
215
215
|
/**
|
|
216
216
|
* Asynchronously process dotenv files of the form `.env[.<ENV>][.<PRIVATE_TOKEN>]`
|
|
@@ -218,6 +218,6 @@ declare const generateGetDotenvCli: ({ logger, preHook, postHook, ...cliOptionsC
|
|
|
218
218
|
* @param options - `GetDotenvOptions` object
|
|
219
219
|
* @returns The combined parsed dotenv object.
|
|
220
220
|
*/
|
|
221
|
-
declare const getDotenv: (options?: GetDotenvOptions) => Promise<ProcessEnv>;
|
|
221
|
+
declare const getDotenv: (options?: Partial<GetDotenvOptions>) => Promise<ProcessEnv>;
|
|
222
222
|
|
|
223
223
|
export { type GetDotenvDynamic, type GetDotenvOptions, type ProcessEnv, dotenvExpand, dotenvExpandAll, dotenvExpandFromProcessEnv, generateGetDotenvCli, getDotenv };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import require$$0 from 'events';
|
|
2
2
|
import require$$1 from 'child_process';
|
|
3
|
-
import require$$0$1
|
|
3
|
+
import require$$0$1 from 'path';
|
|
4
4
|
import require$$0$2 from 'fs';
|
|
5
5
|
import require$$4$1 from 'process';
|
|
6
6
|
import { Buffer as Buffer$1 } from 'node:buffer';
|
|
@@ -17,7 +17,7 @@ import require$$0$4 from 'constants';
|
|
|
17
17
|
import require$$0$5 from 'util';
|
|
18
18
|
import require$$5 from 'assert';
|
|
19
19
|
import { webcrypto } from 'node:crypto';
|
|
20
|
-
import url, { fileURLToPath as fileURLToPath$1 } from 'url';
|
|
20
|
+
import url, { resolve, fileURLToPath as fileURLToPath$1 } from 'url';
|
|
21
21
|
import fsPromises from 'node:fs/promises';
|
|
22
22
|
import require$$2 from 'os';
|
|
23
23
|
import require$$3 from 'crypto';
|
|
@@ -25700,115 +25700,27 @@ async function findUp(name, {
|
|
|
25700
25700
|
}
|
|
25701
25701
|
}
|
|
25702
25702
|
|
|
25703
|
-
function findUpSync(name, {
|
|
25704
|
-
cwd = process$3.cwd(),
|
|
25705
|
-
type = 'file',
|
|
25706
|
-
stopAt,
|
|
25707
|
-
} = {}) {
|
|
25708
|
-
let directory = path$s.resolve(toPath$1(cwd) ?? '');
|
|
25709
|
-
const {root} = path$s.parse(directory);
|
|
25710
|
-
stopAt = path$s.resolve(directory, toPath$1(stopAt) ?? root);
|
|
25711
|
-
|
|
25712
|
-
while (directory && directory !== stopAt && directory !== root) {
|
|
25713
|
-
const filePath = path$s.isAbsolute(name) ? name : path$s.join(directory, name);
|
|
25714
|
-
|
|
25715
|
-
try {
|
|
25716
|
-
const stats = fs$v.statSync(filePath, {throwIfNoEntry: false});
|
|
25717
|
-
if ((type === 'file' && stats?.isFile()) || (type === 'directory' && stats?.isDirectory())) {
|
|
25718
|
-
return filePath;
|
|
25719
|
-
}
|
|
25720
|
-
} catch {}
|
|
25721
|
-
|
|
25722
|
-
directory = path$s.dirname(directory);
|
|
25723
|
-
}
|
|
25724
|
-
}
|
|
25725
|
-
|
|
25726
25703
|
async function packageDirectory({cwd} = {}) {
|
|
25727
25704
|
const filePath = await findUp('package.json', {cwd});
|
|
25728
25705
|
return filePath && path$s.dirname(filePath);
|
|
25729
25706
|
}
|
|
25730
25707
|
|
|
25731
|
-
|
|
25732
|
-
const filePath = findUpSync('package.json', {cwd});
|
|
25733
|
-
return filePath && path$s.dirname(filePath);
|
|
25734
|
-
}
|
|
25735
|
-
|
|
25736
|
-
const __dirname = dirname(fileURLToPath$1(import.meta.url));
|
|
25737
|
-
/**
|
|
25738
|
-
* Absolute path to the global default CLI options file `getdotenv.config.json`.
|
|
25739
|
-
*
|
|
25740
|
-
* If `get-dotenv` is imported directly, this is the `getdotenv.config.json`
|
|
25741
|
-
* file at the root of the `get-dotenv` package.
|
|
25742
|
-
*
|
|
25743
|
-
* If `get-dotenv` has been used to generate a CLI which is in turn being
|
|
25744
|
-
* imported, this is the `getdotenv.config.json` file at the root of the
|
|
25745
|
-
* imported package.
|
|
25746
|
-
*/
|
|
25747
|
-
const defaultGetDotenvCliOptionsGlobalPath = resolve(__dirname, '../getdotenv.config.json');
|
|
25748
|
-
/**
|
|
25749
|
-
* Global default CLI options.
|
|
25750
|
-
*
|
|
25751
|
-
* If `get-dotenv` is imported directly, these are derived from the
|
|
25752
|
-
* `getdotenv.config.json` file at the root of the `get-dotenv` package.
|
|
25753
|
-
*
|
|
25754
|
-
* If `get-dotenv` has been used to generate a CLI which is in turn being
|
|
25755
|
-
* imported, they are derived from the `getdotenv.config.json` file at the root
|
|
25756
|
-
* of the imported package.
|
|
25757
|
-
*
|
|
25758
|
-
* @defaultValue `{}`
|
|
25759
|
-
*/
|
|
25760
|
-
const defaultGetDotenvCliOptionsGlobal = {
|
|
25708
|
+
const baseGetDotenvCliOptions = {
|
|
25761
25709
|
dotenvToken: '.env',
|
|
25762
25710
|
loadProcess: true,
|
|
25711
|
+
logger: console,
|
|
25763
25712
|
paths: './',
|
|
25764
25713
|
pathsDelimiter: ' ',
|
|
25765
25714
|
privateToken: 'local',
|
|
25766
|
-
shellScripts: {
|
|
25715
|
+
shellScripts: {
|
|
25716
|
+
'git-status': 'git branch --show-current && git status -s -u',
|
|
25717
|
+
},
|
|
25767
25718
|
vars: '',
|
|
25768
25719
|
varsAssignor: '=',
|
|
25769
25720
|
varsDelimiter: ' ',
|
|
25770
|
-
...(fs$a.existsSync(defaultGetDotenvCliOptionsGlobalPath)
|
|
25771
|
-
? JSON.parse(fs$a.readFileSync(defaultGetDotenvCliOptionsGlobalPath).toString())
|
|
25772
|
-
: {}),
|
|
25773
25721
|
};
|
|
25774
|
-
/**
|
|
25775
|
-
* Path to the nearest package directory.
|
|
25776
|
-
*/
|
|
25777
|
-
const pkgDir = packageDirectorySync();
|
|
25778
|
-
if (!pkgDir)
|
|
25779
|
-
throw new Error('Package directory not found.');
|
|
25780
|
-
/**
|
|
25781
|
-
* Absolute path to the local default CLI options file `getdotenv.config.json`.
|
|
25782
|
-
*/
|
|
25783
|
-
const defaultGetDotenvCliOptionsLocalPath = resolve(pkgDir, 'getdotenv.config.json');
|
|
25784
|
-
/**
|
|
25785
|
-
* Local default CLI options.
|
|
25786
|
-
*
|
|
25787
|
-
* @defaultValue `{}`
|
|
25788
|
-
*/
|
|
25789
|
-
const defaultGetDotenvCliOptionsLocal = (fs$a.existsSync(defaultGetDotenvCliOptionsLocalPath)
|
|
25790
|
-
? JSON.parse(fs$a.readFileSync(defaultGetDotenvCliOptionsLocalPath).toString())
|
|
25791
|
-
: {});
|
|
25792
25722
|
|
|
25793
|
-
|
|
25794
|
-
* Merges two sets of `getDotenv` options and eliminates any falsy `vars`. `target` takes precedence.
|
|
25795
|
-
*
|
|
25796
|
-
* @param target - Target options object (takes precedence).
|
|
25797
|
-
* @param source - Source options object (provides defaults).
|
|
25798
|
-
* @returns Merged options object.
|
|
25799
|
-
*/
|
|
25800
|
-
const mergeGetDotenvOptions = (target = {}, source = {}) => ({
|
|
25801
|
-
...source,
|
|
25802
|
-
...target,
|
|
25803
|
-
shellScripts: {
|
|
25804
|
-
...(source.shellScripts ?? {}),
|
|
25805
|
-
...(target.shellScripts ?? {}),
|
|
25806
|
-
},
|
|
25807
|
-
vars: _.pickBy({
|
|
25808
|
-
...(source.vars ?? {}),
|
|
25809
|
-
...(target.vars ?? {}),
|
|
25810
|
-
}, (v) => !!v),
|
|
25811
|
-
});
|
|
25723
|
+
const getDotenvOptionsFilename = 'getdotenv.config.json';
|
|
25812
25724
|
/**
|
|
25813
25725
|
* Converts programmatic CLI options to `getDotenv` options.
|
|
25814
25726
|
*
|
|
@@ -25816,8 +25728,8 @@ const mergeGetDotenvOptions = (target = {}, source = {}) => ({
|
|
|
25816
25728
|
*
|
|
25817
25729
|
* @returns `getDotenv` options.
|
|
25818
25730
|
*/
|
|
25819
|
-
const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, ...rest }
|
|
25820
|
-
...rest,
|
|
25731
|
+
const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, ...rest }) => ({
|
|
25732
|
+
..._.omit(rest, ['debug', 'shellScripts']),
|
|
25821
25733
|
paths: paths?.split(pathsDelimiterPattern
|
|
25822
25734
|
? RegExp(pathsDelimiterPattern)
|
|
25823
25735
|
: pathsDelimiter ?? ' ') ?? [],
|
|
@@ -25829,18 +25741,20 @@ const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPatt
|
|
|
25829
25741
|
? RegExp(varsAssignorPattern)
|
|
25830
25742
|
: varsAssignor ?? '='))),
|
|
25831
25743
|
});
|
|
25832
|
-
|
|
25833
|
-
|
|
25834
|
-
|
|
25835
|
-
|
|
25836
|
-
|
|
25837
|
-
|
|
25838
|
-
|
|
25839
|
-
|
|
25840
|
-
|
|
25841
|
-
|
|
25842
|
-
|
|
25843
|
-
})
|
|
25744
|
+
const resolveGetDotenvOptions = async (customOptions) => {
|
|
25745
|
+
const localPkgDir = await packageDirectory();
|
|
25746
|
+
const localOptionsPath = localPkgDir
|
|
25747
|
+
? resolve(localPkgDir, getDotenvOptionsFilename)
|
|
25748
|
+
: undefined;
|
|
25749
|
+
const localOptions = (localOptionsPath && (await fs$a.exists(localOptionsPath))
|
|
25750
|
+
? JSON.parse((await fs$a.readFile(localOptionsPath)).toString())
|
|
25751
|
+
: {});
|
|
25752
|
+
const result = _.defaultsDeep(customOptions, getDotenvCliOptions2Options(_.defaultsDeep(localOptions, baseGetDotenvCliOptions)));
|
|
25753
|
+
return {
|
|
25754
|
+
...result,
|
|
25755
|
+
vars: _.pickBy(result.vars ?? {}, (v) => !!v),
|
|
25756
|
+
};
|
|
25757
|
+
};
|
|
25844
25758
|
|
|
25845
25759
|
var main$1 = {exports: {}};
|
|
25846
25760
|
|
|
@@ -26310,7 +26224,7 @@ const readDotenv = async (path) => {
|
|
|
26310
26224
|
*/
|
|
26311
26225
|
const getDotenv = async (options = {}) => {
|
|
26312
26226
|
// Apply defaults.
|
|
26313
|
-
const { defaultEnv, dotenvToken = '.env', dynamicPath, env, excludeDynamic = false, excludeEnv = false, excludeGlobal = false, excludePrivate = false, excludePublic = false, loadProcess = false, log = false, logger = console, outputPath, paths = [], privateToken = 'local', vars = {}, } =
|
|
26227
|
+
const { defaultEnv, dotenvToken = '.env', dynamicPath, env, excludeDynamic = false, excludeEnv = false, excludeGlobal = false, excludePrivate = false, excludePublic = false, loadProcess = false, log = false, logger = console, outputPath, paths = [], privateToken = 'local', vars = {}, } = await resolveGetDotenvOptions(options);
|
|
26314
26228
|
// Read .env files.
|
|
26315
26229
|
const loaded = paths.length
|
|
26316
26230
|
? await paths.reduce(async (e, p) => {
|
|
@@ -34191,7 +34105,7 @@ const cmdCommand$1 = new Command()
|
|
|
34191
34105
|
throw new Error(`unable to resolve parent command`);
|
|
34192
34106
|
if (!thisCommand.parent.parent)
|
|
34193
34107
|
throw new Error(`unable to resolve root command`);
|
|
34194
|
-
const {
|
|
34108
|
+
const { getDotenvCliOptions: { logger = console, shellScripts }, } = thisCommand.parent.parent;
|
|
34195
34109
|
const { ignoreErrors, globs, list, pkgCwd, rootPath } = thisCommand.parent.opts();
|
|
34196
34110
|
// Execute shell command.
|
|
34197
34111
|
{
|
|
@@ -34222,7 +34136,7 @@ const batchCommand = new Command()
|
|
|
34222
34136
|
.hook('preSubcommand', async (thisCommand) => {
|
|
34223
34137
|
if (!thisCommand.parent)
|
|
34224
34138
|
throw new Error(`unable to resolve root command`);
|
|
34225
|
-
const {
|
|
34139
|
+
const { getDotenvCliOptions: { logger = console, shellScripts }, } = thisCommand.parent;
|
|
34226
34140
|
const { command, ignoreErrors, globs, list, pkgCwd, rootPath } = thisCommand.opts();
|
|
34227
34141
|
if (command && thisCommand.args.length) {
|
|
34228
34142
|
logger.error(`--command option conflicts with cmd subcommand.`);
|
|
@@ -34253,7 +34167,7 @@ const cmdCommand = new Command()
|
|
|
34253
34167
|
return;
|
|
34254
34168
|
if (!thisCommand.parent)
|
|
34255
34169
|
throw new Error('parent command not found');
|
|
34256
|
-
const {
|
|
34170
|
+
const { getDotenvCliOptions: { debug, logger = console, shellScripts }, } = thisCommand.parent;
|
|
34257
34171
|
const command = thisCommand.args.join(' ');
|
|
34258
34172
|
const shellCommand = shellScripts?.[command] ?? command;
|
|
34259
34173
|
if (debug)
|
|
@@ -34265,19 +34179,50 @@ const cmdCommand = new Command()
|
|
|
34265
34179
|
});
|
|
34266
34180
|
|
|
34267
34181
|
/**
|
|
34268
|
-
*
|
|
34182
|
+
* Resolve `GetDotenvCliGenerateOptions` from `import.meta.url` and custom options.
|
|
34269
34183
|
*/
|
|
34270
|
-
const
|
|
34271
|
-
const
|
|
34272
|
-
...
|
|
34273
|
-
|
|
34274
|
-
|
|
34275
|
-
shellScripts: {
|
|
34276
|
-
...(defaultGetDotenvCliOptionsGlobal.shellScripts ?? {}),
|
|
34277
|
-
...(cliOptionsCustom.shellScripts ?? {}),
|
|
34278
|
-
...(defaultGetDotenvCliOptionsLocal.shellScripts ?? {}),
|
|
34279
|
-
},
|
|
34184
|
+
const resolveGetDotenvCliGenerateOptions = async ({ importMetaUrl, ...customOptions }) => {
|
|
34185
|
+
const baseOptions = {
|
|
34186
|
+
...baseGetDotenvCliOptions,
|
|
34187
|
+
alias: 'getdotenv',
|
|
34188
|
+
description: 'Base CLI.',
|
|
34280
34189
|
};
|
|
34190
|
+
const globalPkgDir = importMetaUrl
|
|
34191
|
+
? await packageDirectory({
|
|
34192
|
+
cwd: fileURLToPath$1(importMetaUrl),
|
|
34193
|
+
})
|
|
34194
|
+
: undefined;
|
|
34195
|
+
const globalOptionsPath = globalPkgDir
|
|
34196
|
+
? resolve(globalPkgDir, getDotenvOptionsFilename)
|
|
34197
|
+
: undefined;
|
|
34198
|
+
const globalOptions = (globalOptionsPath && (await fs$a.exists(globalOptionsPath))
|
|
34199
|
+
? JSON.parse((await fs$a.readFile(globalOptionsPath)).toString())
|
|
34200
|
+
: {});
|
|
34201
|
+
const localPkgDir = await packageDirectory();
|
|
34202
|
+
const localOptionsPath = localPkgDir
|
|
34203
|
+
? resolve(localPkgDir, getDotenvOptionsFilename)
|
|
34204
|
+
: undefined;
|
|
34205
|
+
const localOptions = (localOptionsPath &&
|
|
34206
|
+
localOptionsPath !== globalOptionsPath &&
|
|
34207
|
+
(await fs$a.exists(localOptionsPath))
|
|
34208
|
+
? JSON.parse((await fs$a.readFile(localOptionsPath)).toString())
|
|
34209
|
+
: {});
|
|
34210
|
+
return _.defaultsDeep(customOptions, localOptions, globalOptions, baseOptions);
|
|
34211
|
+
};
|
|
34212
|
+
|
|
34213
|
+
const resolveExclusion = (exclude, excludeOff, defaultValue) => exclude ? true : excludeOff ? undefined : defaultValue ? true : undefined;
|
|
34214
|
+
const resolveExclusionAll = (exclude, excludeOff, defaultValue, excludeAll, excludeAllOff) => excludeAll && !excludeOff
|
|
34215
|
+
? true
|
|
34216
|
+
: excludeAllOff && !exclude
|
|
34217
|
+
? undefined
|
|
34218
|
+
: defaultValue
|
|
34219
|
+
? true
|
|
34220
|
+
: undefined;
|
|
34221
|
+
/**
|
|
34222
|
+
* Generate a Commander CLI Command for get-dotenv.
|
|
34223
|
+
*/
|
|
34224
|
+
const generateGetDotenvCli = async (customOptions) => {
|
|
34225
|
+
const { alias, debug, defaultEnv, description, dotenvToken, dynamicPath, env, excludeDynamic, excludeEnv, excludeGlobal, excludePrivate, excludePublic, loadProcess, log, logger, outputPath, paths, pathsDelimiter, pathsDelimiterPattern, postHook, preHook, privateToken, shellScripts, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, } = await resolveGetDotenvCliGenerateOptions(customOptions);
|
|
34281
34226
|
const excludeAll = !!excludeDynamic &&
|
|
34282
34227
|
((!!excludeEnv && !!excludeGlobal) ||
|
|
34283
34228
|
(!!excludePrivate && !!excludePublic));
|
|
@@ -34330,67 +34275,50 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
|
|
|
34330
34275
|
.addCommand(batchCommand)
|
|
34331
34276
|
.addCommand(cmdCommand, { isDefault: true })
|
|
34332
34277
|
.hook('preSubcommand', async (thisCommand) => {
|
|
34333
|
-
|
|
34334
|
-
|
|
34335
|
-
|
|
34336
|
-
|
|
34337
|
-
|
|
34338
|
-
|
|
34339
|
-
|
|
34340
|
-
|
|
34341
|
-
|
|
34342
|
-
|
|
34278
|
+
// Get parent command GetDotenvCliOptions.
|
|
34279
|
+
const parentGetDotenvCliOptions = process.env.getDotenvCliOptions
|
|
34280
|
+
? JSON.parse(process.env.getDotenvCliOptions)
|
|
34281
|
+
: undefined;
|
|
34282
|
+
// Get raw CLI options from commander.
|
|
34283
|
+
const rawCliOptions = thisCommand.opts();
|
|
34284
|
+
// Extract current GetDotenvCliOptions from raw CLI options.
|
|
34285
|
+
const { command, debugOff, excludeAll, excludeAllOff, excludeDynamicOff, excludeEnvOff, excludeGlobalOff, excludePrivateOff, excludePublicOff, loadProcessOff, logOff, shellScripts, ...rawCliOptionsRest } = rawCliOptions;
|
|
34286
|
+
const currentGetDotenvCliOptions = rawCliOptionsRest;
|
|
34287
|
+
if (shellScripts)
|
|
34288
|
+
currentGetDotenvCliOptions.shellScripts = JSON.parse(shellScripts);
|
|
34289
|
+
// Merge current & parent GetDotenvCliOptions.
|
|
34290
|
+
const mergedGetDotenvCliOptions = _.defaultsDeep(currentGetDotenvCliOptions, parentGetDotenvCliOptions ?? {});
|
|
34343
34291
|
// Resolve flags.
|
|
34344
|
-
|
|
34345
|
-
|
|
34346
|
-
|
|
34347
|
-
|
|
34348
|
-
|
|
34349
|
-
|
|
34350
|
-
|
|
34351
|
-
|
|
34352
|
-
|
|
34353
|
-
|
|
34354
|
-
|
|
34355
|
-
|
|
34356
|
-
|
|
34357
|
-
|
|
34358
|
-
|
|
34359
|
-
|
|
34360
|
-
|
|
34361
|
-
cliOptions.excludeGlobal = resolveExclusionAll(cliOptions.excludeGlobal, excludeGlobalOff, excludeGlobal);
|
|
34362
|
-
cliOptions.excludePrivate = resolveExclusionAll(cliOptions.excludePrivate, excludePrivateOff, excludePrivate);
|
|
34363
|
-
cliOptions.excludePublic = resolveExclusionAll(cliOptions.excludePublic, excludePublicOff, excludePublic);
|
|
34364
|
-
cliOptions.log = resolveExclusion(cliOptions.log, logOff, log);
|
|
34365
|
-
cliOptions.loadProcess = resolveExclusion(cliOptions.loadProcess, loadProcessOff, loadProcess);
|
|
34366
|
-
if (cliOptions.debug)
|
|
34367
|
-
logger.log('\n*** cli options after default resolution ***\n', {
|
|
34368
|
-
cliOptions,
|
|
34292
|
+
mergedGetDotenvCliOptions.debug = resolveExclusion(mergedGetDotenvCliOptions.debug, debugOff, debug);
|
|
34293
|
+
mergedGetDotenvCliOptions.excludeDynamic = resolveExclusionAll(mergedGetDotenvCliOptions.excludeDynamic, excludeDynamicOff, excludeDynamic, excludeAll, excludeAllOff);
|
|
34294
|
+
mergedGetDotenvCliOptions.excludeEnv = resolveExclusionAll(mergedGetDotenvCliOptions.excludeEnv, excludeEnvOff, excludeEnv, excludeAll, excludeAllOff);
|
|
34295
|
+
mergedGetDotenvCliOptions.excludeGlobal = resolveExclusionAll(mergedGetDotenvCliOptions.excludeGlobal, excludeGlobalOff, excludeGlobal, excludeAll, excludeAllOff);
|
|
34296
|
+
mergedGetDotenvCliOptions.excludePrivate = resolveExclusionAll(mergedGetDotenvCliOptions.excludePrivate, excludePrivateOff, excludePrivate, excludeAll, excludeAllOff);
|
|
34297
|
+
mergedGetDotenvCliOptions.excludePublic = resolveExclusionAll(mergedGetDotenvCliOptions.excludePublic, excludePublicOff, excludePublic, excludeAll, excludeAllOff);
|
|
34298
|
+
mergedGetDotenvCliOptions.log = resolveExclusion(mergedGetDotenvCliOptions.log, logOff, log);
|
|
34299
|
+
mergedGetDotenvCliOptions.loadProcess = resolveExclusion(mergedGetDotenvCliOptions.loadProcess, loadProcessOff, loadProcess);
|
|
34300
|
+
if (mergedGetDotenvCliOptions.debug && parentGetDotenvCliOptions)
|
|
34301
|
+
logger.debug('\n*** parent command GetDotenvCliOptions ***\n', parentGetDotenvCliOptions);
|
|
34302
|
+
if (mergedGetDotenvCliOptions.debug)
|
|
34303
|
+
logger.debug('\n*** current command raw options ***\n', rawCliOptions);
|
|
34304
|
+
if (mergedGetDotenvCliOptions.debug)
|
|
34305
|
+
logger.debug('\n*** current command GetDotenvCliOptions ***\n', currentGetDotenvCliOptions);
|
|
34306
|
+
if (mergedGetDotenvCliOptions.debug)
|
|
34307
|
+
logger.debug('\n*** merged GetDotenvCliOptions ***\n', {
|
|
34308
|
+
mergedGetDotenvCliOptions,
|
|
34369
34309
|
});
|
|
34370
34310
|
// Execute pre-hook.
|
|
34371
34311
|
if (preHook) {
|
|
34372
|
-
await preHook(
|
|
34373
|
-
if (
|
|
34374
|
-
logger.
|
|
34312
|
+
await preHook(mergedGetDotenvCliOptions);
|
|
34313
|
+
if (mergedGetDotenvCliOptions.debug)
|
|
34314
|
+
logger.debug('\n*** GetDotenvCliOptions after pre-hook ***\n', mergedGetDotenvCliOptions);
|
|
34375
34315
|
}
|
|
34376
|
-
//
|
|
34377
|
-
|
|
34378
|
-
? JSON.parse(process.env.getDotenvOptions)
|
|
34379
|
-
: {});
|
|
34380
|
-
const cliGetDotenvOptions = getDotenvCliOptions2Options(cliOptions);
|
|
34381
|
-
const getDotenvOptions = mergeGetDotenvOptions(cliGetDotenvOptions, parentGetdotenvOptions);
|
|
34382
|
-
if (cliOptions.debug)
|
|
34383
|
-
logger.log('\n*** getdotenv option resolution ***\n', {
|
|
34384
|
-
parentGetdotenvOptions,
|
|
34385
|
-
cliGetDotenvOptions,
|
|
34386
|
-
getDotenvOptions,
|
|
34387
|
-
});
|
|
34316
|
+
// Persist GetDotenvCliOptions in command for subcommand access.
|
|
34317
|
+
_.set(thisCommand, 'getDotenvCliOptions', mergedGetDotenvCliOptions);
|
|
34388
34318
|
// Execute getdotenv.
|
|
34389
|
-
const
|
|
34390
|
-
|
|
34391
|
-
|
|
34392
|
-
if (cliOptions.debug)
|
|
34393
|
-
logger.log('\n*** resulting dotenv values ***\n', { dotenv });
|
|
34319
|
+
const dotenv = await getDotenv(getDotenvCliOptions2Options(mergedGetDotenvCliOptions));
|
|
34320
|
+
if (mergedGetDotenvCliOptions.debug)
|
|
34321
|
+
logger.debug('\n*** getDotenv output ***\n', dotenv);
|
|
34394
34322
|
// Execute post-hook.
|
|
34395
34323
|
if (postHook)
|
|
34396
34324
|
await postHook(dotenv);
|
|
@@ -34400,13 +34328,13 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
|
|
|
34400
34328
|
process.exit(0);
|
|
34401
34329
|
}
|
|
34402
34330
|
if (command) {
|
|
34403
|
-
const shellCommand =
|
|
34404
|
-
if (
|
|
34405
|
-
logger.
|
|
34331
|
+
const shellCommand = mergedGetDotenvCliOptions.shellScripts?.[command] ?? command;
|
|
34332
|
+
if (mergedGetDotenvCliOptions.debug)
|
|
34333
|
+
logger.debug('\n*** shell command ***\n', shellCommand);
|
|
34406
34334
|
await execaCommand(shellCommand, {
|
|
34407
34335
|
env: {
|
|
34408
34336
|
...process.env,
|
|
34409
|
-
|
|
34337
|
+
getDotenvCliOptions: JSON.stringify(_.omit(mergedGetDotenvCliOptions, ['logger'])),
|
|
34410
34338
|
},
|
|
34411
34339
|
shell: true,
|
|
34412
34340
|
stdio: 'inherit',
|
package/package.json
CHANGED