vue-jscodeshift-adapter is a utility library designed to bridge jscodeshift, Facebook's JavaScript codemod toolkit, with Vue.js Single File Components (SFCs). It enables developers to apply programmatic code transformations specifically to the `<script>` sections within `.vue` files, which jscodeshift does not natively support. The current stable version is 3.0.0. This package was an early solution in the Vue codemod space, heavily inspiring the 'jscodeshift-adapters' project. While jscodeshift itself receives regular updates, vue-jscodeshift-adapter appears to be in a maintenance-only state with its last release over two years ago. Its primary differentiator is its targeted extraction and re-insertion of Vue SFC script content, allowing standard jscodeshift transforms to operate on Vue-specific logic, distinguishing it from general jscodeshift usage or other Vue migration tools like 'vue-codemod' that offer pre-built transformations.
npm install vue-jscodeshift-adapterVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a jscodeshift transform, adapt it for Vue SFCs using vue-jscodeshift-adapter, and execute it via the jscodeshift CLI to modify 'var' declarations to 'let' and add comments to script blocks.
Ensure all `.vue` files you intend to transform include a `<script>` block, even an empty one (`<script></script>`), if you expect the codemod to run.
Thoroughly test transformations on a small subset of your codebase before applying broadly. Consider using the more broadly supported 'jscodeshift-adapters' (which was inspired by this project) or other Vue-specific codemod collections like 'vue-codemod' for Vue 2/3 migrations, which may have more active maintenance.
Ensure your `vue-template-compiler` version matches your installed `vue` package version. If using `vue-loader >= 10.0`, manually update `vue-template-compiler`. If issues persist, check your dependency tree for conflicting `vue-template-compiler` versions and use `resolutions` or `overrides` in your `package.json` to force a consistent version.
Explicitly install `vue-template-compiler` as a dev dependency with the exact same version as your `vue` package: `npm install vue-template-compiler@<YOUR_VUE_VERSION> --save-dev`.
Ensure your `myCodemod` function (passed to `adapt`) ends with `return root.toSource();`.
You do not need to specify a 'vue' parser. Ensure you are using the `--extensions vue,js` flag correctly with jscodeshift to tell it which file types to process. If you need a specific JavaScript/TypeScript parser for the *script content*, specify it via `--parser=tsx` or `--parser=babel` etc.