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

[WB-1870] Adopt pnpm in Wonder Blocks #2453

Merged
merged 20 commits into from
Feb 5, 2025
Merged

[WB-1870] Adopt pnpm in Wonder Blocks #2453

merged 20 commits into from
Feb 5, 2025

Conversation

jandrade
Copy link
Member

@jandrade jandrade commented Feb 3, 2025

Summary:

  • Switched to pnpm.
  • Udpated most of the devDependencies to the latest version. Except eslint as
    the latest version is not compatible with our current setup.
  • Fixed TS errors in tests.
  • Fixed stories, lint, prettier, etc.
  • Updated rollup config to use pnpm (for builds).

Issue: WB-1870

Test plan:

Verify that all the checks pass and that the Storybook site works fine.

@jandrade jandrade self-assigned this Feb 3, 2025
Copy link

changeset-bot bot commented Feb 3, 2025

🦋 Changeset detected

Latest commit: ebc3f2a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 33 packages
Name Type
@khanacademy/wonder-blocks-progress-spinner Minor
@khanacademy/wonder-blocks-birthday-picker Minor
@khanacademy/wonder-blocks-labeled-field Minor
@khanacademy/wonder-blocks-search-field Minor
@khanacademy/wonder-blocks-testing-core Minor
@khanacademy/wonder-blocks-breadcrumbs Minor
@khanacademy/wonder-blocks-icon-button Minor
@khanacademy/wonder-blocks-typography Minor
@khanacademy/wonder-blocks-accordion Minor
@khanacademy/wonder-blocks-clickable Minor
@khanacademy/wonder-blocks-dropdown Minor
@khanacademy/wonder-blocks-popover Minor
@khanacademy/wonder-blocks-testing Minor
@khanacademy/wonder-blocks-theming Minor
@khanacademy/wonder-blocks-toolbar Minor
@khanacademy/wonder-blocks-tooltip Minor
@khanacademy/wonder-blocks-banner Minor
@khanacademy/wonder-blocks-button Minor
@khanacademy/wonder-blocks-layout Minor
@khanacademy/wonder-blocks-switch Minor
@khanacademy/wonder-blocks-timing Minor
@khanacademy/wonder-blocks-tokens Minor
@khanacademy/wonder-blocks-modal Minor
@khanacademy/wonder-blocks-cell Minor
@khanacademy/wonder-blocks-core Minor
@khanacademy/wonder-blocks-data Minor
@khanacademy/wonder-blocks-form Minor
@khanacademy/wonder-blocks-grid Minor
@khanacademy/wonder-blocks-icon Minor
@khanacademy/wonder-blocks-link Minor
@khanacademy/wonder-blocks-pill Minor
@khanacademy/wb-dev-build-settings Minor
@khanacademy/wb-codemod Minor

Not sure what this means? Click here to learn what changesets are.

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

Copy link
Contributor

github-actions bot commented Feb 3, 2025

A new build was pushed to Chromatic! 🚀

https://5e1bf4b385e3fb0020b7073c-bbxjfzdwew.chromatic.com/

Chromatic results:

Metric Total
Captured snapshots 380
Tests with visual changes 16
Total stories 543
Inherited (not captured) snapshots [TurboSnap] 0
Tests on the build 380

@jandrade jandrade changed the title [WB-1870] Addopt pnpm in Wonder Blocks [WB-1870] Adopt pnpm in Wonder Blocks Feb 4, 2025
Copy link
Member Author

Choose a reason for hiding this comment

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

note: I've marked this as minor as the bundled ES files didn't change too much. I only used minor mostly b/c rollup is upgrading from v2 to v4, but there shouldn't be breaking changes in WB packages.

.eslintrc.js Outdated
Copy link
Member Author

Choose a reason for hiding this comment

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

note: I had to modify some rules to account for some package updates, but it mostly affect tests, not prod code.

Copy link
Member Author

Choose a reason for hiding this comment

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

