Registry / web-framework / vue-codemod

vue-codemod

JSON →
library0.0.5jsnpmunverified

vue-codemod is an experimental utility providing a collection of codemod scripts to assist developers in updating Vue.js APIs, primarily for migrating applications from Vue 2 to Vue 3. It leverages Facebook's JSCodeshift for abstract syntax tree (AST) transformations and offers specific support for `.vue` single-file components. As of version `0.0.5`, it includes transformations like `remove-vue-set-and-delete` and outlines a roadmap for further features, including TypeScript support and broader module system compatibility. Maintained by the Vue.js team, its "experimental" status and low version number indicate a development cadence focused on feature completion rather than rapid, frequent releases, positioning it as a tool for early adopters or those undertaking significant migrations. Its key differentiators include official Vue team backing and direct support for `.vue` file transformations, which are critical for comprehensive Vue application upgrades.

npm install vue-codemod
INSTALL
IMPORT
SIG · VUE-CODEMOD
V
vue-codemod
web-frameworkjavascriptv0.0.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

runTransformation
import { runTransformation } from 'vue-codemod'
const { runTransformation } = require('vue-codemod')
Primarily a CLI tool, but exposes a programmatic API. Ensure your project is configured for ESM if importing directly into modern Node.js environments.
CLI Usage (npx)
npx vue-codemod <path> -t <transformation> --params [transformation params]
The most common usage pattern is via the command line using `npx` or a globally installed package. No direct import is required for CLI execution.
Specific Codemod (e.g., remove-vue-set-and-delete)
npx vue-codemod ./src -t remove-vue-set-and-delete
To apply a specific built-in codemod, use the `-t` flag with its name. Replace `./src` with your target files or directory.

Demonstrates the programmatic usage of `vue-codemod` by applying a simple, custom transformation to a temporary file. This illustrates how to interface with `runTransformation` directly, though CLI usage is more common.

import { runTransformation } from 'vue-codemod'; import path from 'path'; import fs from 'fs'; import os from 'os'; // Create a temporary directory and file for the quickstart to operate on const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'vue-codemod-quickstart-')); const filePath = path.join(tempDir, 'main.js'); const originalCode = 'import Vue from "vue";\nnew Vue().mount("#app");\nconsole.log("Hello Vue");'; fs.writeFileSync(filePath, originalCode, 'utf8'); const fileInfo = { path: filePath, source: fs.readFileSync(filePath, 'utf8') }; // This dummy transformation replaces 'Vue' with 'App' for demonstration. // In a real scenario, the 'transformation' argument for 'runTransformation' // would typically be a loaded module from 'vue-codemod/dist/transformations/<name>'. // The 'api' object passed to the transformation function contains 'jscodeshift'. const dummyTransformation = (file: { path: string; source: string }, api: { jscodeshift: any }) => { const j = api.jscodeshift; const root = j(file.source); return root.find(j.Identifier, { name: 'Vue' }) .replaceWith(j.identifier('App')) .toSource(); }; async function applyCodemod() { console.log(`Created temporary file at: ${filePath}`); console.log(`Applying codemod to ${filePath}...`); try { const transformedCode = await runTransformation( fileInfo, dummyTransformation, // Pass the transformation function {} // Optional parameters for the transformation ); console.log('Transformation complete.'); console.log('Original code (first 50 chars):\n' + fileInfo.source.substring(0, 50) + '...'); console.log('Transformed code (first 50 chars):\n' + transformedCode.substring(0, 50) + '...'); // In a real application, you'd write `transformedCode` back to the file // fs.writeFileSync(filePath, transformedCode, 'utf8'); } catch (error) { console.error('Error during transformation:', error); } finally { // Clean up the temporary directory and file fs.rmSync(tempDir, { recursive: true, force: true }); console.log(`Cleaned up temporary directory: ${tempDir}`); } } applyCodemod();
vue-codemod --version
Debug
Known issues
breakingNode.js versions below 10 are no longer supported since `v0.0.5`. Ensure your development environment uses Node.js 10 or higher.
fix
Upgrade your Node.js installation to version 10 or newer. Tools like `nvm` (Node Version Manager) can facilitate this.
affects: >=0.0.5
gotchaThe package is currently in an experimental state (version 0.0.5). While officially maintained, developers should anticipate potential edge cases, subtle differences in migration, or incomplete transformations.
fix
Always use a version control system and conduct thorough testing of your application after applying codemods. Review the generated code carefully before deploying to production environments.
affects: >=0.0.1
gotchaThe codemods are designed as part of a comprehensive Vue 3 migration strategy. Some issues may require manual fixes or reliance on ESLint rules (e.g., `eslint-plugin-vue@7`) rather than automated codemods.
fix
Adhere to the complete migration path outlined in the official Vue 3 migration guide, which includes leveraging ESLint, manual review, and the compatibility build alongside codemods.
affects: >=0.0.1
Errors
Common errors & fixes
Error: transformation <name> not found.
The specified transformation name does not exist among the built-in codemods, or the path to a custom transformation module is incorrect.
fix
Verify the transformation name against the list of included transformations in the `vue-codemod` documentation, or ensure the path to your custom transformation is accurate and accessible.
Error: Path <path> does not exist.
The file or directory path provided to the `vue-codemod` CLI does not correspond to an existing location on the filesystem.
fix
Double-check the provided `<path>` for typos, incorrect relative/absolute paths, or ensure that the target files/directory are accessible from where the command is executed.
SyntaxError: Cannot use import statement outside a module
You are attempting to use an ES module syntax (`import`) in a CommonJS (`require`) environment, or vice-versa, when using the programmatic API or developing custom transformation scripts.
fix
For ES modules, ensure your `package.json` includes `"type": "module"` or use `.mjs` file extensions. For CommonJS, use `require()` statements and `.cjs` file extensions if explicitly needed, or configure your bundler/runtime accordingly.
Upgrade
Version history
0.0.5latest on npm
Audit
Dependencies
jscodeshiftrequiredCore engine for applying AST transformations to code. It is a peer dependency.
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources