Skip to content

Commit a714214

Browse files
sorccuclaude
andcommitted
fix: resolve include patterns to absolute paths in getAutoIncludes
Prevents adding duplicate patches include when the user specifies the pattern with a relative prefix (./patches/**) or absolute path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3e13ab2 commit a714214

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

packages/cli/src/services/__tests__/util.spec.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('util', () => {
3232
})
3333

3434
describe('getAutoIncludes()', () => {
35+
const basePath = '/project'
3536
const makePm = (name: string): PackageManager => ({
3637
name,
3738
representativeLockfile: undefined,
@@ -43,27 +44,37 @@ describe('util', () => {
4344
})
4445

4546
it('should return patches/*.patch for pnpm', () => {
46-
const result = getAutoIncludes(makePm('pnpm'), [])
47+
const result = getAutoIncludes(basePath, makePm('pnpm'), [])
4748
expect(result).toEqual(['patches/*.patch'])
4849
})
4950

5051
it('should return empty for npm', () => {
51-
const result = getAutoIncludes(makePm('npm'), [])
52+
const result = getAutoIncludes(basePath, makePm('npm'), [])
5253
expect(result).toEqual([])
5354
})
5455

5556
it('should return empty for yarn', () => {
56-
const result = getAutoIncludes(makePm('yarn'), [])
57+
const result = getAutoIncludes(basePath, makePm('yarn'), [])
5758
expect(result).toEqual([])
5859
})
5960

6061
it('should skip when user already includes patches/*.patch', () => {
61-
const result = getAutoIncludes(makePm('pnpm'), ['patches/*.patch'])
62+
const result = getAutoIncludes(basePath, makePm('pnpm'), ['patches/*.patch'])
6263
expect(result).toEqual([])
6364
})
6465

6566
it('should skip when user already includes a patches/ subpath', () => {
66-
const result = getAutoIncludes(makePm('pnpm'), ['patches/some-patch.patch'])
67+
const result = getAutoIncludes(basePath, makePm('pnpm'), ['patches/some-patch.patch'])
68+
expect(result).toEqual([])
69+
})
70+
71+
it('should skip when user includes ./patches/**', () => {
72+
const result = getAutoIncludes(basePath, makePm('pnpm'), ['./patches/**'])
73+
expect(result).toEqual([])
74+
})
75+
76+
it('should skip when user includes absolute patches path', () => {
77+
const result = getAutoIncludes(basePath, makePm('pnpm'), ['/project/patches/**'])
6778
expect(result).toEqual([])
6879
})
6980
})

packages/cli/src/services/util.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,16 @@ export function normalizeVersion (v?: string | undefined): string | undefined {
144144
}
145145

146146
export function getAutoIncludes (
147+
basePath: string,
147148
packageManager: PackageManager,
148149
existingIncludes: string[],
149150
): string[] {
150151
const autoIncludes: string[] = []
151152

152153
if (packageManager.name === 'pnpm') {
153154
const patchesPattern = 'patches/*.patch'
154-
const alreadyIncluded = existingIncludes.some(p => p === patchesPattern || p.startsWith('patches/'))
155+
const patchesDir = path.join(basePath, 'patches')
156+
const alreadyIncluded = existingIncludes.some(p => path.resolve(basePath, p).startsWith(patchesDir))
155157
if (!alreadyIncluded) {
156158
autoIncludes.push(patchesPattern)
157159
}
@@ -212,7 +214,7 @@ export async function bundlePlayWrightProject (
212214
}
213215
}
214216

215-
const autoIncludes = getAutoIncludes(Session.packageManager, include)
217+
const autoIncludes = getAutoIncludes(Session.basePath!, Session.packageManager, include)
216218
const effectiveIncludes = [...include, ...autoIncludes]
217219

218220
const includedFiles = await findFilesWithPattern(

0 commit comments

Comments
 (0)