Skip to content

Home > vue-metamorph

vue-metamorph package

Functions

Function

Description

createVueMetamorphCli(options)

Creates a CLI runner that matches files against a glob pattern and runs codemod plugins and manual migration plugins against them.

The runner parses process.argv for the --files <glob>, --plugins <glob...>, and --list-plugins options, and returns an object with run(), abort(), and opts() methods.

findManualMigrations(code, filename, plugins, opts)

Runs manual migration plugins against source code and returns reports that identify the nodes that need human attention. This function doesn't change the code.

transform(code, filename, plugins, opts)

Parses source code into ASTs, runs codemod plugins against them, and returns the transformed source code. This is the core function of vue-metamorph.

The filename determines how vue-metamorph parses the code:

  • .vue — Parsed as a Vue SFC, which covers the template, the scripts, and the styles. - .js, .jsx, .ts, .tsx — Parsed as JavaScript or TypeScript. - .css, .scss, .sass, .less, .styl — Parsed as CSS.

traverseScriptAST(node, methods)

Traverses a script AST. This is an alias for the visit function from ast-types.

It's declared here rather than re-exported directly so that it carries a release tag. api-extractor can't attach a release tag to a destructured binding inside the vendored module.

Interfaces

Interface

Description

CreateVueMetamorphCliOptions

The options for the vue-metamorph CLI runner.

PluginOptions

The parsed CLI options that vue-metamorph passes to each plugin.

Options registered through additionalCliOptions aren't known ahead of time, so every key reads as unknown. That's enough to check whether an option is set:

ts
if (opts.myCustomOption) { ... }

To give an option a declared type, augment this interface once. Match the declaration to the option's Commander registration. Augmentation doesn't validate or convert values.

ts
import 'vue-metamorph';

declare module 'vue-metamorph' {
  interface PluginOptions {
    myCustomOption?: boolean;
  }
}

Namespaces

Namespace

Description

AST

astHelpers

Kinds

namedTypes

Variables

Variable

Description

builders

The AST node builders for both script nodes and Vue SFC template nodes.

Script builders create JavaScript and TypeScript AST nodes, such as builders.identifier() and builders.callExpression(). Template builders create Vue template AST nodes, such as builders.vElement() and builders.vDirective().

Type Aliases

Type Alias

Description

Builders

CodemodPlugin

A plugin that changes source code.

CodemodPluginContext

ErrorReport

An error that occurred while parsing a file or running a plugin against it.

ManualMigrationPlugin

A plugin that finds nodes that can't be migrated automatically.

ManualMigrationPluginContext

ManualMigrationReport

A manual migration that a ManualMigrationPlugin reported.

Plugin_2

The union of the plugin types.

ProgressCallback

The signature of the onProgress function that you pass to createVueMetamorphCli().

TransformResult

The return type of the transform function, which holds the transformed source code and the codemod stats.

VueProgram

An ESTree Program node with an extra isScriptSetup property, which says whether the program holds the contents of a <script setup> block in a Vue SFC.