Why google uses mono-repo

Why google uses mono-repo

Sanfeng soft Zhang Sanfeng

What is monorepo?

Monorepo is a way of managing organization code. In this way, the original method of one module and one repo will be abandoned, and all modules will be managed in one repo instead.

Currently, Babel, React, Angular, Ember, Meteor, Jest, etc. all use Monorepo to manage source code.

Disadvantages of git multi-repository management

1. Difficulty in management and debugging
2. Confusing branch management
3. Complicated dependencies
4. Three-party dependency versions may be inconsistent
5. Taking up a large total space
6. Not conducive to teamwork

Single, multiple warehouse, single warehouse

Why google uses mono-repo
Single application to multiple warehouses to single warehouse

The advantages of a single warehouse: Code specifications are easy to manage and automated tools can be built with one click, one-click deployment is easy to understand the overall project, and developers have a better panoramic view and easy to reuse

Who is using monorepo

Why google uses mono-repo

Basel

Bazel is a renewable code building tool from Google. It is mainly used to build Google's software, to deal with the construction problems that appear in Google's development environment, such as: large-scale data construction problems, shared code base problems, and related problems of software built from source code.

Bazel supports multiple languages ​​and is cross-platform. It also supports automated testing and deployment, has features such as reproducibility and scale. Bazel plays a vital role in Google's large-scale software development practice capabilities.
Why google uses mono-repo

Buck

BUCK is Facebook's open source Android high-speed build system. The speed is over gradle. For more details, please search by yourself.

The 10-line configuration is migrated from the Android Studio + Gradle build system to facebook's BUCK build system, and keep the two compatible at the same time. Use AS for coding, enjoy the functions of Android's most powerful IDE, and use BUCK for packaging, installation and testing, and enjoy the best Android Quickly build the system without disturbing each other. From then on, mom no longer has to worry about me falling asleep while compiling the Android project, and it really only takes 10 lines!

Github address: https://github.com/Piasy/OkBuck/blob/master/README-zh.md

Example

An ideal monorepo structure:


.
├── packages
│      ├─ module-a
│      │    ├─ src            # 模块 a 的源码
│      │    └─ package.json   # 自动生成的,仅模块 a 的依赖
│      └─ module-b
│           ├─ src            # 模块 b 的源码
│           └─ package.json   # 自动生成的,仅模块 b 的依赖
├── tsconfig.json             # 配置文件,对整个项目生效
├── .eslintrc                 # 配置文件,对整个项目生效
├── node_modules              # 整个项目只有一个外层 node_modules
└── package.json              # 包含整个项目所有依赖

There is only one global configuration file. This will not cause the IDE to encounter the configuration file in the subfolder, causing the global configuration to become invalid or abnormal. There is only one node_modules, which not only ensures the consistency of project dependencies, but also avoids repeated installation of dependencies, saving space and improving installation speed.

The brother modules refer to each other through the name defined in the module package.json to ensure the independence of the modules, but there is no need to actually publish or install this module. The path of the virtual module is realized through the paths of tsconfig.json and the alias of webpack. effect.

to sum up

The monorepo structure is now recognized by the industry for microservices. Microservices built in this way can be developed quickly and iterated quickly without affecting the reusability of the project.

Guess you like

Origin blog.51cto.com/15065852/2604946