Skip to content

build: Check for circular deps with madge #3631

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

Merged
merged 13 commits into from
Jun 7, 2021
Merged

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Jun 1, 2021

Madge (https://www.npmjs.com/package/madge) is a library that can
traverse module dependency trees to check for circular dependencies.

We can leverage it using madge --circular /path/to/index.ts to make
sure that our packages don't contain circular deps. On average madge
takes around 2-3 sec per run, so we are not sacrificing a ton of CI time.

@AbhiPrasad AbhiPrasad requested a review from HazAT June 1, 2021 12:40
@AbhiPrasad AbhiPrasad requested a review from kamilogorek as a code owner June 1, 2021 12:40
@AbhiPrasad AbhiPrasad changed the title build: Add build: Check for circular deps with madge Jun 1, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Jun 1, 2021

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 20.83 KB (+0.01% 🔺)
@sentry/browser - Webpack 21.72 KB (-1.63% 🔽)
@sentry/react - Webpack 21.75 KB (-1.63% 🔽)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 28.22 KB (-0.03% 🔽)

@kamilogorek
Copy link
Contributor

If a dependency is shared (like in this case), it can live in the root package.json, as we are using yarn which can resolve it correctly.

@AbhiPrasad
Copy link
Member Author

If a dependency is shared (like in this case), it can live in the root package.json, as we are using yarn which can resolve it correctly.

Fixed

@lobsterkatie
Copy link
Member

On average madge takes around 2-3 sec per run, so we are not sacrificing a ton of CI time.

Given that it's its own job and that nothing depends on it, it should be able to run in parallel, so it actually shouldn't add any time to CI.

@AbhiPrasad
Copy link
Member Author

Turning this into a bigger feature branch and merging in other PRs here.

@AbhiPrasad AbhiPrasad marked this pull request as draft June 1, 2021 18:46
@AbhiPrasad AbhiPrasad force-pushed the abhi/circular-dep branch 6 times, most recently from 679e99a to 80f3962 Compare June 3, 2021 14:00
AbhiPrasad added 10 commits June 3, 2021 11:01
Madge (https://www.npmjs.com/package/madge) is a library that can
traverse module dependency trees to check for circular dependencies.

We can leverage it using `madge --circular /path/to/index.ts` to make
sure that our packages don't contain circular deps. On average madge
takes around 2-3 sec, so we are not sacrificing a ton of CI time.
When running madge on `@sentry/node`:

$ madge --circular src/index.ts
Processed 10 files (698ms) (8 warnings)

✖ Found 1 circular dependency!

1) backend.ts > parsers.ts

To remove the circular relationship between backend and parsers,
we extract the NodeOptions type into a separate types.ts file.
```
$ madge --circular src/index.ts
Processed 5 files (1s) (2 warnings)

✖ Found 2 circular dependencies!

1) hub.ts > interfaces.ts
```

To remove this, the interface.ts was removed and all of it's
types were moved into hub.ts
```
yarn run v1.22.5
$ madge --circular src/index.ts
Processed 5 files (1s) (2 warnings)

✖ Found 1 circular dependency!

1) hub.ts > interfaces.ts > scope.ts > session.ts
```

To remove this circular dep, we extract the SessionFlusher
from session.ts into it's own file.
```
yarn run v1.22.5
$ madge --circular src/index.client.ts && madge --circular src/index.server.ts
Processed 5 files (794ms) (7 warnings)

✔ No circular dependency found!

Processed 7 files (798ms) (9 warnings)

✖ Found 1 circular dependency!

1) index.server.ts > utils/handlers.ts > utils/instrumentServer.ts
```

To remove the circular dependency between index.server.ts and
utils/instrumentServer.ts, we rely on importing Sentry func (like
startTransaction and captureException) from `@sentry/node` directly.
No need to check types files as they are not needed
@AbhiPrasad AbhiPrasad force-pushed the abhi/circular-dep branch from bbc5691 to e07e07c Compare June 3, 2021 15:01
@AbhiPrasad
Copy link
Member Author

Squashed, rebased commits. Each commit should be fairly self explanatory in terms of changes.

@AbhiPrasad AbhiPrasad marked this pull request as ready for review June 3, 2021 15:03
Copy link
Member

@lobsterkatie lobsterkatie left a comment

Choose a reason for hiding this comment

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

Good change!

@lobsterkatie
Copy link
Member

You might check in with @k-fish about the failing ember test. I'm pretty sure the way it's failing is the same way it failed once before on a PR of mine, and he was able to figure out what the issue was and fix it.

@lobsterkatie
Copy link
Member

Oh, tiny nit for future:

To remove this circular dep, we extract the SessionFlusher
from session.ts into it's own file.

To remove this, the interface.ts was removed and all of it's
types were moved into hub.ts

s/it's/its

@k-fish
Copy link
Member

k-fish commented Jun 3, 2021

@lobsterkatie ah right, we did see this before briefly, I think this one might be a flake though. It checks the exact spans that are sent for a pageload, and is just dropping the post render runloop spans, which makes sense if the transaction is wrapping up early. Since it could be a flake unique to how we are testing, I'd first try re-running for now. Just dm me if it continues to fail and I'll look into fixing it.

@AbhiPrasad AbhiPrasad force-pushed the abhi/circular-dep branch from ddf9ced to 3a03a7f Compare June 7, 2021 12:09
@AbhiPrasad AbhiPrasad enabled auto-merge (squash) June 7, 2021 13:12
@AbhiPrasad AbhiPrasad merged commit 4917804 into master Jun 7, 2021
@AbhiPrasad AbhiPrasad deleted the abhi/circular-dep branch June 7, 2021 13:16
@lobsterkatie
Copy link
Member

Thanks, @k-fish! Will let you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants