@nx/react 17.0.0-beta.8 → 17.0.0-rc.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/react",
|
|
3
|
-
"version": "17.0.0-
|
|
3
|
+
"version": "17.0.0-rc.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
|
|
6
6
|
"repository": {
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"file-loader": "^6.2.0",
|
|
38
38
|
"minimatch": "3.0.5",
|
|
39
39
|
"tslib": "^2.3.0",
|
|
40
|
-
"@nx/devkit": "17.0.0-
|
|
41
|
-
"@nx/js": "17.0.0-
|
|
42
|
-
"@nx/eslint": "17.0.0-
|
|
43
|
-
"@nx/web": "17.0.0-
|
|
44
|
-
"@nrwl/react": "17.0.0-
|
|
40
|
+
"@nx/devkit": "17.0.0-rc.0",
|
|
41
|
+
"@nx/js": "17.0.0-rc.0",
|
|
42
|
+
"@nx/eslint": "17.0.0-rc.0",
|
|
43
|
+
"@nx/web": "17.0.0-rc.0",
|
|
44
|
+
"@nrwl/react": "17.0.0-rc.0"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
import { WebDevServerOptions } from '@nx/webpack/src/executors/dev-server/schema';
|
|
3
3
|
type ModuleFederationDevServerOptions = WebDevServerOptions & {
|
|
4
|
-
devRemotes?: string
|
|
4
|
+
devRemotes?: string[];
|
|
5
5
|
skipRemotes?: string[];
|
|
6
|
+
static?: boolean;
|
|
7
|
+
isInitialHost?: boolean;
|
|
6
8
|
};
|
|
7
9
|
export default function moduleFederationDevServer(options: ModuleFederationDevServerOptions, context: ExecutorContext): AsyncIterableIterator<{
|
|
8
10
|
success: boolean;
|
|
@@ -2,14 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const devkit_1 = require("@nx/devkit");
|
|
4
4
|
const dev_server_impl_1 = require("@nx/webpack/src/executors/dev-server/dev-server.impl");
|
|
5
|
-
const
|
|
5
|
+
const file_server_impl_1 = require("@nx/web/src/executors/file-server/file-server.impl");
|
|
6
|
+
const module_federation_1 = require("@nx/webpack/src/utils/module-federation");
|
|
6
7
|
const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
|
|
7
|
-
const chalk = require("chalk");
|
|
8
8
|
const wait_for_port_open_1 = require("@nx/web/src/utils/wait-for-port-open");
|
|
9
|
-
const find_matching_projects_1 = require("nx/src/utils/find-matching-projects");
|
|
10
9
|
const child_process_1 = require("child_process");
|
|
11
|
-
const fs_1 = require("fs");
|
|
12
|
-
const internal_1 = require("@nx/js/src/internal");
|
|
13
10
|
function getBuildOptions(buildTarget, context) {
|
|
14
11
|
const target = (0, devkit_1.parseTargetString)(buildTarget, context);
|
|
15
12
|
const buildOptions = (0, devkit_1.readTargetOptions)(target, context);
|
|
@@ -17,111 +14,88 @@ function getBuildOptions(buildTarget, context) {
|
|
|
17
14
|
...buildOptions,
|
|
18
15
|
};
|
|
19
16
|
}
|
|
20
|
-
function getModuleFederationConfig(tsconfigPath, workspaceRoot, projectRoot) {
|
|
21
|
-
const moduleFederationConfigPathJS = (0, path_1.join)(workspaceRoot, projectRoot, 'module-federation.config.js');
|
|
22
|
-
const moduleFederationConfigPathTS = (0, path_1.join)(workspaceRoot, projectRoot, 'module-federation.config.ts');
|
|
23
|
-
let moduleFederationConfigPath = moduleFederationConfigPathJS;
|
|
24
|
-
// create a no-op so this can be called with issue
|
|
25
|
-
const fullTSconfigPath = tsconfigPath.startsWith(workspaceRoot)
|
|
26
|
-
? tsconfigPath
|
|
27
|
-
: (0, path_1.join)(workspaceRoot, tsconfigPath);
|
|
28
|
-
let cleanupTranspiler = () => { };
|
|
29
|
-
if ((0, fs_1.existsSync)(moduleFederationConfigPathTS)) {
|
|
30
|
-
cleanupTranspiler = (0, internal_1.registerTsProject)(fullTSconfigPath);
|
|
31
|
-
moduleFederationConfigPath = moduleFederationConfigPathTS;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
const config = require(moduleFederationConfigPath);
|
|
35
|
-
cleanupTranspiler();
|
|
36
|
-
return config.default || config;
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
throw new Error(`Could not load ${moduleFederationConfigPath}. Was this project generated with "@nx/react:host"?\nSee: https://nx.dev/concepts/more-concepts/faster-builds-with-module-federation`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
17
|
async function* moduleFederationDevServer(options, context) {
|
|
43
18
|
const nxBin = require.resolve('nx');
|
|
44
|
-
const currIter =
|
|
19
|
+
const currIter = options.static
|
|
20
|
+
? (0, file_server_impl_1.default)({
|
|
21
|
+
...options,
|
|
22
|
+
parallel: false,
|
|
23
|
+
withDeps: false,
|
|
24
|
+
spa: false,
|
|
25
|
+
cors: true,
|
|
26
|
+
}, context)
|
|
27
|
+
: (0, dev_server_impl_1.default)(options, context);
|
|
45
28
|
const p = context.projectsConfigurations.projects[context.projectName];
|
|
46
29
|
const buildOptions = getBuildOptions(options.buildTarget, context);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (remotesToSkip.size > 0) {
|
|
50
|
-
devkit_1.logger.info(`Remotes not served automatically: ${[...remotesToSkip.values()].join(', ')}`);
|
|
30
|
+
if (!options.isInitialHost) {
|
|
31
|
+
return yield* currIter;
|
|
51
32
|
}
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
else if (!context.projectGraph.nodes[validRemote]) {
|
|
59
|
-
remotesNotInWorkspace.push(validRemote);
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
33
|
+
const moduleFederationConfig = (0, module_federation_1.getModuleFederationConfig)(buildOptions.tsConfig, context.root, p.root, 'react');
|
|
34
|
+
const remotes = (0, module_federation_1.getRemotes)(options.devRemotes, options.skipRemotes, moduleFederationConfig, {
|
|
35
|
+
projectName: context.projectName,
|
|
36
|
+
projectGraph: context.projectGraph,
|
|
37
|
+
root: context.root,
|
|
65
38
|
});
|
|
66
|
-
if (remotesNotInWorkspace.length > 0) {
|
|
67
|
-
devkit_1.logger.warn(`Skipping serving ${remotesNotInWorkspace.join(', ')} as they could not be found in the workspace. Ensure they are served correctly.`);
|
|
68
|
-
}
|
|
69
|
-
const remotePorts = knownRemotes.map((r) => context.projectGraph.nodes[r].data.targets['serve'].options.port);
|
|
70
|
-
const devServeApps = !options.devRemotes
|
|
71
|
-
? []
|
|
72
|
-
: Array.isArray(options.devRemotes)
|
|
73
|
-
? (0, find_matching_projects_1.findMatchingProjects)(options.devRemotes, context.projectGraph.nodes)
|
|
74
|
-
: (0, find_matching_projects_1.findMatchingProjects)([options.devRemotes], context.projectGraph.nodes);
|
|
75
|
-
devkit_1.logger.info(`NX Starting module federation dev-server for ${chalk.bold(context.projectName)} with ${knownRemotes.length} remotes`);
|
|
76
|
-
const devRemoteIters = [];
|
|
77
39
|
let isCollectingStaticRemoteOutput = true;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
40
|
+
const devRemoteIters = [];
|
|
41
|
+
for (const app of remotes.devRemotes) {
|
|
42
|
+
const remoteProjectServeTarget = context.projectGraph.nodes[app].data.targets['serve'];
|
|
43
|
+
const isUsingModuleFederationDevServerExecutor = remoteProjectServeTarget.executor.includes('module-federation-dev-server');
|
|
44
|
+
devRemoteIters.push(await (0, devkit_1.runExecutor)({
|
|
45
|
+
project: app,
|
|
46
|
+
target: 'serve',
|
|
47
|
+
configuration: context.configurationName,
|
|
48
|
+
}, {
|
|
49
|
+
watch: true,
|
|
50
|
+
...(isUsingModuleFederationDevServerExecutor
|
|
51
|
+
? { isInitialHost: false }
|
|
52
|
+
: {}),
|
|
53
|
+
}, context));
|
|
54
|
+
}
|
|
55
|
+
for (const app of remotes.staticRemotes) {
|
|
56
|
+
const remoteProjectServeTarget = context.projectGraph.nodes[app].data.targets['serve-static'];
|
|
57
|
+
const isUsingModuleFederationDevServerExecutor = remoteProjectServeTarget.executor.includes('module-federation-dev-server');
|
|
58
|
+
let outWithErr = [];
|
|
59
|
+
const staticProcess = (0, child_process_1.fork)(nxBin, [
|
|
60
|
+
'run',
|
|
61
|
+
`${app}:serve-static${context.configurationName ? `:${context.configurationName}` : ''}`,
|
|
62
|
+
...(isUsingModuleFederationDevServerExecutor
|
|
63
|
+
? [`--isInitialHost=false`]
|
|
64
|
+
: []),
|
|
65
|
+
], {
|
|
66
|
+
cwd: context.root,
|
|
67
|
+
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
|
|
68
|
+
});
|
|
69
|
+
staticProcess.stdout.on('data', (data) => {
|
|
70
|
+
if (isCollectingStaticRemoteOutput) {
|
|
71
|
+
outWithErr.push(data.toString());
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
outWithErr = null;
|
|
75
|
+
staticProcess.stdout.removeAllListeners('data');
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
staticProcess.stderr.on('data', (data) => devkit_1.logger.info(data.toString()));
|
|
79
|
+
staticProcess.on('exit', (code) => {
|
|
80
|
+
if (code !== 0) {
|
|
81
|
+
devkit_1.logger.info(outWithErr.join(''));
|
|
82
|
+
throw new Error(`Remote failed to start. See above for errors.`);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
process.on('SIGTERM', () => staticProcess.kill('SIGTERM'));
|
|
86
|
+
process.on('exit', () => staticProcess.kill('SIGTERM'));
|
|
117
87
|
}
|
|
118
88
|
return yield* (0, async_iterable_1.combineAsyncIterables)(currIter, ...devRemoteIters, (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
|
|
119
|
-
if (
|
|
89
|
+
if (!options.isInitialHost) {
|
|
90
|
+
done();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (remotes.remotePorts.length === 0) {
|
|
120
94
|
done();
|
|
121
95
|
return;
|
|
122
96
|
}
|
|
123
97
|
try {
|
|
124
|
-
await Promise.all(remotePorts.map((port) =>
|
|
98
|
+
await Promise.all(remotes.remotePorts.map((port) =>
|
|
125
99
|
// Allow 20 minutes for each remote to start, which is plenty of time but we can tweak it later if needed.
|
|
126
100
|
// Most remotes should start in under 1 minute.
|
|
127
101
|
(0, wait_for_port_open_1.waitForPortOpen)(port, {
|
|
@@ -91,6 +91,16 @@
|
|
|
91
91
|
"baseHref": {
|
|
92
92
|
"type": "string",
|
|
93
93
|
"description": "Base url for the application being built."
|
|
94
|
+
},
|
|
95
|
+
"static": {
|
|
96
|
+
"type": "boolean",
|
|
97
|
+
"description": "Whether to use a static file server instead of the webpack-dev-server. This should be used for remote applications that are also host applications."
|
|
98
|
+
},
|
|
99
|
+
"isInitialHost": {
|
|
100
|
+
"type": "boolean",
|
|
101
|
+
"description": "Whether the host that is running this executor is the first in the project tree to do so.",
|
|
102
|
+
"default": true,
|
|
103
|
+
"x-priority": "internal"
|
|
94
104
|
}
|
|
95
105
|
}
|
|
96
106
|
}
|