preface

In the previous article, rushJS + PNPM’s Preliminary study of Monorepo, we started our first attempt of Monorepo through rushJS + PNPM. Today, we will talk about some advanced uses. The author will mainly explain some scenarios he used in the project, and please be polite if there is anything inappropriate.

Rush command

rush add

Rush add command is a commonly used command. In the last article, we used rush add command. We added a new package in Monorepo through rush add -p command

usage: rush add [-h] -p PACKAGE [--exact] [--caret] [--dev] [-m] [-s] [--all]
Copy the code

Adding a library to a package we have already used, so let’s try adding a library to a package. Let’s try using the monorepo project created in the previous article to add the Lodash library to landing application

cd apps/landing
rush add -p lodash
Copy the code

After the installation command is executed, we can look at the landing package.json and see that it has been added to

If you look at the pnpm-lock.yaml changes, you can see that there is a new lodash changeAdd devDep to dependencies. Add @types/lodash to add ts to your dependencies. Add devDep to dependencies. Just add it to devDep

rush build

Build commands, which can be used in project deployment or CI processes, can be seen in the official documentation for Usage

usage: rush build [-h] [-p COUNT] [-t PROJECT] [-T PROJECT] [-f PROJECT]
                  [-o PROJECT] [-i PROJECT] [-I PROJECT]
                  [--to-version-policy VERSION_POLICY_NAME]
                  [--from-version-policy VERSION_POLICY_NAME] [-v] [-c]
                  [--ignore-hooks] [--disable-build-cache]
Copy the code

Build all projects without any parameters. Use the -t parameter if you want to build a specific project. We used Rush Build to build all projects in the last article

These two directories are generated after build, let’s delete these two directories first, and then see if there are generated directories and products

Go back to the root directory and run the build command

rush build -t @shared/components
Copy the code

Let’s try building the Landing package, delete the dist and run the build command

rush build -t landing
Copy the code

The @shared/ Components package is a reference to the @shared/ Components package when landing

rush list

This command simply displays all of the packages and does not do much else

rush check

This command is useful for checking whether all dependencies in package.json for each subproject are of the same version, such as the lodash command we used above

Let’s experiment by installing a specific version of LoDash in @shared/ Components

Rush to the add -p [email protected]Copy the code

After that we run the command to see if we can detect it

rush check
Copy the code

As you can see, different versions of LoDash are detected here, which can be used in conjunction with CI. In projects, we make sure that all libraries are kept the same version, and that when a library needs to be upgraded to the latest version, it is upgraded to the same version

rush purge

This command is used to delete some temporary files created by Rush, and is very useful when it is suspected that some cache files are causing some problems

Instead of experimenting here, this command can be used in conjunction with rush Update

rush update --purge
Copy the code

Some supplemental use

PNPM – lock. Yaml conflict

This situation is quite common, and it can’t be avoided when developing multiple people, just need to rush update to generate YAML files and submit them