@nx/react 20.4.0-canary.20250122-3c98a1c → 20.4.0-canary.20250124-45847a6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -6
- package/src/generators/application/application.js +5 -5
- package/src/generators/application/lib/add-project.js +6 -8
- package/src/generators/application/lib/get-app-tests.js +1 -1
- package/src/generators/application/lib/normalize-options.js +7 -3
- package/src/generators/component/lib/normalize-options.js +3 -1
- package/src/generators/hook/hook.js +4 -2
- package/src/generators/host/host.js +1 -1
- package/src/generators/library/lib/normalize-options.js +1 -1
- package/src/generators/library/library.js +8 -9
- package/src/generators/redux/redux.js +3 -2
- package/src/generators/remote/remote.js +7 -7
- package/src/generators/stories/stories.js +2 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/react",
|
3
|
-
"version": "20.4.0-canary.
|
3
|
+
"version": "20.4.0-canary.20250124-45847a6",
|
4
4
|
"private": false,
|
5
5
|
"description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Vitest, Playwright, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
|
6
6
|
"repository": {
|
@@ -38,11 +38,11 @@
|
|
38
38
|
"minimatch": "9.0.3",
|
39
39
|
"picocolors": "^1.1.0",
|
40
40
|
"tslib": "^2.3.0",
|
41
|
-
"@nx/devkit": "20.4.0-canary.
|
42
|
-
"@nx/js": "20.4.0-canary.
|
43
|
-
"@nx/eslint": "20.4.0-canary.
|
44
|
-
"@nx/web": "20.4.0-canary.
|
45
|
-
"@nx/module-federation": "20.4.0-canary.
|
41
|
+
"@nx/devkit": "20.4.0-canary.20250124-45847a6",
|
42
|
+
"@nx/js": "20.4.0-canary.20250124-45847a6",
|
43
|
+
"@nx/eslint": "20.4.0-canary.20250124-45847a6",
|
44
|
+
"@nx/web": "20.4.0-canary.20250124-45847a6",
|
45
|
+
"@nx/module-federation": "20.4.0-canary.20250124-45847a6",
|
46
46
|
"express": "^4.19.2",
|
47
47
|
"http-proxy-middleware": "^3.0.3",
|
48
48
|
"semver": "^7.6.3"
|
@@ -44,6 +44,11 @@ async function applicationGeneratorInternal(tree, schema) {
|
|
44
44
|
});
|
45
45
|
tasks.push(jsInitTask);
|
46
46
|
const options = await (0, normalize_options_1.normalizeOptions)(tree, schema);
|
47
|
+
// If we are using the new TS solution
|
48
|
+
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
49
|
+
if (options.isUsingTsSolutionConfig) {
|
50
|
+
(0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.appProjectRoot);
|
51
|
+
}
|
47
52
|
(0, show_possible_warnings_1.showPossibleWarnings)(tree, options);
|
48
53
|
const initTask = await (0, init_1.default)(tree, {
|
49
54
|
...options,
|
@@ -127,11 +132,6 @@ async function applicationGeneratorInternal(tree, schema) {
|
|
127
132
|
}, options.linter === 'eslint'
|
128
133
|
? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
|
129
134
|
: undefined);
|
130
|
-
// If we are using the new TS solution
|
131
|
-
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
132
|
-
if (options.isUsingTsSolutionConfig) {
|
133
|
-
(0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.appProjectRoot);
|
134
|
-
}
|
135
135
|
(0, sort_fields_1.sortPackageJsonFields)(tree, options.appProjectRoot);
|
136
136
|
if (!options.skipFormat) {
|
137
137
|
await (0, devkit_1.formatFiles)(tree);
|
@@ -5,7 +5,6 @@ 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
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");
|
9
8
|
function addProject(host, options) {
|
10
9
|
const project = {
|
11
10
|
root: options.appProjectRoot,
|
@@ -31,15 +30,14 @@ function addProject(host, options) {
|
|
31
30
|
}
|
32
31
|
if (options.isUsingTsSolutionConfig) {
|
33
32
|
(0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), {
|
34
|
-
name:
|
33
|
+
name: options.projectName,
|
35
34
|
version: '0.0.1',
|
36
35
|
private: true,
|
37
|
-
nx:
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
},
|
36
|
+
nx: options.parsedTags?.length
|
37
|
+
? {
|
38
|
+
tags: options.parsedTags,
|
39
|
+
}
|
40
|
+
: undefined,
|
43
41
|
});
|
44
42
|
}
|
45
43
|
if (!options.isUsingTsSolutionConfig || options.alwaysGenerateProjectJson) {
|
@@ -13,7 +13,7 @@ function getAppTests(options) {
|
|
13
13
|
${options.routing
|
14
14
|
? 'const { getByText } = render(<BrowserRouter><App /></BrowserRouter>);'
|
15
15
|
: 'const { getByText } = render(<App />);'}
|
16
|
-
expect(getByText(
|
16
|
+
expect(getByText(new RegExp('Welcome ${options.projectName}', 'gi'))).toBeTruthy();
|
17
17
|
});
|
18
18
|
`;
|
19
19
|
}
|
@@ -8,6 +8,7 @@ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project
|
|
8
8
|
const assertion_1 = require("../../../utils/assertion");
|
9
9
|
const find_free_port_1 = require("./find-free-port");
|
10
10
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
11
|
+
const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
|
11
12
|
function normalizeDirectory(options) {
|
12
13
|
options.directory = options.directory?.replace(/\\{1,2}/g, '/');
|
13
14
|
const { projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
|
@@ -41,10 +42,13 @@ async function normalizeOptions(host, options) {
|
|
41
42
|
? null
|
42
43
|
: options.style;
|
43
44
|
(0, assertion_1.assertValidStyle)(options.style);
|
45
|
+
const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
|
44
46
|
const normalized = {
|
45
47
|
...options,
|
46
|
-
name:
|
47
|
-
projectName:
|
48
|
+
name: appProjectName,
|
49
|
+
projectName: isUsingTsSolutionConfig
|
50
|
+
? (0, get_import_path_1.getImportPath)(host, appProjectName)
|
51
|
+
: appProjectName,
|
48
52
|
appProjectRoot,
|
49
53
|
e2eProjectName,
|
50
54
|
e2eProjectRoot,
|
@@ -52,7 +56,7 @@ async function normalizeOptions(host, options) {
|
|
52
56
|
fileName,
|
53
57
|
styledModule,
|
54
58
|
hasStyles: options.style !== 'none',
|
55
|
-
isUsingTsSolutionConfig
|
59
|
+
isUsingTsSolutionConfig,
|
56
60
|
};
|
57
61
|
normalized.routing = normalized.routing ?? false;
|
58
62
|
normalized.strict = normalized.strict ?? true;
|
@@ -4,6 +4,7 @@ exports.normalizeOptions = normalizeOptions;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
5
|
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
6
6
|
const assertion_1 = require("../../../utils/assertion");
|
7
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
7
8
|
async function normalizeOptions(tree, options) {
|
8
9
|
(0, assertion_1.assertValidStyle)(options.style);
|
9
10
|
const { artifactName: name, directory, fileName, filePath, fileExtension, fileExtensionType, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
|
@@ -19,7 +20,8 @@ async function normalizeOptions(tree, options) {
|
|
19
20
|
const styledModule = /^(css|scss|less|none)$/.test(options.style)
|
20
21
|
? null
|
21
22
|
: options.style;
|
22
|
-
if (options.export &&
|
23
|
+
if (options.export &&
|
24
|
+
(0, ts_solution_setup_1.getProjectType)(tree, projectRoot, projectType) === 'application') {
|
23
25
|
devkit_1.logger.warn(`The "--export" option should not be used with applications and will do nothing.`);
|
24
26
|
}
|
25
27
|
options.classComponent = options.classComponent ?? false;
|
@@ -7,6 +7,7 @@ const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/a
|
|
7
7
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
8
8
|
const path_1 = require("path");
|
9
9
|
const ast_utils_1 = require("../../utils/ast-utils");
|
10
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
10
11
|
async function hookGenerator(host, schema) {
|
11
12
|
const options = await normalizeOptions(host, schema);
|
12
13
|
createFiles(host, options);
|
@@ -61,8 +62,9 @@ async function normalizeOptions(host, options) {
|
|
61
62
|
: `use${className}`;
|
62
63
|
const hookTypeName = (0, devkit_1.names)(hookName).className;
|
63
64
|
const project = (0, devkit_1.getProjects)(host).get(projectName);
|
64
|
-
const { sourceRoot: projectSourceRoot, projectType } = project;
|
65
|
-
if (options.export &&
|
65
|
+
const { root, sourceRoot: projectSourceRoot, projectType } = project;
|
66
|
+
if (options.export &&
|
67
|
+
(0, ts_solution_setup_1.getProjectType)(host, root, projectType) === 'application') {
|
66
68
|
devkit_1.logger.warn(`The "--export" option should not be used with applications and will do nothing.`);
|
67
69
|
}
|
68
70
|
return {
|
@@ -43,7 +43,7 @@ async function hostGenerator(host, schema) {
|
|
43
43
|
const initTask = await (0, application_1.default)(host, {
|
44
44
|
...options,
|
45
45
|
directory: options.appProjectRoot,
|
46
|
-
name: options.
|
46
|
+
name: options.name,
|
47
47
|
// The target use-case is loading remotes as child routes, thus always enable routing.
|
48
48
|
routing: true,
|
49
49
|
skipFormat: true,
|
@@ -37,6 +37,9 @@ async function libraryGeneratorInternal(host, schema) {
|
|
37
37
|
});
|
38
38
|
tasks.push(jsInitTask);
|
39
39
|
const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
|
40
|
+
if (options.isUsingTsSolutionConfig) {
|
41
|
+
(0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
|
42
|
+
}
|
40
43
|
if (options.publishable === true && !schema.importPath) {
|
41
44
|
throw new Error(`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`);
|
42
45
|
}
|
@@ -53,12 +56,11 @@ async function libraryGeneratorInternal(host, schema) {
|
|
53
56
|
name: options.importPath,
|
54
57
|
version: '0.0.1',
|
55
58
|
...(0, determine_entry_fields_1.determineEntryFields)(options),
|
56
|
-
nx:
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
},
|
59
|
+
nx: options.parsedTags?.length
|
60
|
+
? {
|
61
|
+
tags: options.parsedTags,
|
62
|
+
}
|
63
|
+
: undefined,
|
62
64
|
files: options.publishable ? ['dist', '!**/*.tsbuildinfo'] : undefined,
|
63
65
|
});
|
64
66
|
}
|
@@ -207,9 +209,6 @@ async function libraryGeneratorInternal(host, schema) {
|
|
207
209
|
}, options.linter === 'eslint'
|
208
210
|
? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
|
209
211
|
: undefined);
|
210
|
-
if (options.isUsingTsSolutionConfig) {
|
211
|
-
(0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
|
212
|
-
}
|
213
212
|
(0, sort_fields_1.sortPackageJsonFields)(host, options.projectRoot);
|
214
213
|
if (!options.skipFormat) {
|
215
214
|
await (0, devkit_1.formatFiles)(host);
|
@@ -8,6 +8,7 @@ const devkit_1 = require("@nx/devkit");
|
|
8
8
|
const js_1 = require("@nx/js");
|
9
9
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
10
10
|
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
11
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
11
12
|
let tsModule;
|
12
13
|
async function reduxGenerator(host, schema) {
|
13
14
|
const options = await normalizeOptions(host, schema);
|
@@ -88,12 +89,12 @@ async function normalizeOptions(host, options) {
|
|
88
89
|
const extraNames = (0, devkit_1.names)(name);
|
89
90
|
const projects = (0, devkit_1.getProjects)(host);
|
90
91
|
const project = projects.get(projectName);
|
91
|
-
const { sourceRoot, projectType } = project;
|
92
|
+
const { root, sourceRoot, projectType } = project;
|
92
93
|
const tsConfigJson = (0, devkit_1.readJson)(host, (0, js_1.getRootTsConfigPathInTree)(host));
|
93
94
|
const tsPaths = tsConfigJson.compilerOptions
|
94
95
|
? tsConfigJson.compilerOptions.paths || {}
|
95
96
|
: {};
|
96
|
-
const modulePath = projectType === 'application'
|
97
|
+
const modulePath = (0, ts_solution_setup_1.getProjectType)(host, root, projectType) === 'application'
|
97
98
|
? options.path
|
98
99
|
? `./app/${options.path}/${extraNames.fileName}.slice`
|
99
100
|
: `./app/${extraNames.fileName}.slice`
|
@@ -62,29 +62,29 @@ async function remoteGenerator(host, schema) {
|
|
62
62
|
if (options.dynamic) {
|
63
63
|
// Dynamic remotes generate with library { type: 'var' } by default.
|
64
64
|
// We need to ensure that the remote name is a valid variable name.
|
65
|
-
const isValidRemote = (0, js_1.isValidVariable)(options.
|
65
|
+
const isValidRemote = (0, js_1.isValidVariable)(options.name);
|
66
66
|
if (!isValidRemote.isValid) {
|
67
|
-
throw new Error(`Invalid remote name provided: ${options.
|
67
|
+
throw new Error(`Invalid remote name provided: ${options.name}. ${isValidRemote.message}`);
|
68
68
|
}
|
69
69
|
}
|
70
70
|
await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'application');
|
71
71
|
const REMOTE_NAME_REGEX = '^[a-zA-Z_$][a-zA-Z_$0-9]*$';
|
72
72
|
const remoteNameRegex = new RegExp(REMOTE_NAME_REGEX);
|
73
|
-
if (!remoteNameRegex.test(options.
|
74
|
-
throw new Error((0, devkit_1.stripIndents) `Invalid remote name: ${options.
|
73
|
+
if (!remoteNameRegex.test(options.name)) {
|
74
|
+
throw new Error((0, devkit_1.stripIndents) `Invalid remote name: ${options.name}. Remote project names must:
|
75
75
|
- Start with a letter, dollar sign ($) or underscore (_)
|
76
76
|
- Followed by any valid character (letters, digits, underscores, or dollar signs)
|
77
77
|
The regular expression used is ${REMOTE_NAME_REGEX}.`);
|
78
78
|
}
|
79
79
|
const initAppTask = await (0, application_1.default)(host, {
|
80
80
|
...options,
|
81
|
-
name: options.
|
81
|
+
name: options.name,
|
82
82
|
skipFormat: true,
|
83
83
|
alwaysGenerateProjectJson: true,
|
84
84
|
});
|
85
85
|
tasks.push(initAppTask);
|
86
|
-
if (
|
87
|
-
(0, update_host_with_remote_1.updateHostWithRemote)(host,
|
86
|
+
if (options.host) {
|
87
|
+
(0, update_host_with_remote_1.updateHostWithRemote)(host, options.host, options.name);
|
88
88
|
}
|
89
89
|
// Module federation requires bootstrap code to be dynamically imported.
|
90
90
|
// Renaming original entry file so we can use `import(./bootstrap)` in
|
@@ -11,10 +11,11 @@ const path_1 = require("path");
|
|
11
11
|
const minimatch_1 = require("minimatch");
|
12
12
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
13
13
|
const versions_1 = require("../../utils/versions");
|
14
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
14
15
|
let tsModule;
|
15
16
|
async function projectRootPath(tree, config) {
|
16
17
|
let projectDir;
|
17
|
-
if (config.projectType === 'application') {
|
18
|
+
if ((0, ts_solution_setup_1.getProjectType)(tree, config.root, config.projectType) === 'application') {
|
18
19
|
const isNextJs = await isNextJsProject(tree, config);
|
19
20
|
if (isNextJs) {
|
20
21
|
// Next.js apps
|