From 55ff902dec5197aa84b06aa6ba36e2c8d510f33d Mon Sep 17 00:00:00 2001 From: Aukevanoost Date: Wed, 11 Nov 2026 12:25:50 +0100 Subject: [PATCH 1/5] chore(deps): require @softarc/native-federation-orchestrator ^4.10.0 Orchestrator 4.10 is the first that accepts core 4.10 as a peer. The init schematic now writes the same range instead of ^4.8.0, which overwrote a user's newer range and could leave a lockfile on an orchestrator that rejects the adapter's core. --- package.json | 2 +- pnpm-lock.yaml | 32 +++++++++---------- .../init/steps/add-dependencies.spec.ts | 20 ++++++++++++ src/schematics/init/steps/add-dependencies.ts | 2 +- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 2de27c62..9f027597 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "@angular-devkit/schematics": "~22.2.0", "@chialab/esbuild-plugin-commonjs": "^0.19.0", "@softarc/native-federation": "~4.10.0", - "@softarc/native-federation-orchestrator": "^4.9.0", + "@softarc/native-federation-orchestrator": "^4.10.0", "es-module-shims": "^2.8.0", "esbuild": "^0.28.0", "jsonc-parser": "^3.3.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fdd9794c..085120f2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -28,8 +28,8 @@ importers: specifier: ~4.10.0 version: 4.10.0 '@softarc/native-federation-orchestrator': - specifier: ^4.9.0 - version: 4.9.0(@softarc/native-federation@4.10.0) + specifier: ^4.10.0 + version: 4.10.0(@softarc/native-federation@4.10.0) es-module-shims: specifier: ^2.8.0 version: 2.8.4 @@ -502,8 +502,8 @@ packages: peerDependencies: eslint: ^6.0.0 || ^7.0.0 || >=8.0.0 - '@eslint-community/regexpp@4.12.2': - resolution: {integrity: sha512-EriSTlt5OC9/7SXkRSCAhfSxxoSUgBm33OH+IkwbdpgoqsSsUg7y3uh+IICI/Qg4BBWr3U2i39RpmycbxMq4ew==, tarball: https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.12.2.tgz} + '@eslint-community/regexpp@4.12.3': + resolution: {integrity: sha512-R76UKbvsqI68DJJVTVyqFKqU98CN4+B+acxNfEA2IFarSzP0SjtKf/3+fFiXzTyv5Fj3PxLkGHe2wnVWWMxobQ==, tarball: https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.12.3.tgz} engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0} '@eslint/config-array@0.23.5': @@ -1563,11 +1563,11 @@ packages: cpu: [x64] os: [win32] - '@softarc/native-federation-orchestrator@4.9.0': - resolution: {integrity: sha512-qPe4SrIgdLC6k3Hpcb7v+rFrtHEpIOYUfIj6OsmaAL8z1hUKd9YSliTRE7Q12spFfDj2x9jG+RPebrtj2ImDjw==, tarball: https://registry.npmjs.org/@softarc/native-federation-orchestrator/-/native-federation-orchestrator-4.9.0.tgz} - engines: {node: '>=24.16.0'} + '@softarc/native-federation-orchestrator@4.10.0': + resolution: {integrity: sha512-XtbJ7/mfq/Qf3dx5vWon2XMBOcGdt63JxiARXVmDiEgENQEKaGmGOnl5Y9HZZUr1teOAm48BYJ/JutPGgQ9U8w==, tarball: https://registry.npmjs.org/@softarc/native-federation-orchestrator/-/native-federation-orchestrator-4.10.0.tgz} + engines: {node: '>=20.6.0'} peerDependencies: - '@softarc/native-federation': ^4.8.0 + '@softarc/native-federation': ^4.10.0 peerDependenciesMeta: '@softarc/native-federation': optional: true @@ -1783,8 +1783,8 @@ packages: resolution: {integrity: sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==, tarball: https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz} engines: {node: '>=12'} - ast-v8-to-istanbul@1.0.7: - resolution: {integrity: sha512-kFL68AG6ajd8fg248zwM9GQrUWEp79gsmjum34OEXjs4yHuUMZfYKwOLW9GMmB4oNvVrj+EAGxsP7ye2UR9UlA==, tarball: https://registry.npmjs.org/ast-v8-to-istanbul/-/ast-v8-to-istanbul-1.0.7.tgz} + ast-v8-to-istanbul@1.0.8: + resolution: {integrity: sha512-lPdpagk13ANXV+HClJEpCZM7kUsl5XcvgqKzZhaj6Ve1ZFICcY2sGhAN1n1vT0tML6EclT7bfVgTxqL57Gkpow==, tarball: https://registry.npmjs.org/ast-v8-to-istanbul/-/ast-v8-to-istanbul-1.0.8.tgz} balanced-match@4.0.3: resolution: {integrity: sha512-1pHv8LX9CpKut1Zp4EXey7Z8OfH11ONNH6Dhi2WDUt31VVZFXZzKwXcysBgqSumFCmR+0dqjMK5v5JiFHzi0+g==, tarball: https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.3.tgz} @@ -3630,7 +3630,7 @@ snapshots: eslint: 10.14.0(jiti@2.7.0) eslint-visitor-keys: 3.4.3 - '@eslint-community/regexpp@4.12.2': {} + '@eslint-community/regexpp@4.12.3': {} '@eslint/config-array@0.23.5': dependencies: @@ -4279,7 +4279,7 @@ snapshots: '@rollup/rollup-win32-x64-msvc@4.68.0': optional: true - '@softarc/native-federation-orchestrator@4.9.0(@softarc/native-federation@4.10.0)': + '@softarc/native-federation-orchestrator@4.10.0(@softarc/native-federation@4.10.0)': dependencies: semver: 7.8.6 optionalDependencies: @@ -4332,7 +4332,7 @@ snapshots: '@typescript-eslint/eslint-plugin@8.72.1(@typescript-eslint/parser@8.72.1(eslint@10.14.0(jiti@2.7.0))(typescript@6.0.3))(eslint@10.14.0(jiti@2.7.0))(typescript@6.0.3)': dependencies: - '@eslint-community/regexpp': 4.12.2 + '@eslint-community/regexpp': 4.12.3 '@typescript-eslint/parser': 8.72.1(eslint@10.14.0(jiti@2.7.0))(typescript@6.0.3) '@typescript-eslint/scope-manager': 8.72.1 '@typescript-eslint/type-utils': 8.72.1(eslint@10.14.0(jiti@2.7.0))(typescript@6.0.3) @@ -4429,7 +4429,7 @@ snapshots: dependencies: '@bcoe/v8-coverage': 1.0.2 '@vitest/utils': 4.1.12 - ast-v8-to-istanbul: 1.0.7 + ast-v8-to-istanbul: 1.0.8 istanbul-lib-coverage: 3.2.2 istanbul-lib-report: 3.0.1 istanbul-reports: 3.2.0 @@ -4532,7 +4532,7 @@ snapshots: assertion-error@2.0.1: {} - ast-v8-to-istanbul@1.0.7: + ast-v8-to-istanbul@1.0.8: dependencies: '@jridgewell/trace-mapping': 0.3.31 estree-walker: 3.0.3 @@ -4784,7 +4784,7 @@ snapshots: eslint@10.14.0(jiti@2.7.0): dependencies: '@eslint-community/eslint-utils': 4.10.1(eslint@10.14.0(jiti@2.7.0)) - '@eslint-community/regexpp': 4.12.2 + '@eslint-community/regexpp': 4.12.3 '@eslint/config-array': 0.23.5 '@eslint/config-helpers': 0.7.0 '@eslint/core': 1.2.1 diff --git a/src/schematics/init/steps/add-dependencies.spec.ts b/src/schematics/init/steps/add-dependencies.spec.ts index f2e10e57..cf523273 100644 --- a/src/schematics/init/steps/add-dependencies.spec.ts +++ b/src/schematics/init/steps/add-dependencies.spec.ts @@ -1,5 +1,7 @@ import { EmptyTree, type Tree } from '@angular-devkit/schematics'; +import { readFileSync } from 'node:fs'; + import { addDependencies } from './add-dependencies.js'; const CONTEXT = { addTask: () => undefined } as never; @@ -51,4 +53,22 @@ describe('addDependencies', () => { /@angular\/core is not a dependency/ ); }); + + // A lower range than the adapter's own lets an existing lockfile keep an orchestrator that + // rejects the adapter's core as a peer, installing two copies side by side. + it('pins the orchestrator to the range the adapter itself depends on', () => { + const adapterPkg = JSON.parse( + readFileSync(new URL('../../../../package.json', import.meta.url), 'utf8') + ); + tree.overwrite( + 'package.json', + JSON.stringify({ devDependencies: { '@softarc/native-federation-orchestrator': '^4.0.0' } }) + ); + + addDependencies(tree, CONTEXT, { ssr: false, webcomponent: false }); + + expect(packageJson(tree).devDependencies['@softarc/native-federation-orchestrator']).toBe( + adapterPkg.dependencies['@softarc/native-federation-orchestrator'] + ); + }); }); diff --git a/src/schematics/init/steps/add-dependencies.ts b/src/schematics/init/steps/add-dependencies.ts index d0244ef1..f65ca025 100644 --- a/src/schematics/init/steps/add-dependencies.ts +++ b/src/schematics/init/steps/add-dependencies.ts @@ -30,7 +30,7 @@ export function addDependencies( addDependency('dependencies', 'es-module-shims', '^2.8.0'); - addDependency('devDependencies', '@softarc/native-federation-orchestrator', '^4.8.0', true); + addDependency('devDependencies', '@softarc/native-federation-orchestrator', '^4.10.0', true); if (ssr) { console.log('SSR detected ...'); From 8af17374240dcc387b0ac922f6a58797ebb03188 Mon Sep 17 00:00:00 2001 From: Aukevanoost Date: Wed, 11 Nov 2026 12:25:50 +0100 Subject: [PATCH 2/5] fix(schematics): key the generated remote map by the raw project name init camelized sibling project names (wc-remote -> wcRemote), but the remote's federation config registers under the raw name, so both the static host's main.ts and the dynamic host's federation.manifest.json pointed at a remote that is never initialized. --- .../init/steps/generate-remote-map.spec.ts | 41 +++++++++++++++++++ .../init/steps/generate-remote-map.ts | 5 +-- 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 src/schematics/init/steps/generate-remote-map.spec.ts diff --git a/src/schematics/init/steps/generate-remote-map.spec.ts b/src/schematics/init/steps/generate-remote-map.spec.ts new file mode 100644 index 00000000..166c351e --- /dev/null +++ b/src/schematics/init/steps/generate-remote-map.spec.ts @@ -0,0 +1,41 @@ +import { generateRemoteMap } from './generate-remote-map.js'; + +function app(port?: number) { + return { + projectType: 'application', + architect: { build: {}, serve: { options: port ? { port } : {} } }, + }; +} + +describe('generateRemoteMap', () => { + // The init template writes `name: ''` into the remote's federation config, so a + // camelized key (`wcRemote`) would never match the remote's registered name `wc-remote`. + it('keys each remote by its raw project name', () => { + const workspace = { + projects: { shell: app(4200), 'wc-remote': app(4201) }, + }; + + expect(generateRemoteMap(workspace, 'shell')).toEqual({ + 'wc-remote': 'http://localhost:4201/remoteEntry.json', + }); + }); + + it('prefers the original serve port once a sibling has been federated', () => { + const remote = app(9999); + Object.assign(remote.architect, { 'serve-original': { options: { port: 4201 } } }); + + expect( + generateRemoteMap({ projects: { shell: app(), mfe1: remote } }, 'shell'), + ).toEqual({ + mfe1: 'http://localhost:4201/remoteEntry.json', + }); + }); + + it('skips libraries and the project itself', () => { + const workspace = { + projects: { shell: app(4200), lib: { ...app(), projectType: 'library' } }, + }; + + expect(generateRemoteMap(workspace, 'shell')).toEqual({}); + }); +}); diff --git a/src/schematics/init/steps/generate-remote-map.ts b/src/schematics/init/steps/generate-remote-map.ts index 6fa9d558..7d981f28 100644 --- a/src/schematics/init/steps/generate-remote-map.ts +++ b/src/schematics/init/steps/generate-remote-map.ts @@ -1,5 +1,3 @@ -import { strings } from '@angular-devkit/core'; - export function generateRemoteMap(workspace: any, projectName: string) { const result = {} as Record; @@ -17,7 +15,8 @@ export function generateRemoteMap(workspace: any, projectName: string) { project.architect['serve-original']?.options?.port ?? project.architect.serve?.options?.port ?? 4200; - result[strings.camelize(p)] = `http://localhost:${pPort}/remoteEntry.json`; + // The key must equal the remote's federation.config `name`, which is the raw project name. + result[p] = `http://localhost:${pPort}/remoteEntry.json`; } } From 58bee14c019cb6a61b62acdf06cceae64ea13e8d Mon Sep 17 00:00:00 2001 From: Aukevanoost Date: Wed, 11 Nov 2026 12:25:50 +0100 Subject: [PATCH 3/5] fix(config): keep shared locales when ignoreUnusedDeps is disabled withNativeFederation stripped every @angular/common/locales/* entry when ignoreUnusedDeps was off. Core 4.10 never expands locales on its own, so the only entries left to strip were the ones listed via shareAngularLocales, which the docs offer as the fallback for this case. --- src/config/share-utils.spec.ts | 10 +++++++--- src/config/share-utils.ts | 32 ++------------------------------ 2 files changed, 9 insertions(+), 33 deletions(-) diff --git a/src/config/share-utils.spec.ts b/src/config/share-utils.spec.ts index e7058a54..84884e0c 100644 --- a/src/config/share-utils.spec.ts +++ b/src/config/share-utils.spec.ts @@ -156,19 +156,23 @@ describe('withNativeFederation', () => { expect(mockCoreWithNativeFederation.mock.calls[0]![0].platform).toBe('browser'); }); - it('removes @angular/common/locales entries when ignoreUnusedDeps is disabled', () => { + // Core 4.10 never expands `@angular/common/locales/*` itself, so any locale key here was + // listed by the user (e.g. via shareAngularLocales) and must survive. + it('keeps locale entries when ignoreUnusedDeps is disabled', () => { mockCoreWithNativeFederation.mockReturnValue({ features: { ignoreUnusedDeps: false }, shared: { '@angular/core': { singleton: true }, '@angular/common/locales/de': { singleton: true }, - '@angular/common/locales/fr': { singleton: true }, }, }); const result = withNativeFederation({ shared: {} } as never); - expect(Object.keys(result.shared)).toEqual(['@angular/core']); + expect(Object.keys(result.shared)).toEqual([ + '@angular/core', + '@angular/common/locales/de', + ]); }); it('keeps locale entries when ignoreUnusedDeps is enabled', () => { diff --git a/src/config/share-utils.ts b/src/config/share-utils.ts index 6c59d17b..beb18d67 100644 --- a/src/config/share-utils.ts +++ b/src/config/share-utils.ts @@ -14,10 +14,7 @@ import { withNativeFederation as coreWithNativeFederation, } from "@softarc/native-federation/config"; import { NG_SKIP_LIST } from "./angular-skip-list.js"; -import type { - NormalizedFederationConfig, - NormalizedSharedExternalsConfig, -} from "@softarc/native-federation/internal"; +import type { NormalizedFederationConfig } from "@softarc/native-federation/internal"; import { existsSync, readFileSync } from "node:fs"; import * as path from "node:path"; import { cwd } from "node:process"; @@ -64,14 +61,7 @@ export function withNativeFederation( cfg.platform = getDefaultPlatform(Object.keys(cfg.shared ?? {})); } - const normalized = coreWithNativeFederation(cfg); - - // This is for being backwards compatible - if (!normalized.features.ignoreUnusedDeps) { - normalized.shared = removeNgLocales(normalized.shared); - } - - return normalized; + return coreWithNativeFederation(cfg); } /** @@ -166,21 +156,3 @@ function fromBuilder( ? (value as ConfigBuilder).get() : (value as T | undefined); } - -function removeNgLocales( - shared: NormalizedSharedExternalsConfig, -): NormalizedSharedExternalsConfig { - const keys = Object.keys(shared).filter( - (k) => !k.startsWith("@angular/common/locales"), - ); - - const filtered = keys.reduce( - (acc, curr) => ({ - ...acc, - [curr]: shared[curr], - }), - {}, - ); - - return filtered; -} From 3fb8400607ffb4cd53d396bb97414888c56e6080 Mon Sep 17 00:00:00 2001 From: Aukevanoost Date: Wed, 11 Nov 2026 12:25:50 +0100 Subject: [PATCH 4/5] fix(schematics): remove es-module-shims from the restored build target remove read the polyfills from the federation builder's options instead of the original ones on the esbuild target, so es-module-shims stayed in angular.json after esbuild was moved back to build. --- src/schematics/remove/schematic.spec.ts | 72 +++++++++++++++++++++++++ src/schematics/remove/schematic.ts | 11 ++-- 2 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 src/schematics/remove/schematic.spec.ts diff --git a/src/schematics/remove/schematic.spec.ts b/src/schematics/remove/schematic.spec.ts new file mode 100644 index 00000000..5304cd0b --- /dev/null +++ b/src/schematics/remove/schematic.spec.ts @@ -0,0 +1,72 @@ +import { EmptyTree, type Tree } from '@angular-devkit/schematics'; + +import remove from './schematic.js'; + +// Shape of a project right after `init`: the federation builder took over `build` and the +// original application builder (with polyfills) moved to `esbuild`. +function federatedWorkspace() { + return { + projects: { + mfe1: { + root: 'projects/mfe1', + sourceRoot: 'projects/mfe1/src', + architect: { + build: { + builder: '@angular-architects/native-federation:build', + options: { target: 'mfe1:esbuild:production' }, + }, + esbuild: { + builder: '@angular/build:application', + options: { + main: 'projects/mfe1/src/main.ts', + polyfills: ['zone.js', 'es-module-shims'], + }, + }, + serve: { + builder: '@angular-architects/native-federation:build', + options: {}, + }, + 'serve-original': { + builder: '@angular/build:dev-server', + configurations: { + production: { buildTarget: 'mfe1:esbuild:production' }, + development: { buildTarget: 'mfe1:esbuild:development' }, + }, + }, + }, + }, + }, + }; +} + +async function run(tree: Tree) { + const rule = remove({ project: 'mfe1' } as never); + await (rule as (t: Tree) => Promise)(tree); + return JSON.parse(tree.readText('angular.json')); +} + +describe('remove', () => { + let tree: Tree; + + beforeEach(() => { + tree = new EmptyTree(); + tree.create('angular.json', JSON.stringify(federatedWorkspace())); + }); + + it('restores the original build target without es-module-shims', async () => { + const { architect } = (await run(tree)).projects.mfe1; + + expect(architect.esbuild).toBeUndefined(); + expect(architect.build.builder).toBe('@angular/build:application'); + expect(architect.build.options.polyfills).toEqual(['zone.js']); + }); + + it('points serve back at the build target', async () => { + const { architect } = (await run(tree)).projects.mfe1; + + expect(architect.serve.builder).toBe('@angular/build:dev-server'); + expect(architect.serve.configurations.production.buildTarget).toBe( + 'mfe1:build:production', + ); + }); +}); diff --git a/src/schematics/remove/schematic.ts b/src/schematics/remove/schematic.ts index 1610b6f5..ed51e95a 100644 --- a/src/schematics/remove/schematic.ts +++ b/src/schematics/remove/schematic.ts @@ -96,13 +96,12 @@ function normalizeOptions(options: NfSchematicSchema, workspace: any): Normalize .join(projectRoot, 'src/assets/federation.manifest.json') .replace(/\\/g, '/'); - const main = projectConfig.architect.build.options.main; + // After init, `build` is the federation builder and the original options live on `esbuild`. + const buildOptions = (projectConfig.architect.esbuild ?? projectConfig.architect.build).options; + const main = buildOptions.main; - if (!projectConfig.architect.build.options.polyfills) { - projectConfig.architect.build.options.polyfills = []; - } - - const polyfills = projectConfig.architect.build.options.polyfills; + buildOptions.polyfills ??= []; + const polyfills = buildOptions.polyfills; return { polyfills, projectName, From 77c17354a260c71d72bd1c55cc72b919f5adb67c Mon Sep 17 00:00:00 2001 From: Aukevanoost Date: Wed, 11 Nov 2026 12:32:54 +0100 Subject: [PATCH 5/5] fix: address review of the pre-release QA fixes - correct the orchestrator rationale: 4.8 and 4.9 accept core 4.10 as a peer; the risk of a lower range is a second orchestrator copy - locale spec: core does expand locales with resolveGlob; merge the two ignoreUnusedDeps cases - remove: drop the polyfills option when es-module-shims was its only entry, drop the unused main field, use browser in the spec fixture --- src/config/share-utils.spec.ts | 25 +++---------- .../init/steps/add-dependencies.spec.ts | 4 +-- src/schematics/remove/schematic.spec.ts | 17 ++++++++- src/schematics/remove/schematic.ts | 35 +++++++------------ 4 files changed, 35 insertions(+), 46 deletions(-) diff --git a/src/config/share-utils.spec.ts b/src/config/share-utils.spec.ts index 84884e0c..3367c761 100644 --- a/src/config/share-utils.spec.ts +++ b/src/config/share-utils.spec.ts @@ -156,28 +156,11 @@ describe('withNativeFederation', () => { expect(mockCoreWithNativeFederation.mock.calls[0]![0].platform).toBe('browser'); }); - // Core 4.10 never expands `@angular/common/locales/*` itself, so any locale key here was - // listed by the user (e.g. via shareAngularLocales) and must survive. - it('keeps locale entries when ignoreUnusedDeps is disabled', () => { + // Locale keys only get here when the user lists them (shareAngularLocales) or opts into + // `includeSecondaries: { resolveGlob: true }`, so they are kept either way. + it.each([true, false])('keeps locale entries when ignoreUnusedDeps is %s', ignoreUnusedDeps => { mockCoreWithNativeFederation.mockReturnValue({ - features: { ignoreUnusedDeps: false }, - shared: { - '@angular/core': { singleton: true }, - '@angular/common/locales/de': { singleton: true }, - }, - }); - - const result = withNativeFederation({ shared: {} } as never); - - expect(Object.keys(result.shared)).toEqual([ - '@angular/core', - '@angular/common/locales/de', - ]); - }); - - it('keeps locale entries when ignoreUnusedDeps is enabled', () => { - mockCoreWithNativeFederation.mockReturnValue({ - features: { ignoreUnusedDeps: true }, + features: { ignoreUnusedDeps }, shared: { '@angular/core': { singleton: true }, '@angular/common/locales/de': { singleton: true }, diff --git a/src/schematics/init/steps/add-dependencies.spec.ts b/src/schematics/init/steps/add-dependencies.spec.ts index cf523273..acd41e7f 100644 --- a/src/schematics/init/steps/add-dependencies.spec.ts +++ b/src/schematics/init/steps/add-dependencies.spec.ts @@ -54,8 +54,8 @@ describe('addDependencies', () => { ); }); - // A lower range than the adapter's own lets an existing lockfile keep an orchestrator that - // rejects the adapter's core as a peer, installing two copies side by side. + // A lower range than the adapter's own lets an existing lockfile keep an older orchestrator + // next to the adapter's, so the workspace ends up with two copies. it('pins the orchestrator to the range the adapter itself depends on', () => { const adapterPkg = JSON.parse( readFileSync(new URL('../../../../package.json', import.meta.url), 'utf8') diff --git a/src/schematics/remove/schematic.spec.ts b/src/schematics/remove/schematic.spec.ts index 5304cd0b..bb6c26a5 100644 --- a/src/schematics/remove/schematic.spec.ts +++ b/src/schematics/remove/schematic.spec.ts @@ -18,7 +18,7 @@ function federatedWorkspace() { esbuild: { builder: '@angular/build:application', options: { - main: 'projects/mfe1/src/main.ts', + browser: 'projects/mfe1/src/main.ts', polyfills: ['zone.js', 'es-module-shims'], }, }, @@ -39,6 +39,12 @@ function federatedWorkspace() { }; } +function withPolyfills(polyfills: string[]) { + const workspace = federatedWorkspace(); + workspace.projects.mfe1.architect.esbuild.options.polyfills = polyfills; + return JSON.stringify(workspace); +} + async function run(tree: Tree) { const rule = remove({ project: 'mfe1' } as never); await (rule as (t: Tree) => Promise)(tree); @@ -69,4 +75,13 @@ describe('remove', () => { 'mfe1:build:production', ); }); + + // A zoneless app only had es-module-shims, which init added; leave no empty array behind. + it('drops the polyfills option once es-module-shims was the only entry', async () => { + tree.overwrite('angular.json', withPolyfills(['es-module-shims'])); + + const { architect } = (await run(tree)).projects.mfe1; + + expect(architect.build.options).not.toHaveProperty('polyfills'); + }); }); diff --git a/src/schematics/remove/schematic.ts b/src/schematics/remove/schematic.ts index ed51e95a..fda65e2c 100644 --- a/src/schematics/remove/schematic.ts +++ b/src/schematics/remove/schematic.ts @@ -5,13 +5,12 @@ import type { NfSchematicSchema } from './schema.js'; import * as path from 'path'; type NormalizedOptions = { - polyfills: string; + buildOptions: { polyfills?: string | string[] }; projectName: string; projectRoot: string; projectSourceRoot: string; manifestPath: string; projectConfig: any; - main: string; }; export default function remove(options: NfSchematicSchema): Rule { @@ -21,13 +20,13 @@ export default function remove(options: NfSchematicSchema): Rule { const normalized = normalizeOptions(options, workspace); - const { polyfills, projectRoot } = normalized; + const { buildOptions, projectRoot } = normalized; const bootstrapPath = path.join(projectRoot, 'src/bootstrap.ts'); const mainPath = path.join(projectRoot, 'src/main.ts'); makeMainSync(tree, bootstrapPath, mainPath); - updatePolyfills(tree, polyfills); + updatePolyfills(tree, buildOptions); updateWorkspaceConfig(tree, normalized, workspace, workspaceFileName); }; } @@ -98,26 +97,29 @@ function normalizeOptions(options: NfSchematicSchema, workspace: any): Normalize // After init, `build` is the federation builder and the original options live on `esbuild`. const buildOptions = (projectConfig.architect.esbuild ?? projectConfig.architect.build).options; - const main = buildOptions.main; - buildOptions.polyfills ??= []; - const polyfills = buildOptions.polyfills; return { - polyfills, + buildOptions, projectName, projectRoot, projectSourceRoot, manifestPath, projectConfig, - main, }; } -function updatePolyfills(tree: Tree, polyfills: string | string[]) { +function updatePolyfills(tree: Tree, buildOptions: NormalizedOptions['buildOptions']) { + const { polyfills } = buildOptions; if (typeof polyfills === 'string') { updatePolyfillsFile(tree, polyfills); + return; + } + + const remaining = (polyfills ?? []).filter(p => p !== 'es-module-shims'); + if (remaining.length) { + buildOptions.polyfills = remaining; } else { - updatePolyfillsArray(tree, polyfills); + delete buildOptions.polyfills; } } @@ -129,17 +131,6 @@ function updatePolyfillsFile(tree: Tree, polyfills: string) { } } -function updatePolyfillsArray(_tree: Tree, polyfills: string[]) { - const polyfillsConfig = polyfills as string[]; - - const index = polyfillsConfig.findIndex(p => p === 'es-module-shims'); - if (index === -1) { - return; - } - - polyfillsConfig.splice(index, 1); -} - export function getWorkspaceFileName(tree: Tree): string { if (tree.exists('angular.json')) { return 'angular.json';