(
argv: string[],
stdOut?: boolean,
opts: NextDevOptions = {}
)
| 417 | } |
| 418 | |
| 419 | export function runNextCommandDev( |
| 420 | argv: string[], |
| 421 | stdOut?: boolean, |
| 422 | opts: NextDevOptions = {} |
| 423 | ): Promise<(typeof stdOut extends true ? string : ChildProcess) | undefined> { |
| 424 | const nextDir = path.dirname(require.resolve('next/package')) |
| 425 | const nextBin = opts.nextBin || path.join(nextDir, 'dist/bin/next') |
| 426 | const cwd = opts.cwd || nextDir |
| 427 | const env = { |
| 428 | ...process.env, |
| 429 | // @ts-ignore packages/next/types/global.d.ts should allow undefined NODE_ENV |
| 430 | NODE_ENV: undefined as NodeJS.ProcessEnv['NODE_ENV'], |
| 431 | __NEXT_TEST_MODE: 'true', |
| 432 | ...opts.env, |
| 433 | } |
| 434 | |
| 435 | const nodeArgs = opts.nodeArgs || [] |
| 436 | return new Promise((resolve, reject) => { |
| 437 | const instance = spawn( |
| 438 | 'node', |
| 439 | [...nodeArgs, '--no-deprecation', nextBin, ...argv], |
| 440 | { |
| 441 | cwd, |
| 442 | env, |
| 443 | } |
| 444 | ) |
| 445 | let didResolve = false |
| 446 | |
| 447 | const bootType = |
| 448 | opts.nextStart || stdOut ? 'start' : opts?.turbo ? 'turbo' : 'dev' |
| 449 | |
| 450 | function handleStdout(data) { |
| 451 | const message = data.toString() |
| 452 | const bootupMarkers = { |
| 453 | dev: /✓ ready/i, |
| 454 | turbo: /✓ ready/i, |
| 455 | start: /✓ ready/i, |
| 456 | } |
| 457 | |
| 458 | const strippedMessage = stripAnsi(message) as any |
| 459 | |
| 460 | if ( |
| 461 | (opts.bootupMarker && opts.bootupMarker.test(strippedMessage)) || |
| 462 | bootupMarkers[bootType].test(strippedMessage) |
| 463 | ) { |
| 464 | if (!didResolve) { |
| 465 | didResolve = true |
| 466 | // Pass down the original message |
| 467 | resolve(stdOut ? message : instance) |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | if (typeof opts.onStdout === 'function') { |
| 472 | opts.onStdout(message) |
| 473 | } |
| 474 | |
| 475 | if (opts.stdout !== false) { |
| 476 | process.stdout.write(message) |
no test coverage detected