@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/index.cjs CHANGED
@@ -25,7 +25,6 @@ var require$$2 = require('os');
25
25
  var require$$3 = require('crypto');
26
26
  require('node:stream');
27
27
 
28
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
29
28
  // like String.prototype.search but returns the last index
30
29
  const searchLast = (str, rgx) => {
31
30
  const matches = Array.from(str.matchAll(rgx));
@@ -25703,115 +25702,27 @@ async function findUp(name, {
25703
25702
  }
25704
25703
  }
25705
25704
 
25706
- function findUpSync(name, {
25707
- cwd = process$3.cwd(),
25708
- type = 'file',
25709
- stopAt,
25710
- } = {}) {
25711
- let directory = path$s.resolve(toPath$1(cwd) ?? '');
25712
- const {root} = path$s.parse(directory);
25713
- stopAt = path$s.resolve(directory, toPath$1(stopAt) ?? root);
25714
-
25715
- while (directory && directory !== stopAt && directory !== root) {
25716
- const filePath = path$s.isAbsolute(name) ? name : path$s.join(directory, name);
25717
-
25718
- try {
25719
- const stats = fs$v.statSync(filePath, {throwIfNoEntry: false});
25720
- if ((type === 'file' && stats?.isFile()) || (type === 'directory' && stats?.isDirectory())) {
25721
- return filePath;
25722
- }
25723
- } catch {}
25724
-
25725
- directory = path$s.dirname(directory);
25726
- }
25727
- }
25728
-
25729
25705
  async function packageDirectory({cwd} = {}) {
25730
25706
  const filePath = await findUp('package.json', {cwd});
25731
25707
  return filePath && path$s.dirname(filePath);
25732
25708
  }
25733
25709
 
25734
- function packageDirectorySync({cwd} = {}) {
25735
- const filePath = findUpSync('package.json', {cwd});
25736
- return filePath && path$s.dirname(filePath);
25737
- }
25738
-
25739
- const __dirname$1 = require$$0$1.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
25740
- /**
25741
- * Absolute path to the global default CLI options file `getdotenv.config.json`.
25742
- *
25743
- * If `get-dotenv` is imported directly, this is the `getdotenv.config.json`
25744
- * file at the root of the `get-dotenv` package.
25745
- *
25746
- * If `get-dotenv` has been used to generate a CLI which is in turn being
25747
- * imported, this is the `getdotenv.config.json` file at the root of the
25748
- * imported package.
25749
- */
25750
- const defaultGetDotenvCliOptionsGlobalPath = require$$0$1.resolve(__dirname$1, '../getdotenv.config.json');
25751
- /**
25752
- * Global default CLI options.
25753
- *
25754
- * If `get-dotenv` is imported directly, these are derived from the
25755
- * `getdotenv.config.json` file at the root of the `get-dotenv` package.
25756
- *
25757
- * If `get-dotenv` has been used to generate a CLI which is in turn being
25758
- * imported, they are derived from the `getdotenv.config.json` file at the root
25759
- * of the imported package.
25760
- *
25761
- * @defaultValue `{}`
25762
- */
25763
- const defaultGetDotenvCliOptionsGlobal = {
25710
+ const baseGetDotenvCliOptions = {
25764
25711
  dotenvToken: '.env',
25765
25712
  loadProcess: true,
25713
+ logger: console,
25766
25714
  paths: './',
25767
25715
  pathsDelimiter: ' ',
25768
25716
  privateToken: 'local',
25769
- shellScripts: {},
25717
+ shellScripts: {
25718
+ 'git-status': 'git branch --show-current && git status -s -u',
25719
+ },
25770
25720
  vars: '',
25771
25721
  varsAssignor: '=',
25772
25722
  varsDelimiter: ' ',
25773
- ...(fs$a.existsSync(defaultGetDotenvCliOptionsGlobalPath)
25774
- ? JSON.parse(fs$a.readFileSync(defaultGetDotenvCliOptionsGlobalPath).toString())
25775
- : {}),
25776
25723
  };
25777
- /**
25778
- * Path to the nearest package directory.
25779
- */
25780
- const pkgDir = packageDirectorySync();
25781
- if (!pkgDir)
25782
- throw new Error('Package directory not found.');
25783
- /**
25784
- * Absolute path to the local default CLI options file `getdotenv.config.json`.
25785
- */
25786
- const defaultGetDotenvCliOptionsLocalPath = require$$0$1.resolve(pkgDir, 'getdotenv.config.json');
25787
- /**
25788
- * Local default CLI options.
25789
- *
25790
- * @defaultValue `{}`
25791
- */
25792
- const defaultGetDotenvCliOptionsLocal = (fs$a.existsSync(defaultGetDotenvCliOptionsLocalPath)
25793
- ? JSON.parse(fs$a.readFileSync(defaultGetDotenvCliOptionsLocalPath).toString())
25794
- : {});
25795
25724
 
25796
- /**
25797
- * Merges two sets of `getDotenv` options and eliminates any falsy `vars`. `target` takes precedence.
25798
- *
25799
- * @param target - Target options object (takes precedence).
25800
- * @param source - Source options object (provides defaults).
25801
- * @returns Merged options object.
25802
- */
25803
- const mergeGetDotenvOptions = (target = {}, source = {}) => ({
25804
- ...source,
25805
- ...target,
25806
- shellScripts: {
25807
- ...(source.shellScripts ?? {}),
25808
- ...(target.shellScripts ?? {}),
25809
- },
25810
- vars: _.pickBy({
25811
- ...(source.vars ?? {}),
25812
- ...(target.vars ?? {}),
25813
- }, (v) => !!v),
25814
- });
25725
+ const getDotenvOptionsFilename = 'getdotenv.config.json';
25815
25726
  /**
25816
25727
  * Converts programmatic CLI options to `getDotenv` options.
25817
25728
  *
@@ -25819,8 +25730,8 @@ const mergeGetDotenvOptions = (target = {}, source = {}) => ({
25819
25730
  *
25820
25731
  * @returns `getDotenv` options.
25821
25732
  */
25822
- const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, ...rest } = {}) => ({
25823
- ...rest,
25733
+ const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, ...rest }) => ({
25734
+ ..._.omit(rest, ['debug', 'shellScripts']),
25824
25735
  paths: paths?.split(pathsDelimiterPattern
25825
25736
  ? RegExp(pathsDelimiterPattern)
25826
25737
  : pathsDelimiter ?? ' ') ?? [],
@@ -25832,18 +25743,20 @@ const getDotenvCliOptions2Options = ({ paths, pathsDelimiter, pathsDelimiterPatt
25832
25743
  ? RegExp(varsAssignorPattern)
25833
25744
  : varsAssignor ?? '='))),
25834
25745
  });
