|
| 1 | +/** |
| 2 | + * Puts the vendored Playwright script next to the bundle that reads it. |
| 3 | + * |
| 4 | + * `vp pack` bundles code and nothing else, so a static asset under `src/` never |
| 5 | + * reaches `dist-electron/`. The bundled main resolves the script relative to |
| 6 | + * itself -- correct in a packaged app, where `src/` does not exist -- so without |
| 7 | + * this copy the file is only ever where the runtime is not looking. |
| 8 | + * |
| 9 | + * The symptom is quiet, which is the reason this exists as its own step rather |
| 10 | + * than a line in a build script: `browser_snapshot` fails with ENOENT, the model |
| 11 | + * shrugs and falls back to screenshots, and the agent still looks like it works. |
| 12 | + */ |
| 13 | +import { copyFileSync, existsSync, mkdirSync } from "node:fs"; |
| 14 | +import { dirname, join } from "node:path"; |
| 15 | +import { fileURLToPath } from "node:url"; |
| 16 | + |
| 17 | +import { |
| 18 | + VENDOR_DIRECTORY_NAME, |
| 19 | + VENDORED_INJECTED_MANIFEST_FILENAME, |
| 20 | + VENDORED_INJECTED_SCRIPT_FILENAME, |
| 21 | +} from "@threadlines/shared/previewInjectedScript"; |
| 22 | + |
| 23 | +const desktopDir = dirname(dirname(fileURLToPath(import.meta.url))); |
| 24 | + |
| 25 | +/** The manifest travels with the script so a shipped build can say which |
| 26 | + * playwright-core it came from. */ |
| 27 | +const assets = [VENDORED_INJECTED_SCRIPT_FILENAME, VENDORED_INJECTED_MANIFEST_FILENAME]; |
| 28 | + |
| 29 | +export function copyPreviewVendor() { |
| 30 | + const from = join(desktopDir, "src", "preview", VENDOR_DIRECTORY_NAME); |
| 31 | + const to = join(desktopDir, "dist-electron", VENDOR_DIRECTORY_NAME); |
| 32 | + |
| 33 | + mkdirSync(to, { recursive: true }); |
| 34 | + for (const asset of assets) { |
| 35 | + const source = join(from, asset); |
| 36 | + if (!existsSync(source)) { |
| 37 | + throw new Error( |
| 38 | + `Missing vendored preview asset ${source}. ` + |
| 39 | + `Run 'vp run --filter @threadlines/desktop vendor:playwright' to regenerate it.`, |
| 40 | + ); |
| 41 | + } |
| 42 | + copyFileSync(source, join(to, asset)); |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +if (process.argv[1] === fileURLToPath(import.meta.url)) { |
| 47 | + copyPreviewVendor(); |
| 48 | +} |
0 commit comments