From d211ffb3f34007f3bbe147aa17441339b5f61ffd Mon Sep 17 00:00:00 2001 From: Esben Petersen Date: Sun, 23 Jul 2017 22:00:27 +0200 Subject: [PATCH] rename --module-bind-x config keys from (pre/post)Loaders to rules will also add enfore:pre/post to the rule configuration closes #4917 --- bin/convert-argv.js | 18 ++++++++++++------ test/binCases/module/module-bind/file.post | 1 + test/binCases/module/module-bind/file.pre | 1 + test/binCases/module/module-bind/index.js | 3 +++ .../binCases/module/module-bind/post-loader.js | 4 ++++ test/binCases/module/module-bind/pre-loader.js | 4 ++++ test/binCases/module/module-bind/test.js | 10 ++++++++++ test/binCases/module/module-bind/test.opts | 7 +++++++ .../module/module-bind/webpack.config.js | 5 +++++ 9 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 test/binCases/module/module-bind/file.post create mode 100644 test/binCases/module/module-bind/file.pre create mode 100644 test/binCases/module/module-bind/index.js create mode 100644 test/binCases/module/module-bind/post-loader.js create mode 100644 test/binCases/module/module-bind/pre-loader.js create mode 100644 test/binCases/module/module-bind/test.js create mode 100644 test/binCases/module/module-bind/test.opts create mode 100644 test/binCases/module/module-bind/webpack.config.js diff --git a/bin/convert-argv.js b/bin/convert-argv.js index fa7ca1a0b9e..13908c49a75 100644 --- a/bin/convert-argv.js +++ b/bin/convert-argv.js @@ -293,24 +293,30 @@ module.exports = function(yargs, argv, convertOptions) { ensureObject(options, "entry"); }); - function bindLoaders(arg, collection) { + function bindRules(arg, collection) { ifArgPair(arg, function(name, binding) { if(name === null) { name = binding; binding += "-loader"; } - options.module[collection].push({ + var rule = { test: new RegExp("\\." + name.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + "$"), loader: binding - }); + } + if (arg === "module-bind-pre") { + rule.enforce = "pre" + } else if (arg === "module-bind-post") { + rule.enforce = "post" + } + options.module[collection].push(rule); }, function() { ensureObject(options, "module"); ensureArray(options.module, collection); }); } - bindLoaders("module-bind", "loaders"); - bindLoaders("module-bind-pre", "preLoaders"); - bindLoaders("module-bind-post", "postLoaders"); + bindRules("module-bind", "rules"); + bindRules("module-bind-pre", "rules"); + bindRules("module-bind-post", "rules"); var defineObject; ifArgPair("define", function(name, value) { diff --git a/test/binCases/module/module-bind/file.post b/test/binCases/module/module-bind/file.post new file mode 100644 index 00000000000..8b1e502f812 --- /dev/null +++ b/test/binCases/module/module-bind/file.post @@ -0,0 +1 @@ +post diff --git a/test/binCases/module/module-bind/file.pre b/test/binCases/module/module-bind/file.pre new file mode 100644 index 00000000000..ecca61d996a --- /dev/null +++ b/test/binCases/module/module-bind/file.pre @@ -0,0 +1 @@ +pre diff --git a/test/binCases/module/module-bind/index.js b/test/binCases/module/module-bind/index.js new file mode 100644 index 00000000000..3af465b8605 --- /dev/null +++ b/test/binCases/module/module-bind/index.js @@ -0,0 +1,3 @@ +var pre = require('./file.pre'); +var post = require('./file.post'); +module.exports = "foo"; diff --git a/test/binCases/module/module-bind/post-loader.js b/test/binCases/module/module-bind/post-loader.js new file mode 100644 index 00000000000..3d336c23870 --- /dev/null +++ b/test/binCases/module/module-bind/post-loader.js @@ -0,0 +1,4 @@ +module.exports = function(source) { + console.log('post-loaded ' + source.replace('\n', '')) + return source; +}; diff --git a/test/binCases/module/module-bind/pre-loader.js b/test/binCases/module/module-bind/pre-loader.js new file mode 100644 index 00000000000..8b5a0729545 --- /dev/null +++ b/test/binCases/module/module-bind/pre-loader.js @@ -0,0 +1,4 @@ +module.exports = function(source) { + console.log('pre-loaded ' + source.replace('\n', '')) + return source; +}; diff --git a/test/binCases/module/module-bind/test.js b/test/binCases/module/module-bind/test.js new file mode 100644 index 00000000000..eeef1f0ca6c --- /dev/null +++ b/test/binCases/module/module-bind/test.js @@ -0,0 +1,10 @@ +"use strict"; + +module.exports = function testAssertions(code, stdout, stderr) { + code.should.be.exactly(0); + + stdout.should.be.ok(); + stdout.should.containEql("pre-loaded pre"); + stdout.should.containEql("post-loaded post"); + stderr.should.be.empty(); +}; diff --git a/test/binCases/module/module-bind/test.opts b/test/binCases/module/module-bind/test.opts new file mode 100644 index 00000000000..94331cd34e2 --- /dev/null +++ b/test/binCases/module/module-bind/test.opts @@ -0,0 +1,7 @@ +--entry ./index.js +--config ./webpack.config.js +--output-filename [name].js +--output-chunk-filename [id].chunk.js +--target async-node +--module-bind-pre pre=./pre-loader +--module-bind-post post=./post-loader diff --git a/test/binCases/module/module-bind/webpack.config.js b/test/binCases/module/module-bind/webpack.config.js new file mode 100644 index 00000000000..7ae59c51e2c --- /dev/null +++ b/test/binCases/module/module-bind/webpack.config.js @@ -0,0 +1,5 @@ +var path = require("path"); + +module.exports = { + entry: path.resolve(__dirname, "./index"), +};