-
Notifications
You must be signed in to change notification settings - Fork 247
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
Build watch #2100
Build watch #2100
Conversation
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
{ | ||
name: 'hydrogen:cli:client', | ||
buildStart() { | ||
clientBuildStatus?.resolve(); | ||
clientBuildStatus = deferPromise(); | ||
}, | ||
buildEnd(error) { | ||
if (error) clientBuildStatus.reject(error); | ||
}, | ||
writeBundle() { | ||
clientBuildStatus.resolve(); | ||
}, | ||
}, |
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.
The server rebuild needs to wait until the client build is finished. This deferred promise helps with that.
if ('close' in clientBuild) promises.push(clientBuild.close()); | ||
if ('close' in serverBuild) promises.push(serverBuild.close()); |
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.
The type of clientBuild
and serverBuild
is different in watch mode. Using in
here correctly discriminates the type.
if (!process.env.NODE_ENV) process.env.NODE_ENV = 'production'; | ||
if (!process.env.NODE_ENV) | ||
process.env.NODE_ENV = watch ? 'development' : 'production'; |
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.
Using development
with watch mode to allow our CSP to connect to Miniflare's loopback server (localhost:).
async onRebuild() { | ||
if (projectBuild.state === 'pending') { | ||
projectBuild.resolve(); |
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.
We need the first build finished before starting MiniOxygen with files in disk.
@@ -92,7 +92,6 @@ export const commonFlags = { | |||
description: | |||
'Automatically generates GraphQL types for your project’s Storefront API queries.', | |||
required: false, | |||
default: false, |
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.
Turns out Oclif's dependOn
for flags doesn't work if the flag has a default value.
@blittle Thanks for the thorough review! Most problem were due to a bad last minute copy-paste 🤦
Copy-pasted code and forgot to enable the watcher for the diff folder 🙃
Yes, it does. I've added a comment in the code to explain this because I even forgot about it myself when you mentioned it:
Same thing, forgot to enable the watcher. Note that codegen reruns but we are ignoring the changes in Git. I think this is all now fixed in the recent commints 👍 |
I can only repro this issue 50% of the time or so, but when running I have to kill the whole terminal to get it to stop. |
@blittle I was only able to reproduce this very few times. It looks like even when we close Rollup watchers, the build still continues and then it starts failing synchronously when it can't find the diff files that we just removed on process exit. I've added a few changes to try to ensure the build exits before we remove files so that we don't go into an infinite sync error loop. I'm not able to reproduce it after these changes but maybe I was just lucky. Please try it again but, in any case, these errors only happens with |
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 still see the --diff
problem, but like you said, it only affects us.
* Improve deferPromise utility for debugging * Implement --watch in build command * Support --codegen with --watch in build command * Add --build to preview command * Fix codegen flag relationship * Use new flag in skeleton * Pass --entry from preview to build * Extract resource cleanup logic * Setup resource cleanup for build watch * Add --watch to preview command * Replace command in examples * Consider classic compiler in preview * Support --diff in preview to test in examples * Changesets * Silence non-actionable build logs during preview * Typo * Improve error when worker file is not found * Remove default false values in flags to avoid issues with flag dependencies * Fix diff watcher in build and preview * Add explanatory comment for flag combination * Use helper * Ensure processExit is called after 5 seconds * Try to ensure process exits
This is a prerequisite for supporting
h2 debug cpu
in Vite. Features:--watch
toh2 build
--build --watch --codegen
toh2 preview
--diff
inh2 preview
Note
Miniflare is currently not compatible with CSP nonces and WS connections. Therefore, live reload doesn't work with
h2 preview --build --watch
until that's fixed and you need to refresh the browser manually.I've reported the problem here: cloudflare/workers-sdk#5829