@karmaniverous/get-dotenv 6.5.1 → 6.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1792,6 +1792,52 @@ declare const applyIncludeExclude: (env: ProcessEnv, { include, exclude, }: {
1792
1792
  exclude?: string[];
1793
1793
  }) => ProcessEnv;
1794
1794
 
1795
+ /**
1796
+ * Assert that a value is a non-empty string.
1797
+ *
1798
+ * @param v - Value to check.
1799
+ * @param msg - Error message to throw if check fails.
1800
+ */
1801
+ declare const requireString: (v: unknown, msg: string) => string;
1802
+ /**
1803
+ * Assert that the byte length of a value (stringified) does not exceed a limit.
1804
+ *
1805
+ * @param value - Value to measure (strings used as-is; others JSON-stringified).
1806
+ * @param limit - Maximum allowed byte length.
1807
+ * @param errorMsg - Error message string or generator function.
1808
+ */
1809
+ declare const assertByteLimit: (value: unknown, limit: number, errorMsg: string | ((v: unknown, l: number) => string)) => void;
1810
+
1811
+ /**
1812
+ * Perform a deep defaults‑style merge across plain objects.
1813
+ * - Only merges plain objects (prototype === Object.prototype).
1814
+ * - Arrays and non‑objects are replaced, not merged.
1815
+ * - `undefined` values are ignored and do not overwrite prior values.
1816
+ *
1817
+ * @typeParam T - Resulting shape after merging all layers.
1818
+ * @returns The merged object typed as T.
1819
+ *
1820
+ * @example
1821
+ * defaultsDeep(\{ a: 1, nested: \{ b: 2 \} \}, \{ nested: \{ b: 3, c: 4 \} \})
1822
+ * =\> \{ a: 1, nested: \{ b: 3, c: 4 \} \}
1823
+ */
1824
+ declare function defaultsDeep<A extends object>(a?: Partial<A>): A;
1825
+ declare function defaultsDeep<A extends object, B extends object>(a?: Partial<A>, b?: Partial<B>): A & B;
1826
+ declare function defaultsDeep<A extends object, B extends object, C extends object>(a?: Partial<A>, b?: Partial<B>, c?: Partial<C>): A & B & C;
1827
+ declare function defaultsDeep<A extends object, B extends object, C extends object, D extends object>(a?: Partial<A>, b?: Partial<B>, c?: Partial<C>, d?: Partial<D>): A & B & C & D;
1828
+ declare function defaultsDeep<A extends object, B extends object, C extends object, D extends object, E extends object>(a?: Partial<A>, b?: Partial<B>, c?: Partial<C>, d?: Partial<D>, e?: Partial<E>): A & B & C & D & E;
1829
+ declare function defaultsDeep<T extends object>(...layers: Array<Partial<T> | undefined>): T;
1830
+
1831
+ /**
1832
+ * Serialize a dotenv record to a file with minimal quoting (multiline values are quoted).
1833
+ * Future-proofs for ordering/sorting changes (currently insertion order).
1834
+ *
1835
+ * @param filename - Destination dotenv file path.
1836
+ * @param data - Env-like map of values to write (values may be `undefined`).
1837
+ * @returns A `Promise\<void\>` which resolves when the file has been written.
1838
+ */
1839
+ declare function writeDotenvFile(filename: string, data: ProcessEnv): Promise<void>;
1840
+
1795
1841
  /**
1796
1842
  * Deeply interpolate string leaves against envRef.
1797
1843
  * Arrays are not recursed into; they are returned unchanged.
@@ -1803,6 +1849,36 @@ declare const applyIncludeExclude: (env: ProcessEnv, { include, exclude, }: {
1803
1849
  */
1804
1850
  declare const interpolateDeep: <T>(value: T, envRef: ProcessEnv) => T;
1805
1851
 
