Skip to content

Commit e77f67b

Browse files
committed
Add documentation
Those of us that have worked on the monorepo have a lot of context around why it exists, what it does, and how to work with it, but for everyone else, this context may not exist. The set of guides in this commit aims to fill in the missing gaps. I've also included a bit around preview builds at the end. We may also need an expanded section on creating new releases, as people may not immediately jump to the docs for `create-release-branch`, and those docs may not be as comprehensive as they could be. This could come in a future PR, however.
1 parent fe822ff commit e77f67b

File tree

7 files changed

+299
-9
lines changed

7 files changed

+299
-9
lines changed

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ package-lock.json
1111
.eslintcache
1212

1313
.DS_STORE
14-
coverage
15-
dist
16-
docs
14+
packages/*/coverage
15+
packages/*/dist
16+
packages/*/docs
1717

1818
# yarn v3 (w/o zero-install)
1919
# See: https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
@@ -26,4 +26,4 @@ docs
2626
!.yarn/versions
2727

2828
# typescript
29-
*.tsbuildinfo
29+
packages/*/*.tsbuildinfo

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A collection of platform-agnostic modules for creating secure data models for cr
44

55
## Modules
66

7-
This is a monorepo that houses the following packages. Please refer to the READMEs for these packages for installation and usage instructions:
7+
This repo houses the following packages, which you can examine for installation and usage instructions:
88

99
- [`@metamask/address-book-controller`](packages/address-book-controller)
1010
- [`@metamask/announcement-controller`](packages/announcement-controller)
@@ -26,13 +26,23 @@ This is a monorepo that houses the following packages. Please refer to the READM
2626
- [`@metamask/subject-metadata-controller`](packages/subject-metadata-controller)
2727
- [`@metamask/transaction-controller`](packages/transaction-controller)
2828

29-
Here is a graph that shows the dependencies among all packages:
29+
Or, in graph form:
3030

3131
![Dependency graph](assets/dependency-graph.png)
3232

