Node.js server support (from NODE_SERVER_USECASE_REPORT.md): splitting a
CommonJS server now produces output that actually runs under node.
- New
--target node|browser|auto(defaultauto): AST-based runtime detection (require/module.exports/__dirname/process→ node;document/navigator→ browser). Strings/comments never influence the result; UMDtypeofguards are ignored (they prove nothing at runtime). Recorded in the manifest astarget+targetReason(js/ts only). - New
--loader-mode require(js, CommonJS only): multi-file Node loader — publishes the CommonJS wrapper bindings onglobalThis, thenvm.runInThisContexts each part in manifest order in one shared scope (mirrors the Python exec bootstrap).node app.jsandrequire('./app.js')behave like the original;module.exportsworks. Refused for ESM inputs and non-js languages with guidance. - Classic-loader guardrail: a detected/forced node target with the
classicloader refuses with the one-line fix (--loader-mode inlineorrequire); under--checkit stays advisory (exit 2). Ambiguous files keep classic behavior (no silent behavior change without evidence). --loader-mode inlineunder Node was already correct (self-contained concat,module.exports/__dirnameland where they were) — now guarded and documented as the recommended Node default.
cjs-exports(warn): top-levelmodule.exports/exports.x— invisible to ordering; must stay in the last part.node-globals(note, node target only):__dirname/__filename/process/Bufferin play.esm-require-mix(warn):import/exportandrequirein one file.top-level-return(warn, require mode): legal CJS, SyntaxError in the vm-run parts.browser-loader-on-node(warn; error path under explicit--target node): classic loader requested for a Node program.target-ambiguous(note): detection scored unknown —--targetwins.
target,targetReason,loaderRuntime(node|browser, js/ts only) andentryExports(top-level CommonJS export names, informational).
- New
test/fixtures/nodeserver.js+ 8 tests: target detection, guardrail refusals, require-mode stdout equivalence (sorted multiset — cross-file side-effect order is the documented limitation),require()ability of the entry with working exports, dup last-wins under the require loader.
Drop-in replacement release: the split output must be able to replace the original file with the host app behaving identically (see AGENTS.md "Drop-in contract"). Plus startup/install performance and safety.
- Refuse to overwrite the input file itself (outDir == input dir + loader
collision) unless
--force; the input is never deleted, even with--force. - Stale cleanup is manifest-tracked + name-precise — it only removes files
the tool emitted. It no longer deletes unrelated
*.js/*.ts/*.pyfiles in outDir, and refuses foreign-name collisions unless--force. --checkno longer needs outDir and never writes (previouslysplitcode app.js --checkcreated a./--check/directory with a full split).- New
--force(allow the above) and--dry-run(plan, write nothing).
- Duplicate declarations: order + cluster edges now link to every
same-name declaration. The
duplast-wins probe (function dup(){return 1} / function dup(){return 2} / console.log(dup())) prints2under real per-file loading (was1). - ESM inputs (
parserMode: "module") now get<script type="module">loader/tags instead of classic tags that throw at runtime. - New
--loader-mode inline: self-contained loader with all parts concatenated in order (nodocument.write, no extra requests). - New preflight codes (JS):
indirect-eval,string-callback,cjs-require,dynamic-global-key,prototype-methods,implicit-global; (TS):indirect-eval,string-callback,cjs-require,prototype-methods. Extendedimport-scriptsto member form (self.importScripts). A 9-pattern evasive fixture went from "clean" to 5 warnings + 2 notes. - New
--strict: refuse to write when preflight warns (exit 2). Exit codes documented: 0 success · 1 error · 2 risky. - HTML rewrite is span-splicing now: only processed inline blocks are
touched, other page bytes preserved verbatim (was
<hr/>→<hr>etc.). - Manifest gains
tool,toolVersion,schemaVersion,loaderMode,strict,hubThreshold,input{file,bytes,statements,sha256},output{statements,bytes}(all additive — old readers keep working). toKebabempty-base fallback (section-N) + 80-char filename cap.- Friendly errors (no stacks) for missing input, unparseable files
(preflight findings shown), oversized input (
--max-bytes, default 32MB), and missing optionaltypescript.
- Startup 713ms → ~118ms for JS runs (
typescript/node-html-parsernow lazy;typescriptmoved tooptionalDependencies). - Every input is parsed once, not 2–3× (shared AST caches; Python warns
merged into
pyfacts.py— onepython3spawn, was two; full Python run 1.59s → 0.59s). - Kahn ordering is a binary heap (3 000 clusters: 536ms → ~10ms);
Louvain uses integer-key weights; Tarjan adjacency hoisted;
chars()sizes precomputed; comment attach is a single sweep; Python offset mapping precomputed per line. - Content-hash skip: unchanged files aren't rewritten on reruns.
npm test(30 checks incl. per-file behavioral equivalence harness),npm run bench,prepacksyntax gate,engines: node>=16.- New flags:
--strict --force --dry-run --no-louvain --no-hubs --loader-mode --max-bytes --timing --quiet --help --version; flags accepted before or after outDir;--min-charsstrictly validated. typescriptis optional: JS/HTML/Python installs drop from ~27MB.
- Multi-language: TS + HTML + Python frontends on shared backend.
- Preflight risk scan per file type +
--checkmode. - Claude Skill + agent docs, GitHub Pages landing page,
llms.txt.