mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 10:04:05 +00:00
41 lines
911 B
TypeScript
41 lines
911 B
TypeScript
|
/**
|
||
|
* This file is used to wrap the CLI entrypoint in a restartable process.
|
||
|
*/
|
||
|
import { fileURLToPath } from 'node:url'
|
||
|
import { execa } from 'execa'
|
||
|
import { EXIT_CODE_RESTART } from './constants'
|
||
|
|
||
|
const cliEntry = fileURLToPath(new URL('../dist/cli-run.mjs', import.meta.url))
|
||
|
|
||
|
async function startSubprocess (preArgs: string[], postArgs: string[]) {
|
||
|
const child = await execa(
|
||
|
'node',
|
||
|
[
|
||
|
...preArgs,
|
||
|
cliEntry,
|
||
|
...postArgs
|
||
|
],
|
||
|
{
|
||
|
reject: false,
|
||
|
stdio: 'inherit',
|
||
|
env: {
|
||
|
...process.env,
|
||
|
NUXI_CLI_WRAPPER: 'true'
|
||
|
}
|
||
|
}
|
||
|
)
|
||
|
if (child.exitCode === EXIT_CODE_RESTART) {
|
||
|
await startSubprocess(preArgs, postArgs)
|
||
|
} else {
|
||
|
process.exit(child.exitCode)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const args = process.argv.slice(2)
|
||
|
// only enable wrapper in dev command
|
||
|
if (args[0] === 'dev') {
|
||
|
await startSubprocess([], args)
|
||
|
} else {
|
||
|
await import(cliEntry)
|
||
|
}
|