1.0.2 • Published 11 months ago

jscodeshift-adapters v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

jscodeshift-adapters

Run jscodeshift on scripts contained in Svelte components, Vue components, and more. Supports both esmodule and commonjs projects. Additional adapter contributions are welcome!

Install

npm install jscodeshift-adapters -D

Usage

The instructions below assume you're familiar with jscodeshift.

Run a codemod on some .js, .ts, .vue, .svelte, and/or .html files

When transformingfileInfo.source will be
.jsthe contents of the file
.tsthe contents of the file
.vuethe contents of <script>
.sveltethe contents of <script>
.htmlthe contents of <script>

The source file will be updated appropriately based on the return value of your transform().

For files that do not have an appropriate script source (such as a <script> tag), your codemod will not be called and the source file will not be changed.

1. Create wrapped transform function

// my-transform.js
import adapt from "jscodeshift-adapters";
import someCodemod from "some-codemod";

export default adapt(someCodemod);

2. Run jscodeshift

$ jscodeshift <path> -t my-transform.js --extensions js,ts,html,svelte,vue --parser tsx

See jscodeshift readme for more info on jscodeshift CLI. Note that you must use the tsx parser or another parser that supports typescript for handling files which use typescript syntax.

Acknowledgements

Heavily inspired by Paul Salaets's vue-jscodeshift-adapter, copied and modified to support asynchronous transform functions and running in commonjs contexts.

@knighted/duel for dual commonjs and esm build target support.

License

MIT

1.0.2

11 months ago

1.0.1

11 months ago

1.0.1-beta.3

11 months ago

1.0.1-beta.2

11 months ago

1.0.1-beta.1

11 months ago

1.0.0

12 months ago

1.0.0-beta.8

12 months ago

1.0.0-beta.7

12 months ago

1.0.0-beta.6

12 months ago

1.0.0-beta.5

12 months ago

1.0.0-beta.4

12 months ago

1.0.0-beta.3

12 months ago

1.0.0-beta.2

12 months ago

1.0.0-beta.1

12 months ago

1.0.0-beta.0

12 months ago