remove unused/unneeded esbuild plugins (#57408)

* rm unused htmlIndexPlugin

* remove esbuild experimentalNotice plugin
This commit is contained in:
Quinn Slack 2023-10-06 00:55:29 -07:00 committed by GitHub
parent 4b9ae191ca
commit c915ee79bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1 additions and 97 deletions

View File

@ -3,12 +3,7 @@ import path from 'path'
import * as esbuild from 'esbuild'
import {
stylePlugin,
packageResolutionPlugin,
experimentalNoticePlugin,
buildTimerPlugin,
} from '@sourcegraph/build-config'
import { stylePlugin, packageResolutionPlugin, buildTimerPlugin } from '@sourcegraph/build-config'
import { isDefined } from '@sourcegraph/common'
async function copyStaticFiles(sourceDir: string, destinationDir: string): Promise<void> {
@ -37,7 +32,6 @@ export const BUILD_OPTIONS: esbuild.BuildOptions = {
path: require.resolve('path-browserify'),
}),
buildTimerPlugin,
experimentalNoticePlugin,
].filter(isDefined),
define: {
global: 'window',

View File

@ -1,5 +1,4 @@
import type * as esbuild from 'esbuild'
import signale from 'signale'
export * from './monacoPlugin'
export * from './packageResolutionPlugin'
@ -16,12 +15,3 @@ export const buildTimerPlugin: esbuild.Plugin = {
build.onEnd(() => console.log(`# esbuild: build took ${Date.now() - buildStarted}ms`))
},
}
export const experimentalNoticePlugin: esbuild.Plugin = {
name: 'experimentalNotice',
setup: (): void => {
signale.info(
'esbuild usage is experimental. See https://docs.sourcegraph.com/dev/background-information/web/build#esbuild.'
)
},
}

View File

@ -12,7 +12,6 @@ import {
monacoPlugin,
RXJS_RESOLUTIONS,
buildMonaco,
experimentalNoticePlugin,
buildTimerPlugin,
} from '@sourcegraph/build-config'
import { isDefined } from '@sourcegraph/common'
@ -67,7 +66,6 @@ export const BUILD_OPTIONS: esbuild.BuildOptions = {
}),
omitSlowDeps ? null : monacoPlugin(MONACO_LANGUAGES_AND_FEATURES),
buildTimerPlugin,
experimentalNoticePlugin,
].filter(isDefined),
define: {
...Object.fromEntries(

View File

@ -1,78 +0,0 @@
import fs from 'fs'
import path from 'path'
import type * as esbuild from 'esbuild'
import * as handlebars from 'handlebars'
import { STATIC_ASSETS_PATH } from '@sourcegraph/build-config'
import { type WebpackManifest, HTML_INDEX_PATH } from '../utils'
// Note: This is only valid for Cody App.
export const assetPathPrefix = '/'
export const getManifest = (jsEntrypoint: string, cssEntrypoint?: string): WebpackManifest => ({
'app.js': path.join(assetPathPrefix, jsEntrypoint ?? 'scripts/app.js'),
'app.css': path.join(assetPathPrefix, cssEntrypoint ?? 'scripts/app.css'),
isModule: true,
})
const writeHtmlIndex = async (manifest: WebpackManifest): Promise<void> => {
const template = await fs.promises.readFile('index.html.template', 'utf8')
const render = handlebars.compile(template)
const content = render({
cssBundle: manifest['app.css'],
jsBundle: manifest['app.js'],
isModule: manifest.isModule,
})
await fs.promises.writeFile(HTML_INDEX_PATH, content)
}
const ENTRYPOINT_NAME = 'scripts/shell'
/**
* An esbuild plugin to write a index.html file for Sourcegraph, for compatibility with the current
* Go backend template system.
*
* This is only used in Cody App, currently.
*/
export const htmlIndexPlugin: esbuild.Plugin = {
name: 'htmlIndex',
setup: build => {
build.initialOptions.metafile = true
build.onEnd(async result => {
const { entryPoints } = build.initialOptions
const outputs = result?.metafile?.outputs
if (!entryPoints) {
console.error('[htmlIndexPlugin] No entrypoints found')
return
}
const absoluteEntrypoint: string | undefined = (entryPoints as any)[ENTRYPOINT_NAME]
if (!absoluteEntrypoint) {
console.error('[htmlIndexPlugin] No entrypoint found with the name scripts/app')
return
}
const relativeEntrypoint = path.relative(process.cwd(), absoluteEntrypoint)
if (!outputs) {
return
}
let jsEntrypoint: string | undefined
let cssEntrypoint: string | undefined
// Find the entrypoint in the output files
for (const [asset, output] of Object.entries(outputs)) {
if (output.entryPoint === relativeEntrypoint) {
jsEntrypoint = path.relative(STATIC_ASSETS_PATH, asset)
if (output.cssBundle) {
cssEntrypoint = path.relative(STATIC_ASSETS_PATH, output.cssBundle)
}
}
}
await writeHtmlIndex(getManifest(jsEntrypoint ?? '', cssEntrypoint))
})
},
}