@nx/react 0.0.0-pr-29314-e664f92 → 0.0.0-pr-29286-735af1e
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/LICENSE +1 -1
- package/migrations.json +15 -0
- package/package.json +8 -7
- package/plugins/jest.js +6 -11
- package/src/generators/application/application.d.ts +3 -3
- package/src/generators/application/application.js +59 -194
- package/src/generators/application/files/base-rsbuild/src/app/__fileName__.spec.tsx__tmpl__ +10 -0
- package/src/generators/application/files/base-rsbuild/src/assets/.gitkeep +0 -0
- package/src/generators/application/files/base-rsbuild/src/favicon.ico +0 -0
- package/src/generators/application/files/base-rsbuild/src/index.html +14 -0
- package/src/generators/application/files/base-rsbuild/src/main.tsx__tmpl__ +32 -0
- package/src/generators/application/files/base-rsbuild/tsconfig.app.json__tmpl__ +31 -0
- package/src/generators/application/files/style-tailwind/src/app/__fileName__.tsx__tmpl__ +1 -1
- package/src/generators/application/lib/add-e2e.js +13 -1
- package/src/generators/application/lib/add-linting.d.ts +3 -0
- package/src/generators/application/lib/add-linting.js +48 -0
- package/src/generators/application/lib/bundlers/add-rsbuild.d.ts +4 -0
- package/src/generators/application/lib/bundlers/add-rsbuild.js +63 -0
- package/src/generators/application/lib/bundlers/add-rspack.d.ts +5 -0
- package/src/generators/application/lib/bundlers/add-rspack.js +55 -0
- package/src/generators/application/lib/bundlers/add-vite.d.ts +4 -0
- package/src/generators/application/lib/bundlers/add-vite.js +67 -0
- package/src/generators/application/lib/bundlers/add-webpack.d.ts +3 -0
- package/src/generators/application/lib/bundlers/add-webpack.js +18 -0
- package/src/generators/application/lib/create-application-files.js +5 -0
- package/src/generators/application/lib/install-common-dependencies.d.ts +1 -1
- package/src/generators/application/lib/install-common-dependencies.js +6 -3
- package/src/generators/application/schema.d.ts +1 -1
- package/src/generators/application/schema.json +1 -1
- package/src/generators/component/files/__fileName__.__ext__ +3 -3
- package/src/generators/component/schema.json +4 -0
- package/src/generators/host/host.js +1 -0
- package/src/generators/init/init.d.ts +1 -1
- package/src/generators/init/init.js +8 -6
- package/src/generators/library/library.js +4 -7
- package/src/generators/library/schema.json +4 -0
- package/src/generators/remote/remote.js +1 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +6 -0
- package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.d.ts +2 -0
- package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.js +18 -0
- package/src/utils/has-rsbuild-plugin.d.ts +2 -0
- package/src/utils/has-rsbuild-plugin.js +10 -0
- package/src/utils/version-utils.d.ts +14 -0
- package/src/utils/version-utils.js +56 -0
- package/src/utils/versions.d.ts +14 -7
- package/src/utils/versions.js +16 -8
package/LICENSE
CHANGED
package/migrations.json
CHANGED
|
@@ -41,6 +41,12 @@
|
|
|
41
41
|
"version": "20.2.0-beta.2",
|
|
42
42
|
"description": "Update the withModuleFederation import use @nx/module-federation/webpack.",
|
|
43
43
|
"factory": "./src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package"
|
|
44
|
+
},
|
|
45
|
+
"ensure-nx-module-federation-package": {
|
|
46
|
+
"cli": "nx",
|
|
47
|
+
"version": "20.3.0-beta.2",
|
|
48
|
+
"description": "If workspace includes Module Federation projects, ensure the new @nx/module-federation package is installed.",
|
|
49
|
+
"factory": "./src/migrations/update-20-3-0/ensure-nx-module-federation-package"
|
|
44
50
|
}
|
|
45
51
|
},
|
|
46
52
|
"packageJsonUpdates": {
|
|
@@ -185,6 +191,15 @@
|
|
|
185
191
|
"alwaysAddToPackageJson": false
|
|
186
192
|
}
|
|
187
193
|
}
|
|
194
|
+
},
|
|
195
|
+
"20.3.0": {
|
|
196
|
+
"version": "20.3.0-beta.0",
|
|
197
|
+
"packages": {
|
|
198
|
+
"@testing-library/react": {
|
|
199
|
+
"version": "16.1.0",
|
|
200
|
+
"alwaysAddToPackageJson": false
|
|
201
|
+
}
|
|
202
|
+
}
|
|
188
203
|
}
|
|
189
204
|
}
|
|
190
205
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/react",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-29286-735af1e",
|
|
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, Vitest, Playwright, 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": {
|
|
@@ -38,13 +38,14 @@
|
|
|
38
38
|
"minimatch": "9.0.3",
|
|
39
39
|
"picocolors": "^1.1.0",
|
|
40
40
|
"tslib": "^2.3.0",
|
|
41
|
-
"@nx/devkit": "0.0.0-pr-
|
|
42
|
-
"@nx/js": "0.0.0-pr-
|
|
43
|
-
"@nx/eslint": "0.0.0-pr-
|
|
44
|
-
"@nx/web": "0.0.0-pr-
|
|
45
|
-
"@nx/module-federation": "0.0.0-pr-
|
|
41
|
+
"@nx/devkit": "0.0.0-pr-29286-735af1e",
|
|
42
|
+
"@nx/js": "0.0.0-pr-29286-735af1e",
|
|
43
|
+
"@nx/eslint": "0.0.0-pr-29286-735af1e",
|
|
44
|
+
"@nx/web": "0.0.0-pr-29286-735af1e",
|
|
45
|
+
"@nx/module-federation": "0.0.0-pr-29286-735af1e",
|
|
46
46
|
"express": "^4.19.2",
|
|
47
|
-
"http-proxy-middleware": "^3.0.3"
|
|
47
|
+
"http-proxy-middleware": "^3.0.3",
|
|
48
|
+
"semver": "^7.6.3"
|
|
48
49
|
},
|
|
49
50
|
"publishConfig": {
|
|
50
51
|
"access": "public"
|
package/plugins/jest.js
CHANGED
|
@@ -16,17 +16,12 @@ module.exports = {
|
|
|
16
16
|
module.exports = {
|
|
17
17
|
__esModule: true,
|
|
18
18
|
default: ${assetFilename},
|
|
19
|
-
ReactComponent:
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
props: Object.assign({}, props, {
|
|
26
|
-
children: ${assetFilename}
|
|
27
|
-
})
|
|
28
|
-
};
|
|
29
|
-
}),
|
|
19
|
+
ReactComponent: function ${componentName}(props) {
|
|
20
|
+
return React.createElement(
|
|
21
|
+
'svg',
|
|
22
|
+
Object.assign({}, props, { children: ${assetFilename} })
|
|
23
|
+
);
|
|
24
|
+
},
|
|
30
25
|
};`,
|
|
31
26
|
};
|
|
32
27
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Schema } from './schema';
|
|
2
1
|
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
3
|
-
|
|
4
|
-
export declare function
|
|
2
|
+
import { Schema } from './schema';
|
|
3
|
+
export declare function applicationGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
4
|
+
export declare function applicationGeneratorInternal(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
5
5
|
export default applicationGenerator;
|
|
@@ -2,7 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applicationGenerator = applicationGenerator;
|
|
4
4
|
exports.applicationGeneratorInternal = applicationGeneratorInternal;
|
|
5
|
-
const
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const js_1 = require("@nx/js");
|
|
7
|
+
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
8
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
9
|
+
const create_ts_config_1 = require("../../utils/create-ts-config");
|
|
10
|
+
const add_styled_dependencies_1 = require("../../rules/add-styled-dependencies");
|
|
11
|
+
const setup_tailwind_1 = require("../setup-tailwind/setup-tailwind");
|
|
12
|
+
const init_1 = require("../init/init");
|
|
6
13
|
const create_application_files_1 = require("./lib/create-application-files");
|
|
7
14
|
const update_jest_config_1 = require("./lib/update-jest-config");
|
|
8
15
|
const normalize_options_1 = require("./lib/normalize-options");
|
|
@@ -10,71 +17,23 @@ const add_project_1 = require("./lib/add-project");
|
|
|
10
17
|
const add_jest_1 = require("./lib/add-jest");
|
|
11
18
|
const add_routing_1 = require("./lib/add-routing");
|
|
12
19
|
const set_defaults_1 = require("./lib/set-defaults");
|
|
13
|
-
const
|
|
14
|
-
const devkit_1 = require("@nx/devkit");
|
|
15
|
-
const init_1 = require("../init/init");
|
|
16
|
-
const eslint_1 = require("@nx/eslint");
|
|
17
|
-
const versions_1 = require("../../utils/versions");
|
|
18
|
-
const maybe_js_1 = require("../../utils/maybe-js");
|
|
19
|
-
const install_common_dependencies_1 = require("./lib/install-common-dependencies");
|
|
20
|
-
const create_ts_config_1 = require("../../utils/create-ts-config");
|
|
21
|
-
const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
|
22
|
-
const pc = require("picocolors");
|
|
23
|
-
const show_possible_warnings_1 = require("./lib/show-possible-warnings");
|
|
20
|
+
const add_linting_1 = require("./lib/add-linting");
|
|
24
21
|
const add_e2e_1 = require("./lib/add-e2e");
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
async function
|
|
32
|
-
|
|
33
|
-
if (options.linter === eslint_1.Linter.EsLint) {
|
|
34
|
-
const lintTask = await (0, eslint_1.lintProjectGenerator)(host, {
|
|
35
|
-
linter: options.linter,
|
|
36
|
-
project: options.projectName,
|
|
37
|
-
tsConfigPaths: [
|
|
38
|
-
(0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
|
39
|
-
],
|
|
40
|
-
unitTestRunner: options.unitTestRunner,
|
|
41
|
-
skipFormat: true,
|
|
42
|
-
rootProject: options.rootProject,
|
|
43
|
-
skipPackageJson: options.skipPackageJson,
|
|
44
|
-
addPlugin: options.addPlugin,
|
|
45
|
-
});
|
|
46
|
-
tasks.push(lintTask);
|
|
47
|
-
if ((0, eslint_file_1.isEslintConfigSupported)(host)) {
|
|
48
|
-
if ((0, flat_config_1.useFlatConfig)(host)) {
|
|
49
|
-
(0, eslint_file_1.addPredefinedConfigToFlatLintConfig)(host, options.appProjectRoot, 'flat/react');
|
|
50
|
-
// Add an empty rules object to users know how to add/override rules
|
|
51
|
-
(0, eslint_file_1.addOverrideToLintConfig)(host, options.appProjectRoot, {
|
|
52
|
-
files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
|
|
53
|
-
rules: {},
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
const addExtendsTask = (0, eslint_file_1.addExtendsToLintConfig)(host, options.appProjectRoot, { name: 'plugin:@nx/react', needCompatFixup: true });
|
|
58
|
-
tasks.push(addExtendsTask);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (!options.skipPackageJson) {
|
|
62
|
-
const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, lint_1.extraEslintDependencies.dependencies, lint_1.extraEslintDependencies.devDependencies);
|
|
63
|
-
const addSwcTask = (0, add_swc_dependencies_1.addSwcDependencies)(host);
|
|
64
|
-
tasks.push(installTask, addSwcTask);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
68
|
-
}
|
|
69
|
-
async function applicationGenerator(host, schema) {
|
|
70
|
-
return await applicationGeneratorInternal(host, {
|
|
22
|
+
const show_possible_warnings_1 = require("./lib/show-possible-warnings");
|
|
23
|
+
const install_common_dependencies_1 = require("./lib/install-common-dependencies");
|
|
24
|
+
const add_webpack_1 = require("./lib/bundlers/add-webpack");
|
|
25
|
+
const add_rspack_1 = require("./lib/bundlers/add-rspack");
|
|
26
|
+
const add_rsbuild_1 = require("./lib/bundlers/add-rsbuild");
|
|
27
|
+
const add_vite_1 = require("./lib/bundlers/add-vite");
|
|
28
|
+
async function applicationGenerator(tree, schema) {
|
|
29
|
+
return await applicationGeneratorInternal(tree, {
|
|
71
30
|
addPlugin: false,
|
|
72
31
|
...schema,
|
|
73
32
|
});
|
|
74
33
|
}
|
|
75
|
-
async function applicationGeneratorInternal(
|
|
34
|
+
async function applicationGeneratorInternal(tree, schema) {
|
|
76
35
|
const tasks = [];
|
|
77
|
-
const jsInitTask = await (0, js_1.initGenerator)(
|
|
36
|
+
const jsInitTask = await (0, js_1.initGenerator)(tree, {
|
|
78
37
|
...schema,
|
|
79
38
|
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
|
|
80
39
|
skipFormat: true,
|
|
@@ -82,15 +41,15 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
82
41
|
formatter: schema.formatter,
|
|
83
42
|
});
|
|
84
43
|
tasks.push(jsInitTask);
|
|
85
|
-
const options = await (0, normalize_options_1.normalizeOptions)(
|
|
86
|
-
(0, show_possible_warnings_1.showPossibleWarnings)(
|
|
87
|
-
const initTask = await (0, init_1.default)(
|
|
44
|
+
const options = await (0, normalize_options_1.normalizeOptions)(tree, schema);
|
|
45
|
+
(0, show_possible_warnings_1.showPossibleWarnings)(tree, options);
|
|
46
|
+
const initTask = await (0, init_1.default)(tree, {
|
|
88
47
|
...options,
|
|
89
48
|
skipFormat: true,
|
|
90
49
|
});
|
|
91
50
|
tasks.push(initTask);
|
|
92
51
|
if (!options.addPlugin) {
|
|
93
|
-
const nxJson = (0, devkit_1.readNxJson)(
|
|
52
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
94
53
|
nxJson.targetDefaults ??= {};
|
|
95
54
|
if (!Object.keys(nxJson.targetDefaults).includes('build')) {
|
|
96
55
|
nxJson.targetDefaults.build = {
|
|
@@ -101,172 +60,78 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
101
60
|
else if (!nxJson.targetDefaults.build.dependsOn) {
|
|
102
61
|
nxJson.targetDefaults.build.dependsOn = ['^build'];
|
|
103
62
|
}
|
|
104
|
-
(0, devkit_1.updateNxJson)(
|
|
63
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
105
64
|
}
|
|
106
65
|
if (options.bundler === 'webpack') {
|
|
107
|
-
|
|
108
|
-
const webpackInitTask = await webpackInitGenerator(host, {
|
|
109
|
-
skipPackageJson: options.skipPackageJson,
|
|
110
|
-
skipFormat: true,
|
|
111
|
-
addPlugin: options.addPlugin,
|
|
112
|
-
});
|
|
113
|
-
tasks.push(webpackInitTask);
|
|
114
|
-
if (!options.skipPackageJson) {
|
|
115
|
-
const { ensureDependencies } = await Promise.resolve().then(() => require('@nx/webpack/src/utils/ensure-dependencies'));
|
|
116
|
-
tasks.push(ensureDependencies(host, { uiFramework: 'react' }));
|
|
117
|
-
}
|
|
66
|
+
await (0, add_webpack_1.initWebpack)(tree, options, tasks);
|
|
118
67
|
}
|
|
119
68
|
else if (options.bundler === 'rspack') {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
skipFormat: true,
|
|
125
|
-
});
|
|
126
|
-
tasks.push(rspackInitTask);
|
|
69
|
+
await (0, add_rspack_1.initRspack)(tree, options, tasks);
|
|
70
|
+
}
|
|
71
|
+
else if (options.bundler === 'rsbuild') {
|
|
72
|
+
await (0, add_rsbuild_1.initRsbuild)(tree, options, tasks);
|
|
127
73
|
}
|
|
128
74
|
if (!options.rootProject) {
|
|
129
|
-
(0, create_ts_config_1.extractTsConfigBase)(
|
|
75
|
+
(0, create_ts_config_1.extractTsConfigBase)(tree);
|
|
130
76
|
}
|
|
131
|
-
await (0, create_application_files_1.createApplicationFiles)(
|
|
132
|
-
(0, add_project_1.addProject)(
|
|
77
|
+
await (0, create_application_files_1.createApplicationFiles)(tree, options);
|
|
78
|
+
(0, add_project_1.addProject)(tree, options);
|
|
133
79
|
if (options.style === 'tailwind') {
|
|
134
|
-
const twTask = await (0, setup_tailwind_1.setupTailwindGenerator)(
|
|
80
|
+
const twTask = await (0, setup_tailwind_1.setupTailwindGenerator)(tree, {
|
|
135
81
|
project: options.projectName,
|
|
136
82
|
});
|
|
137
83
|
tasks.push(twTask);
|
|
138
84
|
}
|
|
139
85
|
if (options.bundler === 'vite') {
|
|
140
|
-
|
|
141
|
-
// We recommend users use `import.meta.env.MODE` and other variables in their code to differentiate between production and development.
|
|
142
|
-
// See: https://vitejs.dev/guide/env-and-mode.html
|
|
143
|
-
if (host.exists((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'))) {
|
|
144
|
-
host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'));
|
|
145
|
-
}
|
|
146
|
-
const viteTask = await viteConfigurationGenerator(host, {
|
|
147
|
-
uiFramework: 'react',
|
|
148
|
-
project: options.projectName,
|
|
149
|
-
newProject: true,
|
|
150
|
-
includeVitest: options.unitTestRunner === 'vitest',
|
|
151
|
-
inSourceTests: options.inSourceTests,
|
|
152
|
-
compiler: options.compiler,
|
|
153
|
-
skipFormat: true,
|
|
154
|
-
addPlugin: options.addPlugin,
|
|
155
|
-
projectType: 'application',
|
|
156
|
-
});
|
|
157
|
-
tasks.push(viteTask);
|
|
158
|
-
createOrEditViteConfig(host, {
|
|
159
|
-
project: options.projectName,
|
|
160
|
-
includeLib: false,
|
|
161
|
-
includeVitest: options.unitTestRunner === 'vitest',
|
|
162
|
-
inSourceTests: options.inSourceTests,
|
|
163
|
-
rollupOptionsExternal: [
|
|
164
|
-
"'react'",
|
|
165
|
-
"'react-dom'",
|
|
166
|
-
"'react/jsx-runtime'",
|
|
167
|
-
],
|
|
168
|
-
imports: [
|
|
169
|
-
options.compiler === 'swc'
|
|
170
|
-
? `import react from '@vitejs/plugin-react-swc'`
|
|
171
|
-
: `import react from '@vitejs/plugin-react'`,
|
|
172
|
-
],
|
|
173
|
-
plugins: ['react()'],
|
|
174
|
-
}, false);
|
|
86
|
+
await (0, add_vite_1.setupViteConfiguration)(tree, options, tasks);
|
|
175
87
|
}
|
|
176
88
|
else if (options.bundler === 'rspack') {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
js: options.js,
|
|
182
|
-
useJsx: true,
|
|
183
|
-
}, `src/main.tsx`)),
|
|
184
|
-
tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
|
185
|
-
target: 'web',
|
|
186
|
-
newProject: true,
|
|
187
|
-
framework: 'react',
|
|
188
|
-
});
|
|
189
|
-
tasks.push(rspackTask);
|
|
89
|
+
await (0, add_rspack_1.setupRspackConfiguration)(tree, options, tasks);
|
|
90
|
+
}
|
|
91
|
+
else if (options.bundler === 'rsbuild') {
|
|
92
|
+
await (0, add_rsbuild_1.setupRsbuildConfiguration)(tree, options, tasks);
|
|
190
93
|
}
|
|
191
94
|
if (options.bundler !== 'vite' && options.unitTestRunner === 'vitest') {
|
|
192
|
-
|
|
193
|
-
const vitestTask = await vitestGenerator(host, {
|
|
194
|
-
uiFramework: 'react',
|
|
195
|
-
coverageProvider: 'v8',
|
|
196
|
-
project: options.projectName,
|
|
197
|
-
inSourceTests: options.inSourceTests,
|
|
198
|
-
skipFormat: true,
|
|
199
|
-
addPlugin: options.addPlugin,
|
|
200
|
-
});
|
|
201
|
-
tasks.push(vitestTask);
|
|
202
|
-
createOrEditViteConfig(host, {
|
|
203
|
-
project: options.projectName,
|
|
204
|
-
includeLib: false,
|
|
205
|
-
includeVitest: true,
|
|
206
|
-
inSourceTests: options.inSourceTests,
|
|
207
|
-
rollupOptionsExternal: [
|
|
208
|
-
"'react'",
|
|
209
|
-
"'react-dom'",
|
|
210
|
-
"'react/jsx-runtime'",
|
|
211
|
-
],
|
|
212
|
-
imports: [
|
|
213
|
-
options.compiler === 'swc'
|
|
214
|
-
? `import react from '@vitejs/plugin-react-swc'`
|
|
215
|
-
: `import react from '@vitejs/plugin-react'`,
|
|
216
|
-
],
|
|
217
|
-
plugins: ['react()'],
|
|
218
|
-
}, true);
|
|
95
|
+
await (0, add_vite_1.setupVitestConfiguration)(tree, options, tasks);
|
|
219
96
|
}
|
|
220
97
|
if ((options.bundler === 'vite' || options.unitTestRunner === 'vitest') &&
|
|
221
98
|
options.inSourceTests) {
|
|
222
|
-
|
|
99
|
+
tree.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/app/${options.fileName}.spec.tsx`));
|
|
223
100
|
}
|
|
224
|
-
const lintTask = await addLinting(
|
|
101
|
+
const lintTask = await (0, add_linting_1.addLinting)(tree, options);
|
|
225
102
|
tasks.push(lintTask);
|
|
226
|
-
const e2eTask = await (0, add_e2e_1.addE2e)(
|
|
103
|
+
const e2eTask = await (0, add_e2e_1.addE2e)(tree, options);
|
|
227
104
|
tasks.push(e2eTask);
|
|
228
105
|
if (options.unitTestRunner === 'jest') {
|
|
229
|
-
const jestTask = await (0, add_jest_1.addJest)(
|
|
106
|
+
const jestTask = await (0, add_jest_1.addJest)(tree, options);
|
|
230
107
|
tasks.push(jestTask);
|
|
231
108
|
}
|
|
232
109
|
// Handle tsconfig.spec.json for jest or vitest
|
|
233
|
-
(0, update_jest_config_1.updateSpecConfig)(
|
|
234
|
-
const stylePreprocessorTask = (0, install_common_dependencies_1.installCommonDependencies)(
|
|
110
|
+
(0, update_jest_config_1.updateSpecConfig)(tree, options);
|
|
111
|
+
const stylePreprocessorTask = await (0, install_common_dependencies_1.installCommonDependencies)(tree, options);
|
|
235
112
|
tasks.push(stylePreprocessorTask);
|
|
236
|
-
const styledTask = (0, add_styled_dependencies_1.addStyledModuleDependencies)(
|
|
113
|
+
const styledTask = (0, add_styled_dependencies_1.addStyledModuleDependencies)(tree, options);
|
|
237
114
|
tasks.push(styledTask);
|
|
238
|
-
const routingTask = (0, add_routing_1.addRouting)(
|
|
115
|
+
const routingTask = (0, add_routing_1.addRouting)(tree, options);
|
|
239
116
|
tasks.push(routingTask);
|
|
240
|
-
(0, set_defaults_1.setDefaults)(
|
|
117
|
+
(0, set_defaults_1.setDefaults)(tree, options);
|
|
241
118
|
if (options.bundler === 'rspack' && options.style === 'styled-jsx') {
|
|
242
|
-
|
|
243
|
-
tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {}, { 'babel-loader': versions_1.babelLoaderVersion }));
|
|
244
|
-
host.write((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'rspack.config.js'), (0, devkit_1.stripIndents) `
|
|
245
|
-
const { composePlugins, withNx, withReact } = require('@nx/rspack');
|
|
246
|
-
module.exports = composePlugins(withNx(), withReact(), (config) => {
|
|
247
|
-
config.module.rules.push({
|
|
248
|
-
test: /\\.[jt]sx$/i,
|
|
249
|
-
use: [
|
|
250
|
-
{
|
|
251
|
-
loader: 'babel-loader',
|
|
252
|
-
options: {
|
|
253
|
-
presets: ['@babel/preset-typescript'],
|
|
254
|
-
plugins: ['styled-jsx/babel'],
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
|
-
],
|
|
258
|
-
});
|
|
259
|
-
return config;
|
|
260
|
-
});
|
|
261
|
-
`);
|
|
119
|
+
(0, add_rspack_1.handleStyledJsxForRspack)(tasks, tree, options);
|
|
262
120
|
}
|
|
263
|
-
(0, ts_solution_setup_1.updateTsconfigFiles)(
|
|
121
|
+
(0, ts_solution_setup_1.updateTsconfigFiles)(tree, options.appProjectRoot, 'tsconfig.app.json', {
|
|
264
122
|
jsx: 'react-jsx',
|
|
265
123
|
module: 'esnext',
|
|
266
124
|
moduleResolution: 'bundler',
|
|
267
|
-
}
|
|
125
|
+
}, options.linter === 'eslint'
|
|
126
|
+
? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
|
|
127
|
+
: undefined);
|
|
128
|
+
// If we are using the new TS solution
|
|
129
|
+
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
|
130
|
+
if (options.isUsingTsSolutionConfig) {
|
|
131
|
+
(0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.appProjectRoot);
|
|
132
|
+
}
|
|
268
133
|
if (!options.skipFormat) {
|
|
269
|
-
await (0, devkit_1.formatFiles)(
|
|
134
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
270
135
|
}
|
|
271
136
|
tasks.push(() => {
|
|
272
137
|
(0, log_show_project_command_1.logShowProjectCommand)(options.projectName);
|
|
File without changes
|
|
Binary file
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<title><%= className %></title>
|
|
6
|
+
<base href="/" />
|
|
7
|
+
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
9
|
+
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="root"></div>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<%_ if (strict) { _%>import { StrictMode } from 'react';<%_ } _%>
|
|
2
|
+
import * as ReactDOM from 'react-dom/client';
|
|
3
|
+
<%_ if (routing) { _%>import { BrowserRouter } from 'react-router-dom';<%_ } _%>
|
|
4
|
+
import App from './app/<%= fileName %>';
|
|
5
|
+
<%_ if(hasStyleFile) { _%>
|
|
6
|
+
import './styles.<%= style %>'
|
|
7
|
+
<%_ } _%>
|
|
8
|
+
|
|
9
|
+
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
|
|
10
|
+
<%_ if(strict && !routing) { _%>
|
|
11
|
+
root.render(
|
|
12
|
+
<StrictMode>
|
|
13
|
+
<App/>
|
|
14
|
+
</StrictMode>
|
|
15
|
+
)
|
|
16
|
+
<%_ } _%>
|
|
17
|
+
<%_ if(!strict && routing) { _%>
|
|
18
|
+
root.render(
|
|
19
|
+
<BrowserRouter>
|
|
20
|
+
<App/>
|
|
21
|
+
</BrowserRouter>
|
|
22
|
+
)
|
|
23
|
+
<%_ } _%>
|
|
24
|
+
<%_ if(strict && routing) { _%>
|
|
25
|
+
root.render(
|
|
26
|
+
<StrictMode>
|
|
27
|
+
<BrowserRouter>
|
|
28
|
+
<App/>
|
|
29
|
+
</BrowserRouter>
|
|
30
|
+
</StrictMode>
|
|
31
|
+
)
|
|
32
|
+
<%_ } _%>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<%_ if (isUsingTsSolutionSetup) { _%>{
|
|
2
|
+
"extends": "<%= offsetFromRoot%>tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "dist",
|
|
5
|
+
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"lib": ["dom"],
|
|
8
|
+
"types": [
|
|
9
|
+
"node",
|
|
10
|
+
<%_ if (style === 'styled-jsx') { _%>"@nx/react/typings/styled-jsx.d.ts",<%_ } _%>
|
|
11
|
+
"@nx/react/typings/cssmodule.d.ts",
|
|
12
|
+
"@nx/react/typings/image.d.ts"
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"],
|
|
16
|
+
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
|
17
|
+
}<% } else { %>{
|
|
18
|
+
"extends": "./tsconfig.json",
|
|
19
|
+
"compilerOptions": {
|
|
20
|
+
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
|
|
21
|
+
"types": [
|
|
22
|
+
"node",
|
|
23
|
+
<%_ if (style === 'styled-jsx') { _%>"@nx/react/typings/styled-jsx.d.ts",<%_ } _%>
|
|
24
|
+
"@nx/react/typings/cssmodule.d.ts",
|
|
25
|
+
"@nx/react/typings/image.d.ts"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"],
|
|
29
|
+
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
|
30
|
+
}
|
|
31
|
+
<% } %>
|
|
@@ -7,11 +7,14 @@ const versions_1 = require("../../../utils/versions");
|
|
|
7
7
|
const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
|
|
8
8
|
const has_vite_plugin_1 = require("../../../utils/has-vite-plugin");
|
|
9
9
|
const has_rspack_plugin_1 = require("../../../utils/has-rspack-plugin");
|
|
10
|
+
const has_rsbuild_plugin_1 = require("../../../utils/has-rsbuild-plugin");
|
|
10
11
|
const find_plugin_for_config_file_1 = require("@nx/devkit/src/utils/find-plugin-for-config-file");
|
|
11
12
|
const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
|
|
12
13
|
async function addE2e(tree, options) {
|
|
13
14
|
const hasNxBuildPlugin = (options.bundler === 'webpack' && (0, has_webpack_plugin_1.hasWebpackPlugin)(tree)) ||
|
|
14
15
|
(options.bundler === 'rspack' && (0, has_rspack_plugin_1.hasRspackPlugin)(tree)) ||
|
|
16
|
+
(options.bundler === 'rsbuild' &&
|
|
17
|
+
(await (0, has_rsbuild_plugin_1.hasRsbuildPlugin)(tree, options.appProjectRoot))) ||
|
|
15
18
|
(options.bundler === 'vite' && (0, has_vite_plugin_1.hasVitePlugin)(tree));
|
|
16
19
|
let e2eWebServerInfo = {
|
|
17
20
|
e2eWebServerAddress: `http://localhost:${options.devServerPort ?? 4200}`,
|
|
@@ -28,6 +31,11 @@ async function addE2e(tree, options) {
|
|
|
28
31
|
const { getViteE2EWebServerInfo } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
29
32
|
e2eWebServerInfo = await getViteE2EWebServerInfo(tree, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, `vite.config.${options.js ? 'js' : 'ts'}`), options.addPlugin, options.devServerPort ?? 4200);
|
|
30
33
|
}
|
|
34
|
+
else if (options.bundler === 'rsbuild') {
|
|
35
|
+
(0, devkit_1.ensurePackage)('@nx/rsbuild', versions_1.nxVersion);
|
|
36
|
+
const { getRsbuildE2EWebServerInfo } = await Promise.resolve().then(() => require('@nx/rsbuild/config-utils'));
|
|
37
|
+
e2eWebServerInfo = await getRsbuildE2EWebServerInfo(tree, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, `rsbuild.config.${options.js ? 'js' : 'ts'}`), options.addPlugin, options.devServerPort ?? 4200);
|
|
38
|
+
}
|
|
31
39
|
if (!hasNxBuildPlugin) {
|
|
32
40
|
await (0, web_1.webStaticServeGenerator)(tree, {
|
|
33
41
|
buildTarget: `${options.projectName}:build`,
|
|
@@ -65,7 +73,11 @@ async function addE2e(tree, options) {
|
|
|
65
73
|
project: options.e2eProjectName,
|
|
66
74
|
directory: 'src',
|
|
67
75
|
// the name and root are already normalized, instruct the generator to use them as is
|
|
68
|
-
bundler: options.bundler === 'rspack'
|
|
76
|
+
bundler: options.bundler === 'rspack'
|
|
77
|
+
? 'webpack'
|
|
78
|
+
: options.bundler === 'rsbuild'
|
|
79
|
+
? 'none'
|
|
80
|
+
: options.bundler,
|
|
69
81
|
skipFormat: true,
|
|
70
82
|
devServerTarget: e2eWebServerInfo.e2eDevServerTarget,
|
|
71
83
|
baseUrl: e2eWebServerInfo.e2eWebServerAddress,
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addLinting = addLinting;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const eslint_1 = require("@nx/eslint");
|
|
6
|
+
const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
|
|
7
|
+
const flat_config_1 = require("@nx/eslint/src/utils/flat-config");
|
|
8
|
+
const devkit_2 = require("@nx/devkit");
|
|
9
|
+
const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
|
10
|
+
const lint_1 = require("../../../utils/lint");
|
|
11
|
+
async function addLinting(host, options) {
|
|
12
|
+
const tasks = [];
|
|
13
|
+
if (options.linter === eslint_1.Linter.EsLint) {
|
|
14
|
+
const lintTask = await (0, eslint_1.lintProjectGenerator)(host, {
|
|
15
|
+
linter: options.linter,
|
|
16
|
+
project: options.projectName,
|
|
17
|
+
tsConfigPaths: [
|
|
18
|
+
(0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
|
19
|
+
],
|
|
20
|
+
unitTestRunner: options.unitTestRunner,
|
|
21
|
+
skipFormat: true,
|
|
22
|
+
rootProject: options.rootProject,
|
|
23
|
+
skipPackageJson: options.skipPackageJson,
|
|
24
|
+
addPlugin: options.addPlugin,
|
|
25
|
+
});
|
|
26
|
+
tasks.push(lintTask);
|
|
27
|
+
if ((0, eslint_file_1.isEslintConfigSupported)(host)) {
|
|
28
|
+
if ((0, flat_config_1.useFlatConfig)(host)) {
|
|
29
|
+
(0, eslint_file_1.addPredefinedConfigToFlatLintConfig)(host, options.appProjectRoot, 'flat/react');
|
|
30
|
+
// Add an empty rules object to users know how to add/override rules
|
|
31
|
+
(0, eslint_file_1.addOverrideToLintConfig)(host, options.appProjectRoot, {
|
|
32
|
+
files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
|
|
33
|
+
rules: {},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const addExtendsTask = (0, eslint_file_1.addExtendsToLintConfig)(host, options.appProjectRoot, { name: 'plugin:@nx/react', needCompatFixup: true });
|
|
38
|
+
tasks.push(addExtendsTask);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!options.skipPackageJson) {
|
|
42
|
+
const installTask = (0, devkit_2.addDependenciesToPackageJson)(host, lint_1.extraEslintDependencies.dependencies, lint_1.extraEslintDependencies.devDependencies);
|
|
43
|
+
const addSwcTask = (0, add_swc_dependencies_1.addSwcDependencies)(host);
|
|
44
|
+
tasks.push(installTask, addSwcTask);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return (0, devkit_2.runTasksInSerial)(...tasks);
|
|
48
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
import { NormalizedSchema, Schema } from '../../schema';
|
|
3
|
+
export declare function initRsbuild(tree: Tree, options: NormalizedSchema<Schema>, tasks: any[]): Promise<void>;
|
|
4
|
+
export declare function setupRsbuildConfiguration(tree: Tree, options: NormalizedSchema<Schema>, tasks: any[]): Promise<void>;
|