25835
- /**
25836
- * Extracts default programmatic `getDotenv` options from the global & local
25837
- * CLI options defined in the respective `getdotenv.config.json` files.
25838
- */
25839
- const getDotenvDefaultOptions = getDotenvCliOptions2Options({
25840
- ...defaultGetDotenvCliOptionsGlobal,
25841
- ...defaultGetDotenvCliOptionsLocal,
25842
- shellScripts: {
25843
- ...(defaultGetDotenvCliOptionsGlobal.shellScripts ?? {}),
25844
- ...(defaultGetDotenvCliOptionsLocal.shellScripts ?? {}),
25845
- },
25846
- });
25746
+ const resolveGetDotenvOptions = async (customOptions) => {
25747
+ const localPkgDir = await packageDirectory();
25748
+ const localOptionsPath = localPkgDir
25749
+ ? url.resolve(localPkgDir, getDotenvOptionsFilename)
25750
+ : undefined;
25751
+ const localOptions = (localOptionsPath && (await fs$a.exists(localOptionsPath))
25752
+ ? JSON.parse((await fs$a.readFile(localOptionsPath)).toString())
25753
+ : {});
25754
+ const result = _.defaultsDeep(customOptions, getDotenvCliOptions2Options(_.defaultsDeep(localOptions, baseGetDotenvCliOptions)));
25755
+ return {
25756
+ ...result,
25757
+ vars: _.pickBy(result.vars ?? {}, (v) => !!v),
25758
+ };
25759
+ };
25847
25760
 
25848
25761
  var main$1 = {exports: {}};
25849
25762
 
@@ -26313,7 +26226,7 @@ const readDotenv = async (path) => {
26313
26226
  */
26314
26227
  const getDotenv = async (options = {}) => {
26315
26228
  // Apply defaults.
26316
- 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 = {}, } = mergeGetDotenvOptions(options, getDotenvDefaultOptions);
26229
+ 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);
26317
26230
  // Read .env files.
26318
26231
  const loaded = paths.length
26319
26232
  ? await paths.reduce(async (e, p) => {
@@ -34194,7 +34107,7 @@ const cmdCommand$1 = new Command()
34194
34107
  throw new Error(`unable to resolve parent command`);
34195
34108
  if (!thisCommand.parent.parent)
34196
34109
  throw new Error(`unable to resolve root command`);
34197
- const { getDotenvOptions: { logger = console, shellScripts }, } = thisCommand.parent.parent;
34110
+ const { getDotenvCliOptions: { logger = console, shellScripts }, } = thisCommand.parent.parent;
34198
34111
  const { ignoreErrors, globs, list, pkgCwd, rootPath } = thisCommand.parent.opts();
34199
34112
  // Execute shell command.
34200
34113
  {
@@ -34225,7 +34138,7 @@ const batchCommand = new Command()
34225
34138
  .hook('preSubcommand', async (thisCommand) => {
34226
34139
  if (!thisCommand.parent)
34227
34140
  throw new Error(`unable to resolve root command`);
34228
- const { getDotenvOptions: { logger = console, shellScripts }, } = thisCommand.parent;
34141
+ const { getDotenvCliOptions: { logger = console, shellScripts }, } = thisCommand.parent;
34229
34142
  const { command, ignoreErrors, globs, list, pkgCwd, rootPath } = thisCommand.opts();
34230
34143
  if (command && thisCommand.args.length) {
34231
34144
  logger.error(`--command option conflicts with cmd subcommand.`);
@@ -34256,7 +34169,7 @@ const cmdCommand = new Command()
34256
34169
  return;
34257
34170
  if (!thisCommand.parent)
34258
34171
  throw new Error('parent command not found');
34259
- const { getDotenvOptions: { debug, logger = console, shellScripts }, } = thisCommand.parent;
34172
+ const { getDotenvCliOptions: { debug, logger = console, shellScripts }, } = thisCommand.parent;
34260
34173
  const command = thisCommand.args.join(' ');
34261
34174
  const shellCommand = shellScripts?.[command] ?? command;
34262
34175
  if (debug)
@@ -34268,19 +34181,50 @@ const cmdCommand = new Command()
34268
34181
  });
34269
34182
 
34270
34183
  /**
34271
- * Generate a Commander CLI Command for get-dotenv.
34184
+ * Resolve `GetDotenvCliGenerateOptions` from `import.meta.url` and custom options.
34272
34185
  */
34273
- const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptionsCustom } = {}) => {
34274
- const { alias = 'getdotenv', debug, defaultEnv, description = 'Base CLI.', dotenvToken, dynamicPath, env, excludeDynamic, excludeEnv, excludeGlobal, excludePrivate, excludePublic, loadProcess, log, outputPath, paths, pathsDelimiter, pathsDelimiterPattern, privateToken, shellScripts, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, } = {
34275
- ...defaultGetDotenvCliOptionsGlobal,
34276
- ...cliOptionsCustom,
34277
- ...defaultGetDotenvCliOptionsLocal,
34278
- shellScripts: {
34279
- ...(defaultGetDotenvCliOptionsGlobal.shellScripts ?? {}),
34280
- ...(cliOptionsCustom.shellScripts ?? {}),
34281
- ...(defaultGetDotenvCliOptionsLocal.shellScripts ?? {}),
34282
- },
34186
+ const resolveGetDotenvCliGenerateOptions = async ({ importMetaUrl, ...customOptions }) => {
34187
+ const baseOptions = {
34188
+ ...baseGetDotenvCliOptions,
34189
+ alias: 'getdotenv',
34190
+ description: 'Base CLI.',
34283
34191
  };
34192
+ const globalPkgDir = importMetaUrl
34193
+ ? await packageDirectory({
34194
+ cwd: url.fileURLToPath(importMetaUrl),
34195
+ })
34196
+ : undefined;
34197
+ const globalOptionsPath = globalPkgDir
34198
+ ? url.resolve(globalPkgDir, getDotenvOptionsFilename)
34199
+ : undefined;
34200
+ const globalOptions = (globalOptionsPath && (await fs$a.exists(globalOptionsPath))
34201
+ ? JSON.parse((await fs$a.readFile(globalOptionsPath)).toString())
34202
+ : {});
34203
+ const localPkgDir = await packageDirectory();
34204
+ const localOptionsPath = localPkgDir
34205
+ ? url.resolve(localPkgDir, getDotenvOptionsFilename)
34206
+ : undefined;
34207
+ const localOptions = (localOptionsPath &&
34208
+ localOptionsPath !== globalOptionsPath &&
34209
+ (await fs$a.exists(localOptionsPath))
34210
+ ? JSON.parse((await fs$a.readFile(localOptionsPath)).toString())
34211
+ : {});
34212
+ return _.defaultsDeep(customOptions, localOptions, globalOptions, baseOptions);
34213
+ };
34214
+
34215
+ const resolveExclusion = (exclude, excludeOff, defaultValue) => exclude ? true : excludeOff ? undefined : defaultValue ? true : undefined;
34216
+ const resolveExclusionAll = (exclude, excludeOff, defaultValue, excludeAll, excludeAllOff) => excludeAll && !excludeOff
34217
+ ? true
34218
+ : excludeAllOff && !exclude
34219
+ ? undefined
34220
+ : defaultValue
34221
+ ? true
34222
+ : undefined;
34223
+ /**
34224
+ * Generate a Commander CLI Command for get-dotenv.
34225
+ */
34226
+ const generateGetDotenvCli = async (customOptions) => {
34227
+ 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);
34284
34228
  const excludeAll = !!excludeDynamic &&
34285
34229
  ((!!excludeEnv && !!excludeGlobal) ||
34286
34230
  (!!excludePrivate && !!excludePublic));
@@ -34333,67 +34277,50 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34333
34277
  .addCommand(batchCommand)
34334
34278
  .addCommand(cmdCommand, { isDefault: true })
34335
34279
  .hook('preSubcommand', async (thisCommand) => {
34336
- const rawOptions = thisCommand.opts();
34337
- if (rawOptions.debug)
34338
- logger.log('\n*** raw cli options ***\n', { rawOptions });
34339
- // Load options.
34340
- const { command, debugOff, excludeAll, excludeAllOff, excludeDynamicOff, excludeEnvOff, excludeGlobalOff, excludePrivateOff, excludePublicOff, loadProcessOff, logOff, ...cliOptions } = {
34341
- ...rawOptions,
34342
- shellScripts: rawOptions.shellScripts
34343
- ? JSON.parse(rawOptions.shellScripts)
34344
- : undefined,
34345
- };
34280
+ // Get parent command GetDotenvCliOptions.
34281
+ const parentGetDotenvCliOptions = process.env.getDotenvCliOptions
34282
+ ? JSON.parse(process.env.getDotenvCliOptions)
34283
+ : undefined;
34284
+ // Get raw CLI options from commander.
34285
+ const rawCliOptions = thisCommand.opts();
34286
+ // Extract current GetDotenvCliOptions from raw CLI options.
34287
+ const { command, debugOff, excludeAll, excludeAllOff, excludeDynamicOff, excludeEnvOff, excludeGlobalOff, excludePrivateOff, excludePublicOff, loadProcessOff, logOff, shellScripts, ...rawCliOptionsRest } = rawCliOptions;
34288
+ const currentGetDotenvCliOptions = rawCliOptionsRest;
34289
+ if (shellScripts)
34290
+ currentGetDotenvCliOptions.shellScripts = JSON.parse(shellScripts);
34291
+ // Merge current & parent GetDotenvCliOptions.
34292
+ const mergedGetDotenvCliOptions = _.defaultsDeep(currentGetDotenvCliOptions, parentGetDotenvCliOptions ?? {});
34346
34293
  // Resolve flags.
34347
- const resolveExclusion = (exclude, excludeOff, defaultValue) => exclude
34348
- ? true
34349
- : excludeOff
34350
- ? undefined
34351
- : defaultValue
34352
- ? true
34353
- : undefined;
34354
- const resolveExclusionAll = (exclude, excludeOff, defaultValue) => excludeAll && !excludeOff
34355
- ? true
34356
- : excludeAllOff && !exclude
34357
- ? undefined
34358
- : defaultValue
34359
- ? true
34360
- : undefined;
34361
- cliOptions.debug = resolveExclusion(cliOptions.debug, debugOff, debug);
34362
- cliOptions.excludeDynamic = resolveExclusionAll(cliOptions.excludeDynamic, excludeDynamicOff, excludeDynamic);
34363
- cliOptions.excludeEnv = resolveExclusionAll(cliOptions.excludeEnv, excludeEnvOff, excludeEnv);
34364
- cliOptions.excludeGlobal = resolveExclusionAll(cliOptions.excludeGlobal, excludeGlobalOff, excludeGlobal);
34365
- cliOptions.excludePrivate = resolveExclusionAll(cliOptions.excludePrivate, excludePrivateOff, excludePrivate);
34366
- cliOptions.excludePublic = resolveExclusionAll(cliOptions.excludePublic, excludePublicOff, excludePublic);
34367
- cliOptions.log = resolveExclusion(cliOptions.log, logOff, log);
34368
- cliOptions.loadProcess = resolveExclusion(cliOptions.loadProcess, loadProcessOff, loadProcess);
34369
- if (cliOptions.debug)
34370
- logger.log('\n*** cli options after default resolution ***\n', {
34371
- cliOptions,
34294
+ mergedGetDotenvCliOptions.debug = resolveExclusion(mergedGetDotenvCliOptions.debug, debugOff, debug);
34295
+ mergedGetDotenvCliOptions.excludeDynamic = resolveExclusionAll(mergedGetDotenvCliOptions.excludeDynamic, excludeDynamicOff, excludeDynamic, excludeAll, excludeAllOff);
34296
+ mergedGetDotenvCliOptions.excludeEnv = resolveExclusionAll(mergedGetDotenvCliOptions.excludeEnv, excludeEnvOff, excludeEnv, excludeAll, excludeAllOff);
34297
+ mergedGetDotenvCliOptions.excludeGlobal = resolveExclusionAll(mergedGetDotenvCliOptions.excludeGlobal, excludeGlobalOff, excludeGlobal, excludeAll, excludeAllOff);
34298
+ mergedGetDotenvCliOptions.excludePrivate = resolveExclusionAll(mergedGetDotenvCliOptions.excludePrivate, excludePrivateOff, excludePrivate, excludeAll, excludeAllOff);
34299
+ mergedGetDotenvCliOptions.excludePublic = resolveExclusionAll(mergedGetDotenvCliOptions.excludePublic, excludePublicOff, excludePublic, excludeAll, excludeAllOff);
34300
+ mergedGetDotenvCliOptions.log = resolveExclusion(mergedGetDotenvCliOptions.log, logOff, log);
34301
+ mergedGetDotenvCliOptions.loadProcess = resolveExclusion(mergedGetDotenvCliOptions.loadProcess, loadProcessOff, loadProcess);
34302
+ if (mergedGetDotenvCliOptions.debug && parentGetDotenvCliOptions)
34303
+ logger.debug('\n*** parent command GetDotenvCliOptions ***\n', parentGetDotenvCliOptions);
34304
+ if (mergedGetDotenvCliOptions.debug)
34305
+ logger.debug('\n*** current command raw options ***\n', rawCliOptions);
34306
+ if (mergedGetDotenvCliOptions.debug)
34307
+ logger.debug('\n*** current command GetDotenvCliOptions ***\n', currentGetDotenvCliOptions);
34308
+ if (mergedGetDotenvCliOptions.debug)
34309
+ logger.debug('\n*** merged GetDotenvCliOptions ***\n', {
34310
+ mergedGetDotenvCliOptions,
34372
34311
  });
34373
34312
  // Execute pre-hook.
34374
34313
  if (preHook) {
34375
- await preHook(cliOptions);
34376
- if (cliOptions.debug)
34377
- logger.log('\n*** cli options after pre-hook ***\n', cliOptions);
34314
+ await preHook(mergedGetDotenvCliOptions);
34315
+ if (mergedGetDotenvCliOptions.debug)
34316
+ logger.debug('\n*** GetDotenvCliOptions after pre-hook ***\n', mergedGetDotenvCliOptions);
34378
34317
  }
34379
- // Get getdotenv options from parent command.
34380
- const parentGetdotenvOptions = (process.env.getDotenvOptions
34381
- ? JSON.parse(process.env.getDotenvOptions)
34382
- : {});
34383
- const cliGetDotenvOptions = getDotenvCliOptions2Options(cliOptions);
34384
- const getDotenvOptions = mergeGetDotenvOptions(cliGetDotenvOptions, parentGetdotenvOptions);
34385
- if (cliOptions.debug)
34386
- logger.log('\n*** getdotenv option resolution ***\n', {
34387
- parentGetdotenvOptions,
34388
- cliGetDotenvOptions,
34389
- getDotenvOptions,
34390
- });
34318
+ // Persist GetDotenvCliOptions in command for subcommand access.
34319
+ _.set(thisCommand, 'getDotenvCliOptions', mergedGetDotenvCliOptions);
34391
34320
  // Execute getdotenv.
34392
- const getDotenvOptionsProp = { ...getDotenvOptions, logger };
34393
- _.set(thisCommand, 'getDotenvOptions', getDotenvOptionsProp);
34394
- const dotenv = await getDotenv(getDotenvOptionsProp);
34395
- if (cliOptions.debug)
34396
- logger.log('\n*** resulting dotenv values ***\n', { dotenv });
34321
+ const dotenv = await getDotenv(getDotenvCliOptions2Options(mergedGetDotenvCliOptions));
34322
+ if (mergedGetDotenvCliOptions.debug)
34323
+ logger.debug('\n*** getDotenv output ***\n', dotenv);
34397
34324
  // Execute post-hook.
34398
34325
  if (postHook)
34399
34326
  await postHook(dotenv);
@@ -34403,13 +34330,13 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
34403
34330
  process.exit(0);
34404
34331
  }
34405
34332
  if (command) {
34406
- const shellCommand = getDotenvOptionsProp.shellScripts?.[command] ?? command;
34407
- if (cliOptions.debug)
34408
- logger.log('\n*** shell command ***\n', shellCommand);
34333
+ const shellCommand = mergedGetDotenvCliOptions.shellScripts?.[command] ?? command;
34334
+ if (mergedGetDotenvCliOptions.debug)
34335
+ logger.debug('\n*** shell command ***\n', shellCommand);
34409
34336
  await execaCommand(shellCommand, {
34410
34337
  env: {
34411
34338
  ...process.env,
34412
- getDotenvOptions: JSON.stringify(getDotenvOptions),
34339
+ getDotenvCliOptions: JSON.stringify(_.omit(mergedGetDotenvCliOptions, ['logger'])),
34413
34340
  },
34414
34341
  shell: true,
34415
34342
  stdio: 'inherit',
package/dist/index.d.cts 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` and `getDotEnvSync`.
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?: string;
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 Omit<GetDotenvCliOptions, 'env'> {
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?: 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: ({ logger, preHook, postHook, ...cliOptionsCustom }?: GetDotenvCliGenerateOptions) => Command;
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.d.mts 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` and `getDotEnvSync`.
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?: string;
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 Omit<GetDotenvCliOptions, 'env'> {
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?: 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: ({ logger, preHook, postHook, ...cliOptionsCustom }?: GetDotenvCliGenerateOptions) => Command;
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 };