Lerna笔记

basic workflow

npm i -g lerna
mkdir lerna-playground && cd "$_"
npx lerna init
{
  "packages": [
    "packages/*"
  ],
  "version": "0.0.0"
}

for independent versioning mode, change version field value to independent or init project with –independent option

npx lerna init --independent #  or use: npx lerna init -i

By default, lerna initializes the packages list as [“packages/"], but you can also use another directory such as [“modules/"], or [“package1”, “package2”]. The globs defined are relative to the directory that lerna.json lives in, which is usually the repository root. The only restriction is that you can’t directly nest package locations, but this is a restriction shared by “normal” npm packages as well.

{
  "packages": [
    "packages/*",
    "libraries/*"
  ],
  "version": "independent"
}
npx lerna create foo # add new package to the first folder of packages field
npx lerna create bar libraries # add new package to libraries
npx lerna import ace # import existing repo to default location
npx lerna import ace --dest=libraries # import existing repo to libraries
npx lerna list
npx lerna add lodash # add common dependency
npx lerna add moment --scope foo # add dependency for package foo
npx lerna add bar --scope foor # add local bar package as dependency of foo package
npx lerna link # Symlink together all packages that are dependencies of each other
lerna link --force-local # local package first
npx lerna bootstrap # install dependencies for packages
npx lerna run start # execute npm run start in all packages that have configured a npm start script
npx lerna run build --scope foo # execute npm run build for package foo
npx leran run build --stream --scope foo # stream output of child process
npx lerna exec --scope foo -- gulp # execute command gulp for package foo
lerna exec -- rm -rf ./node_modules # remove node_modules folder in current folder
# Bump version of packages changed since the last release
npx lerna version 1.0.0
npx lerna version patch # semver keyword
npx lerna version       # select from prompt(s)
npx lerna clean # remove the node_modules directory from all packages
npx lerna clean --scope foo # remove the node_modules directory from foo package

lerna clean command never remove root node_modules

npx lerna changed # show packages that have been modified
npx lerna diff
npx lerna diff foo