{"id":17910292,"url":"https://github.com/raulfdm/pin-dependencies-checker","last_synced_at":"2025-03-23T21:33:12.787Z","repository":{"id":57142113,"uuid":"265798301","full_name":"raulfdm/pin-dependencies-checker","owner":"raulfdm","description":"A tiny cli checker for unpinned (^) dependencies version","archived":false,"fork":false,"pushed_at":"2024-07-29T17:13:14.000Z","size":458,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-09-30T06:39:32.200Z","etag":null,"topics":["cli","dependencies","node","typescript"],"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/raulfdm.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":"2020-05-21T08:43:49.000Z","updated_at":"2024-07-29T17:12:14.000Z","dependencies_parsed_at":"2024-07-29T20:11:37.193Z","dependency_job_id":null,"html_url":"https://github.com/raulfdm/pin-dependencies-checker","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raulfdm%2Fpin-dependencies-checker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raulfdm%2Fpin-dependencies-checker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raulfdm%2Fpin-dependencies-checker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raulfdm%2Fpin-dependencies-checker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raulfdm","download_url":"https://codeload.github.com/raulfdm/pin-dependencies-checker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221918090,"owners_count":16901597,"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":["cli","dependencies","node","typescript"],"created_at":"2024-10-28T19:29:53.311Z","updated_at":"2024-10-28T19:29:53.382Z","avatar_url":"https://github.com/raulfdm.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pin Dependencies Checker CLI\n\n\u003e Sometimes you need a reminder for mundane tasks.\n\n## Table of Contents\n\n- [Why](#why)\n- [How it Works](#how-it-works)\n- [Getting Started](#getting-started)\n- [Arguments](#arguments)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Why\n\nWhen installing dependencies without specifying a version, package managers (yarn, npm, pnpm, etc.) will, by default, install the latest published version with a caret `^`:\n\n```bash\npnpm add lodash\n```\n\n```json\n{\n  \"dependencies\": {\n    \"lodash\": \"^4.17.21\"\n  }\n}\n```\n\nThis is termed a \"ranged\" version.\n\nIn the lock file, it will be registered that `lodash` is installed on version `4.17.21` OR HIGHER... and this is where issues arise.\n\nSuppose lodash `4.18.0` is released, and it removes or alters an API our codebase depends on. If I need to regenerate my `lockfile` for any reason, the package manager will again fetch the latest version 4 of `lodash`. Instead of installing `4.17.21`, it will fetch the new `4.18.0`.\n\nIf we have unit tests, builds, etc., we'll likely encounter issues without understanding the cause. Our package.json hasn't changed, right? However, it's the `lockfile` that determines which dependencies get installed.\n\nOne way to ensure consistent versions is to avoid installing ranged versions. This can be achieved in various ways depending on the package manager:\n\n```bash\npnpm add --save-exact lodash\n```\n\nOr, using pnpm, it can be defined in `.npmrc`:\n\n```\nsave-prefix=''\n```\n\nAlternatively, you can use this tool as a pre-commit reminder to assess all dependencies you've installed and check for ranged versions. 😅\n\n\u003e [!IMPORTANT]  \n\u003e Renovate provides an [extensive article](https://docs.renovatebot.com/dependency-pinning/) detailing the issues with ranged versions. I highly recommend reading it.\n\n## How it Works\n\nThe process is straightforward:\n\n1. Scan all `package.json` files in the current work directory.\n2. Identify all dependencies that:\n   - aren't valid semver versions (e.g. `1.2.3` or `4.5.6.alpha`)\n   - are URLs or GitHub repositories and don't contain a commitish string neither a semver string\n3. If any are found, the CLI will list them and exit with an error.\n4. Otherwise, it will exit successfully.\n\n## Getting Started\n\nYou can use this CLI directly from the registry via [`npx`](https://docs.npmjs.com/cli/v8/commands/npx) or [`pnpm dlx`](https://pnpm.io/cli/dlx):\n\n```bash\npnpm dlx pin-dependencies-checker\n\n# OR using npm\n\nnpx pin-dependencies-checker\n```\n\nAlternatively, add it to your project's dev dependencies:\n\n```bash\npnpm add --save-exact --save-dev pin-dependencies-checker\n# Or the equivalent command for your package manager\n```\n\nThen run:\n\n```bash\npnpm pin-checker\n# Or for npm or yarn\nnpx pin-checker\n```\n\n### Git Hooks\n\nYou can automate the CLI execution using a git hook (e.g., pre-commit).\n\nMany JS projects use [`husky`](https://github.com/typicode/husky) for this purpose.\n\nSimply add the command to your `pre-commit` script:\n\n```bash\n# Other commands and setup\npnpm pin-checker\n\n# Or using npx\nnpx pin-checker\n```\n\n## Arguments\n\nBy default, this CLI scans only `dependencies` and `devDependencies`. This behavior can be modified with CLI arguments.\n\n### `--ignore-workspaces`\n\n\u003e Default: false\n\nAllows versions starting with `workspaces:` to be ignored:\n\n```bash\npnpm pin-checker --ignore-workspaces\n```\n\n### `--ignore-catalog`\n\n\u003e Default: false\n\nAllows versions starting with `catalog:` to be ignored:\n\n```bash\npnpm pin-checker --ignore-catalog\n```\n\n\u003e [See more about pnpm's catalogs feature](https://pnpm.io/catalogs)\n\n### `--no-deps`\n\n\u003e Default: false\n\nSkips the `dependencies` evaluation:\n\n```bash\npnpm pin-checker --no-deps\n```\n\n### `--no-dev-deps`\n\n\u003e Default: false\n\nSkips the `devDependencies` evaluation:\n\n```bash\npnpm pin-checker --no-dev-deps\n```\n\n### `--peer-deps`\n\n\u003e Default: false\n\nEvaluates `peerDependencies`:\n\n\u003e **NOTE**\n\u003e Peer dependencies are primarily for libraries, indicating to the package manager the necessary version for the library to function correctly. You likely don't want to verify this.\n\n```bash\npnpm pin-checker --peer-deps\n```\n\n### `--optional-deps`\n\n\u003e Default: false\n\nEvaluates [`optionalDependencies`](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#optionaldependencies):\n\n```bash\npnpm pin-checker --optional-deps\n```\n\n## Contributing\n\nTo run this project, you'll need:\n\n- Node 20 or higher\n- pnpm\n\nAfter cloning, install the dependencies:\n\n```bash\npnpm install\n```\n\nYou can either link the package globally or run the command:\n\n```bash\npnpm run dev\n```\n\nThis will evaluate the current repository, which can be handy for quick tests.\n\nTo run unit tests:\n\n```bash\npnpm run test\n```\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraulfdm%2Fpin-dependencies-checker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraulfdm%2Fpin-dependencies-checker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraulfdm%2Fpin-dependencies-checker/lists"}