Skip to content

feat: adopt the 4.7.0 config builders - #141

Merged
Aukevanoost merged 5 commits into
mainfrom
feat/config-builder-types
Sep 23, 2026
Merged

Aukevanoost merged 5 commits into
mainfrom
feat/config-builder-types

Conversation

@Aukevanoost

@Aukevanoost Aukevanoost commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Follows @softarc/native-federation onto the config API of 4.7.0, where shared and sharedMappings accept the fromPackageJson / mappingsFromWorkspace builders directly (native-federation/native-federation-core#146).

Platform inference broke on a builder

withNativeFederation inferred the platform from Object.keys(cfg.shared). With a builder passed as shared, those keys are the builder's methods, so an SSR app got platform: 'browser' without a warning. The builder is now resolved once before the inference, and core receives the resolved object.

Types

  • The config helpers declare their return types (PackageJsonExternalsBuilder, ResolvedSharedExternalsConfig, NormalizedFederationConfig) instead of inferring them from core.
  • /config now also exports ExternalConfig, SharedExternalsConfig and SharedMappingEntry next to FederationConfig.
  • The builder types (PackageJsonExternalsBuilder, WorkspaceMappingsBuilder, ConfigBuilder) are left unexported to keep the seam with core small. They still reach users through the signatures.

Checked with a // @ts-check federation.config.mjs against the built package: the builders are typed as PackageJsonExternalsBuilder / WorkspaceMappingsBuilder, and an unknown key is flagged against FederationConfig.

Init schematic

init now generates fromPackageJson(...).patch(['@angular/core'], { includeSecondaries: { keepAll: true } }) instead of spreading shareAll(...) with an overrides entry that repeated every base option. Rendered against a scratch workspace, the old and new templates resolve to the same config, with one exception: @angular/core no longer carries a version field.

The old override derived that field from the declared range (^22.0.0 became 22.0.0), and the @angular/core/* secondaries inherited it over the installed version. Without the field, @angular/core is resolved like every other shareAll package, from its installed package.json.

Docs

pnpm typecheck, pnpm lint (0 errors, 34 pre-existing warnings) and pnpm test (252 passing) are green.

Core 4.7.0 lets `shared` take a builder such as `fromPackageJson(...)` directly. The platform
was inferred from `Object.keys(cfg.shared)`, which then lists the builder's methods, so an SSR
app got 'browser' without a warning. The builder is now resolved once before the inference and
core receives the resolved object.

The config helpers now declare their return types instead of inferring them from core.
`/config` now also exports `ExternalConfig`, `SharedExternalsConfig` and `SharedMappingEntry`
next to `FederationConfig`. The builder types stay core's: they reach users through the
signatures without being part of this package's API.
`init` now writes `fromPackageJson(...).override(...)` instead of spreading `shareAll(...)`
with `overrides`. The resolved config is identical; the builder no longer needs `.get()` since
core 4.7.0.
Also lists `fromPackageJson().filter()`, and notes that wildcard mappings need
`includeSecondaries: { resolveGlob: true }` when `ignoreUnusedDeps` is off
(native-federation/native-federation-core#147).
`.patch()` merges `includeSecondaries: { keepAll: true }` into the entry `fromPackageJson`
already built, so the base options are not repeated. It also stops `@angular/core` from
carrying a `version` taken from the declared range (`^22.0.0` -> `22.0.0`), which its
secondaries inherited over the installed version.
@Aukevanoost
Aukevanoost merged commit 7090cdc into main Sep 23, 2026
1 check passed
Aukevanoost added a commit that referenced this pull request Sep 24, 2026
Backports 22.1.3..22.2.0 onto the Angular 21 layout.

Incoming:
- #138: each federation build context gets its own generated tsconfig
  (write-context-tsconfig) instead of rewriting `files` in
  tsconfig.federation.json, and every mapping/exposed context is disposed
  before the app build. init no longer writes `files`; the new update22-2
  migration removes it from existing tsconfig.federation.json files.
- #143: builder accepts a `define` option, merged over the Angular target's
  define for exposed modules and passed through to the dev server
  (createInternalAngularBuilder moved to internal-angular-builder.ts).
- #141: config types exported, shared builders accepted without get(), init
  generates the shared config with fromPackageJson and patches @angular/core.
- #142: README overhaul pointing to the documentation website;
  MIGRATION_GUIDE.md removed in favour of the website's migration guide.
- @softarc/native-federation ~4.7.0, jsonc-parser added, json5 dropped.

Angular 21 specific adaptations:
- Layout: write-context-tsconfig lands in src/utils/ next to the bundler;
  src/utils/update-federation-tsconfig.* is removed as on main. Comment
  pointers to tools/esbuild/ respelled to utils/.
- Skipped d535e07 (Angular 22.2 upgrade): node-modules-bundler keeps the 21.2
  JavaScriptTransformer/Cache signatures, and federation-source-files keeps
  reading SourceFileCache.keys(), which is still a Map on 21.2.
- internal-angular-builder drops instrumentForCoverage, which this branch
  never carried; it only forwards define.
- Restores the pre-app-build dispose (#47) that the earlier main merge
  (d00b9fc) dropped, now as disposeFederationContexts() per #138.
- update22-2 keeps main's path and key for easier future merges, versioned
  21.2.13 so it runs when updating the -v4 package.
- README respelled for -v4 (badges, install, init, config import, ng update)
  with the version example set to 21.2.x.
- Kept deleted as before: update22 schematic, share-utils.spec.ts and
  tools/esbuild/angular-esbuild-adapter.spec.ts.
- Kept the ng21 pins, -v4 package name, 21.2.12 version and the TS 5.9 /
  eslint 9 toolchain; took only the core bump and jsonc-parser from main.
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.

1 participant