Skip to content

Commit 4fe95f9

Browse files
fix: crash with source maps when the parallel option is false (#53)
1 parent bdb3f52 commit 4fe95f9

File tree

6 files changed

+209
-69
lines changed

6 files changed

+209
-69
lines changed

src/minify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const minify = async (options) => {
4949

5050
return {
5151
code: result.css,
52-
map: result.map,
52+
map: result.map && result.map.toString(),
5353
warnings: warningsToString(result.warnings()),
5454
};
5555
};

test/__snapshots__/sourceMap-option.test.js.snap.webpack4

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,92 @@ exports[`when applied with "sourceMap" option should work with SourceMapDevToolP
6969

7070
exports[`when applied with "sourceMap" option should work with SourceMapDevToolPlugin plugin): warnings 1`] = `Array []`;
7171

72+
exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: assets 1`] = `
73+
Object {
74+
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
75+
/*# sourceMappingURL=entry.css.map*/",
76+
"entry.css.map": {
77+
"version": 3,
78+
"sources": [
79+
"webpack:///./sourcemap/bar.scss",
80+
"webpack:///./sourcemap/foo.scss"
81+
],
82+
"names": [],
83+
"mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB",
84+
"file": "entry.css",
85+
"sourcesContent": [
86+
"body {\\n font-weight: bold;\\n}",
87+
"@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}"
88+
],
89+
"sourceRoot": ""
90+
},
91+
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
92+
/*# sourceMappingURL=entry2.css.map*/",
93+
"entry2.css.map": {
94+
"version": 3,
95+
"sources": [
96+
"webpack:///./sourcemap/bar.scss",
97+
"webpack:///./sourcemap/foo.css"
98+
],
99+
"names": [],
100+
"mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB",
101+
"file": "entry2.css",
102+
"sourcesContent": [
103+
"body {\\n font-weight: bold;\\n}",
104+
"@import 'bar';\\n\\nbody {\\n color: red;\\n}\\n\\nbody a {\\n text-align: center;\\n}"
105+
],
106+
"sourceRoot": ""
107+
},
108+
}
109+
`;
110+
111+
exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: errors 1`] = `Array []`;
112+
113+
exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: warnings 1`] = `Array []`;
114+
115+
exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: assets 1`] = `
116+
Object {
117+
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
118+
/*# sourceMappingURL=entry.css.map*/",
119+
"entry.css.map": {
120+
"version": 3,
121+
"sources": [
122+
"webpack:///./sourcemap/bar.scss",
123+
"webpack:///./sourcemap/foo.scss"
124+
],
125+
"names": [],
126+
"mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB",
127+
"file": "entry.css",
128+
"sourcesContent": [
129+
"body {\\n font-weight: bold;\\n}",
130+
"@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}"
131+
],
132+
"sourceRoot": ""
133+
},
134+
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
135+
/*# sourceMappingURL=entry2.css.map*/",
136+
"entry2.css.map": {
137+
"version": 3,
138+
"sources": [
139+
"webpack:///./sourcemap/bar.scss",
140+
"webpack:///./sourcemap/foo.css"
141+
],
142+
"names": [],
143+
"mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB",
144+
"file": "entry2.css",
145+
"sourcesContent": [
146+
"body {\\n font-weight: bold;\\n}",
147+
"@import 'bar';\\n\\nbody {\\n color: red;\\n}\\n\\nbody a {\\n text-align: center;\\n}"
148+
],
149+
"sourceRoot": ""
150+
},
151+
}
152+
`;
153+
154+
exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: errors 1`] = `Array []`;
155+
156+
exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: warnings 1`] = `Array []`;
157+
72158
exports[`when applied with "sourceMap" option should work with the "devtool" option: assets 1`] = `
73159
Object {
74160
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}

