From 1c961afe7bdd386adcde00c5bbd73f8127bda5b2 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 30 Dec 2015 16:39:10 +0100 Subject: [PATCH] fixed small issues with new loader-runner --- .gitattributes | 1 + lib/ConstPlugin.js | 9 +++++++-- lib/LoaderOptionsPlugin.js | 5 ++++- lib/NodeStuffPlugin.js | 4 +++- test/cases/loaders/query/index.js | 2 +- test/cases/resolving/context/index.js | 4 ++-- test/hotCases/fake-update-loader.js | 1 + 7 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.gitattributes b/.gitattributes index dd6c9a6c4..ac579eb7b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ * text=auto +test/statsCases/* eol=lf examples/* eol=lf bin/* eol=lf \ No newline at end of file diff --git a/lib/ConstPlugin.js b/lib/ConstPlugin.js index a74193952..a125e3d75 100644 --- a/lib/ConstPlugin.js +++ b/lib/ConstPlugin.js @@ -7,6 +7,11 @@ var BasicEvaluatedExpression = require("./BasicEvaluatedExpression"); var NullFactory = require("./NullFactory"); +function getQuery(request) { + var i = request.indexOf("?"); + return i < 0 ? "" : request.substr(i); +} + function ConstPlugin() {} module.exports = ConstPlugin; @@ -42,13 +47,13 @@ ConstPlugin.prototype.apply = function(compiler) { compiler.parser.plugin("evaluate Identifier __resourceQuery", function(expr) { if(!this.state.module) return; var res = new BasicEvaluatedExpression(); - res.setString(this.state.module.splitQuery(this.state.module.resource)[1]); + res.setString(getQuery(this.state.module.resource)); res.setRange(expr.range); return res; }); compiler.parser.plugin("expression __resourceQuery", function() { if(!this.state.module) return; - this.state.current.addVariable("__resourceQuery", JSON.stringify(this.state.module.splitQuery(this.state.module.resource)[1])); + this.state.current.addVariable("__resourceQuery", JSON.stringify(getQuery(this.state.module.resource))); return true; }); }; diff --git a/lib/LoaderOptionsPlugin.js b/lib/LoaderOptionsPlugin.js index 8e066d63f..8fcccedbe 100644 --- a/lib/LoaderOptionsPlugin.js +++ b/lib/LoaderOptionsPlugin.js @@ -19,7 +19,10 @@ LoaderOptionsPlugin.prototype.apply = function(compiler) { var options = this.options; compiler.plugin("compilation", function(compilation) { compilation.plugin("normal-module-loader", function(context, module) { - if(module.resource && ModuleFilenameHelpers.matchObject(options, module.splitQuery(module.resource)[0])) { + var resource = module.resource; + if(!resource) return; + var i = resource.indexOf("?"); + if(ModuleFilenameHelpers.matchObject(options, i < 0 ? resource : resource.substr(0, i))) { Object.keys(options).filter(function(key) { return ["include", "exclude", "test"].indexOf(key) < 0 }).forEach(function(key) { diff --git a/lib/NodeStuffPlugin.js b/lib/NodeStuffPlugin.js index 0dcc91162..a03703acf 100644 --- a/lib/NodeStuffPlugin.js +++ b/lib/NodeStuffPlugin.js @@ -48,7 +48,9 @@ NodeStuffPlugin.prototype.apply = function(compiler) { compiler.parser.plugin("evaluate Identifier __filename", function(expr) { if(!this.state.module) return; var res = new BasicEvaluatedExpression(); - res.setString(this.state.module.splitQuery(this.state.module.resource)[0]); + var resource = this.state.module.resource; + var i = resource.indexOf("?"); + res.setString(i < 0 ? resource : resource.substr(0, i)); res.setRange(expr.range); return res; }); diff --git a/test/cases/loaders/query/index.js b/test/cases/loaders/query/index.js index fe256ffb0..5ce94909a 100644 --- a/test/cases/loaders/query/index.js +++ b/test/cases/loaders/query/index.js @@ -40,7 +40,7 @@ it("should pass query to loader over context", function() { var test = "test"; var result = require("./loaders/queryloader?query!./context-query-test/" + test); result.should.be.eql({ - resourceQuery: null, + resourceQuery: "", query: "?query", prev: "test content" }); diff --git a/test/cases/resolving/context/index.js b/test/cases/resolving/context/index.js index 816a64d4c..0b4e1b9a6 100644 --- a/test/cases/resolving/context/index.js +++ b/test/cases/resolving/context/index.js @@ -1,12 +1,12 @@ it("should resolve loaders relative to require", function() { var index = "index", test = "test"; require("./loaders/queryloader?query!!!!./node_modules/subcontent/" + index + ".js").should.be.eql({ - resourceQuery: null, + resourceQuery: "", query: "?query", prev: "module.exports = \"error\";" }); require("!./loaders/queryloader?query!./node_modules/subcontent/" + test + ".jade").should.be.eql({ - resourceQuery: null, + resourceQuery: "", query: "?query", prev: "xyz: abc" }); diff --git a/test/hotCases/fake-update-loader.js b/test/hotCases/fake-update-loader.js index 823c91592..43f0488ae 100644 --- a/test/hotCases/fake-update-loader.js +++ b/test/hotCases/fake-update-loader.js @@ -1,4 +1,5 @@ module.exports = function(source) { + this.cacheable(false); var idx = this.options.updateIndex; var items = source.split(/---+\r?\n/g); return items[idx] || items[items.length - 1];