Skip to content

Commit 9d29b5f

Browse files
authored
fix: add pip3 shim support and MSYS path normalization (#264)
* fix: add pip3 shim support and MSYS path normalization in index.mts - Add pip3 to ecosystem lists in external-tools.json (free + enterprise) - Add pip3 to SHIM_CMDS in setup action.yml (free + enterprise) - Add msysToWinPath normalization in index.mts for Windows MSYS paths (/c/Users/... -> C:\Users\...) matching the existing fix in action.yml * refactor(sfw): use fromUnixPath from @socketsecurity/lib for MSYS path conversion
1 parent b9cabb4 commit 9d29b5f

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

.claude/hooks/setup-security-tools/external-tools.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"sha256": "c953e62ad7928d4d8f2302f5737884ea1a757babc26bed6a42b9b6b68a5d54af"
5757
}
5858
},
59-
"ecosystems": ["npm", "yarn", "pnpm", "pip", "uv", "cargo"]
59+
"ecosystems": ["npm", "yarn", "pnpm", "pip", "pip3", "uv", "cargo"]
6060
},
6161
"sfw-enterprise": {
6262
"description": "Socket Firewall (enterprise tier)",
@@ -85,7 +85,7 @@
8585
"sha256": "9a50e1ddaf038138c3f85418dc5df0113bbe6fc884f5abe158beaa9aea18d70a"
8686
}
8787
},
88-
"ecosystems": ["npm", "yarn", "pnpm", "pip", "uv", "cargo", "gem", "bundler", "nuget"]
88+
"ecosystems": ["npm", "yarn", "pnpm", "pip", "pip3", "uv", "cargo", "gem", "bundler", "nuget"]
8989
}
9090
}
9191
}

.claude/hooks/setup-security-tools/index.mts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { fileURLToPath } from 'node:url'
1919
import { whichSync } from '@socketsecurity/lib/bin'
2020
import { downloadBinary } from '@socketsecurity/lib/dlx/binary'
2121
import { getDefaultLogger } from '@socketsecurity/lib/logger'
22+
import { normalizePath } from '@socketsecurity/lib/paths/normalize'
2223
import { getSocketHomePath } from '@socketsecurity/lib/paths/socket'
2324
import { spawn, spawnSync } from '@socketsecurity/lib/spawn'
2425
import { z } from 'zod'
@@ -194,6 +195,7 @@ async function setupSfw(apiKey: string | undefined): Promise<boolean> {
194195

195196
// Create shims.
196197
const isWindows = process.platform === 'win32'
198+
197199
const shimDir = path.join(getSocketHomePath(), 'sfw', 'shims')
198200
await fs.mkdir(shimDir, { recursive: true })
199201
const ecosystems = [...(sfwConfig.ecosystems ?? [])]
@@ -202,12 +204,14 @@ async function setupSfw(apiKey: string | undefined): Promise<boolean> {
202204
}
203205
const cleanPath = (process.env['PATH'] ?? '').split(path.delimiter)
204206
.filter(p => p !== shimDir).join(path.delimiter)
207+
const sfwBin = normalizePath(binaryPath)
205208
const created: string[] = []
206209
for (const cmd of ecosystems) {
207-
const realBin = whichSync(cmd, { nothrow: true, path: cleanPath })
210+
let realBin = whichSync(cmd, { nothrow: true, path: cleanPath })
208211
if (!realBin || typeof realBin !== 'string') continue
212+
realBin = normalizePath(realBin)
209213

210-
// Bash shim (macOS/Linux).
214+
// Bash shim (macOS/Linux/Windows Git Bash).
211215
const bashLines = [
212216
'#!/bin/bash',
213217
`export PATH="$(echo "$PATH" | tr ':' '\\n' | grep -vxF '${shimDir}' | paste -sd: -)"`,
@@ -226,7 +230,7 @@ async function setupSfw(apiKey: string | undefined): Promise<boolean> {
226230
'fi',
227231
)
228232
}
229-
bashLines.push(`exec "${binaryPath}" "${realBin}" "$@"`)
233+
bashLines.push(`exec "${sfwBin}" "${realBin}" "$@"`)
230234
const bashContent = bashLines.join('\n') + '\n'
231235
const bashPath = path.join(shimDir, cmd)
232236
if (!existsSync(bashPath) || await fs.readFile(bashPath, 'utf8').catch(() => '') !== bashContent) {
@@ -256,7 +260,7 @@ async function setupSfw(apiKey: string | undefined): Promise<boolean> {
256260
+ `set "PATH=%PATH:;${shimDir};=%"\r\n`
257261
+ `set "PATH=%PATH:~1,-1%"\r\n`
258262
+ cmdApiKeyBlock
259-
+ `"${binaryPath}" "${realBin}" %*\r\n`
263+
+ `"${sfwBin}" "${realBin}" %*\r\n`
260264
const cmdPath = path.join(shimDir, `${cmd}.cmd`)
261265
if (!existsSync(cmdPath) || await fs.readFile(cmdPath, 'utf8').catch(() => '') !== cmdContent) {
262266
await fs.writeFile(cmdPath, cmdContent)

.github/actions/setup/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ runs:
172172
strip_shim_dir() { echo "$PATH" | tr ':' '\n' | grep -vxF "$SHIM_DIR" | paste -sd: -; }
173173
CLEAN_PATH="$(strip_shim_dir)"
174174
SSL_WORKAROUND=""
175-
SHIM_CMDS="npm yarn pnpm pip uv cargo"
175+
SHIM_CMDS="npm yarn pnpm pip pip3 uv cargo"
176176
if [ "$SFW_IS_ENTERPRISE" = "true" ]; then
177-
SHIM_CMDS="npm yarn pnpm pip uv cargo gem bundler nuget"
177+
SHIM_CMDS="npm yarn pnpm pip pip3 uv cargo gem bundler nuget"
178178
# Go wrapper mode is only supported on Linux.
179179
[[ "$OSTYPE" == linux* ]] && SHIM_CMDS="$SHIM_CMDS go"
180180
else

0 commit comments

Comments
 (0)