Skip to content

Commit 766b07e

Browse files
authored
build: flatten golden files directory (#22967)
Currently all the golden files for primary entry points are at the root which makes them easy to find, but the ones for secondary entry points are in sub-directories and all have the same name (`autocomplete/testing.d.ts`, `button/testing.d.ts` etc.) which is hard to look up and looks weird when browsing through the file system. These changes flatten the directory so that the testing files are next to their entry points.
1 parent d97e5ae commit 766b07e

40 files changed

+8
-4
lines changed

tools/public_api_guard/generate-guard-tests.bzl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ load("@npm//ts-api-guardian:index.bzl", "ts_api_guardian_test")
77
against the associated source entry point.
88
"""
99

10-
def generate_test_targets(golden_files):
11-
for golden_file in golden_files:
10+
def generate_test_targets(targets):
11+
for target_name in targets:
1212
# Splits the path that is relative to the current directory into the package name and
1313
# entry point tail path. The package name is always the first path segment (e.g. "cdk/")
14-
[package_name, entry_point_tail] = golden_file.split("/", 1)
14+
[package_name, entry_point_tail] = target_name.split("/", 1)
1515

1616
# Name of the entry-point (e.g. "a11y", "drag-drop", "platform")
1717
entry_point = entry_point_tail[:-len(".d.ts")]
1818

19+
# Name of the .d.ts file that will be produced. We replace the slashes in the entry
20+
# point name with underscores so that we can get a flat directory of golden files.
21+
golden_file = "%s/%s" % (package_name, entry_point_tail.replace("/", "-"))
22+
1923
# Construct the path to the given entry-point. Note that we also need to find a way to
2024
# allow guards for the primary entry-point of a package. e.g. "//src/cdk:cdk" should be also
2125
# validated. We achieve this by checking if the package_name is equal to the entry_point name.
@@ -24,7 +28,7 @@ def generate_test_targets(golden_files):
2428

2529
# Create the test rule that compares the build output with the golden file.
2630
ts_api_guardian_test(
27-
name = "%s_api" % golden_file,
31+
name = "%s_api" % target_name,
2832
actual = "angular_material/src/%s/index.d.ts" % entry_point_path,
2933
data = [golden_file] + [
3034
"//src/%s" % (entry_point_path),

0 commit comments

Comments
 (0)