Skip to content

Commit 55050e0

Browse files
sorccuclaude
andcommitted
refactor: remove unnecessary patches dir existence check from getAutoIncludes
The glob pattern harmlessly matches nothing when the directory doesn't exist, so the statSync check was redundant. This also removes the basePath parameter and simplifies the tests to pure logic checks. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 29118e3 commit 55050e0

2 files changed

Lines changed: 13 additions & 40 deletions

File tree

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

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import path from 'node:path'
2-
import fs from 'node:fs/promises'
3-
import os from 'node:os'
4-
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
2+
import { describe, it, expect } from 'vitest'
53

64
import {
75
pathToPosix,
@@ -34,8 +32,6 @@ describe('util', () => {
3432
})
3533

3634
describe('getAutoIncludes()', () => {
37-
let tmpDir: string
38-
3935
const makePm = (name: string): PackageManager => ({
4036
name,
4137
representativeLockfile: undefined,
@@ -46,46 +42,28 @@ describe('util', () => {
4642
detector: () => ({}) as any,
4743
})
4844

49-
beforeEach(async () => {
50-
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'checkly-test-'))
51-
})
52-
53-
afterEach(async () => {
54-
await fs.rm(tmpDir, { recursive: true, force: true })
55-
})
56-
57-
it('should return patches/** when pnpm and patches dir exists', async () => {
58-
await fs.mkdir(path.join(tmpDir, 'patches'))
59-
const result = getAutoIncludes(tmpDir, makePm('pnpm'), [])
45+
it('should return patches/** for pnpm', () => {
46+
const result = getAutoIncludes(makePm('pnpm'), [])
6047
expect(result).toEqual(['patches/**'])
6148
})
6249

63-
it('should return empty when pnpm but no patches dir', () => {
64-
const result = getAutoIncludes(tmpDir, makePm('pnpm'), [])
65-
expect(result).toEqual([])
66-
})
67-
68-
it('should return empty for npm even with patches dir', async () => {
69-
await fs.mkdir(path.join(tmpDir, 'patches'))
70-
const result = getAutoIncludes(tmpDir, makePm('npm'), [])
50+
it('should return empty for npm', () => {
51+
const result = getAutoIncludes(makePm('npm'), [])
7152
expect(result).toEqual([])
7253
})
7354

74-
it('should return empty for yarn even with patches dir', async () => {
75-
await fs.mkdir(path.join(tmpDir, 'patches'))
76-
const result = getAutoIncludes(tmpDir, makePm('yarn'), [])
55+
it('should return empty for yarn', () => {
56+
const result = getAutoIncludes(makePm('yarn'), [])
7757
expect(result).toEqual([])
7858
})
7959

80-
it('should skip when user already includes patches/**', async () => {
81-
await fs.mkdir(path.join(tmpDir, 'patches'))
82-
const result = getAutoIncludes(tmpDir, makePm('pnpm'), ['patches/**'])
60+
it('should skip when user already includes patches/**', () => {
61+
const result = getAutoIncludes(makePm('pnpm'), ['patches/**'])
8362
expect(result).toEqual([])
8463
})
8564

86-
it('should skip when user already includes a patches/ subpath', async () => {
87-
await fs.mkdir(path.join(tmpDir, 'patches'))
88-
const result = getAutoIncludes(tmpDir, makePm('pnpm'), ['patches/some-patch.patch'])
65+
it('should skip when user already includes a patches/ subpath', () => {
66+
const result = getAutoIncludes(makePm('pnpm'), ['patches/some-patch.patch'])
8967
expect(result).toEqual([])
9068
})
9169
})

packages/cli/src/services/util.ts

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

146146
export function getAutoIncludes (
147-
basePath: string,
148147
packageManager: PackageManager,
149148
existingIncludes: string[],
150149
): string[] {
@@ -154,11 +153,7 @@ export function getAutoIncludes (
154153
const patchesPattern = 'patches/**'
155154
const alreadyIncluded = existingIncludes.some(p => p === patchesPattern || p.startsWith('patches/'))
156155
if (!alreadyIncluded) {
157-
const patchesDir = path.join(basePath, 'patches')
158-
const exists = fsSync.statSync(patchesDir, { throwIfNoEntry: false })?.isDirectory()
159-
if (exists) {
160-
autoIncludes.push(patchesPattern)
161-
}
156+
autoIncludes.push(patchesPattern)
162157
}
163158
}
164159

@@ -217,7 +212,7 @@ export async function bundlePlayWrightProject (
217212
}
218213
}
219214

220-
const autoIncludes = getAutoIncludes(Session.basePath!, Session.packageManager, include)
215+
const autoIncludes = getAutoIncludes(Session.packageManager, include)
221216
const effectiveIncludes = [...include, ...autoIncludes]
222217

223218
const includedFiles = await findFilesWithPattern(

0 commit comments

Comments
 (0)