Skip to content

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

Open

Description

@jonmarozick

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:

  1. The externals cache. On a checksum hit, core copies the cached shared bundles without running esbuild (bundle-shared.ts L156–167), so a plugin sees nothing. We force cacheExternalArtifacts: false whenever licenses are extracted.
  2. process.exit after the last output. runBuilder's finally schedules process.exit 500 ms out (the TODO: fix retry issue from #106), so a post-step has to be synchronous.
  3. 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:

  1. Set metafile: true in the node-modules bundler. angular-bundler.ts already sets it (L168–169).
  2. 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.
  3. After buildApplication finishes, append entries for the adapter's bundles to the 3rdpartylicenses.txt Angular wrote, in Angular's format, skipping entries already there. The extractor could be ported with an // upstream: tag, like the other copied helpers.
  4. Optionally, legalComments could then follow Angular again ('none' under extractLicenses), 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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions