Commit activity
Last 12 weeks · 13 commits
Community health
3 of 6 standards met
Recent PRs & issues
answers which package manager a project uses. Could also expose an opt-in, read-only way to find which package manager owns a specific global installation of a package? Use case Cloudflare's PR uses for project installs and has separate global ownership probes. A self-updating CLI needs to update the copy that's actually running. If npm and pnpm both have the same package installed globally, finding its name in either list (or finding a manager on ) doesn't establish ownership. Proposed API Something like , where the caller supplies the path to the installed package's manifest. Compare its canonical path with the paths reported by the managers' global probes and distinguish a unique match from no match or multiple matches. Keep this separate from so ordinary project detection doesn't spawn subprocesses. The API would not install or update packages; that decision stays with the caller. The PR has probes for npm, pnpm, Yarn Classic, and Bun that could serve as a starting point. Vite+ is a useful additional case: uses its own store, so a adapter would need a supported way to resolve the installed package path. A name match from alone isn't sufficient. Would this fit the library's scope? Happy to contribute if so.
Problem is documented as an ordered list where each entry does one thing: : Look up for lock files. : Look up for the field in package.json. : Look up for the field in package.json. The implementation does not match. reads the field to resolve the version, and / share a single , so both fields are read no matter which one you ask for. With the current release, on a project containing and : Reordering the two strategies changes nothing, so the option cannot be used to prefer a lock file over a declared field. On a project that only has : returns a result even though the project has no at all. Changes only looks at lock files. and are now separate, each reading only its own field. The Rush special case ( => ) moves out of into a new strategy. The default order becomes . is read once per directory for both field strategies, so is still called exactly once. is exported so callers do not have to hard-code the default order. Compatibility The default output is unchanged. The default order had to change because no longer reads the field: putting the fields first is what keeps both the field and its version authoritative. The breaking part is limited to callers that pass an explicit non-default array: they now get what they asked for. If you would rather avoid a major bump, I can keep the current default order, but then has to keep reading the field and the bug above stays. One deliberate side effect: now receives the unknown instead of . Before, the devEngines path passed , which is whenever devEngines is the only field present. It is covered by tests. Tests passes (172 tests). New tests pin strategy independence and the argument. Follow-up: with the strategies actually independent, the order becomes meaningful enough to be worth making extensible. I plan to send a separate PR that lets an entry be a function, so callers can insert their own rules without touching this package.
Stacked on #91.** The first commit of this branch is #91 itself; the only new commit here is the second one. Please review and merge #91 first — I will rebase this branch onto once it lands. Problem is configurable but the rules are not. A caller can only pick from the built-in strategies, so there is no way to put a project-specific rule in front of them. The only workaround is to call and override the result afterwards, which means the caller cannot express "a declared field wins over a lock file" or "this directory always uses yarn" through the same API. Changes A strategy entry can now be a function as well as a name: is widened, so passing a plain array of names keeps working. Only the old string union is renamed to . A custom strategy runs once per directory, exactly like a built-in one, in the configured order. Returning a stops the detection. Returning / falls through to the next strategy. exposes the same helper the built-in strategies use, the original (so and can be reused), and . behaves like a dynamic : it prevents walking up to the parent directories, while the remaining strategies of the current directory still run. was exported in #91, so callers do not have to hard-code the default order: Compatibility Additive. Existing calls that pass an array of strategy names are untouched, and without still uses . The exported API snapshot only gains , , and . Tests passes (179 tests). New tests cover: a custom strategy winning over a lock file falling through to the built-in strategies the context (, , , ) preventing the walk up, while the remaining strategies of the current directory still run composing a custom strategy with
Repository: made-in-common/package-manager-detector. Description: Package manager detector Stars: 174, Forks: 32. Primary language: TypeScript. Languages: TypeScript (96.8%), JavaScript (3.2%). License: MIT. Topics: bun, deno, detector, npm, package-manager, pnpm, yarn. Latest release: v1.9.0 (1mo ago). Open PRs: 8, open issues: 6. Last activity: 1d ago. Community health: 50%. Top contributors: antfu, userquin, benmccann, bluwy, antfubot, bartlomieju, AdrianGonz97, colinhacks, sxzz, luxass and others.