@karmaniverous/get-dotenv 5.2.5 → 6.0.0-0

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.
Files changed (41) hide show
  1. package/README.md +63 -67
  2. package/dist/cliHost.cjs +765 -549
  3. package/dist/cliHost.d.cts +128 -84
  4. package/dist/cliHost.d.mts +128 -84
  5. package/dist/cliHost.d.ts +128 -84
  6. package/dist/cliHost.mjs +765 -549
  7. package/dist/getdotenv.cli.mjs +915 -685
  8. package/dist/index.cjs +959 -1006
  9. package/dist/index.d.cts +18 -178
  10. package/dist/index.d.mts +18 -178
  11. package/dist/index.d.ts +18 -178
  12. package/dist/index.mjs +960 -1006
  13. package/dist/plugins-aws.cjs +0 -1
  14. package/dist/plugins-aws.d.cts +8 -78
  15. package/dist/plugins-aws.d.mts +8 -78
  16. package/dist/plugins-aws.d.ts +8 -78
  17. package/dist/plugins-aws.mjs +0 -1
  18. package/dist/plugins-batch.cjs +53 -11
  19. package/dist/plugins-batch.d.cts +10 -79
  20. package/dist/plugins-batch.d.mts +10 -79
  21. package/dist/plugins-batch.d.ts +10 -79
  22. package/dist/plugins-batch.mjs +53 -11
  23. package/dist/plugins-cmd.cjs +162 -1555
  24. package/dist/plugins-cmd.d.cts +8 -78
  25. package/dist/plugins-cmd.d.mts +8 -78
  26. package/dist/plugins-cmd.d.ts +8 -78
  27. package/dist/plugins-cmd.mjs +162 -1554
  28. package/dist/plugins-demo.cjs +52 -7
  29. package/dist/plugins-demo.d.cts +8 -78
  30. package/dist/plugins-demo.d.mts +8 -78
  31. package/dist/plugins-demo.d.ts +8 -78
  32. package/dist/plugins-demo.mjs +52 -7
  33. package/dist/plugins-init.d.cts +8 -78
  34. package/dist/plugins-init.d.mts +8 -78
  35. package/dist/plugins-init.d.ts +8 -78
  36. package/dist/plugins.cjs +283 -1630
  37. package/dist/plugins.d.cts +10 -79
  38. package/dist/plugins.d.mts +10 -79
  39. package/dist/plugins.d.ts +10 -79
  40. package/dist/plugins.mjs +285 -1631
  41. package/package.json +4 -2
@@ -1,76 +1,6 @@
1
1
  import { Command } from 'commander';
2
2
  import { ZodType } from 'zod';
3
3
 
