Skip to content

Commit b061496

Browse files
authored
chore: 🤖 add circular dependency safe guards (#864)
* chore: 🤖 add script for circular dependency check * chore: 🤖 declare circular-dependency:check script * docs: 📝 add circular dependency check section * chore: 🤖 add changeset * chore: 🤖 add circular dependency check to pre-commit hook * chore: 🤖 add circular dep check to code-quality workflow ci/cd * chore: 🤖 update lockfile * chore: 🤖 update changeset (fix incorrect name) * fix: 🐛 skott cmd call * chore: 🤖 code review suggestions
1 parent 71fb216 commit b061496

File tree

7 files changed

+1029
-41
lines changed

7 files changed

+1029
-41
lines changed

.changeset/nine-queens-allow.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
'@clickhouse/click-ui': patch
3+
---
4+
5+
Add circular dependency check to prevent and detect circular import cycles that can cause build issues, runtime errors, and bundle size problems.
6+
7+
## How to use?
8+
9+
Run the circular dependency check:
10+
11+
```sh
12+
yarn circular-dependency:check
13+
```
14+
15+
The command analyzes the source code starting from the `src` directory and reports any circular dependencies found.
16+
17+
To check a specific entry point:
18+
19+
```sh
20+
yarn circular-dependency:check src/components
21+
```
22+
23+
If circular dependencies are detected, the output will show the file paths involved in the cycle, helping you identify which imports need to be refactored to break the dependency chain.

.github/workflows/code-quality.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ jobs:
3030

3131
- name: Formatter
3232
run: yarn format
33+
34+
- name: Circular Dependencies
35+
run: yarn circular-dependency:check

.husky/pre-commit

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ else
3131
exit 1
3232
fi
3333

34+
if yarn circular-dependency:check; then
35+
echo "✅ Circular dependency check is good!"
36+
else
37+
echo "⚠️ WARNING: Circular dependency checkup found issues, fix them before committing, please!"
38+
echo "💡 Use the following command to get further reports in your resolution yarn circular-dependency:check"
39+
exit 1
40+
fi
41+
3442
if yarn changeset:verify; then
3543
echo "✅ Changeset file's included!"
3644
else
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
ENTRY_POINT="${1:-src}"
4+
5+
IGNORE_PATTERNS="node_modules/**,**/*.stories.tsx,**/*.stories.ts,**/*.test.ts,**/*.test.tsx"
6+
7+
echo "🔍 Checking for circular dependencies in $ENTRY_POINT..."
8+
echo ""
9+
10+
TEMP_OUTPUT=$(mktemp)
11+
trap 'rm -f "$TEMP_OUTPUT"' EXIT
12+
13+
if command -v yarn &> /dev/null; then
14+
yarn exec skott "$ENTRY_POINT" \
15+
--displayMode=file-tree \
16+
--showCircularDependencies \
17+
--ignorePattern="$IGNORE_PATTERNS" \
18+
--exitCodeOnCircularDependencies=1 > "$TEMP_OUTPUT" 2>&1 || true
19+
else
20+
echo "👹 Oops! The package skott is missing, have you installed the project dependencies?"
21+
22+
exit 1
23+
fi
24+
25+
if grep -q "✖.*circular dependencies found" "$TEMP_OUTPUT"; then
26+
echo "❌ Circular dependencies detected!"
27+
echo ""
28+
grep -A 1000 "✖.*circular dependencies found" "$TEMP_OUTPUT" | head -100
29+
echo ""
30+
echo "💡 To fix these issues, review the files listed above."
31+
32+
exit 1
33+
elif grep -q "✓.*no circular dependencies found" "$TEMP_OUTPUT"; then
34+
echo "✅ No circular dependencies found!"
35+
36+
exit 0
37+
else
38+
echo "⚠️ Warning: Could not determine circular dependency status from skott output"
39+
cat "$TEMP_OUTPUT"
40+
41+
exit 1
42+
fi

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ You can find the official docs for the Click UI design system and component libr
2222
* [Development](#development)
2323
- [Generating design tokens](#generating-design-tokens)
2424
- [Local development](#local-development)
25+
- [Circular dependency check](#circular-dependency-check)
2526
* [Tests](#Tests)
2627
- [Functional tests](#functional-tests)
2728
- [Visual regression tests](#visual-regression-tests)
@@ -96,6 +97,16 @@ After cloning the repository change to the work directory and install the depend
9697
yarn
9798
```
9899

100+
### Circular dependency check
101+
102+
Check for circular dependencies that can cause build and runtime issues:
103+
104+
```sh
105+
yarn circular-dependency:check
106+
```
107+
108+
If circular dependencies are found it'll exit with a report showing the affeced files which require your attention.
109+
99110
### Generating design tokens
100111

101112
Tokens are provided by a style directionary sourced from [tokens-studio](https://tokens.studio/).

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@
322322
"changeset:add": "yarn changeset",
323323
"changeset:status": "yarn changeset status",
324324
"changeset:verify": ".scripts/bash/changeset-verification",
325+
"circular-dependency:check": ".scripts/bash/circular-dependency-check",
325326
"changeset:version": "yarn changeset version",
326327
"convert:logo": ".scripts/convert-svg-to-react-component --type=logos",
327328
"convert:icon": ".scripts/convert-svg-to-react-component --type=icons",
@@ -418,6 +419,7 @@
418419
"react": "18.3.1",
419420
"react-dom": "18.3.1",
420421
"rollup-plugin-visualizer": "^6.0.5",
422+
"skott": "^0.35.4",
421423
"storybook": "^10.1.10",
422424
"storybook-addon-pseudo-states": "^10.1.10",
423425
"style-dictionary": "^5.0.0",

0 commit comments

Comments
 (0)