Repository navigation
feat(codemod): add @octanejs/codemod, a React to Octane/TSRX migration CLI - #2264
Conversation
…n CLI
Add `octane-codemod`, which rewrites React + TSX/JSX modules as Octane +
TSRX: React imports and React libraries move to `octane` and their bindings,
components become `@{ … }` templates with `@if`/`@for`/`@try` where that keeps
React's behavior, and template modules are renamed to `.tsrx` with every
import of them updated. Every migrated module is compiled before it is
written; `--strong` applies the compiler's fixes and keeps each module Strong
where the compiler accepts it.
Names resolve through a single-file TypeScript binding, contexts by
provenance across modules, literals and comments survive rewrites, and a
second run changes nothing. `@octanejs/cli` exports its binding catalog and
fix application for the codemod to reuse.
The Hacker News example gains a codemod lane: `codemod.mjs` respells `jsx/`
with React imports and migrates it, and the shared Playwright journeys run
against the result as a third project.
docs/octane-codemod-plan.md holds the implementation plan and the
third-party corpus results.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The conflicts were all generated lockfile hashes (`audit/react-parity.json` and the evals manifest); they are regenerated by `pnpm sync` against the merged `pnpm-lock.yaml`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…unner Concise pass over the codemod before review: - Find the project root and walk its sources with `findRoot` and `scanSourceFiles` from `@octanejs/cli` instead of a second walker; dot directories such as `.storybook/` are now skipped like other tooling. - Share the compiler finding shape (`finding`, `thrown`) between the runner and the Strong pass. - Report a module the compiler rejects in every mode as its compile error, not as a Strong blocker, with a regression test. - Collapse duplicated helpers in the transform (binding names, line prefixes, whitespace-only children) and flatten `mapReactImport`. - Count CLI errors from one findings list; `--no-verify` uses `parseArgs` `allowNegative`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website-mcp | bb1f3dd | Commit Preview URL Branch Preview URL |
Oct 28 2026, 09:38 PM |
…ng fallback
- Map `import('react')` and other dynamic imports of React modules to their
Octane module, as static imports already were.
- Rewrite `.Provider` on the context's tag name, so self-closing providers
migrate too; this replaces the element-level provider rewrite.
- Remove the `"use strong"` the codemod added wherever it sits in the
prologue (after `"use client"` too) when a module falls back to
compatibility mode.
- `test:e2e:dev` in the Hacker News example generates the codemod app first.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
octane-website | bb1f3dd | Commit Preview URL Branch Preview URL |
Oct 28 2026, 09:38 PM |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
Autofix Details
Bugbot Autofix prepared fixes for both issues found in the latest run.
- ✅ Fixed: Strong fallback misses mid-line directive
- Removed the
^anchor andmflag from the regex inwithoutDirectiveso it matches"use strong";\neven when preceded by a same-line block comment at the insertion point.
- Removed the
- ✅ Fixed: Codemod now walks
out/trees- Added
'out'to the CLI'sIGNORED_DIRSset used byscanSourceFiles, restoring the skip behavior the codemod's previous local walker had for the standardtscoutput directory.
- Added
Or push these changes by commenting:
@cursor push 5e78a9dce4
Preview (5e78a9dce4)
diff --git a/packages/cli/src/kernel/project.js b/packages/cli/src/kernel/project.js
--- a/packages/cli/src/kernel/project.js
+++ b/packages/cli/src/kernel/project.js
@@ -6,6 +6,7 @@
'node_modules',
'dist',
'build',
+ 'out',
'.git',
'coverage',
'.next',
diff --git a/packages/codemod/src/strong.js b/packages/codemod/src/strong.js
--- a/packages/codemod/src/strong.js
+++ b/packages/codemod/src/strong.js
@@ -21,7 +21,7 @@
*/
function withoutDirective(code) {
const top = '"use strong";\n\n';
- return code.startsWith(top) ? code.slice(top.length) : code.replace(/^"use strong";\n/m, '');
+ return code.startsWith(top) ? code.slice(top.length) : code.replace(/"use strong";\n/, '');
}
const MAX_ROUNDS = 6;You can send follow-ups to the cloud agent here.
- The prologue insertion point only ever falls at a line start (after a shebang, blank lines, whole-line comments, and directives), so the Strong fallback always finds the directive line it added, including when a comment shares the first line with code. - Project scans skip `out/` build output again, now in the CLI's shared walker, so `octane analyze` skips it too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tion debt `@octanejs/codemod` is a Node CLI like `@octanejs/cli`: it validates its shipped source with Node's types and publishes `.js` without sibling declarations. List it beside the CLI under both rules, tracked by #2266, which covers shipping declarations and scoping the Node-types rule for every Node tooling package. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The conflicts were all generated lockfile hashes (`audit/react-parity.json` and the evals manifest); they are regenerated by `pnpm sync` against the merged `pnpm-lock.yaml`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Benchmark report🟢 No byte growth, no added work, and no timing changes beyond ±3%. Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)No changes across 111 measured values. Public-import reachability bundles (bytes)No changes across 141 measured values. |
- Only a default import of React or Octane stands for the whole module; any
other module's default import is its `default` export, so a context
imported with `import Theme from './theme'` is recognized through the
project's context index and its `.Provider` migrates.
- `import('react').X` in a type position maps its module, and a React type
name Octane spells differently, the same way static imports do; renamed
relative modules are followed there too.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Nested import types skip rewrite
- Replaced
this.source.slice(specifier.end, node.end)withthis.span(node, specifier.end, node.end, PLAIN)inreplaceSpecifierso nested child nodes (includingimport('react')in type arguments) are visited and rewritten during migration.
- Replaced
Or push these changes by commenting:
@cursor push 7bb3b74c19
Preview (7bb3b74c19)
diff --git a/packages/codemod/src/transform.js b/packages/codemod/src/transform.js
--- a/packages/codemod/src/transform.js
+++ b/packages/codemod/src/transform.js
@@ -766,7 +766,7 @@
quote +
next +
quote +
- this.source.slice(specifier.end, node.end)
+ this.span(node, specifier.end, node.end, PLAIN)
);
}
diff --git a/packages/codemod/tests/transform.test.js b/packages/codemod/tests/transform.test.js
--- a/packages/codemod/tests/transform.test.js
+++ b/packages/codemod/tests/transform.test.js
@@ -134,6 +134,16 @@
expect(code).toContain("Component = import('octane').FC<{ id: string }>;");
});
+ it('rewrites nested `import()` types inside remapped specifiers', () => {
+ const source = "export type Result = import('./App').Props<import('react').ReactNode>;\n";
+ const { code } = transformModule(source, 'nested.ts', {
+ resolveSpecifier: (s) => (s === './App' ? './App.tsrx' : null),
+ });
+ expect(code).toContain("import('./App.tsrx').Props");
+ expect(code).toContain("import('octane').OctaneNode");
+ expect(code).not.toContain("import('react')");
+ });
+
it('rewrites self-closing context providers', () => {
const source =
"import { createContext } from 'react';\nconst Theme = createContext('light');\nexport function A() {\n\treturn <Theme.Provider value=\"dark\" />;\n}\n";You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 718665b. Configure here.
A remapped specifier copied the rest of its node verbatim, so in
`import('./box').Box<import('react').ReactNode>` the nested React import
was never migrated. The rest of the node is now emitted, which visits its
type arguments.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Migrated react-hooks is correct and beats React on every op, but trails the hand-written octane-tsrx target 1.2-169x and ships React-sized bytes. Record the numbers, the Strong blockers, react-classes, and the three rule candidates they point to: text-hole casts, render(App), and row inlining held on the keyed-selection question. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A child hole whose type proves it a string becomes `{x as string}`; a
number or bigint becomes `{String(x)}` (a template literal where a local
shadows `String`). Types come from one program over the project under
its tsconfig, so imported types resolve, falling back to the module's
own program, which now loads the ES5 library so array and string members
have types. As with the compiler's typed-text proof, the rule runs only
on TypeScript modules in a project with `strictNullChecks`: otherwise a
`string` may hold null, which React renders as nothing.
The js-framework run measured the casts at about 20% off creates. The
corpus casts 219 holes with no new compile errors and Strong unchanged.
The plan now records the keyed-selection finding: the inlined row's slow
selection was its `String()` call, a compiler gap fixed in #2268, not
the useReducer state; the un-inlined row's cost is memo's comparator, so
dropping a provably safe comparator replaces row inlining as the
candidate rule.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…fects Every module with JSX (`.jsx`, `.tsx`, or a `.js` file with JSX) now becomes `.tsrx`, entries and helpers without a component included, so no `.tsx` module is left outside Strong mode. A module that was JavaScript gains `// @ts-nocheck`, so it stays as unchecked as it was. On the corpus this takes `.tsrx` modules from 414 to 488 and Strong from 316 to 378, with no compile errors. Validating on the weather and chat benchmark apps found three defects: - a `.jsx` entry kept JSX that Octane's Vite plugin does not compile, so the build failed (fixed by the TSRX change); root-absolute `index.html` script paths now resolve from the page's directory; - a key on every arm of a conditional row stayed on the arms, leaving an unkeyed `@for` of runtime descriptors (+12.8 kB, ~2x streaming); a shared key now moves to the header, and differing keys keep `.map()`; - finding lines named the new file with the old file's lines, and Strong blockers kept the directive's lines; notes now name the original file, and blockers are shifted to the written one. The Hacker News server loads a TSRX `entry-server` when the lane has one. The plan records both apps' results and the compiler follow-ups. Co-Authored-By: Claude Opus 5.5 <[email protected]>


Summary
@octanejs/codemod(binoctane-codemod), which migrates a React + TSX/JSX codebase to Octane + TSRX, and with--strongtakes each module to Strong mode where the compiler accepts it..tsrx, so no.tsxmodule is left outside Strong mode; one that was JavaScript gains// @ts-nocheckand stays unchecked. Holes whose types prove them strings or numbers become text bindings ({x as string},{String(n)}).docs/octane-codemod-plan.md. M1 still needs the first publish; the TS2300 fix it was waiting on landed in fix(octane): let a type-only import share a name with a value declaration #2265.Why
forwardRef, providers, text-inputonChange, and dependency-list semantics, then renaming files and every import of them. Getting TSRX's template and Strong-mode benefits takes more again. The codemod does the mechanical parts and lists the rest by file and line.{n && <X />}stays a hole because React renders0there, anduseEffect(fn)gainsnullbecause Octane infers an omitted dependency list.Changes
packages/codemod: a new package.transform.jsbinds each module with a single-file TypeScript program, so names resolve by scope rather than spelling. A recursive emitter then copies untouched source byte for byte while per-node rules rewrite spans.template-textcasts a child hole whose type is a string, number, or bigint. Types come from one program over the project under its tsconfig, so imported types resolve. Like the compiler's typed-text proof, it runs only on TypeScript modules in a project withstrictNullChecks; otherwise astringmay hold null, which React renders as nothing.project.jsruns two passes: the first builds the rename map and a cross-module context index, the second rewrites every module, its specifiers, andindex.htmlentries. It maps React packages to bindings and lists React packages that have no binding.strong.jsloops compile → apply the compiler's suggested edits plus the codemod's exact-semantics fixers → fall back to compatibility mode, reporting what still blocks Strong.@octanejs/cli: exports./data(the binding catalog) and./fix(applyFixes/pruneImports), plusfindRootandscanSourceFilesfrom the root. The codemod uses them to find the project root and its sources, map packages, and apply fixes exactly asoctane analyze --fixdoes.examples/hacker-news: adds a codemod lane.codemod.mjsrespellsjsx/with React imports (react,react-dom/client,@tanstack/react-query,@tanstack/react-router), migrates it, and fails on any codemod error or leftover React import.build:codemodtypechecks (tsconfig.codemod.json) and builds the result.codemod, on:5195with SSR on:5197.server.mjsloads a TSRXentry-serverwhen the lane has one, since the migrated entries are.tsrx.jsx/vite.config.tsnames its Vite cache after its own directory so the copy gets its own cache.codemodvitest project, the package in the roottypecheck, the byte-exact fixtures in.prettierignore, adeveloper toolingrole inscripts/workspace-packages.mjs, andpnpm syncoutput. The lockfile hash changed, which updates thereact-parity.jsonand evals manifest hashes.Validation
pnpm format:check: not run repo-wide;pnpm format:files:checkpasses on every changed filepnpm typecheck: not run in full;octane-tscis clean onpackages/codemod/tsconfig.typecheck.json,examples/hacker-news/tsconfig.json, andexamples/hacker-news/tsconfig.codemod.jsonpnpm test: not run in fullvitest run --project codemod, 38 passed;pnpm --dir examples/hacker-news build:codemod(typecheck and build) passes with TSRX entriespnpm --dir examples/hacker-news test:e2e, run locally: 30 passed (jsx10,tsrx10,codemod10), no retries. After themainmerge and the concise pass,codemod.mjsandtsconfig.codemod.jsonwere rerun clean; Playwright was not rerun.pnpm sync,pnpm examples:catalog:check, andpnpm packages:inventorypass.tsrx, 0 compile errors and 378/488 Strong (it was 414 and 316/414 before every JSX module became TSRX, and 2 errors, both TS2300, before fix(octane): let a type-only import share a name with a value declaration #2265).template-textcasts 219 holes. Dot-directories such as.storybook/are no longer scanned, which removed 6 bulletproof-react files. A second run over a migrated copy of each app changes nothing. The per-app table is in the plan.react-hookspasses the harness's DOM checks and is faster than React on every op, but trails the hand-writtenoctane-tsrxtarget 1.2–169× and ships 65 kB gzip against its 37 kB.--strongfell back on three real blockers (an impure reducer andflushSync), andreact-classesreports its four classes. The numbers, the attribution runs, and the rule candidates are in the plan; nothing in the repo runs this benchmark yet. The slow keyed selection in the attribution run was a compiler gap withString()in rows, fixed in perf(octane): keep compiler fast paths through standard conversion calls #2268, not the reducer state.benchmarks/weather-app,benchmarks/chat-stream), migrated fromde97a8ad54and run through each harness againstoctane-tsrxand React: both pass every check and beat React. Three codemod defects they found are fixed here with tests: a.jsxentry kept JSX that Octane's Vite plugin does not compile (build failure); a key on every arm of a conditional row stayed on the arms (+12.8 kB, about 2× on streaming); finding lines pointed at neither file. Results and the compiler gaps they found are in the plan.20b0534e2bwere fixed in0adb0e902c, each with a test or script change, and the threads resolved: dynamicimport('react'), self-closing<Ctx.Provider />,"use strong"left after a"use client"prologue on fallback, andtest:e2e:devwithout a generatedcodemod/.perf-review: not applicable. Nothing touchespackages/octane/src, compiler output, or a binding hot path.concise-code: src +3,178 −1 (runtime +0 −0); the text-hole rule, its project program, and the defect fixes are +314 of that. The pass itself was +135 −212 inpackages/. It reused the CLI'sfindRoot/scanSourceFilesinstead of a second walker, shared the compiler finding helpers between the runner and the Strong pass, collapsed duplicated transform helpers, and counts CLI errors from one list. It also found and fixed a bug: a module that fails to compile in every mode was reported as a Strong blocker warning; it is now an error, with a regression test.packages/codemod(the package);examples/hacker-news/codemod.mjsandtsconfig.codemod.json(the lane);docs/octane-codemod-plan.md; two changesets.transformModule,runCodemod,strengthen, andloadCompiler(used by the tests and the lane); the CLI's./data,./fix,findRoot, andscanSourceFiles(used by the codemod).octane migratecommand inside@octanejs/cli(every CLI user would install TypeScript, and the request was a separate package); jscodeshift/recast (they can't print TSRX, and the TypeScript checker is needed for scope now and types in M2); reusing the CLI'sloadCompiler(the codemod needs a bundled-compiler fallback the CLI deliberately avoids; follow-up).Risk / follow-ups
.tsrxrejectedimport type { X }besidefunction Xwith TS2300, which caused both corpus compile errors. fix(octane): let a type-only import share a name with a value declaration #2265 fixed it in the parser, and this branch includes that fix after mergingmain. The codemod never renamed around it.@octanejs/codemodis listed inSOURCE_PUBLICATION_DEBTbeside@octanejs/clifornode-types-in-validation-tsconfiganduntyped-published-javascript. As a Node CLI it validates with Node's types and publishes.jswithout.d.ts. Source-publication rules: Node tooling packages validate with Node types and ship untyped JS #2266 tracks shipping declarations and scoping the Node-types rule for every Node tooling package.@octanejs/codemodhasoctaneas a regular dependency so it can check its output in a React project that has no Octane installed yet. It never runs inside an app, so there's no second runtime.template-textemits{String(n)}for numbers. Inside@forrows that is fast once perf(octane): keep compiler fast paths through standard conversion calls #2268 lands; in component bodies, only once perf(octane): keep compiler fast paths through standard conversion calls #2268's extension to them lands. Until then aString()call keeps that component off the compiler's fast paths, so perf(octane): keep compiler fast paths through standard conversion calls #2268 should merge first or alongside..tsrxwith// @ts-nocheck. Its tooling now treats it as TypeScript, but it is not type-checked, as before.@radix-ui/react-*) are reported, not migrated. Binding import adapters are workstream 4 in the plan.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.Note
Medium Risk
Automated source rewrites touch real app code and file renames; behavior is gated by compiler verification and new e2e, but the rule set is still a growing prototype with reported unmigrated APIs.
Overview
Introduces
@octanejs/codemod(octane-codemod), a migration tool that rewrites React + TSX/JSX to Octane + TSRX: import/binding substitution, template lowering (@{ … },@if/@for/@try),forwardRef, context, legacy roots, text-input handlers, and.tsrxrenames with import/HTML updates. Each changed module is compiled before write;--strongreuses compiler fixes (via shared@octanejs/cli/fix) and falls back to compatibility when Strong blockers remain.@octanejs/clinow exports the binding catalog (./data), analyze fix helpers (./fix),findRoot/scanSourceFiles, and skipsout/in scans so the codemod discovers sources like the CLI.The Hacker News example adds a
codemodlane (codemod.mjs, build/typecheck, Playwright on:5195/SSR:5197) so the same 10 journeys run on codemod output as on hand-written jsx/tsrx. Repo wiring includes vitestcodemodproject, typecheck config, fixture prettierignore, implementation plan doc, and changesets.Reviewed by Cursor Bugbot for commit de97a8a. Bugbot is set up for automated code reviews on this repo. Configure here.