Skip to content

Commit e2aa475

Browse files
committed
build: migrate @angular/ssr tests to rules_js
Migrates the SSR tesst to run natively via `rules_js`. Notably, we still need the bundling in between as the tests and SSR plain code is not valid ESM technically; due to lack of extensions. We'll need to revisit this in the future, or at the very least come up with a `rules_js`-variant of the `spec_bundle`; but for this is sufficient and unblocks other packages.
1 parent fece30a commit e2aa475

13 files changed

+104
-23
lines changed

.aspect/rules/external_repository_action_cache/npm_translate_lock_MzA5NzUwNzMx

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
# This file should be checked into version control along with the pnpm-lock.yaml file.
44
.npmrc=-1406867100
55
package.json=688000741
6+
packages/angular/build/package.json=1789788715
67
packages/angular/cli/package.json=349838588
78
packages/angular/pwa/package.json=-1352285148
9+
packages/angular/ssr/package.json=120782115
810
packages/angular_devkit/architect/package.json=-1496633956
911
packages/angular_devkit/architect_cli/package.json=1551210941
12+
packages/angular_devkit/build_angular/package.json=-1437596637
1013
packages/angular_devkit/build_webpack/package.json=373950017
1114
packages/angular_devkit/core/package.json=339935828
1215
packages/angular_devkit/schematics/package.json=673943597
1316
packages/angular_devkit/schematics_cli/package.json=-356386813
1417
packages/ngtools/webpack/package.json=-942726894
1518
packages/schematics/angular/package.json=251715148
16-
pnpm-lock.yaml=604009520
17-
pnpm-workspace.yaml=1732591250
19+
pnpm-lock.yaml=319177102
20+
pnpm-workspace.yaml=-1635877240
1821
yarn.lock=969972397

BUILD.bazel

+16-6
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,28 @@ rules_js_tsconfig(
3434
)
3535

3636
rules_js_tsconfig(
37-
name = "build-tsconfig-angular",
38-
src = "tsconfig-build-ng.json",
37+
name = "test-tsconfig",
38+
src = "tsconfig-test.json",
3939
deps = [
4040
"tsconfig.json",
41+
"//:node_modules/@types/jasmine",
42+
"//:node_modules/@types/node",
4143
],
4244
)
4345

4446
rules_js_tsconfig(
45-
name = "test-tsconfig",
46-
src = "tsconfig-test.json",
47+
name = "build-tsconfig-esm",
48+
src = "tsconfig-build-esm.json",
4749
deps = [
4850
"tsconfig.json",
51+
],
52+
)
53+
54+
rules_js_tsconfig(
55+
name = "test-tsconfig-esm",
56+
src = "tsconfig-test-esm.json",
57+
deps = [
58+
":build-tsconfig-esm",
4959
"//:node_modules/@types/jasmine",
5060
"//:node_modules/@types/node",
5161
],
@@ -92,8 +102,8 @@ config_setting(
92102
)
93103

94104
ts_config(
95-
name = "tsconfig-build-ng",
96-
src = "tsconfig-build-ng.json",
105+
name = "tsconfig-build-esm",
106+
src = "tsconfig-build-esm.json",
97107
deps = [
98108
":tsconfig.json",
99109
],

WORKSPACE

+3-1
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,13 @@ npm_translate_lock(
186186
data = [
187187
"//:package.json",
188188
"//:pnpm-workspace.yaml",
189+
"//packages/angular/build:package.json",
189190
"//packages/angular/cli:package.json",
190191
"//packages/angular/pwa:package.json",
192+
"//packages/angular/ssr:package.json",
191193
"//packages/angular_devkit/architect:package.json",
192194
"//packages/angular_devkit/architect_cli:package.json",
195+
"//packages/angular_devkit/build_angular:package.json",
193196
"//packages/angular_devkit/build_webpack:package.json",
194197
"//packages/angular_devkit/core:package.json",
195198
"//packages/angular_devkit/schematics:package.json",
@@ -245,5 +248,4 @@ http_archive(
245248

246249
load("@aspect_rules_jasmine//jasmine:dependencies.bzl", "rules_jasmine_dependencies")
247250

248-
# Fetch dependencies which users need as well
249251
rules_jasmine_dependencies()

packages/angular/ssr/BUILD.bazel

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
load("@aspect_rules_js//npm:defs.bzl", "npm_package")
12
load("@npm//@angular/build-tooling/bazel/api-golden:index.bzl", "api_golden_test_npm_package")
23
load("@rules_pkg//:pkg.bzl", "pkg_tar")
34
load("//tools:defaults.bzl", "ng_package")
4-
load("//tools:interop.bzl", "ts_project")
5+
load("//tools:defaults2.bzl", "ts_project")
56

67
package(default_visibility = ["//visibility:public"])
78

@@ -25,7 +26,7 @@ ts_project(
2526
],
2627
module_name = "@angular/ssr",
2728
source_map = True,
28-
tsconfig = "//:build-tsconfig-angular",
29+
tsconfig = "//:build-tsconfig-esm",
2930
deps = [
3031
"//:node_modules/@angular/common",
3132
"//:node_modules/@angular/core",
@@ -37,7 +38,7 @@ ts_project(
3738
)
3839

3940
ng_package(
40-
name = "npm_package",
41+
name = "angular_package",
4142
package_name = "@angular/ssr",
4243
srcs = [
4344
":package.json",
@@ -51,7 +52,6 @@ ng_package(
5152
nested_packages = [
5253
"//packages/angular/ssr/schematics:npm_package",
5354
],
54-
tags = ["release-package"],
5555
deps = [
5656
":ssr",
5757
"//packages/angular/ssr/node",
@@ -67,6 +67,21 @@ pkg_tar(
6767
tags = ["manual"],
6868
)
6969

70+
# TODO: Replace when `ng_package` creates a valid `rules_js`-compliant npm package.
71+
npm_package(
72+
name = "npm_package",
73+
srcs = [":angular_package"],
74+
replace_prefixes = {
75+
"angular_package/": "",
76+
},
77+
tags = ["release-package"],
78+
)
79+
80+
alias(
81+
name = "pkg",
82+
actual = ":npm_package",
83+
)
84+
7085
api_golden_test_npm_package(
7186
name = "ssr_api",
7287
data = [

packages/angular/ssr/node/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ts_project(
1616
],
1717
module_name = "@angular/ssr/node",
1818
source_map = True,
19-
tsconfig = "//:build-tsconfig-angular",
19+
tsconfig = "//:build-tsconfig-esm",
2020
deps = [
2121
"//:node_modules/@angular/core",
2222
"//:node_modules/@angular/platform-server",

packages/angular/ssr/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@angular/ssr",
33
"version": "0.0.0-PLACEHOLDER",
44
"description": "Angular server side rendering utilities",
5+
"type": "module",
56
"license": "MIT",
67
"homepage": "https://github.com/angular/angular-cli",
78
"keywords": [

packages/angular/ssr/test/BUILD.bazel

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
load("@npm//@angular/build-tooling/bazel/spec-bundling:index.bzl", "spec_bundle")
2-
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
3-
load("//tools:interop.bzl", "ts_project")
2+
load("//tools:defaults2.bzl", "jasmine_test", "ts_project")
43

54
ts_project(
65
name = "unit_test_lib",
76
testonly = True,
87
srcs = glob(
98
include = ["**/*.ts"],
109
),
10+
tsconfig = "//:test-tsconfig-esm",
1111
deps = [
1212
"//:node_modules/@angular/common",
1313
"//:node_modules/@angular/compiler",
@@ -19,6 +19,8 @@ ts_project(
1919
],
2020
)
2121

22+
# TODO: Replace this with a `rules_js` variant, or make the SSR package
23+
# native ESM compatible! (import extensions etc.)
2224
spec_bundle(
2325
name = "esm_tests_bundled",
2426
downlevel_async_await = False,
@@ -29,7 +31,9 @@ spec_bundle(
2931
],
3032
)
3133

32-
jasmine_node_test(
34+
jasmine_test(
3335
name = "test",
34-
deps = [":esm_tests_bundled"],
36+
data = [
37+
":esm_tests_bundled",
38+
],
3539
)

pnpm-lock.yaml

+28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ packages:
88
- packages/angular_devkit/schematics_cli
99
- packages/angular/cli
1010
- packages/angular/pwa
11+
- packages/angular/ssr
1112
- packages/schematics/angular
1213
- packages/ngtools/webpack

tools/bazel/npm_package.bzl

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def npm_package(
1616
stamp_files = [],
1717
pkg_json = "package.json",
1818
extra_substitutions = {},
19+
replace_prefixes = {},
1920
**kwargs):
2021
if name != "pkg":
2122
fail("Expected npm_package to be named `pkg`. " +
@@ -96,12 +97,12 @@ def npm_package(
9697
visibility = visibility,
9798
# Note: Order matters here! Last file takes precedence after replaced prefixes.
9899
srcs = deps + stamp_targets + [":final_package_json"],
99-
replace_prefixes = {
100+
replace_prefixes = dict({
100101
"substituted_final/": "",
101102
"substituted_with_tars/": "",
102103
"substituted_with_snapshot_repos/": "",
103104
"substituted/": "",
104-
},
105+
}, **replace_prefixes),
105106
allow_overwrites = True,
106107
**kwargs
107108
)

tools/defaults2.bzl

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def ts_project(**kwargs):
88
def npm_package(**kwargs):
99
_npm_package(**kwargs)
1010

11-
def jasmine_test(data = [], **kwargs):
11+
def jasmine_test(data = [], args = [], **kwargs):
1212
# Create relative path to root, from current package dir. Necessary as
1313
# we change the `chdir` below to the package directory.
1414
relative_to_root = "/".join([".."] * len(native.package_name().split("/")))
@@ -18,8 +18,10 @@ def jasmine_test(data = [], **kwargs):
1818
chdir = native.package_name(),
1919
args = [
2020
"--require=%s/node_modules/source-map-support/register.js" % relative_to_root,
21-
"**/*.js",
22-
],
21+
"**/*spec.js",
22+
"**/*spec.mjs",
23+
"**/*spec.cjs",
24+
] + args,
2325
data = data + ["//:node_modules/source-map-support"],
2426
**kwargs
2527
)
File renamed without changes.

tsconfig-test-esm.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Root tsconfig file for use building all Angular packages. Note there is no rootDir
3+
* and therefore any tsconfig in the package directory will need to define its own
4+
* rootDir.
5+
*/
6+
{
7+
"extends": "./tsconfig-build-esm.json",
8+
"compilerOptions": {
9+
"sourceMap": false,
10+
"inlineSourceMap": true,
11+
"inlineSources": true,
12+
"types": ["node", "jasmine"]
13+
}
14+
}

0 commit comments

Comments
 (0)