import { readFile, writeFile } from 'node:fs/promises' import path from 'node:path' import { createRequire } from 'node:module' import * as esbuild from 'esbuild' const require = createRequire(import.meta.url) const scriptDir = import.meta.dirname const mobileRoot = path.resolve(scriptDir, '..') const outputPath = path.join(mobileRoot, 'src', 'terminal', 'terminal-webview-engine.generated.ts') /** * The stylesheet is written beside the engine rather than inside it because the two have different * consumers. The WebView document needs both, as text; the web page needs the CSS and must never * resolve the 612 KiB engine string, which is unusable under the shell's `script-src 'self'` and * is the largest module the session route's closure would otherwise carry. One file each is what * lets the page import one without reaching the other. */ const cssOutputPath = path.join( mobileRoot, 'src', 'terminal', 'terminal-webview-engine-css.generated.ts' ) const target = 'chrome74' const packages = ['@xterm/xterm', '@xterm/addon-unicode11', '@xterm/addon-webgl'] async function readPackageVersion(packageName) { // Why: a package.json module specifier must use '/' — path.join emits '\' on // Windows, yielding an unresolvable bare specifier that fails postinstall there. const packageJsonPath = require.resolve(`${packageName}/package.json`) const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8')) return `${packageName}@${packageJson.version}` } function htmlText(value, closingTag) { return value.replace(new RegExp(`