-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeer-dependencies
63 lines (54 loc) · 1.68 KB
/
peer-dependencies
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
#!/usr/bin/env node
/**
* This is an internal script to update peer dependencies based on released
* Safire Packages version.
*/
'use strict';
const fs = require('fs');
const Project = require('@lerna/project');
async function updatePeerDeps() {
// List all packages within the monorepo
const project = new Project(process.cwd());
const packages = await project.getPackages();
// Build a map of module name/version pairs
const lbModuleVersions = {};
for (const p of packages) {
lbModuleVersions[p.name] = p.version;
}
for (const p of packages) {
// Load package.json
const pkgJsonFile = p.manifestLocation;
const pkgJson = require(pkgJsonFile);
let updated = false;
if (pkgJson.peerDependencies) {
// Check all entries in peerDependencies
for (const d in pkgJson.peerDependencies) {
const pkgVersion = lbModuleVersions[d];
if (pkgVersion) {
// Update the version range to be `^<pkgVersion>`
// We choose to be conservative as only this version has been verified
// by CI
pkgJson.peerDependencies[d] = `^${pkgVersion}`;
updated = true;
}
}
}
if (!updated) continue;
// Convert to JSON
const json = JSON.stringify(pkgJson, null, 2);
if (process.argv[2] === '-f') {
// Using `-f` to overwrite package.json
fs.writeFileSync(pkgJsonFile, json + '\n', {encoding: 'utf-8'});
console.log('%s has been updated.', pkgJsonFile);
} else {
// Otherwise write to console
console.log('%s\n', pkgJsonFile, json);
}
}
}
if (require.main === module) {
updatePeerDeps().catch(err => {
console.error(err);
process.exit(1);
});
}