From 46d38a874429200bafc295a450f4fb8d00aacc18 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 9 Feb 2024 02:27:34 +0100 Subject: [PATCH] fix: parsing dependency path --- packages/dependency-path/src/index.ts | 7 +++---- packages/dependency-path/test/index.ts | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/dependency-path/src/index.ts b/packages/dependency-path/src/index.ts index f1effef360..260aff901c 100644 --- a/packages/dependency-path/src/index.ts +++ b/packages/dependency-path/src/index.ts @@ -8,13 +8,12 @@ export function isAbsolute (dependencyPath: string) { export function indexOfPeersSuffix (depPath: string) { if (!depPath.endsWith(')')) return -1 - let open = true + let open = 1 for (let i = depPath.length - 2; i >= 0; i--) { if (depPath[i] === '(') { - open = false + open-- } else if (depPath[i] === ')') { - if (open) return -1 - open = true + open++ } else if (!open) { return i + 1 } diff --git a/packages/dependency-path/test/index.ts b/packages/dependency-path/test/index.ts index 7e6e5e9628..385c1ea9a1 100644 --- a/packages/dependency-path/test/index.ts +++ b/packages/dependency-path/test/index.ts @@ -78,5 +78,6 @@ test('depPathToFilename()', () => { test('tryGetPackageId', () => { expect(tryGetPackageId('/foo@1.0.0(@types/babel__core@7.1.14)')).toEqual('/foo@1.0.0') + expect(tryGetPackageId('/foo@1.0.0(@types/babel__core@7.1.14(is-odd@1.0.0))')).toEqual('/foo@1.0.0') expect(tryGetPackageId('/@(-.-)/foo@1.0.0(@types/babel__core@7.1.14)')).toEqual('/@(-.-)/foo@1.0.0') })