@karmaniverous/get-dotenv 6.2.4 → 6.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +1 -0
  2. package/dist/chunks/{AwsRestJsonProtocol-Bq1HE-Ln.mjs → AwsRestJsonProtocol-fYZqn-kW.mjs} +2 -2
  3. package/dist/chunks/{createCli-BY6_cfZr.mjs → createCli-BnRdfRRL.mjs} +7 -6
  4. package/dist/chunks/{externalDataInterceptor-CbsdEYa-.mjs → externalDataInterceptor-CILOLqbB.mjs} +2 -2
  5. package/dist/chunks/{getSSOTokenFromFile-hUSpR7Wf.mjs → getSSOTokenFromFile-BwMkZ_yT.mjs} +1 -1
  6. package/dist/chunks/{index-C_wqbTwI.mjs → index-0-nP97ri.mjs} +7 -6
  7. package/dist/chunks/{index-CeCufHlm.mjs → index-70Dm0f1N.mjs} +11 -10
  8. package/dist/chunks/{index-BPYF6K_G.mjs → index-BhVOypA1.mjs} +9 -8
  9. package/dist/chunks/{index-cIunyiUQ.mjs → index-CcwT4HJK.mjs} +6 -5
  10. package/dist/chunks/{index-BpCF5UKx.mjs → index-D8UL3w94.mjs} +6 -5
  11. package/dist/chunks/{index-Cu7rdyqN.mjs → index-DLNhHC15.mjs} +9 -8
  12. package/dist/chunks/{index-Dp1Ip6Ra.mjs → index-DWqbxY8Y.mjs} +11 -10
  13. package/dist/chunks/{index-c7zKtEuy.mjs → index-Du51s-Z0.mjs} +8 -7
  14. package/dist/chunks/{index-B5JKTBOL.mjs → index-DuSz0ul6.mjs} +8 -7
  15. package/dist/chunks/{index-DWAtHEA-.mjs → index-OeNCYa8T.mjs} +6 -5
  16. package/dist/chunks/{index-DyU5pKKi.mjs → index-_FP0whjC.mjs} +6 -5
  17. package/dist/chunks/{index-BEJFiHMX.mjs → index-o5zJ9PWL.mjs} +15 -15
  18. package/dist/chunks/{index-Bc3h0a95.mjs → index-r0Me7-sT.mjs} +112 -6
  19. package/dist/chunks/{loadSso-w1eTVg0O.mjs → loadSso-CLR1fKci.mjs} +8 -7
  20. package/dist/chunks/{loader-DnhPeGfq.mjs → loader-CePOf74i.mjs} +1 -0
  21. package/dist/chunks/{parseKnownFiles-B9cDK21V.mjs → parseKnownFiles-BQvmJ0HK.mjs} +1 -1
  22. package/dist/chunks/readDotenvCascade-DfFkWMjs.mjs +546 -0
  23. package/dist/chunks/{readMergedOptions-Nt0TR7dX.mjs → readMergedOptions-B7VdLROn.mjs} +62 -272
  24. package/dist/chunks/{resolveCliOptions-TFRzhB2c.mjs → resolveCliOptions-pgUXHJtj.mjs} +2 -1
  25. package/dist/chunks/{sdk-stream-mixin-BZoJ5jy9.mjs → sdk-stream-mixin-ecbbBR0l.mjs} +1 -1
  26. package/dist/chunks/{spawnEnv-CN8a7cNR.mjs → spawnEnv-CQwFu7ZJ.mjs} +2 -1
  27. package/dist/chunks/{types-DJ-BGABd.mjs → types-CVDR-Sjk.mjs} +1 -1
  28. package/dist/cli.d.ts +218 -84
  29. package/dist/cli.mjs +10 -10
  30. package/dist/cliHost.d.ts +218 -84
  31. package/dist/cliHost.mjs +8 -7
  32. package/dist/config.mjs +2 -1
  33. package/dist/env-overlay.d.ts +304 -2
  34. package/dist/env-overlay.mjs +38 -1
  35. package/dist/getdotenv.cli.mjs +10 -10
  36. package/dist/index.d.ts +703 -86
  37. package/dist/index.mjs +862 -13
  38. package/dist/plugins-aws.d.ts +153 -19
  39. package/dist/plugins-aws.mjs +5 -4
  40. package/dist/plugins-batch.d.ts +153 -19
  41. package/dist/plugins-batch.mjs +5 -4
  42. package/dist/plugins-cmd.d.ts +153 -19
  43. package/dist/plugins-cmd.mjs +7 -6
  44. package/dist/plugins-init.d.ts +153 -19
  45. package/dist/plugins-init.mjs +4 -4
  46. package/dist/plugins.d.ts +153 -19
  47. package/dist/plugins.mjs +9 -9
  48. package/package.json +1 -1
  49. package/dist/chunks/overlayEnv-Bs2kVayG.mjs +0 -234
package/dist/index.d.ts CHANGED
@@ -2,6 +2,218 @@ import { z, ZodObject } from 'zod';
2
2
  export { z } from 'zod';
3
3
  import { OptionValues, Command, InferCommandArguments, Option, CommandUnknownOpts } from '@commander-js/extra-typings';
4
4
 
