1
1
// @ts -check
2
2
import * as fs from 'fs/promises'
3
- import { createRequire } from 'module'
4
3
import * as path from 'path'
5
4
import { pathToFileURL } from 'url'
6
5
import clearModule from 'clear-module'
@@ -21,8 +20,6 @@ import { expiringMap } from './expiring-map.js'
21
20
import { resolveFrom , resolveIn } from './resolve'
22
21
import type { ContextContainer } from './types'
23
22
24
- let localRequire = createRequire ( import . meta. url )
25
-
26
23
let sourceToPathMap = new Map < string , string | null > ( )
27
24
let sourceToEntryMap = new Map < string , string | null > ( )
28
25
let pathToContextMap = expiringMap < string | null , ContextContainer > ( 10_000 )
@@ -151,9 +148,6 @@ async function loadTailwindConfig(
151
148
* Create a loader function that can load plugins and config files relative to
152
149
* the CSS file that uses them. However, we don't want missing files to prevent
153
150
* everything from working so we'll let the error handler decide how to proceed.
154
- *
155
- * @param {object } param0
156
- * @returns
157
151
*/
158
152
function createLoader < T > ( {
159
153
filepath,
@@ -162,12 +156,11 @@ function createLoader<T>({
162
156
filepath : string
163
157
onError : ( id : string , error : unknown ) => T
164
158
} ) {
165
- let baseDir = path . dirname ( filepath )
166
159
let cacheKey = `${ + Date . now ( ) } `
167
160
168
- return async function loadFile ( id : string ) {
161
+ async function loadFile ( id : string , base : string ) {
169
162
try {
170
- let resolved = resolveFrom ( baseDir , id )
163
+ let resolved = resolveFrom ( base , id )
171
164
let url = pathToFileURL ( resolved )
172
165
url . searchParams . append ( 't' , cacheKey )
173
166
@@ -176,6 +169,9 @@ function createLoader<T>({
176
169
return onError ( id , err )
177
170
}
178
171
}
172
+
173
+ let baseDir = path . dirname ( filepath )
174
+ return ( id : string ) => loadFile ( id , baseDir )
179
175
}
180
176
181
177
async function loadV4 (
@@ -199,10 +195,11 @@ async function loadV4(
199
195
let css = await fs . readFile ( entryPoint , 'utf-8' )
200
196
let resolveImports = postcss ( [ postcssImport ( ) ] )
201
197
let result = await resolveImports . process ( css , { from : entryPoint } )
198
+ css = result . css
202
199
203
200
// Load the design system and set up a compatible context object that is
204
201
// usable by the rest of the plugin
205
- let design = await tw . __unstable__loadDesignSystem ( result . css , {
202
+ let design = await tw . __unstable__loadDesignSystem ( css , {
206
203
loadPlugin : createLoader ( {
207
204
filepath : entryPoint ,
208
205
onError ( id , err ) {
0 commit comments