Skip to content
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

Integrate hydrogen-react into the hydrogen monorepo #605

Merged
merged 188 commits into from
Mar 3, 2023

Conversation

frehner
Copy link
Contributor

@frehner frehner commented Mar 1, 2023

WHY are these changes introduced?

This is the majority of the work to integrate hydrogen-react back into the hydrogen repo. Namely:

  • Code migration (hypothetically, with completely git history. Thanks @gfscott !) This is why the commit history is so large
  • Development workflow is working. There's probably room to optimize this, but saving a component in hydrogen-react will cause a page refresh in the demo-store
  • CI processes are integrated. In addition, a new monorepo-root-level npm script has been added (called ci:checks) that enables you to quickly run all the ci checks locally; before, you had to know which scripts were run in CI, and then run then individually.
  • Updates the issue template to incorporate the idea of multiple packages
  • Updates the root README to incorporate the idea of multiple packages (thanks @gfscott !)
  • Updates docs and package.json to point to the new repo location

A big thank you to @wizardlyhel @juanpprieto and @blittle for pairing on this throughout various points as well!

Final questions:

  • Should we add the NextJS app?

HOW to test your changes?

  1. Checkout this branch,
  2. clear your node_modules at all levels,
  3. npm i,
  4. npm run dev,
  5. edit code in hydrogen-react and hydrogen, ensure it works and that it reloads correctly

Also:

  • Run ladle (npm run dev:story) in the hydrogen-react package and ensure that it is working as well. (This helps you develop components in isolation, outside of remix)

Post-merge steps

  • Validate that publishing works with changesets in this new setup
  • Update the docs system to point to this new repo
  • We'll need to migrate issues, PRs, discussions

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes

frehner and others added 30 commits September 27, 2022 10:32
Add github workflows
* test to see if alex is breaking ci stuff

* add alex back, and check changeset checker

* downgrade alex, and add better words/docs on changeset reminder

* revert alex downgrade

* see if we can figure out where this is coming from

* remove testing as it didn't find anything

* remove diff command on alex

* remove comment that tests changeset checker
* Fix readmes

* update terminology
Add the variant source header for SFAPI calls.
* provide guidance on setting the header content type

* language lint

* change pkg name
* update readme

* fix links

Co-authored-by: Elise Yang <eliseyang@elises-mbp-2.lan>
* CI action for publishing the next version automatically

* remove output to file
* CI action for publishing the next version automatically

* remove output to file

* Don't use the action to run these commands
* Change TS's module resolution to 'node' instead of nodenext

* Include stories in TS checking now, and fix issues
* Copy CartProvider from hydrogen repo

* Add worktop lib to use the cookies package for CartProvider

* Modify CartProvider to fit hydrogen-ui

* Add CartProvider story

* add changeset

* Cart provider updates (#14)

* Change ts moduleresolution (#13)

* Change TS's module resolution to 'node' instead of nodenext

* Include stories in TS checking now, and fix issues

* Starting work on simplifying the cart code in hui

* Simply more cart-related files and remove a bunch of them

* All CI checks are passing, and types are improved.

* Better file names

* Fix mock import filename

* Remove any type

* Improve release notes, update type names, fix typo

* Correct alex config file and allow hooks

Co-authored-by: Anthony Frehner <frehner@users.noreply.github.com>
Copy link
Contributor Author

@frehner frehner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can pretty much ignore all the files/change inside of the packages/hydrogen-react folder, so that should help this PR be much smaller.

@@ -48,7 +48,7 @@ jobs:
- name: 📥 Install dependencies
run: npm ci

- name: 🔬 Lint
- name: 🔬 Check Formatting
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in the prettier job, so the name needed to be updated.

@@ -4,10 +4,11 @@
"scripts": {
"build": "turbo build --parallel",
"build:pkg": "npm run build -- --filter=./packages/*",
"ci:checks": "turbo run lint test format:check typecheck",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new command that can be run from root, to run all ci checks locally

"dev": "npm run dev:pkg -- --filter=./templates/demo-store",
"dev:pkg": "cross-env LOCAL_DEV=true turbo dev --parallel --filter=./packages/*",
"preview": "turbo build --filter=./packages/* && npm run preview -w demo-store",
"lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx ./packages && npm run lint -w demo-store",
"lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx ./packages & npm run lint -w demo-store",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run the scripts in parallel instead of serially

@@ -4,19 +4,18 @@ import {fileURLToPath} from 'url';

(async () => {
const root = fileURLToPath(new URL('..', import.meta.url));
const hydrogenReact = 'node_modules/@shopify/hydrogen-react';
const hydrogenReact = 'packages/hydrogen-react';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small updates to this script to get it working with the local files

@@ -30,6 +30,9 @@
"@shopify/create-hydrogen#build": {
"dependsOn": ["@shopify/cli-hydrogen#build"]
},
"@shopify/hydrogen#build": {
"dependsOn": ["@shopify/hydrogen-react#build"]
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hydrogen requires hydrogen-react to build first

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For everything; hydrogen re-exports things from hydrogen-react, so that will only work if hydrogen-react has been built first.

@cartogram
Copy link
Contributor

clear your node_modules at all levels,

npm exec --workspaces -- npx rimraf node_modules && npx rimraf node_modules

Copy link
Contributor

@cartogram cartogram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local testing went smoothly 🎉

packages/hydrogen-react/package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@lordofthecactus lordofthecactus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @frehner! I tophatted with ladle and everything seems to work alright.

.gitignore Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated

**Requirements:**

- Node.js version 16.14.0 or higher
- `npm`, `yarn` or `pnpm`
- `npm` version 8.3.1 (or your package manager of choice, such as `yarn` or `pnpm`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this specific version of npm? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an addition by @gfscott ; thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not add npm version, unless there was a requirement for a certain version

package.json Show resolved Hide resolved
packages/hydrogen-react/CONTRIBUTING.md Show resolved Hide resolved
@cartogram
Copy link
Contributor

@frehner wondering if it still makes sense to be using vite? Just a question for future discussion, not a blocker for this PR.

@frehner
Copy link
Contributor Author

frehner commented Mar 2, 2023

@frehner wondering if it still makes sense to be using vite? Just a question for future discussion, not a blocker for this PR.

Yeah it's a good and valid question. I used Vite originally because that's what v1 was using, but now that v2 uses tsup it's worth looking into whether tsup supports all the things we need to do to bundle hydrogen-react, and if not, is Vite still the best tool or should we use something like Rollup or microbundle or whatever.

Co-authored-by: Daniel Rios <daniel.riospavia@shopify.com>
Copy link
Contributor

@frandiox frandiox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM!

@@ -14,7 +14,7 @@
"scripts": {
"build": "tsup --clean --config ../../tsup.config.ts && npm run copy-hydrogen-react",
"copy-hydrogen-react": "node ../../scripts/copy-hydrogen-react.mjs",
"dev": "tsup --watch --config ../../tsup.config.ts",
"dev": "tsup --watch --config ../../tsup.config.ts --watch ../../node_modules/@shopify/hydrogen-react/dist/browser-prod/index.mjs",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe ../hydrogen-react/dist/browser-prod/index.mjs better? The node_modules one should be a symlink to this one.

Also, what's this for? Types? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helped hydrogen reload when hydrogen-react is updated. It could be that it's not needed, I'll verify, but we had a hard time getting it to work correctly and this is what we ended up with.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed that this is necessary to get reloading working (at least with the way it is setup now).

I'll merge with this, but improvements as followups are very welcome!

@@ -30,6 +30,9 @@
"@shopify/create-hydrogen#build": {
"dependsOn": ["@shopify/cli-hydrogen#build"]
},
"@shopify/hydrogen#build": {
"dependsOn": ["@shopify/hydrogen-react#build"]
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the types?

@github-actions github-actions bot had a problem deploying to preview March 3, 2023 20:09 Failure
@github-actions github-actions bot had a problem deploying to preview March 3, 2023 20:13 Failure
@github-actions github-actions bot had a problem deploying to preview March 3, 2023 20:27 Failure
@github-actions github-actions bot had a problem deploying to preview March 3, 2023 20:27 Failure
@frehner frehner merged commit a215152 into 2023-01 Mar 3, 2023
@frehner frehner deleted the integrate-hydrogen-react branch March 3, 2023 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants