Permalink
Browse files

fixed small issues with new loader-runner

  • Loading branch information...
1 parent ded70ae commit 1c961afe7bdd386adcde00c5bbd73f8127bda5b2 @sokra sokra committed Dec 30, 2015
View
@@ -1,3 +1,4 @@
* text=auto
+test/statsCases/* eol=lf
examples/* eol=lf
bin/* eol=lf
View
@@ -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;
});
};
@@ -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) {
@@ -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;
});
@@ -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"
});
@@ -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"
});
@@ -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];

0 comments on commit 1c961af

Please sign in to comment.