Skip to content

Commit

Permalink
Merge pull request #5985 from EugeneHlushko/respect-no-deprecation-flag
Browse files Browse the repository at this point in the history
Improvement: Ensure respect for --no-deprecation flag when adding non…
  • Loading branch information
sokra committed Nov 23, 2017
2 parents 20759bb + 6a1f424 commit 885e9ee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
48 changes: 22 additions & 26 deletions lib/Compiler.js
Expand Up @@ -6,6 +6,7 @@

const path = require("path");
const Tapable = require("tapable");
const util = require("util");

const Compilation = require("./Compilation");
const Stats = require("./Stats");
Expand Down Expand Up @@ -186,35 +187,30 @@ class Compiler extends Tapable {
loader: null,
context: null
};
let deprecationReported = false;
this.parser = {
plugin: (hook, fn) => {
if(!deprecationReported) {
console.warn("webpack: Using compiler.parser is deprecated.\n" +
"Use compiler.plugin(\"compilation\", function(compilation, data) {\n data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.plugin(/* ... */); });\n}); instead. " +
"It was called " + new Error().stack.split("\n")[2].trim() + ".");
deprecationReported = true;
}
this.plugin("compilation", (compilation, data) => {
data.normalModuleFactory.plugin("parser", parser => {
parser.plugin(hook, fn);
plugin: util.deprecate(
(hook, fn) => {
this.plugin("compilation", (compilation, data) => {
data.normalModuleFactory.plugin("parser", parser => {
parser.plugin(hook, fn);
});
});
});
},
apply: () => {
const args = arguments;
if(!deprecationReported) {
console.warn("webpack: Using compiler.parser is deprecated.\n" +
"Use compiler.plugin(\"compilation\", function(compilation, data) {\n data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.apply(/* ... */); });\n}); instead. " +
"It was called " + new Error().stack.split("\n")[2].trim() + ".");
deprecationReported = true;
}
this.plugin("compilation", (compilation, data) => {
data.normalModuleFactory.plugin("parser", parser => {
parser.apply.apply(parser, args);
},
"webpack: Using compiler.parser is deprecated.\n" +
"Use compiler.plugin(\"compilation\", function(compilation, data) {\n data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.plugin(/* ... */); });\n}); instead. "
),
apply: util.deprecate(
() => {
const args = arguments;
this.plugin("compilation", (compilation, data) => {
data.normalModuleFactory.plugin("parser", parser => {
parser.apply(parser, args);
});
});
});
}
},
"webpack: Using compiler.parser is deprecated.\n" +
"Use compiler.plugin(\"compilation\", function(compilation, data) {\n data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.apply(/* ... */); });\n}); instead. "
)
};

this.options = {};
Expand Down
8 changes: 8 additions & 0 deletions test/Compiler.test.js
Expand Up @@ -178,6 +178,14 @@ describe("Compiler", () => {
});
});
describe("parser", () => {
describe("plugin", () => {
it("invokes sets a 'compilation' plugin", (done) => {
compiler.plugin = sinon.spy();
compiler.parser.plugin();
compiler.plugin.callCount.should.be.exactly(1);
done();
});
});
describe("apply", () => {
it("invokes sets a 'compilation' plugin", (done) => {
compiler.plugin = sinon.spy();
Expand Down

0 comments on commit 885e9ee

Please sign in to comment.