@0x-lerna-fork/bootstrap 中文文档教程

发布于 5年前 浏览 24 项目主页 更新于 3年前

@0x-lerna-fork/bootstrap

将本地包链接在一起并安装剩余的包依赖

项 安装 lerna 以访问 lerna CLI。

Usage

$ lerna bootstrap

在当前的 Lerna 仓库中引导包。 安装它们的所有依赖项并链接任何交叉依赖项。

运行时,此命令将:

  1. npm install all external dependencies of each package.
  2. Symlink together all Lerna packages that are dependencies of each other.
  3. npm run prepublish in all bootstrapped packages (unless --ignore-prepublish is passed).
  4. npm run prepare in all bootstrapped packages.

lerna bootstrap 遵守 --ignore--scope--include-filtered-dependencies 标志(参见 过滤标志)。

通过将额外的参数放在 -- 之后将它们传递给 npm 客户端:

$ lerna bootstrap -- --production --no-optional

也可以在 lerna.json 中配置:

{
  ...
  "npmClient": "yarn",
  "npmClientArgs": ["--production", "--no-optional"]
}

--hoist [glob]

安装匹配 glob 的外部依赖 项回购根所以他们是 适用于所有包。 来自这些依赖项的任何二进制文件都将是 链接到依赖包 node_modules/.bin/ 目录,所以它们是 可用于 npm 脚本。 如果选项存在但未给出 glob 默认值为 **(提升所有内容)。 该选项仅影响 bootstrap 命令。

$ lerna bootstrap --hoist

有关 --hoist 的背景信息,请参阅提升文档 .

注意:如果包依赖于外部依赖项的不同版本, 最常用的版本将被提升,并发出警告。

--strict

当与 hoist 一起使用时,将抛出错误并在发出版本警告后停止引导。 如果您没有提升,或者没有版本警告,则无效。

$ lerna bootstrap --hoist --strict

--nohoist [glob]

不要在存储库根目录下安装与 glob 匹配的外部依赖项。 这 可用于选择不提升某些依赖项。

$ lerna bootstrap --hoist --nohoist=babel-*

--ignore

$ lerna bootstrap --ignore component-*

--ignore 标志,当与 bootstrap 命令一起使用时,也可以在 command.bootstrap 下的 lerna.json 中设置.ignore 键。 命令行标志将优先于此选项。

示例

{
  "version": "0.0.0",
  "command": {
    "bootstrap": {
      "ignore": "component-*"
    }
  }
}

提示:glob 与 package.json 中定义的包名称匹配, 不是包所在的目录名称。

Options

--ignore-prepublish

跳过默认情况下在引导程序包中运行的预发布生命周期脚本。 请注意,此生命周期已弃用, 并且可能会在 Lerna 的下一个主要版本中被删除。

$ lerna bootstrap --ignore-prepublish

--ignore-scripts

跳过通常在引导程序包中运行的任何生命周期脚本(prepare 等)。

$ lerna bootstrap --ignore-scripts

--registry <url>

使用此标志运行时,转发的 npm 命令将为您的包使用指定的注册表。

如果您不想显式设置注册表,这很有用 例如使用时,在所有 package.json 文件中单独配置 私人登记处。

--npm-client <client>

必须是知道如何安装 npm 包依赖项的可执行文件。 默认的 --npm-clientnpm

$ lerna bootstrap --npm-client=yarn

也可以在 lerna.json 中配置:

{
  ...
  "npmClient": "yarn"
}

--use-workspaces

启用与 Yarn 工作区(自 yarn@0.27+ 起可用)。 数组中的值是 Lerna 将操作委托给 Yarn 的命令(目前只有 bootstrapping)。 如果 --use-workspaces 为真,则 packages 将被 package.json/workspaces 中的值覆盖。 也可以在 lerna.json 中配置:

{
  ...
  "npmClient": "yarn",
  "useWorkspaces": true
}

