Skip to content

Commit 64ad940

Browse files
committed
Use resolveBinPath for Windows support
1 parent 77b3fd4 commit 64ad940

File tree

5 files changed

+86
-82
lines changed

5 files changed

+86
-82
lines changed

.dep-stats.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"@apideck/better-ajv-errors": "0.3.6",
44
"@octokit/rest": "21.1.1",
55
"@pnpm/lockfile-file": "^9.1.3",
6-
"@socketregistry/hyrious__bun.lockb": "1.0.14",
6+
"@socketregistry/hyrious__bun.lockb": "1.0.15",
77
"@socketregistry/indent-string": "1.0.11",
88
"@socketregistry/is-interactive": "1.0.2",
99
"@socketregistry/is-unicode-supported": "1.0.2",
1010
"@socketregistry/packageurl-js": "1.0.3",
1111
"@socketsecurity/config": "2.1.3",
12-
"@socketsecurity/registry": "1.0.127",
12+
"@socketsecurity/registry": "1.0.128",
1313
"@socketsecurity/sdk": "1.4.5",
1414
"blessed": "0.1.81",
1515
"blessed-contrib": "4.11.0",
@@ -68,12 +68,12 @@
6868
"external": {
6969
"@apideck/better-ajv-errors": "0.3.6",
7070
"@pnpm/lockfile-file": "^9.1.3",
71-
"@socketregistry/hyrious__bun.lockb": "1.0.14",
71+
"@socketregistry/hyrious__bun.lockb": "1.0.15",
7272
"@socketregistry/indent-string": "1.0.11",
7373
"@socketregistry/is-interactive": "1.0.2",
7474
"@socketregistry/packageurl-js": "1.0.3",
7575
"@socketsecurity/config": "2.1.3",
76-
"@socketsecurity/registry": "1.0.127",
76+
"@socketsecurity/registry": "1.0.128",
7777
"@socketsecurity/sdk": "1.4.5",
7878
"blessed": "0.1.81",
7979
"blessed-contrib": "4.11.0",

package-lock.json

Lines changed: 59 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@
7373
"@apideck/better-ajv-errors": "0.3.6",
7474
"@octokit/rest": "21.1.1",
7575
"@pnpm/lockfile-file": "^9.1.3",
76-
"@socketregistry/hyrious__bun.lockb": "1.0.14",
76+
"@socketregistry/hyrious__bun.lockb": "1.0.15",
7777
"@socketregistry/indent-string": "1.0.11",
7878
"@socketregistry/is-interactive": "1.0.2",
7979
"@socketregistry/is-unicode-supported": "1.0.2",
8080
"@socketregistry/packageurl-js": "1.0.3",
8181
"@socketsecurity/config": "2.1.3",
82-
"@socketsecurity/registry": "1.0.127",
82+
"@socketsecurity/registry": "1.0.128",
8383
"@socketsecurity/sdk": "1.4.5",
8484
"blessed": "0.1.81",
8585
"blessed-contrib": "4.11.0",
@@ -141,8 +141,8 @@
141141
"@types/update-notifier": "^6.0.8",
142142
"@types/which": "^3.0.4",
143143
"@types/yargs-parser": "^21.0.3",
144-
"@typescript-eslint/eslint-plugin": "^8.26.0",
145-
"@typescript-eslint/parser": "^8.26.0",
144+
"@typescript-eslint/eslint-plugin": "^8.26.1",
145+
"@typescript-eslint/parser": "^8.26.1",
146146
"@vitest/coverage-v8": "3.0.8",
147147
"cross-env": "^7.0.3",
148148
"del-cli": "^6.0.0",
@@ -169,7 +169,7 @@
169169
"synp": "^1.9.14",
170170
"type-coverage": "^2.29.7",
171171
"typescript": "5.4.5",
172-
"typescript-eslint": "^8.26.0",
172+
"typescript-eslint": "^8.26.1",
173173
"unplugin-purge-polyfills": "^0.0.7",
174174
"vitest": "3.0.8"
175175
},

