From 4feaa88a791df5a345b4d48d4b2db4b1c8097279 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Thu, 10 Dec 2020 23:00:41 -0800 Subject: [PATCH] refactor: bazel_patch_module_resolver default to false This turns off our monkey-patches for require() for nodejs_binary, nodejs_test, and macros like jasmine_node_test. Note it was previously disabled for npm_package_bin and generated index.bzl binaries in #1440 BREAKING CHANGE: By default, we no longer patch the require() function, instead you should rely on the linker to make node modules resolvable at the standard location if this breaks you, the quickest fix is to flip the flag back on a nodejs_binary/nodejs_test/npm_package_bin with `templated_args = ["--bazel_patch_module_resolver"]`, see https://github.com/bazelbuild/rules_nodejs/pull/2344 as an example. Another fix is to explicitly use our runfiles helper library, see https://github.com/bazelbuild/rules_nodejs/pull/2341 as an example. Fixes #2125 --- internal/node/launcher.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/internal/node/launcher.sh b/internal/node/launcher.sh index 0fac88789c..7fdec0d188 100644 --- a/internal/node/launcher.sh +++ b/internal/node/launcher.sh @@ -179,8 +179,7 @@ EXIT_CODE_CAPTURE="" RUN_LINKER=true NODE_PATCHES=true -# TODO(alex): change the default to false -PATCH_REQUIRE=true +PATCH_REQUIRE=false for ARG in ${ALL_ARGS[@]+"${ALL_ARGS[@]}"}; do case "$ARG" in # Supply custom linker arguments for first-party dependencies @@ -193,10 +192,9 @@ for ARG in ${ALL_ARGS[@]+"${ALL_ARGS[@]}"}; do --bazel_capture_exit_code=*) EXIT_CODE_CAPTURE="${ARG#--bazel_capture_exit_code=}" ;; # Disable the node_loader.js monkey patches for require() # Note that this means you need an explicit runfiles helper library + # This flag is now a no-op since the default is also false --nobazel_patch_module_resolver) PATCH_REQUIRE=false ;; # Enable the node_loader.js monkey patches for require() - # Currently a no-op, but specifying this makes the behavior unchanged when we update - # the default for PATCH_REQUIRE above --bazel_patch_module_resolver) PATCH_REQUIRE=true ;; # Disable the --require node-patches (undocumented and unused; only here as an escape value) --nobazel_node_patches) NODE_PATCHES=false ;;