Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ test:debug --test_arg=--node_options=--inspect-brk --test_output=streamed --test
build --sandbox_default_allow_network=false
test --sandbox_default_allow_network=false

# Required by `rules_ts`.
common --@aspect_rules_ts//ts:skipLibCheck=always
common --@aspect_rules_ts//ts:default_to_tsc_transpiler

# Turn off legacy external runfiles
build --nolegacy_external_runfiles
run --nolegacy_external_runfiles
Expand Down Expand Up @@ -74,8 +78,6 @@ build:remote --google_default_credentials

# Setup the toolchain and platform for the remote build execution. The platform
# is provided by the shared dev-infra package and targets k8 remote containers.
build:remote --crosstool_top=//bazel/remote-execution/cpp:cc_toolchain_suite
build:remote --extra_toolchains=//bazel/remote-execution/cpp:cc_toolchain
build:remote --extra_execution_platforms=//bazel/remote-execution:platform_with_network
build:remote --host_platform=//bazel/remote-execution:platform_with_network
build:remote --platforms=//bazel/remote-execution:platform_with_network
Expand Down
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.4.0
6.5.0
14 changes: 0 additions & 14 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,6 @@ jobs:
- run: yarn install --immutable
- run: yarn bazel test -- //...

test-win:
timeout-minutes: 30
runs-on: windows-latest
steps:
# Because the checkout and setup node action is contained in the dev-infra repo, we must
# checkout the repo to be able to run the action we have created. Other repos will skip
# this step.
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: ./github-actions/npm/checkout-and-setup-node
- uses: ./github-actions/bazel/setup
- uses: ./github-actions/bazel/configure-remote
- run: yarn install --immutable
- run: yarn bazel test --test_tag_filters=windows --build_tests_only -- ... -bazel/remote-execution/...

test-macos:
timeout-minutes: 30
runs-on: macos-latest
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ github-actions/unified-status-check/main.js
.github/local-actions/changelog/main.js

bazel/map-size-tracking/test/size-golden.json

bazel/pnpm-lock.yaml
12 changes: 10 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
load("@aspect_rules_ts//ts:defs.bzl", rules_js_tsconfig = "ts_config")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
load("@npm//@bazel/typescript:index.bzl", "ts_config")

# BEGIN-INTERNAL
load("//:package.bzl", "NPM_PACKAGE_SUBSTITUTIONS")
load("//tools:defaults.bzl", "pkg_npm")
load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")

rules_js_tsconfig(
name = "rjs-tsconfig",
src = "tsconfig.json",
visibility = ["//bazel:__subpackages__"],
)

