-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
conformDependencies.js
61 lines (45 loc) · 1.25 KB
/
conformDependencies.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
const rootDeps = require("./package.json").devDependencies;
const fs = require("fs");
const dir = fs.readdirSync("./packages");
dir.forEach(mod => {
const pjson = require(`./packages/${mod}/package.json`);
const devDeps = pjson.devDependencies || {};
Object.keys(devDeps).forEach(dep => {
if (rootDeps[dep]) {
devDeps[dep] = rootDeps[dep];
}
});
const peerDeps = pjson.peerDependencies || {};
Object.keys(peerDeps).forEach(dep => {
if (devDeps[dep]) {
peerDeps[dep] = devDeps[dep];
} else if (rootDeps[dep]) {
peerDeps[dep] = rootDeps[dep];
}
});
Object.keys(peerDeps).forEach(dep => {
if (!devDeps[dep]) {
devDeps[dep] = peerDeps[dep];
}
});
if (Object.keys(peerDeps).length > 0) {
const sortedKeys = Object.keys(peerDeps).sort();
const sdeps = {};
sortedKeys.forEach(k => {
sdeps[k] = peerDeps[k];
});
pjson.peerDependencies = sdeps;
}
if (Object.keys(devDeps).length > 0) {
const sortedKeys = Object.keys(devDeps).sort();
const sdeps = {};
sortedKeys.forEach(k => {
sdeps[k] = devDeps[k];
});
pjson.devDependencies = sdeps;
}
fs.writeFileSync(
`./packages/${mod}/package.json`,
JSON.stringify(pjson, null, 2)
);
});