-
Notifications
You must be signed in to change notification settings - Fork 303
/
.pnpmfile.cjs
48 lines (39 loc) · 1.61 KB
/
.pnpmfile.cjs
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
//@ts-check
// https://pnpm.io/pnpmfile
// https://github.com/pnpm/pnpm/issues/4214
// https://github.com/pnpm/pnpm/issues/5391
const rootPkg = require('./package.json');
console.log (`Checking for package peerDependency overrides`);
const remapPeerDependencies = [
{ package: '@solana-program/compute-budget', packageVersion: '0.6.1', peerDependency: '@solana/web3.js', newVersion: '2.0.0' },
];
function overridesPeerDependencies(pkg) {
if (pkg.peerDependencies) {
remapPeerDependencies.map(dep => {
if (pkg.name === dep.package && pkg.version.startsWith(dep.packageVersion)) {
console.log(` - Checking ${pkg.name}@${pkg.version}`); // , pkg.peerDependencies);
if (dep.peerDependency in pkg.peerDependencies) {
try {
console.log(` - Overriding ${pkg.name}@${pkg.version} peerDependency ${dep.peerDependency}@${pkg.peerDependencies[dep.peerDependency]}`);
// First add a new dependency to the package and then remove the peer dependency.
// This approach has the added advantage that scoped overrides should now work, too.
pkg.dependencies[dep.peerDependency] = dep.newVersion;
delete pkg.peerDependencies[dep.peerDependency];
console.log(` - Overrode ${pkg.name}@${pkg.version} peerDependency ${dep.peerDependency}@${pkg.dependencies[dep.peerDependency]}`);
} catch (err) {
console.error(err);
}
}
}
});
}
}
module.exports = {
hooks: {
readPackage(pkg, _context) {
// skipDeps(pkg);
overridesPeerDependencies(pkg);
return pkg;
},
},
};