@pumped-fn/codemod
v0.1.3
Published
Codemods for @pumped-fn packages
Maintainers
Readme
@pumped-fn/codemod
One-time migration tool from @pumped-fn/core-next to @pumped-fn/lite.
Transform Flow
graph TD
A[Source Files] --> B[jscodeshift]
B --> C{Transform Type}
C --> D[provide → atom]
C --> E[derive → atom with deps]
C --> F[executor.lazy/reactive → controller]
C --> G[Type Transforms]
D --> H[Transformed Files]
E --> H
F --> H
G --> H
H --> I[migration-report.md]
I --> J[Manual Review]Usage
# Run on current directory
npx @pumped-fn/codemod
# Run on specific path
npx @pumped-fn/codemod ./src
# Dry run (preview changes)
npx @pumped-fn/codemod --dry
# Verbose output
npx @pumped-fn/codemod --verboseWhat Gets Transformed
| Before | After |
|--------|-------|
| provide((ctl) => value) | atom({ factory: (ctx) => value }) |
| derive([a, b], fn) | atom({ deps: { a, b }, factory: fn }) |
| executor.lazy | controller(executor) |
| executor.reactive | controller(executor) |
| Core.Executor<T> | Lite.Atom<T> |
| ctl.release() | ctx.invalidate() |
| import { ... } from '@pumped-fn/core-next' | import { ... } from '@pumped-fn/lite' |
Migration Report
After running, check migration-report.md for:
- Summary statistics (files processed, transforms applied)
- Edge cases requiring manual review
- AI-friendly JSON for assisted migration
- Detailed breakdown of each transform type
After Running
# Review changes
git diff
# Update dependencies
npm uninstall @pumped-fn/core-next
npm install @pumped-fn/lite
# Fix remaining TypeScript errors
npm run typecheckEdge Cases
Some patterns cannot be auto-transformed:
Core.Static<T>- no equivalent in literesolves([...])- usePromise.allwithscope.resolve()- Dynamic accessor references - requires manual refactoring
- Spread in dependencies - convert to explicit object keys
- Complex executor patterns - may need manual review
These cases are flagged in migration-report.md with file locations for manual review.
CLI Options
Options:
--dry Preview changes without writing files
--verbose Show detailed transform information
--help Show help messageExamples
Basic Migration
Before:
import { provide, derive } from '@pumped-fn/core-next';
const user = provide(() => ({ name: 'Alice' }));
const name = derive([user], ([value]) => value.name);After:
import { atom } from '@pumped-fn/lite';
const user = atom({ factory: () => ({ name: 'Alice' }) });
const name = atom({
deps: { user },
factory: (_ctx, { user }) => user.name,
});Controller Migration
The codemod replaces .lazy and .reactive accessor references with controller(executor). It does not
turn an executor factory into a Lite flow. Review the generated controller call and define a flow manually
when the old code represented reusable execution:
import { flow, typed } from '@pumped-fn/lite';
const fetchUser = flow({
name: 'fetch-user',
parse: typed<{ id: string }>(),
deps: { http },
factory: (ctx, { http }) => http.get(`/api/users/${ctx.input.id}`),
});Troubleshooting
TypeScript errors after migration:
- Check
migration-report.mdfor edge cases - Review type transforms for
Core.Executor→Lite.Atom - Ensure
@pumped-fn/liteis installed
Transforms not applied:
- Verify file patterns match (
.ts,.tsxfiles) - Check for syntax errors in source files
- Use
--verboseto see transform details
Need to revert:
git checkout .Part of pumped-fn — start with the docs or the mental model.
