42a164f522
Updates to rules_nodejs 2.2.0. This is the first major release in 7 months and includes a number of features as well as breaking changes. Release notes: https://github.com/bazelbuild/rules_nodejs/releases/tag/2.0.0 Features of note for angular/angular: * stdout/stderr/exit code capture; this could be potentially be useful * TypeScript (ts_project); a simpler tsc rule that ts_library that can be used in the repo where ts_library is too heavy weight Breaking changes of note for angular/angular: * loading custom rules from npm packages: `ts_library` is no longer loaded from `@npm_bazel_typescript//:index.bzl` (which no longer exists) but is now loaded from `@npm//@bazel/typescript:index.bzl` * with the loading changes above, `load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")` is no longer needed in the WORKSPACE which also means that yarn_install does not need to run unless building/testing a target that depends on @npm. In angular/angular this is a minor improvement as almost everything depends on @npm. * @angular/bazel package is also updated in this PR to support the new load location; Angular + Bazel users that require it for ng_package (ng_module is no longer needed in OSS with Angular 10) will need to load from `@npm//@angular/bazel:index.bzl`. I investigated if it was possible to maintain backward compatability for the old load location `@npm_angular_bazel` but it is not since the package itself needs to be updated to load from `@npm//@bazel/typescript:index.bzl` instead of `@npm_bazel_typescript//:index.bzl` as it depends on ts_library internals for ng_module. * runfiles.resolve will now throw instead of returning undefined to match behavior of node require Other changes in angular/angular: * integration/bazel has been updated to use both ng_module and ts_libary with use_angular_plugin=true. The latter is the recommended way for rules_nodejs users to compile Angular 10 with Ivy. Bazel + Angular ViewEngine is supported with @angular/bazel <= 9.0.5 and Angular <= 8. There is still Angular ViewEngine example on rules_nodejs https://github.com/bazelbuild/rules_nodejs/tree/stable/examples/angular_view_engine on these older versions but users that want to update to Angular 10 and are on Bazel must switch to Ivy and at that point ts_library with use_angular_plugin=true is more performant that ng_module. Angular example in rules_nodejs is configured this way as well: https://github.com/bazelbuild/rules_nodejs/tree/stable/examples/angular. As an aside, we also have an example of building Angular 10 with architect() rule directly instead of using ts_library with angular plugin: https://github.com/bazelbuild/rules_nodejs/tree/stable/examples/angular_bazel_architect. NB: ng_module is still required for angular/angular repository as it still builds ViewEngine & @angular/bazel also provides the ng_package rule. ng_module can be removed in the future if ViewEngine is no longer needed in angular repo. * JSModuleInfo provider added to ng_module. this is for forward compat for future rules_nodejs versions. PR Close #39182
116 lines
2.8 KiB
Python
116 lines
2.8 KiB
Python
# BEGIN-INTERNAL
|
|
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
|
|
load("@npm//@bazel/typescript:index.bzl", "ts_library")
|
|
load("//tools:defaults.bzl", "jasmine_node_test")
|
|
|
|
ts_library(
|
|
name = "lib",
|
|
srcs = glob(["lib/*.ts"]),
|
|
module_name = "ts-api-guardian",
|
|
tsconfig = "//tools:tsconfig.json",
|
|
visibility = ["//visibility:public"],
|
|
deps = [
|
|
"@npm//@types/diff",
|
|
"@npm//@types/minimist",
|
|
"@npm//@types/node",
|
|
"@npm//chalk",
|
|
"@npm//diff",
|
|
"@npm//minimist",
|
|
"@npm//typescript",
|
|
],
|
|
)
|
|
|
|
# Copy Angular's license to govern ts-api-guardian as well.
|
|
# We use a genrule to put it in this package, so it will be in the right root directory.
|
|
genrule(
|
|
name = "license",
|
|
srcs = ["//:LICENSE"],
|
|
outs = ["LICENSE"],
|
|
cmd = "cp $< $@",
|
|
)
|
|
|
|
pkg_npm(
|
|
name = "ts-api-guardian",
|
|
srcs = [
|
|
"BUILD.bazel",
|
|
"README.md",
|
|
"bin/ts-api-guardian",
|
|
"index.bzl",
|
|
"package.json",
|
|
],
|
|
substitutions = {
|
|
"@angular//tools/ts-api-guardian:bin": "@npm_ts_api_guardian//:bin",
|
|
"@angular//tools/ts-api-guardian:lib": "@npm//ts-api-guardian",
|
|
"angular/tools/ts-api-guardian/": "npm_ts_api_guardian/",
|
|
},
|
|
deps = [
|
|
":lib",
|
|
":license",
|
|
],
|
|
)
|
|
|
|
#######################################3
|
|
# Tests for this package
|
|
|
|
ts_library(
|
|
name = "test_lib",
|
|
testonly = True,
|
|
srcs = glob(
|
|
["test/*.ts"],
|
|
exclude = ["test/bootstrap.ts"],
|
|
),
|
|
tsconfig = "//tools:tsconfig-test",
|
|
deps = [
|
|
":lib",
|
|
"@npm//@types/chai",
|
|
"@npm//@types/jasmine",
|
|
"@npm//@types/node",
|
|
"@npm//chai",
|
|
"@npm//jasmine",
|
|
"@npm//typescript",
|
|
],
|
|
)
|
|
|
|
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 = [":bootstrap_es5"],
|
|
data = glob([
|
|
"test/fixtures/*.ts",
|
|
"test/fixtures/*.patch",
|
|
]) + [
|
|
":ts-api-guardian",
|
|
],
|
|
)
|
|
# END-INTERNAL
|
|
|
|
filegroup(
|
|
name = "bin",
|
|
srcs = glob(["lib/*.js"]) + ["bin/ts-api-guardian"],
|
|
visibility = ["//visibility:public"],
|
|
)
|
|
|
|
# Exported to be referenced as entry_point of the nodejs_binary
|
|
exports_files(["bin/ts-api-guardian"])
|