MCPcopy Index your code
hub / github.com/blitz-js/blitz / runNextCommand

Function runNextCommand

integration-tests/utils/next-test-utils.ts:319–396  ·  view source on GitHub ↗
(argv, options: RunNextCommandOptions = {})

Source from the content-addressed store, hash-verified

317//Next Utils
318
319export 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

Callers 3

nextBuildFunction · 0.85
nextExportFunction · 0.85
nextExportDefaultFunction · 0.85

Calls 4

toStringMethod · 0.80
getCommandBinFunction · 0.70
logMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected