mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-16 13:03:31 +08:00
Project entry HTML often only mounts a dev-server app, while built output can be served statically. The desktop open-with policy now only offers the in-app browser for static HTML candidates, and preview-fs rewrites built HTML root-relative assets under the workspace preview path. Constraint: Frontend project index.html needs a dev server instead of preview-fs static serving Rejected: Treat every .html file as browser-previewable | project entry HTML can render blank or with missing assets Confidence: high Scope-risk: moderate Tested: cd desktop && bun run check:desktop Tested: bun run check:server Tested: git diff --check Not-tested: bun run verify was intentionally stopped at user request
37 lines
873 B
TypeScript
37 lines
873 B
TypeScript
const HTML_EXT = /\.(html?|xhtml)$/i
|
|
const INDEX_HTML_RE = /(^|\/)index\.html?$/i
|
|
|
|
const STATIC_OUTPUT_DIRS = new Set([
|
|
'build',
|
|
'coverage',
|
|
'dist',
|
|
'docs',
|
|
'lcov-report',
|
|
'out',
|
|
'public',
|
|
'site',
|
|
'storybook-static',
|
|
])
|
|
|
|
function normalizePathForPolicy(filePath: string): string {
|
|
return filePath
|
|
.split(/[?#]/, 1)[0]!
|
|
.replace(/\\/g, '/')
|
|
.replace(/^\.\//, '')
|
|
}
|
|
|
|
export function isHtmlFilePath(filePath: string): boolean {
|
|
return HTML_EXT.test(normalizePathForPolicy(filePath))
|
|
}
|
|
|
|
export function shouldOfferStaticHtmlPreview(filePath: string): boolean {
|
|
const normalized = normalizePathForPolicy(filePath)
|
|
if (!HTML_EXT.test(normalized)) return false
|
|
if (!INDEX_HTML_RE.test(normalized)) return true
|
|
|
|
return normalized
|
|
.split('/')
|
|
.filter(Boolean)
|
|
.some((segment) => STATIC_OUTPUT_DIRS.has(segment.toLowerCase()))
|
|
}
|