File tree Expand file tree Collapse file tree 1 file changed +32
-5
lines changed
Expand file tree Collapse file tree 1 file changed +32
-5
lines changed Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments