build: use bazel ts_library rule to build @angular/ssr

The `@angular/ssr` package does not require the Angular compiler and can instead use the
`ts_library` to compile the TypeScript code.  The `@angular/bazel` package has also been
update and a more limited patch is now used due to only needing the `ng_package` rule.
The continued use of the `ng_package` rule maintains the existing output structure for the
`@angular/ssr` package.
This commit is contained in:
Charles Lyding 2023-08-29 18:17:21 -04:00 committed by Alan Agius
parent 51414b6de3
commit a00b21afdf
6 changed files with 21 additions and 121 deletions

View File

@ -69,7 +69,7 @@ yarn_install(
data = [
"//:.yarn/releases/yarn-1.22.17.cjs",
"//:.yarnrc",
"//:tools/postinstall/patches/@angular+bazel+16.0.0-next.6.patch",
"//:tools/postinstall/patches/@angular+bazel+17.0.0-next.1.patch",
"//:tools/postinstall/patches/@bazel+concatjs+5.8.1.patch",
],
# Currently disabled due to:

View File

@ -60,7 +60,7 @@
"devDependencies": {
"@ampproject/remapping": "2.2.1",
"@angular/animations": "17.0.0-next.1",
"@angular/bazel": "https://github.com/angular/bazel-builds.git#bac9c1abe1e6ac1801fbbccb53353a1ed7126469",
"@angular/bazel": "https://github.com/angular/bazel-builds.git#392c26f29f65e6141cf336e9eb372c4e5b7e9c3d",
"@angular/build-tooling": "https://github.com/angular/dev-infra-private-build-tooling-builds.git#22a9a75114d5e80907054f01b9fa360972de1c05",
"@angular/cdk": "17.0.0-next.0",
"@angular/common": "17.0.0-next.1",

View File

@ -1,16 +1,17 @@
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("//tools:defaults.bzl", "ng_module", "ng_package")
load("//tools:defaults.bzl", "ng_package", "ts_library")
load("@npm//@angular/build-tooling/bazel/api-golden:index.bzl", "api_golden_test_npm_package")
package(default_visibility = ["//visibility:public"])
ng_module(
ts_library(
name = "ssr",
package_name = "@angular/ssr",
srcs = glob([
"*.ts",
"src/**/*.ts",
]),
module_name = "@angular/ssr",
deps = [
"@npm//@angular/core",
"@npm//@angular/platform-server",

View File

@ -1,101 +0,0 @@
diff --git a/node_modules/@angular/bazel/src/ng_module/ng_module.bzl b/node_modules/@angular/bazel/src/ng_module/ng_module.bzl
index 99d7f6d..3ea60ea 100755
--- a/node_modules/@angular/bazel/src/ng_module/ng_module.bzl
+++ b/node_modules/@angular/bazel/src/ng_module/ng_module.bzl
@@ -18,6 +18,7 @@ load(
"TsConfigInfo",
"compile_ts",
"js_ecma_script_module_info",
+ "js_named_module_info",
"js_module_info",
"node_modules_aspect",
"ts_providers_dict_to_struct",
@@ -151,9 +152,9 @@ def _ngc_tsconfig(ctx, files, srcs, **kwargs):
is_devmode = "devmode_manifest" in kwargs
outs = _expected_outs(ctx)
if is_devmode:
- expected_outs = outs.devmode_js
+ expected_outs = outs.devmode_js + outs.declarations
else:
- expected_outs = outs.closure_js + outs.declarations
+ expected_outs = outs.closure_js
if not ctx.attr.type_check and ctx.attr.strict_templates:
fail("Cannot set type_check = False and strict_templates = True for ng_module()")
@@ -359,11 +360,11 @@ def _compile_action(
def _prodmode_compile_action(ctx, inputs, outputs, tsconfig_file, node_opts):
outs = _expected_outs(ctx)
- return _compile_action(ctx, inputs, outputs + outs.closure_js + outs.prod_perf_files + outs.declarations, tsconfig_file, node_opts, "prodmode")
+ return _compile_action(ctx, inputs, outputs + outs.closure_js + outs.prod_perf_files, tsconfig_file, node_opts, "prodmode")
def _devmode_compile_action(ctx, inputs, outputs, tsconfig_file, node_opts):
outs = _expected_outs(ctx)
- compile_action_outputs = outputs + outs.devmode_js + outs.dev_perf_files
+ compile_action_outputs = outputs + outs.devmode_js + outs.dev_perf_files + outs.declarations
_compile_action(ctx, inputs, compile_action_outputs, tsconfig_file, node_opts, "devmode")
# Note: We need to define `label` and `srcs_files` as `tsc_wrapped` passes
@@ -417,9 +418,13 @@ def _ng_module_impl(ctx):
# and issue https://github.com/bazelbuild/rules_nodejs/issues/57 for more details.
ts_providers["providers"].extend([
js_module_info(
- sources = ts_providers["typescript"]["es6_sources"],
+ sources = ts_providers["typescript"]["es5_sources"],
deps = ctx.attr.deps,
),
+ js_named_module_info(
+ sources = ts_providers["typescript"]["es5_sources"],
+ deps = ctx.attr.deps,
+ ),
js_ecma_script_module_info(
sources = ts_providers["typescript"]["es6_sources"],
deps = ctx.attr.deps,
@@ -435,7 +440,7 @@ def _ng_module_impl(ctx):
package_name = ctx.attr.package_name,
package_path = ctx.attr.package_path,
path = path,
- files = ts_providers["typescript"]["es6_sources"],
+ files = ts_providers["typescript"]["es5_sources"],
))
return ts_providers_dict_to_struct(ts_providers)
diff --git a/node_modules/@angular/bazel/src/ngc-wrapped/index.mjs b/node_modules/@angular/bazel/src/ngc-wrapped/index.mjs
index 8681a4c..e3b497a 100755
--- a/node_modules/@angular/bazel/src/ngc-wrapped/index.mjs
+++ b/node_modules/@angular/bazel/src/ngc-wrapped/index.mjs
@@ -13,7 +13,7 @@ import * as fs from 'fs';
import * as path from 'path';
import * as tsickle from 'tsickle';
import ts from 'typescript';
-import { EXT, patchNgHostWithFileNameToModuleName as patchNgHost, relativeToRootDirs } from './utils';
+import { EXT, patchNgHostWithFileNameToModuleName as patchNgHost, relativeToRootDirs } from './utils.mjs';
// FIXME: we should be able to add the assets to the tsconfig so FileLoader
// knows about them
const NGC_ASSETS = /\.(css|html)$/;
@@ -351,6 +351,12 @@ function gatherDiagnosticsForInputsOnly(options, bazelOpts, ngProgram) {
}
return diagnostics;
}
+
+main(process.argv.slice(2)).then(exitCode => process.exitCode = exitCode).catch(e => {
+ console.error(e);
+ process.exitCode = 1;
+});
+
/**
* @deprecated
* Kept here just for compatibility with 1P tools. To be removed soon after 1P update.
diff --git a/node_modules/@angular/bazel/src/ngc-wrapped/ngc-wrapped-main.mjs b/node_modules/@angular/bazel/src/ngc-wrapped/ngc-wrapped-main.mjs
index 3649c11..0f4af3c 100755
--- a/node_modules/@angular/bazel/src/ngc-wrapped/ngc-wrapped-main.mjs
+++ b/node_modules/@angular/bazel/src/ngc-wrapped/ngc-wrapped-main.mjs
@@ -5,7 +5,7 @@
* 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
*/
-import { main } from './index';
+import { main } from './index.mjs';
main(process.argv.slice(2)).then(exitCode => process.exitCode = exitCode).catch(e => {
console.error(e);
process.exitCode = 1;

View File

@ -0,0 +1,13 @@
diff --git a/node_modules/@angular/bazel/src/ng_package/packager.mjs b/node_modules/@angular/bazel/src/ng_package/packager.mjs
index 9454623..d28910a 100755
--- a/node_modules/@angular/bazel/src/ng_package/packager.mjs
+++ b/node_modules/@angular/bazel/src/ng_package/packager.mjs
@@ -7,7 +7,7 @@
*/
import * as fs from 'fs';
import * as path from 'path';
-import { analyzeFileAndEnsureNoCrossImports } from './cross_entry_points_imports';
+import { analyzeFileAndEnsureNoCrossImports } from './cross_entry_points_imports.mjs';
/**
* List of known `package.json` fields which provide information about
* supported package formats and their associated entry paths.

View File

@ -121,13 +121,12 @@
dependencies:
tslib "^2.3.0"
"@angular/bazel@https://github.com/angular/bazel-builds.git#bac9c1abe1e6ac1801fbbccb53353a1ed7126469":
version "16.0.0-next.6"
resolved "https://github.com/angular/bazel-builds.git#bac9c1abe1e6ac1801fbbccb53353a1ed7126469"
"@angular/bazel@https://github.com/angular/bazel-builds.git#392c26f29f65e6141cf336e9eb372c4e5b7e9c3d":
version "17.0.0-next.1"
resolved "https://github.com/angular/bazel-builds.git#392c26f29f65e6141cf336e9eb372c4e5b7e9c3d"
dependencies:
"@microsoft/api-extractor" "^7.24.2"
magic-string "^0.30.0"
tsickle "^0.46.3"
tslib "^2.3.0"
"@angular/benchpress@0.3.0":
@ -3626,11 +3625,6 @@
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca"
integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==
"@types/minimist@^1.2.1":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c"
integrity sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==
"@types/node-fetch@*", "@types/node-fetch@^2.1.6":
version "2.6.4"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.4.tgz#1bc3a26de814f6bf466b25aeb1473fa1afe6a660"
@ -12146,13 +12140,6 @@ tsconfig-paths@^3.14.2:
minimist "^1.2.6"
strip-bom "^3.0.0"
tsickle@^0.46.3:
version "0.46.3"
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.46.3.tgz#b74918a77e3ca1310a2ce4d019f5d6294360b56d"
integrity sha512-9PDXxOrtn2AdpvDin6FLGveXVGg8ec3ga8fh8mPR5lz9KtitW6riVgxgagicdfF1rgiBxDeH+5hVowPXhmZbYQ==
dependencies:
"@types/minimist" "^1.2.1"
tslib@2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.1.tgz#fd8c9a0ff42590b25703c0acb3de3d3f4ede0410"