From c2d4ab133084c276d43d4e83f95a267f19de641b Mon Sep 17 00:00:00 2001 From: joffeoja <51059438+joffeoja@users.noreply.github.com> Date: Mon, 29 Sep 2025 22:27:51 +0200 Subject: [PATCH] fix(core): require user-installed esbuild for config.ts; show install hint if missing --- core/config/load.ts | 134 +++++++++++++------------------------------- 1 file changed, 39 insertions(+), 95 deletions(-) diff --git a/core/config/load.ts b/core/config/load.ts index 22a7ab22f..331288bb4 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -10,7 +10,6 @@ import { ModelRole, } from "@continuedev/config-yaml"; import * as JSONC from "comment-json"; -import * as tar from "tar"; import { BrowserSerializedContinueConfig, @@ -696,102 +695,43 @@ function escapeSpacesInPath(p: string): string { return p.replace(/ /g, "\\ "); } -async function handleEsbuildInstallation(ide: IDE, ideType: IdeType) { - // JetBrains is currently the only IDE that we've reached the plugin size limit and - // therefore need to install esbuild manually to reduce the size - if (ideType !== "jetbrains") { - return; - } - - const globalContext = new GlobalContext(); - if (globalContext.get("hasDismissedConfigTsNoticeJetBrains")) { - return; - } - - const esbuildPath = getEsbuildBinaryPath(); - - if (fs.existsSync(esbuildPath)) { - return; - } - - console.debug("No esbuild binary detected"); - - const shouldInstall = await promptEsbuildInstallation(ide); - - if (shouldInstall) { - await downloadAndInstallEsbuild(ide); - } -} - -async function promptEsbuildInstallation(ide: IDE): Promise { - const installMsg = "Install esbuild"; - const dismissMsg = "Dismiss"; - - const res = await ide.showToast( - "warning", - "You're using a custom 'config.ts' file, which requires 'esbuild' to be installed. Would you like to install it now?", - dismissMsg, - installMsg, - ); - - if (res === dismissMsg) { - const globalContext = new GlobalContext(); - globalContext.update("hasDismissedConfigTsNoticeJetBrains", true); - return false; - } - - return res === installMsg; -} - -/** - * The download logic is adapted from here: https://esbuild.github.io/getting-started/#download-a-build - */ -async function downloadAndInstallEsbuild(ide: IDE) { - const esbuildPath = getEsbuildBinaryPath(); - const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "esbuild-")); +async function handleEsbuildInstallation( + ide: IDE, + _ideType: IdeType, +): Promise { + // Only check when config.ts is going to be used; never auto-install. + const installCmd = "npm i esbuild@x.x.x --prefix ~/.continue"; + // Try to detect a user-installed esbuild (normal resolution) try { - const target = `${os.platform()}-${os.arch()}`; - const version = "0.19.11"; - const url = `https://registry.npmjs.org/@esbuild/${target}/-/${target}-${version}.tgz`; - const tgzPath = path.join(tempDir, `esbuild-${version}.tgz`); - - console.debug(`Downloading esbuild from: ${url}`); - execSync(`curl -fo "${tgzPath}" "${url}"`); - - console.debug(`Extracting tgz file to: ${tempDir}`); - await tar.x({ - file: tgzPath, - cwd: tempDir, - strip: 2, // Remove the top two levels of directories - }); - - // Ensure the destination directory exists - const destDir = path.dirname(esbuildPath); - if (!fs.existsSync(destDir)) { - fs.mkdirSync(destDir, { recursive: true }); + await import("esbuild"); + return true; // available + } catch { + // Try resolving from ~/.continue/node_modules as a courtesy + try { + const userEsbuild = path.join( + os.homedir(), + ".continue", + "node_modules", + "esbuild", + ); + const candidate = require.resolve("esbuild", { paths: [userEsbuild] }); + // eslint-disable-next-line @typescript-eslint/no-var-requires + require(candidate); + return true; // available via ~/.continue + } catch { + // Not available → show friendly instructions and opt out of building + await ide.showToast( + "error", + [ + "config.ts has been deprecated and esbuild is no longer automatically installed by Continue.", + "To use config.ts, install esbuild manually:", + "", + ` ${installCmd}`, + ].join("\n"), + ); + return false; } - - // Move the file - const extractedBinaryPath = path.join(tempDir, "esbuild"); - fs.renameSync(extractedBinaryPath, esbuildPath); - - // Ensure the binary is executable (not needed on Windows) - if (os.platform() !== "win32") { - fs.chmodSync(esbuildPath, 0o755); - } - - // Clean up - fs.unlinkSync(tgzPath); - fs.rmSync(tempDir, { recursive: true }); - - await ide.showToast( - "info", - `'esbuild' successfully installed to ${esbuildPath}`, - ); - } catch (error) { - console.error("Error downloading or saving esbuild binary:", error); - throw error; } } @@ -866,7 +806,11 @@ async function buildConfigTsandReadConfigJs(ide: IDE, ideType: IdeType) { return; } - await handleEsbuildInstallation(ide, ideType); + const ok = await handleEsbuildInstallation(ide, ideType); + if (!ok) { + // esbuild not available → we already showed a friendly message; skip building + return; + } await tryBuildConfigTs(); return readConfigJs();