diff --git a/src/utils/fs/glob.mts b/src/utils/fs/glob.mts index 6b937bf84..55a2fefba 100644 --- a/src/utils/fs/glob.mts +++ b/src/utils/fs/glob.mts @@ -1,18 +1,16 @@ -import os from 'node:os' -import path from 'node:path' - import fastGlob from 'fast-glob' import ignore from 'ignore' import micromatch from 'micromatch' +import os from 'node:os' +import path from 'node:path' import { parse as yamlParse } from 'yaml' -import { safeReadFile } from '@socketsecurity/lib/fs' +import { NODE_MODULES } from '@socketsecurity/lib/constants/paths' +import { isDirSync, safeReadFile } from '@socketsecurity/lib/fs' import { defaultIgnore } from '@socketsecurity/lib/globs' import { readPackageJson } from '@socketsecurity/lib/packages' import { transform } from '@socketsecurity/lib/streams' import { isNonEmptyString } from '@socketsecurity/lib/strings' -import { NODE_MODULES } from '@socketsecurity/lib/constants/paths' - import { PNPM } from '../../constants/agents.mjs' @@ -310,6 +308,13 @@ export function pathsToGlobPatterns( // Expand tilde paths. const expanded = expandTildePath(p) // Convert current directory references to glob patterns. - return expanded === '.' || expanded === './' ? '**/*' : expanded + if (expanded === '.' || expanded === './') { + return '**/*' + } + // If the path is a directory, scan it recursively for all files. + if (isDirSync(expanded)) { + return `${expanded}/**/*` + } + return expanded }) } diff --git a/src/utils/fs/path-resolve.test.mts b/src/utils/fs/path-resolve.test.mts index 55cfe292a..cf88c5f99 100644 --- a/src/utils/fs/path-resolve.test.mts +++ b/src/utils/fs/path-resolve.test.mts @@ -150,6 +150,27 @@ describe('Path Resolve', () => { ]) }) + it('should handle a directory path input', async () => { + const subDirPath = normalizePath(path.join(mockFixturePath, 'subdir')) + mockTestFs({ + [`${mockFixturePath}/package.json`]: '{}', + [`${subDirPath}/package.json`]: '{}', + [`${subDirPath}/nested/package.json`]: '{}', + }) + + const actual = await sortedGetPackageFilesFullScans( + [subDirPath], + globPatterns, + { + cwd: mockFixturePath, + }, + ) + expect(actual.map(normalizePath)).toEqual([ + `${subDirPath}/nested/package.json`, + `${subDirPath}/package.json`, + ]) + }) + it('should respect ignores from socket config', async () => { mockTestFs({ [`${mockFixturePath}/bar/package-lock.json`]: '{}',