@nx/rspack 19.7.1 → 20.0.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 (122) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +70 -34
  3. package/executors.json +2 -2
  4. package/module-federation.js +0 -1
  5. package/package.json +14 -9
  6. package/plugin.js +0 -1
  7. package/src/executors/dev-server/dev-server.impl.js +39 -38
  8. package/src/executors/dev-server/lib/get-dev-server-config.js +1 -3
  9. package/src/executors/dev-server/lib/serve-path.js +0 -1
  10. package/src/executors/dev-server/schema.json +3 -9
  11. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +109 -98
  12. package/src/executors/module-federation-dev-server/schema.json +1 -3
  13. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +153 -148
  14. package/src/executors/module-federation-ssr-dev-server/schema.json +1 -4
  15. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +117 -125
  16. package/src/executors/rspack/rspack.impl.js +60 -67
  17. package/src/executors/rspack/schema.json +6 -26
  18. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js +0 -1
  19. package/src/executors/ssr-dev-server/schema.json +1 -4
  20. package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +26 -40
  21. package/src/generators/application/application.js +79 -76
  22. package/src/generators/application/lib/create-ts-config.js +5 -3
  23. package/src/generators/application/lib/normalize-options.js +12 -7
  24. package/src/generators/application/schema.json +1 -0
  25. package/src/generators/configuration/configuration.js +63 -65
  26. package/src/generators/configuration/schema.json +2 -1
  27. package/src/generators/init/init.js +58 -59
  28. package/src/generators/init/schema.json +2 -1
  29. package/src/generators/preset/preset.js +26 -29
  30. package/src/generators/preset/schema.json +1 -0
  31. package/src/index.js +0 -1
  32. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -7
  33. package/src/plugins/generate-package-json-plugin.js +1 -3
  34. package/src/plugins/plugin.js +81 -90
  35. package/src/utils/config.js +7 -11
  36. package/src/utils/create-compiler.js +21 -25
  37. package/src/utils/generator-utils.js +55 -66
  38. package/src/utils/get-copy-patterns.js +1 -3
  39. package/src/utils/jest-utils.js +0 -1
  40. package/src/utils/mode-utils.js +0 -1
  41. package/src/utils/model.js +0 -1
  42. package/src/utils/module-federation/build-static.remotes.js +57 -61
  43. package/src/utils/module-federation/dependencies.js +1 -3
  44. package/src/utils/module-federation/get-remotes-for-host.js +4 -8
  45. package/src/utils/module-federation/index.js +0 -1
  46. package/src/utils/module-federation/models/index.js +0 -1
  47. package/src/utils/module-federation/package-json.js +0 -1
  48. package/src/utils/module-federation/parse-static-remotes-config.js +2 -3
  49. package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +1 -2
  50. package/src/utils/module-federation/public-api.js +0 -1
  51. package/src/utils/module-federation/remotes.js +0 -1
  52. package/src/utils/module-federation/secondary-entry-points.js +4 -5
  53. package/src/utils/module-federation/share.js +22 -19
  54. package/src/utils/module-federation/start-remote-proxies.js +0 -1
  55. package/src/utils/module-federation/start-ssr-remote-proxies.js +0 -1
  56. package/src/utils/module-federation/typescript.js +6 -6
  57. package/src/utils/module-federation/with-module-federation/package-json.js +0 -1
  58. package/src/utils/module-federation/with-module-federation/utils.js +41 -43
  59. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +48 -35
  60. package/src/utils/module-federation/with-module-federation/with-module-federation.js +56 -38
  61. package/src/utils/normalize-assets.js +5 -3
  62. package/src/utils/read-rspack-options.js +23 -27
  63. package/src/utils/resolve-user-defined-rspack-config.js +0 -1
  64. package/src/utils/versions.d.ts +2 -2
  65. package/src/utils/versions.js +2 -3
  66. package/src/utils/with-nx.js +30 -13
  67. package/src/utils/with-react.js +11 -5
  68. package/src/utils/with-web.js +20 -11
  69. package/module-federation.js.map +0 -1
  70. package/plugin.js.map +0 -1
  71. package/src/executors/dev-server/dev-server.impl.js.map +0 -1
  72. package/src/executors/dev-server/lib/get-dev-server-config.js.map +0 -1
  73. package/src/executors/dev-server/lib/serve-path.js.map +0 -1
  74. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js.map +0 -1
  75. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js.map +0 -1
  76. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js.map +0 -1
  77. package/src/executors/rspack/rspack.impl.js.map +0 -1
  78. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js.map +0 -1
  79. package/src/executors/ssr-dev-server/ssr-dev-server.impl.js.map +0 -1
  80. package/src/generators/application/application.js.map +0 -1
  81. package/src/generators/application/lib/create-ts-config.js.map +0 -1
  82. package/src/generators/application/lib/normalize-options.js.map +0 -1
  83. package/src/generators/configuration/configuration.js.map +0 -1
  84. package/src/generators/init/init.js.map +0 -1
  85. package/src/generators/preset/preset.js.map +0 -1
  86. package/src/index.js.map +0 -1
  87. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js.map +0 -1
  88. package/src/plugins/generate-package-json-plugin.js.map +0 -1
  89. package/src/plugins/plugin.js.map +0 -1
  90. package/src/utils/config.js.map +0 -1
  91. package/src/utils/create-compiler.js.map +0 -1
  92. package/src/utils/generator-utils.js.map +0 -1
  93. package/src/utils/get-copy-patterns.js.map +0 -1
  94. package/src/utils/jest-utils.js.map +0 -1
  95. package/src/utils/mode-utils.js.map +0 -1
  96. package/src/utils/model.js.map +0 -1
  97. package/src/utils/module-federation/build-static.remotes.js.map +0 -1
  98. package/src/utils/module-federation/dependencies.js.map +0 -1
  99. package/src/utils/module-federation/get-remotes-for-host.js.map +0 -1
  100. package/src/utils/module-federation/index.js.map +0 -1
  101. package/src/utils/module-federation/models/index.js.map +0 -1
  102. package/src/utils/module-federation/package-json.js.map +0 -1
  103. package/src/utils/module-federation/parse-static-remotes-config.js.map +0 -1
  104. package/src/utils/module-federation/plugins/runtime-library-control.plugin.js.map +0 -1
  105. package/src/utils/module-federation/public-api.js.map +0 -1
  106. package/src/utils/module-federation/remotes.js.map +0 -1
  107. package/src/utils/module-federation/secondary-entry-points.js.map +0 -1
  108. package/src/utils/module-federation/share.js.map +0 -1
  109. package/src/utils/module-federation/start-remote-proxies.js.map +0 -1
  110. package/src/utils/module-federation/start-ssr-remote-proxies.js.map +0 -1
  111. package/src/utils/module-federation/typescript.js.map +0 -1
  112. package/src/utils/module-federation/with-module-federation/package-json.js.map +0 -1
  113. package/src/utils/module-federation/with-module-federation/utils.js.map +0 -1
  114. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js.map +0 -1
  115. package/src/utils/module-federation/with-module-federation/with-module-federation.js.map +0 -1
  116. package/src/utils/normalize-assets.js.map +0 -1
  117. package/src/utils/read-rspack-options.js.map +0 -1
  118. package/src/utils/resolve-user-defined-rspack-config.js.map +0 -1
  119. package/src/utils/versions.js.map +0 -1
  120. package/src/utils/with-nx.js.map +0 -1
  121. package/src/utils/with-react.js.map +0 -1
  122. package/src/utils/with-web.js.map +0 -1
