Skip to content

Commit d20ec44

Browse files
committed
build: setup rules_js properly and expose initialization helpers
This allows for the dev-infra repository to be conveniently used in e.g. the angular-cli repository, allowing for rules to be consumed like we are testing and building them inside this workspace. This greatly simplfies developer productivity for dev-infra and also allows us to avoid complexity around shipping, or bundling. Consider examples like API extractor which cannot be bundled due to reliance on assets inside the `node_modules` directory.
1 parent a6d7865 commit d20ec44

File tree

17 files changed

+513
-75
lines changed

17 files changed

+513
-75
lines changed

.bazelrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ test:debug --test_arg=--node_options=--inspect-brk --test_output=streamed --test
66
build --sandbox_default_allow_network=false
77
test --sandbox_default_allow_network=false
88

9+
# Required by `rules_ts`.
10+
common --@aspect_rules_ts//ts:skipLibCheck=always
11+
common --@aspect_rules_ts//ts:default_to_tsc_transpiler
12+
913
# Turn off legacy external runfiles
1014
build --nolegacy_external_runfiles
1115
run --nolegacy_external_runfiles
@@ -74,8 +78,6 @@ build:remote --google_default_credentials
7478

7579
# Setup the toolchain and platform for the remote build execution. The platform
7680
# is provided by the shared dev-infra package and targets k8 remote containers.
77-
build:remote --crosstool_top=//bazel/remote-execution/cpp:cc_toolchain_suite
78-
build:remote --extra_toolchains=//bazel/remote-execution/cpp:cc_toolchain
7981
build:remote --extra_execution_platforms=//bazel/remote-execution:platform_with_network
8082
build:remote --host_platform=//bazel/remote-execution:platform_with_network
8183
build:remote --platforms=//bazel/remote-execution:platform_with_network

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.4.0
1+
6.5.0

BUILD.bazel

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
load("@aspect_rules_ts//ts:defs.bzl", rules_js_tsconfig = "ts_config")
2+
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
3+
load("@npm//@bazel/typescript:index.bzl", "ts_config")
4+
15
# BEGIN-INTERNAL
26
load("//:package.bzl", "NPM_PACKAGE_SUBSTITUTIONS")
37
load("//tools:defaults.bzl", "pkg_npm")
4-
load("@npm//@bazel/typescript:index.bzl", "ts_config")
5-
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
8+
9+
rules_js_tsconfig(
10+
name = "rjs-tsconfig",
11+
src = "tsconfig.json",
12+
visibility = ["//bazel:__subpackages__"],
13+
)
614

