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

Commit e0cd3c8

Browse files
Bundle legacy code intel extension for native integrations (#42106)
Part of #41921 We have a deployment method of the browser extensions that we call "native integrations". The idea here is that we inject the browser extension code directly from the code host so that users do not need to install an extension. Most prominently, this is used by GitLab who currently bundles a version of the native integrations package with their on-premise builds so instance admins can enable this for users. The issue with this deployment model is that we have no impact on when these clients are updated. We rely on GitLabs rollout and update policies so these cycles are super slow. For the upcoming release, we had to cut a corner for this and made the extensions GraphQL endpoints handle eventual native integration requests with special care to not break them. Since we eventually want to remove these APIs, we want to move fast here and provide a new native integration build that does not use these APIs anymore. Before we can update the bundled version on the GitLab end, we need to make sure that the package contains a bundled version of the code intel APIs (similar to our browser extensions right now). This is what's happening here: - This PR adds bundles the legacy code intel APIs to the `@sourcegraph/code-host-integration` package. - It also changes the gating of the inlined extensions so that they are loaded on GitLab. Co-authored-by: Taras Yemets <[email protected]>
1 parent b354496 commit e0cd3c8

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

client/browser/scripts/build-npm.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { writeFile } from 'mz/fs'
55
import * as semver from 'semver'
66
import signale from 'signale'
77

8+
import { copyInlineExtensions } from './tasks'
9+
810
export const packagePath = path.resolve(__dirname, '..', 'build', 'integration')
911

1012
/**
@@ -41,4 +43,6 @@ export async function buildNpm(bumpVersion?: boolean): Promise<void> {
4143
signale.info(`New version is ${packageJson.version}`)
4244
// Write package.json
4345
await writeFile(path.join(packagePath, 'package.json'), JSON.stringify(packageJson, null, 2))
46+
47+
copyInlineExtensions(packagePath)
4448
}

client/browser/scripts/tasks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function copyExtensionAssets(toDirectory: string): void {
111111
*
112112
* The pre-requisite step is to first clone, build, and copy into `build/extensions`.
113113
*/
114-
function copyInlineExtensions(toDirectory: string): void {
114+
export function copyInlineExtensions(toDirectory: string): void {
115115
shelljs.cp('-R', 'build/extensions', toDirectory)
116116
}
117117

client/browser/src/shared/platform/inlineExtensionsService.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { PlatformContext } from '@sourcegraph/shared/src/platform/context'
88

99
import extensions from '../../../code-intel-extensions.json'
1010
import { EnableLegacyExtensionsResult } from '../../graphql-operations'
11-
import { isExtension } from '../context'
1211

1312
const DEFAULT_ENABLE_LEGACY_EXTENSIONS = false
1413

@@ -45,7 +44,16 @@ export const shouldUseInlineExtensions = (requestGraphQL: PlatformContext['reque
4544
return DEFAULT_ENABLE_LEGACY_EXTENSIONS
4645
}
4746
}),
48-
map(enableLegacyExtensions => !enableLegacyExtensions && isExtension)
47+
map(enableLegacyExtensions => {
48+
// TODO: The Phabricator native extension is currently the only runtime that runs the
49+
// browser extension code but does not use bundled extensions yet. We will fix this
50+
// when we update the browser extensions to use the new code intel APIs (#42104).
51+
if (window.SOURCEGRAPH_PHABRICATOR_EXTENSION === true) {
52+
return false
53+
}
54+
55+
return !enableLegacyExtensions
56+
})
4957
)
5058

5159
/**
@@ -54,10 +62,27 @@ export const shouldUseInlineExtensions = (requestGraphQL: PlatformContext['reque
5462
function getURLsForInlineExtension(extensionID: string): { manifestURL: string; scriptURL: string } {
5563
const kebabCaseExtensionID = extensionID.replace(/^sourcegraph\//, 'sourcegraph-')
5664

57-
return {
58-
manifestURL: browser.extension.getURL(`extensions/${kebabCaseExtensionID}/package.json`),
59-
scriptURL: browser.extension.getURL(`extensions/${kebabCaseExtensionID}/extension.js`),
65+
const manifestPath = `extensions/${kebabCaseExtensionID}/package.json`
66+
const scriptPath = `extensions/${kebabCaseExtensionID}/extension.js`
67+
68+
// In a browser extension environment, we need to find the absolute ULR in the browser extension
69+
// asssets directory.
70+
if (typeof window.browser !== 'undefined') {
71+
return {
72+
manifestURL: browser.extension.getURL(manifestPath),
73+
scriptURL: browser.extension.getURL(scriptPath),
74+
}
6075
}
76+
// If SOURCEGRAPH_ASSETS_URL is defined (happening for e.g. GitLab native extenisons), we can
77+
// use this URL as the root for bundled assets.
78+
if (window.SOURCEGRAPH_ASSETS_URL) {
79+
return {
80+
manifestURL: new URL(manifestPath, window.SOURCEGRAPH_ASSETS_URL).toString(),
81+
scriptURL: new URL(scriptPath, window.SOURCEGRAPH_ASSETS_URL).toString(),
82+
}
83+
}
84+
85+
throw new Error('Can not construct extension URLs')
6186
}
6287

6388
export function getInlineExtensions(): Observable<ExecutableExtension[]> {

0 commit comments

Comments
 (0)