blob: 23435bd036246186b1a96885ee5facbec0e52af0 [file]
<!--
Documentation generated by Skydoc
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width initial-scale=1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Install NodeJS</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700" type="text/css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://code.getmdl.io/1.1.1/material.green-light_blue.min.css">
<script defer src="https://code.getmdl.io/1.1.1/material.min.js"></script>
<link rel="stylesheet" href="/rules_nodejs/main.css">
</head>
<body>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-drawer
mdl-layout--fixed-header">
<header class="mdl-layout__header">
<div class="mdl-layout__header-row">
<span class="mdl-layout-title">Install NodeJS</span>
</div>
</header>
<div class="mdl-layout__drawer">
<span class="mdl-layout-title">Bazel</span>
<nav class="drawer-nav">
<ul class="drawer-nav">
<li><a href="/rules_nodejs/index.html">Overview</a></li>
<li>
<a href="/rules_nodejs/common/check_bazel_version.html">Check Bazel version</a>
<ul>
<li><a href="/rules_nodejs/common/check_bazel_version.html#overview">Overview</a></li>
</ul>
</li>
<li>
<a href="/rules_nodejs/jasmine_node_test/jasmine_node_test.html">NodeJS testing</a>
<ul>
<li><a href="/rules_nodejs/jasmine_node_test/jasmine_node_test.html#overview">Overview</a></li>
</ul>
</li>
<li>
<a href="/rules_nodejs/node/node.html">Executing programs</a>
<ul>
<li><a href="/rules_nodejs/node/node.html#overview">Overview</a></li>
<li>
<a href="/rules_nodejs/node/node.html#nodejs_binary">
nodejs_binary
</a>
</li>
<li>
<a href="/rules_nodejs/node/node.html#nodejs_test">
nodejs_test
</a>
</li>
</ul>
</li>
<li>
<a href="/rules_nodejs/node/node_repositories.html">Install NodeJS</a>
<ul>
<li><a href="/rules_nodejs/node/node_repositories.html#overview">Overview</a></li>
</ul>
</li>
<li>
<a href="/rules_nodejs/npm_install/npm_install.html">Install npm packages</a>
<ul>
<li><a href="/rules_nodejs/npm_install/npm_install.html#overview">Overview</a></li>
</ul>
</li>
<li>
<a href="/rules_nodejs/npm_package/npm_package.html">npm packaging</a>
<ul>
<li><a href="/rules_nodejs/npm_package/npm_package.html#overview">Overview</a></li>
<li>
<a href="/rules_nodejs/npm_package/npm_package.html#npm_package">
npm_package
</a>
</li>
</ul>
</li>
<li>
<a href="/rules_nodejs/rollup/rollup_bundle.html">Rollup bundling</a>
<ul>
<li><a href="/rules_nodejs/rollup/rollup_bundle.html#overview">Overview</a></li>
<li>
<a href="/rules_nodejs/rollup/rollup_bundle.html#rollup_bundle">
rollup_bundle
</a>
</li>
</ul>
</li>
</ul>
</nav>
</div>
<main class="mdl-layout__content">
<div class="page-content">
<h1>Install NodeJS</h1>
<nav class="toc">
<h2><a href="#overview">Overview</a></h2>
<h2>Macros</h2>
<ul>
<li><a href="#node_repositories">node_repositories</a></li>
</ul>
</nav>
<hr>
<h2 id="overview">Overview</h2>
<p>This is a repository rule, see <a href="https://docs.bazel.build/versions/master/skylark/repository_rules.html">https://docs.bazel.build/versions/master/skylark/repository_rules.html</a></p>
<p>This runs when the user invokes node_repositories() from their WORKSPACE.</p>
<hr>
<h2 id="node_repositories">node_repositories</h2>
<pre>node_repositories(<a href="#node_repositories.package_json">package_json</a>)</pre>
<p>To be run in user's WORKSPACE to install rules_nodejs dependencies.</p>
<p>When the rule executes, it downloads node, npm, and yarn.
We fetch a specific version of Node, to ensure builds are hermetic, and to allow developers to skip installation of node if the entire toolchain is built on Bazel.</p>
<p>It exposes workspaces <code>@nodejs</code> and <code>@yarn</code> containing some rules the user can call later:</p>
<ul>
<li>Run node: <code>bazel run @nodejs//:node path/to/program.js</code></li>
<li>Install dependencies using npm: <code>bazel run @nodejs//:npm install</code></li>
<li>Install dependencies using yarn: <code>bazel run @yarn//:yarn</code></li>
</ul>
<p>Note that the dependency installation scripts will run in each subpackage indicated by the <code>package_json</code> attribute.</p>
<p>This approach uses npm/yarn as the package manager. You could instead have Bazel act as the package manager, running the install behind the scenes.
See the <code>npm_install</code> and <code>yarn_install</code> rules, and the discussion in the README.</p>
<pre><code>load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories")
node_repositories(package_json = ["//:package.json", "//subpkg:package.json"])
</code></pre>
<p>Running <code>bazel run @yarn//:yarn</code> in this repo would create <code>/node_modules</code> and <code>/subpkg/node_modules</code>.</p>
<h3 id="node_repositories_args">Attributes</h3>
<table class="params-table">
<colgroup>
<col class="col-param" />
<col class="col-description" />
</colgroup>
<tbody>
<tr id="node_repositories.package_json">
<td><code>package_json</code></td>
<td>
<p><code>Unknown; Required</code></p>
<p>a list of labels, which indicate the package.json files that need to be installed.</p>
</td>
</tr>
</tbody>
</table>
</div>
<footer class="mdl-mini-footer">
<div class="mdl-mini-footer__left-section">
<div class="mdl-logo">Bazel</div>
<ul class="mdl-mini-footer__link-list">
<li><a href="https://bazel.build">Home</a></li>
<li><a href="https://github.com/bazelbuild">GitHub</a></li>
</ul>
</div>
</footer>
</main>
</div>
</body>
</html>