{"id":14978213,"url":"https://github.com/robintail/allowed-dependencies","last_synced_at":"2025-10-28T08:31:57.141Z","repository":{"id":251892527,"uuid":"838761497","full_name":"RobinTail/allowed-dependencies","owner":"RobinTail","description":"ESLint plugin Allowed Dependencies","archived":false,"fork":false,"pushed_at":"2024-10-09T16:12:12.000Z","size":601,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-11T17:21:23.742Z","etag":null,"topics":["dependencies","eslint","eslint-plugin","eslint-rules","eslintplugin","exhaustive","external-dependency","extraneous","import","modules","restriction"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/eslint-plugin-allowed-dependencies","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/RobinTail.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":"2024-08-06T09:38:58.000Z","updated_at":"2024-10-09T16:12:15.000Z","dependencies_parsed_at":"2024-09-07T08:49:22.896Z","dependency_job_id":"a9f9b243-3eda-40d3-847a-d00bfd37e511","html_url":"https://github.com/RobinTail/allowed-dependencies","commit_stats":{"total_commits":83,"total_committers":4,"mean_commits":20.75,"dds":0.3132530120481928,"last_synced_commit":"033671aa0f7db73b3c38d09a98612958953093f6"},"previous_names":["robintail/allowed-dependencies"],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinTail%2Fallowed-dependencies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinTail%2Fallowed-dependencies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinTail%2Fallowed-dependencies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinTail%2Fallowed-dependencies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobinTail","download_url":"https://codeload.github.com/RobinTail/allowed-dependencies/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219859904,"owners_count":16556031,"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":["dependencies","eslint","eslint-plugin","eslint-rules","eslintplugin","exhaustive","external-dependency","extraneous","import","modules","restriction"],"created_at":"2024-09-24T13:57:04.715Z","updated_at":"2025-10-28T08:31:57.135Z","avatar_url":"https://github.com/RobinTail.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ESLint plugin Allowed Dependencies\n\n[![Coverage Status](https://coveralls.io/repos/github/RobinTail/allowed-dependencies/badge.svg)](https://coveralls.io/github/RobinTail/allowed-dependencies)\n![License](https://img.shields.io/npm/l/eslint-plugin-allowed-dependencies.svg?color=green25)\n![npm release](https://img.shields.io/npm/v/eslint-plugin-allowed-dependencies.svg?color=green25\u0026label=latest)\n![downloads](https://img.shields.io/npm/dw/eslint-plugin-allowed-dependencies.svg)\n\nESLint plugin for restricting imports to package dependency categories.\nSuggested to be used for source code, to prevent importing packages that are not present in the distribution.\n\nThe plugin distinguishes between production dependencies, mandatory and optional peers in your `package.json`.\nThe import syntax also matters: regular `import` or `import type` (excluded from distributable javascript code).\n\n## Demo\n\n```jsonc\n// package.json\n{\n  \"dependencies\": { \"express-zod-api\": \"^20\" },\n  \"devDependencies\": { \"typescript\": \"^5\" },\n  \"peerDependencies\": { \"prettier\": \"^3\" },\n  \"peerDependenciesMeta\": { \"prettier\": { \"optional\": true } },\n}\n```\n\n```typescript\n// src/index.ts\nimport { createServer } from \"express-zod-api\"; // OK\nimport { join } from \"node:fs\"; // OK\nimport { helper } from \"./tools\"; // OK\nimport { factory } from \"typescript\"; // Error: Only 'import type' syntax is allowed for typescript.\nimport { format } from \"prettier\"; // Error: Only 'import type' syntax is allowed for prettier.\nimport fancyFn from \"unlisted-module\"; // Error: Importing unlisted-module is not allowed.\n```\n\n## Relationships and differences\n\n- Unlike `@typescript-eslint/no-restricted-imports` rule, it allows you to configure what can be imported, and not what\n  cannot, and not specifically, but by category.\n- Unlike `no-extraneous-dependencies` of `eslint-plugin-import` plugin, it supports ESLint 9 and its flat config.\n- Unlike same rule of `eslint-plugin-import-x` plugin, it does not require to install a typescript resolver to operate.\n- The plugin also supports reading multiple `package.json`.\n\n# Quick start\n\n## Requirements\n\n- Node.js `^20.19.0 || ^22.12.0 || ^24.0.0`\n- `eslint@^9.0.0`\n- `typescript-eslint@^8.0.0`\n\n## Installation\n\n```shell\nyarn add --dev eslint-plugin-allowed-dependencies\n```\n\n## Setup\n\n```javascript\n// eslint.config.js or .mjs if you're developing in CommonJS environment\nimport jsPlugin from \"@eslint/js\";\nimport tsPlugin from \"typescript-eslint\";\nimport allowedDepsPlugin from \"eslint-plugin-allowed-dependencies\";\n\nexport default [\n  {\n    plugins: {\n      allowed: allowedDepsPlugin,\n    },\n  },\n  jsPlugin.configs.recommended,\n  ...tsPlugin.configs.recommended,\n  // For the sources:\n  {\n    files: [\"src/**/*.ts\"], // implies that \"src\" only contains the sources\n    rules: {\n      \"allowed/dependencies\": \"error\",\n    },\n  },\n  // In case \"src\" also contains tests:\n  // {\n  //  files: [\"src/**/*.spec.ts\"], // exclude test files\n  //  rules: { \"allowed/dependencies\": \"off\" },\n  // },\n];\n```\n\n# Configuration\n\n## Options\n\nSupply the options this way:\n\n```json5\n{\n  rules: {\n    \"allowed/dependencies\": [\n      \"error\", // these are defaults:\n      {\n        packageDir: \".\",\n        production: true,\n        requiredPeers: true,\n        optionalPeers: \"typeOnly\",\n        development: \"typeOnly\",\n        typeOnly: [],\n        ignore: [\"^\\\\.\", \"^node:\"],\n      },\n      // {...} — you can add more (workspaces?)\n    ],\n  },\n}\n```\n\nBy default, the plugin is configured for checking the source code based on the `package.json` located in the current\nworking directory of the ESLint process. Production dependencies and mandatory peers are allowed to import,\nbut optional peers and development modules are allowed to be imported only as types.\n\n```yaml\npackageDir:\n  description: The path having your package.json\n  type: string\n  default: ctx.cwd # ESLint process.cwd()\n\nproduction:\n  description: Allow importing the packages listed in manifest.dependencies\n  type:\n    - boolean\n    - \"typeOnly\"\n  default: true\n\nrequiredPeers:\n  description: Allow importing the non-optional packages listed in manifest.peerDependencies\n  type:\n    - boolean\n    - \"typeOnly\"\n  default: true\n\noptionalPeers:\n  description: Allow importing the packages marked as optional in manifest.peerDependenciesMeta\n  type:\n    - boolean\n    - \"typeOnly\"\n  default: \"typeOnly\"\n\ndevelopment:\n  description: Allow importing the packages listed in manifest.devDependencies\n  type:\n    - boolean\n    - \"typeOnly\"\n  default: \"typeOnly\"\n\ntypeOnly:\n  description: Extra packages to allow type only imports\n  type: string[]\n  default: []\n\nignore:\n  description: List of patterns to ignore in the import statements\n  type: string[]\n  default:\n    - \"^\\\\.\" # relative paths (starts with a dot)\n    - \"^node:\" # built-in modules (prefixed with \"node:\")\n```\n\n## packageDir option\n\nIf you're using workspaces or somehow running ESLint from different locations, you'd need an absolute path:\n\n```javascript\n// for CommonJS:\nconst options = {\n  packageDir: __dirname,\n};\n```\n\n```javascript\n// for ESM:\nimport { fileURLToPath } from \"node:url\";\nimport { dirname } from \"node:path\";\n\nconst options = {\n  packageDir: dirname(fileURLToPath(import.meta.url)),\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobintail%2Fallowed-dependencies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobintail%2Fallowed-dependencies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobintail%2Fallowed-dependencies/lists"}