@nx/module-federation 20.2.0-beta.1 → 20.2.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/angular.d.ts +2 -0
  2. package/angular.js +5 -0
  3. package/index.d.ts +1 -0
  4. package/index.js +4 -0
  5. package/package.json +12 -11
  6. package/rspack.d.ts +2 -0
  7. package/rspack.js +5 -0
  8. package/src/utils/dependencies.d.ts +6 -0
  9. package/src/utils/dependencies.js +56 -0
  10. package/src/utils/get-remotes-for-host.d.ts +16 -0
  11. package/src/utils/get-remotes-for-host.js +97 -0
  12. package/src/utils/index.d.ts +9 -0
  13. package/src/utils/index.js +12 -0
  14. package/src/utils/models/index.d.ts +47 -0
  15. package/src/utils/models/index.js +2 -0
  16. package/src/utils/package-json.d.ts +8 -0
  17. package/src/utils/package-json.js +12 -0
  18. package/src/utils/parse-static-remotes-config.d.ts +13 -0
  19. package/src/utils/parse-static-remotes-config.js +34 -0
  20. package/src/utils/plugins/runtime-library-control.plugin.d.ts +3 -0
  21. package/src/utils/plugins/runtime-library-control.plugin.js +54 -0
  22. package/src/utils/public-api.d.ts +6 -0
  23. package/src/utils/public-api.js +16 -0
  24. package/src/utils/remotes.d.ts +19 -0
  25. package/src/utils/remotes.js +89 -0
  26. package/src/utils/secondary-entry-points.d.ts +12 -0
  27. package/src/utils/secondary-entry-points.js +125 -0
  28. package/src/utils/share.d.ts +49 -0
  29. package/src/utils/share.js +246 -0
  30. package/src/utils/start-remote-proxies.d.ts +5 -0
  31. package/src/utils/start-remote-proxies.js +38 -0
  32. package/src/utils/start-ssr-remote-proxies.d.ts +5 -0
  33. package/src/utils/start-ssr-remote-proxies.js +52 -0
  34. package/src/utils/typescript.d.ts +4 -0
  35. package/src/utils/typescript.js +53 -0
  36. package/src/with-module-federation/angular/utils.d.ts +15 -0
  37. package/src/with-module-federation/angular/utils.js +101 -0
  38. package/src/with-module-federation/angular/with-module-federation-ssr.d.ts +2 -0
  39. package/src/with-module-federation/angular/with-module-federation-ssr.js +68 -0
  40. package/src/with-module-federation/angular/with-module-federation.d.ts +2 -0
  41. package/src/with-module-federation/angular/with-module-federation.js +70 -0
  42. package/src/with-module-federation/rspack/utils.d.ts +12 -0
  43. package/src/with-module-federation/rspack/utils.js +74 -0
  44. package/src/with-module-federation/rspack/with-module-federation-ssr.d.ts +4 -0
  45. package/src/with-module-federation/rspack/with-module-federation-ssr.js +62 -0
  46. package/src/with-module-federation/rspack/with-module-federation.d.ts +9 -0
  47. package/src/with-module-federation/rspack/with-module-federation.js +70 -0
  48. package/src/with-module-federation/webpack/utils.d.ts +12 -0
  49. package/src/with-module-federation/webpack/utils.js +75 -0
  50. package/src/with-module-federation/webpack/with-module-federation-ssr.d.ts +2 -0
  51. package/src/with-module-federation/webpack/with-module-federation-ssr.js +50 -0
  52. package/src/with-module-federation/webpack/with-module-federation.d.ts +5 -0
  53. package/src/with-module-federation/webpack/with-module-federation.js +62 -0
  54. package/webpack.d.ts +2 -0
  55. package/webpack.js +5 -0
package/angular.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './src/with-module-federation/angular/with-module-federation';
2
+ export * from './src/with-module-federation/angular/with-module-federation-ssr';
package/angular.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./src/with-module-federation/angular/with-module-federation"), exports);
5
+ tslib_1.__exportStar(require("./src/with-module-federation/angular/with-module-federation-ssr"), exports);
package/index.d.ts CHANGED
@@ -0,0 +1 @@
1
+ export * from './src/utils/public-api';
package/index.js CHANGED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./src/utils/public-api"), exports);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nx/module-federation",
3
3
  "description": "The Nx Plugin for Module Federation contains executors and utilities that support building applications using Module Federation.",
4
- "version": "20.2.0-beta.1",
4
+ "version": "20.2.0-beta.3",
5
5
  "type": "commonjs",
