mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-16 21:58:19 +00:00
fix(cli): close process by default after command invokation (#4192)
This commit is contained in:
parent
edd0b30896
commit
396472778f
@ -26,26 +26,18 @@ async function _main () {
|
||||
}
|
||||
|
||||
// Check Node.js version in background
|
||||
setTimeout(() => { checkEngines() }, 1000)
|
||||
setTimeout(() => { checkEngines().catch(() => {}) }, 1000)
|
||||
|
||||
try {
|
||||
// @ts-ignore default.default is hotfix for #621
|
||||
const cmd = await commands[command as Command]() as NuxtCommand
|
||||
if (args.h || args.help) {
|
||||
showHelp(cmd.meta)
|
||||
} else {
|
||||
await cmd.invoke(args)
|
||||
}
|
||||
} catch (err) {
|
||||
onFatalError(err)
|
||||
// @ts-ignore default.default is hotfix for #621
|
||||
const cmd = await commands[command as Command]() as NuxtCommand
|
||||
if (args.h || args.help) {
|
||||
showHelp(cmd.meta)
|
||||
} else {
|
||||
const result = await cmd.invoke(args)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
function onFatalError (err: unknown) {
|
||||
consola.error(err)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// Wrap all console logs with consola for better DX
|
||||
consola.wrapConsole()
|
||||
|
||||
@ -53,5 +45,16 @@ process.on('unhandledRejection', err => consola.error('[unhandledRejection]', er
|
||||
process.on('uncaughtException', err => consola.error('[uncaughtException]', err))
|
||||
|
||||
export function main () {
|
||||
_main().catch(onFatalError)
|
||||
_main()
|
||||
.then((result) => {
|
||||
if (result === 'error') {
|
||||
process.exit(1)
|
||||
} else if (result !== 'wait') {
|
||||
process.exit(0)
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
consola.error(error)
|
||||
process.exit(1)
|
||||
})
|
||||
}
|
||||
|
@ -108,5 +108,7 @@ export default defineNuxtCommand({
|
||||
if (currentNuxt) {
|
||||
await currentNuxt.hooks.callHook('listen', listener.server, listener)
|
||||
}
|
||||
|
||||
return 'wait'
|
||||
}
|
||||
})
|
||||
|
@ -30,8 +30,10 @@ export interface NuxtCommandMeta {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export type CLIInvokeResult = void | 'error' | 'wait'
|
||||
|
||||
export interface NuxtCommand {
|
||||
invoke(args: Argv): Promise<void> | void
|
||||
invoke(args: Argv): Promise<CLIInvokeResult> | CLIInvokeResult
|
||||
meta: NuxtCommandMeta
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,10 @@ export default defineNuxtCommand({
|
||||
dev: !!args.dev,
|
||||
watch: !!args.watch
|
||||
})
|
||||
|
||||
if (args.watch) {
|
||||
return 'wait'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user