@@ -15,13 +15,19 @@ const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
15
15
  const cache_directory_1 = require("nx/src/utils/cache-directory");
16
16
  const start_ssr_remote_proxies_1 = require("../../utils/module-federation/start-ssr-remote-proxies");
17
17
  function normalizeOptions(options) {
18
- var _a;
19
- return Object.assign(Object.assign({}, options), { ssl: (_a = options.ssl) !== null && _a !== void 0 ? _a : false, sslCert: options.sslCert ? (0, path_1.join)(devkit_1.workspaceRoot, options.sslCert) : undefined, sslKey: options.sslKey ? (0, path_1.join)(devkit_1.workspaceRoot, options.sslKey) : undefined });
18
+ return {
19
+ ...options,
20
+ ssl: options.ssl ?? false,
21
+ sslCert: options.sslCert ? (0, path_1.join)(devkit_1.workspaceRoot, options.sslCert) : undefined,
22
+ sslKey: options.sslKey ? (0, path_1.join)(devkit_1.workspaceRoot, options.sslKey) : undefined,
23
+ };
20
24
  }
21
25
  function getBuildOptions(buildTarget, context) {
22
26
  const target = (0, devkit_1.parseTargetString)(buildTarget, context);
23
27
  const buildOptions = (0, devkit_1.readTargetOptions)(target, context);
24
- return Object.assign({}, buildOptions);
28
+ return {
29
+ ...buildOptions,
30
+ };
25
31
  }
26
32
  function startSsrStaticRemotesFileServer(ssrStaticRemotesConfig, context, options) {
27
33
  if (ssrStaticRemotesConfig.remotes.length === 0) {
@@ -52,158 +58,157 @@ function startSsrStaticRemotesFileServer(ssrStaticRemotesConfig, context, option
52
58
  }, context);
53
59
  return staticRemotesIter;
54
60
  }
