diff --git a/README.md b/README.md index 71b7fb9..8ede0e4 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ pnpm install -g @offckb/cli _Require Node version `>= v20.0.0`. We recommend using latest [LTS](https://nodejs.org/en/download/package-manager) version of Node to run `offckb`_ +**Note for Windows users:** If installation fails due to native module compilation issues, the CLI will still work but may use portable binaries instead of optimized ones. For better performance, consider installing Visual Studio Build Tools. + ## Usage ```sh diff --git a/package.json b/package.json index 8549c77..9124b80 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ }, "pnpm": { "onlyBuiltDependencies": [ - "cpu-features", "secp256k1" ] }, @@ -55,7 +54,6 @@ }, "devDependencies": { "@types/adm-zip": "^0.5.5", - "@types/cpu-features": "^0.0.3", "@types/node": "^20.17.24", "@types/node-fetch": "^2.6.11", "@types/semver": "^7.5.7", @@ -80,12 +78,14 @@ "child_process": "^1.0.2", "ckb-transaction-dumper": "^0.4.2", "commander": "^12.0.0", - "cpu-features": "^0.0.10", "http-proxy": "^1.18.1", "https-proxy-agent": "^7.0.5", "node-fetch": "2", "semver": "^7.6.0", "tar": "^6.2.1", "winston": "^3.17.0" + }, + "optionalDependencies": { + "cpu-features": "^0.0.10" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9e4a9dc..9e0c747 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,9 +35,6 @@ importers: commander: specifier: ^12.0.0 version: 12.1.0 - cpu-features: - specifier: ^0.0.10 - version: 0.0.10 http-proxy: specifier: ^1.18.1 version: 1.18.1 @@ -60,9 +57,6 @@ importers: '@types/adm-zip': specifier: ^0.5.5 version: 0.5.7 - '@types/cpu-features': - specifier: ^0.0.3 - version: 0.0.3 '@types/node': specifier: ^20.17.24 version: 20.17.24 @@ -102,6 +96,10 @@ importers: typescript: specifier: ^5.3.3 version: 5.8.2 + optionalDependencies: + cpu-features: + specifier: ^0.0.10 + version: 0.0.10 packages: @@ -357,9 +355,6 @@ packages: '@types/adm-zip@0.5.7': resolution: {integrity: sha512-DNEs/QvmyRLurdQPChqq0Md4zGvPwHerAJYWk9l2jCbD1VPpnzRJorOdiq4zsw09NFbYnhfsoEhWtxIzXpn2yw==} - '@types/cpu-features@0.0.3': - resolution: {integrity: sha512-W/Ep+LDZoxMbCcH7LHRB3RN+TY4gbHl3u4uRq4XsxOh1gnpf5Lkwy5xWTBKSaJYQuMLW2XPAmRWA5Ucsy2EGVQ==} - '@types/http-proxy@1.17.16': resolution: {integrity: sha512-sdWoUajOB1cd0A8cRRQ1cfyWNbmFKLAqBB89Y8x5iYyG/mkJHc0YUH8pdWBy2omi9qtCpiIgGjuwO0dQST2l5w==} @@ -1998,8 +1993,6 @@ snapshots: dependencies: '@types/node': 20.17.24 - '@types/cpu-features@0.0.3': {} - '@types/http-proxy@1.17.16': dependencies: '@types/node': 20.17.24 @@ -2268,7 +2261,8 @@ snapshots: base64-js: 1.5.1 ieee754: 1.2.1 - buildcheck@0.0.6: {} + buildcheck@0.0.6: + optional: true call-bind-apply-helpers@1.0.2: dependencies: @@ -2375,6 +2369,7 @@ snapshots: dependencies: buildcheck: 0.0.6 nan: 2.22.2 + optional: true create-hash@1.2.0: dependencies: diff --git a/src/node/install.ts b/src/node/install.ts index 3fee4bb..dbb8136 100644 --- a/src/node/install.ts +++ b/src/node/install.ts @@ -9,7 +9,6 @@ import { Request } from '../util/request'; import { getCKBBinaryInstallPath, getCKBBinaryPath, readSettings } from '../cfg/setting'; import { encodeBinPathForTerminal } from '../util/encoding'; import { logger } from '../util/logger'; -import CPUFeatures from 'cpu-features'; export async function installCKBBinary(version: string) { const ckbBinPath = getCKBBinaryPath(version); @@ -149,14 +148,30 @@ function getExtension(): 'tar.gz' | 'zip' { return 'zip'; } +let cachedIsPortable: boolean | undefined = undefined; + function isPortable(): boolean { - const features = CPUFeatures(); - if (features.arch === 'x86') { - const flags = features.flags as CPUFeatures.X86CpuFlags; - // if lacks any of the following instruction, use portable binary - return !(flags.avx2 && flags.sse4_2 && flags.bmi2 && flags.pclmulqdq); + if (cachedIsPortable !== undefined) { + return cachedIsPortable; + } + + try { + const CPUFeatures = require('cpu-features'); + const features = CPUFeatures(); + if (features.arch === 'x86') { + const flags = features.flags as any; // CPUFeatures.X86CpuFlags + // if lacks any of the following instruction, use portable binary + cachedIsPortable = !(flags.avx2 && flags.sse4_2 && flags.bmi2 && flags.pclmulqdq); + } else { + cachedIsPortable = false; + } + } catch (error) { + // If cpu-features fails to load (e.g., on Windows without build tools), use portable binary + logger.warn('Failed to detect CPU features, using portable binary', error); + cachedIsPortable = true; } - return false; + + return cachedIsPortable; } function buildCKBGithubReleasePackageName(version: string, opt: { os?: string; arch?: string } = {}) { diff --git a/templates/v3/js-script-next-js/packages/frontend/package.json b/templates/v3/js-script-next-js/packages/frontend/package.json index de11a62..0c64d99 100644 --- a/templates/v3/js-script-next-js/packages/frontend/package.json +++ b/templates/v3/js-script-next-js/packages/frontend/package.json @@ -11,7 +11,7 @@ "dependencies": { "@ckb-ccc/connector-react": "^v1.0.14", "@ckb-ccc/lumos-patches": "^1.0.14", - "next": "^15.4.8", + "next": "^15.4.10", "react": "^18", "react-dom": "^18" }, diff --git a/templates/v3/js-script-next-js/pnpm-lock.yaml b/templates/v3/js-script-next-js/pnpm-lock.yaml index 8f19e20..2bcfc5e 100644 --- a/templates/v3/js-script-next-js/pnpm-lock.yaml +++ b/templates/v3/js-script-next-js/pnpm-lock.yaml @@ -37,8 +37,8 @@ importers: specifier: ^1.0.14 version: 1.0.16(typescript@5.8.3) next: - specifier: ^15.4.8 - version: 15.4.8(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + specifier: ^15.4.10 + version: 15.4.10(react-dom@18.3.1(react@18.3.1))(react@18.3.1) react: specifier: ^18 version: 18.3.1 @@ -841,8 +841,8 @@ packages: '@nervosnetwork/ckb-types@0.109.5': resolution: {integrity: sha512-5jQNjFw76YCd+Ppl+0RvBWzxwvWaKfWC5wjVFFdNAieX7xksCHfZFIeow8je7AF8uVypwe56WlLBlblxw9NBBQ==} - '@next/env@15.4.8': - resolution: {integrity: sha512-LydLa2MDI1NMrOFSkO54mTc8iIHSttj6R6dthITky9ylXV2gCGi0bHQjVCtLGRshdRPjyh2kXbxJukDtBWQZtQ==} + '@next/env@15.4.10': + resolution: {integrity: sha512-knhmoJ0Vv7VRf6pZEPSnciUG1S4bIhWx+qTYBW/AjxEtlzsiNORPk8sFDCEvqLfmKuey56UB9FL1UdHEV3uBrg==} '@next/eslint-plugin-next@14.2.3': resolution: {integrity: sha512-L3oDricIIjgj1AVnRdRor21gI7mShlSwU/1ZGHmqM3LzHhXXhdkrfeNY5zif25Bi5Dd7fiJHsbhoZCHfXYvlAw==} @@ -1429,8 +1429,8 @@ packages: resolution: {integrity: sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==} engines: {node: '>=10'} - caniuse-lite@1.0.30001759: - resolution: {integrity: sha512-Pzfx9fOKoKvevQf8oCXoyNRQ5QyxJj+3O0Rqx2V5oxT61KGx8+n6hV/IUyJeifUci2clnmmKVpvtiqRzgiWjSw==} + caniuse-lite@1.0.30001760: + resolution: {integrity: sha512-7AAMPcueWELt1p3mi13HR/LHH0TJLT11cnwDJEs3xA4+CK/PLKeO9Kl1oru24htkyUKtkGCvAx4ohB0Ttry8Dw==} chalk@4.1.2: resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==} @@ -2609,8 +2609,8 @@ packages: natural-compare@1.4.0: resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} - next@15.4.8: - resolution: {integrity: sha512-jwOXTz/bo0Pvlf20FSb6VXVeWRssA2vbvq9SdrOPEg9x8E1B27C2rQtvriAn600o9hH61kjrVRexEffv3JybuA==} + next@15.4.10: + resolution: {integrity: sha512-itVlc79QjpKMFMRhP+kbGKaSG/gZM6RCvwhEbwmCNF06CdDiNaoHcbeg0PqkEa2GOcn8KJ0nnc7+yL7EjoYLHQ==} engines: {node: ^18.18.0 || ^19.8.0 || >= 20.0.0} hasBin: true peerDependencies: @@ -4422,7 +4422,7 @@ snapshots: '@nervosnetwork/ckb-types@0.109.5': {} - '@next/env@15.4.8': {} + '@next/env@15.4.10': {} '@next/eslint-plugin-next@14.2.3': dependencies: @@ -4952,7 +4952,7 @@ snapshots: browserslist@4.24.4: dependencies: - caniuse-lite: 1.0.30001759 + caniuse-lite: 1.0.30001760 electron-to-chromium: 1.5.136 node-releases: 2.0.19 update-browserslist-db: 1.1.3(browserslist@4.24.4) @@ -5024,7 +5024,7 @@ snapshots: camelcase@6.3.0: {} - caniuse-lite@1.0.30001759: {} + caniuse-lite@1.0.30001760: {} chalk@4.1.2: dependencies: @@ -6605,11 +6605,11 @@ snapshots: natural-compare@1.4.0: {} - next@15.4.8(react-dom@18.3.1(react@18.3.1))(react@18.3.1): + next@15.4.10(react-dom@18.3.1(react@18.3.1))(react@18.3.1): dependencies: - '@next/env': 15.4.8 + '@next/env': 15.4.10 '@swc/helpers': 0.5.15 - caniuse-lite: 1.0.30001759 + caniuse-lite: 1.0.30001760 postcss: 8.4.31 react: 18.3.1 react-dom: 18.3.1(react@18.3.1) diff --git a/templates/v3/next-js-template/frontend/package-lock.json b/templates/v3/next-js-template/frontend/package-lock.json index 6c1bfdf..ed69e7d 100644 --- a/templates/v3/next-js-template/frontend/package-lock.json +++ b/templates/v3/next-js-template/frontend/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "@ckb-ccc/connector-react": "^v1.0.30", "@ckb-ccc/lumos-patches": "^1.0.14", - "next": "^15.4.8", + "next": "^15.4.10", "react": "^18", "react-dom": "^18" }, @@ -1590,9 +1590,9 @@ "integrity": "sha512-5jQNjFw76YCd+Ppl+0RvBWzxwvWaKfWC5wjVFFdNAieX7xksCHfZFIeow8je7AF8uVypwe56WlLBlblxw9NBBQ==" }, "node_modules/@next/env": { - "version": "15.4.8", - "resolved": "https://registry.npmjs.org/@next/env/-/env-15.4.8.tgz", - "integrity": "sha512-LydLa2MDI1NMrOFSkO54mTc8iIHSttj6R6dthITky9ylXV2gCGi0bHQjVCtLGRshdRPjyh2kXbxJukDtBWQZtQ==", + "version": "15.4.10", + "resolved": "https://registry.npmjs.org/@next/env/-/env-15.4.10.tgz", + "integrity": "sha512-knhmoJ0Vv7VRf6pZEPSnciUG1S4bIhWx+qTYBW/AjxEtlzsiNORPk8sFDCEvqLfmKuey56UB9FL1UdHEV3uBrg==", "license": "MIT" }, "node_modules/@next/eslint-plugin-next": { @@ -5626,12 +5626,12 @@ "dev": true }, "node_modules/next": { - "version": "15.4.8", - "resolved": "https://registry.npmjs.org/next/-/next-15.4.8.tgz", - "integrity": "sha512-jwOXTz/bo0Pvlf20FSb6VXVeWRssA2vbvq9SdrOPEg9x8E1B27C2rQtvriAn600o9hH61kjrVRexEffv3JybuA==", + "version": "15.4.10", + "resolved": "https://registry.npmjs.org/next/-/next-15.4.10.tgz", + "integrity": "sha512-itVlc79QjpKMFMRhP+kbGKaSG/gZM6RCvwhEbwmCNF06CdDiNaoHcbeg0PqkEa2GOcn8KJ0nnc7+yL7EjoYLHQ==", "license": "MIT", "dependencies": { - "@next/env": "15.4.8", + "@next/env": "15.4.10", "@swc/helpers": "0.5.15", "caniuse-lite": "^1.0.30001579", "postcss": "8.4.31", diff --git a/templates/v3/next-js-template/frontend/package.json b/templates/v3/next-js-template/frontend/package.json index 1022b13..5ff00e5 100644 --- a/templates/v3/next-js-template/frontend/package.json +++ b/templates/v3/next-js-template/frontend/package.json @@ -11,7 +11,7 @@ "dependencies": { "@ckb-ccc/connector-react": "^v1.0.30", "@ckb-ccc/lumos-patches": "^1.0.14", - "next": "^15.4.8", + "next": "^15.4.10", "react": "^18", "react-dom": "^18" },