Packages renamed to the @uhhm scope (@uhhm/buuh, @uhhm/buuh-html, @uhhm/buuh-component, @uhhm/buuh-devtools, @uhhm/buuh-migrate, @uhhm/bankai). Scoping is load-bearing twice over: npm routes registries per scope so @uhhm/* resolves against project.uhhm.no while everything else stays on npmjs, and it means this fork never squats upstream's names anywhere. The codemod now migrates choo v7 apps to the @uhhm names. README rewritten with the fork framing and full upstream credit; the choojs RFC moves to docs/upstream-rfc-draft.md, in the drawer for if this work ever goes home. API unchanged — choo() is still choo(). Also: Gitea Actions CI + release workflows (npm publish to the uhhm registry on tag push, CDN bundle uploaded as a generic package), npm run bundle producing dist-cdn/buuh.js (the whole framework as one minified ES module for import-map use), docs/publishing.md explaining what Gitea Packages is (a real npm registry) and is not (a CDN — serve the bundle from a static host with module-safe MIME instead), and onload.js constructing window.MutationObserver to match its own guard (surfaced by smoke-testing the bundle outside a full browser). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014NgfSjHE11oFpoSnLVKLXd
107 lines
3.4 KiB
JavaScript
107 lines
3.4 KiB
JavaScript
// Test server for e2e runs: static files from the repo root plus /ssr,
|
|
// which server-renders the counter app and serves a hydration page — the
|
|
// same app module the import map hands to the browser.
|
|
|
|
import { createServer } from 'node:http'
|
|
import { readFile } from 'node:fs/promises'
|
|
import { join, normalize, extname, dirname } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
import { Readable } from 'node:stream'
|
|
|
|
import createApp from '../../examples/counter/app.js'
|
|
import createStreamingApp from '../../examples/streaming/app.js'
|
|
|
|
const root = normalize(join(dirname(fileURLToPath(import.meta.url)), '..', '..'))
|
|
|
|
const MIME = {
|
|
'.html': 'text/html; charset=utf-8',
|
|
'.js': 'text/javascript; charset=utf-8',
|
|
'.mjs': 'text/javascript; charset=utf-8',
|
|
'.css': 'text/css; charset=utf-8',
|
|
'.json': 'application/json; charset=utf-8'
|
|
}
|
|
|
|
const IMPORT_MAP = JSON.stringify({
|
|
imports: {
|
|
'@uhhm/buuh': '/packages/core/index.js',
|
|
'@uhhm/buuh/timing': '/packages/core/lib/timing.js',
|
|
'@uhhm/buuh-html': '/packages/html/browser.js',
|
|
'@uhhm/buuh-html/raw': '/packages/html/raw.js',
|
|
'@uhhm/buuh-html/morph': '/packages/html/morph.js',
|
|
'@uhhm/buuh-html/hydrate': '/packages/html/hydrate.js'
|
|
}
|
|
})
|
|
|
|
function ssrPage () {
|
|
const body = createApp().toString('/')
|
|
// When a view owns <body>, scripts belong in <head>: type="module" is
|
|
// deferred by definition, and body must contain only what the view
|
|
// renders or hydration would (rightly) flag the extra nodes.
|
|
return `<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>choo v8 ssr counter</title>
|
|
<script type="importmap">${IMPORT_MAP}</script>
|
|
<script type="module">
|
|
import createApp from '/examples/counter/app.js'
|
|
createApp().mount('body')
|
|
</script>
|
|
</head>
|
|
${body}
|
|
</html>`
|
|
}
|
|
|
|
export function startServer () {
|
|
const server = createServer(async (req, res) => {
|
|
const url = new URL(req.url, 'http://localhost')
|
|
|
|
if (url.pathname === '/ssr') {
|
|
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' })
|
|
res.end(ssrPage())
|
|
return
|
|
}
|
|
|
|
if (url.pathname === '/stream') {
|
|
const delay = Number(url.searchParams.get('delay')) || 500
|
|
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' })
|
|
// padding nudges browsers to start parsing before the stream closes
|
|
res.write('<!doctype html>\n<html lang="en">\n<head><meta charset="utf-8"><title>choo streams</title></head>\n' + '<!-- ' + ' '.repeat(1024) + ' -->\n')
|
|
const body = Readable.fromWeb(createStreamingApp({ delay }).toStream('/'))
|
|
body.pipe(res, { end: false })
|
|
body.on('end', () => res.end('\n</html>'))
|
|
body.on('error', () => res.destroy())
|
|
return
|
|
}
|
|
|
|
let pathname = decodeURIComponent(url.pathname)
|
|
if (pathname.endsWith('/')) pathname += 'index.html'
|
|
const file = normalize(join(root, pathname))
|
|
if (!file.startsWith(root)) {
|
|
res.writeHead(403).end()
|
|
return
|
|
}
|
|
|
|
try {
|
|
const data = await readFile(file)
|
|
res.writeHead(200, {
|
|
'content-type': MIME[extname(file)] || 'application/octet-stream'
|
|
})
|
|
res.end(data)
|
|
} catch (e) {
|
|
res.writeHead(404).end('not found: ' + pathname)
|
|
}
|
|
})
|
|
|
|
return new Promise((resolve) => {
|
|
server.listen(0, '127.0.0.1', () => {
|
|
resolve({
|
|
server,
|
|
origin: `http://127.0.0.1:${server.address().port}`,
|
|
close: () => new Promise((r) => server.close(r))
|
|
})
|
|
})
|
|
})
|
|
}
|