First, install the dependencies that the codemod relies on. These are addons that the codemod will add imports from:
ember install ember-classic-decorator ember install ember-decorators
Then, boot up your application. Then, the codemod can be run using the following command:
npx ember-native-class-codemod http://localhost:4200/path/to/server [OPTIONS] path/of/files/ or/some**/*glob.js
The codemod accepts the following options:
||Enable/disable transformation using class fields|
||Enable/disable transformation using decorators|
||Enable/disable adding the
||String||Empty (match all types in path)||Apply transformation to only passed type. The type can be one of
||Whether to use double or single quotes by default for new statements that are added during the codemod.|
Gathering Runtime Data
The first argument that you must pass to the codemod is the URL of a running instance of your application. The codemod opens up your application and analyzes the classes directly, so it can transform them, which is why it needs this URL. Any classes that were not analyzed will not be transformed. This includes classes that are private to a module and never exported.
If you have any lazily loaded modules, such as modules from Ember Engines, you'll need to make sure that the URL you provide loads these modules as well. Otherwise, the codemod will not be able to detect them or analyze them.
type option can be used to further narrow down transforms to a particular type of
ember object within the application or addon. The types can be any of the
The path of the file being transformed is matched against the glob pattern of the type to determine whether to run the specific transforms.
If a type is not provided, the codemods will run against all the types in the path provided.
The codemods log execution information in the
codemods.log file in the current
directory where the codemods are being executed. Specifically, details such as
failures and reasons for failures, are logged. This would be the recommended
starting point for debugging issues related to these codemods.
While the codemods transforms many types of ember objects, it does not support transformation of
ember-dataclasses such as
- Ember Objects with objects or arrays as direct properties (
queryParamsare the exception). See eslint-plugin-ember/avoid-leaking-state-in-ember-objects for more details.
- Ember objects with computed properties that use the
More Transform Examples
- clone the repo
- change into the repo directory