From b788c36909d0d87d0353ca4d11465834b0c23f31 Mon Sep 17 00:00:00 2001 From: atscott Date: Fri, 10 Jan 2020 13:39:40 -0800 Subject: [PATCH] Revert "build: add a before-all-other bootstrap script that patches require (#34589)" (#34730) This reverts commit c3e843995434ace3e0a96faa950cd13f3ee90fbb. PR Close #34730 --- packages/core/test/render3/load_domino.ts | 6 +++++ .../zone.js/test/node_bluebird_entry_point.ts | 6 +++++ packages/zone.js/test/node_entry_point.ts | 6 +++++ .../test/node_entry_point_no_patch_clock.ts | 6 +++++ .../node_error_disable_policy_entry_point.ts | 6 +++++ .../node_error_lazy_policy_entry_point.ts | 6 +++++ tools/defaults.bzl | 7 +---- tools/testing/BUILD.bazel | 2 -- tools/testing/bazel_patch_require.js | 26 ------------------- tools/testing/init_node_spec.ts | 6 +++++ 10 files changed, 43 insertions(+), 34 deletions(-) delete mode 100644 tools/testing/bazel_patch_require.js diff --git a/packages/core/test/render3/load_domino.ts b/packages/core/test/render3/load_domino.ts index 8d9d549640..3fa4a37ea8 100644 --- a/packages/core/test/render3/load_domino.ts +++ b/packages/core/test/render3/load_domino.ts @@ -6,6 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ +// bootstrap the bazel require patch since this bootstrap script is loaded with +// `--node_options=--require=$(rlocation $(location script.js))` +if (process.env['BAZEL_NODE_RUNFILES_HELPER']) { + require(process.env['BAZEL_NODE_RUNFILES_HELPER'] as string).patchRequire(); +} + // Needed to run animation tests import 'zone.js/lib/node/rollup-main'; import '@angular/compiler'; // For JIT mode. Must be in front of any other @angular/* imports. diff --git a/packages/zone.js/test/node_bluebird_entry_point.ts b/packages/zone.js/test/node_bluebird_entry_point.ts index ae0da24027..41ca57f817 100644 --- a/packages/zone.js/test/node_bluebird_entry_point.ts +++ b/packages/zone.js/test/node_bluebird_entry_point.ts @@ -6,6 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ +// bootstrap the bazel require patch since this bootstrap script is loaded with +// `--node_options=--require=$(rlocation $(location script.js))` +if (process.env['BAZEL_NODE_RUNFILES_HELPER']) { + require(process.env['BAZEL_NODE_RUNFILES_HELPER'] as string).patchRequire(); +} + // Must be loaded before zone loads, so that zone can detect WTF. import './test_fake_polyfill'; diff --git a/packages/zone.js/test/node_entry_point.ts b/packages/zone.js/test/node_entry_point.ts index e63e7595d6..f63265b69a 100644 --- a/packages/zone.js/test/node_entry_point.ts +++ b/packages/zone.js/test/node_entry_point.ts @@ -13,6 +13,12 @@ * found in the LICENSE file at https://angular.io/license */ +// bootstrap the bazel require patch since this bootstrap script is loaded with +// `--node_options=--require=$(rlocation $(location script.js))` +if (process.env['BAZEL_NODE_RUNFILES_HELPER']) { + require(process.env['BAZEL_NODE_RUNFILES_HELPER'] as string).patchRequire(); +} + // Must be loaded before zone loads, so that zone can detect WTF. import './node-env-setup'; import './test_fake_polyfill'; diff --git a/packages/zone.js/test/node_entry_point_no_patch_clock.ts b/packages/zone.js/test/node_entry_point_no_patch_clock.ts index a91766407f..80d7c478bc 100644 --- a/packages/zone.js/test/node_entry_point_no_patch_clock.ts +++ b/packages/zone.js/test/node_entry_point_no_patch_clock.ts @@ -13,6 +13,12 @@ * found in the LICENSE file at https://angular.io/license */ +// bootstrap the bazel require patch since this bootstrap script is loaded with +// `--node_options=--require=$(rlocation $(location script.js))` +if (process.env['BAZEL_NODE_RUNFILES_HELPER']) { + require(process.env['BAZEL_NODE_RUNFILES_HELPER'] as string).patchRequire(); +} + // Must be loaded before zone loads, so that zone can detect WTF. import './node-env-setup'; import './test_fake_polyfill'; diff --git a/packages/zone.js/test/node_error_disable_policy_entry_point.ts b/packages/zone.js/test/node_error_disable_policy_entry_point.ts index 841039900d..61eb31cc12 100644 --- a/packages/zone.js/test/node_error_disable_policy_entry_point.ts +++ b/packages/zone.js/test/node_error_disable_policy_entry_point.ts @@ -6,6 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ +// bootstrap the bazel require patch since this bootstrap script is loaded with +// `--node_options=--require=$(rlocation $(location script.js))` +if (process.env['BAZEL_NODE_RUNFILES_HELPER']) { + require(process.env['BAZEL_NODE_RUNFILES_HELPER'] as string).patchRequire(); +} + process.env['errorpolicy'] = (global as any)['__Zone_Error_BlacklistedStackFrames_policy'] = 'disable'; import './node_error_entry_point'; diff --git a/packages/zone.js/test/node_error_lazy_policy_entry_point.ts b/packages/zone.js/test/node_error_lazy_policy_entry_point.ts index 61b5e56093..cb08a023cc 100644 --- a/packages/zone.js/test/node_error_lazy_policy_entry_point.ts +++ b/packages/zone.js/test/node_error_lazy_policy_entry_point.ts @@ -6,5 +6,11 @@ * found in the LICENSE file at https://angular.io/license */ +// bootstrap the bazel require patch since this bootstrap script is loaded with +// `--node_options=--require=$(rlocation $(location script.js))` +if (process.env['BAZEL_NODE_RUNFILES_HELPER']) { + require(process.env['BAZEL_NODE_RUNFILES_HELPER'] as string).patchRequire(); +} + process.env['errorpolicy'] = (global as any)['__Zone_Error_BlacklistedStackFrames_policy'] = 'lazy'; import './node_error_entry_point'; diff --git a/tools/defaults.bzl b/tools/defaults.bzl index 4d96e64f52..56618df1be 100644 --- a/tools/defaults.bzl +++ b/tools/defaults.bzl @@ -268,16 +268,11 @@ def jasmine_node_test(bootstrap = [], **kwargs): "@npm//source-map-support", "@npm//tslib", "@npm//xhr2", - "//tools/testing:bazel_patch_require.js", ] configuration_env_vars = kwargs.pop("configuration_env_vars", []) + [ "angular_ivy_enabled", ] - templated_args = [ - # bazel_patch_require.js must be first - # TODO(gregmagolan): remove this once linker has been applied to nodejs_binary targets by default in rules_nodejs - "--node_options=--require=$(rlocation $(location //tools/testing:bazel_patch_require.js))", - ] + kwargs.pop("templated_args", []) + templated_args = kwargs.pop("templated_args", []) for label in bootstrap: deps += [label] templated_args += ["--node_options=--require=$(rlocation $(location %s))" % label] diff --git a/tools/testing/BUILD.bazel b/tools/testing/BUILD.bazel index e29e450f40..705e4d562b 100644 --- a/tools/testing/BUILD.bazel +++ b/tools/testing/BUILD.bazel @@ -2,8 +2,6 @@ load("//tools:defaults.bzl", "ts_library") package(default_visibility = ["//visibility:public"]) -exports_files(["bazel_patch_require.js"]) - ts_library( name = "browser", testonly = 1, diff --git a/tools/testing/bazel_patch_require.js b/tools/testing/bazel_patch_require.js deleted file mode 100644 index 8b1d06f8e1..0000000000 --- a/tools/testing/bazel_patch_require.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -// Load the Bazel Node runfiles helper script and patch the NodeJS module resolution. This is -// necessary to ensure that imports are properly resolved in Bazel. By default, the module -// resolution is patched in `nodejs_binary` targets when the main script loads, but since we -// --require boostrap scripts before the main script, this bootstrap script is loaded first so that -// subsequent bootstrap scripts can resolve their imports. -// -// We're in a valley with the runfiles support right now having removed the `bootstrap` attribute -// for rule_nodejs 1.0 but not applied the linker to run targets yet in rules_nodejs. In a near -// future rules_nodejs release, the runfiles helper won't be required as standard node module -// resolution works with the linker. -// -// We could have left the `bootstrap` attribute in for 1.0 and removed it for 2.0 but since we had -// an alternate approach that we're using here that isn't going to be broken in the future by the -// linker being added we decided to pull it for 1.0 so that we have fewer major breaking changes in -// 2.0. -if (process.env['BAZEL_NODE_RUNFILES_HELPER']) { - require(process.env['BAZEL_NODE_RUNFILES_HELPER']).patchRequire(); -} diff --git a/tools/testing/init_node_spec.ts b/tools/testing/init_node_spec.ts index 7a0aa0eec6..54ec2186d2 100644 --- a/tools/testing/init_node_spec.ts +++ b/tools/testing/init_node_spec.ts @@ -6,6 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ +// bootstrap the bazel require patch since this bootstrap script is loaded with +// `--node_options=--require=$(rlocation $(location script.js))` +if (process.env['BAZEL_NODE_RUNFILES_HELPER']) { + require(process.env['BAZEL_NODE_RUNFILES_HELPER'] as string).patchRequire(); +} + import 'zone.js/lib/node/rollup-main'; import 'zone.js/lib/zone-spec/long-stack-trace'; import 'zone.js/lib/zone-spec/task-tracking';