forked from jenkinsci/blueocean-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkdeps.js
77 lines (54 loc) · 2.37 KB
/
checkdeps.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"use strict";
/*********************************************************************************************
**********************************************************************************************
Checks for version inconsistencies in top-level project dependencies.
Usage:
node checkdeps.js
If conflicting versions are detected, this will print them out as JSON on STDERR and
exit(1). If no conflicts are detected, there is no output and normal exit
**********************************************************************************************
*********************************************************************************************/
// --[ State ]--------------------------------------------------------------------------------
var allDependencies = {};
// --[ Helpers ]------------------------------------------------------------------------------
function initEntry(dependency, version) {
if (!allDependencies.hasOwnProperty(dependency)) {
allDependencies[dependency] = {};
}
var versions = allDependencies[dependency];
if (!versions.hasOwnProperty(version)) {
versions[version] = [];
}
}
// --[ Consume package.json files ]-----------------------------------------------------------
var packageFiles = [];
packageFiles.push(require("./blueocean-dashboard/package.json"));
packageFiles.push(require("./blueocean-web/package.json"));
packageFiles.forEach(packageFile => {
addDependencies("prod", packageFile.dependencies);
addDependencies("dev", packageFile.devDependencies);
addDependencies("peer", packageFile.peerDependencies);
function addDependencies(kind, deps) {
if (deps) {
Object.keys(deps).forEach(dependency => {
const version = deps[dependency];
initEntry(dependency, version);
allDependencies[dependency][version].push(packageFile.name + " (" + kind + ")");
});
}
}
});
// --[ Check + print results ]----------------------------------------------------------------
let errs = [];
Object.keys(allDependencies).forEach(dependency => {
let versions = allDependencies[dependency];
if (Object.keys(versions).length !== 1) {
let err = {};
err[dependency] = versions;
errs.push(err);
}
});
if (errs.length) {
console.error(JSON.stringify(errs, null, 4));
process.exit(1);
}