Files
angular__angular/packages/bazel/BUILD.bazel
T

40 lines
1.8 KiB
Python
Raw Normal View History

build: upgrade angular build, integration/bazel and @angular/bazel package to rule_nodejs 2.2.0 (#39182) 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
2020-06-25 01:32:41 -07:00
# BEGIN-DEV-ONLY
load("//tools:defaults.bzl", "pkg_npm")
pkg_npm(
name = "npm_package",
srcs = glob(
["*"],
exclude = ["yarn.lock"],
) + [
"//packages/bazel/src:package_assets",
feat(bazel): create transition for enabling partial compilation (#43431) Creates, a currently still unused, Bazel transition that will control a build setting that is enabling the partial compilation mode for `ng_module` rule targets. This is in preparation of implementing the Angular Package Format v13 (which should ship in partial compilation). Note: Various other approaches aside from the `transition` has been considered. Here is a small summary of the largest ideas that have been tried for the APF v13 partial compilation refactor. **Using an aspect for partial compilation in `ng_package`** Similar to how we had an aspect for ESM5 compilation in the past, an aspect could be used to create partial compilation prodmode output for packaging. The aspect would take the existing prodmode compilation details and "replay" the compilation with a modified tsconfig that enables partial compilation. This _can_ work but requires lots of caution and is very prone to issues. In order to avoid conflicts with the existing prodmode output, the partial compilation outputs would need to be written to a sub-directory. This makes module resolution extremely difficult when `ng_package` creates the FESM bundles. Also it is difficult to merge multiple of these aspect-compiled folders into a single one for exposing the non-bundled ESM output. It becomes especially difficult to ensure that such an aspect target will actually use the _correct_ dependency type definition when compiled. e.g. consider a case where a partial compiled target relies on another Angular target. The dependency will be compiled partially first, but the other target _needs_ to rely on the partial compilation `d.ts` output of the dependency (and *NOT* the devmode `.d.ts` output). This is incorrect and can cause other type-checking issues / or invalid output. To make this work, the module resolution when invoking tsc_wrapped would also need to be updated/patched. This is out of scope and not reasonable to maintain. **Exposing a third output flavor directly in the rule** Instead of replying a compilation, we could expose an output flavor next to `devmode` and `prodmode`. This sounded like the easiest solution at first, but it will have the same problems as the aspect approach (in terms of module resoltion and avoiding conflicts of files). We cannot control how TS emits `.d.ts` or `.js` files (without patching into the compiler host), so we would need to store the compilation output in a sub-folder similar to the aspect.. resulting in the same issues. This is do-able but would require module resolution to be patched and we do not have control over `@bazel/typescript`. Also, `@bazel/typescript` does not forsee a third output flavor, so that logic would need to be changed significantly as well. PR Close #43431
2021-09-27 23:56:23 +02:00
"//packages/bazel/src/ng_module:package_assets",
"//packages/bazel/src/types_bundle:package_assets",
"//packages/bazel/src/ng_package:package_assets",
"//packages/bazel/src/ngc-wrapped:package_assets",
"//packages/bazel/third_party/github.com/bazelbuild/bazel/src/main/protobuf:package_assets",
],
substitutions = {
"(#|//)\\s+BEGIN-DEV-ONLY[\\w\\W]+?(#|//)\\s+END-DEV-ONLY": "",
feat(bazel): create transition for enabling partial compilation (#43431) Creates, a currently still unused, Bazel transition that will control a build setting that is enabling the partial compilation mode for `ng_module` rule targets. This is in preparation of implementing the Angular Package Format v13 (which should ship in partial compilation). Note: Various other approaches aside from the `transition` has been considered. Here is a small summary of the largest ideas that have been tried for the APF v13 partial compilation refactor. **Using an aspect for partial compilation in `ng_package`** Similar to how we had an aspect for ESM5 compilation in the past, an aspect could be used to create partial compilation prodmode output for packaging. The aspect would take the existing prodmode compilation details and "replay" the compilation with a modified tsconfig that enables partial compilation. This _can_ work but requires lots of caution and is very prone to issues. In order to avoid conflicts with the existing prodmode output, the partial compilation outputs would need to be written to a sub-directory. This makes module resolution extremely difficult when `ng_package` creates the FESM bundles. Also it is difficult to merge multiple of these aspect-compiled folders into a single one for exposing the non-bundled ESM output. It becomes especially difficult to ensure that such an aspect target will actually use the _correct_ dependency type definition when compiled. e.g. consider a case where a partial compiled target relies on another Angular target. The dependency will be compiled partially first, but the other target _needs_ to rely on the partial compilation `d.ts` output of the dependency (and *NOT* the devmode `.d.ts` output). This is incorrect and can cause other type-checking issues / or invalid output. To make this work, the module resolution when invoking tsc_wrapped would also need to be updated/patched. This is out of scope and not reasonable to maintain. **Exposing a third output flavor directly in the rule** Instead of replying a compilation, we could expose an output flavor next to `devmode` and `prodmode`. This sounded like the easiest solution at first, but it will have the same problems as the aspect approach (in terms of module resoltion and avoiding conflicts of files). We cannot control how TS emits `.d.ts` or `.js` files (without patching into the compiler host), so we would need to store the compilation output in a sub-folder similar to the aspect.. resulting in the same issues. This is do-able but would require module resolution to be patched and we do not have control over `@bazel/typescript`. Also, `@bazel/typescript` does not forsee a third output flavor, so that logic would need to be changed significantly as well. PR Close #43431
2021-09-27 23:56:23 +02:00
# The partial compilation transition is applied in the user workspace. We do not want to require
# users having to define the build setting, so we directly point the flag label to the place where
# we expect `@angular/bazel` being located. Note: This expects the `@npm//` workspace to be used.
"//packages/bazel/src:partial_compilation": "@npm//@angular/bazel/src:partial_compilation",
# Substitutions to account for label changes when `@angular/bazel` is consumed externally.
# NodeJS binaries are pre-built and should be consumed through the NPM bin scripts of the package.
"//packages/bazel/src/types_bundle:types_bundler": "@npm//@angular/bazel/bin:types_bundler",
build: upgrade angular build, integration/bazel and @angular/bazel package to rule_nodejs 2.2.0 (#39182) 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
2020-06-25 01:32:41 -07:00
"//packages/bazel/": "//@angular/bazel/",
"@npm//@bazel/concatjs/internal:": "//@bazel/concatjs/internal:",
},
tags = ["release-with-framework"],
# Do not add more to this list.
# Dependencies on the full npm_package cause long re-builds.
visibility = ["//integration:__subpackages__"],
deps = [
"//packages/bazel/src/ng_package:lib",
"//packages/bazel/src/ngc-wrapped:ngc_lib",
"//packages/bazel/src/types_bundle:lib",
],
)
build: upgrade angular build, integration/bazel and @angular/bazel package to rule_nodejs 2.2.0 (#39182) 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
2020-06-25 01:32:41 -07:00
# END-DEV-ONLY