@nx/rspack 19.8.0 → 20.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.
- package/LICENSE +1 -1
- package/README.md +70 -34
- package/executors.json +2 -2
- package/module-federation.js +0 -1
- package/package.json +14 -9
- package/plugin.js +0 -1
- package/src/executors/dev-server/dev-server.impl.js +39 -38
- package/src/executors/dev-server/lib/get-dev-server-config.js +1 -3
- package/src/executors/dev-server/lib/serve-path.js +0 -1
- package/src/executors/dev-server/schema.json +3 -9
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +109 -98
- package/src/executors/module-federation-dev-server/schema.json +1 -3
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +153 -148
- package/src/executors/module-federation-ssr-dev-server/schema.json +1 -4
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +117 -125
- package/src/executors/rspack/rspack.impl.js +60 -67
- package/src/executors/rspack/schema.json +6 -26
- package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js +0 -1
- package/src/executors/ssr-dev-server/schema.json +1 -4
- package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +26 -40
- package/src/generators/application/application.js +79 -76
- package/src/generators/application/lib/create-ts-config.js +5 -3
- package/src/generators/application/lib/normalize-options.js +12 -7
- package/src/generators/application/schema.json +1 -0
- package/src/generators/configuration/configuration.js +63 -65
- package/src/generators/configuration/schema.json +2 -1
- package/src/generators/init/init.js +58 -59
- package/src/generators/init/schema.json +2 -1
- package/src/generators/preset/preset.js +26 -29
- package/src/generators/preset/schema.json +1 -0
- package/src/index.js +0 -1
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -7
- package/src/plugins/generate-package-json-plugin.js +1 -3
- package/src/plugins/plugin.js +81 -90
- package/src/utils/config.js +7 -11
- package/src/utils/create-compiler.js +21 -25
- package/src/utils/generator-utils.js +55 -66
- package/src/utils/get-copy-patterns.js +1 -3
- package/src/utils/jest-utils.js +0 -1
- package/src/utils/mode-utils.js +0 -1
- package/src/utils/model.js +0 -1
- package/src/utils/module-federation/build-static.remotes.js +57 -61
- package/src/utils/module-federation/dependencies.js +1 -3
- package/src/utils/module-federation/get-remotes-for-host.js +4 -8
- package/src/utils/module-federation/index.js +0 -1
- package/src/utils/module-federation/models/index.js +0 -1
- package/src/utils/module-federation/package-json.js +0 -1
- package/src/utils/module-federation/parse-static-remotes-config.js +2 -3
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +1 -2
- package/src/utils/module-federation/public-api.js +0 -1
- package/src/utils/module-federation/remotes.js +0 -1
- package/src/utils/module-federation/secondary-entry-points.js +4 -5
- package/src/utils/module-federation/share.js +22 -19
- package/src/utils/module-federation/start-remote-proxies.js +0 -1
- package/src/utils/module-federation/start-ssr-remote-proxies.js +0 -1
- package/src/utils/module-federation/typescript.js +6 -6
- package/src/utils/module-federation/with-module-federation/package-json.js +0 -1
- package/src/utils/module-federation/with-module-federation/utils.js +41 -43
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +48 -35
- package/src/utils/module-federation/with-module-federation/with-module-federation.js +56 -38
- package/src/utils/normalize-assets.js +5 -3
- package/src/utils/read-rspack-options.js +23 -27
- package/src/utils/resolve-user-defined-rspack-config.js +0 -1
- package/src/utils/versions.js +0 -1
- package/src/utils/with-nx.js +30 -13
- package/src/utils/with-react.js +11 -5
- package/src/utils/with-web.js +20 -11
- package/module-federation.js.map +0 -1
- package/plugin.js.map +0 -1
- package/src/executors/dev-server/dev-server.impl.js.map +0 -1
- package/src/executors/dev-server/lib/get-dev-server-config.js.map +0 -1
- package/src/executors/dev-server/lib/serve-path.js.map +0 -1
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js.map +0 -1
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js.map +0 -1
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js.map +0 -1
- package/src/executors/rspack/rspack.impl.js.map +0 -1
- package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js.map +0 -1
- package/src/executors/ssr-dev-server/ssr-dev-server.impl.js.map +0 -1
- package/src/generators/application/application.js.map +0 -1
- package/src/generators/application/lib/create-ts-config.js.map +0 -1
- package/src/generators/application/lib/normalize-options.js.map +0 -1
- package/src/generators/configuration/configuration.js.map +0 -1
- package/src/generators/init/init.js.map +0 -1
- package/src/generators/preset/preset.js.map +0 -1
- package/src/index.js.map +0 -1
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js.map +0 -1
- package/src/plugins/generate-package-json-plugin.js.map +0 -1
- package/src/plugins/plugin.js.map +0 -1
- package/src/utils/config.js.map +0 -1
- package/src/utils/create-compiler.js.map +0 -1
- package/src/utils/generator-utils.js.map +0 -1
- package/src/utils/get-copy-patterns.js.map +0 -1
- package/src/utils/jest-utils.js.map +0 -1
- package/src/utils/mode-utils.js.map +0 -1
- package/src/utils/model.js.map +0 -1
- package/src/utils/module-federation/build-static.remotes.js.map +0 -1
- package/src/utils/module-federation/dependencies.js.map +0 -1
- package/src/utils/module-federation/get-remotes-for-host.js.map +0 -1
- package/src/utils/module-federation/index.js.map +0 -1
- package/src/utils/module-federation/models/index.js.map +0 -1
- package/src/utils/module-federation/package-json.js.map +0 -1
- package/src/utils/module-federation/parse-static-remotes-config.js.map +0 -1
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.js.map +0 -1
- package/src/utils/module-federation/public-api.js.map +0 -1
- package/src/utils/module-federation/remotes.js.map +0 -1
- package/src/utils/module-federation/secondary-entry-points.js.map +0 -1
- package/src/utils/module-federation/share.js.map +0 -1
- package/src/utils/module-federation/start-remote-proxies.js.map +0 -1
- package/src/utils/module-federation/start-ssr-remote-proxies.js.map +0 -1
- package/src/utils/module-federation/typescript.js.map +0 -1
- package/src/utils/module-federation/with-module-federation/package-json.js.map +0 -1
- package/src/utils/module-federation/with-module-federation/utils.js.map +0 -1
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js.map +0 -1
- package/src/utils/module-federation/with-module-federation/with-module-federation.js.map +0 -1
- package/src/utils/normalize-assets.js.map +0 -1
- package/src/utils/read-rspack-options.js.map +0 -1
- package/src/utils/resolve-user-defined-rspack-config.js.map +0 -1
- package/src/utils/versions.js.map +0 -1
- package/src/utils/with-nx.js.map +0 -1
- package/src/utils/with-react.js.map +0 -1
- package/src/utils/with-web.js.map +0 -1
package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js
CHANGED
|
@@ -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
|
-
|
|
19
|
-
|
|
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
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
77
|
-
|
|
88
|
+
}
|
|
89
|
+
return remoteIters;
|
|
78
90
|
}
|
|
79
|
-
function buildSsrStaticRemotes(staticRemotesConfig, nxBin, context, options) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
147
|
-
|
|
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
|
-
|
|
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
|
-
|
|
186
|
+
done();
|
|
187
|
+
return;
|
|
153
188
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
package/src/executors/module-federation-static-server/module-federation-static-server.impl.js
CHANGED
|
@@ -36,50 +36,48 @@ function getBuildAndServeOptionsFromServeTarget(serveTarget, context) {
|
|
|
36
36
|
pathToManifestFile,
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
-
function buildHost(nxBin, buildTarget, context) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|