4
- /**
5
- * Minimal root options shape shared by CLI and generator layers.
6
- * Keep keys optional to respect exactOptionalPropertyTypes semantics.
7
- */
8
- type RootOptionsShape = {
9
- env?: string;
10
- vars?: string;
11
- command?: string;
12
- outputPath?: string;
13
- shell?: string | boolean;
14
- loadProcess?: boolean;
15
- excludeAll?: boolean;
16
- excludeDynamic?: boolean;
17
- excludeEnv?: boolean;
18
- excludeGlobal?: boolean;
19
- excludePrivate?: boolean;
20
- excludePublic?: boolean;
21
- log?: boolean;
22
- debug?: boolean;
23
- capture?: boolean;
24
- strict?: boolean;
25
- redact?: boolean;
26
- warnEntropy?: boolean;
27
- entropyThreshold?: number;
28
- entropyMinLength?: number;
29
- entropyWhitelist?: string[];
30
- redactPatterns?: string[];
31
- defaultEnv?: string;
32
- dotenvToken?: string;
33
- dynamicPath?: string;
34
- trace?: boolean | string[];
35
- paths?: string;
36
- pathsDelimiter?: string;
37
- pathsDelimiterPattern?: string;
38
- privateToken?: string;
39
- varsDelimiter?: string;
40
- varsDelimiterPattern?: string;
41
- varsAssignor?: string;
42
- varsAssignorPattern?: string;
43
- scripts?: ScriptsTable;
44
- };
45
- /**
46
- * Scripts table shape (configurable shell type).
47
- */
48
- type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<string, string | {
49
- cmd: string;
50
- shell?: TShell;
51
- }>;
52
-
53
- /**
54
- * Adapter-layer augmentation: add chainable helpers to GetDotenvCli without
55
- * coupling the core host to cliCore. Importing this module has side effects:
56
- * it extends the prototype and merges types for consumers.
57
- */
58
- declare module '../cliHost/GetDotenvCli' {
59
- interface GetDotenvCli {
60
- /**
61
- * Attach legacy root flags to this CLI instance. Defaults come from
62
- * baseRootOptionDefaults when none are provided. */
63
- attachRootOptions(defaults?: Partial<RootOptionsShape>, opts?: {
64
- includeCommandOption?: boolean;
65
- }): this;
66
- /**
67
- * Install a preSubcommand hook that merges CLI flags (including parent
68
- * round-trip) and resolves the dotenv context before executing actions.
69
- * Defaults come from baseRootOptionDefaults when none are provided.
70
- */ passOptions(defaults?: Partial<RootOptionsShape>): this;
71
- }
72
- }
73
-
74
4
  /**
75
5
  * A minimal representation of an environment key/value mapping.
76
6
  * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
@@ -165,14 +95,6 @@ interface GetDotenvOptions {
165
95
  useConfigLoader?: boolean;
166
96
  }
167
97
 
168
- /** * Per-invocation context shared with plugins and actions. */
169
- type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
170
- optionsResolved: TOptions;
171
- dotenv: ProcessEnv;
172
- plugins?: Record<string, unknown>;
173
- pluginConfigs?: Record<string, unknown>;
174
- };
175
-
176
98
  /** src/cliHost/definePlugin.ts
177
99
  * Plugin contracts for the GetDotenv CLI host.
178
100
  *
@@ -223,6 +145,14 @@ interface GetDotenvCliPlugin {
223
145
  use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
224
146
  }
225
147
 
148
+ /** * Per-invocation context shared with plugins and actions. */
149
+ type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
150
+ optionsResolved: TOptions;
151
+ dotenv: ProcessEnv;
152
+ plugins?: Record<string, unknown>;
153
+ pluginConfigs?: Record<string, unknown>;
154
+ };
155
+
226
156
  /**
227
157
  * Batch services (neutral): resolve command and shell settings.
228
158
  * Shared by the generator path and the batch plugin to avoid circular deps.
@@ -241,7 +171,8 @@ type BatchPluginOptions = {
241
171
  /**
242
172
  * Batch plugin for the GetDotenv CLI host.
243
173
  *
244
- * Mirrors the legacy batch subcommand behavior without altering the shipped CLI. * Options:
174
+ * Mirrors the legacy batch subcommand behavior without altering the shipped CLI.
175
+ * Options:
245
176
  * - scripts/shell: used to resolve command and shell behavior per script or global default.
246
177
  * - logger: defaults to console.
247
178
  */
@@ -1,76 +1,6 @@
1
1
  import { Command } from 'commander';
2
2
  import { ZodType } from 'zod';
3
3
 
