Skip to content

Commit 07f95c7

Browse files
committed
Merge pull request webpack#2306 from beauroberts/issue-2299-webpack-1
Fixes issue webpack#2299 for 1.x
2 parents da40998 + a3f3ce0 commit 07f95c7

File tree

6 files changed

+49
-3
lines changed

6 files changed

+49
-3
lines changed

lib/dependencies/LoaderPlugin.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ LoaderPlugin.prototype.apply = function(compiler) {
2323
], true, "lm", false, function(err) {
2424
if(err) return callback(err);
2525

26-
module = dep.module;
27-
if(!module) return callback(new Error("Cannot load the module"));
28-
if(module.building) module.building.push(next);
26+
if(!dep.module) return callback(new Error("Cannot load the module"));
27+
if(dep.module.building) dep.module.building.push(next);
2928
else next();
3029

3130
function next(err) {

test/cases/loaders/issue-2299/a.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"imports": [
3+
"./subdir_1/b.json",
4+
"./subdir_2/c.json"
5+
],
6+
"a": true
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
it("should be able to use loadModule multiple times within a loader, on files in different directories", function() {
2+
require('!./loader/index.js!./a.json').should.have.properties(['a', 'b', 'c']);
3+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var path = require('path');
2+
var async = require('async');
3+
module.exports = function(content) {
4+
var cb = this.async();
5+
var json = JSON.parse(content);
6+
async.mapSeries(
7+
json.imports,
8+
function(url, callback) {
9+
this.loadModule(url, function(err, source, map, module) {
10+
if (err) {
11+
return callback(err);
12+
}
13+
callback(null, this.exec(source, url));
14+
}.bind(this))
15+
}.bind(this),
16+
function(err, results) {
17+
if (err) {
18+
return cb(err);
19+
}
20+
// Combine all the results into one object and return it
21+
cb(null, 'module.exports = ' + JSON.stringify(results.reduce(function(prev, result) {
22+
for (var key in result) {
23+
if (result.hasOwnProperty(key)) {
24+
prev[key] = result[key];
25+
}
26+
}
27+
return prev;
28+
}, json)));
29+
}
30+
);
31+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"b": true
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"c": true
3+
}

0 commit comments

Comments
 (0)