Install npm packages
Bazel

Install npm packages


Overview

Rules to install NodeJS dependencies during WORKSPACE evaluation. This happens before the first build or test runs, allowing you to use Bazel as the package manager.

See discussion in the README.


npm_install

npm_install(name, data, exclude_packages, included_files, manual_build_file_contents, package_json, package_lock_json, prod_only, quiet, timeout)

Runs npm install during workspace setup.

Attributes

name

Name; Required

A unique name for this rule.

data

List of labels; Optional; Default is []

exclude_packages

List of strings; Optional; Default is ['@bazel/bazel']

List of packages to exclude from install.

    Use this when you want to install a package during manual yarn or npm
    install but not install it when Bazel manages dependencies.

    Note: this attribute may be removed in the future if bazel managed npm
    dependencies are changed to install to the workspace `node_modules` folder
    instead of `$(bazel info output_base)/external/wksp`.
included_files

List of strings; Optional; Default is []

List of file extensions to be included in the npm package targets.

    For example, [".js", ".d.ts", ".proto", ".json", ""].

    This option is useful to limit the number of files that are inputs
    to actions that depend on npm package targets. See
    https://github.com/bazelbuild/bazel/issues/5153.

    If set to an empty list then all files are included in the package targets.
    If set to a list of extensions, only files with matching extensions are
    included in the package targets. An empty string in the list is a special
    string that denotes that files with no extensions such as `README` should
    be included in the package targets.

    This attribute applies to both the coarse `@wksp//:node_modules` target
    as well as the fine grained targets such as `@wksp//foo`.
manual_build_file_contents

String; Optional; Default is ''

Experimental attribute that can be used to override the generated BUILD.bazel file and set its contents manually. Can be used to work-around a bazel performance issue if the default @wksp//:node_modules target has too many files in it. See https://github.com/bazelbuild/bazel/issues/5153. If you are running into performance issues due to a large node_modules target it is recommended to switch to using fine grained npm dependencies.

package_json

Label; Required

package_lock_json

Label; Optional

prod_only

Boolean; Optional; Default is False

Don't install devDependencies

quiet

Boolean; Optional; Default is False

If stdout and stderr should be printed to the terminal.

timeout

Integer; Optional; Default is 600

Maximum duration of the command "npm install" in seconds (default is 600 seconds).


yarn_install

yarn_install(name, data, exclude_packages, included_files, manual_build_file_contents, package_json, prod_only, quiet, timeout, use_global_yarn_cache, yarn_lock)

Runs yarn install during workspace setup.

Attributes

name

Name; Required

A unique name for this rule.

data

List of labels; Optional; Default is []

exclude_packages

List of strings; Optional; Default is ['@bazel/bazel']

List of packages to exclude from install.

    Use this when you want to install a package during manual yarn or npm
    install but not install it when Bazel manages dependencies.

    Note: this attribute may be removed in the future if bazel managed npm
    dependencies are changed to install to the workspace `node_modules` folder
    instead of `$(bazel info output_base)/external/wksp`.
included_files

List of strings; Optional; Default is []

List of file extensions to be included in the npm package targets.

    For example, [".js", ".d.ts", ".proto", ".json", ""].

    This option is useful to limit the number of files that are inputs
    to actions that depend on npm package targets. See
    https://github.com/bazelbuild/bazel/issues/5153.

    If set to an empty list then all files are included in the package targets.
    If set to a list of extensions, only files with matching extensions are
    included in the package targets. An empty string in the list is a special
    string that denotes that files with no extensions such as `README` should
    be included in the package targets.

    This attribute applies to both the coarse `@wksp//:node_modules` target
    as well as the fine grained targets such as `@wksp//foo`.
manual_build_file_contents

String; Optional; Default is ''

Experimental attribute that can be used to override the generated BUILD.bazel file and set its contents manually. Can be used to work-around a bazel performance issue if the default @wksp//:node_modules target has too many files in it. See https://github.com/bazelbuild/bazel/issues/5153. If you are running into performance issues due to a large node_modules target it is recommended to switch to using fine grained npm dependencies.

package_json

Label; Required

prod_only

Boolean; Optional; Default is False

Don't install devDependencies

quiet

Boolean; Optional; Default is False

If stdout and stderr should be printed to the terminal.

timeout

Integer; Optional; Default is 600

Maximum duration of the command "yarn" in seconds. (default is 600 seconds).

use_global_yarn_cache

Boolean; Optional; Default is True

Use the global yarn cache on the system. The cache lets you avoid downloading packages multiple times. However, it can introduce non-hermeticity, and the yarn cache can have bugs. Disabling this attribute causes every run of yarn to have a unique cache_directory.

yarn_lock

Label; Required