5
+ /**
6
+ * Dotenv provenance model (descriptor-only).
7
+ *
8
+ * Requirements addressed:
9
+ * - Host ctx carries a dotenv provenance mapping describing per-key origin and override history.
10
+ * - Provenance is descriptor-only (no value payloads).
11
+ * - Provenance is an ordered stack per key in ascending precedence; the last entry is effective.
12
+ * - Explicit unsets are represented as `op: 'unset'` without requiring deletion of keys from the env map.
13
+ */
14
+ /**
15
+ * Provenance kind for an entry in {@link DotenvProvenance}.
16
+ *
17
+ * @public
18
+ */
19
+ type DotenvProvenanceKind = 'file' | 'config' | 'vars' | 'dynamic';
20
+ /**
21
+ * Operation represented by a provenance entry.
22
+ *
23
+ * @public
24
+ */
25
+ type DotenvProvenanceOp = 'set' | 'unset';
26
+ /**
27
+ * Base shape for all provenance entries.
28
+ *
29
+ * @public
30
+ */
31
+ interface DotenvProvenanceEntryBase {
32
+ /**
33
+ * The kind of provenance entry.
34
+ */
35
+ kind: DotenvProvenanceKind;
36
+ /**
37
+ * The operation applied at this layer.
38
+ */
39
+ op: DotenvProvenanceOp;
40
+ }
41
+ /**
42
+ * Provenance entry representing a value sourced from a dotenv file in the cascade.
43
+ *
44
+ * @public
45
+ */
46
+ interface DotenvFileProvenanceEntry extends DotenvProvenanceEntryBase {
47
+ /** Discriminator. */
48
+ kind: 'file';
49
+ /** Global vs env-scoped file. */
50
+ scope: 'global' | 'env';
51
+ /** Public vs private file. */
52
+ privacy: 'public' | 'private';
53
+ /** Environment name (required when scope is `env`). */
54
+ env?: string;
55
+ /**
56
+ * The corresponding `paths[]` entry as provided by the caller/CLI.
57
+ * This is not an absolute path by policy.
58
+ */
59
+ path: string;
60
+ /**
61
+ * The computed dotenv filename token (e.g., `.env`, `.env.dev`, `.env.local`, `.env.dev.local`).
62
+ */
63
+ file: string;
64
+ }
65
+ /**
66
+ * Provenance entry representing a value sourced from config overlays (`vars` / `envVars`).
67
+ *
68
+ * @public
69
+ */
70
+ interface DotenvConfigProvenanceEntry extends DotenvProvenanceEntryBase {
71
+ /** Discriminator. */
72
+ kind: 'config';
73
+ /** Global vs env-scoped config slice. */
74
+ scope: 'global' | 'env';
75
+ /** Public vs private on the privacy axis (`local` config maps to `private`). */
76
+ privacy: 'public' | 'private';
77
+ /** Environment name (required when scope is `env`). */
78
+ env?: string;
79
+ /** Packaged vs project config origin. */
80
+ configScope: 'packaged' | 'project';
81
+ /** Public vs local config file. */
82
+ configPrivacy: 'public' | 'local';
83
+ }
84
+ /**
85
+ * Provenance entry representing explicit variables overrides.
86
+ *
87
+ * Notes:
88
+ * - This kind represents values injected via `vars` (CLI/programmatic), not dotenv files.
89
+ *
90
+ * @public
91
+ */
92
+ interface DotenvVarsProvenanceEntry extends DotenvProvenanceEntryBase {
93
+ /** Discriminator. */
94
+ kind: 'vars';
95
+ }
96
+ /**
97
+ * Source tier for dynamic variables.
98
+ *
99
+ * @public
100
+ */
101
+ type DotenvDynamicSource = 'config' | 'programmatic' | 'dynamicPath';
102
+ /**
103
+ * Provenance entry representing dynamic variables.
104
+ *
105
+ * @public
106
+ */
107
+ interface DotenvDynamicProvenanceEntry extends DotenvProvenanceEntryBase {
108
+ /** Discriminator. */
109
+ kind: 'dynamic';
110
+ /** Dynamic source tier. */
111
+ dynamicSource: DotenvDynamicSource;
112
+ /**
113
+ * The `dynamicPath` value as provided by the caller/CLI when `dynamicSource` is `dynamicPath`.
114
+ * This is not resolved to an absolute path by provenance policy.
115
+ */
116
+ dynamicPath?: string;
117
+ }
118
+ /**
119
+ * Union of all supported provenance entry shapes.
120
+ *
121
+ * @public
122
+ */
123
+ type DotenvProvenanceEntry = DotenvFileProvenanceEntry | DotenvConfigProvenanceEntry | DotenvVarsProvenanceEntry | DotenvDynamicProvenanceEntry;
124
+ /**
125
+ * Per-key provenance history.
126
+ *
127
+ * Each key maps to an array of entries ordered in ascending precedence (lower to higher).
128
+ *
129
+ * @public
130
+ */
131
+ type DotenvProvenance = Record<string, DotenvProvenanceEntry[]>;
132
+
133
+ /**
134
+ * Resolved CLI options schema.
135
+ * For the current step this mirrors the RAW schema; later stages may further
136
+ * narrow types post-resolution in the host pipeline.
137
+ */
138
+ /**
139
+ * CLI options schema (resolved).
140
+ *
141
+ * Today this mirrors {@link getDotenvCliOptionsSchemaRaw}, but is kept as a distinct export
142
+ * so future resolution steps can narrow or materialize defaults without breaking the API.
143
+ *
144
+ * @public
145
+ */
146
+ declare const getDotenvCliOptionsSchemaResolved: z.ZodObject<{
147
+ defaultEnv: z.ZodOptional<z.ZodString>;
148
+ dotenvToken: z.ZodOptional<z.ZodString>;
149
+ dynamicPath: z.ZodOptional<z.ZodString>;
150
+ dynamic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
151
+ env: z.ZodOptional<z.ZodString>;
152
+ excludeDynamic: z.ZodOptional<z.ZodBoolean>;
153
+ excludeEnv: z.ZodOptional<z.ZodBoolean>;
154
+ excludeGlobal: z.ZodOptional<z.ZodBoolean>;
155
+ excludePrivate: z.ZodOptional<z.ZodBoolean>;
156
+ excludePublic: z.ZodOptional<z.ZodBoolean>;
157
+ loadProcess: z.ZodOptional<z.ZodBoolean>;
158
+ log: z.ZodOptional<z.ZodBoolean>;
159
+ logger: z.ZodDefault<z.ZodUnknown>;
160
+ outputPath: z.ZodOptional<z.ZodString>;
161
+ privateToken: z.ZodOptional<z.ZodString>;
162
+ debug: z.ZodOptional<z.ZodBoolean>;
163
+ strict: z.ZodOptional<z.ZodBoolean>;
164
+ capture: z.ZodOptional<z.ZodBoolean>;
165
+ trace: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
166
+ redact: z.ZodOptional<z.ZodBoolean>;
167
+ warnEntropy: z.ZodOptional<z.ZodBoolean>;
168
+ entropyThreshold: z.ZodOptional<z.ZodNumber>;
169
+ entropyMinLength: z.ZodOptional<z.ZodNumber>;
170
+ entropyWhitelist: z.ZodOptional<z.ZodArray<z.ZodString>>;
171
+ redactPatterns: z.ZodOptional<z.ZodArray<z.ZodString>>;
172
+ paths: z.ZodOptional<z.ZodString>;
173
+ pathsDelimiter: z.ZodOptional<z.ZodString>;
174
+ pathsDelimiterPattern: z.ZodOptional<z.ZodString>;
175
+ scripts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
176
+ shell: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
177
+ vars: z.ZodOptional<z.ZodString>;
178
+ varsAssignor: z.ZodOptional<z.ZodString>;
179
+ varsAssignorPattern: z.ZodOptional<z.ZodString>;
180
+ varsDelimiter: z.ZodOptional<z.ZodString>;
181
+ varsDelimiterPattern: z.ZodOptional<z.ZodString>;
182
+ }, z.core.$strip>;
183
+
184
+ /**
185
+ * Resolved programmatic options schema (post-inheritance).
186
+ * For now, this mirrors the RAW schema; future stages may materialize defaults
187
+ * and narrow shapes as resolution is wired into the host.
188
+ */
189
+ /**
190
+ * Programmatic options schema (resolved).
191
+ *
192
+ * Today this mirrors {@link getDotenvOptionsSchemaRaw}, but is kept as a distinct export
193
+ * so future resolution steps can narrow or materialize defaults without breaking the API.
194
+ *
195
+ * @public
196
+ */
197
+ declare const getDotenvOptionsSchemaResolved: z.ZodObject<{
198
+ defaultEnv: z.ZodOptional<z.ZodString>;
199
+ dotenvToken: z.ZodOptional<z.ZodString>;
200
+ dynamicPath: z.ZodOptional<z.ZodString>;
201
+ dynamic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
202
+ env: z.ZodOptional<z.ZodString>;
203
+ excludeDynamic: z.ZodOptional<z.ZodBoolean>;
204
+ excludeEnv: z.ZodOptional<z.ZodBoolean>;
205
+ excludeGlobal: z.ZodOptional<z.ZodBoolean>;
206
+ excludePrivate: z.ZodOptional<z.ZodBoolean>;
207
+ excludePublic: z.ZodOptional<z.ZodBoolean>;
208
+ loadProcess: z.ZodOptional<z.ZodBoolean>;
209
+ log: z.ZodOptional<z.ZodBoolean>;
210
+ logger: z.ZodDefault<z.ZodUnknown>;
211
+ outputPath: z.ZodOptional<z.ZodString>;
212
+ paths: z.ZodOptional<z.ZodArray<z.ZodString>>;
213
+ privateToken: z.ZodOptional<z.ZodString>;
214
+ vars: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodString>>>;
215
+ }, z.core.$strip>;
216
+
5
217
  /**
6
218
  * Minimal root options shape shared by CLI and generator layers.
7
219
  * Keep keys optional to respect exactOptionalPropertyTypes semantics.
@@ -121,6 +333,12 @@ interface GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions>
121
333
  * Final composed dotenv environment for this invocation.
122
334
  */
