@nx/rspack 24.0.0-beta.2 → 24.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.
- package/dist/src/executors/dev-server/dev-server.impl.js +0 -2
- package/dist/src/executors/rspack/lib/config.js +18 -8
- package/dist/src/generators/configuration/configuration.js +2 -24
- package/dist/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.js +78 -45
- package/dist/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.d.ts +1 -0
- package/dist/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.js +31 -2
- package/dist/src/generators/convert-config-to-rspack-plugin/schema.json +2 -2
- package/dist/src/generators/convert-to-inferred/convert-to-inferred.js +5 -4
- package/dist/src/generators/convert-to-inferred/utils/build-post-target-transformer.js +13 -5
- package/dist/src/generators/convert-to-inferred/utils/serve-post-target-transformer.js +8 -14
- package/dist/src/generators/convert-webpack/convert-webpack.js +20 -74
- package/dist/src/generators/convert-webpack/lib/transform-plugin-config.d.ts +1 -1
- package/dist/src/generators/convert-webpack/lib/transform-plugin-config.js +47 -69
- package/dist/src/generators/init/init.js +38 -44
- package/dist/src/generators/init/schema.d.ts +0 -1
- package/dist/src/migrations/update-24-0-0/finish-inferred-conversion.md +11 -0
- package/dist/src/migrations/update-24-0-0/inventory.d.ts +9 -0
- package/dist/src/migrations/update-24-0-0/inventory.js +53 -0
- package/dist/src/migrations/update-24-0-0/migrate-compose-plugins.d.ts +10 -0
- package/dist/src/migrations/update-24-0-0/migrate-compose-plugins.js +60 -0
- package/dist/src/migrations/update-24-0-0/migrate-compose-plugins.md +95 -0
- package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.d.ts +6 -0
- package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.js +36 -0
- package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.md +90 -0
- package/dist/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.js +4 -1
- package/dist/src/utils/config.d.ts +10 -14
- package/dist/src/utils/config.js +17 -70
- package/dist/src/utils/deprecation.d.ts +1 -6
- package/dist/src/utils/deprecation.js +4 -23
- package/dist/src/utils/e2e-web-server-info-utils.d.ts +1 -1
- package/dist/src/utils/e2e-web-server-info-utils.js +2 -2
- package/dist/src/utils/generator-utils.d.ts +0 -2
- package/dist/src/utils/generator-utils.js +45 -167
- package/dist/src/utils/with-nx.d.ts +5 -9
- package/dist/src/utils/with-nx.js +5 -32
- package/dist/src/utils/with-react.d.ts +5 -8
- package/dist/src/utils/with-react.js +5 -15
- package/dist/src/utils/with-web.d.ts +5 -8
- package/dist/src/utils/with-web.js +5 -44
- package/executors.json +0 -25
- package/migrations.json +13 -0
- package/package.json +6 -25
- package/dist/module-federation.d.ts +0 -4
- package/dist/module-federation.js +0 -9
- package/dist/src/executors/module-federation-dev-server/lib/index.d.ts +0 -2
- package/dist/src/executors/module-federation-dev-server/lib/index.js +0 -5
- package/dist/src/executors/module-federation-dev-server/lib/normalize-options.d.ts +0 -4
- package/dist/src/executors/module-federation-dev-server/lib/normalize-options.js +0 -19
- package/dist/src/executors/module-federation-dev-server/lib/start-remotes.d.ts +0 -5
- package/dist/src/executors/module-federation-dev-server/lib/start-remotes.js +0 -33
- package/dist/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +0 -6
- package/dist/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +0 -74
- package/dist/src/executors/module-federation-dev-server/schema.d.ts +0 -25
- package/dist/src/executors/module-federation-dev-server/schema.json +0 -104
- package/dist/src/executors/module-federation-ssr-dev-server/lib/index.d.ts +0 -2
- package/dist/src/executors/module-federation-ssr-dev-server/lib/index.js +0 -5
- package/dist/src/executors/module-federation-ssr-dev-server/lib/normalize-options.d.ts +0 -4
- package/dist/src/executors/module-federation-ssr-dev-server/lib/normalize-options.js +0 -23
- package/dist/src/executors/module-federation-ssr-dev-server/lib/start-remotes.d.ts +0 -5
- package/dist/src/executors/module-federation-ssr-dev-server/lib/start-remotes.js +0 -34
- package/dist/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts +0 -5
- package/dist/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +0 -65
- package/dist/src/executors/module-federation-ssr-dev-server/schema.d.ts +0 -29
- package/dist/src/executors/module-federation-ssr-dev-server/schema.json +0 -85
- package/dist/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +0 -12
- package/dist/src/executors/module-federation-static-server/module-federation-static-server.impl.js +0 -237
- package/dist/src/executors/module-federation-static-server/schema.d.ts +0 -3
- package/dist/src/executors/module-federation-static-server/schema.json +0 -16
- package/dist/src/executors/rspack/rspack.impl.d.ts +0 -7
- package/dist/src/executors/rspack/rspack.impl.js +0 -127
- package/dist/src/executors/rspack/schema.json +0 -410
- package/dist/src/generators/convert-webpack/lib/transform-cjs.d.ts +0 -2
- package/dist/src/generators/convert-webpack/lib/transform-cjs.js +0 -263
- package/dist/src/generators/convert-webpack/lib/transform-esm.d.ts +0 -2
- package/dist/src/generators/convert-webpack/lib/transform-esm.js +0 -263
- package/dist/src/utils/has-plugin.d.ts +0 -2
- package/dist/src/utils/has-plugin.js +0 -10
- package/dist/src/utils/module-federation-deprecation.d.ts +0 -6
- package/dist/src/utils/module-federation-deprecation.js +0 -30
package/dist/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = moduleFederationSsrDevServer;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const internal_1 = require("@nx/devkit/internal");
|
|
7
|
-
const internal_2 = require("@nx/js/internal");
|
|
8
|
-
const internal_3 = require("@nx/module-federation/internal");
|
|
9
|
-
const internal_4 = require("@nx/web/internal");
|
|
10
|
-
const fs_1 = require("fs");
|
|
11
|
-
const path_1 = require("path");
|
|
12
|
-
const ssr_dev_server_impl_1 = tslib_1.__importDefault(require("../ssr-dev-server/ssr-dev-server.impl"));
|
|
13
|
-
const lib_1 = require("./lib");
|
|
14
|
-
const module_federation_deprecation_1 = require("../../utils/module-federation-deprecation");
|
|
15
|
-
async function* moduleFederationSsrDevServer(ssrDevServerOptions, context) {
|
|
16
|
-
(0, module_federation_deprecation_1.warnRspackMfSsrDevServerExecutorDeprecation)();
|
|
17
|
-
const options = (0, lib_1.normalizeOptions)(ssrDevServerOptions);
|
|
18
|
-
const iter = (0, ssr_dev_server_impl_1.default)(options, context);
|
|
19
|
-
const projectConfig = context.projectsConfigurations.projects[context.projectName];
|
|
20
|
-
let pathToManifestFile = (0, path_1.join)(context.root, (0, internal_2.getProjectSourceRoot)(projectConfig), 'assets/module-federation.manifest.json');
|
|
21
|
-
if (options.pathToManifestFile) {
|
|
22
|
-
const userPathToManifestFile = (0, path_1.join)(context.root, options.pathToManifestFile);
|
|
23
|
-
if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
|
|
24
|
-
throw new Error(`The provided Module Federation manifest file path does not exist. Please check the file exists at "${userPathToManifestFile}".`);
|
|
25
|
-
}
|
|
26
|
-
else if ((0, path_1.extname)(userPathToManifestFile) !== '.json') {
|
|
27
|
-
throw new Error(`The Module Federation manifest file must be a JSON. Please ensure the file at ${userPathToManifestFile} is a JSON.`);
|
|
28
|
-
}
|
|
29
|
-
pathToManifestFile = userPathToManifestFile;
|
|
30
|
-
}
|
|
31
|
-
if (!options.isInitialHost) {
|
|
32
|
-
return yield* iter;
|
|
33
|
-
}
|
|
34
|
-
const { staticRemotesIter, devRemoteIters, remotes } = await (0, internal_3.startRemoteIterators)(options, context, lib_1.startRemotes, pathToManifestFile, 'react', true);
|
|
35
|
-
return yield* (0, internal_1.combineAsyncIterables)(iter, ...devRemoteIters, ...(staticRemotesIter ? [staticRemotesIter] : []), (0, internal_1.createAsyncIterable)(async ({ next, done }) => {
|
|
36
|
-
if (!options.isInitialHost) {
|
|
37
|
-
done();
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (remotes.remotePorts.length === 0) {
|
|
41
|
-
done();
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
const host = options.host ?? 'localhost';
|
|
46
|
-
const baseUrl = `http${options.ssl ? 's' : ''}://${host}:${options.port}`;
|
|
47
|
-
const portsToWaitFor = staticRemotesIter && options.staticRemotesPort
|
|
48
|
-
? [options.staticRemotesPort, ...remotes.remotePorts]
|
|
49
|
-
: [...remotes.remotePorts];
|
|
50
|
-
await Promise.all(portsToWaitFor.map((port) => (0, internal_4.waitForPortOpen)(port, {
|
|
51
|
-
retries: 480,
|
|
52
|
-
retryDelay: 2500,
|
|
53
|
-
host,
|
|
54
|
-
})));
|
|
55
|
-
devkit_1.logger.info(`Nx all ssr remotes have started, server ready at ${baseUrl}`);
|
|
56
|
-
next({ success: true, baseUrl });
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
throw new Error(`Nx failed to start ssr remotes. Check above for errors.`);
|
|
60
|
-
}
|
|
61
|
-
finally {
|
|
62
|
-
done();
|
|
63
|
-
}
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { DevRemoteDefinition } from '@nx/module-federation/internal';
|
|
2
|
-
import { RspackSsrDevServerOptions } from '../ssr-dev-server/schema';
|
|
3
|
-
|
|
4
|
-
export type ModuleFederationSsrDevServerOptions = RspackSsrDevServerOptions & {
|
|
5
|
-
devRemotes?: (
|
|
6
|
-
| string
|
|
7
|
-
| {
|
|
8
|
-
remoteName: string;
|
|
9
|
-
configuration: string;
|
|
10
|
-
}
|
|
11
|
-
)[];
|
|
12
|
-
|
|
13
|
-
skipRemotes?: string[];
|
|
14
|
-
host: string;
|
|
15
|
-
pathToManifestFile?: string;
|
|
16
|
-
staticRemotesPort?: number;
|
|
17
|
-
parallel?: number;
|
|
18
|
-
ssl?: boolean;
|
|
19
|
-
sslKey?: string;
|
|
20
|
-
sslCert?: string;
|
|
21
|
-
isInitialHost?: boolean;
|
|
22
|
-
verbose?: boolean;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export type NormalizedModuleFederationSsrDevServerOptions =
|
|
26
|
-
ModuleFederationSsrDevServerOptions & {
|
|
27
|
-
devRemotes: DevRemoteDefinition[];
|
|
28
|
-
verbose: boolean;
|
|
29
|
-
};
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 2,
|
|
3
|
-
"continuous": true,
|
|
4
|
-
"outputCapture": "direct-nodejs",
|
|
5
|
-
"title": "Module Federation SSR Dev Server",
|
|
6
|
-
"x-deprecated": "The `@nx/rspack:module-federation-ssr-dev-server` executor is deprecated. SSR is not first-classed in the new `@nx/react:consumer`/`@nx/react:provider` generators. Removed in Nx v24.",
|
|
7
|
-
"description": "Serve a SSR Consumer (host) application along with its known Producers (remotes).",
|
|
8
|
-
"cli": "nx",
|
|
9
|
-
"type": "object",
|
|
10
|
-
"properties": {
|
|
11
|
-
"browserTarget": {
|
|
12
|
-
"type": "string",
|
|
13
|
-
"description": "Target which builds the browser application.",
|
|
14
|
-
"x-priority": "important"
|
|
15
|
-
},
|
|
16
|
-
"serverTarget": {
|
|
17
|
-
"type": "string",
|
|
18
|
-
"description": "Target which builds the server application.",
|
|
19
|
-
"x-priority": "important"
|
|
20
|
-
},
|
|
21
|
-
"port": {
|
|
22
|
-
"type": "number",
|
|
23
|
-
"description": "The port to be set on `process.env.PORT` for use in the server.",
|
|
24
|
-
"default": 4200,
|
|
25
|
-
"x-priority": "important"
|
|
26
|
-
},
|
|
27
|
-
"devRemotes": {
|
|
28
|
-
"type": "array",
|
|
29
|
-
"items": {
|
|
30
|
-
"type": "string"
|
|
31
|
-
},
|
|
32
|
-
"description": "List of Producers (remote) applications to run in development mode (i.e. using serve target).",
|
|
33
|
-
"x-priority": "important",
|
|
34
|
-
"alias": "devProducers"
|
|
35
|
-
},
|
|
36
|
-
"skipRemotes": {
|
|
37
|
-
"type": "array",
|
|
38
|
-
"items": {
|
|
39
|
-
"type": "string"
|
|
40
|
-
},
|
|
41
|
-
"description": "List of Producers (remote) applications to not automatically serve, either statically or in development mode.",
|
|
42
|
-
"x-priority": "important",
|
|
43
|
-
"alias": "skipProducers"
|
|
44
|
-
},
|
|
45
|
-
"host": {
|
|
46
|
-
"type": "string",
|
|
47
|
-
"description": "Host to listen on.",
|
|
48
|
-
"default": "localhost"
|
|
49
|
-
},
|
|
50
|
-
"staticRemotesPort": {
|
|
51
|
-
"type": "number",
|
|
52
|
-
"description": "The port at which to serve the file-server for the static Producers (remotes).",
|
|
53
|
-
"alias": "staticProducersPort"
|
|
54
|
-
},
|
|
55
|
-
"pathToManifestFile": {
|
|
56
|
-
"type": "string",
|
|
57
|
-
"description": "Path to a Module Federation manifest file (e.g. `my/path/to/module-federation.manifest.json`) containing the dynamic Producers (remote) applications relative to the workspace root."
|
|
58
|
-
},
|
|
59
|
-
"ssl": {
|
|
60
|
-
"type": "boolean",
|
|
61
|
-
"description": "Serve using HTTPS.",
|
|
62
|
-
"default": false
|
|
63
|
-
},
|
|
64
|
-
"sslKey": {
|
|
65
|
-
"type": "string",
|
|
66
|
-
"description": "SSL key to use for serving HTTPS."
|
|
67
|
-
},
|
|
68
|
-
"sslCert": {
|
|
69
|
-
"type": "string",
|
|
70
|
-
"description": "SSL certificate to use for serving HTTPS."
|
|
71
|
-
},
|
|
72
|
-
"publicHost": {
|
|
73
|
-
"type": "string",
|
|
74
|
-
"description": "Public URL where the application will be served."
|
|
75
|
-
},
|
|
76
|
-
"isInitialHost": {
|
|
77
|
-
"type": "boolean",
|
|
78
|
-
"description": "Whether the Consumer (host) that is running this executor is the first in the project tree to do so.",
|
|
79
|
-
"default": true,
|
|
80
|
-
"x-priority": "internal",
|
|
81
|
-
"alias": "isInitialConsumer"
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
"required": ["browserTarget", "serverTarget"]
|
|
85
|
-
}
|
package/dist/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
-
import { StaticRemotesConfig } from '@nx/module-federation/internal';
|
|
3
|
-
import { ModuleFederationDevServerOptions } from '../module-federation-dev-server/schema';
|
|
4
|
-
import { ModuleFederationStaticServerSchema } from './schema';
|
|
5
|
-
export declare function startProxies(staticRemotesConfig: StaticRemotesConfig, hostServeOptions: ModuleFederationDevServerOptions, mappedLocationOfHost: string, mappedLocationsOfRemotes: Record<string, string>, sslOptions?: {
|
|
6
|
-
pathToCert: string;
|
|
7
|
-
pathToKey: string;
|
|
8
|
-
}): void;
|
|
9
|
-
export default function moduleFederationStaticServer(schema: ModuleFederationStaticServerSchema, context: ExecutorContext): AsyncGenerator<{
|
|
10
|
-
success: boolean;
|
|
11
|
-
baseUrl: string;
|
|
12
|
-
}, any, any>;
|
package/dist/src/executors/module-federation-static-server/module-federation-static-server.impl.js
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.startProxies = startProxies;
|
|
4
|
-
exports.default = moduleFederationStaticServer;
|
|
5
|
-
const internal_1 = require("@nx/devkit/internal");
|
|
6
|
-
const devkit_1 = require("@nx/devkit");
|
|
7
|
-
const internal_2 = require("@nx/js/internal");
|
|
8
|
-
const internal_3 = require("@nx/module-federation/internal");
|
|
9
|
-
const internal_4 = require("@nx/web/internal");
|
|
10
|
-
const child_process_1 = require("child_process");
|
|
11
|
-
const fs_1 = require("fs");
|
|
12
|
-
const path_1 = require("path");
|
|
13
|
-
const module_federation_deprecation_1 = require("../../utils/module-federation-deprecation");
|
|
14
|
-
function getBuildAndServeOptionsFromServeTarget(serveTarget, context) {
|
|
15
|
-
const target = (0, devkit_1.parseTargetString)(serveTarget, context);
|
|
16
|
-
const serveOptions = (0, devkit_1.readTargetOptions)(target, context);
|
|
17
|
-
const buildTarget = (0, devkit_1.parseTargetString)(serveOptions.buildTarget, context);
|
|
18
|
-
const buildOptions = (0, devkit_1.readTargetOptions)(buildTarget, context);
|
|
19
|
-
let pathToManifestFile = (0, path_1.join)(context.root, (0, internal_2.getProjectSourceRoot)(context.projectGraph.nodes[context.projectName].data), 'assets/module-federation.manifest.json');
|
|
20
|
-
if (serveOptions.pathToManifestFile) {
|
|
21
|
-
const userPathToManifestFile = (0, path_1.join)(context.root, serveOptions.pathToManifestFile);
|
|
22
|
-
if (!(0, fs_1.existsSync)(userPathToManifestFile)) {
|
|
23
|
-
throw new Error(`The provided Module Federation manifest file path does not exist. Please check the file exists at "${userPathToManifestFile}".`);
|
|
24
|
-
}
|
|
25
|
-
else if ((0, path_1.extname)(serveOptions.pathToManifestFile) !== '.json') {
|
|
26
|
-
throw new Error(`The Module Federation manifest file must be a JSON. Please ensure the file at ${userPathToManifestFile} is a JSON.`);
|
|
27
|
-
}
|
|
28
|
-
pathToManifestFile = userPathToManifestFile;
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
buildTarget,
|
|
32
|
-
buildOptions,
|
|
33
|
-
serveOptions,
|
|
34
|
-
pathToManifestFile,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
async function buildHost(nxBin, buildTarget, context) {
|
|
38
|
-
await new Promise((res, rej) => {
|
|
39
|
-
const staticProcess = (0, child_process_1.fork)(nxBin, [
|
|
40
|
-
`run`,
|
|
41
|
-
`${buildTarget.project}:${buildTarget.target}${buildTarget.configuration
|
|
42
|
-
? `:${buildTarget.configuration}`
|
|
43
|
-
: context.configurationName
|
|
44
|
-
? `:${context.configurationName}`
|
|
45
|
-
: ''}`,
|
|
46
|
-
], {
|
|
47
|
-
cwd: context.root,
|
|
48
|
-
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
|
|
49
|
-
});
|
|
50
|
-
staticProcess.stdout.on('data', (data) => {
|
|
51
|
-
const ANSII_CODE_REGEX = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
|
|
52
|
-
const stdoutString = data.toString().replace(ANSII_CODE_REGEX, '');
|
|
53
|
-
// in addition to writing into the stdout stream, also show error directly in console
|
|
54
|
-
// so the error is easily discoverable. 'ERROR in' is the key word to search in webpack output.
|
|
55
|
-
if (stdoutString.includes('ERROR in')) {
|
|
56
|
-
devkit_1.logger.log(stdoutString);
|
|
57
|
-
}
|
|
58
|
-
if (stdoutString.includes('Successfully ran target build')) {
|
|
59
|
-
staticProcess.stdout.removeAllListeners('data');
|
|
60
|
-
devkit_1.logger.info(`NX Built host`);
|
|
61
|
-
res();
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
staticProcess.stderr.on('data', (data) => devkit_1.logger.info(data.toString()));
|
|
65
|
-
staticProcess.once('exit', (code) => {
|
|
66
|
-
staticProcess.stdout.removeAllListeners('data');
|
|
67
|
-
staticProcess.stderr.removeAllListeners('data');
|
|
68
|
-
if (code !== 0) {
|
|
69
|
-
rej(`Host failed to build. See above for details.`);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
res();
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
process.on('SIGTERM', () => staticProcess.kill('SIGTERM'));
|
|
76
|
-
process.on('exit', () => staticProcess.kill('SIGTERM'));
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
function moveToTmpDirectory(staticRemotesConfig, hostOutputPath, hostUrlSegment) {
|
|
80
|
-
const commonOutputDirectory = (0, path_1.join)(devkit_1.workspaceRoot, 'tmp/static-module-federation');
|
|
81
|
-
for (const app of staticRemotesConfig.remotes) {
|
|
82
|
-
const remoteConfig = staticRemotesConfig.config[app];
|
|
83
|
-
(0, fs_1.cpSync)(remoteConfig.outputPath, (0, path_1.join)(commonOutputDirectory, remoteConfig.urlSegment), {
|
|
84
|
-
force: true,
|
|
85
|
-
recursive: true,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
(0, fs_1.cpSync)(hostOutputPath, (0, path_1.join)(commonOutputDirectory, hostUrlSegment), {
|
|
89
|
-
force: true,
|
|
90
|
-
recursive: true,
|
|
91
|
-
});
|
|
92
|
-
const cleanup = () => {
|
|
93
|
-
(0, fs_1.rmSync)(commonOutputDirectory, { force: true, recursive: true });
|
|
94
|
-
};
|
|
95
|
-
process.on('SIGTERM', () => {
|
|
96
|
-
cleanup();
|
|
97
|
-
});
|
|
98
|
-
process.on('exit', () => {
|
|
99
|
-
cleanup();
|
|
100
|
-
});
|
|
101
|
-
return commonOutputDirectory;
|
|
102
|
-
}
|
|
103
|
-
function startProxies(staticRemotesConfig, hostServeOptions, mappedLocationOfHost, mappedLocationsOfRemotes, sslOptions) {
|
|
104
|
-
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
105
|
-
const express = require('express');
|
|
106
|
-
let sslCert;
|
|
107
|
-
let sslKey;
|
|
108
|
-
if (sslOptions && sslOptions.pathToCert && sslOptions.pathToKey) {
|
|
109
|
-
if ((0, fs_1.existsSync)(sslOptions.pathToCert) && (0, fs_1.existsSync)(sslOptions.pathToKey)) {
|
|
110
|
-
sslCert = (0, fs_1.readFileSync)(sslOptions.pathToCert);
|
|
111
|
-
sslKey = (0, fs_1.readFileSync)(sslOptions.pathToKey);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
devkit_1.logger.warn(`Encountered SSL options in project.json, however, the certificate files do not exist in the filesystem. Using http.`);
|
|
115
|
-
devkit_1.logger.warn(`Attempted to find '${sslOptions.pathToCert}' and '${sslOptions.pathToKey}'.`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
const http = require('http');
|
|
119
|
-
const https = require('https');
|
|
120
|
-
devkit_1.logger.info(`NX Starting static remotes proxies...`);
|
|
121
|
-
for (const app of staticRemotesConfig.remotes) {
|
|
122
|
-
const expressProxy = express();
|
|
123
|
-
expressProxy.use(createProxyMiddleware({
|
|
124
|
-
target: mappedLocationsOfRemotes[app],
|
|
125
|
-
changeOrigin: true,
|
|
126
|
-
secure: sslCert ? false : undefined,
|
|
127
|
-
}));
|
|
128
|
-
const proxyServer = (sslCert ? https : http)
|
|
129
|
-
.createServer({ cert: sslCert, key: sslKey }, expressProxy)
|
|
130
|
-
.listen(staticRemotesConfig.config[app].port);
|
|
131
|
-
process.on('SIGTERM', () => proxyServer.close());
|
|
132
|
-
process.on('exit', () => proxyServer.close());
|
|
133
|
-
}
|
|
134
|
-
devkit_1.logger.info(`NX Static remotes proxies started successfully`);
|
|
135
|
-
devkit_1.logger.info(`NX Starting static host proxy...`);
|
|
136
|
-
const expressProxy = express();
|
|
137
|
-
expressProxy.use(createProxyMiddleware({
|
|
138
|
-
target: mappedLocationOfHost,
|
|
139
|
-
changeOrigin: true,
|
|
140
|
-
secure: sslCert ? false : undefined,
|
|
141
|
-
pathRewrite: (path) => {
|
|
142
|
-
let pathRewrite = path;
|
|
143
|
-
for (const app of staticRemotesConfig.remotes) {
|
|
144
|
-
if (path.endsWith(app)) {
|
|
145
|
-
pathRewrite = '/';
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return pathRewrite;
|
|
150
|
-
},
|
|
151
|
-
}));
|
|
152
|
-
const proxyServer = (sslCert ? https : http)
|
|
153
|
-
.createServer({ cert: sslCert, key: sslKey }, expressProxy)
|
|
154
|
-
.listen(hostServeOptions.port);
|
|
155
|
-
process.on('SIGTERM', () => proxyServer.close());
|
|
156
|
-
process.on('exit', () => proxyServer.close());
|
|
157
|
-
devkit_1.logger.info('NX Static host proxy started successfully');
|
|
158
|
-
}
|
|
159
|
-
async function* moduleFederationStaticServer(schema, context) {
|
|
160
|
-
(0, module_federation_deprecation_1.warnRspackMfStaticServerExecutorDeprecation)();
|
|
161
|
-
// Force Node to resolve to look for the nx binary that is inside node_modules
|
|
162
|
-
const nxBin = require.resolve('nx/bin/nx');
|
|
163
|
-
// Get the remotes from the module federation config
|
|
164
|
-
const p = context.projectsConfigurations.projects[context.projectName];
|
|
165
|
-
const options = getBuildAndServeOptionsFromServeTarget(schema.serveTarget, context);
|
|
166
|
-
const moduleFederationConfig = (0, internal_3.getModuleFederationConfig)(options.buildOptions.tsConfig, context.root, p.root, 'react');
|
|
167
|
-
const remotes = (0, internal_3.getRemotes)([], options.serveOptions.skipRemotes, moduleFederationConfig, {
|
|
168
|
-
projectName: context.projectName,
|
|
169
|
-
projectGraph: context.projectGraph,
|
|
170
|
-
root: context.root,
|
|
171
|
-
}, options.pathToManifestFile);
|
|
172
|
-
const staticRemotesConfig = (0, internal_3.parseStaticRemotesConfig)([...remotes.staticRemotes, ...remotes.dynamicRemotes], context);
|
|
173
|
-
options.serveOptions.staticRemotesPort ??= remotes.staticRemotePort;
|
|
174
|
-
const mappedLocationsOfStaticRemotes = await (0, internal_3.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options.serveOptions);
|
|
175
|
-
// Build the host
|
|
176
|
-
const hostUrlSegment = (0, path_1.basename)(options.buildOptions.outputPath);
|
|
177
|
-
const mappedLocationOfHost = `http${options.serveOptions.ssl ? 's' : ''}://${options.serveOptions.host}:${options.serveOptions.staticRemotesPort}/${hostUrlSegment}`;
|
|
178
|
-
await buildHost(nxBin, options.buildTarget, context);
|
|
179
|
-
// Move to a temporary directory
|
|
180
|
-
const commonOutputDirectory = moveToTmpDirectory(staticRemotesConfig, options.buildOptions.outputPath, hostUrlSegment);
|
|
181
|
-
// File Serve the temporary directory
|
|
182
|
-
const staticFileServerIter = (0, internal_4.fileServerExecutor)({
|
|
183
|
-
cors: true,
|
|
184
|
-
watch: false,
|
|
185
|
-
staticFilePath: commonOutputDirectory,
|
|
186
|
-
parallel: false,
|
|
187
|
-
spa: false,
|
|
188
|
-
withDeps: false,
|
|
189
|
-
host: options.serveOptions.host,
|
|
190
|
-
port: options.serveOptions.staticRemotesPort,
|
|
191
|
-
ssl: options.serveOptions.ssl,
|
|
192
|
-
sslCert: options.serveOptions.sslCert,
|
|
193
|
-
sslKey: options.serveOptions.sslKey,
|
|
194
|
-
cacheSeconds: -1,
|
|
195
|
-
}, context);
|
|
196
|
-
// express proxy all of it
|
|
197
|
-
startProxies(staticRemotesConfig, options.serveOptions, mappedLocationOfHost, mappedLocationsOfStaticRemotes, options.serveOptions.ssl
|
|
198
|
-
? {
|
|
199
|
-
pathToCert: (0, path_1.join)(devkit_1.workspaceRoot, options.serveOptions.sslCert),
|
|
200
|
-
pathToKey: (0, path_1.join)(devkit_1.workspaceRoot, options.serveOptions.sslKey),
|
|
201
|
-
}
|
|
202
|
-
: undefined);
|
|
203
|
-
return yield* (0, internal_1.combineAsyncIterables)(staticFileServerIter, (0, internal_1.createAsyncIterable)(async ({ next, done }) => {
|
|
204
|
-
const host = options.serveOptions.host ?? 'localhost';
|
|
205
|
-
const baseUrl = `http${options.serveOptions.ssl ? 's' : ''}://${host}:${options.serveOptions.port}`;
|
|
206
|
-
if (remotes.remotePorts.length === 0) {
|
|
207
|
-
const portsToWaitFor = [options.serveOptions.staticRemotesPort];
|
|
208
|
-
await Promise.all(portsToWaitFor.map((port) => (0, internal_4.waitForPortOpen)(port, {
|
|
209
|
-
retries: 480,
|
|
210
|
-
retryDelay: 2500,
|
|
211
|
-
host: host,
|
|
212
|
-
})));
|
|
213
|
-
devkit_1.logger.info(`NX Server ready at ${baseUrl}`);
|
|
214
|
-
next({ success: true, baseUrl: baseUrl });
|
|
215
|
-
done();
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
try {
|
|
219
|
-
const portsToWaitFor = staticFileServerIter && options.serveOptions.staticRemotesPort
|
|
220
|
-
? [options.serveOptions.staticRemotesPort, ...remotes.remotePorts]
|
|
221
|
-
: [...remotes.remotePorts];
|
|
222
|
-
await Promise.all(portsToWaitFor.map((port) => (0, internal_4.waitForPortOpen)(port, {
|
|
223
|
-
retries: 480,
|
|
224
|
-
retryDelay: 2500,
|
|
225
|
-
host: host,
|
|
226
|
-
})));
|
|
227
|
-
devkit_1.logger.info(`NX Server ready at ${baseUrl}`);
|
|
228
|
-
next({ success: true, baseUrl: baseUrl });
|
|
229
|
-
}
|
|
230
|
-
catch (err) {
|
|
231
|
-
throw new Error(`Failed to start. Check above for any errors.`);
|
|
232
|
-
}
|
|
233
|
-
finally {
|
|
234
|
-
done();
|
|
235
|
-
}
|
|
236
|
-
}));
|
|
237
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 2,
|
|
3
|
-
"continuous": true,
|
|
4
|
-
"outputCapture": "direct-nodejs",
|
|
5
|
-
"title": "Module Federation Static Dev Server",
|
|
6
|
-
"x-deprecated": "The `@nx/rspack:module-federation-static-server` executor is deprecated. Use `vite preview` / `rsbuild preview` via `nx:run-commands` instead. Removed in Nx v24.",
|
|
7
|
-
"description": "Serve a Consumer (host) application statically along with it's Producers (remotes).",
|
|
8
|
-
"cli": "nx",
|
|
9
|
-
"type": "object",
|
|
10
|
-
"properties": {
|
|
11
|
-
"serveTarget": {
|
|
12
|
-
"type": "string"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"required": ["serveTarget"]
|
|
16
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
-
import { RspackExecutorSchema } from './schema';
|
|
3
|
-
export default function runExecutor(options: RspackExecutorSchema, context: ExecutorContext): AsyncGenerator<{
|
|
4
|
-
success: boolean;
|
|
5
|
-
outfile?: string;
|
|
6
|
-
}, void, any>;
|
|
7
|
-
export declare function executeTypeCheck(options: RspackExecutorSchema, context: ExecutorContext): Promise<void>;
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = runExecutor;
|
|
4
|
-
exports.executeTypeCheck = executeTypeCheck;
|
|
5
|
-
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const internal_1 = require("@nx/devkit/internal");
|
|
7
|
-
const js_1 = require("@nx/js");
|
|
8
|
-
const internal_2 = require("@nx/js/internal");
|
|
9
|
-
const path_1 = require("path");
|
|
10
|
-
const create_compiler_1 = require("../../utils/create-compiler");
|
|
11
|
-
const mode_utils_1 = require("../../utils/mode-utils");
|
|
12
|
-
const normalize_options_1 = require("./lib/normalize-options");
|
|
13
|
-
const deprecation_1 = require("../../utils/deprecation");
|
|
14
|
-
async function* runExecutor(options, context) {
|
|
15
|
-
(0, deprecation_1.warnRspackExecutorDeprecation)();
|
|
16
|
-
process.env.NODE_ENV ??= options.mode ?? 'production';
|
|
17
|
-
options.target ??= 'web';
|
|
18
|
-
const metadata = context.projectsConfigurations.projects[context.projectName];
|
|
19
|
-
const sourceRoot = (0, internal_2.getProjectSourceRoot)(metadata);
|
|
20
|
-
const normalizedOptions = (0, normalize_options_1.normalizeOptions)(options, context.root, metadata.root, sourceRoot);
|
|
21
|
-
if ((0, mode_utils_1.isMode)(process.env.NODE_ENV)) {
|
|
22
|
-
normalizedOptions.mode = process.env.NODE_ENV;
|
|
23
|
-
}
|
|
24
|
-
if (!normalizedOptions.skipTypeChecking) {
|
|
25
|
-
await executeTypeCheck(normalizedOptions, context);
|
|
26
|
-
}
|
|
27
|
-
const compiler = await (0, create_compiler_1.createCompiler)(normalizedOptions, context);
|
|
28
|
-
const iterable = (0, internal_1.createAsyncIterable)(async ({ next, done }) => {
|
|
29
|
-
const watch = ((0, create_compiler_1.isMultiCompiler)(compiler)
|
|
30
|
-
? compiler.options[0].watch
|
|
31
|
-
: compiler.options.watch) ?? options.watch;
|
|
32
|
-
if (watch) {
|
|
33
|
-
const watcher = compiler.watch({}, async (err, stats) => {
|
|
34
|
-
if (err) {
|
|
35
|
-
devkit_1.logger.error(err);
|
|
36
|
-
next({ success: false });
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (!compiler || !stats) {
|
|
40
|
-
devkit_1.logger.error(new Error('Compiler or stats not available'));
|
|
41
|
-
next({ success: false });
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const statsOptions = getStatsOptions(compiler);
|
|
45
|
-
const printedStats = stats.toString(statsOptions);
|
|
46
|
-
// Avoid extra empty line when `stats: 'none'`
|
|
47
|
-
if (printedStats) {
|
|
48
|
-
console.error(printedStats);
|
|
49
|
-
}
|
|
50
|
-
next({
|
|
51
|
-
success: !stats.hasErrors(),
|
|
52
|
-
outfile: (0, path_1.resolve)(context.root, normalizedOptions.outputPath, 'main.js'),
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
registerCleanupCallback(() => {
|
|
56
|
-
watcher.close(() => {
|
|
57
|
-
devkit_1.logger.info('Watcher closed');
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
compiler.run(async (err, stats) => {
|
|
63
|
-
compiler.close(() => {
|
|
64
|
-
if (err) {
|
|
65
|
-
devkit_1.logger.error(err);
|
|
66
|
-
next({ success: false });
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (!compiler || !stats) {
|
|
70
|
-
devkit_1.logger.error(new Error('Compiler or stats not available'));
|
|
71
|
-
next({ success: false });
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const statsOptions = getStatsOptions(compiler);
|
|
75
|
-
const printedStats = stats.toString(statsOptions);
|
|
76
|
-
// Avoid extra empty line when `stats: 'none'`
|
|
77
|
-
if (printedStats) {
|
|
78
|
-
console.error(printedStats);
|
|
79
|
-
}
|
|
80
|
-
next({
|
|
81
|
-
success: !stats.hasErrors(),
|
|
82
|
-
outfile: (0, path_1.resolve)(context.root, normalizedOptions.outputPath, 'main.js'),
|
|
83
|
-
});
|
|
84
|
-
done();
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
yield* iterable;
|
|
90
|
-
}
|
|
91
|
-
// copied from packages/esbuild/src/executors/esbuild/esbuild.impl.ts
|
|
92
|
-
function registerCleanupCallback(callback) {
|
|
93
|
-
const wrapped = () => {
|
|
94
|
-
callback();
|
|
95
|
-
process.off('SIGINT', wrapped);
|
|
96
|
-
process.off('SIGTERM', wrapped);
|
|
97
|
-
process.off('exit', wrapped);
|
|
98
|
-
};
|
|
99
|
-
process.on('SIGINT', wrapped);
|
|
100
|
-
process.on('SIGTERM', wrapped);
|
|
101
|
-
process.on('exit', wrapped);
|
|
102
|
-
}
|
|
103
|
-
async function executeTypeCheck(options, context) {
|
|
104
|
-
const projectConfiguration = context.projectGraph.nodes[context.projectName].data;
|
|
105
|
-
const result = await (0, js_1.runTypeCheck)({
|
|
106
|
-
workspaceRoot: (0, path_1.resolve)(projectConfiguration.root),
|
|
107
|
-
tsConfigPath: options.tsConfig,
|
|
108
|
-
mode: 'noEmit',
|
|
109
|
-
// TS 6 defaults rootDir to the tsconfig dir, so from-source workspace
|
|
110
|
-
// libs (outside the project) trip TS6059. rootDir is emit-only and this
|
|
111
|
-
// is noEmit, so widen it to the workspace root to clear the false error.
|
|
112
|
-
rootDir: context.root,
|
|
113
|
-
});
|
|
114
|
-
await (0, js_1.printDiagnostics)(result.errors, result.warnings);
|
|
115
|
-
if (result.errors.length > 0) {
|
|
116
|
-
throw new Error('Found type errors. See above.');
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
function getStatsOptions(compiler) {
|
|
120
|
-
return (0, create_compiler_1.isMultiCompiler)(compiler)
|
|
121
|
-
? {
|
|
122
|
-
children: compiler.compilers.map((compiler) => compiler.options ? compiler.options.stats : undefined),
|
|
123
|
-
}
|
|
124
|
-
: compiler.options
|
|
125
|
-
? compiler.options.stats
|
|
126
|
-
: undefined;
|
|
127
|
-
}
|