@luna-oss/codemod
v5.0.0
Published
Moon's component library migration tool
Downloads
68
Readme
@luna-oss/codemod
Moon Design System codemods and CLI tools for automating migrations and transformations.
The @luna-oss/codemod package automates upgrades between major versions of the Moon design system and its component packages. The runner discovers transformations from transformations/<migration> and runs them via jscodeshift.
Usage
npx @luna-oss/codemod [options]When invoked without --migration, an interactive wizard prompts you to select a migration and the file extensions to scan.
Options
| Flag | Alias | Description | Default |
| --- | --- | --- | --- |
| --migration <name> | -m | Migration to run. Discovered from transformations/. | (prompted) |
| --target <dir> | -t | Directory to apply transformations to. | process.cwd() |
| --extensions <list> | -x | File extensions to include (jsx, tsx, js, ts). | jsx tsx |
| --verbose | -v | Stream detailed jscodeshift output to codemod.log. | false |
| --yes | -y | Skip confirmation when the Git working tree is dirty. | false |
Authoring transformations
Transformations live under transformations/<migration>/<name>.ts and are compiled to .js for runtime use. Each transformation exports a default function wrapped with wrap from src/utils:
import { wrap, renameImportPath } from "@luna-oss/codemod/src/utils";
import { TransformationContext } from "@luna-oss/codemod/types";
import { ImportDeclaration } from "jscodeshift";
export default wrap(({ root }: TransformationContext) => {
root.find(ImportDeclaration).forEach(p => {
/* ... */
});
});Tests for transformations should live next to them in __tests__/ and use jscodeshift's test utilities.
Status
Moon V5 ships with no built-in legacy migrations because Moon V5 is the first public release of @luna-oss/*. New migrations will be added here for future major versions. The CLI auto-discovers any folder under transformations/, so adding a migration is just a matter of dropping a folder of jscodeshift transforms into place.
