From dc1eff8e8af5dc2f7fa739c80b53e2521b2fb4b1 Mon Sep 17 00:00:00 2001 From: Test Date: Mon, 14 Oct 2024 17:24:44 -0700 Subject: [PATCH] add download step --- .idea/.name | 2 +- binary/.idea/vcs.xml | 6 ++ binary/build.js | 1 + core/config/load.ts | 122 +++++++++++++++++++------- core/util/GlobalContext.ts | 1 + core/util/paths.ts | 15 ++-- extensions/intellij/gradle.properties | 4 +- scripts/util/index.js | 5 +- 8 files changed, 114 insertions(+), 42 deletions(-) create mode 100644 binary/.idea/vcs.xml diff --git a/.idea/.name b/.idea/.name index c0d78d1d5..389f6bc71 100644 --- a/.idea/.name +++ b/.idea/.name @@ -1 +1 @@ -Continue IntelliJ Extension \ No newline at end of file +continue-intellij-extension \ No newline at end of file diff --git a/binary/.idea/vcs.xml b/binary/.idea/vcs.xml new file mode 100644 index 000000000..6c0b86358 --- /dev/null +++ b/binary/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/binary/build.js b/binary/build.js index ce8f3997e..3afd1811a 100644 --- a/binary/build.js +++ b/binary/build.js @@ -276,6 +276,7 @@ async function installNodeModuleInTempDirAndCopyToCurrent(packageName, toCopy) { `node_modules/${targetToLanceDb[target]}/index.node`, `${targetDir}/index.node`, ); + } const pathsToVerify = []; for (target of targets) { diff --git a/core/config/load.ts b/core/config/load.ts index 67982ecad..9f2de836e 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -49,6 +49,8 @@ import { getConfigJsonPathForRemote, getConfigTsPath, getContinueDotEnv, + getContinueUtilsPath, + getEsbuildBinaryPath, readAllGlobalPromptFiles, } from "../util/paths.js"; import { @@ -62,6 +64,7 @@ import { getPromptFiles, slashCommandFromPromptFile, } from "./promptFile.js"; +import { GlobalContext } from "../util/GlobalContext.js"; function resolveSerializedConfig(filepath: string): SerializedContinueConfig { let content = fs.readFileSync(filepath, "utf8"); @@ -525,46 +528,103 @@ function escapeSpacesInPath(p: string): string { return p.replace(/ /g, "\\ "); } -async function buildConfigTs() { - if (!fs.existsSync(getConfigTsPath())) { +async function buildConfigTs(ide: IDE, ideType: IdeType) { + const configTsPath = getConfigTsPath(); + + if (!fs.existsSync(configTsPath)) { return undefined; } - try { - if (process.env.IS_BINARY === "true") { - execSync( - `${escapeSpacesInPath(path.dirname(process.execPath))}/esbuild${ - getTarget().startsWith("win32") ? ".exe" : "" - } ${escapeSpacesInPath( - getConfigTsPath(), - )} --bundle --outfile=${escapeSpacesInPath( - getConfigJsPath(), - )} --platform=node --format=cjs --sourcemap --external:fetch --external:fs --external:path --external:os --external:child_process`, - ); - } else { - // Dynamic import esbuild so potentially disastrous errors can be caught - const esbuild = await import("esbuild"); + const defaultContent = `export function modifyConfig(config: Config): Config { + return config; +}`; - await esbuild.build({ - entryPoints: [getConfigTsPath()], - bundle: true, - platform: "node", - format: "cjs", - outfile: getConfigJsPath(), - external: ["fetch", "fs", "path", "os", "child_process"], - sourcemap: true, - }); + // Read the current content of config.ts + const currentContent = fs.readFileSync(configTsPath, "utf8"); + + // Check if the current content matches the default content + if (currentContent.trim() !== defaultContent.trim()) { + // Config.ts has been modified + const esbuildPath = getEsbuildBinaryPath(); + const globalContext = new GlobalContext(); + + if ( + ideType === "jetbrains" && + !globalContext.get("hasReceivedConfigTsNoticeJetBrains") + ) { + try { + fs.accessSync(esbuildPath); + } catch (error) { + globalContext.update("hasReceivedConfigTsNoticeJetBrains", true); + + const actionMsg = "Install esbuild"; + + const res = await ide.showToast( + "info", + "You're using a custom 'config.ts' file, which requires 'esbuild' to be installed. Would you like to install it now?", + actionMsg, + ); + + if (res === actionMsg) { + const url = "https://esbuild.github.io/dl/v0.19.11"; + + try { + const response = await fetch(url); + const binaryData = await response.arrayBuffer(); + + fs.writeFileSync( + esbuildPath, + new Uint8Array(binaryData as ArrayBuffer), + ); + + fs.chmodSync(esbuildPath, 0o755); + + await ide.showToast( + "info", + `'esbuild' successfully installed to ${esbuildPath}`, + ); + } catch (error) { + console.debug("Error downloading or saving esbuild binary:", error); + } + } + } + } + + try { + if (process.env.IS_BINARY === "true") { + execSync( + `${escapeSpacesInPath(getEsbuildBinaryPath())} ${escapeSpacesInPath( + getConfigTsPath(), + )} --bundle --outfile=${escapeSpacesInPath( + getConfigJsPath(), + )} --platform=node --format=cjs --sourcemap --external:fetch --external:fs --external:path --external:os --external:child_process`, + ); + } else { + // Dynamic import esbuild so potentially disastrous errors can be caught + const { build } = await import("esbuild"); + + await build({ + entryPoints: [getConfigTsPath()], + bundle: true, + platform: "node", + format: "cjs", + outfile: getConfigJsPath(), + external: ["fetch", "fs", "path", "os", "child_process"], + sourcemap: true, + }); + } + } catch (e) { + console.log( + `Build error. Please check your ~/.continue/config.ts file: ${e}`, + ); + return undefined; } - } catch (e) { - console.log( - `Build error. Please check your ~/.continue/config.ts file: ${e}`, - ); - return undefined; } if (!fs.existsSync(getConfigJsPath())) { return undefined; } + return fs.readFileSync(getConfigJsPath(), "utf8"); } @@ -590,7 +650,7 @@ async function loadFullConfigNode( let intermediate = await serializedToIntermediateConfig(serialized, ide); // Apply config.ts to modify intermediate config - const configJsContents = await buildConfigTs(); + const configJsContents = await buildConfigTs(ide, ideType); if (configJsContents) { try { // Try config.ts first diff --git a/core/util/GlobalContext.ts b/core/util/GlobalContext.ts index 3880b4609..ddc14bbd0 100644 --- a/core/util/GlobalContext.ts +++ b/core/util/GlobalContext.ts @@ -13,6 +13,7 @@ export type GlobalContextType = { * For VS Code users, it is unnecessary since we use transformers.js by default. */ curEmbeddingsProviderId: EmbeddingsProvider["id"]; + hasReceivedConfigTsNoticeJetBrains: boolean; }; /** diff --git a/core/util/paths.ts b/core/util/paths.ts index 28216d8af..864fc2c68 100644 --- a/core/util/paths.ts +++ b/core/util/paths.ts @@ -12,6 +12,10 @@ dotenv.config(); const CONTINUE_GLOBAL_DIR = process.env.CONTINUE_GLOBAL_DIR ?? path.join(os.homedir(), ".continue"); +export const DEFAULT_CONFIG_TS_CONTENTS = `export function modifyConfig(config: Config): Config { + return config; +}`; + export function getChromiumPath(): string { return path.join(getContinueUtilsPath(), ".chromium-browser-snapshots"); } @@ -80,12 +84,7 @@ export function getConfigJsonPath(ideType: IdeType = "vscode"): string { export function getConfigTsPath(): string { const p = path.join(getContinueGlobalPath(), "config.ts"); if (!fs.existsSync(p)) { - fs.writeFileSync( - p, - `export function modifyConfig(config: Config): Config { - return config; -}`, - ); + fs.writeFileSync(p, DEFAULT_CONFIG_TS_CONTENTS); } const typesPath = path.join(getContinueGlobalPath(), "types"); @@ -345,3 +344,7 @@ export function readAllGlobalPromptFiles( export function getRepoMapFilePath(): string { return path.join(getContinueUtilsPath(), "repo_map.txt"); } + +export function getEsbuildBinaryPath(): string { + return path.join(getContinueUtilsPath(), "esbuild"); +} diff --git a/extensions/intellij/gradle.properties b/extensions/intellij/gradle.properties index 5174871a2..a892cf145 100644 --- a/extensions/intellij/gradle.properties +++ b/extensions/intellij/gradle.properties @@ -9,7 +9,7 @@ pluginSinceBuild=223 #pluginUntilBuild = 232.* # IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension platformType=IC -platformVersion=2023.2 +platformVersion=2022.3.3 #platformVersion = LATEST-EAP-SNAPSHOT # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html # Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 @@ -23,4 +23,4 @@ org.gradle.configuration-cache=true # Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html org.gradle.caching=true # Enable Gradle Kotlin DSL Lazy Property Assignment -> https://docs.gradle.org/current/userguide/kotlin_dsl.html#kotdsl:assignment -systemProp.org.gradle.unsafe.kotlin.assignment=true +systemProp.org.gradle.unsafe.kotlin.assignment=true \ No newline at end of file diff --git a/scripts/util/index.js b/scripts/util/index.js index ec866eec3..384557492 100644 --- a/scripts/util/index.js +++ b/scripts/util/index.js @@ -1,5 +1,4 @@ const fs = require("fs"); -const os = require("os"); const { execSync } = require("child_process"); function execCmdSync(cmd) { @@ -91,7 +90,9 @@ function validateFilesPresent(pathsToVerify) { if (missingFiles.length > 0 || emptyFiles.length > 0) { throw new Error( - `The following files were missing:\n- ${missingFiles.join("\n- ")}\n\nThe following files were empty:\n- ${emptyFiles.join("\n- ")}`, + `The following files were missing:\n- ${missingFiles.join( + "\n- ", + )}\n\nThe following files were empty:\n- ${emptyFiles.join("\n- ")}`, ); } else { console.log("All paths exist");