@karmaniverous/get-dotenv 6.1.1 → 6.2.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.
package/dist/cliHost.d.ts CHANGED
@@ -113,9 +113,21 @@ declare const defineScripts: <TShell extends string | boolean>() => <T extends S
113
113
  * @public
114
114
  */
115
115
  interface GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> {
116
+ /**
117
+ * Fully resolved option bag used to compute this context.
118
+ */
116
119
  optionsResolved: TOptions;
120
+ /**
121
+ * Final composed dotenv environment for this invocation.
122
+ */
117
123
  dotenv: ProcessEnv;
124
+ /**
125
+ * Optional runtime plugin state bag. Plugins may publish non-sensitive metadata here.
126
+ */
118
127
  plugins?: Record<string, unknown>;
128
+ /**
129
+ * Per-plugin validated configuration slices keyed by realized mount path.
130
+ */
119
131
  pluginConfigs?: Record<string, unknown>;
120
132
  }
121
133
  /**
@@ -141,6 +153,14 @@ interface BrandOptions {
141
153
  * For the current step this mirrors the RAW schema; later stages may further
142
154
  * narrow types post-resolution in the host pipeline.
143
155
  */
156
+ /**
157
+ * CLI options schema (resolved).
158
+ *
159
+ * Today this mirrors {@link getDotenvCliOptionsSchemaRaw}, but is kept as a distinct export
160
+ * so future resolution steps can narrow or materialize defaults without breaking the API.
161
+ *
162
+ * @public
163
+ */
144
164
  declare const getDotenvCliOptionsSchemaResolved: z.ZodObject<{
145
165
  defaultEnv: z.ZodOptional<z.ZodString>;
146
166
  dotenvToken: z.ZodOptional<z.ZodString>;
@@ -184,6 +204,14 @@ declare const getDotenvCliOptionsSchemaResolved: z.ZodObject<{
184
204
  * For now, this mirrors the RAW schema; future stages may materialize defaults
185
205
  * and narrow shapes as resolution is wired into the host.
186
206
  */
207
+ /**
208
+ * Programmatic options schema (resolved).
209
+ *
210
+ * Today this mirrors {@link getDotenvOptionsSchemaRaw}, but is kept as a distinct export
211
+ * so future resolution steps can narrow or materialize defaults without breaking the API.
212
+ *
213
+ * @public
214
+ */
187
215
  declare const getDotenvOptionsSchemaResolved: z.ZodObject<{
188
216
  defaultEnv: z.ZodOptional<z.ZodString>;
189
217
  dotenvToken: z.ZodOptional<z.ZodString>;
@@ -238,7 +266,7 @@ type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
238
266
  * Canonical programmatic options type (schema-derived).
239
267
  * This type is the single source of truth for programmatic options.
240
268
  */
241
- type GetDotenvOptions = z.output<typeof getDotenvOptionsSchemaResolved> & {
269
+ type GetDotenvOptions = Omit<z.output<typeof getDotenvOptionsSchemaResolved>, 'logger' | 'dynamic'> & {
242
270
  /**
243
271
  * Compile-time overlay: narrowed logger for DX (schema stores unknown).
244
272
  */
@@ -259,11 +287,15 @@ type Scripts = ScriptsTable;
259
287
  * stringly paths/vars, and inherited programmatic fields (minus normalized
260
288
  * shapes that are handled by resolution).
261
289
  */
262
- type GetDotenvCliOptions = z.output<typeof getDotenvCliOptionsSchemaResolved> & {
290
+ type GetDotenvCliOptions = Omit<z.output<typeof getDotenvCliOptionsSchemaResolved>, 'logger' | 'dynamic' | 'scripts'> & {
263
291
  /**
264
292
  * Compile-only overlay for DX: logger narrowed from unknown.
265
293
  */
266
294
  logger: Logger;
295
+ /**
296
+ * Compile-only overlay for DX: dynamic map narrowed from unknown.
297
+ */
298
+ dynamic?: GetDotenvDynamic;
267
299
  /**
268
300
  * Compile-only overlay for DX: scripts narrowed from Record\<string, unknown\>.
269
301
  */
@@ -336,13 +368,37 @@ interface GetDotenvCliPublic<TOptions extends GetDotenvOptions = GetDotenvOption
336
368
  getCtx(): GetDotenvCliCtx<TOptions>;
337
369
  /** Check whether a context has been resolved (non-throwing). */
338
370
  hasCtx(): boolean;
371
+ /**
372
+ * Resolve options and compute the dotenv context for this invocation.
373
+ *
374
+ * @param customOptions - Partial options to overlay for this invocation.
375
+ * @param opts - Optional resolver behavior switches (for example, whether to run `afterResolve`).
376
+ * @returns A promise resolving to the computed invocation context.
377
+ */
339
378
  resolveAndLoad(customOptions?: Partial<TOptions>, opts?: ResolveAndLoadOptions): Promise<GetDotenvCliCtx<TOptions>>;
379
+ /**
380
+ * Tag an option with a help group identifier for grouped root help rendering.
381
+ *
382
+ * @param opt - The Commander option to tag.
383
+ * @param group - Group identifier (for example, `base`, `app`, or `plugin:<name>`).
384
+ * @returns Nothing.
385
+ */
340
386
  setOptionGroup(opt: Option, group: string): void;
341
387
  /**
342
388
  * Create a dynamic option whose description is computed at help time
343
389
  * from the resolved configuration.
344
390
  */
391
+ /**
392
+ * Create a dynamic option whose description is computed at help time from the resolved configuration.
393
+ *
394
+ * @param flags - Commander option flags usage string.
395
+ * @param desc - Description builder called during help rendering with the resolved help config.
396
+ * @param parser - Optional argument parser.
397
+ * @param defaultValue - Optional default value.
398
+ * @returns A Commander `Option` instance with a dynamic description.
399
+ */
345
400
  createDynamicOption<Usage extends string>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option<Usage>;
401
+ /** {@inheritDoc} */
346
402
  createDynamicOption<Usage extends string, TValue = unknown>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser: (value: string, previous?: TValue) => TValue, defaultValue?: TValue): Option<Usage>;
347
403
  }
348
404
  /**
@@ -405,7 +461,27 @@ interface GetDotenvCliPlugin<TOptions extends GetDotenvOptions = GetDotenvOption
405
461
  * return types from definePlugin provide stronger DX for shipped/typed plugins.
406
462
  */
407
463
  interface PluginWithInstanceHelpers<TOptions extends GetDotenvOptions = GetDotenvOptions, TConfig = unknown, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> extends GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal> {
464
+ /**
465
+ * Read the validated (and interpolated) configuration slice for this plugin instance.
466
+ *
467
+ * @param cli - The plugin mount (or any command under this mount) used to resolve the invocation context.
468
+ * @returns The plugin configuration slice, typed as `TCfg`.
469
+ * @throws Error when called before the host has resolved the invocation context.
470
+ */
408
471
  readConfig<TCfg = TConfig>(cli: GetDotenvCliPublic<TOptions, unknown[], OptionValues, OptionValues>): Readonly<TCfg>;
472
+ /**
473
+ * Create a Commander option whose help-time description receives the resolved root help config
474
+ * and this plugin instance’s validated configuration slice.
475
+ *
476
+ * @typeParam TCfg - The plugin configuration slice type.
477
+ * @typeParam Usage - The Commander usage string for the option flags.
478
+ * @param cli - The plugin mount used to associate the option with a realized mount path.
479
+ * @param flags - Commander option flags usage string.
480
+ * @param desc - Description builder receiving the resolved help config and the plugin config slice.
481
+ * @param parser - Optional argument parser.
482
+ * @param defaultValue - Optional default value.
483
+ * @returns A Commander `Option` instance with a dynamic description.
484
+ */
409
485
  createPluginDynamicOption<TCfg = TConfig, Usage extends string = string>(cli: GetDotenvCliPublic<TOptions, unknown[], OptionValues, OptionValues>, flags: Usage, desc: (cfg: ResolvedHelpConfig, pluginCfg: Readonly<TCfg>) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option<Usage>;
410
486
  }
411
487
  /**
@@ -417,6 +493,14 @@ type DefineSpec<TOptions extends GetDotenvOptions = GetDotenvOptions, TArgs exte
417
493
  * passes it into setup; return void | Promise<void>.
418
494
  */
419
495
  ns: string;
496
+ /**
497
+ * Plugin setup hook.
498
+ *
499
+ * Called by the host during installation to attach commands/options/hooks to the provided mount.
500
+ *
501
+ * @param cli - The command mount created by the host for this plugin instance.
502
+ * @returns Nothing (or a promise resolving to nothing) after setup completes.
503
+ */
420
504
  setup: (cli: GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>) => void | Promise<void>;
421
505
  };
422
506
  /**
@@ -441,6 +525,27 @@ declare function definePlugin<TOptions extends GetDotenvOptions>(spec: DefineSpe
441
525
  * Checks GETDOTENV_STDIO env var or the provided bag capture flag.
442
526
  */
443
527
  declare const shouldCapture: (bagCapture?: boolean) => boolean;
528
+ /**
529
+ * Result object returned by {@link runCommandResult}.
530
+ *
531
+ * @public
532
+ */
533
+ interface RunCommandResult {
534
+ /**
535
+ * Exit code of the child process.
536
+ *
537
+ * Conventionally, `0` indicates success.
538
+ */
539
+ exitCode: number;
540
+ /**
541
+ * Captured standard output (stdout) as UTF-8 text.
542
+ */
543
+ stdout: string;
544
+ /**
545
+ * Captured standard error (stderr) as UTF-8 text.
546
+ */
547
+ stderr: string;
548
+ }
444
549
  /**
445
550
  * Options for runCommandResult (buffered execution).
446
551
  *
@@ -485,17 +590,33 @@ interface RunCommandOptions {
485
590
  * - Never re-emits stdout/stderr to parent; returns captured buffers.
486
591
  * - Supports optional timeout (ms).
487
592
  */
488
- declare function runCommandResult(command: readonly string[], shell: false, opts?: RunCommandResultOptions): Promise<{
489
- exitCode: number;
490
- stdout: string;
491
- stderr: string;
492
- }>;
493
- declare function runCommandResult(command: string | readonly string[], shell: string | boolean | URL, opts?: RunCommandResultOptions): Promise<{
494
- exitCode: number;
495
- stdout: string;
496
- stderr: string;
497
- }>;
593
+ declare function runCommandResult(command: readonly string[], shell: false, opts?: RunCommandResultOptions): Promise<RunCommandResult>;
594
+ /**
595
+ * Execute a command and capture stdout/stderr (buffered).
596
+ *
597
+ * @param command - Command string (shell) or argv array (shell-off supported).
598
+ * @param shell - Shell setting (false for plain execution).
599
+ * @param opts - Execution options (cwd/env/timeout).
600
+ * @returns A promise resolving to the captured result.
601
+ */
602
+ declare function runCommandResult(command: string | readonly string[], shell: string | boolean | URL, opts?: RunCommandResultOptions): Promise<RunCommandResult>;
603
+ /**
604
+ * Execute a command and return its exit code.
605
+ *
606
+ * @param command - Command string (shell) or argv array (shell-off supported).
607
+ * @param shell - Shell setting (false for plain execution).
608
+ * @param opts - Execution options (cwd/env/stdio).
609
+ * @returns A promise resolving to the process exit code.
610
+ */
498
611
  declare function runCommand(command: readonly string[], shell: false, opts: RunCommandOptions): Promise<number>;
612
+ /**
613
+ * Execute a command and return its exit code.
614
+ *
615
+ * @param command - Command string (shell) or argv array (shell-off supported).
616
+ * @param shell - Shell setting (false for plain execution).
617
+ * @param opts - Execution options (cwd/env/stdio).
618
+ * @returns A promise resolving to the process exit code.
619
+ */
499
620
  declare function runCommand(command: string | readonly string[], shell: string | boolean | URL, opts: RunCommandOptions): Promise<number>;
500
621
 
501
622
  /** src/cliHost/GetDotenvCli.ts
@@ -639,6 +760,71 @@ declare class GetDotenvCli<TOptions extends GetDotenvOptions = GetDotenvOptions,
639
760
  */
640
761
  declare const getRootCommand: (cmd: CommandUnknownOpts) => CommandUnknownOpts;
641
762
 
763
+ /**
764
+ * Options for {@link groupPlugins}.
765
+ *
766
+ * This helper creates a “namespace-only” parent plugin (a command that exists only
767
+ * to group child plugins under a shared prefix, like `tooling getdotenv init`).
768
+ *
769
+ * The returned plugin is composable: call `.use(childPlugin)` to mount children.
770
+ *
771
+ * @typeParam TOptions - The host option bag type.
772
+ *
773
+ * @public
774
+ */
775
+ interface GroupPluginsOptions<TOptions extends GetDotenvOptions = GetDotenvOptions> {
776
+ /**
777
+ * Namespace for the grouping command (the command name used in the CLI).
778
+ */
779
+ ns: string;
780
+ /**
781
+ * Long-form description shown when rendering help for the group command.
782
+ */
783
+ description?: string;
784
+ /**
785
+ * Short summary shown in the parent command’s subcommand list.
786
+ */
787
+ summary?: string;
788
+ /**
789
+ * Help group heading for this command when listed in the parent’s help output.
790
+ */
791
+ helpGroup?: string;
792
+ /**
793
+ * Optional aliases for the group command (e.g., `['gd']`).
794
+ */
795
+ aliases?: string[];
796
+ /**
797
+ * Optional hook to customize the group command mount (e.g., attach a note or
798
+ * a small set of options). Avoid adding actions here; keep this a group.
799
+ */
800
+ configure?: (cli: GetDotenvCliPublic<TOptions>) => void | Promise<void>;
801
+ }
802
+ /**
803
+ * Create a namespace-only parent plugin (a group command) for composing plugins
804
+ * under a shared prefix.
805
+ *
806
+ * This is a convenience wrapper around {@link definePlugin} that performs no
807
+ * action by default and exists only for command organization.
808
+ *
809
+ * @example
810
+ * ```ts
811
+ * program.use(
812
+ * groupPlugins({
813
+ * ns: 'getdotenv',
814
+ * description: 'getdotenv utility functions',
815
+ * aliases: ['gd'],
816
+ * }).use(initPlugin()),
817
+ * );
818
+ * ```
819
+ *
820
+ * @typeParam TOptions - The host option bag type.
821
+ * @param options - Group plugin options.
822
+ * @returns A plugin instance that can `.use(...)` child plugins.
823
+ *
824
+ * @public
825
+ */
826
+ declare function groupPlugins<TOptions extends GetDotenvOptions = GetDotenvOptions>(options: GroupPluginsOptions<TOptions>): PluginWithInstanceHelpers<TOptions, {}>;
827
+
642
828
  /** src/cliHost/invoke.ts
643
829
  * Shared helpers for composing child env overlays and preserving argv for Node -e.
644
830
  */
@@ -720,6 +906,21 @@ declare const resolveCommand: (scripts: ScriptsTable | undefined, command: strin
720
906
  */
721
907
  declare const resolveShell: <TShell extends string | boolean>(scripts: ScriptsTable<TShell> | undefined, command: string, shell: TShell | undefined) => TShell | false;
722
908
 
909
+ /**
910
+ * Minimal shape accepted by {@link resolveCliOptions}.
911
+ *
912
+ * This exists to document the `scripts` property used for nesting and to avoid
913
+ * undocumented inline intersections in generated TypeDoc output.
914
+ *
915
+ * @public
916
+ */
917
+ interface ResolveCliOptionsShape extends Partial<RootOptionsShape> {
918
+ /**
919
+ * Optional scripts table, typically injected from configuration sources and/or
920
+ * inherited from a parent invocation via `process.env.getDotenvCliOptions`.
921
+ */
922
+ scripts?: ScriptsTable;
923
+ }
723
924
  /**
724
925
  * Result of CLI option resolution.
725
926
  */
@@ -741,9 +942,7 @@ interface ResolveCliOptionsResult<T> {
741
942
  * into a GetDotenvCliOptions-like object. Types are intentionally wide to
742
943
  * avoid cross-layer coupling; callers may cast as needed.
743
944
  */
744
- declare const resolveCliOptions: <T extends Partial<RootOptionsShape> & {
745
- scripts?: ScriptsTable;
746
- }>(rawCliOptions: unknown, defaults: Partial<T>, parentJson?: string) => ResolveCliOptionsResult<T>;
945
+ declare const resolveCliOptions: <T extends ResolveCliOptionsShape>(rawCliOptions: unknown, defaults: Partial<T>, parentJson?: string) => ResolveCliOptionsResult<T>;
747
946
 
748
947
  /**
749
948
  * Build a sanitized environment object for spawning child processes.
@@ -755,5 +954,5 @@ declare const resolveCliOptions: <T extends Partial<RootOptionsShape> & {
755
954
  */
756
955
  declare const buildSpawnEnv: (base?: NodeJS.ProcessEnv, overlay?: Record<string, string | undefined>) => NodeJS.ProcessEnv;
757
956
 
758
- export { GetDotenvCli, baseGetDotenvCliOptions, buildSpawnEnv, composeNestedEnv, definePlugin, defineScripts, getRootCommand, maybePreserveNodeEvalArgv, readMergedOptions, resolveCliOptions, resolveCommand, resolveShell, runCommand, runCommandResult, shouldCapture, stripOne, toHelpConfig };
759
- export type { BrandOptions, DefineSpec, GetDotenvCliCtx, GetDotenvCliOptions, GetDotenvCliPlugin, GetDotenvCliPublic, InferPluginConfig, PluginChildEntry, PluginFlattenedEntry, PluginNamespaceOverride, PluginWithInstanceHelpers, ResolveAndLoadOptions, ResolveCliOptionsResult, ResolvedHelpConfig, RootOptionsShape, RunCommandOptions, RunCommandResultOptions, ScriptDef, Scripts, ScriptsTable };
957
+ export { GetDotenvCli, baseGetDotenvCliOptions, buildSpawnEnv, composeNestedEnv, definePlugin, defineScripts, getRootCommand, groupPlugins, maybePreserveNodeEvalArgv, readMergedOptions, resolveCliOptions, resolveCommand, resolveShell, runCommand, runCommandResult, shouldCapture, stripOne, toHelpConfig };
958
+ export type { BrandOptions, DefineSpec, GetDotenvCliCtx, GetDotenvCliOptions, GetDotenvCliPlugin, GetDotenvCliPublic, GroupPluginsOptions, InferPluginConfig, PluginChildEntry, PluginFlattenedEntry, PluginNamespaceOverride, PluginWithInstanceHelpers, ResolveAndLoadOptions, ResolveCliOptionsResult, ResolvedHelpConfig, RootOptionsShape, RunCommandOptions, RunCommandResultOptions, ScriptDef, Scripts, ScriptsTable };
package/dist/cliHost.mjs CHANGED
@@ -21,26 +21,58 @@ import { Option, Command } from '@commander-js/extra-typings';
21
21
  * Minimal process env representation used by options and helpers.
22
22
  * Values may be `undefined` to indicate "unset".
23
23
  */
24
+ /**
25
+ * Schema for an env-like record.
26
+ *
27
+ * Keys are environment variable names and values are either strings or `undefined`
28
+ * (to represent “unset”).
29
+ *
30
+ * @public
31
+ */
24
32
  const processEnvSchema = z.record(z.string(), z.string().optional());
25
33
  // RAW: all fields optional — undefined means "inherit" from lower layers.
34
+ /**
35
+ * Programmatic options schema (raw).
36
+ *
37
+ * This schema is the canonical runtime source of truth for the `getDotenv()` programmatic API.
38
+ * All fields are optional; `undefined` generally means “inherit default/lower layer”.
39
+ *
40
+ * @public
41
+ */
26
42
  const getDotenvOptionsSchemaRaw = z.object({
43
+ /** Default environment name when `env` is not provided. */
27
44
  defaultEnv: z.string().optional(),
45
+ /** Base dotenv filename token (default `.env`). */
28
46
  dotenvToken: z.string().optional(),
47
+ /** Path to a dynamic variables module (JS/TS) to load and apply. */
29
48
  dynamicPath: z.string().optional(),
30
- // Dynamic map is intentionally wide for now; refine once sources are normalized.
49
+ /** Dynamic map is intentionally wide for now; refine once sources are normalized. */
31
50
  dynamic: z.record(z.string(), z.unknown()).optional(),
51
+ /** Selected environment name for this invocation (for env-scoped files and overlays). */
32
52
  env: z.string().optional(),
53
+ /** When true, skip applying dynamic variables. */
33
54
  excludeDynamic: z.boolean().optional(),
55
+ /** When true, skip environment-scoped dotenv files. */
34
56
  excludeEnv: z.boolean().optional(),
57
+ /** When true, skip global dotenv files. */
35
58
  excludeGlobal: z.boolean().optional(),
59
+ /** When true, skip private dotenv files. */
36
60
  excludePrivate: z.boolean().optional(),
61
+ /** When true, skip public dotenv files. */
37
62
  excludePublic: z.boolean().optional(),
63
+ /** When true, merge the final composed environment into `process.env`. */
38
64
  loadProcess: z.boolean().optional(),
65
+ /** When true, log the final environment map via `logger`. */
39
66
  log: z.boolean().optional(),
67
+ /** Logger used when `log` is enabled (console-compatible). */
40
68
  logger: z.unknown().default(console),
69
+ /** Optional output dotenv file path to write after composition. */
41
70
  outputPath: z.string().optional(),
71
+ /** Dotenv search paths (ordered). */
42
72
  paths: z.array(z.string()).optional(),
73
+ /** Private token suffix for private dotenv files (default `local`). */
43
74
  privateToken: z.string().optional(),
75
+ /** Explicit variables to overlay onto the composed dotenv map. */
44
76
  vars: processEnvSchema.optional(),
45
77
  });
46
78
  /**
@@ -48,6 +80,14 @@ const getDotenvOptionsSchemaRaw = z.object({
48
80
  * For now, this mirrors the RAW schema; future stages may materialize defaults
49
81
  * and narrow shapes as resolution is wired into the host.
50
82
  */
83
+ /**
84
+ * Programmatic options schema (resolved).
85
+ *
86
+ * Today this mirrors {@link getDotenvOptionsSchemaRaw}, but is kept as a distinct export
87
+ * so future resolution steps can narrow or materialize defaults without breaking the API.
88
+ *
89
+ * @public
90
+ */
51
91
  const getDotenvOptionsSchemaResolved = getDotenvOptionsSchemaRaw;
52
92
 
53
93
  /**
@@ -57,27 +97,55 @@ const getDotenvOptionsSchemaResolved = getDotenvOptionsSchemaRaw;
57
97
  * reflect normalized types (paths: string[], vars: ProcessEnv), applied in the
58
98
  * CLI resolution pipeline.
59
99
  */
100
+ /**
101
+ * CLI options schema (raw).
102
+ *
103
+ * Extends the programmatic options schema with CLI-only flags and stringly inputs
104
+ * which are normalized later by the host resolution pipeline.
105
+ *
106
+ * @public
107
+ */
60
108
  const getDotenvCliOptionsSchemaRaw = getDotenvOptionsSchemaRaw.extend({
61
109
  // CLI-specific fields (stringly inputs before preprocessing)
110
+ /** Enable verbose debug output (host-specific). */
62
111
  debug: z.boolean().optional(),
112
+ /** Fail on validation errors (schema/requiredKeys). */
63
113
  strict: z.boolean().optional(),
114
+ /** Capture child process stdio (useful for CI/tests). */
64
115
  capture: z.boolean().optional(),
116
+ /** Emit child env diagnostics (boolean or selected keys). */
65
117
  trace: z.union([z.boolean(), z.array(z.string())]).optional(),
118
+ /** Enable presentation-time redaction in trace/log output. */
66
119
  redact: z.boolean().optional(),
120
+ /** Enable entropy warnings in trace/log output. */
67
121
  warnEntropy: z.boolean().optional(),
122
+ /** Entropy threshold (bits/char) for warnings. */
68
123
  entropyThreshold: z.number().optional(),
124
+ /** Minimum value length to consider for entropy warnings. */
69
125
  entropyMinLength: z.number().optional(),
126
+ /** Regex patterns (strings) to suppress entropy warnings by key. */
70
127
  entropyWhitelist: z.array(z.string()).optional(),
128
+ /** Additional key-match patterns (strings) for redaction. */
71
129
  redactPatterns: z.array(z.string()).optional(),
130
+ /** Dotenv search paths provided as a single delimited string. */
72
131
  paths: z.string().optional(),
132
+ /** Delimiter string used to split `paths`. */
73
133
  pathsDelimiter: z.string().optional(),
134
+ /** Regex pattern used to split `paths` (takes precedence over delimiter). */
74
135
  pathsDelimiterPattern: z.string().optional(),
136
+ /** Scripts table in a permissive shape at parse time (validated elsewhere). */
75
137
  scripts: z.record(z.string(), z.unknown()).optional(),
138
+ /** Shell selection (`false` for shell-off, string for explicit shell). */
76
139
  shell: z.union([z.boolean(), z.string()]).optional(),
140
+ /** Extra variables expressed as a single delimited string of assignments. */
77
141
  vars: z.string().optional(),
142
+ /** Assignment operator used when parsing `vars`. */
78
143
  varsAssignor: z.string().optional(),
144
+ /** Regex pattern used as the assignment operator for `vars` parsing. */
79
145
  varsAssignorPattern: z.string().optional(),
146
+ /** Delimiter string used to split `vars`. */
80
147
  varsDelimiter: z.string().optional(),
148
+ /** Regex pattern used to split `vars` (takes precedence over delimiter). */
81
149
  varsDelimiterPattern: z.string().optional(),
82
150
  });
83
151
 
@@ -101,17 +169,34 @@ const envStringMap = z.record(z.string(), stringMap);
101
169
  * Raw configuration schema for get‑dotenv config files (JSON/YAML/JS/TS).
102
170
  * Validates allowed top‑level keys without performing path normalization.
103
171
  */
172
+ /**
173
+ * Config schema for discovered get-dotenv configuration documents (raw).
174
+ *
175
+ * This schema validates the allowed top-level keys for configuration files.
176
+ * It does not normalize paths or coerce types beyond Zod’s parsing.
177
+ *
178
+ * @public
179
+ */
104
180
  const getDotenvConfigSchemaRaw = z.object({
181
+ /** Root option defaults applied by the host (CLI-like, collapsed families). */
105
182
  rootOptionDefaults: getDotenvCliOptionsSchemaRaw.optional(),
183
+ /** Help-time visibility map for root flags (false hides). */
106
184
  rootOptionVisibility: visibilityMap.optional(),
107
- scripts: z.record(z.string(), z.unknown()).optional(), // Scripts validation left wide; generator validates elsewhere
185
+ /** Scripts table used by cmd/batch resolution (validation intentionally permissive here). */
186
+ scripts: z.record(z.string(), z.unknown()).optional(),
187
+ /** Keys required to be present in the final composed environment. */
108
188
  requiredKeys: z.array(z.string()).optional(),
189
+ /** Validation schema (JS/TS only; JSON/YAML loader rejects). */
109
190
  schema: z.unknown().optional(), // JS/TS-only; loader rejects in JSON/YAML
191
+ /** Public global variables (string-only). */
110
192
  vars: stringMap.optional(), // public, global
193
+ /** Public per-environment variables (string-only). */
111
194
  envVars: envStringMap.optional(), // public, per-env
112
195
  // Dynamic in config (JS/TS only). JSON/YAML loader will reject if set.
196
+ /** Dynamic variable definitions (JS/TS only). */
113
197
  dynamic: z.unknown().optional(),
114
198
  // Per-plugin config bag; validated by plugins/host when used.
199
+ /** Per-plugin config slices keyed by realized mount path (for example, `aws/whoami`). */
115
200
  plugins: z.record(z.string(), z.unknown()).optional(),
116
201
  });
117
202
  /**
@@ -863,13 +948,21 @@ const redactObject = (obj, opts) => {
863
948
  * Base root CLI defaults (shared; kept untyped here to avoid cross-layer deps).
864
949
  * Used as the bottom layer for CLI option resolution.
865
950
  */
951
+ const baseScripts = {
952
+ 'git-status': {
953
+ cmd: 'git branch --show-current && git status -s -u',
954
+ shell: true,
955
+ },
956
+ };
866
957
  /**
867
- * Default values for root CLI options used by the host and helpers as the
868
- * baseline layer during option resolution.
958
+ * Default values for root CLI options used by the host and helpers as the baseline layer during option resolution.
869
959
  *
870
- * These defaults correspond to the "stringly" root surface (see `RootOptionsShape`)
871
- * and are merged by precedence with create-time overrides and any discovered
872
- * configuration `rootOptionDefaults` before CLI flags are applied.
960
+ * These defaults correspond to the stringly root surface (see `RootOptionsShape`) and are merged by precedence with:
961
+ * - create-time overrides
962
+ * - any discovered configuration `rootOptionDefaults`
963
+ * - and finally CLI flags at runtime
964
+ *
965
+ * @public
873
966
  */
874
967
  const baseRootOptionDefaults = {
875
968
  dotenvToken: '.env',
@@ -883,12 +976,7 @@ const baseRootOptionDefaults = {
883
976
  paths: './',
884
977
  pathsDelimiter: ' ',
885
978
  privateToken: 'local',
886
- scripts: {
887
- 'git-status': {
888
- cmd: 'git branch --show-current && git status -s -u',
889
- shell: true,
890
- },
891
- },
979
+ scripts: baseScripts,
892
980
  shell: true,
893
981
  vars: '',
894
982
  varsAssignor: '=',
@@ -1435,6 +1523,14 @@ async function _execNormalized(command, shell, opts = {}) {
1435
1523
  return out;
1436
1524
  }
1437
1525
  }
1526
+ /**
1527
+ * Execute a command and capture stdout/stderr (buffered).
1528
+ *
1529
+ * @param command - Command string (shell) or argv array (shell-off supported).
1530
+ * @param shell - Shell setting (false for plain execution).
1531
+ * @param opts - Execution options (cwd/env/timeout).
1532
+ * @returns A promise resolving to the captured result.
1533
+ */
1438
1534
  async function runCommandResult(command, shell, opts = {}) {
1439
1535
  // Build opts without injecting undefined (exactOptionalPropertyTypes-safe)
1440
1536
  const coreOpts = { stdio: 'pipe' };
@@ -1449,6 +1545,14 @@ async function runCommandResult(command, shell, opts = {}) {
1449
1545
  }
1450
1546
  return _execNormalized(command, shell, coreOpts);
1451
1547
  }
1548
+ /**
1549
+ * Execute a command and return its exit code.
1550
+ *
1551
+ * @param command - Command string (shell) or argv array (shell-off supported).
1552
+ * @param shell - Shell setting (false for plain execution).
1553
+ * @param opts - Execution options (cwd/env/stdio).
1554
+ * @returns A promise resolving to the process exit code.
1555
+ */
1452
1556
  async function runCommand(command, shell, opts) {
1453
1557
  // Build opts without injecting undefined (exactOptionalPropertyTypes-safe)
1454
1558
  const callOpts = {};
@@ -1908,6 +2012,16 @@ function evaluateDynamicOptions(root, resolved) {
1908
2012
  visit(root);
1909
2013
  }
1910
2014
 
2015
+ /**
2016
+ * Initialize a {@link GetDotenvCli} instance with help configuration and safe defaults.
2017
+ *
2018
+ * @remarks
2019
+ * This is a low-level initializer used by the host constructor to keep `GetDotenvCli.ts`
2020
+ * small and to centralize help/output behavior.
2021
+ *
2022
+ * @param cli - The CLI instance to initialize.
2023
+ * @param headerGetter - Callback returning an optional help header string.
2024
+ */
1911
2025
  function initializeInstance(cli, headerGetter) {
1912
2026
  // Configure grouped help: show only base options in default "Options";
1913
2027
  // subcommands show all of their own options.
@@ -2344,6 +2458,56 @@ const getRootCommand = (cmd) => {
2344
2458
  return node;
2345
2459
  };
2346
2460
 
2461
+ /**
2462
+ * Create a namespace-only parent plugin (a group command) for composing plugins
2463
+ * under a shared prefix.
2464
+ *
2465
+ * This is a convenience wrapper around {@link definePlugin} that performs no
2466
+ * action by default and exists only for command organization.
2467
+ *
2468
+ * @example
2469
+ * ```ts
2470
+ * program.use(
2471
+ * groupPlugins({
2472
+ * ns: 'getdotenv',
2473
+ * description: 'getdotenv utility functions',
2474
+ * aliases: ['gd'],
2475
+ * }).use(initPlugin()),
2476
+ * );
2477
+ * ```
2478
+ *
2479
+ * @typeParam TOptions - The host option bag type.
2480
+ * @param options - Group plugin options.
2481
+ * @returns A plugin instance that can `.use(...)` child plugins.
2482
+ *
2483
+ * @public
2484
+ */
2485
+ function groupPlugins(options) {
2486
+ const ns = typeof options.ns === 'string' && options.ns.trim().length > 0
2487
+ ? options.ns.trim()
2488
+ : '';
2489
+ if (!ns)
2490
+ throw new Error('groupPlugins: options.ns must be a non-empty string.');
2491
+ return definePlugin({
2492
+ ns,
2493
+ async setup(cli) {
2494
+ if (typeof options.description === 'string')
2495
+ cli.description(options.description);
2496
+ if (typeof options.summary === 'string')
2497
+ cli.summary(options.summary);
2498
+ if (typeof options.helpGroup === 'string')
2499
+ cli.helpGroup(options.helpGroup);
2500
+ if (Array.isArray(options.aliases) && options.aliases.length > 0) {
2501
+ cli.aliases(options.aliases);
2502
+ }
2503
+ if (typeof options.configure === 'function') {
2504
+ await options.configure(cli);
2505
+ }
2506
+ return undefined;
2507
+ },
2508
+ });
2509
+ }
2510
+
2347
2511
  /**
2348
2512
  * Build a help-time configuration bag for dynamic option descriptions.
2349
2513
  * Centralizes construction and reduces inline casts at call sites.
@@ -2648,4 +2812,4 @@ const buildSpawnEnv = (base, overlay) => {
2648
2812
  */
2649
2813
  const defineScripts = () => (t) => t;
2650
2814
 
2651
- export { GetDotenvCli, baseGetDotenvCliOptions, buildSpawnEnv, composeNestedEnv, definePlugin, defineScripts, getRootCommand, maybePreserveNodeEvalArgv, readMergedOptions, resolveCliOptions, resolveCommand, resolveShell, runCommand, runCommandResult, shouldCapture, stripOne, toHelpConfig };
2815
+ export { GetDotenvCli, baseGetDotenvCliOptions, buildSpawnEnv, composeNestedEnv, definePlugin, defineScripts, getRootCommand, groupPlugins, maybePreserveNodeEvalArgv, readMergedOptions, resolveCliOptions, resolveCommand, resolveShell, runCommand, runCommandResult, shouldCapture, stripOne, toHelpConfig };
package/dist/config.d.ts CHANGED
@@ -120,6 +120,11 @@ type ProcessEnv = Record<string, string | undefined>;
120
120
  */
121
121
  type Scripts = ScriptsTable;
122
122
 
123
+ /**
124
+ * Resolved configuration object type returned by {@link getDotenvConfigSchemaResolved}.
125
+ *
126
+ * @public
127
+ */
123
128
  type GetDotenvConfigResolved = {
124
129
  /**
125
130
  * Help-time/runtime root defaults applied by the host (collapsed families; CLI‑like).
@@ -195,6 +200,13 @@ declare const discoverConfigFiles: (importMetaUrl?: string) => Promise<ConfigFil
195
200
  * For JS/TS: default export is loaded; "dynamic" is allowed.
196
201
  */
197
202
  declare const loadConfigFile: (filePath: string) => Promise<GetDotenvConfigResolved>;
203
+ /**
204
+ * Loaded configuration sources keyed by origin scope and privacy.
205
+ *
206
+ * This is the primary output of {@link resolveGetDotenvConfigSources}.
207
+ *
208
+ * @public
209
+ */
198
210
  interface ResolvedConfigSources {
199
211
  /** Configuration from the package root (public only). */
200
212
  packaged?: GetDotenvConfigResolved;