{"id":19355481,"url":"https://github.com/antfu-collective/package-manager-detector","last_synced_at":"2026-07-01T07:01:39.062Z","repository":{"id":250146732,"uuid":"833607927","full_name":"antfu-collective/package-manager-detector","owner":"antfu-collective","description":"Package manager detector","archived":false,"fork":false,"pushed_at":"2026-07-01T05:55:18.000Z","size":456,"stargazers_count":165,"open_issues_count":9,"forks_count":26,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-07-01T06:34:12.084Z","etag":null,"topics":["bun","deno","detector","npm","package-manager","pnpm","yarn"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antfu-collective.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-07-25T11:45:03.000Z","updated_at":"2026-07-01T05:55:21.000Z","dependencies_parsed_at":"2025-10-19T14:34:35.742Z","dependency_job_id":"cd275b91-d333-485c-8d84-f4093c12d733","html_url":"https://github.com/antfu-collective/package-manager-detector","commit_stats":null,"previous_names":["userquin/package-manager-detector","antfu-collective/package-manager-detector"],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/antfu-collective/package-manager-detector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antfu-collective%2Fpackage-manager-detector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antfu-collective%2Fpackage-manager-detector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antfu-collective%2Fpackage-manager-detector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antfu-collective%2Fpackage-manager-detector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antfu-collective","download_url":"https://codeload.github.com/antfu-collective/package-manager-detector/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antfu-collective%2Fpackage-manager-detector/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34996290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-01T02:00:05.325Z","response_time":130,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bun","deno","detector","npm","package-manager","pnpm","yarn"],"created_at":"2024-11-10T06:01:12.986Z","updated_at":"2026-07-01T07:01:39.043Z","avatar_url":"https://github.com/antfu-collective.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# package-manager-detector\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![JSDocs][jsdocs-src]][jsdocs-href]\n[![License][license-src]][license-href]\n\nPackage manager detector is based on lock files, the `package.json` `packageManager` field, and installation metadata to detect the package manager used in a project.\n\nIt supports `npm`, `yarn`, `pnpm`, `deno`, `bun`, `nub`, and `aube`.\n\n## Install\n\n```sh\n# pnpm\npnpm add package-manager-detector\n\n# npm\nnpm i package-manager-detector\n\n# yarn\nyarn add package-manager-detector\n```\n\n## Usage\n\nTo check the file system for which package manager is used:\n\n```js\nimport { detect } from 'package-manager-detector/detect'\n```\n\nor to get the currently running package manager:\n\n```js\nimport { getUserAgent } from 'package-manager-detector/detect'\n```\n\n## Customize Detection Strategy\n\nBy default, the `detect` API searches through the current directory for lock files, and if none exists, it looks for the `packageManager` field in `package.json`. If that also doesn't exist, it will check the `devEngines.packageManager` field in `package.json`. If all strategies couldn't detect the package manager, it'll crawl upwards to the parent directory and repeat the detection process until it reaches the root directory.\n\nThe strategies can be configured through `detect`'s `strategies` option with the following accepted strategies:\n\n- `'lockfile'`: Look up for lock files.\n- `'packageManager-field'`: Look up for the `packageManager` field in package.json.\n- `'devEngines-field'`: Look up for the `devEngines.packageManager` field in package.json.\n- `'install-metadata'`: Look up for installation metadata added by package managers.\n\nThe order of the strategies can also be changed to prioritize one strategy over another. For example, if you prefer to detect the package manager used for installation:\n\n```js\nimport { detect } from 'package-manager-detector/detect'\n\nconst pm = await detect({\n  strategies: ['install-metadata', 'lockfile', 'packageManager-field', 'devEngines-field']\n})\n```\n\n## Agents and Commands\n\nThis package includes package manager agents and their corresponding commands for:\n\n- `'agent'` - run the package manager with no arguments\n- `'install'` - install dependencies\n- `'frozen'` - install dependencies using frozen lockfile\n- `'add'` - add dependencies\n- `'uninstall'` - remove dependencies\n- `'global'` - install global packages\n- `'global_uninstall'` - remove global packages\n- `'upgrade'` - upgrade dependencies\n- `'upgrade-interactive'` - upgrade dependencies interactively: not available for `npm`\n- `'dedupe'` - deduplicate dependencies with overlapping ranges: not available for `deno` and `bun`\n- `'execute'` - download \u0026 execute binary scripts\n- `'execute-local'` - execute binary scripts (from package locally installed)\n- `'run'` - run `package.json` scripts\n\n### Using Agents and Commands\n\nA `resolveCommand` function is provided to resolve the command for a specific agent.\n\n```ts\nimport { resolveCommand } from 'package-manager-detector/commands'\nimport { detect } from 'package-manager-detector/detect'\n\nconst pm = await detect()\nif (!pm)\n  throw new Error('Could not detect package manager')\n\nconst { command, args } = resolveCommand(pm.agent, 'add', ['@antfu/ni']) // { command: 'pnpm', args: ['add', '@antfu/ni'] }\nconsole.log(`Detected the ${pm.agent} package manager. You can run a install with ${command} ${args.join(' ')}`)\n```\n\nYou can check the source code or the [JSDocs](https://www.jsdocs.io/package/package-manager-detector) for more information.\n\n## License\n\n[MIT](./LICENSE) License © 2020-PRESENT [Anthony Fu](https://github.com/antfu)\n\n\u003c!-- Badges --\u003e\n\n[npm-version-src]: https://img.shields.io/npm/v/package-manager-detector?style=flat\u0026colorA=18181B\u0026colorB=F0DB4F\n[npm-version-href]: https://npmjs.com/package/package-manager-detector\n[npm-downloads-src]: https://img.shields.io/npm/dm/package-manager-detector?style=flat\u0026colorA=18181B\u0026colorB=F0DB4F\n[npm-downloads-href]: https://npmjs.com/package/package-manager-detector\n[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat\u0026colorA=18181B\u0026colorB=F0DB4F\n[jsdocs-href]: https://www.jsdocs.io/package/package-manager-detector\n[license-src]: https://img.shields.io/github/license/antfu-collective/package-manager-detector.svg?style=flat\u0026colorA=18181B\u0026colorB=F0DB4F\n[license-href]: https://github.com/antfu-collective/package-manager-detector/blob/main/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantfu-collective%2Fpackage-manager-detector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantfu-collective%2Fpackage-manager-detector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantfu-collective%2Fpackage-manager-detector/lists"}