@@ -24,8 +24,20 @@ import {
2424import { tmpdir } from "node:os" ;
2525import { basename , dirname , isAbsolute , join , posix , relative } from "node:path" ;
2626import { fileURLToPath , pathToFileURL } from "node:url" ;
27+ import {
28+ createBundledRuntimeDependencyInstallArgs ,
29+ createBundledRuntimeDependencyInstallEnv ,
30+ createNestedNpmInstallEnv ,
31+ runBundledRuntimeDependencyNpmInstall ,
32+ } from "./lib/bundled-runtime-deps-install.mjs" ;
2733import { resolveNpmRunner } from "./npm-runner.mjs" ;
2834
35+ export {
36+ createBundledRuntimeDependencyInstallArgs ,
37+ createBundledRuntimeDependencyInstallEnv ,
38+ createNestedNpmInstallEnv ,
39+ } ;
40+
2941export const BUNDLED_PLUGIN_INSTALL_TARGETS = [ ] ;
3042
3143const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
@@ -582,32 +594,6 @@ export function discoverBundledPluginRuntimeDeps(params = {}) {
582594 . toSorted ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
583595}
584596
585- export function createNestedNpmInstallEnv ( env = process . env ) {
586- const nextEnv = { ...env } ;
587- delete nextEnv . npm_config_global ;
588- delete nextEnv . npm_config_location ;
589- delete nextEnv . npm_config_prefix ;
590- return nextEnv ;
591- }
592-
593- export function createBundledRuntimeDependencyInstallEnv ( env = process . env ) {
594- return {
595- ...createNestedNpmInstallEnv ( env ) ,
596- npm_config_dry_run : "false" ,
597- npm_config_fetch_retries : env . npm_config_fetch_retries ?? "5" ,
598- npm_config_fetch_retry_maxtimeout : env . npm_config_fetch_retry_maxtimeout ?? "120000" ,
599- npm_config_fetch_retry_mintimeout : env . npm_config_fetch_retry_mintimeout ?? "10000" ,
600- npm_config_fetch_timeout : env . npm_config_fetch_timeout ?? "300000" ,
601- npm_config_legacy_peer_deps : "true" ,
602- npm_config_package_lock : "false" ,
603- npm_config_save : "false" ,
604- } ;
605- }
606-
607- export function createBundledRuntimeDependencyInstallArgs ( missingSpecs ) {
608- return [ "install" , "--ignore-scripts" , ...missingSpecs ] ;
609- }
610-
611597function shouldEagerInstallBundledPluginDeps ( env = process . env ) {
612598 return env ?. [ EAGER_BUNDLED_PLUGIN_DEPS_ENV ] ?. trim ( ) === "1" ;
613599}
@@ -1003,19 +989,12 @@ export function runBundledPluginPostinstall(params = {}) {
1003989 comSpec : params . comSpec ,
1004990 npmArgs : createBundledRuntimeDependencyInstallArgs ( missingSpecs ) ,
1005991 } ) ;
1006- const result = spawn ( npmRunner . command , npmRunner . args , {
992+ runBundledRuntimeDependencyNpmInstall ( {
1007993 cwd : packageRoot ,
1008- encoding : "utf8" ,
994+ npmRunner ,
1009995 env : npmRunner . env ?? installEnv ,
1010- stdio : "pipe" ,
1011- windowsHide : true ,
1012- shell : npmRunner . shell ,
1013- windowsVerbatimArguments : npmRunner . windowsVerbatimArguments ,
996+ spawnSyncImpl : spawn ,
1014997 } ) ;
1015- if ( result . status !== 0 ) {
1016- const output = [ result . stderr , result . stdout ] . filter ( Boolean ) . join ( "\n" ) . trim ( ) ;
1017- throw new Error ( output || "npm install failed" ) ;
1018- }
1019998 log . log ( `[postinstall] installed bundled plugin deps: ${ missingSpecs . join ( ", " ) } ` ) ;
1020999 } catch ( e ) {
10211000 // Non-fatal: gateway will surface the missing dep via doctor.
0 commit comments