@hyperfrontend/builder/package/licenses

licenses

Opt-in third-party license collection.

collectThirdPartyLicenses(workspaceRoot, externals) scans the workspace node_modules for each external dependency, parses its package.json, locates a LICENSE file with case-insensitive matching, and infers the SPDX identifier — falling back to the license field when content-based detection is inconclusive. generateThirdPartyLicensesContent renders the collection as a markdown table; writeThirdPartyLicensesFile emits the file at the dist root. The license-URL builder lives in license-url.ts and supports GitHub, GitLab, and Bitbucket; other platforms resolve to null.

API Reference

ƒ Functions

§function

collectThirdPartyLicenses(workspaceRoot: string, externals: string[]): ThirdPartyLicenseEntry[]

Collects license information for every external dependency of the project being built.
The dependency list is supplied by the caller (typically the resolved external list from the bundle phase, with workspace-internal entries already removed). For each dependency, the function locates the installed package under <workspaceRoot>/node_modules, parses its package.json, scans for a LICENSE file, and attempts to derive a canonical license URL from the upstream repository field. Missing dependencies are logged at warn level and dropped from the result.

Parameters

NameTypeDescription
§workspaceRoot
string
Absolute path to the workspace root containing node_modules.
§externals
string[]
List of external (non-workspace) dependency names to inspect.

Returns

ThirdPartyLicenseEntry[]
Sorted list of license entries, one per resolvable dependency.

Example

Collecting licenses for a built library's bundle phase externals

const entries = collectThirdPartyLicenses('/abs/repo', ['rollup', 'typescript'])
§function

generateThirdPartyLicensesContent(entries: ThirdPartyLicenseEntry[]): string

Renders the markdown body for THIRD_PARTY_LICENSES.md from a collected list of license entries.
The output is a top-level heading followed by a two-column table mapping each dependency to a markdown link pointing at the upstream license file (or the raw license type when no URL is available). The body always ends with a trailing newline.

Parameters

NameTypeDescription
§entries
ThirdPartyLicenseEntry[]
License entries produced by collectThirdPartyLicenses.

Returns

string
Markdown content suitable for writing to disk.

Example

Generating the markdown body from a license collection

const md = generateThirdPartyLicensesContent(entries)
§function

writeThirdPartyLicensesFile(outputPath: string, content: string): void

Writes the rendered third-party-licenses content as <outputPath>/THIRD_PARTY_LICENSES.md. Parent directories are created if necessary by the underlying project-scope writer.

Parameters

NameTypeDescription
§outputPath
string
Absolute path to the build output directory (the dist root).
§content
string
Rendered markdown body produced by generateThirdPartyLicensesContent.

Example

Writing the file at the dist root

writeThirdPartyLicensesFile(ctx.outputPath, content)

Types

§type

ThirdPartyLicenseEntry

License entry for a single third-party dependency.