From c07c86e4fc01a9e086f09034e1b890c3b9e25ac0 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Wed, 21 Feb 2024 10:36:33 +0530 Subject: [PATCH] fix: install deps if node_modules not found --- esbuild/esbuild.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/esbuild/esbuild.js b/esbuild/esbuild.js index c64b68fc3d..b4d6ac24f9 100644 --- a/esbuild/esbuild.js +++ b/esbuild/esbuild.js @@ -499,14 +499,27 @@ function run_build_command_for_apps(apps) { let root_app_path = path.resolve(get_app_path(app), ".."); let package_json = path.resolve(root_app_path, "package.json"); - if (fs.existsSync(package_json)) { - let { scripts } = require(package_json); - if (scripts && scripts.build) { - log("\nRunning build command for", chalk.bold(app)); - process.chdir(root_app_path); - execSync("yarn build", { encoding: "utf8", stdio: "inherit" }); - } + let node_modules = path.resolve(root_app_path, "node_modules"); + + if (!fs.existsSync(package_json)) { + continue; } + + let { scripts } = require(package_json); + if (!scripts?.build) { + continue; + } + + process.chdir(root_app_path); + if (!fs.existsSync(node_modules)) { + log( + `\nInstalling dependencies for ${chalk.bold(app)} (because node_modules not found)` + ); + execSync("yarn install", { encoding: "utf8", stdio: "inherit" }); + } + + log("\nRunning build command for", chalk.bold(app)); + execSync("yarn build", { encoding: "utf8", stdio: "inherit" }); } process.chdir(cwd);