Run jscodeshift on scripts contained in Svelte components, Vue components, and more. Supports both esmodule and commonjs projects. Additional adapter contributions are welcome!
npm install jscodeshift-adapters -D
The instructions below assume you're familiar with jscodeshift.
.js
, .ts
, .vue
, .svelte
, and/or .html
filesWhen 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.
// my-transform.js
import adapt from "jscodeshift-adapters";
import someCodemod from "some-codemod";
export default adapt(someCodemod);
$ 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.
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.
MIT