-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
base: main
Are you sure you want to change the base?
Conversation
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. |
Builds ready [d9391f4]
Page Load Metrics (1687 ± 73 ms)
Bundle size diffs
|
d9391f4
to
077da6a
Compare
New and updated dependencies detected. Learn more about Socket for GitHub ↗︎
|
Builds ready [8e2731e]
Page Load Metrics (1641 ± 64 ms)
Bundle size diffs
|
Builds ready [7ddc5bf]
Page Load Metrics (1558 ± 60 ms)
Bundle size diffs
|
@metamaskbot update-policies |
Policies updated. 🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff |
Builds ready [194c797]
Page Load Metrics (1744 ± 130 ms)
Bundle size diffs
|
Builds ready [a58a5c6]
Page Load Metrics (1609 ± 78 ms)
Bundle size diffs
|
Builds ready [45b07bd]
Page Load Metrics (1647 ± 91 ms)
Bundle size diffs
|
Builds ready [bbb63a1]
Page Load Metrics (2045 ± 121 ms)
Bundle size diffs
|
Builds ready [1b087ed]
Page Load Metrics (1658 ± 58 ms)
Bundle size diffs
|
@@ -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" |
There was a problem hiding this comment.
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 | ||
]; |
There was a problem hiding this comment.
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.
// 'development/', // Development scripts and utilities | ||
// 'test/', // Tests |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.
Builds ready [6fa08fb]
Page Load Metrics (1704 ± 87 ms)
Bundle size diffs
|
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
:User introduced a new circular dependency in a folder that isn't permitted:
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:
User introduced a file madge can't parse:
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
, runyarn circular-deps:update
, then runyarn 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 runyarn 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 addingimport '../ui/css/index.scss';
to/app/scripts/load/ui.ts
, then runningyarn circular-deps:update
.