Upgrade transitive npm dependency
org.openrewrite.javascript.UpgradeTransitiveDependencyVersionArtifactorg.openrewrite:rewrite-javascriptPins or upgrades a transitive npm dependency by adding an override entry to package.json and regenerating the lock file. For npm and Bun, adds to the overrides field; for Yarn, adds to resolutions; for pnpm, adds to pnpm.overrides. The override is idempotent — if the entry already exists with the same version, no change is made. Not safe to use as a precondition: invokes the package manager and publishes per-project state shared with other dependency recipes.
Add to your build
~/.gradle/gradle.properties
codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN
build.gradle.kts
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.javascript.UpgradeTransitiveDependencyVersion")
}
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
}
dependencies {
rewrite("org.openrewrite:rewrite-javascript:8.92.8")
}
Then run
./gradlew rewriteRunThis recipe has required options, which a build sets in a rewrite.yml recipe that you activate instead.
Usage
You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.javascript.UpgradeTransitiveDependencyVersion --recipe-option "packageName=lodash" --recipe-option "newVersion=^5.0.0"If the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite:rewrite-javascript:RELEASEOptions
| Name | Type | Description |
|---|---|---|
packageNamerequired | String | The name of the transitive npm dependency to upgrade. e.g. lodash |
newVersionrequired | String | The version constraint to set on the override entry. e.g. ^5.0.0 |
dependencyPath | String | Optional dependency path (pnpm-style a>b>c or yarn-style a/b/c) to scope the override. When omitted, applies as a global override.e.g. express>accepts |
Data tables
Structured output this recipe can produce.
- Node.js lock regeneration failuresLock files that could not be regenerated after a dependency edit, and why.
org.openrewrite.javascript.table.NodeLockRegenerationFailures - Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats