diff --git a/lib/parsers/yarn-utils.ts b/lib/parsers/yarn-utils.ts index 71ad63e5..d4198dda 100644 --- a/lib/parsers/yarn-utils.ts +++ b/lib/parsers/yarn-utils.ts @@ -8,12 +8,18 @@ export type ParseResolution = typeof parseResolution; const keyNormalizer = (resolutionParser: ParseResolution) => (key: string): string => { // See https://yarnpkg.com/features/protocols + key = key.replace(/::.*$/, '') + .trim(); let normalizedKey = key - .replace(/(#|::).*$/, '') + .replace(/#.*$/, '') .trim(); const patchIndex = normalizedKey.indexOf(PATCH_PLACEHOLDER); if (patchIndex > -1) { - normalizedKey = normalizedKey.substr(patchIndex + PATCH_PLACEHOLDER.length); + if (key.indexOf('#builtin') > -1) { + normalizedKey = normalizedKey.substr(patchIndex + PATCH_PLACEHOLDER.length); + } else { + return key; + } } const fileProtocol = normalizedKey.match(/^(.+)@((file|link|portal):.+)$/); if (fileProtocol) { diff --git a/test/lib/yarn-utils.test.ts b/test/lib/yarn-utils.test.ts index df437b8d..6e717376 100644 --- a/test/lib/yarn-utils.test.ts +++ b/test/lib/yarn-utils.test.ts @@ -62,11 +62,21 @@ if (getRuntimeVersion() >= 10) { }); test('Should work for patch protocol', async (t) => { + const key = normalizer('left-pad@patch:left-pad@1.0.x#./my-patch.patch::locator=external-tarball%40workspace%3A.'); + t.deepEqual(key, [ 'left-pad@patch:left-pad@1.0.x#./my-patch.patch'], 'Resolution is normalized'); + }); + + test('Should work for patch protocol with scope', async (t) => { + const key = normalizer('@types/istanbul-reports@patch:@types/istanbul-reports@1.1.1#./my-patch.patch::locator=external-tarball%40workspace%3A.'); + t.deepEqual(key, [ '@types/istanbul-reports@patch:@types/istanbul-reports@1.1.1#./my-patch.patch'], 'Resolution is normalized'); + }); + + test('Should work for builtin patch protocol', async (t) => { const key = normalizer('fsevents@patch:fsevents@^1.2.7#builtin'); t.deepEqual(key, [ 'fsevents@^1.2.7'], 'Resolution is normalized'); }); - test('Should work for patch protocol - multiple resolutions', async (t) => { + test('Should work for builtin patch protocol - multiple resolutions', async (t) => { const key = normalizer('fsevents@patch:fsevents@^1.2.7#builtin, fsevents@patch:fsevents@^1.2.6#builtin'); t.deepEqual(key, [ 'fsevents@^1.2.7', 'fsevents@^1.2.6'], 'Resolution is normalized'); });