run-gates.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. /**
  2. * Run local and CI quality gates with bounded in-process scheduling.
  3. *
  4. * The gate vocabulary stays in package.json; this runner only decides which
  5. * independent commands can overlap and which commands wait for built artifacts.
  6. */
  7. import { spawn } from 'node:child_process'
  8. import { availableParallelism } from 'node:os'
  9. import { resolve } from 'node:path'
  10. import { performance } from 'node:perf_hooks'
  11. type Mode =
  12. | 'ci-primary'
  13. | 'ci-static'
  14. | 'ci-lint'
  15. | 'ci-coverage'
  16. | 'ci-snapshot'
  17. | 'ci-artifacts'
  18. | 'node-compat'
  19. | 'pre-push'
  20. | 'doc-sync'
  21. type GateStatus = 'pending' | 'running' | 'passed' | 'failed' | 'skipped'
  22. interface Gate {
  23. id: string
  24. label: string
  25. displayCommand: string
  26. command: string
  27. args: string[]
  28. needs?: string[]
  29. env?: Record<string, string | undefined>
  30. input?: string
  31. verify?: (result: GateResult) => Promise<void>
  32. }
  33. interface GateResult {
  34. gate: Gate
  35. status: GateStatus
  36. durationMs: number
  37. stdout: string
  38. stderr: string
  39. output: GateOutputChunk[]
  40. exitCode: number | null
  41. error?: string
  42. }
  43. interface GateOutputChunk {
  44. stream: 'stdout' | 'stderr'
  45. text: string
  46. }
  47. interface RunningGate {
  48. gate: Gate
  49. promise: Promise<GateResult>
  50. }
  51. interface ConcurrencyDefault {
  52. workers: number
  53. source: string
  54. }
  55. const root = resolve(import.meta.dirname, '..')
  56. const mode = parseMode(process.argv[2])
  57. const gates = gatesForMode(mode)
  58. const concurrencyDefault = defaultConcurrency(mode, gates.length)
  59. const concurrencyOverride = process.env.DSH_GATE_CONCURRENCY
  60. const maxConcurrency = concurrencyFromEnv('DSH_GATE_CONCURRENCY', concurrencyDefault.workers)
  61. const verbose = process.env.DSH_GATE_VERBOSE === '1'
  62. const startedAt = performance.now()
  63. const concurrencySource = concurrencyOverride === undefined || concurrencyOverride === ''
  64. ? concurrencyDefault.source
  65. : '$DSH_GATE_CONCURRENCY'
  66. console.log(`run-gates: ${mode} running ${gates.length} gate(s) with ${maxConcurrency} worker(s) from ${concurrencySource}.`)
  67. const results = await runGates(gates, maxConcurrency)
  68. printSummary(results, performance.now() - startedAt)
  69. if (results.some(result => result.status === 'failed' || result.status === 'skipped')) process.exit(1)
  70. function parseMode(raw: string | undefined): Mode {
  71. switch (raw) {
  72. case 'ci-primary':
  73. case 'ci-static':
  74. case 'ci-lint':
  75. case 'ci-coverage':
  76. case 'ci-snapshot':
  77. case 'ci-artifacts':
  78. case 'node-compat':
  79. case 'pre-push':
  80. case 'doc-sync':
  81. return raw
  82. default:
  83. throw new Error(
  84. `run-gates: expected mode ci-primary | ci-static | ci-lint | ci-coverage | ci-snapshot | ci-artifacts | node-compat | pre-push | doc-sync, got ${JSON.stringify(raw)}.`,
  85. )
  86. }
  87. }
  88. function defaultConcurrency(selectedMode: Mode, total: number): ConcurrencyDefault {
  89. const available = availableParallelism()
  90. // Local modes cap workers: several doc gates each build a full ts.Program,
  91. // so an uncapped default on a large host trades wall clock for memory blowups.
  92. const localCap = selectedMode === 'pre-push' || selectedMode === 'doc-sync'
  93. const modeLimit = localCap ? Math.min(4, available) : available
  94. return {
  95. workers: Math.min(total, modeLimit),
  96. source: localCap
  97. ? `${available} available CPU(s), ${selectedMode} cap 4`
  98. : `${available} available CPU(s)`,
  99. }
  100. }
  101. function concurrencyFromEnv(name: string, fallback: number): number {
  102. const raw = process.env[name]
  103. if (raw === undefined || raw === '') return fallback
  104. const parsed = Number.parseInt(raw, 10)
  105. if (!Number.isSafeInteger(parsed) || parsed < 1) {
  106. throw new Error(`run-gates: ${name} must be a positive integer, got ${JSON.stringify(raw)}.`)
  107. }
  108. return parsed
  109. }
  110. function pnpmScript(id: string, script: string, options: Partial<Gate> = {}): Gate {
  111. return {
  112. id,
  113. label: options.label ?? script,
  114. displayCommand: `pnpm run ${script}`,
  115. ...pnpmInvocation(['run', script]),
  116. ...options,
  117. }
  118. }
  119. function pnpmExec(id: string, args: string[], options: Partial<Gate> = {}): Gate {
  120. return {
  121. id,
  122. label: options.label ?? `pnpm exec ${args.join(' ')}`,
  123. displayCommand: `pnpm exec ${args.join(' ')}`,
  124. ...pnpmInvocation(['exec', ...args]),
  125. ...options,
  126. }
  127. }
  128. function pnpmInvocation(args: string[]): Pick<Gate, 'command' | 'args'> {
  129. const entrypoint = process.env.npm_execpath
  130. if (entrypoint === undefined || entrypoint === '') {
  131. throw new Error('run-gates: npm_execpath is unavailable; invoke the runner through a pnpm package script.')
  132. }
  133. // Windows cannot spawn the pnpm.cmd shim directly; the JavaScript entrypoint keeps every host shell-free.
  134. return { command: process.execPath, args: [entrypoint, ...args] }
  135. }
  136. function nodeOptions(...options: string[]): string {
  137. return [process.env.NODE_OPTIONS, ...options].filter(option => option !== undefined && option !== '').join(' ')
  138. }
  139. function gatesForMode(selected: Mode): Gate[] {
  140. switch (selected) {
  141. case 'ci-primary':
  142. return ciPrimaryGates()
  143. case 'ci-static':
  144. return ciStaticGates()
  145. case 'ci-lint':
  146. return [
  147. lintGate(),
  148. pnpmScript('duplication', 'duplication'),
  149. ]
  150. case 'ci-coverage':
  151. return [
  152. pnpmScript('build', 'build'),
  153. coverageGate(),
  154. ]
  155. case 'ci-snapshot':
  156. return [
  157. pnpmScript('build', 'build'),
  158. snapshotGate(),
  159. ]
  160. case 'ci-artifacts':
  161. return ciArtifactGates()
  162. case 'node-compat':
  163. return [
  164. pnpmScript('typecheck', 'typecheck'),
  165. pnpmExec('source-worker-smoke', [
  166. 'vitest',
  167. 'run',
  168. 'packages/workflow/workflow-workerthread/tests/source-worker.compat.spec.ts',
  169. ], { label: 'source worker smoke' }),
  170. pnpmExec('jsonl-zstd-smoke', [
  171. 'vitest',
  172. 'run',
  173. 'packages/session-persistence/session-persistence-jsonl/tests/zstd.compat.spec.ts',
  174. ], { label: 'JSONL Zstandard smoke' }),
  175. ]
  176. case 'pre-push':
  177. return [
  178. pnpmScript('runtime-closure', 'verify-runtime-closure', { label: 'runtime closure' }),
  179. pnpmScript('cordis-config', 'verify-cordis-config', { label: 'Cordis config' }),
  180. pnpmScript('test', 'test'),
  181. pnpmScript('duplication', 'duplication'),
  182. snapshotGate(),
  183. pnpmScript('build', 'build'),
  184. ...hygieneLeafGates({ artifactNeeds: ['build'] }),
  185. ...docSyncLeafGates({
  186. docTypecheckNeeds: ['build'],
  187. docTypecheckEnv: { DSH_DOC_TYPECHECK_USE_BUILD_OUTPUT: '1' },
  188. }),
  189. pnpmScript('module-graph', 'verify-module-graph', { label: 'module graph' }),
  190. ]
  191. case 'doc-sync':
  192. return docSyncLeafGates()
  193. }
  194. }
  195. function ciPrimaryGates(): Gate[] {
  196. return [
  197. pnpmScript('runtime-closure', 'verify-runtime-closure', { label: 'runtime closure' }),
  198. pnpmScript('constraints', 'constraints'),
  199. pnpmScript('package-invariants', 'verify-package-invariants', { label: 'package invariants' }),
  200. pnpmScript('cordis-config', 'verify-cordis-config', { label: 'Cordis config' }),
  201. pnpmScript('typecheck', 'typecheck'),
  202. lintGate(),
  203. pnpmScript('duplication', 'duplication'),
  204. coverageGate(),
  205. snapshotGate(),
  206. ...docSyncLeafGates(),
  207. pnpmScript('module-graph', 'verify-module-graph', { label: 'module graph' }),
  208. pnpmScript('knip', 'knip'),
  209. pnpmScript('build', 'build', { needs: ['typecheck'] }),
  210. pnpmScript('publint', 'publint', { needs: ['build'] }),
  211. pnpmScript('node-next-types', 'verify-node-next-types', {
  212. label: 'node-next types',
  213. needs: ['build'],
  214. }),
  215. builtPackageInvariantsGate(['build']),
  216. builtBinSmokeGate(),
  217. ]
  218. }
  219. function ciStaticGates(): Gate[] {
  220. return [
  221. pnpmScript('runtime-closure', 'verify-runtime-closure', { label: 'runtime closure' }),
  222. pnpmScript('constraints', 'constraints'),
  223. pnpmScript('package-invariants', 'verify-package-invariants', { label: 'package invariants' }),
  224. pnpmScript('cordis-config', 'verify-cordis-config', { label: 'Cordis config' }),
  225. ...docSyncLeafGates(),
  226. pnpmScript('module-graph', 'verify-module-graph', { label: 'module graph' }),
  227. pnpmScript('knip', 'knip'),
  228. ]
  229. }
  230. function ciArtifactGates(): Gate[] {
  231. return [
  232. pnpmScript('build', 'build'),
  233. pnpmScript('publint', 'publint', { needs: ['build'] }),
  234. pnpmScript('node-next-types', 'verify-node-next-types', {
  235. label: 'node-next types',
  236. needs: ['build'],
  237. }),
  238. builtPackageInvariantsGate(['build']),
  239. builtBinSmokeGate(),
  240. ]
  241. }
  242. function lintGate(): Gate {
  243. if (process.env.DSH_ESLINT_CACHE === '1') {
  244. return pnpmExec('lint', [
  245. 'eslint',
  246. '.',
  247. '--cache',
  248. '--cache-location',
  249. '.cache/eslint/',
  250. '--cache-strategy',
  251. 'content',
  252. ], {
  253. label: 'lint',
  254. env: { NODE_OPTIONS: nodeOptions('--max-old-space-size=8192') },
  255. })
  256. }
  257. return pnpmScript('lint', 'lint', {
  258. env: { NODE_OPTIONS: nodeOptions('--max-old-space-size=8192') },
  259. })
  260. }
  261. function coverageGate(): Gate {
  262. return pnpmExec('coverage', [
  263. 'vitest',
  264. 'run',
  265. '--coverage',
  266. ...positiveIntArg('DSH_COVERAGE_MAX_WORKERS', '--maxWorkers'),
  267. ], {
  268. label: 'test:coverage',
  269. env: { DSH_EXAMPLE_MODE: 'lib' },
  270. needs: ['build'],
  271. })
  272. }
  273. // The snapshot suite boots the example bins in `lib` mode (built artifact under plain Node,
  274. // plugins via real exports) — CI and pre-push already build, so they exercise what ships rather
  275. // than the tsx/source path dev uses. It therefore waits on `build`.
  276. function snapshotGate(): Gate {
  277. return pnpmScript('snapshot', 'test:snapshot', {
  278. env: { DSH_EXAMPLE_MODE: 'lib' },
  279. needs: ['build'],
  280. })
  281. }
  282. function builtPackageInvariantsGate(needs?: string[]): Gate {
  283. return pnpmScript('built-package-invariants', 'verify-built-package-invariants', {
  284. label: 'built package invariants',
  285. ...needs === undefined ? {} : { needs },
  286. })
  287. }
  288. function positiveIntArg(envName: string, flag: string): string[] {
  289. const raw = process.env[envName]
  290. if (raw === undefined || raw === '') return []
  291. const parsed = Number.parseInt(raw, 10)
  292. if (!Number.isSafeInteger(parsed) || parsed < 1 || String(parsed) !== raw) {
  293. throw new Error(`run-gates: ${envName} must be a positive integer, got ${JSON.stringify(raw)}.`)
  294. }
  295. return [`${flag}=${raw}`]
  296. }
  297. function hygieneLeafGates(options: { artifactNeeds?: string[] } = {}): Gate[] {
  298. const artifactOptions = options.artifactNeeds === undefined ? {} : { needs: options.artifactNeeds }
  299. return [
  300. pnpmScript('knip', 'knip'),
  301. pnpmScript('publint', 'publint', artifactOptions),
  302. pnpmScript('constraints', 'constraints'),
  303. pnpmScript('package-invariants', 'verify-package-invariants', { label: 'package invariants' }),
  304. builtPackageInvariantsGate(options.artifactNeeds),
  305. pnpmScript('node-next-types', 'verify-node-next-types', {
  306. label: 'node-next types',
  307. ...artifactOptions,
  308. }),
  309. ]
  310. }
  311. function docSyncLeafGates(options: {
  312. docTypecheckNeeds?: string[]
  313. docTypecheckEnv?: Record<string, string | undefined>
  314. } = {}): Gate[] {
  315. const docTypecheckOptions: Partial<Gate> = {}
  316. if (options.docTypecheckNeeds !== undefined) docTypecheckOptions.needs = options.docTypecheckNeeds
  317. if (options.docTypecheckEnv !== undefined) docTypecheckOptions.env = options.docTypecheckEnv
  318. return [
  319. pnpmScript('doc-typecheck', 'doc-typecheck', docTypecheckOptions),
  320. pnpmScript('cordis-catalog', 'verify-cordis-catalog', { label: 'cordis catalog' }),
  321. pnpmScript('cordis-api', 'verify-cordis-api', { label: 'cordis api' }),
  322. pnpmScript('export-jsdoc', 'verify-export-jsdoc', { label: 'export jsdoc' }),
  323. pnpmScript('tool-catalog', 'verify-tool-catalog', { label: 'tool catalog' }),
  324. pnpmScript('config-catalog', 'verify-config-catalog', { label: 'config catalog' }),
  325. pnpmScript('persistence-catalog', 'verify-persistence-catalog', { label: 'persistence catalog' }),
  326. pnpmScript('doc-graphs', 'verify-doc-graphs', { label: 'doc graphs' }),
  327. pnpmScript('scoped-events', 'verify-scoped-events', { label: 'scoped events' }),
  328. pnpmScript('markdown-wrap', 'verify-md-wrap', { label: 'markdown wrap' }),
  329. pnpmScript('markdown-links', 'verify-md-links', { label: 'markdown links' }),
  330. pnpmScript('doc-refs', 'verify-doc-refs', { label: 'doc refs' }),
  331. pnpmScript('package-paths', 'verify-package-paths', { label: 'package paths' }),
  332. pnpmScript('package-readme-model-experience', 'verify-package-readme-model-experience', { label: 'package README model experience' }),
  333. pnpmScript('mermaid', 'verify-mermaid'),
  334. pnpmScript('agent-note-classification', 'verify-agent-note-classification', { label: 'agent note classification' }),
  335. pnpmScript('agent-note-format', 'verify-agent-note-format', { label: 'agent note format' }),
  336. pnpmScript('type-equivalence', 'verify-type-equiv', { label: 'type equivalence' }),
  337. pnpmScript('translation-prompt', 'verify-translation-prompt', { label: 'translation prompt' }),
  338. pnpmScript('translation-pairing', 'verify-translation-pairing', { label: 'translation pairing' }),
  339. pnpmScript('doc-budgets', 'verify-doc-budgets', { label: 'doc budgets' }),
  340. // Keep the VitePress build in this single gate because projection rewrites website/.generated.
  341. pnpmScript('docs-site', 'docs:check', { label: 'documentation site' }),
  342. pnpmScript('package-readme-limitations', 'verify-package-readme-limitations', { label: 'package README limitations' }),
  343. ]
  344. }
  345. function builtBinSmokeGate(): Gate {
  346. return pnpmExec('built-bin-smoke', [
  347. 'vitest',
  348. 'run',
  349. '--config',
  350. 'vitest.e2e.config.ts',
  351. 'examples/headless-agent/tests/keyless-smoke.e2e.ts',
  352. 'examples/tui-agent/tests/tui-keyless-smoke.e2e.ts',
  353. 'packages/examples/cli-demo/tests/built-bin.e2e.ts',
  354. 'packages/examples/acp-demo/tests/built-bin.e2e.ts',
  355. 'packages/ui/jsonrpc/tests/built-scope-carrier.e2e.ts',
  356. // The worker-entry packages' built bundles: the only automated proof
  357. // that lib/index.js resolves its sibling lib/worker.cjs under plain node
  358. // (the e2e lane runs unbuilt, so these files self-skip there).
  359. 'packages/workflow/workflow-workerthread/tests/built-worker.e2e.ts',
  360. 'packages/code-runtime/code-runtime-worker/tests/built-lib.e2e.ts',
  361. ], {
  362. label: 'built-bin smoke',
  363. needs: ['build'],
  364. env: { DSH_EXAMPLE_MODE: 'lib' },
  365. })
  366. }
  367. async function runGates(allGates: Gate[], maxActive: number): Promise<GateResult[]> {
  368. const states = new Map<string, GateStatus>(allGates.map(gate => [gate.id, 'pending']))
  369. const results = new Map<string, GateResult>()
  370. const running: RunningGate[] = []
  371. for (;;) {
  372. let madeProgress = false
  373. while (running.length < maxActive) {
  374. const ready = allGates.find(gate => states.get(gate.id) === 'pending' && dependenciesPassed(gate, states))
  375. if (ready === undefined) break
  376. states.set(ready.id, 'running')
  377. running.push({ gate: ready, promise: runGate(ready) })
  378. console.log(`run-gates: start ${ready.label}`)
  379. madeProgress = true
  380. }
  381. if (running.length === 0) {
  382. const pending = allGates.filter(gate => states.get(gate.id) === 'pending')
  383. for (const gate of pending) {
  384. const failedDeps = (gate.needs ?? []).filter(id => states.get(id) !== 'passed')
  385. const result: GateResult = {
  386. gate,
  387. status: 'skipped',
  388. durationMs: 0,
  389. stdout: '',
  390. stderr: '',
  391. output: [],
  392. exitCode: null,
  393. error: `dependency failed or skipped: ${failedDeps.join(', ')}`,
  394. }
  395. states.set(gate.id, 'skipped')
  396. results.set(gate.id, result)
  397. printResult(result)
  398. }
  399. break
  400. }
  401. if (!madeProgress) {
  402. const settled = await Promise.race(running.map(async item => ({ item, result: await item.promise })))
  403. running.splice(running.indexOf(settled.item), 1)
  404. states.set(settled.item.gate.id, settled.result.status)
  405. results.set(settled.item.gate.id, settled.result)
  406. printResult(settled.result)
  407. }
  408. }
  409. return allGates.map((gate) => {
  410. const result = results.get(gate.id)
  411. if (result === undefined) throw new Error(`run-gates: missing result for ${gate.id}.`)
  412. return result
  413. })
  414. }
  415. function dependenciesPassed(gate: Gate, states: Map<string, GateStatus>): boolean {
  416. return (gate.needs ?? []).every(id => states.get(id) === 'passed')
  417. }
  418. async function runGate(gate: Gate): Promise<GateResult> {
  419. const started = performance.now()
  420. let stdout = ''
  421. let stderr = ''
  422. const output: GateOutputChunk[] = []
  423. let spawnError: string | undefined
  424. const exitCode = await new Promise<number | null>((resolveExit) => {
  425. const child = spawn(gate.command, gate.args, {
  426. cwd: root,
  427. env: { ...process.env, ...gate.env },
  428. stdio: ['pipe', 'pipe', 'pipe'],
  429. })
  430. child.stdout.setEncoding('utf8')
  431. child.stderr.setEncoding('utf8')
  432. child.stdout.on('data', (chunk: string) => {
  433. stdout += chunk
  434. output.push({ stream: 'stdout', text: chunk })
  435. })
  436. child.stderr.on('data', (chunk: string) => {
  437. stderr += chunk
  438. output.push({ stream: 'stderr', text: chunk })
  439. })
  440. child.on('error', (error) => {
  441. spawnError = `failed to start command: ${error.message}`
  442. resolveExit(null)
  443. })
  444. child.on('close', resolveExit)
  445. if (gate.input !== undefined) child.stdin.end(gate.input)
  446. else child.stdin.end()
  447. })
  448. let status: GateStatus = exitCode === 0 && spawnError === undefined ? 'passed' : 'failed'
  449. let error = spawnError
  450. if (status === 'passed' && gate.verify !== undefined) {
  451. try {
  452. await gate.verify({ gate, status, durationMs: performance.now() - started, stdout, stderr, output, exitCode })
  453. } catch (verifyError: unknown) {
  454. status = 'failed'
  455. error = verifyError instanceof Error ? verifyError.message : String(verifyError)
  456. }
  457. }
  458. const result: GateResult = {
  459. gate,
  460. status,
  461. durationMs: performance.now() - started,
  462. stdout,
  463. stderr,
  464. output,
  465. exitCode,
  466. }
  467. if (error !== undefined) result.error = error
  468. return result
  469. }
  470. function printResult(result: GateResult): void {
  471. const seconds = (result.durationMs / 1000).toFixed(2)
  472. if (result.status === 'passed' && !verbose) {
  473. console.log(`run-gates: PASS ${result.gate.label} (${seconds}s)`)
  474. return
  475. }
  476. const heading = `${result.status.toUpperCase()} ${result.gate.label} (${seconds}s)`
  477. const writeHeading = result.status === 'passed' ? console.log : console.error
  478. writeHeading(`\n== ${heading} ==`)
  479. if (result.status !== 'passed') console.error(`command: ${result.gate.displayCommand}`)
  480. printOutput(result.output)
  481. if (result.error !== undefined) console.error(result.error)
  482. }
  483. function printSummary(results: GateResult[], durationMs: number): void {
  484. const passed = results.filter(result => result.status === 'passed').length
  485. const failed = results.filter(result => result.status === 'failed').length
  486. const skipped = results.filter(result => result.status === 'skipped').length
  487. const seconds = (durationMs / 1000).toFixed(2)
  488. console.log(`\nrun-gates: ${passed} passed, ${failed} failed, ${skipped} skipped in ${seconds}s.`)
  489. const unsuccessful = results.filter(result => result.status === 'failed' || result.status === 'skipped')
  490. if (unsuccessful.length === 0) return
  491. console.error('run-gates: unsuccessful gates:')
  492. for (const result of unsuccessful) {
  493. const duration = (result.durationMs / 1000).toFixed(2)
  494. const reason = result.error ?? (result.exitCode === null ? 'no exit code' : `exit ${result.exitCode}`)
  495. console.error(` - ${result.status.toUpperCase()} ${result.gate.label} (${duration}s, ${reason})`)
  496. console.error(` ${result.gate.displayCommand}`)
  497. }
  498. }
  499. function printOutput(output: GateOutputChunk[]): void {
  500. for (const chunk of output) {
  501. if (chunk.stream === 'stdout') process.stdout.write(chunk.text)
  502. else process.stderr.write(chunk.text)
  503. }
  504. }