@nx/react 21.0.0-beta.0 → 21.0.0-beta.10
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/migrations.json +0 -38
- package/package.json +6 -6
- package/plugins/nx-react-webpack-plugin/lib/apply-react-config.js +3 -1
- package/router-plugin.d.ts +1 -0
- package/router-plugin.js +5 -0
- package/src/executors/module-federation-dev-server/schema.json +1 -0
- package/src/executors/module-federation-ssr-dev-server/schema.json +1 -0
- package/src/executors/module-federation-static-server/schema.json +1 -0
- package/src/generators/application/application.js +52 -15
- package/src/generators/application/files/react-router-ssr/common/app/app-nav.tsx__tmpl__ +14 -0
- package/src/generators/application/files/react-router-ssr/common/app/entry.client.tsx__tmpl__ +18 -0
- package/src/generators/application/files/react-router-ssr/common/app/entry.server.tsx__tmpl__ +74 -0
- package/src/generators/application/files/react-router-ssr/common/app/root.tsx__tmpl__ +51 -0
- package/src/generators/application/files/react-router-ssr/common/app/routes/about.tsx__tmpl__ +7 -0
- package/src/generators/application/files/react-router-ssr/common/app/routes.tsx__tmpl__ +6 -0
- package/src/generators/application/files/react-router-ssr/common/public/favicon.ico +0 -0
- package/src/generators/application/files/react-router-ssr/common/react-router.config.ts__tmpl__ +5 -0
- package/src/generators/application/files/react-router-ssr/common/tests/routes/_index.spec.tsx__tmpl__ +16 -0
- package/src/generators/application/files/react-router-ssr/common/tsconfig.app.json__tmpl__ +23 -0
- package/src/generators/application/files/react-router-ssr/common/tsconfig.json__tmpl__ +27 -0
- package/src/generators/application/files/react-router-ssr/non-root/.gitignore__tmpl__ +5 -0
- package/src/generators/application/files/react-router-ssr/non-root/package.json__tmpl__ +24 -0
- package/src/generators/application/files/react-router-ssr/nx-welcome/claimed/app/nx-welcome.tsx__tmpl__ +866 -0
- package/src/generators/application/files/react-router-ssr/nx-welcome/not-configured/app/nx-welcome.tsx__tmpl__ +866 -0
- package/src/generators/application/files/react-router-ssr/nx-welcome/unclaimed/app/nx-welcome.tsx__tmpl__ +864 -0
- package/src/generators/application/files/react-router-ssr/ts-solution/package.json__tmpl__ +24 -0
- package/src/generators/application/files/react-router-ssr/ts-solution/tsconfig.app.json__tmpl__ +39 -0
- package/src/generators/application/lib/add-e2e.js +38 -71
- package/src/generators/application/lib/add-jest.js +26 -2
- package/src/generators/application/lib/add-linting.d.ts +1 -0
- package/src/generators/application/lib/add-linting.js +38 -0
- package/src/generators/application/lib/add-project.js +31 -15
- package/src/generators/application/lib/add-routing.js +1 -1
- package/src/generators/application/lib/bundlers/add-rspack.d.ts +0 -1
- package/src/generators/application/lib/bundlers/add-rspack.js +0 -18
- package/src/generators/application/lib/bundlers/add-vite.js +15 -6
- package/src/generators/application/lib/create-application-files.d.ts +61 -0
- package/src/generators/application/lib/create-application-files.js +81 -39
- package/src/generators/application/lib/get-app-tests.js +3 -3
- package/src/generators/application/lib/install-common-dependencies.js +13 -2
- package/src/generators/application/lib/normalize-options.d.ts +0 -2
- package/src/generators/application/lib/normalize-options.js +14 -20
- package/src/generators/application/schema.d.ts +5 -1
- package/src/generators/application/schema.json +10 -1
- package/src/generators/component-test/component-test.js +1 -1
- package/src/generators/cypress-component-configuration/lib/add-files.d.ts +1 -1
- package/src/generators/cypress-component-configuration/lib/add-files.js +7 -4
- package/src/generators/host/files/rspack-module-federation/rspack.config.js__tmpl__ +37 -13
- package/src/generators/host/files/rspack-module-federation/rspack.config.prod.js__tmpl__ +60 -32
- package/src/generators/host/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +6 -0
- package/src/generators/host/files/rspack-module-federation-ssr/rspack.config.js__tmpl__ +66 -0
- package/src/generators/host/files/rspack-module-federation-ssr/server.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__ +49 -0
- package/src/generators/host/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +6 -0
- package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +66 -0
- package/src/generators/host/files/rspack-module-federation-ssr-ts/server.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__ +49 -0
- package/src/generators/host/files/rspack-module-federation-ts/rspack.config.prod.ts__tmpl__ +37 -9
- package/src/generators/host/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +37 -14
- package/src/generators/host/host.js +21 -18
- package/src/generators/host/lib/add-module-federation-files.js +28 -12
- package/src/generators/host/lib/normalize-host-name.d.ts +2 -0
- package/src/generators/host/lib/normalize-host-name.js +12 -0
- package/src/generators/host/lib/setup-ssr-for-host.d.ts +3 -3
- package/src/generators/host/lib/setup-ssr-for-host.js +46 -22
- package/src/generators/init/init.js +23 -0
- package/src/generators/init/schema.d.ts +2 -0
- package/src/generators/library/lib/add-rollup-build-target.d.ts +3 -1
- package/src/generators/library/lib/add-rollup-build-target.js +6 -7
- package/src/generators/library/lib/create-files.js +2 -1
- package/src/generators/library/lib/normalize-options.js +8 -5
- package/src/generators/library/library.js +44 -30
- package/src/generators/library/schema.d.ts +2 -0
- package/src/generators/library/schema.json +8 -4
- package/src/generators/remote/files/rspack-module-federation/rspack.config.js__tmpl__ +40 -13
- package/src/generators/remote/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +6 -0
- package/src/generators/remote/files/rspack-module-federation-ssr/rspack.config.js__tmpl__ +69 -0
- package/src/generators/remote/files/rspack-module-federation-ssr/server.ts__tmpl__ +2 -2
- package/src/generators/remote/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__ +45 -0
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +6 -0
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +69 -0
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/server.ts__tmpl__ +2 -2
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__ +45 -0
- package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +40 -13
- package/src/generators/remote/lib/setup-ssr-for-remote.d.ts +1 -1
- package/src/generators/remote/lib/setup-ssr-for-remote.js +37 -15
- package/src/generators/remote/remote.js +46 -30
- package/src/plugins/router-plugin.d.ts +10 -0
- package/src/plugins/router-plugin.js +221 -0
- package/src/rules/update-module-federation-project.d.ts +2 -1
- package/src/rules/update-module-federation-project.js +28 -47
- package/src/utils/assertion.d.ts +2 -0
- package/src/utils/assertion.js +6 -0
- package/src/utils/ast-utils.d.ts +1 -1
- package/src/utils/ast-utils.js +2 -2
- package/src/utils/ct-utils.d.ts +1 -1
- package/src/utils/versions.d.ts +6 -4
- package/src/utils/versions.js +9 -6
- package/src/generators/host/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +0 -16
- package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +0 -16
- package/src/generators/remote/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +0 -16
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +0 -16
- package/src/migrations/update-18-1-1/fix-target-defaults-inputs.d.ts +0 -2
- package/src/migrations/update-18-1-1/fix-target-defaults-inputs.js +0 -53
- package/src/utils/format-file.d.ts +0 -1
- package/src/utils/format-file.js +0 -11
@@ -2,39 +2,61 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.setupSsrForRemote = setupSsrForRemote;
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
|
+
const devkit_2 = require("@nx/devkit");
|
5
6
|
const versions_1 = require("../../../utils/versions");
|
7
|
+
const create_application_files_1 = require("../../application/lib/create-application-files");
|
6
8
|
async function setupSsrForRemote(tree, options, appName) {
|
7
9
|
const tasks = [];
|
8
|
-
const project = (0,
|
10
|
+
const project = (0, devkit_2.readProjectConfiguration)(tree, appName);
|
9
11
|
const pathToModuleFederationSsrFiles = options.typescriptConfiguration
|
10
12
|
? `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation-ssr-ts`
|
11
13
|
: `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation-ssr`;
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
const templateVariables = options.bundler === 'rspack'
|
15
|
+
? {
|
16
|
+
...(0, create_application_files_1.getDefaultTemplateVariables)(tree, options),
|
17
|
+
rspackPluginOptions: {
|
18
|
+
...(0, create_application_files_1.createNxRspackPluginOptions)(options, (0, devkit_1.offsetFromRoot)(options.appProjectRoot), false),
|
19
|
+
mainServer: `./server.ts`,
|
20
|
+
},
|
21
|
+
port: Number(options?.devServerPort) || 4200,
|
22
|
+
appName,
|
23
|
+
}
|
24
|
+
: {
|
25
|
+
...options,
|
26
|
+
port: Number(options?.devServerPort) || 4200,
|
27
|
+
appName,
|
28
|
+
tmpl: '',
|
29
|
+
browserBuildOutputPath: project.targets.build?.options?.outputPath,
|
30
|
+
serverBuildOutputPath: project.targets.server?.options?.outputPath,
|
31
|
+
};
|
32
|
+
(0, devkit_2.generateFiles)(tree, (0, devkit_2.joinPathFragments)(__dirname, `../files/${pathToModuleFederationSsrFiles}`), project.root, templateVariables);
|
20
33
|
// For hosts to use when running remotes in static mode.
|
21
|
-
const originalOutputPath = project.targets.build?.options?.outputPath
|
34
|
+
const originalOutputPath = project.targets.build?.options?.outputPath ??
|
35
|
+
options.isUsingTsSolutionConfig
|
36
|
+
? 'dist'
|
37
|
+
: (0, devkit_2.joinPathFragments)((0, devkit_1.offsetFromRoot)(options.appProjectRoot), 'dist', options.appProjectRoot != '.'
|
38
|
+
? options.appProjectRoot
|
39
|
+
: options.projectName);
|
22
40
|
const serverOptions = project.targets.server?.options;
|
23
41
|
const serverOutputPath = serverOptions?.outputPath ??
|
24
|
-
(0,
|
42
|
+
(0, devkit_2.joinPathFragments)(originalOutputPath, 'server');
|
25
43
|
const serverOutputName = serverOptions?.outputFileName ?? 'main.js';
|
26
44
|
project.targets['serve-static'] = {
|
27
45
|
dependsOn: ['build', 'server'],
|
28
46
|
executor: 'nx:run-commands',
|
29
47
|
defaultConfiguration: 'development',
|
30
48
|
options: {
|
31
|
-
command: `PORT=${options.devServerPort ?? 4200} node ${(0,
|
49
|
+
command: `PORT=${options.devServerPort ?? 4200} node ${(0, devkit_2.joinPathFragments)(serverOutputPath, serverOutputName)}`,
|
32
50
|
},
|
33
51
|
};
|
34
|
-
(0,
|
35
|
-
const installTask = (0,
|
52
|
+
(0, devkit_2.updateProjectConfiguration)(tree, appName, project);
|
53
|
+
const installTask = (0, devkit_2.addDependenciesToPackageJson)(tree, {
|
36
54
|
'@module-federation/node': versions_1.moduleFederationNodeVersion,
|
55
|
+
cors: versions_1.corsVersion,
|
56
|
+
isbot: versions_1.isbotVersion,
|
57
|
+
express: versions_1.expressVersion,
|
58
|
+
'@types/express': versions_1.typesExpressVersion,
|
37
59
|
}, {});
|
38
60
|
tasks.push(installTask);
|
39
|
-
return (0,
|
61
|
+
return (0, devkit_2.runTasksInSerial)(...tasks);
|
40
62
|
}
|
@@ -17,12 +17,21 @@ const maybe_js_1 = require("../../utils/maybe-js");
|
|
17
17
|
const js_1 = require("@nx/js");
|
18
18
|
const versions_1 = require("../../utils/versions");
|
19
19
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
20
|
+
const create_application_files_1 = require("../application/lib/create-application-files");
|
20
21
|
function addModuleFederationFiles(host, options) {
|
21
|
-
const templateVariables =
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
const templateVariables = options.bundler === 'rspack'
|
23
|
+
? {
|
24
|
+
...(0, create_application_files_1.getDefaultTemplateVariables)(host, options),
|
25
|
+
rspackPluginOptions: {
|
26
|
+
...(0, create_application_files_1.createNxRspackPluginOptions)(options, (0, devkit_1.offsetFromRoot)(options.appProjectRoot), false),
|
27
|
+
mainServer: `./server.ts`,
|
28
|
+
},
|
29
|
+
}
|
30
|
+
: {
|
31
|
+
...(0, devkit_1.names)(options.projectName),
|
32
|
+
...options,
|
33
|
+
tmpl: '',
|
34
|
+
};
|
26
35
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, `./files/${options.js
|
27
36
|
? options.bundler === 'rspack'
|
28
37
|
? 'rspack-common'
|
@@ -48,43 +57,46 @@ function addModuleFederationFiles(host, options) {
|
|
48
57
|
async function remoteGenerator(host, schema) {
|
49
58
|
const tasks = [];
|
50
59
|
const options = {
|
51
|
-
...(await (0, normalize_options_1.normalizeOptions)(host,
|
60
|
+
...(await (0, normalize_options_1.normalizeOptions)(host, {
|
61
|
+
...schema,
|
62
|
+
useProjectJson: true,
|
63
|
+
})),
|
52
64
|
// when js is set to true, we want to use the js configuration
|
53
65
|
js: schema.js ?? false,
|
54
66
|
typescriptConfiguration: schema.js
|
55
67
|
? false
|
56
68
|
: schema.typescriptConfiguration ?? true,
|
57
69
|
dynamic: schema.dynamic ?? false,
|
58
|
-
// TODO(colum): remove when MF works with Crystal
|
59
|
-
addPlugin: false,
|
70
|
+
// TODO(colum): remove when Webpack MF works with Crystal
|
71
|
+
addPlugin: !schema.bundler || schema.bundler === 'rspack' ? true : false,
|
60
72
|
bundler: schema.bundler ?? 'rspack',
|
61
73
|
};
|
62
74
|
if (options.dynamic) {
|
63
75
|
// Dynamic remotes generate with library { type: 'var' } by default.
|
64
76
|
// We need to ensure that the remote name is a valid variable name.
|
65
|
-
const isValidRemote = (0, js_1.isValidVariable)(options.
|
77
|
+
const isValidRemote = (0, js_1.isValidVariable)(options.projectName);
|
66
78
|
if (!isValidRemote.isValid) {
|
67
|
-
throw new Error(`Invalid remote name provided: ${options.
|
79
|
+
throw new Error(`Invalid remote name provided: ${options.projectName}. ${isValidRemote.message}`);
|
68
80
|
}
|
69
81
|
}
|
70
|
-
await (0, project_name_and_root_utils_1.
|
82
|
+
await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'application');
|
71
83
|
const REMOTE_NAME_REGEX = '^[a-zA-Z_$][a-zA-Z_$0-9]*$';
|
72
84
|
const remoteNameRegex = new RegExp(REMOTE_NAME_REGEX);
|
73
|
-
if (!remoteNameRegex.test(options.
|
74
|
-
throw new Error((0, devkit_1.stripIndents) `Invalid remote name: ${options.
|
85
|
+
if (!remoteNameRegex.test(options.projectName)) {
|
86
|
+
throw new Error((0, devkit_1.stripIndents) `Invalid remote name: ${options.projectName}. Remote project names must:
|
75
87
|
- Start with a letter, dollar sign ($) or underscore (_)
|
76
88
|
- Followed by any valid character (letters, digits, underscores, or dollar signs)
|
77
89
|
The regular expression used is ${REMOTE_NAME_REGEX}.`);
|
78
90
|
}
|
79
91
|
const initAppTask = await (0, application_1.default)(host, {
|
80
92
|
...options,
|
81
|
-
name: options.
|
93
|
+
name: options.projectName,
|
82
94
|
skipFormat: true,
|
83
|
-
|
95
|
+
useProjectJson: true,
|
84
96
|
});
|
85
97
|
tasks.push(initAppTask);
|
86
98
|
if (options.host) {
|
87
|
-
(0, update_host_with_remote_1.updateHostWithRemote)(host, options.host, options.
|
99
|
+
(0, update_host_with_remote_1.updateHostWithRemote)(host, options.host, options.projectName);
|
88
100
|
}
|
89
101
|
// Module federation requires bootstrap code to be dynamically imported.
|
90
102
|
// Renaming original entry file so we can use `import(./bootstrap)` in
|
@@ -94,29 +106,33 @@ async function remoteGenerator(host, schema) {
|
|
94
106
|
(0, update_module_federation_project_1.updateModuleFederationProject)(host, options);
|
95
107
|
(0, setup_tspath_for_remote_1.setupTspathForRemote)(host, options);
|
96
108
|
if (options.ssr) {
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
109
|
+
if (options.bundler !== 'rspack') {
|
110
|
+
const setupSsrTask = await (0, setup_ssr_1.default)(host, {
|
111
|
+
project: options.projectName,
|
112
|
+
serverPort: options.devServerPort,
|
113
|
+
skipFormat: true,
|
114
|
+
bundler: options.bundler,
|
115
|
+
});
|
116
|
+
tasks.push(setupSsrTask);
|
117
|
+
}
|
104
118
|
const setupSsrForRemoteTask = await (0, setup_ssr_for_remote_1.setupSsrForRemote)(host, options, options.projectName);
|
105
119
|
tasks.push(setupSsrForRemoteTask);
|
106
120
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
107
|
-
if (options.bundler
|
108
|
-
projectConfig.targets.server.executor = '@nx/rspack:rspack';
|
109
|
-
projectConfig.targets.server.options.rspackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `rspack.server.config.${options.typescriptConfiguration ? 'ts' : 'js'}`);
|
110
|
-
delete projectConfig.targets.server.options.webpackConfig;
|
111
|
-
}
|
112
|
-
else {
|
121
|
+
if (options.bundler !== 'rspack') {
|
113
122
|
projectConfig.targets.server.options.webpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `webpack.server.config.${options.typescriptConfiguration ? 'ts' : 'js'}`);
|
123
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
|
114
124
|
}
|
115
|
-
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
|
116
125
|
}
|
117
126
|
if (!options.setParserOptionsProject) {
|
118
127
|
host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.lint.json'));
|
119
128
|
}
|
129
|
+
if (options.host && options.bundler === 'rspack') {
|
130
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
131
|
+
projectConfig.targets.serve ??= {};
|
132
|
+
projectConfig.targets.serve.dependsOn ??= [];
|
133
|
+
projectConfig.targets.serve.dependsOn.push(`${options.host}:serve`);
|
134
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
|
135
|
+
}
|
120
136
|
if (options.host && options.dynamic) {
|
121
137
|
const hostConfig = (0, devkit_1.readProjectConfiguration)(host, schema.host);
|
122
138
|
const pathToMFManifest = (0, devkit_1.joinPathFragments)(hostConfig.sourceRoot, 'assets/module-federation.manifest.json');
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { type CreateNodesV2 } from '@nx/devkit';
|
2
|
+
export interface ReactRouterPluginOptions {
|
3
|
+
buildTargetName?: string;
|
4
|
+
devTargetName?: string;
|
5
|
+
startTargetName?: string;
|
6
|
+
typecheckTargetName?: string;
|
7
|
+
buildDepsTargetName?: string;
|
8
|
+
watchDepsTargetName?: string;
|
9
|
+
}
|
10
|
+
export declare const createNodesV2: CreateNodesV2<ReactRouterPluginOptions>;
|
@@ -0,0 +1,221 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createNodesV2 = void 0;
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
5
|
+
const path_1 = require("path");
|
6
|
+
const fs_1 = require("fs");
|
7
|
+
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
8
|
+
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
9
|
+
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
10
|
+
const js_1 = require("@nx/js");
|
11
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
12
|
+
const util_1 = require("@nx/js/src/plugins/typescript/util");
|
13
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
14
|
+
const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
|
15
|
+
const pmCommand = (0, devkit_1.getPackageManagerCommand)();
|
16
|
+
const reactRouterConfigBlob = '**/react-router.config.{ts,js,cjs,cts,mjs,mts}';
|
17
|
+
function readTargetsCache(cachePath) {
|
18
|
+
return process.env.NX_CACHE_PROJECT_GRAPH !== 'false' && (0, fs_1.existsSync)(cachePath)
|
19
|
+
? (0, devkit_1.readJsonFile)(cachePath)
|
20
|
+
: {};
|
21
|
+
}
|
22
|
+
function writeTargetsToCache(cachePath, results) {
|
23
|
+
(0, devkit_1.writeJsonFile)(cachePath, results);
|
24
|
+
}
|
25
|
+
exports.createNodesV2 = [
|
26
|
+
reactRouterConfigBlob,
|
27
|
+
async (configFiles, options, context) => {
|
28
|
+
const optionsHash = (0, devkit_internals_1.hashObject)(options);
|
29
|
+
const normalizedOptions = normalizeOptions(options);
|
30
|
+
const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `react-router-${optionsHash}.hash`);
|
31
|
+
const targetsCache = readTargetsCache(cachePath);
|
32
|
+
const isUsingTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)();
|
33
|
+
const { roots: projectRoots, configFiles: validConfigFiles } = configFiles.reduce((acc, configFile) => {
|
34
|
+
const potentialRoot = (0, path_1.dirname)(configFile);
|
35
|
+
if (checkIfConfigFileShouldBeProject(potentialRoot, context)) {
|
36
|
+
acc.roots.push(potentialRoot);
|
37
|
+
acc.configFiles.push(configFile);
|
38
|
+
}
|
39
|
+
return acc;
|
40
|
+
}, {
|
41
|
+
roots: [],
|
42
|
+
configFiles: [],
|
43
|
+
});
|
44
|
+
const lockfile = (0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot));
|
45
|
+
const hashes = await (0, calculate_hash_for_create_nodes_1.calculateHashesForCreateNodes)(projectRoots, { ...normalizedOptions, isUsingTsSolutionSetup }, context, projectRoots.map((_) => [lockfile]));
|
46
|
+
try {
|
47
|
+
return await (0, devkit_1.createNodesFromFiles)(async (configFile, _, context, idx) => {
|
48
|
+
const projectRoot = (0, path_1.dirname)(configFile);
|
49
|
+
const siblingFiles = (0, fs_1.readdirSync)((0, devkit_1.joinPathFragments)(context.workspaceRoot, projectRoot));
|
50
|
+
const hash = hashes[idx] + configFile;
|
51
|
+
const { projectType, metadata, targets } = (targetsCache[hash] ??=
|
52
|
+
await buildReactRouterTargets(configFile, projectRoot, normalizedOptions, context, siblingFiles, isUsingTsSolutionSetup));
|
53
|
+
const project = {
|
54
|
+
root: projectRoot,
|
55
|
+
targets,
|
56
|
+
metadata,
|
57
|
+
};
|
58
|
+
if (project.targets[normalizedOptions.buildTargetName]) {
|
59
|
+
project.projectType = projectType;
|
60
|
+
}
|
61
|
+
return {
|
62
|
+
projects: {
|
63
|
+
[projectRoot]: project,
|
64
|
+
},
|
65
|
+
};
|
66
|
+
}, validConfigFiles, options, context);
|
67
|
+
}
|
68
|
+
finally {
|
69
|
+
writeTargetsToCache(cachePath, targetsCache);
|
70
|
+
}
|
71
|
+
},
|
72
|
+
];
|
73
|
+
async function buildReactRouterTargets(configFilePath, projectRoot, options, context, siblingFiles, isUsingTsSolutionSetup) {
|
74
|
+
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
75
|
+
const configPath = (0, path_1.join)(context.workspaceRoot, configFilePath);
|
76
|
+
if (require.cache[configPath])
|
77
|
+
(0, config_utils_1.clearRequireCache)();
|
78
|
+
const reactRouterConfig = await (0, config_utils_1.loadConfigFile)(configPath);
|
79
|
+
const isLibMode = reactRouterConfig?.ssr !== undefined && reactRouterConfig.ssr === false;
|
80
|
+
const { buildDirectory, serverBuildPath } = await getBuildPaths(reactRouterConfig, isLibMode);
|
81
|
+
const targets = {};
|
82
|
+
targets[options.buildTargetName] = await getBuildTargetConfig(options.buildTargetName, projectRoot, buildDirectory, serverBuildPath, namedInputs, isUsingTsSolutionSetup);
|
83
|
+
targets[options.devTargetName] = await devTarget(projectRoot, isUsingTsSolutionSetup);
|
84
|
+
if (serverBuildPath) {
|
85
|
+
targets[options.startTargetName] = await startTarget(projectRoot, serverBuildPath, options.buildTargetName, isUsingTsSolutionSetup);
|
86
|
+
}
|
87
|
+
targets[options.typecheckTargetName] = await typecheckTarget(projectRoot, options.typecheckTargetName, namedInputs, siblingFiles, isUsingTsSolutionSetup);
|
88
|
+
(0, util_1.addBuildAndWatchDepsTargets)(context.workspaceRoot, projectRoot, targets, options, pmCommand);
|
89
|
+
const metadata = {};
|
90
|
+
return {
|
91
|
+
targets,
|
92
|
+
metadata,
|
93
|
+
projectType: isLibMode ? 'library' : 'application',
|
94
|
+
};
|
95
|
+
}
|
96
|
+
async function getBuildTargetConfig(buildTargetName, projectRoot, buildDirectory, serverBuildDirectory, namedInputs, isUsingTsSolutionSetup) {
|
97
|
+
const basePath = projectRoot === '.'
|
98
|
+
? `{workspaceRoot}`
|
99
|
+
: (0, devkit_1.joinPathFragments)(`{workspaceRoot}`, projectRoot);
|
100
|
+
const outputs = [
|
101
|
+
(0, devkit_1.joinPathFragments)(basePath, buildDirectory),
|
102
|
+
...(serverBuildDirectory
|
103
|
+
? [(0, devkit_1.joinPathFragments)(basePath, serverBuildDirectory)]
|
104
|
+
: []),
|
105
|
+
];
|
106
|
+
const buildTarget = {
|
107
|
+
cache: true,
|
108
|
+
dependsOn: [`^${buildTargetName}`],
|
109
|
+
inputs: [
|
110
|
+
...('production' in namedInputs
|
111
|
+
? ['production', '^production']
|
112
|
+
: ['default', '^default']),
|
113
|
+
{ externalDependencies: ['@react-router/dev'] },
|
114
|
+
],
|
115
|
+
outputs,
|
116
|
+
command: 'react-router build',
|
117
|
+
options: { cwd: projectRoot },
|
118
|
+
};
|
119
|
+
if (isUsingTsSolutionSetup) {
|
120
|
+
buildTarget.syncGenerators = ['@nx/js:typescript-sync'];
|
121
|
+
}
|
122
|
+
return buildTarget;
|
123
|
+
}
|
124
|
+
async function getBuildPaths(reactRouterConfig, isLibMode) {
|
125
|
+
return {
|
126
|
+
buildDirectory: reactRouterConfig?.buildDirectory ?? 'build/client',
|
127
|
+
...(isLibMode
|
128
|
+
? undefined
|
129
|
+
: {
|
130
|
+
serverBuildPath: reactRouterConfig?.buildDirectory
|
131
|
+
? (0, path_1.join)((0, path_1.dirname)(reactRouterConfig.buildDirectory), `server`)
|
132
|
+
: 'build/server',
|
133
|
+
}),
|
134
|
+
};
|
135
|
+
}
|
136
|
+
async function devTarget(projectRoot, isUsingTsSolutionSetup) {
|
137
|
+
const devTarget = {
|
138
|
+
continuous: true,
|
139
|
+
command: 'react-router dev',
|
140
|
+
options: { cwd: projectRoot },
|
141
|
+
};
|
142
|
+
if (isUsingTsSolutionSetup) {
|
143
|
+
devTarget.syncGenerators = ['@nx/js:typescript-sync'];
|
144
|
+
}
|
145
|
+
return devTarget;
|
146
|
+
}
|
147
|
+
async function startTarget(projectRoot, serverBuildPath, buildTargetName, isUsingTsSolutionSetup) {
|
148
|
+
const serverPath = serverBuildPath === 'build/server'
|
149
|
+
? `${serverBuildPath}/index.js`
|
150
|
+
: serverBuildPath;
|
151
|
+
const startTarget = {
|
152
|
+
continuous: true,
|
153
|
+
dependsOn: [buildTargetName],
|
154
|
+
command: `react-router-serve ${serverPath}`,
|
155
|
+
options: { cwd: projectRoot },
|
156
|
+
};
|
157
|
+
if (isUsingTsSolutionSetup) {
|
158
|
+
startTarget.syncGenerators = ['@nx/js:typescript-sync'];
|
159
|
+
}
|
160
|
+
return startTarget;
|
161
|
+
}
|
162
|
+
async function typecheckTarget(projectRoot, typecheckTargetName, namedInputs, siblingFiles, isUsingTsSolutionSetup) {
|
163
|
+
const hasTsConfigAppJson = siblingFiles.includes('tsconfig.app.json');
|
164
|
+
const typecheckTarget = {
|
165
|
+
cache: true,
|
166
|
+
inputs: [
|
167
|
+
...('production' in namedInputs
|
168
|
+
? ['production', '^production']
|
169
|
+
: ['default', '^default']),
|
170
|
+
{ externalDependencies: ['typescript'] },
|
171
|
+
],
|
172
|
+
command: isUsingTsSolutionSetup
|
173
|
+
? `tsc --build --emitDeclarationOnly`
|
174
|
+
: `tsc${hasTsConfigAppJson ? ` -p tsconfig.app.json` : ``} --noEmit`,
|
175
|
+
options: {
|
176
|
+
cwd: projectRoot,
|
177
|
+
},
|
178
|
+
metadata: {
|
179
|
+
description: `Runs type-checking for the project.`,
|
180
|
+
technologies: ['typescript'],
|
181
|
+
help: {
|
182
|
+
command: isUsingTsSolutionSetup
|
183
|
+
? `${pmCommand.exec} tsc --build --help`
|
184
|
+
: `${pmCommand.exec} tsc${hasTsConfigAppJson ? ` -p tsconfig.app.json` : ``} --help`,
|
185
|
+
example: isUsingTsSolutionSetup
|
186
|
+
? { args: ['--force'] }
|
187
|
+
: { options: { noEmit: true } },
|
188
|
+
},
|
189
|
+
},
|
190
|
+
};
|
191
|
+
if (isUsingTsSolutionSetup) {
|
192
|
+
typecheckTarget.dependsOn = [`^${typecheckTargetName}`];
|
193
|
+
typecheckTarget.syncGenerators = ['@nx/js:typescript-sync'];
|
194
|
+
}
|
195
|
+
return typecheckTarget;
|
196
|
+
}
|
197
|
+
function normalizeOptions(options) {
|
198
|
+
options ??= {};
|
199
|
+
options.buildTargetName ??= 'build';
|
200
|
+
options.devTargetName ??= 'dev';
|
201
|
+
options.startTargetName ??= 'start';
|
202
|
+
options.typecheckTargetName ??= 'typecheck';
|
203
|
+
return options;
|
204
|
+
}
|
205
|
+
function checkIfConfigFileShouldBeProject(projectRoot, context) {
|
206
|
+
// Do not create a project if package.json and project.json isn't there.
|
207
|
+
const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
|
208
|
+
return hasRequiredConfigs(siblingFiles);
|
209
|
+
}
|
210
|
+
function hasRequiredConfigs(files) {
|
211
|
+
const lowerFiles = files.map((file) => file.toLowerCase());
|
212
|
+
// Check if vite.config.{ext} is present
|
213
|
+
const hasViteConfig = lowerFiles.some((file) => {
|
214
|
+
const parts = file.split('.');
|
215
|
+
return parts[0] === 'vite' && parts[1] === 'config' && parts.length > 2;
|
216
|
+
});
|
217
|
+
if (!hasViteConfig)
|
218
|
+
return false;
|
219
|
+
const hasProjectOrPackageJson = lowerFiles.includes('project.json') || lowerFiles.includes('package.json');
|
220
|
+
return hasProjectOrPackageJson;
|
221
|
+
}
|
@@ -4,23 +4,9 @@ exports.updateModuleFederationProject = updateModuleFederationProject;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
5
|
const maybe_js_1 = require("../utils/maybe-js");
|
6
6
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
7
|
-
function updateModuleFederationProject(host, options) {
|
7
|
+
function updateModuleFederationProject(host, options, isHost = false) {
|
8
8
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
9
|
-
if (options.bundler
|
10
|
-
projectConfig.targets.build.executor = '@nx/rspack:rspack';
|
11
|
-
projectConfig.targets.build.options = {
|
12
|
-
...(projectConfig.targets.build.options ?? {}),
|
13
|
-
main: (0, maybe_js_1.maybeJs)({ js: options.js, useJsx: true }, `${options.appProjectRoot}/src/main.ts`),
|
14
|
-
rspackConfig: `${options.appProjectRoot}/rspack.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
|
15
|
-
target: 'web',
|
16
|
-
};
|
17
|
-
projectConfig.targets.build.configurations ??= {};
|
18
|
-
projectConfig.targets.build.configurations.production = {
|
19
|
-
...(projectConfig.targets.build.configurations?.production ?? {}),
|
20
|
-
rspackConfig: `${options.appProjectRoot}/rspack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
|
21
|
-
};
|
22
|
-
}
|
23
|
-
else {
|
9
|
+
if (options.bundler !== 'rspack') {
|
24
10
|
projectConfig.targets.build.options = {
|
25
11
|
...(projectConfig.targets.build.options ?? {}),
|
26
12
|
main: (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/src/main.ts`),
|
@@ -34,15 +20,7 @@ function updateModuleFederationProject(host, options) {
|
|
34
20
|
}
|
35
21
|
// If host should be configured to use dynamic federation
|
36
22
|
if (options.dynamic) {
|
37
|
-
if (options.bundler
|
38
|
-
const pathToProdRspackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `rspack.prod.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`);
|
39
|
-
if (host.exists(pathToProdRspackConfig)) {
|
40
|
-
host.delete(pathToProdRspackConfig);
|
41
|
-
}
|
42
|
-
delete projectConfig.targets.build.configurations.production
|
43
|
-
?.rspackConfig;
|
44
|
-
}
|
45
|
-
else {
|
23
|
+
if (options.bundler !== 'rspack') {
|
46
24
|
const pathToProdWebpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `webpack.prod.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`);
|
47
25
|
if (host.exists(pathToProdWebpackConfig)) {
|
48
26
|
host.delete(pathToProdWebpackConfig);
|
@@ -51,36 +29,39 @@ function updateModuleFederationProject(host, options) {
|
|
51
29
|
?.webpackConfig;
|
52
30
|
}
|
53
31
|
}
|
54
|
-
if (options.bundler
|
55
|
-
projectConfig.targets.serve.executor =
|
56
|
-
'@nx/rspack:module-federation-dev-server';
|
57
|
-
}
|
58
|
-
else {
|
32
|
+
if (options.bundler !== 'rspack') {
|
59
33
|
projectConfig.targets.serve.executor =
|
60
34
|
'@nx/react:module-federation-dev-server';
|
61
35
|
}
|
62
|
-
projectConfig.targets.serve
|
36
|
+
projectConfig.targets.serve ??= {};
|
37
|
+
projectConfig.targets.serve.options ??= {};
|
38
|
+
projectConfig.targets.serve.options.port =
|
39
|
+
options.bundler === 'rspack' && options.ssr && isHost
|
40
|
+
? 4000
|
41
|
+
: options.devServerPort;
|
63
42
|
// `serve-static` for remotes that don't need to be in development mode
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
serveTarget: `${options.projectName}:serve`,
|
72
|
-
},
|
73
|
-
configurations: {
|
74
|
-
development: {
|
75
|
-
serveTarget: `${options.projectName}:serve:development`,
|
43
|
+
if (options.bundler !== 'rspack') {
|
44
|
+
const serveStaticExecutor = '@nx/react:module-federation-static-server';
|
45
|
+
projectConfig.targets['serve-static'] = {
|
46
|
+
executor: serveStaticExecutor,
|
47
|
+
defaultConfiguration: 'production',
|
48
|
+
options: {
|
49
|
+
serveTarget: `${options.projectName}:serve`,
|
76
50
|
},
|
77
|
-
|
78
|
-
|
51
|
+
configurations: {
|
52
|
+
development: {
|
53
|
+
serveTarget: `${options.projectName}:serve:development`,
|
54
|
+
},
|
55
|
+
production: {
|
56
|
+
serveTarget: `${options.projectName}:serve:production`,
|
57
|
+
},
|
79
58
|
},
|
80
|
-
}
|
81
|
-
}
|
59
|
+
};
|
60
|
+
}
|
82
61
|
// Typechecks must be performed first before build and serve to generate remote d.ts files.
|
83
62
|
if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)(host)) {
|
63
|
+
projectConfig.targets.build ??= {};
|
64
|
+
projectConfig.targets.serve ??= {};
|
84
65
|
projectConfig.targets.build.dependsOn = ['^build', 'typecheck'];
|
85
66
|
projectConfig.targets.serve.dependsOn = ['typecheck'];
|
86
67
|
}
|
package/src/utils/assertion.d.ts
CHANGED
package/src/utils/assertion.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.assertValidStyle = assertValidStyle;
|
4
|
+
exports.assertValidReactRouter = assertValidReactRouter;
|
4
5
|
const VALID_STYLES = [
|
5
6
|
'css',
|
6
7
|
'scss',
|
@@ -16,3 +17,8 @@ function assertValidStyle(style) {
|
|
16
17
|
throw new Error(`Unsupported style option found: ${style}. Valid values are: "${VALID_STYLES.join('", "')}"`);
|
17
18
|
}
|
18
19
|
}
|
20
|
+
function assertValidReactRouter(reactRouter, bundler) {
|
21
|
+
if (reactRouter && bundler !== 'vite') {
|
22
|
+
throw new Error(`Unsupported bundler found: ${bundler}. React Router is only supported with 'vite'.`);
|
23
|
+
}
|
24
|
+
}
|
package/src/utils/ast-utils.d.ts
CHANGED
@@ -11,7 +11,7 @@ export declare function findComponentImportPath(componentName: string, source: t
|
|
11
11
|
export declare function findElements(source: ts.SourceFile, tagName: string): ts.Node[];
|
12
12
|
export declare function findClosestOpening(tagName: string, node: ts.Node): ts.Node;
|
13
13
|
export declare function isTag(tagName: string, node: ts.Node): boolean;
|
14
|
-
export declare function addInitialRoutes(sourcePath: string, source: ts.SourceFile): StringChange[];
|
14
|
+
export declare function addInitialRoutes(sourcePath: string, source: ts.SourceFile, addBrowserRouter?: boolean): StringChange[];
|
15
15
|
export declare function addRoute(sourcePath: string, source: ts.SourceFile, options: {
|
16
16
|
routePath: string;
|
17
17
|
componentName: string;
|
package/src/utils/ast-utils.js
CHANGED
@@ -234,7 +234,7 @@ function isTag(tagName, node) {
|
|
234
234
|
}
|
235
235
|
return false;
|
236
236
|
}
|
237
|
-
function addInitialRoutes(sourcePath, source) {
|
237
|
+
function addInitialRoutes(sourcePath, source, addBrowserRouter) {
|
238
238
|
if (!tsModule) {
|
239
239
|
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
240
240
|
}
|
@@ -281,7 +281,7 @@ function addInitialRoutes(sourcePath, source) {
|
|
281
281
|
`,
|
282
282
|
};
|
283
283
|
return [
|
284
|
-
...addImport(source, `import { Route, Routes, Link } from 'react-router-dom';`),
|
284
|
+
...addImport(source, `import { Route, Routes, Link ${addBrowserRouter ? ', BrowserRouter ' : ''}} from 'react-router-dom';`),
|
285
285
|
insertRoutes,
|
286
286
|
];
|
287
287
|
}
|
package/src/utils/ct-utils.d.ts
CHANGED
@@ -10,5 +10,5 @@ export declare function getBundlerFromTarget(found: FoundTarget, tree: Tree): Pr
|
|
10
10
|
export declare function getActualBundler(tree: Tree, options: {
|
11
11
|
buildTarget?: string;
|
12
12
|
bundler?: 'vite' | 'webpack';
|
13
|
-
}, found: FoundTarget): Promise<"
|
13
|
+
}, found: FoundTarget): Promise<"webpack" | "vite">;
|
14
14
|
export declare function isComponent(tree: Tree, filePath: string): boolean;
|
package/src/utils/versions.d.ts
CHANGED
@@ -14,7 +14,7 @@ export declare const typesReactDomVersion = "19.0.0";
|
|
14
14
|
export declare const typesReactIsV18Version = "18.3.0";
|
15
15
|
export declare const typesReactIsVersion = "19.0.0";
|
16
16
|
export declare const reactViteVersion = "^4.2.0";
|
17
|
-
export declare const typesNodeVersion = "
|
17
|
+
export declare const typesNodeVersion = "^20.0.0";
|
18
18
|
export declare const babelPresetReactVersion = "^7.14.5";
|
19
19
|
export declare const babelCoreVersion = "^7.14.5";
|
20
20
|
export declare const styledComponentsVersion = "5.3.6";
|
@@ -23,7 +23,9 @@ export declare const emotionStyledVersion = "11.11.0";
|
|
23
23
|
export declare const emotionReactVersion = "11.11.1";
|
24
24
|
export declare const emotionBabelPlugin = "11.11.0";
|
25
25
|
export declare const styledJsxVersion = "5.1.2";
|
26
|
-
export declare const reactRouterDomVersion = "6.
|
26
|
+
export declare const reactRouterDomVersion = "6.29.0";
|
27
|
+
export declare const reactRouterVersion = "^7.2.0";
|
28
|
+
export declare const reactRouterIsBotVersion = "^4.4.0";
|
27
29
|
export declare const testingLibraryReactVersion = "16.1.0";
|
28
30
|
export declare const testingLibraryDomVersion = "10.4.0";
|
29
31
|
export declare const reduxjsToolkitVersion = "1.9.3";
|
@@ -42,8 +44,8 @@ export declare const typesExpressVersion = "^4.17.21";
|
|
42
44
|
export declare const isbotVersion = "^3.6.5";
|
43
45
|
export declare const corsVersion = "~2.8.5";
|
44
46
|
export declare const typesCorsVersion = "~2.8.12";
|
45
|
-
export declare const moduleFederationNodeVersion = "^2.6.
|
46
|
-
export declare const moduleFederationEnhancedVersion = "^0.
|
47
|
+
export declare const moduleFederationNodeVersion = "^2.6.26";
|
48
|
+
export declare const moduleFederationEnhancedVersion = "^0.9.0";
|
47
49
|
export declare const lessVersion = "3.12.2";
|
48
50
|
export declare const sassVersion = "^1.55.0";
|
49
51
|
export declare const rollupPluginUrlVersion = "^8.0.2";
|