{"id":15024860,"url":"https://github.com/bahmutov/am-i-a-dependency","last_synced_at":"2025-04-12T12:51:57.338Z","repository":{"id":57177007,"uuid":"95733597","full_name":"bahmutov/am-i-a-dependency","owner":"bahmutov","description":"Check if the package is being installed by another package","archived":false,"fork":false,"pushed_at":"2018-04-28T01:39:18.000Z","size":15,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T08:03:28.716Z","etag":null,"topics":["install","nodejs","npm","postgresql","utility"],"latest_commit_sha":null,"homepage":null,"language":"Shell","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/bahmutov.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":"2017-06-29T03:10:37.000Z","updated_at":"2023-09-08T17:26:54.000Z","dependencies_parsed_at":"2022-08-28T18:58:14.796Z","dependency_job_id":null,"html_url":"https://github.com/bahmutov/am-i-a-dependency","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fam-i-a-dependency","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fam-i-a-dependency/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fam-i-a-dependency/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fam-i-a-dependency/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bahmutov","download_url":"https://codeload.github.com/bahmutov/am-i-a-dependency/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571522,"owners_count":21126518,"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":["install","nodejs","npm","postgresql","utility"],"created_at":"2024-09-24T20:01:05.115Z","updated_at":"2025-04-12T12:51:57.294Z","avatar_url":"https://github.com/bahmutov.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# am-i-a-dependency\n\n\u003e Check if the package is being installed by another package\n\n[![NPM][npm-icon] ][npm-url]\n\n[![Build status][ci-image] ][ci-url]\n[![semantic-release][semantic-image] ][semantic-url]\n[![js-standard-style][standard-image]][standard-url]\n[![next-update-travis badge][nut-badge]][nut-readme]\n\n## Problem\n\nOften you want to run a post install script that does something. Yet, this\n`postinstall` script will run *even in the module itself*. Thus we need a\nsimple way to determine if we are installing our dependencies or installing\nthe current module as a dependency of some other module. This can be\nexplained by a difference in commands below\n\n```\nnpm i      -\u003e we are installing our dependencies\nnpm i foo  -\u003e module \"foo\" is being installed as a dependency\n```\n\nIf module `foo` has a `postinstall` script, it can use this module\n`am-i-a-dependency` to determine if it should be executed.\n\n## Install\n\nRequires [Node](https://nodejs.org/en/) version 4 or above.\n\n```sh\nnpm install --save am-i-a-dependency\n```\n## Use\n\nImagine a `postinstall` script\n\n```json\n{\n  \"scripts\": {\n    \"postinstall\": \"node something.js\"\n  }\n}\n```\n\nThen inside `something.js` we can check\n\n```js\n// something.js\nconst amDependency = require('am-i-a-dependency')()\nif (amDependency) {\n  // yes, do something interesting\n  // someone is executing \"npm install foo\"\n} else {\n  // we are inside \"foo\" itself, so nothing to do\n}\n```\n\n### Small print\n\nAuthor: Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt; \u0026copy; 2017\n\n* [@bahmutov](https://twitter.com/bahmutov)\n* [glebbahmutov.com](https://glebbahmutov.com)\n* [blog](https://glebbahmutov.com/blog)\n\nLicense: MIT - do anything with the code, but don't blame me if it does not work.\n\nSupport: if you find any problems with this module, email / tweet /\n[open issue](https://github.com/bahmutov/am-i-a-dependency/issues) on Github\n\n## MIT License\n\nCopyright (c) 2017 Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt;\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n\n[npm-icon]: https://nodei.co/npm/am-i-a-dependency.svg?downloads=true\n[npm-url]: https://npmjs.org/package/am-i-a-dependency\n[ci-image]: https://travis-ci.org/bahmutov/am-i-a-dependency.svg?branch=master\n[ci-url]: https://travis-ci.org/bahmutov/am-i-a-dependency\n[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\n[semantic-url]: https://github.com/semantic-release/semantic-release\n[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg\n[standard-url]: http://standardjs.com/\n[nut-badge]: https://img.shields.io/badge/next--update--travis-monthly-green.svg\n[nut-readme]: https://github.com/bahmutov/next-update-travis#readme\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fam-i-a-dependency","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbahmutov%2Fam-i-a-dependency","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fam-i-a-dependency/lists"}