@nx/react 18.1.0-beta.0 → 18.1.0-beta.1
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 +11 -5
- package/src/generators/application/application.js +9 -1
- package/src/generators/application/files/base-vite/index.html__tmpl__ +1 -1
- package/src/generators/application/files/nx-welcome/src/app/nx-welcome.tsx +1 -1
- package/src/generators/application/files/style-tailwind/src/app/__fileName__.tsx__tmpl__ +33 -0
- package/src/generators/application/files/style-tailwind/src/styles.css +1 -0
- 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 +9 -4
- package/src/generators/application/lib/normalize-options.js +1 -1
- package/src/generators/application/lib/update-jest-config.js +2 -1
- package/src/generators/application/schema.json +4 -0
- 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/schema.json +7 -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 +7 -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/assertion.js +1 -0
- package/src/utils/maybe-js.d.ts +3 -0
- package/typings/style.d.ts +1 -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.1.0-beta.
|
|
3
|
+
"version": "18.1.0-beta.1",
|
|
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.1.0-beta.
|
|
40
|
-
"@nx/js": "18.1.0-beta.
|
|
41
|
-
"@nx/eslint": "18.1.0-beta.
|
|
42
|
-
"@nx/web": "18.1.0-beta.
|
|
43
|
-
"@nrwl/react": "18.1.0-beta.
|
|
39
|
+
"@nx/devkit": "18.1.0-beta.1",
|
|
40
|
+
"@nx/js": "18.1.0-beta.1",
|
|
41
|
+
"@nx/eslint": "18.1.0-beta.1",
|
|
42
|
+
"@nx/web": "18.1.0-beta.1",
|
|
43
|
+
"@nrwl/react": "18.1.0-beta.1"
|
|
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,16 +185,18 @@ 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
201
|
catch {
|
|
196
202
|
throw new Error(`Timed out waiting for remote to start. Check above for any errors.`);
|
|
@@ -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");
|
|
@@ -23,6 +24,7 @@ const add_e2e_1 = require("./lib/add-e2e");
|
|
|
23
24
|
const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
|
|
24
25
|
const js_1 = require("@nx/js");
|
|
25
26
|
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
27
|
+
const setup_tailwind_1 = require("../setup-tailwind/setup-tailwind");
|
|
26
28
|
async function addLinting(host, options) {
|
|
27
29
|
const tasks = [];
|
|
28
30
|
if (options.linter === eslint_1.Linter.EsLint) {
|
|
@@ -91,6 +93,12 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
91
93
|
}
|
|
92
94
|
(0, create_application_files_1.createApplicationFiles)(host, options);
|
|
93
95
|
(0, add_project_1.addProject)(host, options);
|
|
96
|
+
if (options.style === 'tailwind') {
|
|
97
|
+
const twTask = await (0, setup_tailwind_1.setupTailwindGenerator)(host, {
|
|
98
|
+
project: options.projectName,
|
|
99
|
+
});
|
|
100
|
+
tasks.push(twTask);
|
|
101
|
+
}
|
|
94
102
|
if (options.bundler === 'vite') {
|
|
95
103
|
const { createOrEditViteConfig, viteConfigurationGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
96
104
|
// We recommend users use `import.meta.env.MODE` and other variables in their code to differentiate between production and development.
|
|
@@ -131,7 +139,7 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
131
139
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxRspackVersion);
|
|
132
140
|
const rspackTask = await configurationGenerator(host, {
|
|
133
141
|
project: options.projectName,
|
|
134
|
-
main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0,
|
|
142
|
+
main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/main.tsx`)),
|
|
135
143
|
tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
|
136
144
|
target: 'web',
|
|
137
145
|
newProject: true,
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
9
9
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
|
10
|
-
<% if (!styledModule && style !== 'none') { %><link rel="stylesheet" href="/src/styles.<%= style %>" /><% } %>
|
|
10
|
+
<% if (!styledModule && style !== 'none') { %><link rel="stylesheet" href="/src/styles.<%= style === 'tailwind' ? 'css' : style %>" /><% } %>
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
13
13
|
<div id="root"></div>
|
|
@@ -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"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<% if (classComponent) { %>
|
|
2
|
+
import { Component } from 'react';
|
|
3
|
+
<% } if (!minimal) { %>
|
|
4
|
+
import NxWelcome from "./nx-welcome";
|
|
5
|
+
<% } %>
|
|
6
|
+
|
|
7
|
+
<% if (classComponent) { %>
|
|
8
|
+
export class App extends Component {
|
|
9
|
+
render() {
|
|
10
|
+
<% } else { %>
|
|
11
|
+
export function App() {
|
|
12
|
+
<% } %>
|
|
13
|
+
return (
|
|
14
|
+
<div>
|
|
15
|
+
<% if (!minimal) { %>
|
|
16
|
+
<NxWelcome title="<%= projectName %>"/>
|
|
17
|
+
<% } else { %>
|
|
18
|
+
<h1>
|
|
19
|
+
<span> Hello there, </span>
|
|
20
|
+
Welcome <%= projectName %> 👋
|
|
21
|
+
</h1>
|
|
22
|
+
<% } %>
|
|
23
|
+
</div>);
|
|
24
|
+
<% if (classComponent) { %>
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
<% } else { %>
|
|
28
|
+
}
|
|
29
|
+
<% } %>
|
|
30
|
+
|
|
31
|
+
export default App;
|
|
32
|
+
|
|
33
|
+
<% if (inSourceTests === true) { %> <%- inSourceVitestTests %> <% } %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/* You can add global styles to this file, and also import other style files */
|
|
@@ -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') {
|
|
@@ -17,6 +17,9 @@ function createApplicationFiles(host, options) {
|
|
|
17
17
|
else if (options.style === 'styled-jsx') {
|
|
18
18
|
styleSolutionSpecificAppFiles = '../files/style-styled-jsx';
|
|
19
19
|
}
|
|
20
|
+
else if (options.style === 'tailwind') {
|
|
21
|
+
styleSolutionSpecificAppFiles = '../files/style-tailwind';
|
|
22
|
+
}
|
|
20
23
|
else if (options.style === 'none') {
|
|
21
24
|
styleSolutionSpecificAppFiles = '../files/style-none';
|
|
22
25
|
}
|
|
@@ -128,11 +131,13 @@ function createNxWebpackPluginOptions(options) {
|
|
|
128
131
|
: options.projectName),
|
|
129
132
|
index: './src/index.html',
|
|
130
133
|
baseHref: '/',
|
|
131
|
-
main: (0,
|
|
134
|
+
main: (0, maybe_js_1.maybeJs)(options, `./src/main.tsx`),
|
|
132
135
|
tsConfig: './tsconfig.app.json',
|
|
133
136
|
assets: ['./src/favicon.ico', './src/assets'],
|
|
134
137
|
styles: options.styledModule || !options.hasStyles
|
|
135
138
|
? []
|
|
136
|
-
: [
|
|
139
|
+
: [
|
|
140
|
+
`./src/styles.${options.style !== 'tailwind' ? options.style : 'css'}`,
|
|
141
|
+
],
|
|
137
142
|
};
|
|
138
143
|
}
|
|
@@ -35,7 +35,7 @@ async function normalizeOptions(host, options, callingGenerator = '@nx/react:app
|
|
|
35
35
|
? options.tags.split(',').map((s) => s.trim())
|
|
36
36
|
: [];
|
|
37
37
|
const fileName = options.pascalCaseFiles ? 'App' : 'app';
|
|
38
|
-
const styledModule = /^(css|scss|less|none)$/.test(options.style)
|
|
38
|
+
const styledModule = /^(css|scss|less|tailwind|none)$/.test(options.style)
|
|
39
39
|
? null
|
|
40
40
|
: options.style;
|
|
41
41
|
(0, assertion_1.assertValidStyle)(options.style);
|
|
@@ -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);
|
|
@@ -62,6 +62,10 @@
|
|
|
62
62
|
"value": "less",
|
|
63
63
|
"label": "LESS [ https://lesscss.org ]"
|
|
64
64
|
},
|
|
65
|
+
{
|
|
66
|
+
"value": "tailwind",
|
|
67
|
+
"label": "tailwind [ https://tailwindcss.com/ ]"
|
|
68
|
+
},
|
|
65
69
|
{
|
|
66
70
|
"value": "styled-components",
|
|
67
71
|
"label": "styled-components [ https://styled-components.com ]"
|
|
@@ -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';
|
|
@@ -49,6 +49,10 @@
|
|
|
49
49
|
"value": "less",
|
|
50
50
|
"label": "LESS [ https://lesscss.org ]"
|
|
51
51
|
},
|
|
52
|
+
{
|
|
53
|
+
"value": "tailwind",
|
|
54
|
+
"label": "tailwind [ https://tailwindcss.com/ ]"
|
|
55
|
+
},
|
|
52
56
|
{
|
|
53
57
|
"value": "styled-components",
|
|
54
58
|
"label": "styled-components [ https://styled-components.com ]"
|
|
@@ -100,7 +104,8 @@
|
|
|
100
104
|
"e2eTestRunner": {
|
|
101
105
|
"type": "string",
|
|
102
106
|
"enum": ["cypress", "playwright", "none"],
|
|
103
|
-
"description": "Test runner to use for end to end (
|
|
107
|
+
"description": "Test runner to use for end to end (E2E) tests.",
|
|
108
|
+
"x-prompt": "Which E2E test runner would you like to use?",
|
|
104
109
|
"default": "cypress"
|
|
105
110
|
},
|
|
106
111
|
"tags": {
|
|
@@ -170,7 +175,7 @@
|
|
|
170
175
|
},
|
|
171
176
|
"typescriptConfiguration": {
|
|
172
177
|
"type": "boolean",
|
|
173
|
-
"description": "Whether the module federation configuration and webpack configuration files should use TS.",
|
|
178
|
+
"description": "Whether the module federation configuration and webpack configuration files should use TS. When --js is used, this flag is ignored.",
|
|
174
179
|
"default": true
|
|
175
180
|
}
|
|
176
181
|
},
|
|
@@ -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);
|
|
@@ -55,6 +55,10 @@
|
|
|
55
55
|
"value": "less",
|
|
56
56
|
"label": "LESS [ https://lesscss.org ]"
|
|
57
57
|
},
|
|
58
|
+
{
|
|
59
|
+
"value": "tailwind",
|
|
60
|
+
"label": "tailwind [ https://tailwindcss.com/ ]"
|
|
61
|
+
},
|
|
58
62
|
{
|
|
59
63
|
"value": "styled-components",
|
|
60
64
|
"label": "styled-components [ https://styled-components.com ]"
|
|
@@ -106,7 +110,8 @@
|
|
|
106
110
|
"e2eTestRunner": {
|
|
107
111
|
"type": "string",
|
|
108
112
|
"enum": ["cypress", "playwright", "none"],
|
|
109
|
-
"description": "Test runner to use for end to end (
|
|
113
|
+
"description": "Test runner to use for end to end (E2E) tests.",
|
|
114
|
+
"x-prompt": "Which E2E test runner would you like to use?",
|
|
110
115
|
"default": "cypress"
|
|
111
116
|
},
|
|
112
117
|
"tags": {
|
|
@@ -169,7 +174,7 @@
|
|
|
169
174
|
},
|
|
170
175
|
"typescriptConfiguration": {
|
|
171
176
|
"type": "boolean",
|
|
172
|
-
"description": "Whether the module federation configuration and webpack configuration files should use TS.",
|
|
177
|
+
"description": "Whether the module federation configuration and webpack configuration files should use TS. When --js is used, this flag is ignored.",
|
|
173
178
|
"default": true
|
|
174
179
|
}
|
|
175
180
|
},
|
|
@@ -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
|
}
|
package/src/utils/assertion.js
CHANGED
package/typings/style.d.ts
CHANGED
|
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
|