Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No errors plugin deprecate #3570

Merged
merged 9 commits into from Dec 30, 2016
19 changes: 19 additions & 0 deletions lib/NoEmitOnErrorsPlugin.js
@@ -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
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
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
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
@@ -0,0 +1 @@
require('./file');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write a test case with error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

3 changes: 3 additions & 0 deletions test/fixtures/temp-cache-fixture/a.js
@@ -0,0 +1,3 @@
module.exports = function a() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These files should not be commited. They are only create temporary by the test suite. You probably canceled tests before they are remove. If you want to you could add them to .gitignore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, canceled before test suite was entirely done. Will remove them and ignore them as well. Thanks @sokra!

return "This is a";
};
4 changes: 4 additions & 0 deletions test/fixtures/temp-cache-fixture/c.js
@@ -0,0 +1,4 @@
module.exports = function b() {
require("./a");
return "This is c";
};