55
- function startRemotes(remotes, context, options) {
56
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
57
- var _a, _b;
58
- const remoteIters = [];
59
- const target = 'serve';
60
- for (const app of remotes) {
61
- const remoteProjectServeTarget = context.projectGraph.nodes[app].data.targets[target];
62
- const isUsingModuleFederationSsrDevServerExecutor = remoteProjectServeTarget.executor.includes('module-federation-ssr-dev-server');
63
- const configurationOverride = (_b = (_a = options.devRemotes) === null || _a === void 0 ? void 0 : _a.find((remote) => typeof remote !== 'string' && remote.remoteName === app)) === null || _b === void 0 ? void 0 : _b.configuration;
64
- {
65
- const defaultOverrides = Object.assign(Object.assign(Object.assign(Object.assign({}, (options.host ? { host: options.host } : {})), (options.ssl ? { ssl: options.ssl } : {})), (options.sslCert ? { sslCert: options.sslCert } : {})), (options.sslKey ? { sslKey: options.sslKey } : {}));
66
- const overrides = Object.assign(Object.assign({ watch: true }, defaultOverrides), (isUsingModuleFederationSsrDevServerExecutor
61
+ async function startRemotes(remotes, context, options) {
62
+ const remoteIters = [];
63
+ const target = 'serve';
64
+ for (const app of remotes) {
65
+ const remoteProjectServeTarget = context.projectGraph.nodes[app].data.targets[target];
66
+ const isUsingModuleFederationSsrDevServerExecutor = remoteProjectServeTarget.executor.includes('module-federation-ssr-dev-server');
67
+ const configurationOverride = options.devRemotes?.find((remote) => typeof remote !== 'string' && remote.remoteName === app)?.configuration;
68
+ {
69
+ const defaultOverrides = {
70
+ ...(options.host ? { host: options.host } : {}),
71
+ ...(options.ssl ? { ssl: options.ssl } : {}),
72
+ ...(options.sslCert ? { sslCert: options.sslCert } : {}),
73
+ ...(options.sslKey ? { sslKey: options.sslKey } : {}),
74
+ };
75
+ const overrides = {
76
+ watch: true,
77
+ ...defaultOverrides,
78
+ ...(isUsingModuleFederationSsrDevServerExecutor
67
79
  ? { isInitialHost: false }
68
- : {}));
69
- remoteIters.push(yield (0, devkit_1.runExecutor)({
70
- project: app,
71
- target,
72
- configuration: configurationOverride !== null && configurationOverride !== void 0 ? configurationOverride : context.configurationName,
73
- }, overrides, context));
74
- }
80
+ : {}),
81
+ };
82
+ remoteIters.push(await (0, devkit_1.runExecutor)({
83
+ project: app,
84
+ target,
85
+ configuration: configurationOverride ?? context.configurationName,
86
+ }, overrides, context));
75
87
  }
76
- return remoteIters;
77
- });
88
+ }
89
+ return remoteIters;
78
90
  }
