Skip to content

Commit

Permalink
build: flatten golden files directory (#22967)
Browse files Browse the repository at this point in the history
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.

(cherry picked from commit 766b07e)
  • Loading branch information
crisbeto authored and wagnermaciel committed Jun 16, 2021
1 parent 3675a24 commit 8dbdd4e
Show file tree
Hide file tree
Showing 40 changed files with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tools/public_api_guard/generate-guard-tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ load("@npm//ts-api-guardian:index.bzl", "ts_api_guardian_test")
against the associated source entry point.
"""

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

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

# Name of the .d.ts file that will be produced. We replace the slashes in the entry
# point name with underscores so that we can get a flat directory of golden files.
golden_file = "%s/%s" % (package_name, entry_point_tail.replace("/", "-"))

# Construct the path to the given entry-point. Note that we also need to find a way to
# allow guards for the primary entry-point of a package. e.g. "//src/cdk:cdk" should be also
# validated. We achieve this by checking if the package_name is equal to the entry_point name.
Expand All @@ -24,7 +28,7 @@ def generate_test_targets(golden_files):

# Create the test rule that compares the build output with the golden file.
ts_api_guardian_test(
name = "%s_api" % golden_file,
name = "%s_api" % target_name,
actual = "angular_material/src/%s/index.d.ts" % entry_point_path,
data = [golden_file] + [
"//src/%s" % (entry_point_path),
Expand Down

0 comments on commit 8dbdd4e

Please sign in to comment.