Files
Bendik Aagaard LynghaugandClaude Fable 5 ce1ec9e4a9 rebrand: buuh — a friendly public fork under the uhhm org
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
2026-09-08 19:55:20 +02:00

99 lines
4.0 KiB
JavaScript

// The v7 → v8 source transform. Deliberately regex-based and honest about
// it: simple top-level CJS patterns are converted mechanically, package
// specifiers are remapped, and everything the regexes cannot prove is
// reported as a note instead of guessed at.
// old specifier → new specifier
export const SPECIFIERS = {
choo: '@uhhm/buuh',
'choo/html': '@uhhm/buuh-html',
'choo/html/raw': '@uhhm/buuh-html/raw',
'choo/component': '@uhhm/buuh-component',
nanohtml: '@uhhm/buuh-html',
'nanohtml/raw': '@uhhm/buuh-html/raw',
nanomorph: '@uhhm/buuh-html/morph',
nanocomponent: '@uhhm/buuh-component',
'choo-devtools': '@uhhm/buuh-devtools'
}
// old specifier → guidance (no direct replacement package)
export const RETIRED = {
nanobus: "built into @uhhm/buuh — use app.emitter, or import Nanobus from '@uhhm/buuh' internals is no longer needed",
nanorouter: 'built into @uhhm/buuh — app.route covers it',
nanohref: 'built into @uhhm/buuh — link handling is automatic',
nanotiming: "built into @uhhm/buuh — import from '@uhhm/buuh/timing' if you need it directly",
nanoraf: 'retired — use requestAnimationFrame, or rely on choo render batching',
nanoquery: 'retired — state.query is built in; use URLSearchParams directly elsewhere',
nanoassert: 'retired — use plain checks or node:assert',
nanolru: 'retired — the component cache is built into @uhhm/buuh',
'choo-lazy-route': "replaced by lazy() from '@uhhm/buuh': app.route('/x', lazy(() => import('./x.js')))",
'choo-service-worker': 'kept as a concept; bankai v10 will inject the asset manifest — check docs before migrating this one'
}
export default function transform (source) {
const notes = []
let code = source
// --- CJS → ESM, simple top-level forms ---
// const { a, b } = require('x')
code = code.replace(
/^(\s*)(?:var|let|const)\s*\{([^}]+)\}\s*=\s*require\((['"])([^'"]+)\3\)\s*;?[^\S\n]*$/gm,
(m, indent, names, q, spec) => `${indent}import {${names}} from '${spec}'`
)
// const X = require('x').default / .thing
code = code.replace(
/^(\s*)(?:var|let|const)\s+([A-Za-z_$][\w$]*)\s*=\s*require\((['"])([^'"]+)\3\)\.default\s*;?[^\S\n]*$/gm,
(m, indent, name, q, spec) => `${indent}import ${name} from '${spec}'`
)
code = code.replace(
/^(\s*)(?:var|let|const)\s+([A-Za-z_$][\w$]*)\s*=\s*require\((['"])([^'"]+)\3\)\.([A-Za-z_$][\w$]*)\s*;?[^\S\n]*$/gm,
(m, indent, name, q, spec, prop) => `${indent}import { ${prop} as ${name} } from '${spec}'`
)
// const X = require('x')
code = code.replace(
/^(\s*)(?:var|let|const)\s+([A-Za-z_$][\w$]*)\s*=\s*require\((['"])([^'"]+)\3\)\s*;?[^\S\n]*$/gm,
(m, indent, name, q, spec) => `${indent}import ${name} from '${spec}'`
)
// bare require('x') statements (side-effect imports)
code = code.replace(
/^(\s*)require\((['"])([^'"]+)\2\)\s*;?[^\S\n]*$/gm,
(m, indent, q, spec) => `${indent}import '${spec}'`
)
// module.exports = X
code = code.replace(/^(\s*)module\.exports\s*=\s*/gm, (m, indent, offset) => {
return `${indent}export default `
})
// --- specifier remapping (imports and any requires we couldn't convert) ---
code = code.replace(
/(from\s*|import\s*\(\s*|import\s+|require\s*\(\s*)(['"])([^'"]+)\2/g,
(m, lead, q, spec) => {
if (SPECIFIERS[spec]) return `${lead}${q}${SPECIFIERS[spec]}${q}`
if (RETIRED[spec]) {
notes.push(`'${spec}': ${RETIRED[spec]}`)
}
return m
}
)
// --- things we refuse to guess at ---
if (/module\.exports\.[A-Za-z_$]/.test(code)) {
notes.push('module.exports.<name> assignments found — convert to named `export` statements by hand')
}
if (/\brequire\s*\(/.test(code)) {
notes.push('require() calls remain (non-top-level or dynamic) — convert to import/await import() by hand')
}
if (/\bexports\.[A-Za-z_$]/.test(code)) {
notes.push('bare exports.<name> assignments found — convert to named `export` statements by hand')
}
return { code, changed: code !== source, notes: [...new Set(notes)] }
}