forked from siemens/element
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostversion.js
More file actions
42 lines (38 loc) · 1.19 KB
/
postversion.js
File metadata and controls
42 lines (38 loc) · 1.19 KB
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
import { glob } from 'node:fs/promises';
import { readFile, writeFile } from 'node:fs/promises';
async function updatePeerDependencies() {
const versions = new Map();
for await (const file of glob(['package.json', 'projects/**/package.json'])) {
const content = JSON.parse(await readFile(file, { encoding: 'utf8' }));
versions.set(content.name, content.version);
console.log(file);
}
for await (const file of glob([
'package.json',
'projects/**/package.json',
'dist/**/package.json'
])) {
let updated = false;
const content = JSON.parse(await readFile(file, { encoding: 'utf8' }));
if (content.peerDependencies) {
for (const dependencyType of [
'dependencies',
'devDependencies',
'peerDependencies',
'optionalDependencies'
]) {
for (const name of Object.keys(content[dependencyType] ?? [])) {
const version = versions.get(name);
if (versions.has(name)) {
content[dependencyType][name] = version;
updated = true;
}
}
}
}
if (updated) {
await writeFile(file, JSON.stringify(content, null, 2));
}
}
}
updatePeerDependencies();