note: I created this custom action based on the one @jeresig created in the main repo (see ./github/actions/shared-node-cache/action.yml).

A bunch of files are now using this internal action instead of the external one to avoid breaking other repos that still rely on yarn.


- name: Verify changeset entries
uses: Khan/[email protected]
- uses: Khan/actions@check-for-changeset-v1
Copy link
Member Author

Choose a reason for hiding this comment

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

note: Reverted back to use Khan/actions@check-for-changeset-v1 as it doesn't rely on a package manager to resolve dependency changes.

The reason why Khan/changeset-per-package is no longer viable with pnpm is that this action relies heavily on yarn: https://github.com/Khan/changeset-per-package/blob/main/src/main.ts#L35

One thing to take into consideration is that the WB repo never got issues with check-for-changeset, so reverting back to it should be safe.

Copy link
Member Author

Choose a reason for hiding this comment

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

note: Updated some packages, and that needed to update the plugin references in here.

Comment on lines +31 to +41
async viteFinal(config, options) {
// Merge custom configuration into the default config
const {mergeConfig} = await import("vite");

return mergeConfig(config, {
// Prevent Vite from inlining phosphor-icons
build: {
assetsInlineLimit: 0,
},
});
},
Copy link
Member Author

Choose a reason for hiding this comment

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

note: I tried to define assetsInlineLimit directly in vite.config.ts but Storybook seems to have an issue reading that file, so I had to move that part here to avoid having issues with SVG rendering in Storybook.

Copy link
Member

Choose a reason for hiding this comment

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

Ohh interesting!

