Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor
  • Loading branch information
thecrypticace committed Sep 23, 2024
commit 92046621ee2618ce0e0cf7a2eac7ca00bd896c08
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,31 @@ export async function isMaybeV4(css: string): Promise<boolean> {
* Create a loader function that can load plugins and config files relative to
* the CSS file that uses them. However, we don't want missing files to prevent
* everything from working so we'll let the error handler decide how to proceed.
*
* @param {object} param0
* @returns
*/
function createLoader<T>({
filepath,
onError,
}: {
filepath: string
onError: (id: string, error: unknown) => T
onError: (id: string, error: unknown, resourceType: string) => T
}) {
let baseDir = path.dirname(filepath)
let cacheKey = `${+Date.now()}`

return async function loadFile(id: string) {
async function loadFile(id: string, base: string, resourceType: string) {
try {
let resolved = resolveFrom(baseDir, id)
let resolved = resolveFrom(base, id)

let url = pathToFileURL(resolved)
url.searchParams.append('t', cacheKey)

return await import(url.href).then((m) => m.default ?? m)
} catch (err) {
return onError(id, err)
return onError(id, err, resourceType)
}
}

let baseDir = path.dirname(filepath)
return (id: string) => loadFile(id, baseDir, 'module')
}

export async function loadDesignSystem(
Expand Down