-
-
Notifications
You must be signed in to change notification settings - Fork 27k
/
Copy pathdetectMissingVendors.js
34 lines (31 loc) · 1.1 KB
/
detectMissingVendors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// @remove-on-eject-begin
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// @remove-on-eject-end
'use strict';
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
function detectMissingVendors(pathToPackageJson, pathToVendors) {
const packageJson = require(pathToPackageJson);
const dependencies = Object.keys(packageJson.dependencies || {})
.concat(Object.keys(packageJson.devDependencies || {}))
.concat(Object.keys(packageJson.peerDependencies || {}));
const vendors = fs.existsSync(pathToVendors) ? require(pathToVendors) : [];
const missingVendors = vendors.filter(
vendor => dependencies.indexOf(vendor) === -1
);
if (missingVendors.length > 0) {
throw new Error(
'Error: Unknown vendors: ' +
chalk.yellow(missingVendors) +
" should be listed in the project's dependencies.\n" +
`(Vendors defined in '${path.resolve(pathToVendors)}')`
);
}
}
module.exports = detectMissingVendors;