3333
> **Note**
3434
> To regenerate this graph, run `yarn generate-dependency-graph`.
3535
36+
## Architecture
37+
38+
This is a monorepo that houses multiple packages published under the `@metamask` namespace on NPM. Here are some topics you may find useful when developing:
39+
40+
- [What is a controller and how are they used?](docs/what.md)
41+
- [Why we're using a monorepo](docs/why.md)
42+
- [How the monorepo works](docs/how.md)
43+
- [Common tasks you may need to perform when working on a package](docs/common-tasks.md)
44+
- [How to test in-progress changes to a package within a project](docs/preview-builds.md)
45+
3646
## Contributing
3747

3848
### Setup
@@ -41,17 +51,17 @@ Here is a graph that shows the dependencies among all packages:
4151
- If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm use` will automatically choose the right node version for you.
4252
- Install [Yarn v3](https://yarnpkg.com/getting-started/install).
4353
- Run `yarn install` to install dependencies and run any required post-install scripts.
44-
- Run `yarn simple-git-hooks` to add a [Git hook](https://github.com/toplenboren/simple-git-hooks#what-is-a-git-hook) which will ensure that all files pass the linter before you push a branch.
54+
- Run `yarn simple-git-hooks` to add a [Git hook](https://github.com/toplenboren/simple-git-hooks#what-is-a-git-hook) to your local development environment which will ensure that all files pass the linter before you push a branch.
4555

4656
### Testing and Linting
4757

48-
Run `yarn test` to run tests for all packages. Run `yarn workspace <package-name> run test` to run tests for a single package.
58+
Run `yarn test` to run tests for all packages. Run `yarn workspace <package-name> run test` to run tests for a single package (where `<package-name>` is the published name of a package, e.g. `@metamask/announcement-controller`, not its location within the monorepo, e.g. `packages/announcement-controller`).
4959

5060
Run `yarn lint` to lint all files and show possible violations, or run `yarn lint:fix` to fix any automatically fixable violations.
5161

5262
### Release & Publishing
5363

54-
This project follows a unique release process. The [`create-release-branch`](https://github.com/MetaMask/create-release-branch) tool and [`action-publish-release`](https://github.com/MetaMask/action-publish-release) GitHub action are used to automate the release process; see those repositories for more information about how they work.
64+
This project follows a process which is unique to this repo. The [`create-release-branch`](https://github.com/MetaMask/create-release-branch) tool and [`action-publish-release`](https://github.com/MetaMask/action-publish-release) GitHub action are used to automate the release process; see those repositories for more information about how they work.
5565

5666
1. To begin the release process, run `create-release-branch`, specifying the packages you want to release. This tool will bump versions and update changelogs across the monorepo automatically, then create a new branch for you.
5767

docs/common-tasks.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Common monorepo tasks
2+
3+
When working with the monorepo, you will always be concerned with one of two needs:
4+
5+
- How do I do something for only one package?
6+
- How do I do the same thing across all packages?
7+
8+
If you've read the ["How"](./how.md) section you know that we can use Yarn for both of these, because it treats the monorepo as a workspace of workspaces.
9+
10+
## Doing something for only one package
11+
12+
Use `yarn workspace <package> <rest...>`.
13+
14+
That `package` argument is important: it's the name of the package you want to target, not the directory where the package is located.
15+
16+
As for the `rest`, it depends on what you want to do:
17+
18+
- If you want to run a package script (a command configured under the package's `scripts` field) or an executable (a command that a dependency provides), use `run` followed by the name of the script and the arguments.
19+
- If you want to run an arbitrary command, use `exec` followed by the name of the command and the arguments.
20+
21+
### Examples
22+
23+
We'll assume you're working with the package `@metamask/address-book-controller`:
24+
25+
If you want to use the package script `test` to run all tests:
26+
27+
```
28+
yarn workspace @metamask/address-book-controller run test
29+
```
30+
31+
If you want to use the `jest` executable to run Jest directly instead:
32+
33+
```
34+
yarn workspace @metamask/address-book-controller run jest
35+
```
36+
37+
If you want to read `package.json` and run it through `jq` to grab the current version:
38+
39+
```
40+
yarn workspace @metamask/address-book-controller exec cat package.json | jq '.version'
41+
```
42+
43+
## Doing the same thing across all packages
44+
45+
Use `yarn workspaces foreach <rest...>` (notice the `s`).
46+
47+
As with `yarn workspace`, it depends on what you want to do:
48+
49+
- If you want to run a package script, use `run` followed by the name of the script and the arguments.
50+
- If you want to run an arbitrary command, use `exec` followed by the name of the command and the arguments.
51+
52+
This command takes a bunch of options, but these are the ones we've found useful:
53+
54+
- `--verbose` is practically necessary, because without it, you won't know which part of the output came from which package.
55+
- `--parallel` will run the command across a set pool of packages at the same time. This can be handy for speeding up your run.
56+
- `--topological` / `--topological-dev` is neat because it will sort packages in dependency order. This means that the command will run first for packages that do not depend on any other packages, then it will run the command for all of the packages that depend on those packages, etc. (The `-dev` variant includes `devDependencies` when determining what a package's dependencies are, otherwise they are ignored.)
57+
58+
### Examples
59+
60+
If you want to use the package script `test` to run all tests across all packages (note: the `yarn test` command does this already):
61+
62+
```
63+
yarn workspaces foreach --verbose test
64+
```
65+
66+
If you want to use the `jest` executable to run Jest directly for all packages:
67+
68+
```
69+
yarn workspaces foreach --verbose run jest
70+
```
71+
72+
If you want to read `package.json` and run it through `jq` to grab the current version for all packages in parallel (note the double quotes):
73+
74+
```
75+
yarn workspaces foreach --verbose --parallel exec "cat package.json | jq '.version'"
76+
```

0 commit comments

Comments
 (0)