@wigxel/react-tf-oxc
v0.1.16
Published
Transform React function components from arrow functions to function declarations
Downloads
1,540
Readme
@wigxel/react-tf-oxc
A CLI tool that transforms React codebase to the Wigxel coding standards, powered by oxc-parser (Rust-based).
Requires Node.js >= 22.
Features
- Arrow Function → Function Declaration: Automatically converts arrow function components to function declarations
- Inline Type Extraction: Extracts inline type literals to named type aliases (e.g.,
{ name: string }→ComponentProps) - Named Type Destructuring: Moves destructuring to function body for components with ≥3 props or default values
- Rest Element Handling: Renames
...propsto...restPropsto avoid naming conflicts - Gitignore-Aware Filtering: Respects
.gitignorefiles when scanning for files - Content-Hash Caching: Skips unchanged files for faster re-runs
- Parallel Processing: Uses worker threads for multi-core performance
- Debug Mode: Real-time logging with color-coded timing
Usage
# Basic usage (current directory)
oxc-nurm
# Scan specific directory
oxc-nurm ./src
# Scan multiple directories
oxc-nurm app components lib
# With debug logging
oxc-nurm ./src --debug
# Force reprocess (ignore cache)
oxc-nurm ./src --force
# Specify number of workers
oxc-nurm ./src --workers 8Options
| Option | Alias | Description | Default |
| ------------- | ----- | -------------------------------- | ------- |
| --directory | - | Directories to scan (repeatable) | . |
| --debug | -d | Enable debug logging | false |
| --workers | -w | Number of worker threads | 4 |
| --force | -f | Force reprocess (ignore cache) | false |
Transformations
Arrow Function with Inline Type
Before:
const Box = ({ boxes, count }: { boxes: number; count: string }) => {
return (
<div>
{boxes} - {count}
</div>
);
};After:
type BoxProps = {
boxes: number;
count: string;
};
function Box(props: BoxProps) {
const { boxes, count } = props;
return (
<div>
{boxes} - {count}
</div>
);
}Function Declaration with Named Type (≥3 Props)
Before:
function Avatar({ size = 80, disabled, className, ...props }: AvatarProps) {
return <div {...props} className={className} />;
}After:
function Avatar(props: AvatarProps) {
const { size = 80, disabled, className, ...restProps } = props;
return <div {...restProps} className={className} />;
}How It Works
- Scanning: Recursively scans the target directory for
.tsxfiles, respecting.gitignorerules - Caching: Checks content-hash cache to skip unchanged files
- Parallel Processing: Distributes files across worker threads
- AST Transformation: Uses
oxc-parserto parse and transform the AST - Output: Writes transformed files back to disk
Cache
The tool uses content-hash caching stored in node_modules/.cache/react-component-transformer/transformer-cache.fsh at the project root. It automatically skips unchanged files between runs.
To force reprocessing of all files, use the --force flag.
Development
# Install dependencies
pnpm install
# Run tests
pnpm test
# Build the CLI
pnpm build
# Run demo
pnpm demoLicense
MIT
