File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 3
3
filenameToPascalCase,
4
4
filenameToTypingsFilename,
5
5
getCssModuleKeys,
6
+ getNamedExports,
6
7
generateGenericExportInterface,
7
8
} = require ( "./utils" ) ;
8
9
const persist = require ( "./persist" ) ;
@@ -63,9 +64,12 @@ module.exports = function (content, ...args) {
63
64
64
65
// let's only check `exports.locals` for keys to avoid getting keys from the sourcemap when it's enabled
65
66
// if we cannot find locals, then the module only contains global styles
67
+ const isModule = / (?: ^ | \n ) e x p o r t \s + (?: v a r | l e t | c o n s t ) \s + \S + \s * = / g. test ( content )
66
68
const indexOfLocals = content . indexOf ( ".locals" ) ;
67
69
const cssModuleKeys =
68
- indexOfLocals === - 1
70
+ isModule
71
+ ? getNamedExports ( content )
72
+ : indexOfLocals === - 1
69
73
? [ ]
70
74
: getCssModuleKeys ( content . substring ( indexOfLocals ) ) ;
71
75
Original file line number Diff line number Diff line change @@ -19,6 +19,19 @@ const getCssModuleKeys = (content) => {
19
19
return cssModuleKeys ;
20
20
} ;
21
21
22
+ const getNamedExports = ( content ) => {
23
+ const exportRegex = / (?: ^ | \n ) e x p o r t \s + (?: v a r | l e t | c o n s t ) \s + ( \S + ?) \s * = / g;
24
+ let match ;
25
+ const namedExports = [ ] ;
26
+
27
+ while ( ( match = exportRegex . exec ( content ) ) ) {
28
+ if ( namedExports . indexOf ( match [ 1 ] ) < 0 ) {
29
+ namedExports . push ( match [ 1 ] ) ;
30
+ }
31
+ }
32
+ return namedExports ;
33
+ } ;
34
+
22
35
/**
23
36
* @param {string } filename
24
37
*/
@@ -80,6 +93,7 @@ export = ${moduleName};`;
80
93
81
94
module . exports = {
82
95
getCssModuleKeys,
96
+ getNamedExports,
83
97
filenameToPascalCase,
84
98
filenameToTypingsFilename,
85
99
generateGenericExportInterface,
You can’t perform that action at this time.
0 commit comments