Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

inter-native-class-internal-codemod

22a4MIT2.0.1

Codemods for transforming ember app code to native class syntax with decorators.

codemod-cli

readme

inter-native-class-internal-codemod

Build Status npm version

A codemod for transforming your ember app code to native JavaScript class syntax with decorators!

Usage

First, install the dependencies that the codemod relies on. These are addons that the codemod will add imports from:

ember install ember-decorators 
# ember install ember-classic-decorator

Then, boot up your application. Then, the codemod can be run using the following command:

npx inter-native-class-internal-codemod http://localhost:4200/path/to/server [OPTIONS] path/of/files/ or/some**/*glob.js

The codemod accepts the following options:

Option Value Default Details
--class-fields boolean true Enable/disable transformation using class fields
--decorators boolean true Enable/disable transformation using decorators
--classic-decorator boolean false Enable/disable adding the @classic decorator, which helps with transitioning Ember Octane
--type String Empty (match all types in path) Apply transformation to only passed type. The type can be one of services, routes, components, controllers
--quote String 'single' 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.

Types

The 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 following:

Type Option
Services --type=services
Routes --type=routes
Components --type=components
Controllers --type=controllers

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.

Debugging

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.

Unsupported Types

While the codemods transforms many types of ember objects, it does not support transformation of

  • ember-data classes such as DS.Model, DS.Adapter etc
  • Mixins
  • Ember Objects with objects or arrays as direct properties (actions and queryParams are the exception). See eslint-plugin-ember/avoid-leaking-state-in-ember-objects for more details.
  • Ember objects with computed properties that use the meta or property modifiers.

More Transform Examples

Contributing

Installation

  • clone the repo
  • change into the repo directory
  • yarn

Running Tests

  • yarn test

Update Documentation

  • yarn update-docs

changelog

v1.1.0 (2019-08-20)

:rocket: Enhancement

  • #177 Fixup class naming logic and make it work with pods (@pzuraq)
  • #176 Removes @className and @attribute in favor of @classNameBindings and @attributeBindings (@pzuraq)

:bug: Bug Fix

:memo: Documentation

:house: Internal

  • #180 Adds tests for reopening classes (@pzuraq)
  • #173 Swap out the telemetry helpers for the ember-codemods-telemetry-helpers package (@NullVoxPopuli)
  • #143 Add test for using ember-concurrency tasks in converted objects. (@rwjblue)
  • #151 Fixup typo in method name closet -> closest. (@rwjblue)

Committers: 7

v1.0.1 (2019-06-23)

:bug: Bug Fix

  • #140 Avoid **/tmp/** when looking for package.json's. (@rwjblue)

:memo: Documentation

  • #137 Add dependency installation to the README (@pzuraq)
  • #136 Update the README to match v1.0.0 refactors (@pzuraq)

Committers: 3

v1.0.0 (2019-06-20)

:boom: Breaking Change

:rocket: Enhancement

  • #132 Adds the classicDecorator option and enable it by default (@pzuraq)

:bug: Bug Fix

  • #129 Fix issues identifying in-repo addon paths in getTelemetryFor. (@rwjblue)
  • #130 Ensure logging of modules that failed to gather telemetry. (@rwjblue)
  • #126 Wait for telemetry before starting transforms (@pzuraq)

:house: Internal

  • #131 Fix in-repo addon acceptance test to demonstrate real world failure with in-repo addons. (@rwjblue)
  • #133 Convert to single quotes in Prettier configuration (@pzuraq)
  • #128 Add in-repo addon to acceptance test. (@rwjblue)
  • #127 Split apart and add unit tests for getTelemetryFor. (@rwjblue)

Committers: 2

v0.2.1 (2019-06-19)

:bug: Bug Fix

  • #125 Handle module failures gracefully while gathering telemetry. (@rwjblue)
  • #124 Add puppeteer launch flag to ignore https errors (@ssutar)

:memo: Documentation

Committers: 2

v0.2.0 (2019-06-18)

:boom: Breaking Change

  • #118 [FEATURE] Replace dyfactor with puppeteer (@pzuraq)

:rocket: Enhancement

  • #118 [FEATURE] Replace dyfactor with puppeteer (@pzuraq)
  • #112 Update to use official decorators from Ember as much as possible (@ssutar)
  • #89 Import @service and @controller from @ember packages (@ssutar)

:bug: Bug Fix

  • #116 Merge imports from the same module (@ssutar)
  • #94 Add automatic detection of an infinite @action loop (@ssutar)

:memo: Documentation

:house: Internal

  • #122 Add automated release setup and documentation. (@rwjblue)

Committers: 4