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

chore: migrate from yarn to pnpm #4897

Closed
wants to merge 43 commits into from
Closed

Conversation

cardoso
Copy link
Contributor

@cardoso cardoso commented Nov 20, 2024

Details

I'm still going through all scripts and haven't touched CI yet, but this is mostly working.

I don't know what external workflows might depend on things like the versions being spelled out in package.json and could break by using workspace:* and others. I initially made it work without that feature, so I can revert back to spelled out versions if needed.

Since pnpm doesn’t hoist dependencies to the root by default, it uncovers several issues similar to

I’m submitting fixes for those separately to make sure they are correct.

I recommend cloning in a separate folder or running git clean -dfX before trying this out.

pnpm version used: 9.14.2.

Closes #4426

Top-level package.json scripts I tested so far:

  • prepare
  • lint
  • format
  • bundlesize,
  • build
  • build:performance
  • build:performance:components
  • build:performance:benchmarks
  • copy-fork
  • dev
  • test
  • test:bespoke,
  • test:debug
  • test:ci
  • test:karma
  • test:karma:start
  • test:integration
  • test:performance
  • test:performance:best
  • test:performance:best:ci
  • test:types
  • release:version
  • release:publish

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.

GUS work item

@cardoso cardoso requested a review from a team as a code owner November 20, 2024 20:59
Copy link
Collaborator

@nolanlawson nolanlawson 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 looking good so far. I'm surprised so many changed are needed for pnpm, but I do like the workspace:* thing.

One thing missing: this code to build the benchmarks will need to run yarn or pnpm:

'yarn --immutable',
// bust the Tachometer cache in case these files change locally
`echo '${directoryHash}'`,
'yarn build:performance:components',

The reason is that it is going to compare the current master against an arbitrary commit from the past. Since that arbitrary commit might be using yarn, I'd suggest checking if [ -f yarn.lock ] inline.

@cardoso
Copy link
Contributor Author

cardoso commented Nov 21, 2024

@nolanlawson thank you for looking into this! I'll see what I can do about the benchmark scripts. I left them for last since it takes a while to fully run.

The changes in src are mostly due to the non-flat structure of node_modules, which actually helps figure out some "phantom" and cyclic dependencies since they break pnpm i or type-checking. I'm trying to move the changes to separate PRs though.

Copy link
Collaborator

@nolanlawson nolanlawson left a comment

Choose a reason for hiding this comment

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

LGTM overall. It'll take some muscle memory for me to remember to type pnpm instead of yarn (also a bit more awkward to type 😆) but overall this is a great change. We were sticking with yarn v1 for way too long.

Also: the Tachometer tests work now! I guess we will just "shamefully hoist" 🤷

Thanks a lot!! ❤️

.npmrc Show resolved Hide resolved
@nolanlawson
Copy link
Collaborator

/nucleus test

Co-authored-by: Nolan Lawson <[email protected]>
@nolanlawson
Copy link
Collaborator

/nucleus test

@nolanlawson
Copy link
Collaborator

I can repro the above SauceLabs issue:

  require() of ES Module /Users/nlawson/workspace/lwc/node_modules/.pnpm/[email protected]/node_modules/got/dist/source/index.js from 
/Users/nlawson/workspace/lwc/node_modules/.pnpm/[email protected]/node_modules/saucelabs/build/index.js not 
supported.
Instead change the require of /Users/nlawson/workspace/lwc/node_modules/.pnpm/[email protected]/node_modules/got/dist/source/index.js in 
/Users/nlawson/workspace/lwc/node_modules/.pnpm/[email protected]/node_modules/saucelabs/build/index.js to a 
dynamic import() which is available in all CommonJS modules.

I'll dig into it since you need SauceLabs credentials in order to repro. Not sure why the pnpm change exposed this.

@nolanlawson
Copy link
Collaborator

After some fruitless debugging, I am quite lost. I cannot even figure out how to run the karma scripts with --inspect-brk so that I can debug. pnpm seems to be doing some magic under the hood that is causing weird issues like the ESM/CJS compat issue above. (BTW you can repro in the integration-karma dir using pnpm run start.)

Maybe we can switch to pnpm once require(esm) is shipped in Node v22. I am also still fine with upgrading to latest npm or latest yarn. Thanks again for all your help on this!

@cardoso
Copy link
Contributor Author

cardoso commented Nov 25, 2024

@nolanlawson that's weird... I can't repro here. pnpm run start works fine in integration-karma.

@cardoso
Copy link
Contributor Author

cardoso commented Nov 26, 2024

@nolanlawson actually, the pinned got version wasn't compatible with sauce. I unpinned it and that issue should be fixed.

This wasn't pinned originally, so I don't think it should block this PR.

packages/@lwc/integration-karma > [email protected] > [email protected] > [email protected] > [email protected] > [email protected]

Ref: GHSA-pfrx-2q88-qq97

@nolanlawson
Copy link
Collaborator

nolanlawson commented Nov 26, 2024

Ahhh, that makes sense! I didn't consider that it was the overrides that did it.

BTW I opened #4946 to fix the subdir issue. No need to do it here.

I'm going to do some research into how to do inspect-brk with pnpm but other than that I guess we are good to go! Thanks. 🙇

@nolanlawson
Copy link
Collaborator

/nucleus test

@cardoso
Copy link
Contributor Author

cardoso commented Nov 26, 2024

@nolanlawson maybe you need to do pnpm [command] -- --inspect-brk? pnpm doesn't forward the args the same way as yarn v1.

@nolanlawson
Copy link
Collaborator

Figured out the trick. To run the karma tests in the integration-karma dir, you can do:

NODE_OPTIONS=--inspect-brk ../../../node_modules/.bin/karma start \
    ./scripts/karma-configs/test/local.js --single-run --browsers ChromeHeadless

This is fine – it's just "one of those things you need to know" for pnpm I guess. The ../../../node_modules/.bin/karma is converted by pnpm from a Node script into a bash script (🤯) so you can also modify the node command inside of it to add --inspect-brk.

@nolanlawson
Copy link
Collaborator

/nucleus test

@nolanlawson
Copy link
Collaborator

/nucleus test

@nolanlawson
Copy link
Collaborator

Ugggghh... I just remembered something. Our internal tool for testing downstream repos, Nucleus, does not support pnpm. It only supports npm and yarn. 😞

I think we will either need to switch to npm or latest yarn. Sorry for the runaround @cardoso – I totally forgot until just now.

My personal preference is for latest npm. Don't feel obligated – I can do the conversion.

@cardoso
Copy link
Contributor Author

cardoso commented Nov 26, 2024

@nolanlawson ouch! That was close 😅. Yeah, since I don't have access to nucleus, I'll leave it to you. Not sure if anything here can be reused, so feel free to close this PR.

@nolanlawson
Copy link
Collaborator

Closing for now, would be happy to revisit later!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate from yarn to pnpm
3 participants