Skip to content

Commit

Permalink
fix(webpack): don't try to emit if there were errors (#725)
Browse files Browse the repository at this point in the history
Fixes #724
  • Loading branch information
tivac committed Feb 19, 2020
1 parent c4ca09b commit e9de291
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 31 deletions.
3 changes: 2 additions & 1 deletion packages/webpack/package.json
Expand Up @@ -2,7 +2,8 @@
"name": "@modular-css/webpack",
"version": "25.4.1",
"description": "Webpack support for modular-css",
"main": "./index.js",
"main": "./plugin.js",
"loader": "./loader.js",
"repository": {
"type": "git",
"url": "https://github.com/tivac/modular-css.git",
Expand Down
11 changes: 8 additions & 3 deletions packages/webpack/plugin.js
Expand Up @@ -71,7 +71,12 @@ ModularCSS.prototype.apply = function(compiler) {
}
});

compiler.plugin("emit", (compilation, done) =>
compiler.plugin("emit", (compilation, done) => {
// Don't even bother if errors happened
if(compilation.errors.length) {
return done();
}

this.processor.output({
to : this.options.css || false,
})
Expand Down Expand Up @@ -103,8 +108,8 @@ ModularCSS.prototype.apply = function(compiler) {

return done();
})
.catch(done)
);
.catch(done);
});
};

module.exports = ModularCSS;
11 changes: 11 additions & 0 deletions packages/webpack/test/records/parse-error.js.json
@@ -0,0 +1,11 @@
{
"modules": {
"byIdentifier": {},
"usedIds": {}
},
"chunks": {
"byName": {},
"bySource": {},
"usedIds": []
}
}
4 changes: 4 additions & 0 deletions packages/webpack/test/specimens/parse-error.css
@@ -0,0 +1,4 @@
// This comment should be a parsing error
.foo {
color: red;
}
1 change: 1 addition & 0 deletions packages/webpack/test/specimens/parse-error.js
@@ -0,0 +1 @@
require("./parse-error.css");
65 changes: 38 additions & 27 deletions packages/webpack/test/webpack.test.js
Expand Up @@ -61,7 +61,7 @@ describe("/webpack.js", () => {
expect(typeof Plugin).toBe("function");
});

it("should output css to disk", (done) => {
it("should output css to disk", () => new Promise((done) => {
webpack(config({
entry : "./packages/webpack/test/specimens/simple.js",
}), (err, stats) => {
Expand All @@ -72,9 +72,9 @@ describe("/webpack.js", () => {

done();
});
});
}));

it("should output json to disk", (done) => {
it("should output json to disk", () => new Promise((done) => {
webpack(config({
entry : "./packages/webpack/test/specimens/simple.js",
plugin : {
Expand All @@ -88,9 +88,9 @@ describe("/webpack.js", () => {

done();
});
});
}));

it("should output inline source maps", (done) => {
it("should output inline source maps", () => new Promise((done) => {
webpack(config({
entry : "./packages/webpack/test/specimens/simple.js",
plugin : {
Expand All @@ -103,9 +103,9 @@ describe("/webpack.js", () => {

done();
});
});
}));

it("should output external source maps to disk", (done) => {
it("should output external source maps to disk", () => new Promise((done) => {
webpack(config({
entry : "./packages/webpack/test/specimens/simple.js",
plugin : {
Expand All @@ -120,20 +120,31 @@ describe("/webpack.js", () => {

done();
});
});
}));

// TODO: webpack is doing something weird with errors here suddenly?
it.skip("should report errors", (done) => {
it("should report modular-css errors", () => new Promise((done) => {
webpack(config({
entry : "./packages/webpack/test/specimens/invalid.js",
}), (err, stats) => {
expect(stats.hasErrors()).toBe(true);
expect(stats.toJson().errors[0]).toMatch("Invalid composes reference");

done();
});
});
}));

it("should report postcss errors", () => new Promise((done) => {
webpack(config({
entry : "./packages/webpack/test/specimens/parse-error.js",
}), (err, stats) => {
expect(stats.hasErrors()).toBe(true);
expect(stats.toJson().errors[0]).toMatch("Unexpected '/'");

done();
});
}));

it("should report warnings on invalid property names", (done) => {
it("should report warnings on invalid property names", () => new Promise((done) => {
webpack(config({
entry : "./packages/webpack/test/specimens/invalid-name.js",
}), (err, stats) => {
Expand All @@ -143,9 +154,9 @@ describe("/webpack.js", () => {

done();
});
});
}));

it("should handle dependencies", (done) => {
it("should handle dependencies", () => new Promise((done) => {
webpack(config({
entry : "./packages/webpack/test/specimens/start.js",
plugin : {
Expand All @@ -160,9 +171,9 @@ describe("/webpack.js", () => {

done();
});
});
}));

it("should support ES2015 default exports", (done) => {
it("should support ES2015 default exports", () => new Promise((done) => {
webpack(config({
entry : "./packages/webpack/test/specimens/es2015-default.js",
}), (err, stats) => {
Expand All @@ -173,9 +184,9 @@ describe("/webpack.js", () => {

done();
});
});
}));

it("should support ES2015 named exports", (done) => {
it("should support ES2015 named exports", () => new Promise((done) => {
webpack(config({
entry : "./packages/webpack/test/specimens/es2015-named.js",
}), (err, stats) => {
Expand All @@ -186,9 +197,9 @@ describe("/webpack.js", () => {

done();
});
});
}));

it("should support disabling namedExports when the option is set", (done) => {
it("should support disabling namedExports when the option is set", () => new Promise((done) => {
webpack(config({
entry : "./packages/webpack/test/specimens/simple.js",
use : {
Expand All @@ -204,9 +215,9 @@ describe("/webpack.js", () => {

done();
});
});
}));

it("should support disabling styleExport when the option is set", (done) => {
it("should support disabling styleExport when the option is set", () => new Promise((done) => {
webpack(config({
entry : "./packages/webpack/test/specimens/simple.js",
use : {
Expand All @@ -222,9 +233,9 @@ describe("/webpack.js", () => {

done();
});
});
}));

it("should support disabling defaultExport when the option is set", (done) => {
it("should support disabling defaultExport when the option is set", () => new Promise((done) => {
webpack(config({
entry : "./packages/webpack/test/specimens/simple.js",
use : {
Expand All @@ -240,9 +251,9 @@ describe("/webpack.js", () => {

done();
});
});
}));

it("should generate correct builds in watch mode when files change", (done) => {
it("should generate correct builds in watch mode when files change", () => new Promise((done) => {
var changed = 0,
compiler, watcher;

Expand Down Expand Up @@ -280,7 +291,7 @@ describe("/webpack.js", () => {

return watcher.close();
});
});
}));

it("should generate correct builds when files change", () => {
var changed = "./packages/webpack/test/output/changed.css",
Expand Down

0 comments on commit e9de291

Please sign in to comment.