@@ -464,7 +464,7 @@ export const SingleSection: StoryComponentType = {
return (
<Accordion>
{[
<AccordionSection header="First section">
<AccordionSection header="First section" key={0}>
Copy link
Member Author

Choose a reason for hiding this comment

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

note: Added key in a bunch of story examples to prevent a browser warning where a collection of nodes need a specific key/id in React.

@@ -41,7 +41,7 @@ const createConfig = (pkgName) => {
presets,
plugins,
exclude: "node_modules/**",
runtimeHelpers: true,
babelHelpers: "runtime",
Copy link
Member Author

Choose a reason for hiding this comment

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

note: This API changed with rollup v4, so I just had to make it compatible.

"typecheck": "tsc",
"typewatch": "tsc --noEmit --watch --incremental",
"add:devdepbysha": "bash -c 'yarn add -W --dev \"git+https://[email protected]/Khan/$0.git#$1\"'"
"add:devdepbysha": "bash -c 'pnpm add -W --dev \"git+https://[email protected]/Khan/$0.git#$1\"'"
},
"author": "",
"license": "MIT",
"devDependencies": {
Copy link
Member Author

Choose a reason for hiding this comment

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

note: Used pnpm u -i --latest to update a bunch of dev dependencies in the repo. I tried to preserve or update to some specific versions in some cases to be compatible with webapp (e.g. babel).

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for updating our dev dependencies!

@@ -29,6 +30,6 @@
"react": "18.2.0"
},
"devDependencies": {
"@khanacademy/wb-dev-build-settings": "^2.0.0"
"@khanacademy/wb-dev-build-settings": "workspace:*"
Copy link
Member Author

Choose a reason for hiding this comment

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

note: modified this in all WB packages to manage build-settings as a workspace alias.

https://pnpm.io/workspaces#referencing-workspace-packages-through-aliases

Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, is there a reason why the other wonder-blocks dependencies don't use workspace:* as well? (ex: above we have "@khanacademy/wonder-blocks-clickable": "^6.0.0", instead of workspace:* also!)

Copy link
Member Author

Choose a reason for hiding this comment

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

That's an excellent question! I'm not sure why I didn't try that, but I don't see why not. My only concern would be that maybe changesets would need to find a way to figure out how to bump to the proper versions. I'll try to see what happens.

Copy link
Member Author

Choose a reason for hiding this comment

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

@beaesguerra I was looking at monorepos with similar tooling and it seems that it should work (in theory). But in order to test that properly, I'm going to land this into main, so we can get the "Check build sizes" workflow step running, then I'll experiment with it in a separate PR to see if something breaks and/or the bundled versions are affected. If that works, it would be really great as we would reduce the times we'd need to update package.json files, or it would simplify such updates. I'll keep you posted about this, and thanks for the suggestion/question!

Copy link
Member

Choose a reason for hiding this comment

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

Sounds like a good plan, thanks for looking into this!

@jandrade jandrade marked this pull request as ready for review February 4, 2025 17:49
@khan-actions-bot
Copy link
Contributor

Gerald

Required Reviewers
  • @Khan/wonder-blocks for changes to .eslintignore, .eslintrc.js, .gitignore, README.md, babel.config.js, jest.config.js, package.json, pnpm-lock.yaml, pnpm-workspace.yaml, vite.config.ts, vitest.config.ts, .changeset/polite-pianos-serve.md, .storybook/.babelrc.js, .storybook/main.ts, build-settings/babel.config.js, build-settings/check-type-definitions.ts, build-settings/rollup.config.mjs, utils/test-file-for.js, .github/workflows/chromatic-build.yml, .github/workflows/deploy.yml, .github/workflows/node-ci-lint.yml, .github/workflows/node-ci-pr.yml, .github/workflows/node-ci-push.yml, .github/workflows/node-ci-test.yml, .github/workflows/release.yml, __docs__/components/token-table.tsx, __docs__/wonder-blocks-accordion/accordion.stories.tsx, __docs__/wonder-blocks-banner/banner.argtypes.ts, __docs__/wonder-blocks-breadcrumbs/breadcrumbs.argtypes.ts, __docs__/wonder-blocks-button/button-variants.stories.tsx, __docs__/wonder-blocks-button/button.argtypes.ts, __docs__/wonder-blocks-cell/compact-cell.argtypes.tsx, __docs__/wonder-blocks-cell/compact-cell.stories.tsx, __docs__/wonder-blocks-cell/detail-cell.stories.tsx, __docs__/wonder-blocks-clickable/clickable-behavior.argtypes.ts, __docs__/wonder-blocks-clickable/clickable.argtypes.ts, __docs__/wonder-blocks-core/view.argtypes.ts, __docs__/wonder-blocks-dropdown/multi-select-variants.stories.tsx, __docs__/wonder-blocks-dropdown/multi-select.stories.tsx, __docs__/wonder-blocks-dropdown/single-select-variants.stories.tsx, __docs__/wonder-blocks-dropdown/single-select.stories.tsx, __docs__/wonder-blocks-form/labeled-text-field.argtypes.ts, __docs__/wonder-blocks-form/text-field.argtypes.ts, __docs__/wonder-blocks-icon/phosphor-icon.argtypes.ts, __docs__/wonder-blocks-icon/phosphor-icon.stories.tsx, __docs__/wonder-blocks-link/link.argtypes.tsx, __docs__/wonder-blocks-modal/one-pane-dialog.argtypes.ts, __docs__/wonder-blocks-pill/pill.stories.tsx, __docs__/wonder-blocks-popover/popover-content.argtypes.tsx, __docs__/wonder-blocks-switch/switch-variants.stories.tsx, config/jest/test.config.js, packages/wonder-blocks-accordion/package.json, packages/wonder-blocks-banner/package.json, packages/wonder-blocks-birthday-picker/package.json, packages/wonder-blocks-breadcrumbs/package.json, packages/wonder-blocks-button/package.json, packages/wonder-blocks-cell/package.json, packages/wonder-blocks-clickable/package.json, packages/wonder-blocks-core/package.json, packages/wonder-blocks-data/package.json, packages/wonder-blocks-dropdown/package.json, packages/wonder-blocks-form/package.json, packages/wonder-blocks-grid/package.json, packages/wonder-blocks-icon/package.json, packages/wonder-blocks-icon-button/package.json, packages/wonder-blocks-labeled-field/package.json, packages/wonder-blocks-layout/package.json, packages/wonder-blocks-link/package.json, packages/wonder-blocks-modal/package.json, packages/wonder-blocks-pill/package.json, packages/wonder-blocks-popover/package.json, packages/wonder-blocks-progress-spinner/package.json, packages/wonder-blocks-search-field/package.json, packages/wonder-blocks-switch/package.json, packages/wonder-blocks-testing/package.json, packages/wonder-blocks-testing-core/package.json, packages/wonder-blocks-theming/package.json, packages/wonder-blocks-timing/package.json, packages/wonder-blocks-tokens/package.json, packages/wonder-blocks-toolbar/package.json, packages/wonder-blocks-tooltip/package.json, packages/wonder-blocks-typography/package.json, utils/publish/publish-snapshot.sh, utils/testing/expect-render-error.tsx, wb-codemod/bin/cli.js, wb-codemod/src/wb-codemod.js, .github/actions/shared-node-cache/action.yml, packages/wonder-blocks-testing-core/src/respond-with.ts, packages/wonder-blocks-testing-core/src/response-impl.ts, packages/wonder-blocks-button/src/components/button-core.tsx, packages/wonder-blocks-core/src/components/view.tsx, packages/wonder-blocks-data/src/components/data.ts, packages/wonder-blocks-data/src/hooks/use-cached-effect.ts, packages/wonder-blocks-data/src/hooks/use-hydratable-effect.ts, packages/wonder-blocks-data/src/util/data-error.ts, packages/wonder-blocks-data/src/util/gql-error.ts, packages/wonder-blocks-data/src/util/graphql-document-node-parser.ts, packages/wonder-blocks-dropdown/src/components/action-menu.tsx, packages/wonder-blocks-dropdown/src/components/combobox.tsx, packages/wonder-blocks-dropdown/src/components/dropdown-core-virtualized.tsx, packages/wonder-blocks-dropdown/src/components/dropdown-core.tsx, packages/wonder-blocks-dropdown/src/components/multi-select.tsx, packages/wonder-blocks-dropdown/src/components/single-select.tsx, packages/wonder-blocks-icon/src/components/phosphor-icon.tsx, packages/wonder-blocks-icon/src/util/icon-util.ts, packages/wonder-blocks-icon-button/src/util/icon-button-util.ts, packages/wonder-blocks-layout/src/util/test-util.ts, packages/wonder-blocks-link/src/components/link-core.tsx, packages/wonder-blocks-modal/src/components/focus-trap.tsx, packages/wonder-blocks-modal/src/components/modal-backdrop.tsx, packages/wonder-blocks-modal/src/components/modal-launcher.tsx, packages/wonder-blocks-modal/src/util/maybe-get-portal-mounted-modal-host-element.test.tsx, packages/wonder-blocks-popover/src/components/focus-manager.tsx, packages/wonder-blocks-popover/src/components/initial-focus.ts, packages/wonder-blocks-popover/src/components/popover-anchor.ts, packages/wonder-blocks-popover/src/components/popover-event-listener.ts, packages/wonder-blocks-popover/src/components/popover.tsx, packages/wonder-blocks-testing-core/src/harness/adapt.tsx, packages/wonder-blocks-testing-core/src/harness/types.ts, packages/wonder-blocks-toolbar/src/components/toolbar.tsx, packages/wonder-blocks-tooltip/src/components/tooltip-anchor.tsx, packages/wonder-blocks-tooltip/src/util/ref-tracker.ts, packages/wonder-blocks-data/src/hooks/__tests__/use-cached-effect.test.tsx, packages/wonder-blocks-data/src/util/__tests__/serializable-in-memory-cache.test.ts, packages/wonder-blocks-dropdown/src/components/__tests__/multi-select.test.tsx, packages/wonder-blocks-modal/src/components/__tests__/modal-launcher.test.tsx, packages/wonder-blocks-testing-core/src/harness/__tests__/types.typestest.tsx, packages/wonder-blocks-testing-core/src/harness/adapters/error-boundary.tsx, packages/wonder-blocks-timing/src/util/__tests__/animation-frame.test.ts, packages/wonder-blocks-tooltip/src/components/__tests__/tooltip-bubble.test.tsx, packages/wonder-blocks-testing-core/src/harness/adapters/__tests__/error-boundary.test.tsx

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

@khan-actions-bot khan-actions-bot requested a review from a team February 4, 2025 17:49
@jandrade jandrade requested a review from a team February 4, 2025 17:52
Copy link
Contributor

github-actions bot commented Feb 4, 2025

npm Snapshot: Published

🎉 Good news!! We've packaged up the latest commit from this PR (7834dd9) and published all packages with changesets to npm.

You can install the packages in webapp by running:

./services/static/dev/tools/deploy_wonder_blocks.js --tag="PR2453"

Packages can also be installed manually by running:

pnpm add @khanacademy/wonder-blocks-<package-name>@PR2453

Copy link
Member

@beaesguerra beaesguerra left a comment

Choose a reason for hiding this comment

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

Looks good! I left some questions for my own learning 😄 Thanks for switching us to pnpm in WB 🎉

"typecheck": "tsc",
"typewatch": "tsc --noEmit --watch --incremental",
"add:devdepbysha": "bash -c 'yarn add -W --dev \"git+https://[email protected]/Khan/$0.git#$1\"'"
"add:devdepbysha": "bash -c 'pnpm add -W --dev \"git+https://[email protected]/Khan/$0.git#$1\"'"
},
"author": "",
"license": "MIT",
"devDependencies": {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for updating our dev dependencies!

@@ -29,6 +30,6 @@
"react": "18.2.0"
},
"devDependencies": {
"@khanacademy/wb-dev-build-settings": "^2.0.0"
"@khanacademy/wb-dev-build-settings": "workspace:*"
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, is there a reason why the other wonder-blocks dependencies don't use workspace:* as well? (ex: above we have "@khanacademy/wonder-blocks-clickable": "^6.0.0", instead of workspace:* also!)

@@ -23,6 +22,7 @@ describe("SerializableInMemoryCache", () => {

it("should throw if the cloning fails", () => {
// Arrange
const WSCore = require("@khanacademy/wonder-stuff-core");
Copy link
Member

Choose a reason for hiding this comment

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

For my own learning, how come we had to change how we were importing WSCore?

Copy link
Member Author

Choose a reason for hiding this comment

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

TBH I changed devDeps and at some point those tests started to break. I don't recall changing anything related to Jest, so this was surprising to me. I applied this solution as I encountered similar situations in webapp and/or WB in the past and that solved the issue.

My guess is that pnpm is not able to import the same dependency that is used in the implementation, so the mock is never called. I switched to this approach to ensure that we always import/require the right dep. It might have to do with the fact that Jest still uses CJS for testing (where as the code uses ES Modules).

Copy link
Member

@jeresig jeresig left a comment

Choose a reason for hiding this comment

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

Changes all look reasonable to me - glad you were able to find a good solution here!

Comment on lines +31 to +41
async viteFinal(config, options) {
// Merge custom configuration into the default config
const {mergeConfig} = await import("vite");

return mergeConfig(config, {
// Prevent Vite from inlining phosphor-icons
build: {
assetsInlineLimit: 0,
},
});
},
Copy link
Member

Choose a reason for hiding this comment

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

Ohh interesting!

@jandrade jandrade merged commit f03298f into main Feb 5, 2025
13 of 14 checks passed
@jandrade jandrade deleted the pnpm-migration branch February 5, 2025 21:49
Copy link

codecov bot commented Feb 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (c4914ee) to head (ebc3f2a).
Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@     Coverage Diff      @@
##   main   #2453   +/-   ##
============================
============================

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c4914ee...ebc3f2a. Read the comment docs.

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.

4 participants