Skip to content

Commit 5d5c783

Browse files
committed
build: migrate @angular/pwa tests to rules_js
This commit changes the execution of `@angular/pwa` tests to `rules_js` native `jasmine_test`. This requires setting it up in the pnpm workspace for first-party linked dependencies, and it also requires a small trick for making the peer dependency substitution work well with the pnpm workspace installs. pnpm will fail as it couldn't find a "suitable" local, or external version, so we are just using the local variant for install, and later replace during "packaging" via an extra substitution. Ideally we'd somehow leave the placeholder for clarity, but it's not possible right now. Good thing is that the peer deps aren't being touched here, as it's all done via constants now.
1 parent e0da576 commit 5d5c783

File tree

7 files changed

+46
-21
lines changed

7 files changed

+46
-21
lines changed

.aspect/rules/external_repository_action_cache/npm_translate_lock_MzA5NzUwNzMx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
.npmrc=-2023857461
55
package.json=-497647638
66
packages/angular/cli/package.json=-1878910022
7+
packages/angular/pwa/package.json=-466738595
78
packages/angular_devkit/architect/package.json=-1496633956
89
packages/angular_devkit/architect_cli/package.json=1551210941
910
packages/angular_devkit/core/package.json=339935828
1011
packages/angular_devkit/schematics/package.json=673943597
1112
packages/schematics/angular/package.json=251715148
12-
pnpm-lock.yaml=1517985739
13-
pnpm-workspace.yaml=-1051214858
13+
pnpm-lock.yaml=1107856419
14+
pnpm-workspace.yaml=-818108966
1415
yarn.lock=-1008526801

WORKSPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ npm_translate_lock(
187187
"//:package.json",
188188
"//:pnpm-workspace.yaml",
189189
"//packages/angular/cli:package.json",
190+
"//packages/angular/pwa:package.json",
190191
"//packages/angular_devkit/architect:package.json",
191192
"//packages/angular_devkit/architect_cli:package.json",
192193
"//packages/angular_devkit/core:package.json",

packages/angular/pwa/BUILD.bazel

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
# Use of this source code is governed by an MIT-style license that can be
44
# found in the LICENSE file at https://angular.dev/license
55

6-
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
7-
load("//tools:defaults2.bzl", "npm_package", "ts_project")
6+
load("@npm2//:defs.bzl", "npm_link_all_packages")
7+
load("//:constants.bzl", "ANGULAR_FW_PEER_DEP")
8+
load("//tools:defaults2.bzl", "jasmine_test", "npm_package", "ts_project")
89
load("//tools:ts_json_schema.bzl", "ts_json_schema")
910

1011
licenses(["notice"])
1112

1213
package(default_visibility = ["//visibility:public"])
1314

15+
npm_link_all_packages()
16+
1417
RUNTIME_ASSETS = glob(
1518
include = [
1619
"pwa/*.js",
@@ -32,10 +35,10 @@ ts_project(
3235
data = RUNTIME_ASSETS,
3336
module_name = "@angular/pwa",
3437
deps = [
38+
":node_modules/@angular-devkit/schematics",
39+
":node_modules/@schematics/angular",
3540
"//:node_modules/@types/node",
3641
"//:node_modules/parse5-html-rewriting-stream",
37-
"//packages/angular_devkit/schematics:schematics_rjs",
38-
"//packages/schematics/angular:angular_rjs",
3942
],
4043
)
4144

@@ -55,9 +58,9 @@ ts_project(
5558
],
5659
)
5760

58-
jasmine_node_test(
61+
jasmine_test(
5962
name = "pwa_test",
60-
srcs = [":pwa_test_lib"],
63+
data = [":pwa_test_lib_rjs"],
6164
)
6265

6366
genrule(
@@ -69,6 +72,10 @@ genrule(
6972

7073
npm_package(
7174
name = "pkg",
75+
extra_substitutions = {
76+
# Peer dependency is replaced as pnpm workspace otherwise can't resolve it.
77+
"\"../cli\"": "\"%s\"" % ANGULAR_FW_PEER_DEP,
78+
},
7279
pkg_deps = [
7380
"//packages/angular_devkit/schematics:package.json",
7481
"//packages/schematics/angular:package.json",

packages/angular/pwa/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
"save": false
1313
},
1414
"dependencies": {
15-
"@angular-devkit/schematics": "0.0.0-PLACEHOLDER",
16-
"@schematics/angular": "0.0.0-PLACEHOLDER",
15+
"@angular-devkit/schematics": "workspace:0.0.0-PLACEHOLDER",
16+
"@schematics/angular": "workspace:0.0.0-PLACEHOLDER",
1717
"parse5-html-rewriting-stream": "7.0.0"
1818
},
1919
"peerDependencies": {
20-
"@angular/cli": "0.0.0-ANGULAR-FW-PEER-DEP"
20+
"@angular/cli": "../cli"
2121
},
2222
"peerDependenciesMeta": {
2323
"@angular/cli": {

pnpm-lock.yaml

Lines changed: 17 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ packages:
55
- packages/angular_devkit/core
66
- packages/angular_devkit/schematics
77
- packages/angular/cli
8+
- packages/angular/pwa
89
- packages/schematics/angular

tools/bazel/npm_package.bzl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def npm_package(
1515
pkg_deps = [],
1616
stamp_files = [],
1717
pkg_json = "package.json",
18+
extra_substitutions = {},
1819
**kwargs):
1920
if name != "pkg":
2021
fail("Expected npm_package to be named `pkg`. " +
@@ -61,6 +62,9 @@ def npm_package(
6162
out = "substituted_with_snapshot_repos/package.json",
6263
)
6364

65+
nostamp_subs = dict(substitutions["rjs"]["nostamp"], **extra_substitutions)
66+
stamp_subs = dict(substitutions["rjs"]["stamp"], **extra_substitutions)
67+
6468
expand_template(
6569
name = "final_package_json",
6670
template = select({
@@ -71,8 +75,8 @@ def npm_package(
7175
"//conditions:default": "substituted/package.json",
7276
}),
7377
out = "substituted_final/package.json",
74-
substitutions = substitutions["rjs"]["nostamp"],
75-
stamp_substitutions = substitutions["rjs"]["stamp"],
78+
substitutions = nostamp_subs,
79+
stamp_substitutions = stamp_subs,
7680
)
7781

7882
stamp_targets = []
@@ -81,8 +85,8 @@ def npm_package(
8185
name = "stamp_file_%s" % f,
8286
template = f,
8387
out = "substituted/%s" % f,
84-
substitutions = substitutions["rjs"]["nostamp"],
85-
stamp_substitutions = substitutions["rjs"]["stamp"],
88+
substitutions = nostamp_subs,
89+
stamp_substitutions = stamp_subs,
8690
)
8791

8892
stamp_targets.append("stamp_file_%s" % f)

0 commit comments

Comments
 (0)