|
| 1 | +<h1 align="center">@crimson_dev/command-codemod</h1> |
| 2 | + |
| 3 | +<p align="center"> |
| 4 | + <strong>Automated migration from <code>cmdk</code> to <code>@crimson_dev/command-react</code></strong> |
| 5 | +</p> |
| 6 | + |
| 7 | +<p align="center"> |
| 8 | + <a href="https://www.npmjs.com/package/@crimson_dev/command-codemod"><img src="https://img.shields.io/npm/v/@crimson_dev/command-codemod?style=flat-square&color=crimson" alt="npm" /></a> |
| 9 | + <a href="https://github.com/ABCrimson/modern-cmdk/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@crimson_dev/command-codemod?style=flat-square" alt="license" /></a> |
| 10 | +</p> |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## What is this? |
| 15 | + |
| 16 | +A set of jscodeshift transforms that automatically migrate your codebase from `cmdk` (pacocoursey/cmdk) to `@crimson_dev/command-react`. Handles import rewrites, API changes, and data attribute renames. |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +Run all transforms at once: |
| 21 | + |
| 22 | +```bash |
| 23 | +npx @crimson_dev/command-codemod ./src |
| 24 | +``` |
| 25 | + |
| 26 | +Or run individual transforms: |
| 27 | + |
| 28 | +```bash |
| 29 | +npx @crimson_dev/command-codemod --transform import-rewrite ./src |
| 30 | +npx @crimson_dev/command-codemod --transform forward-ref ./src |
| 31 | +npx @crimson_dev/command-codemod --transform data-attrs ./src |
| 32 | +npx @crimson_dev/command-codemod --transform should-filter ./src |
| 33 | +``` |
| 34 | + |
| 35 | +### Options |
| 36 | + |
| 37 | +| Flag | Description | |
| 38 | +|------|-------------| |
| 39 | +| `--transform <name>` | Run a specific transform (default: all) | |
| 40 | +| `--dry-run` | Preview changes without writing files | |
| 41 | +| `--concurrency <n>` | Number of files to process in parallel (default: CPU count) | |
| 42 | + |
| 43 | +## Transforms |
| 44 | + |
| 45 | +### `import-rewrite` |
| 46 | + |
| 47 | +Rewrites `cmdk` imports to `@crimson_dev/command-react`: |
| 48 | + |
| 49 | +```diff |
| 50 | +- import { Command } from 'cmdk'; |
| 51 | ++ import { Command } from '@crimson_dev/command-react'; |
| 52 | +``` |
| 53 | + |
| 54 | +### `forward-ref` |
| 55 | + |
| 56 | +Removes `forwardRef` wrappers — React 19 passes `ref` as a regular prop: |
| 57 | + |
| 58 | +```diff |
| 59 | +- const MyCommand = forwardRef<HTMLDivElement, Props>((props, ref) => ( |
| 60 | +- <Command ref={ref} {...props} /> |
| 61 | +- )); |
| 62 | ++ function MyCommand({ ref, ...props }: Props & { ref?: Ref<HTMLDivElement> }) { |
| 63 | ++ return <Command ref={ref} {...props} />; |
| 64 | ++ } |
| 65 | +``` |
| 66 | + |
| 67 | +### `data-attrs` |
| 68 | + |
| 69 | +Updates data attribute selectors to the new naming convention: |
| 70 | + |
| 71 | +```diff |
| 72 | +- [cmdk-root] { ... } |
| 73 | ++ [data-command-root] { ... } |
| 74 | + |
| 75 | +- [cmdk-item][aria-selected="true"] { ... } |
| 76 | ++ [data-command-item][data-active] { ... } |
| 77 | +``` |
| 78 | + |
| 79 | +### `should-filter` |
| 80 | + |
| 81 | +Migrates the `shouldFilter` prop to the new `filter` prop: |
| 82 | + |
| 83 | +```diff |
| 84 | +- <Command shouldFilter={false}> |
| 85 | ++ <Command filter={false}> |
| 86 | +``` |
| 87 | + |
| 88 | +## Dry Run |
| 89 | + |
| 90 | +Always preview first: |
| 91 | + |
| 92 | +```bash |
| 93 | +npx @crimson_dev/command-codemod --dry-run ./src |
| 94 | +``` |
| 95 | + |
| 96 | +Output shows each file with planned changes, without modifying anything. |
| 97 | + |
| 98 | +## Requirements |
| 99 | + |
| 100 | +- Node.js >= 25.8.0 |
| 101 | +- Files must be valid TypeScript/JavaScript (`.ts`, `.tsx`, `.js`, `.jsx`) |
| 102 | + |
| 103 | +## Links |
| 104 | + |
| 105 | +- [Migration Guide](https://github.com/ABCrimson/modern-cmdk) |
| 106 | +- [React Adapter](https://www.npmjs.com/package/@crimson_dev/command-react) |
| 107 | + |
| 108 | +## License |
| 109 | + |
| 110 | +MIT |
0 commit comments