@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.
- package/README.md +1 -1
- package/dist/cli.mjs +99 -10
- package/dist/cliHost.d.ts +14 -1
- package/dist/cliHost.mjs +54 -8
- package/dist/config.d.ts +4 -0
- package/dist/config.mjs +17 -7
- package/dist/env-overlay.d.ts +11 -0
- package/dist/env-overlay.mjs +24 -7
- package/dist/getdotenv.cli.mjs +99 -10
- package/dist/index.d.ts +88 -2
- package/dist/index.mjs +112 -11
- package/dist/plugins-aws.mjs +50 -7
- package/dist/plugins-batch.mjs +48 -7
- package/dist/plugins-cmd.mjs +48 -7
- package/dist/plugins-init.mjs +77 -10
- package/dist/plugins.mjs +95 -10
- package/dist/templates/cli/index.ts +1 -2
- package/dist/templates/cli/plugins/hello.ts +2 -3
- package/dist/templates/config/ts/getdotenv.config.ts +1 -1
- package/dist/templates/getdotenv.config.ts +1 -1
- package/dist/templates/hello.ts +2 -3
- package/dist/templates/index.ts +1 -2
- package/dist/templates/plugins/hello.ts +2 -3
- package/dist/templates/ts/getdotenv.config.ts +1 -1
- package/package.json +1 -1
- package/templates/cli/index.ts +1 -2
- package/templates/cli/plugins/hello.ts +2 -3
- package/templates/config/ts/getdotenv.config.ts +1 -1
package/README.md
CHANGED
|
@@ -70,7 +70,7 @@ Embed a CLI quickly (shipped plugins wired for you):
|
|
|
70
70
|
#!/usr/bin/env node
|
|
71
71
|
import { createCli } from '@karmaniverous/get-dotenv/cli';
|
|
72
72
|
|
|
73
|
-
await createCli({ alias: 'toolbox' })
|
|
73
|
+
await createCli({ alias: 'toolbox' })();
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
More first steps and tips at [Getting Started](./guides/getting-started.md)
|
package/dist/cli.mjs
CHANGED
|
@@ -169,6 +169,10 @@ function defaultsDeep(...layers) {
|
|
|
169
169
|
/**
|
|
170
170
|
* Serialize a dotenv record to a file with minimal quoting (multiline values are quoted).
|
|
171
171
|
* Future-proofs for ordering/sorting changes (currently insertion order).
|
|
172
|
+
*
|
|
173
|
+
* @param filename - Destination dotenv file path.
|
|
174
|
+
* @param data - Env-like map of values to write (values may be `undefined`).
|
|
175
|
+
* @returns A `Promise\<void\>` which resolves when the file has been written.
|
|
172
176
|
*/
|
|
173
177
|
async function writeDotenvFile(filename, data) {
|
|
174
178
|
// Serialize: key=value with quotes only for multiline values.
|
|
@@ -404,14 +408,20 @@ const cleanupOldCacheFiles = async (cacheDir, baseName, keep = Math.max(1, Numbe
|
|
|
404
408
|
}
|
|
405
409
|
};
|
|
406
410
|
/**
|
|
407
|
-
* Load a module default export from a JS/TS file with robust fallbacks
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
* 2) esbuild bundle to a temp ESM file,
|
|
411
|
-
* 3) typescript.transpileModule fallback for simple modules.
|
|
411
|
+
* Load a module default export from a JS/TS file with robust fallbacks.
|
|
412
|
+
*
|
|
413
|
+
* Behavior by extension:
|
|
412
414
|
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
+
* - `.js`/`.mjs`/`.cjs`: direct dynamic import.
|
|
416
|
+
* - `.ts`/`.mts`/`.cts`/`.tsx`:
|
|
417
|
+
* - try direct dynamic import (when a TS loader is active),
|
|
418
|
+
* - else compile via `esbuild` to a cached `.mjs` file and import,
|
|
419
|
+
* - else fallback to `typescript.transpileModule` for simple modules.
|
|
420
|
+
*
|
|
421
|
+
* @typeParam T - Type of the expected default export.
|
|
422
|
+
* @param absPath - Absolute path to the source file.
|
|
423
|
+
* @param cacheDirName - Cache subfolder under `.tsbuild/`.
|
|
424
|
+
* @returns A `Promise\<T | undefined\>` resolving to the default export (if any).
|
|
415
425
|
*/
|
|
416
426
|
const loadModuleDefault = async (absPath, cacheDirName) => {
|
|
417
427
|
const ext = path.extname(absPath).toLowerCase();
|
|
@@ -483,6 +493,10 @@ const loadModuleDefault = async (absPath, cacheDirName) => {
|
|
|
483
493
|
/**
|
|
484
494
|
* Omit keys whose runtime value is undefined from a shallow object.
|
|
485
495
|
* Returns a Partial with non-undefined value types preserved.
|
|
496
|
+
*
|
|
497
|
+
* @typeParam T - Input object shape.
|
|
498
|
+
* @param obj - Object to filter.
|
|
499
|
+
* @returns A shallow copy of `obj` without keys whose value is `undefined`.
|
|
486
500
|
*/
|
|
487
501
|
function omitUndefined(obj) {
|
|
488
502
|
const out = {};
|
|
@@ -494,6 +508,10 @@ function omitUndefined(obj) {
|
|
|
494
508
|
}
|
|
495
509
|
/**
|
|
496
510
|
* Specialized helper for env-like maps: drop undefined and return string-only.
|
|
511
|
+
*
|
|
512
|
+
* @typeParam V - Value type for present entries (must extend `string`).
|
|
513
|
+
* @param obj - Env-like record containing `string | undefined` values.
|
|
514
|
+
* @returns A new record containing only the keys with defined values.
|
|
497
515
|
*/
|
|
498
516
|
function omitUndefinedRecord(obj) {
|
|
499
517
|
const out = {};
|
|
@@ -711,6 +729,10 @@ const resolveGetDotenvConfigSources = async (importMetaUrl) => {
|
|
|
711
729
|
* - If a JS/TS `schema` is present, use schema.safeParse(finalEnv).
|
|
712
730
|
* - Else if `requiredKeys` is present, check presence (value !== undefined).
|
|
713
731
|
* - Returns a flat list of issue strings; caller decides warn vs fail.
|
|
732
|
+
*
|
|
733
|
+
* @param finalEnv - Final composed environment to validate.
|
|
734
|
+
* @param sources - Resolved config sources providing `schema` and/or `requiredKeys`.
|
|
735
|
+
* @returns A list of human-readable issue strings (empty when valid).
|
|
714
736
|
*/
|
|
715
737
|
const validateEnvAgainstSources = (finalEnv, sources) => {
|
|
716
738
|
const pick = (getter) => {
|
|
@@ -770,6 +792,11 @@ const validateEnvAgainstSources = (finalEnv, sources) => {
|
|
|
770
792
|
* Apply a dynamic map to the target progressively.
|
|
771
793
|
* - Functions receive (target, env) and may return string | undefined.
|
|
772
794
|
* - Literals are assigned directly (including undefined).
|
|
795
|
+
*
|
|
796
|
+
* @param target - Mutable target environment to assign into.
|
|
797
|
+
* @param map - Dynamic map to apply (functions and/or literal values).
|
|
798
|
+
* @param env - Selected environment name (if any) passed through to dynamic functions.
|
|
799
|
+
* @returns Nothing.
|
|
773
800
|
*/
|
|
774
801
|
function applyDynamicMap(target, map, env) {
|
|
775
802
|
if (!map)
|
|
@@ -789,6 +816,12 @@ function applyDynamicMap(target, map, env) {
|
|
|
789
816
|
* Error behavior:
|
|
790
817
|
* - On failure to load/compile/evaluate the module, throws a unified message:
|
|
791
818
|
* "Unable to load dynamic TypeScript file: <absPath>. Install 'esbuild'..."
|
|
819
|
+
*
|
|
820
|
+
* @param target - Mutable target environment to assign into.
|
|
821
|
+
* @param absPath - Absolute path to the dynamic module file.
|
|
822
|
+
* @param env - Selected environment name (if any).
|
|
823
|
+
* @param cacheDirName - Cache subdirectory under `.tsbuild/` for compiled artifacts.
|
|
824
|
+
* @returns A `Promise\<void\>` which resolves after the module (if present) has been applied.
|
|
792
825
|
*/
|
|
793
826
|
async function loadAndApplyDynamic(target, absPath, env, cacheDirName) {
|
|
794
827
|
if (!(await fs.exists(absPath)))
|
|
@@ -1951,6 +1984,10 @@ function renderOptionGroups(cmd) {
|
|
|
1951
1984
|
/**
|
|
1952
1985
|
* Compose root/parent help output by inserting grouped sections between
|
|
1953
1986
|
* Options and Commands, ensuring a trailing blank line.
|
|
1987
|
+
*
|
|
1988
|
+
* @param base - Base help text produced by Commander.
|
|
1989
|
+
* @param cmd - Command instance whose grouped options should be rendered.
|
|
1990
|
+
* @returns The modified help text with grouped blocks inserted.
|
|
1954
1991
|
*/
|
|
1955
1992
|
function buildHelpInformation(base, cmd) {
|
|
1956
1993
|
const groups = renderOptionGroups(cmd);
|
|
@@ -2463,6 +2500,10 @@ const toHelpConfig = (merged, plugins) => {
|
|
|
2463
2500
|
/**
|
|
2464
2501
|
* Compose a child-process env overlay from dotenv and the merged CLI options bag.
|
|
2465
2502
|
* Returns a shallow object including getDotenvCliOptions when serializable.
|
|
2503
|
+
*
|
|
2504
|
+
* @param merged - Resolved CLI options bag (or a JSON-serializable subset).
|
|
2505
|
+
* @param dotenv - Composed dotenv variables for the current invocation.
|
|
2506
|
+
* @returns A string-only env overlay suitable for child process spawning.
|
|
2466
2507
|
*/
|
|
2467
2508
|
function composeNestedEnv(merged, dotenv) {
|
|
2468
2509
|
const out = {};
|
|
@@ -2485,6 +2526,7 @@ function composeNestedEnv(merged, dotenv) {
|
|
|
2485
2526
|
* Strip one layer of symmetric outer quotes (single or double) from a string.
|
|
2486
2527
|
*
|
|
2487
2528
|
* @param s - Input string.
|
|
2529
|
+
* @returns `s` without one symmetric outer quote pair (when present).
|
|
2488
2530
|
*/
|
|
2489
2531
|
const stripOne = (s) => {
|
|
2490
2532
|
if (s.length < 2)
|
|
@@ -2497,6 +2539,9 @@ const stripOne = (s) => {
|
|
|
2497
2539
|
/**
|
|
2498
2540
|
* Preserve argv array for Node -e/--eval payloads under shell-off and
|
|
2499
2541
|
* peel one symmetric outer quote layer from the code argument.
|
|
2542
|
+
*
|
|
2543
|
+
* @param args - Argument vector intended for direct execution (shell-off).
|
|
2544
|
+
* @returns Either the original `args` or a modified copy with a normalized eval payload.
|
|
2500
2545
|
*/
|
|
2501
2546
|
function maybePreserveNodeEvalArgv(args) {
|
|
2502
2547
|
if (args.length >= 3) {
|
|
@@ -2963,7 +3008,10 @@ function applyRootVisibility(program, visibility) {
|
|
|
2963
3008
|
* Apply resolved AWS context to `process.env` and `ctx.plugins`.
|
|
2964
3009
|
* Centralizes logic shared between the plugin action and `afterResolve` hook.
|
|
2965
3010
|
*
|
|
3011
|
+
* @param out - Resolved AWS context to apply.
|
|
3012
|
+
* @param ctx - Host context to publish non-sensitive metadata into.
|
|
2966
3013
|
* @param setProcessEnv - Whether to write credentials/region to `process.env` (default true).
|
|
3014
|
+
* @returns Nothing.
|
|
2967
3015
|
*/
|
|
2968
3016
|
function applyAwsContext(out, ctx, setProcessEnv = true) {
|
|
2969
3017
|
const { profile, region, credentials } = out;
|
|
@@ -2999,6 +3047,9 @@ const unquote = (s) => s.length >= 2 &&
|
|
|
2999
3047
|
: s;
|
|
3000
3048
|
/**
|
|
3001
3049
|
* Parse AWS credentials from JSON output (AWS CLI v2 export-credentials).
|
|
3050
|
+
*
|
|
3051
|
+
* @param txt - Raw stdout text from the AWS CLI.
|
|
3052
|
+
* @returns Parsed credentials, or `undefined` when the input is not recognized.
|
|
3002
3053
|
*/
|
|
3003
3054
|
const parseExportCredentialsJson = (txt) => {
|
|
3004
3055
|
try {
|
|
@@ -3022,6 +3073,9 @@ const parseExportCredentialsJson = (txt) => {
|
|
|
3022
3073
|
/**
|
|
3023
3074
|
* Parse AWS credentials from environment-export output (shell-agnostic).
|
|
3024
3075
|
* Supports POSIX `export KEY=VAL` and PowerShell `$Env:KEY=VAL`.
|
|
3076
|
+
*
|
|
3077
|
+
* @param txt - Raw stdout text from the AWS CLI.
|
|
3078
|
+
* @returns Parsed credentials, or `undefined` when the input is not recognized.
|
|
3025
3079
|
*/
|
|
3026
3080
|
const parseExportCredentialsEnv = (txt) => {
|
|
3027
3081
|
const lines = txt.split(/\r?\n/);
|
|
@@ -3107,6 +3161,7 @@ const exportCredentials = async (profile, timeoutMs = DEFAULT_TIMEOUT_MS) => {
|
|
|
3107
3161
|
* Applies strategy (cli-export vs none) and handling for SSO login-on-demand.
|
|
3108
3162
|
*
|
|
3109
3163
|
* @param options - Context options including current dotenv and plugin config.
|
|
3164
|
+
* @returns A `Promise\<AwsContext\>` containing any resolved profile, region, and credentials.
|
|
3110
3165
|
*/
|
|
3111
3166
|
const resolveAwsContext = async ({ dotenv, cfg, }) => {
|
|
3112
3167
|
const profileKey = cfg.profileKey ?? 'AWS_LOCAL_PROFILE';
|
|
@@ -14509,14 +14564,21 @@ const cmdPlugin = (options = {}) => {
|
|
|
14509
14564
|
};
|
|
14510
14565
|
|
|
14511
14566
|
/**
|
|
14512
|
-
* Ensure a directory exists.
|
|
14567
|
+
* Ensure a directory exists (parents included).
|
|
14568
|
+
*
|
|
14569
|
+
* @param p - Directory path to create.
|
|
14570
|
+
* @returns A `Promise\<string\>` resolving to the provided `p` value.
|
|
14513
14571
|
*/
|
|
14514
14572
|
const ensureDir = async (p) => {
|
|
14515
14573
|
await fs.ensureDir(p);
|
|
14516
14574
|
return p;
|
|
14517
14575
|
};
|
|
14518
14576
|
/**
|
|
14519
|
-
* Write text content to a file, ensuring the parent directory exists.
|
|
14577
|
+
* Write UTF-8 text content to a file, ensuring the parent directory exists.
|
|
14578
|
+
*
|
|
14579
|
+
* @param dest - Destination file path.
|
|
14580
|
+
* @param data - File contents to write.
|
|
14581
|
+
* @returns A `Promise\<void\>` which resolves when the file is written.
|
|
14520
14582
|
*/
|
|
14521
14583
|
const writeFile$1 = async (dest, data) => {
|
|
14522
14584
|
await ensureDir(path.dirname(dest));
|
|
@@ -14528,6 +14590,7 @@ const writeFile$1 = async (dest, data) => {
|
|
|
14528
14590
|
* @param src - Source file path.
|
|
14529
14591
|
* @param dest - Destination file path.
|
|
14530
14592
|
* @param substitutions - Map of token literals to replacement strings.
|
|
14593
|
+
* @returns A `Promise\<void\>` which resolves when the file has been copied.
|
|
14531
14594
|
*/
|
|
14532
14595
|
const copyTextFile = async (src, dest, substitutions) => {
|
|
14533
14596
|
const contents = await fs.readFile(src, 'utf-8');
|
|
@@ -14539,6 +14602,10 @@ const copyTextFile = async (src, dest, substitutions) => {
|
|
|
14539
14602
|
/**
|
|
14540
14603
|
* Ensure a set of lines exist (exact match) in a file. Creates the file
|
|
14541
14604
|
* when missing. Returns whether it was created or changed.
|
|
14605
|
+
*
|
|
14606
|
+
* @param filePath - Target file path to create/update.
|
|
14607
|
+
* @param lines - Lines which must be present (exact string match).
|
|
14608
|
+
* @returns A `Promise\<object\>` describing whether the file was created and/or changed.
|
|
14542
14609
|
*/
|
|
14543
14610
|
const ensureLines = async (filePath, lines) => {
|
|
14544
14611
|
const exists = await fs.pathExists(filePath);
|
|
@@ -14566,11 +14633,23 @@ const ensureLines = async (filePath, lines) => {
|
|
|
14566
14633
|
return { created: false, changed: false };
|
|
14567
14634
|
};
|
|
14568
14635
|
|
|
14569
|
-
|
|
14636
|
+
/**
|
|
14637
|
+
* Absolute path to the shipped templates directory.
|
|
14638
|
+
*
|
|
14639
|
+
* Used by the init scaffolder to locate files under `templates/` at runtime.
|
|
14640
|
+
*
|
|
14641
|
+
* @remarks
|
|
14642
|
+
* This path is resolved relative to the current working directory. It assumes
|
|
14643
|
+
* the `templates/` folder is present alongside the installed package (or in the
|
|
14644
|
+
* repository when running from source).
|
|
14645
|
+
*/
|
|
14570
14646
|
const TEMPLATES_ROOT = path.resolve('templates');
|
|
14571
14647
|
|
|
14572
14648
|
/**
|
|
14573
14649
|
* Plan the copy operations for configuration files.
|
|
14650
|
+
*
|
|
14651
|
+
* @param options - Planning options for config scaffolding.
|
|
14652
|
+
* @returns An array of copy operations to perform.
|
|
14574
14653
|
*/
|
|
14575
14654
|
const planConfigCopies = ({ format, withLocal, destRoot, }) => {
|
|
14576
14655
|
const copies = [];
|
|
@@ -14614,6 +14693,9 @@ const planConfigCopies = ({ format, withLocal, destRoot, }) => {
|
|
|
14614
14693
|
};
|
|
14615
14694
|
/**
|
|
14616
14695
|
* Plan the copy operations for the CLI skeleton.
|
|
14696
|
+
*
|
|
14697
|
+
* @param options - Planning options for CLI scaffolding.
|
|
14698
|
+
* @returns An array of copy operations to perform.
|
|
14617
14699
|
*/
|
|
14618
14700
|
const planCliCopies = ({ cliName, destRoot, }) => {
|
|
14619
14701
|
const subs = { __CLI_NAME__: cliName };
|
|
@@ -14635,6 +14717,8 @@ const planCliCopies = ({ cliName, destRoot, }) => {
|
|
|
14635
14717
|
/**
|
|
14636
14718
|
* Determine whether the current environment should be treated as non-interactive.
|
|
14637
14719
|
* CI heuristics include: CI, GITHUB_ACTIONS, BUILDKITE, TEAMCITY_VERSION, TF_BUILD.
|
|
14720
|
+
*
|
|
14721
|
+
* @returns `true` when running in a CI-like environment or when stdin/stdout are not TTYs.
|
|
14638
14722
|
*/
|
|
14639
14723
|
const isNonInteractive = () => {
|
|
14640
14724
|
const ciLike = process.env.CI ||
|
|
@@ -14647,6 +14731,11 @@ const isNonInteractive = () => {
|
|
|
14647
14731
|
/**
|
|
14648
14732
|
* Prompt the user for a file collision decision.
|
|
14649
14733
|
* Returns a single-character code representing overwrite/example/skip (or 'all' variants).
|
|
14734
|
+
*
|
|
14735
|
+
* @param filePath - Path of the colliding file (for display).
|
|
14736
|
+
* @param logger - Logger used for user-facing messages.
|
|
14737
|
+
* @param rl - Readline interface used to capture user input.
|
|
14738
|
+
* @returns A single-character decision code.
|
|
14650
14739
|
*/
|
|
14651
14740
|
const promptDecision = async (filePath, logger, rl) => {
|
|
14652
14741
|
logger.log(`File exists: ${filePath}\nChoose: [o]verwrite, [e]xample, [s]kip, [O]verwrite All, [E]xample All, [S]kip All`);
|
package/dist/cliHost.d.ts
CHANGED
|
@@ -436,6 +436,11 @@ declare function definePlugin<TOptions extends GetDotenvOptions, Schema extends
|
|
|
436
436
|
}): PluginWithInstanceHelpers<TOptions, z.output<Schema>>;
|
|
437
437
|
declare function definePlugin<TOptions extends GetDotenvOptions>(spec: DefineSpec<TOptions>): PluginWithInstanceHelpers<TOptions, {}>;
|
|
438
438
|
|
|
439
|
+
/**
|
|
440
|
+
* Helper to decide whether to capture child stdio.
|
|
441
|
+
* Checks GETDOTENV_STDIO env var or the provided bag capture flag.
|
|
442
|
+
*/
|
|
443
|
+
declare const shouldCapture: (bagCapture?: boolean) => boolean;
|
|
439
444
|
/**
|
|
440
445
|
* Options for runCommandResult (buffered execution).
|
|
441
446
|
*
|
|
@@ -641,17 +646,25 @@ declare const getRootCommand: (cmd: CommandUnknownOpts) => CommandUnknownOpts;
|
|
|
641
646
|
/**
|
|
642
647
|
* Compose a child-process env overlay from dotenv and the merged CLI options bag.
|
|
643
648
|
* Returns a shallow object including getDotenvCliOptions when serializable.
|
|
649
|
+
*
|
|
650
|
+
* @param merged - Resolved CLI options bag (or a JSON-serializable subset).
|
|
651
|
+
* @param dotenv - Composed dotenv variables for the current invocation.
|
|
652
|
+
* @returns A string-only env overlay suitable for child process spawning.
|
|
644
653
|
*/
|
|
645
654
|
declare function composeNestedEnv(merged: GetDotenvCliOptions | Record<string, unknown>, dotenv: Record<string, string | undefined>): Record<string, string>;
|
|
646
655
|
/**
|
|
647
656
|
* Strip one layer of symmetric outer quotes (single or double) from a string.
|
|
648
657
|
*
|
|
649
658
|
* @param s - Input string.
|
|
659
|
+
* @returns `s` without one symmetric outer quote pair (when present).
|
|
650
660
|
*/
|
|
651
661
|
declare const stripOne: (s: string) => string;
|
|
652
662
|
/**
|
|
653
663
|
* Preserve argv array for Node -e/--eval payloads under shell-off and
|
|
654
664
|
* peel one symmetric outer quote layer from the code argument.
|
|
665
|
+
*
|
|
666
|
+
* @param args - Argument vector intended for direct execution (shell-off).
|
|
667
|
+
* @returns Either the original `args` or a modified copy with a normalized eval payload.
|
|
655
668
|
*/
|
|
656
669
|
declare function maybePreserveNodeEvalArgv(args: string[]): string[];
|
|
657
670
|
|
|
@@ -742,5 +755,5 @@ declare const resolveCliOptions: <T extends Partial<RootOptionsShape> & {
|
|
|
742
755
|
*/
|
|
743
756
|
declare const buildSpawnEnv: (base?: NodeJS.ProcessEnv, overlay?: Record<string, string | undefined>) => NodeJS.ProcessEnv;
|
|
744
757
|
|
|
745
|
-
export { GetDotenvCli, baseGetDotenvCliOptions, buildSpawnEnv, composeNestedEnv, definePlugin, defineScripts, getRootCommand, maybePreserveNodeEvalArgv, readMergedOptions, resolveCliOptions, resolveCommand, resolveShell, runCommand, runCommandResult, stripOne, toHelpConfig };
|
|
758
|
+
export { GetDotenvCli, baseGetDotenvCliOptions, buildSpawnEnv, composeNestedEnv, definePlugin, defineScripts, getRootCommand, maybePreserveNodeEvalArgv, readMergedOptions, resolveCliOptions, resolveCommand, resolveShell, runCommand, runCommandResult, shouldCapture, stripOne, toHelpConfig };
|
|
746
759
|
export type { BrandOptions, DefineSpec, GetDotenvCliCtx, GetDotenvCliOptions, GetDotenvCliPlugin, GetDotenvCliPublic, InferPluginConfig, PluginChildEntry, PluginFlattenedEntry, PluginNamespaceOverride, PluginWithInstanceHelpers, ResolveAndLoadOptions, ResolveCliOptionsResult, ResolvedHelpConfig, RootOptionsShape, RunCommandOptions, RunCommandResultOptions, ScriptDef, Scripts, ScriptsTable };
|
package/dist/cliHost.mjs
CHANGED
|
@@ -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
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
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
|
-
* @
|
|
397
|
-
* @param
|
|
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)))
|
|
@@ -1299,6 +1328,11 @@ const dbg = (...args) => {
|
|
|
1299
1328
|
console.error('[getdotenv:run]', ...args);
|
|
1300
1329
|
}
|
|
1301
1330
|
};
|
|
1331
|
+
/**
|
|
1332
|
+
* Helper to decide whether to capture child stdio.
|
|
1333
|
+
* Checks GETDOTENV_STDIO env var or the provided bag capture flag.
|
|
1334
|
+
*/
|
|
1335
|
+
const shouldCapture = (bagCapture) => process.env.GETDOTENV_STDIO === 'pipe' || Boolean(bagCapture);
|
|
1302
1336
|
// Strip repeated symmetric outer quotes (single or double) until stable.
|
|
1303
1337
|
// This is safe for argv arrays passed to execa (no quoting needed) and avoids
|
|
1304
1338
|
// passing quote characters through to Node (e.g., for `node -e "<code>"`).
|
|
@@ -1795,6 +1829,10 @@ function renderOptionGroups(cmd) {
|
|
|
1795
1829
|
/**
|
|
1796
1830
|
* Compose root/parent help output by inserting grouped sections between
|
|
1797
1831
|
* Options and Commands, ensuring a trailing blank line.
|
|
1832
|
+
*
|
|
1833
|
+
* @param base - Base help text produced by Commander.
|
|
1834
|
+
* @param cmd - Command instance whose grouped options should be rendered.
|
|
1835
|
+
* @returns The modified help text with grouped blocks inserted.
|
|
1798
1836
|
*/
|
|
1799
1837
|
function buildHelpInformation(base, cmd) {
|
|
1800
1838
|
const groups = renderOptionGroups(cmd);
|
|
@@ -2320,6 +2358,10 @@ const toHelpConfig = (merged, plugins) => {
|
|
|
2320
2358
|
/**
|
|
2321
2359
|
* Compose a child-process env overlay from dotenv and the merged CLI options bag.
|
|
2322
2360
|
* Returns a shallow object including getDotenvCliOptions when serializable.
|
|
2361
|
+
*
|
|
2362
|
+
* @param merged - Resolved CLI options bag (or a JSON-serializable subset).
|
|
2363
|
+
* @param dotenv - Composed dotenv variables for the current invocation.
|
|
2364
|
+
* @returns A string-only env overlay suitable for child process spawning.
|
|
2323
2365
|
*/
|
|
2324
2366
|
function composeNestedEnv(merged, dotenv) {
|
|
2325
2367
|
const out = {};
|
|
@@ -2342,6 +2384,7 @@ function composeNestedEnv(merged, dotenv) {
|
|
|
2342
2384
|
* Strip one layer of symmetric outer quotes (single or double) from a string.
|
|
2343
2385
|
*
|
|
2344
2386
|
* @param s - Input string.
|
|
2387
|
+
* @returns `s` without one symmetric outer quote pair (when present).
|
|
2345
2388
|
*/
|
|
2346
2389
|
const stripOne = (s) => {
|
|
2347
2390
|
if (s.length < 2)
|
|
@@ -2354,6 +2397,9 @@ const stripOne = (s) => {
|
|
|
2354
2397
|
/**
|
|
2355
2398
|
* Preserve argv array for Node -e/--eval payloads under shell-off and
|
|
2356
2399
|
* peel one symmetric outer quote layer from the code argument.
|
|
2400
|
+
*
|
|
2401
|
+
* @param args - Argument vector intended for direct execution (shell-off).
|
|
2402
|
+
* @returns Either the original `args` or a modified copy with a normalized eval payload.
|
|
2357
2403
|
*/
|
|
2358
2404
|
function maybePreserveNodeEvalArgv(args) {
|
|
2359
2405
|
if (args.length >= 3) {
|
|
@@ -2602,4 +2648,4 @@ const buildSpawnEnv = (base, overlay) => {
|
|
|
2602
2648
|
*/
|
|
2603
2649
|
const defineScripts = () => (t) => t;
|
|
2604
2650
|
|
|
2605
|
-
export { GetDotenvCli, baseGetDotenvCliOptions, buildSpawnEnv, composeNestedEnv, definePlugin, defineScripts, getRootCommand, maybePreserveNodeEvalArgv, readMergedOptions, resolveCliOptions, resolveCommand, resolveShell, runCommand, runCommandResult, stripOne, toHelpConfig };
|
|
2651
|
+
export { GetDotenvCli, baseGetDotenvCliOptions, buildSpawnEnv, composeNestedEnv, definePlugin, defineScripts, getRootCommand, maybePreserveNodeEvalArgv, readMergedOptions, resolveCliOptions, resolveCommand, resolveShell, runCommand, runCommandResult, shouldCapture, stripOne, toHelpConfig };
|
package/dist/config.d.ts
CHANGED
|
@@ -226,6 +226,10 @@ declare const toFileUrl: (p: string) => string;
|
|
|
226
226
|
* - If a JS/TS `schema` is present, use schema.safeParse(finalEnv).
|
|
227
227
|
* - Else if `requiredKeys` is present, check presence (value !== undefined).
|
|
228
228
|
* - Returns a flat list of issue strings; caller decides warn vs fail.
|
|
229
|
+
*
|
|
230
|
+
* @param finalEnv - Final composed environment to validate.
|
|
231
|
+
* @param sources - Resolved config sources providing `schema` and/or `requiredKeys`.
|
|
232
|
+
* @returns A list of human-readable issue strings (empty when valid).
|
|
229
233
|
*/
|
|
230
234
|
declare const validateEnvAgainstSources: (finalEnv: ProcessEnv, sources: ResolvedConfigSources) => string[];
|
|
231
235
|
|
package/dist/config.mjs
CHANGED
|
@@ -148,14 +148,20 @@ const cleanupOldCacheFiles = async (cacheDir, baseName, keep = Math.max(1, Numbe
|
|
|
148
148
|
}
|
|
149
149
|
};
|
|
150
150
|
/**
|
|
151
|
-
* Load a module default export from a JS/TS file with robust fallbacks
|
|
152
|
-
* - .js/.mjs/.cjs: direct import * - .ts/.mts/.cts/.tsx:
|
|
153
|
-
* 1) try direct import (if a TS loader is active),
|
|
154
|
-
* 2) esbuild bundle to a temp ESM file,
|
|
155
|
-
* 3) typescript.transpileModule fallback for simple modules.
|
|
151
|
+
* Load a module default export from a JS/TS file with robust fallbacks.
|
|
156
152
|
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
153
|
+
* Behavior by extension:
|
|
154
|
+
*
|
|
155
|
+
* - `.js`/`.mjs`/`.cjs`: direct dynamic import.
|
|
156
|
+
* - `.ts`/`.mts`/`.cts`/`.tsx`:
|
|
157
|
+
* - try direct dynamic import (when a TS loader is active),
|
|
158
|
+
* - else compile via `esbuild` to a cached `.mjs` file and import,
|
|
159
|
+
* - else fallback to `typescript.transpileModule` for simple modules.
|
|
160
|
+
*
|
|
161
|
+
* @typeParam T - Type of the expected default export.
|
|
162
|
+
* @param absPath - Absolute path to the source file.
|
|
163
|
+
* @param cacheDirName - Cache subfolder under `.tsbuild/`.
|
|
164
|
+
* @returns A `Promise\<T | undefined\>` resolving to the default export (if any).
|
|
159
165
|
*/
|
|
160
166
|
const loadModuleDefault = async (absPath, cacheDirName) => {
|
|
161
167
|
const ext = path.extname(absPath).toLowerCase();
|
|
@@ -372,6 +378,10 @@ const toFileUrl = (p) => pathToFileURL(path.resolve(p)).toString();
|
|
|
372
378
|
* - If a JS/TS `schema` is present, use schema.safeParse(finalEnv).
|
|
373
379
|
* - Else if `requiredKeys` is present, check presence (value !== undefined).
|
|
374
380
|
* - Returns a flat list of issue strings; caller decides warn vs fail.
|
|
381
|
+
*
|
|
382
|
+
* @param finalEnv - Final composed environment to validate.
|
|
383
|
+
* @param sources - Resolved config sources providing `schema` and/or `requiredKeys`.
|
|
384
|
+
* @returns A list of human-readable issue strings (empty when valid).
|
|
375
385
|
*/
|
|
376
386
|
const validateEnvAgainstSources = (finalEnv, sources) => {
|
|
377
387
|
const pick = (getter) => {
|
package/dist/env-overlay.d.ts
CHANGED
|
@@ -179,6 +179,11 @@ type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<Get
|
|
|
179
179
|
* Apply a dynamic map to the target progressively.
|
|
180
180
|
* - Functions receive (target, env) and may return string | undefined.
|
|
181
181
|
* - Literals are assigned directly (including undefined).
|
|
182
|
+
*
|
|
183
|
+
* @param target - Mutable target environment to assign into.
|
|
184
|
+
* @param map - Dynamic map to apply (functions and/or literal values).
|
|
185
|
+
* @param env - Selected environment name (if any) passed through to dynamic functions.
|
|
186
|
+
* @returns Nothing.
|
|
182
187
|
*/
|
|
183
188
|
declare function applyDynamicMap(target: ProcessEnv, map?: GetDotenvDynamic, env?: string): void;
|
|
184
189
|
/**
|
|
@@ -189,6 +194,12 @@ declare function applyDynamicMap(target: ProcessEnv, map?: GetDotenvDynamic, env
|
|
|
189
194
|
* Error behavior:
|
|
190
195
|
* - On failure to load/compile/evaluate the module, throws a unified message:
|
|
191
196
|
* "Unable to load dynamic TypeScript file: <absPath>. Install 'esbuild'..."
|
|
197
|
+
*
|
|
198
|
+
* @param target - Mutable target environment to assign into.
|
|
199
|
+
* @param absPath - Absolute path to the dynamic module file.
|
|
200
|
+
* @param env - Selected environment name (if any).
|
|
201
|
+
* @param cacheDirName - Cache subdirectory under `.tsbuild/` for compiled artifacts.
|
|
202
|
+
* @returns A `Promise\<void\>` which resolves after the module (if present) has been applied.
|
|
192
203
|
*/
|
|
193
204
|
declare function loadAndApplyDynamic(target: ProcessEnv, absPath: string, env: string | undefined, cacheDirName: string): Promise<void>;
|
|
194
205
|
|
package/dist/env-overlay.mjs
CHANGED
|
@@ -165,14 +165,20 @@ const cleanupOldCacheFiles = async (cacheDir, baseName, keep = Math.max(1, Numbe
|
|
|
165
165
|
}
|
|
166
166
|
};
|
|
167
167
|
/**
|
|
168
|
-
* Load a module default export from a JS/TS file with robust fallbacks
|
|
169
|
-
* - .js/.mjs/.cjs: direct import * - .ts/.mts/.cts/.tsx:
|
|
170
|
-
* 1) try direct import (if a TS loader is active),
|
|
171
|
-
* 2) esbuild bundle to a temp ESM file,
|
|
172
|
-
* 3) typescript.transpileModule fallback for simple modules.
|
|
168
|
+
* Load a module default export from a JS/TS file with robust fallbacks.
|
|
173
169
|
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
170
|
+
* Behavior by extension:
|
|
171
|
+
*
|
|
172
|
+
* - `.js`/`.mjs`/`.cjs`: direct dynamic import.
|
|
173
|
+
* - `.ts`/`.mts`/`.cts`/`.tsx`:
|
|
174
|
+
* - try direct dynamic import (when a TS loader is active),
|
|
175
|
+
* - else compile via `esbuild` to a cached `.mjs` file and import,
|
|
176
|
+
* - else fallback to `typescript.transpileModule` for simple modules.
|
|
177
|
+
*
|
|
178
|
+
* @typeParam T - Type of the expected default export.
|
|
179
|
+
* @param absPath - Absolute path to the source file.
|
|
180
|
+
* @param cacheDirName - Cache subfolder under `.tsbuild/`.
|
|
181
|
+
* @returns A `Promise\<T | undefined\>` resolving to the default export (if any).
|
|
176
182
|
*/
|
|
177
183
|
const loadModuleDefault = async (absPath, cacheDirName) => {
|
|
178
184
|
const ext = path.extname(absPath).toLowerCase();
|
|
@@ -250,6 +256,11 @@ const loadModuleDefault = async (absPath, cacheDirName) => {
|
|
|
250
256
|
* Apply a dynamic map to the target progressively.
|
|
251
257
|
* - Functions receive (target, env) and may return string | undefined.
|
|
252
258
|
* - Literals are assigned directly (including undefined).
|
|
259
|
+
*
|
|
260
|
+
* @param target - Mutable target environment to assign into.
|
|
261
|
+
* @param map - Dynamic map to apply (functions and/or literal values).
|
|
262
|
+
* @param env - Selected environment name (if any) passed through to dynamic functions.
|
|
263
|
+
* @returns Nothing.
|
|
253
264
|
*/
|
|
254
265
|
function applyDynamicMap(target, map, env) {
|
|
255
266
|
if (!map)
|
|
@@ -269,6 +280,12 @@ function applyDynamicMap(target, map, env) {
|
|
|
269
280
|
* Error behavior:
|
|
270
281
|
* - On failure to load/compile/evaluate the module, throws a unified message:
|
|
271
282
|
* "Unable to load dynamic TypeScript file: <absPath>. Install 'esbuild'..."
|
|
283
|
+
*
|
|
284
|
+
* @param target - Mutable target environment to assign into.
|
|
285
|
+
* @param absPath - Absolute path to the dynamic module file.
|
|
286
|
+
* @param env - Selected environment name (if any).
|
|
287
|
+
* @param cacheDirName - Cache subdirectory under `.tsbuild/` for compiled artifacts.
|
|
288
|
+
* @returns A `Promise\<void\>` which resolves after the module (if present) has been applied.
|
|
272
289
|
*/
|
|
273
290
|
async function loadAndApplyDynamic(target, absPath, env, cacheDirName) {
|
|
274
291
|
if (!(await fs.exists(absPath)))
|