Skip to content

Commit 31b42d1

Browse files
committed
Attempt to fix path resolution of CLI modules on Windows #2
1 parent 09695fa commit 31b42d1

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

programs/cli/utils.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,39 @@ export async function requireOrDlx(
255255
let postInstallPkgJson: any
256256

257257
// If install reported success but the package.json is still missing,
258-
// surface a clear installation error instead of a misleading entry-point error.
258+
// attempt a last-resort npm install into the same cache directory before
259+
// surfacing a clear installation error.
259260
if (!fs.existsSync(pkgJsonPath)) {
260-
throw new Error(
261-
`Failed to install ${spec}: package.json not found at ${pkgJsonPath}. ` +
262-
'If you use a custom registry or auth, ensure your npm/pnpm config is visible to the Extension.js CLI.'
263-
)
261+
try {
262+
const args = [
263+
'i',
264+
spec,
265+
'--no-fund',
266+
'--no-audit',
267+
'--prefer-online',
268+
'--omit=dev',
269+
'--omit=optional',
270+
'--no-package-lock'
271+
]
272+
const npmStatus =
273+
spawnSync(isWin ? 'npm.cmd' : 'npm', args, {
274+
cwd: cacheDir,
275+
stdio: 'ignore'
276+
}).status || 0
277+
278+
if (npmStatus !== 0 || !fs.existsSync(pkgJsonPath)) {
279+
throw new Error(
280+
`Failed to install ${spec}: package.json not found at ${pkgJsonPath}. ` +
281+
'If you use a custom registry or auth, ensure your npm/pnpm config is visible to the Extension.js CLI.'
282+
)
283+
}
284+
} catch (err) {
285+
if (err instanceof Error) throw err
286+
throw new Error(
287+
`Failed to install ${spec}: package.json not found at ${pkgJsonPath}. ` +
288+
'If you use a custom registry or auth, ensure your npm/pnpm config is visible to the Extension.js CLI.'
289+
)
290+
}
264291
}
265292

266293
try {

0 commit comments

Comments
 (0)