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

Infra: Switch monorepo tooling to wireit and pnpm #2345

Merged
merged 145 commits into from
Jul 22, 2022
Merged

Conversation

ryan-roemer
Copy link
Member

@ryan-roemer ryan-roemer commented Jun 30, 2022

This PR is a big infrastructure overhaul to switch us from lerna + yarn to wireit + pnpm.

Why?

Our existing setup of yarn + lerna has the following undesirable things:

  1. Installs are slow on yarn
  2. Yarn1 isn't updated anymore and simple package dependency updates don't work out of the box. It's a huge pain to update anything.
  3. Lerna is getting old, and while the NX team has agreed to support it now, our build is (1) slow, (2) not cached at all, and (3) opaque as to what you need to run task-wise to support other tasks.

So, let's welcome PNPM + Wireit!

  1. PNPM is a fast installer and well supported for normal things like package upgrades.
  2. Wireit allows fine-grained subtask caching and dependency specifications to allow us to: (1) specify dependencies so when you run pnpm run jest all the other things that need to happen magically happen, (2) caches sub-tasks so things that don't have changed file inputs don't re-run, and (3) has full GH actions CI support!

To get a sense of how much faster our build has become take a look at the CI times for this branch in https://github.com/FormidableLabs/victory/actions?query=branch%3Ainfra%2Fpnpm-wireit++ -- when no input files change our CI times are about 1 minute. When some things change, a couple minutes. When all things (or our base scripts) change, we take the full hit of a comparable existing Victory CI time of like 15-16 mins.

For the average Victory developer, if you're working in just one package, you can just run the project-level pnpm run check and have like a full build and everything work reasonably fast without needing to know more or run subtasks!

Check it out

$ npm install -g pnpm
$ pnpm install
# This will be slow!
$ pnpm run check

# ... but the second time will be super fast! And as you change things subsequent runs should be very fast!
$ pnpm run check

Implementation notes

  • High level:

    • Dependency graph architecture: All of our tasks now use wireit to identify and run/cache dependencies. So, if you want to run jest, you just run pnpm run jest and don't need to worry about "what else needs to be built?" before that.
    • Parallelization: To best use wireit, we've refactored our tasks to be more package-specific where possible. E.g., we run lint in incremental mode per-package meaning that both Wireit (at package level) and eslint (at file level within package) re-execute on the narrowest unit of "changed files" possible.
  • Demos: The demos originally had imports from victory*/src/index (source) which wasn't efficient or consistent because the transitive deps on other victory packages was on built files. I refactored these to be normal victory(-<NAME>) imports using built files.

  • src:

    • Since we did a "fresh" install with pnpm, there were some updates in lint packages that meant source or tests needed small tweaks to continue passing/building.
    • Refactor self-references within a package to not use package name.
    • Fixed missing package dependencies uncovered as pnpm-based installs will fail on missing dependencies that are flattened and "accidentally work" in yarn/npm.
  • Configs:

    • Webpack resolve.alias: Since we no longer hoist victory packages to root, we now add aliases for our webpack configs and storybook (which uses webpack) programatically.
    • Babel, Jest configs: Normalized the naming and location of these across normal and native ones.
  • Incremental caching:

    • eslint

Remaining work in this PR

Big tasks:

  • Victory Native: We need to check that everything still works for reals in RN and for our demos.
  • Chromatic: We use chromatic mainly through GH actions which don't need changes. But we also have localdev tasks to test things out. Should be straightforward.
  • Docs: This is still an independent install via yarn. Should work, but let's check.
  • Watch support: Something reasonable for most workflows out of the gate. Ticket the rest.
    • start*
    • check
    • build: Might combine with check (?)
  • Fix scripts: We have to pass different "fix" flags to things. Let's aggregate to individual and meta-tasks.

All the rest:

  • Update all tasks, workflows, and guides in CONTRIBUTING.md
  • Configure wireit package locks Needed customization for PNPM and we should identify which subtasks should have a package log dep. Add pnpm-lock.yaml as files field for some tasks.
  • Search on
    • yarn
    • lerna
    • nps (direct uses)
    • TODO(wireit)
    • TODO(pnpm)

Remaining work (ticketed)

Incremental caching: Investigate opportunities for tool-level incremental caching. #2375

Various things

Copy link
Member

@scottrippey scottrippey left a comment

Choose a reason for hiding this comment

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

Looking good so far! So excited about the initial results.
Excellent idea to automate the wireit config!

packages/victory-canvas/package.json Show resolved Hide resolved
packages/victory-vendor/package.json Show resolved Hide resolved
scripts/sync-pkgs-wireit.js Outdated Show resolved Hide resolved
scripts/sync-pkgs-wireit.js Outdated Show resolved Hide resolved
scripts/sync-pkgs-wireit.js Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to staging-2345 July 19, 2022 21:19 Inactive
@github-actions github-actions bot temporarily deployed to staging-2345 July 19, 2022 21:52 Inactive
@github-actions github-actions bot temporarily deployed to staging-2345 July 19, 2022 22:09 Inactive
@github-actions github-actions bot temporarily deployed to staging-2345 July 20, 2022 22:11 Inactive
@github-actions github-actions bot temporarily deployed to staging-2345 July 20, 2022 22:52 Inactive
@ryan-roemer ryan-roemer changed the title [WIP] Infra: Switch monorepo tooling to wireit and pnpm Infra: Switch monorepo tooling to wireit and pnpm Jul 20, 2022
@ryan-roemer ryan-roemer marked this pull request as ready for review July 20, 2022 23:04
package.json Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to staging-2345 July 21, 2022 21:59 Inactive
Copy link
Member

@scottrippey scottrippey left a comment

Choose a reason for hiding this comment

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

Well I did a spot-check of several of the --watch workflows, and I'm thrilled!
It's awesome how we can just jump into packages/victory-line and run pnpm run jest and it just works! Pulls from all previous cache's. Detects changes instantly, and reruns very fast.

LGTM!

@github-actions github-actions bot temporarily deployed to staging-2345 July 22, 2022 17:48 Inactive
Copy link
Contributor

@gksander gksander left a comment

Choose a reason for hiding this comment

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

This is AWESOME. 🎈

@github-actions github-actions bot temporarily deployed to staging-2345 July 22, 2022 19:05 Inactive
@ryan-roemer ryan-roemer merged commit 1aaa85f into main Jul 22, 2022
@ryan-roemer ryan-roemer deleted the infra/pnpm-wireit branch July 22, 2022 19:21
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.

3 participants