@nx/module-federation 24.0.0-beta.2 → 24.0.0-beta.4

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 (131) hide show
  1. package/README.md +1 -3
  2. package/dist/angular.d.ts +1 -5
  3. package/dist/angular.js +7 -6
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.js +0 -2
  6. package/dist/rspack.d.ts +1 -5
  7. package/dist/rspack.js +7 -6
  8. package/dist/src/migrations/update-24-0-0/inventory.d.ts +11 -0
  9. package/dist/src/migrations/update-24-0-0/inventory.js +139 -0
  10. package/dist/src/migrations/update-24-0-0/migrate-angular-module-federation.d.ts +5 -0
  11. package/dist/src/migrations/update-24-0-0/migrate-angular-module-federation.js +18 -0
  12. package/dist/src/migrations/update-24-0-0/migrate-module-federation.d.ts +10 -0
  13. package/dist/src/migrations/update-24-0-0/migrate-module-federation.js +26 -0
  14. package/dist/src/migrations/update-24-0-0/migrate-module-federation.md +1931 -0
  15. package/dist/src/migrations/update-24-0-0/migrate-react-module-federation.d.ts +5 -0
  16. package/dist/src/migrations/update-24-0-0/migrate-react-module-federation.js +18 -0
  17. package/dist/src/stubs/models.d.ts +26 -0
  18. package/dist/src/stubs/stubs.d.ts +19 -0
  19. package/dist/src/stubs/stubs.js +43 -0
  20. package/dist/webpack.d.ts +1 -2
  21. package/dist/webpack.js +4 -3
  22. package/migrations.json +6 -0
  23. package/package.json +5 -60
  24. package/readme-template.md +1 -3
  25. package/dist/internal.d.ts +0 -2
  26. package/dist/internal.js +0 -13
  27. package/dist/src/executors/utils/build-static-remotes.d.ts +0 -4
  28. package/dist/src/executors/utils/build-static-remotes.js +0 -67
  29. package/dist/src/executors/utils/index.d.ts +0 -4
  30. package/dist/src/executors/utils/index.js +0 -6
  31. package/dist/src/executors/utils/models.d.ts +0 -30
  32. package/dist/src/executors/utils/start-remote-iterators.d.ts +0 -25
  33. package/dist/src/executors/utils/start-remote-iterators.js +0 -52
  34. package/dist/src/executors/utils/start-static-remotes-file-server.d.ts +0 -15
  35. package/dist/src/executors/utils/start-static-remotes-file-server.js +0 -61
  36. package/dist/src/plugins/models/index.d.ts +0 -14
  37. package/dist/src/plugins/models/index.js +0 -2
  38. package/dist/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-dev-server-plugin.d.ts +0 -13
  39. package/dist/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-dev-server-plugin.js +0 -75
  40. package/dist/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-plugin.d.ts +0 -11
  41. package/dist/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-plugin.js +0 -93
  42. package/dist/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-ssr-dev-server-plugin.d.ts +0 -15
  43. package/dist/src/plugins/nx-module-federation-plugin/angular/nx-module-federation-ssr-dev-server-plugin.js +0 -107
  44. package/dist/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-dev-server-plugin.d.ts +0 -13
  45. package/dist/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-dev-server-plugin.js +0 -75
  46. package/dist/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-plugin.d.ts +0 -11
  47. package/dist/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-plugin.js +0 -80
  48. package/dist/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-ssr-dev-server-plugin.d.ts +0 -15
  49. package/dist/src/plugins/nx-module-federation-plugin/rspack/nx-module-federation-ssr-dev-server-plugin.js +0 -107
  50. package/dist/src/plugins/utils/build-static-remotes.d.ts +0 -3
  51. package/dist/src/plugins/utils/build-static-remotes.js +0 -65
  52. package/dist/src/plugins/utils/get-dynamic-manifest-file.d.ts +0 -2
  53. package/dist/src/plugins/utils/get-dynamic-manifest-file.js +0 -18
  54. package/dist/src/plugins/utils/get-remotes.d.ts +0 -7
  55. package/dist/src/plugins/utils/get-remotes.js +0 -68
  56. package/dist/src/plugins/utils/get-static-remotes.d.ts +0 -3
  57. package/dist/src/plugins/utils/get-static-remotes.js +0 -27
  58. package/dist/src/plugins/utils/index.d.ts +0 -7
  59. package/dist/src/plugins/utils/index.js +0 -10
  60. package/dist/src/plugins/utils/parse-remotes-config.d.ts +0 -6
  61. package/dist/src/plugins/utils/parse-remotes-config.js +0 -35
  62. package/dist/src/plugins/utils/start-remote-proxies.d.ts +0 -5
  63. package/dist/src/plugins/utils/start-remote-proxies.js +0 -65
  64. package/dist/src/plugins/utils/start-static-remotes-file-server.d.ts +0 -2
  65. package/dist/src/plugins/utils/start-static-remotes-file-server.js +0 -46
  66. package/dist/src/utils/dependencies.d.ts +0 -6
  67. package/dist/src/utils/dependencies.js +0 -70
  68. package/dist/src/utils/framework-detection.d.ts +0 -2
  69. package/dist/src/utils/framework-detection.js +0 -20
  70. package/dist/src/utils/get-remotes-for-host.d.ts +0 -17
  71. package/dist/src/utils/get-remotes-for-host.js +0 -154
  72. package/dist/src/utils/index.d.ts +0 -11
  73. package/dist/src/utils/index.js +0 -14
  74. package/dist/src/utils/is-serve-mode.d.ts +0 -2
  75. package/dist/src/utils/is-serve-mode.js +0 -19
  76. package/dist/src/utils/models/index.d.ts +0 -47
  77. package/dist/src/utils/models/index.js +0 -2
  78. package/dist/src/utils/module-federation-config.d.ts +0 -57
  79. package/dist/src/utils/module-federation-config.js +0 -144
  80. package/dist/src/utils/normalize-project-name.d.ts +0 -1
  81. package/dist/src/utils/normalize-project-name.js +0 -10
  82. package/dist/src/utils/package-json.d.ts +0 -2
  83. package/dist/src/utils/package-json.js +0 -12
  84. package/dist/src/utils/parse-static-remotes-config.d.ts +0 -13
  85. package/dist/src/utils/parse-static-remotes-config.js +0 -62
  86. package/dist/src/utils/plugins/runtime-library-control.plugin.d.ts +0 -3
  87. package/dist/src/utils/plugins/runtime-library-control.plugin.js +0 -54
  88. package/dist/src/utils/port-utils.d.ts +0 -7
  89. package/dist/src/utils/port-utils.js +0 -22
  90. package/dist/src/utils/public-api.d.ts +0 -7
  91. package/dist/src/utils/public-api.js +0 -18
  92. package/dist/src/utils/remotes.d.ts +0 -19
  93. package/dist/src/utils/remotes.js +0 -75
  94. package/dist/src/utils/rspack-version.d.ts +0 -3
  95. package/dist/src/utils/rspack-version.js +0 -11
  96. package/dist/src/utils/secondary-entry-points.d.ts +0 -12
  97. package/dist/src/utils/secondary-entry-points.js +0 -125
  98. package/dist/src/utils/share.d.ts +0 -58
  99. package/dist/src/utils/share.js +0 -334
  100. package/dist/src/utils/start-remote-proxies.d.ts +0 -5
  101. package/dist/src/utils/start-remote-proxies.js +0 -55
  102. package/dist/src/utils/start-ssr-remote-proxies.d.ts +0 -5
  103. package/dist/src/utils/start-ssr-remote-proxies.js +0 -69
  104. package/dist/src/utils/typescript.d.ts +0 -4
  105. package/dist/src/utils/typescript.js +0 -53
  106. package/dist/src/utils/url-helpers.d.ts +0 -13
  107. package/dist/src/utils/url-helpers.js +0 -70
  108. package/dist/src/with-module-federation/angular/utils.d.ts +0 -28
  109. package/dist/src/with-module-federation/angular/utils.js +0 -83
  110. package/dist/src/with-module-federation/angular/with-module-federation-ssr.d.ts +0 -2
  111. package/dist/src/with-module-federation/angular/with-module-federation-ssr.js +0 -86
  112. package/dist/src/with-module-federation/angular/with-module-federation.d.ts +0 -2
  113. package/dist/src/with-module-federation/angular/with-module-federation.js +0 -85
  114. package/dist/src/with-module-federation/react/utils.d.ts +0 -2
  115. package/dist/src/with-module-federation/react/utils.js +0 -17
  116. package/dist/src/with-module-federation/rspack/utils.d.ts +0 -10
  117. package/dist/src/with-module-federation/rspack/utils.js +0 -32
  118. package/dist/src/with-module-federation/rspack/with-module-federation-ssr.d.ts +0 -4
  119. package/dist/src/with-module-federation/rspack/with-module-federation-ssr.js +0 -75
  120. package/dist/src/with-module-federation/rspack/with-module-federation.d.ts +0 -9
  121. package/dist/src/with-module-federation/rspack/with-module-federation.js +0 -82
  122. package/dist/src/with-module-federation/webpack/utils.d.ts +0 -10
  123. package/dist/src/with-module-federation/webpack/utils.js +0 -32
  124. package/dist/src/with-module-federation/webpack/with-module-federation-ssr.d.ts +0 -2
  125. package/dist/src/with-module-federation/webpack/with-module-federation-ssr.js +0 -69
  126. package/dist/src/with-module-federation/webpack/with-module-federation.d.ts +0 -5
  127. package/dist/src/with-module-federation/webpack/with-module-federation.js +0 -72
  128. package/dist/url-helpers.d.ts +0 -13
  129. package/dist/url-helpers.js +0 -78
  130. package/executors.json +0 -4
  131. /package/dist/src/{executors/utils → stubs}/models.js +0 -0
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isPortInUse = isPortInUse;
4
- const net_1 = require("net");
5
- /**
6
- * Check if a port is in use by attempting to bind to it. Binding is local and
7
- * resolves immediately, so unlike a connection-based check it never stalls on
8
- * the OS TCP connect timeout when `localhost` resolves to an unreachable address
9
- * (e.g. IPv6 `::1`) -- the cause of the `nx serve` hang in #33909.
10
- */
11
- function isPortInUse(port, host = 'localhost') {
12
- return new Promise((resolve) => {
13
- const server = (0, net_1.createServer)();
14
- server.once('error', (err) => {
15
- resolve(err.code === 'EADDRINUSE');
16
- });
17
- server.once('listening', () => {
18
- server.close(() => resolve(false));
19
- });
20
- server.listen(port, host);
21
- });
22
- }
@@ -1,7 +0,0 @@
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 { normalizeProjectName } from './normalize-project-name';
4
- import { mapRemotes, mapRemotesForSSR } from './remotes';
5
- import { getDependentPackagesForProject } from './dependencies';
6
- import { readRootPackageJson } from './package-json';
7
- export { ModuleFederationConfig, NxModuleFederationConfigOverride, SharedLibraryConfig, SharedWorkspaceLibraryConfig, AdditionalSharedConfig, WorkspaceLibrary, SharedFunction, WorkspaceLibrarySecondaryEntryPoint, Remotes, ModuleFederationLibrary, applySharedFunction, applyAdditionalShared, getNpmPackageSharedConfig, shareWorkspaceLibraries, sharePackages, mapRemotes, mapRemotesForSSR, normalizeProjectName, getDependentPackagesForProject, readRootPackageJson, };
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readRootPackageJson = exports.getDependentPackagesForProject = exports.normalizeProjectName = 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 normalize_project_name_1 = require("./normalize-project-name");
11
- Object.defineProperty(exports, "normalizeProjectName", { enumerable: true, get: function () { return normalize_project_name_1.normalizeProjectName; } });
12
- const remotes_1 = require("./remotes");
13
- Object.defineProperty(exports, "mapRemotes", { enumerable: true, get: function () { return remotes_1.mapRemotes; } });
14
- Object.defineProperty(exports, "mapRemotesForSSR", { enumerable: true, get: function () { return remotes_1.mapRemotesForSSR; } });
15
- const dependencies_1 = require("./dependencies");
16
- Object.defineProperty(exports, "getDependentPackagesForProject", { enumerable: true, get: function () { return dependencies_1.getDependentPackagesForProject; } });
17
- const package_json_1 = require("./package-json");
18
- Object.defineProperty(exports, "readRootPackageJson", { enumerable: true, get: function () { return package_json_1.readRootPackageJson; } });
@@ -1,19 +0,0 @@
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>;
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapRemotes = mapRemotes;
4
- exports.mapRemotesForSSR = mapRemotesForSSR;
5
- const url_helpers_1 = require("./url-helpers");
6
- const normalize_project_name_1 = require("./normalize-project-name");
7
- /**
8
- * Map remote names to a format that can be understood and used by Module
9
- * Federation.
10
- *
11
- * @param remotes - The remotes to map
12
- * @param remoteEntryExt - The file extension of the remoteEntry file
13
- * @param determineRemoteUrl - The function used to lookup the URL of the served remote
14
- */
15
- function mapRemotes(remotes, remoteEntryExt, determineRemoteUrl, isRemoteGlobal = false) {
16
- const mappedRemotes = {};
17
- for (const nxRemoteProjectName of remotes) {
18
- if (Array.isArray(nxRemoteProjectName)) {
19
- const mfRemoteName = nxRemoteProjectName[0];
20
- mappedRemotes[mfRemoteName] = handleArrayRemote(nxRemoteProjectName, remoteEntryExt, isRemoteGlobal);
21
- }
22
- else if (typeof nxRemoteProjectName === 'string') {
23
- mappedRemotes[nxRemoteProjectName] = 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
- const [nxRemoteProjectName, remoteLocation] = remote;
31
- const mfRemoteName = (0, normalize_project_name_1.normalizeProjectName)(nxRemoteProjectName);
32
- const finalRemoteUrl = (0, url_helpers_1.processRemoteLocation)(remoteLocation, remoteEntryExt);
33
- // Promise-based remotes should not use the global prefix format
34
- if (remoteLocation.startsWith('promise new Promise')) {
35
- return finalRemoteUrl;
36
- }
37
- return isRemoteGlobal ? `${mfRemoteName}@${finalRemoteUrl}` : finalRemoteUrl;
38
- }
39
- // Helper function to deal with remotes that are strings
40
- function handleStringRemote(nxRemoteProjectName, determineRemoteUrl, isRemoteGlobal) {
41
- const globalPrefix = isRemoteGlobal
42
- ? `${(0, normalize_project_name_1.normalizeProjectName)(nxRemoteProjectName)}@`
43
- : '';
44
- return `${globalPrefix}${determineRemoteUrl(nxRemoteProjectName)}`;
45
- }
46
- /**
47
- * Map remote names to a format that can be understood and used by Module
48
- * Federation.
49
- *
50
- * @param remotes - The remotes to map
51
- * @param remoteEntryExt - The file extension of the remoteEntry file
52
- * @param determineRemoteUrl - The function used to lookup the URL of the served remote
53
- */
54
- function mapRemotesForSSR(remotes, remoteEntryExt, determineRemoteUrl) {
55
- const mappedRemotes = {};
56
- for (const remote of remotes) {
57
- if (Array.isArray(remote)) {
58
- let [nxRemoteProjectName, remoteLocation] = remote;
59
- const mfRemoteName = (0, normalize_project_name_1.normalizeProjectName)(nxRemoteProjectName);
60
- const finalRemoteUrl = (0, url_helpers_1.processRemoteLocation)(remoteLocation, remoteEntryExt);
61
- // Promise-based remotes should not use the global prefix format
62
- if (remoteLocation.startsWith('promise new Promise')) {
63
- mappedRemotes[mfRemoteName] = finalRemoteUrl;
64
- }
65
- else {
66
- mappedRemotes[mfRemoteName] = `${mfRemoteName}@${finalRemoteUrl}`;
67
- }
68
- }
69
- else if (typeof remote === 'string') {
70
- const mfRemoteName = (0, normalize_project_name_1.normalizeProjectName)(remote);
71
- mappedRemotes[remote] = `${mfRemoteName}@${determineRemoteUrl(remote)}`;
72
- }
73
- }
74
- return mappedRemotes;
75
- }
@@ -1,3 +0,0 @@
1
- import type { Compiler } from '@rspack/core';
2
- export declare function getRspackMajorVersion(compiler: Compiler): number;
3
- export declare function isRspackV2(compiler: Compiler): boolean;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRspackMajorVersion = getRspackMajorVersion;
4
- exports.isRspackV2 = isRspackV2;
5
- // Read from compiler.rspack to avoid a value import of the (pure-ESM) v2 package.
6
- function getRspackMajorVersion(compiler) {
7
- return parseInt(compiler.rspack.rspackVersion ?? '1', 10);
8
- }
9
- function isRspackV2(compiler) {
10
- return getRspackMajorVersion(compiler) >= 2;
11
- }
@@ -1,12 +0,0 @@
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;
@@ -1,125 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collectWorkspaceLibrarySecondaryEntryPoints = collectWorkspaceLibrarySecondaryEntryPoints;
4
- exports.getNonNodeModulesSubDirs = getNonNodeModulesSubDirs;
5
- exports.recursivelyCollectSecondaryEntryPointsFromDirectory = recursivelyCollectSecondaryEntryPointsFromDirectory;
6
- exports.collectPackageSecondaryEntryPoints = collectPackageSecondaryEntryPoints;
7
- const path_1 = require("path");
8
- const fs_1 = require("fs");
9
- const devkit_1 = require("@nx/devkit");
10
- const internal_1 = require("@nx/devkit/internal");
11
- function collectWorkspaceLibrarySecondaryEntryPoints(library, tsconfigPathAliases) {
12
- const libraryRoot = (0, path_1.join)(devkit_1.workspaceRoot, library.root);
13
- const needsSecondaryEntryPointsCollected = (0, fs_1.existsSync)((0, path_1.join)(libraryRoot, 'ng-package.json'));
14
- const secondaryEntryPoints = [];
15
- if (needsSecondaryEntryPointsCollected) {
16
- const tsConfigAliasesForLibWithSecondaryEntryPoints = Object.entries(tsconfigPathAliases).reduce((acc, [tsKey, tsPaths]) => {
17
- if (!tsKey.startsWith(library.importKey)) {
18
- return { ...acc };
19
- }
20
- if (tsPaths.some((path) => path.startsWith(`${library.root}/`))) {
21
- acc = { ...acc, [tsKey]: tsPaths };
22
- }
23
- return acc;
24
- }, {});
25
- for (const [alias] of Object.entries(tsConfigAliasesForLibWithSecondaryEntryPoints)) {
26
- const pathToLib = (0, path_1.dirname)((0, path_1.join)(devkit_1.workspaceRoot, tsconfigPathAliases[alias][0]));
27
- let searchDir = pathToLib;
28
- while (searchDir !== libraryRoot) {
29
- if ((0, fs_1.existsSync)((0, path_1.join)(searchDir, 'ng-package.json'))) {
30
- secondaryEntryPoints.push({ name: alias, path: pathToLib });
31
- break;
32
- }
33
- searchDir = (0, path_1.dirname)(searchDir);
34
- }
35
- }
36
- }
37
- return secondaryEntryPoints;
38
- }
39
- function getNonNodeModulesSubDirs(directory) {
40
- return (0, fs_1.readdirSync)(directory)
41
- .filter((file) => file !== 'node_modules')
42
- .map((file) => (0, path_1.join)(directory, file))
43
- .filter((file) => (0, fs_1.lstatSync)(file).isDirectory());
44
- }
45
- function recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion, pkgRoot, mainEntryPointExports, directories, collectedPackages) {
46
- for (const directory of directories) {
47
- const packageJsonPath = (0, path_1.join)(directory, 'package.json');
48
- const relativeEntryPointPath = (0, path_1.relative)(pkgRoot, directory);
49
- const entryPointName = (0, devkit_1.joinPathFragments)(pkgName, relativeEntryPointPath);
50
- if ((0, fs_1.existsSync)(packageJsonPath)) {
51
- try {
52
- // require the secondary entry point to try to rule out sample code
53
- require.resolve(entryPointName, { paths: [devkit_1.workspaceRoot] });
54
- const { name } = (0, devkit_1.readJsonFile)(packageJsonPath);
55
- // further check to make sure what we were able to require is the
56
- // same as the package name
57
- if (name === entryPointName) {
58
- collectedPackages.push({ name, version: pkgVersion });
59
- }
60
- }
61
- catch { }
62
- }
63
- else if (mainEntryPointExports) {
64
- // if the package.json doesn't exist, check if the directory is
65
- // exported by the main entry point
66
- const entryPointExportKey = `./${relativeEntryPointPath}`;
67
- const entryPointInfo = mainEntryPointExports[entryPointExportKey];
68
- if (entryPointInfo) {
69
- collectedPackages.push({
70
- name: entryPointName,
71
- version: pkgVersion,
72
- });
73
- }
74
- }
75
- const subDirs = getNonNodeModulesSubDirs(directory);
76
- recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion, pkgRoot, mainEntryPointExports, subDirs, collectedPackages);
77
- }
78
- }
79
- function collectPackagesFromExports(pkgName, pkgVersion, exports, collectedPackages) {
80
- for (const [relativeEntryPoint, exportOptions] of Object.entries(exports)) {
81
- const defaultExportOptions = typeof exportOptions?.['default'] === 'string'
82
- ? exportOptions?.['default']
83
- : exportOptions?.['default']?.['default'];
84
- if (defaultExportOptions?.search(/\.(js|mjs|cjs)$/)) {
85
- let entryPointName = (0, devkit_1.joinPathFragments)(pkgName, relativeEntryPoint);
86
- if (entryPointName.endsWith('.json')) {
87
- entryPointName = (0, path_1.dirname)(entryPointName);
88
- }
89
- if (entryPointName === '.') {
90
- continue;
91
- }
92
- if (collectedPackages.find((p) => p.name === entryPointName)) {
93
- continue;
94
- }
95
- collectedPackages.push({ name: entryPointName, version: pkgVersion });
96
- }
97
- }
98
- }
99
- function collectPackageSecondaryEntryPoints(pkgName, pkgVersion, collectedPackages) {
100
- let pathToPackage;
101
- let packageJsonPath;
102
- let packageJson;
103
- try {
104
- ({ path: packageJsonPath, packageJson } = (0, internal_1.readModulePackageJson)(pkgName));
105
- pathToPackage = (0, path_1.dirname)(packageJsonPath);
106
- }
107
- catch {
108
- // the package.json might not resolve if the package has the "exports"
109
- // entry and is not exporting the package.json file, fall back to trying
110
- // to find it from the top-level node_modules
111
- pathToPackage = (0, path_1.join)(devkit_1.workspaceRoot, 'node_modules', pkgName);
112
- packageJsonPath = (0, path_1.join)(pathToPackage, 'package.json');
113
- if (!(0, fs_1.existsSync)(packageJsonPath)) {
114
- // might not exist if it's nested in another package, just return here
115
- return;
116
- }
117
- packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
118
- }
119
- const { exports } = packageJson;
120
- if (exports) {
121
- collectPackagesFromExports(pkgName, pkgVersion, exports, collectedPackages);
122
- }
123
- const subDirs = getNonNodeModulesSubDirs(pathToPackage);
124
- recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion, pathToPackage, exports, subDirs, collectedPackages);
125
- }
@@ -1,58 +0,0 @@
1
- import type { SharedLibraryConfig, SharedWorkspaceLibraryConfig, WorkspaceLibrary } from './models';
2
- import { AdditionalSharedConfig, SharedFunction } from './models';
3
- import { type ProjectGraph } from '@nx/devkit';
4
- /**
5
- * Build an object of functions to be used with the ModuleFederationPlugin to
6
- * share Nx Workspace Libraries between Hosts and Remotes.
7
- *
8
- * @param workspaceLibs - The Nx Workspace Libraries to share
9
- * @param tsConfigPath - The path to TS Config File that contains the Path Mappings for the Libraries
10
- * @param bundler - The bundler to use for the replacement plugin
11
- */
12
- export declare function shareWorkspaceLibraries(workspaceLibs: WorkspaceLibrary[], tsConfigPath?: string, bundler?: 'rspack' | 'webpack'): SharedWorkspaceLibraryConfig;
13
- /**
14
- * Build the Module Federation Share Config for a specific package and the
15
- * specified version of that package.
16
- * @param pkgName - Name of the package to share
17
- * @param version - Version of the package to require by other apps in the Module Federation setup
18
- */
19
- export declare function getNpmPackageSharedConfig(pkgName: string, version: string): SharedLibraryConfig | undefined;
20
- /**
21
- * Narrow a list of package names down to those with a version declared in the
22
- * root package.json.
23
- *
24
- * Version resolution matches {@link sharePackages}, so a package kept here never
25
- * trips the missing-version warning in {@link getNpmPackageSharedConfig}.
26
- * @param packages - Array of package names as strings
27
- */
28
- export declare function filterPackagesDeclaredInRootPackageJson(packages: string[]): string[];
29
- /**
30
- * Create a dictionary of packages and their Module Federation Shared Config
31
- * from an array of package names.
32
- *
33
- * Lookup the versions of the packages from the root package.json file in the
34
- * workspace.
35
- * @param packages - Array of package names as strings
36
- */
37
- export declare function sharePackages(packages: string[]): Record<string, SharedLibraryConfig>;
38
- /**
39
- * Apply a custom function provided by the user that will modify the Shared Config
40
- * of the dependencies for the Module Federation build.
41
- *
42
- * @param sharedConfig - The original Shared Config to be modified
43
- * @param sharedFn - The custom function to run
44
- */
45
- export declare function applySharedFunction(sharedConfig: Record<string, SharedLibraryConfig>, sharedFn: SharedFunction | undefined): void;
46
- /**
47
- * Add additional dependencies to the shared package that may not have been
48
- * discovered by the project graph.
49
- *
50
- * This can be useful for applications that use a Dependency Injection system
51
- * that expects certain Singleton values to be present in the shared injection
52
- * hierarchy.
53
- *
54
- * @param sharedConfig - The original Shared Config
55
- * @param additionalShared - The additional dependencies to add
56
- * @param projectGraph - The Nx project graph
57
- */
58
- export declare function applyAdditionalShared(sharedConfig: Record<string, SharedLibraryConfig>, additionalShared: AdditionalSharedConfig | undefined, projectGraph: ProjectGraph): void;