sourcegraph/client/browser/scripts/build-npm.ts
Philipp Spiess e0cd3c89f0
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 <yemets.taras@gmail.com>
2022-09-27 12:24:48 +02:00

49 lines
1.4 KiB
TypeScript

import * as path from 'path'
import latestVersion from 'latest-version'
import { writeFile } from 'mz/fs'
import * as semver from 'semver'
import signale from 'signale'
import { copyInlineExtensions } from './tasks'
export const packagePath = path.resolve(__dirname, '..', 'build', 'integration')
/**
* Build a new native integration to npm package
*/
export async function buildNpm(bumpVersion?: boolean): Promise<void> {
const name = '@sourcegraph/code-host-integration'
// Bump version
let version = '0.0.0'
if (bumpVersion) {
try {
const currentVersion = await latestVersion(name)
signale.info(`Current version is ${currentVersion}`)
version = semver.inc(currentVersion, 'patch')!
} catch (error) {
if (error && error.name === 'PackageNotFoundError') {
signale.info('Package is not released yet')
} else {
throw error
}
}
}
const packageJson = {
name,
version,
license: 'Apache-2.0',
repository: {
type: 'git',
url: 'https://github.com/sourcegraph/sourcegraph',
directory: 'browser',
},
}
signale.info(`New version is ${packageJson.version}`)
// Write package.json
await writeFile(path.join(packagePath, 'package.json'), JSON.stringify(packageJson, null, 2))
copyInlineExtensions(packagePath)
}