1852
+ /**
1853
+ * Load a module default export from a JS/TS file with robust fallbacks.
1854
+ *
1855
+ * Behavior by extension:
1856
+ *
1857
+ * - `.js`/`.mjs`/`.cjs`: direct dynamic import.
1858
+ * - `.ts`/`.mts`/`.cts`/`.tsx`:
1859
+ * - try direct dynamic import (when a TS loader is active),
1860
+ * - else compile via `esbuild` to a cached `.mjs` file and import,
1861
+ * - else fallback to `typescript.transpileModule` for simple modules.
1862
+ *
1863
+ * @typeParam T - Type of the expected default export.
1864
+ * @param absPath - Absolute path to the source file.
1865
+ * @param cacheDirName - Cache subfolder under `.tsbuild/`.
1866
+ * @returns A `Promise\<T | undefined\>` resolving to the default export (if any).
1867
+ */
1868
+ declare const loadModuleDefault: <T>(absPath: string, cacheDirName: string) => Promise<T | undefined>;
1869
+
1870
+ /**
1871
+ * A silent logger that implements the Logger interface but performs no operations.
1872
+ */
1873
+ declare const silentLogger: Logger;
1874
+
1875
+ /**
1876
+ * Parse a value into a number or undefined.
1877
+ *
1878
+ * @param v - Value to parse.
1879
+ * @returns The parsed number, or undefined if the input was undefined or empty string.
1880
+ */
1881
+ declare const toNumber: (v: unknown) => number | undefined;
1806
1882
  /**
1807
1883
  * Build a Commander option parser that coerces a raw string to a finite number.
1808
1884
  *
@@ -1825,5 +1901,27 @@ declare const parsePositiveInt: (label: string) => (raw: string) => number;
1825
1901
  */
1826
1902
  declare const parseNonNegativeInt: (label: string) => (raw: string) => number;
1827
1903
 
1828
- export { GetDotenvCli, applyDotenvEdits, applyIncludeExclude, baseRootOptionDefaults, buildSpawnEnv, createCli, defineDynamic, defineGetDotenvConfig, definePlugin, defineScripts, dotenvExpand, dotenvExpandAll, dotenvExpandFromProcessEnv, editDotenvFile, editDotenvText, getDotenv, getDotenvCliOptions2Options, groupPlugins, interpolateDeep, maybeWarnEntropy, parseDotenvDocument, parseFiniteNumber, parseNonNegativeInt, parsePositiveInt, readMergedOptions, redactDisplay, redactObject, renderDotenvDocument, shouldCapture, traceChildEnv };
1829
- export type { CreateCliOptions, DotenvAssignmentSegment, DotenvBareKeySegment, DotenvConfigProvenanceEntry, DotenvDocument, DotenvDuplicateKeyStrategy, DotenvDynamicProvenanceEntry, DotenvDynamicSource, DotenvEditMode, DotenvEditOptions, DotenvEolMode, DotenvFileProvenanceEntry, DotenvFs, DotenvPathSearchOrder, DotenvProvenance, DotenvProvenanceEntry, DotenvProvenanceEntryBase, DotenvProvenanceKind, DotenvProvenanceOp, DotenvSegment, DotenvTargetPrivacy, DotenvTargetScope, DotenvUpdateMap, DotenvUpdateValue, DotenvVarsProvenanceEntry, DynamicFn, DynamicMap, EditDotenvFileOptions, EditDotenvFileResult, EntropyOptions, GetDotenvCliOptions, GetDotenvCliPlugin, GetDotenvCliPublic, GetDotenvConfig, GetDotenvDynamic, GetDotenvOptions, InferGetDotenvVarsFromConfig, InferPluginConfig, PluginWithInstanceHelpers, ProcessEnv, RedactOptions, ScriptsTable, TraceChildEnvOptions };
1904
+ /**
1905
+ * Options for the tokenizer used by shell-off command handling.
1906
+ *
1907
+ * @public
1908
+ */
1909
+ interface TokenizeOptions {
1910
+ /**
1911
+ * When true, keep doubled quotes inside a quoted segment (e.g., `""` stays `""`),
1912
+ * which is useful for preserving Node -e payload quoting patterns.
1913
+ * When false (default), doubled quotes collapse to a single literal quote.
1914
+ */
1915
+ preserveDoubledQuotes?: boolean;
1916
+ }
1917
+ /**
1918
+ * Minimal tokenizer for shell-off execution.
1919
+ * Splits by whitespace while preserving quoted segments (single or double quotes).
1920
+ *
1921
+ * @param command - The command string to tokenize.
1922
+ * @param opts - Tokenization options (e.g. quote handling).
1923
+ */
1924
+ declare const tokenize: (command: string, opts?: TokenizeOptions) => string[];
1925
+
1926
+ export { GetDotenvCli, applyDotenvEdits, applyIncludeExclude, assertByteLimit, baseRootOptionDefaults, buildSpawnEnv, createCli, defaultsDeep, defineDynamic, defineGetDotenvConfig, definePlugin, defineScripts, dotenvExpand, dotenvExpandAll, dotenvExpandFromProcessEnv, editDotenvFile, editDotenvText, getDotenv, getDotenvCliOptions2Options, groupPlugins, interpolateDeep, loadModuleDefault, maybeWarnEntropy, parseDotenvDocument, parseFiniteNumber, parseNonNegativeInt, parsePositiveInt, readMergedOptions, redactDisplay, redactObject, renderDotenvDocument, requireString, shouldCapture, silentLogger, toNumber, tokenize, traceChildEnv, writeDotenvFile };
1927
+ export type { CreateCliOptions, DotenvAssignmentSegment, DotenvBareKeySegment, DotenvConfigProvenanceEntry, DotenvDocument, DotenvDuplicateKeyStrategy, DotenvDynamicProvenanceEntry, DotenvDynamicSource, DotenvEditMode, DotenvEditOptions, DotenvEolMode, DotenvFileProvenanceEntry, DotenvFs, DotenvPathSearchOrder, DotenvProvenance, DotenvProvenanceEntry, DotenvProvenanceEntryBase, DotenvProvenanceKind, DotenvProvenanceOp, DotenvSegment, DotenvTargetPrivacy, DotenvTargetScope, DotenvUpdateMap, DotenvUpdateValue, DotenvVarsProvenanceEntry, DynamicFn, DynamicMap, EditDotenvFileOptions, EditDotenvFileResult, EntropyOptions, GetDotenvCliOptions, GetDotenvCliPlugin, GetDotenvCliPublic, GetDotenvConfig, GetDotenvDynamic, GetDotenvOptions, InferGetDotenvVarsFromConfig, InferPluginConfig, PluginWithInstanceHelpers, ProcessEnv, RedactOptions, ScriptsTable, TokenizeOptions, TraceChildEnvOptions };
package/dist/index.mjs CHANGED
@@ -1,27 +1,27 @@
1
1
  export { c as createCli } from './chunks/createCli-pZgHlwKX.mjs';
