Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement runtime package manager detection #164

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Eazash
Copy link

@Eazash Eazash commented Nov 22, 2024

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

@pi0
Copy link
Member

pi0 commented Nov 22, 2024

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

@@ -109,6 +128,7 @@ const main = defineCommand({
uninstall: remove,
un: remove,
detect,
"detect-runner": detectRunner,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we simplify to have nypm detect that displays both detection results.

@@ -3,6 +3,7 @@ export type PackageManagerName = "npm" | "yarn" | "pnpm" | "bun";
export type PackageManager = {
name: PackageManagerName;
command: string;
packageRunner?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might make it an array. It is a map of known args => package runner

Copy link

codecov bot commented Nov 22, 2024

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 ⚠️
src/cli.ts 0.00% 17 Missing ⚠️
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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants