Skip to content

Commit

Permalink
build: track circular dependency in the codebase (#29811)
Browse files Browse the repository at this point in the history
## **Description**

This PR introduces circular dependency detection, tracking, and
CODEOWNERS.

Here are the key changes:

1. Added a new circular dependency detection system:
- New script `development/circular-deps.ts` that uses `madge` to detect
circular dependencies
   - New config file `.madgerc` for TypeScript-specific settings
- Generated baseline file `development/circular-deps.json` containing
current circular dependencies

2. Added new yarn scripts in `package.json`:
- `yarn circular-deps:check` - Verifies circular dependencies match
baseline
- `yarn circular-deps:update` - Updates baseline with current circular
dependencies

3. Added CI integration:
- Added `.github/workflows/test-circular-deps.yml` to run circular
dependency check

4. Assigning appropriate CODEOWNERS to `circular-deps.jsonc`

The PR essentially sets up a process to track new circular dependencies
while acknowledging existing ones in the codebase.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29811?quickstart=1)

## **Related issues**

* Fixes: MetaMask/MetaMask-planning#3088

## **Manual testing steps**

1. Remove (or add) a circular dependency in the code.
2. Run `yarn circular-deps:check` => should report that codebase is out
of sync with `circular-deps.jsonc`
3. Run `yarn circular-deps:update` => should update
`circular-deps.jsonc` to match the codebase. Inspect the diff.
4. Run `yarn circular-deps:check` => should pass.

## **Screenshots/Recordings**
## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: MetaMask Bot <[email protected]>
Co-authored-by: Howard Braham <[email protected]>
  • Loading branch information
3 people authored Feb 3, 2025
1 parent b9d63a4 commit c89f440
Show file tree
Hide file tree
Showing 11 changed files with 1,094 additions and 360 deletions.
5 changes: 5 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ offscreen/scripts/offscreen.ts @MetaMask/snaps-devs
# make all such communication opt IN versus opt OUT.
privacy-snapshot.json @MetaMask/extension-privacy-reviewers


# A machine-generated file that tracks circular dependencies in the codebase.
# It is updated using yarn circular-deps:update
development/circular-deps.jsonc @MetaMask/extension-security-team @HowardBraham @dbrans

# The CODEOWNERS file constitutes an agreement amongst organization
# admins and maintainers to restrict approval capabilities to a subset
# of contributors. Modifications to this file result in a modification of
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ jobs:
name: Test lint
uses: ./.github/workflows/test-lint.yml

test-circular-deps:
name: Test circular deps
uses: ./.github/workflows/test-circular-deps.yml

test-lint-changelog:
name: Test lint changelog
uses: ./.github/workflows/test-lint-changelog.yml
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/test-circular-deps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Test Circular Dependencies

on:
workflow_call:

jobs:
test-circular-deps:
name: Test circular dependencies
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup environment
uses: metamask/github-tools/.github/actions/setup-environment@main

- name: Check circular dependencies
run: yarn circular-deps:check
15 changes: 15 additions & 0 deletions .madgerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"detectiveOptions": {
"es6": {
"skipTypeImports": true
},
"ts": {
"skipTypeImports": true,
"skipAsyncImports": true
},
"tsx": {
"skipTypeImports": true,
"skipAsyncImports": true
}
}
}
Loading

0 comments on commit c89f440

Please sign in to comment.