From 884c91899d00ab6707b658e9bb635df09f222bd5 Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Thu, 3 Aug 2023 12:38:10 -0700 Subject: [PATCH] docs: add package path to bin example (#1172) --- docs/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 1ec54063d..3976e2e51 100644 --- a/docs/README.md +++ b/docs/README.md @@ -177,7 +177,7 @@ with a rule like [`copy_to_bin`](https://docs.aspect.build/aspect-build/bazel-li rules_js automatically mirrors the `bin` field from the `package.json` file of your npm dependencies to a Starlark API you can load from in your BUILD file or macro. -For example, if you depend on the `typescript` npm package, you write this in `BUILD`: +For example, if you depend on the `typescript` npm package in your root `package.json`, the `tsc` bin entry can be accessed in a `BUILD`: ```starlark= load("@npm//:typescript/package_json.bzl", typescript_bin = "bin") @@ -195,6 +195,12 @@ typescript_bin.tsc( ) ``` +If you depend on the `typescript` npm package from a nested `package.json` such as `myapp/package.json`, the bin entry would be loaded from the nested package: + +```starlark= +load("@npm//myapp:typescript/package_json.bzl", typescript_bin = "bin") +``` + Each bin exposes three rules, one for each Bazel command ("verb"): build, test and run - each aligning with the corresponding [js_run_binary](./js_run_binary.md), [js_test](#js_test) and [js_binary](./js_binary.md) rule APIs. For example: