fix(web): ensure web deps installed before vite build in runtime (#768)

Co-authored-by: Codex <codex@local>
This commit is contained in:
Lyon
2026-06-03 17:28:30 +08:00
committed by GitHub
parent a78a4199a8
commit 6ecfe015cf
@@ -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");