From 1afd2738490105647076b685dc443e776d184342 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 30 Dec 2025 02:42:51 +0000 Subject: [PATCH 1/2] Initial plan From 66a26990995de0f77c08b169a11ffa2f00f12dc6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 30 Dec 2025 02:45:47 +0000 Subject: [PATCH 2/2] Apply review suggestions: add error logging and memoize isPortable Co-authored-by: RetricSu <23436060+RetricSu@users.noreply.github.com> --- src/node/install.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/node/install.ts b/src/node/install.ts index bc40997..3425669 100644 --- a/src/node/install.ts +++ b/src/node/install.ts @@ -148,21 +148,30 @@ function getExtension(): 'tar.gz' | 'zip' { return 'zip'; } +let cachedIsPortable: boolean | undefined = undefined; + function isPortable(): boolean { + 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 - return !(flags.avx2 && flags.sse4_2 && flags.bmi2 && flags.pclmulqdq); + cachedIsPortable = !(flags.avx2 && flags.sse4_2 && flags.bmi2 && flags.pclmulqdq); + } else { + cachedIsPortable = false; } - return 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'); - return true; + logger.warn('Failed to detect CPU features, using portable binary', error); + cachedIsPortable = true; } + + return cachedIsPortable; } function buildCKBGithubReleasePackageName(version: string, opt: { os?: string; arch?: string } = {}) {