Skip to content

Commit 70ea93d

Browse files
committed
refactor(compiler-cli): Do extract symbols from private modules.
Modules like `core/primitives` are considered private and their symbols shouldn't be exposed nor linked in the docs.
1 parent 5e42769 commit 70ea93d

File tree

8 files changed

+30
-10
lines changed

8 files changed

+30
-10
lines changed

adev/shared-docs/pipeline/api-gen/extraction/extract_api_to_json.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ def _extract_api_to_json(ctx):
1616
# Pass the module_label for the extracted APIs, This is something like core for "@angular/core".
1717
args.add(ctx.attr.module_label)
1818

19+
# Pass the set of private modules that should not be included in the API reference.
20+
args.add_joined(ctx.attr.private_modules, join_with = ",")
21+
1922
# Pass the entry_point for from which to extract public symbols.
2023
args.add(ctx.file.entry_point)
2124

@@ -77,6 +80,9 @@ extract_api_to_json = rule(
7780
mandatory = True,
7881
allow_single_file = True,
7982
),
83+
"private_modules": attr.string_list(
84+
doc = """List of private modules that should not be included in the API symbol linking""",
85+
),
8086
"import_map": attr.label_keyed_string_dict(
8187
doc = """Map of import path to the index.ts file for that import""",
8288
allow_files = True,

adev/shared-docs/pipeline/api-gen/extraction/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ function main() {
1717
const [
1818
moduleName,
1919
moduleLabel,
20+
serializedPrivateModules,
2021
entryPointExecRootRelativePath,
2122
srcs,
2223
outputFilenameExecRootRelativePath,
2324
serializedPathMapWithExecRootRelativePaths,
2425
extraEntriesSrcs,
2526
] = rawParamLines;
2627

28+
const privateModules = new Set(serializedPrivateModules.split(','));
29+
2730
// The path map is a serialized JSON map of import path to index.ts file.
2831
// For example, {'@angular/core': 'path/to/some/index.ts'}
2932
const pathMap = JSON.parse(serializedPathMapWithExecRootRelativePaths) as Record<string, string>;
@@ -61,7 +64,7 @@ function main() {
6164
return result.concat(JSON.parse(readFileSync(path, {encoding: 'utf8'})) as DocEntry[]);
6265
}, []);
6366

64-
const apiDoc = program.getApiDocumentation(entryPointExecRootRelativePath);
67+
const apiDoc = program.getApiDocumentation(entryPointExecRootRelativePath, privateModules);
6568
const extractedEntries = apiDoc.entries;
6669
const combinedEntries = extractedEntries.concat(extraEntries);
6770

adev/shared-docs/pipeline/api-gen/generate_api_docs.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
load("//adev/shared-docs/pipeline/api-gen/extraction:extract_api_to_json.bzl", "extract_api_to_json")
22
load("//adev/shared-docs/pipeline/api-gen/rendering:render_api_to_html.bzl", "render_api_to_html")
33

4-
def generate_api_docs(name, module_name, entry_point, srcs, module_label = None, import_map = {}, extra_entries = []):
4+
def generate_api_docs(name, module_name, entry_point, srcs, private_modules = [""], module_label = None, import_map = {}, extra_entries = []):
55
"""Generates API documentation reference pages for the given sources."""
66
json_outfile = name + "_api.json"
77

@@ -14,6 +14,7 @@ def generate_api_docs(name, module_name, entry_point, srcs, module_label = None,
1414
output_name = json_outfile,
1515
import_map = import_map,
1616
extra_entries = extra_entries,
17+
private_modules = private_modules,
1718
)
1819

1920
render_api_to_html(

packages/compiler-cli/src/ngtsc/core/src/compiler.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,10 @@ export class NgCompiler {
904904
*
905905
* @returns A map of symbols with their associated module, eg: ApplicationRef => @angular/core
906906
*/
907-
getApiDocumentation(entryPoint: string): {entries: DocEntry[]; symbols: Map<string, string>} {
907+
getApiDocumentation(
908+
entryPoint: string,
909+
privateModules: Set<string>,
910+
): {entries: DocEntry[]; symbols: Map<string, string>} {
908911
const compilation = this.ensureAnalyzed();
909912
const checker = this.inputProgram.getTypeChecker();
910913
const docsExtractor = new DocsExtractor(checker, compilation.metaReader);
@@ -922,7 +925,7 @@ export class NgCompiler {
922925
// TODO: Technically the current directory is not the root dir.
923926
// Should probably be derived from the config.
924927
const rootDir = this.inputProgram.getCurrentDirectory();
925-
return docsExtractor.extractAll(entryPointSourceFile, rootDir);
928+
return docsExtractor.extractAll(entryPointSourceFile, rootDir, privateModules);
926929
}
927930

928931
/**

packages/compiler-cli/src/ngtsc/docs/src/extractor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class DocsExtractor {
5050
extractAll(
5151
sourceFile: ts.SourceFile,
5252
rootDir: string,
53+
privateModules: Set<string>,
5354
): {entries: DocEntry[]; symbols: Map<string, string>} {
5455
const entries: DocEntry[] = [];
5556
const symbols = new Map<string, string>();
@@ -77,8 +78,7 @@ export class DocsExtractor {
7778
*/
7879
const importedSymbols = getImportedSymbols(realSourceFile);
7980
importedSymbols.forEach((moduleName, symbolName) => {
80-
// TODO: we probably want to filter out symbols from private modules (like core/primitives)
81-
if (symbolName.startsWith('ɵ')) {
81+
if (symbolName.startsWith('ɵ') || privateModules.has(moduleName)) {
8282
return;
8383
}
8484

packages/compiler-cli/src/ngtsc/program.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,11 @@ export class NgtscProgram implements api.Program {
399399
* @param entryPoint Path to the entry point for the package for which API
400400
* docs should be extracted.
401401
*/
402-
getApiDocumentation(entryPoint: string): {entries: DocEntry[]; symbols: Map<string, string>} {
403-
return this.compiler.getApiDocumentation(entryPoint);
402+
getApiDocumentation(
403+
entryPoint: string,
404+
privateModules: Set<string>,
405+
): {entries: DocEntry[]; symbols: Map<string, string>} {
406+
return this.compiler.getApiDocumentation(entryPoint, privateModules);
404407
}
405408

406409
getEmittedSourceFiles(): Map<string, ts.SourceFile> {

packages/compiler-cli/test/ngtsc/env.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,14 @@ export class NgtscTestEnvironment {
321321
const {rootNames, options} = readNgcCommandLineAndConfiguration(this.commandLineArgs);
322322
const host = createCompilerHost({options});
323323
const program = createProgram({rootNames, host, options});
324-
return (program as NgtscProgram).getApiDocumentation(entryPoint).entries;
324+
return (program as NgtscProgram).getApiDocumentation(entryPoint, new Set()).entries;
325325
}
326326

327327
driveDocsExtractionForSymbols(entryPoint: string): Map<string, string> {
328328
const {rootNames, options} = readNgcCommandLineAndConfiguration(this.commandLineArgs);
329329
const host = createCompilerHost({options});
330330
const program = createProgram({rootNames, host, options});
331-
return (program as NgtscProgram).getApiDocumentation(entryPoint).symbols;
331+
return (program as NgtscProgram).getApiDocumentation(entryPoint, new Set()).symbols;
332332
}
333333

334334
driveXi18n(format: string, outputFileName: string, locale: string | null = null): void {

packages/core/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ generate_api_docs(
140140
],
141141
entry_point = ":index.ts",
142142
module_name = "@angular/core",
143+
private_modules = [
144+
"core/primitives/signals",
145+
"core/primitives/event-dispatch",
146+
],
143147
)
144148

145149
genrule(

0 commit comments

Comments
 (0)