Permalink
Browse files

fix(package-analyzer): find location of packages outside of node_modules

fixes #567
  • Loading branch information...
JeroenVinke committed Mar 30, 2017
1 parent 55e487d commit 324f3e14ffdd3c8e1b93715d2a7a8dfb80125844
Showing with 18 additions and 3 deletions.
  1. +1 −1 lib/build/bundle.js
  2. +17 −2 lib/build/package-analyzer.js
View
@@ -94,7 +94,7 @@ exports.Bundle = class {
}
getDependencyLocations() {
- return this.includes.filter(inclusion => inclusion.description)
+ return this.includes.filter(inclusion => inclusion.description && inclusion.description.location)
.map(inclusion => {
let normalizedLocation = path.posix.normalize(inclusion.description.location).replace(/\\/g, '\/');
return {
@@ -28,7 +28,7 @@ exports.PackageAnalyzer = class {
description.source = 'custom';
description.loaderConfig = loaderConfig;
- return Promise.resolve(description);
+ return loadPackageMetadata(this.project, description).then(() => description);
}
};
@@ -37,6 +37,10 @@ function loadPackageMetadata(project, description) {
.then(() => fs.readFile(description.metadataLocation))
.then(data => {
description.metadata = JSON.parse(data.toString());
+ })
+ .catch(e => {
+ console.log(`Unable to load package metadata (package.json) of ${description.name}:`);
+ console.log(e);
});
}
@@ -73,8 +77,19 @@ function setLocation(project, description) {
description.location = packageFolder;
description.metadataLocation = path.join(description.location, 'package.json');
});
+ case 'custom':
+ if (!description.loaderConfig || !description.loaderConfig.packageRoot) {
+ return Promise.reject(`Error: packageRoot property not defined for the "${description.name}" package. It is recommended to ` +
+ 'define the packageRoot for packages outside the node_modules folder, so that the files end up in' +
+ 'the correct bundle');
+ }
+
+ description.location = path.resolve(project.paths.root, description.loaderConfig.packageRoot);
+ description.metadataLocation = path.join(description.location, 'package.json');
+
+ return Promise.resolve();
default:
- throw new Error(`The package source "${description.source}" is not supported.`);
+ return Promise.reject(`The package source "${description.source}" is not supported.`);
}
}

0 comments on commit 324f3e1

Please sign in to comment.