Skip to content

Commit 5f78dfd

Browse files
committed
fix bug where directory target were not handled according to the specification
1 parent 6380947 commit 5f78dfd

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/utils/glob.mts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ignore from 'ignore'
55
import micromatch from 'micromatch'
66
import { parse as yamlParse } from 'yaml'
77

8-
import { safeReadFile } from '@socketsecurity/registry/lib/fs'
8+
import { isDirSync, safeReadFile } from '@socketsecurity/registry/lib/fs'
99
import { defaultIgnore } from '@socketsecurity/registry/lib/globs'
1010
import { readPackageJson } from '@socketsecurity/registry/lib/packages'
1111
import { transform } from '@socketsecurity/registry/lib/streams'
@@ -291,5 +291,14 @@ export function pathsToGlobPatterns(
291291
paths: string[] | readonly string[],
292292
): string[] {
293293
// TODO: Does not support `~/` paths.
294-
return paths.map(p => (p === '.' || p === './' ? '**/*' : p))
294+
return paths.map(p => {
295+
if (p === '.' || p === './') {
296+
return '**/*'
297+
}
298+
// If the path is a directory, scan it recursively for all files.
299+
if (isDirSync(p)) {
300+
return `${p}/**/*`
301+
}
302+
return p
303+
})
295304
}

src/utils/path-resolve.test.mts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,27 @@ describe('Path Resolve', () => {
110110
])
111111
})
112112

113+
it('should handle a directory path input', async () => {
114+
const subDirPath = normalizePath(path.join(mockFixturePath, 'subdir'))
115+
mockTestFs({
116+
[`${mockFixturePath}/package.json`]: '{}',
117+
[`${subDirPath}/package.json`]: '{}',
118+
[`${subDirPath}/nested/package.json`]: '{}',
119+
})
120+
121+
const actual = await sortedGetPackageFilesFullScans(
122+
[subDirPath],
123+
globPatterns,
124+
{
125+
cwd: mockFixturePath,
126+
},
127+
)
128+
expect(actual.map(normalizePath)).toEqual([
129+
`${subDirPath}/nested/package.json`,
130+
`${subDirPath}/package.json`,
131+
])
132+
})
133+
113134
it('should respect ignores from socket config', async () => {
114135
mockTestFs({
115136
[`${mockFixturePath}/bar/package-lock.json`]: '{}',

0 commit comments

Comments
 (0)