test/__snapshots__/sourceMap-option.test.js.snap.webpack5

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,92 @@ exports[`when applied with "sourceMap" option should work with SourceMapDevToolP
6969

7070
exports[`when applied with "sourceMap" option should work with SourceMapDevToolPlugin plugin): warnings 1`] = `Array []`;
7171

72+
exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: assets 1`] = `
73+
Object {
74+
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
75+
/*# sourceMappingURL=entry.css.map*/",
76+
"entry.css.map": {
77+
"version": 3,
78+
"sources": [
79+
"webpack:///./sourcemap/bar.scss",
80+
"webpack:///./sourcemap/foo.scss"
81+
],
82+
"names": [],
83+
"mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB",
84+
"file": "entry.css",
85+
"sourcesContent": [
86+
"body {\\n font-weight: bold;\\n}",
87+
"@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}"
88+
],
89+
"sourceRoot": ""
90+
},
91+
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
92+
/*# sourceMappingURL=entry2.css.map*/",
93+
"entry2.css.map": {
94+
"version": 3,
95+
"sources": [
96+
"webpack:///./sourcemap/bar.scss",
97+
"webpack:///./sourcemap/foo.css"
98+
],
99+
"names": [],
100+
"mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB",
101+
"file": "entry2.css",
102+
"sourcesContent": [
103+
"body {\\n font-weight: bold;\\n}",
104+
"@import 'bar';\\n\\nbody {\\n color: red;\\n}\\n\\nbody a {\\n text-align: center;\\n}"
105+
],
106+
"sourceRoot": ""
107+
},
108+
}
109+
`;
110+
111+
exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: errors 1`] = `Array []`;
112+
113+
exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: warnings 1`] = `Array []`;
114+
115+
exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: assets 1`] = `
116+
Object {
117+
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
118+
/*# sourceMappingURL=entry.css.map*/",
119+
"entry.css.map": {
120+
"version": 3,
121+
"sources": [
122+
"webpack:///./sourcemap/bar.scss",
123+
"webpack:///./sourcemap/foo.scss"
124+
],
125+
"names": [],
126+
"mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB",
127+
"file": "entry.css",
128+
"sourcesContent": [
129+
"body {\\n font-weight: bold;\\n}",
130+
"@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}"
131+
],
132+
"sourceRoot": ""
133+
},
134+
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
135+
/*# sourceMappingURL=entry2.css.map*/",
136+
"entry2.css.map": {
137+
"version": 3,
138+
"sources": [
139+
"webpack:///./sourcemap/bar.scss",
140+
"webpack:///./sourcemap/foo.css"
141+
],
142+
"names": [],
143+
"mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB",
144+
"file": "entry2.css",
145+
"sourcesContent": [
146+
"body {\\n font-weight: bold;\\n}",
147+
"@import 'bar';\\n\\nbody {\\n color: red;\\n}\\n\\nbody a {\\n text-align: center;\\n}"
148+
],
149+
"sourceRoot": ""
150+
},
151+
}
152+
`;
153+
154+
exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: errors 1`] = `Array []`;
155+
156+
exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: warnings 1`] = `Array []`;
157+
72158
exports[`when applied with "sourceMap" option should work with the "devtool" option: assets 1`] = `
73159
Object {
74160
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}