79
- function buildSsrStaticRemotes(staticRemotesConfig, nxBin, context, options) {
80
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
81
- if (!staticRemotesConfig.remotes.length) {
82
- return;
83
- }
84
- devkit_1.logger.info(`Nx is building ${staticRemotesConfig.remotes.length} static remotes...`);
85
- const mapLocationOfRemotes = {};
86
- for (const remoteApp of staticRemotesConfig.remotes) {
87
- mapLocationOfRemotes[remoteApp] = `http${options.ssl ? 's' : ''}://${options.host}:${options.staticRemotesPort}/${staticRemotesConfig.config[remoteApp].urlSegment}`;
88
- }
89
- yield new Promise((resolve) => {
90
- const childProcess = (0, child_process_1.fork)(nxBin, [
91
- 'run-many',
92
- '--target=server',
93
- '--projects',
94
- staticRemotesConfig.remotes.join(','),
95
- ...(context.configurationName
96
- ? [`--configuration=${context.configurationName}`]
97
- : []),
98
- ...(options.parallel ? [`--parallel=${options.parallel}`] : []),
99
- ], {
100
- cwd: context.root,
101
- stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
102
- });
103
- // Add a listener to the child process to capture the build log
104
- const remoteBuildLogFile = (0, path_1.join)(cache_directory_1.workspaceDataDirectory,
105
- // eslint-disable-next-line
106
- `${new Date().toISOString().replace(/[:\.]/g, '_')}-build.log`);
107
- const remoteBuildLogStream = (0, fs_1.createWriteStream)(remoteBuildLogFile);
108
- childProcess.stdout.on('data', (data) => {
109
- const ANSII_CODE_REGEX =
110
- // eslint-disable-next-line no-control-regex
111
- /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
112
- const stdoutString = data.toString().replace(ANSII_CODE_REGEX, '');
113
- remoteBuildLogStream.write(stdoutString);
114
- // in addition to writing into the stdout stream, also show error directly in console
115
- // so the error is easily discoverable. 'ERROR in' is the key word to search in webpack output.
116
- if (stdoutString.includes('ERROR in')) {
117
- devkit_1.logger.log(stdoutString);
118
- }
119
- if (stdoutString.includes('Successfully ran target server')) {
120
- childProcess.stdout.removeAllListeners('data');
121
- devkit_1.logger.info(`Nx Built ${staticRemotesConfig.remotes.length} static remotes.`);
122
- resolve();
123
- }
124
- });
125
- process.on('SIGTERM', () => childProcess.kill('SIGTERM'));
126
- process.on('exit', () => childProcess.kill('SIGTERM'));
91
+ async function buildSsrStaticRemotes(staticRemotesConfig, nxBin, context, options) {
92
+ if (!staticRemotesConfig.remotes.length) {
93
+ return;
94
+ }
95
+ devkit_1.logger.info(`Nx is building ${staticRemotesConfig.remotes.length} static remotes...`);
96
+ const mapLocationOfRemotes = {};
97
+ for (const remoteApp of staticRemotesConfig.remotes) {
98
+ mapLocationOfRemotes[remoteApp] = `http${options.ssl ? 's' : ''}://${options.host}:${options.staticRemotesPort}/${staticRemotesConfig.config[remoteApp].urlSegment}`;
99
+ }
100
+ await new Promise((resolve) => {
101
+ const childProcess = (0, child_process_1.fork)(nxBin, [
102
+ 'run-many',
103
+ '--target=server',
104
+ '--projects',
105
+ staticRemotesConfig.remotes.join(','),
106
+ ...(context.configurationName
107
+ ? [`--configuration=${context.configurationName}`]
108
+ : []),
109
+ ...(options.parallel ? [`--parallel=${options.parallel}`] : []),
110
+ ], {
111
+ cwd: context.root,
112
+ stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
127
113
  });
128
- return mapLocationOfRemotes;
129
- });
130
- }
131
- function moduleFederationSsrDevServer(ssrDevServerOptions, context) {
132
- return tslib_1.__asyncGenerator(this, arguments, function* moduleFederationSsrDevServer_1() {
133
- var _a, _b, _c;
134
- const options = normalizeOptions(ssrDevServerOptions);
135
- // Force Node to resolve to look for the nx binary that is inside node_modules
136
- const nxBin = require.resolve('nx/bin/nx');
137
- const iter = (0, ssr_dev_server_impl_1.default)(options, context);
138
- const projectConfig = context.projectsConfigurations.projects[context.projectName];
139
- const buildOptions = getBuildOptions(options.browserTarget, context);
140
- let pathToManifestFile = (0, path_1.join)(context.root, projectConfig.sourceRoot, 'assets/module-federation.manifest.json');
141
- if (options.pathToManifestFile) {
142
- const userPathToManifestFile = (0, path_1.join)(context.root, options.pathToManifestFile);
143
- if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
144
- throw new Error(`The provided Module Federation manifest file path does not exist. Please check the file exists at "${userPathToManifestFile}".`);
114
+ // Add a listener to the child process to capture the build log
115
+ const remoteBuildLogFile = (0, path_1.join)(cache_directory_1.workspaceDataDirectory,
116
+ // eslint-disable-next-line
117
+ `${new Date().toISOString().replace(/[:\.]/g, '_')}-build.log`);
118
+ const remoteBuildLogStream = (0, fs_1.createWriteStream)(remoteBuildLogFile);
119
+ childProcess.stdout.on('data', (data) => {
120
+ const ANSII_CODE_REGEX =
121
+ // eslint-disable-next-line no-control-regex
122
+ /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
123
+ const stdoutString = data.toString().replace(ANSII_CODE_REGEX, '');
124
+ remoteBuildLogStream.write(stdoutString);
125
+ // in addition to writing into the stdout stream, also show error directly in console
126
+ // so the error is easily discoverable. 'ERROR in' is the key word to search in webpack output.
127
+ if (stdoutString.includes('ERROR in')) {
128
+ devkit_1.logger.log(stdoutString);
145
129
  }
146
- else if ((0, path_1.extname)(userPathToManifestFile) !== '.json') {
147
- throw new Error(`The Module Federation manifest file must be a JSON. Please ensure the file at ${userPathToManifestFile} is a JSON.`);
130
+ if (stdoutString.includes('Successfully ran target server')) {
131
+ childProcess.stdout.removeAllListeners('data');
132
+ devkit_1.logger.info(`Nx Built ${staticRemotesConfig.remotes.length} static remotes.`);
133
+ resolve();
148
134
  }
149
- pathToManifestFile = userPathToManifestFile;
135
+ });
136
+ process.on('SIGTERM', () => childProcess.kill('SIGTERM'));
137
+ process.on('exit', () => childProcess.kill('SIGTERM'));
138
+ });
139
+ return mapLocationOfRemotes;
140
+ }
141
+ async function* moduleFederationSsrDevServer(ssrDevServerOptions, context) {
142
+ const options = normalizeOptions(ssrDevServerOptions);
143
+ // Force Node to resolve to look for the nx binary that is inside node_modules
144
+ const nxBin = require.resolve('nx/bin/nx');
145
+ const iter = (0, ssr_dev_server_impl_1.default)(options, context);
146
+ const projectConfig = context.projectsConfigurations.projects[context.projectName];
147
+ const buildOptions = getBuildOptions(options.browserTarget, context);
148
+ let pathToManifestFile = (0, path_1.join)(context.root, projectConfig.sourceRoot, 'assets/module-federation.manifest.json');
149
+ if (options.pathToManifestFile) {
150
+ const userPathToManifestFile = (0, path_1.join)(context.root, options.pathToManifestFile);
151
+ if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
152
+ throw new Error(`The provided Module Federation manifest file path does not exist. Please check the file exists at "${userPathToManifestFile}".`);
150
153
  }
154
+ else if ((0, path_1.extname)(userPathToManifestFile) !== '.json') {
155
+ throw new Error(`The Module Federation manifest file must be a JSON. Please ensure the file at ${userPathToManifestFile} is a JSON.`);
156
+ }
157
+ pathToManifestFile = userPathToManifestFile;
158
+ }
159
+ if (!options.isInitialHost) {
160
+ return yield* iter;
161
+ }
162
+ const moduleFederationConfig = (0, module_federation_1.getModuleFederationConfig)(buildOptions.tsConfig, context.root, projectConfig.root, 'react');
163
+ const remoteNames = options.devRemotes?.map((remote) => typeof remote === 'string' ? remote : remote.remoteName);
164
+ const remotes = (0, module_federation_1.getRemotes)(remoteNames, options.skipRemotes, moduleFederationConfig, {
165
+ projectName: context.projectName,
166
+ projectGraph: context.projectGraph,
167
+ root: context.root,
168
+ }, pathToManifestFile);
169
+ options.staticRemotesPort ??= remotes.staticRemotePort;
170
+ process.env.NX_MF_DEV_REMOTES = JSON.stringify([
171
+ ...(remotes.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName) ?? []),
172
+ projectConfig.name,
173
+ ]);
174
+ const staticRemotesConfig = (0, parse_static_remotes_config_1.parseStaticSsrRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
175
+ const mappedLocationsOfStaticRemotes = await buildSsrStaticRemotes(staticRemotesConfig, nxBin, context, options);
176
+ const devRemoteIters = await startRemotes(remotes.devRemotes, context, options);
177
+ const staticRemotesIter = startSsrStaticRemotesFileServer(staticRemotesConfig, context, options);
178
+ (0, start_ssr_remote_proxies_1.startSsrRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
179
+ ? {
180
+ pathToCert: options.sslCert,
181
+ pathToKey: options.sslKey,
182
+ }
183
+ : undefined);
184
+ return yield* (0, async_iterable_1.combineAsyncIterables)(iter, ...devRemoteIters, ...(staticRemotesIter ? [staticRemotesIter] : []), (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
151
185
  if (!options.isInitialHost) {
152
- return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(iter))));
186
+ done();
187
+ return;
153
188
  }
154
- const moduleFederationConfig = (0, module_federation_1.getModuleFederationConfig)(buildOptions.tsConfig, context.root, projectConfig.root, 'react');
155
- const remoteNames = (_a = options.devRemotes) === null || _a === void 0 ? void 0 : _a.map((remote) => typeof remote === 'string' ? remote : remote.remoteName);
156
- const remotes = (0, module_federation_1.getRemotes)(remoteNames, options.skipRemotes, moduleFederationConfig, {
157
- projectName: context.projectName,
158
- projectGraph: context.projectGraph,
159
- root: context.root,
160
- }, pathToManifestFile);
161
- (_b = options.staticRemotesPort) !== null && _b !== void 0 ? _b : (options.staticRemotesPort = remotes.staticRemotePort);
162
- process.env.NX_MF_DEV_REMOTES = JSON.stringify([
163
- ...((_c = remotes.devRemotes.map((r) => typeof r === 'string' ? r : r.remoteName)) !== null && _c !== void 0 ? _c : []),
164
- projectConfig.name,
165
- ]);
166
- const staticRemotesConfig = (0, parse_static_remotes_config_1.parseStaticSsrRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
167
- const mappedLocationsOfStaticRemotes = yield tslib_1.__await(buildSsrStaticRemotes(staticRemotesConfig, nxBin, context, options));
168
- const devRemoteIters = yield tslib_1.__await(startRemotes(remotes.devRemotes, context, options));
169
- const staticRemotesIter = startSsrStaticRemotesFileServer(staticRemotesConfig, context, options);
170
- (0, start_ssr_remote_proxies_1.startSsrRemoteProxies)(staticRemotesConfig, mappedLocationsOfStaticRemotes, options.ssl
171
- ? {
172
- pathToCert: options.sslCert,
173
- pathToKey: options.sslKey,
174
- }
175
- : undefined);
176
- return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, async_iterable_1.combineAsyncIterables)(iter, ...devRemoteIters, ...(staticRemotesIter ? [staticRemotesIter] : []), (0, async_iterable_1.createAsyncIterable)((_a) => tslib_1.__awaiter(this, [_a], void 0, function* ({ next, done }) {
177
- var _b;
178
- if (!options.isInitialHost) {
179
- done();
180
- return;
181
- }
182
- if (remotes.remotePorts.length === 0) {
183
- done();
184
- return;
185
- }
186
- try {
187
- const host = (_b = options.host) !== null && _b !== void 0 ? _b : 'localhost';
188
- const baseUrl = `http${options.ssl ? 's' : ''}://${host}:${options.port}`;
189
- const portsToWaitFor = staticRemotesIter
190
- ? [options.staticRemotesPort, ...remotes.remotePorts]
191
- : [...remotes.remotePorts];
192
- yield Promise.all(portsToWaitFor.map((port) => (0, wait_for_port_open_1.waitForPortOpen)(port, {
193
- retries: 480,
194
- retryDelay: 2500,
195
- host,
196
- })));
197
- devkit_1.logger.info(`Nx all ssr remotes have started, server ready at ${baseUrl}`);
198
- next({ success: true, baseUrl });
199
- }
200
- catch (error) {
201
- throw new Error(`Nx failed to start ssr remotes. Check above for errors.`);
202
- }
203
- finally {
204
- done();
205
- }
206
- })))))));
207
- });
189
+ if (remotes.remotePorts.length === 0) {
190
+ done();
191
+ return;
192
+ }
193
+ try {
194
+ const host = options.host ?? 'localhost';
195
+ const baseUrl = `http${options.ssl ? 's' : ''}://${host}:${options.port}`;
196
+ const portsToWaitFor = staticRemotesIter
197
+ ? [options.staticRemotesPort, ...remotes.remotePorts]
198
+ : [...remotes.remotePorts];
199
+ await Promise.all(portsToWaitFor.map((port) => (0, wait_for_port_open_1.waitForPortOpen)(port, {
200
+ retries: 480,
201
+ retryDelay: 2500,
202
+ host,
203
+ })));
204
+ devkit_1.logger.info(`Nx all ssr remotes have started, server ready at ${baseUrl}`);
205
+ next({ success: true, baseUrl });
206
+ }
207
+ catch (error) {
208
+ throw new Error(`Nx failed to start ssr remotes. Check above for errors.`);
209
+ }
210
+ finally {
211
+ done();
212
+ }
213
+ }));
208
214
  }
