-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(nuxi): cli wrapper for self restart #18641
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
431e1bb
feat(nuxi): cli-wrapper for self restart
antfu a6a5d6f
chore: properly bundle cli-warpper
antfu c0c4734
chore: fix path
antfu 69fea57
chore: compactiable with stub mode
antfu 06ed209
perf: only enable subprocess in dev command
antfu f40bf10
Merge branch 'main' into feat/nuxi-restart
danielroe f8fc0fc
Merge branch 'main' into feat/nuxi-restart
antfu 447f337
feat: add hook
antfu 086e375
chore: change code to 85
antfu File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perf: I guess we can use
fork
(orexec
) fromnod:child_process
. This is also consistent with the final nuxi-ng implementation and provides a communication channel.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see we use
execa
in many places already, and the chunk is shared. I guess the performance won't be a big issue here.I am just worried about using
fork
orexec
might create more issues to handle on different OS, etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main usecase i added execa was search path compatibility which isnβt a case here. Also fork copies mem in unix then execs which by theory at least should be faster than loading node to the mem again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we mesure the performance difference here?
I like the simplicity of code and execa has some good features:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of those benefits aren't relevant here and main benefit is using fork over exec with fine gained control. we are forking a known entry as process (not a on-off executation like other commands).
Finally this impl will be part of citty's dev server so this change is to make sure we are aligned :)