Run a script in Windows PowerShell with `env`.
(script: string, env: NodeJS.ProcessEnv)
| 150 | |
| 151 | /** Run a script in Windows PowerShell with `env`. */ |
| 152 | function powershell(script: string, env: NodeJS.ProcessEnv): Promise<{ code: number; stdout: string; stderr: string }> { |
| 153 | const encoded = Buffer.from(`$ErrorActionPreference='Stop'\n$ProgressPreference='SilentlyContinue'\n${script}`, 'utf16le').toString('base64'); |
| 154 | return new Promise((resolve) => { |
| 155 | execFile( |
| 156 | 'powershell.exe', |
| 157 | ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-EncodedCommand', encoded], |
| 158 | { windowsHide: true, timeout: 120_000, env }, |
| 159 | (err, stdout, stderr) => resolve({ code: err ? (typeof err.code === 'number' ? err.code : 1) : 0, stdout: stdout.trim(), stderr }), |
| 160 | ); |
| 161 | }); |
| 162 | } |
| 163 | |
| 164 | /** A module newer than Windows PowerShell's own, whose one command fails. */ |
| 165 | function standIn(name: string, command: string, message: string): void { |
no test coverage detected