@nx/react 18.0.4 → 18.0.5
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 +6 -6
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +15 -7
- package/src/generators/application/application.js +2 -1
- package/src/generators/application/files/nx-welcome/src/app/nx-welcome.tsx +1 -1
- package/src/generators/application/lib/add-e2e.js +2 -2
- package/src/generators/application/lib/add-project.d.ts +0 -1
- package/src/generators/application/lib/add-project.js +5 -10
- package/src/generators/application/lib/add-routing.d.ts +1 -1
- package/src/generators/application/lib/add-routing.js +4 -8
- package/src/generators/application/lib/create-application-files.js +3 -3
- package/src/generators/application/lib/update-jest-config.js +2 -1
- package/src/generators/federate-module/schema.json +2 -1
- package/src/generators/host/files/common/src/app/__fileName__.js__tmpl__ +33 -0
- package/src/generators/host/host.js +5 -1
- package/src/generators/host/lib/add-module-federation-files.d.ts +1 -1
- package/src/generators/host/lib/add-module-federation-files.js +3 -2
- package/src/generators/host/lib/update-module-federation-e2e-project.js +7 -5
- package/src/generators/host/schema.json +3 -2
- package/src/generators/library/lib/add-rollup-build-target.js +1 -1
- package/src/generators/library/lib/update-app-routes.js +1 -1
- package/src/generators/library/library.js +4 -3
- package/src/generators/remote/files/module-federation/module-federation.config.js__tmpl__ +1 -1
- package/src/generators/remote/files/module-federation-ssr/module-federation.server.config.js__tmpl__ +1 -1
- package/src/generators/remote/files/module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
- package/src/generators/remote/lib/setup-tspath-for-remote.js +2 -1
- package/src/generators/remote/lib/update-host-with-remote.js +10 -1
- package/src/generators/remote/remote.js +8 -2
- package/src/generators/remote/schema.json +3 -2
- package/src/rules/update-module-federation-project.d.ts +1 -0
- package/src/rules/update-module-federation-project.js +5 -4
- package/src/utils/maybe-js.d.ts +3 -0
- package/src/generators/library/lib/maybe-js.d.ts +0 -2
- /package/src/generators/host/files/{module-federation/src/main.ts__tmpl__ → common/src/main.js__tmpl__} +0 -0
- /package/src/generators/host/files/{common → common-ts}/src/app/__fileName__.tsx__tmpl__ +0 -0
- /package/src/generators/host/files/{module-federation-ts → common-ts}/src/main.ts__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation/src/main.ts__tmpl__ → common/src/main.js__tmpl__} +0 -0
- /package/src/generators/remote/files/{module-federation/src/remote-entry.ts__tmpl__ → common/src/remote-entry.js__tmpl__} +0 -0
- /package/src/generators/remote/files/{module-federation-ts → common-ts}/src/main.ts__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation-ts → common-ts}/src/remote-entry.ts__tmpl__ +0 -0
- /package/src/{generators/library/lib → utils}/maybe-js.js +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/react",
|
|
3
|
-
"version": "18.0.
|
|
3
|
+
"version": "18.0.5",
|
|
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": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"chalk": "^4.1.0",
|
|
37
37
|
"minimatch": "9.0.3",
|
|
38
38
|
"tslib": "^2.3.0",
|
|
39
|
-
"@nx/devkit": "18.0.
|
|
40
|
-
"@nx/js": "18.0.
|
|
41
|
-
"@nx/eslint": "18.0.
|
|
42
|
-
"@nx/web": "18.0.
|
|
43
|
-
"@nrwl/react": "18.0.
|
|
39
|
+
"@nx/devkit": "18.0.5",
|
|
40
|
+
"@nx/js": "18.0.5",
|
|
41
|
+
"@nx/eslint": "18.0.5",
|
|
42
|
+
"@nx/web": "18.0.5",
|
|
43
|
+
"@nrwl/react": "18.0.5"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
@@ -55,7 +55,7 @@ function startStaticRemotesFileServer(staticRemotesConfig, context, options) {
|
|
|
55
55
|
}, context);
|
|
56
56
|
return staticRemotesIter;
|
|
57
57
|
}
|
|
58
|
-
async function startDevRemotes(remotes, context) {
|
|
58
|
+
async function startDevRemotes(remotes, context, options) {
|
|
59
59
|
const devRemoteIters = [];
|
|
60
60
|
for (const app of remotes.devRemotes) {
|
|
61
61
|
const remoteProjectServeTarget = context.projectGraph.nodes[app].data.targets['serve'];
|
|
@@ -66,6 +66,10 @@ async function startDevRemotes(remotes, context) {
|
|
|
66
66
|
configuration: context.configurationName,
|
|
67
67
|
}, {
|
|
68
68
|
watch: true,
|
|
69
|
+
...(options.host ? { host: options.host } : {}),
|
|
70
|
+
...(options.ssl ? { ssl: options.ssl } : {}),
|
|
71
|
+
...(options.sslCert ? { sslCert: options.sslCert } : {}),
|
|
72
|
+
...(options.sslKey ? { sslKey: options.sslKey } : {}),
|
|
69
73
|
...(isUsingModuleFederationDevServerExecutor
|
|
70
74
|
? { isInitialHost: false }
|
|
71
75
|
: {}),
|
|
@@ -167,7 +171,7 @@ async function* moduleFederationDevServer(options, context) {
|
|
|
167
171
|
}
|
|
168
172
|
const staticRemotesConfig = parseStaticRemotesConfig(remotes.staticRemotes, context);
|
|
169
173
|
await buildStaticRemotes(staticRemotesConfig, nxBin, context, options);
|
|
170
|
-
const devRemoteIters = await startDevRemotes(remotes, context);
|
|
174
|
+
const devRemoteIters = await startDevRemotes(remotes, context, options);
|
|
171
175
|
const staticRemotesIter = remotes.staticRemotes.length > 0
|
|
172
176
|
? startStaticRemotesFileServer(staticRemotesConfig, context, options)
|
|
173
177
|
: undefined;
|
|
@@ -181,19 +185,23 @@ async function* moduleFederationDevServer(options, context) {
|
|
|
181
185
|
return;
|
|
182
186
|
}
|
|
183
187
|
try {
|
|
188
|
+
const host = options.host ?? 'localhost';
|
|
189
|
+
const baseUrl = `http${options.ssl ? 's' : ''}://${host}:${options.port}`;
|
|
184
190
|
const portsToWaitFor = staticRemotesIter
|
|
185
191
|
? [options.staticRemotesPort, ...remotes.remotePorts]
|
|
186
192
|
: [...remotes.remotePorts];
|
|
187
193
|
await Promise.all(portsToWaitFor.map((port) => (0, wait_for_port_open_1.waitForPortOpen)(port, {
|
|
188
194
|
retries: 480,
|
|
189
195
|
retryDelay: 2500,
|
|
190
|
-
host:
|
|
196
|
+
host: host,
|
|
191
197
|
})));
|
|
192
|
-
devkit_1.logger.info(`NX All remotes started, server ready at
|
|
193
|
-
next({ success: true, baseUrl:
|
|
198
|
+
devkit_1.logger.info(`NX All remotes started, server ready at ${baseUrl}`);
|
|
199
|
+
next({ success: true, baseUrl: baseUrl });
|
|
194
200
|
}
|
|
195
|
-
catch {
|
|
196
|
-
throw new Error(`
|
|
201
|
+
catch (err) {
|
|
202
|
+
throw new Error(`Failed to start remotes. Check above for any errors.`, {
|
|
203
|
+
cause: err,
|
|
204
|
+
});
|
|
197
205
|
}
|
|
198
206
|
finally {
|
|
199
207
|
done();
|
|
@@ -14,6 +14,7 @@ const devkit_1 = require("@nx/devkit");
|
|
|
14
14
|
const init_1 = require("../init/init");
|
|
15
15
|
const eslint_1 = require("@nx/eslint");
|
|
16
16
|
const versions_1 = require("../../utils/versions");
|
|
17
|
+
const maybe_js_1 = require("../../utils/maybe-js");
|
|
17
18
|
const install_common_dependencies_1 = require("./lib/install-common-dependencies");
|
|
18
19
|
const create_ts_config_1 = require("../../utils/create-ts-config");
|
|
19
20
|
const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
|
@@ -131,7 +132,7 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
131
132
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxRspackVersion);
|
|
132
133
|
const rspackTask = await configurationGenerator(host, {
|
|
133
134
|
project: options.projectName,
|
|
134
|
-
main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0,
|
|
135
|
+
main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/main.tsx`)),
|
|
135
136
|
tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
|
136
137
|
target: 'web',
|
|
137
138
|
newProject: true,
|
|
@@ -735,7 +735,7 @@ export function NxWelcome({ title }: { title: string }) {
|
|
|
735
735
|
You can activate distributed tasks executions and caching by
|
|
736
736
|
running:
|
|
737
737
|
</p>
|
|
738
|
-
<pre>nx connect
|
|
738
|
+
<pre>nx connect</pre>
|
|
739
739
|
<a
|
|
740
740
|
href="https://nx.app/?utm_source=nx-project"
|
|
741
741
|
target="_blank"
|
|
@@ -34,7 +34,7 @@ async function addE2e(tree, options) {
|
|
|
34
34
|
bundler: options.bundler === 'rspack' ? 'webpack' : options.bundler,
|
|
35
35
|
skipFormat: true,
|
|
36
36
|
devServerTarget: `${options.projectName}:serve`,
|
|
37
|
-
baseUrl:
|
|
37
|
+
baseUrl: `http://localhost:${options.devServerPort ?? 4200}`,
|
|
38
38
|
jsx: true,
|
|
39
39
|
rootProject: options.rootProject,
|
|
40
40
|
webServerCommands: hasNxBuildPlugin
|
|
@@ -66,7 +66,7 @@ async function addE2e(tree, options) {
|
|
|
66
66
|
linter: options.linter,
|
|
67
67
|
setParserOptionsProject: options.setParserOptionsProject,
|
|
68
68
|
webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx serve ${options.name}`,
|
|
69
|
-
webServerAddress:
|
|
69
|
+
webServerAddress: `http://localhost:${options.devServerPort ?? 4200}`,
|
|
70
70
|
rootProject: options.rootProject,
|
|
71
71
|
addPlugin: options.addPlugin,
|
|
72
72
|
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.addProject = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
|
|
6
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
6
7
|
function addProject(host, options) {
|
|
7
8
|
const project = {
|
|
8
9
|
root: options.appProjectRoot,
|
|
@@ -24,12 +25,6 @@ function addProject(host, options) {
|
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
27
|
exports.addProject = addProject;
|
|
27
|
-
function maybeJs(options, path) {
|
|
28
|
-
return options.js && (path.endsWith('.ts') || path.endsWith('.tsx'))
|
|
29
|
-
? path.replace(/\.tsx?$/, '.js')
|
|
30
|
-
: path;
|
|
31
|
-
}
|
|
32
|
-
exports.maybeJs = maybeJs;
|
|
33
28
|
function createBuildTarget(options) {
|
|
34
29
|
return {
|
|
35
30
|
executor: '@nx/webpack:webpack',
|
|
@@ -42,7 +37,7 @@ function createBuildTarget(options) {
|
|
|
42
37
|
: options.projectName),
|
|
43
38
|
index: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/index.html'),
|
|
44
39
|
baseHref: '/',
|
|
45
|
-
main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, maybeJs(options, `src/main.tsx`)),
|
|
40
|
+
main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/main.tsx`)),
|
|
46
41
|
tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
|
47
42
|
assets: [
|
|
48
43
|
(0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/favicon.ico'),
|
|
@@ -66,8 +61,8 @@ function createBuildTarget(options) {
|
|
|
66
61
|
production: {
|
|
67
62
|
fileReplacements: [
|
|
68
63
|
{
|
|
69
|
-
replace: (0, devkit_1.joinPathFragments)(options.appProjectRoot, maybeJs(options, `src/environments/environment.ts`)),
|
|
70
|
-
with: (0, devkit_1.joinPathFragments)(options.appProjectRoot, maybeJs(options, `src/environments/environment.prod.ts`)),
|
|
64
|
+
replace: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/environments/environment.ts`)),
|
|
65
|
+
with: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/environments/environment.prod.ts`)),
|
|
71
66
|
},
|
|
72
67
|
],
|
|
73
68
|
optimization: true,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addRouting = void 0;
|
|
4
|
-
const ast_utils_1 = require("../../../utils/ast-utils");
|
|
5
|
-
const versions_1 = require("../../../utils/versions");
|
|
6
4
|
const devkit_1 = require("@nx/devkit");
|
|
7
5
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
6
|
+
const ast_utils_1 = require("../../../utils/ast-utils");
|
|
7
|
+
const versions_1 = require("../../../utils/versions");
|
|
8
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
8
9
|
let tsModule;
|
|
9
10
|
function addRouting(host, options) {
|
|
10
11
|
if (!options.routing) {
|
|
@@ -13,7 +14,7 @@ function addRouting(host, options) {
|
|
|
13
14
|
if (!tsModule) {
|
|
14
15
|
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
15
16
|
}
|
|
16
|
-
const appPath = (0, devkit_1.joinPathFragments)(options.appProjectRoot, maybeJs(options, `src/app/${options.fileName}.tsx`));
|
|
17
|
+
const appPath = (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/app/${options.fileName}.tsx`));
|
|
17
18
|
const appFileContent = host.read(appPath, 'utf-8');
|
|
18
19
|
const appSource = tsModule.createSourceFile(appPath, appFileContent, tsModule.ScriptTarget.Latest, true);
|
|
19
20
|
const changes = (0, devkit_1.applyChangesToString)(appFileContent, (0, ast_utils_1.addInitialRoutes)(appPath, appSource));
|
|
@@ -24,8 +25,3 @@ function addRouting(host, options) {
|
|
|
24
25
|
return () => { };
|
|
25
26
|
}
|
|
26
27
|
exports.addRouting = addRouting;
|
|
27
|
-
function maybeJs(options, path) {
|
|
28
|
-
return options.js && (path.endsWith('.ts') || path.endsWith('.tsx'))
|
|
29
|
-
? path.replace(/\.tsx?$/, '.js')
|
|
30
|
-
: path;
|
|
31
|
-
}
|
|
@@ -6,9 +6,9 @@ const js_1 = require("@nx/js");
|
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const create_ts_config_1 = require("../../../utils/create-ts-config");
|
|
8
8
|
const get_in_source_vitest_tests_template_1 = require("../../../utils/get-in-source-vitest-tests-template");
|
|
9
|
-
const
|
|
10
|
-
const add_project_1 = require("./add-project");
|
|
9
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
11
10
|
const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
|
|
11
|
+
const get_app_tests_1 = require("./get-app-tests");
|
|
12
12
|
function createApplicationFiles(host, options) {
|
|
13
13
|
let styleSolutionSpecificAppFiles;
|
|
14
14
|
if (options.styledModule && options.style !== 'styled-jsx') {
|
|
@@ -128,7 +128,7 @@ function createNxWebpackPluginOptions(options) {
|
|
|
128
128
|
: options.projectName),
|
|
129
129
|
index: './src/index.html',
|
|
130
130
|
baseHref: '/',
|
|
131
|
-
main: (0,
|
|
131
|
+
main: (0, maybe_js_1.maybeJs)(options, `./src/main.tsx`),
|
|
132
132
|
tsConfig: './tsconfig.app.json',
|
|
133
133
|
assets: ['./src/favicon.ico', './src/assets'],
|
|
134
134
|
styles: options.styledModule || !options.hasStyles
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateSpecConfig = void 0;
|
|
4
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
4
5
|
const jest_utils_1 = require("../../../utils/jest-utils");
|
|
5
6
|
const devkit_1 = require("@nx/devkit");
|
|
6
7
|
function updateSpecConfig(host, options) {
|
|
@@ -21,7 +22,7 @@ function updateSpecConfig(host, options) {
|
|
|
21
22
|
if (options.unitTestRunner !== 'jest') {
|
|
22
23
|
return;
|
|
23
24
|
}
|
|
24
|
-
const configPath = `${options.appProjectRoot}/jest.config
|
|
25
|
+
const configPath = (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/jest.config.ts`);
|
|
25
26
|
const originalContent = host.read(configPath, 'utf-8');
|
|
26
27
|
const content = (0, jest_utils_1.updateJestConfigContent)(originalContent);
|
|
27
28
|
host.write(configPath, content);
|
|
@@ -69,7 +69,8 @@
|
|
|
69
69
|
"e2eTestRunner": {
|
|
70
70
|
"type": "string",
|
|
71
71
|
"enum": ["cypress", "playwright", "none"],
|
|
72
|
-
"description": "Test runner to use for end to end (
|
|
72
|
+
"description": "Test runner to use for end to end (E2E) tests.",
|
|
73
|
+
"x-prompt": "Which E2E test runner would you like to use?",
|
|
73
74
|
"default": "cypress"
|
|
74
75
|
},
|
|
75
76
|
"host": {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
<% if (!minimal) { %>
|
|
3
|
+
import NxWelcome from "./nx-welcome";
|
|
4
|
+
<% } %>
|
|
5
|
+
import { Link, Route, Routes } from 'react-router-dom';
|
|
6
|
+
|
|
7
|
+
<% if (remotes.length > 0) { %>
|
|
8
|
+
<% remotes.forEach(function(r) { %>
|
|
9
|
+
const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
|
|
10
|
+
<% }); %>
|
|
11
|
+
<% } %>
|
|
12
|
+
export function App() {
|
|
13
|
+
return (
|
|
14
|
+
<React.Suspense fallback={null}>
|
|
15
|
+
<ul>
|
|
16
|
+
<li><Link to="/">Home</Link></li>
|
|
17
|
+
<% remotes.forEach(function(r) { %>
|
|
18
|
+
<li><Link to="/<%=r.fileName%>"><%=r.className%></Link></li>
|
|
19
|
+
<% }); %>
|
|
20
|
+
</ul>
|
|
21
|
+
<Routes>
|
|
22
|
+
<% if (!minimal) { %>
|
|
23
|
+
<Route path="/" element={<NxWelcome title="<%= projectName %>"/>} />
|
|
24
|
+
<% } %>
|
|
25
|
+
<% remotes.forEach(function(r) { %>
|
|
26
|
+
<Route path="/<%=r.fileName%>" element={<<%= r.className %>/>} />
|
|
27
|
+
<% }); %>
|
|
28
|
+
</Routes>
|
|
29
|
+
</React.Suspense>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default App;
|
|
@@ -23,7 +23,10 @@ async function hostGeneratorInternal(host, schema) {
|
|
|
23
23
|
const tasks = [];
|
|
24
24
|
const options = {
|
|
25
25
|
...(await (0, normalize_options_1.normalizeOptions)(host, schema, '@nx/react:host')),
|
|
26
|
-
|
|
26
|
+
js: schema.js ?? false,
|
|
27
|
+
typescriptConfiguration: schema.js
|
|
28
|
+
? false
|
|
29
|
+
: schema.typescriptConfiguration ?? true,
|
|
27
30
|
dynamic: schema.dynamic ?? false,
|
|
28
31
|
// TODO(colum): remove when MF works with Crystal
|
|
29
32
|
addPlugin: false,
|
|
@@ -55,6 +58,7 @@ async function hostGeneratorInternal(host, schema) {
|
|
|
55
58
|
skipFormat: true,
|
|
56
59
|
projectNameAndRootFormat: options.projectNameAndRootFormat,
|
|
57
60
|
typescriptConfiguration: options.typescriptConfiguration,
|
|
61
|
+
js: options.js,
|
|
58
62
|
dynamic: options.dynamic,
|
|
59
63
|
host: options.name,
|
|
60
64
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NormalizedSchema } from '../schema';
|
|
2
1
|
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { NormalizedSchema } from '../schema';
|
|
3
3
|
export declare function addModuleFederationFiles(host: Tree, options: NormalizedSchema, defaultRemoteManifest: {
|
|
4
4
|
name: string;
|
|
5
5
|
port: number;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addModuleFederationFiles = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
5
6
|
function addModuleFederationFiles(host, options, defaultRemoteManifest) {
|
|
6
7
|
const templateVariables = {
|
|
7
8
|
...(0, devkit_1.names)(options.name),
|
|
@@ -20,8 +21,8 @@ function addModuleFederationFiles(host, options, defaultRemoteManifest) {
|
|
|
20
21
|
// Module federation requires bootstrap code to be dynamically imported.
|
|
21
22
|
// Renaming original entry file so we can use `import(./bootstrap)` in
|
|
22
23
|
// new entry file.
|
|
23
|
-
host.rename((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/main.tsx'), (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/bootstrap.tsx'));
|
|
24
|
-
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, `../files
|
|
24
|
+
host.rename((0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, 'src/main.tsx')), (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, 'src/bootstrap.tsx')));
|
|
25
|
+
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, `../files/${options.js ? 'common' : 'common-ts'}`), options.appProjectRoot, templateVariables);
|
|
25
26
|
const pathToModuleFederationFiles = options.typescriptConfiguration
|
|
26
27
|
? 'module-federation-ts'
|
|
27
28
|
: 'module-federation';
|
|
@@ -5,11 +5,13 @@ const devkit_1 = require("@nx/devkit");
|
|
|
5
5
|
function updateModuleFederationE2eProject(host, options) {
|
|
6
6
|
try {
|
|
7
7
|
let projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.e2eProjectName);
|
|
8
|
-
projectConfig.targets.e2e.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
if (projectConfig.targets.e2e.executor !== '@nx/playwright:playwright') {
|
|
9
|
+
projectConfig.targets.e2e.options = {
|
|
10
|
+
...projectConfig.targets.e2e.options,
|
|
11
|
+
baseUrl: `http://localhost:${options.devServerPort}`,
|
|
12
|
+
};
|
|
13
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.e2eProjectName, projectConfig);
|
|
14
|
+
}
|
|
13
15
|
}
|
|
14
16
|
catch {
|
|
15
17
|
// nothing
|
|
@@ -100,7 +100,8 @@
|
|
|
100
100
|
"e2eTestRunner": {
|
|
101
101
|
"type": "string",
|
|
102
102
|
"enum": ["cypress", "playwright", "none"],
|
|
103
|
-
"description": "Test runner to use for end to end (
|
|
103
|
+
"description": "Test runner to use for end to end (E2E) tests.",
|
|
104
|
+
"x-prompt": "Which E2E test runner would you like to use?",
|
|
104
105
|
"default": "cypress"
|
|
105
106
|
},
|
|
106
107
|
"tags": {
|
|
@@ -170,7 +171,7 @@
|
|
|
170
171
|
},
|
|
171
172
|
"typescriptConfiguration": {
|
|
172
173
|
"type": "boolean",
|
|
173
|
-
"description": "Whether the module federation configuration and webpack configuration files should use TS.",
|
|
174
|
+
"description": "Whether the module federation configuration and webpack configuration files should use TS. When --js is used, this flag is ignored.",
|
|
174
175
|
"default": true
|
|
175
176
|
}
|
|
176
177
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addRollupBuildTarget = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const maybe_js_1 = require("
|
|
5
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
6
6
|
const versions_1 = require("../../../utils/versions");
|
|
7
7
|
async function addRollupBuildTarget(host, options) {
|
|
8
8
|
const tasks = [];
|
|
@@ -4,7 +4,7 @@ exports.updateAppRoutes = void 0;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const ast_utils_1 = require("../../../utils/ast-utils");
|
|
6
6
|
const ast_utils_2 = require("../../../utils/ast-utils");
|
|
7
|
-
const maybe_js_1 = require("
|
|
7
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
8
8
|
const versions_1 = require("../../../utils/versions");
|
|
9
9
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
10
10
|
let tsModule;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.libraryGeneratorInternal = exports.libraryGenerator = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
4
5
|
const devkit_1 = require("@nx/devkit");
|
|
5
6
|
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
|
7
|
+
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
6
8
|
const js_1 = require("@nx/js");
|
|
7
9
|
const versions_1 = require("../../utils/versions");
|
|
10
|
+
const maybe_js_1 = require("../../utils/maybe-js");
|
|
8
11
|
const component_1 = require("../component/component");
|
|
9
12
|
const init_1 = require("../init/init");
|
|
10
13
|
const jest_utils_1 = require("../../utils/jest-utils");
|
|
@@ -16,8 +19,6 @@ const create_files_1 = require("./lib/create-files");
|
|
|
16
19
|
const create_ts_config_1 = require("../../utils/create-ts-config");
|
|
17
20
|
const install_common_dependencies_1 = require("./lib/install-common-dependencies");
|
|
18
21
|
const set_defaults_1 = require("./lib/set-defaults");
|
|
19
|
-
const path_1 = require("path");
|
|
20
|
-
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
21
22
|
async function libraryGenerator(host, schema) {
|
|
22
23
|
return await libraryGeneratorInternal(host, {
|
|
23
24
|
addPlugin: false,
|
|
@@ -177,7 +178,7 @@ async function libraryGeneratorInternal(host, schema) {
|
|
|
177
178
|
(0, create_ts_config_1.extractTsConfigBase)(host);
|
|
178
179
|
if (!options.skipTsConfig) {
|
|
179
180
|
(0, js_1.addTsConfigPath)(host, options.importPath, [
|
|
180
|
-
(0, devkit_1.joinPathFragments)(options.projectRoot, './src
|
|
181
|
+
(0, maybe_js_1.maybeJs)(options, (0, devkit_1.joinPathFragments)(options.projectRoot, './src/index.ts')),
|
|
181
182
|
]);
|
|
182
183
|
}
|
|
183
184
|
if (!options.skipFormat) {
|
|
@@ -3,7 +3,7 @@ import {ModuleFederationConfig} from '@nx/webpack';
|
|
|
3
3
|
const config: ModuleFederationConfig = {
|
|
4
4
|
name: '<%= projectName %>',
|
|
5
5
|
exposes: {
|
|
6
|
-
'./Module': '<%= appProjectRoot %>/src/remote-entry
|
|
6
|
+
'./Module': '<%= appProjectRoot %>/src/remote-entry.<%= js ? 'js' : 'ts' %>',
|
|
7
7
|
},
|
|
8
8
|
};
|
|
9
9
|
|
|
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.setupTspathForRemote = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const js_1 = require("@nx/js");
|
|
6
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
6
7
|
function setupTspathForRemote(tree, options) {
|
|
7
8
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.name);
|
|
8
|
-
const exportPath =
|
|
9
|
+
const exportPath = (0, maybe_js_1.maybeJs)(options, './src/remote-entry.ts');
|
|
9
10
|
const exportName = 'Module';
|
|
10
11
|
(0, js_1.addTsConfigPath)(tree, `${options.name}/${exportName}`, [
|
|
11
12
|
(0, devkit_1.joinPathFragments)(project.root, exportPath),
|
|
@@ -46,7 +46,16 @@ function updateHostWithRemote(host, hostName, remoteName) {
|
|
|
46
46
|
}
|
|
47
47
|
exports.updateHostWithRemote = updateHostWithRemote;
|
|
48
48
|
function findAppComponentPath(host, sourceRoot) {
|
|
49
|
-
const locations = [
|
|
49
|
+
const locations = [
|
|
50
|
+
'app/app.tsx',
|
|
51
|
+
'app/App.tsx',
|
|
52
|
+
'app/app.js',
|
|
53
|
+
'app/App.js',
|
|
54
|
+
'app.tsx',
|
|
55
|
+
'App.tsx',
|
|
56
|
+
'app.js',
|
|
57
|
+
'App.js',
|
|
58
|
+
];
|
|
50
59
|
for (const loc of locations) {
|
|
51
60
|
if (host.exists((0, devkit_1.joinPathFragments)(sourceRoot, loc))) {
|
|
52
61
|
return (0, devkit_1.joinPathFragments)(sourceRoot, loc);
|
|
@@ -12,12 +12,14 @@ const setup_ssr_for_remote_1 = require("./lib/setup-ssr-for-remote");
|
|
|
12
12
|
const setup_tspath_for_remote_1 = require("./lib/setup-tspath-for-remote");
|
|
13
13
|
const add_remote_to_dynamic_host_1 = require("./lib/add-remote-to-dynamic-host");
|
|
14
14
|
const add_mf_env_to_inputs_1 = require("../../utils/add-mf-env-to-inputs");
|
|
15
|
+
const maybe_js_1 = require("../../utils/maybe-js");
|
|
15
16
|
function addModuleFederationFiles(host, options) {
|
|
16
17
|
const templateVariables = {
|
|
17
18
|
...(0, devkit_1.names)(options.name),
|
|
18
19
|
...options,
|
|
19
20
|
tmpl: '',
|
|
20
21
|
};
|
|
22
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, `./files/${options.js ? 'common' : 'common-ts'}`), options.appProjectRoot, templateVariables);
|
|
21
23
|
const pathToModuleFederationFiles = options.typescriptConfiguration
|
|
22
24
|
? 'module-federation-ts'
|
|
23
25
|
: 'module-federation';
|
|
@@ -45,7 +47,11 @@ async function remoteGeneratorInternal(host, schema) {
|
|
|
45
47
|
const tasks = [];
|
|
46
48
|
const options = {
|
|
47
49
|
...(await (0, normalize_options_1.normalizeOptions)(host, schema, '@nx/react:remote')),
|
|
48
|
-
|
|
50
|
+
// when js is set to true, we want to use the js configuration
|
|
51
|
+
js: schema.js ?? false,
|
|
52
|
+
typescriptConfiguration: schema.js
|
|
53
|
+
? false
|
|
54
|
+
: schema.typescriptConfiguration ?? true,
|
|
49
55
|
dynamic: schema.dynamic ?? false,
|
|
50
56
|
// TODO(colum): remove when MF works with Crystal
|
|
51
57
|
addPlugin: false,
|
|
@@ -63,7 +69,7 @@ async function remoteGeneratorInternal(host, schema) {
|
|
|
63
69
|
// Module federation requires bootstrap code to be dynamically imported.
|
|
64
70
|
// Renaming original entry file so we can use `import(./bootstrap)` in
|
|
65
71
|
// new entry file.
|
|
66
|
-
host.rename((0, path_1.join)(options.appProjectRoot, 'src/main.tsx'), (0, path_1.join)(options.appProjectRoot, 'src/bootstrap.tsx'));
|
|
72
|
+
host.rename((0, path_1.join)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, 'src/main.tsx')), (0, path_1.join)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, 'src/bootstrap.tsx')));
|
|
67
73
|
addModuleFederationFiles(host, options);
|
|
68
74
|
(0, update_module_federation_project_1.updateModuleFederationProject)(host, options);
|
|
69
75
|
(0, setup_tspath_for_remote_1.setupTspathForRemote)(host, options);
|
|
@@ -106,7 +106,8 @@
|
|
|
106
106
|
"e2eTestRunner": {
|
|
107
107
|
"type": "string",
|
|
108
108
|
"enum": ["cypress", "playwright", "none"],
|
|
109
|
-
"description": "Test runner to use for end to end (
|
|
109
|
+
"description": "Test runner to use for end to end (E2E) tests.",
|
|
110
|
+
"x-prompt": "Which E2E test runner would you like to use?",
|
|
110
111
|
"default": "cypress"
|
|
111
112
|
},
|
|
112
113
|
"tags": {
|
|
@@ -169,7 +170,7 @@
|
|
|
169
170
|
},
|
|
170
171
|
"typescriptConfiguration": {
|
|
171
172
|
"type": "boolean",
|
|
172
|
-
"description": "Whether the module federation configuration and webpack configuration files should use TS.",
|
|
173
|
+
"description": "Whether the module federation configuration and webpack configuration files should use TS. When --js is used, this flag is ignored.",
|
|
173
174
|
"default": true
|
|
174
175
|
}
|
|
175
176
|
},
|
|
@@ -3,20 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.updateModuleFederationProject = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const versions_1 = require("../utils/versions");
|
|
6
|
+
const maybe_js_1 = require("../utils/maybe-js");
|
|
6
7
|
function updateModuleFederationProject(host, options) {
|
|
7
8
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
|
8
9
|
projectConfig.targets.build.options = {
|
|
9
10
|
...projectConfig.targets.build.options,
|
|
10
|
-
main: `${options.appProjectRoot}/src/main.ts
|
|
11
|
-
webpackConfig: `${options.appProjectRoot}/webpack.config.${options.typescriptConfiguration ? 'ts' : 'js'}`,
|
|
11
|
+
main: (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/src/main.ts`),
|
|
12
|
+
webpackConfig: `${options.appProjectRoot}/webpack.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
|
|
12
13
|
};
|
|
13
14
|
projectConfig.targets.build.configurations.production = {
|
|
14
15
|
...projectConfig.targets.build.configurations.production,
|
|
15
|
-
webpackConfig: `${options.appProjectRoot}/webpack.config.prod.${options.typescriptConfiguration ? 'ts' : 'js'}`,
|
|
16
|
+
webpackConfig: `${options.appProjectRoot}/webpack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
|
|
16
17
|
};
|
|
17
18
|
// If host should be configured to use dynamic federation
|
|
18
19
|
if (options.dynamic) {
|
|
19
|
-
const pathToProdWebpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `webpack.prod.config.${options.typescriptConfiguration ? 'ts' : 'js'}`);
|
|
20
|
+
const pathToProdWebpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `webpack.prod.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`);
|
|
20
21
|
if (host.exists(pathToProdWebpackConfig)) {
|
|
21
22
|
host.delete(pathToProdWebpackConfig);
|
|
22
23
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/src/generators/remote/files/{module-federation-ts → common-ts}/src/remote-entry.ts__tmpl__
RENAMED
|
File without changes
|
|
File without changes
|