Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 77bbca5

Browse files
committed
wip before using codeintel api directly
1 parent f5705f4 commit 77bbca5

File tree

18 files changed

+88
-68
lines changed

18 files changed

+88
-68
lines changed

client/browser/config/esbuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function esbuildBuildOptions(mode: 'dev' | 'prod', extraPlugins: esbuild.
3333
// Worker
3434
path.resolve(browserSourcePath, 'shared/extensionHostWorker.ts'),
3535
],
36-
format: 'esm',
36+
format: 'cjs',
3737
platform: 'browser',
3838
plugins: [stylePlugin, ...extraPlugins],
3939
define: {

client/browser/scripts/tasks.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import fs from 'fs'
33
import path from 'path'
44

5-
import { omit, cloneDeep, curry } from 'lodash'
5+
import { cloneDeep, curry, omit } from 'lodash'
66
import shelljs from 'shelljs'
77
import signale from 'signale'
88
import utcVersion from 'utc-version'
@@ -175,7 +175,7 @@ function writeManifest(environment: BuildEnvironment, browser: Browser, writeDir
175175
if (EXTENSION_PERMISSIONS_ALL_URLS) {
176176
manifest.permissions!.push('<all_urls>')
177177
/** Set key to make extension id deterministic */
178-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
178+
179179
// @ts-ignore
180180
manifest.key = manifestSpec.dev.key
181181
signale.info('Adding <all_urls> to permissions because of env var setting')
@@ -186,11 +186,6 @@ function writeManifest(environment: BuildEnvironment, browser: Browser, writeDir
186186
delete manifest.storage
187187
}
188188

189-
if (browser === 'firefox') {
190-
// activeTab is not sufficient to call browser.scripting.executeScript (as it is in Chrome).
191-
manifest.permissions.push('scripting')
192-
}
193-
194189
if (browser === 'safari') {
195190
// If any modifications need to be done to the manifest for Safari, they
196191
// can be done here.
@@ -206,6 +201,14 @@ function writeManifest(environment: BuildEnvironment, browser: Browser, writeDir
206201
delete manifest.background!.service_worker
207202
}
208203

204+
if (browser === 'firefox') {
205+
manifest.browser_specific_settings = {
206+
gecko: {
207+
id: 'sourcegraph-for-firefox@sourcegraph.com',
208+
},
209+
}
210+
}
211+
209212
delete manifest.$schema
210213

211214
if (environment === 'prod' && useUtcVersion) {

client/browser/src/browser-extension/browser-action-icon.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import { IsProductionVersion } from './util'
99
* on the state of the browser extension.
1010
*/
1111

12-
/** State of the Sourcegraph browser extension, as represented by the browser
13-
* action icon. */
12+
/**
13+
* State of the Sourcegraph browser extension, as represented by the browser
14+
* action icon.
15+
*/
1416
export type BrowserActionIconState = 'active' | 'active-with-alert' | 'inactive'
1517
interface BrowserActionIconPaths {
1618
'32': string
@@ -21,36 +23,36 @@ interface BrowserActionIconPaths {
2123
const browserActionIconPaths: Record<BrowserActionIconState, BrowserActionIconPaths> = IsProductionVersion
2224
? {
2325
active: {
24-
'32': 'img/icon-32.png',
25-
'48': 'img/icon-48.png',
26-
'128': 'img/icon-128.png',
26+
'32': '/img/icon-32.png',
27+
'48': '/img/icon-48.png',
28+
'128': '/img/icon-128.png',
2729
},
2830
'active-with-alert': {
29-
'32': 'img/icon-active-with-alert-32.png',
30-
'48': 'img/icon-active-with-alert-48.png',
31-
'128': 'img/icon-active-with-alert-128.png',
31+
'32': '/img/icon-active-with-alert-32.png',
32+
'48': '/img/icon-active-with-alert-48.png',
33+
'128': '/img/icon-active-with-alert-128.png',
3234
},
3335
inactive: {
34-
'32': 'img/icon-inactive-32.png',
35-
'48': 'img/icon-inactive-48.png',
36-
'128': 'img/icon-inactive-128.png',
36+
'32': '/img/icon-inactive-32.png',
37+
'48': '/img/icon-inactive-48.png',
38+
'128': '/img/icon-inactive-128.png',
3739
},
3840
}
3941
: {
4042
active: {
41-
'32': 'img/dev/icon-32.png',
42-
'48': 'img/dev/icon-48.png',
43-
'128': 'img/dev/icon-128.png',
43+
'32': '/img/dev/icon-32.png',
44+
'48': '/img/dev/icon-48.png',
45+
'128': '/img/dev/icon-128.png',
4446
},
4547
'active-with-alert': {
46-
'32': 'img/dev/icon-active-with-alert-32.png',
47-
'48': 'img/dev/icon-active-with-alert-48.png',
48-
'128': 'img/dev/icon-active-with-alert-128.png',
48+
'32': '/img/dev/icon-active-with-alert-32.png',
49+
'48': '/img/dev/icon-active-with-alert-48.png',
50+
'128': '/img/dev/icon-active-with-alert-128.png',
4951
},
5052
inactive: {
51-
'32': 'img/dev/icon-inactive-32.png',
52-
'48': 'img/dev/icon-inactive-48.png',
53-
'128': 'img/dev/icon-inactive-128.png',
53+
'32': '/img/dev/icon-inactive-32.png',
54+
'48': '/img/dev/icon-inactive-48.png',
55+
'128': '/img/dev/icon-inactive-128.png',
5456
},
5557
}
5658

@@ -60,7 +62,7 @@ const browserActionIconPaths: Record<BrowserActionIconState, BrowserActionIconPa
6062
export function setBrowserActionIconState(iconState: BrowserActionIconState): void {
6163
const iconPaths = browserActionIconPaths[iconState]
6264
console.log('Setting icons to', iconPaths)
63-
browser.action.setIcon({ path: iconPaths }).catch(error => {
65+
;(browser.action ?? browser.browserAction).setIcon({ path: iconPaths }).catch(error => {
6466
console.error(error)
6567
})
6668
}

client/browser/src/browser-extension/environmentAssertion.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export function assertEnvironment(environment: typeof window['EXTENSION_ENV']): void {
2-
if (window.EXTENSION_ENV !== environment) {
2+
if (globalThis.EXTENSION_ENV !== environment) {
33
throw new Error(
44
'Detected transitive import of an entrypoint! ' +
5-
String(window.EXTENSION_ENV) +
5+
String(globalThis.EXTENSION_ENV) +
66
' attempted to import a file that is only intended to be imported by ' +
77
String(environment) +
88
'.'

client/browser/src/browser-extension/manifest.spec.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"run_at": "document_idle"
2929
}
3030
],
31-
"permissions": ["activeTab", "storage"],
31+
"permissions": ["activeTab", "storage", "scripting"],
3232
"host_permissions": ["https://github.com/*", "https://sourcegraph.com/*"],
3333
"optional_host_permissions": ["https://*/*", "http://*/*"],
3434
"options_ui": {
@@ -40,18 +40,13 @@
4040
},
4141
"web_accessible_resources": [
4242
{
43-
"resources": ["img/*", "css/*"],
43+
"resources": ["img/*", "css/*", "extensions/*", "extensions/sourcegraph-go/*"],
4444
"matches": ["<all_urls>"]
4545
}
4646
],
4747
"omnibox": {
4848
"keyword": "src"
4949
},
50-
"browser_specific_settings": {
51-
"gecko": {
52-
"id": "sourcegraph-for-firefox@sourcegraph.com"
53-
}
54-
},
5550
"dev": {
5651
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCl2X/axNHMbP0K/NCpMzGo/pgBSsHB2xKx6tfohORKtEv2wUMBPmkK3++kirrwYO2f8Ficyq6pjlXV8LjwPSjSw9KZj6bkDn8QNoSdCp6x9i8ZOWPw6UTQ6s54b3rGQNyvrvfD7S6LphxGEx8rNlkjpWKcrvY3+DyoFKHP/hax7wIDAQAB"
5752
}

client/browser/src/browser-extension/scripts/backgroundPage.main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ async function main(): Promise<void> {
281281

282282
// The `popup=true` param is used by the options page to determine if it's
283283
// loaded in the popup or in th standalone options page.
284-
browser.action.setPopup({ popup: 'options.html?popup=true' })
284+
;(browser.action ?? browser.browserAction).setPopup({ popup: 'options.html?popup=true' })
285285

286286
const ENDPOINT_KIND_REGEX = /^(proxy|expose)-/
287287

@@ -363,8 +363,8 @@ function handleBrowserPortPair(
363363
const subscriptions = new Subscription()
364364

365365
console.log('Extension host client connected')
366-
const { worker, clientEndpoints } = createExtensionHostWorker(workerBundleURL)
367-
subscriptions.add(() => worker.terminate())
366+
const { terminate: terminateExtensionHost, clientEndpoints } = createExtensionHostWorker(workerBundleURL)
367+
subscriptions.add(() => terminateExtensionHost())
368368

369369
/** Forwards all messages between two endpoints (in one direction) */
370370
const forwardEndpoint = (from: Endpoint, to: Endpoint): void => {

client/browser/src/browser-extension/scripts/contentPage.main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import '../../config/extension.entry'
12
// Set globals first before any imports.
23
import '../../config/content.entry'
3-
import '../../config/extension.entry'
44
// Polyfill before other imports.
55
import '../../shared/polyfills'
66

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
window.EXTENSION_ENV = 'BACKGROUND'
1+
globalThis.EXTENSION_ENV = 'BACKGROUND'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
window.EXTENSION_ENV = 'CONTENT'
1+
globalThis.EXTENSION_ENV = 'CONTENT'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
window.SG_ENV = 'EXTENSION'
1+
globalThis.SG_ENV = 'EXTENSION'

0 commit comments

Comments
 (0)