UNPKG

727 BJavaScriptView Raw
1const logger = require('./logger');
2const Package = require('./package');
3const getPackages = require('./get-packages');
4const loadManifest = require('./load-manifest');
5
6module.exports = async (globs = []) => {
7 const locations = await getPackages(globs);
8 const packages = [];
9
10 locations.forEach(location => {
11 let manifest;
12
13 try {
14 manifest = loadManifest(location);
15 } catch (error) {
16 logger.warning(error.toString());
17 }
18
19 if (manifest) {
20 if (packages.some(pkg => manifest.name === pkg.name)) {
21 throw new Error(
22 `Two or more packages have been found with the same name: "${manifest.name}"`,
23 );
24 } else {
25 packages.push(new Package(manifest, location));
26 }
27 }
28 });
29
30 return packages;
31};