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

Add support for yarn-berry lockfiles #28

Merged
merged 5 commits into from
Jul 11, 2023
Merged

Conversation

mikeduminy
Copy link
Contributor

@mikeduminy mikeduminy commented Jul 4, 2023

Added support for parsing yarn-berry lockfiles (they are pure yaml).

We can no longer look up dependencies by package@version because berry adds additional things like a protocol (e.g. package@protocol:version), so there's now a regex (with tests) that strips out the protocol.

An argument could be made that this should be a separate command, like npm and yarn. Let me know what feels best.

Also, maybe this could be a berry plugin? I'm not sure what the capabilities are.

@oblador
Copy link
Owner

oblador commented Jul 5, 2023

Been a whike since i looked into berry, but yes i think it can be solved to some degree with config instead, although at potentially higher maintenance cost.

Btw, have you looked into this package that seems to support both formats? https://www.npmjs.com/package/@yarnpkg/parsers

@mikeduminy
Copy link
Contributor Author

That works even better, good idea!

Copy link
Owner

@oblador oblador left a comment

Choose a reason for hiding this comment

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

Worth mentioning in README that it supports berry maybe?


it('should parse a yarn berry descriptor with scope', () => {
expect(parseYarnDescriptor('@snel/[email protected]')).toEqual({
packageName: '@snel/hest',
Copy link
Owner

Choose a reason for hiding this comment

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

* @param {string} descriptor - The yarn berry descriptor to parse.
* @returns {ParsedDescriptor} The parsed descriptor.
*/
function parseYarnDescriptor(descriptor) {
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
function parseYarnDescriptor(descriptor) {
function parseBerryDescriptor(descriptor) {

Maybe? I was worried this regex would slow down non-berry users at first glance. Speaking of that, how's the perf with a large berry workspace like yours?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Performance looks good. Only adds ~4% increase in time in a large project

Before PR:

  Time (mean ± σ):      4.028 s ±  0.101 s    [User: 3.634 s, System: 0.342 s]
  Range (min … max):    3.935 s …  4.207 s    10 runs

After PR:

  Time (mean ± σ):      4.121 s ±  0.152 s    [User: 3.748 s, System: 0.328 s]
  Range (min … max):    3.975 s …  4.453 s    10 runs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As for the suggestion, this function parses both yarn v1 and berry descriptors. At the time of calling it we don't know which version of yarn lockfile we are parsing. Unless of course we interpret the "metadata" value in the parse result, but that's a bit messy.

I can clarify that this parses both descriptors in the JSDoc

Copy link
Owner

Choose a reason for hiding this comment

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

Sweet, makes sense!

package.json Outdated Show resolved Hide resolved
Co-authored-by: Joel Arvidsson <[email protected]>
@oblador
Copy link
Owner

oblador commented Jul 11, 2023

@mikeduminy Need to update lock file too.

@mikeduminy
Copy link
Contributor Author

mikeduminy commented Jul 11, 2023

@oblador done!

@oblador oblador merged commit 5908131 into oblador:master Jul 11, 2023
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.

2 participants