@karmaniverous/get-dotenv 4.0.0-0 → 4.0.0-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.
@@ -14,13 +14,13 @@ import fs$m, { createWriteStream, createReadStream } from 'node:fs';
14
14
  import { setTimeout as setTimeout$1 } from 'node:timers/promises';
15
15
  import require$$0$2 from 'stream';
16
16
  import { debuglog } from 'node:util';
17
- import require$$2 from 'os';
18
17
  import require$$0$3 from 'constants';
19
18
  import require$$4$2 from 'util';
20
19
  import require$$5 from 'assert';
21
20
  import { webcrypto } from 'node:crypto';
22
21
  import url, { fileURLToPath as fileURLToPath$1 } from 'url';
23
22
  import 'node:fs/promises';
23
+ import require$$2 from 'os';
24
24
  import require$$3 from 'crypto';
25
25
 
26
26
  // like String.prototype.search but returns the last index
@@ -89,6 +89,16 @@ const dotenvExpandAll = (values = {}, { ref = process.env, progressive = false,
89
89
  });
90
90
  return acc;
91
91
  }, {});
92
+ /**
93
+ * Recursively expands environment variables in a string using `process.env` as
94
+ * the expansion reference. Variables may be presented with optional default as
95
+ * `$VAR[:default]` or `${VAR[:default]}`. Unknown variables will expand to an
96
+ * empty string.
97
+ *
98
+ * @param value - The string to expand.
99
+ * @returns The expanded string.
100
+ */
101
+ const dotenvExpandFromProcessEnv = (value) => dotenvExpand(value, process.env);
92
102
 
93
103
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
94
104
 
@@ -23231,7 +23241,7 @@ var constants = require$$0$3;
23231
23241
  var origCwd = process.cwd;
23232
23242
  var cwd = null;
23233
23243
 
23234
- var platform$1 = process.env.GRACEFUL_FS_PLATFORM || process.platform;
23244
+ var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
23235
23245
 
