@nx/react 20.2.0-beta.2 → 20.2.0-beta.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/migrations.json +33 -0
- package/module-federation.d.ts +6 -4
- package/module-federation.js +16 -7
- package/package.json +6 -6
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +5 -7
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +5 -7
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +1 -1
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +4 -5
- package/src/generators/application/application.js +20 -6
- package/src/generators/application/files/base-rspack/rspack.config.js__tmpl__ +53 -0
- package/src/generators/application/files/base-rspack/tsconfig.app.json__tmpl__ +21 -4
- package/src/generators/application/files/base-vite/tsconfig.app.json__tmpl__ +19 -2
- package/src/generators/application/files/base-webpack/tsconfig.app.json__tmpl__ +20 -3
- package/src/generators/application/files/style-css-module/src/app/__fileName__.tsx__tmpl__ +2 -2
- package/src/generators/application/lib/add-e2e.d.ts +1 -1
- package/src/generators/application/lib/add-e2e.js +45 -15
- package/src/generators/application/lib/add-jest.js +1 -0
- package/src/generators/application/lib/add-project.js +85 -3
- package/src/generators/application/lib/create-application-files.js +30 -1
- package/src/generators/application/lib/normalize-options.js +2 -0
- package/src/generators/application/lib/update-jest-config.js +5 -0
- package/src/generators/application/schema.d.ts +5 -0
- package/src/generators/application/schema.json +19 -15
- package/src/generators/component/component.js +3 -1
- package/src/generators/component/lib/normalize-options.js +2 -1
- package/src/generators/component/schema.d.ts +1 -1
- package/src/generators/component/schema.json +3 -5
- package/src/generators/hook/hook.js +10 -25
- package/src/generators/hook/schema.d.ts +0 -2
- package/src/generators/hook/schema.json +10 -18
- package/src/generators/host/files/rspack-module-federation/rspack.config.js__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation/rspack.config.prod.js__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ts/rspack.config.prod.ts__tmpl__ +2 -1
- package/src/generators/host/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +2 -1
- package/src/generators/host/files/webpack-module-federation/webpack.config.js__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation/webpack.config.prod.js__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation-ssr/module-federation.server.config.js__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation-ts/webpack.config.prod.ts__tmpl__ +2 -2
- package/src/generators/host/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +3 -2
- package/src/generators/host/host.js +3 -2
- package/src/generators/host/lib/update-module-federation-tsconfig.d.ts +3 -0
- package/src/generators/host/lib/update-module-federation-tsconfig.js +39 -0
- package/src/generators/init/init.js +0 -2
- package/src/generators/library/lib/create-files.d.ts +1 -1
- package/src/generators/library/lib/create-files.js +22 -2
- package/src/generators/library/lib/normalize-options.js +3 -0
- package/src/generators/library/library.js +46 -16
- package/src/generators/library/schema.d.ts +1 -0
- package/src/generators/library/schema.json +14 -11
- package/src/generators/redux/schema.json +13 -4
- package/src/generators/remote/files/rspack-module-federation/rspack.config.js__tmpl__ +1 -1
- package/src/generators/remote/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +1 -1
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation/webpack.config.js__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +1 -1
- package/src/generators/remote/remote.js +1 -2
- package/src/migrations/update-20-2-0/migrate-mf-imports-to-new-package.d.ts +2 -0
- package/src/migrations/update-20-2-0/migrate-mf-imports-to-new-package.js +66 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts +2 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +35 -0
- package/src/rules/update-module-federation-project.js +12 -4
- package/src/utils/build-static.remotes.d.ts +1 -1
- package/src/utils/create-ts-config.js +57 -7
- package/src/utils/has-rspack-plugin.d.ts +2 -0
- package/src/utils/has-rspack-plugin.js +10 -0
- package/src/utils/versions.d.ts +2 -3
- package/src/utils/versions.js +3 -5
- package/src/generators/application/lib/add-project-root-to-rspack-plugin-excludes.d.ts +0 -2
- package/src/generators/application/lib/add-project-root-to-rspack-plugin-excludes.js +0 -31
- package/src/generators/library/files/common/package.json__tmpl__ +0 -4
- package/src/generators/library/files/vite/package.json__tmpl__ +0 -12
- package/src/module-federation/load-config.d.ts +0 -3
- package/src/module-federation/load-config.js +0 -15
- package/src/module-federation/models.d.ts +0 -24
- package/src/module-federation/models.js +0 -2
- package/src/module-federation/package-json.d.ts +0 -8
- package/src/module-federation/package-json.js +0 -12
- package/src/module-federation/utils.d.ts +0 -12
- package/src/module-federation/utils.js +0 -75
- package/src/module-federation/with-module-federation-ssr.d.ts +0 -2
- package/src/module-federation/with-module-federation-ssr.js +0 -50
- package/src/module-federation/with-module-federation.d.ts +0 -7
- package/src/module-federation/with-module-federation.js +0 -63
@@ -4,6 +4,8 @@ exports.addProject = addProject;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
5
|
const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
|
6
6
|
const maybe_js_1 = require("../../../utils/maybe-js");
|
7
|
+
const has_rspack_plugin_1 = require("../../../utils/has-rspack-plugin");
|
8
|
+
const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
|
7
9
|
function addProject(host, options) {
|
8
10
|
const project = {
|
9
11
|
root: options.appProjectRoot,
|
@@ -20,9 +22,89 @@ function addProject(host, options) {
|
|
20
22
|
};
|
21
23
|
}
|
22
24
|
}
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
else if (options.bundler === 'rspack' &&
|
26
|
+
(!(0, has_rspack_plugin_1.hasRspackPlugin)(host) || !options.addPlugin)) {
|
27
|
+
project.targets = {
|
28
|
+
build: createRspackBuildTarget(options),
|
29
|
+
serve: createRspackServeTarget(options),
|
30
|
+
};
|
31
|
+
}
|
32
|
+
if (options.isUsingTsSolutionConfig) {
|
33
|
+
(0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), {
|
34
|
+
name: (0, get_import_path_1.getImportPath)(host, options.name),
|
35
|
+
version: '0.0.1',
|
36
|
+
private: true,
|
37
|
+
nx: {
|
38
|
+
name: options.name,
|
39
|
+
projectType: 'application',
|
40
|
+
sourceRoot: `${options.appProjectRoot}/src`,
|
41
|
+
tags: options.parsedTags?.length ? options.parsedTags : undefined,
|
42
|
+
},
|
43
|
+
});
|
44
|
+
}
|
45
|
+
if (!options.isUsingTsSolutionConfig || options.alwaysGenerateProjectJson) {
|
46
|
+
(0, devkit_1.addProjectConfiguration)(host, options.projectName, {
|
47
|
+
...project,
|
48
|
+
});
|
49
|
+
}
|
50
|
+
}
|
51
|
+
function createRspackBuildTarget(options) {
|
52
|
+
return {
|
53
|
+
executor: '@nx/rspack:rspack',
|
54
|
+
outputs: ['{options.outputPath}'],
|
55
|
+
defaultConfiguration: 'production',
|
56
|
+
options: {
|
57
|
+
outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot),
|
58
|
+
index: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/index.html'),
|
59
|
+
baseHref: '/',
|
60
|
+
main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/main.tsx`)),
|
61
|
+
tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
62
|
+
assets: [
|
63
|
+
(0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/favicon.ico'),
|
64
|
+
(0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/assets'),
|
65
|
+
],
|
66
|
+
rspackConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'rspack.config.js'),
|
67
|
+
styles: options.styledModule || !options.hasStyles
|
68
|
+
? []
|
69
|
+
: [
|
70
|
+
(0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/styles.${options.style}`),
|
71
|
+
],
|
72
|
+
scripts: [],
|
73
|
+
configurations: {
|
74
|
+
development: {
|
75
|
+
mode: 'development',
|
76
|
+
},
|
77
|
+
production: {
|
78
|
+
mode: 'production',
|
79
|
+
optimization: true,
|
80
|
+
sourceMap: false,
|
81
|
+
outputHashing: 'all',
|
82
|
+
namedChunks: false,
|
83
|
+
extractLicenses: true,
|
84
|
+
vendorChunk: false,
|
85
|
+
},
|
86
|
+
},
|
87
|
+
},
|
88
|
+
};
|
89
|
+
}
|
90
|
+
function createRspackServeTarget(options) {
|
91
|
+
return {
|
92
|
+
executor: '@nx/rspack:dev-server',
|
93
|
+
defaultConfiguration: 'development',
|
94
|
+
options: {
|
95
|
+
buildTarget: `${options.projectName}:build`,
|
96
|
+
hmr: true,
|
97
|
+
},
|
98
|
+
configurations: {
|
99
|
+
development: {
|
100
|
+
buildTarget: `${options.projectName}:build:development`,
|
101
|
+
},
|
102
|
+
production: {
|
103
|
+
buildTarget: `${options.projectName}:build:production`,
|
104
|
+
hmr: false,
|
105
|
+
},
|
106
|
+
},
|
107
|
+
};
|
26
108
|
}
|
27
109
|
function createBuildTarget(options) {
|
28
110
|
return {
|
@@ -10,6 +10,8 @@ const maybe_js_1 = require("../../../utils/maybe-js");
|
|
10
10
|
const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
|
11
11
|
const get_app_tests_1 = require("./get-app-tests");
|
12
12
|
const onboarding_1 = require("nx/src/nx-cloud/utilities/onboarding");
|
13
|
+
const has_rspack_plugin_1 = require("../../../utils/has-rspack-plugin");
|
14
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
13
15
|
async function createApplicationFiles(host, options) {
|
14
16
|
let styleSolutionSpecificAppFiles;
|
15
17
|
if (options.styledModule && options.style !== 'styled-jsx') {
|
@@ -46,6 +48,7 @@ async function createApplicationFiles(host, options) {
|
|
46
48
|
inSourceVitestTests: (0, get_in_source_vitest_tests_template_1.getInSourceVitestTestsTemplate)(appTests),
|
47
49
|
style: options.style === 'tailwind' ? 'css' : options.style,
|
48
50
|
hasStyleFile,
|
51
|
+
isUsingTsSolutionSetup: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host),
|
49
52
|
};
|
50
53
|
if (options.bundler === 'vite') {
|
51
54
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-vite'), options.appProjectRoot, templateVariables);
|
@@ -114,7 +117,12 @@ async function createApplicationFiles(host, options) {
|
|
114
117
|
}
|
115
118
|
}
|
116
119
|
else if (options.bundler === 'rspack') {
|
117
|
-
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-rspack'), options.appProjectRoot,
|
120
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-rspack'), options.appProjectRoot, {
|
121
|
+
...templateVariables,
|
122
|
+
rspackPluginOptions: (0, has_rspack_plugin_1.hasRspackPlugin)(host)
|
123
|
+
? createNxRspackPluginOptions(options)
|
124
|
+
: null,
|
125
|
+
});
|
118
126
|
}
|
119
127
|
if (options.unitTestRunner === 'none' ||
|
120
128
|
(options.unitTestRunner === 'vitest' && options.inSourceTests == true)) {
|
@@ -156,3 +164,24 @@ function createNxWebpackPluginOptions(options) {
|
|
156
164
|
],
|
157
165
|
};
|
158
166
|
}
|
167
|
+
function createNxRspackPluginOptions(options) {
|
168
|
+
return {
|
169
|
+
target: 'web',
|
170
|
+
outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot != '.'
|
171
|
+
? options.appProjectRoot
|
172
|
+
: options.projectName),
|
173
|
+
index: './src/index.html',
|
174
|
+
baseHref: '/',
|
175
|
+
main: (0, maybe_js_1.maybeJs)({
|
176
|
+
js: options.js,
|
177
|
+
useJsx: true,
|
178
|
+
}, `./src/main.tsx`),
|
179
|
+
tsConfig: './tsconfig.app.json',
|
180
|
+
assets: ['./src/favicon.ico', './src/assets'],
|
181
|
+
styles: options.styledModule || !options.hasStyles
|
182
|
+
? []
|
183
|
+
: [
|
184
|
+
`./src/styles.${options.style !== 'tailwind' ? options.style : 'css'}`,
|
185
|
+
],
|
186
|
+
};
|
187
|
+
}
|
@@ -7,6 +7,7 @@ const devkit_1 = require("@nx/devkit");
|
|
7
7
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
8
8
|
const assertion_1 = require("../../../utils/assertion");
|
9
9
|
const find_free_port_1 = require("./find-free-port");
|
10
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
10
11
|
function normalizeDirectory(options) {
|
11
12
|
options.directory = options.directory?.replace(/\\{1,2}/g, '/');
|
12
13
|
const { projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
|
@@ -51,6 +52,7 @@ async function normalizeOptions(host, options) {
|
|
51
52
|
fileName,
|
52
53
|
styledModule,
|
53
54
|
hasStyles: options.style !== 'none',
|
55
|
+
isUsingTsSolutionConfig: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host),
|
54
56
|
};
|
55
57
|
normalized.routing = normalized.routing ?? false;
|
56
58
|
normalized.strict = normalized.strict ?? true;
|
@@ -17,6 +17,11 @@ function updateSpecConfig(host, options) {
|
|
17
17
|
types.push('@nx/react/typings/cssmodule.d.ts', '@nx/react/typings/image.d.ts');
|
18
18
|
compilerOptions.types = types;
|
19
19
|
json.compilerOptions = compilerOptions;
|
20
|
+
if (options.isUsingTsSolutionConfig) {
|
21
|
+
// add project reference to the runtime tsconfig.app.json file
|
22
|
+
json.references ??= [];
|
23
|
+
json.references.push({ path: './tsconfig.app.json' });
|
24
|
+
}
|
20
25
|
return json;
|
21
26
|
});
|
22
27
|
if (options.unitTestRunner !== 'jest') {
|
@@ -25,8 +25,12 @@ export interface Schema {
|
|
25
25
|
rootProject?: boolean;
|
26
26
|
bundler?: 'webpack' | 'vite' | 'rspack';
|
27
27
|
minimal?: boolean;
|
28
|
+
// Internal options
|
28
29
|
addPlugin?: boolean;
|
29
30
|
nxCloudToken?: string;
|
31
|
+
useTsSolution?: boolean;
|
32
|
+
formatter?: 'prettier' | 'none';
|
33
|
+
alwaysGenerateProjectJson?: boolean; // this is needed for MF currently
|
30
34
|
}
|
31
35
|
|
32
36
|
export interface NormalizedSchema<T extends Schema = Schema> extends T {
|
@@ -40,4 +44,5 @@ export interface NormalizedSchema<T extends Schema = Schema> extends T {
|
|
40
44
|
hasStyles: boolean;
|
41
45
|
unitTestRunner: 'jest' | 'vitest' | 'none';
|
42
46
|
addPlugin?: boolean;
|
47
|
+
isUsingTsSolutionConfig?: boolean;
|
43
48
|
}
|
@@ -80,12 +80,6 @@
|
|
80
80
|
]
|
81
81
|
}
|
82
82
|
},
|
83
|
-
"linter": {
|
84
|
-
"description": "The tool to use for running lint checks.",
|
85
|
-
"type": "string",
|
86
|
-
"enum": ["eslint", "none"],
|
87
|
-
"default": "eslint"
|
88
|
-
},
|
89
83
|
"routing": {
|
90
84
|
"type": "boolean",
|
91
85
|
"description": "Generate application with routes.",
|
@@ -104,11 +98,29 @@
|
|
104
98
|
"default": false,
|
105
99
|
"x-priority": "internal"
|
106
100
|
},
|
101
|
+
"bundler": {
|
102
|
+
"description": "The bundler to use.",
|
103
|
+
"type": "string",
|
104
|
+
"enum": ["vite", "webpack", "rspack"],
|
105
|
+
"x-prompt": "Which bundler do you want to use to build the application?",
|
106
|
+
"default": "vite",
|
107
|
+
"x-priority": "important"
|
108
|
+
},
|
109
|
+
"linter": {
|
110
|
+
"description": "The tool to use for running lint checks.",
|
111
|
+
"type": "string",
|
112
|
+
"enum": ["eslint", "none"],
|
113
|
+
"default": "none",
|
114
|
+
"x-prompt": "Which linter would you like to use?",
|
115
|
+
"x-priority": "important"
|
116
|
+
},
|
107
117
|
"unitTestRunner": {
|
108
118
|
"type": "string",
|
109
119
|
"enum": ["vitest", "jest", "none"],
|
110
120
|
"description": "Test runner to use for unit tests.",
|
111
|
-
"default": "
|
121
|
+
"default": "none",
|
122
|
+
"x-prompt": "What unit test runner should be used?",
|
123
|
+
"x-priority": "important"
|
112
124
|
},
|
113
125
|
"inSourceTests": {
|
114
126
|
"type": "boolean",
|
@@ -171,14 +183,6 @@
|
|
171
183
|
"default": false,
|
172
184
|
"hidden": true
|
173
185
|
},
|
174
|
-
"bundler": {
|
175
|
-
"description": "The bundler to use.",
|
176
|
-
"type": "string",
|
177
|
-
"enum": ["vite", "webpack", "rspack"],
|
178
|
-
"x-prompt": "Which bundler do you want to use to build the application?",
|
179
|
-
"default": "vite",
|
180
|
-
"x-priority": "important"
|
181
|
-
},
|
182
186
|
"minimal": {
|
183
187
|
"description": "Generate a React app with a minimal setup, no separate test files.",
|
184
188
|
"type": "boolean",
|
@@ -67,7 +67,9 @@ function addExportsToBarrel(host, options) {
|
|
67
67
|
const workspace = (0, devkit_1.getProjects)(host);
|
68
68
|
const isApp = workspace.get(options.projectName).projectType === 'application';
|
69
69
|
if (options.export && !isApp) {
|
70
|
-
const indexFilePath =
|
70
|
+
const indexFilePath = options.projectSourceRoot
|
71
|
+
? (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.js ? 'index.js' : 'index.ts')
|
72
|
+
: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src', options.js ? 'index.js' : 'index.ts');
|
71
73
|
const indexSource = host.read(indexFilePath, 'utf-8');
|
72
74
|
if (indexSource !== null) {
|
73
75
|
const indexSourceFile = tsModule.createSourceFile(indexFilePath, indexSource, tsModule.ScriptTarget.Latest, true);
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import type { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
2
1
|
import { SupportedStyles } from '../../../typings/style';
|
3
2
|
|
4
3
|
export interface Schema {
|
@@ -20,6 +19,7 @@ export interface Schema {
|
|
20
19
|
|
21
20
|
export interface NormalizedSchema extends Schema {
|
22
21
|
directory: string;
|
22
|
+
projectRoot: string;
|
23
23
|
projectSourceRoot: string;
|
24
24
|
projectName: string;
|
25
25
|
fileName: string;
|
@@ -8,19 +8,17 @@
|
|
8
8
|
"properties": {
|
9
9
|
"path": {
|
10
10
|
"type": "string",
|
11
|
-
"description": "
|
11
|
+
"description": "The file path to the component without the file extension. Relative to the current working directory.",
|
12
12
|
"$default": {
|
13
13
|
"$source": "argv",
|
14
14
|
"index": 0
|
15
15
|
},
|
16
|
-
"x-prompt": "
|
16
|
+
"x-prompt": "What is the component file path?",
|
17
17
|
"x-priority": "important"
|
18
18
|
},
|
19
19
|
"name": {
|
20
20
|
"type": "string",
|
21
|
-
"description": "The name of the
|
22
|
-
"x-prompt": "What name would you like to use for the component?",
|
23
|
-
"x-priority": "important"
|
21
|
+
"description": "The component symbol name. Defaults to the last segment of the file path."
|
24
22
|
},
|
25
23
|
"style": {
|
26
24
|
"description": "The file extension to be used for style files.",
|
@@ -49,22 +49,20 @@ function addExportsToBarrel(host, options) {
|
|
49
49
|
}
|
50
50
|
}
|
51
51
|
async function normalizeOptions(host, options) {
|
52
|
-
|
53
|
-
const { directory, fileName: _fileName, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
|
52
|
+
const { artifactName, directory, fileName: hookFilename, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
|
54
53
|
path: options.path,
|
55
54
|
name: options.name,
|
56
55
|
fileExtension: 'tsx',
|
57
56
|
});
|
58
|
-
const { className
|
59
|
-
//
|
60
|
-
//
|
61
|
-
const
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
: 'Use'.concat(className);
|
57
|
+
const { className } = (0, devkit_1.names)(hookFilename);
|
58
|
+
// if name is provided, use it as is for the hook name, otherwise prepend
|
59
|
+
// `use` to the pascal-cased file name if it doesn't already start with `use`
|
60
|
+
const hookName = options.name
|
61
|
+
? artifactName
|
62
|
+
: className.toLocaleLowerCase().startsWith('use')
|
63
|
+
? className
|
64
|
+
: `use${className}`;
|
65
|
+
const hookTypeName = (0, devkit_1.names)(hookName).className;
|
68
66
|
const project = (0, devkit_1.getProjects)(host).get(projectName);
|
69
67
|
const { sourceRoot: projectSourceRoot, projectType } = project;
|
70
68
|
if (options.export && projectType === 'application') {
|
@@ -80,17 +78,4 @@ async function normalizeOptions(host, options) {
|
|
80
78
|
projectName,
|
81
79
|
};
|
82
80
|
}
|
83
|
-
function assertValidOptions(options) {
|
84
|
-
const slashes = ['/', '\\'];
|
85
|
-
slashes.forEach((s) => {
|
86
|
-
if (options.name.indexOf(s) !== -1) {
|
87
|
-
const [name, ...rest] = options.name.split(s).reverse();
|
88
|
-
let suggestion = rest.map((x) => x.toLowerCase()).join(s);
|
89
|
-
if (options.directory) {
|
90
|
-
suggestion = `${options.directory}${s}${suggestion}`;
|
91
|
-
}
|
92
|
-
throw new Error(`Found "${s}" in the hook name. Did you mean to use the --directory option (e.g. \`nx g c ${name} --directory ${suggestion}\`)?`);
|
93
|
-
}
|
94
|
-
});
|
95
|
-
}
|
96
81
|
exports.default = hookGenerator;
|
@@ -7,26 +7,28 @@
|
|
7
7
|
"type": "object",
|
8
8
|
"examples": [
|
9
9
|
{
|
10
|
-
"
|
11
|
-
"
|
10
|
+
"description": "Generate a hook with the exported symbol matching the file name. It results in the hook `useFoo` at `mylib/src/lib/foo.ts`",
|
11
|
+
"command": "nx g @nx/react:hook mylib/src/lib/foo"
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"description": "Generate a hook with the exported symbol different from the file name. It results in the hook `useCustom` at `mylib/src/lib/foo.ts`",
|
15
|
+
"command": "nx g @nx/react:hook mylib/src/lib/foo --name=useCustom"
|
12
16
|
}
|
13
17
|
],
|
14
18
|
"properties": {
|
15
19
|
"path": {
|
16
20
|
"type": "string",
|
17
|
-
"description": "
|
21
|
+
"description": "The file path to the hook without the file extension. Relative to the current working directory.",
|
18
22
|
"$default": {
|
19
23
|
"$source": "argv",
|
20
24
|
"index": 0
|
21
25
|
},
|
22
|
-
"x-prompt": "
|
26
|
+
"x-prompt": "What is the hook file path?",
|
23
27
|
"x-priority": "important"
|
24
28
|
},
|
25
29
|
"name": {
|
26
30
|
"type": "string",
|
27
|
-
"description": "The name of the
|
28
|
-
"x-prompt": "What name would you like to use for the hook?",
|
29
|
-
"x-priority": "important"
|
31
|
+
"description": "The hook symbol name. Defaults to the last segment of the file path."
|
30
32
|
},
|
31
33
|
"js": {
|
32
34
|
"type": "boolean",
|
@@ -39,16 +41,6 @@
|
|
39
41
|
"default": false,
|
40
42
|
"x-priority": "internal"
|
41
43
|
},
|
42
|
-
"directory": {
|
43
|
-
"type": "string",
|
44
|
-
"description": "The directory at which to create the hook file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the project root.",
|
45
|
-
"x-priority": "important"
|
46
|
-
},
|
47
|
-
"nameAndDirectoryFormat": {
|
48
|
-
"description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
|
49
|
-
"type": "string",
|
50
|
-
"enum": ["as-provided", "derived"]
|
51
|
-
},
|
52
44
|
"export": {
|
53
45
|
"type": "boolean",
|
54
46
|
"description": "When true, the hook is exported from the project `index.ts` (if it exists).",
|
@@ -57,5 +49,5 @@
|
|
57
49
|
"x-prompt": "Should this hook be exported in the project?"
|
58
50
|
}
|
59
51
|
},
|
60
|
-
"required": ["
|
52
|
+
"required": ["path"]
|
61
53
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
const { composePlugins, withNx, withReact } = require('@nx/rspack');
|
2
|
-
const { withModuleFederation } = require('@nx/
|
2
|
+
const { withModuleFederation } = require('@nx/module-federation/rspack');
|
3
3
|
|
4
4
|
const baseConfig = require('./module-federation.config');
|
5
5
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
const { composePlugins, withNx, withReact } = require('@nx/rspack');
|
2
|
-
const { withModuleFederation } = require('@nx/
|
2
|
+
const { withModuleFederation } = require('@nx/module-federation/rspack');
|
3
3
|
|
4
4
|
const baseConfig = require('./module-federation.config');
|
5
5
|
|
package/src/generators/host/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
const {composePlugins, withNx, withReact} = require('@nx/rspack');
|
2
|
-
const {withModuleFederationForSSR} = require('@nx/
|
2
|
+
const {withModuleFederationForSSR} = require('@nx/module-federation/rspack');
|
3
3
|
|
4
4
|
const baseConfig = require('./module-federation.config');
|
5
5
|
|
package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import {composePlugins, withNx, withReact} from '@nx/rspack';
|
2
|
-
import {withModuleFederationForSSR} from '@nx/
|
2
|
+
import {withModuleFederationForSSR} from '@nx/module-federation/rspack';
|
3
3
|
|
4
4
|
import baseConfig from './module-federation.config';
|
5
5
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { composePlugins, withNx, withReact } from '@nx/rspack';
|
2
|
-
import { withModuleFederation
|
2
|
+
import { withModuleFederation } from '@nx/module-federation/rspack';
|
3
|
+
import { ModuleFederationConfig } from '@nx/module-federation';
|
3
4
|
|
4
5
|
import baseConfig from './module-federation.config';
|
5
6
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import {composePlugins, withNx, withReact} from '@nx/rspack';
|
2
|
-
import {withModuleFederation
|
2
|
+
import { withModuleFederation } from '@nx/module-federation/rspack';
|
3
|
+
import { ModuleFederationConfig } from '@nx/module-federation';
|
3
4
|
|
4
5
|
import baseConfig from './module-federation.config';
|
5
6
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
const { composePlugins, withNx } = require('@nx/webpack');
|
2
2
|
const { withReact } = require('@nx/react');
|
3
|
-
const { withModuleFederation } = require('@nx/
|
3
|
+
const { withModuleFederation } = require('@nx/module-federation/webpack');
|
4
4
|
|
5
5
|
const baseConfig = require('./module-federation.config');
|
6
6
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
const { composePlugins, withNx } = require('@nx/webpack');
|
2
2
|
const { withReact } = require('@nx/react');
|
3
|
-
const { withModuleFederation } = require('@nx/
|
3
|
+
const { withModuleFederation } = require('@nx/module-federation/webpack');
|
4
4
|
|
5
5
|
const baseConfig = require('./module-federation.config');
|
6
6
|
|
package/src/generators/host/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
const {composePlugins, withNx} = require('@nx/webpack');
|
2
2
|
const {withReact} = require('@nx/react');
|
3
|
-
const {withModuleFederationForSSR} = require('@nx/
|
3
|
+
const {withModuleFederationForSSR} = require('@nx/module-federation/webpack');
|
4
4
|
|
5
5
|
const baseConfig = require('./module-federation.config');
|
6
6
|
|
package/src/generators/host/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import {composePlugins, withNx} from '@nx/webpack';
|
2
2
|
import {withReact} from '@nx/react';
|
3
|
-
import {withModuleFederationForSSR} from '@nx/
|
3
|
+
import {withModuleFederationForSSR} from '@nx/module-federation/webpack';
|
4
4
|
|
5
5
|
import baseConfig from './module-federation.config';
|
6
6
|
|
package/src/generators/host/files/webpack-module-federation-ts/webpack.config.prod.ts__tmpl__
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { composePlugins, withNx } from '@nx/webpack';
|
2
2
|
import { withReact } from '@nx/react';
|
3
|
-
import { withModuleFederation } from '@nx/
|
4
|
-
import { ModuleFederationConfig } from '@nx/
|
3
|
+
import { withModuleFederation } from '@nx/module-federation/webpack';
|
4
|
+
import { ModuleFederationConfig } from '@nx/module-federation';
|
5
5
|
|
6
6
|
import baseConfig from './module-federation.config';
|
7
7
|
|
@@ -1,6 +1,7 @@
|
|
1
|
-
import {composePlugins, withNx
|
1
|
+
import {composePlugins, withNx} from '@nx/webpack';
|
2
2
|
import {withReact} from '@nx/react';
|
3
|
-
import {withModuleFederation} from '@nx/
|
3
|
+
import {withModuleFederation} from '@nx/module-federation/webpack';
|
4
|
+
import { ModuleFederationConfig } from '@nx/module-federation';
|
4
5
|
|
5
6
|
import baseConfig from './module-federation.config';
|
6
7
|
|
@@ -15,9 +15,8 @@ const add_mf_env_to_inputs_1 = require("../../utils/add-mf-env-to-inputs");
|
|
15
15
|
const js_1 = require("@nx/js");
|
16
16
|
const versions_1 = require("../../utils/versions");
|
17
17
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
18
|
-
const
|
18
|
+
const update_module_federation_tsconfig_1 = require("./lib/update-module-federation-tsconfig");
|
19
19
|
async function hostGenerator(host, schema) {
|
20
|
-
(0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(host, 'react', 'host');
|
21
20
|
const tasks = [];
|
22
21
|
const options = {
|
23
22
|
...(await (0, normalize_options_1.normalizeOptions)(host, schema)),
|
@@ -48,6 +47,7 @@ async function hostGenerator(host, schema) {
|
|
48
47
|
// The target use-case is loading remotes as child routes, thus always enable routing.
|
49
48
|
routing: true,
|
50
49
|
skipFormat: true,
|
50
|
+
alwaysGenerateProjectJson: true,
|
51
51
|
});
|
52
52
|
tasks.push(initTask);
|
53
53
|
const remotesWithPorts = [];
|
@@ -80,6 +80,7 @@ async function hostGenerator(host, schema) {
|
|
80
80
|
(0, add_module_federation_files_1.addModuleFederationFiles)(host, options, remotesWithPorts);
|
81
81
|
(0, update_module_federation_project_1.updateModuleFederationProject)(host, options);
|
82
82
|
(0, update_module_federation_e2e_project_1.updateModuleFederationE2eProject)(host, options);
|
83
|
+
(0, update_module_federation_tsconfig_1.updateModuleFederationTsconfig)(host, options);
|
83
84
|
if (options.ssr) {
|
84
85
|
const setupSsrTask = await (0, setup_ssr_1.default)(host, {
|
85
86
|
project: options.projectName,
|