exports_files([
"package.json",
Expand Down
51 changes: 44 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
workspace(
name = "dev-infra",
managed_directories = {"@npm": ["node_modules"]},
name = "devinfra",
)

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

NODE_VERSION = "18.20.0"

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

http_archive(
name = "aspect_rules_js",
sha256 = "875b8d01af629dbf626eddc5cf239c9f0da20330f4d99ad956afc961096448dd",
strip_prefix = "rules_js-2.1.3",
url = "https://github.com/aspect-build/rules_js/releases/download/v2.1.3/rules_js-v2.1.3.tar.gz",
)

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@aspect_rules_js//js:toolchains.bzl", "rules_js_register_toolchains")

rules_js_register_toolchains()

load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install")

yarn_install(
name = "npm",
# Yarn Berry/v2+ expects `--immutable` instead of `--frozen-lockfile`.
args = ["--immutable"],
data = [
"//:.yarn/patches/@angular-bazel-npm.patch",
"//:.yarn/patches/@bazel-jasmine-npm.patch",
"//:.yarn/patches/@octokit-graphql-schema-npm-15.3.0-4046a59648.patch",
"//:.yarn/releases/yarn-4.6.0.cjs",
"//:.yarnrc.yml",
],
Expand All @@ -68,9 +87,6 @@ yarn_install(
# 2. Incompatibilites with the `ts_library` rule.
exports_directories_only = False,
package_json = "//:package.json",
# We prefer to symlink the `node_modules` to only maintain a single install.
# See https://github.com/angular/dev-infra/pull/446#issuecomment-1059820287 for details.
symlink_node_modules = True,
yarn = "//:.yarn/releases/yarn-4.6.0.cjs",
yarn_lock = "//:yarn.lock",
)
Expand Down Expand Up @@ -120,11 +136,32 @@ register_toolchains(
"//bazel/git-toolchain:git_linux_toolchain",
"//bazel/git-toolchain:git_macos_x86_toolchain",
"//bazel/git-toolchain:git_macos_arm64_toolchain",
"//bazel/git-toolchain:git_windows_toolchain",
)

http_file(
name = "bazel_test_status_proto",
sha256 = "61ce1dc62fdcfd6d68624a403e0f04c5fd5136d933b681467aad1ad2d00dbb03",
urls = ["https://raw.githubusercontent.com/bazelbuild/bazel/5.0.0/src/main/protobuf/test_status.proto"],
)

http_archive(
name = "aspect_rules_ts",
sha256 = "013a10b2b457add73b081780e604778eb50a141709f9194298f97761acdcc169",
strip_prefix = "rules_ts-3.4.0",
url = "https://github.com/aspect-build/rules_ts/releases/download/v3.4.0/rules_ts-v3.4.0.tar.gz",
)

load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")

rules_ts_dependencies(
ts_integrity = "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==",
ts_version_from = "//bazel:package.json",
)

load("//bazel:setup_dependencies_1.bzl", "setup_dependencies_1")

setup_dependencies_1()

load("//bazel:setup_dependencies_2.bzl", "setup_dependencies_2")

setup_dependencies_2()
12 changes: 12 additions & 0 deletions bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
load("@devinfra_npm//:defs.bzl", "npm_link_all_packages")

npm_link_all_packages()

ts_config(
name = "tsconfig",
src = "tsconfig.json",
visibility = ["//bazel:__subpackages__"],
deps = ["//:rjs-tsconfig"],
)

filegroup(
name = "static_files",
srcs = [
Expand Down
16 changes: 6 additions & 10 deletions bazel/api-golden/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//bazel:defaults.bzl", "ts_library")
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

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

Expand All @@ -7,25 +7,21 @@ exports_files([
"index_npm_packages.ts",
])

ts_library(
ts_project(
name = "api-golden",
srcs = [
"find_entry_points.ts",
"index.ts",
"index_npm_packages.ts",
"module_mappings.ts",
"patch-host.ts",
"path-normalize.ts",
"test_api_report.ts",
],
# A tsconfig needs to be specified as otherwise `ts_library` will look for the config
# in `//:package.json` and this breaks when the BUILD file is copied to `@npm//`.
tsconfig = "//:tsconfig.json",
tsconfig = "//bazel:tsconfig",
deps = [
"@npm//@bazel/runfiles",
"@npm//@microsoft/api-extractor",
"@npm//@types/node",
"@npm//typescript",
"//bazel:node_modules/@microsoft/api-extractor",
"//bazel:node_modules/@types/node",
"//bazel:node_modules/typescript",
],
)

Expand Down
2 changes: 1 addition & 1 deletion bazel/api-golden/find_entry_points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import {dirname, join, relative} from 'path';
import {lstatSync, readFileSync, readdirSync} from 'fs';

import {PackageJson} from './index_npm_packages';
import {PackageJson} from './index_npm_packages.js';

/** Interface describing a resolved NPM package entry point. */
export interface PackageEntryPoint {
Expand Down
124 changes: 38 additions & 86 deletions bazel/api-golden/index.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("//bazel:extract_types.bzl", "extract_types")
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary", "nodejs_test")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("//bazel/api-golden:index_rjs.bzl", _rjs_api_golden_test_npm_package = "api_golden_test_npm_package")

nodejs_test_args = [
# Needed so that node doesn't walk back to the source directory.
Expand All @@ -10,18 +11,8 @@ nodejs_test_args = [

default_strip_export_pattern = "^ɵ(?!ɵdefineInjectable|ɵinject|ɵInjectableDef)"

def _escape_regex_for_arg(value):
"""Escapes a Regular expression so that it can be passed as process argument."""
return "\"%s\"" % value

def extract_module_names_from_npm_targets(type_targets):
"""Extracts the module names from a list of NPM targets.

For example: Consider the `@npm//@types/node` target. This function extracts
`@types/node` from the label. This is needed so that the Node types can be
resolved from within the test runner through runfile resolution.
"""
module_names = []
types = {}

for type_target in type_targets:
type_label = Label(type_target)
Expand All @@ -31,9 +22,9 @@ def extract_module_names_from_npm_targets(type_targets):
fail("Expected type targets to be part of the `@npm` workspace." +
"e.g. `@npm//@types/nodes`.")

module_names.append(type_package)
types[type_target] = type_package

return module_names
return types

def api_golden_test(
name,
Expand All @@ -43,52 +34,33 @@ def api_golden_test(
strip_export_pattern = default_strip_export_pattern,
types = [],
**kwargs):
"""Builds an API report for the specified entry-point and compares it against the
specified golden

Args;
name: Name of the test target
golden: Manifest path to the golden file
entry_point: Manifest path to the type definition entry-point.
data: Runtime dependenices needed for the rule (e.g. transitive type definitions)
strip_export_pattern: An optional regular expression to filter out exports from the golden.
types: Optional list of type targets to make available in the API report generation.
"""

quoted_export_pattern = _escape_regex_for_arg(strip_export_pattern)

kwargs["tags"] = kwargs.get("tags", []) + ["api_guard"]
write_file(
name = "%s_synthetic_package_json" % name,
out = "package.json",
content = [json.encode({
"name": name,
"exports": {
".": {
"types": entry_point,
},
},
})],
)

# For API golden tests not running against a NPM package, we extract all transitive
# declarations of the specified `data` targets. This is necessary because API extractor
# needs to resolve other targets that have been linked by the Bazel NodeJS rules. The
# linker by default only provides access to JavaScript sources, but the API extractor is
# specifically concerned with type definitions that we can extract manually here.
extract_types(
name = "%s_data_typings" % name,
pkg_npm(
name = "%s_synthetic_package" % name,
deps = data + ["%s_synthetic_package_json" % name],
testonly = True,
deps = data,
)

test_data = ["//bazel/api-golden", "//:package.json", ":%s_data_typings" % name] + \
data + types

nodejs_test(
_rjs_api_golden_test_npm_package(
no_copy_to_bin = types,
name = name,
data = test_data,
entry_point = "//bazel/api-golden:index.ts",
templated_args = nodejs_test_args + [golden, entry_point, "false", quoted_export_pattern] +
extract_module_names_from_npm_targets(types),
**kwargs
)

nodejs_binary(
name = name + ".accept",
testonly = True,
data = test_data,
entry_point = "//bazel/api-golden:index.ts",
templated_args = nodejs_test_args + [golden, entry_point, "true", quoted_export_pattern] +
extract_module_names_from_npm_targets(types),
golden_dir = fixup_path_for_rules_js(golden),
data = [":%s_synthetic_package" % name] + data,
npm_package = "%s/%s_synthetic_package" % (native.package_name(), name),
strip_export_pattern = strip_export_pattern,
types = extract_module_names_from_npm_targets(types),
**kwargs
)

Expand All @@ -100,37 +72,17 @@ def api_golden_test_npm_package(
strip_export_pattern = default_strip_export_pattern,
types = [],
**kwargs):
"""Builds an API report for all entry-points within the given NPM package and compares it
against goldens within the specified directory.

Args;
name: Name of the test target
golden_dir: Manifest path to the golden directory
npm_package: Manifest path to the NPM package.
data: Runtime dependenices needed for the rule (e.g. the tree artifact of the NPM package)
strip_export_pattern: An optional regular expression to filter out exports from the golden.
types: Optional list of type targets to make available in the API report generation.
"""

quoted_export_pattern = _escape_regex_for_arg(strip_export_pattern)

kwargs["tags"] = kwargs.get("tags", []) + ["api_guard"]

nodejs_test(
_rjs_api_golden_test_npm_package(
name = name,
data = ["//bazel/api-golden"] + data + types,
entry_point = "//bazel/api-golden:index_npm_packages.ts",
templated_args = nodejs_test_args + [golden_dir, npm_package, "false", quoted_export_pattern] +
extract_module_names_from_npm_targets(types),
no_copy_to_bin = types,
golden_dir = fixup_path_for_rules_js(golden_dir),
npm_package = fixup_path_for_rules_js(npm_package),
data = data,
strip_export_pattern = strip_export_pattern,
types = extract_module_names_from_npm_targets(types),
**kwargs
)

nodejs_binary(
name = name + ".accept",
testonly = True,
data = ["//bazel/api-golden"] + data + types,
entry_point = "//bazel/api-golden:index_npm_packages.ts",
templated_args = nodejs_test_args + [golden_dir, npm_package, "true", quoted_export_pattern] +
extract_module_names_from_npm_targets(types),
**kwargs
)
def fixup_path_for_rules_js(p):
segs = p.split("/")
return "/".join(segs[1:])
Loading
Loading