diff --git a/docs/Built-ins.md b/docs/Built-ins.md index 0bd83826e3..663733bf3a 100755 --- a/docs/Built-ins.md +++ b/docs/Built-ins.md @@ -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` + + + + + + diff --git a/index.for_docs.bzl b/index.for_docs.bzl index 886258b3ab..cdfdccd233 100644 --- a/index.for_docs.bzl +++ b/index.for_docs.bzl @@ -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 diff --git a/internal/node/npm_package_bin.bzl b/internal/node/npm_package_bin.bzl index f28a1648ce..3b40f729a8 100644 --- a/internal/node/npm_package_bin.bzl +++ b/internal/node/npm_package_bin.bzl @@ -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 ) diff --git a/packages/rollup/BUILD.bazel b/packages/rollup/BUILD.bazel index 4908386265..6015f550ab 100644 --- a/packages/rollup/BUILD.bazel +++ b/packages/rollup/BUILD.bazel @@ -33,7 +33,6 @@ npm_package( srcs = [ "@npm_bazel_rollup//:package_contents", ], - tags = ["do-not-publish"], vendor_external = [ "npm_bazel_rollup", ], diff --git a/packages/terser/BUILD.bazel b/packages/terser/BUILD.bazel index 9f6c50963b..7958eed276 100644 --- a/packages/terser/BUILD.bazel +++ b/packages/terser/BUILD.bazel @@ -33,7 +33,6 @@ npm_package( srcs = [ "@npm_bazel_terser//:package_contents", ], - tags = ["do-not-publish"], vendor_external = [ "npm_bazel_terser", ],