@nx/react 17.0.3 → 17.0.4
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/README.md +9 -4
- package/generators.json +1 -1
- package/index.d.ts +1 -0
- package/index.js +3 -1
- package/mf/dynamic-federation.d.ts +4 -0
- package/mf/dynamic-federation.js +75 -0
- package/mf/index.d.ts +1 -0
- package/mf/index.js +7 -0
- package/migrations.json +21 -0
- package/package.json +7 -7
- package/plugins/component-testing/index.js +52 -24
- package/plugins/component-testing/webpack-fallback.js +1 -1
- package/plugins/nx-react-webpack-plugin/lib/apply-react-config.d.ts +4 -0
- package/plugins/nx-react-webpack-plugin/lib/apply-react-config.js +86 -0
- package/plugins/nx-react-webpack-plugin/nx-react-webpack-plugin.d.ts +8 -0
- package/plugins/nx-react-webpack-plugin/nx-react-webpack-plugin.js +13 -0
- package/plugins/storybook/index.js +6 -2
- package/plugins/storybook/merge-plugins.d.ts +1 -1
- package/plugins/webpack.d.ts +1 -3
- package/plugins/webpack.js +3 -11
- package/plugins/with-react.d.ts +2 -4
- package/plugins/with-react.js +2 -58
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +12 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +149 -51
- package/src/executors/module-federation-dev-server/schema.json +9 -1
- package/src/generators/application/application.js +41 -18
- package/src/generators/application/files/base-vite/index.html__tmpl__ +1 -1
- package/src/generators/application/files/base-webpack/src/index.html +0 -2
- package/src/generators/application/files/base-webpack/webpack.config.js__tmpl__ +46 -5
- package/src/generators/application/files/nx-welcome/src/app/nx-welcome.tsx +54 -13
- package/src/generators/application/files/style-tailwind/src/app/__fileName__.tsx__tmpl__ +33 -0
- package/src/generators/application/files/style-tailwind/src/styles.css +1 -0
- package/src/generators/application/lib/add-e2e.js +25 -7
- package/src/generators/application/lib/add-jest.js +2 -2
- package/src/generators/application/lib/add-project.d.ts +2 -2
- package/src/generators/application/lib/add-project.js +12 -15
- package/src/generators/application/lib/add-routing.d.ts +1 -1
- package/src/generators/application/lib/add-routing.js +4 -8
- package/src/generators/application/lib/create-application-files.js +30 -1
- package/src/generators/application/lib/install-common-dependencies.js +15 -1
- package/src/generators/application/lib/normalize-options.js +35 -1
- package/src/generators/application/lib/set-defaults.js +1 -0
- package/src/generators/application/lib/update-jest-config.js +8 -8
- package/src/generators/application/schema.d.ts +5 -0
- package/src/generators/application/schema.json +7 -3
- package/src/generators/component/files/__fileName__.tsx__tmpl__ +39 -22
- package/src/generators/component/lib/normalize-options.js +4 -2
- package/src/generators/component/schema.d.ts +6 -4
- package/src/generators/component/schema.json +7 -7
- package/src/generators/component-cypress-spec/schema.json +1 -1
- package/src/generators/component-story/schema.json +1 -1
- package/src/generators/component-test/schema.json +1 -1
- package/src/generators/cypress-component-configuration/cypress-component-configuration.d.ts +2 -1
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js +18 -7
- package/src/generators/cypress-component-configuration/lib/add-files.js +1 -6
- package/src/generators/cypress-component-configuration/schema.d.ts +1 -0
- package/src/generators/federate-module/federate-module.js +2 -2
- package/src/generators/federate-module/schema.d.ts +1 -1
- package/src/generators/federate-module/schema.json +4 -3
- package/src/generators/hook/files/__fileName__.ts__tmpl__ +15 -15
- package/src/generators/hook/schema.d.ts +4 -4
- package/src/generators/hook/schema.json +5 -5
- package/src/generators/host/files/common/src/main.js__tmpl__ +10 -0
- package/src/generators/host/files/common/tsconfig.lint.json__tmpl__ +19 -0
- package/src/generators/host/files/common-ts/src/app/__fileName__.tsx__tmpl__ +41 -0
- package/src/generators/host/files/common-ts/src/main.ts__tmpl__ +10 -0
- package/src/generators/host/files/module-federation/module-federation.config.js__tmpl__ +17 -2
- package/src/generators/host/files/module-federation-ssr/module-federation.server.config.js__tmpl__ +5 -2
- package/src/generators/host/files/module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +5 -2
- package/src/generators/host/files/module-federation-ts/module-federation.config.ts__tmpl__ +17 -2
- package/src/generators/host/files/module-federation-ts/webpack.config.prod.ts__tmpl__ +2 -1
- package/src/generators/host/files/module-federation-ts/webpack.config.ts__tmpl__ +2 -2
- package/src/generators/host/host.js +15 -1
- package/src/generators/host/lib/add-module-federation-files.d.ts +2 -1
- package/src/generators/host/lib/add-module-federation-files.js +24 -11
- package/src/generators/host/lib/setup-ssr-for-host.js +1 -0
- package/src/generators/host/lib/update-module-federation-e2e-project.js +7 -5
- package/src/generators/host/schema.d.ts +5 -2
- package/src/generators/host/schema.json +16 -6
- package/src/generators/init/init.d.ts +1 -1
- package/src/generators/init/init.js +10 -49
- package/src/generators/init/schema.d.ts +1 -6
- package/src/generators/init/schema.json +5 -22
- package/src/generators/library/lib/add-linting.js +2 -2
- package/src/generators/library/lib/add-rollup-build-target.d.ts +2 -1
- package/src/generators/library/lib/add-rollup-build-target.js +16 -8
- package/src/generators/library/lib/install-common-dependencies.js +13 -5
- package/src/generators/library/lib/normalize-options.js +34 -5
- package/src/generators/library/lib/update-app-routes.js +1 -1
- package/src/generators/library/library.js +17 -6
- package/src/generators/library/schema.d.ts +1 -0
- package/src/generators/library/schema.json +3 -3
- package/src/generators/redux/schema.d.ts +1 -1
- package/src/generators/redux/schema.json +2 -2
- package/src/generators/remote/files/module-federation/module-federation.config.js__tmpl__ +4 -1
- package/src/generators/remote/files/module-federation-ssr/module-federation.server.config.js__tmpl__ +1 -1
- package/src/generators/remote/files/module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/module-federation-ssr-ts/tsconfig.lint.json__tmpl__ +19 -0
- package/src/generators/remote/files/module-federation-ts/module-federation.config.ts__tmpl__ +4 -1
- package/src/generators/remote/files/module-federation-ts/tsconfig.lint.json__tmpl__ +19 -0
- package/src/generators/remote/lib/add-remote-to-dynamic-host.d.ts +2 -0
- package/src/generators/remote/lib/add-remote-to-dynamic-host.js +11 -0
- package/src/generators/remote/lib/setup-ssr-for-remote.js +5 -1
- package/src/generators/remote/lib/setup-tspath-for-remote.js +2 -1
- package/src/generators/remote/lib/update-host-with-remote.js +10 -1
- package/src/generators/remote/remote.js +22 -2
- package/src/generators/remote/schema.d.ts +3 -2
- package/src/generators/remote/schema.json +17 -6
- package/src/generators/setup-ssr/schema.json +1 -1
- package/src/generators/setup-ssr/setup-ssr.js +23 -7
- package/src/generators/setup-tailwind/schema.json +1 -1
- package/src/generators/stories/schema.json +1 -1
- package/src/generators/stories/stories.js +17 -5
- package/src/generators/storybook-configuration/configuration.d.ts +2 -0
- package/src/generators/storybook-configuration/configuration.js +37 -15
- package/src/generators/storybook-configuration/schema.d.ts +2 -1
- package/src/generators/storybook-configuration/schema.json +7 -7
- package/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.d.ts +2 -0
- package/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.js +26 -0
- package/src/migrations/update-18-1-1/fix-target-defaults-inputs.d.ts +2 -0
- package/src/migrations/update-18-1-1/fix-target-defaults-inputs.js +53 -0
- package/src/module-federation/ast-utils.js +1 -1
- package/src/module-federation/utils.js +8 -1
- package/src/module-federation/with-module-federation-ssr.js +3 -0
- package/src/module-federation/with-module-federation.d.ts +3 -3
- package/src/module-federation/with-module-federation.js +14 -4
- package/src/rules/update-module-federation-project.d.ts +2 -0
- package/src/rules/update-module-federation-project.js +12 -3
- package/src/utils/add-mf-env-to-inputs.d.ts +2 -0
- package/src/utils/add-mf-env-to-inputs.js +27 -0
- package/src/utils/assertion.js +1 -0
- package/src/utils/ct-utils.d.ts +6 -1
- package/src/utils/ct-utils.js +39 -9
- package/src/utils/get-in-source-vitest-tests-template.js +1 -1
- package/src/utils/has-vite-plugin.d.ts +2 -0
- package/src/utils/has-vite-plugin.js +11 -0
- package/src/utils/has-webpack-plugin.d.ts +2 -0
- package/src/utils/has-webpack-plugin.js +11 -0
- package/src/utils/maybe-js.d.ts +3 -0
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
- package/typings/style.d.ts +1 -0
- package/src/generators/application/files/base-webpack/src/environments/environment.prod.ts__tmpl__ +0 -3
- package/src/generators/application/files/base-webpack/src/environments/environment.ts__tmpl__ +0 -6
- package/src/generators/host/files/module-federation/src/main.ts__tmpl__ +0 -1
- package/src/generators/host/files/module-federation-ts/src/main.ts__tmpl__ +0 -1
- package/src/generators/library/lib/maybe-js.d.ts +0 -2
- /package/src/generators/host/files/common/src/app/{__fileName__.tsx__tmpl__ → __fileName__.js__tmpl__} +0 -0
- /package/src/generators/remote/files/{module-federation/src/main.ts__tmpl__ → common/src/main.js__tmpl__} +0 -0
- /package/src/generators/remote/files/{module-federation/src/remote-entry.ts__tmpl__ → common/src/remote-entry.js__tmpl__} +0 -0
- /package/src/generators/remote/files/{module-federation-ts → common-ts}/src/main.ts__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation-ts → common-ts}/src/remote-entry.ts__tmpl__ +0 -0
- /package/src/{generators/library/lib → utils}/maybe-js.js +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<% if (classComponent) { %>
|
|
2
|
+
import { Component } from 'react';
|
|
3
|
+
<% } if (!minimal) { %>
|
|
4
|
+
import NxWelcome from "./nx-welcome";
|
|
5
|
+
<% } %>
|
|
6
|
+
|
|
7
|
+
<% if (classComponent) { %>
|
|
8
|
+
export class App extends Component {
|
|
9
|
+
render() {
|
|
10
|
+
<% } else { %>
|
|
11
|
+
export function App() {
|
|
12
|
+
<% } %>
|
|
13
|
+
return (
|
|
14
|
+
<div>
|
|
15
|
+
<% if (!minimal) { %>
|
|
16
|
+
<NxWelcome title="<%= projectName %>"/>
|
|
17
|
+
<% } else { %>
|
|
18
|
+
<h1>
|
|
19
|
+
<span> Hello there, </span>
|
|
20
|
+
Welcome <%= projectName %> 👋
|
|
21
|
+
</h1>
|
|
22
|
+
<% } %>
|
|
23
|
+
</div>);
|
|
24
|
+
<% if (classComponent) { %>
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
<% } else { %>
|
|
28
|
+
}
|
|
29
|
+
<% } %>
|
|
30
|
+
|
|
31
|
+
export default App;
|
|
32
|
+
|
|
33
|
+
<% if (inSourceTests === true) { %> <%- inSourceVitestTests %> <% } %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/* You can add global styles to this file, and also import other style files */
|
|
@@ -4,13 +4,20 @@ exports.addE2e = void 0;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const web_1 = require("@nx/web");
|
|
6
6
|
const versions_1 = require("../../../utils/versions");
|
|
7
|
+
const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
|
|
8
|
+
const has_vite_plugin_1 = require("../../../utils/has-vite-plugin");
|
|
7
9
|
async function addE2e(tree, options) {
|
|
8
10
|
switch (options.e2eTestRunner) {
|
|
9
11
|
case 'cypress': {
|
|
10
|
-
(0,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const hasNxBuildPlugin = (options.bundler === 'webpack' && (0, has_webpack_plugin_1.hasWebpackPlugin)(tree)) ||
|
|
13
|
+
(options.bundler === 'vite' && (0, has_vite_plugin_1.hasVitePlugin)(tree));
|
|
14
|
+
if (!hasNxBuildPlugin) {
|
|
15
|
+
await (0, web_1.webStaticServeGenerator)(tree, {
|
|
16
|
+
buildTarget: `${options.projectName}:build`,
|
|
17
|
+
targetName: 'serve-static',
|
|
18
|
+
spa: true,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
14
21
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
|
|
15
22
|
(0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
|
|
16
23
|
projectType: 'application',
|
|
@@ -27,9 +34,19 @@ async function addE2e(tree, options) {
|
|
|
27
34
|
// the name and root are already normalized, instruct the generator to use them as is
|
|
28
35
|
bundler: options.bundler === 'rspack' ? 'webpack' : options.bundler,
|
|
29
36
|
skipFormat: true,
|
|
30
|
-
devServerTarget: `${options.projectName}
|
|
37
|
+
devServerTarget: `${options.projectName}:${options.e2eWebServerTarget}`,
|
|
38
|
+
baseUrl: options.e2eWebServerAddress,
|
|
31
39
|
jsx: true,
|
|
32
40
|
rootProject: options.rootProject,
|
|
41
|
+
webServerCommands: hasNxBuildPlugin
|
|
42
|
+
? {
|
|
43
|
+
default: `nx run ${options.projectName}:${options.e2eWebServerTarget}`,
|
|
44
|
+
production: `nx run ${options.projectName}:preview`,
|
|
45
|
+
}
|
|
46
|
+
: undefined,
|
|
47
|
+
ciWebServerCommand: hasNxBuildPlugin
|
|
48
|
+
? `nx run ${options.projectName}:serve-static`
|
|
49
|
+
: undefined,
|
|
33
50
|
});
|
|
34
51
|
}
|
|
35
52
|
case 'playwright': {
|
|
@@ -49,9 +66,10 @@ async function addE2e(tree, options) {
|
|
|
49
66
|
js: false,
|
|
50
67
|
linter: options.linter,
|
|
51
68
|
setParserOptionsProject: options.setParserOptionsProject,
|
|
52
|
-
webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx
|
|
53
|
-
webServerAddress:
|
|
69
|
+
webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx ${options.e2eWebServerTarget} ${options.name}`,
|
|
70
|
+
webServerAddress: options.e2eWebServerAddress,
|
|
54
71
|
rootProject: options.rootProject,
|
|
72
|
+
addPlugin: options.addPlugin,
|
|
55
73
|
});
|
|
56
74
|
}
|
|
57
75
|
case 'none':
|
|
@@ -4,10 +4,10 @@ exports.addJest = void 0;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const versions_1 = require("../../../utils/versions");
|
|
6
6
|
async function addJest(host, options) {
|
|
7
|
-
|
|
8
|
-
if (options.unitTestRunner !== 'jest') {
|
|
7
|
+
if (options.unitTestRunner === 'none') {
|
|
9
8
|
return () => { };
|
|
10
9
|
}
|
|
10
|
+
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
|
|
11
11
|
return await configurationGenerator(host, {
|
|
12
12
|
...options,
|
|
13
13
|
project: options.projectName,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { NormalizedSchema } from '../schema';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
2
|
+
import { Tree } from '@nx/devkit';
|
|
3
|
+
export declare function addProject(host: Tree, options: NormalizedSchema): void;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.addProject = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
|
|
6
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
5
7
|
function addProject(host, options) {
|
|
6
8
|
const project = {
|
|
7
9
|
root: options.appProjectRoot,
|
|
@@ -11,22 +13,18 @@ function addProject(host, options) {
|
|
|
11
13
|
tags: options.parsedTags,
|
|
12
14
|
};
|
|
13
15
|
if (options.bundler === 'webpack') {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
if (!(0, has_webpack_plugin_1.hasWebpackPlugin)(host) || !options.addPlugin) {
|
|
17
|
+
project.targets = {
|
|
18
|
+
build: createBuildTarget(options),
|
|
19
|
+
serve: createServeTarget(options),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
18
22
|
}
|
|
19
23
|
(0, devkit_1.addProjectConfiguration)(host, options.projectName, {
|
|
20
24
|
...project,
|
|
21
25
|
});
|
|
22
26
|
}
|
|
23
27
|
exports.addProject = addProject;
|
|
24
|
-
function maybeJs(options, path) {
|
|
25
|
-
return options.js && (path.endsWith('.ts') || path.endsWith('.tsx'))
|
|
26
|
-
? path.replace(/\.tsx?$/, '.js')
|
|
27
|
-
: path;
|
|
28
|
-
}
|
|
29
|
-
exports.maybeJs = maybeJs;
|
|
30
28
|
function createBuildTarget(options) {
|
|
31
29
|
return {
|
|
32
30
|
executor: '@nx/webpack:webpack',
|
|
@@ -39,7 +37,7 @@ function createBuildTarget(options) {
|
|
|
39
37
|
: options.projectName),
|
|
40
38
|
index: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/index.html'),
|
|
41
39
|
baseHref: '/',
|
|
42
|
-
main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, maybeJs(options, `src/main.tsx`)),
|
|
40
|
+
main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/main.tsx`)),
|
|
43
41
|
tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
|
44
42
|
assets: [
|
|
45
43
|
(0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/favicon.ico'),
|
|
@@ -51,7 +49,6 @@ function createBuildTarget(options) {
|
|
|
51
49
|
(0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/styles.${options.style}`),
|
|
52
50
|
],
|
|
53
51
|
scripts: [],
|
|
54
|
-
isolatedConfig: true,
|
|
55
52
|
webpackConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'webpack.config.js'),
|
|
56
53
|
},
|
|
57
54
|
configurations: {
|
|
@@ -64,8 +61,8 @@ function createBuildTarget(options) {
|
|
|
64
61
|
production: {
|
|
65
62
|
fileReplacements: [
|
|
66
63
|
{
|
|
67
|
-
replace: (0, devkit_1.joinPathFragments)(options.appProjectRoot, maybeJs(options, `src/environments/environment.ts`)),
|
|
68
|
-
with: (0, devkit_1.joinPathFragments)(options.appProjectRoot, maybeJs(options, `src/environments/environment.prod.ts`)),
|
|
64
|
+
replace: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/environments/environment.ts`)),
|
|
65
|
+
with: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/environments/environment.prod.ts`)),
|
|
69
66
|
},
|
|
70
67
|
],
|
|
71
68
|
optimization: true,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addRouting = void 0;
|
|
4
|
-
const ast_utils_1 = require("../../../utils/ast-utils");
|
|
5
|
-
const versions_1 = require("../../../utils/versions");
|
|
6
4
|
const devkit_1 = require("@nx/devkit");
|
|
7
5
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
6
|
+
const ast_utils_1 = require("../../../utils/ast-utils");
|
|
7
|
+
const versions_1 = require("../../../utils/versions");
|
|
8
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
8
9
|
let tsModule;
|
|
9
10
|
function addRouting(host, options) {
|
|
10
11
|
if (!options.routing) {
|
|
@@ -13,7 +14,7 @@ function addRouting(host, options) {
|
|
|
13
14
|
if (!tsModule) {
|
|
14
15
|
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
15
16
|
}
|
|
16
|
-
const appPath = (0, devkit_1.joinPathFragments)(options.appProjectRoot, maybeJs(options, `src/app/${options.fileName}.tsx`));
|
|
17
|
+
const appPath = (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/app/${options.fileName}.tsx`));
|
|
17
18
|
const appFileContent = host.read(appPath, 'utf-8');
|
|
18
19
|
const appSource = tsModule.createSourceFile(appPath, appFileContent, tsModule.ScriptTarget.Latest, true);
|
|
19
20
|
const changes = (0, devkit_1.applyChangesToString)(appFileContent, (0, ast_utils_1.addInitialRoutes)(appPath, appSource));
|
|
@@ -24,8 +25,3 @@ function addRouting(host, options) {
|
|
|
24
25
|
return () => { };
|
|
25
26
|
}
|
|
26
27
|
exports.addRouting = addRouting;
|
|
27
|
-
function maybeJs(options, path) {
|
|
28
|
-
return options.js && (path.endsWith('.ts') || path.endsWith('.tsx'))
|
|
29
|
-
? path.replace(/\.tsx?$/, '.js')
|
|
30
|
-
: path;
|
|
31
|
-
}
|
|
@@ -6,6 +6,8 @@ const js_1 = require("@nx/js");
|
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const create_ts_config_1 = require("../../../utils/create-ts-config");
|
|
8
8
|
const get_in_source_vitest_tests_template_1 = require("../../../utils/get-in-source-vitest-tests-template");
|
|
9
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
10
|
+
const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
|
|
9
11
|
const get_app_tests_1 = require("./get-app-tests");
|
|
10
12
|
function createApplicationFiles(host, options) {
|
|
11
13
|
let styleSolutionSpecificAppFiles;
|
|
@@ -15,6 +17,9 @@ function createApplicationFiles(host, options) {
|
|
|
15
17
|
else if (options.style === 'styled-jsx') {
|
|
16
18
|
styleSolutionSpecificAppFiles = '../files/style-styled-jsx';
|
|
17
19
|
}
|
|
20
|
+
else if (options.style === 'tailwind') {
|
|
21
|
+
styleSolutionSpecificAppFiles = '../files/style-tailwind';
|
|
22
|
+
}
|
|
18
23
|
else if (options.style === 'none') {
|
|
19
24
|
styleSolutionSpecificAppFiles = '../files/style-none';
|
|
20
25
|
}
|
|
@@ -38,7 +43,12 @@ function createApplicationFiles(host, options) {
|
|
|
38
43
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-vite'), options.appProjectRoot, templateVariables);
|
|
39
44
|
}
|
|
40
45
|
else if (options.bundler === 'webpack') {
|
|
41
|
-
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-webpack'), options.appProjectRoot,
|
|
46
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-webpack'), options.appProjectRoot, {
|
|
47
|
+
...templateVariables,
|
|
48
|
+
webpackPluginOptions: (0, has_webpack_plugin_1.hasWebpackPlugin)(host)
|
|
49
|
+
? createNxWebpackPluginOptions(options)
|
|
50
|
+
: null,
|
|
51
|
+
});
|
|
42
52
|
if (options.compiler === 'babel') {
|
|
43
53
|
(0, devkit_1.writeJson)(host, `${options.appProjectRoot}/.babelrc`, {
|
|
44
54
|
presets: [
|
|
@@ -112,3 +122,22 @@ function createApplicationFiles(host, options) {
|
|
|
112
122
|
(0, create_ts_config_1.createTsConfig)(host, options.appProjectRoot, 'app', options, relativePathToRootTsConfig);
|
|
113
123
|
}
|
|
114
124
|
exports.createApplicationFiles = createApplicationFiles;
|
|
125
|
+
function createNxWebpackPluginOptions(options) {
|
|
126
|
+
return {
|
|
127
|
+
target: 'web',
|
|
128
|
+
compiler: options.compiler ?? 'babel',
|
|
129
|
+
outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot != '.'
|
|
130
|
+
? options.appProjectRoot
|
|
131
|
+
: options.projectName),
|
|
132
|
+
index: './src/index.html',
|
|
133
|
+
baseHref: '/',
|
|
134
|
+
main: (0, maybe_js_1.maybeJs)(options, `./src/main.tsx`),
|
|
135
|
+
tsConfig: './tsconfig.app.json',
|
|
136
|
+
assets: ['./src/favicon.ico', './src/assets'],
|
|
137
|
+
styles: options.styledModule || !options.hasStyles
|
|
138
|
+
? []
|
|
139
|
+
: [
|
|
140
|
+
`./src/styles.${options.style !== 'tailwind' ? options.style : 'css'}`,
|
|
141
|
+
],
|
|
142
|
+
};
|
|
143
|
+
}
|
|
@@ -4,7 +4,18 @@ exports.installCommonDependencies = void 0;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const versions_1 = require("../../../utils/versions");
|
|
6
6
|
function installCommonDependencies(host, options) {
|
|
7
|
-
|
|
7
|
+
if (options.skipPackageJson) {
|
|
8
|
+
return () => { };
|
|
9
|
+
}
|
|
10
|
+
const dependencies = {};
|
|
11
|
+
const devDependencies = {
|
|
12
|
+
'@types/node': versions_1.typesNodeVersion,
|
|
13
|
+
'@types/react': versions_1.typesReactVersion,
|
|
14
|
+
'@types/react-dom': versions_1.typesReactDomVersion,
|
|
15
|
+
};
|
|
16
|
+
if (options.bundler !== 'vite') {
|
|
17
|
+
dependencies['tslib'] = versions_1.tsLibVersion;
|
|
18
|
+
}
|
|
8
19
|
// Vite requires style preprocessors to be installed manually.
|
|
9
20
|
// `@nx/webpack` installs them automatically for now.
|
|
10
21
|
if (options.bundler === 'vite' || options.unitTestRunner === 'vitest') {
|
|
@@ -28,6 +39,9 @@ function installCommonDependencies(host, options) {
|
|
|
28
39
|
devDependencies['@babel/core'] = versions_1.babelCoreVersion;
|
|
29
40
|
}
|
|
30
41
|
}
|
|
42
|
+
if (options.unitTestRunner && options.unitTestRunner !== 'none') {
|
|
43
|
+
devDependencies['@testing-library/react'] = versions_1.testingLibraryReactVersion;
|
|
44
|
+
}
|
|
31
45
|
return (0, devkit_1.addDependenciesToPackageJson)(host, {}, devDependencies);
|
|
32
46
|
}
|
|
33
47
|
exports.installCommonDependencies = installCommonDependencies;
|
|
@@ -26,15 +26,46 @@ async function normalizeOptions(host, options, callingGenerator = '@nx/react:app
|
|
|
26
26
|
rootProject: options.rootProject,
|
|
27
27
|
callingGenerator,
|
|
28
28
|
});
|
|
29
|
+
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
30
|
+
const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
31
|
+
nxJson.useInferencePlugins !== false;
|
|
32
|
+
options.addPlugin ??= addPlugin;
|
|
29
33
|
options.rootProject = appProjectRoot === '.';
|
|
30
34
|
options.projectNameAndRootFormat = projectNameAndRootFormat;
|
|
35
|
+
let e2eWebServerTarget = 'serve';
|
|
36
|
+
if (options.addPlugin) {
|
|
37
|
+
if (nxJson.plugins) {
|
|
38
|
+
for (const plugin of nxJson.plugins) {
|
|
39
|
+
if (options.bundler === 'vite' &&
|
|
40
|
+
typeof plugin === 'object' &&
|
|
41
|
+
plugin.plugin === '@nx/vite/plugin' &&
|
|
42
|
+
plugin.options.serveTargetName) {
|
|
43
|
+
e2eWebServerTarget = plugin.options
|
|
44
|
+
.serveTargetName;
|
|
45
|
+
}
|
|
46
|
+
else if (options.bundler === 'webpack' &&
|
|
47
|
+
typeof plugin === 'object' &&
|
|
48
|
+
plugin.plugin === '@nx/webpack/plugin' &&
|
|
49
|
+
plugin.options.serveTargetName) {
|
|
50
|
+
e2eWebServerTarget = plugin.options
|
|
51
|
+
.serveTargetName;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
let e2ePort = options.devServerPort ?? 4200;
|
|
57
|
+
if (nxJson.targetDefaults?.[e2eWebServerTarget] &&
|
|
58
|
+
nxJson.targetDefaults?.[e2eWebServerTarget].options?.port) {
|
|
59
|
+
e2ePort = nxJson.targetDefaults?.[e2eWebServerTarget].options?.port;
|
|
60
|
+
}
|
|
31
61
|
const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
|
|
32
62
|
const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
|
|
63
|
+
const e2eWebServerAddress = `http://localhost:${e2ePort}`;
|
|
33
64
|
const parsedTags = options.tags
|
|
34
65
|
? options.tags.split(',').map((s) => s.trim())
|
|
35
66
|
: [];
|
|
36
67
|
const fileName = options.pascalCaseFiles ? 'App' : 'app';
|
|
37
|
-
const styledModule = /^(css|scss|less|none)$/.test(options.style)
|
|
68
|
+
const styledModule = /^(css|scss|less|tailwind|none)$/.test(options.style)
|
|
38
69
|
? null
|
|
39
70
|
: options.style;
|
|
40
71
|
(0, assertion_1.assertValidStyle)(options.style);
|
|
@@ -48,6 +79,9 @@ async function normalizeOptions(host, options, callingGenerator = '@nx/react:app
|
|
|
48
79
|
appProjectRoot,
|
|
49
80
|
e2eProjectName,
|
|
50
81
|
e2eProjectRoot,
|
|
82
|
+
e2eWebServerAddress,
|
|
83
|
+
e2eWebServerTarget,
|
|
84
|
+
e2ePort,
|
|
51
85
|
parsedTags,
|
|
52
86
|
fileName,
|
|
53
87
|
styledModule,
|
|
@@ -14,6 +14,7 @@ function setDefaults(host, options) {
|
|
|
14
14
|
nxJson.generators['@nx/react'] = nxJson.generators['@nx/react'] || {};
|
|
15
15
|
const prev = { ...nxJson.generators['@nx/react'] };
|
|
16
16
|
const appDefaults = {
|
|
17
|
+
babel: true,
|
|
17
18
|
style: options.style,
|
|
18
19
|
linter: options.linter,
|
|
19
20
|
bundler: options.bundler,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateSpecConfig = void 0;
|
|
4
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
4
5
|
const jest_utils_1 = require("../../../utils/jest-utils");
|
|
5
6
|
const devkit_1 = require("@nx/devkit");
|
|
6
7
|
function updateSpecConfig(host, options) {
|
|
@@ -8,21 +9,20 @@ function updateSpecConfig(host, options) {
|
|
|
8
9
|
return;
|
|
9
10
|
}
|
|
10
11
|
(0, devkit_1.updateJson)(host, `${options.appProjectRoot}/tsconfig.spec.json`, (json) => {
|
|
11
|
-
|
|
12
|
+
const compilerOptions = json.compilerOptions ?? {};
|
|
13
|
+
const types = compilerOptions.types ?? [];
|
|
12
14
|
if (options.style === 'styled-jsx') {
|
|
13
|
-
|
|
15
|
+
types.push('@nx/react/typings/styled-jsx.d.ts');
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
'@nx/react/typings/image.d.ts',
|
|
19
|
-
];
|
|
17
|
+
types.push('@nx/react/typings/cssmodule.d.ts', '@nx/react/typings/image.d.ts');
|
|
18
|
+
compilerOptions.types = types;
|
|
19
|
+
json.compilerOptions = compilerOptions;
|
|
20
20
|
return json;
|
|
21
21
|
});
|
|
22
22
|
if (options.unitTestRunner !== 'jest') {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
-
const configPath = `${options.appProjectRoot}/jest.config
|
|
25
|
+
const configPath = (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/jest.config.ts`);
|
|
26
26
|
const originalContent = host.read(configPath, 'utf-8');
|
|
27
27
|
const content = (0, jest_utils_1.updateJestConfigContent)(originalContent);
|
|
28
28
|
host.write(configPath, content);
|
|
@@ -28,6 +28,7 @@ export interface Schema {
|
|
|
28
28
|
rootProject?: boolean;
|
|
29
29
|
bundler?: 'webpack' | 'vite' | 'rspack';
|
|
30
30
|
minimal?: boolean;
|
|
31
|
+
addPlugin?: boolean;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
export interface NormalizedSchema<T extends Schema = Schema> extends T {
|
|
@@ -35,9 +36,13 @@ export interface NormalizedSchema<T extends Schema = Schema> extends T {
|
|
|
35
36
|
appProjectRoot: string;
|
|
36
37
|
e2eProjectName: string;
|
|
37
38
|
e2eProjectRoot: string;
|
|
39
|
+
e2eWebServerAddress: string;
|
|
40
|
+
e2eWebServerTarget: string;
|
|
41
|
+
e2ePort: number;
|
|
38
42
|
parsedTags: string[];
|
|
39
43
|
fileName: string;
|
|
40
44
|
styledModule: null | SupportedStyles;
|
|
41
45
|
hasStyles: boolean;
|
|
42
46
|
unitTestRunner: 'jest' | 'vitest' | 'none';
|
|
47
|
+
addPlugin?: boolean;
|
|
43
48
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
3
|
"cli": "nx",
|
|
4
4
|
"$id": "NxReactApp",
|
|
5
5
|
"title": "Create a React Application",
|
|
@@ -56,11 +56,15 @@
|
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
58
|
"value": "scss",
|
|
59
|
-
"label": "SASS(.scss) [
|
|
59
|
+
"label": "SASS(.scss) [ https://sass-lang.com ]"
|
|
60
60
|
},
|
|
61
61
|
{
|
|
62
62
|
"value": "less",
|
|
63
|
-
"label": "LESS [
|
|
63
|
+
"label": "LESS [ https://lesscss.org ]"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"value": "tailwind",
|
|
67
|
+
"label": "tailwind [ https://tailwindcss.com/ ]"
|
|
64
68
|
},
|
|
65
69
|
{
|
|
66
70
|
"value": "styled-components",
|
|
@@ -32,13 +32,30 @@ const Styled<%= className %> = styled.div`
|
|
|
32
32
|
color: pink;
|
|
33
33
|
`;
|
|
34
34
|
<% }%>
|
|
35
|
-
<% if
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
<% if(!isNextPage) { %>
|
|
36
|
+
<% if (classComponent) { %>
|
|
37
|
+
export class <%= className %> extends Component<<%= className %>Props> {
|
|
38
|
+
override render() {
|
|
39
|
+
return (
|
|
40
|
+
<<%= wrapper %><%- extras %>>
|
|
41
|
+
<%= styledModule === 'styled-jsx' ? `<style jsx>{\`div { color: pink; }\`}</style>` : `` %>
|
|
42
|
+
<p>Welcome to <%= className %>!</p>
|
|
43
|
+
<% if (routing) { %>
|
|
44
|
+
<ul>
|
|
45
|
+
<li><Link to="/"><%= name %> root</Link></li>
|
|
46
|
+
</ul>
|
|
47
|
+
<Route path="/" element={<div>This is the <%= name %> root route.</div>} />
|
|
48
|
+
<% } %>
|
|
49
|
+
</<%= wrapper %>>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
<% } else { %>
|
|
54
|
+
export function <%= className %>(props: <%= className %>Props) {
|
|
38
55
|
return (
|
|
39
56
|
<<%= wrapper %><%- extras %>>
|
|
40
|
-
|
|
41
|
-
<
|
|
57
|
+
<% if (styledModule === 'styled-jsx') { %><style jsx>{`div { color: pink; }`}</style><% } %>
|
|
58
|
+
<h1>Welcome to <%= className %>!</h1>
|
|
42
59
|
<% if (routing) { %>
|
|
43
60
|
<ul>
|
|
44
61
|
<li><Link to="/"><%= name %> root</Link></li>
|
|
@@ -48,24 +65,24 @@ export class <%= className %> extends Component<<%= className %>Props> {
|
|
|
48
65
|
</<%= wrapper %>>
|
|
49
66
|
);
|
|
50
67
|
}
|
|
51
|
-
}
|
|
68
|
+
<% } %>
|
|
69
|
+
|
|
70
|
+
export default <%= className %>;
|
|
52
71
|
<% } else { %>
|
|
53
|
-
export function <%= className %>(props: <%= className %>Props) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
72
|
+
export default function <%= className %>(props: <%= className %>Props) {
|
|
73
|
+
return (
|
|
74
|
+
<<%= wrapper %><%- extras %>>
|
|
75
|
+
<% if (styledModule === 'styled-jsx') { %><style jsx>{`div { color: pink; }`}</style><% } %>
|
|
76
|
+
<h1>Welcome to <%= className %>!</h1>
|
|
77
|
+
<% if (routing) { %>
|
|
78
|
+
<ul>
|
|
79
|
+
<li><Link to="/"><%= name %> root</Link></li>
|
|
80
|
+
</ul>
|
|
81
|
+
<Route path="/" element={<div>This is the <%= name %> root route.</div>} />
|
|
82
|
+
<% } %>
|
|
83
|
+
</<%= wrapper %>>
|
|
84
|
+
);
|
|
85
|
+
};
|
|
67
86
|
<% } %>
|
|
68
87
|
|
|
69
|
-
export default <%= className %>;
|
|
70
|
-
|
|
71
88
|
<% if (inSourceTests === true) { %> <%- inSourceVitestTests %> <% } %>
|
|
@@ -22,7 +22,7 @@ async function normalizeOptions(tree, options) {
|
|
|
22
22
|
});
|
|
23
23
|
const project = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
24
24
|
const { className } = (0, devkit_1.names)(name);
|
|
25
|
-
const { sourceRoot: projectSourceRoot, projectType } = project;
|
|
25
|
+
const { sourceRoot: projectSourceRoot, root: projectRoot, projectType, } = project;
|
|
26
26
|
const styledModule = /^(css|scss|less|none)$/.test(options.style)
|
|
27
27
|
? null
|
|
28
28
|
: options.style;
|
|
@@ -33,6 +33,8 @@ async function normalizeOptions(tree, options) {
|
|
|
33
33
|
options.routing = options.routing ?? false;
|
|
34
34
|
options.globalCss = options.globalCss ?? false;
|
|
35
35
|
options.inSourceTests = options.inSourceTests ?? false;
|
|
36
|
+
//TODO (nicholas): Remove when Next page generator is removed
|
|
37
|
+
options.isNextPage = options.isNextPage ?? false;
|
|
36
38
|
return {
|
|
37
39
|
...options,
|
|
38
40
|
projectName,
|
|
@@ -42,7 +44,7 @@ async function normalizeOptions(tree, options) {
|
|
|
42
44
|
className,
|
|
43
45
|
fileName,
|
|
44
46
|
filePath,
|
|
45
|
-
projectSourceRoot,
|
|
47
|
+
projectSourceRoot: projectSourceRoot ?? projectRoot,
|
|
46
48
|
};
|
|
47
49
|
}
|
|
48
50
|
exports.normalizeOptions = normalizeOptions;
|
|
@@ -3,7 +3,7 @@ import { SupportedStyles } from '../../../typings/style';
|
|
|
3
3
|
export interface Schema {
|
|
4
4
|
name: string;
|
|
5
5
|
/**
|
|
6
|
-
* @deprecated Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx
|
|
6
|
+
* @deprecated Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v19.
|
|
7
7
|
*/
|
|
8
8
|
project?: string;
|
|
9
9
|
style: SupportedStyles;
|
|
@@ -11,18 +11,18 @@ export interface Schema {
|
|
|
11
11
|
directory?: string;
|
|
12
12
|
export?: boolean;
|
|
13
13
|
/**
|
|
14
|
-
* @deprecated Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx
|
|
14
|
+
* @deprecated Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19.
|
|
15
15
|
*/
|
|
16
16
|
pascalCaseFiles?: boolean;
|
|
17
17
|
/**
|
|
18
|
-
* @deprecated Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx
|
|
18
|
+
* @deprecated Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19.
|
|
19
19
|
*/
|
|
20
20
|
pascalCaseDirectory?: boolean;
|
|
21
21
|
classComponent?: boolean;
|
|
22
22
|
routing?: boolean;
|
|
23
23
|
js?: boolean;
|
|
24
24
|
/**
|
|
25
|
-
* @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx
|
|
25
|
+
* @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
|
|
26
26
|
*/
|
|
27
27
|
flat?: boolean;
|
|
28
28
|
globalCss?: boolean;
|
|
@@ -33,6 +33,8 @@ export interface Schema {
|
|
|
33
33
|
// Used by other wrapping generators to preserve previous behavior
|
|
34
34
|
// e.g. @nx/next:component
|
|
35
35
|
derivedDirectory?: string;
|
|
36
|
+
// Used by Next.js to determine how React should generate the page
|
|
37
|
+
isNextPage?: boolean;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
export interface NormalizedSchema extends Schema {
|