@@ -3,11 +3,9 @@ import MagicString, { Bundle as MagicStringBundle } from 'magic-string';
33import type { ModuleInfo , PluginContext } from 'rollup' ;
44
55/** Generate a CSS bundle from Rollup context */
6- export function generateCssBundle ( {
7- getModuleIds,
8- getModuleInfo,
9- warn,
10- } : Pick < PluginContext , 'getModuleIds' | 'getModuleInfo' | 'warn' > ) : {
6+ export function generateCssBundle (
7+ plugin : Pick < PluginContext , 'getModuleIds' | 'getModuleInfo' | 'warn' > ,
8+ ) : {
119 bundle : MagicStringBundle ;
1210 extractedCssIds : Set < string > ;
1311} {
@@ -16,17 +14,18 @@ export function generateCssBundle({
1614
1715 // 1. identify CSS files to bundle
1816 const cssFiles : Record < string , ImportChain > = { } ;
19- for ( const id of getModuleIds ( ) ) {
17+ for ( const id of plugin . getModuleIds ( ) ) {
2018 if ( cssFileFilter . test ( id ) ) {
21- cssFiles [ id ] = buildImportChain ( id , { getModuleInfo , warn } ) ;
19+ cssFiles [ id ] = buildImportChain ( id , plugin ) ;
2220 }
2321 }
2422
2523 // 2. build bundle from import order
2624 for ( const id of sortModules ( cssFiles ) ) {
27- const { importedIdResolutions } = getModuleInfo ( id ) ?? { } ;
28- for ( const resolution of importedIdResolutions ?? [ ] ) {
29- if ( resolution . meta . css && ! extractedCssIds . has ( resolution . id ) ) {
25+ const { importedIds } = plugin . getModuleInfo ( id ) ?? { } ;
26+ for ( const importedId of importedIds ?? [ ] ) {
27+ const resolution = plugin . getModuleInfo ( importedId ) ;
28+ if ( resolution ?. meta . css && ! extractedCssIds . has ( resolution . id ) ) {
3029 extractedCssIds . add ( resolution . id ) ;
3130 cssBundle . addSource ( {
3231 filename : resolution . id ,
@@ -45,9 +44,9 @@ export type ImportChain = [id: string, order: number][];
4544/** Trace a file back through its importers, building an ordered list */
4645export function buildImportChain (
4746 id : string ,
48- { getModuleInfo , warn } : Pick < PluginContext , 'getModuleInfo' | 'warn' > ,
47+ plugin : Pick < PluginContext , 'getModuleInfo' | 'warn' > ,
4948) : ImportChain {
50- let mod : ModuleInfo | null = getModuleInfo ( id ) ! ;
49+ let mod : ModuleInfo | null = plugin . getModuleInfo ( id ) ! ;
5150 if ( ! mod ) {
5251 return [ ] ;
5352 }
@@ -61,14 +60,14 @@ export function buildImportChain(
6160 break ;
6261 }
6362 if ( chain . some ( ( [ id ] ) => id === lastImporterId ) ) {
64- warn (
63+ plugin . warn (
6564 `Circular import detected. Can’t determine ideal import order of module.\n${ chain
6665 . reverse ( )
6766 . join ( '\n → ' ) } `,
6867 ) ;
6968 break ;
7069 }
71- mod = getModuleInfo ( lastImporterId ) ;
70+ mod = plugin . getModuleInfo ( lastImporterId ) ;
7271 if ( ! mod ) {
7372 break ;
7473 }
0 commit comments