forked from storybookjs/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-matching-deps.ts
53 lines (37 loc) · 1.46 KB
/
check-matching-deps.ts
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
import glob from 'glob';
import pkg from './package.json';
const packageGlobs = pkg.workspaces.packages;
console.log('packageGlobs', packageGlobs);
const packages = packageGlobs
.map((packageName) => {
return glob.sync(`./${packageName}/package.json`);
})
.flat();
console.log('checking the following locations ', packages);
type DepsComparison = Record<string, Record<string, string>>;
const depsLookup = packages.reduce((dependenciesMap, packagePath) => {
const json = require(packagePath);
const deps: [string, string][] = Object.entries(json.dependencies ?? {});
const devDeps: [string, string][] = Object.entries(json.devDependencies ?? {});
const currentDependencies = deps.concat(devDeps);
return currentDependencies.reduce((depsMapSoFar, [currentDependency, version]) => {
if (!depsMapSoFar[currentDependency]) {
depsMapSoFar[currentDependency] = {
[json.name]: version,
};
} else {
depsMapSoFar[currentDependency][json.name] = version;
}
return depsMapSoFar;
}, dependenciesMap);
}, {} as DepsComparison);
console.log('checking for mismatched versions of dependencies');
let sum = 0;
Object.entries(depsLookup).forEach(([dependency, versionsMap]) => {
const versionValues = Object.values(versionsMap);
if (versionValues.length > 1 && versionValues.some((v) => v !== versionValues[0])) {
console.log({ dependency, versionsMap });
sum++;
}
});
console.log(`found ${sum} mismatched versions`);