根级 package.json 还必须包含一个 workspaces 数组:

{
  "private": true,
  "devDependencies": {
    "lerna": "^2.2.0"
  },
  "workspaces": ["packages/*"]
}

这个列表与 lerna 的 packages config(与 package.json 匹配的目录的 glob 列表), 除了它不支持递归 glob(“**”,又名“globstars”)。

--no-ci

当使用默认的 --npm-client 时,lerna bootstrap 将调用 npm ci 而不是 CI 环境中的 npm install。 要禁用此行为,请传递 --no-ci

$ lerna bootstrap --no-ci

要在本地安装期间强制它(它不会自动启用),请传递 --ci< /code>:

$ lerna bootstrap --ci

这对于“干净”重新安装或全新克隆后的初始安装很有用。

--force-local

$ lerna bootstrap --force-local

传递后,此标志会导致 bootstrap 命令始终对本地依赖项进行符号链接,而不管匹配的版本范围如何。

How It Works

让我们以 babel 为例。

  • babel-generator and source-map (among others) are dependencies of babel-core.
  • babel-core's package.json lists both these packages as keys in dependencies, as shown below.
// babel-core package.json
{
  "name": "babel-core",
  ...
  "dependencies": {
    ...
    "babel-generator": "^6.9.0",
    ...
    "source-map": "^0.5.0"
  }
}
  • Lerna checks if each dependency is also part of the Lerna repo.
  • In this example, babel-generator can be an internal dependency, while source-map is always an external dependency.
  • The version of babel-generator in the package.json of babel-core is satisfied by packages/babel-generator, passing for an internal dependency.
  • source-map is npm installed (or yarned) like normal.
  • packages/babel-core/node_modules/babel-generator symlinks to packages/babel-generator
  • This allows nested directory imports

Notes

  • When a dependency version in a package is not satisfied by a package of the same name in the repo, it will be npm installed (or yarned) like normal.
  • Dist-tags, like latest, do not satisfy semver ranges.
  • Circular dependencies result in circular symlinks which may impact your editor/IDE.

Webstorm 在存在循环符号链接时锁定。 为防止这种情况,请将 node_modules 添加到 Preferences | 中忽略的文件和文件夹列表中。 编辑| 文件类型 | 忽略的文件和文件夹

@0x-lerna-fork/bootstrap

Link local packages together and install remaining package dependencies

Install lerna for access to the lerna CLI.

Usage

$ lerna bootstrap

Bootstrap the packages in the current Lerna repo. Installs all of their dependencies and links any cross-dependencies.

When run, this command will:

  1. npm install all external dependencies of each package.
  2. Symlink together all Lerna packages that are dependencies of each other.
  3. npm run prepublish in all bootstrapped packages (unless --ignore-prepublish is passed).
  4. npm run prepare in all bootstrapped packages.

lerna bootstrap respects the --ignore, --scope and --include-filtered-dependencies flags (see Filter Flags).

Pass extra arguments to npm client by placing them after --:

$ lerna bootstrap -- --production --no-optional

May also be configured in lerna.json:

{
  ...
  "npmClient": "yarn",
  "npmClientArgs": ["--production", "--no-optional"]
}

--hoist [glob]

Install external dependencies matching glob at the repo root so they're available to all packages. Any binaries from these dependencies will be linked into dependent package node_modules/.bin/ directories so they're available for npm scripts. If the option is present but no glob is given the default is ** (hoist everything). This option only affects the bootstrap command.

$ lerna bootstrap --hoist

For background on --hoist, see the hoist documentation.

Note: If packages depend on different versions of an external dependency, the most commonly used version will be hoisted, and a warning will be emitted.

--strict

When used in conjunction with hoist will throw an error and stop bootstrapping after emitting the version warnings. Has no effect if you aren't hoisting, or if there are no version warnings.

$ lerna bootstrap --hoist --strict

--nohoist [glob]

