How to quickly identify Circular dependencies in React-Native
Asked Answered
D

1

6

In a React-Native project using NPM, is there a quick way to identify Dependency cycle problems (aka when lint gives out an error of "cycle dependency detected"?

I am looking for something similar to this: https://spin.atomicobject.com/2018/06/25/circular-dependencies-javascript/ (Or simple to follow instructions on how to use that plugin under react/npm)

Descartes answered 12/12, 2020 at 2:39 Comment(1)
I am trying to find something that works with react-native too, but maybe github.com/acrazing/dpdm can work with shellscript + husky, as this might throw and exit code when a circular dependency problem is found npx dpdm ./src/* --circular --exit-code circular:1 --warning falseSporogony
S
6

I currently use the dpdm lib to check for circular dependencies on the react-native project.

Example:

npx dpdm ./src/* --circular --exit-code circular:1 --warning=false

With error:

✔ [718/718] Analyze done!
• Circular Dependencies
  01) src/services/index.ts -> src/services/Rating/index.ts

No error:

✔ [719/719] Analyze done!
• Circular Dependencies
  ✅ Congratulations, no circular dependency were found in your project.

CircleCI script fails if any circular dependency is found:

check-circular-dependency:
executor:
  name: react-native/linux_js
  node_version: '14'
steps:
  - checkout-and-attach-workspace
  - run:
      name: Check for Circular dependency
      command: npx dpdm ./src/* --circular --exit-code circular:1 --warning=false --tree=false
Sporogony answered 17/5, 2021 at 21:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.