jscodeshift-adapters
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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 transforming fileInfo.source will be
.js the contents of the file
.ts the contents of the file
.vue the contents of <script>
.svelte the contents of <script>
.html the 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

Readme

Keywords

none

Package Sidebar

Install

npm i jscodeshift-adapters

Weekly Downloads

393

Version

1.0.2

License

MIT

Unpacked Size

26.3 kB

Total Files

27

Last publish

Collaborators

  • fnimick