@nx/react 20.5.0-canary.20250304-8e6c007 → 20.5.0-canary.20250306-ada8be4
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/lib/add-e2e.js +0 -4
- package/src/generators/application/lib/add-project.js +15 -3
- package/src/generators/application/lib/create-application-files.js +1 -1
- package/src/generators/application/lib/normalize-options.d.ts +0 -2
- package/src/generators/application/lib/normalize-options.js +7 -20
- package/src/generators/application/schema.d.ts +3 -0
- package/src/generators/host/host.js +5 -2
- package/src/generators/library/lib/normalize-options.js +7 -5
- package/src/generators/library/library.js +11 -8
- package/src/generators/library/schema.d.ts +1 -0
- package/src/generators/remote/remote.js +11 -8
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/react",
|
3
|
-
"version": "20.5.0-canary.
|
3
|
+
"version": "20.5.0-canary.20250306-ada8be4",
|
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.5.0-canary.
|
42
|
-
"@nx/js": "20.5.0-canary.
|
43
|
-
"@nx/eslint": "20.5.0-canary.
|
44
|
-
"@nx/web": "20.5.0-canary.
|
45
|
-
"@nx/module-federation": "20.5.0-canary.
|
41
|
+
"@nx/devkit": "20.5.0-canary.20250306-ada8be4",
|
42
|
+
"@nx/js": "20.5.0-canary.20250306-ada8be4",
|
43
|
+
"@nx/eslint": "20.5.0-canary.20250306-ada8be4",
|
44
|
+
"@nx/web": "20.5.0-canary.20250306-ada8be4",
|
45
|
+
"@nx/module-federation": "20.5.0-canary.20250306-ada8be4",
|
46
46
|
"express": "^4.21.2",
|
47
47
|
"http-proxy-middleware": "^3.0.3",
|
48
48
|
"semver": "^7.6.3"
|
@@ -52,8 +52,6 @@ async function addE2e(tree, options) {
|
|
52
52
|
version: '0.0.1',
|
53
53
|
private: true,
|
54
54
|
nx: {
|
55
|
-
projectType: 'application',
|
56
|
-
sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
|
57
55
|
implicitDependencies: [options.projectName],
|
58
56
|
},
|
59
57
|
});
|
@@ -122,8 +120,6 @@ async function addE2e(tree, options) {
|
|
122
120
|
version: '0.0.1',
|
123
121
|
private: true,
|
124
122
|
nx: {
|
125
|
-
projectType: 'application',
|
126
|
-
sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
|
127
123
|
implicitDependencies: [options.projectName],
|
128
124
|
},
|
129
125
|
});
|
@@ -29,11 +29,23 @@ function addProject(host, options) {
|
|
29
29
|
};
|
30
30
|
}
|
31
31
|
if (options.isUsingTsSolutionConfig) {
|
32
|
-
|
33
|
-
name: options.
|
32
|
+
const packageJson = {
|
33
|
+
name: options.importPath,
|
34
34
|
version: '0.0.1',
|
35
35
|
private: true,
|
36
|
-
}
|
36
|
+
};
|
37
|
+
if (options.projectName !== options.importPath) {
|
38
|
+
packageJson.nx = { name: options.projectName };
|
39
|
+
}
|
40
|
+
if (Object.keys(project.targets).length) {
|
41
|
+
packageJson.nx ??= {};
|
42
|
+
packageJson.nx.targets = project.targets;
|
43
|
+
}
|
44
|
+
if (options.parsedTags?.length) {
|
45
|
+
packageJson.nx ??= {};
|
46
|
+
packageJson.nx.tags = options.parsedTags;
|
47
|
+
}
|
48
|
+
(0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), packageJson);
|
37
49
|
}
|
38
50
|
if (!options.isUsingTsSolutionConfig || options.alwaysGenerateProjectJson) {
|
39
51
|
(0, devkit_1.addProjectConfiguration)(host, options.projectName, {
|
@@ -39,7 +39,7 @@ async function createApplicationFiles(host, options) {
|
|
39
39
|
const relativePathToRootTsConfig = (0, js_1.getRelativePathToRootTsConfig)(host, options.appProjectRoot);
|
40
40
|
const appTests = (0, get_app_tests_1.getAppTests)(options);
|
41
41
|
const templateVariables = {
|
42
|
-
...
|
42
|
+
...options.names,
|
43
43
|
...options,
|
44
44
|
js: !!options.js, // Ensure this is defined in template
|
45
45
|
tmpl: '',
|
@@ -1,5 +1,3 @@
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
2
2
|
import { NormalizedSchema, Schema } from '../schema';
|
3
|
-
export declare function normalizeDirectory(options: Schema): string;
|
4
|
-
export declare function normalizeProjectName(options: Schema): string;
|
5
3
|
export declare function normalizeOptions<T extends Schema = Schema>(host: Tree, options: Schema): Promise<NormalizedSchema<T>>;
|
@@ -1,27 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.normalizeDirectory = normalizeDirectory;
|
4
|
-
exports.normalizeProjectName = normalizeProjectName;
|
5
3
|
exports.normalizeOptions = normalizeOptions;
|
6
4
|
const devkit_1 = require("@nx/devkit");
|
7
5
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
8
6
|
const assertion_1 = require("../../../utils/assertion");
|
9
7
|
const find_free_port_1 = require("./find-free-port");
|
10
8
|
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");
|
12
|
-
function normalizeDirectory(options) {
|
13
|
-
options.directory = options.directory?.replace(/\\{1,2}/g, '/');
|
14
|
-
const { projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
|
15
|
-
return projectDirectory
|
16
|
-
? `${(0, devkit_1.names)(projectDirectory).fileName}/${(0, devkit_1.names)(options.name).fileName}`
|
17
|
-
: (0, devkit_1.names)(options.name).fileName;
|
18
|
-
}
|
19
|
-
function normalizeProjectName(options) {
|
20
|
-
return normalizeDirectory(options).replace(new RegExp('/', 'g'), '-');
|
21
|
-
}
|
22
9
|
async function normalizeOptions(host, options) {
|
23
|
-
await (0, project_name_and_root_utils_1.
|
24
|
-
const { projectName:
|
10
|
+
await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'application');
|
11
|
+
const { projectName, names: projectNames, projectRoot: appProjectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
25
12
|
name: options.name,
|
26
13
|
projectType: 'application',
|
27
14
|
directory: options.directory,
|
@@ -32,6 +19,8 @@ async function normalizeOptions(host, options) {
|
|
32
19
|
nxJson.useInferencePlugins !== false;
|
33
20
|
options.addPlugin ??= addPlugin;
|
34
21
|
options.rootProject = appProjectRoot === '.';
|
22
|
+
const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
|
23
|
+
const appProjectName = !isUsingTsSolutionConfig || options.name ? projectName : importPath;
|
35
24
|
const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
|
36
25
|
const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
|
37
26
|
const parsedTags = options.tags
|
@@ -42,20 +31,18 @@ async function normalizeOptions(host, options) {
|
|
42
31
|
? null
|
43
32
|
: options.style;
|
44
33
|
(0, assertion_1.assertValidStyle)(options.style);
|
45
|
-
const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
|
46
34
|
const normalized = {
|
47
35
|
...options,
|
48
|
-
|
49
|
-
projectName: isUsingTsSolutionConfig
|
50
|
-
? (0, get_import_path_1.getImportPath)(host, appProjectName)
|
51
|
-
: appProjectName,
|
36
|
+
projectName: appProjectName,
|
52
37
|
appProjectRoot,
|
38
|
+
importPath,
|
53
39
|
e2eProjectName,
|
54
40
|
e2eProjectRoot,
|
55
41
|
parsedTags,
|
56
42
|
fileName,
|
57
43
|
styledModule,
|
58
44
|
hasStyles: options.style !== 'none',
|
45
|
+
names: (0, devkit_1.names)(projectNames.projectSimpleName),
|
59
46
|
isUsingTsSolutionConfig,
|
60
47
|
};
|
61
48
|
normalized.routing = normalized.routing ?? false;
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import type { names } from '@nx/devkit';
|
1
2
|
import type { Linter, LinterType } from '@nx/eslint';
|
2
3
|
import type { SupportedStyles } from '../../../typings/style';
|
3
4
|
|
@@ -38,11 +39,13 @@ export interface NormalizedSchema<T extends Schema = Schema> extends T {
|
|
38
39
|
appProjectRoot: string;
|
39
40
|
e2eProjectName: string;
|
40
41
|
e2eProjectRoot: string;
|
42
|
+
importPath: string;
|
41
43
|
parsedTags: string[];
|
42
44
|
fileName: string;
|
43
45
|
styledModule: null | SupportedStyles;
|
44
46
|
hasStyles: boolean;
|
45
47
|
unitTestRunner: 'jest' | 'vitest' | 'none';
|
46
48
|
addPlugin?: boolean;
|
49
|
+
names: ReturnType<typeof names>;
|
47
50
|
isUsingTsSolutionConfig?: boolean;
|
48
51
|
}
|
@@ -19,7 +19,10 @@ const update_module_federation_tsconfig_1 = require("./lib/update-module-federat
|
|
19
19
|
async function hostGenerator(host, schema) {
|
20
20
|
const tasks = [];
|
21
21
|
const options = {
|
22
|
-
...(await (0, normalize_options_1.normalizeOptions)(host,
|
22
|
+
...(await (0, normalize_options_1.normalizeOptions)(host, {
|
23
|
+
...schema,
|
24
|
+
alwaysGenerateProjectJson: true,
|
25
|
+
})),
|
23
26
|
js: schema.js ?? false,
|
24
27
|
typescriptConfiguration: schema.js
|
25
28
|
? false
|
@@ -39,7 +42,7 @@ async function hostGenerator(host, schema) {
|
|
39
42
|
}
|
40
43
|
});
|
41
44
|
}
|
42
|
-
await (0, project_name_and_root_utils_1.
|
45
|
+
await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'application');
|
43
46
|
const initTask = await (0, application_1.default)(host, {
|
44
47
|
...options,
|
45
48
|
directory: options.appProjectRoot,
|
@@ -7,7 +7,7 @@ const assertion_1 = require("../../../utils/assertion");
|
|
7
7
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
8
8
|
async function normalizeOptions(host, options) {
|
9
9
|
const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
|
10
|
-
await (0, project_name_and_root_utils_1.
|
10
|
+
await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'library');
|
11
11
|
const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
12
12
|
name: options.name,
|
13
13
|
projectType: 'library',
|
@@ -41,7 +41,7 @@ async function normalizeOptions(host, options) {
|
|
41
41
|
bundler,
|
42
42
|
fileName,
|
43
43
|
routePath: `/${projectNames.projectSimpleName}`,
|
44
|
-
name: isUsingTsSolutionConfig ? importPath : projectName,
|
44
|
+
name: isUsingTsSolutionConfig && !options.name ? importPath : projectName,
|
45
45
|
projectRoot,
|
46
46
|
parsedTags,
|
47
47
|
importPath,
|
@@ -51,13 +51,15 @@ async function normalizeOptions(host, options) {
|
|
51
51
|
normalized.inSourceTests === normalized.minimal || normalized.inSourceTests;
|
52
52
|
if (options.appProject) {
|
53
53
|
const appProjectConfig = (0, devkit_1.getProjects)(host).get(options.appProject);
|
54
|
-
|
55
|
-
|
54
|
+
const appProjectType = (0, ts_solution_setup_1.getProjectType)(host, appProjectConfig.root, appProjectConfig.projectType);
|
55
|
+
if (appProjectType !== 'application') {
|
56
|
+
throw new Error(`appProject expected type of "application" but got "${appProjectType}"`);
|
56
57
|
}
|
58
|
+
const appSourceRoot = (0, ts_solution_setup_1.getProjectSourceRoot)(host, appProjectConfig.sourceRoot, appProjectConfig.root);
|
57
59
|
normalized.appMain =
|
58
60
|
appProjectConfig.targets.build?.options?.main ??
|
59
61
|
findMainEntry(host, appProjectConfig.root);
|
60
|
-
normalized.appSourceRoot = (0, devkit_1.normalizePath)(
|
62
|
+
normalized.appSourceRoot = (0, devkit_1.normalizePath)(appSourceRoot);
|
61
63
|
// TODO(jack): We should use appEntryFile instead of appProject so users can directly set it rather than us inferring it.
|
62
64
|
if (!normalized.appMain) {
|
63
65
|
throw new Error(`Could not locate project main for ${options.appProject}`);
|
@@ -53,17 +53,20 @@ async function libraryGeneratorInternal(host, schema) {
|
|
53
53
|
});
|
54
54
|
tasks.push(initTask);
|
55
55
|
if (options.isUsingTsSolutionConfig) {
|
56
|
-
|
57
|
-
name: options.importPath
|
56
|
+
const packageJson = {
|
57
|
+
name: options.importPath,
|
58
58
|
version: '0.0.1',
|
59
59
|
...(0, determine_entry_fields_1.determineEntryFields)(options),
|
60
|
-
nx: options.parsedTags?.length
|
61
|
-
? {
|
62
|
-
tags: options.parsedTags,
|
63
|
-
}
|
64
|
-
: undefined,
|
65
60
|
files: options.publishable ? ['dist', '!**/*.tsbuildinfo'] : undefined,
|
66
|
-
}
|
61
|
+
};
|
62
|
+
if (options.name !== options.importPath) {
|
63
|
+
packageJson.nx = { name: options.name };
|
64
|
+
}
|
65
|
+
if (options.parsedTags?.length) {
|
66
|
+
packageJson.nx ??= {};
|
67
|
+
packageJson.nx.tags = options.parsedTags;
|
68
|
+
}
|
69
|
+
(0, devkit_1.writeJson)(host, `${options.projectRoot}/package.json`, packageJson);
|
67
70
|
}
|
68
71
|
else {
|
69
72
|
(0, devkit_1.addProjectConfiguration)(host, options.name, {
|
@@ -48,7 +48,10 @@ function addModuleFederationFiles(host, options) {
|
|
48
48
|
async function remoteGenerator(host, schema) {
|
49
49
|
const tasks = [];
|
50
50
|
const options = {
|
51
|
-
...(await (0, normalize_options_1.normalizeOptions)(host,
|
51
|
+
...(await (0, normalize_options_1.normalizeOptions)(host, {
|
52
|
+
...schema,
|
53
|
+
alwaysGenerateProjectJson: true,
|
54
|
+
})),
|
52
55
|
// when js is set to true, we want to use the js configuration
|
53
56
|
js: schema.js ?? false,
|
54
57
|
typescriptConfiguration: schema.js
|
@@ -62,29 +65,29 @@ async function remoteGenerator(host, schema) {
|
|
62
65
|
if (options.dynamic) {
|
63
66
|
// Dynamic remotes generate with library { type: 'var' } by default.
|
64
67
|
// We need to ensure that the remote name is a valid variable name.
|
65
|
-
const isValidRemote = (0, js_1.isValidVariable)(options.
|
68
|
+
const isValidRemote = (0, js_1.isValidVariable)(options.projectName);
|
66
69
|
if (!isValidRemote.isValid) {
|
67
|
-
throw new Error(`Invalid remote name provided: ${options.
|
70
|
+
throw new Error(`Invalid remote name provided: ${options.projectName}. ${isValidRemote.message}`);
|
68
71
|
}
|
69
72
|
}
|
70
|
-
await (0, project_name_and_root_utils_1.
|
73
|
+
await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'application');
|
71
74
|
const REMOTE_NAME_REGEX = '^[a-zA-Z_$][a-zA-Z_$0-9]*$';
|
72
75
|
const remoteNameRegex = new RegExp(REMOTE_NAME_REGEX);
|
73
|
-
if (!remoteNameRegex.test(options.
|
74
|
-
throw new Error((0, devkit_1.stripIndents) `Invalid remote name: ${options.
|
76
|
+
if (!remoteNameRegex.test(options.projectName)) {
|
77
|
+
throw new Error((0, devkit_1.stripIndents) `Invalid remote name: ${options.projectName}. Remote project names must:
|
75
78
|
- Start with a letter, dollar sign ($) or underscore (_)
|
76
79
|
- Followed by any valid character (letters, digits, underscores, or dollar signs)
|
77
80
|
The regular expression used is ${REMOTE_NAME_REGEX}.`);
|
78
81
|
}
|
79
82
|
const initAppTask = await (0, application_1.default)(host, {
|
80
83
|
...options,
|
81
|
-
name: options.
|
84
|
+
name: options.projectName,
|
82
85
|
skipFormat: true,
|
83
86
|
alwaysGenerateProjectJson: true,
|
84
87
|
});
|
85
88
|
tasks.push(initAppTask);
|
86
89
|
if (options.host) {
|
87
|
-
(0, update_host_with_remote_1.updateHostWithRemote)(host, options.host, options.
|
90
|
+
(0, update_host_with_remote_1.updateHostWithRemote)(host, options.host, options.projectName);
|
88
91
|
}
|
89
92
|
// Module federation requires bootstrap code to be dynamically imported.
|
90
93
|
// Renaming original entry file so we can use `import(./bootstrap)` in
|