4
- /**
5
- * Minimal root options shape shared by CLI and generator layers.
6
- * Keep keys optional to respect exactOptionalPropertyTypes semantics.
7
- */
8
- type RootOptionsShape = {
9
- env?: string;
10
- vars?: string;
11
- command?: string;
12
- outputPath?: string;
13
- shell?: string | boolean;
14
- loadProcess?: boolean;
15
- excludeAll?: boolean;
16
- excludeDynamic?: boolean;
17
- excludeEnv?: boolean;
18
- excludeGlobal?: boolean;
19
- excludePrivate?: boolean;
20
- excludePublic?: boolean;
21
- log?: boolean;
22
- debug?: boolean;
23
- capture?: boolean;
24
- strict?: boolean;
25
- redact?: boolean;
26
- warnEntropy?: boolean;
27
- entropyThreshold?: number;
28
- entropyMinLength?: number;
29
- entropyWhitelist?: string[];
30
- redactPatterns?: string[];
31
- defaultEnv?: string;
32
- dotenvToken?: string;
33
- dynamicPath?: string;
34
- trace?: boolean | string[];
35
- paths?: string;
36
- pathsDelimiter?: string;
37
- pathsDelimiterPattern?: string;
38
- privateToken?: string;
39
- varsDelimiter?: string;
40
- varsDelimiterPattern?: string;
41
- varsAssignor?: string;
42
- varsAssignorPattern?: string;
43
- scripts?: ScriptsTable;
44
- };
45
- /**
46
- * Scripts table shape (configurable shell type).
47
- */
48
- type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<string, string | {
49
- cmd: string;
50
- shell?: TShell;
51
- }>;
52
-
53
- /**
54
- * Adapter-layer augmentation: add chainable helpers to GetDotenvCli without
55
- * coupling the core host to cliCore. Importing this module has side effects:
56
- * it extends the prototype and merges types for consumers.
57
- */
58
- declare module '../cliHost/GetDotenvCli' {
59
- interface GetDotenvCli {
60
- /**
61
- * Attach legacy root flags to this CLI instance. Defaults come from
62
- * baseRootOptionDefaults when none are provided. */
63
- attachRootOptions(defaults?: Partial<RootOptionsShape>, opts?: {
64
- includeCommandOption?: boolean;
65
- }): this;
66
- /**
67
- * Install a preSubcommand hook that merges CLI flags (including parent
68
- * round-trip) and resolves the dotenv context before executing actions.
69
- * Defaults come from baseRootOptionDefaults when none are provided.
70
- */ passOptions(defaults?: Partial<RootOptionsShape>): this;
71
- }
72
- }
73
-
74
4
  /**
75
5
  * A minimal representation of an environment key/value mapping.
76
6
  * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
@@ -165,14 +95,6 @@ interface GetDotenvOptions {
165
95
  useConfigLoader?: boolean;
166
96
  }
167
97
 
168
- /** * Per-invocation context shared with plugins and actions. */
169
- type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
170
- optionsResolved: TOptions;
171
- dotenv: ProcessEnv;
172
- plugins?: Record<string, unknown>;
173
- pluginConfigs?: Record<string, unknown>;
174
- };
175
-
176
98
  /** src/cliHost/definePlugin.ts
177
99
  * Plugin contracts for the GetDotenv CLI host.
178
100
  *
@@ -223,6 +145,14 @@ interface GetDotenvCliPlugin {
223
145
  use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
224
146
  }
225
147
 
148
+ /** * Per-invocation context shared with plugins and actions. */
149
+ type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
150
+ optionsResolved: TOptions;
151
+ dotenv: ProcessEnv;
152
+ plugins?: Record<string, unknown>;
153
+ pluginConfigs?: Record<string, unknown>;
154
+ };
155
+
226
156
  /**
227
157
  * Batch services (neutral): resolve command and shell settings.
228
158
  * Shared by the generator path and the batch plugin to avoid circular deps.
@@ -241,7 +171,8 @@ type BatchPluginOptions = {
241
171
  /**
242
172
  * Batch plugin for the GetDotenv CLI host.
243
173
  *
244
- * Mirrors the legacy batch subcommand behavior without altering the shipped CLI. * Options:
174
+ * Mirrors the legacy batch subcommand behavior without altering the shipped CLI.
175
+ * Options:
245
176
  * - scripts/shell: used to resolve command and shell behavior per script or global default.
246
177
  * - logger: defaults to console.
247
178
  */
@@ -235,9 +235,10 @@ const globPaths = async ({ globs, logger, pkgCwd, rootPath, }) => {
235
235
  }
236
236
  return { absRootPath, paths };
237
237
  };
