fix(web): ensure web deps installed before vite build in runtime (#768)
Co-authored-by: Codex <codex@local>
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user