Browse Source

fixed small issues with new loader-runner

tags/v2.0.3-beta
Tobias Koppers 3 years ago
parent
commit
1c961afe7b

+ 1
- 0
.gitattributes View File

@@ -1,3 +1,4 @@
* text=auto
test/statsCases/* eol=lf
examples/* eol=lf
bin/* eol=lf

+ 7
- 2
lib/ConstPlugin.js View File

@@ -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;
});
};

+ 4
- 1
lib/LoaderOptionsPlugin.js View File

@@ -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) {

+ 3
- 1
lib/NodeStuffPlugin.js View File

@@ -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;
});

+ 1
- 1
test/cases/loaders/query/index.js View File

@@ -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"
});

+ 2
- 2
test/cases/resolving/context/index.js View File

@@ -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
- 0
test/hotCases/fake-update-loader.js View File

@@ -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];

Loading…
Cancel
Save