mirror of
https://github.com/stablyai/orca.git
synced 2026-09-26 16:02:43 +00:00
Round 1's finding: the input assertion built the bundle while the wrapper assertions read the committed string, so under the presets-to-preferences control the rebuild red and `__commonJS` passed against a stale artifact. And `inputs.length > 40` was a bound, not a census. `terminalDocumentBundle()` returns the text and the module list from one build, and `buildTerminalDocumentScript` is that function's text — so the thing measured is the thing written. The case asserts the exact input count, no node_modules input, neither wrapper, and that the committed artifact equals what the sources build. A stale artifact now reds. Controls: the presets pointed back at `storage/preferences` fails on the inputs and on `__commonJS` in the same run; `MIN_FIT_COLS` changed to 21 without rebuilding fails the equality. Worth knowing for the next reader: an unused export or a dropped comment does not fail it, because esbuild does not emit either — the assertion is about what ships. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
88 lines
3.1 KiB
JavaScript
88 lines
3.1 KiB
JavaScript
import { writeFile } from 'node:fs/promises'
|
|
import path from 'node:path'
|
|
import esbuild from 'esbuild'
|
|
|
|
/**
|
|
* The in-WebView terminal document, bundled from its modules.
|
|
*
|
|
* The document is a string the native WebView loads inside its HTML, so it cannot be an ES module
|
|
* there — and it is ordinary TypeScript everywhere else, which the page imports directly. So this
|
|
* is one esbuild bundle of the entry that calls `createTerminalDocument()` with no host, written
|
|
* out as a string exactly as the xterm engine beside it is.
|
|
*
|
|
* `iife`, so the bundle's module scope is its own and nothing it declares reaches the page it is
|
|
* pasted into. Not minified: the document is read in crash reports and in the WebView's own
|
|
* console, and the size it saves is small beside the engine it sits next to.
|
|
*/
|
|
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',
|
|
'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.`
|
|
|
|
/**
|
|
* One options object, so a census of what the bundle contains measures the bundle that ships.
|
|
*
|
|
* `minify: false` is load-bearing beyond readability: the engine-error overlay reports the line and
|
|
* column `window.onerror` hands it, and a minified document makes both useless.
|
|
*/
|
|
export function terminalDocumentBuildOptions(extra = {}) {
|
|
return {
|
|
entryPoints: [ENTRY],
|
|
bundle: true,
|
|
format: 'iife',
|
|
minify: false,
|
|
platform: 'browser',
|
|
target: TARGET,
|
|
legalComments: 'none',
|
|
write: false,
|
|
logLevel: 'silent',
|
|
...extra
|
|
}
|
|
}
|
|
|
|
/**
|
|
* One bundle, and everything a reader asks about it.
|
|
*
|
|
* The text and the module list come from the same build because they are two readings of one
|
|
* thing: a census that built its own would answer about a bundle nobody ships, and the pair is
|
|
* what lets a test compare the committed artifact with what the sources say it should be.
|
|
*/
|
|
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()
|
|
}
|