Skip to content

Commit e2b1502

Browse files
greglockwoodmarkdalgleish
authored andcommitted
fix(emit): Omit source map keys from generated types (#12)
1 parent e7342df commit e2b1502

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module.exports = function(content, ...rest) {
6363
const cssModuleInterfaceFilename = filenameToTypingsFilename(filename);
6464
const { read, write } = makeFileHandlers(cssModuleInterfaceFilename);
6565

66-
const keyRegex = /"([^\\"]+)":/g;
66+
const keyRegex = /"([^\\"]+)":\s*"(?:[^\\"]+)",?$/gm;
6767
let match;
6868
const cssModuleKeys = [];
6969

test/compiler.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const webpack = require('webpack');
33
const memoryfs = require('memory-fs');
44

55
module.exports = (entry, options = {}) => {
6+
const { sourceMap, ...loaderOptions } = options;
67
const compiler = webpack({
78
context: path.dirname(entry),
89
entry,
@@ -17,12 +18,13 @@ module.exports = (entry, options = {}) => {
1718
use: [
1819
{
1920
loader: require.resolve('../index.js'),
20-
options
21+
options: loaderOptions
2122
},
2223
{
2324
loader: 'css-loader',
2425
options: {
25-
modules: true
26+
modules: true,
27+
sourceMap: !!sourceMap
2628
}
2729
}
2830
]

test/emit-declaration/__snapshots__/emit-declaration.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Can emit valid declaration 1`] = `
3+
exports[`Can emit valid declaration without sourceMaps 1`] = `
44
"// This file is automatically generated.
55
// Please do not change this file!
66
interface CssExports {

test/emit-declaration/emit-declaration.test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require('fs');
22
const compiler = require('../compiler.js');
33

4-
test('Can emit valid declaration', async () => {
4+
test('Can emit valid declaration without sourceMaps', async () => {
55
await compiler(require.resolve('./index.js'));
66

77
const declaration = fs.readFileSync(
@@ -11,3 +11,26 @@ test('Can emit valid declaration', async () => {
1111

1212
expect(declaration).toMatchSnapshot();
1313
});
14+
15+
test('Can emit valid declaration with sourceMap', async () => {
16+
await compiler(require.resolve('./index.js'), { sourceMap: true });
17+
18+
const declaration = fs.readFileSync(
19+
require.resolve('./index.css.d.ts'),
20+
'utf-8'
21+
);
22+
23+
expect(declaration).toMatchInlineSnapshot(`
24+
"// This file is automatically generated.
25+
// Please do not change this file!
26+
interface CssExports {
27+
'otherClass': string;
28+
'someClass': string;
29+
'validClass': string;
30+
}
31+
declare var cssExports: CssExports;
32+
export = cssExports;
33+
"
34+
`);
35+
});
36+

0 commit comments

Comments
 (0)