@hyperfrontend/builder/package/licenseslicenses
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
collectBundledThirdPartyLicenses( options: CollectBundledThirdPartyLicensesOptions): ThirdPartyLicenseEntry[ ]
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
| Name | Type | Description |
|---|---|---|
§options | CollectBundledThirdPartyLicensesOptions | Project, workspace and external boundaries for the walk. |
Returns
ThirdPartyLicenseEntry[ ]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/'),
})collectThirdPartyLicenses( workspaceRoot: string, externals: string[ ]): ThirdPartyLicenseEntry[ ]
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
Returns
ThirdPartyLicenseEntry[ ]Example
Collecting licenses for a built library's bundle phase externals
const entries = collectThirdPartyLicenses('/abs/repo', ['rollup', 'typescript'])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
| Name | Type | Description |
|---|---|---|
§entries | ThirdPartyLicenseEntry[ | License entries produced by collectThirdPartyLicenses. |
Returns
stringExample
Generating the markdown body from a license collection
const md = generateThirdPartyLicensesContent(entries)<outputPath>/THIRD_PARTY_LICENSES.md. Parent directories are created if necessary by the underlying project-scope writer.Parameters
Example
Writing the file at the dist root
writeThirdPartyLicensesFile(ctx.outputPath, content)◈ Interfaces
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.isWorkspacePackage:IsWorkspacePackagePredicatePredicate identifying workspace packages, which are walked through but never recorded.