Skip to content

feat: implement runtime package manager detection - #164

Draft
Eazash wants to merge 3 commits into
unjs:mainfrom
Eazash:feat/runtime-api
Draft

feat: implement runtime package manager detection#164
Eazash wants to merge 3 commits into
unjs:mainfrom
Eazash:feat/runtime-api

Conversation

@Eazash

@Eazash Eazash commented Nov 22, 2024

Copy link
Copy Markdown

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

pi0 commented Nov 22, 2024

Copy link
Copy Markdown
Member

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

Comment thread src/cli.ts
uninstall: remove,
un: remove,
detect,
"detect-runner": detectRunner,

Copy link
Copy Markdown
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.

Comment thread src/types.ts
export type PackageManager = {
name: PackageManagerName;
command: string;
packageRunner?: string;

Copy link
Copy Markdown
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

@codecov

codecov Bot commented Nov 22, 2024

Copy link
Copy Markdown

Codecov Report

❌ 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 140 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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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