Skip to content

Commit c3e8439

Browse files
gregmagolanatscott
authored andcommitted
build: add a before-all-other bootstrap script that patches require (angular#34589)
This removes the churn in the existing bootstrap scripts. PR Close angular#34589
1 parent 4754e49 commit c3e8439

10 files changed

Lines changed: 34 additions & 43 deletions

packages/core/test/render3/load_domino.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
// bootstrap the bazel require patch since this bootstrap script is loaded with
10-
// `--node_options=--require=$(rlocation $(location script.js))`
11-
if (process.env['BAZEL_NODE_RUNFILES_HELPER']) {
12-
require(process.env['BAZEL_NODE_RUNFILES_HELPER'] as string).patchRequire();
13-
}
14-
159
// Needed to run animation tests
1610
import 'zone.js/lib/node/rollup-main';
1711
import '@angular/compiler'; // For JIT mode. Must be in front of any other @angular/* imports.

packages/zone.js/test/node_bluebird_entry_point.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
// bootstrap the bazel require patch since this bootstrap script is loaded with
10-
// `--node_options=--require=$(rlocation $(location script.js))`
11-
if (process.env['BAZEL_NODE_RUNFILES_HELPER']) {
12-
require(process.env['BAZEL_NODE_RUNFILES_HELPER'] as string).patchRequire();
13-
}
14-
159
// Must be loaded before zone loads, so that zone can detect WTF.
1610
import './test_fake_polyfill';
1711

packages/zone.js/test/node_entry_point.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
* found in the LICENSE file at https://angular.io/license
1414
*/
1515

16-
// bootstrap the bazel require patch since this bootstrap script is loaded with
17-
// `--node_options=--require=$(rlocation $(location script.js))`
18-
if (process.env['BAZEL_NODE_RUNFILES_HELPER']) {
19-
require(process.env['BAZEL_NODE_RUNFILES_HELPER'] as string).patchRequire();
20-
}
21-
2216
// Must be loaded before zone loads, so that zone can detect WTF.
2317
import './node-env-setup';
2418
import './test_fake_polyfill';

packages/zone.js/test/node_entry_point_no_patch_clock.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
* found in the LICENSE file at https://angular.io/license
1414
*/
1515

16-
// bootstrap the bazel require patch since this bootstrap script is loaded with
17-
// `--node_options=--require=$(rlocation $(location script.js))`
18-
if (process.env['BAZEL_NODE_RUNFILES_HELPER']) {
19-
require(process.env['BAZEL_NODE_RUNFILES_HELPER'] as string).patchRequire();
20-
}
21-
2216
// Must be loaded before zone loads, so that zone can detect WTF.
2317
import './node-env-setup';
2418
import './test_fake_polyfill';

packages/zone.js/test/node_error_disable_policy_entry_point.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
// bootstrap the bazel require patch since this bootstrap script is loaded with
10-
// `--node_options=--require=$(rlocation $(location script.js))`
11-
if (process.env['BAZEL_NODE_RUNFILES_HELPER']) {
12-
require(process.env['BAZEL_NODE_RUNFILES_HELPER'] as string).patchRequire();
13-
}
14-
159
process.env['errorpolicy'] = (global as any)['__Zone_Error_BlacklistedStackFrames_policy'] =
1610
'disable';
1711
import './node_error_entry_point';

packages/zone.js/test/node_error_lazy_policy_entry_point.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,5 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
// bootstrap the bazel require patch since this bootstrap script is loaded with
10-
// `--node_options=--require=$(rlocation $(location script.js))`
11-
if (process.env['BAZEL_NODE_RUNFILES_HELPER']) {
12-
require(process.env['BAZEL_NODE_RUNFILES_HELPER'] as string).patchRequire();
13-
}
14-
159
process.env['errorpolicy'] = (global as any)['__Zone_Error_BlacklistedStackFrames_policy'] = 'lazy';
1610
import './node_error_entry_point';

tools/defaults.bzl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,16 @@ def jasmine_node_test(bootstrap = [], **kwargs):
268268
"@npm//source-map-support",
269269
"@npm//tslib",
270270
"@npm//xhr2",
271+
"//tools/testing:bazel_patch_require.js",
271272
]
272273
configuration_env_vars = kwargs.pop("configuration_env_vars", []) + [
273274
"angular_ivy_enabled",
274275
]
275-
templated_args = kwargs.pop("templated_args", [])
276+
templated_args = [
277+
# bazel_patch_require.js must be first
278+
# TODO(gregmagolan): remove this once linker has been applied to nodejs_binary targets by default in rules_nodejs
279+
"--node_options=--require=$(rlocation $(location //tools/testing:bazel_patch_require.js))",
280+
] + kwargs.pop("templated_args", [])
276281
for label in bootstrap:
277282
deps += [label]
278283
templated_args += ["--node_options=--require=$(rlocation $(location %s))" % label]

tools/testing/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ load("//tools:defaults.bzl", "ts_library")
22

33
package(default_visibility = ["//visibility:public"])
44

5+
exports_files(["bazel_patch_require.js"])
6+
57
ts_library(
68
name = "browser",
79
testonly = 1,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
// Load the Bazel Node runfiles helper script and patch the NodeJS module resolution. This is
10+
// necessary to ensure that imports are properly resolved in Bazel. By default, the module
11+
// resolution is patched in `nodejs_binary` targets when the main script loads, but since we
12+
// --require boostrap scripts before the main script, this bootstrap script is loaded first so that
13+
// subsequent bootstrap scripts can resolve their imports.
14+
//
15+
// We're in a valley with the runfiles support right now having removed the `bootstrap` attribute
16+
// for rule_nodejs 1.0 but not applied the linker to run targets yet in rules_nodejs. In a near
17+
// future rules_nodejs release, the runfiles helper won't be required as standard node module
18+
// resolution works with the linker.
19+
//
20+
// We could have left the `bootstrap` attribute in for 1.0 and removed it for 2.0 but since we had
21+
// an alternate approach that we're using here that isn't going to be broken in the future by the
22+
// linker being added we decided to pull it for 1.0 so that we have fewer major breaking changes in
23+
// 2.0.
24+
if (process.env['BAZEL_NODE_RUNFILES_HELPER']) {
25+
require(process.env['BAZEL_NODE_RUNFILES_HELPER']).patchRequire();
26+
}

tools/testing/init_node_spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
// bootstrap the bazel require patch since this bootstrap script is loaded with
10-
// `--node_options=--require=$(rlocation $(location script.js))`
11-
if (process.env['BAZEL_NODE_RUNFILES_HELPER']) {
12-
require(process.env['BAZEL_NODE_RUNFILES_HELPER'] as string).patchRequire();
13-
}
14-
159
import 'zone.js/lib/node/rollup-main';
1610
import 'zone.js/lib/zone-spec/long-stack-trace';
1711
import 'zone.js/lib/zone-spec/task-tracking';

0 commit comments

Comments
 (0)