Skip to content

Commit

Permalink
fix(package-analyzer): find location of packages outside of node_modules
Browse files Browse the repository at this point in the history
fixes #567
  • Loading branch information
JeroenVinke committed Apr 8, 2017
1 parent 55e487d commit 324f3e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/build/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 17 additions & 2 deletions lib/build/package-analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exports.PackageAnalyzer = class {
description.source = 'custom';
description.loaderConfig = loaderConfig;

return Promise.resolve(description);
return loadPackageMetadata(this.project, description).then(() => description);
}
};

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

Expand Down Expand Up @@ -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.`);
}
}

Expand Down

0 comments on commit 324f3e1

Please sign in to comment.