@nx/rspack 20.2.0-beta.2 → 20.2.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 (103) hide show
  1. package/app-plugin.d.ts +2 -0
  2. package/app-plugin.js +5 -0
  3. package/generators.json +10 -0
  4. package/migrations.json +21 -1
  5. package/module-federation.d.ts +4 -1
  6. package/module-federation.js +7 -2
  7. package/package.json +10 -8
  8. package/react-plugin.d.ts +1 -0
  9. package/react-plugin.js +5 -0
  10. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +5 -7
  11. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +5 -7
  12. package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +1 -1
  13. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +4 -5
  14. package/src/executors/rspack/schema.d.ts +1 -1
  15. package/src/executors/rspack/schema.json +1 -1
  16. package/src/generators/application/application.js +0 -2
  17. package/src/generators/configuration/configuration.js +0 -2
  18. package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.d.ts +7 -0
  19. package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.js +92 -0
  20. package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.d.ts +6 -0
  21. package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.js +106 -0
  22. package/src/generators/convert-config-to-rspack-plugin/lib/normalize-path-options.d.ts +2 -0
  23. package/src/generators/convert-config-to-rspack-plugin/lib/normalize-path-options.js +73 -0
  24. package/src/generators/convert-config-to-rspack-plugin/lib/utils.d.ts +1 -0
  25. package/src/generators/convert-config-to-rspack-plugin/lib/utils.js +13 -0
  26. package/src/generators/convert-config-to-rspack-plugin/lib/validate-project.d.ts +9 -0
  27. package/src/generators/convert-config-to-rspack-plugin/lib/validate-project.js +40 -0
  28. package/src/generators/convert-config-to-rspack-plugin/schema.json +19 -0
  29. package/src/generators/convert-to-inferred/__snapshots__/convert-to-inferred.spec.ts.snap +268 -0
  30. package/src/generators/convert-to-inferred/convert-to-inferred.d.ts +12 -0
  31. package/src/generators/convert-to-inferred/convert-to-inferred.js +114 -0
  32. package/src/generators/convert-to-inferred/schema.json +19 -0
  33. package/src/generators/convert-to-inferred/utils/ast.d.ts +3 -0
  34. package/src/generators/convert-to-inferred/utils/ast.js +40 -0
  35. package/src/generators/convert-to-inferred/utils/build-post-target-transformer.d.ts +6 -0
  36. package/src/generators/convert-to-inferred/utils/build-post-target-transformer.js +210 -0
  37. package/src/generators/convert-to-inferred/utils/index.d.ts +3 -0
  38. package/src/generators/convert-to-inferred/utils/index.js +6 -0
  39. package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.d.ts +6 -0
  40. package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.js +207 -0
  41. package/src/generators/convert-to-inferred/utils/types.d.ts +11 -0
  42. package/src/generators/convert-webpack/lib/transform-cjs.js +5 -5
  43. package/src/generators/convert-webpack/lib/transform-esm.js +5 -5
  44. package/src/generators/init/init.js +0 -2
  45. package/src/index.d.ts +1 -0
  46. package/src/index.js +1 -0
  47. package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts +2 -0
  48. package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +35 -0
  49. package/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.d.ts +16 -0
  50. package/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.js +43 -0
  51. package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.d.ts +8 -0
  52. package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.js +13 -0
  53. package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.d.ts +31 -0
  54. package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.js +73 -0
  55. package/src/plugins/utils/apply-base-config.js +3 -0
  56. package/src/plugins/utils/apply-web-config.d.ts +2 -2
  57. package/src/plugins/utils/apply-web-config.js +1 -1
  58. package/src/plugins/utils/plugins/normalize-options.js +1 -1
  59. package/src/plugins/utils/plugins/nx-tsconfig-paths-rspack-plugin.js +3 -2
  60. package/src/utils/create-compiler.js +3 -1
  61. package/src/utils/generator-utils.d.ts +2 -2
  62. package/src/utils/generator-utils.js +134 -67
  63. package/src/utils/has-plugin.d.ts +2 -0
  64. package/src/utils/has-plugin.js +10 -0
  65. package/src/utils/module-federation/build-static.remotes.d.ts +1 -1
  66. package/src/utils/versions.d.ts +2 -2
  67. package/src/utils/versions.js +2 -2
  68. package/src/utils/module-federation/dependencies.d.ts +0 -6
  69. package/src/utils/module-federation/dependencies.js +0 -56
  70. package/src/utils/module-federation/get-remotes-for-host.d.ts +0 -16
  71. package/src/utils/module-federation/get-remotes-for-host.js +0 -99
  72. package/src/utils/module-federation/index.d.ts +0 -6
  73. package/src/utils/module-federation/index.js +0 -9
  74. package/src/utils/module-federation/models/index.d.ts +0 -47
  75. package/src/utils/module-federation/package-json.d.ts +0 -8
  76. package/src/utils/module-federation/package-json.js +0 -12
  77. package/src/utils/module-federation/parse-static-remotes-config.d.ts +0 -13
  78. package/src/utils/module-federation/parse-static-remotes-config.js +0 -34
  79. package/src/utils/module-federation/plugins/runtime-library-control.plugin.d.ts +0 -3
  80. package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +0 -54
  81. package/src/utils/module-federation/public-api.d.ts +0 -8
  82. package/src/utils/module-federation/public-api.js +0 -20
  83. package/src/utils/module-federation/remotes.d.ts +0 -19
  84. package/src/utils/module-federation/remotes.js +0 -85
  85. package/src/utils/module-federation/secondary-entry-points.d.ts +0 -12
  86. package/src/utils/module-federation/secondary-entry-points.js +0 -104
  87. package/src/utils/module-federation/share.d.ts +0 -48
  88. package/src/utils/module-federation/share.js +0 -235
  89. package/src/utils/module-federation/start-remote-proxies.d.ts +0 -5
  90. package/src/utils/module-federation/start-remote-proxies.js +0 -45
  91. package/src/utils/module-federation/start-ssr-remote-proxies.d.ts +0 -5
  92. package/src/utils/module-federation/start-ssr-remote-proxies.js +0 -59
  93. package/src/utils/module-federation/typescript.d.ts +0 -4
  94. package/src/utils/module-federation/typescript.js +0 -53
  95. package/src/utils/module-federation/with-module-federation/package-json.d.ts +0 -8
  96. package/src/utils/module-federation/with-module-federation/package-json.js +0 -12
  97. package/src/utils/module-federation/with-module-federation/utils.d.ts +0 -12
  98. package/src/utils/module-federation/with-module-federation/utils.js +0 -76
  99. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.d.ts +0 -3
  100. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +0 -62
  101. package/src/utils/module-federation/with-module-federation/with-module-federation.d.ts +0 -8
  102. package/src/utils/module-federation/with-module-federation/with-module-federation.js +0 -70
  103. /package/src/{utils/module-federation/models/index.js → generators/convert-to-inferred/utils/types.js} +0 -0
@@ -1,235 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shareWorkspaceLibraries = shareWorkspaceLibraries;
4
- exports.getNpmPackageSharedConfig = getNpmPackageSharedConfig;
5
- exports.sharePackages = sharePackages;
6
- exports.applySharedFunction = applySharedFunction;
7
- exports.applyAdditionalShared = applyAdditionalShared;
8
- const devkit_1 = require("@nx/devkit");
9
- const core_1 = require("@rspack/core");
10
- const fs_1 = require("fs");
11
- const path_1 = require("path");
12
- const package_json_1 = require("./package-json");
13
- const secondary_entry_points_1 = require("./secondary-entry-points");
14
- const typescript_1 = require("./typescript");
15
- /**
16
- * Build an object of functions to be used with the ModuleFederationPlugin to
17
- * share Nx Workspace Libraries between Hosts and Remotes.
18
- *
19
- * @param workspaceLibs - The Nx Workspace Libraries to share
20
- * @param tsConfigPath - The path to TS Config File that contains the Path Mappings for the Libraries
21
- */
22
- function shareWorkspaceLibraries(workspaceLibs, tsConfigPath = process.env.NX_TSCONFIG_PATH ?? (0, typescript_1.getRootTsConfigPath)()) {
23
- if (!workspaceLibs) {
24
- return getEmptySharedLibrariesConfig();
25
- }
26
- const tsconfigPathAliases = (0, typescript_1.readTsPathMappings)(tsConfigPath);
27
- if (!Object.keys(tsconfigPathAliases).length) {
28
- return getEmptySharedLibrariesConfig();
29
- }
30
- // Nested projects must come first, sort them as such
31
- const sortedTsConfigPathAliases = {};
32
- Object.keys(tsconfigPathAliases)
33
- .sort((a, b) => {
34
- return b.split('/').length - a.split('/').length;
35
- })
36
- .forEach((key) => (sortedTsConfigPathAliases[key] = tsconfigPathAliases[key]));
37
- const pathMappings = [];
38
- for (const [key, paths] of Object.entries(sortedTsConfigPathAliases)) {
39
- const library = workspaceLibs.find((lib) => lib.importKey === key);
40
- if (!library) {
41
- continue;
42
- }
43
- // This is for Angular Projects that use ng-package.json
44
- // It will do nothing for React Projects
45
- (0, secondary_entry_points_1.collectWorkspaceLibrarySecondaryEntryPoints)(library, sortedTsConfigPathAliases).forEach(({ name, path }) => pathMappings.push({
46
- name,
47
- path,
48
- }));
49
- pathMappings.push({
50
- name: key,
51
- path: (0, path_1.normalize)((0, path_1.join)(devkit_1.workspaceRoot, paths[0])),
52
- });
53
- }
54
- return {
55
- getAliases: () => pathMappings.reduce((aliases, library) => ({
56
- ...aliases,
57
- // If the library path ends in a wildcard, remove it as rspack can't handle this in resolve.alias
58
- // e.g. path/to/my/lib/* -> path/to/my/lib
59
- [library.name]: library.path.replace(/\/\*$/, ''),
60
- }), {}),
61
- getLibraries: (projectRoot, eager) => {
62
- let pkgJson = null;
63
- if (projectRoot &&
64
- (0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot, 'package.json'))) {
65
- pkgJson = (0, devkit_1.readJsonFile)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot, 'package.json'));
66
- }
67
- return pathMappings.reduce((libraries, library) => {
68
- // Check to see if the library version is declared in the app's package.json
69
- let version = pkgJson?.dependencies?.[library.name];
70
- if (!version && workspaceLibs.length > 0) {
71
- const workspaceLib = workspaceLibs.find((lib) => lib.importKey === library.name);
72
- const libPackageJsonPath = workspaceLib
73
- ? (0, path_1.join)(workspaceLib.root, 'package.json')
74
- : null;
75
- if (libPackageJsonPath && (0, fs_1.existsSync)(libPackageJsonPath)) {
76
- pkgJson = (0, devkit_1.readJsonFile)(libPackageJsonPath);
77
- if (pkgJson) {
78
- version = pkgJson.version;
79
- }
80
- }
81
- }
82
- return {
83
- ...libraries,
84
- [library.name]: {
85
- ...(version
86
- ? {
87
- requiredVersion: version,
88
- singleton: true,
89
- }
90
- : { requiredVersion: false }),
91
- eager,
92
- },
93
- };
94
- }, {});
95
- },
96
- getReplacementPlugin: () => new core_1.NormalModuleReplacementPlugin(/./, (req) => {
97
- if (!req.request.startsWith('.')) {
98
- return;
99
- }
100
- const from = req.context;
101
- const to = (0, path_1.normalize)((0, path_1.join)(req.context, req.request));
102
- for (const library of pathMappings) {
103
- const libFolder = (0, path_1.normalize)((0, path_1.dirname)(library.path));
104
- if (!from.startsWith(libFolder) && to.startsWith(libFolder)) {
105
- const newReq = library.name.endsWith('/*')
106
- ? /**
107
- * req usually is in the form of "../../../path/to/file"
108
- * library.path is usually in the form of "/Users/username/path/to/Workspace/path/to/library"
109
- *
110
- * When a wildcard is used in the TS path mappings, we want to get everything after the import to
111
- * re-route the request correctly inline with the rspack resolve.alias
112
- */
113
- (0, path_1.join)(library.name, req.request.split(library.path.replace(devkit_1.workspaceRoot, '').replace('/*', ''))[1])
114
- : library.name;
115
- req.request = newReq;
116
- }
117
- }
118
- }),
119
- };
120
- }
121
- /**
122
- * Build the Module Federation Share Config for a specific package and the
123
- * specified version of that package.
124
- * @param pkgName - Name of the package to share
125
- * @param version - Version of the package to require by other apps in the Module Federation setup
126
- */
127
- function getNpmPackageSharedConfig(pkgName, version) {
128
- if (!version) {
129
- devkit_1.logger.warn(`Could not find a version for "${pkgName}" in the root "package.json" ` +
130
- 'when collecting shared packages for the Module Federation setup. ' +
131
- 'The package will not be shared.');
132
- return undefined;
133
- }
134
- return { singleton: true, strictVersion: true, requiredVersion: version };
135
- }
136
- /**
137
- * Create a dictionary of packages and their Module Federation Shared Config
138
- * from an array of package names.
139
- *
140
- * Lookup the versions of the packages from the root package.json file in the
141
- * workspace.
142
- * @param packages - Array of package names as strings
143
- */
144
- function sharePackages(packages) {
145
- const pkgJson = (0, package_json_1.readRootPackageJson)();
146
- const allPackages = [];
147
- packages.forEach((pkg) => {
148
- const pkgVersion = pkgJson.dependencies?.[pkg] ?? pkgJson.devDependencies?.[pkg];
149
- allPackages.push({ name: pkg, version: pkgVersion });
150
- (0, secondary_entry_points_1.collectPackageSecondaryEntryPoints)(pkg, pkgVersion, allPackages);
151
- });
152
- return allPackages.reduce((shared, pkg) => {
153
- const config = getNpmPackageSharedConfig(pkg.name, pkg.version);
154
- if (config) {
155
- shared[pkg.name] = config;
156
- }
157
- return shared;
158
- }, {});
159
- }
160
- /**
161
- * Apply a custom function provided by the user that will modify the Shared Config
162
- * of the dependencies for the Module Federation build.
163
- *
164
- * @param sharedConfig - The original Shared Config to be modified
165
- * @param sharedFn - The custom function to run
166
- */
167
- function applySharedFunction(sharedConfig, sharedFn) {
168
- if (!sharedFn) {
169
- return;
170
- }
171
- for (const [libraryName, library] of Object.entries(sharedConfig)) {
172
- const mappedDependency = sharedFn(libraryName, library);
173
- if (mappedDependency === false) {
174
- delete sharedConfig[libraryName];
175
- continue;
176
- }
177
- else if (!mappedDependency) {
178
- continue;
179
- }
180
- sharedConfig[libraryName] = mappedDependency;
181
- }
182
- }
183
- /**
184
- * Add additional dependencies to the shared package that may not have been
185
- * discovered by the project graph.
186
- *
187
- * This can be useful for applications that use a Dependency Injection system
188
- * that expects certain Singleton values to be present in the shared injection
189
- * hierarchy.
190
- *
191
- * @param sharedConfig - The original Shared Config
192
- * @param additionalShared - The additional dependencies to add
193
- * @param projectGraph - The Nx project graph
194
- */
195
- function applyAdditionalShared(sharedConfig, additionalShared, projectGraph) {
196
- if (!additionalShared) {
197
- return;
198
- }
199
- for (const shared of additionalShared) {
200
- if (typeof shared === 'string') {
201
- addStringDependencyToSharedConfig(sharedConfig, shared, projectGraph);
202
- }
203
- else if (Array.isArray(shared)) {
204
- sharedConfig[shared[0]] = shared[1];
205
- }
206
- else if (typeof shared === 'object') {
207
- sharedConfig[shared.libraryName] = shared.sharedConfig;
208
- }
209
- }
210
- }
211
- function addStringDependencyToSharedConfig(sharedConfig, dependency, projectGraph) {
212
- if (projectGraph.nodes[dependency]) {
213
- sharedConfig[dependency] = { requiredVersion: false };
214
- }
215
- else if (projectGraph.externalNodes?.[`npm:${dependency}`]) {
216
- const pkgJson = (0, package_json_1.readRootPackageJson)();
217
- const config = getNpmPackageSharedConfig(dependency, pkgJson.dependencies?.[dependency] ??
218
- pkgJson.devDependencies?.[dependency]);
219
- if (!config) {
220
- return;
221
- }
222
- sharedConfig[dependency] = config;
223
- }
224
- else {
225
- throw new Error(`The specified dependency "${dependency}" in the additionalShared configuration does not exist in the project graph. ` +
226
- `Please check your additionalShared configuration and make sure you are including valid workspace projects or npm packages.`);
227
- }
228
- }
229
- function getEmptySharedLibrariesConfig() {
230
- return {
231
- getAliases: () => ({}),
232
- getLibraries: () => ({}),
233
- getReplacementPlugin: () => new core_1.NormalModuleReplacementPlugin(/./, () => undefined),
234
- };
235
- }
@@ -1,5 +0,0 @@
1
- import { StaticRemotesConfig } from './parse-static-remotes-config';
2
- export declare function startRemoteProxies(staticRemotesConfig: StaticRemotesConfig, mappedLocationsOfRemotes: Record<string, string>, sslOptions?: {
3
- pathToCert: string;
4
- pathToKey: string;
5
- }): void;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startRemoteProxies = startRemoteProxies;
4
- const devkit_1 = require("@nx/devkit");
5
- const fs_1 = require("fs");
6
- function startRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes, sslOptions) {
7
- // eslint-disable-next-line @typescript-eslint/no-var-requires
8
- const { createProxyMiddleware } = require('http-proxy-middleware');
9
- // eslint-disable-next-line @typescript-eslint/no-var-requires
10
- const express = require('express');
11
- let sslCert;
12
- let sslKey;
13
- if (sslOptions && sslOptions.pathToCert && sslOptions.pathToKey) {
14
- if ((0, fs_1.existsSync)(sslOptions.pathToCert) && (0, fs_1.existsSync)(sslOptions.pathToKey)) {
15
- sslCert = (0, fs_1.readFileSync)(sslOptions.pathToCert);
16
- sslKey = (0, fs_1.readFileSync)(sslOptions.pathToKey);
17
- }
18
- else {
19
- devkit_1.logger.warn(`Encountered SSL options in project.json, however, the certificate files do not exist in the filesystem. Using http.`);
20
- devkit_1.logger.warn(`Attempted to find '${sslOptions.pathToCert}' and '${sslOptions.pathToKey}'.`);
21
- }
22
- }
23
- // eslint-disable-next-line @typescript-eslint/no-var-requires
24
- const http = require('http');
25
- // eslint-disable-next-line @typescript-eslint/no-var-requires
26
- const https = require('https');
27
- devkit_1.logger.info(`NX Starting static remotes proxies...`);
28
- for (const app of staticRemotesConfig.remotes) {
29
- const expressProxy = express();
30
- expressProxy.use(createProxyMiddleware({
31
- target: mappedLocationsOfRemotes[app],
32
- changeOrigin: true,
33
- secure: sslCert ? false : undefined,
34
- }));
35
- const proxyServer = (sslCert
36
- ? https.createServer({
37
- cert: sslCert,
38
- key: sslKey,
39
- }, expressProxy)
40
- : http.createServer(expressProxy)).listen(staticRemotesConfig.config[app].port);
41
- process.on('SIGTERM', () => proxyServer.close());
42
- process.on('exit', () => proxyServer.close());
43
- }
44
- devkit_1.logger.info(`NX Static remotes proxies started successfully`);
45
- }
@@ -1,5 +0,0 @@
1
- import type { StaticRemotesConfig } from './parse-static-remotes-config';
2
- export declare function startSsrRemoteProxies(staticRemotesConfig: StaticRemotesConfig, mappedLocationsOfRemotes: Record<string, string>, sslOptions?: {
3
- pathToCert: string;
4
- pathToKey: string;
5
- }): void;
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startSsrRemoteProxies = startSsrRemoteProxies;
4
- const devkit_1 = require("@nx/devkit");
5
- const fs_1 = require("fs");
6
- function startSsrRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes, sslOptions) {
7
- // eslint-disable-next-line @typescript-eslint/no-var-requires
8
- const { createProxyMiddleware } = require('http-proxy-middleware');
9
- // eslint-disable-next-line @typescript-eslint/no-var-requires
10
- const express = require('express');
11
- let sslCert;
12
- let sslKey;
13
- if (sslOptions && sslOptions.pathToCert && sslOptions.pathToKey) {
14
- if ((0, fs_1.existsSync)(sslOptions.pathToCert) && (0, fs_1.existsSync)(sslOptions.pathToKey)) {
15
- sslCert = (0, fs_1.readFileSync)(sslOptions.pathToCert);
16
- sslKey = (0, fs_1.readFileSync)(sslOptions.pathToKey);
17
- }
18
- else {
19
- devkit_1.logger.warn(`Encountered SSL options in project.json, however, the certificate files do not exist in the filesystem. Using http.`);
20
- devkit_1.logger.warn(`Attempted to find '${sslOptions.pathToCert}' and '${sslOptions.pathToKey}'.`);
21
- }
22
- }
23
- // eslint-disable-next-line @typescript-eslint/no-var-requires
24
- const http = require('http');
25
- // eslint-disable-next-line @typescript-eslint/no-var-requires
26
- const https = require('https');
27
- devkit_1.logger.info(`NX Starting static remotes proxies...`);
28
- for (const app of staticRemotesConfig.remotes) {
29
- const expressProxy = express();
30
- /**
31
- * SSR remotes have two output paths: one for the browser and one for the server.
32
- * We need to handle paths for both of them.
33
- * The browser output path is used to serve the client-side code.
34
- * The server output path is used to serve the server-side code.
35
- */
36
- expressProxy.use(createProxyMiddleware({
37
- target: `${mappedLocationsOfRemotes[app]}`,
38
- secure: sslCert ? false : undefined,
39
- changeOrigin: true,
40
- pathRewrite: (path) => {
41
- if (path.includes('/server')) {
42
- return path;
43
- }
44
- else {
45
- return `browser/${path}`;
46
- }
47
- },
48
- }));
49
- const proxyServer = (sslCert
50
- ? https.createServer({
51
- cert: sslCert,
52
- key: sslKey,
53
- }, expressProxy)
54
- : http.createServer(expressProxy)).listen(staticRemotesConfig.config[app].port);
55
- process.on('SIGTERM', () => proxyServer.close());
56
- process.on('exit', () => proxyServer.close());
57
- }
58
- devkit_1.logger.info(`Nx SSR Static remotes proxies started successfully`);
59
- }
@@ -1,4 +0,0 @@
1
- import { ParsedCommandLine } from 'typescript';
2
- export declare function readTsPathMappings(tsConfigPath?: string): ParsedCommandLine['options']['paths'];
3
- export declare function readTsConfig(tsConfigPath: string): ParsedCommandLine;
4
- export declare function getRootTsConfigPath(): string | null;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readTsPathMappings = readTsPathMappings;
4
- exports.readTsConfig = readTsConfig;
5
- exports.getRootTsConfigPath = getRootTsConfigPath;
6
- const fs_1 = require("fs");
7
- const path_1 = require("path");
8
- const devkit_1 = require("@nx/devkit");
9
- const tsConfig = new Map();
10
- const tsPathMappings = new Map();
11
- function readTsPathMappings(tsConfigPath = process.env.NX_TSCONFIG_PATH ?? getRootTsConfigPath()) {
12
- if (tsPathMappings.has(tsConfigPath)) {
13
- return tsPathMappings.get(tsConfigPath);
14
- }
15
- if (!tsConfig.has(tsConfigPath)) {
16
- tsConfig.set(tsConfigPath, readTsConfiguration(tsConfigPath));
17
- }
18
- tsPathMappings.set(tsConfigPath, {});
19
- Object.entries(tsConfig.get(tsConfigPath).options?.paths ?? {}).forEach(([alias, paths]) => {
20
- tsPathMappings.set(tsConfigPath, {
21
- ...tsPathMappings.get(tsConfigPath),
22
- [alias]: paths.map((path) => path.replace(/^\.\//, '')),
23
- });
24
- });
25
- return tsPathMappings.get(tsConfigPath);
26
- }
27
- function readTsConfiguration(tsConfigPath) {
28
- if (!(0, fs_1.existsSync)(tsConfigPath)) {
29
- throw new Error(`NX MF: TsConfig Path for workspace libraries does not exist! (${tsConfigPath}).`);
30
- }
31
- return readTsConfig(tsConfigPath);
32
- }
33
- let tsModule;
34
- function readTsConfig(tsConfigPath) {
35
- if (!tsModule) {
36
- tsModule = require('typescript');
37
- }
38
- const readResult = tsModule.readConfigFile(tsConfigPath, tsModule.sys.readFile);
39
- return tsModule.parseJsonConfigFileContent(readResult.config, tsModule.sys, (0, path_1.dirname)(tsConfigPath));
40
- }
41
- function getRootTsConfigPath() {
42
- const tsConfigFileName = getRootTsConfigFileName();
43
- return tsConfigFileName ? (0, path_1.join)(devkit_1.workspaceRoot, tsConfigFileName) : null;
44
- }
45
- function getRootTsConfigFileName() {
46
- for (const tsConfigName of ['tsconfig.base.json', 'tsconfig.json']) {
47
- const tsConfigPath = (0, path_1.join)(devkit_1.workspaceRoot, tsConfigName);
48
- if ((0, fs_1.existsSync)(tsConfigPath)) {
49
- return tsConfigName;
50
- }
51
- }
52
- return null;
53
- }
@@ -1,8 +0,0 @@
1
- export declare function readRootPackageJson(): {
2
- dependencies?: {
3
- [key: string]: string;
4
- };
5
- devDependencies?: {
6
- [key: string]: string;
7
- };
8
- };
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readRootPackageJson = readRootPackageJson;
4
- const devkit_1 = require("@nx/devkit");
5
- const fs_1 = require("fs");
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 MFE: Could not find root package.json to determine dependency versions.');
10
- }
11
- return (0, devkit_1.readJsonFile)(pkgJsonPath);
12
- }
@@ -1,12 +0,0 @@
1
- import { ModuleFederationConfig } from '../models';
2
- export declare function getFunctionDeterminateRemoteUrl(isServer?: boolean): (remote: string) => string;
3
- export declare function getModuleFederationConfig(mfConfig: ModuleFederationConfig, options?: {
4
- isServer: boolean;
5
- determineRemoteUrl?: (remote: string) => string;
6
- }): Promise<{
7
- sharedLibraries: import("../models").SharedWorkspaceLibraryConfig;
8
- sharedDependencies: {
9
- [x: string]: import("../models").SharedLibraryConfig;
10
- };
11
- mappedRemotes: {};
12
- }>;
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFunctionDeterminateRemoteUrl = getFunctionDeterminateRemoteUrl;
4
- exports.getModuleFederationConfig = getModuleFederationConfig;
5
- const devkit_1 = require("@nx/devkit");
6
- const project_graph_1 = require("nx/src/project-graph/project-graph");
7
- const dependencies_1 = require("../dependencies");
8
- const remotes_1 = require("../remotes");
9
- const share_1 = require("../share");
10
- function getFunctionDeterminateRemoteUrl(isServer = false) {
11
- const target = 'serve';
12
- const remoteEntry = isServer ? 'server/remoteEntry.js' : 'remoteEntry.js';
13
- return function (remote) {
14
- const mappedStaticRemotesFromEnv = process.env
15
- .NX_MF_DEV_SERVER_STATIC_REMOTES
16
- ? JSON.parse(process.env.NX_MF_DEV_SERVER_STATIC_REMOTES)
17
- : undefined;
18
- if (mappedStaticRemotesFromEnv && mappedStaticRemotesFromEnv[remote]) {
19
- return `${mappedStaticRemotesFromEnv[remote]}/${remoteEntry}`;
20
- }
21
- let remoteConfiguration = null;
22
- try {
23
- remoteConfiguration = (0, project_graph_1.readCachedProjectConfiguration)(remote);
24
- }
25
- catch (e) {
26
- throw new Error(`Cannot find remote: "${remote}". Check that the remote name is correct in your module federation config file.\n`);
27
- }
28
- const serveTarget = remoteConfiguration?.targets?.[target];
29
- if (!serveTarget) {
30
- throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "${serveTarget}" target.\n
31
- You can also use the tuple syntax in your rspack config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``);
32
- }
33
- const host = serveTarget.options?.host ??
34
- `http${serveTarget.options.ssl ? 's' : ''}://localhost`;
35
- const port = serveTarget.options?.port ?? 4201;
36
- return `${host.endsWith('/') ? host.slice(0, -1) : host}:${port}/${remoteEntry}`;
37
- };
38
- }
39
- async function getModuleFederationConfig(mfConfig, options = { isServer: false }) {
40
- let projectGraph;
41
- try {
42
- projectGraph = (0, devkit_1.readCachedProjectGraph)();
43
- }
44
- catch (e) {
45
- projectGraph = await (0, devkit_1.createProjectGraphAsync)();
46
- }
47
- const project = projectGraph.nodes[mfConfig.name]?.data;
48
- if (!project) {
49
- throw Error(`Cannot find project "${mfConfig.name}". Check that the name is correct in module-federation.config.js`);
50
- }
51
- const dependencies = (0, dependencies_1.getDependentPackagesForProject)(projectGraph, mfConfig.name);
52
- if (mfConfig.shared) {
53
- dependencies.workspaceLibraries = dependencies.workspaceLibraries.filter((lib) => mfConfig.shared(lib.importKey, {}) !== false);
54
- dependencies.npmPackages = dependencies.npmPackages.filter((pkg) => mfConfig.shared(pkg, {}) !== false);
55
- }
56
- const sharedLibraries = (0, share_1.shareWorkspaceLibraries)(dependencies.workspaceLibraries);
57
- const npmPackages = (0, share_1.sharePackages)(dependencies.npmPackages);
58
- const sharedDependencies = {
59
- ...sharedLibraries.getLibraries(project.root),
60
- ...npmPackages,
61
- };
62
- (0, share_1.applySharedFunction)(sharedDependencies, mfConfig.shared);
63
- (0, share_1.applyAdditionalShared)(sharedDependencies, mfConfig.additionalShared, projectGraph);
64
- // Choose the correct mapRemotes function based on the server state.
65
- const mapRemotesFunction = options.isServer ? remotes_1.mapRemotesForSSR : remotes_1.mapRemotes;
66
- // Determine the URL function, either from provided options or by using a default.
67
- const determineRemoteUrlFunction = options.determineRemoteUrl
68
- ? options.determineRemoteUrl
69
- : getFunctionDeterminateRemoteUrl(options.isServer);
70
- // Map the remotes if they exist, otherwise default to an empty object.
71
- let mappedRemotes = {};
72
- if (mfConfig.remotes && mfConfig.remotes.length > 0) {
73
- mappedRemotes = mapRemotesFunction(mfConfig.remotes, 'js', determineRemoteUrlFunction);
74
- }
75
- return { sharedLibraries, sharedDependencies, mappedRemotes };
76
- }
@@ -1,3 +0,0 @@
1
- import { ModuleFederationConfig, NxModuleFederationConfigOverride } from '../models';
2
- import { NxRspackExecutionContext } from '../../config';
3
- export declare function withModuleFederationForSSR(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: any, { context }: NxRspackExecutionContext) => any>;
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withModuleFederationForSSR = withModuleFederationForSSR;
4
- const core_1 = require("@rspack/core");
5
- const utils_1 = require("./utils");
6
- async function withModuleFederationForSSR(options, configOverride) {
7
- if (global.NX_GRAPH_CREATION) {
8
- return (config) => config;
9
- }
10
- const { sharedLibraries, sharedDependencies, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options, {
11
- isServer: true,
12
- });
13
- return (config, { context }) => {
14
- config.target = 'async-node';
15
- config.output.uniqueName = options.name;
16
- config.output.library = {
17
- type: 'commonjs-module',
18
- };
19
- config.optimization = {
20
- ...(config.optimization ?? {}),
21
- runtimeChunk: false,
22
- };
23
- config.plugins.push(
24
- // eslint-disable-next-line @typescript-eslint/no-var-requires
25
- new (require('@module-federation/enhanced/rspack').ModuleFederationPlugin)({
26
- name: options.name.replace(/-/g, '_'),
27
- filename: 'remoteEntry.js',
28
- exposes: options.exposes,
29
- remotes: mappedRemotes,
30
- shared: {
31
- ...sharedDependencies,
32
- },
33
- isServer: true,
34
- library: {
35
- type: 'commonjs-module',
36
- },
37
- remoteType: 'script',
38
- /**
39
- * Apply user-defined config overrides
40
- */
41
- ...(configOverride ? configOverride : {}),
42
- runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
43
- !options.disableNxRuntimeLibraryControlPlugin
44
- ? [
45
- ...(configOverride?.runtimePlugins ?? []),
46
- require.resolve('@module-federation/node/runtimePlugin'),
47
- require.resolve('@nx/rspack/src/utils/module-federation/plugins/runtime-library-control.plugin.js'),
48
- ]
49
- : [
50
- ...(configOverride?.runtimePlugins ?? []),
51
- require.resolve('@module-federation/node/runtimePlugin'),
52
- ],
53
- virtualRuntimeEntry: true,
54
- }, {}), sharedLibraries.getReplacementPlugin());
55
- // The env var is only set from the module-federation-dev-server
56
- // Attach the runtime plugin
57
- config.plugins.push(new core_1.DefinePlugin({
58
- 'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
59
- }));
60
- return config;
61
- };
62
- }
@@ -1,8 +0,0 @@
1
- import type { Configuration } from '@rspack/core';
2
- import { ModuleFederationConfig, NxModuleFederationConfigOverride } from '../models';
3
- import { NxRspackExecutionContext } from '../../config';
4
- /**
5
- * @param {ModuleFederationConfig} options
6
- * @param {NxModuleFederationConfigOverride} configOverride
7
- */
8
- export declare function withModuleFederation(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: Configuration, { context }: NxRspackExecutionContext) => Configuration>;