Skip to content

Commit 082dc17

Browse files
elodszopossokra
authored andcommitted
No errors plugin deprecate (webpack#3570)
* 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
1 parent dc0f4e5 commit 082dc17

6 files changed

Lines changed: 82 additions & 0 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/node_modules
22
/test/js
33
/test/browsertest/js
4+
/test/fixtures/temp-cache-fixture
45
/benchmark/js
56
/benchmark/fixtures
67
/examples/*/js

‎lib/NoEmitOnErrorsPlugin.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
5+
function NoEmitOnErrorsPlugin() {}
6+
7+
module.exports = NoEmitOnErrorsPlugin;
8+
NoEmitOnErrorsPlugin.prototype.apply = function(compiler) {
9+
compiler.plugin("should-emit", function(compilation) {
10+
if(compilation.errors.length > 0)
11+
return false;
12+
});
13+
compiler.plugin("compilation", function(compilation) {
14+
compilation.plugin("should-record", function() {
15+
if(compilation.errors.length > 0)
16+
return false;
17+
});
18+
});
19+
};

‎lib/NoErrorsPlugin.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33
Author Tobias Koppers @sokra
44
*/
55
function NoErrorsPlugin() {}
6+
7+
var deprecationReported = false;
8+
69
module.exports = NoErrorsPlugin;
710
NoErrorsPlugin.prototype.apply = function(compiler) {
811
compiler.plugin("should-emit", function(compilation) {
12+
if(!deprecationReported) {
13+
compilation.warnings.push("webpack: Using NoErrorsPlugin is deprecated.\n" +
14+
"Use NoEmitOnErrorsPlugin instead.\n");
15+
deprecationReported = true;
16+
}
917
if(compilation.errors.length > 0)
1018
return false;
1119
});

‎lib/webpack.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ exportPlugins(exports, ".", [
9898
"SetVarMainTemplatePlugin",
9999
"UmdMainTemplatePlugin",
100100
"NoErrorsPlugin",
101+
"NoEmitOnErrorsPlugin",
101102
"NewWatchingPlugin",
102103
"EnvironmentPlugin",
103104
"DllPlugin",

‎test/Errors.test.js‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,58 @@ describe("Errors", function() {
9292
done();
9393
});
9494
});
95+
it("should warn about NoErrorsPlugin being deprecated in favor of NoEmitOnErrorsPlugin", function(done) {
96+
getErrors({
97+
entry: "./no-errors-deprecate",
98+
plugins: [
99+
new webpack.NoErrorsPlugin()
100+
]
101+
}, function(errors, warnings) {
102+
warnings.length.should.be.eql(1);
103+
var lines = warnings[0].split("\n");
104+
lines[0].should.match(/webpack/);
105+
lines[0].should.match(/NoErrorsPlugin/);
106+
lines[0].should.match(/deprecated/);
107+
lines[1].should.match(/NoEmitOnErrorsPlugin/);
108+
lines[1].should.match(/instead/);
109+
done();
110+
});
111+
});
112+
it("should not warn if the NoEmitOnErrorsPlugin is used over the NoErrorsPlugin", function(done) {
113+
getErrors({
114+
entry: "./no-errors-deprecate",
115+
plugins: [
116+
new webpack.NoEmitOnErrorsPlugin()
117+
]
118+
}, function(errors, warnings) {
119+
errors.length.should.be.eql(0);
120+
warnings.length.should.be.eql(0);
121+
done();
122+
});
123+
});
124+
it("should not not emit if NoEmitOnErrorsPlugin is used and there is an error", function(done) {
125+
getErrors({
126+
entry: "./missingFile",
127+
plugins: [
128+
new webpack.NoEmitOnErrorsPlugin()
129+
]
130+
}, function(errors, warnings) {
131+
errors.length.should.be.eql(2);
132+
warnings.length.should.be.eql(0);
133+
errors.sort();
134+
var lines = errors[0].split("\n");
135+
lines[0].should.match(/missingFile.js/);
136+
lines[1].should.match(/^Module not found/);
137+
lines[1].should.match(/\.\/dir\/missing2/);
138+
lines[2].should.match(/missingFile.js 12:9/);
139+
lines = errors[1].split("\n");
140+
lines[0].should.match(/missingFile.js/);
141+
lines[1].should.match(/^Module not found/);
142+
lines[1].should.match(/\.\/missing/);
143+
lines[2].should.match(/missingFile.js 4:0/);
144+
done();
145+
});
146+
});
95147
it("should throw an error when using incorrect CommonsChunkPlugin configuration", function(done) {
96148
getErrors({
97149
entry: {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('./file');

0 commit comments

Comments
 (0)