3.6.0
Upgrade with
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "0fa2d443571c9e02fcb7363a74ae591bdcce2dd76af8677a95965edf329d778a",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/3.6.0/rules_nodejs-3.6.0.tar.gz"],
)
and update @bazel
-scoped npm packages as well.
Features
major performance improvement: node_modules can now be directories
In every prior release of rules_nodejs, third-party libraries from npm (node_modules) were given generated BUILD files that used a filegroup
to expose all the files in the package. Since npm typically has a very high library re-use, it's easy for a project using something like create-react-scripts (or any high-level workflow/build tool) to have tens of thousands of these files. This doesn't work well under Bazel's sandbox or runfiles features, because these do some filesystem operation for every file.
This release adds an add opt-in exports_directories_only mode to yarn_install and npm_install. It defaults to False, but we intend to flip the default to True in our next major release (4.0)
To opt-in, in your WORKSPACE:
npm_install(
name = "npm",
...
# export only top-level package directory artifacts from node_modules
exports_directories_only = True,
)
Then, to avoid warnings from Bazel about directories as sources, add this to your .bazelrc
:
startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1
Turning this on will decrease the time it takes for Bazel to setup runfiles and sandboxing when
there are a large number of npm dependencies as inputs to an action. One user observed an improvement from ~48m to ~30m on their build.
This breaks compatibilty for labels that reference files within npm packages such as @npm//:node_modules/prettier/bin-prettier.js
.
To reference files within npm packages, you can use the directory_file_path
rule and/or DirectoryFilePathInfo
provider.
Note, some rules still need upgrading to support consuming DirectoryFilePathInfo
where needed.
NB: This feature requires runfiles be enabled due to an issue in Bazel which we are still investigating.
On Windows runfiles are off by default and must be enabled with the --enable_runfiles
flag when
using this feature.
NB: ts_library
does not support directory artifact npm deps due to internal design choice of having all input sources files explicitly specified
NB: karma_web_test
and karma_web_test_suite
do not yet support directory artifact npm deps as they require node_modules/requirejs/require.js
& node_modules/karma-requirejs/lib/adapter.js
explicit source files in deps
For the nodejs_binary
& nodejs_test
entry_point
attribute (which often needs to reference a file within
an npm package) you can set the entry_point to a dict with a single entry, where the key corresponds to the directory artifact
label and the value corresponds to the path within that directory to the entry point.
For example,
nodejs_binary(
name = "prettier",
data = ["@npm//prettier"],
entry_point = "@npm//:node_modules/prettier/bin-prettier.js",
)
becomes,
nodejs_binary(
name = "prettier",
data = ["@npm//prettier"],
entry_point = { "@npm//:node_modules/prettier": "bin-prettier.js" },
)
For other labels that are passed to $(rootpath)
, $(execpath)
, or $(location)
you can simply break these apart into
the directory artifact label that gets passed to the expander & path part to follows it.
For example,
$(rootpath @npm//:node_modules/prettier/bin-prettier.js")
becomes,
$(rootpath @npm//:node_modules/prettier)/bin-prettier.js
Other features
- support dict style directory_file_path entry_point in nodejs_binary, nodejs_test & jasmine_node_test (737674f)
- support directory_file_path entry_point in npm_umd_bundle (4e44178)
Bug Fixes
- allow for only stderr to be set on npm_package_bin (fa8f5b1)
- builtin: add two missing locations where Mac M1 support needs to be declared (2ad950f), closes #2733
- builtin: propogate tags to both generated targets in generated_file_test (c4403fc)
- builtin: support directory_file_path entry_point in nodejs_binary & nodejs_test when --bazel_patch_module_resolver is set (51676ef)
- jasmine: don't assume entry_point is a label as it may now be a dict (3683466)
- jasmine: unhanded promise rejection causes tests suit to pass (3c4ef58), closes 3.7.0/lib/jasmine.js#L267 #2688
- terser: make terser resolve more robust by not assuming a single /terser/ segment in the path (4709ffb)
- typescript: fixed "output was not created" error for ts_project with supports_workers (807b07b)
- typescript: repair error reporting when a ts_project is missing declaration=True (cd08efe)