123
335
  dotenv: ProcessEnv;
336
+ /**
337
+ * Dotenv provenance history for {@link GetDotenvCliCtx.dotenv}.
338
+ *
339
+ * Descriptor-only: does not include value payloads.
340
+ */
341
+ dotenvProvenance: DotenvProvenance;
124
342
  /**
125
343
  * Optional runtime plugin state bag. Plugins may publish non-sensitive metadata here.
126
344
  */
@@ -148,90 +366,6 @@ interface BrandOptions {
148
366
  helpHeader?: string;
149
367
  }
150
368
 
151
- /**
152
- * Resolved CLI options schema.
153
- * For the current step this mirrors the RAW schema; later stages may further
154
- * narrow types post-resolution in the host pipeline.
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
- */
164
- declare const getDotenvCliOptionsSchemaResolved: z.ZodObject<{
165
- defaultEnv: z.ZodOptional<z.ZodString>;
166
- dotenvToken: z.ZodOptional<z.ZodString>;
167
- dynamicPath: z.ZodOptional<z.ZodString>;
168
- dynamic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
169
- env: z.ZodOptional<z.ZodString>;
170
- excludeDynamic: z.ZodOptional<z.ZodBoolean>;
171
- excludeEnv: z.ZodOptional<z.ZodBoolean>;
172
- excludeGlobal: z.ZodOptional<z.ZodBoolean>;
173
- excludePrivate: z.ZodOptional<z.ZodBoolean>;
174
- excludePublic: z.ZodOptional<z.ZodBoolean>;
175
- loadProcess: z.ZodOptional<z.ZodBoolean>;
176
- log: z.ZodOptional<z.ZodBoolean>;
177
- logger: z.ZodDefault<z.ZodUnknown>;
178
- outputPath: z.ZodOptional<z.ZodString>;
179
- privateToken: z.ZodOptional<z.ZodString>;
180
- debug: z.ZodOptional<z.ZodBoolean>;
181
- strict: z.ZodOptional<z.ZodBoolean>;
182
- capture: z.ZodOptional<z.ZodBoolean>;
183
- trace: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
184
- redact: z.ZodOptional<z.ZodBoolean>;
185
- warnEntropy: z.ZodOptional<z.ZodBoolean>;
186
- entropyThreshold: z.ZodOptional<z.ZodNumber>;
187
- entropyMinLength: z.ZodOptional<z.ZodNumber>;
188
- entropyWhitelist: z.ZodOptional<z.ZodArray<z.ZodString>>;
189
- redactPatterns: z.ZodOptional<z.ZodArray<z.ZodString>>;
190
- paths: z.ZodOptional<z.ZodString>;
191
- pathsDelimiter: z.ZodOptional<z.ZodString>;
192
- pathsDelimiterPattern: z.ZodOptional<z.ZodString>;
193
- scripts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
194
- shell: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
195
- vars: z.ZodOptional<z.ZodString>;
196
- varsAssignor: z.ZodOptional<z.ZodString>;
197
- varsAssignorPattern: z.ZodOptional<z.ZodString>;
198
- varsDelimiter: z.ZodOptional<z.ZodString>;
199
- varsDelimiterPattern: z.ZodOptional<z.ZodString>;
200
- }, z.core.$strip>;
201
-
202
- /**
203
- * Resolved programmatic options schema (post-inheritance).
204
- * For now, this mirrors the RAW schema; future stages may materialize defaults
205
- * and narrow shapes as resolution is wired into the host.
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
- */
215
- declare const getDotenvOptionsSchemaResolved: z.ZodObject<{
216
- defaultEnv: z.ZodOptional<z.ZodString>;
217
- dotenvToken: z.ZodOptional<z.ZodString>;
218
- dynamicPath: z.ZodOptional<z.ZodString>;
219
- dynamic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
220
- env: z.ZodOptional<z.ZodString>;
221
- excludeDynamic: z.ZodOptional<z.ZodBoolean>;
222
- excludeEnv: z.ZodOptional<z.ZodBoolean>;
223
- excludeGlobal: z.ZodOptional<z.ZodBoolean>;
224
- excludePrivate: z.ZodOptional<z.ZodBoolean>;
225
- excludePublic: z.ZodOptional<z.ZodBoolean>;
226
- loadProcess: z.ZodOptional<z.ZodBoolean>;
227
- log: z.ZodOptional<z.ZodBoolean>;
228
- logger: z.ZodDefault<z.ZodUnknown>;
229
- outputPath: z.ZodOptional<z.ZodString>;
230
- paths: z.ZodOptional<z.ZodArray<z.ZodString>>;
231
- privateToken: z.ZodOptional<z.ZodString>;
232
- vars: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodString>>>;
233
- }, z.core.$strip>;
234
-
235
369
  /**
236
370
  * Canonical programmatic options and helpers for get-dotenv.
237
371
  *
@@ -1170,6 +1304,489 @@ declare function dotenvExpandAll<T extends Record<string, string | undefined> |
1170
1304
  */
