@offckb/cli 0.3.0-canary-119a74a.0 → 0.3.0-canary-e7bf6be.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,6 +46,7 @@ const tar = __importStar(require("tar"));
46
46
  const request_1 = require("../util/request");
47
47
  const setting_1 = require("../cfg/setting");
48
48
  const encoding_1 = require("../util/encoding");
49
+ const cpu_features_1 = __importDefault(require("cpu-features"));
49
50
  function installCKBBinary(version) {
50
51
  return __awaiter(this, void 0, void 0, function* () {
51
52
  const ckbBinPath = (0, setting_1.getCKBBinaryPath)(version);
@@ -97,6 +98,7 @@ exports.downloadCKBBinaryAndUnzip = downloadCKBBinaryAndUnzip;
97
98
  function downloadAndSaveCKBBinary(version, tempFilePath) {
98
99
  return __awaiter(this, void 0, void 0, function* () {
99
100
  const downloadURL = buildDownloadUrl(version);
101
+ console.log(`downloading ${downloadURL} ..`);
100
102
  const response = yield request_1.Request.send(downloadURL);
101
103
  const arrayBuffer = yield response.arrayBuffer();
102
104
  fs.writeFileSync(tempFilePath, Buffer.from(arrayBuffer));
@@ -189,10 +191,24 @@ function getExtension() {
189
191
  }
190
192
  return 'zip';
191
193
  }
194
+ function isPortable() {
195
+ const features = (0, cpu_features_1.default)();
196
+ if (features.arch === 'x86') {
197
+ const flags = features.flags;
198
+ // if lacks any of the following instruction, use portable binary
199
+ return !(flags.avx2 && flags.sse4_2 && flags.bmi2 && flags.pclmulqdq);
200
+ }
201
+ return false;
202
+ }
192
203
  function buildDownloadUrl(version, opt = {}) {
193
204
  const os = opt.os || getOS();
194
205
  const arch = opt.arch || getArch();
195
206
  const extension = opt.ext || getExtension();
196
- return `https://github.com/nervosnetwork/ckb/releases/download/v${version}/ckb_v${version}_${arch}-${os}.${extension}`;
207
+ if (isPortable()) {
208
+ return `https://github.com/nervosnetwork/ckb/releases/download/v${version}/ckb_v${version}_${arch}-${os}-portable.${extension}`;
209
+ }
210
+ else {
211
+ return `https://github.com/nervosnetwork/ckb/releases/download/v${version}/ckb_v${version}_${arch}-${os}.${extension}`;
212
+ }
197
213
  }
198
214
  exports.buildDownloadUrl = buildDownloadUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@offckb/cli",
3
- "version": "0.3.0-canary-119a74a.0",
3
+ "version": "0.3.0-canary-e7bf6be.0",
4
4
  "description": "ckb development network for your first try",
5
5
  "author": "CKB EcoFund",
6
6
  "license": "MIT",
@@ -46,6 +46,7 @@
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/adm-zip": "^0.5.5",
49
+ "@types/cpu-features": "^0.0.3",
49
50
  "@types/node": "^20.11.19",
50
51
  "@types/node-fetch": "^2.6.11",
51
52
  "@types/semver": "^7.5.7",
@@ -68,6 +69,7 @@
68
69
  "child_process": "^1.0.2",
69
70
  "ckb-transaction-dumper": "^0.4.0",
70
71
  "commander": "^12.0.0",
72
+ "cpu-features": "^0.0.10",
71
73
  "http-proxy": "^1.18.1",
72
74
  "https-proxy-agent": "^7.0.5",
73
75
  "node-fetch": "2",