ember-codemods / ember-native-class-codemod

A codemod-cli project for converting Ember objects to es6 native classes
67 stars 38 forks source link

Ember Data not working correctly #62

Open pzuraq opened 5 years ago

pzuraq commented 5 years ago

The following file did not transform, and all of the properties seemed to trigger errors:

import { computed } from '@ember/object';
import { gt } from '@ember/object/computed';
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { hasMany, belongsTo } from 'ember-data/relationships';
import moment from 'moment';

export default Model.extend({
  isAddon: true,
  name: attr('string'),
  description: attr('string'),
  repositoryUrl: attr('string'),
  latestVersionDate: attr('date'),
  publishedDate: attr('date'),
  license: attr('string'),
  isDeprecated: attr('boolean'),
  note: attr('string'),
  isOfficial: attr('boolean'),
  isCliDependency: attr('boolean'),
  isHidden: attr('boolean'),
  hasInvalidGithubRepo: attr('boolean'),
  score: attr('number'),
  ranking: attr('number'),
  githubUsers: hasMany('github-user'),
  lastMonthDownloads: attr('number'),
  isWip: attr('boolean'),
  isTopDownloaded: attr('boolean'),
  isTopStarred: attr('boolean'),
  demoUrl: attr('string'),
  updatedAt: attr('date'),
  githubStats: belongsTo('github-stats', { async: true }),
  latestAddonVersion: belongsTo('version', { async: true }),
  latestReview: belongsTo('review', { async: true }),
  categories: hasMany('category', { async: true }),
  keywords: hasMany('keyword', { async: true }),
  versions: hasMany('version', { async: true }),
  maintainers: hasMany('maintainer', { async: true }),
  readme: belongsTo('readme', { async: true }),
  hasMoreThan1Contributor: gt('githubUsers.length', 1),
  npmUrl: computed('name', function() {
    return `https://www.npmjs.com/package/${this.get('name')}`;
  }),
  isNewAddon: computed('publishedDate', function() {
    return moment(this.get('publishedDate')).isAfter(moment().subtract(2, 'weeks'));
  })
});
ssutar commented 5 years ago

What are the errors? Ideally it should skip the file because the codmods do not handle ember-data https://github.com/ember-codemods/ember-es6-class-codemod#unsupported-types

pzuraq commented 5 years ago

Right, the codemod should handle Ember Data since we have decorators for model attributes and relationships.

ssutar commented 5 years ago

Yes, but I think thats the decision we took before starting. I think a new codemod ember-data should be created under ember-es6-class-codemod to handle the model attributes and relationships

pzuraq commented 5 years ago

I think #72 may help give some context here, we can now wrap all non-standard macros so we can transform classes we previously could not. In the future, this won't even be necessary - once https://github.com/emberjs/ember.js/pull/17548 lands and decorators are supported in Ember itself, all current computed property macros will be decorators, so we can remove any wrapComputed calls.

In the meantime though, it is probably not ideal to have ember-data macros be wrapped each time, so I think we should add them to the transform.

maxwondercorn commented 4 years ago

I see that Models are being converted in the current version but the attr transforms and options are removed from the decorators.

Never mind, I was using ember-es6-class-codemod. This works correctly in ember-native-class-codemod.

I think It is confusing when there are two different codemods that do effectively the same thing. One should be marked as deprecated.

Thanks for the great work on this