@karmaniverous/get-dotenv 5.0.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -194,6 +194,48 @@ const runCommand = async (command, shell, opts) => {
194
194
  }
195
195
  };
196
196
 
197
+ const dropUndefined = (bag) => Object.fromEntries(Object.entries(bag).filter((e) => typeof e[1] === 'string'));
198
+ /** Build a sanitized env for child processes from base + overlay. */
199
+ const buildSpawnEnv = (base, overlay) => {
200
+ const raw = {
201
+ ...(base ?? {}),
202
+ ...(overlay ?? {}),
203
+ };
204
+ // Drop undefined first
205
+ const entries = Object.entries(dropUndefined(raw));
206
+ if (process.platform === 'win32') {
207
+ // Windows: keys are case-insensitive; collapse duplicates
208
+ const byLower = new Map();
209
+ for (const [k, v] of entries) {
210
+ byLower.set(k.toLowerCase(), [k, v]); // last wins; preserve latest casing
211
+ }
212
+ const out = {};
213
+ for (const [, [k, v]] of byLower)
214
+ out[k] = v;
215
+ // HOME fallback from USERPROFILE (common expectation)
216
+ if (!Object.prototype.hasOwnProperty.call(out, 'HOME')) {
217
+ const up = out['USERPROFILE'];
218
+ if (typeof up === 'string' && up.length > 0)
219
+ out['HOME'] = up;
220
+ }
221
+ // Normalize TMP/TEMP coherence (pick any present; reflect to both)
222
+ const tmp = out['TMP'] ?? out['TEMP'];
223
+ if (typeof tmp === 'string' && tmp.length > 0) {
224
+ out['TMP'] = tmp;
225
+ out['TEMP'] = tmp;
226
+ }
227
+ return out;
228
+ }
229
+ // POSIX: keep keys as-is
230
+ const out = Object.fromEntries(entries);
231
+ // Ensure TMPDIR exists when any temp key is present (best-effort)
232
+ const tmpdir = out['TMPDIR'] ?? out['TMP'] ?? out['TEMP'];
233
+ if (typeof tmpdir === 'string' && tmpdir.length > 0) {
234
+ out['TMPDIR'] = tmpdir;
235
+ }
236
+ return out;
237
+ };
238
+
197
239
  /**
198
240
  * Define a GetDotenv CLI plugin with compositional helpers.
199
241
  *
@@ -548,7 +590,7 @@ const awsPlugin = () => definePlugin({
548
590
  const shellSetting = resolveShell(rootOpts?.scripts, 'aws', rootOpts?.shell);
549
591
  const ctxDotenv = (ctx?.dotenv ?? {});
550
592
  const exit = await runCommand(argv, shellSetting, {
551
- env: { ...process.env, ...ctxDotenv },
593
+ env: buildSpawnEnv(process.env, ctxDotenv),
552
594
  stdio: capture ? 'pipe' : 'inherit',
553
595
  });
554
596
  // Deterministic termination (suppressed under tests)
@@ -95,6 +95,93 @@ interface GetDotenvOptions {
95
95
  useConfigLoader?: boolean;
96
96
  }
97
97
 
98
+ type Scripts = Record<string, string | {
99
+ cmd: string;
100
+ shell?: string | boolean;
101
+ }>;
102
+ /**
103
+ * Options passed programmatically to `getDotenvCli`.
104
+ */
105
+ interface GetDotenvCliOptions extends Omit<GetDotenvOptions, 'paths' | 'vars'> {
106
+ /**
107
+ * Logs CLI internals when true.
108
+ */
109
+ debug?: boolean;
110
+ /**
111
+ * Strict mode: fail the run when env validation issues are detected
112
+ * (schema or requiredKeys). Warns by default when false or unset.
113
+ */
114
+ strict?: boolean;
115
+ /**
116
+ * Redaction (presentation): mask secret-like values in logs/trace.
117
+ */
118
+ redact?: boolean;
119
+ /**
120
+ * Entropy warnings (presentation): emit once-per-key warnings for high-entropy values.
121
+ */
122
+ warnEntropy?: boolean;
123
+ entropyThreshold?: number;
124
+ entropyMinLength?: number;
125
+ entropyWhitelist?: string[];
126
+ redactPatterns?: string[];
127
+ /**
128
+ * When true, capture child stdout/stderr and re-emit after completion.
129
+ * Useful for tests/CI. Default behavior is streaming via stdio: 'inherit'.
130
+ */
131
+ capture?: boolean;
132
+ /**
133
+ * A delimited string of paths to dotenv files.
134
+ */
135
+ paths?: string;
136
+ /**
137
+ * A delimiter string with which to split `paths`. Only used if
138
+ * `pathsDelimiterPattern` is not provided.
139
+ */
140
+ pathsDelimiter?: string;
141
+ /**
142
+ * A regular expression pattern with which to split `paths`. Supersedes
143
+ * `pathsDelimiter`.
144
+ */
145
+ pathsDelimiterPattern?: string;
146
+ /**
147
+ * Scripts that can be executed from the CLI, either individually or via the batch subcommand.
148
+ */
149
+ scripts?: Scripts;
150
+ /**
151
+ * Determines how commands and scripts are executed. If `false` or
152
+ * `undefined`, commands are executed as plain Javascript using the default
153
+ * execa parser. If `true`, commands are executed using the default OS shell
154
+ * parser. Otherwise the user may provide a specific shell string (e.g.
155
+ * `/bin/bash`)
156
+ */
157
+ shell?: string | boolean;
158
+ /**
159
+ * A delimited string of key-value pairs declaratively specifying variables &
160
+ * values to be loaded in addition to any dotenv files.
161
+ */
162
+ vars?: string;
163
+ /**
164
+ * A string with which to split keys from values in `vars`. Only used if
165
+ * `varsDelimiterPattern` is not provided.
166
+ */
167
+ varsAssignor?: string;
168
+ /**
169
+ * A regular expression pattern with which to split variable names from values
170
+ * in `vars`. Supersedes `varsAssignor`.
171
+ */
172
+ varsAssignorPattern?: string;
173
+ /**
174
+ * A string with which to split `vars` into key-value pairs. Only used if
175
+ * `varsDelimiterPattern` is not provided.
176
+ */
177
+ varsDelimiter?: string;
178
+ /**
179
+ * A regular expression pattern with which to split `vars` into key-value
180
+ * pairs. Supersedes `varsDelimiter`.
181
+ */
182
+ varsDelimiterPattern?: string;
183
+ }
184
+
98
185
  /** * Per-invocation context shared with plugins and actions. */
99
186
  type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
100
187
  optionsResolved: TOptions;
@@ -102,6 +189,7 @@ type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
102
189
  plugins?: Record<string, unknown>;
103
190
  pluginConfigs?: Record<string, unknown>;
104
191
  };
192
+ declare const HELP_HEADER_SYMBOL: unique symbol;
105
193
  /**
106
194
  * Plugin-first CLI host for get-dotenv. Extends Commander.Command.
107
195
  *
@@ -114,10 +202,13 @@ type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
114
202
  * NOTE: This host is additive and does not alter the legacy CLI.
115
203
  */
116
204
  declare class GetDotenvCli<TOptions extends GetDotenvOptions = GetDotenvOptions> extends Command {
205
+ #private;
117
206
  /** Registered top-level plugins (composition happens via .use()) */
118
207
  private _plugins;
119
208
  /** One-time installation guard */
120
209
  private _installed;
210
+ /** Optional header line to prepend in help output */
211
+ private [HELP_HEADER_SYMBOL];
121
212
  constructor(alias?: string);
122
213
  /**
123
214
  * Resolve options (strict) and compute dotenv context. * Stores the context on the instance under a symbol.
@@ -127,9 +218,33 @@ declare class GetDotenvCli<TOptions extends GetDotenvOptions = GetDotenvOptions>
127
218
  * Retrieve the current invocation context (if any).
128
219
  */
129
220
  getCtx(): GetDotenvCliCtx<TOptions> | undefined;
221
+ /**
222
+ * Retrieve the merged root CLI options bag (if set by passOptions()).
223
+ * Downstream-safe: no generics required.
224
+ */
225
+ getOptions(): GetDotenvCliOptions | undefined;
226
+ /** Internal: set the merged root options bag for this run. */
227
+ _setOptionsBag(bag: GetDotenvCliOptions): void;
130
228
  /** * Convenience helper to create a namespaced subcommand.
131
229
  */
132
230
  ns(name: string): Command;
231
+ /**
232
+ * Tag options added during the provided callback as 'app' for grouped help.
233
+ * Allows downstream apps to demarcate their root-level options.
234
+ */
235
+ tagAppOptions<T>(fn: (root: Command) => T): T;
236
+ /**
237
+ * Branding helper: set CLI name/description/version and optional help header.
238
+ * If version is omitted and importMetaUrl is provided, attempts to read the
239
+ * nearest package.json version (best-effort; non-fatal on failure).
240
+ */
241
+ brand(args: {
242
+ name?: string;
243
+ description?: string;
244
+ version?: string;
245
+ importMetaUrl?: string;
246
+ helpHeader?: string;
247
+ }): Promise<this>;
133
248
  /**
134
249
  * Register a plugin for installation (parent level).
135
250
  * Installation occurs on first resolveAndLoad() (or explicit install()).
@@ -95,6 +95,93 @@ interface GetDotenvOptions {
95
95
  useConfigLoader?: boolean;
96
96
  }
97
97
 
98
+ type Scripts = Record<string, string | {
99
+ cmd: string;
100
+ shell?: string | boolean;
101
+ }>;
102
+ /**
103
+ * Options passed programmatically to `getDotenvCli`.
104
+ */
105
+ interface GetDotenvCliOptions extends Omit<GetDotenvOptions, 'paths' | 'vars'> {
106
+ /**
107
+ * Logs CLI internals when true.
108
+ */
109
+ debug?: boolean;
110
+ /**
111
+ * Strict mode: fail the run when env validation issues are detected
112
+ * (schema or requiredKeys). Warns by default when false or unset.
113
+ */
114
+ strict?: boolean;
115
+ /**
116
+ * Redaction (presentation): mask secret-like values in logs/trace.
117
+ */
118
+ redact?: boolean;
119
+ /**
120
+ * Entropy warnings (presentation): emit once-per-key warnings for high-entropy values.
121
+ */
122
+ warnEntropy?: boolean;
123
+ entropyThreshold?: number;
124
+ entropyMinLength?: number;
125
+ entropyWhitelist?: string[];
126
+ redactPatterns?: string[];
127
+ /**
128
+ * When true, capture child stdout/stderr and re-emit after completion.
129
+ * Useful for tests/CI. Default behavior is streaming via stdio: 'inherit'.
130
+ */
131
+ capture?: boolean;
132
+ /**
133
+ * A delimited string of paths to dotenv files.
134
+ */
135
+ paths?: string;
136
+ /**
137
+ * A delimiter string with which to split `paths`. Only used if
138
+ * `pathsDelimiterPattern` is not provided.
139
+ */
140
+ pathsDelimiter?: string;
141
+ /**
142
+ * A regular expression pattern with which to split `paths`. Supersedes
143
+ * `pathsDelimiter`.
144
+ */
145
+ pathsDelimiterPattern?: string;
146
+ /**
147
+ * Scripts that can be executed from the CLI, either individually or via the batch subcommand.
148
+ */
149
+ scripts?: Scripts;
150
+ /**
151
+ * Determines how commands and scripts are executed. If `false` or
152
+ * `undefined`, commands are executed as plain Javascript using the default
153
+ * execa parser. If `true`, commands are executed using the default OS shell
154
+ * parser. Otherwise the user may provide a specific shell string (e.g.
155
+ * `/bin/bash`)
156
+ */
157
+ shell?: string | boolean;
158
+ /**
159
+ * A delimited string of key-value pairs declaratively specifying variables &
160
+ * values to be loaded in addition to any dotenv files.
161
+ */
162
+ vars?: string;
163
+ /**
164
+ * A string with which to split keys from values in `vars`. Only used if
165
+ * `varsDelimiterPattern` is not provided.
166
+ */
167
+ varsAssignor?: string;
168
+ /**
169
+ * A regular expression pattern with which to split variable names from values
170
+ * in `vars`. Supersedes `varsAssignor`.
171
+ */
172
+ varsAssignorPattern?: string;
173
+ /**
174
+ * A string with which to split `vars` into key-value pairs. Only used if
175
+ * `varsDelimiterPattern` is not provided.
176
+ */
177
+ varsDelimiter?: string;
178
+ /**
179
+ * A regular expression pattern with which to split `vars` into key-value
180
+ * pairs. Supersedes `varsDelimiter`.
181
+ */
182
+ varsDelimiterPattern?: string;
183
+ }
184
+
98
185
  /** * Per-invocation context shared with plugins and actions. */
99
186
  type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
100
187
  optionsResolved: TOptions;
@@ -102,6 +189,7 @@ type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
102
189
  plugins?: Record<string, unknown>;
103
190
  pluginConfigs?: Record<string, unknown>;
104
191
  };
