{"id":17837443,"url":"https://github.com/ndaba1/get-pm","last_synced_at":"2025-07-14T15:33:25.786Z","repository":{"id":106273318,"uuid":"586268282","full_name":"ndaba1/get-pm","owner":"ndaba1","description":"Detect and abstract away package managers in JS/TS codebases","archived":false,"fork":false,"pushed_at":"2023-01-22T16:29:49.000Z","size":183,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-14T19:37:46.900Z","etag":null,"topics":["detect-pm","nodejs","package-manager","preferred-pm","which-pm","which-pm-runs"],"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/ndaba1.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2023-01-07T14:41:10.000Z","updated_at":"2023-01-22T16:32:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"65368ebe-22c2-4b03-9ed8-de1b04d19f85","html_url":"https://github.com/ndaba1/get-pm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ndaba1/get-pm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndaba1%2Fget-pm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndaba1%2Fget-pm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndaba1%2Fget-pm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndaba1%2Fget-pm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ndaba1","download_url":"https://codeload.github.com/ndaba1/get-pm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndaba1%2Fget-pm/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265312072,"owners_count":23745177,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["detect-pm","nodejs","package-manager","preferred-pm","which-pm","which-pm-runs"],"created_at":"2024-10-27T20:47:12.856Z","updated_at":"2025-07-14T15:33:25.753Z","avatar_url":"https://github.com/ndaba1.png","language":"TypeScript","readme":"## get-pm\nDetect and abstract away package managers in JS/TS codebases\n\n### Why?\nMany a time, I find myself creating CLIs that require some sort of access to the user's package manager. This is a pain to do, as I have to write a bunch of code to detect the user's package manager, and then write code to abstract away the differences between the package managers. This package aims to solve that problem.\n\nRight about now, you might be thinking \"Why not use [which-pm](https://github.com/zkochan/packages/tree/main/which-pm) or [which-pm-runs](https://github.com/zkochan/packages/tree/main/which-pm-runs) or [preferred-pm](https://github.com/zkochan/packages/tree/main/preferred-pm)\". Well, those packages are great, but they don't abstract away the differences between the package managers. This package does that.\n\n### Detection logic\n- If a bin target is executed with a user_agent i.e `npx` | `pnpx` | `yarn dlx`, then the package manager is detected from the user_agent.\n- If a `lockfile` is present, then the package manager is detected from the `lockfile`.\n- If `node_modules` is present, then the package manager is detected from the `node_modules`.\n- If multiple package managers are detected and the `prefer` option has been passed, then the package manager is detected from the `prefer` option. see example below.\n- If all else fails, defaults to `npm`.\n\n### Usage\n```ts\nimport { getPackageManager } from 'get-pm';\n\nconst pm = getPackageManager({\n    prefer: ['pnpm', 'yarn'], // optional - if multiple found, prefer these\n    cwd: process.cwd(), // optional - defaults to process.cwd()\n    workspace: true, // optional - treat working dir as a workspace\n    silent: false, // optional - suppress console output when running pm commands eg. `pm.install()`\n});\n\nconsole.log(pm.name); // npm | yarn | pnpm\nconsole.log(pm.version) // semver version of the package manager\n\n// install packages defined in package.json\nawait pm.install();\n\n// add packages\nawait pm.add(['foo', 'bar']);\n\n// add packages with flags/options\nawait pm.add(['foo', 'bar'], \"-Dw\"); // -Dw is the workspace flag for pnpm\n\n// remove packages\nawait pm.remove(['foo', 'bar']);\n\n// run scripts in package.json\nawait pm.run('build');\n\n// execute binaries\nawait pm.exec('tailwindcss', ['init', '-p']);\n```\n\n## Usage with commonjs\nThe get-pm package is an esm module which cannot be used with the default `require` syntax in commonjs. To use it with cjs, you will have to use the `import` syntax as shown below:\n\n```ts\nasync function getPm() {\n    const { getPackageManager } = await import(\"get-pm\")\n    const pm = getPackageManager();\n\n    return pm\n}\n\n```\n\n### License\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndaba1%2Fget-pm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fndaba1%2Fget-pm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndaba1%2Fget-pm/lists"}