nypm icon indicating copy to clipboard operation
nypm copied to clipboard

feat: implement runtime package manager detection

Open Eazash opened this issue 1 year ago • 2 comments

This PR adds a detectRuntimePackageManager api function to detect the current package manager in runtime using the npm-config-user-agent environment variable. It also adds a refactor so that argv parsing can be a safe fallback in the event that the environment variable is not set.

The possible usecases for this API include

  • Allowing scripts that contain a package manager selector to default to and/or suggest the package manage currently in use
  • Enabling silent scripts that don't require user input for package installation (for use in CI environments)

I'm currently marking this as a draft because I'd appreciate suggestions on how to implement tests for this new API.

References

  • pnpm/pnpm#4317
  • npm/cli#1919
  • yarnpkg/yarn#7127

Eazash avatar Nov 22 '24 08:11 Eazash

This is nice idea!

  • Can you please add tests to make sure pnpm and yarn (v1 and berry+) are detected? (we can use mocking of process to avoid extra exec overhead)
  • We shall also implement logic for arv0 (runtime binary as package manager: bun/deno) -- we might use join + prefix check

pi0 avatar Nov 22 '24 10:11 pi0

Codecov Report

Attention: Patch coverage is 18.00000% with 41 lines in your changes missing coverage. Please review.

Project coverage is 60.00%. Comparing base (660392f) to head (a7e121f). Report is 67 commits behind head on main.

Files with missing lines Patch % Lines
src/package-manager.ts 27.27% 24 Missing :warning:
src/cli.ts 0.00% 17 Missing :warning:
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #164       +/-   ##
===========================================
- Coverage   82.17%   60.00%   -22.18%     
===========================================
  Files           6        5        -1     
  Lines         516      530       +14     
  Branches       71       91       +20     
===========================================
- Hits          424      318      -106     
- Misses         91      209      +118     
- Partials        1        3        +2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Nov 22 '24 10:11 codecov[bot]