Skip to content

Commit 8b82083

Browse files
docs: add blog post about the monorepo migration
1 parent a144505 commit 8b82083

File tree

4 files changed

+128
-0
lines changed

4 files changed

+128
-0
lines changed

blog/2024-07-12-monorepo.md

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
title: Socket.IO monorepo
3+
slug: /monorepo/
4+
authors:
5+
- darrachequesne
6+
---
7+
8+
Hello everyone!
9+
10+
We are happy to announce that the Socket.IO codebase has been merged into a monorepo.
11+
12+
<!--truncate-->
13+
14+
:::note
15+
16+
A monorepo is a single repository containing multiple distinct projects, with well-defined relationships.
17+
18+
More info [here](https://monorepo.tools)
19+
20+
:::
21+
22+
## Modular architecture
23+
24+
As part of the work towards [v1.0](/blog/introducing-socket-io-1-0/) ten years ago (!), the Socket.IO codebase was split into several packages, each with its own responsibility:
25+
26+
![Diagram of the package inter-dependencies](/images/blog/monorepo/packages.png)
27+
28+
At the time, tools like [`lerna`](https://lerna.js.org/) or [pnpm workspaces](https://pnpm.io/workspaces) that make it easier to develop and publish multiple JavaScript packages from the same repository did not exist yet, so the codebase was split into multiple GitHub repositories:
29+
30+
- https://github.com/socketio/socket.io
31+
- https://github.com/socketio/socket.io-client
32+
- https://github.com/socketio/socket.io-parser
33+
- ...
34+
35+
However, this structure has several downsides:
36+
37+
- it's harder for newcomers to dig into the codebase and understand what's going on under the hood
38+
- a change that affects multiple repositories is more difficult to test
39+
- mundane tasks like configuring CI or updating development dependencies must be replicated across all repositories
40+
41+
That's why we have made the decision to merge all repositories into [a single one](https://github.com/socketio/socket.io). The source codes for the different packages are now located in the `packages/` directory:
42+
43+
```
44+
packages/
45+
├── engine.io
46+
├── engine.io-client
47+
├── engine.io-parser
48+
├── socket.io
49+
├── socket.io-adapter
50+
├── socket.io-client
51+
└── socket.io-parser
52+
```
53+
54+
## Workspaces
55+
56+
To manage the packages, we use [npm workspaces](https://docs.npmjs.com/cli/v10/using-npm/workspaces) which were introduced in npm v7 (bundled with Node.js v15). The `package.json` file at the root of the repository lists all packages and their development dependencies:
57+
58+
```json title="package.json"
59+
{
60+
"private": true,
61+
"workspaces": [
62+
"packages/engine.io-parser",
63+
"packages/engine.io",
64+
"packages/engine.io-client",
65+
"packages/socket.io-adapter",
66+
"packages/socket.io-parser",
67+
"packages/socket.io-client",
68+
"packages/socket.io"
69+
],
70+
"devDependencies": {
71+
// [...]
72+
}
73+
}
74+
```
75+
76+
After cloning the repository, running `npm install` will fetch all necessary dependencies and create the links between the packages:
77+
78+
```bash
79+
$ npm ls
80+
socket.io@ /git/socket.io
81+
└─┬ [email protected] -> ./packages/socket.io
82+
83+
84+
85+
86+
# highlight-next-line
87+
├── [email protected] -> ./packages/engine.io
88+
# highlight-next-line
89+
├─┬ [email protected] -> ./packages/socket.io-adapter
90+
│ ├── [email protected] deduped
91+
│ └── [email protected] overridden
92+
# highlight-next-line
93+
└─┬ [email protected] -> ./packages/socket.io-parser
94+
├── @socket.io/[email protected] -> ./packages/socket.io-component-emitter
95+
└── [email protected] deduped
96+
```
97+
98+
And finally, running `npm test --workspaces` (or `npm test -ws`) will run the tests on all workspaces, ensuring that any change is properly tested over the whole codebase.
99+
100+
:::tip
101+
102+
Our [contributing guide](https://github.com/socketio/socket.io/blob/main/CONTRIBUTING.md) has been updated accordingly.
103+
104+
:::
105+
106+
## Git history
107+
108+
Obviously, losing 10 years of git history from the other repositories was not an option. The repositories have thus been merged with the `--allow-unrelated-histories` option, in order to include their history in the monorepo:
109+
110+
![Schema of the preserved git history](/images/blog/monorepo/git-history.png)
111+
112+
Reference: https://git-scm.com/docs/git-merge#Documentation/git-merge.txt---allow-unrelated-histories
113+
114+
## GitHub issues
115+
116+
Similarly, it was not conceivable to lose the list of open GitHub issues across all repositories, since it is our most valuable source of user feedback, so they have been moved to the main repository: https://github.com/socketio/socket.io/issues
117+
118+
Hopefully, this change should make it easier for anyone to contribute to the project in the future.
119+
120+
That's all folks, thanks for reading!

diagrams/packages.mermaid

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
flowchart
2+
socket.io --> engine.io
3+
socket.io --> socket.io-parser
4+
socket.io-client --> socket.io-parser
5+
socket.io-client --> engine.io-client
6+
engine.io --> engine.io-parser
7+
engine.io-client --> engine.io-parser
8+
socket.io --> socket.io-adapter
229 KB
Loading
58.4 KB
Loading

0 commit comments

Comments
 (0)