@@ -15,7 +15,7 @@ import type {PageLink} from "./pager.js";
15
15
import { findLink , normalizePath } from "./pager.js" ;
16
16
import { isAssetPath , resolvePath , resolveRelativePath } from "./path.js" ;
17
17
import type { Resolvers } from "./resolvers.js" ;
18
- import { getModuleStaticImports , getResolvers } from "./resolvers.js" ;
18
+ import { getModuleResolver , getModuleStaticImports , getResolvers } from "./resolvers.js" ;
19
19
import { rollupClient } from "./rollup.js" ;
20
20
21
21
export interface RenderOptions extends Config {
@@ -281,16 +281,26 @@ function hasGoogleFonts(stylesheets: Set<string>): boolean {
281
281
return false ;
282
282
}
283
283
284
+ export type RenderModuleOptions = Omit < TranspileModuleOptions , "root" | "path" | "servePath" | "params" > ;
285
+
284
286
export async function renderModule (
285
287
root : string ,
286
288
path : string ,
287
- options ?: Omit < TranspileModuleOptions , " root" | " path" | "servePath" | "params" >
289
+ { resolveImport = getModuleResolver ( root , path ) , ... options } : RenderModuleOptions = { }
288
290
) : Promise < string > {
289
291
const module = findModule ( root , path ) ;
290
292
if ( ! module ) throw enoent ( path ) ;
291
- const input = `${ ( await getModuleStaticImports ( root , path ) )
292
- . map ( ( i ) => `import ${ JSON . stringify ( i ) } ;\n` )
293
- . join ( "" ) } export * from ${ JSON . stringify ( path ) } ;
294
- ` ;
295
- return await transpileModule ( input , { root, path, servePath : path , params : module . params , ...options } ) ;
293
+ const imports = new Set < string > ( ) ;
294
+ const resolutions = new Set < string > ( ) ;
295
+ for ( const i of await getModuleStaticImports ( root , path ) ) {
296
+ const r = await resolveImport ( i ) ;
297
+ if ( ! resolutions . has ( r ) ) {
298
+ resolutions . add ( r ) ;
299
+ imports . add ( i ) ;
300
+ }
301
+ }
302
+ const input = Array . from ( imports , ( i ) => `import ${ JSON . stringify ( i ) } ;\n` )
303
+ . concat ( `export * from ${ JSON . stringify ( path ) } ;\n` )
304
+ . join ( "" ) ;
305
+ return await transpileModule ( input , { root, path, servePath : path , params : module . params , resolveImport, ...options } ) ;
296
306
}
0 commit comments