added IS_TEST build flag (#2770)

* added IS_TEST build flag

* removed cross-env
This commit is contained in:
pashpashpash 2025-04-09 15:32:08 -07:00 committed by GitHub
parent 2ef4e56bca
commit 2c0afbc3be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 82 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
"claude-dev": minor
---
added IS_TEST build flag

13
.vscode/launch.json vendored
View File

@ -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}"
}
}
]
}

51
.vscode/tasks.json vendored
View File

@ -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"
}
}
},
{

View File

@ -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 */

View File

@ -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",

View File

@ -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")

View File

@ -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",

View File

@ -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: {