Overview
The API Links generator creates a mapping of publicly accessible functions in Node.js to their source code locations in the GitHub repository. This enables linking from documentation to implementation.Unlike other generators, this processes JavaScript source files rather than Markdown documentation files.
Metadata
Generator identifier
Generator version
Requires JavaScript AST generator output as input (not Markdown)
Configuration
Output directory path for the generated apilinks.json file
Enable JSON minification (removes whitespace)
Git reference (branch/tag) for generating GitHub blob URLs
Repository path for generating GitHub URLs
Output Format
The generator produces:- Single file:
apilinks.json - Format: Object mapping function names to GitHub URLs
- Example:
Usage
Dependency Chain
- ast-js - Parses JavaScript files to AST
- api-links - Extracts exports and maps to source locations
Implementation Details
The generator:- Iterates through JavaScript AST programs
- Extracts exported functions and classes using
extractExports - Finds definitions and their line numbers using
findDefinitions - Checks for indirect references using
checkIndirectReferences - Generates GitHub blob URLs with line anchors
- Outputs mapping to
apilinks.json
Export Extraction
TheextractExports function:
- Analyzes
module.exportsassignments - Identifies exported functions, classes, and properties
- Maps export names to their definitions
- Handles various export patterns (direct, indirect, etc.)
Definition Finding
ThefindDefinitions function:
- Traverses the AST to locate function/class definitions
- Records line numbers for each definition
- Handles:
- Function declarations
- Class declarations
- Variable declarations with function expressions
- Method definitions
Indirect References
ThecheckIndirectReferences function:
- Identifies functions referenced through variables
- Resolves aliases and re-exports
- Ensures complete mapping of public API
URL Generation
GitHub URLs are generated using:- Base URL from
GITHUB_BLOB_URLtemplate - Repository and reference from configuration
- File basename (e.g.,
http.js) - Line number anchor (e.g.,
#L45)
https://github.com/nodejs/node/blob/main/lib/http.js#L45
Source: src/generators/api-links/