Skip to content

Commit

Permalink
fix: crash with source maps when the parallel option is false (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Jan 8, 2021
1 parent bdb3f52 commit 4fe95f9
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 69 deletions.
2 changes: 1 addition & 1 deletion src/minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const minify = async (options) => {

return {
code: result.css,
map: result.map,
map: result.map && result.map.toString(),
warnings: warningsToString(result.warnings()),
};
};
Expand Down
86 changes: 86 additions & 0 deletions test/__snapshots__/sourceMap-option.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,92 @@ exports[`when applied with "sourceMap" option should work with SourceMapDevToolP

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

exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: assets 1`] = `
Object {
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
/*# sourceMappingURL=entry.css.map*/",
"entry.css.map": {
"version": 3,
"sources": [
"webpack:///./sourcemap/bar.scss",
"webpack:///./sourcemap/foo.scss"
],
"names": [],
"mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB",
"file": "entry.css",
"sourcesContent": [
"body {\\n font-weight: bold;\\n}",
"@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}"
],
"sourceRoot": ""
},
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
/*# sourceMappingURL=entry2.css.map*/",
"entry2.css.map": {
"version": 3,
"sources": [
"webpack:///./sourcemap/bar.scss",
"webpack:///./sourcemap/foo.css"
],
"names": [],
"mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB",
"file": "entry2.css",
"sourcesContent": [
"body {\\n font-weight: bold;\\n}",
"@import 'bar';\\n\\nbody {\\n color: red;\\n}\\n\\nbody a {\\n text-align: center;\\n}"
],
"sourceRoot": ""
},
}
`;

exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: errors 1`] = `Array []`;

exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: warnings 1`] = `Array []`;

exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: assets 1`] = `
Object {
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
/*# sourceMappingURL=entry.css.map*/",
"entry.css.map": {
"version": 3,
"sources": [
"webpack:///./sourcemap/bar.scss",
"webpack:///./sourcemap/foo.scss"
],
"names": [],
"mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB",
"file": "entry.css",
"sourcesContent": [
"body {\\n font-weight: bold;\\n}",
"@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}"
],
"sourceRoot": ""
},
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
/*# sourceMappingURL=entry2.css.map*/",
"entry2.css.map": {
"version": 3,
"sources": [
"webpack:///./sourcemap/bar.scss",
"webpack:///./sourcemap/foo.css"
],
"names": [],
"mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB",
"file": "entry2.css",
"sourcesContent": [
"body {\\n font-weight: bold;\\n}",
"@import 'bar';\\n\\nbody {\\n color: red;\\n}\\n\\nbody a {\\n text-align: center;\\n}"
],
"sourceRoot": ""
},
}
`;

exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: errors 1`] = `Array []`;

exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: warnings 1`] = `Array []`;

exports[`when applied with "sourceMap" option should work with the "devtool" option: assets 1`] = `
Object {
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
Expand Down
86 changes: 86 additions & 0 deletions test/__snapshots__/sourceMap-option.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,92 @@ exports[`when applied with "sourceMap" option should work with SourceMapDevToolP

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

exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: assets 1`] = `
Object {
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
/*# sourceMappingURL=entry.css.map*/",
"entry.css.map": {
"version": 3,
"sources": [
"webpack:///./sourcemap/bar.scss",
"webpack:///./sourcemap/foo.scss"
],
"names": [],
"mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB",
"file": "entry.css",
"sourcesContent": [
"body {\\n font-weight: bold;\\n}",
"@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}"
],
"sourceRoot": ""
},
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
/*# sourceMappingURL=entry2.css.map*/",
"entry2.css.map": {
"version": 3,
"sources": [
"webpack:///./sourcemap/bar.scss",
"webpack:///./sourcemap/foo.css"
],
"names": [],
"mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB",
"file": "entry2.css",
"sourcesContent": [
"body {\\n font-weight: bold;\\n}",
"@import 'bar';\\n\\nbody {\\n color: red;\\n}\\n\\nbody a {\\n text-align: center;\\n}"
],
"sourceRoot": ""
},
}
`;

exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: errors 1`] = `Array []`;

exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "false" value: warnings 1`] = `Array []`;

exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: assets 1`] = `
Object {
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
/*# sourceMappingURL=entry.css.map*/",
"entry.css.map": {
"version": 3,
"sources": [
"webpack:///./sourcemap/bar.scss",
"webpack:///./sourcemap/foo.scss"
],
"names": [],
"mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCCnB,OAGI,iBAAkB",
"file": "entry.css",
"sourcesContent": [
"body {\\n font-weight: bold;\\n}",
"@import 'bar';\\n\\nbody {\\n color: red;\\n a {\\n text-align: center;\\n }\\n}"
],
"sourceRoot": ""
},
"entry2.css": "body{font-weight:700;color:red}body a{text-align:center}
/*# sourceMappingURL=entry2.css.map*/",
"entry2.css.map": {
"version": 3,
"sources": [
"webpack:///./sourcemap/bar.scss",
"webpack:///./sourcemap/foo.css"
],
"names": [],
"mappings": "AAAA,KACE,eAAiB,CCEjB,SDFiB,CCKnB,OACE,iBAAkB",
"file": "entry2.css",
"sourcesContent": [
"body {\\n font-weight: bold;\\n}",
"@import 'bar';\\n\\nbody {\\n color: red;\\n}\\n\\nbody a {\\n text-align: center;\\n}"
],
"sourceRoot": ""
},
}
`;

exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: errors 1`] = `Array []`;

exports[`when applied with "sourceMap" option should work with the "devtool" option and the "parallel" option with "true" value: warnings 1`] = `Array []`;

exports[`when applied with "sourceMap" option should work with the "devtool" option: assets 1`] = `
Object {
"entry.css": "body{font-weight:700;color:red}body a{text-align:center}
Expand Down
36 changes: 2 additions & 34 deletions test/__snapshots__/worker.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,11 @@ Array [

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

exports[`worker should minify css: map 1`] = `
Object {
"file": "entry.css",
"mappings": "AAAA,KAAK,SAAA,CCCL,KAAK,WAAY",
"names": Array [],
"sources": Array [
"foo.css",
"entry.css",
],
"sourcesContent": Array [
".foo{color:red;}",
".foo{color:red;}
.bar{color:coral;}",
],
"version": 3,
}
`;
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;}\\"]}"`;

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

exports[`worker should work inputSourceMap as prev: map 1`] = `
Object {
"file": "entry.css",
"mappings": "AAAA,KAAK,SAAA,CCCL,KAAK,WAAY",
"names": Array [],
"sources": Array [
"foo.css",
"entry.css",
],
"sourcesContent": Array [
".foo{color:red;}",
".foo{color:red;}
.bar{color:coral;}",
],
"version": 3,
}
`;
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;}\\"]}"`;

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

Expand Down
36 changes: 2 additions & 34 deletions test/__snapshots__/worker.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,11 @@ Array [

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

exports[`worker should minify css: map 1`] = `
Object {
"file": "entry.css",
"mappings": "AAAA,KAAK,SAAA,CCCL,KAAK,WAAY",
"names": Array [],
"sources": Array [
"foo.css",
"entry.css",
],
"sourcesContent": Array [
".foo{color:red;}",
".foo{color:red;}
.bar{color:coral;}",
],
"version": 3,
}
`;
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;}\\"]}"`;

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

exports[`worker should work inputSourceMap as prev: map 1`] = `
Object {
"file": "entry.css",
"mappings": "AAAA,KAAK,SAAA,CCCL,KAAK,WAAY",
"names": Array [],
"sources": Array [
"foo.css",
"entry.css",
],
"sourcesContent": Array [
".foo{color:red;}",
".foo{color:red;}
.bar{color:coral;}",
],
"version": 3,
}
`;
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;}\\"]}"`;

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

Expand Down
32 changes: 32 additions & 0 deletions test/sourceMap-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,38 @@ describe('when applied with "sourceMap" option', () => {
expect(getWarnings(stats)).toMatchSnapshot('warnings');
});

it('should work with the "devtool" option and the "parallel" option with "false" value', async () => {
const compiler = getCompiler(baseConfig);

new CssMinimizerPlugin({
parallel: false,
}).apply(compiler);

const stats = await compile(compiler);

expect(readAssets(compiler, stats, /\.css(\.map)?$/)).toMatchSnapshot(
'assets'
);
expect(getErrors(stats)).toMatchSnapshot('errors');
expect(getWarnings(stats)).toMatchSnapshot('warnings');
});

it('should work with the "devtool" option and the "parallel" option with "true" value', async () => {
const compiler = getCompiler(baseConfig);

new CssMinimizerPlugin({
parallel: true,
}).apply(compiler);

const stats = await compile(compiler);

expect(readAssets(compiler, stats, /\.css(\.map)?$/)).toMatchSnapshot(
'assets'
);
expect(getErrors(stats)).toMatchSnapshot('errors');
expect(getWarnings(stats)).toMatchSnapshot('warnings');
});

it('should work with the "true" value', async () => {
const config = Object.assign(baseConfig, {
module: {
Expand Down

0 comments on commit 4fe95f9

Please sign in to comment.