Repository navigation
Description
Follow-up to the legalComments point in #163.
Problem
With extractLicenses on (the @angular/build:application default), Angular writes 3rdpartylicenses.txt from the metafiles of its own esbuild builds (extractLicenses(metafiles, …) in execute-build.ts). Shared packages are external to that build. The adapter bundles them, and the exposed modules, in esbuild contexts of its own (node-modules-bundler.ts, angular-bundler.ts), so none of those packages reach the file.
script-options.ts keeps legalComments: 'eof' to compensate (L51–53). That only keeps the notices sources carry as legal comments (/*!, @license). In one of our remotes' production dist/, all 17 legal comments in the JS are Google LLC headers (Angular, Lit). Nothing in dist/ carries a notice for rxjs (Apache-2.0), tslib, i18next, @auth0/auth0-angular or launchdarkly-js-client-sdk, though all five are shared there.
Numbers
Angular 22.2.4, adapter 22.2.3, fromPackageJson(...) sharing with denseChunking and denseExternals, production configuration with extractLicenses: true. One host (ignoreUnusedDeps: false, 28 shared packages) and five remotes (9–16 shared packages each):
| Build | Packages in Angular's 3rdpartylicenses.txt |
Packages with code in dist/ |
|---|---|---|
| host | 14 | 55 |
| remote 1 | 5 | 27 |
| remote 2 | 7 | 34 |
| remote 3 | 7 | 35 |
| remote 4 | 6 | 34 |
| remote 5 | 6 | 37 |
"Packages with code in dist/" comes from the metafiles of the adapter's own esbuild builds (see the workaround below). We cross-checked it against production source maps: every node_modules package named in any map's sources is in that set. The shared bundles also contain packages that are never shared themselves (lit-html, lit-element, @lit/reactive-element, @floating-ui/dom, @auth0/auth0-spa-js, …), so the packageNames in remoteEntry.json are not enough on their own either.
Workaround we use
A custom builder that calls runBuilder from @angular-architects/native-federation/internal with one esbuild plugin:
{
name: 'third-party-licenses',
setup(build) {
build.initialOptions.metafile = true;
build.onEnd((result) => {
if (result.metafile) metafiles.push(result.metafile);
});
},
}After the run, it applies Angular's rules to those metafiles: bytesInOutput > 0, the package root after the last node_modules, name and license from package.json, text from SEE LICENSE IN or a LICENSE-like root file. It then appends an entry in Angular's format for each package the file doesn't already contain.
Three things made this harder than it should be:
- The externals cache. On a checksum hit, core copies the cached shared bundles without running esbuild (
bundle-shared.tsL156–167), so a plugin sees nothing. We forcecacheExternalArtifacts: falsewhenever licenses are extracted. process.exitafter the last output.runBuilder'sfinallyschedulesprocess.exit500 ms out (theTODO: fix retry issue from #106), so a post-step has to be synchronous.- Angular's extractor isn't exported from
@angular/build/private, so the rules and the format are a port.
Proposal
When the resolved Angular target has extractLicenses: true:
- Set
metafile: truein the node-modules bundler.angular-bundler.tsalready sets it (L168–169). - Store the bundled package list with each cached shared bundle (core's cache metadata), so a cache hit still contributes its packages. This touches core and the build-adapter interface, so it's probably the main design question.
- After
buildApplicationfinishes, append entries for the adapter's bundles to the3rdpartylicenses.txtAngular wrote, in Angular's format, skipping entries already there. The extractor could be ported with an// upstream:tag, like the other copied helpers. - Optionally,
legalCommentscould then follow Angular again ('none'underextractLicenses), which also makes the shared bundles smaller.
One edge case to decide: some libraries ship their dependencies as preserved modules under their own dist/node_modules/<dep>/, with no package.json there. Angular's extractor skips those silently. We resolve them the way Node would from that folder (the installed copy) and warn when that fails; matching Angular and skipping them would also be defensible.
#193 does 1 and 3. Instead of 2, it skips the externals cache in builds that extract licenses, which costs about 2 s on a production build of a 9-package remote. If you'd rather keep the cache there, 2 needs a small addition to core's cache metadata, and I'm happy to do that next. It follows Angular on the vendored-dependency edge case and leaves legalComments alone.
Activity