Skip to content

Commit ef7d1f7

Browse files
authored
fix: web ui bundle build on windows (anomalyco#19337)
1 parent b7a06e1 commit ef7d1f7

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

packages/opencode/script/build.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,24 @@ const skipEmbedWebUi = process.argv.includes("--skip-embed-web-ui")
6868
const createEmbeddedWebUIBundle = async () => {
6969
console.log(`Building Web UI to embed in the binary`)
7070
const appDir = path.join(import.meta.dirname, "../../app")
71+
const dist = path.join(appDir, "dist")
7172
await $`bun run --cwd ${appDir} build`
72-
const allFiles = await Array.fromAsync(new Bun.Glob("**/*").scan({ cwd: path.join(appDir, "dist") }))
73-
const fileMap = `
74-
// Import all files as file_$i with type: "file"
75-
${allFiles.map((filePath, i) => `import file_${i} from "${path.join(appDir, "dist", filePath)}" with { type: "file" };`).join("\n")}
76-
// Export with original mappings
77-
export default {
78-
${allFiles.map((filePath, i) => `"${filePath}": file_${i},`).join("\n")}
79-
}
80-
`.trim()
81-
return fileMap
73+
const files = (await Array.fromAsync(new Bun.Glob("**/*").scan({ cwd: dist })))
74+
.map((file) => file.replaceAll("\\", "/"))
75+
.sort()
76+
const imports = files.map((file, i) => {
77+
const spec = path.relative(dir, path.join(dist, file)).replaceAll("\\", "/")
78+
return `import file_${i} from ${JSON.stringify(spec.startsWith(".") ? spec : `./${spec}`)} with { type: "file" };`
79+
})
80+
const entries = files.map((file, i) => ` ${JSON.stringify(file)}: file_${i},`)
81+
return [
82+
`// Import all files as file_$i with type: "file"`,
83+
...imports,
84+
`// Export with original mappings`,
85+
`export default {`,
86+
...entries,
87+
`}`,
88+
].join("\n")
8289
}
8390

8491
const embeddedFileMap = skipEmbedWebUi ? null : await createEmbeddedWebUIBundle()

0 commit comments

Comments
 (0)