@ionic/migrate
v1.0.0
Published
Migration tool to automate and report on breaking changes across Ionic Framework major versions.
Readme
@ionic/migrate
Automates and reports the breaking changes between major versions of Ionic Framework. It scans your app, applies the changes it can make safely, and prints a checklist of the ones you need to do by hand, each with a file and line and a link to the docs.
It handles Angular, React, and Vue (and vanilla) from one command. New breaking changes and future majors are added as data, not new tooling.
Usage
Run it from the root of your app:
npx @ionic/migrateCommit first. The tool edits files in place and won't write to a dirty working tree, so git is your undo. Then review the diff and the checklist it prints.
Options
--dry-run Report what would change without writing anything
--check Report only. Exit non-zero if any migration applies (for CI)
--experimental Include experimental migrations
--force Write even if the working tree is dirty or not a git repo
--no-format Skip running the project's Prettier over changed files
--no-install Skip reinstalling dependencies after the version bump
--from <major> Override the detected source major version
--to <major> Override the target major version
-h, --help Show this helpWhat it does
Every breaking change is one of three kinds:
- Auto-fix: a deterministic edit that preserves behavior, applied for you.
- Report-only: a change that needs judgement (semantic rework, a dialect choice). The tool finds it and explains it, but won't rewrite it.
- Experimental: an edit that is correct but whose consequence is a judgement
call, so it only runs with
--experimental. A report-only migration covers the same change by default.
Coverage
Each major upgrade has its own page, listing every change the tool covers, whether it is auto-fixed, report-only, or experimental, and the changes left for you to make by hand:
How it works
- Detect the installed framework and major version from
package.json. - Select the migrations whose version range applies. A project already on the target major selects nothing, so a finished migration doesn't run again.
- Apply the auto-fixes and collect the report-only findings.
- Print a grouped summary of what was fixed and what's left for you.
- Format the changed files with the project's own Prettier, so the AST-based
edits match the surrounding style. Pass
--no-formatto skip it. - Reinstall dependencies (using the lockfile's package manager) so
node_modulesmatches the bumpedpackage.json. Pass--no-installto skip it, then reinstall yourself before starting the app.
Transforms use ts-morph to locate nodes for TypeScript and TSX, and a small
quote-aware scanner for HTML and Vue templates, so it doesn't touch string
literals, comments, or unrelated code.
Limitations
These hold for every major. What a given upgrade can't reach is on its own page
under docs/.
- Single-shot. A project migrator isn't idempotent, and an import rewrite in
particular will corrupt already-migrated code if you re-run it. The version
gate prevents that once the
@ionic/*bump has landed. - Only
.tsand.tsxare loaded intots-morph, so.js/.jsxfiles and Angular inline templates (atemplate:string in a decorator) get the text-scan migrations but not the AST-based ones. - No
tsconfig.jsonis read. The type checker gets a fixed configuration, so apathsalias doesn't resolve, and a migration reading types treats what it can't reach as unknown rather than as nothing to report. - The template scanner is best-effort, not a full HTML parser.
- Stylesheet scanning covers
.cssand.scssfiles. Styles inlined in a component decorator'sstylesarray aren't read.
Extending
Add a migration by dropping a file under src/migrations/v<major>/ that exports
a Migration (see src/types.ts) and registering it in
src/migrations/index.ts. Give it a detect() and, when the change is safe to
automate, a fix(), plus fromMajor/toMajor for version scoping and a
fixture-backed test. The engine handles selection, ordering, git safety,
formatting, and reporting.
Then add a row to that major's page under docs/, creating
docs/v<major>.md if it's the first migration for a new one. That page is what
tells someone whether an upgrade is covered, so it's part of the migration, not
an afterthought.
Development
npm test # Vitest
npm run lint # tsc --noEmit
npm run build # emit dist/