From 0b6b015503ac38c95345105ac85e80735ba0ccc0 Mon Sep 17 00:00:00 2001 From: Lukas Holzer Date: Thu, 11 Jul 2024 15:35:10 +0200 Subject: [PATCH] fix: relative path pattern in workspace globs (#5763) --- .../workspaces/get-workspace-packages.test.ts | 18 ++++++++++++++++++ .../src/workspaces/get-workspace-packages.ts | 6 ++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/build-info/src/workspaces/get-workspace-packages.test.ts b/packages/build-info/src/workspaces/get-workspace-packages.test.ts index 2508898e8b..f5a52fc526 100644 --- a/packages/build-info/src/workspaces/get-workspace-packages.test.ts +++ b/packages/build-info/src/workspaces/get-workspace-packages.test.ts @@ -102,3 +102,21 @@ test('should map the project paths correctly', async ({ fs }) => { { path: join('apps/deep/deeper/f'), name: undefined }, ]) }) + +test('should match deep packages with a globstar expression and a leading ./', async ({ fs }) => { + const cwd = mockFileSystem( + { + 'package.json': '{}', + 'apps/other/hello.txt': '', + 'apps/deep/a/package.json': '{}', + 'apps/deep/b/package.json': JSON.stringify({ name: 'b' }), + 'apps/deep/c/package.json': JSON.stringify({ name: 'c' }), + 'apps/deep/d/no-package': '{}', + }, + 'test', + ) + expect(await getWorkspacePackages(new Project(fs, cwd), ['./apps/deep/**', '!./apps/deep/a'])).toMatchObject([ + { path: join('apps/deep/b'), name: 'b' }, + { path: join('apps/deep/c'), name: 'c' }, + ]) +}) diff --git a/packages/build-info/src/workspaces/get-workspace-packages.ts b/packages/build-info/src/workspaces/get-workspace-packages.ts index 5091148494..59d0c163fa 100644 --- a/packages/build-info/src/workspaces/get-workspace-packages.ts +++ b/packages/build-info/src/workspaces/get-workspace-packages.ts @@ -100,7 +100,8 @@ export async function getWorkspacePackages(project: Project, patterns: string[] const results = ( await Promise.all( patterns.map((pattern) => { - const matcher = new Minimatch(pattern) + const cleanedPattern = pattern.replace(/^!?(\.\/)/, (match, p1) => match.replace(p1, '')) + const matcher = new Minimatch(cleanedPattern) if (matcher.negate) { return } @@ -118,7 +119,8 @@ export async function getWorkspacePackages(project: Project, patterns: string[] for (const result of results) { for (const pattern of patterns) { - const matcher = new Minimatch(pattern) + const cleanedPattern = pattern.replace(/^!?(\.\/)/, (match, p1) => match.replace(p1, '')) + const matcher = new Minimatch(cleanedPattern) if (minimatch(result.path, matcher.pattern)) { filtered.set(project.fs.join(result.path), result) if (matcher.negate) {