@karmaniverous/get-dotenv 6.0.0 → 6.1.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.
@@ -151,6 +151,10 @@ function defaultsDeep(...layers) {
151
151
  /**
152
152
  * Serialize a dotenv record to a file with minimal quoting (multiline values are quoted).
153
153
  * Future-proofs for ordering/sorting changes (currently insertion order).
154
+ *
155
+ * @param filename - Destination dotenv file path.
156
+ * @param data - Env-like map of values to write (values may be `undefined`).
157
+ * @returns A `Promise\<void\>` which resolves when the file has been written.
154
158
  */
155
159
  async function writeDotenvFile(filename, data) {
156
160
  // Serialize: key=value with quotes only for multiline values.
@@ -386,14 +390,20 @@ const cleanupOldCacheFiles = async (cacheDir, baseName, keep = Math.max(1, Numbe
386
390
  }
387
391
  };
388
392
  /**
389
- * Load a module default export from a JS/TS file with robust fallbacks:
390
- * - .js/.mjs/.cjs: direct import * - .ts/.mts/.cts/.tsx:
391
- * 1) try direct import (if a TS loader is active),
392
- * 2) esbuild bundle to a temp ESM file,
393
- * 3) typescript.transpileModule fallback for simple modules.
393
+ * Load a module default export from a JS/TS file with robust fallbacks.
394
+ *
395
+ * Behavior by extension:
396
+ *
397
+ * - `.js`/`.mjs`/`.cjs`: direct dynamic import.
398
+ * - `.ts`/`.mts`/`.cts`/`.tsx`:
399
+ * - try direct dynamic import (when a TS loader is active),
400
+ * - else compile via `esbuild` to a cached `.mjs` file and import,
401
+ * - else fallback to `typescript.transpileModule` for simple modules.
394
402
  *
395
- * @param absPath - absolute path to source file
396
- * @param cacheDirName - cache subfolder under .tsbuild
403
+ * @typeParam T - Type of the expected default export.
404
+ * @param absPath - Absolute path to the source file.
405
+ * @param cacheDirName - Cache subfolder under `.tsbuild/`.
406
+ * @returns A `Promise\<T | undefined\>` resolving to the default export (if any).
397
407
  */
398
408
  const loadModuleDefault = async (absPath, cacheDirName) => {
399
409
  const ext = path.extname(absPath).toLowerCase();
@@ -465,6 +475,10 @@ const loadModuleDefault = async (absPath, cacheDirName) => {
465
475
  /**
466
476
  * Omit keys whose runtime value is undefined from a shallow object.
467
477
  * Returns a Partial with non-undefined value types preserved.
478
+ *
479
+ * @typeParam T - Input object shape.
480
+ * @param obj - Object to filter.
481
+ * @returns A shallow copy of `obj` without keys whose value is `undefined`.
468
482
  */
469
483
  function omitUndefined(obj) {
470
484
  const out = {};
@@ -476,6 +490,10 @@ function omitUndefined(obj) {
476
490
  }
477
491
  /**
478
492
  * Specialized helper for env-like maps: drop undefined and return string-only.
493
+ *
494
+ * @typeParam V - Value type for present entries (must extend `string`).
495
+ * @param obj - Env-like record containing `string | undefined` values.
496
+ * @returns A new record containing only the keys with defined values.
479
497
  */
480
498
  function omitUndefinedRecord(obj) {
481
499
  const out = {};
@@ -690,6 +708,11 @@ const resolveGetDotenvConfigSources = async (importMetaUrl) => {
690
708
  * Apply a dynamic map to the target progressively.
691
709
  * - Functions receive (target, env) and may return string | undefined.
692
710
  * - Literals are assigned directly (including undefined).
711
+ *
712
+ * @param target - Mutable target environment to assign into.
713
+ * @param map - Dynamic map to apply (functions and/or literal values).
714
+ * @param env - Selected environment name (if any) passed through to dynamic functions.
715
+ * @returns Nothing.
693
716
  */
694
717
  function applyDynamicMap(target, map, env) {
695
718
  if (!map)
@@ -709,6 +732,12 @@ function applyDynamicMap(target, map, env) {
709
732
  * Error behavior:
710
733
  * - On failure to load/compile/evaluate the module, throws a unified message:
711
734
  * "Unable to load dynamic TypeScript file: <absPath>. Install 'esbuild'..."
735
+ *
736
+ * @param target - Mutable target environment to assign into.
737
+ * @param absPath - Absolute path to the dynamic module file.
738
+ * @param env - Selected environment name (if any).
739
+ * @param cacheDirName - Cache subdirectory under `.tsbuild/` for compiled artifacts.
740
+ * @returns A `Promise\<void\>` which resolves after the module (if present) has been applied.
712
741
  */
713
742
  async function loadAndApplyDynamic(target, absPath, env, cacheDirName) {
714
743
  if (!(await fs.exists(absPath)))
@@ -1799,6 +1828,10 @@ function renderOptionGroups(cmd) {
1799
1828
  /**
1800
1829
  * Compose root/parent help output by inserting grouped sections between
1801
1830
  * Options and Commands, ensuring a trailing blank line.
1831
+ *
1832
+ * @param base - Base help text produced by Commander.
1833
+ * @param cmd - Command instance whose grouped options should be rendered.
1834
+ * @returns The modified help text with grouped blocks inserted.
1802
1835
  */
1803
1836
  function buildHelpInformation(base, cmd) {
1804
1837
  const groups = renderOptionGroups(cmd);
@@ -2395,7 +2428,10 @@ const buildSpawnEnv = (base, overlay) => {
2395
2428
  * Apply resolved AWS context to `process.env` and `ctx.plugins`.
2396
2429
  * Centralizes logic shared between the plugin action and `afterResolve` hook.
2397
2430
  *
2431
+ * @param out - Resolved AWS context to apply.
2432
+ * @param ctx - Host context to publish non-sensitive metadata into.
2398
2433
  * @param setProcessEnv - Whether to write credentials/region to `process.env` (default true).
2434
+ * @returns Nothing.
2399
2435
  */
2400
2436
  function applyAwsContext(out, ctx, setProcessEnv = true) {
2401
2437
  const { profile, region, credentials } = out;
@@ -2431,6 +2467,9 @@ const unquote = (s) => s.length >= 2 &&
2431
2467
  : s;
2432
2468
  /**
2433
2469
  * Parse AWS credentials from JSON output (AWS CLI v2 export-credentials).
2470
+ *
2471
+ * @param txt - Raw stdout text from the AWS CLI.
2472
+ * @returns Parsed credentials, or `undefined` when the input is not recognized.
2434
2473
  */
2435
2474
  const parseExportCredentialsJson = (txt) => {
2436
2475
  try {
@@ -2454,6 +2493,9 @@ const parseExportCredentialsJson = (txt) => {
2454
2493
  /**
2455
2494
  * Parse AWS credentials from environment-export output (shell-agnostic).
2456
2495
  * Supports POSIX `export KEY=VAL` and PowerShell `$Env:KEY=VAL`.
2496
+ *
2497
+ * @param txt - Raw stdout text from the AWS CLI.
2498
+ * @returns Parsed credentials, or `undefined` when the input is not recognized.
2457
2499
  */
2458
2500
  const parseExportCredentialsEnv = (txt) => {
2459
2501
  const lines = txt.split(/\r?\n/);
@@ -2539,6 +2581,7 @@ const exportCredentials = async (profile, timeoutMs = DEFAULT_TIMEOUT_MS) => {
2539
2581
  * Applies strategy (cli-export vs none) and handling for SSO login-on-demand.
2540
2582
  *
2541
2583
  * @param options - Context options including current dotenv and plugin config.
2584
+ * @returns A `Promise\<AwsContext\>` containing any resolved profile, region, and credentials.
2542
2585
  */
2543
2586
  const resolveAwsContext = async ({ dotenv, cfg, }) => {
2544
2587
  const profileKey = cfg.profileKey ?? 'AWS_LOCAL_PROFILE';
@@ -152,6 +152,10 @@ function defaultsDeep(...layers) {
152
152
  /**
153
153
  * Serialize a dotenv record to a file with minimal quoting (multiline values are quoted).
154
154
  * Future-proofs for ordering/sorting changes (currently insertion order).
155
+ *
156
+ * @param filename - Destination dotenv file path.
157
+ * @param data - Env-like map of values to write (values may be `undefined`).
158
+ * @returns A `Promise\<void\>` which resolves when the file has been written.
155
159
  */
156
160
  async function writeDotenvFile(filename, data) {
157
161
  // Serialize: key=value with quotes only for multiline values.
@@ -387,14 +391,20 @@ const cleanupOldCacheFiles = async (cacheDir, baseName, keep = Math.max(1, Numbe
387
391
  }
388
392
  };
389
393
  /**
390
- * Load a module default export from a JS/TS file with robust fallbacks:
391
- * - .js/.mjs/.cjs: direct import * - .ts/.mts/.cts/.tsx:
392
- * 1) try direct import (if a TS loader is active),
393
- * 2) esbuild bundle to a temp ESM file,
394
- * 3) typescript.transpileModule fallback for simple modules.
394
+ * Load a module default export from a JS/TS file with robust fallbacks.
395
+ *
396
+ * Behavior by extension:
397
+ *
398
+ * - `.js`/`.mjs`/`.cjs`: direct dynamic import.
399
+ * - `.ts`/`.mts`/`.cts`/`.tsx`:
400
+ * - try direct dynamic import (when a TS loader is active),
401
+ * - else compile via `esbuild` to a cached `.mjs` file and import,
402
+ * - else fallback to `typescript.transpileModule` for simple modules.
395
403
  *
396
- * @param absPath - absolute path to source file
397
- * @param cacheDirName - cache subfolder under .tsbuild
404
+ * @typeParam T - Type of the expected default export.
405
+ * @param absPath - Absolute path to the source file.
406
+ * @param cacheDirName - Cache subfolder under `.tsbuild/`.
407
+ * @returns A `Promise\<T | undefined\>` resolving to the default export (if any).
398
408
  */
399
409
  const loadModuleDefault = async (absPath, cacheDirName) => {
400
410
  const ext = path.extname(absPath).toLowerCase();
@@ -466,6 +476,10 @@ const loadModuleDefault = async (absPath, cacheDirName) => {
466
476
  /**
467
477
  * Omit keys whose runtime value is undefined from a shallow object.
468
478
  * Returns a Partial with non-undefined value types preserved.
479
+ *
480
+ * @typeParam T - Input object shape.
481
+ * @param obj - Object to filter.
482
+ * @returns A shallow copy of `obj` without keys whose value is `undefined`.
469
483
  */
470
484
  function omitUndefined(obj) {
471
485
  const out = {};
@@ -477,6 +491,10 @@ function omitUndefined(obj) {
477
491
  }
478
492
  /**
479
493
  * Specialized helper for env-like maps: drop undefined and return string-only.
494
+ *
495
+ * @typeParam V - Value type for present entries (must extend `string`).
496
+ * @param obj - Env-like record containing `string | undefined` values.
497
+ * @returns A new record containing only the keys with defined values.
480
498
  */
481
499
  function omitUndefinedRecord(obj) {
482
500
  const out = {};
@@ -691,6 +709,11 @@ const resolveGetDotenvConfigSources = async (importMetaUrl) => {
691
709
  * Apply a dynamic map to the target progressively.
692
710
  * - Functions receive (target, env) and may return string | undefined.
693
711
  * - Literals are assigned directly (including undefined).
712
+ *
713
+ * @param target - Mutable target environment to assign into.
714
+ * @param map - Dynamic map to apply (functions and/or literal values).
715
+ * @param env - Selected environment name (if any) passed through to dynamic functions.
716
+ * @returns Nothing.
694
717
  */
695
718
  function applyDynamicMap(target, map, env) {
696
719
  if (!map)
@@ -710,6 +733,12 @@ function applyDynamicMap(target, map, env) {
710
733
  * Error behavior:
711
734
  * - On failure to load/compile/evaluate the module, throws a unified message:
712
735
  * "Unable to load dynamic TypeScript file: <absPath>. Install 'esbuild'..."
736
+ *
737
+ * @param target - Mutable target environment to assign into.
738
+ * @param absPath - Absolute path to the dynamic module file.
739
+ * @param env - Selected environment name (if any).
740
+ * @param cacheDirName - Cache subdirectory under `.tsbuild/` for compiled artifacts.
741
+ * @returns A `Promise\<void\>` which resolves after the module (if present) has been applied.
713
742
  */
714
743
  async function loadAndApplyDynamic(target, absPath, env, cacheDirName) {
715
744
  if (!(await fs.exists(absPath)))
@@ -1781,6 +1810,10 @@ function renderOptionGroups(cmd) {
1781
1810
  /**
1782
1811
  * Compose root/parent help output by inserting grouped sections between
1783
1812
  * Options and Commands, ensuring a trailing blank line.
1813
+ *
1814
+ * @param base - Base help text produced by Commander.
1815
+ * @param cmd - Command instance whose grouped options should be rendered.
1816
+ * @returns The modified help text with grouped blocks inserted.
1784
1817
  */
1785
1818
  function buildHelpInformation(base, cmd) {
1786
1819
  const groups = renderOptionGroups(cmd);
@@ -2276,6 +2309,10 @@ class GetDotenvCli extends Command {
2276
2309
  /**
2277
2310
  * Compose a child-process env overlay from dotenv and the merged CLI options bag.
2278
2311
  * Returns a shallow object including getDotenvCliOptions when serializable.
2312
+ *
2313
+ * @param merged - Resolved CLI options bag (or a JSON-serializable subset).
2314
+ * @param dotenv - Composed dotenv variables for the current invocation.
2315
+ * @returns A string-only env overlay suitable for child process spawning.
2279
2316
  */
2280
2317
  function composeNestedEnv(merged, dotenv) {
2281
2318
  const out = {};
@@ -2298,6 +2335,7 @@ function composeNestedEnv(merged, dotenv) {
2298
2335
  * Strip one layer of symmetric outer quotes (single or double) from a string.
2299
2336
  *
2300
2337
  * @param s - Input string.
2338
+ * @returns `s` without one symmetric outer quote pair (when present).
2301
2339
  */
2302
2340
  const stripOne = (s) => {
2303
2341
  if (s.length < 2)
@@ -2310,6 +2348,9 @@ const stripOne = (s) => {
2310
2348
  /**
2311
2349
  * Preserve argv array for Node -e/--eval payloads under shell-off and
2312
2350
  * peel one symmetric outer quote layer from the code argument.
2351
+ *
2352
+ * @param args - Argument vector intended for direct execution (shell-off).
2353
+ * @returns Either the original `args` or a modified copy with a normalized eval payload.
2313
2354
  */
2314
2355
  function maybePreserveNodeEvalArgv(args) {
2315
2356
  if (args.length >= 3) {
@@ -151,6 +151,10 @@ function defaultsDeep(...layers) {
151
151
  /**
152
152
  * Serialize a dotenv record to a file with minimal quoting (multiline values are quoted).
153
153
  * Future-proofs for ordering/sorting changes (currently insertion order).
154
+ *
155
+ * @param filename - Destination dotenv file path.
156
+ * @param data - Env-like map of values to write (values may be `undefined`).
157
+ * @returns A `Promise\<void\>` which resolves when the file has been written.
154
158
  */
155
159
  async function writeDotenvFile(filename, data) {
156
160
  // Serialize: key=value with quotes only for multiline values.
@@ -386,14 +390,20 @@ const cleanupOldCacheFiles = async (cacheDir, baseName, keep = Math.max(1, Numbe
386
390
  }
387
391
  };
388
392
  /**
389
- * Load a module default export from a JS/TS file with robust fallbacks:
390
- * - .js/.mjs/.cjs: direct import * - .ts/.mts/.cts/.tsx:
391
- * 1) try direct import (if a TS loader is active),
392
- * 2) esbuild bundle to a temp ESM file,
393
- * 3) typescript.transpileModule fallback for simple modules.
393
+ * Load a module default export from a JS/TS file with robust fallbacks.
394
+ *
395
+ * Behavior by extension:
396
+ *
397
+ * - `.js`/`.mjs`/`.cjs`: direct dynamic import.
398
+ * - `.ts`/`.mts`/`.cts`/`.tsx`:
399
+ * - try direct dynamic import (when a TS loader is active),
400
+ * - else compile via `esbuild` to a cached `.mjs` file and import,
401
+ * - else fallback to `typescript.transpileModule` for simple modules.
394
402
  *
395
- * @param absPath - absolute path to source file
396
- * @param cacheDirName - cache subfolder under .tsbuild
403
+ * @typeParam T - Type of the expected default export.
404
+ * @param absPath - Absolute path to the source file.
405
+ * @param cacheDirName - Cache subfolder under `.tsbuild/`.
406
+ * @returns A `Promise\<T | undefined\>` resolving to the default export (if any).
397
407
  */
398
408
  const loadModuleDefault = async (absPath, cacheDirName) => {
399
409
  const ext = path.extname(absPath).toLowerCase();
@@ -465,6 +475,10 @@ const loadModuleDefault = async (absPath, cacheDirName) => {
465
475
  /**
466
476
  * Omit keys whose runtime value is undefined from a shallow object.
467
477
  * Returns a Partial with non-undefined value types preserved.
478
+ *
479
+ * @typeParam T - Input object shape.
480
+ * @param obj - Object to filter.
481
+ * @returns A shallow copy of `obj` without keys whose value is `undefined`.
468
482
  */
469
483
  function omitUndefined(obj) {
470
484
  const out = {};
@@ -476,6 +490,10 @@ function omitUndefined(obj) {
476
490
  }
477
491
  /**
478
492
  * Specialized helper for env-like maps: drop undefined and return string-only.
493
+ *
494
+ * @typeParam V - Value type for present entries (must extend `string`).
495
+ * @param obj - Env-like record containing `string | undefined` values.
496
+ * @returns A new record containing only the keys with defined values.
479
497
  */
480
498
  function omitUndefinedRecord(obj) {
481
499
  const out = {};
@@ -696,6 +714,11 @@ const resolveGetDotenvConfigSources = async (importMetaUrl) => {
696
714
  * Apply a dynamic map to the target progressively.
697
715
  * - Functions receive (target, env) and may return string | undefined.
698
716
  * - Literals are assigned directly (including undefined).
717
+ *
718
+ * @param target - Mutable target environment to assign into.
719
+ * @param map - Dynamic map to apply (functions and/or literal values).
720
+ * @param env - Selected environment name (if any) passed through to dynamic functions.
721
+ * @returns Nothing.
699
722
  */
700
723
  function applyDynamicMap(target, map, env) {
701
724
  if (!map)
@@ -715,6 +738,12 @@ function applyDynamicMap(target, map, env) {
715
738
  * Error behavior:
716
739
  * - On failure to load/compile/evaluate the module, throws a unified message:
717
740
  * "Unable to load dynamic TypeScript file: <absPath>. Install 'esbuild'..."
741
+ *
742
+ * @param target - Mutable target environment to assign into.
743
+ * @param absPath - Absolute path to the dynamic module file.
744
+ * @param env - Selected environment name (if any).
745
+ * @param cacheDirName - Cache subdirectory under `.tsbuild/` for compiled artifacts.
746
+ * @returns A `Promise\<void\>` which resolves after the module (if present) has been applied.
718
747
  */
719
748
  async function loadAndApplyDynamic(target, absPath, env, cacheDirName) {
720
749
  if (!(await fs.exists(absPath)))
@@ -1863,6 +1892,10 @@ function renderOptionGroups(cmd) {
1863
1892
  /**
1864
1893
  * Compose root/parent help output by inserting grouped sections between
1865
1894
  * Options and Commands, ensuring a trailing blank line.
1895
+ *
1896
+ * @param base - Base help text produced by Commander.
1897
+ * @param cmd - Command instance whose grouped options should be rendered.
1898
+ * @returns The modified help text with grouped blocks inserted.
1866
1899
  */
1867
1900
  function buildHelpInformation(base, cmd) {
1868
1901
  const groups = renderOptionGroups(cmd);
@@ -2364,6 +2397,10 @@ const baseGetDotenvCliOptions = baseRootOptionDefaults;
2364
2397
  /**
2365
2398
  * Compose a child-process env overlay from dotenv and the merged CLI options bag.
2366
2399
  * Returns a shallow object including getDotenvCliOptions when serializable.
2400
+ *
2401
+ * @param merged - Resolved CLI options bag (or a JSON-serializable subset).
2402
+ * @param dotenv - Composed dotenv variables for the current invocation.
2403
+ * @returns A string-only env overlay suitable for child process spawning.
2367
2404
  */
2368
2405
  function composeNestedEnv(merged, dotenv) {
2369
2406
  const out = {};
@@ -2386,6 +2423,7 @@ function composeNestedEnv(merged, dotenv) {
2386
2423
  * Strip one layer of symmetric outer quotes (single or double) from a string.
2387
2424
  *
2388
2425
  * @param s - Input string.
2426
+ * @returns `s` without one symmetric outer quote pair (when present).
2389
2427
  */
2390
2428
  const stripOne = (s) => {
2391
2429
  if (s.length < 2)
@@ -2398,6 +2436,9 @@ const stripOne = (s) => {
2398
2436
  /**
2399
2437
  * Preserve argv array for Node -e/--eval payloads under shell-off and
2400
2438
  * peel one symmetric outer quote layer from the code argument.
2439
+ *
2440
+ * @param args - Argument vector intended for direct execution (shell-off).
2441
+ * @returns Either the original `args` or a modified copy with a normalized eval payload.
2401
2442
  */
2402
2443
  function maybePreserveNodeEvalArgv(args) {
2403
2444
  if (args.length >= 3) {
@@ -153,6 +153,10 @@ function defaultsDeep(...layers) {
153
153
  /**
154
154
  * Serialize a dotenv record to a file with minimal quoting (multiline values are quoted).
155
155
  * Future-proofs for ordering/sorting changes (currently insertion order).
156
+ *
157
+ * @param filename - Destination dotenv file path.
158
+ * @param data - Env-like map of values to write (values may be `undefined`).
159
+ * @returns A `Promise\<void\>` which resolves when the file has been written.
156
160
  */
157
161
  async function writeDotenvFile(filename, data) {
158
162
  // Serialize: key=value with quotes only for multiline values.
@@ -388,14 +392,20 @@ const cleanupOldCacheFiles = async (cacheDir, baseName, keep = Math.max(1, Numbe
388
392
  }
389
393
  };
390
394
  /**
391
- * Load a module default export from a JS/TS file with robust fallbacks:
392
- * - .js/.mjs/.cjs: direct import * - .ts/.mts/.cts/.tsx:
393
- * 1) try direct import (if a TS loader is active),
394
- * 2) esbuild bundle to a temp ESM file,
395
- * 3) typescript.transpileModule fallback for simple modules.
395
+ * Load a module default export from a JS/TS file with robust fallbacks.
396
+ *
397
+ * Behavior by extension:
398
+ *
399
+ * - `.js`/`.mjs`/`.cjs`: direct dynamic import.
400
+ * - `.ts`/`.mts`/`.cts`/`.tsx`:
401
+ * - try direct dynamic import (when a TS loader is active),
402
+ * - else compile via `esbuild` to a cached `.mjs` file and import,
403
+ * - else fallback to `typescript.transpileModule` for simple modules.
396
404
  *
397
- * @param absPath - absolute path to source file
398
- * @param cacheDirName - cache subfolder under .tsbuild
405
+ * @typeParam T - Type of the expected default export.
406
+ * @param absPath - Absolute path to the source file.
407
+ * @param cacheDirName - Cache subfolder under `.tsbuild/`.
408
+ * @returns A `Promise\<T | undefined\>` resolving to the default export (if any).
399
409
  */
400
410
  const loadModuleDefault = async (absPath, cacheDirName) => {
401
411
  const ext = path.extname(absPath).toLowerCase();
@@ -467,6 +477,10 @@ const loadModuleDefault = async (absPath, cacheDirName) => {
467
477
  /**
468
478
  * Omit keys whose runtime value is undefined from a shallow object.
469
479
  * Returns a Partial with non-undefined value types preserved.
480
+ *
481
+ * @typeParam T - Input object shape.
482
+ * @param obj - Object to filter.
483
+ * @returns A shallow copy of `obj` without keys whose value is `undefined`.
470
484
  */
471
485
  function omitUndefined(obj) {
472
486
  const out = {};
@@ -478,6 +492,10 @@ function omitUndefined(obj) {
478
492
  }
479
493
  /**
480
494
  * Specialized helper for env-like maps: drop undefined and return string-only.
495
+ *
496
+ * @typeParam V - Value type for present entries (must extend `string`).
497
+ * @param obj - Env-like record containing `string | undefined` values.
498
+ * @returns A new record containing only the keys with defined values.
481
499
  */
482
500
  function omitUndefinedRecord(obj) {
483
501
  const out = {};
@@ -637,6 +655,11 @@ const resolveGetDotenvConfigSources = async (importMetaUrl) => {
637
655
  * Apply a dynamic map to the target progressively.
638
656
  * - Functions receive (target, env) and may return string | undefined.
639
657
  * - Literals are assigned directly (including undefined).
658
+ *
659
+ * @param target - Mutable target environment to assign into.
660
+ * @param map - Dynamic map to apply (functions and/or literal values).
661
+ * @param env - Selected environment name (if any) passed through to dynamic functions.
662
+ * @returns Nothing.
640
663
  */
641
664
  function applyDynamicMap(target, map, env) {
642
665
  if (!map)
@@ -656,6 +679,12 @@ function applyDynamicMap(target, map, env) {
656
679
  * Error behavior:
657
680
  * - On failure to load/compile/evaluate the module, throws a unified message:
658
681
  * "Unable to load dynamic TypeScript file: <absPath>. Install 'esbuild'..."
682
+ *
683
+ * @param target - Mutable target environment to assign into.
684
+ * @param absPath - Absolute path to the dynamic module file.
685
+ * @param env - Selected environment name (if any).
686
+ * @param cacheDirName - Cache subdirectory under `.tsbuild/` for compiled artifacts.
687
+ * @returns A `Promise\<void\>` which resolves after the module (if present) has been applied.
659
688
  */
660
689
  async function loadAndApplyDynamic(target, absPath, env, cacheDirName) {
661
690
  if (!(await fs.exists(absPath)))
@@ -1601,6 +1630,10 @@ function renderOptionGroups(cmd) {
1601
1630
  /**
1602
1631
  * Compose root/parent help output by inserting grouped sections between
1603
1632
  * Options and Commands, ensuring a trailing blank line.
1633
+ *
1634
+ * @param base - Base help text produced by Commander.
1635
+ * @param cmd - Command instance whose grouped options should be rendered.
1636
+ * @returns The modified help text with grouped blocks inserted.
1604
1637
  */
1605
1638
  function buildHelpInformation(base, cmd) {
1606
1639
  const groups = renderOptionGroups(cmd);
@@ -2120,14 +2153,21 @@ const readMergedOptions = (cmd) => {
2120
2153
  };
2121
2154
 
2122
2155
  /**
2123
- * Ensure a directory exists.
2156
+ * Ensure a directory exists (parents included).
2157
+ *
2158
+ * @param p - Directory path to create.
2159
+ * @returns A `Promise\<string\>` resolving to the provided `p` value.
2124
2160
  */
2125
2161
  const ensureDir = async (p) => {
2126
2162
  await fs.ensureDir(p);
2127
2163
  return p;
2128
2164
  };
2129
2165
  /**
2130
- * Write text content to a file, ensuring the parent directory exists.
2166
+ * Write UTF-8 text content to a file, ensuring the parent directory exists.
2167
+ *
2168
+ * @param dest - Destination file path.
2169
+ * @param data - File contents to write.
2170
+ * @returns A `Promise\<void\>` which resolves when the file is written.
2131
2171
  */
2132
2172
  const writeFile = async (dest, data) => {
2133
2173
  await ensureDir(path.dirname(dest));
@@ -2139,6 +2179,7 @@ const writeFile = async (dest, data) => {
2139
2179
  * @param src - Source file path.
2140
2180
  * @param dest - Destination file path.
2141
2181
  * @param substitutions - Map of token literals to replacement strings.
2182
+ * @returns A `Promise\<void\>` which resolves when the file has been copied.
2142
2183
  */
2143
2184
  const copyTextFile = async (src, dest, substitutions) => {
2144
2185
  const contents = await fs.readFile(src, 'utf-8');
@@ -2150,6 +2191,10 @@ const copyTextFile = async (src, dest, substitutions) => {
2150
2191
  /**
2151
2192
  * Ensure a set of lines exist (exact match) in a file. Creates the file
2152
2193
  * when missing. Returns whether it was created or changed.
2194
+ *
2195
+ * @param filePath - Target file path to create/update.
2196
+ * @param lines - Lines which must be present (exact string match).
2197
+ * @returns A `Promise\<object\>` describing whether the file was created and/or changed.
2153
2198
  */
2154
2199
  const ensureLines = async (filePath, lines) => {
2155
2200
  const exists = await fs.pathExists(filePath);
@@ -2177,11 +2222,23 @@ const ensureLines = async (filePath, lines) => {
2177
2222
  return { created: false, changed: false };
2178
2223
  };
2179
2224
 
2180
- // Templates root used by the scaffolder
2225
+ /**
2226
+ * Absolute path to the shipped templates directory.
2227
+ *
2228
+ * Used by the init scaffolder to locate files under `templates/` at runtime.
2229
+ *
2230
+ * @remarks
2231
+ * This path is resolved relative to the current working directory. It assumes
2232
+ * the `templates/` folder is present alongside the installed package (or in the
2233
+ * repository when running from source).
2234
+ */
2181
2235
  const TEMPLATES_ROOT = path.resolve('templates');
2182
2236
 
2183
2237
  /**
2184
2238
  * Plan the copy operations for configuration files.
2239
+ *
2240
+ * @param options - Planning options for config scaffolding.
2241
+ * @returns An array of copy operations to perform.
2185
2242
  */
2186
2243
  const planConfigCopies = ({ format, withLocal, destRoot, }) => {
2187
2244
  const copies = [];
@@ -2225,6 +2282,9 @@ const planConfigCopies = ({ format, withLocal, destRoot, }) => {
2225
2282
  };
2226
2283
  /**
2227
2284
  * Plan the copy operations for the CLI skeleton.
2285
+ *
2286
+ * @param options - Planning options for CLI scaffolding.
2287
+ * @returns An array of copy operations to perform.
2228
2288
  */
2229
2289
  const planCliCopies = ({ cliName, destRoot, }) => {
2230
2290
  const subs = { __CLI_NAME__: cliName };
@@ -2246,6 +2306,8 @@ const planCliCopies = ({ cliName, destRoot, }) => {
2246
2306
  /**
2247
2307
  * Determine whether the current environment should be treated as non-interactive.
2248
2308
  * CI heuristics include: CI, GITHUB_ACTIONS, BUILDKITE, TEAMCITY_VERSION, TF_BUILD.
2309
+ *
2310
+ * @returns `true` when running in a CI-like environment or when stdin/stdout are not TTYs.
2249
2311
  */
2250
2312
  const isNonInteractive = () => {
2251
2313
  const ciLike = process.env.CI ||
@@ -2258,6 +2320,11 @@ const isNonInteractive = () => {
2258
2320
  /**
2259
2321
  * Prompt the user for a file collision decision.
2260
2322
  * Returns a single-character code representing overwrite/example/skip (or 'all' variants).
2323
+ *
2324
+ * @param filePath - Path of the colliding file (for display).
2325
+ * @param logger - Logger used for user-facing messages.
2326
+ * @param rl - Readline interface used to capture user input.
2327
+ * @returns A single-character decision code.
2261
2328
  */
2262
2329
  const promptDecision = async (filePath, logger, rl) => {
2263
2330
  logger.log(`File exists: ${filePath}\nChoose: [o]verwrite, [e]xample, [s]kip, [O]verwrite All, [E]xample All, [S]kip All`);