File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import ignore from 'ignore'
55import micromatch from 'micromatch'
66import { parse as yamlParse } from 'yaml'
77
8- import { safeReadFile } from '@socketsecurity/registry/lib/fs'
8+ import { isDirSync , safeReadFile } from '@socketsecurity/registry/lib/fs'
99import { defaultIgnore } from '@socketsecurity/registry/lib/globs'
1010import { readPackageJson } from '@socketsecurity/registry/lib/packages'
1111import { 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}
Original file line number Diff line number Diff 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` ] : '{}' ,
You can’t perform that action at this time.
0 commit comments