238
- const execShellCommandBatch = async ({ command, getDotenvCliOptions, globs, ignoreErrors, list, logger, pkgCwd, rootPath, shell, }) => {
238
+ const execShellCommandBatch = async ({ command, getDotenvCliOptions, dotenvEnv, globs, ignoreErrors, list, logger, pkgCwd, rootPath, shell, }) => {
239
239
  const capture = process.env.GETDOTENV_STDIO === 'pipe' ||
240
- Boolean(getDotenvCliOptions?.capture); // Require a command only when not listing. In list mode, a command is optional.
240
+ Boolean(getDotenvCliOptions?.capture);
241
+ // Require a command only when not listing. In list mode, a command is optional.
241
242
  if (!command && !list) {
242
243
  logger.error(`No command provided. Use --command or --list.`);
243
244
  process.exit(0);
@@ -284,12 +285,25 @@ const execShellCommandBatch = async ({ command, getDotenvCliOptions, globs, igno
284
285
  const hasCmd = (typeof command === 'string' && command.length > 0) ||
285
286
  (Array.isArray(command) && command.length > 0);
286
287
  if (hasCmd) {
287
- const envBag = getDotenvCliOptions !== undefined
288
- ? { getDotenvCliOptions: JSON.stringify(getDotenvCliOptions) }
289
- : undefined;
288
+ // Compose child env overlay from dotenv (drop undefined) and merged options
289
+ const overlay = {};
290
+ if (dotenvEnv) {
291
+ for (const [k, v] of Object.entries(dotenvEnv)) {
292
+ if (typeof v === 'string')
293
+ overlay[k] = v;
294
+ }
295
+ }
296
+ if (getDotenvCliOptions !== undefined) {
297
+ try {
298
+ overlay.getDotenvCliOptions = JSON.stringify(getDotenvCliOptions);
299
+ }
300
+ catch {
301
+ // best-effort: omit if serialization fails
302
+ }
303
+ }
290
304
  await runCommand(command, shell, {
291
305
  cwd: path,
292
- env: buildSpawnEnv(process.env, envBag),
306
+ env: buildSpawnEnv(process.env, overlay),
293
307
  stdio: capture ? 'pipe' : 'inherit',
294
308
  });
295
309
  }
@@ -355,6 +369,7 @@ const buildDefaultCmdAction = (cli, batchCmd, opts) => async (commandParts, _sub
355
369
  const ctx = cli.getCtx();
356
370
  const cfgRaw = (ctx?.pluginConfigs?.['batch'] ?? {});
357
371
  const cfg = (cfgRaw || {});
372
+ const dotenvEnv = (ctx?.dotenv ?? {});
358
373
  // Resolve batch flags from the captured parent (batch) command.
359
374
  const raw = batchCmd.opts();
360
375
  const listFromParent = !!raw.list;
@@ -373,6 +388,7 @@ const buildDefaultCmdAction = (cli, batchCmd, opts) => async (commandParts, _sub
373
388
  if (typeof commandOpt === 'string') {
374
389
  await execShellCommandBatch({
375
390
  command: resolveCommand(scripts, commandOpt),
391
+ dotenvEnv,
376
392
  globs,
377
393
  ignoreErrors,
378
394
  list: false,
@@ -384,6 +400,7 @@ const buildDefaultCmdAction = (cli, batchCmd, opts) => async (commandParts, _sub
384
400
  return;
385
401
  }
386
402
  if (raw.list || localList) {
403
+ const shellBag = ((batchCmd.parent ?? undefined)?.getDotenvCliOptions ?? {});
387
404
  await execShellCommandBatch({
388
405
  globs,
389
406
  ignoreErrors,
@@ -391,7 +408,7 @@ const buildDefaultCmdAction = (cli, batchCmd, opts) => async (commandParts, _sub
391
408
  logger: loggerLocal,
392
409
  ...(pkgCwd ? { pkgCwd } : {}),
393
410
  rootPath,
394
- shell: (shell ?? false),
411
+ shell: (shell ?? shellBag.shell ?? false),
395
412
  });
396
413
  return;
397
414
  }
@@ -458,6 +475,7 @@ const buildDefaultCmdAction = (cli, batchCmd, opts) => async (commandParts, _sub
458
475
  }
459
476
  await execShellCommandBatch({
460
477
  command: commandArg,
478
+ dotenvEnv,
461
479
  ...(envBag ? { getDotenvCliOptions: envBag } : {}),
462
480
  globs,
463
481
  ignoreErrors,
@@ -476,6 +494,7 @@ const buildParentAction = (cli, opts) => async (commandParts, thisCommand) => {
476
494
  const logger = opts.logger ?? console;
477
495
  // Ensure context exists (host preSubcommand on root creates if missing).
478
496
  const ctx = cli.getCtx();
497
+ const dotenvEnv = (ctx?.dotenv ?? {});
479
498
  const cfgRaw = (ctx?.pluginConfigs?.['batch'] ?? {});
480
499
  const cfg = (cfgRaw || {});
481
500
  const raw = thisCommand.opts();
@@ -498,6 +517,7 @@ const buildParentAction = (cli, opts) => async (commandParts, thisCommand) => {
498
517
  const commandArg = resolved;
499
518
  await execShellCommandBatch({
500
519
  command: commandArg,
520
+ dotenvEnv,
501
521
  globs,
502
522
  ignoreErrors,
503
523
  list: false,
@@ -535,6 +555,7 @@ const buildParentAction = (cli, opts) => async (commandParts, thisCommand) => {
535
555
  const shellOpt = opts.shell ?? cfg.shell ?? mergedBag.shell;
536
556
  await execShellCommandBatch({
537
557
  command: resolveCommand(scriptsOpt, commandOpt),
558
+ dotenvEnv,
538
559
  globs,
539
560
  ignoreErrors,
540
561
  list,
@@ -578,7 +599,8 @@ const BatchConfigSchema = z.object({
578
599
  /**
579
600
  * Batch plugin for the GetDotenv CLI host.
580
601
  *
581
- * Mirrors the legacy batch subcommand behavior without altering the shipped CLI. * Options:
602
+ * Mirrors the legacy batch subcommand behavior without altering the shipped CLI.
603
+ * Options:
582
604
  * - scripts/shell: used to resolve command and shell behavior per script or global default.
583
605
  * - logger: defaults to console.
584
606
  */
@@ -590,12 +612,32 @@ const batchPlugin = (opts = {}) => definePlugin({
590
612
  setup(cli) {
591
613
  const ns = cli.ns('batch');
592
614
  const batchCmd = ns; // capture the parent "batch" command for default-subcommand context
615
+ const host = cli;
616
+ const pluginId = 'batch';
617
+ const GROUP = `plugin:${pluginId}`;
593
618
  ns.description('Batch command execution across multiple working directories.')
594
619
  .enablePositionalOptions()
595
620
  .passThroughOptions()
596
- .option('-p, --pkg-cwd', 'use nearest package directory as current working directory')
597
- .option('-r, --root-path <string>', 'path to batch root directory from current working directory', './')
598
- .option('-g, --globs <string>', 'space-delimited globs from root path', '*')
621
+ // Dynamic help: show effective defaults from the merged/interpolated plugin config slice.
622
+ .addOption((() => {
623
+ const opt = host.createDynamicOption('-p, --pkg-cwd', (cfg) => {
624
+ const slice = cfg.plugins.batch ?? {};
625
+ const on = !!slice.pkgCwd;
626
+ return `use nearest package directory as current working directory${on ? ' (default)' : ''}`;
627
+ });
628
+ opt.__group = GROUP;
629
+ return opt;
630
+ })())
631
+ .addOption((() => {
632
+ const opt = host.createDynamicOption('-r, --root-path <string>', (cfg) => `path to batch root directory from current working directory (default: ${JSON.stringify(cfg.plugins.batch?.rootPath || './')})`);
633
+ opt.__group = GROUP;
634
+ return opt;
635
+ })())
636
+ .addOption((() => {
637
+ const opt = host.createDynamicOption('-g, --globs <string>', (cfg) => `space-delimited globs from root path (default: ${JSON.stringify(cfg.plugins.batch?.globs || '*')})`);
638
+ opt.__group = GROUP;
639
+ return opt;
640
+ })())
599
641
  .option('-c, --command <string>', 'command executed according to the base shell resolution')
600
642
  .option('-l, --list', 'list working directories without executing command')
601
643
  .option('-e, --ignore-errors', 'ignore errors and continue with next path')