Skip to content

Commit cde6867

Browse files
chore: updating readme (#429)
## **Description** This PR fixes the dependency graph generation in the README.md by correcting the relationships between packages. Previously, the graph was showing incorrect dependencies, making every package appear as a dependency of each other. Specific changes: 1. Added correct dependency relationships 2. The dependency graph now accurately represents the actual package relationships in the monorepo This change ensures that the README's dependency graph is an accurate representation of the project's package structure, making it easier for developers to understand the relationships between different packages. ## **Related issues** Fixes: N/A ## **Manual testing steps** 1. Run `yarn update-readme-content` to generate the updated dependency graph 2. Verify that the new dependency relationships are correct ## **Screenshots/Recordings** ### **Before** The dependency graph showed incorrect relationships between packages. ![Screenshot 2025-02-12 at 4 22 24 PM](https://github.com/user-attachments/assets/605ad84d-60dc-40db-b2e5-a127ad52712e) ### **After** ![Screenshot 2025-02-12 at 4 21 40 PM](https://github.com/user-attachments/assets/f136746b-6cb5-4795-8a2c-21a067c56d26) ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.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.
1 parent c4c3f29 commit cde6867

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ linkStyle default opacity:0.5
3030
design_system_twrnc_preset(["@metamask/design-system-twrnc-preset"]);
3131
design_tokens(["@metamask/design-tokens"]);
3232
design_system_react --> design_system_tailwind_preset;
33+
design_system_react --> design_tokens;
3334
design_system_react_native --> design_system_twrnc_preset;
35+
design_system_tailwind_preset --> design_tokens;
36+
design_system_twrnc_preset --> design_tokens;
37+
design_tokens --> design_system_react;
3438
```
3539

3640
<!-- end dependency graph -->

scripts/update-readme-content.ts

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import path from 'path';
77
type Workspace = {
88
location: string;
99
name: string;
10-
workspaceDependencies: string[];
10+
dependencies: string[];
1111
};
1212

1313
const DEPENDENCY_GRAPH_START_MARKER = '<!-- start dependency graph -->';
@@ -56,7 +56,33 @@ async function retrieveWorkspaces(): Promise<Workspace[]> {
5656
'--verbose',
5757
]);
5858

59-
return stdout.split('\n').map((line) => JSON.parse(line));
59+
const workspaces = stdout.split('\n').map((line) => JSON.parse(line));
60+
61+
// Get actual dependencies for each workspace
62+
return Promise.all(
63+
workspaces.map(async (workspace) => {
64+
const packageJsonPath = path.join(
65+
process.cwd(),
66+
workspace.location,
67+
'package.json',
68+
);
69+
const packageJson = JSON.parse(
70+
await fs.promises.readFile(packageJsonPath, 'utf8'),
71+
);
72+
73+
// Collect all dependencies that are workspace packages
74+
const deps = [
75+
...Object.keys(packageJson.dependencies || {}),
76+
...Object.keys(packageJson.devDependencies || {}),
77+
...Object.keys(packageJson.peerDependencies || {}),
78+
].filter((dep) => dep.startsWith('@metamask/'));
79+
80+
return {
81+
...workspace,
82+
dependencies: deps,
83+
};
84+
}),
85+
);
6086
}
6187

6288
/**
@@ -99,16 +125,21 @@ function buildMermaidNodeLines(workspaces: Workspace[]): string[] {
99125
*/
100126
function buildMermaidConnectionLines(workspaces: Workspace[]): string[] {
101127
const connections: string[] = [];
128+
const workspacesByName = new Map(workspaces.map((w) => [w.name, w]));
129+
102130
workspaces.forEach((workspace) => {
103-
const fullPackageName = workspace.name;
104-
const shortPackageName = fullPackageName
131+
const shortPackageName = workspace.name
105132
.replace(/^@metamask\//u, '')
106133
.replace(/-/gu, '_');
107-
workspace.workspaceDependencies.forEach((dependency) => {
108-
const shortDependencyName = dependency
109-
.replace(/^packages\//u, '')
110-
.replace(/-/gu, '_');
111-
connections.push(`${shortPackageName} --> ${shortDependencyName};`);
134+
135+
workspace.dependencies.forEach((dependencyName) => {
136+
// Only create connection if dependency is a workspace package
137+
if (workspacesByName.has(dependencyName)) {
138+
const shortDependencyName = dependencyName
139+
.replace(/^@metamask\//u, '')
140+
.replace(/-/gu, '_');
141+
connections.push(`${shortPackageName} --> ${shortDependencyName};`);
142+
}
112143
});
113144
});
114145
return connections;

0 commit comments

Comments
 (0)