{"id":16528693,"url":"https://github.com/zetlen/npm-is","last_synced_at":"2026-05-15T07:02:28.956Z","repository":{"id":65464976,"uuid":"261597877","full_name":"zetlen/npm-is","owner":"zetlen","description":"Detect the package manager client running the current script.","archived":false,"fork":false,"pushed_at":"2020-05-06T14:43:54.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-02-15T23:47:30.481Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zetlen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-05T22:35:20.000Z","updated_at":"2020-05-06T14:43:57.000Z","dependencies_parsed_at":"2023-01-24T17:25:22.716Z","dependency_job_id":null,"html_url":"https://github.com/zetlen/npm-is","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zetlen%2Fnpm-is","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zetlen%2Fnpm-is/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zetlen%2Fnpm-is/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zetlen%2Fnpm-is/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zetlen","download_url":"https://codeload.github.com/zetlen/npm-is/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241629739,"owners_count":19993707,"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":[],"created_at":"2024-10-11T17:41:15.004Z","updated_at":"2026-05-15T07:02:28.898Z","avatar_url":"https://github.com/zetlen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Detect the package manager client running the current script.\nDetects NPM and yarn, as well as any hard executable path.\n\nUse this when your project requires a specific package manager to work\ncorrectly, such as a monorepo using Yarn workspaces.\nIt can help your package scripts exit early if they're being invoked outside of\nthe required package manager.\n\n## Recommended Usage\n\nIn a monorepo, or any repo with `private: true`, it's safe to catch things as\nearly as possible.\nAdd a `preinstall` script to prevent the wrong package manager from even\nbeginning to install dependencies.\nUse `npx` to dynamically install `npm-is` before any other\nmodules are installed.\n\n```diff\n {\n   \"name\": \"my-yarn-only-monorepo\",\n   \"version\": \"1.0.0\",\n   \"private\": true,\n   \"workspaces\": [\n     \"packages/*\"\n   ]\n   \"scripts\": {\n+    \"preinstall\": \"npx npm-is yarn\"\n   }\n }\n```\n\nNow, this happens when you try to `npm install`.\n\n```sh\n$ npm install\n\n\u003e my-yarn-only-monorepo@1.0.0 preinstall /Users/me/repo\n\u003e npx npm-is yarn\n\n/Users/me/repo/node_modules/npm-is/npm-is.js:54\n    throw new WrongPackageManagerError(allowed, invoked);\n    ^\n\nError: This project can only be used with the \"yarn\" package manager, but it was\ninvoked by \"npm\", which is not supported.\n```\n\n## Install\n\n**Don't install this as a dependency if you're going to use it in the**\n**[recommended way described above](#Recommended_usage).**\n\n**Instead, run it with `npx` so that it works before dependencies are installed!**\n\nBut if you insist:\n\nwith npm: `npm install --save-dev npm-is`\n\nwith yarn: `yarn add --dev npm-is`\n\n## Advanced Usage\n\n### CLI\n\nWith no arguments, `npm-is` prints the current package manager.\nSo, running it outside a package manager with no arguments, it will print\nnothing.\nRunning it inside an NPM script with NPM should print `npm` to the command line.\n\nWith arguments, `npm-is` will take each of its arguments to be\nallowed package managers.\nIf the `preinstall` script is `\"npm-is yarn npm\"`, then install\nwill only succeed if the package manager in use is Yarn or NPM.\nOnly `npm` and `yarn` are currently supported as shorthand.\nIf you're using a custom package manager, you must know its exec path (that is,\nthe value of the environment variable `$npm_execpath` when it is running\nlifecycle scripts) and pass that as an argument.\nIf the `preinstall` script is `\"npm-is /path/to/pnpm`, then\ninstall will only succeed if `$npm_execpath` is exactly `/path/to/pnpm`.\n\n### Node API\n\n```js\nconst npmIs = require(\"npm-is\");\n\n// returns true if Yarn\nnpmIs(\"yarn\");\n// returns true if Yarn or NPM\nnpmIs([\"yarn\", \"npm\"]);\n// returns true if Yarn, NPM, or custom executable\nnpmIs([\"yarn\", \"npm\", \"/some/custom/one\"]);\n\n// Throws instead of returning false\nnpmIs.assert(\"yarn\");\nnpmIs.assert([\"yarn\", \"npm\"]);\nnpmIs.assert([\"yarn\", \"npm\", \"/some/custom/one\"]);\n\n// Returns \"npm\" if NPM, \"yarn\" if Yarn,\n// empty string if no package manager,\n// or full execPath if anything else\nnpmIs.detect();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzetlen%2Fnpm-is","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzetlen%2Fnpm-is","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzetlen%2Fnpm-is/lists"}