Skip to content

albertywu/flowshift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flowshift

Flowshift is a toolkit for for transforming flow to typescript using jscodeshift.

Each plugin is a jscodeshift-style transform, which makes codemods easy to test in isolation. See here for a sample plugin and its associated test file.

Todo

  • exact types removal
  • covariance notation + -> readonly
  • generics
    • basics
    • bounded polymorphism
  • maybe types
  • imports remove type
  • type casting
  • typeof imports
  • $Enum -> keyof X
  • $Record
  • type-narrowing functions (%checks)
  • flag unfix-able with a comment
  • release
    • generate a manifest file that maps flow file -> replacements
    • docs

Run a Plugin

# 1) install jscodeshift
yarn global add jscodeshift

# 2) run a plugin on a flow file
jscodeshift --parser=flow -t <path-to-plugin-file> <flow file>

# 3) flow file is now modified per plugin!

Plugins

Plugins use jscodeshift to transform flow source code into typescript source code. Plugins are stored in the plugins folder with their associated test fixtures.

A plugin is simply a transform function as defined below. If the function returns a string, then the file is written with the value of the returned string. If the return value is undefined, nothing happens to the original file.

Plugin functions are invoked by the cli command jscodeshift.

function transform(fileInfo: FileInfo, api: Api, options: Options): string | undefined {
  // transform code goes here
}

type FileInfo = {
  path: string;   // file path
  source: string; // source code
}

type Api = {
  jscodeshift: JsCodeShift; // the main library for flow AST stuff
  ... // other stuff we don't care about
}

type Options = {
  [key: string]: string // passed in via CLI command `jscodeshift`
}

Test

yarn test

Install

yarn

Contribute

Releases

No releases published

Packages

No packages published