Skip to content

Commit

Permalink
chore: fixes after release
Browse files Browse the repository at this point in the history
forgot to publish the two new packages
npm_package_bin was not documented
alexeagle committed Sep 26, 2019
1 parent e353056 commit e733e80
Showing 5 changed files with 102 additions and 3 deletions.
94 changes: 94 additions & 0 deletions docs/Built-ins.md
Original file line number Diff line number Diff line change
@@ -1286,3 +1286,97 @@ Defaults to `""`




## npm_package_bin

Run an arbitrary npm package binary (anything under node_modules/.bin/*) under Bazel.

It must produce outputs. If you just want to run a program with `bazel run`, use the nodejs_binary rule.

This is like a genrule() except that it runs our launcher script that first
links the node_modules tree before running the program.

This is a great candidate to wrap with a macro, as documented:
https://docs.bazel.build/versions/master/skylark/macros.html#full-example



### Usage

```
npm_package_bin(tool, package, package_bin, data, outs, args, output_dir, kwargs)
```



#### `tool`
a label for a binary to run, like `@npm//terser/bin:terser`. This is the longer form of package/package_bin.
Note that you can also refer to a binary in your local workspace.

Defaults to `None`



#### `package`
an npm package whose binary to run, like "terser". Assumes your node_modules are installed in a workspace called "npm"

Defaults to `None`



#### `package_bin`
the "bin" entry from `package` that should be run. By default package_bin is the same string as `package`

Defaults to `None`



#### `data`
similar to [genrule.srcs](https://docs.bazel.build/versions/master/be/general.html#genrule.srcs)
may also include targets that produce or reference npm packages which are needed by the tool

Defaults to `[]`



#### `outs`
similar to [genrule.outs](https://docs.bazel.build/versions/master/be/general.html#genrule.outs)

Defaults to `[]`



#### `args`
Command-line arguments to the tool.

Subject to 'Make variable' substitution.
Can use $(location) expansion. See https://docs.bazel.build/versions/master/be/make-variables.html
You may also refer to the location of the output_dir with the special `$@` replacement, like genrule.

Defaults to `[]`



#### `output_dir`
set to True if you want the output to be a directory
Exactly one of `outs`, `output_dir` may be used.
If you output a directory, there can only be one output, which will be named the same as the target.

Defaults to `False`



#### `kwargs`





2 changes: 2 additions & 0 deletions index.for_docs.bzl
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ This differs from :index.bzl because we don't have wrapping macros that hide the
load("//internal/common:check_bazel_version.bzl", _check_bazel_version = "check_bazel_version")
load("//internal/node:node.bzl", _nodejs_binary = "nodejs_binary", _nodejs_test = "nodejs_test")
load("//internal/node:node_repositories.bzl", _node_repositories = "node_repositories_rule")
load("//internal/node:npm_package_bin.bzl", _npm_bin = "npm_package_bin")
load("//internal/npm_install:npm_install.bzl", _npm_install = "npm_install", _yarn_install = "yarn_install")
load("//internal/npm_package:npm_package.bzl", _npm_package = "npm_package")
load("//internal/rollup:rollup_bundle.bzl", _rollup_bundle = "rollup_bundle")
@@ -31,4 +32,5 @@ rollup_bundle = _rollup_bundle
npm_package = _npm_package
npm_install = _npm_install
yarn_install = _yarn_install
npm_package_bin = _npm_bin
# ANY RULES ADDED HERE SHOULD BE DOCUMENTED, run yarn skydoc to verify
7 changes: 6 additions & 1 deletion internal/node/npm_package_bin.bzl
Original file line number Diff line number Diff line change
@@ -52,8 +52,9 @@ _npm_package_bin = rule(
attrs = _ATTRS,
)

def npm_package_bin(tool = None, package = None, package_bin = None, **kwargs):
def npm_package_bin(tool = None, package = None, package_bin = None, data = [], outs = [], args = [], output_dir = False, **kwargs):
"""Run an arbitrary npm package binary (anything under node_modules/.bin/*) under Bazel.
It must produce outputs. If you just want to run a program with `bazel run`, use the nodejs_binary rule.
This is like a genrule() except that it runs our launcher script that first
@@ -88,6 +89,10 @@ def npm_package_bin(tool = None, package = None, package_bin = None, **kwargs):
package_bin = package
tool = "@npm//%s/bin:%s" % (package, package_bin)
_npm_package_bin(
data = data,
outs = outs,
args = args,
output_dir = output_dir,
tool = tool,
**kwargs
)
1 change: 0 additions & 1 deletion packages/rollup/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -33,7 +33,6 @@ npm_package(
srcs = [
"@npm_bazel_rollup//:package_contents",
],
tags = ["do-not-publish"],
vendor_external = [
"npm_bazel_rollup",
],
1 change: 0 additions & 1 deletion packages/terser/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -33,7 +33,6 @@ npm_package(
srcs = [
"@npm_bazel_terser//:package_contents",
],
tags = ["do-not-publish"],
vendor_external = [
"npm_bazel_terser",
],

0 comments on commit e733e80

Please sign in to comment.