192
+ declare const HELP_HEADER_SYMBOL: unique symbol;
105
193
  /**
106
194
  * Plugin-first CLI host for get-dotenv. Extends Commander.Command.
107
195
  *
@@ -114,10 +202,13 @@ type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
114
202
  * NOTE: This host is additive and does not alter the legacy CLI.
115
203
  */
116
204
  declare class GetDotenvCli<TOptions extends GetDotenvOptions = GetDotenvOptions> extends Command {
205
+ #private;
117
206
  /** Registered top-level plugins (composition happens via .use()) */
118
207
  private _plugins;
119
208
  /** One-time installation guard */
120
209
  private _installed;
210
+ /** Optional header line to prepend in help output */
211
+ private [HELP_HEADER_SYMBOL];
121
212
  constructor(alias?: string);
122
213
  /**
123
214
  * Resolve options (strict) and compute dotenv context. * Stores the context on the instance under a symbol.
@@ -127,9 +218,33 @@ declare class GetDotenvCli<TOptions extends GetDotenvOptions = GetDotenvOptions>
127
218
  * Retrieve the current invocation context (if any).
128
219
  */
129
220
  getCtx(): GetDotenvCliCtx<TOptions> | undefined;
221
+ /**
222
+ * Retrieve the merged root CLI options bag (if set by passOptions()).
223
+ * Downstream-safe: no generics required.
224
+ */
225
+ getOptions(): GetDotenvCliOptions | undefined;
226
+ /** Internal: set the merged root options bag for this run. */
227
+ _setOptionsBag(bag: GetDotenvCliOptions): void;
130
228
  /** * Convenience helper to create a namespaced subcommand.
131
229
  */
132
230
  ns(name: string): Command;
231
+ /**
232
+ * Tag options added during the provided callback as 'app' for grouped help.
233
+ * Allows downstream apps to demarcate their root-level options.
234
+ */
235
+ tagAppOptions<T>(fn: (root: Command) => T): T;
236
+ /**
237
+ * Branding helper: set CLI name/description/version and optional help header.
238
+ * If version is omitted and importMetaUrl is provided, attempts to read the
239
+ * nearest package.json version (best-effort; non-fatal on failure).
240
+ */
241
+ brand(args: {
242
+ name?: string;
243
+ description?: string;
244
+ version?: string;
245
+ importMetaUrl?: string;
246
+ helpHeader?: string;
247
+ }): Promise<this>;
133
248
  /**
134
249
  * Register a plugin for installation (parent level).
135
250
  * Installation occurs on first resolveAndLoad() (or explicit install()).
@@ -95,6 +95,93 @@ interface GetDotenvOptions {
95
95
  useConfigLoader?: boolean;
96
96
  }
97
97
 
98
+ type Scripts = Record<string, string | {
99
+ cmd: string;
100
+ shell?: string | boolean;
101
+ }>;
102
+ /**
103
+ * Options passed programmatically to `getDotenvCli`.
104
+ */
105
+ interface GetDotenvCliOptions extends Omit<GetDotenvOptions, 'paths' | 'vars'> {
106
+ /**
107
+ * Logs CLI internals when true.
108
+ */
109
+ debug?: boolean;
110
+ /**
111
+ * Strict mode: fail the run when env validation issues are detected
112
+ * (schema or requiredKeys). Warns by default when false or unset.
113
+ */
114
+ strict?: boolean;
115
+ /**
116
+ * Redaction (presentation): mask secret-like values in logs/trace.
117
+ */
118
+ redact?: boolean;
119
+ /**
120
+ * Entropy warnings (presentation): emit once-per-key warnings for high-entropy values.
121
+ */
122
+ warnEntropy?: boolean;
123
+ entropyThreshold?: number;
124
+ entropyMinLength?: number;
125
+ entropyWhitelist?: string[];
126
+ redactPatterns?: string[];
127
+ /**
128
+ * When true, capture child stdout/stderr and re-emit after completion.
129
+ * Useful for tests/CI. Default behavior is streaming via stdio: 'inherit'.
130
+ */
131
+ capture?: boolean;
132
+ /**
133
+ * A delimited string of paths to dotenv files.
134
+ */
135
+ paths?: string;
136
+ /**
137
+ * A delimiter string with which to split `paths`. Only used if
138
+ * `pathsDelimiterPattern` is not provided.
139
+ */
140
+ pathsDelimiter?: string;
141
+ /**
142
+ * A regular expression pattern with which to split `paths`. Supersedes
143
+ * `pathsDelimiter`.
144
+ */
145
+ pathsDelimiterPattern?: string;
146
+ /**
147
+ * Scripts that can be executed from the CLI, either individually or via the batch subcommand.
148
+ */
149
+ scripts?: Scripts;
150
+ /**
151
+ * Determines how commands and scripts are executed. If `false` or
152
+ * `undefined`, commands are executed as plain Javascript using the default
153
+ * execa parser. If `true`, commands are executed using the default OS shell
154
+ * parser. Otherwise the user may provide a specific shell string (e.g.
155
+ * `/bin/bash`)
156
+ */
157
+ shell?: string | boolean;
158
+ /**
159
+ * A delimited string of key-value pairs declaratively specifying variables &
160
+ * values to be loaded in addition to any dotenv files.
161
+ */
162
+ vars?: string;
163
+ /**
164
+ * A string with which to split keys from values in `vars`. Only used if
165
+ * `varsDelimiterPattern` is not provided.
166
+ */
167
+ varsAssignor?: string;
168
+ /**
169
+ * A regular expression pattern with which to split variable names from values
170
+ * in `vars`. Supersedes `varsAssignor`.
171
+ */
172
+ varsAssignorPattern?: string;
173
+ /**
174
+ * A string with which to split `vars` into key-value pairs. Only used if
175
+ * `varsDelimiterPattern` is not provided.
176
+ */
177
+ varsDelimiter?: string;
178
+ /**
179
+ * A regular expression pattern with which to split `vars` into key-value
180
+ * pairs. Supersedes `varsDelimiter`.
181
+ */
182
+ varsDelimiterPattern?: string;
183
+ }
184
+
98
185
  /** * Per-invocation context shared with plugins and actions. */
99
186
  type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
100
187
  optionsResolved: TOptions;
@@ -102,6 +189,7 @@ type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
102
189
  plugins?: Record<string, unknown>;
103
190
  pluginConfigs?: Record<string, unknown>;
104
191
  };
