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 single char packages in yarn berry #29

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/parseYarnDescriptor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* A regular expression for parsing a yarn berry descriptor.
*/
const PARSE_REGEX = /(^@?[^/]+?\/?[^@/]+?)@(?:.*:)*(.+)/;
const PARSE_REGEX = /(?<packageName>(^@?[^/]+?\/)?[^@/]+?)@(?:.*:)*(?<version>.+)/;

/**
* @typedef {Object} ParsedDescriptor
Expand Down Expand Up @@ -39,7 +39,8 @@ function parseYarnDescriptor(descriptor) {
if (!result) {
throw new Error(`Unable to parse descriptor: ${descriptor}`);
}
const [, packageName, version] = result;

const { packageName, version } = result.groups;
return { packageName, version };
}

Expand Down
7 changes: 7 additions & 0 deletions test/parse-yarn-descriptor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ describe('parse-yarn-descriptor', () => {
});
});

it('should parse a single char yarn berry descriptor with protocol', () => {
expect(parseYarnDescriptor('q@npm:1.0.0')).toEqual({
packageName: 'q',
version: '1.0.0',
});
});

it('should throw an error if the descriptor is invalid', () => {
expect(() => parseYarnDescriptor('invalid')).toThrow();
});
Expand Down
Loading