@@ -2,7 +2,7 @@ import postcss from 'postcss';
22
33const declWhitelist = [ 'composes' ] ,
44 declFilter = new RegExp ( `^(${ declWhitelist . join ( '|' ) } )$` ) ,
5- matchImports = / ^ ( .+ ?) \s + f r o m \s + (?: " ( [ ^ " ] + ) " | ' ( [ ^ ' ] + ) ' ) $ / ,
5+ matchImports = / ^ ( .+ ?) \s + f r o m \s + (?: " ( [ ^ " ] + ) " | ' ( [ ^ ' ] + ) ' | ( g l o b a l ) ) $ / ,
66 icssImport = / ^ : i m p o r t \( (?: " ( [ ^ " ] + ) " | ' ( [ ^ ' ] + ) ' ) \) / ;
77
88const processor = postcss . plugin ( 'modules-extract-imports' , function ( options ) {
@@ -14,17 +14,23 @@ const processor = postcss.plugin( 'modules-extract-imports', function ( options
1414 // Find any declaration that supports imports
1515 css . walkDecls ( declFilter , ( decl ) => {
1616 let matches = decl . value . match ( matchImports ) ;
17+ let tmpSymbols ;
1718 if ( matches ) {
18- let [ /*match*/ , symbols , doubleQuotePath , singleQuotePath ] = matches ;
19- let path = doubleQuotePath || singleQuotePath ;
20- imports [ path ] = imports [ path ] || { } ;
21- let tmpSymbols = symbols . split ( / \s + / )
22- . map ( s => {
23- if ( ! imports [ path ] [ s ] ) {
24- imports [ path ] [ s ] = createImportedName ( s , path ) ;
25- }
26- return imports [ path ] [ s ] ;
27- } ) ;
19+ let [ /*match*/ , symbols , doubleQuotePath , singleQuotePath , global ] = matches ;
20+ if ( global ) {
21+ // Composing globals simply means changing these classes to wrap them in global(name)
22+ tmpSymbols = symbols . split ( / \s + / ) . map ( s => `global(${ s } )` )
23+ } else {
24+ let path = doubleQuotePath || singleQuotePath ;
25+ imports [ path ] = imports [ path ] || { } ;
26+ tmpSymbols = symbols . split ( / \s + / )
27+ . map ( s => {
28+ if ( ! imports [ path ] [ s ] ) {
29+ imports [ path ] [ s ] = createImportedName ( s , path ) ;
30+ }
31+ return imports [ path ] [ s ] ;
32+ } ) ;
33+ }
2834 decl . value = tmpSymbols . join ( ' ' ) ;
2935 }
3036 } ) ;
0 commit comments