Skip to content

Commit

Permalink
No errors plugin deprecate (webpack#3570)
Browse files Browse the repository at this point in the history
* added deprecation with unit test
* added deprecation for NoErrorsPlugin in favor of NoEmitOnErrorsPlugin with unit test
* add new NoEmitOnErrorsPlugin to exports and add an extra unit test to check that there is no warning when using it
* added test for NoEmitOnErrorsPlugin in case of error
* git ignore temporary test fixtures
  • Loading branch information
elodszopos authored and sokra committed Dec 30, 2016
1 parent dc0f4e5 commit 082dc17
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/node_modules
/test/js
/test/browsertest/js
/test/fixtures/temp-cache-fixture
/benchmark/js
/benchmark/fixtures
/examples/*/js
Expand Down
19 changes: 19 additions & 0 deletions lib/NoEmitOnErrorsPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
function NoEmitOnErrorsPlugin() {}

module.exports = NoEmitOnErrorsPlugin;
NoEmitOnErrorsPlugin.prototype.apply = function(compiler) {
compiler.plugin("should-emit", function(compilation) {
if(compilation.errors.length > 0)
return false;
});
compiler.plugin("compilation", function(compilation) {
compilation.plugin("should-record", function() {
if(compilation.errors.length > 0)
return false;
});
});
};
8 changes: 8 additions & 0 deletions lib/NoErrorsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
Author Tobias Koppers @sokra
*/
function NoErrorsPlugin() {}

var deprecationReported = false;

module.exports = NoErrorsPlugin;
NoErrorsPlugin.prototype.apply = function(compiler) {
compiler.plugin("should-emit", function(compilation) {
if(!deprecationReported) {
compilation.warnings.push("webpack: Using NoErrorsPlugin is deprecated.\n" +
"Use NoEmitOnErrorsPlugin instead.\n");
deprecationReported = true;
}
if(compilation.errors.length > 0)
return false;
});
Expand Down
1 change: 1 addition & 0 deletions lib/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ exportPlugins(exports, ".", [
"SetVarMainTemplatePlugin",
"UmdMainTemplatePlugin",
"NoErrorsPlugin",
"NoEmitOnErrorsPlugin",
"NewWatchingPlugin",
"EnvironmentPlugin",
"DllPlugin",
Expand Down
52 changes: 52 additions & 0 deletions test/Errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,58 @@ describe("Errors", function() {
done();
});
});
it("should warn about NoErrorsPlugin being deprecated in favor of NoEmitOnErrorsPlugin", function(done) {
getErrors({
entry: "./no-errors-deprecate",
plugins: [
new webpack.NoErrorsPlugin()
]
}, function(errors, warnings) {
warnings.length.should.be.eql(1);
var lines = warnings[0].split("\n");
lines[0].should.match(/webpack/);
lines[0].should.match(/NoErrorsPlugin/);
lines[0].should.match(/deprecated/);
lines[1].should.match(/NoEmitOnErrorsPlugin/);
lines[1].should.match(/instead/);
done();
});
});
it("should not warn if the NoEmitOnErrorsPlugin is used over the NoErrorsPlugin", function(done) {
getErrors({
entry: "./no-errors-deprecate",
plugins: [
new webpack.NoEmitOnErrorsPlugin()
]
}, function(errors, warnings) {
errors.length.should.be.eql(0);
warnings.length.should.be.eql(0);
done();
});
});
it("should not not emit if NoEmitOnErrorsPlugin is used and there is an error", function(done) {
getErrors({
entry: "./missingFile",
plugins: [
new webpack.NoEmitOnErrorsPlugin()
]
}, function(errors, warnings) {
errors.length.should.be.eql(2);
warnings.length.should.be.eql(0);
errors.sort();
var lines = errors[0].split("\n");
lines[0].should.match(/missingFile.js/);
lines[1].should.match(/^Module not found/);
lines[1].should.match(/\.\/dir\/missing2/);
lines[2].should.match(/missingFile.js 12:9/);
lines = errors[1].split("\n");
lines[0].should.match(/missingFile.js/);
lines[1].should.match(/^Module not found/);
lines[1].should.match(/\.\/missing/);
lines[2].should.match(/missingFile.js 4:0/);
done();
});
});
it("should throw an error when using incorrect CommonsChunkPlugin configuration", function(done) {
getErrors({
entry: {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/errors/no-errors-deprecate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./file');

0 comments on commit 082dc17

Please sign in to comment.