Skip to content

Commit cddc397

Browse files
committed
Migrate browser build scripts from JavaScript to TypeScript and update related dependencies
1 parent 746eea9 commit cddc397

9 files changed

Lines changed: 474 additions & 88 deletions

File tree

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const fs = require('fs')
2-
const path = require('path')
1+
import * as fs from 'fs'
2+
import * as path from 'path'
33

44
const manifest_path = path.join(__dirname, 'src', 'manifest.json')
55
const manifest = JSON.parse(fs.readFileSync(manifest_path, 'utf8'))
66

7-
const firefox_manifest = { ...manifest }
7+
const firefox_manifest: any = { ...manifest }
88
delete firefox_manifest.manifest_version
99
firefox_manifest.manifest_version = 2
1010

@@ -19,7 +19,7 @@ firefox_manifest.browser_action = firefox_manifest.action
1919
delete firefox_manifest.action
2020

2121
firefox_manifest.permissions = firefox_manifest.permissions.filter(
22-
(p) => p != 'alarms'
22+
(p: string) => p != 'alarms'
2323
)
2424

2525
firefox_manifest.permissions.push('contextualIdentities')
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
const fs = require('fs')
2-
const path = require('path')
3-
const archiver = require('archiver')
1+
import * as fs from 'fs'
2+
import * as path from 'path'
3+
import archiver from 'archiver'
44

