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 support for Yarn patch protocol #887

Merged

Conversation

petermetz
Copy link
Contributor

Description

Introduced logic that transparently handles the patch protocol version syntax by falling back
to the base version string.

#223
https://yarnpkg.com/cli/patch

Fixes #223

Signed-off-by: Peter Somogyvari peter.metz@unarin.com

Motivation and Context

I have third-party packages in our monorepo that ship with issues that I need to patch in a yarn v4 build setup.

Without this change lerna-lite crashes if we are using it in a project that has any yarn patch protocol usage.

#223

How Has This Been Tested?

  1. Manually in the repo at https://github.com/hyperledger/cacti
    1.1. We made changes to third party dependencies (code in the node_modules folder)
    1.2. We committed said changes with yarn patch
    1.3. The build was broken
    1.4. Applied this fix to lerna-lite and now the build is working again.
  2. Automated tests were added as well with our exact use-case see package-graph.spec.ts

Types of changes

  • Chore (change that has absolutely no effect on users)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link

codecov bot commented Jul 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.96%. Comparing base (d011168) to head (413a836).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #887      +/-   ##
==========================================
+ Coverage   97.96%   97.96%   +0.01%     
==========================================
  Files         145      145              
  Lines        8852     8856       +4     
  Branches     2224     2226       +2     
==========================================
+ Hits         8671     8675       +4     
  Misses        180      180              
  Partials        1        1              

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

);
const node = new PackageGraph([pkg]).get('my-pkg');

console.log('node=', node);
Copy link
Member

Choose a reason for hiding this comment

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

we probably don't need this console.log, do we? If not please remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ghiscoding Oops, that was left there by accident, apologies. Sending an update soon!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ghiscoding Removed the logging, please see the updated sources!

// Yarn decided to ignore https://github.com/npm/npm/pull/15900 and implemented "link:"
// As they apparently have no intention of being compatible, we have to do it for them.
// @see https://github.com/yarnpkg/yarn/issues/4212
let spec = graphDependencies[depName].replace(/^link:/, 'file:');
let spec = graphDependencies[depName].replace(/^link:/, 'file:').replace(YARN_PATCH_PROTOCOL_REG_EXP, '$2');
Copy link
Member

@ghiscoding ghiscoding Jul 5, 2024

Choose a reason for hiding this comment

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

I wonder if this will have a perf impact? Wouldn't it be better to make sure that the substring does really start with the text "patch:", the previous check of /^link:/ does that with the use of ^ but you're not using it in your regex, so I think it might better to validate the starting text and do something like this maybe

if (spec.startsWith('patch:')) {
  spec = spec.replace(YARN_PATCH_PROTOCOL_REG_EXP, '$2');
}

what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ghiscoding I agree it's more readable and most likely more performant that way as well, thank you for the great suggestion, I updated it exactly like that!

@ghiscoding
Copy link
Member

ghiscoding commented Jul 5, 2024

@petermetz apart from the 2 comments, the concept looks good, short and sweet :)

Transparently handles the patch protocol version syntax by falling back
to the base version string.

lerna-lite#223
https://yarnpkg.com/cli/patch

Fixes lerna-lite#223

Signed-off-by: Peter Somogyvari <peter.metz@unarin.com>
@petermetz petermetz force-pushed the feat-support-yarn-patch-protocol branch from 5c4e706 to 413a836 Compare July 5, 2024 21:00
@petermetz petermetz requested a review from ghiscoding July 5, 2024 21:01
@petermetz
Copy link
Contributor Author

@petermetz apart from the 2 comments, the concept looks good, short and sweet :)

@ghiscoding Thank you, I made the changes! I left the conversations unresolved: I wasn't sure if you prefer to resolve them yourself or not.

@ghiscoding ghiscoding merged commit 05579ab into lerna-lite:main Jul 5, 2024
6 checks passed
@ghiscoding
Copy link
Member

Great, it looks good now, ready to merge

@petermetz petermetz deleted the feat-support-yarn-patch-protocol branch July 5, 2024 21:20
@petermetz
Copy link
Contributor Author

Great, it looks good now, ready to merge

@ghiscoding Nice! Thank you very much for the quick turnaround!!!

@ghiscoding
Copy link
Member

all good, I wanted to push a new release by tomorrow anyway so the timing is good.
Now available in v3.7.0 thanks again

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.

Support for patch: protocol
2 participants