@nx/react 0.0.0-pr-28808-eac89e6 → 0.0.0-pr-29122-4727ac1
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/schema.json +2 -2
- package/src/generators/component/schema.d.ts +0 -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/library/lib/normalize-options.js +0 -19
- package/src/generators/library/library.js +11 -0
- package/src/generators/library/schema.json +10 -7
- package/src/generators/redux/schema.json +13 -4
- package/src/migrations/update-20-2-0/migrate-mf-imports-to-new-package.js +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/react",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-29122-4727ac1",
|
|
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": "0.0.0-pr-
|
|
42
|
-
"@nx/js": "0.0.0-pr-
|
|
43
|
-
"@nx/eslint": "0.0.0-pr-
|
|
44
|
-
"@nx/web": "0.0.0-pr-
|
|
45
|
-
"@nx/module-federation": "0.0.0-pr-
|
|
41
|
+
"@nx/devkit": "0.0.0-pr-29122-4727ac1",
|
|
42
|
+
"@nx/js": "0.0.0-pr-29122-4727ac1",
|
|
43
|
+
"@nx/eslint": "0.0.0-pr-29122-4727ac1",
|
|
44
|
+
"@nx/web": "0.0.0-pr-29122-4727ac1",
|
|
45
|
+
"@nx/module-federation": "0.0.0-pr-29122-4727ac1",
|
|
46
46
|
"express": "^4.19.2",
|
|
47
47
|
"http-proxy-middleware": "^3.0.3"
|
|
48
48
|
},
|
|
@@ -110,7 +110,7 @@
|
|
|
110
110
|
"description": "The tool to use for running lint checks.",
|
|
111
111
|
"type": "string",
|
|
112
112
|
"enum": ["eslint", "none"],
|
|
113
|
-
"default": "
|
|
113
|
+
"default": "none",
|
|
114
114
|
"x-prompt": "Which linter would you like to use?",
|
|
115
115
|
"x-priority": "important"
|
|
116
116
|
},
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"type": "string",
|
|
119
119
|
"enum": ["vitest", "jest", "none"],
|
|
120
120
|
"description": "Test runner to use for unit tests.",
|
|
121
|
-
"default": "
|
|
121
|
+
"default": "none",
|
|
122
122
|
"x-prompt": "What unit test runner should be used?",
|
|
123
123
|
"x-priority": "important"
|
|
124
124
|
},
|
|
@@ -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
|
}
|
|
@@ -5,27 +5,8 @@ const devkit_1 = require("@nx/devkit");
|
|
|
5
5
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
6
6
|
const assertion_1 = require("../../../utils/assertion");
|
|
7
7
|
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
8
|
-
const prompt_1 = require("@nx/devkit/src/generators/prompt");
|
|
9
8
|
async function normalizeOptions(host, options) {
|
|
10
9
|
const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
|
|
11
|
-
if (isUsingTsSolutionConfig) {
|
|
12
|
-
options.bundler ??= await (0, prompt_1.promptWhenInteractive)({
|
|
13
|
-
type: 'autocomplete',
|
|
14
|
-
name: 'bundler',
|
|
15
|
-
message: `Which bundler would you like to use to build the library? Choose 'none' to skip build setup.`,
|
|
16
|
-
choices: [{ name: 'vite' }, { name: 'rollup' }, { name: 'none' }],
|
|
17
|
-
initial: 0,
|
|
18
|
-
}, { bundler: 'none' }).then(({ bundler }) => bundler);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
options.bundler ??= await (0, prompt_1.promptWhenInteractive)({
|
|
22
|
-
type: 'autocomplete',
|
|
23
|
-
name: 'bundler',
|
|
24
|
-
message: `Which bundler would you like to use to build the library? Choose 'none' to skip build setup.`,
|
|
25
|
-
choices: [{ name: 'none' }, { name: 'vite' }, { name: 'rollup' }],
|
|
26
|
-
initial: 0,
|
|
27
|
-
}, { bundler: undefined }).then(({ bundler }) => bundler);
|
|
28
|
-
}
|
|
29
10
|
await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'library');
|
|
30
11
|
const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
|
31
12
|
name: options.name,
|
|
@@ -47,8 +47,15 @@ async function libraryGeneratorInternal(host, schema) {
|
|
|
47
47
|
});
|
|
48
48
|
tasks.push(initTask);
|
|
49
49
|
if (options.isUsingTsSolutionConfig) {
|
|
50
|
+
const sourceEntry = options.bundler === 'none'
|
|
51
|
+
? options.js
|
|
52
|
+
? './src/index.js'
|
|
53
|
+
: './src/index.ts'
|
|
54
|
+
: undefined;
|
|
50
55
|
(0, devkit_1.writeJson)(host, `${options.projectRoot}/package.json`, {
|
|
51
56
|
name: options.importPath,
|
|
57
|
+
main: sourceEntry,
|
|
58
|
+
types: sourceEntry,
|
|
52
59
|
nx: {
|
|
53
60
|
name: options.importPath === options.name ? undefined : options.name,
|
|
54
61
|
projectType: 'library',
|
|
@@ -205,6 +212,10 @@ async function libraryGeneratorInternal(host, schema) {
|
|
|
205
212
|
if (!options.skipFormat) {
|
|
206
213
|
await (0, devkit_1.formatFiles)(host);
|
|
207
214
|
}
|
|
215
|
+
// Always run install to link packages.
|
|
216
|
+
if (options.isUsingTsSolutionConfig) {
|
|
217
|
+
tasks.push(() => (0, devkit_1.installPackagesTask)(host));
|
|
218
|
+
}
|
|
208
219
|
tasks.push(() => {
|
|
209
220
|
(0, log_show_project_command_1.logShowProjectCommand)(options.name);
|
|
210
221
|
});
|
|
@@ -71,18 +71,26 @@
|
|
|
71
71
|
]
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
|
+
"bundler": {
|
|
75
|
+
"type": "string",
|
|
76
|
+
"description": "The bundler to use. Choosing 'none' means this library is not buildable.",
|
|
77
|
+
"enum": ["none", "vite", "rollup"],
|
|
78
|
+
"default": "none",
|
|
79
|
+
"x-prompt": "Which bundler would you like to use to build the library? Choose 'none' to skip build setup.",
|
|
80
|
+
"x-priority": "important"
|
|
81
|
+
},
|
|
74
82
|
"linter": {
|
|
75
83
|
"description": "The tool to use for running lint checks.",
|
|
76
84
|
"type": "string",
|
|
77
85
|
"enum": ["eslint", "none"],
|
|
78
|
-
"default": "
|
|
86
|
+
"default": "none",
|
|
79
87
|
"x-prompt": "Which linter would you like to use?",
|
|
80
88
|
"x-priority": "important"
|
|
81
89
|
},
|
|
82
90
|
"unitTestRunner": {
|
|
83
91
|
"type": "string",
|
|
84
92
|
"enum": ["vitest", "jest", "none"],
|
|
85
|
-
"default": "
|
|
93
|
+
"default": "none",
|
|
86
94
|
"description": "Test runner to use for unit tests.",
|
|
87
95
|
"x-prompt": "What unit test runner should be used?",
|
|
88
96
|
"x-priority": "important"
|
|
@@ -157,11 +165,6 @@
|
|
|
157
165
|
"description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.",
|
|
158
166
|
"default": false
|
|
159
167
|
},
|
|
160
|
-
"bundler": {
|
|
161
|
-
"type": "string",
|
|
162
|
-
"description": "The bundler to use. Choosing 'none' means this library is not buildable.",
|
|
163
|
-
"enum": ["none", "vite", "rollup"]
|
|
164
|
-
},
|
|
165
168
|
"compiler": {
|
|
166
169
|
"type": "string",
|
|
167
170
|
"enum": ["babel", "swc"],
|
|
@@ -5,21 +5,30 @@
|
|
|
5
5
|
"title": "Create Redux state",
|
|
6
6
|
"description": "Create a Redux state slice for a React project.",
|
|
7
7
|
"type": "object",
|
|
8
|
+
"examples": [
|
|
9
|
+
{
|
|
10
|
+
"description": "Generate a Redux state slice with the exported symbol matching the file name. It results in the slice `fooSlice` at `mylib/src/lib/foo.slice.ts`",
|
|
11
|
+
"command": "nx g @nx/react:redux mylib/src/lib/foo"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"description": "Generate a Redux state slice with the exported symbol different from the file name. It results in the slice `customSlice` at `mylib/src/lib/foo.slice.ts`",
|
|
15
|
+
"command": "nx g @nx/react:redux mylib/src/lib/foo --name=custom"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
8
18
|
"properties": {
|
|
9
19
|
"path": {
|
|
10
20
|
"type": "string",
|
|
11
|
-
"description": "
|
|
21
|
+
"description": "The file path to the Redux state slice without the file extension. Relative to the current working directory.",
|
|
12
22
|
"$default": {
|
|
13
23
|
"$source": "argv",
|
|
14
24
|
"index": 0
|
|
15
25
|
},
|
|
16
|
-
"x-prompt": "
|
|
26
|
+
"x-prompt": "What is the Redux stateslice file path?",
|
|
17
27
|
"x-priority": "important"
|
|
18
28
|
},
|
|
19
29
|
"name": {
|
|
20
30
|
"type": "string",
|
|
21
|
-
"description": "Redux slice name."
|
|
22
|
-
"x-priority": "important"
|
|
31
|
+
"description": "The Redux state slice symbol name. Defaults to the last segment of the file path."
|
|
23
32
|
},
|
|
24
33
|
"appProject": {
|
|
25
34
|
"type": "string",
|
|
@@ -14,6 +14,9 @@ async function migrateMfImportsToNewPackage(tree) {
|
|
|
14
14
|
const rootsToCheck = new Set();
|
|
15
15
|
const graph = await (0, devkit_1.createProjectGraphAsync)();
|
|
16
16
|
for (const [project, dependencies] of Object.entries(graph.dependencies)) {
|
|
17
|
+
if (!graph.nodes[project]) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
17
20
|
const usesNxWebpackOrRspack = dependencies.some((dep) => dep.target === 'npm:@nx/webpack' || dep.target === 'npm:@nx/rspack');
|
|
18
21
|
if (usesNxWebpackOrRspack) {
|
|
19
22
|
const root = graph.nodes[project].data.root;
|