refactor: handle breaking changes in rules_nodejs 1.0.0 (#34589)

The major one that affects the angular repo is the removal of the bootstrap attribute in nodejs_binary, nodejs_test and jasmine_node_test in favor of using templated_args --node_options=--require=/path/to/script. The side-effect of this is that the bootstrap script does not get the require.resolve patches with explicitly loading the targets _loader.js file.

PR Close #34589
This commit is contained in:
Greg Magolan
2019-12-28 18:14:36 -08:00
committed by atscott
parent a9f13015b2
commit 94e6452bac
69 changed files with 318 additions and 131 deletions

View File

@ -1,6 +1,6 @@
"""Re-export of some bazel rules with repository-wide defaults."""
load("@build_bazel_rules_nodejs//:index.bzl", _nodejs_binary = "nodejs_binary", _npm_package = "npm_package")
load("@build_bazel_rules_nodejs//:index.bzl", _nodejs_binary = "nodejs_binary", _pkg_npm = "pkg_npm")
load("@npm_bazel_jasmine//:index.bzl", _jasmine_node_test = "jasmine_node_test")
load("@npm_bazel_karma//:index.bzl", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite")
load("@npm_bazel_typescript//:index.bzl", _ts_devserver = "ts_devserver", _ts_library = "ts_library")
@ -93,7 +93,7 @@ def ts_devserver(**kwargs):
**kwargs
)
def ts_library(tsconfig = None, testonly = False, deps = [], module_name = None, **kwargs):
def ts_library(name, tsconfig = None, testonly = False, deps = [], module_name = None, **kwargs):
"""Default values for ts_library"""
deps = deps + ["@npm//tslib"]
if testonly:
@ -108,6 +108,7 @@ def ts_library(tsconfig = None, testonly = False, deps = [], module_name = None,
module_name = _default_module_name(testonly)
_ts_library(
name = name,
tsconfig = tsconfig,
testonly = testonly,
deps = deps,
@ -115,6 +116,17 @@ def ts_library(tsconfig = None, testonly = False, deps = [], module_name = None,
**kwargs
)
# Select the es5 .js output of the ts_library for use in downstream boostrap targets
# with `output_group = "es5_sources"`. This exposes an internal detail of ts_library
# that is not ideal.
# TODO(gregmagolan): clean this up by using tsc() in these cases rather than ts_library
native.filegroup(
name = "%s_es5" % name,
srcs = [":%s" % name],
testonly = testonly,
output_group = "es5_sources",
)
def ng_module(name, tsconfig = None, entry_point = None, testonly = False, deps = [], module_name = None, bundle_dts = True, **kwargs):
"""Default values for ng_module"""
deps = deps + ["@npm//tslib"]

View File

@ -6,6 +6,15 @@
* found in the LICENSE file at https://angular.io/license
*/
if (process.env['TEST_SRCDIR']) {
// bootstrap the bazel require resolve patch since this
// script is a bootstrap script loaded with --node_options=--require=...
const path = require('path');
require(path.posix.join(
process.env['TEST_SRCDIR'], process.env['TEST_WORKSPACE'],
(process.env['TEST_BINARY'] as string).replace(/\.(sh|bat)$/, '_loader.js'), ));
}
import 'zone.js/lib/node/rollup-main';
import 'zone.js/lib/zone-spec/long-stack-trace';
import 'zone.js/lib/zone-spec/task-tracking';

View File

@ -55,7 +55,10 @@ pkg_npm(
ts_library(
name = "test_lib",
testonly = True,
srcs = glob(["test/*.ts"]),
srcs = glob(
["test/*.ts"],
exclude = ["test/bootstrap.ts"],
),
tsconfig = "//tools:tsconfig-test",
deps = [
":lib",
@ -68,18 +71,40 @@ ts_library(
],
)
ts_library(
name = "bootstrap",
testonly = True,
srcs = ["test/bootstrap.ts"],
tsconfig = "//tools:tsconfig-test",
deps = ["@npm//@types/node"],
)
# Select the es5 .js output of the ts_library :boostrap target
# with `output_group = "es5_sources"` for use in the jasmine_node_test
# below. This exposes an internal detail of ts_library that is not ideal.
# TODO(gregmagolan): clean this up by using tsc() in this case rather than ts_library
filegroup(
name = "bootstrap_es5",
testonly = True,
srcs = [":bootstrap"],
output_group = "es5_sources",
)
jasmine_node_test(
name = "tests",
srcs = [":test_lib"],
bootstrap = ["angular/tools/ts-api-guardian/test/bootstrap.js"],
srcs = [
":test_lib",
],
data = glob([
"test/fixtures/*.ts",
"test/fixtures/*.patch",
]) + [
":bootstrap_es5",
":ts-api-guardian",
# TODO: remove this once the boostrap.js workaround has been removed.
":package.json",
],
templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap_es5))"],
)
# END-INTERNAL