Commit 58cd8e9
Ensure refs in tsconfig files are synced with internal deps (#8384)
### Problem
We use project references to tell TypeScript and other tools about the
structure of the monorepo. Both the root- and package-level tsconfig
files have a `references` field which is used to link packages together.
All packages that we want to build and publish need to be present in
`references` within the root `tsconfig.json` and `tsconfig.build.json`
files, and the `references` field in both root-level and package-level
tsconfig files need to list all internal dependencies.
However, it's a pain to keep references up to date, especially as as
packages are added or dependencies are updated. There are cases in the
past, in fact, where packages were not published or type errors occurred
because the references were not correctly kept in sync.
### Solution
We don't need to do this manual work. We can infer root references by
scanning workspaces, and we can infer references for an individual
package by scanning that package's `dependencies` for other workspace
packages.
This commit adds a script that can be run on both the root workspace and
child workspaces to check and/or regenerate the `references` field for
each tsconfig file so that it is kept in sync with dependencies
throughout the monorepo. There are also new package scripts for use:
- Root level
- **`lint:tsconfigs`:** Validates the root `tsconfig.json` and
`tsconfig.build.json`, erroring if any are out of sync.
- **`lint:tsconfigs:all`:** Validates all `tsconfig.json` and
`tsconfig.build.json` across the monorepo, erroring if any are out of
sync.
- **`lint:tsconfigs:fix`:** Regenerates the root `tsconfig.json` and
`tsconfig.build.json`.
- **`lint:tsconfigs:fix:all`:** Regenerates `tsconfig.json` and
`tsconfig.build.json` files across the monorepo.
- Package level
- **`lint:tsconfigs`:** Validates `tsconfig.json` and
`tsconfig.build.json` in the package, erroring if any are out of sync.
- **`lint:tsconfigs:fix`:** Regenerates `tsconfig.json` and
`tsconfig.build.json` in the package.
As the names indicate, tsconfig file validation is also a part of the
lint pipeline, so CI will now fail if any files are out of date. To make
sure this doesn't happen in the future, this commit also corrects
tsconfig files across the board to add missing references or remove
extra references.
### Why hand-roll a solution?
There are some existing solutions for syncing references within the
TypeScript community, some of which are documented in [this issue][1].
However, I reviewed them and rejected them for various reasons:
- **[`typescript-monorepo-toolkit`][2]:** Doesn't update references for
individual packages based on `dependencies`
- **[`update-ts-references`][3]:** Works, but re-sorts all references,
and drops the leading `./` from references in root tsconfig files; also,
generated files fail Prettier validation
-
**[`@monorepo-utils/workspaces-to-typescript-project-references`][4]:**
Works, but re-sorts all references, and drops the leading `./` from
references in root tsconfig files; also generated files fail Prettier
validation
My thought is that by building our own script, we get to control the
exact changes that are made to tsconfig files, and we get to run all
files through Oxfmt so that engineers do not have to reformat them
manually.
[1]: microsoft/TypeScript#25376
[2]: https://github.com/Bnaya/typescript-monorepo-toolkit
[3]: https://github.com/eBayClassifiedsGroup/update-ts-references
[4]:
https://github.com/azu/monorepo-utils/tree/master/packages/@monorepo-utils/workspaces-to-typescript-project-references
## References
<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?
For example:
* Fixes #12345
* Related to #67890
-->
Closes #966.
Also closes https://consensyssoftware.atlassian.net/browse/WPC-649.
## Checklist
- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them
---------
Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>1 parent b3c1c37 commit 58cd8e9
193 files changed
Lines changed: 2246 additions & 387 deletions
File tree
- .github/workflows
- packages
- account-tree-controller
- accounts-controller
- address-book-controller
- ai-controllers
- analytics-controller
- analytics-data-regulation-controller
- announcement-controller
- app-metadata-controller
- approval-controller
- assets-controllers
- assets-controller
- authenticated-user-storage
- base-controller
- base-data-service
- bitcoin-regtest-up
- bridge-controller
- bridge-status-controller
- build-utils
- chain-agnostic-permission
- chomp-api-service
- claims-controller
- client-controller
- client-utils
- compliance-controller
- composable-controller
- config-registry-controller
- connectivity-controller
- controller-utils
- core-backend
- delegation-controller
- earn-controller
- eip-5792-middleware
- eip-7702-internal-rpc-middleware
- eip1193-permission-middleware
- ens-controller
- eth-block-tracker
- eth-json-rpc-middleware
- eth-json-rpc-provider
- foundryup
- gas-fee-controller
- gator-permissions-controller
- geolocation-controller
- java-tron-up
- json-rpc-engine
- json-rpc-middleware-stream
- keyring-controller
- local-node-utils
- logging-controller
- message-manager
- messenger-cli
- messenger
- money-account-api-data-service
- money-account-balance-service
- money-account-controller
- money-account-upgrade-controller
- multichain-account-service
- multichain-api-middleware
- multichain-network-controller
- multichain-transactions-controller
- name-controller
- network-connection-banner-controller
- network-controller
- network-enablement-controller
- notification-services-controller
- passkey-controller
- permission-controller
- src
- permission-log-controller
- perps-controller
- src
- phishing-controller
- platform-api-docs
- polling-controller
- preferences-controller
- profile-metrics-controller
- profile-sync-controller
- ramps-controller
- rate-limit-controller
- react-data-query
- remote-feature-flag-controller
- sample-controllers
- seedless-onboarding-controller
- selected-network-controller
- shield-controller
- signature-controller
- smart-transactions-controller
- snap-account-service
- social-controllers
- solana-test-validator-up
- stellar-quickstart-up
- storage-service
- subscription-controller
- transaction-controller
- transaction-pay-controller
- user-operation-controller
- wallet-cli
- wallet-framework-docs
- wallet
- scripts/lint-tsconfigs
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
378 | 378 | | |
379 | 379 | | |
380 | 380 | | |
| 381 | + | |
381 | 382 | | |
382 | 383 | | |
383 | 384 | | |
| |||
412 | 413 | | |
413 | 414 | | |
414 | 415 | | |
| 416 | + | |
415 | 417 | | |
416 | 418 | | |
417 | 419 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
120 | | - | |
| 119 | + | |
121 | 120 | | |
122 | 121 | | |
| 122 | + | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
16 | 25 | | |
17 | 26 | | |
18 | 27 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
15 | 22 | | |
16 | 23 | | |
17 | 24 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
0 commit comments