715
exports_files([
816
"package.json",

WORKSPACE

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
workspace(
22
name = "devinfra",
3-
managed_directories = {"@npm": ["node_modules"]},
43
)
54

65
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
76

7+
NODE_VERSION = "18.20.0"
8+
89
# The PKG rules are needed to build tar packages for integration tests. The builtin
910
# rule in `@bazel_tools` is not Windows compatible and outdated.
1011
http_archive(
@@ -50,16 +51,34 @@ nodejs_register_toolchains(
5051
"18.20.0-windows_amd64": ("node-v18.20.0-win-x64.zip", "node-v18.20.0-win-x64", "1c0aab05cc6836a8f5148cca345b92ebc948a4a2013f18d117b7ade6ff05aca6"),
5152
},
5253
# We need at least Node 18.17 due to some transitive dependencies.
53-
node_version = "18.20.0",
54+
node_version = NODE_VERSION,
5455
)
5556

57+
http_archive(
58+
name = "aspect_rules_js",
59+
sha256 = "875b8d01af629dbf626eddc5cf239c9f0da20330f4d99ad956afc961096448dd",
60+
strip_prefix = "rules_js-2.1.3",
61+
url = "https://github.com/aspect-build/rules_js/releases/download/v2.1.3/rules_js-v2.1.3.tar.gz",
62+
)
63+
64+
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
65+
66+
rules_js_dependencies()
67+
68+
load("@aspect_rules_js//js:toolchains.bzl", "rules_js_register_toolchains")
69+
70+
rules_js_register_toolchains()
71+
5672
load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install")
5773

5874
yarn_install(
5975
name = "npm",
6076
# Yarn Berry/v2+ expects `--immutable` instead of `--frozen-lockfile`.
6177
args = ["--immutable"],
6278
data = [
79+
"//:.yarn/patches/@angular-bazel-npm.patch",
80+
"//:.yarn/patches/@bazel-jasmine-npm.patch",
81+
"//:.yarn/patches/@octokit-graphql-schema-npm-15.3.0-4046a59648.patch",
6382
"//:.yarn/releases/yarn-4.6.0.cjs",
6483
"//:.yarnrc.yml",
6584
],
@@ -68,9 +87,6 @@ yarn_install(
6887
# 2. Incompatibilites with the `ts_library` rule.
6988
exports_directories_only = False,
7089
package_json = "//:package.json",
71-
# We prefer to symlink the `node_modules` to only maintain a single install.
72-
# See https://github.com/angular/dev-infra/pull/446#issuecomment-1059820287 for details.
73-
symlink_node_modules = True,
7490
yarn = "//:.yarn/releases/yarn-4.6.0.cjs",
7591
yarn_lock = "//:yarn.lock",
7692
)
@@ -128,3 +144,25 @@ http_file(
128144
sha256 = "61ce1dc62fdcfd6d68624a403e0f04c5fd5136d933b681467aad1ad2d00dbb03",
129145
urls = ["https://raw.githubusercontent.com/bazelbuild/bazel/5.0.0/src/main/protobuf/test_status.proto"],
130146
)
147+
148+
http_archive(
149+
name = "aspect_rules_ts",
150+
sha256 = "013a10b2b457add73b081780e604778eb50a141709f9194298f97761acdcc169",
151+
strip_prefix = "rules_ts-3.4.0",
152+
url = "https://github.com/aspect-build/rules_ts/releases/download/v3.4.0/rules_ts-v3.4.0.tar.gz",
153+
)
154+
155+
load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")
156+
157+
rules_ts_dependencies(
158+
ts_integrity = "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==",
159+
ts_version_from = "//bazel:package.json",
160+
)
161+
162+
load("//bazel:setup_dependencies_1.bzl", "setup_dependencies_1")
163+
164+
setup_dependencies_1()
165+
166+
load("//bazel:setup_dependencies_2.bzl", "setup_dependencies_2")
167+
168+
setup_dependencies_2()

bazel/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
2+
load("@devinfra_npm//:defs.bzl", "npm_link_all_packages")
3+
4+
npm_link_all_packages()
5+
6+
ts_config(
7+
name = "tsconfig",
8+
src = "tsconfig.json",
9+
visibility = ["//bazel:__subpackages__"],
10+
deps = ["//:rjs-tsconfig"],
11+
)
12+
113
filegroup(
214
name = "static_files",
315
srcs = [

bazel/browsers/test/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ js_library(
2727
spec_bundle(
2828
name = "test_bundle",
2929
platform = "browser",
30-
workspace_name = "dev-infra",
30+
workspace_name = "devinfra",
3131
deps = [":test_lib"],
3232
)

bazel/http-server/launcher_template.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fi
2626
# resolve the "nodejs_binary" executable with different file extensions on
2727
# windows, but since we already run this launcher as part of a "sh_binary", we
2828
# can safely execute another shell script from the current shell.
29-
serverBin=$(rlocation "dev-infra/bazel/http-server/server_bin.sh")
29+
serverBin=$(rlocation "devinfra/bazel/http-server/server_bin.sh")
3030

3131
# Start the server with the given arguments. The arguments will be
3232
# substituted based on the rule attributes.

bazel/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@devinfra/bazel",
3+
"dependencies": {
4+
"@microsoft/api-extractor": "7.49.2",
5+
"typescript": "5.7.3",
6+
"@types/node": "22.13.0"
7+
},
8+
"pnpm": {
9+
"onlyBuiltDependencies": []
10+
}
11+
}

0 commit comments

Comments
 (0)