Skip to content

Commit

Permalink
ci: skip type imports when checking circular dependencies (#30080)
Browse files Browse the repository at this point in the history
Skip type imports when checking circular dependencies.

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.


## **Description**



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

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**


### **Before**


### **After**

## **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.
-->
  • Loading branch information
davidmurdoch authored Feb 6, 2025
1 parent 63afa20 commit 6332ad8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 65 deletions.
12 changes: 12 additions & 0 deletions .madgerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
{
"excludeRegExp": [
"/.[^/]*\/test\/.[^/]*/u",
"/.[^/]*\/tests\/.[^/]*/u",
"/.[^/]*\/[^/]*.test.[^/]*/u",
"/.[^/]*\/[^/]*.spec.[^/]*/u",
"/.[^/]*\/stories\/.[^/]*/u",
"/.[^/]*\/storybook\/.[^/]*/u",
"/.[^/]*\/[^/]*.stories.[^/]*/u"
],
"fileExtensions": ["js", "jsx", "ts", "tsx"],
"tsConfig": "tsconfig.json",
"webpackConfig": "webpack.config.js",
"detectiveOptions": {
"es6": {
"skipTypeImports": true
Expand Down
57 changes: 12 additions & 45 deletions development/circular-deps.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@
"app/scripts/controllers/bridge-status/utils.ts",
"app/scripts/controllers/bridge-status/validators.ts"
],
[
"app/scripts/controllers/bridge/bridge-controller.ts",
"app/scripts/controllers/bridge/types.ts"
],
[
"app/scripts/controllers/swaps/index.ts",
"app/scripts/controllers/swaps/swaps.constants.ts",
"app/scripts/controllers/swaps/swaps.types.ts"
],
[
"app/scripts/controllers/swaps/swaps.constants.ts",
"app/scripts/controllers/swaps/swaps.types.ts"
],
[
"app/scripts/lib/transaction/metrics.ts",
"shared/modules/metametrics.ts"
Expand Down Expand Up @@ -151,68 +138,48 @@
],
[
"ui/components/component-library/avatar-account/avatar-account.tsx",
"ui/components/component-library/avatar-account/avatar-account.types.ts",
"ui/components/component-library/avatar-account/index.ts",
"ui/components/component-library/avatar-base/avatar-base.types.ts",
"ui/components/component-library/avatar-base/avatar-base.tsx",
"ui/components/component-library/avatar-base/index.ts",
"ui/components/component-library/index.ts",
"ui/components/component-library/text/index.ts",
"ui/components/component-library/text/text.tsx"
],
[
"ui/components/component-library/badge-wrapper/badge-wrapper.tsx",
"ui/components/component-library/badge-wrapper/badge-wrapper.types.ts",
"ui/components/component-library/badge-wrapper/index.ts",
"ui/components/component-library/index.ts"
],
[
"ui/components/component-library/badge-wrapper/badge-wrapper.tsx",
"ui/components/component-library/badge-wrapper/index.ts",
"ui/components/component-library/index.ts"
],
[
"ui/components/component-library/banner-alert/banner-alert.tsx",
"ui/components/component-library/banner-alert/banner-alert.types.ts",
"ui/components/component-library/banner-alert/index.ts",
"ui/components/component-library/banner-base/banner-base.types.ts",
"ui/components/component-library/button-base/button-base.tsx",
"ui/components/component-library/button-base/index.ts",
"ui/components/component-library/button-link/button-link.tsx",
"ui/components/component-library/button-link/index.ts",
"ui/components/component-library/banner-base/banner-base.tsx",
"ui/components/component-library/banner-base/index.ts",
"ui/components/component-library/index.ts"
],
[
"ui/components/component-library/banner-alert/banner-alert.tsx",
"ui/components/component-library/banner-alert/banner-alert.types.ts",
"ui/components/component-library/banner-alert/index.ts",
"ui/components/component-library/banner-base/banner-base.types.ts",
"ui/components/component-library/button-icon/button-icon.tsx",
"ui/components/component-library/button-icon/index.ts",
"ui/components/component-library/index.ts"
],
[
"ui/components/component-library/banner-alert/banner-alert.tsx",
"ui/components/component-library/banner-alert/banner-alert.types.ts",
"ui/components/component-library/banner-alert/index.ts",
"ui/components/component-library/banner-base/banner-base.types.ts",
"ui/components/component-library/button-link/button-link.tsx",
"ui/components/component-library/button-link/index.ts",
"ui/components/component-library/banner-tip/banner-tip.tsx",
"ui/components/component-library/banner-tip/index.ts",
"ui/components/component-library/index.ts"
],
[
"ui/components/component-library/banner-alert/banner-alert.tsx",
"ui/components/component-library/banner-alert/index.ts",
"ui/components/component-library/banner-base/banner-base.tsx",
"ui/components/component-library/banner-base/index.ts",
"ui/components/component-library/button-base/button-base.tsx",
"ui/components/component-library/button-base/index.ts",
"ui/components/component-library/index.ts"
],
[
"ui/components/component-library/banner-alert/banner-alert.tsx",
"ui/components/component-library/banner-alert/index.ts",
"ui/components/component-library/button-icon/button-icon.tsx",
"ui/components/component-library/button-icon/index.ts",
"ui/components/component-library/index.ts"
],
[
"ui/components/component-library/banner-tip/banner-tip.tsx",
"ui/components/component-library/banner-tip/index.ts",
"ui/components/component-library/button-link/button-link.tsx",
"ui/components/component-library/button-link/index.ts",
"ui/components/component-library/index.ts"
],
[
Expand Down
22 changes: 2 additions & 20 deletions development/circular-deps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env tsx

import fs from 'fs';
import fs, { readFileSync } from 'fs';
import madge from 'madge';
import fg from 'fast-glob';

Expand Down Expand Up @@ -51,18 +51,6 @@ const ENTRYPOINT_PATTERNS = [
'ui/**/*', // UI components and styles
];

// Converts a glob pattern to a RegExp pattern
function globToRegExp(pattern: string): RegExp {
return new RegExp(
pattern
// Convert '**' to '.*' to match any characters.
.replace(/\*\*/gu, '.*')
// Convert '*' to '[^/]*' to match any characters except directory separators.
.replace(/\*/gu, '[^/]*'),
'u',
);
}

/**
* Circular dependencies are represented as an array of arrays, where each
* inner array represents a cycle of dependencies.
Expand All @@ -88,13 +76,7 @@ function normalizeJson(cycles: CircularDeps): CircularDeps {
}

// Common madge configuration
const MADGE_CONFIG = {
circular: true,
extensions: ['js', 'jsx', 'ts', 'tsx'],
excludeRegExp: IGNORE_PATTERNS.map(globToRegExp),
tsConfig: 'tsconfig.json',
webpackConfig: 'webpack.config.js',
};
const MADGE_CONFIG = JSON.parse(readFileSync('.madgerc', 'utf-8'));

async function getMadgeCircularDeps(): Promise<CircularDeps> {
console.log('Running madge to detect circular dependencies...');
Expand Down

0 comments on commit 6332ad8

Please sign in to comment.