Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: enable circular dep linting #30148

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open

Conversation

davidmurdoch
Copy link
Contributor

@davidmurdoch davidmurdoch commented Feb 6, 2025

Note to QA testers. This file does not change runtime behavior. It is a linting tool only. You do not need to test it for a release.


This PR prevents circular dependencies from being added to our codebase in the specified directories (see .madgerc).

It also fixes an issue with our previous version of this check. The previous version ignored many files, because it tried to use a non-existent webpack config. We no longer use the webpackConfig option (it doesn't do anything for us anyway), and we now have an additional check to ensure we do not skip tracking any imported files.

We now check a list of folders that are allowed to have circular dependencies. If a circular dependency is added that it not allowed, the [check](circular-deps:check) job fails, even if it was added to the ./development/circular-deps.jsonc file.

It also does a check to make sure that all "allowed" files/folders actually have circular dependencies within them. If a user removes the last circular dependency from an "allowed" file/folder, the check fails (with a celebratory message and instructions on how to resolve the issue).

Example failure outputs for yarn circular-deps:check:

User needs to run yarn circular-deps:update:

image

User introduced a new circular dependency in a folder that isn't permitted:

image

User removed the last circular dependency in a file/folder that is allowed circular dependencies. They need to remove the allowed folder/file from .madgerc:

image

User introduced a file madge can't parse:

image

There is currently no good resolution for this error. We may need to add a way of working around this in the future. This check exists to ensure we don't skip any circular dependencies again.


Note: behavior of yarn circular-deps:update is not changed; it still only tracks circular deps, it doesn't care about our "allowed" directories or "skipped" files.

To test:

To trigger the new "New circular dependencies issues were found in disallowed folders" error:

Remove any folder/file in the allowedCircularGlob array in .madgerc, run yarn circular-deps:update, then run yarn circular-deps:check to generate the new error message.

To trigger the new "The following allowed circular dependency patterns do not match any files" check:

Add a new file/folder (it doesn't need to exist) to the allowedCircularGlob array in .madgerc then run yarn circular-deps:check to generate the new error message.

To trigger the new "✖ Skipped files found" error:

Add an import to a file that madge can't parse, like a scss file (import '../ui/css/index.scss';). You can test this by adding import '../ui/css/index.scss'; to /app/scripts/load/ui.ts, then running yarn circular-deps:update.

Copy link
Contributor

github-actions bot commented Feb 6, 2025

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-extension-platform Extension Platform team label Feb 6, 2025
@metamaskbot
Copy link
Collaborator

Builds ready [d9391f4]
Page Load Metrics (1687 ± 73 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint14952141168114971
domContentLoaded14492124165615072
load14972145168715373
domInteractive23663094
backgroundConnect1079342512
firstReactRender1674382411
getState5481194
initialActions01000
loadScripts10591659120513163
setupStore764192010
uiStartup17002380191416780
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@davidmurdoch davidmurdoch force-pushed the enable-circular-dep-lint branch from d9391f4 to 077da6a Compare February 13, 2025 21:43
Copy link

socket-security bot commented Feb 13, 2025

New and updated dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@types/[email protected] None 0 6.57 kB types
npm/@types/[email protected] None 0 25.1 kB types
npm/[email protected] 🔁 npm/[email protected] None 0 44.6 kB jonschlinkert
npm/[email protected] 🔁 npm/[email protected] None 0 16.7 kB jonschlinkert
npm/[email protected] 🔁 npm/[email protected] None 0 56.6 kB doowb

View full report↗︎

@metamaskbot
Copy link
Collaborator

Builds ready [8e2731e]
Page Load Metrics (1641 ± 64 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint15201968164912761
domContentLoaded14781947161412862
load15091973164113364
domInteractive2199392411
backgroundConnect867322311
firstReactRender1470352411
getState4361074
initialActions01000
loadScripts9861455116510953
setupStore76816188
uiStartup16902270185614168
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [7ddc5bf]
Page Load Metrics (1558 ± 60 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint14101947156212962
domContentLoaded1396175315208239
load14111945155812560
domInteractive226833147
backgroundConnect9468419948
firstReactRender14100402612
getState45113157
initialActions01000
loadScripts982134810958139
setupStore774252612
uiStartup16122285180917785
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@davidmurdoch
Copy link
Contributor Author

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated.
👀 Please review the diff for suspicious new powers.

🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff

@metamaskbot
Copy link
Collaborator

Builds ready [194c797]
Page Load Metrics (1744 ± 130 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint46126181650356171
domContentLoaded147025041721266128
load148025191744271130
domInteractive24138412814
backgroundConnect107025189
firstReactRender1488372613
getState590152110
initialActions01000
loadScripts104919121254217104
setupStore790252512
uiStartup173329102004303146
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [a58a5c6]
Page Load Metrics (1609 ± 78 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint33717381523289139
domContentLoaded13672156157015876
load13902192160916278
domInteractive237832147
backgroundConnect9148433216
firstReactRender136321126
getState45918178
initialActions00000
loadScripts9611600113412861
setupStore757232010
uiStartup15952525183020096
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [45b07bd]
Page Load Metrics (1647 ± 91 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint48919481555279134
domContentLoaded14242207162119091
load14292224164718991
domInteractive24186493919
backgroundConnect107331168
firstReactRender1472332211
getState565252211
initialActions01000
loadScripts10131779120117584
setupStore75715147
uiStartup16522390187620297
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [bbb63a1]
Page Load Metrics (2045 ± 121 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint28425911770623299
domContentLoaded155725582000256123
load160926262045253121
domInteractive309145168
backgroundConnect1299512612
firstReactRender1577352110
getState76421168
initialActions01000
loadScripts11511954150920598
setupStore86521189
uiStartup179130762340309148
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@davidmurdoch davidmurdoch marked this pull request as ready for review February 25, 2025 17:34
@davidmurdoch davidmurdoch requested review from HowardBraham, dbrans and a team as code owners February 25, 2025 17:34
@metamaskbot
Copy link
Collaborator

Builds ready [1b087ed]
Page Load Metrics (1658 ± 58 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint40419741585297143
domContentLoaded15161965163211957
load15301976165812158
domInteractive157041178
backgroundConnect9109262311
firstReactRender1474392512
getState46412157
initialActions01000
loadScripts1067137211949345
setupStore77116199
uiStartup17122124187912359
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@@ -1,8 +1,18 @@
#!/usr/bin/env tsx
#!/usr/bin/env -S node --require "./node_modules/tsx/dist/preflight.cjs" --import "./node_modules/tsx/dist/loader.mjs"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really necessary, but this is how tsx is used in some of our other modules (in webpack). Only reason for doing it this way is that it is slightly faster.

We don't actually need it here (or in webpack), since we aren't launching these scripts directly. I guess it's more of a "technically correct" than actually useful.

In otherwords: it is safe to ignore this change, safe to revert it to the way it was, and even safe to remove the line complete.

'app/**/*', // Main application code
'shared/**/*', // Shared utilities and components
'ui/**/*', // UI components and styles
];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ENTRYPOINT_PATTERNS are just directories now, not globs, with no filters (IGNORE_PATTERNS), as they aren't needed.

Comment on lines +60 to +61
// 'development/', // Development scripts and utilities
// 'test/', // Tests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to include these, but not necessary to see performance benefits.

import {
OffscreenCommunicationTarget,
TrezorAction,
} from 'shared/constants/offscreen-communication';
import type { Provider } from '@metamask/network-controller';
} from '../shared/constants/offscreen-communication';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, madge would find this file, and try to import this file, which doesn't exist at the given location, and would just ignore it (it marks it as skipped, which this PR no longer allows)

Side note: Our typescript lint process seems to ignore this file.

@metamaskbot
Copy link
Collaborator

Builds ready [6fa08fb]
Page Load Metrics (1704 ± 87 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint14362183170418187
domContentLoaded14252172166917986
load14392185170418187
domInteractive25123503416
backgroundConnect11103342612
firstReactRender147428189
getState56517189
initialActions01000
loadScripts10221606124114469
setupStore75320188
uiStartup160725331947208100
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-extension-platform Extension Platform team
Projects
Status: Needs dev review
Development

Successfully merging this pull request may close these issues.

2 participants