( names: ReadonlyArray<string>, optionsOrExecFile?: WindowsEnvironmentProbeOptions | ExecFileSyncLike, maybeExecFile?: ExecFileSyncLike, )
| 356 | execFile?: ExecFileSyncLike, |
| 357 | ): Partial<Record<string, string>>; |
| 358 | export function readEnvironmentFromWindowsShell( |
| 359 | names: ReadonlyArray<string>, |
| 360 | optionsOrExecFile?: WindowsEnvironmentProbeOptions | ExecFileSyncLike, |
| 361 | maybeExecFile?: ExecFileSyncLike, |
| 362 | ): Partial<Record<string, string>> { |
| 363 | if (names.length === 0) { |
| 364 | return {}; |
| 365 | } |
| 366 | |
| 367 | const options = |
| 368 | typeof optionsOrExecFile === "function" |
| 369 | ? ({} satisfies WindowsEnvironmentProbeOptions) |
| 370 | : (optionsOrExecFile ?? {}); |
| 371 | const execFile: ExecFileSyncLike = |
| 372 | typeof optionsOrExecFile === "function" |
| 373 | ? optionsOrExecFile |
| 374 | : (maybeExecFile ?? (NodeChildProcess.execFileSync as ExecFileSyncLike)); |
| 375 | const command = buildWindowsEnvironmentCaptureCommand(names); |
| 376 | const args = [ |
| 377 | "-NoLogo", |
| 378 | ...(options.loadProfile ? ([] as const) : (["-NoProfile"] as const)), |
| 379 | "-NonInteractive", |
| 380 | "-Command", |
| 381 | command, |
| 382 | ]; |
| 383 | for (const shell of WINDOWS_SHELL_CANDIDATES) { |
| 384 | try { |
| 385 | const output = execFile(shell, args, { encoding: "utf8", timeout: 5000 }); |
| 386 | |
| 387 | const environment: Partial<Record<string, string>> = {}; |
| 388 | for (const name of names) { |
| 389 | const value = extractEnvironmentValue(output, name); |
| 390 | if (value !== undefined) { |
| 391 | environment[name] = value; |
| 392 | } |
| 393 | } |
| 394 | return environment; |
| 395 | } catch { |
| 396 | continue; |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | return {}; |
| 401 | } |
| 402 | |
| 403 | function stripWrappingQuotes(value: string): string { |
| 404 | return value.replace(/^"+|"+$/g, ""); |
no test coverage detected