| |
| |
| <!-- |
| 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>npm packaging</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">npm packaging</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/history-server/history_server.html">Run history-server</a> |
| <ul> |
| </ul> |
| </li> |
| <li> |
| <a href="/rules_nodejs/http-server/http_server.html">Run http-server</a> |
| <ul> |
| </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 & Yarn</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>npm packaging</h1> |
| |
| <nav class="toc"> |
| <h2><a href="#overview">Overview</a></h2> |
| <h2>Rules</h2> |
| <ul> |
| <li><a href="#npm_package">npm_package</a></li> |
| </ul> |
| <h2>Macros</h2> |
| <ul> |
| <li><a href="#create_package">create_package</a></li> |
| </ul> |
| </nav> |
| <hr> |
| <h2 id="overview">Overview</h2> |
| <p>Note, this is intended for sharing library code with non-Bazel consumers.</p> |
| <p>If all users of your library code use Bazel, they should just add your library |
| to the <code>deps</code> of one of their targets.</p> |
| |
| <hr> |
| |
| <h2 id="create_package">create_package</h2> |
| |
| <pre>create_package(<a href="#create_package.ctx">ctx</a>, <a href="#create_package.deps_sources">deps_sources</a>, <a href="#create_package.nested_packages">nested_packages</a>)</pre> |
| |
| <p>Creates an action that produces the npm package.</p> |
| <p>It copies srcs and deps into the artifact and produces the .pack and .publish |
| scripts.</p> |
| <p>Returns: |
| The tree artifact which is the publishable directory.</p> |
| |
| |
| <h3 id="create_package_args">Attributes</h3> |
| |
| <table class="params-table"> |
| <colgroup> |
| <col class="col-param" /> |
| <col class="col-description" /> |
| </colgroup> |
| <tbody> |
| <tr id="create_package.ctx"> |
| <td><code>ctx</code></td> |
| <td> |
| <p><code>Unknown; Required</code></p> |
| <p>the skylark rule context</p> |
| </td> |
| </tr> |
| <tr id="create_package.deps_sources"> |
| <td><code>deps_sources</code></td> |
| <td> |
| <p><code>Unknown; Required</code></p> |
| <p>Files which have been specified as dependencies. Usually ".js" or ".d.ts" |
| generated files.</p> |
| </td> |
| </tr> |
| <tr id="create_package.nested_packages"> |
| <td><code>nested_packages</code></td> |
| <td> |
| <p><code>Unknown; Required</code></p> |
| <p>list of TreeArtifact outputs from other actions which are |
| to be nested inside this package</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| <hr> |
| |
| <h2 id="npm_package">npm_package</h2> |
| |
| <pre>npm_package(<a href="#npm_package.name">name</a>, <a href="#npm_package.deps">deps</a>, <a href="#npm_package.srcs">srcs</a>, <a href="#npm_package.packages">packages</a>, <a href="#npm_package.replace_with_version">replace_with_version</a>, <a href="#npm_package.replacements">replacements</a>, <a href="#npm_package.vendor_external">vendor_external</a>)</pre> |
| |
| <p>The npm_package rule creates a directory containing a publishable npm artifact.</p> |
| <pre><code class="lang-python">load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package") |
| |
| npm_package( |
| name = "my_package", |
| srcs = ["package.json"], |
| deps = [":my_typescript_lib"], |
| replacements = {"//internal/": "//"}, |
| ) |
| </code></pre> |
| <p>You can use a pair of <code>// BEGIN-INTERNAL ... // END-INTERNAL</code> comments to mark regions of files that should be elided during publishing. |
| For example:</p> |
| <pre><code class="lang-javascript">function doThing() { |
| // BEGIN-INTERNAL |
| // This is a secret internal-only comment |
| doInternalOnlyThing(); |
| // END-INTERNAL |
| } |
| </code></pre> |
| <p>Usage:</p> |
| <p><code>npm_package</code> yields three labels. Build the package directory using the default label:</p> |
| <pre><code class="lang-sh">$ bazel build :my_package |
| Target //:my_package up-to-date: |
| bazel-out/fastbuild/bin/my_package |
| $ ls -R bazel-out/fastbuild/bin/my_package |
| </code></pre> |
| <p>Dry-run of publishing to npm, calling <code>npm pack</code> (it builds the package first if needed):</p> |
| <pre><code class="lang-sh">$ bazel run :my_package.pack |
| INFO: Running command line: bazel-out/fastbuild/bin/my_package.pack |
| my-package-name-1.2.3.tgz |
| $ tar -tzf my-package-name-1.2.3.tgz |
| </code></pre> |
| <p>Actually publish the package with <code>npm publish</code> (also builds first):</p> |
| <pre><code class="lang-sh"># Check login credentials |
| $ bazel run @nodejs//:npm who |
| # Publishes the package |
| $ bazel run :my_package.publish |
| </code></pre> |
| <p>You can pass arguments to npm by escaping them from Bazel using a double-hyphen <code>bazel run my_package.publish -- --tag=next</code></p> |
| |
| |
| <h3 id="npm_package_args">Attributes</h3> |
| |
| <table class="params-table"> |
| <colgroup> |
| <col class="col-param" /> |
| <col class="col-description" /> |
| </colgroup> |
| <tbody> |
| <tr id="npm_package.name"> |
| <td><code>name</code></td> |
| <td> |
| <p><code><a href="https://bazel.build/docs/build-ref.html#name">Name</a>; Required</code></p> |
| <p>A unique name for this rule.</p> |
| </td> |
| </tr> |
| <tr id="npm_package.deps"> |
| <td><code>deps</code></td> |
| <td> |
| <p><code>List of <a href="https://bazel.build/docs/build-ref.html#labels">labels</a>; Optional; Default is []</code></p> |
| <p>Other targets which produce files that should be included in the package, such as <code>rollup_bundle</code></p> |
| </td> |
| </tr> |
| <tr id="npm_package.srcs"> |
| <td><code>srcs</code></td> |
| <td> |
| <p><code>List of <a href="https://bazel.build/docs/build-ref.html#labels">labels</a>; Optional; Default is []</code></p> |
| <p>Files inside this directory which are simply copied into the package.</p> |
| </td> |
| </tr> |
| <tr id="npm_package.packages"> |
| <td><code>packages</code></td> |
| <td> |
| <p><code>List of <a href="https://bazel.build/docs/build-ref.html#labels">labels</a>; Optional; Default is []</code></p> |
| <p>Other npm_package rules whose content is copied into this package.</p> |
| </td> |
| </tr> |
| <tr id="npm_package.replace_with_version"> |
| <td><code>replace_with_version</code></td> |
| <td> |
| <p><code>String; Optional; Default is '0.0.0-PLACEHOLDER'</code></p> |
| <p>If set this value is replaced with the version stamp data. |
| See the section on stamping in the README.</p> |
| </td> |
| </tr> |
| <tr id="npm_package.replacements"> |
| <td><code>replacements</code></td> |
| <td> |
| <p><code>Dictionary mapping strings to string; Optional; Default is {}</code></p> |
| <p>Key-value pairs which are replaced in all the files while building the package.</p> |
| </td> |
| </tr> |
| <tr id="npm_package.vendor_external"> |
| <td><code>vendor_external</code></td> |
| <td> |
| <p><code>List of strings; Optional; Default is []</code></p> |
| <p>External workspaces whose contents should be vendored into this workspace. |
| Avoids 'external/foo' path segments in the resulting package. |
| Note: only targets in the workspace root can include files from an external workspace. |
| Targets in nested packages only pick up files from within that package.</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> |