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

feat: add Yarnrc component for YARN_BERRY #3048

Merged
merged 22 commits into from
Nov 6, 2023

Conversation

blimmer
Copy link
Contributor

@blimmer blimmer commented Oct 27, 2023

Description

This PR significantly improves projen's ability to use Yarn Berry.

Relates to #2980

Known Limitations

  • There's not a way to pass plugins yet. When you run yarn plugin import <plugin name>, it writes to .yarnrc.yml and stores the plugin code in .yarn. We'll have to figure out the best way to handle that. The good news is that Yarn v4 includes the most common plugins by default again.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor Author

@blimmer blimmer left a comment

Choose a reason for hiding this comment

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

@mrgrain - I had some time today to work on this. Could you take a look at the inline questions on this draft PR review? Once I get confirmation on how you'd like to proceed, I can finish this up and get it ready for review.

TYIA!

docs/node.md Show resolved Hide resolved
src/javascript/node-package.ts Outdated Show resolved Hide resolved
src/javascript/node-package.ts Show resolved Hide resolved
src/javascript/yarnrc.ts Outdated Show resolved Hide resolved
src/javascript/yarnrc.ts Outdated Show resolved Hide resolved
src/javascript/yarnrc.ts Outdated Show resolved Hide resolved
src/javascript/yarnrc.ts Outdated Show resolved Hide resolved
src/javascript/yarnrc.ts Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Oct 27, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5ca5f6e) 96.34% compared to head (f1e6b78) 96.40%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3048      +/-   ##
==========================================
+ Coverage   96.34%   96.40%   +0.06%     
==========================================
  Files         185      186       +1     
  Lines       34566    35090     +524     
  Branches     3208     3244      +36     
==========================================
+ Hits        33302    33828     +526     
+ Misses       1264     1262       -2     
Files Coverage Δ
src/javascript/index.ts 100.00% <100.00%> (ø)
src/javascript/node-package.ts 95.53% <100.00%> (+0.38%) ⬆️
src/javascript/yarnrc.ts 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


private configureYarnBerry(project: Project, options: NodePackageOptions) {
const {
version = "4.0.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

corepack requires a fully qualified version for the packageManager property. If you provide values like yarn@4, yarn@stable, yarn@~4, etc. you get this error:

Usage Error: Invalid package manager specification in package.json; expected a semver version

$ yarn ...

So, unfortunately, we have to specify a full version here.

Copy link
Contributor

@mrgrain mrgrain Oct 30, 2023

Choose a reason for hiding this comment

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

Ugh. That's annoying. How about we make the version a required option?

Copy link
Contributor Author

@blimmer blimmer Oct 30, 2023

Choose a reason for hiding this comment

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

How would that work if people didn't provide yarnBerryOptions at all? e.g.,

const project = new javascript.NodeProject({
  // ...
  packageManager: javascript.NodePackageManager.YARN_BERRY,
});

Would we throw a runtime error? I'm not sure if that'll be annoying to folks.

I suppose we could introduce it only for YARN_BERRY and not YARN2. YARN2 could not write a .yarnrc.yml file, giving people more time to transition.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that's annoying. I think we might be able to turn javascript.NodePackageManager into an enum like class. With static props for the existing values and YARN_BERRY() a static method that requires a version?

Which feels like what we would really need to do for all corepack package managers?! So we'd end up having an interface like this:

const project = new javascript.NodeProject({
  // Corpack
  packageManager: javascript.CorePack.yarn('1.23.1'),
  packageManager: javascript.CorePack.yarn('4.0.1'),
  packageManager: javascript.CorePack.pnpm('8.0.0'),
  packageManager: javascript.CorePack.npm('100.0'),

 // pre-installed 
  packageManager: javascript.NodePackageManager.NPM,
  packageManager: javascript.NodePackageManager.PNPM,
  packageManager: javascript.NodePackageManager.YARN_CLASSIC,
  packageManager: javascript.NodePackageManager.YARN_BERRY,
});

The pre-installed ones maybe just all need to be deprecated right away? Or at least for YARN_BERRY which recommends corepack.

But let's do this separately. Happy to keep the default version for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good - I filed #3070 to track that. FYI, npm is the only one that cannot be managed by corepack (lol). If we're cool leaving the default version for now, this is ready for review & merge.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep. I'll give it a final review tomorrow.

src/javascript/node-package.ts Outdated Show resolved Hide resolved
@blimmer blimmer marked this pull request as ready for review October 28, 2023 16:46
Copy link
Contributor

@mrgrain mrgrain left a comment

Choose a reason for hiding this comment

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

Good stuff! Obviously we should automated the options, but we don't have infrastructure for this. 🤷🏻

@blimmer
Copy link
Contributor Author

blimmer commented Nov 1, 2023

Btw, although this isn't directly related, we might be getting some nice Corepack reliability improvements in berry: yarnpkg/berry#5912

@mergify mergify bot merged commit 7a3883a into projen:main Nov 6, 2023
13 checks passed
mergify bot pushed a commit that referenced this pull request Nov 7, 2023
Fixes issue introduced with #3048.

We should allow people to set potentially conflicting values to the same value. Previously, I was just checking to see if they were both set at the same time.

---
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
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