Module has dependency
org.openrewrite.javascript.search.ModuleHasDependencyArtifactorg.openrewrite:rewrite-javascriptSearches for Node.js packages that have an npm dependency matching the specified package name. Places a SearchResult marker on all sources within a package with a matching dependency. A source belongs to the package.json in its nearest enclosing directory, so each member of a workspace is its own module. This recipe is intended to be used as a precondition for other recipes. For example this could be used to limit the application of a migration to only packages that use a specific version of a library. If the search result you want is instead just the dependency entry in package.json, use the DependencyInsight recipe instead.
Add to your build
~/.gradle/gradle.properties
codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN
settings.gradle.kts
pluginManagement {
repositories {
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
gradlePluginPortal()
}
}
build.gradle.kts
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.javascript.search.ModuleHasDependency")
}
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.93.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.search.ModuleHasDependency --recipe-option "packageNamePattern=@angular/*"If the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite:rewrite-javascript:RELEASEOptions
| Name | Type | Description |
|---|---|---|
packageNamePatternrequired | String | A glob pattern to match npm package names. Use * as a wildcard.e.g. @angular/* |
scope | String | Match dependencies declared in the specified scope. All scopes are searched by default. e.g. dependencies |
version | String | Match only dependencies whose installed version satisfies this npm semver range. When a dependency is not resolved from a lock file, the lowest version its constraint admits is used. All versions are searched by default. e.g. ^17.0.0 |
onlyDirect | Boolean | If enabled, transitive dependencies will not be considered. All dependencies are searched by default. e.g. true |
Data tables
Structured output this recipe can produce.
- 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