Skip to content

Commit b6c7fec

Browse files
committed
Cleanup filterBySupportedScanFiles
1 parent ee8e44b commit b6c7fec

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/utils/glob.mts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function workspacePatternToGlobPattern(workspace: string): string {
157157
return `${workspace}/package.json`
158158
}
159159

160-
export function filterReportSupportedFiles(
160+
export function filterBySupportedScanFiles(
161161
filepaths: string[] | readonly string[],
162162
supportedFiles: SocketSdkSuccessResult<'getReportSupportedFiles'>['data'],
163163
): string[] {
@@ -191,12 +191,13 @@ export async function globWithGitIgnore(
191191
socketConfig,
192192
...additionalOptions
193193
} = { __proto__: null, ...options } as GlobWithGitIgnoreOptions
194-
const projectIgnorePaths = socketConfig?.projectIgnorePaths
194+
195195
const ignoreFiles = await tinyGlob(['**/.gitignore'], {
196196
absolute: true,
197197
cwd,
198198
expandDirectories: true,
199199
})
200+
const projectIgnorePaths = socketConfig?.projectIgnorePaths
200201
const ignores = [
201202
...ignoredDirPatterns,
202203
...(Array.isArray(projectIgnorePaths)
@@ -220,25 +221,31 @@ export async function globWithGitIgnore(
220221
]
221222
const hasNegatedPattern = ignores.some(p => p.charCodeAt(0) === 33 /*'!'*/)
222223
const globOptions = {
224+
__proto__: null,
223225
absolute: true,
224226
cwd,
225227
dot: true,
226228
expandDirectories: false,
227229
ignore: hasNegatedPattern ? [] : ignores,
228230
...additionalOptions,
229231
}
232+
230233
const result = await tinyGlob(patterns as string[], globOptions)
231234
if (!hasNegatedPattern) {
232235
return result
233236
}
234-
const { absolute } = globOptions
235237

236238
// Note: the input files must be INSIDE the cwd. If you get strange looking
237239
// relative path errors here, most likely your path is outside the given cwd.
238240
const filtered = ignore()
239241
.add(ignores)
240-
.filter(absolute ? result.map(p => path.relative(cwd, p)) : result)
241-
return absolute ? filtered.map(p => path.resolve(cwd, p)) : filtered
242+
.filter(
243+
globOptions.absolute ? result.map(p => path.relative(cwd, p)) : result,
244+
)
245+
246+
return globOptions.absolute
247+
? filtered.map(p => path.resolve(cwd, p))
248+
: filtered
242249
}
243250

244251
export async function globNodeModules(cwd = process.cwd()): Promise<string[]> {

src/utils/path-resolve.mts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { resolveBinPathSync } from '@socketsecurity/registry/lib/npm'
88
import constants from '../constants.mts'
99
import { safeStatsSync } from './fs.mts'
1010
import {
11-
filterReportSupportedFiles,
11+
filterBySupportedScanFiles,
1212
globWithGitIgnore,
1313
pathsToGlobPatterns,
1414
} from './glob.mts'
@@ -105,9 +105,11 @@ export async function getPackageFilesForScan(
105105
__proto__: null,
106106
...options,
107107
} as PackageFilesForScanOptions
108+
108109
const filepaths = await globWithGitIgnore(pathsToGlobPatterns(inputPaths), {
109110
cwd,
110111
socketConfig,
111112
})
112-
return filterReportSupportedFiles(filepaths, supportedFiles)
113+
114+
return filterBySupportedScanFiles(filepaths!, supportedFiles)
113115
}

0 commit comments

Comments
 (0)