Add npm dependency
MSALAdd an npm dependency to package.json and regenerate the lock file natively, without executing the package manager. In a pnpm workspace with catalogs it writes what pnpm add writes under the workspace's catalogMode and saveCatalogName. If the dependency already exists in any scope, the recipe is a no-op. Not safe to use as a precondition: consults the package registry over the network and publishes per-project state shared with other dependency recipes.
org. openrewrite. javascript. AddDependencyRequired
The name of the npm package to add (e.g., lodash, @types/node).
The version constraint to set (e.g., ^5.0.0, ~2.1.0, 3.0.0).
Optional
The dependency scope: dependencies, devDependencies, peerDependencies, or optionalDependencies. Defaults to dependencies.
Add the dependency only to a package.json that itself declares, in any scope, a package matching one of these glob patterns. Declarations are read as they stand before the recipes in a cycle edit them, so in a migration name the package being migrated away from. Leave unset to add the dependency to every package.json. Separate values with commas.
Add the dependency only to a package.json that resolves every one of these name@range entries, split at the last @. A package not declared by the package.json is taken from the nearest enclosing package.json that declares it, as Node resolves it. An entry holds when the version the lock file resolves satisfies the range or, without one, when every version the declared constraint admits does, so ^16 does not satisfy >=16.9.0 <18. Declarations are read as they stand before the recipes in a cycle edit them. Leave unset to add the dependency regardless of versions. Separate values with commas.
mod run . --recipe= org. openrewrite. javascript. AddDependency \
-P packageName= lodash \
-P version= '^5.0.0'Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.