add-jest-peer-dependency
Backstage 1.46.0 codemod: Add jest as explicit peer dependency to root package.json.
Background
Starting with @backstage/cli@0.35.0, jest is a peer dependency instead of a bundled dependency. Projects using Backstage CLI for testing must add Jest and its environment dependencies as devDependencies in their root package.json.
What it does
- Scans root
package.jsonfiles - Checks if
@backstage/cliis present in dependencies or devDependencies - If
jestis already present, skips the file (already migrated) - Adds Jest 30 packages by default (
jest,@types/jest,@jest/environment-jsdom-abstract,jsdom) - With
--param jestVersion=29, adds Jest 29 packages instead (jest,@types/jest,jest-environment-jsdom) - Rewrites
package.jsonviaJSON.stringifywith auto-detected indentation;devDependenciesare sorted alphabetically
Usage
bash
Notes
- Only modifies the ROOT
package.json— individual packagepackage.jsonfiles are excluded - Jest 29 support is temporary; Backstage recommends Jest 30 for CSS
@layercompatibility - See the Jest 30 migration guide for test code changes