test/__snapshots__/worker.test.js.snap.webpack4

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,11 @@ Array [
88

99
exports[`worker should minify css: css 1`] = `".foo{color:red}.bar{color:coral}"`;
1010

11-
exports[`worker should minify css: map 1`] = `
12-
Object {
13-
"file": "entry.css",
14-
"mappings": "AAAA,KAAK,SAAA,CCCL,KAAK,WAAY",
15-
"names": Array [],
16-
"sources": Array [
17-
"foo.css",
18-
"entry.css",
19-
],
20-
"sourcesContent": Array [
21-
".foo{color:red;}",
22-
".foo{color:red;}
23-
.bar{color:coral;}",
24-
],
25-
"version": 3,
26-
}
27-
`;
11+
exports[`worker should minify css: map 1`] = `"{\\"version\\":3,\\"sources\\":[\\"foo.css\\",\\"entry.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,KAAK,SAAA,CCCL,KAAK,WAAY\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\".foo{color:red;}\\",\\".foo{color:red;}\\\\n.bar{color:coral;}\\"]}"`;
2812

2913
exports[`worker should work inputSourceMap as prev: css 1`] = `".foo{color:red}.bar{color:coral}"`;
3014

31-
exports[`worker should work inputSourceMap as prev: map 1`] = `
32-
Object {
33-
"file": "entry.css",
34-
"mappings": "AAAA,KAAK,SAAA,CCCL,KAAK,WAAY",
35-
"names": Array [],
36-
"sources": Array [
37-
"foo.css",
38-
"entry.css",
39-
],
40-
"sourcesContent": Array [
41-
".foo{color:red;}",
42-
".foo{color:red;}
43-
.bar{color:coral;}",
44-
],
45-
"version": 3,
46-
}
47-
`;
15+
exports[`worker should work inputSourceMap as prev: map 1`] = `"{\\"version\\":3,\\"sources\\":[\\"foo.css\\",\\"entry.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,KAAK,SAAA,CCCL,KAAK,WAAY\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\".foo{color:red;}\\",\\".foo{color:red;}\\\\n.bar{color:coral;}\\"]}"`;
4816

4917
exports[`worker should work options.minify function: css 1`] = `".minify {};"`;
5018

test/__snapshots__/worker.test.js.snap.webpack5

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,11 @@ Array [
88

99
exports[`worker should minify css: css 1`] = `".foo{color:red}.bar{color:coral}"`;
1010

11-
exports[`worker should minify css: map 1`] = `
12-
Object {
13-
"file": "entry.css",
14-
"mappings": "AAAA,KAAK,SAAA,CCCL,KAAK,WAAY",
15-
"names": Array [],
16-
"sources": Array [
17-
"foo.css",
18-
"entry.css",
19-
],
20-
"sourcesContent": Array [
21-
".foo{color:red;}",
22-
".foo{color:red;}
23-
.bar{color:coral;}",
24-
],
25-
"version": 3,
26-
}
27-
`;
11+
exports[`worker should minify css: map 1`] = `"{\\"version\\":3,\\"sources\\":[\\"foo.css\\",\\"entry.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,KAAK,SAAA,CCCL,KAAK,WAAY\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\".foo{color:red;}\\",\\".foo{color:red;}\\\\n.bar{color:coral;}\\"]}"`;
2812

2913
exports[`worker should work inputSourceMap as prev: css 1`] = `".foo{color:red}.bar{color:coral}"`;
3014

31-
exports[`worker should work inputSourceMap as prev: map 1`] = `
32-
Object {
33-
"file": "entry.css",
34-
"mappings": "AAAA,KAAK,SAAA,CCCL,KAAK,WAAY",
35-
"names": Array [],
36-
"sources": Array [
37-
"foo.css",
38-
"entry.css",
39-
],
40-
"sourcesContent": Array [
41-
".foo{color:red;}",
42-
".foo{color:red;}
43-
.bar{color:coral;}",
44-
],
45-
"version": 3,
46-
}
47-
`;
15+
exports[`worker should work inputSourceMap as prev: map 1`] = `"{\\"version\\":3,\\"sources\\":[\\"foo.css\\",\\"entry.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,KAAK,SAAA,CCCL,KAAK,WAAY\\",\\"file\\":\\"entry.css\\",\\"sourcesContent\\":[\\".foo{color:red;}\\",\\".foo{color:red;}\\\\n.bar{color:coral;}\\"]}"`;
4816

4917
exports[`worker should work options.minify function: css 1`] = `".minify {};"`;
5018

test/sourceMap-option.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,38 @@ describe('when applied with "sourceMap" option', () => {
7070
expect(getWarnings(stats)).toMatchSnapshot('warnings');
7171
});
7272

73+
it('should work with the "devtool" option and the "parallel" option with "false" value', async () => {
74+
const compiler = getCompiler(baseConfig);
75+
76+
new CssMinimizerPlugin({
77+
parallel: false,
78+
}).apply(compiler);
79+
80+
const stats = await compile(compiler);
81+
82+
expect(readAssets(compiler, stats, /\.css(\.map)?$/)).toMatchSnapshot(
83+
'assets'
84+
);
85+
expect(getErrors(stats)).toMatchSnapshot('errors');
86+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
87+
});
88+
89+
it('should work with the "devtool" option and the "parallel" option with "true" value', async () => {
90+
const compiler = getCompiler(baseConfig);
91+
92+
new CssMinimizerPlugin({
93+
parallel: true,
94+
}).apply(compiler);
95+
96+
const stats = await compile(compiler);
97+
98+
expect(readAssets(compiler, stats, /\.css(\.map)?$/)).toMatchSnapshot(
99+
'assets'
100+
);
101+
expect(getErrors(stats)).toMatchSnapshot('errors');
102+
expect(getWarnings(stats)).toMatchSnapshot('warnings');
103+
});
104+
73105
it('should work with the "true" value', async () => {
74106
const config = Object.assign(baseConfig, {
75107
module: {

0 commit comments

Comments
 (0)