Do not install external dependencies matching glob at the repo root. This can be used to opt out of hoisting for certain dependencies.

$ lerna bootstrap --hoist --nohoist=babel-*

--ignore

$ lerna bootstrap --ignore component-*

The --ignore flag, when used with the bootstrap command, can also be set in lerna.json under the command.bootstrap.ignore key. The command-line flag will take precedence over this option.

Example

{
  "version": "0.0.0",
  "command": {
    "bootstrap": {
      "ignore": "component-*"
    }
  }
}

Hint: The glob is matched against the package name defined in package.json, not the directory name the package lives in.

Options

--ignore-prepublish

Skip prepublish lifecycle scripts run by default in bootstrapped packages. Note, this lifecycle is deprecated, and will likely be removed in the next major version of Lerna.

$ lerna bootstrap --ignore-prepublish

--ignore-scripts

Skip any lifecycle scripts normally run (prepare, etc) in bootstrapped packages.

$ lerna bootstrap --ignore-scripts

--registry <url>

When run with this flag, forwarded npm commands will use the specified registry for your package(s).

This is useful if you do not want to explicitly set up your registry configuration in all of your package.json files individually when e.g. using private registries.

--npm-client <client>

Must be an executable that knows how to install npm package dependencies. The default --npm-client is npm.

$ lerna bootstrap --npm-client=yarn

May also be configured in lerna.json:

{
  ...
  "npmClient": "yarn"
}

--use-workspaces

Enables integration with Yarn Workspaces (available since yarn@0.27+). The values in the array are the commands in which Lerna will delegate operation to Yarn (currently only bootstrapping). If --use-workspaces is true then packages will be overridden by the value from package.json/workspaces. May also be configured in lerna.json:

{
  ...
  "npmClient": "yarn",
  "useWorkspaces": true
}

The root-level package.json must also include a workspaces array:

{
  "private": true,
  "devDependencies": {
    "lerna": "^2.2.0"
  },
  "workspaces": ["packages/*"]
}

This list is broadly similar to lerna's packages config (a list of globs matching directories with a package.json), except it does not support recursive globs ("**", a.k.a. "globstars").

--no-ci

When using the default --npm-client, lerna bootstrap will call npm ci instead of npm install in CI environments. To disable this behavior, pass --no-ci:

$ lerna bootstrap --no-ci

To force it during a local install (where it is not automatically enabled), pass --ci:

$ lerna bootstrap --ci

This can be useful for "clean" re-installs, or initial installations after fresh cloning.

--force-local

$ lerna bootstrap --force-local

When passed, this flag causes the bootstrap command to always symlink local dependencies regardless of matching version range.

How It Works

Let's use babel as an example.

  • babel-generator and source-map (among others) are dependencies of babel-core.
  • babel-core's package.json lists both these packages as keys in dependencies, as shown below.
// babel-core package.json
{
  "name": "babel-core",
  ...
  "dependencies": {
    ...
    "babel-generator": "^6.9.0",
    ...
    "source-map": "^0.5.0"
  }
}
  • Lerna checks if each dependency is also part of the Lerna repo.
  • In this example, babel-generator can be an internal dependency, while source-map is always an external dependency.
  • The version of babel-generator in the package.json of babel-core is satisfied by packages/babel-generator, passing for an internal dependency.
  • source-map is npm installed (or yarned) like normal.
  • packages/babel-core/node_modules/babel-generator symlinks to packages/babel-generator
  • This allows nested directory imports

Notes

  • When a dependency version in a package is not satisfied by a package of the same name in the repo, it will be npm installed (or yarned) like normal.
  • Dist-tags, like latest, do not satisfy semver ranges.
  • Circular dependencies result in circular symlinks which may impact your editor/IDE.

Webstorm locks up when circular symlinks are present. To prevent this, add node_modules to the list of ignored files and folders in Preferences | Editor | File Types | Ignored files and folders.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文