23236
23246
  process.cwd = function() {
23237
23247
  if (!cwd)
@@ -23321,7 +23331,7 @@ function patch$1 (fs) {
23321
23331
  // failures. Also, take care to yield the scheduler. Windows scheduling gives
23322
23332
  // CPU to a busy looping process, which can cause the program causing the lock
23323
23333
  // contention to be starved of CPU by node, so the contention doesn't resolve.
23324
- if (platform$1 === "win32") {
23334
+ if (platform === "win32") {
23325
23335
  fs.rename = typeof fs.rename !== 'function' ? fs.rename
23326
23336
  : (function (fs$rename) {
23327
23337
  function rename (from, to, cb) {
@@ -26340,12 +26350,6 @@ const getDotenv = async (options = {}) => {
26340
26350
  return dotenv;
26341
26351
  };
26342
26352
 
26343
- // Discover platform.
26344
- const platform = require$$2.platform();
26345
- /**
26346
- * `dotenvExpand` function reduced to initial argument (applies default to `ref` argument).
26347
- */
26348
- const dotenvExpandDefault = (value) => dotenvExpand(value);
26349
26353
  /**
26350
26354
  * Generate a Commander CLI Command for get-dotenv.
26351
26355
  */
@@ -26363,15 +26367,15 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
26363
26367
  .description(description)
26364
26368
  .enablePositionalOptions()
26365
26369
  .passThroughOptions()
26366
- .option('-e, --env <string>', `target environment (dotenv-expanded)`, dotenvExpandDefault, env)
26370
+ .option('-e, --env <string>', `target environment (dotenv-expanded)`, dotenvExpandFromProcessEnv, env)
26367
26371
  .option('-v, --vars <string>', `extra variables expressed as delimited key-value pairs (dotenv-expanded): ${[
26368
26372
  ['KEY1', 'VAL1'],
26369
26373
  ['KEY2', 'VAL2'],
26370
26374
  ]
26371
26375
  .map((v) => v.join(varsAssignor))
26372
- .join(varsDelimiter)}`, dotenvExpandDefault)
26373
- .option('-c, --command <string>', 'shell command string (dotenv-expanded)', dotenvExpandDefault)
26374
- .option('-o, --output-path <string>', 'consolidated output file (dotenv-expanded)', dotenvExpandDefault, outputPath)
26376
+ .join(varsDelimiter)}`, dotenvExpandFromProcessEnv)
26377
+ .option('-c, --command <string>', 'shell command string (dotenv-expanded)', dotenvExpandFromProcessEnv)
26378
+ .option('-o, --output-path <string>', 'consolidated output file (dotenv-expanded)', dotenvExpandFromProcessEnv, outputPath)
26375
26379
  .addOption(new Option('-p, --load-process', `load variables to process.env ON${loadProcess ? ' (default)' : ''}`).conflicts('loadProcessOff'))
26376
26380
  .addOption(new Option('-P, --load-process-off', `load variables to process.env OFF${!loadProcess ? ' (default)' : ''}`).conflicts('loadProcess'))
26377
26381
  .addOption(new Option('-a, --exclude-all', `exclude all dotenv variables from loading ON${excludeAll ? ' (default)' : ''}`).conflicts('excludeAllOff'))
@@ -26390,13 +26394,13 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
26390
26394
  .addOption(new Option('-L, --log-off', `console log loaded variables OFF${!log ? ' (default)' : ''}`).conflicts('log'))
26391
26395
  .addOption(new Option('-d, --debug', `debug mode ON${debug ? ' (default)' : ''}`).conflicts('debugOff'))
26392
26396
  .addOption(new Option('-D, --debug-off', `debug mode OFF${!debug ? ' (default)' : ''}`).conflicts('debug'))
26393
- .option('--default-env <string>', 'default target environment', dotenvExpandDefault, defaultEnv)
26394
- .option('--dotenv-token <string>', 'dotenv-expanded token indicating a dotenv file', dotenvExpandDefault, dotenvToken)
26395
- .option('--dynamic-path <string>', 'dynamic variables path', dotenvExpandDefault, dynamicPath)
26396
- .option('--paths <string>', 'dotenv-expanded delimited list of paths to dotenv directory', dotenvExpandDefault, paths)
26397
+ .option('--default-env <string>', 'default target environment', dotenvExpandFromProcessEnv, defaultEnv)
26398
+ .option('--dotenv-token <string>', 'dotenv-expanded token indicating a dotenv file', dotenvExpandFromProcessEnv, dotenvToken)
26399
+ .option('--dynamic-path <string>', 'dynamic variables path', dotenvExpandFromProcessEnv, dynamicPath)
26400
+ .option('--paths <string>', 'dotenv-expanded delimited list of paths to dotenv directory', dotenvExpandFromProcessEnv, paths)
26397
26401
  .option('--paths-delimiter <string>', 'paths delimiter string', pathsDelimiter)
26398
26402
  .option('--paths-delimiter-pattern <string>', 'paths delimiter regex pattern', pathsDelimiterPattern)
26399
- .option('--private-token <string>', 'dotenv-expanded token indicating private variables', dotenvExpandDefault, privateToken)
26403
+ .option('--private-token <string>', 'dotenv-expanded token indicating private variables', dotenvExpandFromProcessEnv, privateToken)
26400
26404
  .option('--vars-delimiter <string>', 'vars delimiter string', varsDelimiter)
26401
26405
  .option('--vars-delimiter-pattern <string>', 'vars delimiter regex pattern', varsDelimiterPattern)
26402
26406
  .option('--vars-assignor <string>', 'vars assignment operator string', varsAssignor)
@@ -26408,12 +26412,18 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
26408
26412
  .enablePositionalOptions()
26409
26413
  .passThroughOptions()
26410
26414
  .action(async (options, command) => {
26411
- const { args } = command;
26412
- if (args.length)
26413
- await execaCommand(args.join(platform === 'win32' ? '\\ ' : ' '), {
26415
+ const { args, getDotenvOptions: { debug }, } = command.parent;
26416
+ if (args.length) {
26417
+ if (debug)
26418
+ logger.log('\n*** raw shell args ***\n', args);
26419
+ const shellCommand = args.join(' ');
26420
+ if (debug)
26421
+ logger.log('\n*** shell command ***\n', shellCommand);
26422
+ await execaCommand(shellCommand, {
26414
26423
  stdio: 'inherit',
26415
26424
  shell: true,
26416
26425
  });
26426
+ }
26417
26427
  }), { isDefault: true })
26418
26428
  .hook('preSubcommand', async (thisCommand) => {
26419
26429
  const rawOptions = thisCommand.opts();
@@ -26479,8 +26489,10 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
26479
26489
  if (postHook)
26480
26490
  await postHook(dotenv);
26481
26491
  // Execute shell command.
26482
- if (command)
26483
- await execaCommand(platform === 'win32' ? command.replace(/ /g, '\\ ') : command, {
26492
+ if (command) {
26493
+ if (cliOptions.debug)
26494
+ logger.log('\n*** shell command ***\n', command);
26495
+ await execaCommand(command, {
26484
26496
  env: {
26485
26497
  ...process.env,
26486
26498
  getDotenvOptions: JSON.stringify(getDotenvOptions),
@@ -26488,6 +26500,7 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
26488
26500
  shell: true,
26489
26501
  stdio: 'inherit',
26490
26502
  });
26503
+ }
26491
26504
  });
26492
26505
  };
26493
26506
 
package/dist/index.cjs CHANGED
@@ -15,13 +15,13 @@ var fs$m = require('node:fs');
15
15
  var promises = require('node:timers/promises');
16
16
  var require$$0$2 = require('stream');
17
17
  var node_util = require('node:util');
18
- var require$$2 = require('os');
19
18
  var require$$0$3 = require('constants');
20
19
  var require$$4$2 = require('util');
21
20
  var require$$5 = require('assert');
22
21
  var node_crypto = require('node:crypto');
23
22
  var url = require('url');
24
23
  require('node:fs/promises');
24
+ var require$$2 = require('os');
25
25
  var require$$3 = require('crypto');
26
26
 
27
27
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
@@ -91,6 +91,16 @@ const dotenvExpandAll = (values = {}, { ref = process.env, progressive = false,
91
91
  });
92
92
  return acc;
93
93
  }, {});
94
+ /**
95
+ * Recursively expands environment variables in a string using `process.env` as
96
+ * the expansion reference. Variables may be presented with optional default as
97
+ * `$VAR[:default]` or `${VAR[:default]}`. Unknown variables will expand to an
98
+ * empty string.
99
+ *
100
+ * @param value - The string to expand.
101
+ * @returns The expanded string.
102
+ */
103
+ const dotenvExpandFromProcessEnv = (value) => dotenvExpand(value, process.env);
94
104
 
95
105
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
96
106
 
@@ -23233,7 +23243,7 @@ var constants = require$$0$3;
23233
23243
  var origCwd = process.cwd;
23234
23244
  var cwd = null;
23235
23245
 
23236
- var platform$1 = process.env.GRACEFUL_FS_PLATFORM || process.platform;
23246
+ var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
23237
23247
 
23238
23248
  process.cwd = function() {
23239
23249
  if (!cwd)
@@ -23323,7 +23333,7 @@ function patch$1 (fs) {
23323
23333
  // failures. Also, take care to yield the scheduler. Windows scheduling gives
23324
23334
  // CPU to a busy looping process, which can cause the program causing the lock
23325
23335
  // contention to be starved of CPU by node, so the contention doesn't resolve.
23326
- if (platform$1 === "win32") {
23336
+ if (platform === "win32") {
23327
23337
  fs.rename = typeof fs.rename !== 'function' ? fs.rename
23328
23338
  : (function (fs$rename) {
23329
23339
  function rename (from, to, cb) {
@@ -26342,12 +26352,6 @@ const getDotenv = async (options = {}) => {
26342
26352
  return dotenv;
26343
26353
  };
26344
26354
 
26345
- // Discover platform.
26346
- const platform = require$$2.platform();
26347
- /**
26348
- * `dotenvExpand` function reduced to initial argument (applies default to `ref` argument).
26349
- */
26350
- const dotenvExpandDefault = (value) => dotenvExpand(value);
26351
26355
  /**
26352
26356
  * Generate a Commander CLI Command for get-dotenv.
26353
26357
  */
@@ -26365,15 +26369,15 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
26365
26369
  .description(description)
26366
26370
  .enablePositionalOptions()
26367
26371
  .passThroughOptions()
26368
- .option('-e, --env <string>', `target environment (dotenv-expanded)`, dotenvExpandDefault, env)
26372
+ .option('-e, --env <string>', `target environment (dotenv-expanded)`, dotenvExpandFromProcessEnv, env)
26369
26373
  .option('-v, --vars <string>', `extra variables expressed as delimited key-value pairs (dotenv-expanded): ${[
26370
26374
  ['KEY1', 'VAL1'],
26371
26375
  ['KEY2', 'VAL2'],
26372
26376
  ]
26373
26377
  .map((v) => v.join(varsAssignor))
26374
- .join(varsDelimiter)}`, dotenvExpandDefault)
26375
- .option('-c, --command <string>', 'shell command string (dotenv-expanded)', dotenvExpandDefault)
26376
- .option('-o, --output-path <string>', 'consolidated output file (dotenv-expanded)', dotenvExpandDefault, outputPath)
26378
+ .join(varsDelimiter)}`, dotenvExpandFromProcessEnv)
26379
+ .option('-c, --command <string>', 'shell command string (dotenv-expanded)', dotenvExpandFromProcessEnv)
26380
+ .option('-o, --output-path <string>', 'consolidated output file (dotenv-expanded)', dotenvExpandFromProcessEnv, outputPath)
26377
26381
  .addOption(new Option('-p, --load-process', `load variables to process.env ON${loadProcess ? ' (default)' : ''}`).conflicts('loadProcessOff'))
26378
26382
  .addOption(new Option('-P, --load-process-off', `load variables to process.env OFF${!loadProcess ? ' (default)' : ''}`).conflicts('loadProcess'))
26379
26383
  .addOption(new Option('-a, --exclude-all', `exclude all dotenv variables from loading ON${excludeAll ? ' (default)' : ''}`).conflicts('excludeAllOff'))
@@ -26392,13 +26396,13 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
26392
26396
  .addOption(new Option('-L, --log-off', `console log loaded variables OFF${!log ? ' (default)' : ''}`).conflicts('log'))
26393
26397
  .addOption(new Option('-d, --debug', `debug mode ON${debug ? ' (default)' : ''}`).conflicts('debugOff'))
26394
26398
  .addOption(new Option('-D, --debug-off', `debug mode OFF${!debug ? ' (default)' : ''}`).conflicts('debug'))
26395
- .option('--default-env <string>', 'default target environment', dotenvExpandDefault, defaultEnv)
26396
- .option('--dotenv-token <string>', 'dotenv-expanded token indicating a dotenv file', dotenvExpandDefault, dotenvToken)
26397
- .option('--dynamic-path <string>', 'dynamic variables path', dotenvExpandDefault, dynamicPath)
26398
- .option('--paths <string>', 'dotenv-expanded delimited list of paths to dotenv directory', dotenvExpandDefault, paths)
26399
+ .option('--default-env <string>', 'default target environment', dotenvExpandFromProcessEnv, defaultEnv)
26400
+ .option('--dotenv-token <string>', 'dotenv-expanded token indicating a dotenv file', dotenvExpandFromProcessEnv, dotenvToken)
26401
+ .option('--dynamic-path <string>', 'dynamic variables path', dotenvExpandFromProcessEnv, dynamicPath)
26402
+ .option('--paths <string>', 'dotenv-expanded delimited list of paths to dotenv directory', dotenvExpandFromProcessEnv, paths)
26399
26403
  .option('--paths-delimiter <string>', 'paths delimiter string', pathsDelimiter)
26400
26404
  .option('--paths-delimiter-pattern <string>', 'paths delimiter regex pattern', pathsDelimiterPattern)
26401
- .option('--private-token <string>', 'dotenv-expanded token indicating private variables', dotenvExpandDefault, privateToken)
26405
+ .option('--private-token <string>', 'dotenv-expanded token indicating private variables', dotenvExpandFromProcessEnv, privateToken)
26402
26406
  .option('--vars-delimiter <string>', 'vars delimiter string', varsDelimiter)
26403
26407
  .option('--vars-delimiter-pattern <string>', 'vars delimiter regex pattern', varsDelimiterPattern)
26404
26408
  .option('--vars-assignor <string>', 'vars assignment operator string', varsAssignor)
@@ -26410,12 +26414,18 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
26410
26414
  .enablePositionalOptions()
26411
26415
  .passThroughOptions()
26412
26416
  .action(async (options, command) => {
26413
- const { args } = command;
26414
- if (args.length)
26415
- await execaCommand(args.join(platform === 'win32' ? '\\ ' : ' '), {
26417
+ const { args, getDotenvOptions: { debug }, } = command.parent;
26418
+ if (args.length) {
26419
+ if (debug)
26420
+ logger.log('\n*** raw shell args ***\n', args);
26421
+ const shellCommand = args.join(' ');
26422
+ if (debug)
26423
+ logger.log('\n*** shell command ***\n', shellCommand);
26424
+ await execaCommand(shellCommand, {
26416
26425
  stdio: 'inherit',
26417
26426
  shell: true,
26418
26427
  });
26428
+ }
26419
26429
  }), { isDefault: true })
26420
26430
  .hook('preSubcommand', async (thisCommand) => {
26421
26431
  const rawOptions = thisCommand.opts();
@@ -26481,8 +26491,10 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
26481
26491
  if (postHook)
26482
26492
  await postHook(dotenv);
26483
26493
  // Execute shell command.
26484
- if (command)
26485
- await execaCommand(platform === 'win32' ? command.replace(/ /g, '\\ ') : command, {
26494
+ if (command) {
26495
+ if (cliOptions.debug)
26496
+ logger.log('\n*** shell command ***\n', command);
26497
+ await execaCommand(command, {
26486
26498
  env: {
26487
26499
  ...process.env,
26488
26500
  getDotenvOptions: JSON.stringify(getDotenvOptions),
@@ -26490,10 +26502,12 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
26490
26502
  shell: true,
26491
26503
  stdio: 'inherit',
26492
26504
  });
26505
+ }
26493
26506
  });
26494
26507
  };
26495
26508
 
26496
26509
  exports.dotenvExpand = dotenvExpand;
26497
26510
  exports.dotenvExpandAll = dotenvExpandAll;
26511
+ exports.dotenvExpandFromProcessEnv = dotenvExpandFromProcessEnv;
26498
26512
  exports.generateGetDotenvCli = generateGetDotenvCli;
26499
26513
  exports.getDotenv = getDotenv;
package/dist/index.d.cts CHANGED
@@ -57,6 +57,10 @@ type Logger = Record<string, (...args: unknown[]) => void>;
57
57
  * Options passed programmatically to `getDotenv` and `getDotEnvSync`.
58
58
  */
59
59
  interface GetDotenvOptions {
60
+ /**
61
+ * log internals to logger
62
+ */
63
+ debug?: boolean;
60
64
  /**
61
65
  * default target environment (used if `env` is not provided)
62
66
  */
@@ -148,6 +152,16 @@ declare const dotenvExpandAll: (values?: ProcessEnv, { ref, progressive, }?: {
148
152
  ref?: ProcessEnv;
149
153
  progressive?: boolean;
150
154
  }) => Record<string, string | undefined>;
155
+ /**
156
+ * Recursively expands environment variables in a string using `process.env` as
157
+ * the expansion reference. Variables may be presented with optional default as
158
+ * `$VAR[:default]` or `${VAR[:default]}`. Unknown variables will expand to an
159
+ * empty string.
160
+ *
161
+ * @param value - The string to expand.
162
+ * @returns The expanded string.
163
+ */
164
+ declare const dotenvExpandFromProcessEnv: (value: string | undefined) => string | undefined;
151
165
 
152
166
  /**
153
167
  * GetDotenv CLI Pre-hook Callback function type. Mutates inbound options &
@@ -231,4 +245,4 @@ declare const generateGetDotenvCli: ({ logger, preHook, postHook, ...cliOptionsC
231
245
  */
232
246
  declare const getDotenv: (options?: GetDotenvOptions) => Promise<ProcessEnv>;
233
247
 
234
- export { type GetDotenvDynamic, type GetDotenvOptions, type ProcessEnv, dotenvExpand, dotenvExpandAll, generateGetDotenvCli, getDotenv };
248
+ export { type GetDotenvDynamic, type GetDotenvOptions, type ProcessEnv, dotenvExpand, dotenvExpandAll, dotenvExpandFromProcessEnv, generateGetDotenvCli, getDotenv };
package/dist/index.d.mts CHANGED
@@ -57,6 +57,10 @@ type Logger = Record<string, (...args: unknown[]) => void>;
57
57
  * Options passed programmatically to `getDotenv` and `getDotEnvSync`.
58
58
  */
59
59
  interface GetDotenvOptions {
60
+ /**
61
+ * log internals to logger
62
+ */
63
+ debug?: boolean;
60
64
  /**
61
65
  * default target environment (used if `env` is not provided)
62
66
  */
@@ -148,6 +152,16 @@ declare const dotenvExpandAll: (values?: ProcessEnv, { ref, progressive, }?: {
148
152
  ref?: ProcessEnv;
149
153
  progressive?: boolean;
150
154
  }) => Record<string, string | undefined>;
155
+ /**
156
+ * Recursively expands environment variables in a string using `process.env` as
157
+ * the expansion reference. Variables may be presented with optional default as
158
+ * `$VAR[:default]` or `${VAR[:default]}`. Unknown variables will expand to an
159
+ * empty string.
160
+ *
161
+ * @param value - The string to expand.
162
+ * @returns The expanded string.
163
+ */
164
+ declare const dotenvExpandFromProcessEnv: (value: string | undefined) => string | undefined;
151
165
 
152
166
  /**
153
167
  * GetDotenv CLI Pre-hook Callback function type. Mutates inbound options &
@@ -231,4 +245,4 @@ declare const generateGetDotenvCli: ({ logger, preHook, postHook, ...cliOptionsC
231
245
  */
232
246
  declare const getDotenv: (options?: GetDotenvOptions) => Promise<ProcessEnv>;
233
247
 
234
- export { type GetDotenvDynamic, type GetDotenvOptions, type ProcessEnv, dotenvExpand, dotenvExpandAll, generateGetDotenvCli, getDotenv };
248
+ export { type GetDotenvDynamic, type GetDotenvOptions, type ProcessEnv, dotenvExpand, dotenvExpandAll, dotenvExpandFromProcessEnv, generateGetDotenvCli, getDotenv };
package/dist/index.d.ts CHANGED
@@ -57,6 +57,10 @@ type Logger = Record<string, (...args: unknown[]) => void>;
57
57
  * Options passed programmatically to `getDotenv` and `getDotEnvSync`.
58
58
  */
59
59
  interface GetDotenvOptions {
60
+ /**
61
+ * log internals to logger
62
+ */
63
+ debug?: boolean;
60
64
  /**
61
65
  * default target environment (used if `env` is not provided)
62
66
  */
@@ -148,6 +152,16 @@ declare const dotenvExpandAll: (values?: ProcessEnv, { ref, progressive, }?: {
148
152
  ref?: ProcessEnv;
149
153
  progressive?: boolean;
150
154
  }) => Record<string, string | undefined>;
155
+ /**
156
+ * Recursively expands environment variables in a string using `process.env` as
157
+ * the expansion reference. Variables may be presented with optional default as
158
+ * `$VAR[:default]` or `${VAR[:default]}`. Unknown variables will expand to an
159
+ * empty string.
160
+ *
161
+ * @param value - The string to expand.
162
+ * @returns The expanded string.
163
+ */
164
+ declare const dotenvExpandFromProcessEnv: (value: string | undefined) => string | undefined;
151
165
 
152
166
  /**
153
167
  * GetDotenv CLI Pre-hook Callback function type. Mutates inbound options &
@@ -231,4 +245,4 @@ declare const generateGetDotenvCli: ({ logger, preHook, postHook, ...cliOptionsC
231
245
  */
232
246
  declare const getDotenv: (options?: GetDotenvOptions) => Promise<ProcessEnv>;
233
247
 
234
- export { type GetDotenvDynamic, type GetDotenvOptions, type ProcessEnv, dotenvExpand, dotenvExpandAll, generateGetDotenvCli, getDotenv };
248
+ export { type GetDotenvDynamic, type GetDotenvOptions, type ProcessEnv, dotenvExpand, dotenvExpandAll, dotenvExpandFromProcessEnv, generateGetDotenvCli, getDotenv };
package/dist/index.mjs CHANGED
@@ -13,13 +13,13 @@ import fs$m, { createWriteStream, createReadStream } from 'node:fs';
13
13
  import { setTimeout as setTimeout$1 } from 'node:timers/promises';
14
14
  import require$$0$2 from 'stream';
15
15
  import { debuglog } from 'node:util';
16
- import require$$2 from 'os';
17
16
  import require$$0$3 from 'constants';
18
17
  import require$$4$2 from 'util';
19
18
  import require$$5 from 'assert';
20
19
  import { webcrypto } from 'node:crypto';
21
20
  import url, { fileURLToPath as fileURLToPath$1 } from 'url';
22
21
  import 'node:fs/promises';
22
+ import require$$2 from 'os';
23
23
  import require$$3 from 'crypto';
24
24
 
25
25
  // like String.prototype.search but returns the last index
@@ -88,6 +88,16 @@ const dotenvExpandAll = (values = {}, { ref = process.env, progressive = false,
88
88
  });
89
89
  return acc;
90
90
  }, {});
91
+ /**
92
+ * Recursively expands environment variables in a string using `process.env` as
93
+ * the expansion reference. Variables may be presented with optional default as
94
+ * `$VAR[:default]` or `${VAR[:default]}`. Unknown variables will expand to an
95
+ * empty string.
96
+ *
97
+ * @param value - The string to expand.
98
+ * @returns The expanded string.
99
+ */
100
+ const dotenvExpandFromProcessEnv = (value) => dotenvExpand(value, process.env);
91
101
 
92
102
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
93
103
 
@@ -23230,7 +23240,7 @@ var constants = require$$0$3;
23230
23240
  var origCwd = process.cwd;
23231
23241
  var cwd = null;
23232
23242
 
23233
- var platform$1 = process.env.GRACEFUL_FS_PLATFORM || process.platform;
23243
+ var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
23234
23244
 
23235
23245
  process.cwd = function() {
23236
23246
  if (!cwd)
@@ -23320,7 +23330,7 @@ function patch$1 (fs) {
23320
23330
  // failures. Also, take care to yield the scheduler. Windows scheduling gives
23321
23331
  // CPU to a busy looping process, which can cause the program causing the lock
23322
23332
  // contention to be starved of CPU by node, so the contention doesn't resolve.
23323
- if (platform$1 === "win32") {
23333
+ if (platform === "win32") {
23324
23334
  fs.rename = typeof fs.rename !== 'function' ? fs.rename
23325
23335
  : (function (fs$rename) {
23326
23336
  function rename (from, to, cb) {
@@ -26339,12 +26349,6 @@ const getDotenv = async (options = {}) => {
26339
26349
  return dotenv;
26340
26350
  };
26341
26351
 
26342
- // Discover platform.
26343
- const platform = require$$2.platform();
26344
- /**
26345
- * `dotenvExpand` function reduced to initial argument (applies default to `ref` argument).
26346
- */
26347
- const dotenvExpandDefault = (value) => dotenvExpand(value);
26348
26352
  /**
26349
26353
  * Generate a Commander CLI Command for get-dotenv.
26350
26354
  */
@@ -26362,15 +26366,15 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
26362
26366
  .description(description)
26363
26367
  .enablePositionalOptions()
26364
26368
  .passThroughOptions()
26365
- .option('-e, --env <string>', `target environment (dotenv-expanded)`, dotenvExpandDefault, env)
26369
+ .option('-e, --env <string>', `target environment (dotenv-expanded)`, dotenvExpandFromProcessEnv, env)
26366
26370
  .option('-v, --vars <string>', `extra variables expressed as delimited key-value pairs (dotenv-expanded): ${[
26367
26371
  ['KEY1', 'VAL1'],
26368
26372
  ['KEY2', 'VAL2'],
26369
26373
  ]
26370
26374
  .map((v) => v.join(varsAssignor))
26371
- .join(varsDelimiter)}`, dotenvExpandDefault)
26372
- .option('-c, --command <string>', 'shell command string (dotenv-expanded)', dotenvExpandDefault)
26373
- .option('-o, --output-path <string>', 'consolidated output file (dotenv-expanded)', dotenvExpandDefault, outputPath)
26375
+ .join(varsDelimiter)}`, dotenvExpandFromProcessEnv)
26376
+ .option('-c, --command <string>', 'shell command string (dotenv-expanded)', dotenvExpandFromProcessEnv)
26377
+ .option('-o, --output-path <string>', 'consolidated output file (dotenv-expanded)', dotenvExpandFromProcessEnv, outputPath)
26374
26378
  .addOption(new Option('-p, --load-process', `load variables to process.env ON${loadProcess ? ' (default)' : ''}`).conflicts('loadProcessOff'))
26375
26379
  .addOption(new Option('-P, --load-process-off', `load variables to process.env OFF${!loadProcess ? ' (default)' : ''}`).conflicts('loadProcess'))
26376
26380
  .addOption(new Option('-a, --exclude-all', `exclude all dotenv variables from loading ON${excludeAll ? ' (default)' : ''}`).conflicts('excludeAllOff'))
@@ -26389,13 +26393,13 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
26389
26393
  .addOption(new Option('-L, --log-off', `console log loaded variables OFF${!log ? ' (default)' : ''}`).conflicts('log'))
26390
26394
  .addOption(new Option('-d, --debug', `debug mode ON${debug ? ' (default)' : ''}`).conflicts('debugOff'))
26391
26395
  .addOption(new Option('-D, --debug-off', `debug mode OFF${!debug ? ' (default)' : ''}`).conflicts('debug'))
26392
- .option('--default-env <string>', 'default target environment', dotenvExpandDefault, defaultEnv)
26393
- .option('--dotenv-token <string>', 'dotenv-expanded token indicating a dotenv file', dotenvExpandDefault, dotenvToken)
26394
- .option('--dynamic-path <string>', 'dynamic variables path', dotenvExpandDefault, dynamicPath)
26395
- .option('--paths <string>', 'dotenv-expanded delimited list of paths to dotenv directory', dotenvExpandDefault, paths)
26396
+ .option('--default-env <string>', 'default target environment', dotenvExpandFromProcessEnv, defaultEnv)
26397
+ .option('--dotenv-token <string>', 'dotenv-expanded token indicating a dotenv file', dotenvExpandFromProcessEnv, dotenvToken)
26398
+ .option('--dynamic-path <string>', 'dynamic variables path', dotenvExpandFromProcessEnv, dynamicPath)
26399
+ .option('--paths <string>', 'dotenv-expanded delimited list of paths to dotenv directory', dotenvExpandFromProcessEnv, paths)
26396
26400
  .option('--paths-delimiter <string>', 'paths delimiter string', pathsDelimiter)
26397
26401
  .option('--paths-delimiter-pattern <string>', 'paths delimiter regex pattern', pathsDelimiterPattern)
26398
- .option('--private-token <string>', 'dotenv-expanded token indicating private variables', dotenvExpandDefault, privateToken)
26402
+ .option('--private-token <string>', 'dotenv-expanded token indicating private variables', dotenvExpandFromProcessEnv, privateToken)
26399
26403
  .option('--vars-delimiter <string>', 'vars delimiter string', varsDelimiter)
26400
26404
  .option('--vars-delimiter-pattern <string>', 'vars delimiter regex pattern', varsDelimiterPattern)
26401
26405
  .option('--vars-assignor <string>', 'vars assignment operator string', varsAssignor)
@@ -26407,12 +26411,18 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
26407
26411
  .enablePositionalOptions()
26408
26412
  .passThroughOptions()
26409
26413
  .action(async (options, command) => {
26410
- const { args } = command;
26411
- if (args.length)
26412
- await execaCommand(args.join(platform === 'win32' ? '\\ ' : ' '), {
26414
+ const { args, getDotenvOptions: { debug }, } = command.parent;
26415
+ if (args.length) {
26416
+ if (debug)
26417
+ logger.log('\n*** raw shell args ***\n', args);
26418
+ const shellCommand = args.join(' ');
26419
+ if (debug)
26420
+ logger.log('\n*** shell command ***\n', shellCommand);
26421
+ await execaCommand(shellCommand, {
26413
26422
  stdio: 'inherit',
26414
26423
  shell: true,
26415
26424
  });
26425
+ }
26416
26426
  }), { isDefault: true })
26417
26427
  .hook('preSubcommand', async (thisCommand) => {
26418
26428
  const rawOptions = thisCommand.opts();
@@ -26478,8 +26488,10 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
26478
26488
  if (postHook)
26479
26489
  await postHook(dotenv);
26480
26490
  // Execute shell command.
26481
- if (command)
26482
- await execaCommand(platform === 'win32' ? command.replace(/ /g, '\\ ') : command, {
26491
+ if (command) {
26492
+ if (cliOptions.debug)
26493
+ logger.log('\n*** shell command ***\n', command);
26494
+ await execaCommand(command, {
26483
26495
  env: {
26484
26496
  ...process.env,
26485
26497
  getDotenvOptions: JSON.stringify(getDotenvOptions),
@@ -26487,7 +26499,8 @@ const generateGetDotenvCli = ({ logger = console, preHook, postHook, ...cliOptio
26487
26499
  shell: true,
26488
26500
  stdio: 'inherit',
26489
26501
  });
26502
+ }
26490
26503
  });
26491
26504
  };
26492
26505
 
26493
- export { dotenvExpand, dotenvExpandAll, generateGetDotenvCli, getDotenv };
26506
+ export { dotenvExpand, dotenvExpandAll, dotenvExpandFromProcessEnv, generateGetDotenvCli, getDotenv };
package/package.json CHANGED
@@ -75,7 +75,6 @@
75
75
  ],
76
76
  "homepage": "https://github.com/karmaniverous/get-dotenv#readme",
77
77
  "keywords": [
78
- "async-programming",
79
78
  "cli",
80
79
  "configuration",
81
80
  "developer-tools",
@@ -85,11 +84,7 @@
85
84
  "environment-variables",
86
85
  "json",
87
86
  "nodejs",
88
- "programming",
89
- "software-development",
90
- "sync-programming",
91
- "typescript",
92
- "yaml"
87
+ "typescript"
93
88
  ],
94
89
  "license": "BSD-3-Clause",
95
90
  "main": "./lib/index.js",
@@ -135,5 +130,5 @@
135
130
  },
136
131
  "type": "module",
137
132
  "types": "dist/index.d.ts",
138
- "version": "4.0.0-0"
133
+ "version": "4.0.0-2"
139
134
  }