5-
const get_version = () => {
5+
const get_version = (): string => {
66
const manifest_path = path.join(__dirname, 'src', 'manifest.json')
77
const manifest = JSON.parse(fs.readFileSync(manifest_path, 'utf8'))
88
return manifest.version
99
}
1010

11-
const create_zip_from_directory = (source_dir, output_path) => {
11+
const create_zip_from_directory = (
12+
source_dir: string,
13+
output_path: string
14+
): Promise<void> => {
1215
return new Promise((resolve, reject) => {
1316
const output = fs.createWriteStream(output_path)
1417
const archive = archiver('zip', {
@@ -22,9 +25,9 @@ const create_zip_from_directory = (source_dir, output_path) => {
2225
})
2326
}
2427

25-
const log = (message) => console.log(`[create-zip-archives] ${message}`)
28+
const log = (message: string) => console.log(`[create-zip-archives] ${message}`)
2629

27-
const delete_old_zip_archives = (current_version) => {
30+
const delete_old_zip_archives = (current_version: string) => {
2831
const files = fs.readdirSync(__dirname)
2932
const zipPattern = /extension-(.+)-(chrome|firefox)\.zip$/
3033
let deletedFiles = 0
@@ -41,8 +44,6 @@ const delete_old_zip_archives = (current_version) => {
4144

4245
if (deletedFiles > 0) {
4346
log(`Deleted ${deletedFiles} old extension archive(s)`)
44-
} else {
45-
log('No old archives to delete')
4647
}
4748
}
4849

@@ -66,7 +67,7 @@ const main = async () => {
6667
)
6768

6869
log(`Successfully created ZIP archives for version ${version}`)
69-
} catch (error) {
70+
} catch (error: any) {
7071
log(`Error creating ZIP archives: ${error.message}`)
7172
process.exit(1)
7273
}

‎apps/browser/package.json‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
{
22
"name": "gemini-coder-connector",
33
"scripts": {
4-
"build": "webpack --mode production && node create-firefox-build.js && node create-zip-archives.js",
4+
"build": "webpack --mode production && ts-node create-firefox-build.ts && ts-node create-zip-archives.ts",
55
"lint": "eslint src --ext ts,tsx",
66
"lint:fix": "eslint src --ext ts,tsx --fix"
77
},
88
"devDependencies": {
99
"@pmmmwh/react-refresh-webpack-plugin": "^0.6.1",
1010
"@svgr/webpack": "^8.1.0",
11+
"@types/archiver": "^6.0.3",
1112
"@types/jest": "^29.5.14",
1213
"@types/node": "20.x",
1314
"@types/webextension-polyfill": "^0.12.4",
14-
"@typescript-eslint/eslint-plugin": "^7.18.0",
15-
"@typescript-eslint/parser": "^7.18.0",
15+
"@typescript-eslint/eslint-plugin": "^8.54.0",
16+
"@typescript-eslint/parser": "^8.54.0",
1617
"archiver": "^6.0.1",
18+
"baseline-browser-mapping": "^2.9.19",
1719
"clean-webpack-plugin": "^4.0.0",
1820
"copy-webpack-plugin": "^12.0.2",
1921
"css-loader": "^6.8.1",
@@ -25,6 +27,7 @@
2527
"sass": "^1.93.2",
2628
"sass-loader": "^13.3.3",
2729
"style-loader": "^3.3.3",
30+
"ts-node": "^10.9.2",
2831
"ts-loader": "^9.5.4",
2932
"typescript": "^5.9.3",
3033
"webextension-polyfill": "^0.12.0",

‎apps/browser/src/background/websocket.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const connect_websocket = async (): Promise<void> => {
6363
is_reconnecting = false
6464
websocket = null
6565
}
66-
} catch (error) {
66+
} catch {
6767
is_reconnecting = false
6868
setTimeout(connect_websocket, CONFIG.RECONNECT_DELAY)
6969
}

‎apps/browser/src/content-scripts/send-prompt-content-script/chatbots/copilot.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Chatbot } from '../types/chatbot'
2-
import { CHATBOTS } from '@shared/constants/chatbots'
32
import {
43
add_apply_response_button,
54
observe_for_responses
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
const path = require('path')
2-
const CopyWebpackPlugin = require('copy-webpack-plugin')
3-
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
4-
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin')
5-
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
1+
import * as path from 'path'
2+
import * as webpack from 'webpack'
3+
import CopyWebpackPlugin from 'copy-webpack-plugin'
4+
import { CleanWebpackPlugin } from 'clean-webpack-plugin'
5+
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
6+
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
7+
import 'webpack-dev-server'
68

7-
module.exports = (_, argv) => {
9+
const config = (_: any, argv: Record<string, any>): webpack.Configuration => {
810
const is_production = argv.mode == 'production'
911

10-
const plugins = [
12+
const plugins: webpack.WebpackPluginInstance[] = [
1113
new MiniCssExtractPlugin({
1214
filename: '[name].css'
13-
}),
15+
}) as unknown as webpack.WebpackPluginInstance,
1416
new CopyWebpackPlugin({
1517
patterns: [
1618
{ from: 'src/manifest.json', to: 'manifest.json' },
@@ -75,6 +77,9 @@ module.exports = (_, argv) => {
7577
extensions: ['.ts', '.tsx', '.js', '.jsx'],
7678
plugins: [new TsconfigPathsPlugin()]
7779
},
78-
plugins
80+
plugins,
81+
stats: 'errors-warnings'
7982
}
8083
}
84+
85+
export default config

‎apps/editor/package.json‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,36 @@
317317
"icon": "$(terminal)"
318318
}
319319
],
320+
"submenus": [
321+
{
322+
"id": "codeWebChat.editorSubmenu",
323+
"label": "Code Web Chat"
324+
}
325+
],
320326
"menus": {
327+
"editor/context": [
328+
{
329+
"submenu": "codeWebChat.editorSubmenu"
330+
}
331+
],
332+
"codeWebChat.editorSubmenu": [
333+
{
334+
"command": "codeWebChat.codeAtCursor",
335+
"group": "1_action@1"
336+
},
337+
{
338+
"command": "codeWebChat.codeAtCursorWithInstructions",
339+
"group": "1_action@2"
340+
},
341+
{
342+
"command": "codeWebChat.codeAtCursorUsing",
343+
"group": "1_action@3"
344+
},
345+
{
346+
"command": "codeWebChat.codeAtCursorWithInstructionsUsing",
347+
"group": "1_action@4"
348+
}
349+
],
321350
"commandPalette": [
322351
{
323352
"command": "codeWebChat.clearChecks",

‎apps/editor/src/commands/code-at-cursor-commands.ts‎

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ const show_ghost_text = async (params: {
5252
}, 10000)
5353
}
5454

55-
const get_code_at_cursor_config = async (
56-
api_providers_manager: ModelProvidersManager,
57-
show_quick_pick: boolean = false,
58-
context: vscode.ExtensionContext,
59-
config_id?: string,
55+
const get_code_at_cursor_config = async (params: {
56+
api_providers_manager: ModelProvidersManager
57+
show_quick_pick?: boolean
58+
context: vscode.ExtensionContext
59+
config_id?: string
6060
panel_provider?: PanelProvider
61-
): Promise<{ provider: any; config: any } | undefined> => {
61+
}): Promise<{ provider: any; config: any } | undefined> => {
6262
const code_at_cursor_configs =
63-
await api_providers_manager.get_code_completions_tool_configs()
63+
await params.api_providers_manager.get_code_completions_tool_configs()
6464

6565
if (code_at_cursor_configs.length == 0) {
6666
vscode.commands.executeCommand('codeWebChat.settings')
@@ -72,18 +72,18 @@ const get_code_at_cursor_config = async (
7272

7373
let selected_config: ToolConfig | null = null
7474

75-
if (config_id !== undefined) {
75+
if (params.config_id !== undefined) {
7676
selected_config =
77-
code_at_cursor_configs.find((c) => get_tool_config_id(c) === config_id) ||
78-
null
79-
} else if (!show_quick_pick) {
77+
code_at_cursor_configs.find(
78+
(c) => get_tool_config_id(c) === params.config_id
79+
) || null
80+
} else if (!params.show_quick_pick) {
8081
const default_config =
81-
await api_providers_manager.get_default_code_completions_config()
82-
82+
await params.api_providers_manager.get_default_code_completions_config()
8383
if (default_config) {
8484
selected_config = default_config
8585
} else {
86-
const recents = context.workspaceState.get<string[]>(
86+
const recents = params.context.workspaceState.get<string[]>(
8787
RECENTLY_USED_CODE_AT_CURSOR_CONFIG_IDS_STATE_KEY
8888
)
8989
const last_selected_id = recents?.[0]
@@ -99,10 +99,10 @@ const get_code_at_cursor_config = async (
9999
}
100100
}
101101

102-
if (!selected_config || show_quick_pick) {
102+
if (!selected_config || params.show_quick_pick) {
103103
const create_items = () => {
104104
const recent_ids =
105-
context.workspaceState.get<string[]>(
105+
params.context.workspaceState.get<string[]>(
106106
RECENTLY_USED_CODE_AT_CURSOR_CONFIG_IDS_STATE_KEY
107107
) || []
108108

@@ -201,24 +201,24 @@ const get_code_at_cursor_config = async (
201201
}
202202

203203
let recents =
204-
context.workspaceState.get<string[]>(
204+
params.context.workspaceState.get<string[]>(
205205
RECENTLY_USED_CODE_AT_CURSOR_CONFIG_IDS_STATE_KEY
206206
) || []
207207
recents = [selected.id, ...recents.filter((id) => id != selected.id)]
208-
context.workspaceState.update(
208+
params.context.workspaceState.update(
209209
RECENTLY_USED_CODE_AT_CURSOR_CONFIG_IDS_STATE_KEY,
210210
recents
211211
)
212212

213-
if (panel_provider) {
214-
panel_provider.send_message({
213+
if (params.panel_provider) {
214+
params.panel_provider.send_message({
215215
command: 'SELECTED_CONFIGURATION_CHANGED',
216216
prompt_type: 'code-at-cursor',
217217
id: selected.id
218218
})
219219
}
220220

221-
const provider = await api_providers_manager.get_provider(
221+
const provider = await params.api_providers_manager.get_provider(
222222
selected.config.provider_name
223223
)
224224
if (!provider) {
@@ -245,7 +245,7 @@ const get_code_at_cursor_config = async (
245245
)
246246
}
247247

248-
const provider = await api_providers_manager.get_provider(
248+
const provider = await params.api_providers_manager.get_provider(
249249
selected_config.provider_name
250250
)
251251

@@ -299,13 +299,13 @@ const perform_code_at_cursor = async (params: {
299299
)
300300
}
301301

302-
const config_result = await get_code_at_cursor_config(
302+
const config_result = await get_code_at_cursor_config({
303303
api_providers_manager,
304-
params.show_quick_pick,
305-
params.context,
306-
params.config_id,
307-
params.panel_provider
308-
)
304+
show_quick_pick: params.show_quick_pick,
305+
context: params.context,
306+
config_id: params.config_id,
307+
panel_provider: params.panel_provider
308+
})
309309

310310
if (!config_result) {
311311
return

0 commit comments

Comments
 (0)