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
3 changes: 1 addition & 2 deletions src/aria/accordion/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("//tools:defaults.bzl", "ng_project", "ng_web_test_suite")
load("//tools/adev-api-extraction:extract_api_to_json.bzl", "extract_api_to_json")
load("//tools:defaults.bzl", "extract_api_to_json", "ng_project", "ng_web_test_suite")

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

Expand Down
3 changes: 1 addition & 2 deletions src/aria/combobox/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("//tools:defaults.bzl", "ng_project", "ng_web_test_suite", "ts_project")
load("//tools/adev-api-extraction:extract_api_to_json.bzl", "extract_api_to_json")
load("//tools:defaults.bzl", "extract_api_to_json", "ng_project", "ng_web_test_suite", "ts_project")

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

Expand Down
3 changes: 1 addition & 2 deletions src/aria/grid/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("//tools:defaults.bzl", "ng_project")
load("//tools/adev-api-extraction:extract_api_to_json.bzl", "extract_api_to_json")
load("//tools:defaults.bzl", "extract_api_to_json", "ng_project")

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

Expand Down
3 changes: 1 addition & 2 deletions src/aria/listbox/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("//tools:defaults.bzl", "ng_project", "ng_web_test_suite")
load("//tools/adev-api-extraction:extract_api_to_json.bzl", "extract_api_to_json")
load("//tools:defaults.bzl", "extract_api_to_json", "ng_project", "ng_web_test_suite")

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

Expand Down
3 changes: 1 addition & 2 deletions src/aria/menu/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("//tools:defaults.bzl", "ng_project", "ng_web_test_suite")
load("//tools/adev-api-extraction:extract_api_to_json.bzl", "extract_api_to_json")
load("//tools:defaults.bzl", "extract_api_to_json", "ng_project", "ng_web_test_suite")

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

Expand Down
3 changes: 1 addition & 2 deletions src/aria/tabs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("//tools:defaults.bzl", "ng_project", "ng_web_test_suite")
load("//tools/adev-api-extraction:extract_api_to_json.bzl", "extract_api_to_json")
load("//tools:defaults.bzl", "extract_api_to_json", "ng_project", "ng_web_test_suite")

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

Expand Down
3 changes: 1 addition & 2 deletions src/aria/toolbar/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("//tools:defaults.bzl", "ng_project", "ng_web_test_suite", "ts_project")
load("//tools/adev-api-extraction:extract_api_to_json.bzl", "extract_api_to_json")
load("//tools:defaults.bzl", "extract_api_to_json", "ng_project", "ng_web_test_suite", "ts_project")

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

Expand Down
3 changes: 1 addition & 2 deletions src/aria/tree/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
load("//tools:defaults.bzl", "ng_project", "ng_web_test_suite")
load("//tools/adev-api-extraction:extract_api_to_json.bzl", "extract_api_to_json")
load("//tools:defaults.bzl", "extract_api_to_json", "ng_project", "ng_web_test_suite")

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

Expand Down
46 changes: 40 additions & 6 deletions tools/adev-api-extraction/extract_api_to_json.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@aspect_rules_js//js:providers.bzl", "JsInfo")

def _extract_api_to_json(ctx):
"""Implementation of the extract_api_to_json rule"""

Expand Down Expand Up @@ -35,11 +37,43 @@ def _extract_api_to_json(ctx):
# specifying them
# https://github.com/bazelbuild/rules_nodejs/blob/5.x/internal/linker/link_node_modules.bzl#L236
path_map = {}
for target, path in ctx.attr.import_map.items():
import_map_files = []
for path, target in ctx.attr.import_map.items():
files = target.files.to_list()
if len(files) != 1:
fail("Expected a single file in import_map target %s" % target.label)
path_map[path] = files[0].path

# Include transitive declarations if available in JsInfo
if JsInfo in target:
files.extend(target[JsInfo].transitive_types.to_list())

import_map_files.extend(files)
if len(files) == 1:
path_map[path] = files[0].path
else:
found_path = None
for f in files:
if f.path.endswith("/node_modules/" + path):
found_path = f.path
break

# Handle @angular package subentries
if path.startswith("@angular/"):
parts = path.split("/")
if len(parts) > 2:
pkg_name = "/".join(parts[:2])
if f.path.endswith("/node_modules/" + pkg_name):
subentry = parts[-1]
found_path = f.path + "/types/" + subentry + ".d.ts"
break

if not found_path:
candidates = [f for f in files if f.path.endswith("/index.d.ts")]
sorted_candidates = sorted(candidates, key = lambda f: len(f.path))
found_path = sorted_candidates[0].path

if found_path:
path_map[path] = found_path
else:
fail("Expected a single file in import_map target %s, but found %s. Could not determine entry point. Files: %s" % (target.label, len(files), [f.path for f in files]))
args.add(json.encode(path_map))

# Pass the set of (optional) extra entries
Expand All @@ -48,7 +82,7 @@ def _extract_api_to_json(ctx):
# Define an action that runs the nodejs_binary executable. This is
# the main thing that this rule does.
ctx.actions.run(
inputs = depset(ctx.files.srcs + ctx.files.extra_entries),
inputs = depset(ctx.files.srcs + ctx.files.extra_entries + import_map_files),
executable = ctx.executable._extract_api_to_json,
outputs = [json_output],
arguments = [args],
Expand Down Expand Up @@ -86,7 +120,7 @@ extract_api_to_json = rule(
"private_modules": attr.string_list(
doc = """List of private modules that should not be included in the API symbol linking""",
),
"import_map": attr.label_keyed_string_dict(
"import_map": attr.string_keyed_label_dict(
doc = """Map of import path to the index.ts file for that import""",
allow_files = True,
),
Expand Down
12 changes: 12 additions & 0 deletions tools/defaults.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@rules_sass//src:index.bzl", _sass_binary = "sass_binary", _sass_library = "sass_library")
load("//:packages.bzl", "NO_STAMP_NPM_PACKAGE_SUBSTITUTIONS", "NPM_PACKAGE_SUBSTITUTIONS")
load("//:pkg-externals.bzl", "PKG_EXTERNALS")
load("//tools/adev-api-extraction:extract_api_to_json.bzl", _extract_api_to_json = "extract_api_to_json")
load("//tools/bazel:ng_package_interop.bzl", "ng_package_interop")
load("//tools/bazel:web_test_suite.bzl", _ng_web_test_suite = "ng_web_test_suite")
load("//tools/extract-tokens:index.bzl", _extract_tokens = "extract_tokens")
Expand Down Expand Up @@ -247,3 +248,14 @@ def protractor_web_test_suite(name, deps, **kwargs):
],
**kwargs
)

def extract_api_to_json(**kwargs):
_extract_api_to_json(
import_map = {
"@angular/core": "//:node_modules/@angular/core",
"@angular/core/*": "//:node_modules/@angular/core",
"@angular/cdk/bidi": "//src/cdk/bidi",
"@angular/aria/private": "//src/aria/private",
},
**kwargs
)
Loading