diff --git a/packages/webpack/src/utils/module-federation/secondary-entry-points.ts b/packages/webpack/src/utils/module-federation/secondary-entry-points.ts index 272613df7e8e0..4226c64bb16bf 100644 --- a/packages/webpack/src/utils/module-federation/secondary-entry-points.ts +++ b/packages/webpack/src/utils/module-federation/secondary-entry-points.ts @@ -105,6 +105,33 @@ export function recursivelyCollectSecondaryEntryPointsFromDirectory( } } +function collectPackagesFromExports( + pkgName: string, + pkgVersion: string, + exports: any | undefined, + collectedPackages: { + name: string; + version: string; + }[] +): void { + for (const [relativeEntryPoint, exportOptions] of Object.entries(exports)) { + if (exportOptions?.['default']?.search(/\.(js|mjs|cjs)$/)) { + let entryPointName = joinPathFragments(pkgName, relativeEntryPoint); + if (entryPointName.endsWith('.json')) { + entryPointName = dirname(entryPointName); + } + if (entryPointName === '.') { + continue; + } + if (collectedPackages.find((p) => p.name === entryPointName)) { + continue; + } + + collectedPackages.push({ name: entryPointName, version: pkgVersion }); + } + } +} + export function collectPackageSecondaryEntryPoints( pkgName: string, pkgVersion: string, @@ -130,6 +157,9 @@ export function collectPackageSecondaryEntryPoints( } const { exports } = packageJson; + if (exports) { + collectPackagesFromExports(pkgName, pkgVersion, exports, collectedPackages); + } const subDirs = getNonNodeModulesSubDirs(pathToPackage); recursivelyCollectSecondaryEntryPointsFromDirectory( pkgName, diff --git a/packages/webpack/src/utils/module-federation/share.spec.ts b/packages/webpack/src/utils/module-federation/share.spec.ts index 5c7a9ad394e16..132071382737e 100644 --- a/packages/webpack/src/utils/module-federation/share.spec.ts +++ b/packages/webpack/src/utils/module-federation/share.spec.ts @@ -163,20 +163,110 @@ describe('MF Share Utils', () => { ]); // ASSERT expect(packages).toEqual({ + '@angular/common': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/common/http': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/common/http/testing': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/common/locales/*': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/common/locales/global/*': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/common/testing': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/common/upgrade': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, '@angular/core': { + requiredVersion: '~13.2.0', singleton: true, strictVersion: true, + }, + '@angular/core/event-dispatch-contract.min.js': { requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, }, - '@angular/common': { + '@angular/core/primitives/event-dispatch': { + requiredVersion: '~13.2.0', singleton: true, strictVersion: true, + }, + '@angular/core/primitives/signals': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/rxjs-interop': { requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/schematics/*': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/testing': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, }, rxjs: { + requiredVersion: '~7.4.0', + singleton: true, + strictVersion: true, + }, + 'rxjs/ajax': { + requiredVersion: '~7.4.0', + singleton: true, + strictVersion: true, + }, + 'rxjs/fetch': { + requiredVersion: '~7.4.0', + singleton: true, + strictVersion: true, + }, + 'rxjs/internal/*': { + requiredVersion: '~7.4.0', + singleton: true, + strictVersion: true, + }, + 'rxjs/operators': { + requiredVersion: '~7.4.0', + singleton: true, + strictVersion: true, + }, + 'rxjs/testing': { + requiredVersion: '~7.4.0', singleton: true, strictVersion: true, + }, + 'rxjs/webSocket': { requiredVersion: '~7.4.0', + singleton: true, + strictVersion: true, }, }); }); @@ -218,6 +308,36 @@ describe('MF Share Utils', () => { // ASSERT expect(packages).toEqual({ '@angular/core': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/event-dispatch-contract.min.js': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/primitives/event-dispatch': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/primitives/signals': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/rxjs-interop': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/schematics/*': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/testing': { singleton: true, strictVersion: true, requiredVersion: '~13.2.0', @@ -227,12 +347,67 @@ describe('MF Share Utils', () => { strictVersion: true, requiredVersion: '~13.2.0', }, + '@angular/common/http': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, '@angular/common/http/testing': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/common/locales/*': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/common/locales/global/*': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/common/testing': { + requiredVersion: '~13.2.0', singleton: true, strictVersion: true, + }, + '@angular/common/upgrade': { requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, }, rxjs: { + requiredVersion: '~7.4.0', + singleton: true, + strictVersion: true, + }, + 'rxjs/ajax': { + requiredVersion: '~7.4.0', + singleton: true, + strictVersion: true, + }, + 'rxjs/fetch': { + requiredVersion: '~7.4.0', + singleton: true, + strictVersion: true, + }, + 'rxjs/internal/*': { + requiredVersion: '~7.4.0', + singleton: true, + strictVersion: true, + }, + 'rxjs/operators': { + requiredVersion: '~7.4.0', + singleton: true, + strictVersion: true, + }, + 'rxjs/testing': { + requiredVersion: '~7.4.0', + singleton: true, + strictVersion: true, + }, + 'rxjs/webSocket': { singleton: true, strictVersion: true, requiredVersion: '~7.4.0', @@ -285,6 +460,31 @@ describe('MF Share Utils', () => { strictVersion: true, requiredVersion: '~13.2.0', }, + '@angular/core/event-dispatch-contract.min.js': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/primitives/event-dispatch': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/primitives/signals': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/rxjs-interop': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/schematics/*': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, '@angular/core/testing': { singleton: true, strictVersion: true, @@ -361,6 +561,31 @@ describe('MF Share Utils', () => { strictVersion: true, requiredVersion: '~13.2.0', }, + '@angular/core/event-dispatch-contract.min.js': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/primitives/event-dispatch': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/primitives/signals': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/rxjs-interop': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, + '@angular/core/schematics/*': { + requiredVersion: '~13.2.0', + singleton: true, + strictVersion: true, + }, '@angular/core/testing': { singleton: true, strictVersion: true,