Files
orca/config/scripts/verify-packaged-web-client.cjs
T
Neil d71e3e9d45 fix(serve): orca serve on orcad serves the browser client and answers plain HTTP (#30120)
* fix(serve): orca serve on orcad serves the browser client and answers plain HTTP

orcad, the default local orca serve host since the compatibility launcher,
was never handed the app's web client directory, so its HTTP server had no
request listener: every GET hung and no Web client URL was printed (#30100).

The CLI now passes the app's unpacked out/web to orcad via --web-client-root,
a server without a web client answers plain HTTP with 404 instead of hanging,
and packaging fails when the unpacked web client or a file it loads is missing.

* test(serve): pin orca serve handing orcad the app's web client root
2026-10-17 16:51:37 -07:00

49 lines
1.9 KiB
JavaScript

const { existsSync, readFileSync } = require('node:fs')
const { join, posix } = require('node:path')
const WEB_CLIENT_INDEX = 'web-index.html'
const REMEDY = 'Run pnpm build:web (build:desktop and build:release already do).'
function failure(message) {
return new Error(`[verify-packaged-web-client] ${message}`)
}
/** The relative files web-index.html loads; the page is useless if any is missing. */
function referencedAssets(html) {
const assets = new Set()
for (const match of html.matchAll(/\b(?:src|href)=["']\.\/([^"'?#]+)/g)) {
assets.add(posix.normalize(match[1]))
}
return [...assets]
}
/**
* Why: orcad serves the browser client by path from the CLI's own app root, and it runs on plain
* Node, which cannot read app.asar. So the page and everything it loads must be unpacked beside
* out/cli, or `orca serve` comes up with no web client (#30100).
*/
function assertPackagedWebClient(resourcesDir) {
const outDir = join(resourcesDir, 'app.asar.unpacked', 'out')
if (!existsSync(join(outDir, 'cli'))) {
throw failure(`no unpacked CLI at ${join(outDir, 'cli')}; the web client root resolves from it`)
}
const webRoot = join(outDir, 'web')
const indexPath = join(webRoot, WEB_CLIENT_INDEX)
if (!existsSync(indexPath)) {
throw failure(`missing unpacked ${indexPath}. ${REMEDY}`)
}
const assets = referencedAssets(readFileSync(indexPath, 'utf8'))
if (assets.length === 0) {
throw failure(`${indexPath} references no ./ assets. ${REMEDY}`)
}
const missing = assets.filter(
(asset) => asset.startsWith('..') || !existsSync(join(webRoot, ...asset.split('/')))
)
if (missing.length > 0) {
throw failure(`${indexPath} loads files missing from ${webRoot}: ${missing.join(', ')}`)
}
console.log(`[verify-packaged-web-client] OK — ${String(assets.length)} asset(s) unpacked`)
}
module.exports = { assertPackagedWebClient }