Skip to content

Commit d98c840

Browse files
committed
Refactor
1 parent 15e8009 commit d98c840

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/config.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @ts-check
22
import * as fs from 'fs/promises'
3-
import { createRequire } from 'module'
43
import * as path from 'path'
54
import { pathToFileURL } from 'url'
65
import clearModule from 'clear-module'
@@ -21,8 +20,6 @@ import { expiringMap } from './expiring-map.js'
2120
import { resolveFrom, resolveIn } from './resolve'
2221
import type { ContextContainer } from './types'
2322

24-
let localRequire = createRequire(import.meta.url)
25-
2623
let sourceToPathMap = new Map<string, string | null>()
2724
let sourceToEntryMap = new Map<string, string | null>()
2825
let pathToContextMap = expiringMap<string | null, ContextContainer>(10_000)
@@ -162,12 +159,11 @@ function createLoader<T>({
162159
filepath: string
163160
onError: (id: string, error: unknown) => T
164161
}) {
165-
let baseDir = path.dirname(filepath)
166162
let cacheKey = `${+Date.now()}`
167163

168-
return async function loadFile(id: string) {
164+
async function loadFile(id: string, base: string) {
169165
try {
170-
let resolved = resolveFrom(baseDir, id)
166+
let resolved = resolveFrom(base, id)
171167
let url = pathToFileURL(resolved)
172168
url.searchParams.append('t', cacheKey)
173169

@@ -176,6 +172,9 @@ function createLoader<T>({
176172
return onError(id, err)
177173
}
178174
}
175+
176+
let baseDir = path.dirname(filepath)
177+
return (id: string) => loadFile(id, baseDir)
179178
}
180179

181180
async function loadV4(
@@ -199,10 +198,11 @@ async function loadV4(
199198
let css = await fs.readFile(entryPoint, 'utf-8')
200199
let resolveImports = postcss([postcssImport()])
201200
let result = await resolveImports.process(css, { from: entryPoint })
201+
css = result.css
202202

203203
// Load the design system and set up a compatible context object that is
204204
// usable by the rest of the plugin
205-
let design = await tw.__unstable__loadDesignSystem(result.css, {
205+
let design = await tw.__unstable__loadDesignSystem(css, {
206206
loadPlugin: createLoader({
207207
filepath: entryPoint,
208208
onError(id, err) {

0 commit comments

Comments
 (0)