Skip to content

Commit

Permalink
build: migrate @angular-devkit/architect jasmine test to native `ru…
Browse files Browse the repository at this point in the history
…les_js`

Instead of using `rules_nodejs` interop and the linker at runtime, the
test target is migrated to the new `jasmine_test` rule, leveraging the
pnpm workspace for first-party dependencies.

Note that in the future we may be able to rename the local node modules
to something more clear. e.g. `:local_modules/@angular-devkit/core`, but
for now this is not possible :(

This commit shows how similar packages can be migrated in the future.
  • Loading branch information
devversion committed Jan 15, 2025
1 parent bc21d81 commit a092dfd
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# Input hashes for repository rule npm_translate_lock(name = "npm2", pnpm_lock = "@//:pnpm-lock.yaml").
# This file should be checked into version control along with the pnpm-lock.yaml file.
.npmrc=-2023857461
package.json=2055569205
pnpm-lock.yaml=1847443622
pnpm-workspace.yaml=1711114604
yarn.lock=86020133
package.json=1658609850
packages/angular_devkit/architect/package.json=-107274537
packages/angular_devkit/core/package.json=339935828
pnpm-lock.yaml=1613268280
pnpm-workspace.yaml=-1853274682
yarn.lock=1185228888
14 changes: 14 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ npm_translate_lock(
data = [
"//:package.json",
"//:pnpm-workspace.yaml",
"//packages/angular_devkit/architect:package.json",
"//packages/angular_devkit/core:package.json",
],
npmrc = "//:.npmrc",
patches = {
Expand Down Expand Up @@ -225,3 +227,15 @@ http_file(
sha256 = "5a5c46846ecda83e05b9da26f1672ad51c59bce08fed88419850d0e29c993b30",
urls = ["https://raw.githubusercontent.com/devversion/rules_angular/4b7532ba2b29078d005899cd15b415593d03cceb/dist/worker.mjs"],
)

http_archive(
name = "aspect_rules_jasmine",
sha256 = "0d2f9c977842685895020cac721d8cc4f1b37aae15af46128cf619741dc61529",
strip_prefix = "rules_jasmine-2.0.0",
url = "https://github.com/aspect-build/rules_jasmine/releases/download/v2.0.0/rules_jasmine-v2.0.0.tar.gz",
)

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

# Fetch dependencies which users need as well
rules_jasmine_dependencies()
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"@types/http-proxy": "^1.17.4",
"@types/ini": "^4.0.0",
"@types/jasmine": "~5.1.0",
"@types/jasmine-reporters": "^2",
"@types/karma": "^6.3.0",
"@types/less": "^3.0.3",
"@types/loader-utils": "^2.0.0",
Expand Down Expand Up @@ -141,6 +142,7 @@
"istanbul-lib-instrument": "6.0.3",
"jasmine": "^5.0.0",
"jasmine-core": "~5.5.0",
"jasmine-reporters": "^2.5.2",
"jasmine-spec-reporter": "~7.0.0",
"jsonc-parser": "3.3.1",
"karma": "~6.4.0",
Expand Down
17 changes: 9 additions & 8 deletions packages/angular_devkit/architect/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
# found in the LICENSE file at https://angular.dev/license

load("@npm//@angular/build-tooling/bazel/api-golden:index.bzl", "api_golden_test_npm_package")
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
load("//tools:defaults2.bzl", "npm_package", "ts_project")
load("@npm2//:defs.bzl", "npm_link_all_packages")
load("//tools:defaults2.bzl", "jasmine_test", "npm_package", "ts_project")
load("//tools:ts_json_schema.bzl", "ts_json_schema")

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

licenses(["notice"])

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

ts_json_schema(
name = "builder_input_schema",
Expand Down Expand Up @@ -66,10 +68,9 @@ ts_project(
data = JSON_FILES,
module_name = "@angular-devkit/architect",
deps = [
":node_modules/@angular-devkit/core",
"//:node_modules/@types/node",
"//:node_modules/rxjs",
"//packages/angular_devkit/core:core_rjs",
"//packages/angular_devkit/core/node:node_rjs",
],
)

Expand All @@ -79,16 +80,16 @@ ts_project(
srcs = glob(["src/**/*_spec.ts"]),
deps = [
":architect_rjs",
":node_modules/@angular-devkit/core",
"//:node_modules/@types/jasmine",
"//:node_modules/rxjs",
"//packages/angular_devkit/architect/testing:testing_rjs",
"//packages/angular_devkit/core:core_rjs",
],
)

jasmine_node_test(
jasmine_test(
name = "architect_test",
srcs = [":architect_test_lib"],
data = [":architect_test_lib_rjs"],
)

# @external_begin
Expand Down
58 changes: 45 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
packages:
- .
- packages/angular_devkit/architect
- packages/angular_devkit/core
9 changes: 9 additions & 0 deletions tools/defaults2.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@aspect_rules_jasmine//jasmine:defs.bzl", _jasmine_test = "jasmine_test")
load("//tools:interop.bzl", _ts_project = "ts_project")
load("//tools/bazel:npm_package.bzl", _npm_package = "npm_package")

Expand All @@ -6,3 +7,11 @@ def ts_project(**kwargs):

def npm_package(**kwargs):
_npm_package(**kwargs)

def jasmine_test(**kwargs):
_jasmine_test(
node_modules = "//:node_modules",
chdir = native.package_name(),
args = ["**/*.js"],
**kwargs
)
15 changes: 13 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ __metadata:
"@types/http-proxy": "npm:^1.17.4"
"@types/ini": "npm:^4.0.0"
"@types/jasmine": "npm:~5.1.0"
"@types/jasmine-reporters": "npm:^2"
"@types/karma": "npm:^6.3.0"
"@types/less": "npm:^3.0.3"
"@types/loader-utils": "npm:^2.0.0"
Expand Down Expand Up @@ -407,6 +408,7 @@ __metadata:
istanbul-lib-instrument: "npm:6.0.3"
jasmine: "npm:^5.0.0"
jasmine-core: "npm:~5.5.0"
jasmine-reporters: "npm:^2.5.2"
jasmine-spec-reporter: "npm:~7.0.0"
jsonc-parser: "npm:3.3.1"
karma: "npm:~6.4.0"
Expand Down Expand Up @@ -4976,7 +4978,16 @@ __metadata:
languageName: node
linkType: hard

"@types/jasmine@npm:~5.1.0":
"@types/jasmine-reporters@npm:^2":
version: 2.5.3
resolution: "@types/jasmine-reporters@npm:2.5.3"
dependencies:
"@types/jasmine": "npm:*"
checksum: 10c0/9e895e1b258bf59fbd7bb8c9079681ad48e1035c33c36e3ab0aa2034fd87e95abf71ef848996c21ca9ecd5a72ce2897cc26162fedf12e0ebaad9969f138a84a4
languageName: node
linkType: hard

"@types/jasmine@npm:*, @types/jasmine@npm:~5.1.0":
version: 5.1.5
resolution: "@types/jasmine@npm:5.1.5"
checksum: 10c0/904a2a6bfe7478478ec73d502708dc4b4cc46fa554c459cee3e0be01efda96fba7d26ef8bec2f246d9163cc517407b135acabcf6f076c11aa514ed9b79bc67e5
Expand Down Expand Up @@ -11913,7 +11924,7 @@ __metadata:
languageName: node
linkType: hard

"jasmine-reporters@npm:~2.5.0":
"jasmine-reporters@npm:^2.5.2, jasmine-reporters@npm:~2.5.0":
version: 2.5.2
resolution: "jasmine-reporters@npm:2.5.2"
dependencies:
Expand Down

0 comments on commit a092dfd

Please sign in to comment.