192
+ declare const HELP_HEADER_SYMBOL: unique symbol;
105
193
  /**
106
194
  * Plugin-first CLI host for get-dotenv. Extends Commander.Command.
107
195
  *
@@ -114,10 +202,13 @@ type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
114
202
  * NOTE: This host is additive and does not alter the legacy CLI.
115
203
  */
116
204
  declare class GetDotenvCli<TOptions extends GetDotenvOptions = GetDotenvOptions> extends Command {
205
+ #private;
117
206
  /** Registered top-level plugins (composition happens via .use()) */
118
207
  private _plugins;
119
208
  /** One-time installation guard */
120
209
  private _installed;
210
+ /** Optional header line to prepend in help output */
211
+ private [HELP_HEADER_SYMBOL];
121
212
  constructor(alias?: string);
122
213
  /**
123
214
  * Resolve options (strict) and compute dotenv context. * Stores the context on the instance under a symbol.
@@ -127,9 +218,33 @@ declare class GetDotenvCli<TOptions extends GetDotenvOptions = GetDotenvOptions>
127
218
  * Retrieve the current invocation context (if any).
128
219
  */
129
220
  getCtx(): GetDotenvCliCtx<TOptions> | undefined;
221
+ /**
222
+ * Retrieve the merged root CLI options bag (if set by passOptions()).
223
+ * Downstream-safe: no generics required.
224
+ */
225
+ getOptions(): GetDotenvCliOptions | undefined;
226
+ /** Internal: set the merged root options bag for this run. */
227
+ _setOptionsBag(bag: GetDotenvCliOptions): void;
130
228
  /** * Convenience helper to create a namespaced subcommand.
131
229
  */
132
230
  ns(name: string): Command;
231
+ /**
232
+ * Tag options added during the provided callback as 'app' for grouped help.
233
+ * Allows downstream apps to demarcate their root-level options.
234
+ */
235
+ tagAppOptions<T>(fn: (root: Command) => T): T;
236
+ /**
237
+ * Branding helper: set CLI name/description/version and optional help header.
238
+ * If version is omitted and importMetaUrl is provided, attempts to read the
239
+ * nearest package.json version (best-effort; non-fatal on failure).
240
+ */
241
+ brand(args: {
242
+ name?: string;
243
+ description?: string;
244
+ version?: string;
245
+ importMetaUrl?: string;
246
+ helpHeader?: string;
247
+ }): Promise<this>;
133
248
  /**
134
249
  * Register a plugin for installation (parent level).
135
250
  * Installation occurs on first resolveAndLoad() (or explicit install()).
@@ -192,6 +192,48 @@ const runCommand = async (command, shell, opts) => {
192
192
  }
193
193
  };
194
194
 
195
+ const dropUndefined = (bag) => Object.fromEntries(Object.entries(bag).filter((e) => typeof e[1] === 'string'));
196
+ /** Build a sanitized env for child processes from base + overlay. */
197
+ const buildSpawnEnv = (base, overlay) => {
198
+ const raw = {
199
+ ...(base ?? {}),
200
+ ...(overlay ?? {}),
201
+ };
202
+ // Drop undefined first
203
+ const entries = Object.entries(dropUndefined(raw));
204
+ if (process.platform === 'win32') {
205
+ // Windows: keys are case-insensitive; collapse duplicates
206
+ const byLower = new Map();
207
+ for (const [k, v] of entries) {
208
+ byLower.set(k.toLowerCase(), [k, v]); // last wins; preserve latest casing
209
+ }
210
+ const out = {};
211
+ for (const [, [k, v]] of byLower)
212
+ out[k] = v;
213
+ // HOME fallback from USERPROFILE (common expectation)
214
+ if (!Object.prototype.hasOwnProperty.call(out, 'HOME')) {
215
+ const up = out['USERPROFILE'];
216
+ if (typeof up === 'string' && up.length > 0)
217
+ out['HOME'] = up;
218
+ }
219
+ // Normalize TMP/TEMP coherence (pick any present; reflect to both)
220
+ const tmp = out['TMP'] ?? out['TEMP'];
221
+ if (typeof tmp === 'string' && tmp.length > 0) {
222
+ out['TMP'] = tmp;
223
+ out['TEMP'] = tmp;
224
+ }
225
+ return out;
226
+ }
227
+ // POSIX: keep keys as-is
228
+ const out = Object.fromEntries(entries);
229
+ // Ensure TMPDIR exists when any temp key is present (best-effort)
230
+ const tmpdir = out['TMPDIR'] ?? out['TMP'] ?? out['TEMP'];
231
+ if (typeof tmpdir === 'string' && tmpdir.length > 0) {
232
+ out['TMPDIR'] = tmpdir;
233
+ }
234
+ return out;
235
+ };
236
+
195
237
  /**
196
238
  * Define a GetDotenv CLI plugin with compositional helpers.
197
239
  *
@@ -546,7 +588,7 @@ const awsPlugin = () => definePlugin({
546
588
  const shellSetting = resolveShell(rootOpts?.scripts, 'aws', rootOpts?.shell);
547
589
  const ctxDotenv = (ctx?.dotenv ?? {});
548
590
  const exit = await runCommand(argv, shellSetting, {
549
- env: { ...process.env, ...ctxDotenv },
591
+ env: buildSpawnEnv(process.env, ctxDotenv),
550
592
  stdio: capture ? 'pipe' : 'inherit',
551
593
  });
552
594
  // Deterministic termination (suppressed under tests)
@@ -165,6 +165,48 @@ const runCommand = async (command, shell, opts) => {
165
165
  }
166
166
  };
167
167
 
168
+ const dropUndefined = (bag) => Object.fromEntries(Object.entries(bag).filter((e) => typeof e[1] === 'string'));
169
+ /** Build a sanitized env for child processes from base + overlay. */
170
+ const buildSpawnEnv = (base, overlay) => {
171
+ const raw = {
172
+ ...(base ?? {}),
173
+ ...(overlay ?? {}),
174
+ };
175
+ // Drop undefined first
176
+ const entries = Object.entries(dropUndefined(raw));
177
+ if (process.platform === 'win32') {
178
+ // Windows: keys are case-insensitive; collapse duplicates
179
+ const byLower = new Map();
180
+ for (const [k, v] of entries) {
181
+ byLower.set(k.toLowerCase(), [k, v]); // last wins; preserve latest casing
182
+ }
183
+ const out = {};
184
+ for (const [, [k, v]] of byLower)
185
+ out[k] = v;
186
+ // HOME fallback from USERPROFILE (common expectation)
187
+ if (!Object.prototype.hasOwnProperty.call(out, 'HOME')) {
188
+ const up = out['USERPROFILE'];
189
+ if (typeof up === 'string' && up.length > 0)
190
+ out['HOME'] = up;
191
+ }
192
+ // Normalize TMP/TEMP coherence (pick any present; reflect to both)
193
+ const tmp = out['TMP'] ?? out['TEMP'];
194
+ if (typeof tmp === 'string' && tmp.length > 0) {
195
+ out['TMP'] = tmp;
196
+ out['TEMP'] = tmp;
197
+ }
198
+ return out;
199
+ }
200
+ // POSIX: keep keys as-is
201
+ const out = Object.fromEntries(entries);
202
+ // Ensure TMPDIR exists when any temp key is present (best-effort)
203
+ const tmpdir = out['TMPDIR'] ?? out['TMP'] ?? out['TEMP'];
204
+ if (typeof tmpdir === 'string' && tmpdir.length > 0) {
205
+ out['TMPDIR'] = tmpdir;
206
+ }
207
+ return out;
208
+ };
209
+
168
210
  const globPaths = async ({ globs, logger, pkgCwd, rootPath, }) => {
169
211
  let cwd = process.cwd();
170
212
  if (pkgCwd) {
@@ -237,14 +279,12 @@ const execShellCommandBatch = async ({ command, getDotenvCliOptions, globs, igno
237
279
  const hasCmd = (typeof command === 'string' && command.length > 0) ||
238
280
  (Array.isArray(command) && command.length > 0);
239
281
  if (hasCmd) {
282
+ const envBag = getDotenvCliOptions !== undefined
283
+ ? { getDotenvCliOptions: JSON.stringify(getDotenvCliOptions) }
284
+ : undefined;
240
285
  await runCommand(command, shell, {
241
286
  cwd: path,
242
- env: {
243
- ...process.env,
244
- getDotenvCliOptions: getDotenvCliOptions
245
- ? JSON.stringify(getDotenvCliOptions)
246
- : undefined,
247
- },
287
+ env: buildSpawnEnv(process.env, envBag),
248
288
  stdio: capture ? 'pipe' : 'inherit',
249
289
  });
250
290
  }