diff --git a/.changeset/lemon-pots-tell.md b/.changeset/lemon-pots-tell.md new file mode 100644 index 000000000..0c075469f --- /dev/null +++ b/.changeset/lemon-pots-tell.md @@ -0,0 +1,5 @@ +--- +"claude-dev": minor +--- + +added IS_TEST build flag diff --git a/.vscode/launch.json b/.vscode/launch.json index c03c771a6..e87e2ad7c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -16,6 +16,19 @@ "IS_DEV": "true", "DEV_WORKSPACE_FOLDER": "${workspaceFolder}" } + }, + { + "name": "Run Extension (Test Mode)", + "type": "extensionHost", + "request": "launch", + "args": ["--extensionDevelopmentPath=${workspaceFolder}"], + "outFiles": ["${workspaceFolder}/dist/**/*.js"], + "preLaunchTask": "${defaultBuildTask}", + "env": { + "IS_DEV": "true", + "IS_TEST": "true", + "DEV_WORKSPACE_FOLDER": "${workspaceFolder}" + } } ] } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 84ebaf3d0..16b95dbbf 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -14,6 +14,14 @@ "isDefault": true } }, + { + "label": "watch:test", + "dependsOn": ["npm: build:webview:test", "npm: dev:webview", "npm: watch:tsc", "npm: watch:esbuild:test"], + "presentation": { + "reveal": "never" + }, + "group": "build" + }, { "type": "npm", "script": "build:webview", @@ -32,6 +40,25 @@ } } }, + { + "type": "npm", + "script": "build:webview:test", + "group": "build", + "problemMatcher": [], + "isBackground": true, + "label": "npm: build:webview:test", + "presentation": { + "group": "watch", + "reveal": "never", + "close": true + }, + "options": { + "env": { + "IS_DEV": "true", + "IS_TEST": "true" + } + } + }, { "type": "npm", "script": "dev:webview", @@ -77,6 +104,30 @@ "group": "watch", "reveal": "never", "close": true + }, + "options": { + "env": { + "IS_DEV": "true" + } + } + }, + { + "type": "npm", + "script": "watch:esbuild:test", + "group": "build", + "problemMatcher": "$esbuild-watch", + "isBackground": true, + "label": "npm: watch:esbuild:test", + "presentation": { + "group": "watch", + "reveal": "never", + "close": true + }, + "options": { + "env": { + "IS_DEV": "true", + "IS_TEST": "true" + } } }, { diff --git a/esbuild.js b/esbuild.js index 9ca34fd59..4504046e1 100644 --- a/esbuild.js +++ b/esbuild.js @@ -4,6 +4,7 @@ const path = require("path") const production = process.argv.includes("--production") const watch = process.argv.includes("--watch") +const test = process.env.IS_TEST === "true" /** * @type {import('esbuild').Plugin} @@ -68,6 +69,10 @@ const extensionConfig = { minify: production, sourcemap: !production, logLevel: "silent", + define: { + "process.env.IS_DEV": JSON.stringify(!production), + "process.env.IS_TEST": JSON.stringify(test), + }, plugins: [ copyWasmFiles, /* add to the end of plugins array */ diff --git a/package.json b/package.json index a30a340f8..c711fcee9 100644 --- a/package.json +++ b/package.json @@ -302,8 +302,12 @@ "compile": "npm run check-types && npm run lint && node esbuild.js", "watch": "npm-run-all -p watch:*", "watch:esbuild": "node esbuild.js --watch", + "watch:esbuild:test": "IS_TEST=true node esbuild.js --watch", "watch:tsc": "tsc --noEmit --watch --project tsconfig.json", "package": "npm run build:webview && npm run check-types && npm run lint && node esbuild.js --production", + "package:test": "IS_TEST=true npm run build:webview:test && npm run check-types && npm run lint && IS_TEST=true node esbuild.js --production", + "build:webview:test": "cd webview-ui && IS_TEST=true npm run build", + "watch:test": "IS_TEST=true npm-run-all -p watch:tsc watch:esbuild:test", "compile-tests": "tsc -p ./tsconfig.test.json --outDir out", "watch-tests": "tsc -p . -w --outDir out", "pretest": "npm run compile-tests && npm run compile && npm run lint", diff --git a/src/extension.ts b/src/extension.ts index ed22d984d..211223507 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -33,6 +33,7 @@ export function activate(context: vscode.ExtensionContext) { const sidebarWebview = new WebviewProvider(context, outputChannel) vscode.commands.executeCommand("setContext", "cline.isDevMode", IS_DEV && IS_DEV === "true") + vscode.commands.executeCommand("setContext", "cline.isTestMode", IS_TEST && IS_TEST === "true") context.subscriptions.push( vscode.window.registerWebviewViewProvider(WebviewProvider.sideBarId, sidebarWebview, { @@ -408,7 +409,7 @@ export function deactivate() { // // This is a workaround to reload the extension when the source code changes // since vscode doesn't support hot reload for extensions -const { IS_DEV, DEV_WORKSPACE_FOLDER } = process.env +const { IS_DEV, DEV_WORKSPACE_FOLDER, IS_TEST } = process.env if (IS_DEV && IS_DEV !== "false") { assert(DEV_WORKSPACE_FOLDER, "DEV_WORKSPACE_FOLDER must be set in development") diff --git a/webview-ui/package.json b/webview-ui/package.json index 9bde60e61..ed7132125 100644 --- a/webview-ui/package.json +++ b/webview-ui/package.json @@ -6,6 +6,7 @@ "scripts": { "dev": "vite", "build": "tsc -b && vite build", + "build:test": "tsc -b && vite build", "preview": "vite preview", "lint": "eslint .", "test": "vitest run", diff --git a/webview-ui/vite.config.ts b/webview-ui/vite.config.ts index fd31daa87..01d34eb43 100644 --- a/webview-ui/vite.config.ts +++ b/webview-ui/vite.config.ts @@ -44,6 +44,7 @@ export default defineConfig({ "process.env": { NODE_ENV: JSON.stringify(process.env.IS_DEV ? "development" : "production"), IS_DEV: JSON.stringify(process.env.IS_DEV), + IS_TEST: JSON.stringify(process.env.IS_TEST), }, }, resolve: {