@nx/react 17.0.3 → 17.0.5
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 +13 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +173 -58
- package/src/executors/module-federation-dev-server/schema.json +13 -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
|
@@ -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 {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
3
|
"cli": "nx",
|
|
4
4
|
"$id": "NxReactComponent",
|
|
5
5
|
"title": "Create a React Component",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"$default": {
|
|
14
14
|
"$source": "projectName"
|
|
15
15
|
},
|
|
16
|
-
"x-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
|
|
16
|
+
"x-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."
|
|
17
17
|
},
|
|
18
18
|
"name": {
|
|
19
19
|
"type": "string",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
42
|
"value": "scss",
|
|
43
|
-
"label": "SASS(.scss) [
|
|
43
|
+
"label": "SASS(.scss) [ https://sass-lang.com ]"
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
46
|
"value": "less",
|
|
47
|
-
"label": "LESS [
|
|
47
|
+
"label": "LESS [ https://lesscss.org ]"
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
50
|
"value": "styled-components",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"type": "boolean",
|
|
92
92
|
"description": "Create component at the source root rather than its own directory.",
|
|
93
93
|
"default": false,
|
|
94
|
-
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx
|
|
94
|
+
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19."
|
|
95
95
|
},
|
|
96
96
|
"export": {
|
|
97
97
|
"type": "boolean",
|
|
@@ -105,14 +105,14 @@
|
|
|
105
105
|
"description": "Use pascal case component file name (e.g. `App.tsx`).",
|
|
106
106
|
"alias": "P",
|
|
107
107
|
"default": false,
|
|
108
|
-
"x-deprecated": "Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx
|
|
108
|
+
"x-deprecated": "Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
|
|
109
109
|
},
|
|
110
110
|
"pascalCaseDirectory": {
|
|
111
111
|
"type": "boolean",
|
|
112
112
|
"description": "Use pascal case directory name (e.g. `App/App.tsx`).",
|
|
113
113
|
"alias": "R",
|
|
114
114
|
"default": false,
|
|
115
|
-
"x-deprecated": "Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx
|
|
115
|
+
"x-deprecated": "Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
|
|
116
116
|
},
|
|
117
117
|
"classComponent": {
|
|
118
118
|
"type": "boolean",
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
2
|
import { CypressComponentConfigurationSchema } from './schema.d';
|
|
3
|
+
export declare function cypressComponentConfigGenerator(tree: Tree, options: CypressComponentConfigurationSchema): Promise<import("@nx/devkit").GeneratorCallback>;
|
|
3
4
|
/**
|
|
4
5
|
* This is for using cypresses own Component testing, if you want to use test
|
|
5
6
|
* storybook components then use componentCypressGenerator instead.
|
|
6
7
|
*
|
|
7
8
|
*/
|
|
8
|
-
export declare function
|
|
9
|
+
export declare function cypressComponentConfigGeneratorInternal(tree: Tree, options: CypressComponentConfigurationSchema): Promise<import("@nx/devkit").GeneratorCallback>;
|
|
9
10
|
export default cypressComponentConfigGenerator;
|
|
@@ -1,26 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cypressComponentConfigGenerator = void 0;
|
|
3
|
+
exports.cypressComponentConfigGeneratorInternal = exports.cypressComponentConfigGenerator = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const versions_1 = require("../../utils/versions");
|
|
6
6
|
const add_files_1 = require("./lib/add-files");
|
|
7
7
|
const ct_utils_1 = require("../../utils/ct-utils");
|
|
8
|
+
function cypressComponentConfigGenerator(tree, options) {
|
|
9
|
+
return cypressComponentConfigGeneratorInternal(tree, {
|
|
10
|
+
addPlugin: false,
|
|
11
|
+
...options,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
exports.cypressComponentConfigGenerator = cypressComponentConfigGenerator;
|
|
8
15
|
/**
|
|
9
16
|
* This is for using cypresses own Component testing, if you want to use test
|
|
10
17
|
* storybook components then use componentCypressGenerator instead.
|
|
11
18
|
*
|
|
12
19
|
*/
|
|
13
|
-
async function
|
|
20
|
+
async function cypressComponentConfigGeneratorInternal(tree, options) {
|
|
14
21
|
const { componentConfigurationGenerator: baseCyCtConfig } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
|
|
22
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
23
|
+
const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
24
|
+
nxJson.useInferencePlugins !== false;
|
|
25
|
+
options.addPlugin ??= addPlugin;
|
|
15
26
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
16
27
|
const installTask = await baseCyCtConfig(tree, {
|
|
17
28
|
project: options.project,
|
|
18
29
|
skipFormat: true,
|
|
19
30
|
jsx: true,
|
|
31
|
+
addPlugin: options.addPlugin,
|
|
20
32
|
});
|
|
21
|
-
const found = await (0, ct_utils_1.
|
|
33
|
+
const found = await (0, ct_utils_1.configureCypressCT)(tree, {
|
|
22
34
|
project: options.project,
|
|
23
35
|
buildTarget: options.buildTarget,
|
|
36
|
+
bundler: options.bundler,
|
|
24
37
|
validExecutorNames: new Set([
|
|
25
38
|
'@nx/webpack:webpack',
|
|
26
39
|
'@nx/vite:build',
|
|
@@ -32,9 +45,7 @@ async function cypressComponentConfigGenerator(tree, options) {
|
|
|
32
45
|
if (!options.skipFormat) {
|
|
33
46
|
await (0, devkit_1.formatFiles)(tree);
|
|
34
47
|
}
|
|
35
|
-
return
|
|
36
|
-
installTask();
|
|
37
|
-
};
|
|
48
|
+
return installTask;
|
|
38
49
|
}
|
|
39
|
-
exports.
|
|
50
|
+
exports.cypressComponentConfigGeneratorInternal = cypressComponentConfigGeneratorInternal;
|
|
40
51
|
exports.default = cypressComponentConfigGenerator;
|
|
@@ -10,9 +10,7 @@ async function addFiles(tree, projectConfig, options, found) {
|
|
|
10
10
|
// when importing react
|
|
11
11
|
const { addMountDefinition, addDefaultCTConfig } = await Promise.resolve().then(() => require('@nx/cypress/src/utils/config'));
|
|
12
12
|
// Specifically undefined to allow Remix workaround of passing an empty string
|
|
13
|
-
const actualBundler =
|
|
14
|
-
? options.bundler
|
|
15
|
-
: await (0, ct_utils_1.getBundlerFromTarget)(found, tree);
|
|
13
|
+
const actualBundler = await (0, ct_utils_1.getActualBundler)(tree, options, found);
|
|
16
14
|
if (options.bundler && options.bundler !== actualBundler) {
|
|
17
15
|
devkit_1.logger.warn(`You have specified ${options.bundler} as the bundler but this project is configured to use ${actualBundler}.
|
|
18
16
|
This may cause errors. If you are seeing errors, try removing the --bundler option.`);
|
|
@@ -21,9 +19,6 @@ async function addFiles(tree, projectConfig, options, found) {
|
|
|
21
19
|
const commandFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'support', 'component.ts');
|
|
22
20
|
const updatedCommandFile = await addMountDefinition(tree.read(commandFile, 'utf-8'));
|
|
23
21
|
tree.write(commandFile, `import { mount } from 'cypress/react18';\n${updatedCommandFile}`);
|
|
24
|
-
const cyFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress.config.ts');
|
|
25
|
-
const updatedCyConfig = await addDefaultCTConfig(tree.read(cyFile, 'utf-8'), { bundler: bundlerToUse });
|
|
26
|
-
tree.write(cyFile, `import { nxComponentTestingPreset } from '@nx/react/plugins/component-testing';\n${updatedCyConfig}`);
|
|
27
22
|
if (options.bundler === 'webpack' ||
|
|
28
23
|
(!options.bundler && actualBundler === 'webpack')) {
|
|
29
24
|
(0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@nx/webpack': versions_1.nxVersion });
|
|
@@ -59,10 +59,10 @@ async function federateModuleGenerator(tree, schema) {
|
|
|
59
59
|
Now you can use the module from your host app like this:
|
|
60
60
|
|
|
61
61
|
Static import:
|
|
62
|
-
import { MyComponent } from '${schema.name}
|
|
62
|
+
import { MyComponent } from '${remoteName}/${schema.name}';
|
|
63
63
|
|
|
64
64
|
Dynamic import:
|
|
65
|
-
import('${schema.name}
|
|
65
|
+
import('${remoteName}/${schema.name}').then((m) => m.${schema.name});
|
|
66
66
|
`);
|
|
67
67
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
68
68
|
}
|
|
@@ -4,7 +4,7 @@ export interface Schema {
|
|
|
4
4
|
remote: string;
|
|
5
5
|
remoteDirectory?: string;
|
|
6
6
|
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
7
|
-
e2eTestRunner?: 'cypress' | 'none';
|
|
7
|
+
e2eTestRunner?: 'cypress' | 'playwright' | 'none';
|
|
8
8
|
host?: string;
|
|
9
9
|
linter?: Linter;
|
|
10
10
|
skipFormat?: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
3
|
"cli": "nx",
|
|
4
4
|
"$id": "NxReactFederateModule",
|
|
5
5
|
"title": "Federate Module",
|
|
@@ -68,8 +68,9 @@
|
|
|
68
68
|
},
|
|
69
69
|
"e2eTestRunner": {
|
|
70
70
|
"type": "string",
|
|
71
|
-
"enum": ["cypress", "none"],
|
|
72
|
-
"description": "Test runner to use for end to end (
|
|
71
|
+
"enum": ["cypress", "playwright", "none"],
|
|
72
|
+
"description": "Test runner to use for end to end (E2E) tests.",
|
|
73
|
+
"x-prompt": "Which E2E test runner would you like to use?",
|
|
73
74
|
"default": "cypress"
|
|
74
75
|
},
|
|
75
76
|
"host": {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { useState, useCallback } from 'react'
|
|
2
|
-
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
4
|
-
export interface <%= hookTypeName %> {
|
|
5
|
-
count: number;
|
|
6
|
-
increment: () => void;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function <%= hookName %>(): <%= hookTypeName %> {
|
|
10
|
-
const [count, setCount] = useState(0)
|
|
11
|
-
const increment = useCallback(() => setCount((x) => x + 1), [])
|
|
12
|
-
return { count, increment }
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default <%= hookName %>;
|
|
1
|
+
import { useState, useCallback } from 'react'
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
4
|
+
export interface <%= hookTypeName %> {
|
|
5
|
+
count: number;
|
|
6
|
+
increment: () => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function <%= hookName %>(): <%= hookTypeName %> {
|
|
10
|
+
const [count, setCount] = useState(0)
|
|
11
|
+
const increment = useCallback(() => setCount((x) => x + 1), [])
|
|
12
|
+
return { count, increment }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default <%= hookName %>;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
export interface Schema {
|
|
2
2
|
name: string;
|
|
3
3
|
/**
|
|
4
|
-
* @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
|
|
4
|
+
* @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.
|
|
5
5
|
*/
|
|
6
6
|
project: string;
|
|
7
7
|
skipTests?: boolean;
|
|
8
8
|
directory?: string;
|
|
9
9
|
export?: boolean;
|
|
10
10
|
/**
|
|
11
|
-
* @deprecated Provide the `name` option instead and use the `as-provided` format. This option will be removed in Nx
|
|
11
|
+
* @deprecated Provide the `name` option instead and use the `as-provided` format. This option will be removed in Nx v19.
|
|
12
12
|
*/
|
|
13
13
|
pascalCaseFiles?: boolean;
|
|
14
14
|
/**
|
|
15
|
-
* @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx
|
|
15
|
+
* @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
|
|
16
16
|
*/
|
|
17
17
|
pascalCaseDirectory?: boolean;
|
|
18
18
|
/**
|
|
19
|
-
* @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx
|
|
19
|
+
* @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
|
|
20
20
|
*/
|
|
21
21
|
flat?: boolean;
|
|
22
22
|
js?: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
3
|
"cli": "nx",
|
|
4
4
|
"$id": "NxReactHook",
|
|
5
5
|
"title": "Create a React Hook for Nx",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"$default": {
|
|
20
20
|
"$source": "projectName"
|
|
21
21
|
},
|
|
22
|
-
"x-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
|
|
22
|
+
"x-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."
|
|
23
23
|
},
|
|
24
24
|
"name": {
|
|
25
25
|
"type": "string",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"type": "boolean",
|
|
57
57
|
"description": "Create hook at the source root rather than its own directory.",
|
|
58
58
|
"default": false,
|
|
59
|
-
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx
|
|
59
|
+
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v19."
|
|
60
60
|
},
|
|
61
61
|
"export": {
|
|
62
62
|
"type": "boolean",
|
|
@@ -70,14 +70,14 @@
|
|
|
70
70
|
"description": "Use pascal case hook file name (e.g. `useHook.ts`).",
|
|
71
71
|
"alias": "P",
|
|
72
72
|
"default": false,
|
|
73
|
-
"x-deprecated": "Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx
|
|
73
|
+
"x-deprecated": "Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
|
|
74
74
|
},
|
|
75
75
|
"pascalCaseDirectory": {
|
|
76
76
|
"type": "boolean",
|
|
77
77
|
"description": "Use pascal case directory name (e.g. `useHook/useHook.ts`).",
|
|
78
78
|
"alias": "R",
|
|
79
79
|
"default": false,
|
|
80
|
-
"x-deprecated": "Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx
|
|
80
|
+
"x-deprecated": "Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
|
|
81
81
|
}
|
|
82
82
|
},
|
|
83
83
|
"required": ["name"]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<% if (dynamic) { %>
|
|
2
|
+
import { setRemoteDefinitions } from '@nx/react/mf';
|
|
3
|
+
|
|
4
|
+
fetch('/assets/module-federation.manifest.json')
|
|
5
|
+
.then((res) => res.json())
|
|
6
|
+
.then(definitions => setRemoteDefinitions(definitions))
|
|
7
|
+
.then(() => import('./bootstrap').catch(err => console.error(err)));
|
|
8
|
+
<% } else { %>
|
|
9
|
+
import('./bootstrap').catch(err => console.error(err));
|
|
10
|
+
<% } %>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc",
|
|
5
|
+
"types": [
|
|
6
|
+
"node",
|
|
7
|
+
"@nx/react/typings/cssmodule.d.ts",
|
|
8
|
+
"@nx/react/typings/image.d.ts"
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
"include": [
|
|
12
|
+
"src/**/*.js",
|
|
13
|
+
"src/**/*.jsx",
|
|
14
|
+
"src/**/*.ts",
|
|
15
|
+
"src/**/*.tsx",
|
|
16
|
+
"webpack.config.ts",
|
|
17
|
+
"webpack.prod.config.ts"
|
|
18
|
+
]
|
|
19
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
<% if (!minimal) { %>
|
|
3
|
+
import NxWelcome from "./nx-welcome";
|
|
4
|
+
<% } %>
|
|
5
|
+
import { Link, Route, Routes } from 'react-router-dom';
|
|
6
|
+
<% if (dynamic) { %>
|
|
7
|
+
import { loadRemoteModule } from '@nx/react/mf';
|
|
8
|
+
<% } %>
|
|
9
|
+
|
|
10
|
+
<% if (remotes.length > 0) { %>
|
|
11
|
+
<% remotes.forEach(function(r) { %>
|
|
12
|
+
<% if (dynamic) { %>
|
|
13
|
+
const <%= r.className %> = React.lazy(() => loadRemoteModule('<%= r.fileName %>', './Module'))
|
|
14
|
+
<% } else { %>
|
|
15
|
+
const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
|
|
16
|
+
<% } %>
|
|
17
|
+
<% }); %>
|
|
18
|
+
<% } %>
|
|
19
|
+
|
|
20
|
+
export function App() {
|
|
21
|
+
return (
|
|
22
|
+
<React.Suspense fallback={null}>
|
|
23
|
+
<ul>
|
|
24
|
+
<li><Link to="/">Home</Link></li>
|
|
25
|
+
<% remotes.forEach(function(r) { %>
|
|
26
|
+
<li><Link to="/<%=r.fileName%>"><%=r.className%></Link></li>
|
|
27
|
+
<% }); %>
|
|
28
|
+
</ul>
|
|
29
|
+
<Routes>
|
|
30
|
+
<% if (!minimal) { %>
|
|
31
|
+
<Route path="/" element={<NxWelcome title="<%= projectName %>"/>} />
|
|
32
|
+
<% } %>
|
|
33
|
+
<% remotes.forEach(function(r) { %>
|
|
34
|
+
<Route path="/<%=r.fileName%>" element={<<%= r.className %>/>} />
|
|
35
|
+
<% }); %>
|
|
36
|
+
</Routes>
|
|
37
|
+
</React.Suspense>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default App;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<% if (dynamic) { %>
|
|
2
|
+
import { setRemoteDefinitions } from '@nx/react/mf';
|
|
3
|
+
|
|
4
|
+
fetch('/assets/module-federation.manifest.json')
|
|
5
|
+
.then((res) => res.json())
|
|
6
|
+
.then(definitions => setRemoteDefinitions(definitions))
|
|
7
|
+
.then(() => import('./bootstrap').catch(err => console.error(err)));
|
|
8
|
+
<% } else { %>
|
|
9
|
+
import('./bootstrap').catch(err => console.error(err));
|
|
10
|
+
<% } %>
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
name: '<%= projectName %>',
|
|
3
|
+
/**
|
|
4
|
+
* To use a remote that does not exist in your current Nx Workspace
|
|
5
|
+
* You can use the tuple-syntax to define your remote
|
|
6
|
+
*
|
|
7
|
+
* remotes: [['my-external-remote', 'https://nx-angular-remote.netlify.app']]
|
|
8
|
+
*
|
|
9
|
+
* You _may_ need to add a `remotes.d.ts` file to your `src/` folder declaring the external remote for tsc, with the
|
|
10
|
+
* following content:
|
|
11
|
+
*
|
|
12
|
+
* declare module 'my-external-remote';
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
3
15
|
remotes: [
|
|
4
|
-
|
|
16
|
+
<% if (static) {
|
|
17
|
+
remotes.forEach(function(r) { %> "<%= r.fileName %>", <% });
|
|
18
|
+
}
|
|
19
|
+
%>
|
|
5
20
|
],
|
|
6
|
-
};
|
|
21
|
+
};
|
package/src/generators/host/files/module-federation-ssr/module-federation.server.config.js__tmpl__
CHANGED
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
const moduleFederationConfig = {
|
|
7
7
|
name: '<%= projectName %>',
|
|
8
8
|
remotes: [
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
<% if (static) {
|
|
10
|
+
remotes.forEach(function(r) { %> "<%= r.fileName %>", <% });
|
|
11
|
+
}
|
|
12
|
+
%>
|
|
13
|
+
],
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
module.exports = moduleFederationConfig;
|
|
@@ -3,8 +3,11 @@ import { ModuleFederationConfig } from '@nx/webpack';
|
|
|
3
3
|
const config: ModuleFederationConfig = {
|
|
4
4
|
name: '<%= projectName %>',
|
|
5
5
|
remotes: [
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
<% if (static) {
|
|
7
|
+
remotes.forEach(function(r) { %> "<%= r.fileName %>", <% });
|
|
8
|
+
}
|
|
9
|
+
%>
|
|
10
|
+
],
|
|
8
11
|
};
|
|
9
12
|
|
|
10
13
|
export default config;
|
|
@@ -2,9 +2,24 @@ import { ModuleFederationConfig } from '@nx/webpack';
|
|
|
2
2
|
|
|
3
3
|
const config: ModuleFederationConfig = {
|
|
4
4
|
name: '<%= projectName %>',
|
|
5
|
+
/**
|
|
6
|
+
* To use a remote that does not exist in your current Nx Workspace
|
|
7
|
+
* You can use the tuple-syntax to define your remote
|
|
8
|
+
*
|
|
9
|
+
* remotes: [['my-external-remote', 'https://nx-angular-remote.netlify.app']]
|
|
10
|
+
*
|
|
11
|
+
* You _may_ need to add a `remotes.d.ts` file to your `src/` folder declaring the external remote for tsc, with the
|
|
12
|
+
* following content:
|
|
13
|
+
*
|
|
14
|
+
* declare module 'my-external-remote';
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
5
17
|
remotes: [
|
|
6
|
-
|
|
7
|
-
|
|
18
|
+
<% if (static) {
|
|
19
|
+
remotes.forEach(function(r) { %> "<%= r.fileName %>", <% });
|
|
20
|
+
}
|
|
21
|
+
%>
|
|
22
|
+
],
|
|
8
23
|
};
|
|
9
24
|
|
|
10
25
|
export default config;
|