diff --git a/lib/build/bundle.js b/lib/build/bundle.js index 462affb88..a1cdb0b1e 100644 --- a/lib/build/bundle.js +++ b/lib/build/bundle.js @@ -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()), [])); } diff --git a/lib/build/bundled-source.js b/lib/build/bundled-source.js index 9f86a4489..9705d11b9 100644 --- a/lib/build/bundled-source.js +++ b/lib/build/bundled-source.js @@ -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}`); } @@ -144,7 +144,7 @@ exports.BundledSource = class { let newItem = bundler.addFile({ path: result.path, contents: result.contents - }, this.includedBy); + }, this.getInclusion(result.path)); newItem.deps = result.deps; } @@ -152,6 +152,18 @@ exports.BundledSource = class { }); } + 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; diff --git a/lib/build/bundler.js b/lib/build/bundler.js index 6bd1855ab..27a88da07 100644 --- a/lib/build/bundler.js +++ b/lib/build/bundler.js @@ -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) {