Skip to content

Commit e297a1c

Browse files
committed
fix: use forward-slash patterns for normalized path matching
- Fix detection.mts to always use forward-slash patterns since normalizePath converts all paths to forward slashes - Remove unused path import from detection.mts - Fix completion.test.mts to expect normalized paths with forward slashes The issue was that path.sep-based pattern selection created backslash patterns on Windows, but normalizedPath had forward slashes, causing pattern matching to fail. Since we normalize all paths to forward slashes, patterns must also use forward slashes.
1 parent c7c1947 commit e297a1c

File tree

3 files changed

+13
-152
lines changed

3 files changed

+13
-152
lines changed

docs/development/SCRIPT-SIMPLIFICATION-QUICK-START.md

Lines changed: 0 additions & 136 deletions
This file was deleted.

packages/cli/src/utils/cli/completion.test.mts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@ describe('completion utilities', () => {
4444
data: 'source /mock/dist/path/data/socket-completion.bash',
4545
})
4646

47-
expect(fs.existsSync).toHaveBeenCalledWith(
48-
'/mock/dist/path/data/socket-completion.bash',
49-
)
47+
// Note: On Windows, path.join returns backslashes, which are then checked by existsSync.
48+
// The implementation normalizes the path display but checks existence with the actual path.
49+
const expectedPath =
50+
path.sep === '\\'
51+
? '\\mock\\dist\\path\\data\\socket-completion.bash'
52+
: '/mock/dist/path/data/socket-completion.bash'
53+
expect(fs.existsSync).toHaveBeenCalledWith(expectedPath)
5054
})
5155

5256
it('returns error when completion script does not exist', () => {
@@ -138,12 +142,9 @@ describe('completion utilities', () => {
138142

139143
expect(result.ok).toBe(true)
140144
if (result.ok) {
145+
// Note: The implementation normalizes paths to forward slashes for bash compatibility.
141146
expect(result.data.targetPath).toBe(
142-
path.join(
143-
path.dirname('/mock/app/data'),
144-
'completion',
145-
'socket-completion.bash',
146-
),
147+
'/mock/app/completion/socket-completion.bash',
147148
)
148149
}
149150
})

packages/cli/src/utils/dlx/detection.mts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
* - Ensures package manager commands work correctly
2323
*/
2424

25-
import path from 'node:path'
26-
2725
import { normalizePath } from '@socketsecurity/lib/path'
2826

2927
import ENV from '../../constants/env.mts'
@@ -59,14 +57,13 @@ export function isRunningInTemporaryExecutor(): boolean {
5957
}
6058

6159
// Check common temporary execution path patterns.
60+
// Note: Always use forward slashes since we normalize paths to forward slashes.
6261
const tempPatterns = [
6362
'_npx', // npm's npx cache directory
6463
'.pnpm-store', // pnpm dlx temporary store
6564
'dlx-', // Common dlx directory prefix
6665
'.yarn/$$', // Yarn Berry PnP virtual packages
67-
path.sep === '\\'
68-
? 'AppData\\Local\\Temp\\xfs-'
69-
: 'AppData/Local/Temp/xfs-', // Yarn on Windows
66+
'AppData/Local/Temp/xfs-', // Yarn on Windows
7067
]
7168

7269
return tempPatterns.some(pattern => normalizedDirname.includes(pattern))
@@ -135,14 +132,13 @@ export function shouldSkipShadow(
135132
}
136133

137134
// Check common temporary execution path patterns.
135+
// Note: Always use forward slashes since we normalize paths to forward slashes.
138136
const tempPatterns = [
139137
'_npx', // npm's npx cache directory
140138
'.pnpm-store', // pnpm dlx temporary store
141139
'dlx-', // Common dlx directory prefix
142140
'.yarn/$$', // Yarn Berry PnP virtual packages
143-
path.sep === '\\'
144-
? 'AppData\\Local\\Temp\\xfs-'
145-
: 'AppData/Local/Temp/xfs-', // Yarn on Windows
141+
'AppData/Local/Temp/xfs-', // Yarn on Windows
146142
]
147143

148144
return tempPatterns.some(pattern => normalizedCwd.includes(pattern))

0 commit comments

Comments
 (0)