|
1 | 1 | import { build } from "esbuild"; |
2 | | -import { copyFile, readFile, readdir, writeFile } from "node:fs/promises"; |
3 | | -import { createHash } from "node:crypto"; |
4 | | -import { join } from "node:path"; |
| 2 | +import { copyFile, writeFile } from "node:fs/promises"; |
5 | 3 | import { fileURLToPath } from "node:url"; |
| 4 | +import { desktopIdentity } from "./desktop-identity.mjs"; |
6 | 5 |
|
7 | | -await build({ |
| 6 | +const guest = await build({ |
8 | 7 | absWorkingDir: fileURLToPath(new URL("..", import.meta.url)), |
9 | 8 | entryPoints: ["src/desktop-guest.mjs"], outfile: "dist/desktop-guest.mjs", bundle: true, |
10 | | - platform: "node", format: "esm", target: "node22", |
| 9 | + platform: "node", format: "esm", target: "node22", metafile: true, |
11 | 10 | // TypeScript's bundled CommonJS runtime also resolves its own file location. |
12 | 11 | // The guest is a standalone ESM file with no installed node_modules. |
13 | 12 | banner: { js: "import { createRequire } from 'node:module'; import { fileURLToPath as guestFileURLToPath } from 'node:url'; import { dirname as guestDirname } from 'node:path'; const require = createRequire(import.meta.url); const __filename = guestFileURLToPath(import.meta.url); const __dirname = guestDirname(__filename);" }, |
14 | 13 | }); |
15 | 14 | await copyFile(new URL("../../../apps/den-worker-runtime/scripts/cloud-desktop.sh", import.meta.url), new URL("../dist/cloud-desktop.sh", import.meta.url)); |
16 | 15 |
|
17 | | -// Compatibility follows source and locked dependencies, not platform-specific |
18 | | -// bundler output or the optional packages present in a developer's install. |
19 | | -const root = fileURLToPath(new URL("../../../../", import.meta.url)); |
20 | | -const fingerprint = createHash("sha256"); |
21 | | -async function include(relative) { |
22 | | - let bytes; |
23 | | - try { bytes = await readFile(join(root, relative)); } |
24 | | - catch (error) { if (error.code === "ENOENT") return; if (error.code !== "EISDIR") throw error; } |
25 | | - if (bytes) { fingerprint.update(relative).update("\0").update(bytes).update("\0"); return; } |
26 | | - for (const entry of (await readdir(join(root, relative))).sort()) await include(`${relative}/${entry}`); |
27 | | -} |
28 | | -for (const relative of [ |
29 | | - "packages/types/src/browser-demonstration.ts", "packages/types/package.json", "packages/types/tsup.config.ts", |
30 | | - "pnpm-lock.yaml", "packages/computer-use/package.json", "packages/computer-use/src", |
31 | | - "packages/codemode/package.json", "packages/codemode/src", |
32 | | - "ee/packages/headless-computer/package.json", "ee/packages/headless-computer/Dockerfile.desktop", |
33 | | - "ee/packages/headless-computer/src/image.ts", "ee/packages/headless-computer/requirements-desktop.lock", |
34 | | - "ee/packages/headless-computer/src/desktop.ts", "ee/packages/headless-computer/src/desktop-apps.mjs", |
35 | | - "ee/packages/headless-computer/src/desktop-guest.mjs", "ee/packages/headless-computer/src/viewer-tickets.mjs", "ee/packages/headless-computer/src/desktop-scripting.mjs", |
36 | | - "ee/packages/headless-computer/src/scripting", "ee/packages/headless-computer/scripts/build-desktop.mjs", |
37 | | - "ee/packages/headless-computer/scripts/desktop-bridge.py", "ee/packages/headless-computer/scripts/vnc-stdio.py", "ee/packages/headless-computer/scripts/configure-desktop-files.sh", |
38 | | - "ee/packages/headless-computer/scripts/install-desktop-apps.sh", |
39 | | - "ee/apps/den-worker-runtime/scripts/cloud-desktop.sh", |
40 | | -]) await include(relative); |
41 | | -for (const name of (await readdir(join(root, "packages/computer-use"))).sort()) { |
42 | | - if ((name.endsWith(".mjs") && !name.endsWith(".test.mjs")) || name.endsWith(".py")) await include(`packages/computer-use/${name}`); |
43 | | -} |
44 | | -const identity = `${fingerprint.digest("hex")}\n`; |
| 16 | +// Compatibility follows what the guest bundles and the image installs, not the rest of the lockfile or code the guest |
| 17 | +// never loads (see desktop-identity.mjs). |
| 18 | +const identity = await desktopIdentity({ |
| 19 | + root: fileURLToPath(new URL("../../../../", import.meta.url)), |
| 20 | + workingDirectory: fileURLToPath(new URL("..", import.meta.url)), |
| 21 | + inputs: Object.keys(guest.metafile.inputs), |
| 22 | +}); |
45 | 23 | await writeFile(new URL("../dist/desktop-guest.version", import.meta.url), identity); |
46 | 24 | // Keep the same identity in bundled Workers, which have no package asset files. |
47 | 25 | await writeFile(new URL("../dist/desktop-identity.mjs", import.meta.url), `export default ${JSON.stringify(identity)};\n`); |
0 commit comments