Class PackageManagerExecutor

java.lang.Object
org.openrewrite.javascript.internal.PackageManagerExecutor

public final class PackageManagerExecutor extends Object
Locates and runs a Node.js package manager CLI (npm, yarn, pnpm, bun). Pre-configured instances are provided for each; find() caches the resolved executable path on first lookup. On Windows the executable is suffixed with .cmd (matching shell-utils.ts behaviour).
  • Field Details

  • Method Details

    • run

      public PackageManagerExecutor.RunResult run(Path workDir, String executablePath, Map<String,String> environment, String... args) throws IOException, InterruptedException
      Run the package manager in the given directory.
      Throws:
      IOException
      InterruptedException
    • find

      public @Nullable String find()
      Find the executable on the system, returning null if not installed.

      Resolution order, most to least preferred:

      1. The executable co-located with the active node. Package managers re-invoke node through a #!/usr/bin/env node shebang, so the one sitting next to the node on PATH is guaranteed to run under a compatible runtime. This prevents npm's validate-engines failure (exit 7) when a hardcoded npm is newer or older than the node that actually executes it.
      2. The executable resolved through PATH (which/where), which stays consistent with the user's shell environment (nvm, fnm, volta, ...).
      3. Common install locations, for processes launched with a minimal PATH (e.g. GUI-launched IDEs on macOS).