This page covers creation of stand-alone Hypermod packages and is for authors who want:
- Control over where and how your Hypermod package is hosted
- Control over tooling, dependencies and techstack
- The option to create completely generic codemods that don't target specific packages
If you prefer to not to maintain a separate package, please see the Authoring guide for other options.
To create a standalone Hypermod package automatically, install the install and use the
npm install -g @hypermod/clior
yarn global add @hypermod/cli
Then given you want to initialize a new project called "foobar", with a codemod targeting version
10.0.0 you can run the following command:
$ hypermod init --package-name="foobar" --version="10.0.0" ~/Desktop
This will create a new directory called "foobar" in the
You can then also initialize subsequent transforms and presets by running the command again:
$ hypermod init --package-name="foobar" --preset="sort-imports" ~/Desktop
The file structure of your new hypermod package will look like this:
hypermod.config.js // main entrypoint containing configuration and references to your transforms
10.0.0/ // semver version
transform.ts // main logic (should contain a transformer)
transform.spec.ts // main tests
motions/ // utility directory
Now to test your transformer, run
yarn test --watch.
See the Testing guide for help getting started with unit tests.
Since your new hypermod package can simply be treated as an NPM package you can simply run
npm version [patch\minor\major] and
Your package will now be accessible via the
hypermod/cli. Refer to the Consuming guide for information about how to run your new codemods.
Here are some helpful example of this setup working in the wild: