{"id":21450945,"url":"https://github.com/soontao/cycle-import-check","last_synced_at":"2025-04-30T21:09:43.363Z","repository":{"id":41103759,"uuid":"137316527","full_name":"Soontao/cycle-import-check","owner":"Soontao","description":"JS module circular dependency check tool","archived":false,"fork":false,"pushed_at":"2025-04-30T15:13:00.000Z","size":1553,"stargazers_count":22,"open_issues_count":4,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-30T21:09:38.747Z","etag":null,"topics":["es6-javascript","import","static-check"],"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/Soontao.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,"zenodo":null}},"created_at":"2018-06-14T06:35:49.000Z","updated_at":"2025-04-30T15:13:05.000Z","dependencies_parsed_at":"2024-01-30T23:53:49.722Z","dependency_job_id":"50cab156-f3ab-4e17-85a0-c924e8aad87e","html_url":"https://github.com/Soontao/cycle-import-check","commit_stats":{"total_commits":228,"total_committers":8,"mean_commits":28.5,"dds":"0.42543859649122806","last_synced_commit":"a19a8efc1165428deb40e53345cdb9d6403dd826"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soontao%2Fcycle-import-check","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soontao%2Fcycle-import-check/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soontao%2Fcycle-import-check/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soontao%2Fcycle-import-check/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Soontao","download_url":"https://codeload.github.com/Soontao/cycle-import-check/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251782775,"owners_count":21642987,"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":["es6-javascript","import","static-check"],"created_at":"2024-11-23T04:17:16.208Z","updated_at":"2025-04-30T21:09:43.339Z","avatar_url":"https://github.com/Soontao.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003cimg src='https://res.cloudinary.com/digf90pwi/image/upload/c_scale,w_68/v1529163036/cycle_bscatc.png' style=\"height: 1.2rem\"\u003e cycle-import-check\n\n\u003e circular dependency check tool for javascript modules\n\n[![Multi-Version Test](https://github.com/Soontao/cycle-import-check/workflows/Multi-Version%20Test/badge.svg)](https://github.com/Soontao/cycle-import-check/actions?query=workflow%3A%22Multi-Version+Test%22)\n[![codecov](https://codecov.io/gh/Soontao/cycle-import-check/branch/master/graph/badge.svg)](https://codecov.io/gh/Soontao/cycle-import-check)\n[![npm](https://img.shields.io/npm/v/cycle-import-check)](https://www.npmjs.com/package/cycle-import-check)\n![node-lts](https://img.shields.io/node/v-lts/cycle-import-check)\n\nES6 circular import check tool, support `js`, `ts`, `jsx`, `tsx` and `mjs` files, and will ignore all `node_modules` files.\n\nSupport `import`, `export` keywords and `require()`, `import()` function now\n\n## Why do we need this tool ?\n\nIn javascript ES6 standard, people use `import` \u0026 `export` keyword in modules, but if js files circular import each other, some exported objects will be `undefined` in runtime.\n\nThe best practice is **one-way dependency**, and I wrote this tool to ensure no circular-dependency in projects.\n\n## Circular dependency sample project\n\nLet's look at a circular dependency example: \n\n\u003e file1.js\n\n```javascript\n// and console will be first triggered in file2\nimport { value2 } from \"./file2\"; \n// file2 is fully imported\nexport const value1 = \"value1\"\n// value2 is 'value2'\nconsole.log(\"value2 in file1: \" + value2) \nsetTimeout(() =\u003e {\n  // value2 is 'value2'\n  console.log(\"delay 200ms, value2 in file1: \" + value2)\n}, 200)\n\n// file1 is fully executed now\n```\n\n\u003e file2.js\n\n```javascript\nimport { value1 } from \"./file1\"; \n// file1 is not fully executed, just ref with cache\nexport const value2 = \"value2\"  \n// value1 is undefined\nconsole.log(\"value1 in file2: \" + value1) \nsetTimeout(() =\u003e {\n  // file1 is executed now\n  console.log(\"delay 200ms, value1 in file2: \" + value1) // value1 is 'value1'\n}, 200)\n\n```\n\n```bash\n\u003e babel-node --presets es2015 file1.js\n\nvalue1 in file2: undefined\nvalue2 in file1: value2\ndelay 200ms, value1 in file2: value1\ndelay 200ms, value2 in file1: value2\n\n```\n\nIf we only have two js files, it's easy to determine wether scripts have circular dependencies.\n\nHowever, if we have a large project with thousands of files, it's hard to do that.\n\nSo, this tool appeared, using old (but efficient) graph algorithms to check for circular dependency.\n\n## How to resolve circular dependency ?\n\nJust extract shared variables/functions into an independent file: \n\n`from`\n\n\n```mermaid\ngraph TD\n    file1.js --\u003e|value1| file2.js\n    file1.js --\u003e|value2| file2.js\n```\n\n`to`\n\n```mermaid\ngraph TD\n    file1.js --\u003e|value1| value.js\n    file2.js --\u003e|value2| value.js\n```\n\n\n## Usage\n\n```bash\nnpx cycle-import-check [a directory path]\n```\n\n\u003e detected\n\n```text\n\n\u003e iscan tests/testproject4\n\nCircular dependency existed in tests/testproject4\n\ncycle 1, size (2):\n\n  tests/testproject4/file2.js\n  tests/testproject4/file1.js\n\n```\n\n\u003e normal\n\n```text\n\n\u003e iscan tests/testproject2\n\nCongratulation! Not found circular dependency in tests/testproject2\n\n```\n\n## [CHANGELOG](./CHANGELOG.md)\n\n## [LICENSE (MIT)](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoontao%2Fcycle-import-check","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoontao%2Fcycle-import-check","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoontao%2Fcycle-import-check/lists"}