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
  • Loading branch information
JeroenVinke committed Mar 30, 2017
1 parent ab292f1 commit 41f0cbe
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 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,11 @@ 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);
throw e;
});
}

Expand Down Expand Up @@ -73,8 +78,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 41f0cbe

Please sign in to comment.