209
- //# sourceMappingURL=module-federation-ssr-dev-server.impl.js.map
@@ -75,8 +75,5 @@
75
75
  "x-priority": "internal"
76
76
  }
77
77
  },
78
- "required": [
79
- "browserTarget",
80
- "serverTarget"
81
- ]
78
+ "required": ["browserTarget", "serverTarget"]
82
79
  }
@@ -36,50 +36,48 @@ function getBuildAndServeOptionsFromServeTarget(serveTarget, context) {
36
36
  pathToManifestFile,
37
37
  };
38
38
  }
39
- function buildHost(nxBin, buildTarget, context) {
40
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
41
- yield new Promise((res, rej) => {
42
- const staticProcess = (0, child_process_1.fork)(nxBin, [
43
- `run`,
44
- `${buildTarget.project}:${buildTarget.target}${buildTarget.configuration
45
- ? `:${buildTarget.configuration}`
46
- : context.configurationName
47
- ? `:${context.configurationName}`
48
- : ''}`,
49
- ], {
50
- cwd: context.root,
51
- stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
52
- });
53
- staticProcess.stdout.on('data', (data) => {
54
- const ANSII_CODE_REGEX =
55
- // eslint-disable-next-line no-control-regex
56
- /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
57
- const stdoutString = data.toString().replace(ANSII_CODE_REGEX, '');
58
- // in addition to writing into the stdout stream, also show error directly in console
59
- // so the error is easily discoverable. 'ERROR in' is the key word to search in webpack output.
60
- if (stdoutString.includes('ERROR in')) {
61
- devkit_1.logger.log(stdoutString);
62
- }
63
- if (stdoutString.includes('Successfully ran target build')) {
64
- staticProcess.stdout.removeAllListeners('data');
65
- devkit_1.logger.info(`NX Built host`);
66
- res();
67
- }
68
- });
69
- staticProcess.stderr.on('data', (data) => devkit_1.logger.info(data.toString()));
70
- staticProcess.once('exit', (code) => {
39
+ async function buildHost(nxBin, buildTarget, context) {
40
+ await new Promise((res, rej) => {
41
+ const staticProcess = (0, child_process_1.fork)(nxBin, [
42
+ `run`,
43
+ `${buildTarget.project}:${buildTarget.target}${buildTarget.configuration
44
+ ? `:${buildTarget.configuration}`
45
+ : context.configurationName
46
+ ? `:${context.configurationName}`
47
+ : ''}`,
48
+ ], {
49
+ cwd: context.root,
50
+ stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
51
+ });
52
+ staticProcess.stdout.on('data', (data) => {
53
+ const ANSII_CODE_REGEX =
54
+ // eslint-disable-next-line no-control-regex
55
+ /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
56
+ const stdoutString = data.toString().replace(ANSII_CODE_REGEX, '');
57
+ // in addition to writing into the stdout stream, also show error directly in console
58
+ // so the error is easily discoverable. 'ERROR in' is the key word to search in webpack output.
59
+ if (stdoutString.includes('ERROR in')) {
60
+ devkit_1.logger.log(stdoutString);
61
+ }
62
+ if (stdoutString.includes('Successfully ran target build')) {
71
63
  staticProcess.stdout.removeAllListeners('data');
72
- staticProcess.stderr.removeAllListeners('data');
73
- if (code !== 0) {
74
- rej(`Host failed to build. See above for details.`);
75
- }
76
- else {
77
- res();
78
- }
79
- });
80
- process.on('SIGTERM', () => staticProcess.kill('SIGTERM'));
81
- process.on('exit', () => staticProcess.kill('SIGTERM'));
64
+ devkit_1.logger.info(`NX Built host`);
65
+ res();
66
+ }
82
67
  });
68
+ staticProcess.stderr.on('data', (data) => devkit_1.logger.info(data.toString()));
69
+ staticProcess.once('exit', (code) => {
70
+ staticProcess.stdout.removeAllListeners('data');
71
+ staticProcess.stderr.removeAllListeners('data');
72
+ if (code !== 0) {
73
+ rej(`Host failed to build. See above for details.`);
74
+ }
75
+ else {
76
+ res();
77
+ }
78
+ });
79
+ process.on('SIGTERM', () => staticProcess.kill('SIGTERM'));
80
+ process.on('exit', () => staticProcess.kill('SIGTERM'));
83
81
  });
84
82
  }
85
83
  function moveToTmpDirectory(staticRemotesConfig, hostOutputPath, hostUrlSegment) {
@@ -166,87 +164,81 @@ function startProxies(staticRemotesConfig, hostServeOptions, mappedLocationOfHos
166
164
  process.on('exit', () => proxyServer.close());
167
165
  devkit_1.logger.info('NX Static host proxy started successfully');
168
166
  }
169
- function moduleFederationStaticServer(schema, context) {
170
- return tslib_1.__asyncGenerator(this, arguments, function* moduleFederationStaticServer_1() {
171
- var _a;
172
- var _b;
173
- // Force Node to resolve to look for the nx binary that is inside node_modules
174
- const nxBin = require.resolve('nx/bin/nx');
175
- // Get the remotes from the module federation config
176
- const p = context.projectsConfigurations.projects[context.projectName];
177
- const options = getBuildAndServeOptionsFromServeTarget(schema.serveTarget, context);
178
- const moduleFederationConfig = (0, module_federation_1.getModuleFederationConfig)(options.buildOptions.tsConfig, context.root, p.root, 'react');
179
- const remotes = (0, module_federation_1.getRemotes)([], options.serveOptions.skipRemotes, moduleFederationConfig, {
180
- projectName: context.projectName,
181
- projectGraph: context.projectGraph,
182
- root: context.root,
183
- }, options.pathToManifestFile);
184
- const staticRemotesConfig = (0, parse_static_remotes_config_1.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
185
- (_a = (_b = options.serveOptions).staticRemotesPort) !== null && _a !== void 0 ? _a : (_b.staticRemotesPort = remotes.staticRemotePort);
186
- const mappedLocationsOfStaticRemotes = yield tslib_1.__await((0, build_static_remotes_1.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options.serveOptions));
187
- // Build the host
188
- const hostUrlSegment = (0, path_1.basename)(options.buildOptions.outputPath);
189
- const mappedLocationOfHost = `http${options.serveOptions.ssl ? 's' : ''}://${options.serveOptions.host}:${options.serveOptions.staticRemotesPort}/${hostUrlSegment}`;
190
- yield tslib_1.__await(buildHost(nxBin, options.buildTarget, context));
191
- // Move to a temporary directory
192
- const commonOutputDirectory = moveToTmpDirectory(staticRemotesConfig, options.buildOptions.outputPath, hostUrlSegment);
193
- // File Serve the temporary directory
194
- const staticFileServerIter = (0, file_server_impl_1.default)({
195
- cors: true,
196
- watch: false,
197
- staticFilePath: commonOutputDirectory,
198
- parallel: false,
199
- spa: false,
200
- withDeps: false,
201
- host: options.serveOptions.host,
202
- port: options.serveOptions.staticRemotesPort,
203
- ssl: options.serveOptions.ssl,
204
- sslCert: options.serveOptions.sslCert,
205
- sslKey: options.serveOptions.sslKey,
206
- cacheSeconds: -1,
207
- }, context);
208
- // express proxy all of it
209
- startProxies(staticRemotesConfig, options.serveOptions, mappedLocationOfHost, mappedLocationsOfStaticRemotes, options.serveOptions.ssl
210
- ? {
211
- pathToCert: (0, path_1.join)(devkit_1.workspaceRoot, options.serveOptions.sslCert),
212
- pathToKey: (0, path_1.join)(devkit_1.workspaceRoot, options.serveOptions.sslKey),
213
- }
214
- : undefined);
215
- return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, async_iterable_1.combineAsyncIterables)(staticFileServerIter, (0, async_iterable_1.createAsyncIterable)((_a) => tslib_1.__awaiter(this, [_a], void 0, function* ({ next, done }) {
216
- var _b;
217
- const host = (_b = options.serveOptions.host) !== null && _b !== void 0 ? _b : 'localhost';
218
- const baseUrl = `http${options.serveOptions.ssl ? 's' : ''}://${host}:${options.serveOptions.port}`;
219
- if (remotes.remotePorts.length === 0) {
220
- const portsToWaitFor = [options.serveOptions.staticRemotesPort];
221
- yield Promise.all(portsToWaitFor.map((port) => (0, wait_for_port_open_1.waitForPortOpen)(port, {
222
- retries: 480,
223
- retryDelay: 2500,
224
- host: host,
225
- })));
226
- devkit_1.logger.info(`NX Server ready at ${baseUrl}`);
227
- next({ success: true, baseUrl: baseUrl });
228
- done();
229
- return;
230
- }
231
- try {
232
- const portsToWaitFor = staticFileServerIter
233
- ? [options.serveOptions.staticRemotesPort, ...remotes.remotePorts]
234
- : [...remotes.remotePorts];
235
- yield Promise.all(portsToWaitFor.map((port) => (0, wait_for_port_open_1.waitForPortOpen)(port, {
236
- retries: 480,
237
- retryDelay: 2500,
238
- host: host,
239
- })));
240
- devkit_1.logger.info(`NX Server ready at ${baseUrl}`);
241
- next({ success: true, baseUrl: baseUrl });
242
- }
243
- catch (err) {
244
- throw new Error(`Failed to start. Check above for any errors.`);
245
- }
246
- finally {
247
- done();
248
- }
249
- })))))));
250
- });
167
+ async function* moduleFederationStaticServer(schema, context) {
168
+ // Force Node to resolve to look for the nx binary that is inside node_modules
169
+ const nxBin = require.resolve('nx/bin/nx');
170
+ // Get the remotes from the module federation config
171
+ const p = context.projectsConfigurations.projects[context.projectName];
172
+ const options = getBuildAndServeOptionsFromServeTarget(schema.serveTarget, context);
173
+ const moduleFederationConfig = (0, module_federation_1.getModuleFederationConfig)(options.buildOptions.tsConfig, context.root, p.root, 'react');
174
+ const remotes = (0, module_federation_1.getRemotes)([], options.serveOptions.skipRemotes, moduleFederationConfig, {
175
+ projectName: context.projectName,
176
+ projectGraph: context.projectGraph,
177
+ root: context.root,
178
+ }, options.pathToManifestFile);
179
+ const staticRemotesConfig = (0, parse_static_remotes_config_1.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
180
+ options.serveOptions.staticRemotesPort ??= remotes.staticRemotePort;
181
+ const mappedLocationsOfStaticRemotes = await (0, build_static_remotes_1.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options.serveOptions);
182
+ // Build the host
183
+ const hostUrlSegment = (0, path_1.basename)(options.buildOptions.outputPath);
184
+ const mappedLocationOfHost = `http${options.serveOptions.ssl ? 's' : ''}://${options.serveOptions.host}:${options.serveOptions.staticRemotesPort}/${hostUrlSegment}`;
185
+ await buildHost(nxBin, options.buildTarget, context);
186
+ // Move to a temporary directory
187
+ const commonOutputDirectory = moveToTmpDirectory(staticRemotesConfig, options.buildOptions.outputPath, hostUrlSegment);
188
+ // File Serve the temporary directory
189
+ const staticFileServerIter = (0, file_server_impl_1.default)({
190
+ cors: true,
191
+ watch: false,
192
+ staticFilePath: commonOutputDirectory,
193
+ parallel: false,
194
+ spa: false,
195
+ withDeps: false,
196
+ host: options.serveOptions.host,
197
+ port: options.serveOptions.staticRemotesPort,
198
+ ssl: options.serveOptions.ssl,
199
+ sslCert: options.serveOptions.sslCert,
200
+ sslKey: options.serveOptions.sslKey,
201
+ cacheSeconds: -1,
202
+ }, context);
203
+ // express proxy all of it
204
+ startProxies(staticRemotesConfig, options.serveOptions, mappedLocationOfHost, mappedLocationsOfStaticRemotes, options.serveOptions.ssl
205
+ ? {
206
+ pathToCert: (0, path_1.join)(devkit_1.workspaceRoot, options.serveOptions.sslCert),
207
+ pathToKey: (0, path_1.join)(devkit_1.workspaceRoot, options.serveOptions.sslKey),
208
+ }
209
+ : undefined);
210
+ return yield* (0, async_iterable_1.combineAsyncIterables)(staticFileServerIter, (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
211
+ const host = options.serveOptions.host ?? 'localhost';
212
+ const baseUrl = `http${options.serveOptions.ssl ? 's' : ''}://${host}:${options.serveOptions.port}`;
213
+ if (remotes.remotePorts.length === 0) {
214
+ const portsToWaitFor = [options.serveOptions.staticRemotesPort];
215
+ await Promise.all(portsToWaitFor.map((port) => (0, wait_for_port_open_1.waitForPortOpen)(port, {
216
+ retries: 480,
217
+ retryDelay: 2500,
218
+ host: host,
219
+ })));
220
+ devkit_1.logger.info(`NX Server ready at ${baseUrl}`);
221
+ next({ success: true, baseUrl: baseUrl });
222
+ done();
223
+ return;
224
+ }
225
+ try {
226
+ const portsToWaitFor = staticFileServerIter
227
+ ? [options.serveOptions.staticRemotesPort, ...remotes.remotePorts]
228
+ : [...remotes.remotePorts];
229
+ await Promise.all(portsToWaitFor.map((port) => (0, wait_for_port_open_1.waitForPortOpen)(port, {
230
+ retries: 480,
231
+ retryDelay: 2500,
232
+ host: host,
233
+ })));
234
+ devkit_1.logger.info(`NX Server ready at ${baseUrl}`);
235
+ next({ success: true, baseUrl: baseUrl });
236
+ }
237
+ catch (err) {
238
+ throw new Error(`Failed to start. Check above for any errors.`);
239
+ }
240
+ finally {
241
+ done();
242
+ }
243
+ }));
251
244
  }
252
- //# sourceMappingURL=module-federation-static-server.impl.js.map