1171
1305
  declare const dotenvExpandFromProcessEnv: (value: string | undefined) => string | undefined;
1172
1306
 
1307
+ /**
1308
+ * Dotenv editor types (format-preserving).
1309
+ *
1310
+ * Requirements addressed:
1311
+ * - Provide a format-preserving dotenv edit surface (pure text pipeline + FS adapter).
1312
+ * - Preserve comments/blank lines/unknown lines and separator spacing; support merge vs sync.
1313
+ * - Deterministic target selection across getdotenv `paths` with optional template bootstrap.
1314
+ *
1315
+ * Notes:
1316
+ * - The parser intentionally preserves unknown lines verbatim rather than rejecting them.
1317
+ * - The editor focuses on `.env`-style KEY=VALUE lines; anything not recognized is preserved as raw text.
1318
+ *
1319
+ * @packageDocumentation
1320
+ */
1321
+ /**
1322
+ * EOL policy for rendering a dotenv document.
1323
+ *
1324
+ * - `preserve`: preserve existing EOLs when possible; inserted line breaks use the detected file EOL.
1325
+ * - `lf`: normalize all line breaks to `\n`.
1326
+ * - `crlf`: normalize all line breaks to `\r\n`.
1327
+ *
1328
+ * @public
1329
+ */
1330
+ type DotenvEolMode = 'preserve' | 'lf' | 'crlf';
1331
+ /**
1332
+ * Editing mode for dotenv updates.
1333
+ *
1334
+ * - `merge` (default): update/add only the provided keys; do not delete unrelated keys.
1335
+ * - `sync`: delete assignment/bare-key lines for keys not present in the update map.
1336
+ *
1337
+ * @public
1338
+ */
1339
+ type DotenvEditMode = 'merge' | 'sync';
1340
+ /**
1341
+ * Strategy for handling duplicate key occurrences.
1342
+ *
1343
+ * - `all` (default): update/delete all occurrences.
1344
+ * - `first`: update/delete only the first occurrence.
1345
+ * - `last`: update/delete only the last occurrence.
1346
+ *
1347
+ * @public
1348
+ */
1349
+ type DotenvDuplicateKeyStrategy = 'all' | 'first' | 'last';
1350
+ /**
1351
+ * Behavior when an update map contains a key with value `undefined`.
1352
+ *
1353
+ * - `skip` (default): do not modify existing occurrences; do not add a new key.
1354
+ *
1355
+ * @public
1356
+ */
1357
+ type DotenvUndefinedBehavior = 'skip';
1358
+ /**
1359
+ * Behavior when an update map contains a key with value `null`.
1360
+ *
1361
+ * - `delete` (default): delete matching assignment/bare-key lines (subject to duplicate strategy).
1362
+ *
1363
+ * @public
1364
+ */
1365
+ type DotenvNullBehavior = 'delete';
1366
+ /**
1367
+ * Update-map value types supported by the editor.
1368
+ *
1369
+ * Notes:
1370
+ * - Objects/arrays are stringified with `JSON.stringify` before writing.
1371
+ * - `null` deletes (by default).
1372
+ * - `undefined` skips (by default).
1373
+ *
1374
+ * @public
1375
+ */
1376
+ type DotenvUpdateValue = string | number | boolean | null | undefined | Record<string, unknown> | Array<unknown>;
1377
+ /**
1378
+ * Update map keyed by dotenv variable name.
1379
+ *
1380
+ * @public
1381
+ */
1382
+ type DotenvUpdateMap = Record<string, DotenvUpdateValue>;
1383
+ /**
1384
+ * Options for editing a dotenv document in memory.
1385
+ *
1386
+ * @public
1387
+ */
1388
+ interface DotenvEditOptions {
1389
+ /**
1390
+ * Editing mode (`merge` vs `sync`).
1391
+ *
1392
+ * @defaultValue `'merge'`
1393
+ */
1394
+ mode?: DotenvEditMode;
1395
+ /**
1396
+ * Duplicate key handling strategy.
1397
+ *
1398
+ * @defaultValue `'all'`
1399
+ */
1400
+ duplicateKeys?: DotenvDuplicateKeyStrategy;
1401
+ /**
1402
+ * `undefined` behavior.
1403
+ *
1404
+ * @defaultValue `'skip'`
1405
+ */
1406
+ undefinedBehavior?: DotenvUndefinedBehavior;
1407
+ /**
1408
+ * `null` behavior.
1409
+ *
1410
+ * @defaultValue `'delete'`
1411
+ */
1412
+ nullBehavior?: DotenvNullBehavior;
1413
+ /**
1414
+ * EOL normalization policy.
1415
+ *
1416
+ * @defaultValue `'preserve'`
1417
+ */
1418
+ eol?: DotenvEolMode;
1419
+ /**
1420
+ * Separator to use when converting a bare-key placeholder into an assignment.
1421
+ *
1422
+ * @defaultValue `'='`
1423
+ */
1424
+ defaultSeparator?: string;
1425
+ }
1426
+ /**
1427
+ * A raw, unrecognized segment of a dotenv file. Preserved verbatim.
1428
+ *
1429
+ * @public
1430
+ */
1431
+ interface DotenvRawSegment {
1432
+ /**
1433
+ * Segment kind.
1434
+ */
1435
+ kind: 'raw';
1436
+ /**
1437
+ * Raw text (including any EOL tokens) preserved verbatim.
1438
+ */
1439
+ raw: string;
1440
+ }
1441
+ /**
1442
+ * Common fields for key-bearing segments (assignment or bare-key placeholder).
1443
+ *
1444
+ * @public
1445
+ */
1446
+ interface DotenvKeySegmentBase {
1447
+ /**
1448
+ * Raw text for the segment, including EOL tokens.
1449
+ */
1450
+ raw: string;
1451
+ /**
1452
+ * The parsed key name (e.g., `APP_SETTING`).
1453
+ */
1454
+ key: string;
1455
+ /**
1456
+ * Prefix before the key (indentation and optional `export` token).
1457
+ * Preserved verbatim.
1458
+ */
1459
+ prefix: string;
1460
+ /**
1461
+ * Trailing EOL token for the last physical line of this segment.
1462
+ * For segments that end at EOF without a trailing newline, this is `''`.
1463
+ */
1464
+ eol: '' | '\n' | '\r\n';
1465
+ }
1466
+ /**
1467
+ * A KEY=VALUE assignment segment.
1468
+ *
1469
+ * Supports single-line and multi-line quoted values (double/single quotes).
1470
+ *
1471
+ * @public
1472
+ */
1473
+ interface DotenvAssignmentSegment extends DotenvKeySegmentBase {
1474
+ /**
1475
+ * Segment kind.
1476
+ */
1477
+ kind: 'assignment';
1478
+ /**
1479
+ * Separator including surrounding whitespace (e.g., `" = "` or `"="`).
1480
+ */
1481
+ separator: string;
1482
+ /**
1483
+ * Whitespace between separator and the start of the value token (preserved).
1484
+ */
1485
+ valuePadding: string;
1486
+ /**
1487
+ * Quote style when the value was quoted in the source.
1488
+ */
1489
+ quote: '"' | "'" | null;
1490
+ /**
1491
+ * Value content (without surrounding quotes).
1492
+ *
1493
+ * Note: multiline values use `\n` internally regardless of file EOL.
1494
+ */
1495
+ value: string;
1496
+ /**
1497
+ * Suffix after the value token on the closing line (typically inline comment + spaces).
1498
+ * Preserved verbatim.
1499
+ */
1500
+ suffix: string;
1501
+ }
1502
+ /**
1503
+ * A bare-key placeholder segment (e.g., `KEY` or `KEY # comment`).
1504
+ *
1505
+ * @public
1506
+ */
1507
+ interface DotenvBareKeySegment extends DotenvKeySegmentBase {
1508
+ /**
1509
+ * Segment kind.
1510
+ */
1511
+ kind: 'bare';
1512
+ /**
1513
+ * Trailing text after the key (spaces and/or inline comment).
1514
+ * Preserved verbatim.
1515
+ */
1516
+ suffix: string;
1517
+ }
1518
+ /**
1519
+ * A parsed dotenv segment.
1520
+ *
1521
+ * @public
1522
+ */
1523
+ type DotenvSegment = DotenvRawSegment | DotenvAssignmentSegment | DotenvBareKeySegment;
1524
+ /**
1525
+ * A parsed dotenv document suitable for format-preserving edits.
1526
+ *
1527
+ * @public
1528
+ */
1529
+ interface DotenvDocument {
1530
+ /**
1531
+ * Detected file EOL (used for inserted line breaks when preserving).
1532
+ */
1533
+ fileEol: '\n' | '\r\n';
1534
+ /**
1535
+ * Whether the original file ended with a trailing newline.
1536
+ */
1537
+ trailingNewline: boolean;
1538
+ /**
1539
+ * Ordered segments comprising the file.
1540
+ */
1541
+ segments: DotenvSegment[];
1542
+ }
1543
+ /**
1544
+ * Minimal filesystem port used by the FS-level editor adapter.
1545
+ *
1546
+ * @public
1547
+ */
1548
+ interface DotenvFs {
1549
+ /**
1550
+ * Return true when a path exists.
1551
+ *
1552
+ * @param p - Path to check.
1553
+ */
1554
+ pathExists(p: string): Promise<boolean>;
1555
+ /**
1556
+ * Read a UTF-8 text file.
1557
+ *
1558
+ * @param p - Path to read.
1559
+ */
1560
+ readFile(p: string): Promise<string>;
1561
+ /**
1562
+ * Write a UTF-8 text file.
1563
+ *
1564
+ * @param p - Path to write.
1565
+ * @param contents - File contents.
1566
+ */
1567
+ writeFile(p: string, contents: string): Promise<void>;
1568
+ /**
1569
+ * Copy a file.
1570
+ *
1571
+ * @param src - Source path.
1572
+ * @param dest - Destination path.
1573
+ */
1574
+ copyFile(src: string, dest: string): Promise<void>;
1575
+ }
1576
+ /**
1577
+ * Dotenv target scope selector for FS-level editing.
1578
+ *
1579
+ * @public
1580
+ */
1581
+ type DotenvTargetScope = 'global' | 'env';
1582
+ /**
1583
+ * Dotenv target privacy selector for FS-level editing.
1584
+ *
1585
+ * @public
1586
+ */
1587
+ type DotenvTargetPrivacy = 'public' | 'private';
1588
+ /**
1589
+ * Path search order for selecting the first target match under `paths`.
1590
+ *
1591
+ * @public
1592
+ */
1593
+ type DotenvPathSearchOrder = 'reverse' | 'forward';
1594
+ /**
1595
+ * Options for resolving and editing a dotenv file in a multi-path cascade.
1596
+ *
1597
+ * @public
1598
+ */
1599
+ interface EditDotenvFileOptions extends DotenvEditOptions {
1600
+ /**
1601
+ * Search paths (directories) to locate the target dotenv file.
1602
+ */
1603
+ paths: string[];
1604
+ /**
1605
+ * Base dotenv filename token.
1606
+ *
1607
+ * @defaultValue `'.env'`
1608
+ */
1609
+ dotenvToken?: string;
1610
+ /**
1611
+ * Private token used for private dotenv files.
1612
+ *
1613
+ * @defaultValue `'local'`
1614
+ */
1615
+ privateToken?: string;
1616
+ /**
1617
+ * Selected environment name (used when `scope` is `env`).
1618
+ */
1619
+ env?: string;
1620
+ /**
1621
+ * Default environment name used when `env` is not provided.
1622
+ */
1623
+ defaultEnv?: string;
1624
+ /**
1625
+ * Scope axis (global vs env-specific).
1626
+ */
1627
+ scope: DotenvTargetScope;
1628
+ /**
1629
+ * Privacy axis (public vs private).
1630
+ */
1631
+ privacy: DotenvTargetPrivacy;
1632
+ /**
1633
+ * Path search order.
1634
+ *
1635
+ * @defaultValue `'reverse'`
1636
+ */
1637
+ searchOrder?: DotenvPathSearchOrder;
1638
+ /**
1639
+ * Template extension used for bootstrap.
1640
+ *
1641
+ * When a target does not exist anywhere under `paths`, but a template exists
1642
+ * (e.g. `.env.local.template`), the template will be copied to the target
1643
+ * path and then edited in place.
1644
+ *
1645
+ * @defaultValue `'template'`
1646
+ */
1647
+ templateExtension?: string;
1648
+ /**
1649
+ * Optional filesystem port override (defaults to a Node FS adapter).
1650
+ */
1651
+ fs?: DotenvFs;
1652
+ }
1653
+ /**
1654
+ * Result of a successful FS-level dotenv edit.
1655
+ *
1656
+ * @public
1657
+ */
1658
+ interface EditDotenvFileResult {
1659
+ /**
1660
+ * Absolute path to the edited dotenv file.
1661
+ */
1662
+ path: string;
1663
+ /**
1664
+ * Whether the file was created from a template during this operation.
1665
+ */
1666
+ createdFromTemplate: boolean;
1667
+ /**
1668
+ * Whether the resulting file content differed from the prior content.
1669
+ */
1670
+ changed: boolean;
1671
+ }
1672
+
1673
+ /**
1674
+ * Apply edits to a parsed dotenv document while preserving formatting.
1675
+ *
1676
+ * Requirements addressed:
1677
+ * - Mode: merge vs sync.
1678
+ * - Duplicate key strategy: all/first/last.
1679
+ * - undefined behavior: skip (default).
1680
+ * - null behavior: delete (default).
1681
+ * - Quote preservation where safe; upgrade quoting when required (multiline, whitespace safety, inline comment safety).
1682
+ *
1683
+ * @packageDocumentation
1684
+ */
1685
+
1686
+ /**
1687
+ * Apply a set of key/value updates to a parsed dotenv document.
1688
+ *
1689
+ * @param doc - Parsed dotenv document.
1690
+ * @param updates - Key/value update map.
1691
+ * @param opts - Editing options.
1692
+ * @returns A new {@link DotenvDocument} with edits applied.
1693
+ *
1694
+ * @public
1695
+ */
1696
+ declare function applyDotenvEdits(doc: DotenvDocument, updates: DotenvUpdateMap, opts?: {
1697
+ mode?: DotenvEditMode;
1698
+ duplicateKeys?: DotenvDuplicateKeyStrategy;
1699
+ undefinedBehavior?: DotenvUndefinedBehavior;
1700
+ nullBehavior?: DotenvNullBehavior;
1701
+ defaultSeparator?: string;
1702
+ }): DotenvDocument;
1703
+
1704
+ /**
1705
+ * FS-level dotenv editor adapter (target resolution + template bootstrap).
1706
+ *
1707
+ * Requirements addressed:
1708
+ * - Deterministic target selection across getdotenv `paths` only.
1709
+ * - Scope axis (global|env) × privacy axis (public|private).
1710
+ * - Template bootstrap: copy `<target>.<templateExtension>` to `<target>` when needed.
1711
+ * - Edit in place while preserving formatting via the pure text editor.
1712
+ *
1713
+ * @packageDocumentation
1714
+ */
1715
+
1716
+ /**
1717
+ * Edit a dotenv file selected by scope/privacy across a list of search paths.
1718
+ *
1719
+ * @param updates - Update map of keys to values.
1720
+ * @param options - Target selection options + edit options.
1721
+ * @returns An {@link EditDotenvFileResult}.
1722
+ *
1723
+ * @public
1724
+ */
1725
+ declare function editDotenvFile(updates: DotenvUpdateMap, options: EditDotenvFileOptions): Promise<EditDotenvFileResult>;
1726
+
1727
+ /**
1728
+ * High-level convenience API for editing dotenv text in memory.
1729
+ *
1730
+ * Requirements addressed:
1731
+ * - Pure/text layer: parse → apply edits → render (no FS).
1732
+ *
1733
+ * @packageDocumentation
1734
+ */
1735
+
1736
+ /**
1737
+ * Edit dotenv text with format preservation.
1738
+ *
1739
+ * @param text - Existing dotenv text.
1740
+ * @param updates - Update map of keys to values.
1741
+ * @param options - Edit options (merge vs sync, duplicates, null/undefined behavior, EOL policy).
1742
+ * @returns Updated dotenv text.
1743
+ *
1744
+ * @public
1745
+ */
1746
+ declare function editDotenvText(text: string, updates: DotenvUpdateMap, options?: DotenvEditOptions): string;
1747
+
1748
+ /**
1749
+ * Parse a dotenv file into a format-preserving document model.
1750
+ *
1751
+ * Requirements addressed:
1752
+ * - Preserve comments, blank lines, ordering, and unknown lines verbatim.
1753
+ * - Preserve separator spacing around `=`.
1754
+ * - Support multiline quoted values (double/single quotes) by grouping physical lines.
1755
+ *
1756
+ * @packageDocumentation
1757
+ */
1758
+
1759
+ /**
1760
+ * Parse dotenv text into a document model that preserves formatting.
1761
+ *
1762
+ * @param text - Dotenv file contents as UTF-8 text.
1763
+ * @returns A parsed {@link DotenvDocument}.
1764
+ *
1765
+ * @public
1766
+ */
1767
+ declare function parseDotenvDocument(text: string): DotenvDocument;
1768
+
1769
+ /**
1770
+ * Render a parsed dotenv document back to text.
1771
+ *
1772
+ * Requirements addressed:
1773
+ * - Preserve existing EOLs by default; support forcing LF/CRLF.
1774
+ * - Preserve trailing newline presence/absence.
1775
+ *
1776
+ * @packageDocumentation
1777
+ */
1778
+
1779
+ /**
1780
+ * Render a {@link DotenvDocument} to text.
1781
+ *
1782
+ * @param doc - Document to render.
1783
+ * @param eolMode - EOL policy (`preserve` | `lf` | `crlf`).
1784
+ * @returns Rendered dotenv text.
1785
+ *
1786
+ * @public
1787
+ */
1788
+ declare function renderDotenvDocument(doc: DotenvDocument, eolMode?: DotenvEolMode): string;
1789
+
1173
1790
  /**
1174
1791
  * Deep interpolation utility for string leaves.
1175
1792
  * - Expands string values using dotenv-style expansion against the provided envRef.
@@ -1192,5 +1809,5 @@ declare const dotenvExpandFromProcessEnv: (value: string | undefined) => string
1192
1809
  */
