Giter Site home page Giter Site logo

ember-data-codemod's Introduction

Ember Data Codemod

A collection of codemods for ember-data. For now, it only contains a codemod to upgrade to the new "@ember-data" packages!

Usage

To run a specific codemod from this project, you would run the following:

npx ember-data-codemod <TRANSFORM NAME> path/of/files/ or/some**/*glob.js

# or

yarn global add ember-data-codemod
ember-data-codemod <TRANSFORM NAME> path/of/files/ or/some**/*glob.js

To run every codemod from this project, you would run the following:

npx ember-data-codemod . path/of/files/ or/some**/*glob.js

# or

yarn global add ember-data-codemod
ember-data-codemod . path/of/files/ or/some**/*glob.js

Transforms

Contributing

Installation

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

Running tests

  • yarn test

Update Documentation

  • yarn update-docs

Credits

This repository is intially a fork of ember-modules-codemod adapted for the needs of ember-data. This PR illustrates the work needed to adapt ember-modules-codemod to fit ember-data needs.

This codemod uses jscodeshift

Links

ember-data-codemod's People

Contributors

alonski avatar bmish avatar dcyriller avatar dependabot-preview[bot] avatar dependabot[bot] avatar runspired avatar snewcomer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ember-data-codemod's Issues

Processes many files in node_modules

This is followup to ember-cli/ember-cli-update-codemods-manifest#59.

Here are reproduction instructions.

  1. Checkout https://github.com/ember-animation/ember-animated at commit 4792f0ab48d0397900fbad1252f7aa5f1d2b93cf
  2. yarn install
  3. npx ember-data-codemod . "tests/dummy/app/**/*.js"

What I see:

npx: installed 304 in 8.757s
Processing 19378 files...
Spawning 7 workers...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
 ERR node_modules/charenc/README.js Transformation error (Unexpected token (1:0))
SyntaxError: Unexpected token (1:0)
    at Object.raise (/Users/edward/.npm/_npx/15090/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/location.js:41:63)
    at Object.unexpected (/Users/edward/.npm/_npx/15090/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/util.js:160:16)
    at Object.parseExprAtom (/Users/edward/.npm/_npx/15090/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/expression.js:1117:20)
    at Object.parseExprAtom (/Users/edward/.npm/_npx/15090/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/plugins/estree.js:279:24)
    at Object.parseExprAtom (/Users/edward/.npm/_npx/15090/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/plugins/jsx/index.js:527:22)
    at Object.parseExprSubscripts (/Users/edward/.npm/_npx/15090/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/expression.js:527:23)
    at Object.parseMaybeUnary (/Users/edward/.npm/_npx/15090/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/expression.js:507:21)
    at Object.parseExprOps (/Users/edward/.npm/_npx/15090/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/expression.js:275:23)
    at Object.parseMaybeConditional (/Users/edward/.npm/_npx/15090/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/expression.js:230:23)
    at Object.parseMaybeAssign (/Users/edward/.npm/_npx/15090/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/expression.js:180:21)
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...
Sending 50 files to free worker...

There are not 19,000 files in the actual project. And the first reported error is for a file inside node_modules that should not have been processed. This leads me to believe that the codemod is incorrectly processing all files under node_modules.

Migrate to `ember-codemods` org?

I’ve slowly been moving the general community codemods that I’ve made into the ember-codemods GitHub org, and inviting others to join me over in that org. Mostly as a way to:

  • increase visibility
  • reduce bus factor
  • reduce overall work load (many other codemodders make light work of the overall maintenance)

We’d make sure to preserve the current permissions (e.g. no reduction in control) if we did the transition.

Would this be something y’all would be open to?

Leave { Serializer } imported from ember-cli-mirage as it is

If you happen to run globals-to-ember-data-imports transform on the whole project and you have a serializer for ember-cli-mirage like an application serializer for example (/mirage/serializers/application.js) then you'll see unwanted change:

- import { Serializer } from 'ember-cli-mirage';
+ import Serializer from '@ember-data/serializer';

The transform should leave this line as it is. Because, in this case, it is expected to import { Serializer } from 3rd party addon.

Workaround:
Don't run the transform against the whole project directory. Run in against specific directories.

Throws when used on TS files with decorators

Hi, thanks for this great codemod.

I found that it throws when used in a app/addon that's using typescript with data decorators.

Reproduction repo: https://github.com/makepanic/ember-data-codemod-issue

Steps to reproduce:

  • clone the repo
  • yarn
  • npx ember-data-codemod . app/models/

Resulting output:

npx: installed 415 in 22.722s
Processing 1 files...
Spawning 1 workers...
Sending 1 files to free worker...
 ERR app/models/foo.ts Transformation error (This experimental syntax requires enabling one of the following parser plugin(s): 'decorators-legacy, decorators' (4:2))
SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): 'decorators-legacy, decorators' (4:2)
    at Object.raise (/user/.npm/_npx/6685/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/location.js:41:63)
    at Object.expectOnePlugin (/user/.npm/_npx/6685/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/util.js:167:18)
    at Object.parseDecorator (/user/.npm/_npx/6685/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/statement.js:368:10)
    at callback (/user/.npm/_npx/6685/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/statement.js:1205:32)
    at Object.withTopicForbiddingContext (/user/.npm/_npx/6685/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/expression.js:2441:14)
    at Object.parseClassBody (/user/.npm/_npx/6685/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/statement.js:1192:10)
    at Object.parseClass (/user/.npm/_npx/6685/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/statement.js:1152:22)
    at Object.parseExportDefaultExpression (/user/.npm/_npx/6685/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/statement.js:1804:19)
    at Object.parseExport (/user/.npm/_npx/6685/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/statement.js:1699:31)
    at Object.parseStatementContent (/user/.npm/_npx/6685/lib/node_modules/ember-data-codemod/node_modules/@babel/parser/src/parser/statement.js:257:25)
All done.
Results:
1 errors
0 unmodified
0 skipped
0 ok
Time elapsed: 1.377seconds

Support `import myAttr from "ember-data/attr"`

Whereas import attr from "ember-data/attr" is supported, import myAttr from "ember-data/attr" is not (yet). It will be ignored by the codemod.

updateExistingLiteralPaths function should be updated to support it.

Note that aliased named import are supported: import { hasMany as many } from "ember-data/relationships" is properly turned into import { hasMany as many } from "@ember-data/model".

Related discussion: #21 (comment)

Migrate to codemod-cli?

Should make some of the overall code structure and testing infrastructure a bit easier.

Migrating might not be very useful since this is already largely "done"...

Codemod for RFC 0739 (Deprecate Non Strict Relationships)?

This RFC stated that:

A codemod should be provided. This codemod would analyze a user's relationships and wherever possible format the provided options with the now deprecated missing information. Note: For the related type and inverse property name when mixin-based polymorphism is present codemods may not be practical.

That doesn't seem to have happened.

Will this ever happen?

Leave RESTAdapter imported from ds-improved-ajax as it is

globals-to-ember-data-imports transform converts imports made for RESTAdapter from ds-improved-ajax/adapters/rest package into @ember-data/adapter/rest.

Git diff, after applying the transform:

- import RESTAdapter from 'ds-improved-ajax/adapters/rest';
+ import RESTAdapter from '@ember-data/adapter/rest';

The transform should leave this line as it is. Because, in this case, it is expected to import RESTAdapter from 3rd party addon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.