mirror of
https://github.com/stablyai/orca.git
synced 2026-11-13 17:37:40 +00:00
70 lines
2.5 KiB
JavaScript
70 lines
2.5 KiB
JavaScript
import { writeFile } from 'node:fs/promises'
|
||
import path from 'node:path'
|
||
import esbuild from 'esbuild'
|
||
|
||
// Bundle createTerminalDocument() without host into an IIFE string for native WebView; page imports ordinary TS instead.
|
||
// IIFE isolates declarations. Keep source readable for crash reports/console; size is small relative to xterm engine.
|
||
const mobileRoot = path.join(import.meta.dirname, '..')
|
||
|
||
/** The oldest WebView Orca supports, matching the engine bundle's own floor (#7030). */
|
||
const TARGET = 'chrome74'
|
||
|
||
const ENTRY = path.join(mobileRoot, 'src', 'terminal', 'document', 'native-document-entry.ts')
|
||
|
||
export const TERMINAL_DOCUMENT_SCRIPT_PATH = path.join(
|
||
mobileRoot,
|
||
'src',
|
||
'terminal',
|
||
'document',
|
||
'terminal-webview-document-script.generated.ts'
|
||
)
|
||
|
||
const GENERATED_HEADER =
|
||
`// Generated by scripts/build-terminal-document-script.mjs. Do not edit.\n` +
|
||
`// The source is mobile/src/terminal/document/, bundled from native-document-entry.ts.\n` +
|
||
`// Target: ${TARGET}. Regenerate via pnpm postinstall.`
|
||
|
||
// Share build options with census so it measures shipped output. Keep minify:false for useful window.onerror line/column.
|
||
// Pin absWorkingDir: esbuild’s module-path comments must be reproducible and must not expose builder home paths.
|
||
export function terminalDocumentBuildOptions(extra = {}) {
|
||
return {
|
||
absWorkingDir: mobileRoot,
|
||
entryPoints: [ENTRY],
|
||
bundle: true,
|
||
format: 'iife',
|
||
minify: false,
|
||
platform: 'browser',
|
||
target: TARGET,
|
||
legalComments: 'none',
|
||
write: false,
|
||
logLevel: 'silent',
|
||
...extra
|
||
}
|
||
}
|
||
|
||
// Return text and module census from one build so tests compare committed artifact against the sources that produced it.
|
||
export async function terminalDocumentBundle() {
|
||
const result = await esbuild.build(terminalDocumentBuildOptions({ metafile: true }))
|
||
const [output] = result.outputFiles
|
||
if (!output) {
|
||
throw new Error('[build-terminal-document-script] esbuild emitted no document bundle')
|
||
}
|
||
return { script: output.text.trimEnd(), inputs: Object.keys(result.metafile.inputs) }
|
||
}
|
||
|
||
export async function buildTerminalDocumentScript() {
|
||
return (await terminalDocumentBundle()).script
|
||
}
|
||
|
||
async function main() {
|
||
const script = await buildTerminalDocumentScript()
|
||
await writeFile(
|
||
TERMINAL_DOCUMENT_SCRIPT_PATH,
|
||
`${GENERATED_HEADER}\nexport const TERMINAL_DOCUMENT_SCRIPT = ${JSON.stringify(script)}\n`
|
||
)
|
||
}
|
||
|
||
if (process.argv[1] && import.meta.url.endsWith(path.basename(process.argv[1]))) {
|
||
await main()
|
||
}
|