1193
1810
  declare const interpolateDeep: <T>(value: T, envRef: ProcessEnv) => T;
1194
1811
 
1195
- export { GetDotenvCli, baseRootOptionDefaults, buildSpawnEnv, createCli, defineDynamic, defineGetDotenvConfig, definePlugin, defineScripts, dotenvExpand, dotenvExpandAll, dotenvExpandFromProcessEnv, getDotenv, getDotenvCliOptions2Options, groupPlugins, interpolateDeep, maybeWarnEntropy, readMergedOptions, redactDisplay, redactObject, shouldCapture, traceChildEnv };
1196
- export type { CreateCliOptions, DynamicFn, DynamicMap, EntropyOptions, GetDotenvCliOptions, GetDotenvCliPlugin, GetDotenvCliPublic, GetDotenvConfig, GetDotenvDynamic, GetDotenvOptions, InferGetDotenvVarsFromConfig, InferPluginConfig, PluginWithInstanceHelpers, ProcessEnv, RedactOptions, ScriptsTable, TraceChildEnvOptions };
1812
+ export { GetDotenvCli, applyDotenvEdits, baseRootOptionDefaults, buildSpawnEnv, createCli, defineDynamic, defineGetDotenvConfig, definePlugin, defineScripts, dotenvExpand, dotenvExpandAll, dotenvExpandFromProcessEnv, editDotenvFile, editDotenvText, getDotenv, getDotenvCliOptions2Options, groupPlugins, interpolateDeep, maybeWarnEntropy, parseDotenvDocument, readMergedOptions, redactDisplay, redactObject, renderDotenvDocument, shouldCapture, traceChildEnv };
1813
+ export type { CreateCliOptions, DotenvAssignmentSegment, DotenvBareKeySegment, DotenvDocument, DotenvDuplicateKeyStrategy, DotenvEditMode, DotenvEditOptions, DotenvEolMode, DotenvFs, DotenvPathSearchOrder, DotenvSegment, DotenvTargetPrivacy, DotenvTargetScope, DotenvUpdateMap, DotenvUpdateValue, DynamicFn, DynamicMap, EditDotenvFileOptions, EditDotenvFileResult, EntropyOptions, GetDotenvCliOptions, GetDotenvCliPlugin, GetDotenvCliPublic, GetDotenvConfig, GetDotenvDynamic, GetDotenvOptions, InferGetDotenvVarsFromConfig, InferPluginConfig, PluginWithInstanceHelpers, ProcessEnv, RedactOptions, ScriptsTable, TraceChildEnvOptions };