33 filenameToPascalCase,
44 filenameToTypingsFilename,
55 getCssModuleKeys,
6- generateGenericExportInterface
6+ generateGenericExportInterface,
77} = require ( "./utils" ) ;
88const persist = require ( "./persist" ) ;
99const verify = require ( "./verify" ) ;
@@ -16,39 +16,38 @@ const schema = {
1616 eol : {
1717 description :
1818 "Newline character to be used in generated d.ts files. Uses OS default. This option is overridden by the formatter option." ,
19- type : "string"
19+ type : "string" ,
2020 } ,
2121 banner : {
2222 description : "To add a 'banner' prefix to each generated `*.d.ts` file" ,
23- type : "string"
23+ type : "string" ,
2424 } ,
2525 formatter : {
2626 description :
2727 "Possible options: none and prettier (requires prettier package installed). Defaults to prettier if `prettier` module can be resolved" ,
28- enum : [ "prettier" , "none" ]
28+ enum : [ "prettier" , "none" ] ,
2929 } ,
3030 disableLocalsExport : {
31- description :
32- "Disable the use of locals export. Defaults to `false`" ,
33- type : "boolean"
31+ description : "Disable the use of locals export. Defaults to `false`" ,
32+ type : "boolean" ,
3433 } ,
3534 verifyOnly : {
3635 description :
3736 "Validate generated `*.d.ts` files and fail if an update is needed (useful in CI). Defaults to `false`" ,
38- type : "boolean"
39- }
37+ type : "boolean" ,
38+ } ,
4039 } ,
41- additionalProperties : false
40+ additionalProperties : false ,
4241} ;
4342
4443/** @type {any } */
4544const configuration = {
4645 name : "typings-for-css-modules-loader" ,
47- baseDataPath : "options"
46+ baseDataPath : "options" ,
4847} ;
4948
5049/** @type {((this: import('webpack').loader.LoaderContext, ...args: any[]) => void) & {pitch?: import('webpack').loader.Loader['pitch']} } */
51- module . exports = function ( content , ...args ) {
50+ module . exports = function ( content , ...args ) {
5251 const options = getOptions ( this ) || { } ;
5352
5453 validateOptions ( schema , options , configuration ) ;
@@ -58,9 +57,12 @@ module.exports = function(content, ...args) {
5857 }
5958
6059 // let's only check `exports.locals` for keys to avoid getting keys from the sourcemap when it's enabled
61- const cssModuleKeys = getCssModuleKeys (
62- content . substring ( content . indexOf ( "exports.locals" ) )
63- ) ;
60+ // if we cannot find locals, then the module only contains global styles
61+ const indexOfLocals = content . indexOf ( ".locals" ) ;
62+ const cssModuleKeys =
63+ indexOfLocals === - 1
64+ ? [ ]
65+ : getCssModuleKeys ( content . substring ( indexOfLocals ) ) ;
6466
6567 /** @type {any } */
6668 const callback = this . async ( ) ;
@@ -85,14 +87,14 @@ module.exports = function(content, ...args) {
8587 ) ;
8688
8789 applyFormattingAndOptions ( cssModuleDefinition , options )
88- . then ( output => {
90+ . then ( ( output ) => {
8991 if ( options . verifyOnly === true ) {
9092 return verify ( cssModuleInterfaceFilename , output ) ;
9193 } else {
9294 persist ( cssModuleInterfaceFilename , output ) ;
9395 }
9496 } )
95- . catch ( err => {
97+ . catch ( ( err ) => {
9698 this . emitError ( err ) ;
9799 } )
98100 . then ( successfulCallback ) ;
@@ -132,7 +134,7 @@ async function applyPrettier(input) {
132134 const prettier = require ( "prettier" ) ;
133135
134136 const config = await prettier . resolveConfig ( "./" , {
135- editorconfig : true
137+ editorconfig : true ,
136138 } ) ;
137139
138140 return prettier . format (
0 commit comments