@@ -24,32 +24,20 @@ export async function isMaybeV4(css: string): Promise<boolean> {
2424 return HAS_V4_THEME . test ( css ) || HAS_V4_IMPORT . test ( css )
2525}
2626
27- let jiti : Jiti | undefined
28-
29- async function importFile ( id : string ) {
30- try {
31- // Load ESM/CJS files through Node/Bun/whatever runtime is being used
32- return await import ( id )
33- } catch {
34- jiti ??= createJiti ( __filename , { moduleCache : false , fsCache : false } )
35-
36- // Transpile using Jiti if we can't load the file directly
37- return await jiti . import ( id )
38- }
39- }
40-
4127/**
4228 * Create a loader function that can load plugins and config files relative to
4329 * the CSS file that uses them. However, we don't want missing files to prevent
4430 * everything from working so we'll let the error handler decide how to proceed.
4531 */
4632function createLoader < T > ( {
4733 legacy,
34+ jiti,
4835 filepath,
4936 resolver,
5037 onError,
5138} : {
5239 legacy : boolean
40+ jiti : Jiti
5341 filepath : string
5442 resolver : Resolver
5543 onError : ( id : string , error : unknown , resourceType : string ) => T
@@ -63,7 +51,7 @@ function createLoader<T>({
6351 let url = pathToFileURL ( resolved )
6452 url . searchParams . append ( 't' , cacheKey )
6553
66- return await importFile ( url . href ) . then ( ( m ) => m . default ?? m )
54+ return await jiti . import ( url . href , { default : true } )
6755 } catch ( err ) {
6856 return onError ( id , err , resourceType )
6957 }
@@ -112,13 +100,20 @@ export async function loadDesignSystem(
112100 css = resolved . css
113101 }
114102
103+ // Create a Jiti instance that can be used to load plugins and config files
104+ let jiti = createJiti ( __filename , {
105+ moduleCache : false ,
106+ fsCache : false ,
107+ } )
108+
115109 // Step 3: Take the resolved CSS and pass it to v4's `loadDesignSystem`
116110 let design : DesignSystem = await tailwindcss . __unstable__loadDesignSystem ( css , {
117111 base : path . dirname ( filepath ) ,
118112
119113 // v4.0.0-alpha.25+
120114 loadModule : createLoader ( {
121115 legacy : false ,
116+ jiti,
122117 filepath,
123118 resolver,
124119 onError : ( id , err , resourceType ) => {
@@ -155,6 +150,7 @@ export async function loadDesignSystem(
155150 // v4.0.0-alpha.24 and below
156151 loadPlugin : createLoader ( {
157152 legacy : true ,
153+ jiti,
158154 filepath,
159155 resolver,
160156 onError ( id , err ) {
@@ -166,6 +162,7 @@ export async function loadDesignSystem(
166162
167163 loadConfig : createLoader ( {
168164 legacy : true ,
165+ jiti,
169166 filepath,
170167 resolver,
171168 onError ( id , err ) {
0 commit comments