Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/utils/path-resolve.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
whichBinSync,
} from '@socketsecurity/registry/lib/bin'
import { isDirSync } from '@socketsecurity/registry/lib/fs'
import { normalizePath } from '@socketsecurity/registry/lib/path'

import constants, { NODE_MODULES, NPM } from '../constants.mts'
import {
Expand Down Expand Up @@ -118,7 +119,7 @@ export type PackageFilesForScanOptions = {
*/
function normalizeScanInputPath(pathToNormalize: string, cwd: string): string {
if (!path.isAbsolute(pathToNormalize)) {
return pathToNormalize
return stripTrailingSlash(normalizePath(pathToNormalize))
}
const relativePath = path.relative(cwd, pathToNormalize)
const isInsideCwd =
Expand Down
19 changes: 19 additions & 0 deletions src/utils/path-resolve.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,25 @@ describe('Path Resolve', () => {
])
})

it('should normalize Windows-style relative directory paths', async () => {
const kernelDirPath = normalizePath(path.join(mockFixturePath, 'Kernel'))
mockTestFs({
[`${kernelDirPath}/package.json`]: '{}',
[`${kernelDirPath}/nested/package.json`]: '{}',
})

const actual = await sortedGetPackageFilesFullScans(
['.\\Kernel\\'],
globPatterns,
{ cwd: mockFixturePath },
)

expect(actual.map(normalizePath)).toEqual([
`${kernelDirPath}/nested/package.json`,
`${kernelDirPath}/package.json`,
])
})

it('should keep scan-root ignores effective when the input path is absolute', async () => {
const appDirPath = normalizePath(path.join(mockFixturePath, 'apps/api'))
mockTestFs({
Expand Down
Loading