@nx/react 21.0.0-beta.1 → 21.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/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 +33 -24
- 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 +4 -0
- 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 +219 -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/utils/format-file.d.ts +0 -1
- package/src/utils/format-file.js +0 -11
@@ -0,0 +1,24 @@
|
|
1
|
+
{
|
2
|
+
"name": "<%= projectName %>",
|
3
|
+
"private": true,
|
4
|
+
"type": "module",
|
5
|
+
"scripts": {},
|
6
|
+
"dependencies": {
|
7
|
+
"@react-router/node": "<%= reactRouterVersion %>",
|
8
|
+
"@react-router/serve": "<%= reactRouterVersion %>",
|
9
|
+
"isbot": "<%= reactRouterIsBotVersion %>",
|
10
|
+
"react": "<%= reactVersion %>",
|
11
|
+
"react-dom": "<%= reactVersion %>",
|
12
|
+
"react-router": "<%= reactRouterVersion %>"
|
13
|
+
},
|
14
|
+
"devDependencies": {
|
15
|
+
"@react-router/dev": "<%= reactRouterVersion %>",
|
16
|
+
"@types/node": "<%= typesNodeVersion %>",
|
17
|
+
"@types/react": "<%= reactVersion %>",
|
18
|
+
"@types/react-dom": "<%= reactVersion %>"
|
19
|
+
},
|
20
|
+
"engines": {
|
21
|
+
"node": ">=20"
|
22
|
+
},
|
23
|
+
"sideEffects": false,
|
24
|
+
}
|
package/src/generators/application/files/react-router-ssr/ts-solution/tsconfig.app.json__tmpl__
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
{
|
2
|
+
"extends": "<%= offsetFromRoot %>tsconfig.base.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"outDir": "dist",
|
5
|
+
"lib": ["DOM", "DOM.Iterable", "ES2019"],
|
6
|
+
"types": ["@react-router/node", "vite/client"],
|
7
|
+
"isolatedModules": true,
|
8
|
+
"esModuleInterop": true,
|
9
|
+
"jsx": "react-jsx",
|
10
|
+
"module": "ESNext",
|
11
|
+
"moduleResolution": "Bundler",
|
12
|
+
"resolveJsonModule": true,
|
13
|
+
"target": "ES2022",
|
14
|
+
"strict": true,
|
15
|
+
"allowJs": true,
|
16
|
+
"skipLibCheck": true,
|
17
|
+
"forceConsistentCasingInFileNames": true
|
18
|
+
},
|
19
|
+
"include": [
|
20
|
+
"app/**/*.ts",
|
21
|
+
"app/**/*.tsx",
|
22
|
+
"app/**/*.js",
|
23
|
+
"app/**/*.jsx",
|
24
|
+
"**/.server/**/*.ts",
|
25
|
+
"**/.server/**/*.tsx",
|
26
|
+
"**/.client/**/*.ts",
|
27
|
+
"**/.client/**/*.tsx"
|
28
|
+
],
|
29
|
+
"exclude": [
|
30
|
+
"tests/**/*.spec.ts",
|
31
|
+
"tests/**/*.test.ts",
|
32
|
+
"tests/**/*.spec.tsx",
|
33
|
+
"tests/**/*.test.tsx",
|
34
|
+
"tests/**/*.spec.js",
|
35
|
+
"tests/**/*.test.js",
|
36
|
+
"tests/**/*.spec.jsx",
|
37
|
+
"tests/**/*.test.jsx"
|
38
|
+
]
|
39
|
+
}
|
@@ -27,9 +27,15 @@ async function addE2e(tree, options) {
|
|
27
27
|
const { getWebpackE2EWebServerInfo } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_1.nxVersion);
|
28
28
|
e2eWebServerInfo = await getWebpackE2EWebServerInfo(tree, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, `webpack.config.${options.js ? 'js' : 'ts'}`), options.addPlugin, options.devServerPort ?? 4200);
|
29
29
|
}
|
30
|
+
else if (options.bundler === 'rspack') {
|
31
|
+
const { getRspackE2EWebServerInfo } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxVersion);
|
32
|
+
e2eWebServerInfo = await getRspackE2EWebServerInfo(tree, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, `rspack.config.${options.js ? 'js' : 'ts'}`), options.addPlugin, options.devServerPort ?? 4200);
|
33
|
+
}
|
30
34
|
else if (options.bundler === 'vite') {
|
31
|
-
const { getViteE2EWebServerInfo } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
32
|
-
e2eWebServerInfo =
|
35
|
+
const { getViteE2EWebServerInfo, getReactRouterE2EWebServerInfo } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
36
|
+
e2eWebServerInfo = options.useReactRouter
|
37
|
+
? await getReactRouterE2EWebServerInfo(tree, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, `vite.config.${options.js ? 'js' : 'ts'}`), options.addPlugin, options.devServerPort ?? 4200)
|
38
|
+
: await getViteE2EWebServerInfo(tree, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, `vite.config.${options.js ? 'js' : 'ts'}`), options.addPlugin, options.devServerPort ?? 4200);
|
33
39
|
}
|
34
40
|
else if (options.bundler === 'rsbuild') {
|
35
41
|
(0, devkit_1.ensurePackage)('@nx/rsbuild', versions_1.nxVersion);
|
@@ -46,17 +52,15 @@ async function addE2e(tree, options) {
|
|
46
52
|
switch (options.e2eTestRunner) {
|
47
53
|
case 'cypress': {
|
48
54
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
},
|
59
|
-
});
|
55
|
+
const packageJson = {
|
56
|
+
name: options.e2eProjectName,
|
57
|
+
version: '0.0.1',
|
58
|
+
private: true,
|
59
|
+
};
|
60
|
+
if (!options.useProjectJson) {
|
61
|
+
packageJson.nx = {
|
62
|
+
implicitDependencies: [options.projectName],
|
63
|
+
};
|
60
64
|
}
|
61
65
|
else {
|
62
66
|
(0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
|
@@ -68,6 +72,9 @@ async function addE2e(tree, options) {
|
|
68
72
|
tags: [],
|
69
73
|
});
|
70
74
|
}
|
75
|
+
if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
|
76
|
+
(0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), packageJson);
|
77
|
+
}
|
71
78
|
const e2eTask = await configurationGenerator(tree, {
|
72
79
|
...options,
|
73
80
|
project: options.e2eProjectName,
|
@@ -116,17 +123,15 @@ async function addE2e(tree, options) {
|
|
116
123
|
}
|
117
124
|
case 'playwright': {
|
118
125
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/playwright', versions_1.nxVersion);
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
},
|
129
|
-
});
|
126
|
+
const packageJson = {
|
127
|
+
name: options.e2eProjectName,
|
128
|
+
version: '0.0.1',
|
129
|
+
private: true,
|
130
|
+
};
|
131
|
+
if (!options.useProjectJson) {
|
132
|
+
packageJson.nx = {
|
133
|
+
implicitDependencies: [options.projectName],
|
134
|
+
};
|
130
135
|
}
|
131
136
|
else {
|
132
137
|
(0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
|
@@ -135,8 +140,12 @@ async function addE2e(tree, options) {
|
|
135
140
|
sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
|
136
141
|
targets: {},
|
137
142
|
implicitDependencies: [options.projectName],
|
143
|
+
tags: [],
|
138
144
|
});
|
139
145
|
}
|
146
|
+
if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
|
147
|
+
(0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), packageJson);
|
148
|
+
}
|
140
149
|
const e2eTask = await configurationGenerator(tree, {
|
141
150
|
project: options.e2eProjectName,
|
142
151
|
skipFormat: true,
|
@@ -3,19 +3,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addJest = addJest;
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
5
|
const versions_1 = require("../../../utils/versions");
|
6
|
+
const node_path_1 = require("node:path");
|
6
7
|
async function addJest(host, options) {
|
7
8
|
if (options.unitTestRunner === 'none') {
|
8
9
|
return () => { };
|
9
10
|
}
|
10
11
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
|
11
|
-
|
12
|
+
await configurationGenerator(host, {
|
12
13
|
...options,
|
13
14
|
project: options.projectName,
|
14
15
|
supportTsx: true,
|
15
16
|
skipSerializers: true,
|
16
|
-
setupFile: 'none',
|
17
|
+
setupFile: options.useReactRouter ? 'react-router' : 'none',
|
17
18
|
compiler: options.compiler,
|
18
19
|
skipFormat: true,
|
19
20
|
runtimeTsconfigFileName: 'tsconfig.app.json',
|
20
21
|
});
|
22
|
+
if (options.useReactRouter) {
|
23
|
+
(0, devkit_1.updateJson)(host, (0, node_path_1.join)(options.appProjectRoot, 'tsconfig.spec.json'), (json) => {
|
24
|
+
json.include = json.include ?? [];
|
25
|
+
const reactRouterTestGlob = options.js
|
26
|
+
? [
|
27
|
+
'test/**/*.spec.jsx',
|
28
|
+
'test/**/*.spec.js',
|
29
|
+
'test/**/*.test.jsx',
|
30
|
+
'test/**/*.test.js',
|
31
|
+
]
|
32
|
+
: [
|
33
|
+
'test/**/*.spec.tsx',
|
34
|
+
'test/**/*.spec.ts',
|
35
|
+
'test/**/*.test.tsx',
|
36
|
+
'test/**/*.test.ts',
|
37
|
+
];
|
38
|
+
return {
|
39
|
+
...json,
|
40
|
+
include: Array.from(new Set([...json.include, ...reactRouterTestGlob])),
|
41
|
+
};
|
42
|
+
});
|
43
|
+
}
|
44
|
+
return () => { };
|
21
45
|
}
|
@@ -1,3 +1,4 @@
|
|
1
1
|
import { type Tree, type GeneratorCallback } from '@nx/devkit';
|
2
2
|
import { NormalizedSchema } from '../schema';
|
3
3
|
export declare function addLinting(host: Tree, options: NormalizedSchema): Promise<GeneratorCallback>;
|
4
|
+
export declare function isEslintInstalled(tree: Tree): boolean;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.addLinting = addLinting;
|
4
|
+
exports.isEslintInstalled = isEslintInstalled;
|
4
5
|
const devkit_1 = require("@nx/devkit");
|
5
6
|
const eslint_1 = require("@nx/eslint");
|
6
7
|
const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
|
@@ -8,6 +9,7 @@ const flat_config_1 = require("@nx/eslint/src/utils/flat-config");
|
|
8
9
|
const devkit_2 = require("@nx/devkit");
|
9
10
|
const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
10
11
|
const lint_1 = require("../../../utils/lint");
|
12
|
+
const versions_1 = require("../../../utils/versions");
|
11
13
|
async function addLinting(host, options) {
|
12
14
|
const tasks = [];
|
13
15
|
if (options.linter === eslint_1.Linter.EsLint) {
|
@@ -43,6 +45,42 @@ async function addLinting(host, options) {
|
|
43
45
|
const addSwcTask = (0, add_swc_dependencies_1.addSwcDependencies)(host);
|
44
46
|
tasks.push(installTask, addSwcTask);
|
45
47
|
}
|
48
|
+
if (options.useReactRouter) {
|
49
|
+
await ignoreReactRouterFilesInEslintConfig(host, options.appProjectRoot);
|
50
|
+
}
|
46
51
|
}
|
47
52
|
return (0, devkit_2.runTasksInSerial)(...tasks);
|
48
53
|
}
|
54
|
+
async function ignoreReactRouterFilesInEslintConfig(tree, projectRoot) {
|
55
|
+
if (!isEslintInstalled(tree)) {
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
(0, devkit_1.ensurePackage)('@nx/eslint', versions_1.nxVersion);
|
59
|
+
const { addIgnoresToLintConfig, isEslintConfigSupported } = await Promise.resolve().then(() => require('@nx/eslint/src/generators/utils/eslint-file'));
|
60
|
+
if (!isEslintConfigSupported(tree)) {
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
const { useFlatConfig } = await Promise.resolve().then(() => require('@nx/eslint/src/utils/flat-config'));
|
64
|
+
const isUsingFlatConfig = useFlatConfig(tree);
|
65
|
+
if (!projectRoot && !isUsingFlatConfig) {
|
66
|
+
// root eslintrc files ignore all files and the root eslintrc files add
|
67
|
+
// back all the project files, so we only add the ignores to the project
|
68
|
+
// eslintrc files
|
69
|
+
return;
|
70
|
+
}
|
71
|
+
// for flat config, we update the root config file
|
72
|
+
const directory = isUsingFlatConfig ? '' : projectRoot ?? '';
|
73
|
+
addIgnoresToLintConfig(tree, directory, ['**/build', '**/.react-router']);
|
74
|
+
}
|
75
|
+
function isEslintInstalled(tree) {
|
76
|
+
try {
|
77
|
+
require('eslint');
|
78
|
+
return true;
|
79
|
+
}
|
80
|
+
catch { }
|
81
|
+
// it might not be installed yet, but it might be in the tree pending install
|
82
|
+
const { devDependencies, dependencies } = tree.exists('package.json')
|
83
|
+
? (0, devkit_1.readJson)(tree, 'package.json')
|
84
|
+
: {};
|
85
|
+
return !!devDependencies?.['eslint'] || !!dependencies?.['eslint'];
|
86
|
+
}
|
@@ -28,26 +28,42 @@ function addProject(host, options) {
|
|
28
28
|
serve: createRspackServeTarget(options),
|
29
29
|
};
|
30
30
|
}
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
const packageJson = {
|
32
|
+
name: options.importPath,
|
33
|
+
version: '0.0.1',
|
34
|
+
private: true,
|
35
|
+
};
|
36
|
+
if (!options.useProjectJson) {
|
37
|
+
if (options.projectName !== options.importPath) {
|
38
|
+
packageJson.nx = { name: options.projectName };
|
39
|
+
}
|
40
|
+
if (Object.keys(project.targets).length) {
|
41
|
+
packageJson.nx ??= {};
|
42
|
+
packageJson.nx.targets = project.targets;
|
43
|
+
}
|
44
|
+
if (options.parsedTags?.length) {
|
45
|
+
packageJson.nx ??= {};
|
46
|
+
packageJson.nx.tags = options.parsedTags;
|
47
|
+
}
|
37
48
|
}
|
38
|
-
|
49
|
+
else {
|
39
50
|
(0, devkit_1.addProjectConfiguration)(host, options.projectName, {
|
40
51
|
...project,
|
41
52
|
});
|
42
53
|
}
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
54
|
+
if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
|
55
|
+
// React Router already adds a package.json to the project root
|
56
|
+
if (options.useReactRouter) {
|
57
|
+
(0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), (json) => {
|
58
|
+
return {
|
59
|
+
name: packageJson.name,
|
60
|
+
...json,
|
61
|
+
};
|
62
|
+
});
|
63
|
+
}
|
64
|
+
else {
|
65
|
+
(0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), packageJson);
|
66
|
+
}
|
51
67
|
}
|
52
68
|
}
|
53
69
|
function createRspackBuildTarget(options) {
|
@@ -20,7 +20,7 @@ function addRouting(host, options) {
|
|
20
20
|
}, `src/app/${options.fileName}.tsx`));
|
21
21
|
const appFileContent = host.read(appPath, 'utf-8');
|
22
22
|
const appSource = tsModule.createSourceFile(appPath, appFileContent, tsModule.ScriptTarget.Latest, true);
|
23
|
-
const changes = (0, devkit_1.applyChangesToString)(appFileContent, (0, ast_utils_1.addInitialRoutes)(appPath, appSource));
|
23
|
+
const changes = (0, devkit_1.applyChangesToString)(appFileContent, (0, ast_utils_1.addInitialRoutes)(appPath, appSource, options.inSourceTests));
|
24
24
|
host.write(appPath, changes);
|
25
25
|
if (!options.skipPackageJson) {
|
26
26
|
return (0, devkit_1.addDependenciesToPackageJson)(host, { 'react-router-dom': versions_1.reactRouterDomVersion }, {});
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import { type Tree } from '@nx/devkit';
|
2
2
|
import { NormalizedSchema, Schema } from '../../schema';
|
3
3
|
export declare function initRspack(tree: Tree, options: NormalizedSchema<Schema>, tasks: any[]): Promise<void>;
|
4
|
-
export declare function setupRspackConfiguration(tree: Tree, options: NormalizedSchema<Schema>, tasks: any[]): Promise<void>;
|
5
4
|
export declare function handleStyledJsxForRspack(tasks: any[], tree: Tree, options: NormalizedSchema<Schema>): void;
|
@@ -1,36 +1,18 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.initRspack = initRspack;
|
4
|
-
exports.setupRspackConfiguration = setupRspackConfiguration;
|
5
4
|
exports.handleStyledJsxForRspack = handleStyledJsxForRspack;
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
7
6
|
const pc = require("picocolors");
|
8
7
|
const versions_1 = require("../../../../utils/versions");
|
9
|
-
const maybe_js_1 = require("../../../../utils/maybe-js");
|
10
8
|
async function initRspack(tree, options, tasks) {
|
11
9
|
const { rspackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxVersion);
|
12
10
|
const rspackInitTask = await rspackInitGenerator(tree, {
|
13
11
|
...options,
|
14
|
-
addPlugin: false,
|
15
12
|
skipFormat: true,
|
16
13
|
});
|
17
14
|
tasks.push(rspackInitTask);
|
18
15
|
}
|
19
|
-
async function setupRspackConfiguration(tree, options, tasks) {
|
20
|
-
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxVersion);
|
21
|
-
const rspackTask = await configurationGenerator(tree, {
|
22
|
-
project: options.projectName,
|
23
|
-
main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)({
|
24
|
-
js: options.js,
|
25
|
-
useJsx: true,
|
26
|
-
}, `src/main.tsx`)),
|
27
|
-
tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
28
|
-
target: 'web',
|
29
|
-
newProject: true,
|
30
|
-
framework: 'react',
|
31
|
-
});
|
32
|
-
tasks.push(rspackTask);
|
33
|
-
}
|
34
16
|
function handleStyledJsxForRspack(tasks, tree, options) {
|
35
17
|
devkit_1.logger.warn(`${pc.bold('styled-jsx')} is not supported by ${pc.bold('Rspack')}. We've added ${pc.bold('babel-loader')} to your project, but using babel will slow down your build.`);
|
36
18
|
tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, { 'babel-loader': versions_1.babelLoaderVersion }));
|
@@ -11,6 +11,18 @@ async function setupViteConfiguration(tree, options, tasks) {
|
|
11
11
|
if (tree.exists((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'))) {
|
12
12
|
tree.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'));
|
13
13
|
}
|
14
|
+
const reactRouterFrameworkConfig = {
|
15
|
+
imports: [`import { reactRouter } from '@react-router/dev/vite'`],
|
16
|
+
plugins: ['!process.env.VITEST && reactRouter()'],
|
17
|
+
};
|
18
|
+
const baseReactConfig = {
|
19
|
+
imports: [
|
20
|
+
options.compiler === 'swc'
|
21
|
+
? `import react from '@vitejs/plugin-react-swc'`
|
22
|
+
: `import react from '@vitejs/plugin-react'`,
|
23
|
+
],
|
24
|
+
plugins: ['react()'],
|
25
|
+
};
|
14
26
|
const viteTask = await viteConfigurationGenerator(tree, {
|
15
27
|
uiFramework: 'react',
|
16
28
|
project: options.projectName,
|
@@ -29,12 +41,9 @@ async function setupViteConfiguration(tree, options, tasks) {
|
|
29
41
|
includeVitest: options.unitTestRunner === 'vitest',
|
30
42
|
inSourceTests: options.inSourceTests,
|
31
43
|
rollupOptionsExternal: ["'react'", "'react-dom'", "'react/jsx-runtime'"],
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
: `import react from '@vitejs/plugin-react'`,
|
36
|
-
],
|
37
|
-
plugins: ['react()'],
|
44
|
+
...(options.useReactRouter
|
45
|
+
? reactRouterFrameworkConfig
|
46
|
+
: baseReactConfig),
|
38
47
|
}, false);
|
39
48
|
}
|
40
49
|
async function setupVitestConfiguration(tree, options, tasks) {
|
@@ -1,3 +1,64 @@
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
2
|
+
import { WithNxOptions } from '@nx/webpack';
|
3
|
+
import { WithReactOptions } from '../../../../plugins/with-react';
|
2
4
|
import { NormalizedSchema } from '../schema';
|
5
|
+
export declare function getDefaultTemplateVariables(host: Tree, options: NormalizedSchema): {
|
6
|
+
typesNodeVersion: string;
|
7
|
+
typesReactDomVersion: string;
|
8
|
+
reactRouterVersion: string;
|
9
|
+
typesReactVersion: string;
|
10
|
+
reactDomVersion: string;
|
11
|
+
reactVersion: string;
|
12
|
+
reactRouterIsBotVersion: string;
|
13
|
+
js: boolean;
|
14
|
+
tmpl: string;
|
15
|
+
offsetFromRoot: string;
|
16
|
+
appTests: string;
|
17
|
+
inSourceVitestTests: string;
|
18
|
+
style: "none" | "styled-components" | "@emotion/styled" | "styled-jsx" | "css" | "scss" | "less";
|
19
|
+
hasStyleFile: boolean;
|
20
|
+
isUsingTsSolutionSetup: boolean;
|
21
|
+
projectName: string;
|
22
|
+
appProjectRoot: string;
|
23
|
+
e2eProjectName: string;
|
24
|
+
e2eProjectRoot: string;
|
25
|
+
importPath: string;
|
26
|
+
parsedTags: string[];
|
27
|
+
fileName: string;
|
28
|
+
styledModule: null | import("../../../..").SupportedStyles;
|
29
|
+
hasStyles: boolean;
|
30
|
+
unitTestRunner: "jest" | "vitest" | "none";
|
31
|
+
addPlugin?: boolean;
|
32
|
+
names: ReturnType<typeof import("@nx/devkit").names>;
|
33
|
+
isUsingTsSolutionConfig?: boolean;
|
34
|
+
directory: string;
|
35
|
+
name: string;
|
36
|
+
skipFormat?: boolean;
|
37
|
+
tags?: string;
|
38
|
+
inSourceTests?: boolean;
|
39
|
+
e2eTestRunner: "cypress" | "playwright" | "none";
|
40
|
+
linter: import("@nx/eslint").Linter | import("@nx/eslint").LinterType;
|
41
|
+
classComponent?: boolean;
|
42
|
+
routing?: boolean;
|
43
|
+
useReactRouter?: boolean;
|
44
|
+
skipNxJson?: boolean;
|
45
|
+
globalCss?: boolean;
|
46
|
+
strict?: boolean;
|
47
|
+
setParserOptionsProject?: boolean;
|
48
|
+
compiler?: "babel" | "swc";
|
49
|
+
remotes?: string[];
|
50
|
+
devServerPort?: number;
|
51
|
+
skipPackageJson?: boolean;
|
52
|
+
rootProject?: boolean;
|
53
|
+
bundler?: "webpack" | "vite" | "rspack" | "rsbuild";
|
54
|
+
minimal?: boolean;
|
55
|
+
nxCloudToken?: string;
|
56
|
+
useTsSolution?: boolean;
|
57
|
+
formatter?: "prettier" | "none";
|
58
|
+
useProjectJson?: boolean;
|
59
|
+
className: string;
|
60
|
+
propertyName: string;
|
61
|
+
constantName: string;
|
62
|
+
};
|
63
|
+
export declare function createNxRspackPluginOptions(options: NormalizedSchema, rootOffset: string, tsx?: boolean): WithNxOptions & WithReactOptions;
|
3
64
|
export declare function createApplicationFiles(host: Tree, options: NormalizedSchema): Promise<void>;
|
@@ -1,5 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getDefaultTemplateVariables = getDefaultTemplateVariables;
|
4
|
+
exports.createNxRspackPluginOptions = createNxRspackPluginOptions;
|
3
5
|
exports.createApplicationFiles = createApplicationFiles;
|
4
6
|
const devkit_1 = require("@nx/devkit");
|
5
7
|
const js_1 = require("@nx/js");
|
@@ -12,6 +14,53 @@ const get_app_tests_1 = require("./get-app-tests");
|
|
12
14
|
const onboarding_1 = require("nx/src/nx-cloud/utilities/onboarding");
|
13
15
|
const has_rspack_plugin_1 = require("../../../utils/has-rspack-plugin");
|
14
16
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
17
|
+
const versions_1 = require("../../../utils/versions");
|
18
|
+
function getDefaultTemplateVariables(host, options) {
|
19
|
+
const hasStyleFile = ['scss', 'css', 'less'].includes(options.style);
|
20
|
+
const appTests = (0, get_app_tests_1.getAppTests)(options);
|
21
|
+
return {
|
22
|
+
...options.names,
|
23
|
+
...options,
|
24
|
+
typesNodeVersion: versions_1.typesNodeVersion,
|
25
|
+
typesReactDomVersion: versions_1.typesReactDomVersion,
|
26
|
+
reactRouterVersion: versions_1.reactRouterVersion,
|
27
|
+
typesReactVersion: versions_1.typesReactVersion,
|
28
|
+
reactDomVersion: versions_1.reactDomVersion,
|
29
|
+
reactVersion: versions_1.reactVersion,
|
30
|
+
reactRouterIsBotVersion: versions_1.reactRouterIsBotVersion,
|
31
|
+
js: !!options.js, // Ensure this is defined in template
|
32
|
+
tmpl: '',
|
33
|
+
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
|
34
|
+
appTests,
|
35
|
+
inSourceVitestTests: (0, get_in_source_vitest_tests_template_1.getInSourceVitestTestsTemplate)(appTests),
|
36
|
+
style: options.style === 'tailwind' ? 'css' : options.style,
|
37
|
+
hasStyleFile,
|
38
|
+
isUsingTsSolutionSetup: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host),
|
39
|
+
};
|
40
|
+
}
|
41
|
+
function createNxRspackPluginOptions(options, rootOffset, tsx = true) {
|
42
|
+
return {
|
43
|
+
target: 'web',
|
44
|
+
outputPath: options.isUsingTsSolutionConfig
|
45
|
+
? 'dist'
|
46
|
+
: (0, devkit_1.joinPathFragments)(rootOffset, 'dist', options.appProjectRoot != '.'
|
47
|
+
? options.appProjectRoot
|
48
|
+
: options.projectName),
|
49
|
+
index: './src/index.html',
|
50
|
+
baseHref: '/',
|
51
|
+
main: (0, maybe_js_1.maybeJs)({
|
52
|
+
js: options.js,
|
53
|
+
useJsx: true,
|
54
|
+
}, `./src/main.${tsx ? 'tsx' : 'ts'}`),
|
55
|
+
tsConfig: './tsconfig.app.json',
|
56
|
+
assets: ['./src/favicon.ico', './src/assets'],
|
57
|
+
styles: options.styledModule || !options.hasStyles
|
58
|
+
? []
|
59
|
+
: [
|
60
|
+
`./src/styles.${options.style !== 'tailwind' ? options.style : 'css'}`,
|
61
|
+
],
|
62
|
+
};
|
63
|
+
}
|
15
64
|
async function createApplicationFiles(host, options) {
|
16
65
|
let styleSolutionSpecificAppFiles;
|
17
66
|
if (options.styledModule && options.style !== 'styled-jsx') {
|
@@ -32,27 +81,17 @@ async function createApplicationFiles(host, options) {
|
|
32
81
|
else {
|
33
82
|
styleSolutionSpecificAppFiles = '../files/style-css-module';
|
34
83
|
}
|
35
|
-
const hasStyleFile = ['scss', 'css', 'less'].includes(options.style);
|
36
84
|
const onBoardingStatus = await (0, onboarding_1.createNxCloudOnboardingURLForWelcomeApp)(host, options.nxCloudToken);
|
37
85
|
const connectCloudUrl = onBoardingStatus === 'unclaimed' &&
|
38
86
|
(await (0, onboarding_1.getNxCloudAppOnBoardingUrl)(options.nxCloudToken));
|
39
87
|
const relativePathToRootTsConfig = (0, js_1.getRelativePathToRootTsConfig)(host, options.appProjectRoot);
|
40
|
-
const
|
41
|
-
|
42
|
-
...(0, devkit_1.names)(options.name),
|
43
|
-
...options,
|
44
|
-
js: !!options.js, // Ensure this is defined in template
|
45
|
-
tmpl: '',
|
46
|
-
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.appProjectRoot),
|
47
|
-
appTests,
|
48
|
-
inSourceVitestTests: (0, get_in_source_vitest_tests_template_1.getInSourceVitestTestsTemplate)(appTests),
|
49
|
-
style: options.style === 'tailwind' ? 'css' : options.style,
|
50
|
-
hasStyleFile,
|
51
|
-
isUsingTsSolutionSetup: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host),
|
52
|
-
};
|
53
|
-
if (options.bundler === 'vite') {
|
88
|
+
const templateVariables = getDefaultTemplateVariables(host, options);
|
89
|
+
if (options.bundler === 'vite' && !options.useReactRouter) {
|
54
90
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-vite'), options.appProjectRoot, templateVariables);
|
55
91
|
}
|
92
|
+
else if (options.bundler === 'vite' && options.useReactRouter) {
|
93
|
+
generateReactRouterFiles(host, options, templateVariables);
|
94
|
+
}
|
56
95
|
else if (options.bundler === 'webpack') {
|
57
96
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-webpack'), options.appProjectRoot, {
|
58
97
|
...templateVariables,
|
@@ -137,9 +176,12 @@ async function createApplicationFiles(host, options) {
|
|
137
176
|
const tutorialUrl = options.rootProject
|
138
177
|
? 'https://nx.dev/getting-started/tutorials/react-standalone-tutorial'
|
139
178
|
: 'https://nx.dev/react-tutorial/1-code-generation?utm_source=nx-project';
|
140
|
-
|
179
|
+
const path = options.useReactRouter
|
180
|
+
? '../files/react-router-ssr/nx-welcome'
|
181
|
+
: '../files/nx-welcome';
|
182
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, path, onBoardingStatus), options.appProjectRoot, { ...templateVariables, connectCloudUrl, tutorialUrl });
|
141
183
|
}
|
142
|
-
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, styleSolutionSpecificAppFiles), options.appProjectRoot, templateVariables);
|
184
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, styleSolutionSpecificAppFiles, options.useReactRouter ? 'src' : ''), options.appProjectRoot, templateVariables);
|
143
185
|
if (options.js) {
|
144
186
|
(0, devkit_1.toJS)(host, {
|
145
187
|
useJsx: options.bundler === 'vite' || options.bundler === 'rspack',
|
@@ -171,26 +213,26 @@ function createNxWebpackPluginOptions(options, rootOffset) {
|
|
171
213
|
],
|
172
214
|
};
|
173
215
|
}
|
174
|
-
function
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
}
|
216
|
+
function generateReactRouterFiles(tree, options, templateVariables) {
|
217
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, '../files/react-router-ssr/common'), options.appProjectRoot, templateVariables);
|
218
|
+
if (options.rootProject) {
|
219
|
+
const gitignore = tree.read('.gitignore', 'utf-8');
|
220
|
+
tree.write('.gitignore', `${gitignore}\n.cache\nbuild\npublic/build\n.env\n\.react-router\n`);
|
221
|
+
}
|
222
|
+
else {
|
223
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, '../files/react-router-ssr/non-root'), options.appProjectRoot, templateVariables);
|
224
|
+
}
|
225
|
+
if (options.isUsingTsSolutionConfig) {
|
226
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, '../files/react-router-ssr/ts-solution'), options.appProjectRoot, templateVariables);
|
227
|
+
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), (json) => {
|
228
|
+
if (options.projectName !== options.importPath) {
|
229
|
+
json.nx = { name: options.projectName };
|
230
|
+
}
|
231
|
+
if (options.parsedTags?.length) {
|
232
|
+
json.nx ??= {};
|
233
|
+
json.nx.tags = options.parsedTags;
|
234
|
+
}
|
235
|
+
return json;
|
236
|
+
});
|
237
|
+
}
|
196
238
|
}
|