-
Notifications
You must be signed in to change notification settings - Fork 6.8k
docs: generate adev-compatible api json #30857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mmalerba
wants to merge
1
commit into
angular:main
Choose a base branch
from
mmalerba:cdk-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+607
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") | ||
load("@aspect_rules_esbuild//esbuild:defs.bzl", "esbuild") | ||
load("//tools:defaults2.bzl", "ts_project") | ||
load("@aspect_rules_ts//ts:defs.bzl", rules_js_tsconfig = "ts_config") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
esbuild( | ||
name = "bin", | ||
bundle = True, | ||
entry_point = ":index.ts", | ||
external = [ | ||
"typescript", | ||
], | ||
format = "esm", | ||
output = "bin.mjs", | ||
platform = "node", | ||
target = "es2022", | ||
deps = [ | ||
":extract_api_to_json_lib", | ||
"//:node_modules/@angular/compiler-cli", | ||
], | ||
) | ||
|
||
ts_project( | ||
name = "extract_api_to_json_lib", | ||
srcs = glob( | ||
["**/*.ts"], | ||
exclude = [ | ||
"**/*.spec.ts", | ||
], | ||
), | ||
resolve_json_module = True, | ||
tsconfig = ":tsconfig", | ||
deps = [ | ||
"//:node_modules/@angular/compiler", | ||
"//:node_modules/@angular/compiler-cli", | ||
"//:node_modules/@bazel/runfiles", | ||
"//:node_modules/@types/node", | ||
"//:node_modules/typescript", | ||
], | ||
) | ||
|
||
# Action binary for the api_gen bazel rule. | ||
nodejs_binary( | ||
name = "extract_api_to_json", | ||
data = [ | ||
":bin", | ||
"//:node_modules/typescript", | ||
], | ||
entry_point = "bin.mjs", | ||
# Note: Using the linker here as we need it for ESM. The linker is not | ||
# super reliably when running concurrently on Windows- but we have existing | ||
# actions using the linker. An alternative would be to: | ||
# - bundle the Angular compiler into a CommonJS bundle | ||
# - use the patched resolution- but also patch the ESM imports (similar to how FW does it). | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
# Expose the sources in the dev-infra NPM package. | ||
filegroup( | ||
name = "files", | ||
srcs = glob(["**/*"]), | ||
) | ||
|
||
rules_js_tsconfig( | ||
name = "tsconfig", | ||
src = "tsconfig.json", | ||
deps = ["//:node_modules/@types/node"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Copied from https://github.com/angular/angular/tree/main/adev/shared-docs/pipeline/api-gen/extraction | ||
|
||
TODO: share this script between angular/angular & angular/components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
load("@build_bazel_rules_nodejs//:providers.bzl", "run_node") | ||
|
||
def _extract_api_to_json(ctx): | ||
"""Implementation of the extract_api_to_json rule""" | ||
|
||
# Define arguments that will be passed to the underlying nodejs program. | ||
args = ctx.actions.args() | ||
|
||
# Use a param file because we may have a large number of inputs. | ||
args.set_param_file_format("multiline") | ||
args.use_param_file("%s", use_always = True) | ||
|
||
# Pass the module_name for the extracted APIs. This will be something like "@angular/core". | ||
args.add(ctx.attr.module_name) | ||
|
||
# Pass the module_label for the extracted APIs, This is something like core for "@angular/core". | ||
args.add(ctx.attr.module_label) | ||
|
||
# Pass the set of private modules that should not be included in the API reference. | ||
args.add_joined(ctx.attr.private_modules, join_with = ",") | ||
|
||
# Pass the entry_point for from which to extract public symbols. | ||
args.add(ctx.file.entry_point) | ||
|
||
# Pass the set of source files from which API reference data will be extracted. | ||
args.add_joined(ctx.files.srcs, join_with = ",") | ||
|
||
# Pass the name of the output JSON file. | ||
json_output = ctx.outputs.output_name | ||
args.add(json_output.path) | ||
|
||
# Pass the import path map | ||
# TODO: consider module_mappings_aspect to deal with path mappings instead of manually | ||
# 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(): | ||
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 | ||
args.add(json.encode(path_map)) | ||
|
||
# Pass the set of (optional) extra entries | ||
args.add_joined(ctx.files.extra_entries, join_with = ",") | ||
|
||
# Define an action that runs the nodejs_binary executable. This is | ||
# the main thing that this rule does. | ||
run_node( | ||
ctx = ctx, | ||
inputs = depset(ctx.files.srcs + ctx.files.extra_entries), | ||
executable = "_extract_api_to_json", | ||
outputs = [json_output], | ||
arguments = [args], | ||
) | ||
|
||
# The return value describes what the rule is producing. In this case we need to specify | ||
# the "DefaultInfo" with the output JSON files. | ||
return [DefaultInfo(files = depset([json_output]))] | ||
|
||
extract_api_to_json = rule( | ||
# Point to the starlark function that will execute for this rule. | ||
implementation = _extract_api_to_json, | ||
doc = """Rule that extracts Angular API reference information from TypeScript | ||
sources and write it to a JSON file""", | ||
|
||
# The attributes that can be set to this rule. | ||
attrs = { | ||
"srcs": attr.label_list( | ||
doc = """The source files for this rule. This must include one or more | ||
TypeScript files.""", | ||
allow_empty = False, | ||
allow_files = True, | ||
), | ||
"output_name": attr.output( | ||
doc = """Name of the JSON output file.""", | ||
), | ||
"entry_point": attr.label( | ||
doc = """Source file entry-point from which to extract public symbols""", | ||
mandatory = True, | ||
allow_single_file = True, | ||
), | ||
"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( | ||
doc = """Map of import path to the index.ts file for that import""", | ||
allow_files = True, | ||
), | ||
"module_name": attr.string( | ||
doc = """JS Module name to be used for the extracted symbols""", | ||
mandatory = True, | ||
), | ||
"module_label": attr.string( | ||
doc = """Module label to be used for the extracted symbols. To be used as display name, for example in API docs""", | ||
), | ||
"extra_entries": attr.label_list( | ||
doc = """JSON files that contain extra entries to append to the final collection.""", | ||
allow_files = True, | ||
), | ||
|
||
# The executable for this rule (private). | ||
"_extract_api_to_json": attr.label( | ||
default = Label("//tools/adev-api-extraction:extract_api_to_json"), | ||
executable = True, | ||
cfg = "exec", | ||
), | ||
}, | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josephperrott @devversion either of you know how to get these files actually pulled into the cdk-builds repo? It looks like the repo contains the contents of the
npm_package
that we build above, but 'm not sure how to get these files pulled into it, or if we actually want thatThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CDK_TARGETS
is defined insrc/cdk/config.bzl
which lists all of the entrypoints and creates the expected targets based on that. Those targets are thets_project
/ng_project
targets, which typically include all*.ts
files (which are transpiled when they are actually brought into the package).Having not looked super closely, I don't think that these files would end up in the npm package by default here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I just wanted to copy this pile of json files into a separate top-level directory in the package. That'll make it easy on the other end to just copy all the files in this directory into the assets directory of adev. If that's not possible I could try including the json in the directory for its entry point and making the script on the other end search through the entry points for a specific file (e.g.
adev-api.json
or something