Skip to content

Commit 5d59349

Browse files
committed
Normalize paths
1 parent e9c9a81 commit 5d59349

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/commands/patch/handle-patch.mts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { debugDir } from '@socketsecurity/registry/lib/debug'
99
import { readDirNames } from '@socketsecurity/registry/lib/fs'
1010
import { logger } from '@socketsecurity/registry/lib/logger'
1111
import { readPackageJson } from '@socketsecurity/registry/lib/packages'
12+
import { normalizePath } from '@socketsecurity/registry/lib/path'
1213
import { isNonEmptyString } from '@socketsecurity/registry/lib/strings'
1314
import { pluralize } from '@socketsecurity/registry/lib/words'
1415

@@ -97,15 +98,15 @@ async function applyNpmPatches(
9798
const dirNames = await readDirNames(nmPath)
9899
for (const dirName of dirNames) {
99100
const isScoped = dirName.startsWith('@')
100-
const pkgPath = path.join(nmPath, dirName)
101+
const pkgPath = normalizePath(path.join(nmPath, dirName))
101102
const pkgSubNames = isScoped
102103
? // eslint-disable-next-line no-await-in-loop
103104
await readDirNames(pkgPath)
104105
: [dirName]
105106

106107
for (const pkgSubName of pkgSubNames) {
107108
const dirFullName = isScoped ? `${dirName}/${pkgSubName}` : pkgSubName
108-
const pkgPath = path.join(nmPath, dirFullName)
109+
const pkgPath = normalizePath(path.join(nmPath, dirFullName))
109110
// eslint-disable-next-line no-await-in-loop
110111
const pkgJson = await readPackageJson(pkgPath, { throws: false })
111112
if (
@@ -247,7 +248,7 @@ async function processFilePatch(
247248

248249
spinner?.stop()
249250

250-
const filepath = path.join(pkgPath, fileName)
251+
const filepath = normalizePath(path.join(pkgPath, fileName))
251252
if (!existsSync(filepath)) {
252253
logger.log(`File not found: ${fileName}`)
253254
if (wasSpinning) {
@@ -307,7 +308,9 @@ async function processFilePatch(
307308
return false
308309
}
309310

310-
const blobPath = path.join(socketDir, 'blobs', fileInfo.afterHash)
311+
const blobPath = normalizePath(
312+
path.join(socketDir, 'blobs', fileInfo.afterHash),
313+
)
311314
if (!existsSync(blobPath)) {
312315
logger.fail(`Error: Patch file not found at ${blobPath}`)
313316
logger.groupEnd()
@@ -373,8 +376,10 @@ export async function handlePatch({
373376
spinner,
374377
}: HandlePatchConfig): Promise<void> {
375378
try {
376-
const dotSocketDirPath = path.join(cwd, DOT_SOCKET_DIR)
377-
const manifestPath = path.join(dotSocketDirPath, MANIFEST_JSON)
379+
const dotSocketDirPath = normalizePath(path.join(cwd, DOT_SOCKET_DIR))
380+
const manifestPath = normalizePath(
381+
path.join(dotSocketDirPath, MANIFEST_JSON),
382+
)
378383
const manifestContent = await fs.readFile(manifestPath, UTF8)
379384
const manifestData = JSON.parse(manifestContent)
380385
const purls = purlObjs.map(String)

src/shadow/npm-base.mts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '@socketsecurity/registry/lib/agent'
99
import { isDebug } from '@socketsecurity/registry/lib/debug'
1010
import { getOwn } from '@socketsecurity/registry/lib/objects'
11+
import { normalizePath } from '@socketsecurity/registry/lib/path'
1112
import { spawn } from '@socketsecurity/registry/lib/spawn'
1213

1314
import { ensureIpcInStdio } from './stdio-ipc.mts'
@@ -51,7 +52,9 @@ export default async function shadowNpmBase(
5152

5253
let cwd = getOwn(spawnOpts, 'cwd') ?? process.cwd()
5354
if (cwd instanceof URL) {
54-
cwd = fileURLToPath(cwd)
55+
cwd = normalizePath(fileURLToPath(cwd))
56+
} else if (typeof cwd === 'string') {
57+
cwd = normalizePath(cwd)
5558
}
5659

5760
const isShadowNpm = binName === NPM

0 commit comments

Comments
 (0)