@@ -69,11 +69,38 @@ if (!fs.existsSync(realExecutable)) {
6969process . env . BUN_INSTALL = versionDir ;
7070process . env . PATH = binDir + path . delimiter + process . env . PATH ;
7171
72+ // --- Transparent Global/Local Install Acceleration & Fixes ---
73+ if ( CMD === 'bun' || CMD === 'bunx' ) {
74+ const installCmds = [ 'install' , 'i' , 'add' , 'a' , 'upgrade' ] ;
75+ const isInstall = ARGS . some ( arg => installCmds . includes ( arg ) ) ;
76+
77+ if ( isInstall ) {
78+ const isGlobal = ARGS . includes ( '-g' ) || ARGS . includes ( '--global' ) ;
79+ const hasRegistryArg = ARGS . includes ( '--registry' ) ;
80+
81+ // 1. Safe Back-off check: Don't interfere if project has config
82+ let hasLocalConfig = false ;
83+ try {
84+ if ( fs . existsSync ( '.npmrc' ) || fs . existsSync ( 'bunfig.toml' ) ) {
85+ hasLocalConfig = true ;
86+ }
87+ } catch ( e ) { }
88+
89+ // 2. Auto-inject Registry for CN users
90+ if ( ! hasRegistryArg && ( isGlobal || ! hasLocalConfig ) ) {
91+ if ( process . env . BVM_REGION === 'cn' || fs . existsSync ( path . join ( BVM_DIR , '.cn' ) ) ) {
92+ ARGS . push ( '--registry' , 'https://registry.npmmirror.com' ) ;
93+ }
94+ }
95+ }
96+ }
97+
7298const child = spawn ( realExecutable , ARGS , { stdio : 'inherit' , shell : false } ) ;
7399child . on ( 'exit' , ( code ) => {
74100 if ( code === 0 && ( CMD === 'bun' || CMD === 'bunx' ) ) {
75101 const isGlobal = ARGS . includes ( '-g' ) || ARGS . includes ( '--global' ) ;
76- const isInstall = ARGS . includes ( 'install' ) || ARGS . includes ( 'add' ) || ARGS . includes ( 'remove' ) || ARGS . includes ( 'upgrade' ) ;
102+ const installCmds = [ 'install' , 'i' , 'add' , 'a' , 'remove' , 'rm' , 'upgrade' ] ;
103+ const isInstall = ARGS . some ( arg => installCmds . includes ( arg ) ) ;
77104
78105 if ( isGlobal && isInstall ) {
79106 try {
0 commit comments