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

Setup turborepo, second try #52

Merged
merged 5 commits into from Feb 21, 2023
Merged

Setup turborepo, second try #52

merged 5 commits into from Feb 21, 2023

Conversation

simonihmig
Copy link
Contributor

@simonihmig simonihmig commented Feb 16, 2023

Another attempt, using a custom sync step to work around vercel/turbo#2306

  • builds on top of Setup turborepo #45
  • adds a sync-pnpm tool to sync the /dist output
  • adds an intermediate turbo task _build to call sync after build

Best reviewed by commit (first one is #45 squashed into one)

@changeset-bot
Copy link

changeset-bot bot commented Feb 16, 2023

⚠️ No Changeset found

Latest commit: 4c81454

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -101,7 +101,8 @@
"types": "./dist/*.d.ts",
"default": "./dist/*.js"
},
"./addon-main.js": "./addon-main.cjs"
"./addon-main.js": "./addon-main.cjs",
"./package.json": "./package.json"
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 a workaround for an unfortunate issue...

sync-pnpm needs to find the hard linked package resolvable from the test-app, which is like a copy of our original addon in the monorepo, just without /dist (which is the issue we need to fix here). But require.resolve('ember-headless-form') does not work, because its main field points to its ./dist/index.js, which des not exist before we have actually synced. So resolve throws.

Then I tried with this package that I found on npm, which basically tries to solve that issue: resolve-pkg. But running into sindresorhus/resolve-pkg#9.

So the workaround here is to make mypackage/package.json resolvable. Not ideal, but works for now. Not sure if we can do this in any other way. We want to delegate the node resolution algorithm to node itself and not re-invent this, but there seems to be no way to say "give me the module path that you would try to require, without actually throwing when it is not available".

Copy link
Contributor

Choose a reason for hiding this comment

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

does this one support exports? https://www.npmjs.com/package/resolve-package-path -- it's what auto-import uses

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to replicate the node module resolution, instead of delegating to node (like require.resolve), so probably that would work! Thanks for the suggestion, will try this out!

Related: sindresorhus/resolve-pkg#9 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will try this out!

It works! 🎉

@NullVoxPopuli
Copy link
Contributor

Total runtime is 22m: https://github.com/CrowdStrike/ember-headless-form/actions/runs/4194427919/usage

can you push an empty commit? hopefully that'd be a full cache hit

@simonihmig
Copy link
Contributor Author

Total runtime is 22m:

For the record, caching seems to be fixed now. Total runtime < 9min - https://github.com/CrowdStrike/ember-headless-form/actions/runs/4196887915/usage

Copy link
Contributor

@NullVoxPopuli NullVoxPopuli left a comment

Choose a reason for hiding this comment

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

Nice work!

Would be cool to see on ember-headless-table and ember-toucan-core, as well 🎉

@simonihmig
Copy link
Contributor Author

Would be cool to see on ember-headless-table and ember-toucan-core, as well 🎉

Yeah, which brings us to the topic of what to do with sync-pnpm. I put it here as a PoC. But if that's the thing we use to fix the issue, then we need to extract that to somewhere!?

@NullVoxPopuli
Copy link
Contributor

then we need to extract that to somewhere!?

I wonder if the turbo-repo folks would be interested in adopting it. I'll ask here: vercel/turbo#2306

@simonihmig
Copy link
Contributor Author

I'll hold this back until we have #44 merged, so I can integrate the docs setup here too...

@github-actions
Copy link
Contributor

github-actions bot commented Feb 20, 2023

Preview URLs

Env: preview
Docs: https://fa46d0ba.ember-headless-form.pages.dev

@simonihmig simonihmig force-pushed the turbo_try2 branch 2 times, most recently from 56fef0e to 1e61c65 Compare February 20, 2023 11:17
import { getPackages } from '@manypkg/get-packages';
import { findRoot } from '@manypkg/find-root';
import { readJson, pathExists } from 'fs-extra/esm';
import { hardLinkDir } from '@pnpm/fs.hard-link-dir';
Copy link
Contributor

Choose a reason for hiding this comment

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

Ahhhh - this is interesting!

Hard link (or copy if linking fails) all files from a directory to several target directories.

So essentially this sync file forces pnpm to hard link the dependencies one way or another so that we don't have to continually pnpm i -f anytime we make a change in the addon source and want to see it in the test-app/docs-app?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly. Also it does only this, it does not try to re-install/shuffle things around.

In an earlier attempt, I tried to just use pnpm i -f in a turbo step, but when things run in parallel, this would lead to weird errors, as pnpm i -f would temporarily remove things from node_modules and add them back moments later, but in the meantime some parallel build would just fail as it would miss some dependencies in node_modules.

So this does just adds back the missing hard links of our /dist folder, and nothing else.

Copy link
Contributor

Choose a reason for hiding this comment

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

Amazing!!

So is the current development process now (for something like docs-app):

  1. make a change in ember-headless-form
  2. pnpm build
  3. see the update in the docs-app?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly, that should work (assuming you have pnpm start or pnpm start:docs running, to continuously rebuild the app).

It is a bit of a regression compared to other v2 addon setups (e.g. using yarn), where this injected thing does not exist (but instead other peer dependency related problems), so you could just run start and it would watch the addon and the test-app. But not a regression compared to the previous state of this addon, because we had to run pnpm i -f again and again, so this should make it better at least!

Copy link
Contributor

Choose a reason for hiding this comment

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

(Definitely copying this for toucan-core)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just realized that the pnpm build script does too much for this use case, as it builds the addons and the apps (test and docs). Will need another iteration!

@simonihmig simonihmig merged commit b0b2a84 into main Feb 21, 2023
@simonihmig simonihmig deleted the turbo_try2 branch February 21, 2023 15:28
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

4 participants