2
2
  import { e as resolveGetDotenvOptions, w as writeDotenvFile } from './chunks/readMergedOptions-uWSetyes.mjs';
3
- export { G as GetDotenvCli, b as baseRootOptionDefaults, f as defineDynamic, h as defineGetDotenvConfig, d as definePlugin, g as getDotenvCliOptions2Options, i as interpolateDeep, r as readMergedOptions } from './chunks/readMergedOptions-uWSetyes.mjs';
4
- export { d as buildSpawnEnv, s as shouldCapture } from './chunks/spawnEnv-5kdIVv0x.mjs';
3
+ export { G as GetDotenvCli, b as baseRootOptionDefaults, a as defaultsDeep, f as defineDynamic, h as defineGetDotenvConfig, d as definePlugin, g as getDotenvCliOptions2Options, i as interpolateDeep, r as readMergedOptions } from './chunks/readMergedOptions-uWSetyes.mjs';
4
+ export { d as buildSpawnEnv, s as shouldCapture, t as tokenize } from './chunks/spawnEnv-5kdIVv0x.mjs';
5
5
  export { d as defineScripts, g as groupPlugins } from './chunks/types-BSMtAo8_.mjs';
6
6
  import { omit, pick } from 'radash';
7
- import 'node:buffer';
8
- import fs from 'fs-extra';
9
- import 'crypto';
10
- import path$1 from 'path';
11
- import 'url';
7
+ import { Buffer } from 'node:buffer';
8
+ export { l as loadModuleDefault } from './chunks/loadModuleDefault-Dj8B3Stt.mjs';
12
9
  import { InvalidArgumentError } from '@commander-js/extra-typings';
13
10
  export { z } from 'zod';
14
11
  import { nanoid } from 'nanoid';
12
+ import path$1 from 'path';
15
13
  import { r as redactObject, m as maybeWarnEntropy } from './chunks/index-Cg50N4ys.mjs';
16
14
  export { a as redactDisplay, t as traceChildEnv } from './chunks/index-Cg50N4ys.mjs';
17
15
  import { g as readDotenv, d as dotenvExpandAll, a as applyDynamicMap, c as loadAndApplyDynamic } from './chunks/readDotenvCascade-HLU7FsEQ.mjs';
18
16
  export { h as dotenvExpand, f as dotenvExpandFromProcessEnv } from './chunks/readDotenvCascade-HLU7FsEQ.mjs';
17
+ import fs from 'fs-extra';
19
18
  import path from 'node:path';
19
+ import 'crypto';
20
+ import 'url';
20
21
  import 'dotenv';
21
22
  import './chunks/loader-CE4HSRN4.mjs';
22
23
  import 'package-directory';
23
24
  import 'yaml';
24
- import './chunks/loadModuleDefault-Dj8B3Stt.mjs';
25
25
  import 'execa';
26
26
  import './chunks/helpConfig-CGejgwWW.mjs';
27
27
  import './chunks/resolveCliOptions-7MwNdHqz.mjs';
@@ -63,6 +63,33 @@ const applyIncludeExclude = (env, { include, exclude, }) => {
63
63
  return out;
64
64
  };
65
65
 
66
+ /**
67
+ * Assert that a value is a non-empty string.
68
+ *
69
+ * @param v - Value to check.
70
+ * @param msg - Error message to throw if check fails.
71
+ */
72
+ const requireString = (v, msg) => {
73
+ if (typeof v !== 'string' || !v)
74
+ throw new Error(msg);
75
+ return v;
76
+ };
77
+ /**
78
+ * Assert that the byte length of a value (stringified) does not exceed a limit.
79
+ *
80
+ * @param value - Value to measure (strings used as-is; others JSON-stringified).
81
+ * @param limit - Maximum allowed byte length.
82
+ * @param errorMsg - Error message string or generator function.
83
+ */
84
+ const assertByteLimit = (value, limit, errorMsg) => {
85
+ const s = typeof value === 'string' ? value : JSON.stringify(value);
86
+ const bytes = Buffer.byteLength(s, 'utf8');
87
+ if (bytes > limit) {
88
+ const msg = typeof errorMsg === 'function' ? errorMsg(value, limit) : errorMsg;
89
+ throw new Error(msg);
90
+ }
91
+ };
92
+
66
93
  /**
67
94
  * Dotenv editor types (format-preserving).
68
95
  *
@@ -799,6 +826,32 @@ async function editDotenvFile(updates, options) {
799
826
  return { path: resolved.targetPath, createdFromTemplate, changed };
800
827
  }
801
828
 
829
+ /**
830
+ * A silent logger that implements the Logger interface but performs no operations.
831
+ */
832
+ const silentLogger = {
833
+ debug: () => { },
834
+ info: () => { },
835
+ warn: () => { },
836
+ error: () => { },
837
+ log: () => { },
838
+ };
839
+
840
+ /**
841
+ * Parse a value into a number or undefined.
842
+ *
843
+ * @param v - Value to parse.
844
+ * @returns The parsed number, or undefined if the input was undefined or empty string.
845
+ */
846
+ const toNumber = (v) => {
847
+ if (typeof v === 'undefined')
848
+ return;
849
+ if (typeof v === 'number')
850
+ return v;
851
+ if (typeof v === 'string' && v.trim())
852
+ return Number(v);
853
+ return;
854
+ };
802
855
  /**
803
856
  * Build a Commander option parser that coerces a raw string to a finite number.
804
857
  *
@@ -944,4 +997,4 @@ async function getDotenv(options = {}) {
944
997
  return resultDotenv;
945
998
  }
946
999
 
947
- export { applyDotenvEdits, applyIncludeExclude, dotenvExpandAll, editDotenvFile, editDotenvText, getDotenv, maybeWarnEntropy, parseDotenvDocument, parseFiniteNumber, parseNonNegativeInt, parsePositiveInt, redactObject, renderDotenvDocument };
1000
+ export { applyDotenvEdits, applyIncludeExclude, assertByteLimit, dotenvExpandAll, editDotenvFile, editDotenvText, getDotenv, maybeWarnEntropy, parseDotenvDocument, parseFiniteNumber, parseNonNegativeInt, parsePositiveInt, redactObject, renderDotenvDocument, requireString, silentLogger, toNumber, writeDotenvFile };
package/package.json CHANGED
@@ -221,5 +221,5 @@
221
221
  },
222
222
  "type": "module",
223
223
  "types": "dist/index.d.ts",
224
- "version": "6.5.1"
224
+ "version": "6.5.2"
225
225
  }