Skip to content

feat(builder): list the packages of the federation bundles in 3rdpartylicenses.txt - #193

Open
jonmarozick wants to merge 2 commits into
native-federation:mainfrom
jonmarozick:feat/federation-licenses
Open

jonmarozick wants to merge 2 commits into
native-federation:mainfrom
jonmarozick:feat/federation-licenses

Conversation

@jonmarozick

Copy link
Copy Markdown

Fixes #192.

What changes

  • src/tools/esbuild/license-extractor.ts: a port of Angular's extractLicenses (// upstream: tag at 11dbe297f8, MIT notice kept). It differs from upstream only in that EXTRACTION_FILE_SEPARATOR is exported, and two eslint-disable-next-line no-empty comments sit on Angular's empty catch {} blocks. A spec runs Angular's own extractor (loaded by path, as assets.spec.ts does) on the same fixtures and expects identical output.
  • Node-modules bundler: sets metafile: true (angular-bundler.ts already did).
  • Build adapter: keeps the latest metafile of each bundle and returns them ordered by bundle name (metafiles()). Shared bundles don't pass their new metafile to entriesByOutputName, so core keeps matching them by file name as before.
  • Builder: when the Angular target has extractLicenses and this isn't the dev server, then after each successful Angular output it appends to the 3rdpartylicenses.txt at the output root an entry for every package of the federation bundles that the file doesn't contain yet. Entries are compared as whole text: both sides come from the same extractor, so a package Angular already listed is skipped, and Angular's part of the file is left byte for byte.
  • Cache: those builds bundle the shared externals without the externals cache, because a cache hit runs no esbuild and leaves no metafile. The builder logs one info line when it does this, and the cacheExternalArtifacts description in schema.json says so.

Trade-off: the externals cache in production builds

On a remote with 9 shared packages (Windows, warm .angular/cache, three runs each), a production build took 11.3–13.2 s without the externals cache and 9.6–10.8 s with it. CI builds that start without a cache are unaffected. Development builds and ng serve keep the cache.

If you'd rather keep the cache in production too, core would have to persist something per shared bundle (for example the input paths with bytesInOutput > 0) in its cache metadata and hand it back on a hit. I'm happy to do that next in core and here, but it changes core's adapter contract, so I didn't want to start with it.

Not changed

  • legalComments stays optimize ? 'eof' : 'inline'. With this change it could follow Angular ('none' under extractLicenses), but that changes bundle output, so it belongs in its own change.
  • Like Angular, packages a library ships under its own dist/node_modules/<dep>/ without a package.json are skipped.
  • The remote builder runs no Angular application build, so there is no 3rdpartylicenses.txt to complete.

Tests

  • New specs:
    • license-extractor.spec.ts: parity with Angular's extractor; tree-shaken and SEE LICENSE IN cases.
    • federation-licenses.spec.ts: appends after Angular's entries; ends up identical to what Angular writes when it bundles everything itself; adds nothing on a second run; leaves the file alone when nothing is missing; writes nothing when Angular wrote no file.
    • Adapter: keeps one metafile per bundle; shared bundles don't set entry.
    • Node-modules bundler: the metafile lists the package files it bundled.
  • pnpm typecheck, pnpm lint (0 errors, same warnings as main), pnpm knip and pnpm build pass.
  • pnpm test on Windows: the 10 new tests pass. The 33 failures are the same 33 that fail on main on this machine (symlink EPERM without Developer Mode, backslash paths). I couldn't run the suite on Linux.
  • Real app: Angular 22.2.4, fromPackageJson with denseChunking and denseExternals, this branch packed and installed into a copy of the app.
    • Production: Angular's own file listed 5 packages; with this change it lists 25. With production source maps turned on, every node_modules package named in the maps is listed, except two that a library vendors without a package.json (see above).
    • Development build: externals cache hits, no licence file.
    • ng serve: serves remoteEntry.json.

🤖 Generated with Claude Code

…ylicenses.txt

With extractLicenses, Angular writes 3rdpartylicenses.txt from the metafiles of its own bundles. The shared and exposed bundles are built in the adapter's own esbuild contexts, so none of their packages were listed; only notices kept as legal comments survived.

The adapter now keeps the latest metafile of each bundle (the node-modules bundler gains metafile: true; shared bundles keep core's file-name matching). After each successful Angular output, the builder appends an entry for every package Angular's file lacks, using a port of Angular's license extractor so rules and format match. Builds that extract licenses bundle the shared externals without the cache, because a cache hit runs no esbuild.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Aukevanoost

Aukevanoost commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Hey thanks for this! I've found a few points though:

  1. Watch mode uses stale metafiles. appendFederationLicenses runs before runFederationRebuild, so on later outputs it reads the previous federation build's metafiles. Linked-package rebuilds don't append at all. Could you move the append so it runs after a completed federation rebuild?

  2. Externals cache. Instead of turning it off, implement cacheData (feat: Let the adapter store data with a cached shared bundle native-federation-core#220, shipping in 4.9.0): return the workspace-relative directories of the packages each shared bundle inlined, and read them back from federationCache.adapterData for the shared bundles. Then the cache override, the log line and the schema.json change can go. Rebase on the core 4.9.0 bump once it's out.

  3. Nit: the metafiles() interface comment just restates the name, so it can go.

Before merging, we'll also need a green CI checkmark

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3rdpartylicenses.txt misses every package the adapter bundles (shared and exposed bundles)

2 participants