src/constants.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,16 @@ const lazyNmBinPath = () =>
248248
// Lazily access constants.rootPath.
249249
path.join(constants.rootPath, `${NODE_MODULES}/.bin`)
250250

251-
// Harden Node security.
252-
// https://nodejs.org/en/learn/getting-started/security-best-practices
251+
// Redefine nodeHardenFlags to account for the INLINED_SOCKET_CLI_SENTRY_BUILD
252+
// environment variable.
253253
const lazyNodeHardenFlags = () =>
254254
// The '@rollup/plugin-replace' will replace "process.env[INLINED_SOCKET_CLI_SENTRY_BUILD]".
255255
// Lazily access constants.WIN32.
256256
process.env[INLINED_SOCKET_CLI_SENTRY_BUILD] || constants.WIN32
257257
? []
258-
: // We have contributed the following patches to our dependencies to make
258+
: // Harden Node security.
259+
// https://nodejs.org/en/learn/getting-started/security-best-practices
260+
// We have contributed the following patches to our dependencies to make
259261
// Node's --frozen-intrinsics workable.
260262
// √ https://github.com/SBoudrias/Inquirer.js/pull/1683
261263
// √ https://github.com/pnpm/components/pull/23

src/utils/path-resolve.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { existsSync, promises as fs, realpathSync, statSync } from 'node:fs'
1+
import { existsSync, promises as fs, statSync } from 'node:fs'
22
import path from 'node:path'
33
import process from 'node:process'
44

@@ -8,6 +8,7 @@ import { glob as tinyGlob } from 'tinyglobby'
88
import which from 'which'
99

1010
import { debugLog } from '@socketsecurity/registry/lib/debug'
11+
import { resolveBinPath } from '@socketsecurity/registry/lib/npm'
1112

1213
import { directoryPatterns } from './ignore-by-default'
1314
import constants from '../constants'
@@ -179,27 +180,29 @@ export function findBinPathDetailsSync(binName: string): {
179180
path: string | undefined
180181
shadowed: boolean
181182
} {
182-
let shadowIndex = -1
183-
const bins =
183+
const binPaths =
184184
which.sync(binName, {
185185
all: true,
186186
nothrow: true
187187
}) ?? []
188-
let binPath: string | undefined
189-
for (let i = 0, { length } = bins; i < length; i += 1) {
190-
const bin = realpathSync.native(bins[i]!)
188+
let shadowIndex = -1
189+
let theBinPath: string | undefined
190+
for (let i = 0, { length } = binPaths; i < length; i += 1) {
191+
const binPath = binPaths[i]!
191192
// Skip our bin directory if it's in the front.
192-
if (path.dirname(bin) === shadowBinPath) {
193+
if (path.dirname(binPath) === shadowBinPath) {
193194
shadowIndex = i
194195
} else {
195-
binPath = bin
196+
theBinPath = resolveBinPath(binPath)
196197
break
197198
}
198199
}
199-
return { name: binName, path: binPath, shadowed: shadowIndex !== -1 }
200+
return { name: binName, path: theBinPath, shadowed: shadowIndex !== -1 }
200201
}
201202

202203
export function findNpmPathSync(npmBinPath: string): string | undefined {
204+
// Lazily access constants.WIN32.
205+
const { WIN32 } = constants
203206
let thePath = npmBinPath
204207
while (true) {
205208
const nmPath = path.join(thePath, NODE_MODULES)
@@ -223,8 +226,7 @@ export function findNpmPathSync(npmBinPath: string): string | undefined {
223226
// Optimistically look for the default location.
224227
(path.basename(thePath) === NPM ||
225228
// Chocolatey installs npm bins in the same directory as node bins.
226-
// Lazily access constants.WIN32.
227-
(constants.WIN32 && existsSync(path.join(thePath, `${NPM}.cmd`))))
229+
(WIN32 && existsSync(path.join(thePath, `${NPM}.cmd`))))
228230
) {
229231
return thePath
230232
}

0 commit comments

Comments
 (0)