@@ -209,10 +209,14 @@ if (isWatch) {
209209 'diff'
210210 ] ;
211211
212+ let fixedCount = 0 ;
213+ const missingFiles = [ ] ;
214+
212215 for ( const module of reactOutputModules ) {
213216 const indexPath = path . join ( outDir , module , 'index.js' ) ;
214217 if ( fs . existsSync ( indexPath ) ) {
215218 let content = fs . readFileSync ( indexPath , 'utf8' ) ;
219+ const originalContent = content ;
216220 // Fix import paths: React outputs are in sibling directories under out/
217221 // Replace './react/out/MODULE/index.js' with '../MODULE/index.js'
218222 // Replace '../react/out/MODULE/index.js' with '../../MODULE/index.js'
@@ -238,29 +242,45 @@ if (isWatch) {
238242 // Fix deep relative imports to VS Code platform/base modules
239243 // When tsup builds, relative imports are preserved, but the output file location
240244 // is different, so paths need adjustment. From out/MODULE/index.js, we need
241- // one more level up to reach the same target as from the source location.
242- // Example: ../../../../../base/... needs to become ../../../../../../base/...
245+ // two more levels up to reach the same target as from the source location.
246+ // Example: ../../../../../base/... (5 levels) needs to become ../../../../../../base/... (7 levels)
243247 // This fixes imports like: import { x } from '../../../../../base/common/platform.js'
244248 // which come from files like systemInfo.ts that import VS Code internal modules
245- // Match any relative import (../...) that leads to base/platform/editor/workbench and add one more level
249+ // Match any relative import (../...) that leads to base/platform/editor/workbench and add two more levels
246250 // Handle: import statements, dynamic imports, and require() calls
247251 content = content . replace (
248252 / ( f r o m \s + [ ' \" ] ) ( (?: \. \. \/ ) + ) ( b a s e | p l a t f o r m | e d i t o r | w o r k b e n c h ) \/ / g,
249- ( match , prefix , dots , module ) => `${ prefix } ${ dots } ../${ module } /`
253+ ( match , prefix , dots , module ) => `${ prefix } ${ dots } ../../ ${ module } /`
250254 ) ;
251255 content = content . replace (
252256 / ( i m p o r t \s * \( \s * [ ' \" ] ) ( (?: \. \. \/ ) + ) ( b a s e | p l a t f o r m | e d i t o r | w o r k b e n c h ) \/ / g,
253- ( match , prefix , dots , module ) => `${ prefix } ${ dots } ../${ module } /`
257+ ( match , prefix , dots , module ) => `${ prefix } ${ dots } ../../ ${ module } /`
254258 ) ;
255259 content = content . replace (
256260 / ( r e q u i r e \( [ ' \" ] ) ( (?: \. \. \/ ) + ) ( b a s e | p l a t f o r m | e d i t o r | w o r k b e n c h ) \/ / g,
257- ( match , prefix , dots , module ) => `${ prefix } ${ dots } ../${ module } /`
261+ ( match , prefix , dots , module ) => `${ prefix } ${ dots } ../../ ${ module } /`
258262 ) ;
259263
260- fs . writeFileSync ( indexPath , content , 'utf8' ) ;
264+ if ( content !== originalContent ) {
265+ fs . writeFileSync ( indexPath , content , 'utf8' ) ;
266+ fixedCount ++ ;
267+ console . log ( ` ✓ Fixed paths in ${ module } /index.js` ) ;
268+ }
269+ } else {
270+ missingFiles . push ( module ) ;
261271 }
262272 }
263273
274+ if ( fixedCount > 0 ) {
275+ // allow-any-unicode-next-line
276+ console . log ( `✅ Fixed import paths in ${ fixedCount } React output files` ) ;
277+ } else {
278+ console . log ( '⚠ No files needed fixing (paths already correct or files not found)' ) ;
279+ }
280+ if ( missingFiles . length > 0 ) {
281+ console . log ( `⚠ Missing files: ${ missingFiles . join ( ', ' ) } ` ) ;
282+ }
283+
264284 // allow-any-unicode-next-line
265285 console . log ( '✅ Build complete!' ) ;
266286}
0 commit comments