6
6
  "repository": {
7
7
  "type": "git",
@@ -24,7 +24,17 @@
24
24
  "main": "index.js",
25
25
  "executors": "./executors.json",
26
26
  "dependencies": {
27
- "tslib": "^2.3.0"
27
+ "tslib": "^2.3.0",
28
+ "@nx/devkit": "20.2.0-beta.3",
29
+ "@nx/js": "20.2.0-beta.3",
30
+ "picocolors": "^1.1.0",
31
+ "webpack": "5.88.0",
32
+ "@rspack/core": "1.1.2",
33
+ "@module-federation/enhanced": "0.7.6",
34
+ "@module-federation/node": "2.6.11",
35
+ "@module-federation/sdk": "0.7.6",
36
+ "express": "^4.19.2",
37
+ "http-proxy-middleware": "^3.0.3"
28
38
  },
29
39
  "peerDependencies": {},
30
40
  "nx-migrations": {
@@ -33,14 +43,5 @@
33
43
  "publishConfig": {
34
44
  "access": "public"
35
45
  },
36
- "exports": {
37
- "./package.json": "./package.json",
38
- ".": {
39
- "types": "./index.d.ts",
40
- "default": "./index.js"
41
- },
42
- "./executors.json": "./executors.json",
43
- "./migrations.json": "./migrations.json"
44
- },
45
46
  "types": "./index.d.ts"
46
47
  }
package/rspack.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './src/with-module-federation/rspack/with-module-federation';
2
+ export * from './src/with-module-federation/rspack/with-module-federation-ssr';
package/rspack.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./src/with-module-federation/rspack/with-module-federation"), exports);
5
+ tslib_1.__exportStar(require("./src/with-module-federation/rspack/with-module-federation-ssr"), exports);
@@ -0,0 +1,6 @@
1
+ import type { ProjectGraph } from '@nx/devkit';
2
+ import type { WorkspaceLibrary } from './models';
3
+ export declare function getDependentPackagesForProject(projectGraph: ProjectGraph, name: string): {
4
+ workspaceLibraries: WorkspaceLibrary[];
5
+ npmPackages: string[];
6
+ };
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDependentPackagesForProject = getDependentPackagesForProject;
4
+ const typescript_1 = require("./typescript");
5
+ const devkit_1 = require("@nx/devkit");
6
+ function getDependentPackagesForProject(projectGraph, name) {
7
+ const { npmPackages, workspaceLibraries } = collectDependencies(projectGraph, name);
8
+ return {
9
+ workspaceLibraries: [...workspaceLibraries.values()],
10
+ npmPackages: [...npmPackages],
11
+ };
12
+ }
13
+ function collectDependencies(projectGraph, name, dependencies = {
14
+ workspaceLibraries: new Map(),
15
+ npmPackages: new Set(),
16
+ }, seen = new Set()) {
17
+ if (seen.has(name)) {
18
+ return dependencies;
19
+ }
20
+ seen.add(name);
21
+ (projectGraph.dependencies[name] ?? []).forEach((dependency) => {
22
+ if (dependency.target.startsWith('npm:')) {
23
+ dependencies.npmPackages.add(dependency.target.replace('npm:', ''));
24
+ }
25
+ else {
26
+ dependencies.workspaceLibraries.set(dependency.target, {
27
+ name: dependency.target,
28
+ root: projectGraph.nodes[dependency.target].data.root,
29
+ importKey: getLibraryImportPath(dependency.target, projectGraph),
30
+ });
31
+ collectDependencies(projectGraph, dependency.target, dependencies, seen);
32
+ }
33
+ });
34
+ return dependencies;
35
+ }
36
+ function getLibraryImportPath(library, projectGraph) {
37
+ let buildLibsFromSource = true;
38
+ if (process.env.NX_BUILD_LIBS_FROM_SOURCE) {
39
+ buildLibsFromSource = process.env.NX_BUILD_LIBS_FROM_SOURCE === 'true';
40
+ }
41
+ const libraryNode = projectGraph.nodes[library];
42
+ let sourceRoots = [libraryNode.data.sourceRoot];
43
+ if (!buildLibsFromSource && process.env.NX_BUILD_TARGET) {
44
+ const buildTarget = (0, devkit_1.parseTargetString)(process.env.NX_BUILD_TARGET, projectGraph);
45
+ sourceRoots = (0, devkit_1.getOutputsForTargetAndConfiguration)(buildTarget, {}, libraryNode);
46
+ }
47
+ const tsConfigPathMappings = (0, typescript_1.readTsPathMappings)();
48
+ for (const [key, value] of Object.entries(tsConfigPathMappings)) {
49
+ for (const src of sourceRoots) {
50
+ if (value.find((path) => path.startsWith(src))) {
51
+ return key;
52
+ }
53
+ }
54
+ }
55
+ return undefined;
56
+ }
@@ -0,0 +1,16 @@
1
+ import { type ProjectGraph } from '@nx/devkit';
2
+ import { ModuleFederationConfig } from './models';
3
+ interface ModuleFederationExecutorContext {
4
+ projectName: string;
5
+ projectGraph: ProjectGraph;
6
+ root: string;
7
+ }
8
+ export declare function getRemotes(devRemotes: string[], skipRemotes: string[], config: ModuleFederationConfig, context: ModuleFederationExecutorContext, pathToManifestFile?: string): {
9
+ staticRemotes: string[];
10
+ devRemotes: any[];
11
+ dynamicRemotes: any[];
12
+ remotePorts: any[];
13
+ staticRemotePort: number;
14
+ };
15
+ export declare function getModuleFederationConfig(tsconfigPath: string, workspaceRoot: string, projectRoot: string, pluginName?: 'react' | 'angular'): any;
16
+ export {};
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRemotes = getRemotes;
4
+ exports.getModuleFederationConfig = getModuleFederationConfig;
5
+ const devkit_1 = require("@nx/devkit");
6
+ const internal_1 = require("@nx/js/src/internal");
7
+ const find_matching_projects_1 = require("nx/src/utils/find-matching-projects");
8
+ const pc = require("picocolors");
9
+ const path_1 = require("path");
10
+ const fs_1 = require("fs");
11
+ function extractRemoteProjectsFromConfig(config, pathToManifestFile) {
12
+ const remotes = [];
13
+ const dynamicRemotes = [];
14
+ if (pathToManifestFile && (0, fs_1.existsSync)(pathToManifestFile)) {
15
+ const moduleFederationManifestJson = (0, fs_1.readFileSync)(pathToManifestFile, 'utf-8');
16
+ if (moduleFederationManifestJson) {
17
+ // This should have shape of
18
+ // {
19
+ // "remoteName": "remoteLocation",
20
+ // }
21
+ const parsedManifest = JSON.parse(moduleFederationManifestJson);
22
+ if (Object.keys(parsedManifest).every((key) => typeof key === 'string' && typeof parsedManifest[key] === 'string')) {
23
+ dynamicRemotes.push(...Object.keys(parsedManifest));
24
+ }
25
+ }
26
+ }
27
+ const staticRemotes = config.remotes?.map((r) => (Array.isArray(r) ? r[0] : r)) ?? [];
28
+ remotes.push(...staticRemotes);
29
+ return { remotes, dynamicRemotes };
30
+ }
31
+ function collectRemoteProjects(remote, collected, context) {
32
+ const remoteProject = context.projectGraph.nodes[remote]?.data;
33
+ if (!context.projectGraph.nodes[remote] || collected.has(remote)) {
34
+ return;
35
+ }
36
+ collected.add(remote);
37
+ const remoteProjectRoot = remoteProject.root;
38
+ const remoteProjectTsConfig = remoteProject.targets['build'].options.tsConfig;
39
+ const remoteProjectConfig = getModuleFederationConfig(remoteProjectTsConfig, context.root, remoteProjectRoot);
40
+ const { remotes: remoteProjectRemotes } = extractRemoteProjectsFromConfig(remoteProjectConfig);
41
+ remoteProjectRemotes.forEach((r) => collectRemoteProjects(r, collected, context));
42
+ }
43
+ function getRemotes(devRemotes, skipRemotes, config, context, pathToManifestFile) {
44
+ const collectedRemotes = new Set();
45
+ const { remotes, dynamicRemotes } = extractRemoteProjectsFromConfig(config, pathToManifestFile);
46
+ remotes.forEach((r) => collectRemoteProjects(r, collectedRemotes, context));
47
+ const remotesToSkip = new Set((0, find_matching_projects_1.findMatchingProjects)(skipRemotes, context.projectGraph.nodes) ?? []);
48
+ if (remotesToSkip.size > 0) {
49
+ devkit_1.logger.info(`Remotes not served automatically: ${[...remotesToSkip.values()].join(', ')}`);
50
+ }
51
+ const knownRemotes = Array.from(collectedRemotes).filter((r) => !remotesToSkip.has(r));
52
+ const knownDynamicRemotes = dynamicRemotes.filter((r) => !remotesToSkip.has(r) && context.projectGraph.nodes[r]);
53
+ devkit_1.logger.info(`NX Starting module federation dev-server for ${pc.bold(context.projectName)} with ${[...knownRemotes, ...knownDynamicRemotes].length} remotes`);
54
+ const devServeApps = new Set(!devRemotes
55
+ ? []
56
+ : Array.isArray(devRemotes)
57
+ ? (0, find_matching_projects_1.findMatchingProjects)(devRemotes, context.projectGraph.nodes)
58
+ : (0, find_matching_projects_1.findMatchingProjects)([devRemotes], context.projectGraph.nodes));
59
+ const staticRemotes = knownRemotes.filter((r) => !devServeApps.has(r));
60
+ const devServeRemotes = [...knownRemotes, ...knownDynamicRemotes].filter((r) => devServeApps.has(r));
61
+ const staticDynamicRemotes = knownDynamicRemotes.filter((r) => !devServeApps.has(r));
62
+ const remotePorts = [...devServeRemotes, ...staticDynamicRemotes].map((r) => context.projectGraph.nodes[r].data.targets['serve'].options.port);
63
+ const staticRemotePort = Math.max(...[
64
+ ...remotePorts,
65
+ ...staticRemotes.map((r) => context.projectGraph.nodes[r].data.targets['serve'].options.port),
66
+ ]) +
67
+ (remotesToSkip.size + 1);
68
+ return {
69
+ staticRemotes,
70
+ devRemotes: devServeRemotes,
71
+ dynamicRemotes: staticDynamicRemotes,
72
+ remotePorts,
73
+ staticRemotePort,
74
+ };
75
+ }
76
+ function getModuleFederationConfig(tsconfigPath, workspaceRoot, projectRoot, pluginName = 'react') {
77
+ const moduleFederationConfigPathJS = (0, path_1.join)(workspaceRoot, projectRoot, 'module-federation.config.js');
78
+ const moduleFederationConfigPathTS = (0, path_1.join)(workspaceRoot, projectRoot, 'module-federation.config.ts');
79
+ let moduleFederationConfigPath = moduleFederationConfigPathJS;
80
+ // create a no-op so this can be called with issue
81
+ const fullTSconfigPath = tsconfigPath.startsWith(workspaceRoot)
82
+ ? tsconfigPath
83
+ : (0, path_1.join)(workspaceRoot, tsconfigPath);
84
+ let cleanupTranspiler = () => { };
85
+ if ((0, fs_1.existsSync)(moduleFederationConfigPathTS)) {
86
+ cleanupTranspiler = (0, internal_1.registerTsProject)(fullTSconfigPath);
87
+ moduleFederationConfigPath = moduleFederationConfigPathTS;
88
+ }
89
+ try {
90
+ const config = require(moduleFederationConfigPath);
91
+ cleanupTranspiler();
92
+ return config.default || config;
93
+ }
94
+ catch {
95
+ throw new Error(`Could not load ${moduleFederationConfigPath}. Was this project generated with "@nx/${pluginName}:host"?\nSee: https://nx.dev/concepts/more-concepts/faster-builds-with-module-federation`);
96
+ }
97
+ }
@@ -0,0 +1,9 @@
1
+ export * from './share';
2
+ export * from './dependencies';
3
+ export * from './package-json';
4
+ export * from './remotes';
5
+ export * from './models';
6
+ export * from './get-remotes-for-host';
7
+ export * from './parse-static-remotes-config';
8
+ export * from './start-remote-proxies';
9
+ export * from './start-ssr-remote-proxies';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./share"), exports);
5
+ tslib_1.__exportStar(require("./dependencies"), exports);
6
+ tslib_1.__exportStar(require("./package-json"), exports);
7
+ tslib_1.__exportStar(require("./remotes"), exports);
8
+ tslib_1.__exportStar(require("./models"), exports);
9
+ tslib_1.__exportStar(require("./get-remotes-for-host"), exports);
10
+ tslib_1.__exportStar(require("./parse-static-remotes-config"), exports);
11
+ tslib_1.__exportStar(require("./start-remote-proxies"), exports);
12
+ tslib_1.__exportStar(require("./start-ssr-remote-proxies"), exports);
@@ -0,0 +1,47 @@
1
+ import type { moduleFederationPlugin } from '@module-federation/sdk';
2
+ import type { NormalModuleReplacementPlugin as RspackNormalModuleReplacementPlugin } from '@rspack/core';
3
+ export type ModuleFederationLibrary = {
4
+ type: string;
5
+ name: string;
6
+ };
7
+ export type WorkspaceLibrary = {
8
+ name: string;
9
+ root: string;
10
+ importKey: string | undefined;
11
+ };
12
+ export type SharedWorkspaceLibraryConfig = {
13
+ getAliases: () => Record<string, string>;
14
+ getLibraries: (projectRoot: string, eager?: boolean) => Record<string, SharedLibraryConfig>;
15
+ getReplacementPlugin: () => RspackNormalModuleReplacementPlugin | import('webpack').NormalModuleReplacementPlugin;
16
+ };
17
+ export type Remotes = Array<string | [remoteName: string, remoteUrl: string]>;
18
+ export interface SharedLibraryConfig {
19
+ singleton?: boolean;
20
+ strictVersion?: boolean;
21
+ requiredVersion?: false | string;
22
+ eager?: boolean;
23
+ }
24
+ export type SharedFunction = (libraryName: string, sharedConfig: SharedLibraryConfig) => undefined | false | SharedLibraryConfig;
25
+ export type AdditionalSharedConfig = Array<string | [libraryName: string, sharedConfig: SharedLibraryConfig] | {
26
+ libraryName: string;
27
+ sharedConfig: SharedLibraryConfig;
28
+ }>;
29
+ export interface ModuleFederationConfig {
30
+ name: string;
31
+ remotes?: Remotes;
32
+ library?: ModuleFederationLibrary;
33
+ exposes?: Record<string, string>;
34
+ shared?: SharedFunction;
35
+ additionalShared?: AdditionalSharedConfig;
36
+ /**
37
+ * `nxRuntimeLibraryControlPlugin` is a runtime module federation plugin to ensure
38
+ * that shared libraries are resolved from a remote with live reload capabilities.
39
+ * If you run into any issues with loading shared libraries, try disabling this option.
40
+ */
41
+ disableNxRuntimeLibraryControlPlugin?: boolean;
42
+ }
43
+ export type NxModuleFederationConfigOverride = Omit<moduleFederationPlugin.ModuleFederationPluginOptions, 'exposes' | 'remotes' | 'name' | 'shared' | 'filename'>;
44
+ export type WorkspaceLibrarySecondaryEntryPoint = {
45
+ name: string;
46
+ path: string;
47
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ export declare function readRootPackageJson(): {
2
+ dependencies?: {
3
+ [key: string]: string;
4
+ };
5
+ devDependencies?: {
6
+ [key: string]: string;
7
+ };
8
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readRootPackageJson = readRootPackageJson;
4
+ const fs_1 = require("fs");
5
+ const devkit_1 = require("@nx/devkit");
6
+ function readRootPackageJson() {
7
+ const pkgJsonPath = (0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, 'package.json');
8
+ if (!(0, fs_1.existsSync)(pkgJsonPath)) {
9
+ throw new Error('NX MF: Could not find root package.json to determine dependency versions.');
10
+ }
11
+ return (0, devkit_1.readJsonFile)(pkgJsonPath);
12
+ }
@@ -0,0 +1,13 @@
1
+ import type { ExecutorContext } from '@nx/devkit';
2
+ export type StaticRemoteConfig = {
3
+ basePath: string;
4
+ outputPath: string;
5
+ urlSegment: string;
6
+ port: number;
7
+ };
8
+ export type StaticRemotesConfig = {
9
+ remotes: string[];
10
+ config: Record<string, StaticRemoteConfig> | undefined;
11
+ };
12
+ export declare function parseStaticRemotesConfig(staticRemotes: string[] | undefined, context: ExecutorContext): StaticRemotesConfig;
13
+ export declare function parseStaticSsrRemotesConfig(staticRemotes: string[] | undefined, context: ExecutorContext): StaticRemotesConfig;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseStaticRemotesConfig = parseStaticRemotesConfig;
4
+ exports.parseStaticSsrRemotesConfig = parseStaticSsrRemotesConfig;
5
+ const path_1 = require("path");
6
+ function parseStaticRemotesConfig(staticRemotes, context) {
7
+ if (!staticRemotes?.length) {
8
+ return { remotes: [], config: undefined };
9
+ }
10
+ const config = {};
11
+ for (const app of staticRemotes) {
12
+ const outputPath = context.projectGraph.nodes[app].data.targets['build'].options.outputPath;
13
+ const basePath = (0, path_1.dirname)(outputPath);
14
+ const urlSegment = (0, path_1.basename)(outputPath);
15
+ const port = context.projectGraph.nodes[app].data.targets['serve'].options.port;
16
+ config[app] = { basePath, outputPath, urlSegment, port };
17
+ }
18
+ return { remotes: staticRemotes, config };
19
+ }
20
+ function parseStaticSsrRemotesConfig(staticRemotes, context) {
21
+ if (!staticRemotes?.length) {
22
+ return { remotes: [], config: undefined };
23
+ }
24
+ const config = {};
25
+ for (const app of staticRemotes) {
26
+ const outputPath = (0, path_1.dirname)(context.projectGraph.nodes[app].data.targets['build'].options.outputPath // dist/checkout/browser -> checkout
27
+ );
28
+ const basePath = (0, path_1.dirname)(outputPath); // dist/checkout -> dist
29
+ const urlSegment = (0, path_1.basename)(outputPath); // dist/checkout -> checkout
30
+ const port = context.projectGraph.nodes[app].data.targets['serve'].options.port;
31
+ config[app] = { basePath, outputPath, urlSegment, port };
32
+ }
33
+ return { remotes: staticRemotes, config };
34
+ }
@@ -0,0 +1,3 @@
1
+ import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
+ declare const nxRuntimeLibraryControlPlugin: () => FederationRuntimePlugin;
3
+ export default nxRuntimeLibraryControlPlugin;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const runtimeStore = {
4
+ sharedPackagesFromDev: {},
5
+ };
6
+ if (process.env.NX_MF_DEV_REMOTES) {
7
+ // process.env.NX_MF_DEV_REMOTES is replaced by an array value via DefinePlugin, even though the original value is a stringified array.
8
+ runtimeStore.devRemotes = process.env
9
+ .NX_MF_DEV_REMOTES;
10
+ }
11
+ const nxRuntimeLibraryControlPlugin = function () {
12
+ return {
13
+ name: 'nx-runtime-library-control-plugin',
14
+ beforeInit(args) {
15
+ runtimeStore.name = args.options.name;
16
+ return args;
17
+ },
18
+ resolveShare: (args) => {
19
+ const { shareScopeMap, scope, pkgName, version, GlobalFederation } = args;
20
+ const originalResolver = args.resolver;
21
+ args.resolver = function () {
22
+ if (!runtimeStore.sharedPackagesFromDev[pkgName]) {
23
+ if (!GlobalFederation.__INSTANCES__) {
24
+ return originalResolver();
25
+ }
26
+ else if (!runtimeStore.devRemotes) {
27
+ return originalResolver();
28
+ }
29
+ const devRemoteInstanceToUse = GlobalFederation.__INSTANCES__.find((instance) => instance.options.shared[pkgName] &&
30
+ runtimeStore.devRemotes.find((dr) => instance.name === dr));
31
+ if (!devRemoteInstanceToUse) {
32
+ return originalResolver();
33
+ }
34
+ runtimeStore.sharedPackagesFromDev[pkgName] =
35
+ devRemoteInstanceToUse.name;
36
+ }
37
+ const remoteInstanceName = runtimeStore.sharedPackagesFromDev[pkgName];
38
+ const remoteInstance = GlobalFederation.__INSTANCES__.find((instance) => instance.name === remoteInstanceName);
39
+ try {
40
+ const remotePkgInfo = remoteInstance.options.shared[pkgName].find((shared) => shared.from === remoteInstanceName);
41
+ remotePkgInfo.useIn.push(runtimeStore.name);
42
+ remotePkgInfo.useIn = Array.from(new Set(remotePkgInfo.useIn));
43
+ shareScopeMap[scope][pkgName][version] = remotePkgInfo;
44
+ return remotePkgInfo;
45
+ }
46
+ catch {
47
+ return originalResolver();
48
+ }
49
+ };
50
+ return args;
51
+ },
52
+ };
53
+ };
54
+ exports.default = nxRuntimeLibraryControlPlugin;
@@ -0,0 +1,6 @@
1
+ import { AdditionalSharedConfig, ModuleFederationConfig, ModuleFederationLibrary, NxModuleFederationConfigOverride, Remotes, SharedFunction, SharedLibraryConfig, SharedWorkspaceLibraryConfig, WorkspaceLibrary, WorkspaceLibrarySecondaryEntryPoint } from './models';
2
+ import { applyAdditionalShared, applySharedFunction, getNpmPackageSharedConfig, sharePackages, shareWorkspaceLibraries } from './share';
3
+ import { mapRemotes, mapRemotesForSSR } from './remotes';
4
+ import { getDependentPackagesForProject } from './dependencies';
5
+ import { readRootPackageJson } from './package-json';
6
+ export { ModuleFederationConfig, NxModuleFederationConfigOverride, SharedLibraryConfig, SharedWorkspaceLibraryConfig, AdditionalSharedConfig, WorkspaceLibrary, SharedFunction, WorkspaceLibrarySecondaryEntryPoint, Remotes, ModuleFederationLibrary, applySharedFunction, applyAdditionalShared, getNpmPackageSharedConfig, shareWorkspaceLibraries, sharePackages, mapRemotes, mapRemotesForSSR, getDependentPackagesForProject, readRootPackageJson, };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readRootPackageJson = exports.getDependentPackagesForProject = exports.mapRemotesForSSR = exports.mapRemotes = exports.sharePackages = exports.shareWorkspaceLibraries = exports.getNpmPackageSharedConfig = exports.applyAdditionalShared = exports.applySharedFunction = void 0;
4
+ const share_1 = require("./share");
5
+ Object.defineProperty(exports, "applyAdditionalShared", { enumerable: true, get: function () { return share_1.applyAdditionalShared; } });
6
+ Object.defineProperty(exports, "applySharedFunction", { enumerable: true, get: function () { return share_1.applySharedFunction; } });
7
+ Object.defineProperty(exports, "getNpmPackageSharedConfig", { enumerable: true, get: function () { return share_1.getNpmPackageSharedConfig; } });
8
+ Object.defineProperty(exports, "sharePackages", { enumerable: true, get: function () { return share_1.sharePackages; } });
9
+ Object.defineProperty(exports, "shareWorkspaceLibraries", { enumerable: true, get: function () { return share_1.shareWorkspaceLibraries; } });
10
+ const remotes_1 = require("./remotes");
11
+ Object.defineProperty(exports, "mapRemotes", { enumerable: true, get: function () { return remotes_1.mapRemotes; } });
12
+ Object.defineProperty(exports, "mapRemotesForSSR", { enumerable: true, get: function () { return remotes_1.mapRemotesForSSR; } });
13
+ const dependencies_1 = require("./dependencies");
14
+ Object.defineProperty(exports, "getDependentPackagesForProject", { enumerable: true, get: function () { return dependencies_1.getDependentPackagesForProject; } });
15
+ const package_json_1 = require("./package-json");
16
+ Object.defineProperty(exports, "readRootPackageJson", { enumerable: true, get: function () { return package_json_1.readRootPackageJson; } });
@@ -0,0 +1,19 @@
1
+ import { Remotes } from './models';
2
+ /**
3
+ * Map remote names to a format that can be understood and used by Module
4
+ * Federation.
5
+ *
6
+ * @param remotes - The remotes to map
7
+ * @param remoteEntryExt - The file extension of the remoteEntry file
8
+ * @param determineRemoteUrl - The function used to lookup the URL of the served remote
9
+ */
10
+ export declare function mapRemotes(remotes: Remotes, remoteEntryExt: 'js' | 'mjs', determineRemoteUrl: (remote: string) => string, isRemoteGlobal?: boolean): Record<string, string>;
11
+ /**
12
+ * Map remote names to a format that can be understood and used by Module
13
+ * Federation.
14
+ *
15
+ * @param remotes - The remotes to map
16
+ * @param remoteEntryExt - The file extension of the remoteEntry file
17
+ * @param determineRemoteUrl - The function used to lookup the URL of the served remote
18
+ */
19
+ export declare function mapRemotesForSSR(remotes: Remotes, remoteEntryExt: 'js' | 'mjs', determineRemoteUrl: (remote: string) => string): Record<string, string>;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapRemotes = mapRemotes;
4
+ exports.mapRemotesForSSR = mapRemotesForSSR;
5
+ const path_1 = require("path");
6
+ /**
7
+ * Map remote names to a format that can be understood and used by Module
8
+ * Federation.
9
+ *
10
+ * @param remotes - The remotes to map
11
+ * @param remoteEntryExt - The file extension of the remoteEntry file
12
+ * @param determineRemoteUrl - The function used to lookup the URL of the served remote
13
+ */
14
+ function mapRemotes(remotes, remoteEntryExt, determineRemoteUrl, isRemoteGlobal = false) {
15
+ const mappedRemotes = {};
16
+ for (const nxRemoteProjectName of remotes) {
17
+ if (Array.isArray(nxRemoteProjectName)) {
18
+ const mfRemoteName = normalizeRemoteName(nxRemoteProjectName[0]);
19
+ mappedRemotes[mfRemoteName] = handleArrayRemote(nxRemoteProjectName, remoteEntryExt, isRemoteGlobal);
20
+ }
21
+ else if (typeof nxRemoteProjectName === 'string') {
22
+ const mfRemoteName = normalizeRemoteName(nxRemoteProjectName);
23
+ mappedRemotes[mfRemoteName] = handleStringRemote(nxRemoteProjectName, determineRemoteUrl, isRemoteGlobal);
24
+ }
25
+ }
26
+ return mappedRemotes;
27
+ }
28
+ // Helper function to deal with remotes that are arrays
29
+ function handleArrayRemote(remote, remoteEntryExt, isRemoteGlobal) {
30
+ let [nxRemoteProjectName, remoteLocation] = remote;
31
+ const mfRemoteName = normalizeRemoteName(nxRemoteProjectName);
32
+ const remoteLocationExt = (0, path_1.extname)(remoteLocation);
33
+ // If remote location already has .js or .mjs extension
34
+ if (['.js', '.mjs', '.json'].includes(remoteLocationExt)) {
35
+ return remoteLocation;
36
+ }
37
+ const baseRemote = remoteLocation.endsWith('/')
38
+ ? remoteLocation.slice(0, -1)
39
+ : remoteLocation;
40
+ const globalPrefix = isRemoteGlobal
41
+ ? `${normalizeRemoteName(nxRemoteProjectName)}@`
42
+ : '';
43
+ // if the remote is defined with anything other than http then we assume it's a promise based remote
44
+ // In that case we should use what the user provides as the remote location
45
+ if (!remoteLocation.startsWith('promise new Promise')) {
46
+ return `${globalPrefix}${baseRemote}/remoteEntry.${remoteEntryExt}`;
47
+ }
48
+ else {
49
+ return remoteLocation;
50
+ }
51
+ }
52
+ // Helper function to deal with remotes that are strings
53
+ function handleStringRemote(nxRemoteProjectName, determineRemoteUrl, isRemoteGlobal) {
54
+ const globalPrefix = isRemoteGlobal
55
+ ? `${normalizeRemoteName(nxRemoteProjectName)}@`
56
+ : '';
57
+ return `${globalPrefix}${determineRemoteUrl(nxRemoteProjectName)}`;
58
+ }
59
+ /**
60
+ * Map remote names to a format that can be understood and used by Module
61
+ * Federation.
62
+ *
63
+ * @param remotes - The remotes to map
64
+ * @param remoteEntryExt - The file extension of the remoteEntry file
65
+ * @param determineRemoteUrl - The function used to lookup the URL of the served remote
66
+ */
67
+ function mapRemotesForSSR(remotes, remoteEntryExt, determineRemoteUrl) {
68
+ const mappedRemotes = {};
69
+ for (const remote of remotes) {
70
+ if (Array.isArray(remote)) {
71
+ let [nxRemoteProjectName, remoteLocation] = remote;
72
+ const mfRemoteName = normalizeRemoteName(nxRemoteProjectName);
73
+ const remoteLocationExt = (0, path_1.extname)(remoteLocation);
74
+ mappedRemotes[mfRemoteName] = `${mfRemoteName}@${['.js', '.mjs', '.json'].includes(remoteLocationExt)
75
+ ? remoteLocation
76
+ : `${remoteLocation.endsWith('/')
77
+ ? remoteLocation.slice(0, -1)
78
+ : remoteLocation}/remoteEntry.${remoteEntryExt}`}`;
79
+ }
80
+ else if (typeof remote === 'string') {
81
+ const mfRemoteName = normalizeRemoteName(remote);
82
+ mappedRemotes[mfRemoteName] = `${mfRemoteName}@${determineRemoteUrl(remote)}`;
83
+ }
84
+ }
85
+ return mappedRemotes;
86
+ }
87
+ function normalizeRemoteName(remote) {
88
+ return remote.replace(/-/g, '_');
89
+ }
@@ -0,0 +1,12 @@
1
+ import type { WorkspaceLibrary } from './models';
2
+ import { WorkspaceLibrarySecondaryEntryPoint } from './models';
3
+ export declare function collectWorkspaceLibrarySecondaryEntryPoints(library: WorkspaceLibrary, tsconfigPathAliases: Record<string, string[]>): WorkspaceLibrarySecondaryEntryPoint[];
4
+ export declare function getNonNodeModulesSubDirs(directory: string): string[];
5
+ export declare function recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName: string, pkgVersion: string, pkgRoot: string, mainEntryPointExports: any | undefined, directories: string[], collectedPackages: {
6
+ name: string;
7
+ version: string;
8
+ }[]): void;
9
+ export declare function collectPackageSecondaryEntryPoints(pkgName: string, pkgVersion: string, collectedPackages: {
10
+ name: string;
11
+ version: string;
12
+ }[]): void;