Skip to content

Commit 24f6ff3

Browse files
authored
docs: add npm_package vs js_library info to troubleshooting.md (#2164)
1 parent 54ee196 commit 24f6ff3

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

docs/troubleshooting.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ See [examples/stack_traces](../examples/stack_traces) for a working example.
151151

152152
For general bazel performance tips see the [Aspect bazelrc guide](https://docs.aspect.build/guides/bazelrc/#performance-options).
153153

154+
### Linking first-party packages
155+
156+
When linking first-party packages it is recommended to use `js_library` or another `JsInfo`-providing rule to represent the package instead of the `npm_package` rule (which provides `NpmPackageInfo`).
157+
158+
The use of `NpmPackageInfo` requires building the full package content in order to output a single directory artifact representing the package.
159+
160+
Using `JsInfo` allows rules_js to passthru the provider without collecting the package content until another action requests it. For example `JsInfo.types`, normally outputted by a slow `.d.ts` producing tool such as `tsc`, is most likely unnecessary when only executing or bundling JavaScript files from `JsInfo.sources`. If `JsInfo.types` is produced by different actions then `JsInfo.sources` then those actions may not be required at all.
161+
154162
### Parallelism (build, test)
155163

156164
A lot of tooling in the JS ecosystem uses parallelism to speed up builds. This is great, but as Bazel also parallels builds this can lead to a lot of contention for resources.

npm/private/npm_package_store.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ https://github.com/npm/rfcs/blob/main/accepted/0042-isolated-mode.md.
2424

2525
_ATTRS = {
2626
"src": attr.label(
27-
doc = """A npm_package target or or any other target that provides a NpmPackageInfo.
27+
doc = """A target providing a `NpmPackageInfo` or `JsInfo` containing the package sources.
2828
""",
2929
mandatory = True,
3030
),
@@ -117,15 +117,15 @@ _ATTRS = {
117117
"package": attr.string(
118118
doc = """The package name to link to.
119119
120-
If unset, the package name in the NpmPackageInfo src must be set.
121-
If set, takes precendance over the package name in the NpmPackageInfo src.
120+
If unset, the package name in the `NpmPackageInfo` src must be set.
121+
If set, takes precendance over the package name in the `NpmPackageInfo` src.
122122
""",
123123
),
124124
"version": attr.string(
125125
doc = """The package version being linked.
126126
127-
If unset, the package version in the NpmPackageInfo src must be set.
128-
If set, takes precendance over the package version in the NpmPackageInfo src.
127+
If unset, the package version in the `NpmPackageInfo` src must be set.
128+
If set, takes precendance over the package version in the `NpmPackageInfo` src.
129129
""",
130130
),
131131
"dev": attr.bool(

npm/private/npm_package_store_internal.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ load(":npm_package_store.bzl", _npm_package_store_lib = "npm_package_store_lib")
55

66
_INTERNAL_ATTRS_STORE = dicts.add(_npm_package_store_lib.attrs, {
77
"src": attr.label(
8-
doc = """A npm_package target or or any other target that provides a NpmPackageInfo.
8+
doc = """A target providing a `NpmPackageInfo` or `JsInfo` containing the package sources.
99
1010
Can be left unspecified to allow for npm_link_package "reference" targets. `npm_link_package`
1111
targets without a `src` are used internally by `npm_import` to create "reference"
@@ -18,13 +18,13 @@ _INTERNAL_ATTRS_STORE = dicts.add(_npm_package_store_lib.attrs, {
1818
"package": attr.string(
1919
doc = """The package name to link to.
2020
21-
Takes precedence over the package name in the NpmPackageInfo src.""",
21+
Takes precedence over the package name in the `NpmPackageInfo` src.""",
2222
mandatory = True,
2323
),
2424
"version": attr.string(
2525
doc = """The package version to link to.
2626
27-
Takes precedence over the package version in the NpmPackageInfo src.""",
27+
Takes precedence over the package version in the `NpmPackageInfo` src.""",
2828
mandatory = True,
2929
),
3030
})

0 commit comments

Comments
 (0)