@@ -35,55 +35,28 @@ const loadConfigFile = quansync(async <T>(
3535 return code
3636 } )
3737
38- const clearCache = ( cache : any , paths : string [ ] ) => {
39- for ( const path of paths ) {
40- if ( cache [ path ] ) {
41- delete cache [ path ]
42- }
43- }
44- }
45-
4638 const importModule = quansync ( {
4739 sync : ( ) => {
4840 const { createJiti } = require ( 'jiti' ) as typeof import ( 'jiti' )
49-
50- // Clear Node.js require cache for the target file before loading
51- // This is crucial for hot-reload scenarios where file content changes
52- clearCache ( require . cache , [ bundleFilepath , filepath ] )
53-
54- const jiti = createJiti ( filepath , {
41+ const jiti = createJiti ( import . meta. url , {
5542 fsCache : false ,
5643 moduleCache : false ,
5744 interopDefault : true ,
5845 } )
59-
60- // Clear jiti cache for the target file
61- clearCache ( jiti . cache , [ bundleFilepath , filepath ] )
62-
6346 config = interopDefault ( jiti ( bundleFilepath ) )
64- dependencies = Object . values ( jiti . cache || { } )
47+ dependencies = Object . values ( jiti . cache )
6548 . map ( i => i . filename )
6649 . filter ( Boolean )
6750 } ,
6851 async : async ( ) => {
6952 const { createJiti } = await import ( 'jiti' )
70-
71- // Clear Node.js require cache for the target file before loading
72- clearCache ( require . cache , [ bundleFilepath , filepath ] )
73-
74- const jiti = createJiti ( filepath , {
53+ const jiti = createJiti ( import . meta. url , {
7554 fsCache : false ,
7655 moduleCache : false ,
7756 interopDefault : true ,
7857 } )
79-
80- // Clear jiti cache for the target file
81- clearCache ( jiti . cache , [ bundleFilepath , filepath ] )
82-
83- // Use sync jiti() instead of jiti.import() to avoid ESM cache issues
84- // jiti() uses CommonJS require which can be invalidated via require.cache
85- config = interopDefault ( jiti ( bundleFilepath ) )
86- dependencies = Object . values ( jiti . cache || { } )
58+ config = interopDefault ( await jiti . import ( bundleFilepath , { default : true } ) )
59+ dependencies = Object . values ( jiti . cache )
8760 . map ( i => i . filename )
8861 . filter ( Boolean )
8962 } ,
0 commit comments