@@ -41,6 +41,7 @@ type WebpackMeta = {
4141} ;
4242
4343type Meta = NextMeta | ViteMeta | WebpackMeta ;
44+ export type AsyncResolver = ( what : string , importer : string , stack : string [ ] ) => Promise < string > ;
4445
4546export type PigmentOptions < Theme extends BaseTheme = BaseTheme > = {
4647 theme ?: Theme ;
@@ -49,7 +50,7 @@ export type PigmentOptions<Theme extends BaseTheme = BaseTheme> = {
4950 debug ?: IFileReporterOptions | false ;
5051 sourceMap ?: boolean ;
5152 meta ?: Meta ;
52- asyncResolve ?: ( what : string ) => string | null ;
53+ asyncResolve ?: ( ... args : Parameters < AsyncResolver > ) => Promise < string | null > ;
5354 transformSx ?: boolean ;
5455} & Partial < WywInJsPluginOptions > ;
5556
@@ -62,8 +63,6 @@ function hasCorectExtension(fileName: string) {
6263const VIRTUAL_CSS_FILE = `\0zero-runtime-styles.css` ;
6364const VIRTUAL_THEME_FILE = `\0zero-runtime-theme.js` ;
6465
65- type AsyncResolver = ( what : string , importer : string , stack : string [ ] ) => Promise < string > ;
66-
6766function isZeroRuntimeThemeFile ( fileName : string ) {
6867 return fileName === VIRTUAL_CSS_FILE || fileName === VIRTUAL_THEME_FILE ;
6968}
@@ -142,14 +141,15 @@ export const plugin = createUnplugin<PigmentOptions, true>((options) => {
142141 let webpackResolver : AsyncResolver ;
143142
144143 const asyncResolve : AsyncResolver = async ( what , importer , stack ) => {
145- const result = asyncResolveOpt ?.( what ) ;
144+ const result = await asyncResolveOpt ?.( what , importer , stack ) ;
146145 if ( typeof result === 'string' ) {
147146 return result ;
148147 }
149148 // Use Webpack's resolver to resolve actual path but
150149 // ignore next.js files during evaluation phase of WyW
151150 if ( webpackResolver && ! what . startsWith ( 'next' ) ) {
152- return webpackResolver ( what , importer , stack ) ;
151+ const resolved = webpackResolver ( what , importer , stack ) ;
152+ return resolved ;
153153 }
154154 return asyncResolveFallback ( what , importer , stack ) ;
155155 } ;
0 commit comments