@@ -3,11 +3,9 @@ import MagicString, { Bundle as MagicStringBundle } from 'magic-string';
3
3
import type { ModuleInfo , PluginContext } from 'rollup' ;
4
4
5
5
/** 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
+ ) : {
11
9
bundle : MagicStringBundle ;
12
10
extractedCssIds : Set < string > ;
13
11
} {
@@ -16,15 +14,15 @@ export function generateCssBundle({
16
14
17
15
// 1. identify CSS files to bundle
18
16
const cssFiles : Record < string , ImportChain > = { } ;
19
- for ( const id of getModuleIds ( ) ) {
17
+ for ( const id of plugin . getModuleIds ( ) ) {
20
18
if ( cssFileFilter . test ( id ) ) {
21
- cssFiles [ id ] = buildImportChain ( id , { getModuleInfo , warn } ) ;
19
+ cssFiles [ id ] = buildImportChain ( id , plugin ) ;
22
20
}
23
21
}
24
22
25
23
// 2. build bundle from import order
26
24
for ( const id of sortModules ( cssFiles ) ) {
27
- const { importedIdResolutions } = getModuleInfo ( id ) ?? { } ;
25
+ const { importedIdResolutions } = plugin . getModuleInfo ( id ) ?? { } ;
28
26
for ( const resolution of importedIdResolutions ?? [ ] ) {
29
27
if ( resolution . meta . css && ! extractedCssIds . has ( resolution . id ) ) {
30
28
extractedCssIds . add ( resolution . id ) ;
@@ -45,9 +43,9 @@ export type ImportChain = [id: string, order: number][];
45
43
/** Trace a file back through its importers, building an ordered list */
46
44
export function buildImportChain (
47
45
id : string ,
48
- { getModuleInfo , warn } : Pick < PluginContext , 'getModuleInfo' | 'warn' > ,
46
+ plugin : Pick < PluginContext , 'getModuleInfo' | 'warn' > ,
49
47
) : ImportChain {
50
- let mod : ModuleInfo | null = getModuleInfo ( id ) ! ;
48
+ let mod : ModuleInfo | null = plugin . getModuleInfo ( id ) ! ;
51
49
if ( ! mod ) {
52
50
return [ ] ;
53
51
}
@@ -61,14 +59,14 @@ export function buildImportChain(
61
59
break ;
62
60
}
63
61
if ( chain . some ( ( [ id ] ) => id === lastImporterId ) ) {
64
- warn (
62
+ plugin . warn (
65
63
`Circular import detected. Can’t determine ideal import order of module.\n${ chain
66
64
. reverse ( )
67
65
. join ( '\n → ' ) } `,
68
66
) ;
69
67
break ;
70
68
}
71
- mod = getModuleInfo ( lastImporterId ) ;
69
+ mod = plugin . getModuleInfo ( lastImporterId ) ;
72
70
if ( ! mod ) {
73
71
break ;
74
72
}
0 commit comments