@hyperfrontend/builder/package/licenses

licenses

Third-party license collection.

collectThirdPartyLicenses(workspaceRoot, externals) scans the workspace node_modules for each named 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. Every entry carries the verbatim license, licence, copying and notice files of its package.

collectBundledThirdPartyLicenses produces the same entries for every third-party package a build inlines. It walks the declared dependencies from the project, through workspace packages, stopping at external names, and resolves each package from the one that requires it, so a nested install is read rather than the hoisted copy.

generateThirdPartyLicensesContent renders the collection as a markdown table followed by the license texts; 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

collectBundledThirdPartyLicenses(options: CollectBundledThirdPartyLicensesOptions): ThirdPartyLicenseEntry[]

Collects a license entry for every third-party package whose code the build inlines into its output.
The walk starts from the project's package.json#dependencies and follows dependencies transitively. A package named in external stops the walk, since the consumer installs it with its own license. A workspace package is walked through but not recorded: it is first-party, yet everything it depends on is bundled along with it. Every other package is recorded and its own dependencies are walked, each resolved the way Node resolves it from the package that requires it. Packages that cannot be found are logged at warn level and skipped.
The result over-approximates what the bundler kept: a package reached by the walk is listed even when tree-shaking removed all of its code.
Parameters
NameTypeDescription
§options
CollectBundledThirdPartyLicensesOptionsProject, workspace and external boundaries for the walk.
Returns
ThirdPartyLicenseEntry[]
License entries sorted by package name, one per inlined package.
Example

Listing the licenses carried by a bundled build

const entries = collectBundledThirdPartyLicenses({
  workspaceRoot: '/abs/repo',
  projectRoot: '/abs/repo/libs/features',
  external: ['tslib', 'typescript'],
  isWorkspacePackage: (name) => name.startsWith('@hyperfrontend/'),
})
§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. Each entry carries the verbatim text of the package's license and notice files.
Parameters
NameTypeDescription
§workspaceRoot
stringAbsolute 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). When any entry carries license texts, a "License texts" section follows the table with each package's license and notice files reproduced verbatim in fenced blocks. 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
stringAbsolute path to the build output directory (the dist root).
§content
stringRendered markdown body produced by generateThirdPartyLicensesContent.
Example

Writing the file at the dist root

writeThirdPartyLicensesFile(ctx.outputPath, content)

◈ Interfaces

§interface

CollectBundledThirdPartyLicensesOptions

Inputs to collectBundledThirdPartyLicenses.
Properties
§workspaceRoot:stringAbsolute workspace root, used to load the tsconfig path mappings that locate workspace packages.
§projectRoot:stringAbsolute path to the project being built; its package.json#dependencies start the walk.
§external:string[]Package names that stay external to the output; the walk stops at each of them.
§isWorkspacePackage:IsWorkspacePackagePredicatePredicate identifying workspace packages, which are walked through but never recorded.

◆ Types

§type

LicenseText

Verbatim content of one license or notice file shipped by a dependency.
§type

ThirdPartyLicenseEntry

License entry for a single third-party dependency.