Skip to content
This repository was archived by the owner on Oct 30, 2020. It is now read-only.

Commit 659b2fb

Browse files
committed
use module keys right away intead of the complete module.export of the locals loader
1 parent caf1267 commit 659b2fb

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/cssModuleToInterface.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const filenameToInterfaceName = (filename) => {
66
.replace(/\W+(\w)/g, (_, c) => c.toUpperCase());
77
};
88

9-
const cssModuleToTypescriptInterfaceProperties = (cssModuleObject, indent = ' ') => {
10-
return Object.keys(cssModuleObject)
9+
const cssModuleToTypescriptInterfaceProperties = (cssModuleKeys, indent = ' ') => {
10+
return cssModuleKeys
1111
.map((key) => `${indent}'${key}': string;`)
1212
.join('\n');
1313
};
@@ -18,9 +18,9 @@ export const filenameToTypingsFilename = (filename) => {
1818
return path.join(dirName, `${baseName}.d.ts`);
1919
};
2020

21-
export const generateInterface = (cssModuleObject, filename, indent) => {
21+
export const generateInterface = (cssModuleKeys, filename, indent) => {
2222
const interfaceName = filenameToInterfaceName(filename);
23-
const interfaceProperties = cssModuleToTypescriptInterfaceProperties(cssModuleObject, indent);
23+
const interfaceProperties = cssModuleToTypescriptInterfaceProperties(cssModuleKeys, indent);
2424
return (
2525
`export interface ${interfaceName} {
2626
${interfaceProperties}

src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ module.exports = function(input) {
2727

2828
// mock async step 2 - offer css loader a "fake" callback
2929
this.async = () => (err, content) => {
30-
const cssmodules = this.exec(content, this.resource);
3130
const requestedResource = this.resourcePath;
32-
3331
const cssModuleInterfaceFilename = filenameToTypingsFilename(requestedResource);
34-
const cssModuleInterface = generateInterface(cssmodules, requestedResource);
32+
33+
let cssModuleKeys = Object.keys(this.exec(content, this.resource));
34+
35+
const cssModuleInterface = generateInterface(cssModuleKeys, requestedResource);
3536
persist.writeToFileIfChanged(cssModuleInterfaceFilename, cssModuleInterface);
3637
// mock async step 3 - make `async` return the actual callback again before calling the 'real' css-loader
3738
delegateToCssLoader(this, input, callback);

0 commit comments

Comments
 (0)