(command, args, options = {})
| 1802 | } |
| 1803 | |
| 1804 | function runBuffer(command, args, options = {}) { |
| 1805 | const startedAt = Date.now(); |
| 1806 | logCommand(command, args); |
| 1807 | const result = spawnSync(command, args, { |
| 1808 | cwd: root, |
| 1809 | encoding: "buffer", |
| 1810 | maxBuffer: options.maxBuffer ?? 16 * 1024 * 1024, |
| 1811 | env: options.env ? { ...process.env, ...options.env } : process.env, |
| 1812 | timeout: options.timeoutMs ?? 120_000, |
| 1813 | }); |
| 1814 | if (result.status !== 0) { |
| 1815 | throw new Error( |
| 1816 | `${command} ${args.join(" ")} failed with ${result.status ?? result.signal}\n${result.stderr?.toString("utf8") ?? ""}\n${result.error?.message ?? ""}`, |
| 1817 | ); |
| 1818 | } |
| 1819 | const elapsedMs = Date.now() - startedAt; |
| 1820 | recordCommandTiming(command, args, elapsedMs); |
| 1821 | if (options.maxElapsedMs && elapsedMs > options.maxElapsedMs) { |
| 1822 | throw new Error( |
| 1823 | `${command} ${args.join(" ")} took ${elapsedMs}ms, above ${options.maxElapsedMs}ms budget`, |
| 1824 | ); |
| 1825 | } |
| 1826 | logCommandResult(command, args, elapsedMs, `<${result.stdout.length} bytes>`); |
| 1827 | return result.stdout; |
| 1828 | } |
| 1829 | |
| 1830 | function recordCommandTiming(command, args, elapsedMs) { |
| 1831 | if (!activeTiming) { |
no test coverage detected