An operation that manages separate projects such as server + front in one repository is called monorepo (monolipo?).
This time, using the monorepo optimization tool Lerna
, we will execute npm install
to the project of all the projects in operation at once.
In my case, I needed it when turning with CI.
Use the lerna exec
command.
For a directory structure like the one below, running lerna exec npm install
in the root directory will run npm install
on both front and server.
├──packages
│ ├── front
│ │ ├── package-lock.json
│ │ ├── package.json
│ │ ...
│ └── server
│ ├── package-lock.json
│ ├── package.json
│ ...
├── package-lock.json
├── package.json
├── lerna.json
...
There are the following two commands for executing commands in each package provided by lerna.
lerna exec
--Execute arbitrary command with all packages
--You can also run the npm run
command, so you can replace the lerna run
with this one (though it doesn't make sense)
--Used with rm etc. in addition to npm installlerna run
--Run npm script on all packages
--Used in test and buildAlso, both commands have quite common options.
--scope
--Perform only the processing of the specified package--stream
--Stream output and output log--parallel
--The log is output like --stream
, but unlike --stream
, it is not executed in order, but all packages are processed at once.
--Because it is dangerous, use it only with watch commands, or limit it to some extent with --scope
.--no-bail
--Even if an error end code appears in the middle, ignore it and execute the command to the end--no-prefix
--Use with --stream
and --parallel
--Disable the package name prefix and output the log--profile
--Profile command execution--profile-location <location>
--Specify the location of profile outputI couldn't find much when I looked up the article, but when I saw the official README, it was easy to solve. Basically, I write it in npm script, so I don't care from the middle, but it is very important to know the types of commands and options just because I can do this.
Recommended Posts