Skip to main content

Node.js dependency insight

org.openrewrite.javascript.search.DependencyInsight

Find direct and transitive npm dependencies matching a package name pattern. Results include dependencies that either directly match or transitively include a matching dependency.

Recipe source

GitHub, Issue Tracker, Maven Central

This recipe is available under the Moderne Source Available License.

Options

TypeNameDescriptionExample
StringpackageNamePatternA glob pattern to match npm package names. Use * as a wildcard.@types/*
StringscopeOptional. Match dependencies in the specified scope. All scopes are searched by default. Valid options: dependencies, devDependencies, peerDependencies, optionalDependencies, bundledDependenciesdependencies
BooleanonlyDirectOptional. If enabled, transitive dependencies will not be considered. All dependencies are searched by default.true

Usage

This recipe has required configuration parameters. Recipes with required configuration parameters cannot be activated directly (unless you are running them via the Moderne CLI). To activate this recipe you must create a new recipe which fills in the required parameters. In your rewrite.yml create a new recipe with a unique name. For example: com.yourorg.DependencyInsightExample. Here's how you can define and customize such a recipe within your rewrite.yml:

rewrite.yml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.DependencyInsightExample
displayName: Node.js dependency insight example
recipeList:
- org.openrewrite.javascript.search.DependencyInsight:
packageNamePattern: '@types/*'
scope: dependencies
onlyDirect: true

Now that com.yourorg.DependencyInsightExample has been defined, activate it in your build file:

  1. Add the following to your build.gradle file:
build.gradle
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}

rewrite {
activeRecipe("com.yourorg.DependencyInsightExample")
setExportDatatables(true)
}

repositories {
mavenCentral()
}
  1. Run gradle rewriteRun to run the recipe.

See how this recipe works across multiple open-source repositories

Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.

Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.

Data Tables

Node.js dependencies in use

org.openrewrite.javascript.table.NodeDependenciesInUse

Direct and transitive dependencies in use in Node.js projects.

Column NameDescription
Project nameThe name of the project that contains the dependency (from package.json).
Project pathThe path to the project.
Package nameThe name of the npm package.
VersionThe resolved version of the package.
Version constraintThe version constraint as declared in package.json.
ScopeDependency scope: dependencies, devDependencies, peerDependencies, optionalDependencies, or bundledDependencies.
DirectWhether this is a direct dependency (true) or transitive dependency (false).
CountHow many times this dependency appears in the dependency tree.
LicenseThe SPDX license identifier of the package, if available.