forked from nuxt/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nuxi): cli wrapper for self restart (#18641)
- Loading branch information
Showing
9 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
#!/usr/bin/env node | ||
process._startTime = Date.now() | ||
import('../dist/cli.mjs').then(r => (r.default || r).main()) | ||
import('../dist/cli-wrapper.mjs') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// @ts-ignore | ||
process._startTime = Date.now() | ||
// @ts-ignore | ||
import('./cli').then(r => (r.default || r).main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* 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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Special exit code to restart the process | ||
* | ||
* Usage: | ||
* ```ts | ||
* if (process.env.NUXI_CLI_WRAPPER) { | ||
* process.exit(EXIT_CODE_RESTART) | ||
* } | ||
* ``` | ||
*/ | ||
export const EXIT_CODE_RESTART = 85 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './run' | ||
export * from './constants' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters