From 5f78dfdf4f36a38b31c63e9b0b88af07293b73aa Mon Sep 17 00:00:00 2001 From: Martin Torp Date: Thu, 16 Oct 2025 09:58:35 +0200 Subject: [PATCH 1/2] fix bug where directory target were not handled according to the specification --- src/utils/glob.mts | 13 +++++++++++-- src/utils/path-resolve.test.mts | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/utils/glob.mts b/src/utils/glob.mts index 6d456296a..ea89f1337 100644 --- a/src/utils/glob.mts +++ b/src/utils/glob.mts @@ -5,7 +5,7 @@ import ignore from 'ignore' import micromatch from 'micromatch' import { parse as yamlParse } from 'yaml' -import { safeReadFile } from '@socketsecurity/registry/lib/fs' +import { isDirSync, safeReadFile } from '@socketsecurity/registry/lib/fs' import { defaultIgnore } from '@socketsecurity/registry/lib/globs' import { readPackageJson } from '@socketsecurity/registry/lib/packages' import { transform } from '@socketsecurity/registry/lib/streams' @@ -291,5 +291,14 @@ export function pathsToGlobPatterns( paths: string[] | readonly string[], ): string[] { // TODO: Does not support `~/` paths. - return paths.map(p => (p === '.' || p === './' ? '**/*' : p)) + return paths.map(p => { + if (p === '.' || p === './') { + return '**/*' + } + // If the path is a directory, scan it recursively for all files. + if (isDirSync(p)) { + return `${p}/**/*` + } + return p + }) } diff --git a/src/utils/path-resolve.test.mts b/src/utils/path-resolve.test.mts index 4156aeaa6..76c1a549e 100644 --- a/src/utils/path-resolve.test.mts +++ b/src/utils/path-resolve.test.mts @@ -110,6 +110,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`]: '{}', From 53d7841555945c3babd4b1d80c5283e7b1d34b8e Mon Sep 17 00:00:00 2001 From: Martin Torp Date: Tue, 21 Oct 2025 09:31:02 +0200 Subject: [PATCH 2/2] fix imports --- src/utils/fs/glob.mts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils/fs/glob.mts b/src/utils/fs/glob.mts index dcf04efb6..55a2fefba 100644 --- a/src/utils/fs/glob.mts +++ b/src/utils/fs/glob.mts @@ -6,11 +6,11 @@ import path from 'node:path' import { parse as yamlParse } from 'yaml' import { NODE_MODULES } from '@socketsecurity/lib/constants/paths' -import { isDirSync, safeReadFile } from '@socketsecurity/registry/lib/fs' -import { defaultIgnore } from '@socketsecurity/registry/lib/globs' -import { readPackageJson } from '@socketsecurity/registry/lib/packages' -import { transform } from '@socketsecurity/registry/lib/streams' -import { isNonEmptyString } from '@socketsecurity/registry/lib/strings' +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 { PNPM } from '../../constants/agents.mjs'