Giter VIP home page Giter VIP logo

relay-codemod's Introduction

relay-codemod Build Status

This repository contains a collection of codemod scripts based for use with JSCodeshift that help update Relay APIs.

Setup & run

  • npm install -g jscodeshift
  • git clone https://github.com/relayjs/relay-codemod.git or download a zip file from https://github.com/relayjs/relay-codemod/archive/master.zip
  • jscodeshift -t <codemod-script> <file>
  • Use the -d option for a dry-run and use -p to print the output for comparison

Included scripts

upgrade-store-api-0.8

jscodeshift -t relay-codemod/transforms/upgrade-store-api-0.8.js <file>

Updates method calls on Relay.Store that were removed in Relay 0.8.0:

  • Relay.Store.update => Relay.Store.commitUpdate

upgrade-requires-1.0

jscodeshift -t relay-codemod/transforms/upgrade-requires-1.0.js <file>

Replaces requires to /classic for upgrading to 1.0.0:

  • require('react-relay') => require('react-relay/classic')
  • from 'react-relay' => from 'react-relay/classic'

migrate-to-modern-1.0

jscodeshift -t relay-codemod/transforms/migrate-to-modern-1.0.js <file>

Attempts (in a crude way) to migrate classic APIs to modern ones.

Caveats for initial version:

  • Only translates fragment containers
  • Only works if react-relay is imported/requried as "Relay"
  • Assumes object spread operator is ok to use

Recast options

Options to recast's printer can be provided through the printOptions command line argument

  • jscodeshift -t transform.js <file> --printOptions='{"quote":"double"}'

relay-codemod's People

Contributors

robrichard avatar steveluscher avatar wincent avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

relay-codemod's Issues

Doesn't work with `import` instead of `require`

Running jscodeshift -t relay-codemod/transforms/migrate-to-modern-1.0.js <file> only works if file uses require to import Relay:

var Relay = require('react-relay/classic');

It doesn't work with import:

import Relay from 'react-relay/classic'

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.