From 6ecfe015cf9e7e1843fcc5349fc6e97bb7fbd0ff Mon Sep 17 00:00:00 2001 From: Lyon <88232613+pikasTech@users.noreply.github.com> Date: Wed, 3 Jun 2026 17:28:30 +0800 Subject: [PATCH] fix(web): ensure web deps installed before vite build in runtime (#768) Co-authored-by: Codex --- web/hwlab-cloud-web/scripts/dist-contract.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/web/hwlab-cloud-web/scripts/dist-contract.ts b/web/hwlab-cloud-web/scripts/dist-contract.ts index ac774ac5..1fa0215f 100644 --- a/web/hwlab-cloud-web/scripts/dist-contract.ts +++ b/web/hwlab-cloud-web/scripts/dist-contract.ts @@ -186,6 +186,7 @@ function listFiles(dir) { } async function runViteBuild(rootDir, outDir) { + await ensureWebDeps(rootDir); const localVite = path.join(rootDir, "node_modules", ".bin", "vite"); const command = fs.existsSync(localVite) ? localVite : "npx"; const args = fs.existsSync(localVite) @@ -201,6 +202,21 @@ async function runViteBuild(rootDir, outDir) { }); } +async function ensureWebDeps(rootDir) { + const lockPath = path.join(rootDir, "bun.lock"); + const nodeModulesPath = path.join(rootDir, "node_modules"); + if (!fs.existsSync(lockPath)) return; + if (fs.existsSync(path.join(nodeModulesPath, "vite")) && fs.existsSync(path.join(nodeModulesPath, "react"))) return; + await new Promise((resolve, reject) => { + const child = spawn("bun", ["install", "--frozen-lockfile"], { cwd: rootDir, stdio: ["ignore", "inherit", "inherit"] }); + child.on("error", reject); + child.on("exit", (code) => { + if (code === 0) resolve(); + else reject(new Error(`bun install exited with code ${code}`)); + }); + }); +} + if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { const args = process.argv.slice(2); const rootIndex = args.indexOf("--root");