Skip to content

Commit

Permalink
Build watch (#2100)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
frandiox committed May 24, 2024
1 parent 53cc94d commit 608389d
Show file tree
Hide file tree
Showing 26 changed files with 422 additions and 86 deletions.
6 changes: 6 additions & 0 deletions .changeset/tiny-pans-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@shopify/cli-hydrogen': minor
---

The `h2 preview` command now supports `--build` and `--watch` flags to preview the project using the build process instead of Vite's dev process.

2 changes: 1 addition & 1 deletion examples/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "shopify hydrogen build --diff",
"dev": "shopify hydrogen dev --codegen --diff",
"preview": "npm run build && shopify hydrogen preview",
"preview": "shopify hydrogen preview --build --diff",
"lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx .",
"typecheck": "tsc --noEmit",
"codegen": "shopify hydrogen codegen"
Expand Down
2 changes: 1 addition & 1 deletion examples/b2b/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "shopify hydrogen build --diff",
"dev": "shopify hydrogen dev --codegen --diff",
"preview": "npm run build && shopify hydrogen preview",
"preview": "shopify hydrogen preview --build --diff",
"lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx .",
"typecheck": "tsc --noEmit",
"codegen": "shopify hydrogen codegen"
Expand Down
2 changes: 1 addition & 1 deletion examples/classic-remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "shopify hydrogen build --diff",
"dev": "shopify hydrogen dev --codegen --diff",
"preview": "npm run build && shopify hydrogen preview",
"preview": "shopify hydrogen preview --build --diff",
"lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx .",
"typecheck": "tsc --noEmit",
"codegen": "shopify hydrogen codegen"
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-cart-method/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "shopify hydrogen build --diff",
"dev": "shopify hydrogen dev --codegen --diff",
"preview": "npm run build && shopify hydrogen preview",
"preview": "shopify hydrogen preview --build --diff",
"lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx .",
"typecheck": "tsc --noEmit",
"codegen": "shopify hydrogen codegen"
Expand Down
2 changes: 1 addition & 1 deletion examples/infinite-scroll/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "shopify hydrogen build --diff",
"dev": "shopify hydrogen dev --codegen --diff",
"preview": "npm run build && shopify hydrogen preview",
"preview": "shopify hydrogen preview --build --diff",
"lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx .",
"typecheck": "tsc --noEmit",
"codegen": "shopify hydrogen codegen"
Expand Down
2 changes: 1 addition & 1 deletion examples/legacy-customer-account-flow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "shopify hydrogen build --diff",
"dev": "shopify hydrogen dev --codegen --diff",
"preview": "npm run build && shopify hydrogen preview",
"preview": "shopify hydrogen preview --build --diff",
"lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx .",
"typecheck": "tsc --noEmit",
"codegen": "shopify hydrogen codegen"
Expand Down
2 changes: 1 addition & 1 deletion examples/metaobjects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "shopify hydrogen build --diff",
"dev": "shopify hydrogen dev --codegen --diff",
"preview": "npm run build && shopify hydrogen preview",
"preview": "shopify hydrogen preview --build --diff",
"lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx .",
"typecheck": "tsc --noEmit",
"codegen": "shopify hydrogen codegen"
Expand Down
2 changes: 1 addition & 1 deletion examples/multipass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "shopify hydrogen build",
"dev": "shopify hydrogen dev --codegen",
"preview": "npm run build && shopify hydrogen preview",
"preview": "shopify hydrogen preview --build",
"lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx .",
"typecheck": "tsc --noEmit",
"codegen": "shopify hydrogen codegen"
Expand Down
2 changes: 1 addition & 1 deletion examples/optimistic-cart-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "shopify hydrogen build --diff",
"dev": "shopify hydrogen dev --codegen --diff",
"preview": "npm run build && shopify hydrogen preview",
"preview": "shopify hydrogen preview --build --diff",
"lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx .",
"typecheck": "tsc --noEmit",
"codegen": "shopify hydrogen codegen"
Expand Down
2 changes: 1 addition & 1 deletion examples/partytown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "npm run partytown && shopify hydrogen build",
"dev": "shopify hydrogen dev --codegen",
"preview": "npm run build && shopify hydrogen preview",
"preview": "shopify hydrogen preview --build",
"lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx .",
"typecheck": "tsc --noEmit",
"codegen": "shopify hydrogen codegen",
Expand Down
2 changes: 1 addition & 1 deletion examples/subscriptions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "shopify hydrogen build",
"dev": "shopify hydrogen dev --codegen",
"preview": "npm run build && shopify hydrogen preview",
"preview": "shopify hydrogen preview --build",
"lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx .",
"typecheck": "tsc --noEmit",
"codegen": "shopify hydrogen codegen"
Expand Down
2 changes: 1 addition & 1 deletion examples/third-party-queries-caching/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "shopify hydrogen build --codegen --diff",
"dev": "shopify hydrogen dev --codegen --diff",
"preview": "npm run build && shopify hydrogen preview",
"preview": "shopify hydrogen preview --build --diff",
"lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx .",
"typecheck": "tsc --noEmit",
"codegen": "shopify hydrogen codegen"
Expand Down
65 changes: 65 additions & 0 deletions packages/cli/oclif.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
"allowNo": false,
"type": "boolean"
},
"watch": {
"description": "Watches for changes and rebuilds the project writing output to disk.",
"env": "SHOPIFY_HYDROGEN_FLAG_WATCH",
"name": "watch",
"allowNo": false,
"type": "boolean"
},
"bundle-stats": {
"description": "[Classic Remix Compiler] Show a bundle size summary after building. Defaults to true, use `--no-bundle-stats` to disable.",
"name": "bundle-stats",
Expand Down Expand Up @@ -1282,6 +1289,64 @@
"required": false,
"allowNo": false,
"type": "boolean"
},
"build": {
"description": "Builds the app before starting the preview server.",
"name": "build",
"allowNo": false,
"type": "boolean"
},
"watch": {
"dependsOn": [
"build"
],
"description": "Watches for changes and rebuilds the project.",
"name": "watch",
"allowNo": false,
"type": "boolean"
},
"entry": {
"dependsOn": [
"build"
],
"description": "Entry file for the worker. Defaults to `./server`.",
"env": "SHOPIFY_HYDROGEN_FLAG_ENTRY",
"name": "entry",
"hasDynamicHelp": false,
"multiple": false,
"type": "option"
},
"codegen": {
"dependsOn": [
"build"
],
"description": "Automatically generates GraphQL types for your project’s Storefront API queries.",
"name": "codegen",
"required": false,
"allowNo": false,
"type": "boolean"
},
"codegen-config-path": {
"dependsOn": [
"codegen"
],
"description": "Specifies a path to a codegen configuration file. Defaults to `<root>/codegen.ts` if this file exists.",
"name": "codegen-config-path",
"required": false,
"hasDynamicHelp": false,
"multiple": false,
"type": "option"
},
"diff": {
"dependsOn": [
"build"
],
"description": "Applies the current files on top of Hydrogen's starter template in a temporary directory.",
"hidden": true,
"name": "diff",
"required": false,
"allowNo": false,
"type": "boolean"
}
},
"hasDynamicHelp": false,
Expand Down
Loading

0 comments on commit 608389d

Please sign in to comment.