{"id":19551405,"url":"https://github.com/aprilandjan/check-npm-client","last_synced_at":"2025-05-08T03:14:02.310Z","repository":{"id":51665999,"uuid":"219166402","full_name":"aprilandjan/check-npm-client","owner":"aprilandjan","description":"check or ensure which npm client(yarn/npm) is currently used","archived":false,"fork":false,"pushed_at":"2021-05-10T20:06:14.000Z","size":68,"stargazers_count":3,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-08T03:13:57.954Z","etag":null,"topics":["ensure-npm-client","npm","npm-client","npm-scripts","npm-user-agent","yarn"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/check-npm-client","language":"JavaScript","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/aprilandjan.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}},"created_at":"2019-11-02T14:36:12.000Z","updated_at":"2022-04-12T05:44:12.000Z","dependencies_parsed_at":"2022-08-23T00:40:17.129Z","dependency_job_id":null,"html_url":"https://github.com/aprilandjan/check-npm-client","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aprilandjan%2Fcheck-npm-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aprilandjan%2Fcheck-npm-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aprilandjan%2Fcheck-npm-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aprilandjan%2Fcheck-npm-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aprilandjan","download_url":"https://codeload.github.com/aprilandjan/check-npm-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252990003,"owners_count":21836668,"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":["ensure-npm-client","npm","npm-client","npm-scripts","npm-user-agent","yarn"],"created_at":"2024-11-11T04:13:48.279Z","updated_at":"2025-05-08T03:14:02.291Z","avatar_url":"https://github.com/aprilandjan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [check-npm-client](https://www.npmjs.com/package/check-npm-client)\n\n[![version](https://img.shields.io/npm/v/check-npm-client?style=flat-square)](https://www.npmjs.com/package/check-npm-client) [![version](https://img.shields.io/npm/dm/check-npm-client?style=flat-square)](https://www.npmjs.com/package/check-npm-client)\n\n`npm` and `yarn` are both npm clients used to manage node.js project dependencies. They are somehow different in some behavior, and thus can affect project running.\n\nThis package provides ready-to-use functionality to check current npm client. When used as [pre](https://docs.npmjs.com/misc/scripts#hook-scripts) commands in npm scripts, it will check if the script is executed by specific npm client (`yarn` or `npm`). If it is restricted, then the script execution will be aborted early.\n\n## Usage Scenario\n\n`yarn` uses [yarn.lock](https://yarnpkg.com/lang/en/docs/yarn-lock/) to ensure versions of dependencies, but `npm` use [package-lock.json](https://docs.npmjs.com/files/package-lock.json) to do that instead. If you use `yarn` to install dependencies in a project which is actually managed by `npm` and `package-lock.json`, the actually installed dependencies in `node_modules` might be different due to [semver](https://docs.npmjs.com/misc/semver) behavior, and this could lead to some un-expected exception while code running.\n\nThis is common when working with others because people tends to use `yarn` or `npm` as their wishes.\n\n## Installation\n\n```bash\n$ npm install check-npm-client\n```\n\nor alternatively, with `yarn`:\n\n```bash\n$ yarn add check-npm-client\n```\n\n## Example\n\nThis package provide a command line tool to invoke checking functionality:\n\n```bash\n# the user must use `npm` to execute the script\n$ check-npm-client --npm-only\n\n# the user must use `yarn` to execute the script\n$ check-npm-client --yarn-only\n\n# automatically check according to current working directory lock files if exists\n$ check-npm-client\n```\n\nBesides, you can use it programmatically:\n\n```javascript\nconst { checkNpmClient } = require('check-npm-client');\nconsole.log(checkNpmClient('yarn'));  // true/false\n```\n\n### Ensure before installation\n\nAdd the script in your `package.json` to ensure that user must install dependencies with `yarn`:\n\n```json\n{\n  \"scripts\": {\n    \"preinstall\": \"npx check-npm-client --yarn-only\"\n  }\n}\n```\n\n**Note #1**: `npx` is required to execute checking because before your project installation, the command `check-npm-client` won't be available.\n\n**Note #2**: `yarn` and `npm` treat `preinstall` script a little differently. `npm` execute it only before `npm install` (not before `npm install \u003cmodule\u003e`), but `yarn` always run it before any installation. See [issue](https://github.com/npm/cli/issues/481) here. So if specified as `--yarn-only` and user use `npm` to install another dependency, the `preinstall` will not be invoked (so the ensurance will fail).\n\n### Ensure before any other script\n\nAdd the script in your `package.json` to ensure that user must use `npm` to run the script `my-task`:\n\n```json\n{\n  \"scripts\": {\n    \"premy-task\": \"check-npm-client --npm-only\",\n    \"my-task\": \"node my-task.js\"\n  }\n}\n```\n\n## References\n\n- \u003chttps://github.com/npm/cli/issues/481\u003e\n- \u003chttps://stackoverflow.com/questions/46725374/how-to-run-a-script-before-installing-any-npm-module\u003e\n- \u003chttps://github.com/yarnpkg/yarn/issues/5063\u003e\n- \u003chttps://docs.npmjs.com/cli/run-script#description\u003e\n- \u003chttps://github.com/yarnpkg/yarn/issues/1732\u003e\n- \u003chttps://github.com/AndersDJohnson/use-yarn\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faprilandjan%2Fcheck-npm-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faprilandjan%2Fcheck-npm-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faprilandjan%2Fcheck-npm-client/lists"}