Skip to content

Commit

Permalink
fix(build): ensure that dependencies get in the correct bundle
Browse files Browse the repository at this point in the history
fixes #342
  • Loading branch information
JeroenVinke committed Mar 15, 2017
1 parent d6f0ada commit f4c9e8f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/build/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ exports.Bundle = class {
return Promise.resolve();
}

getDependencyLocations() {
return this.includes.filter(inclusion => inclusion.description)
.map(inclusion => {
let normalizedLocation = path.posix.normalize(inclusion.description.location).replace(/\\/g,'\/');
return {
location: normalizedLocation,
inclusion: inclusion
}
});
}

getBundledModuleIds() {
return unique(this.includes.reduce((a, b) => a.concat(b.getAllModuleIds()), []));
}
Expand Down
16 changes: 14 additions & 2 deletions lib/build/bundled-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ exports.BundledSource = class {
bundler.addFile({
path: location,
contents: contents
}, that.includedBy);
}, that.getInclusion(location));
} catch(e) {
console.log(`File not found or not accessible: ${location}. Requested by ${modulePath}`);
}
Expand Down Expand Up @@ -144,14 +144,26 @@ exports.BundledSource = class {
let newItem = bundler.addFile({
path: result.path,
contents: result.contents
}, this.includedBy);
}, this.getInclusion(result.path));

newItem.deps = result.deps;
}
}
});
}

getInclusion(filePath) {
let dir = path.dirname(path.posix.normalize(filePath).replace(/\\/g,'\/'));
let dependencyLocations = this.bundler.getAllDependencyLocations();
let dependencyLocation = dependencyLocations.find(x => dir.indexOf(x.location) === 0);

if (dependencyLocation) {
return dependencyLocation.inclusion;
}

return this.includedBy;
}

calculateModuleId(rootDir, loaderConfig) {
if (this.file.description) {
return this.file.description.name;
Expand Down
4 changes: 4 additions & 0 deletions lib/build/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ exports.Bundler = class {
write() {
return Promise.all(this.bundles.map(x => x.write(this.project.build.targets[0])));
}

getAllDependencyLocations() {
return this.bundles.reduce((a, b) => a.concat(b.getDependencyLocations()), [])
}
}

function analyzeDependency(packageAnalyzer, dependency) {
Expand Down

0 comments on commit f4c9e8f

Please sign in to comment.