(argv, options: RunNextCommandOptions = {})
| 317 | //Next Utils |
| 318 | |
| 319 | export function runNextCommand(argv, options: RunNextCommandOptions = {}) { |
| 320 | const nextnextbin = getCommandBin("next", options.cwd) |
| 321 | const nextBin = path.join(nextnextbin, "dist/bin/next") |
| 322 | const cwd = options.cwd || process.cwd() |
| 323 | // Let Next.js decide the environment |
| 324 | const env = { |
| 325 | ...process.env, |
| 326 | NODE_ENV: "production" as const, |
| 327 | __NEXT_TEST_MODE: "true", |
| 328 | ...options.env, |
| 329 | } |
| 330 | |
| 331 | return new Promise((resolve, reject) => { |
| 332 | console.log(`Running command "next ${argv.join(" ")}"`) |
| 333 | const instance = spawn("node", [nextBin, ...argv], { |
| 334 | cwd, |
| 335 | env, |
| 336 | stdio: ["ignore", "pipe", "pipe"], |
| 337 | }) |
| 338 | |
| 339 | if (typeof options.instance === "function") { |
| 340 | options.instance(instance) |
| 341 | } |
| 342 | |
| 343 | let mergedStdio = "" |
| 344 | |
| 345 | let stderrOutput = "" |
| 346 | if (options.stderr) { |
| 347 | instance.stderr?.on("data", function (chunk) { |
| 348 | mergedStdio += chunk |
| 349 | stderrOutput += chunk |
| 350 | |
| 351 | if (options.stderr === "log") { |
| 352 | console.log(chunk.toString()) |
| 353 | } |
| 354 | }) |
| 355 | } else { |
| 356 | instance.stderr?.on("data", function (chunk) { |
| 357 | mergedStdio += chunk |
| 358 | }) |
| 359 | } |
| 360 | |
| 361 | let stdoutOutput = "" |
| 362 | if (options.stdout) { |
| 363 | instance.stdout?.on("data", function (chunk) { |
| 364 | mergedStdio += chunk |
| 365 | stdoutOutput += chunk |
| 366 | |
| 367 | if (options.stdout === "log") { |
| 368 | console.log(chunk.toString()) |
| 369 | } |
| 370 | }) |
| 371 | } else { |
| 372 | instance.stdout?.on("data", function (chunk) { |
| 373 | mergedStdio += chunk |
| 374 | }) |
| 375 | } |
| 376 |
no test coverage detected