-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
resolutions.js
executable file
·84 lines (71 loc) · 2.44 KB
/
resolutions.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
/**
* This script is a helper for running a buidler based e2e unit test target and is
* used in combination with the npm virtual publishing script.
*
* It discovers the current web3 package version, gets its minor increment
* (also the value of the virtually published version) and attaches a yarn resolutions field
* to the target's package.json to coerce any Web3 packages up when target is
* installed.
*
* USAGE: resolutions.js <target-folder-name>
* EXAMPLE: node scripts/js/resolutions.js mosaic-1
*
*/
const fs = require('fs');
const path = require('path');
const semver = require('semver');
const web3PackagePath = path.join(process.cwd(), 'original.package.json');
const targetPackagePath = path.join(process.cwd(), process.argv[2], 'package.json');
const web3Package = require(web3PackagePath);
const targetPackage = require(targetPackagePath);
// Use version least likely to conflict with what's been
// published to npm. (Maps to `lerna version` command
// in e2e.npm.publish.sh)
const version = semver.inc(web3Package.version, 'minor');
const web3Modules = [
"web3",
"web3-bzz",
"web3-core-helpers",
"web3-core-method",
"web3-core-promievent",
"web3-core-requestmanager",
"web3-core-subscriptions",
"web3-core",
"web3-eth-abi",
"web3-eth-accounts",
"web3-eth-contract",
"web3-eth-ens",
"web3-eth-iban",
"web3-eth-personal",
"web3-eth",
"web3-net",
"web3-providers-http",
"web3-providers-ipc",
"web3-providers-ws",
"web3-shh",
"web3-utils"
];
targetPackage.resolutions = {};
// Coerce every version of web3 in the sub-dependency tree to
// the virtually published version
for ( const mod of web3Modules ){
targetPackage.resolutions[`*/**/${mod}`] = version;
}
// Remove any outer-level web3 modules so yarn flat-packs a single
// set of web3 modules at the outerlevel
if (targetPackage.devDependencies){
for ( const mod of web3Modules ){
delete targetPackage.devDependencies[mod];
}
}
if (targetPackage.dependencies){
for ( const mod of web3Modules ){
delete targetPackage.dependencies[mod];
}
}
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
console.log(`Yarn will resolve Web3 packages in "${process.argv[2]}"" to...`);
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
console.log(JSON.stringify(targetPackage.resolutions, null, ' '));
fs.writeFileSync(targetPackagePath, JSON.stringify(targetPackage, null, ' '));