@@ -2,7 +2,7 @@ import postcss from 'postcss';
2
2
3
3
const declWhitelist = [ 'composes' ] ,
4
4
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 ) ) $ / ,
6
6
icssImport = / ^ : i m p o r t \( (?: " ( [ ^ " ] + ) " | ' ( [ ^ ' ] + ) ' ) \) / ;
7
7
8
8
const processor = postcss . plugin ( 'modules-extract-imports' , function ( options ) {
@@ -14,17 +14,23 @@ const processor = postcss.plugin( 'modules-extract-imports', function ( options
14
14
// Find any declaration that supports imports
15
15
css . walkDecls ( declFilter , ( decl ) => {
16
16
let matches = decl . value . match ( matchImports ) ;
17
+ let tmpSymbols ;
17
18
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
+ }
28
34
decl . value = tmpSymbols . join ( ' ' ) ;
29
35
}
30
36
} ) ;
0 commit comments