@nx/react 16.8.0-beta.3 → 16.8.0-beta.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/babel.js +2 -3
- package/package.json +7 -7
- package/plugins/bundle-rollup.js +9 -3
- package/plugins/component-testing/index.js +57 -37
- package/plugins/jest.js +4 -6
- package/plugins/storybook/index.js +46 -17
- package/plugins/with-react.js +5 -9
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +101 -103
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +67 -72
- package/src/generators/application/application.js +124 -124
- package/src/generators/application/lib/add-e2e.js +41 -37
- package/src/generators/application/lib/add-jest.js +13 -8
- package/src/generators/application/lib/add-project.js +4 -3
- package/src/generators/application/lib/create-application-files.js +8 -1
- package/src/generators/application/lib/find-free-port.js +1 -2
- package/src/generators/application/lib/normalize-options.js +49 -47
- package/src/generators/application/lib/set-defaults.js +25 -5
- package/src/generators/component/component.js +68 -64
- package/src/generators/component-cypress-spec/component-cypress-spec.js +6 -9
- package/src/generators/component-story/component-story.js +8 -9
- package/src/generators/component-test/component-test.js +15 -18
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js +23 -26
- package/src/generators/cypress-component-configuration/lib/add-files.js +38 -42
- package/src/generators/hook/hook.js +59 -58
- package/src/generators/host/host.js +54 -53
- package/src/generators/host/lib/add-module-federation-files.js +11 -3
- package/src/generators/host/lib/normalize-remote.js +8 -11
- package/src/generators/host/lib/setup-ssr-for-host.js +21 -15
- package/src/generators/host/lib/update-module-federation-e2e-project.js +5 -2
- package/src/generators/init/init.js +30 -20
- package/src/generators/library/lib/add-linting.js +24 -27
- package/src/generators/library/lib/add-rollup-build-target.js +42 -46
- package/src/generators/library/lib/create-files.js +7 -1
- package/src/generators/library/lib/normalize-options.js +53 -50
- package/src/generators/library/lib/set-defaults.js +12 -4
- package/src/generators/library/library.js +122 -111
- package/src/generators/redux/redux.js +25 -16
- package/src/generators/remote/lib/setup-ssr-for-remote.js +25 -23
- package/src/generators/remote/remote.js +44 -39
- package/src/generators/setup-ssr/setup-ssr.js +134 -132
- package/src/generators/setup-tailwind/lib/update-project.js +3 -5
- package/src/generators/setup-tailwind/setup-tailwind.js +23 -26
- package/src/generators/stories/stories.js +79 -88
- package/src/generators/storybook-configuration/configuration.js +40 -47
- package/src/migrations/update-12-0-0/remove-react-redux-types-package.js +2 -5
- package/src/migrations/update-12-0-0/update-emotion-setup.js +50 -55
- package/src/migrations/update-12-0-0/use-react-jsx-in-tsconfig.js +14 -18
- package/src/migrations/update-12-8-0/update-12-8-0.js +3 -6
- package/src/migrations/update-13-0-0/migrate-storybook-to-webpack-5.js +23 -26
- package/src/migrations/update-13-0-0/update-emotion-setup.js +24 -27
- package/src/migrations/update-13-0-0/webpack5-changes-utils.js +30 -34
- package/src/migrations/update-13-10-0/update-13-10-0.js +15 -18
- package/src/migrations/update-14-0-0/add-default-development-configurations.js +26 -31
- package/src/migrations/update-14-0-0/replace-testing-library-react-hook.js +12 -16
- package/src/migrations/update-14-0-0/update-react-dom-render-for-v18.js +13 -17
- package/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.js +24 -27
- package/src/migrations/update-14-6-0/add-preset-jest-config.js +1 -2
- package/src/migrations/update-15-3-0/install-webpack-rollup-dependencies.js +3 -4
- package/src/migrations/update-15-3-0/update-rollup-executor.js +1 -2
- package/src/migrations/update-15-6-3/webpack-config-setup.js +56 -60
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
- package/src/migrations/update-16-2-0-remove-package/update-16-2-0-remove-package.js +3 -6
- package/src/migrations/update-16-3-0/remove-types-react-router-dom-package.js +3 -6
- package/src/migrations/update-16-7-0/add-babel-core.js +8 -11
- package/src/migrations/update-16-7-0-add-typings/update-16-7-0-add-typings.js +36 -41
- package/src/module-federation/ast-utils.js +1 -1
- package/src/module-federation/load-config.js +1 -1
- package/src/module-federation/utils.js +36 -37
- package/src/module-federation/with-module-federation-ssr.js +24 -25
- package/src/module-federation/with-module-federation.js +23 -22
- package/src/rules/update-module-federation-project.js +9 -2
- package/src/utils/ast-utils.js +12 -15
- package/src/utils/create-ts-config.js +6 -4
- package/src/utils/ct-utils.js +31 -33
- package/src/utils/lint.js +5 -3
- package/src/utils/testing-generators.js +18 -22
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.componentSchematic = exports.componentGenerator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const add_styled_dependencies_1 = require("../../rules/add-styled-dependencies");
|
|
7
6
|
const assertion_1 = require("../../utils/assertion");
|
|
@@ -11,29 +10,32 @@ const versions_1 = require("../../utils/versions");
|
|
|
11
10
|
const get_component_tests_1 = require("./get-component-tests");
|
|
12
11
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
13
12
|
const path_1 = require("path");
|
|
14
|
-
function componentGenerator(host, schema) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
30
|
-
});
|
|
13
|
+
async function componentGenerator(host, schema) {
|
|
14
|
+
const options = await normalizeOptions(host, schema);
|
|
15
|
+
createComponentFiles(host, options);
|
|
16
|
+
const tasks = [];
|
|
17
|
+
const styledTask = (0, add_styled_dependencies_1.addStyledModuleDependencies)(host, options);
|
|
18
|
+
tasks.push(styledTask);
|
|
19
|
+
addExportsToBarrel(host, options);
|
|
20
|
+
if (options.routing) {
|
|
21
|
+
const routingTask = (0, devkit_1.addDependenciesToPackageJson)(host, { 'react-router-dom': versions_1.reactRouterDomVersion }, {});
|
|
22
|
+
tasks.push(routingTask);
|
|
23
|
+
}
|
|
24
|
+
if (!options.skipFormat) {
|
|
25
|
+
await (0, devkit_1.formatFiles)(host);
|
|
26
|
+
}
|
|
27
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
31
28
|
}
|
|
32
29
|
exports.componentGenerator = componentGenerator;
|
|
33
30
|
function createComponentFiles(host, options) {
|
|
34
31
|
const componentDir = (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.directory);
|
|
35
32
|
const componentTests = (0, get_component_tests_1.getComponentTests)(options);
|
|
36
|
-
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), componentDir,
|
|
33
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), componentDir, {
|
|
34
|
+
...options,
|
|
35
|
+
componentTests,
|
|
36
|
+
inSourceVitestTests: (0, get_in_source_vitest_tests_template_1.getInSourceVitestTestsTemplate)(componentTests),
|
|
37
|
+
tmpl: '',
|
|
38
|
+
});
|
|
37
39
|
for (const c of host.listChanges()) {
|
|
38
40
|
let deleteFile = false;
|
|
39
41
|
if ((options.skipTests || options.inSourceTests) &&
|
|
@@ -76,52 +78,54 @@ function addExportsToBarrel(host, options) {
|
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
|
-
function normalizeOptions(host, options) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
options
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
81
|
+
async function normalizeOptions(host, options) {
|
|
82
|
+
assertValidOptions(options);
|
|
83
|
+
const { className, fileName } = (0, devkit_1.names)(options.name);
|
|
84
|
+
const componentFileName = options.fileName ?? (options.pascalCaseFiles ? className : fileName);
|
|
85
|
+
const project = (0, devkit_1.getProjects)(host).get(options.project);
|
|
86
|
+
if (!project) {
|
|
87
|
+
devkit_1.logger.error(`Cannot find the ${options.project} project. Please double check the project name.`);
|
|
88
|
+
throw new Error();
|
|
89
|
+
}
|
|
90
|
+
const { sourceRoot: projectSourceRoot, projectType } = project;
|
|
91
|
+
const directory = await getDirectory(host, options);
|
|
92
|
+
const styledModule = /^(css|scss|less|styl|none)$/.test(options.style)
|
|
93
|
+
? null
|
|
94
|
+
: options.style;
|
|
95
|
+
if (options.export && projectType === 'application') {
|
|
96
|
+
devkit_1.logger.warn(`The "--export" option should not be used with applications and will do nothing.`);
|
|
97
|
+
}
|
|
98
|
+
options.classComponent = options.classComponent ?? false;
|
|
99
|
+
options.routing = options.routing ?? false;
|
|
100
|
+
options.globalCss = options.globalCss ?? false;
|
|
101
|
+
options.inSourceTests = options.inSourceTests ?? false;
|
|
102
|
+
return {
|
|
103
|
+
...options,
|
|
104
|
+
directory,
|
|
105
|
+
styledModule,
|
|
106
|
+
hasStyles: options.style !== 'none',
|
|
107
|
+
className,
|
|
108
|
+
fileName: componentFileName,
|
|
109
|
+
projectSourceRoot,
|
|
110
|
+
};
|
|
105
111
|
}
|
|
106
|
-
function getDirectory(host, options) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return options.flat ? baseDir : (0, devkit_1.joinPathFragments)(baseDir, fileName);
|
|
124
|
-
});
|
|
112
|
+
async function getDirectory(host, options) {
|
|
113
|
+
const genNames = (0, devkit_1.names)(options.name);
|
|
114
|
+
const fileName = options.pascalCaseDirectory === true
|
|
115
|
+
? genNames.className
|
|
116
|
+
: genNames.fileName;
|
|
117
|
+
const workspace = (0, devkit_1.getProjects)(host);
|
|
118
|
+
let baseDir;
|
|
119
|
+
if (options.directory) {
|
|
120
|
+
baseDir = options.directory;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
baseDir =
|
|
124
|
+
workspace.get(options.project).projectType === 'application'
|
|
125
|
+
? 'app'
|
|
126
|
+
: 'lib';
|
|
127
|
+
}
|
|
128
|
+
return options.flat ? baseDir : (0, devkit_1.joinPathFragments)(baseDir, fileName);
|
|
125
129
|
}
|
|
126
130
|
function assertValidOptions(options) {
|
|
127
131
|
(0, assertion_1.assertValidStyle)(options.style);
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.componentCypressSchematic = exports.createComponentSpecFile = exports.getArgsDefaultValue = exports.componentCypressGenerator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const path_1 = require("path");
|
|
7
6
|
const ast_utils_1 = require("../../utils/ast-utils");
|
|
8
7
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
9
8
|
let tsModule;
|
|
10
|
-
function componentCypressGenerator(host, schema) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
});
|
|
9
|
+
async function componentCypressGenerator(host, schema) {
|
|
10
|
+
createComponentSpecFile(host, schema);
|
|
11
|
+
if (!schema.skipFormat) {
|
|
12
|
+
await (0, devkit_1.formatFiles)(host);
|
|
13
|
+
}
|
|
17
14
|
}
|
|
18
15
|
exports.componentCypressGenerator = componentCypressGenerator;
|
|
19
16
|
// TODO: candidate to refactor with the angular component story
|
|
@@ -63,7 +60,7 @@ function createComponentSpecFile(tree, { project, componentPath, js, cypressProj
|
|
|
63
60
|
const cmpDeclaration = (0, ast_utils_1.getComponentNode)(sourceFile);
|
|
64
61
|
if (!cmpDeclaration) {
|
|
65
62
|
const componentNodes = (0, ast_utils_1.findExportDeclarationsForJsx)(sourceFile);
|
|
66
|
-
if (componentNodes
|
|
63
|
+
if (componentNodes?.length) {
|
|
67
64
|
componentNodes.forEach((declaration) => {
|
|
68
65
|
findPropsAndGenerateFileForCypress(tree, sourceFile, declaration, e2eLibIntegrationFolderPath, componentName, project, js, true);
|
|
69
66
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.componentStorySchematic = exports.componentStoryGenerator = exports.findPropsAndGenerateFile = exports.createComponentStoriesFile = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const ast_utils_1 = require("../../utils/ast-utils");
|
|
7
6
|
const component_props_1 = require("../../utils/component-props");
|
|
@@ -30,7 +29,7 @@ function createComponentStoriesFile(host, { project, componentPath, interactionT
|
|
|
30
29
|
const cmpDeclaration = (0, ast_utils_1.getComponentNode)(sourceFile);
|
|
31
30
|
if (!cmpDeclaration) {
|
|
32
31
|
const componentNodes = (0, ast_utils_1.findExportDeclarationsForJsx)(sourceFile);
|
|
33
|
-
if (componentNodes
|
|
32
|
+
if (componentNodes?.length) {
|
|
34
33
|
componentNodes.forEach((declaration) => {
|
|
35
34
|
findPropsAndGenerateFile(host, sourceFile, declaration, componentDirectory, name, interactionTests, isPlainJs, componentNodes.length > 1);
|
|
36
35
|
});
|
|
@@ -60,14 +59,14 @@ function findPropsAndGenerateFile(host, sourceFile, cmpDeclaration, componentDir
|
|
|
60
59
|
});
|
|
61
60
|
}
|
|
62
61
|
exports.findPropsAndGenerateFile = findPropsAndGenerateFile;
|
|
63
|
-
function componentStoryGenerator(host, schema) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (!schema.skipFormat) {
|
|
68
|
-
yield (0, devkit_1.formatFiles)(host);
|
|
69
|
-
}
|
|
62
|
+
async function componentStoryGenerator(host, schema) {
|
|
63
|
+
createComponentStoriesFile(host, {
|
|
64
|
+
...schema,
|
|
65
|
+
interactionTests: schema.interactionTests ?? true,
|
|
70
66
|
});
|
|
67
|
+
if (!schema.skipFormat) {
|
|
68
|
+
await (0, devkit_1.formatFiles)(host);
|
|
69
|
+
}
|
|
71
70
|
}
|
|
72
71
|
exports.componentStoryGenerator = componentStoryGenerator;
|
|
73
72
|
exports.default = componentStoryGenerator;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.componentTestGenerator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const path_1 = require("path");
|
|
7
6
|
const ast_utils_1 = require("../../utils/ast-utils");
|
|
@@ -9,22 +8,20 @@ const component_props_1 = require("../../utils/component-props");
|
|
|
9
8
|
const versions_1 = require("../../utils/versions");
|
|
10
9
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
11
10
|
let tsModule;
|
|
12
|
-
function componentTestGenerator(tree, options) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
});
|
|
11
|
+
async function componentTestGenerator(tree, options) {
|
|
12
|
+
(0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
|
|
13
|
+
const { assertMinimumCypressVersion } = await Promise.resolve().then(() => require('@nx/cypress/src/utils/cypress-version'));
|
|
14
|
+
assertMinimumCypressVersion(10);
|
|
15
|
+
// normalize any windows paths
|
|
16
|
+
options.componentPath = options.componentPath.replace(/\\/g, '/');
|
|
17
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
18
|
+
const normalizedPath = options.componentPath.startsWith(projectConfig.sourceRoot)
|
|
19
|
+
? (0, path_1.relative)(projectConfig.sourceRoot, options.componentPath)
|
|
20
|
+
: options.componentPath;
|
|
21
|
+
const componentPath = (0, devkit_1.joinPathFragments)(projectConfig.sourceRoot, normalizedPath);
|
|
22
|
+
if (tree.exists(componentPath)) {
|
|
23
|
+
generateSpecsForComponents(tree, componentPath);
|
|
24
|
+
}
|
|
28
25
|
}
|
|
29
26
|
exports.componentTestGenerator = componentTestGenerator;
|
|
30
27
|
function generateSpecsForComponents(tree, filePath) {
|
|
@@ -40,7 +37,7 @@ function generateSpecsForComponents(tree, filePath) {
|
|
|
40
37
|
return;
|
|
41
38
|
}
|
|
42
39
|
const defaultExport = (0, ast_utils_1.getComponentNode)(sourceFile);
|
|
43
|
-
if (cmpNodes
|
|
40
|
+
if (cmpNodes?.length) {
|
|
44
41
|
const components = cmpNodes.map((cmp) => {
|
|
45
42
|
const defaults = (0, component_props_1.getDefaultsForComponent)(sourceFile, cmp);
|
|
46
43
|
const isDefaultExport = defaultExport
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cypressComponentConfigGenerator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const versions_1 = require("../../utils/versions");
|
|
7
6
|
const add_files_1 = require("./lib/add-files");
|
|
@@ -11,32 +10,30 @@ const ct_utils_1 = require("../../utils/ct-utils");
|
|
|
11
10
|
* storybook components then use componentCypressGenerator instead.
|
|
12
11
|
*
|
|
13
12
|
*/
|
|
14
|
-
function cypressComponentConfigGenerator(tree, options) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
skipFormat: true,
|
|
21
|
-
});
|
|
22
|
-
const found = yield (0, ct_utils_1.addCTTargetWithBuildTarget)(tree, {
|
|
23
|
-
project: options.project,
|
|
24
|
-
buildTarget: options.buildTarget,
|
|
25
|
-
validExecutorNames: new Set([
|
|
26
|
-
'@nx/webpack:webpack',
|
|
27
|
-
'@nx/vite:build',
|
|
28
|
-
'@nrwl/webpack:webpack',
|
|
29
|
-
'@nrwl/vite:build',
|
|
30
|
-
]),
|
|
31
|
-
});
|
|
32
|
-
yield (0, add_files_1.addFiles)(tree, projectConfig, options, found);
|
|
33
|
-
if (!options.skipFormat) {
|
|
34
|
-
yield (0, devkit_1.formatFiles)(tree);
|
|
35
|
-
}
|
|
36
|
-
return () => {
|
|
37
|
-
installTask();
|
|
38
|
-
};
|
|
13
|
+
async function cypressComponentConfigGenerator(tree, options) {
|
|
14
|
+
const { componentConfigurationGenerator: baseCyCtConfig } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
|
|
15
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
16
|
+
const installTask = await baseCyCtConfig(tree, {
|
|
17
|
+
project: options.project,
|
|
18
|
+
skipFormat: true,
|
|
39
19
|
});
|
|
20
|
+
const found = await (0, ct_utils_1.addCTTargetWithBuildTarget)(tree, {
|
|
21
|
+
project: options.project,
|
|
22
|
+
buildTarget: options.buildTarget,
|
|
23
|
+
validExecutorNames: new Set([
|
|
24
|
+
'@nx/webpack:webpack',
|
|
25
|
+
'@nx/vite:build',
|
|
26
|
+
'@nrwl/webpack:webpack',
|
|
27
|
+
'@nrwl/vite:build',
|
|
28
|
+
]),
|
|
29
|
+
});
|
|
30
|
+
await (0, add_files_1.addFiles)(tree, projectConfig, options, found);
|
|
31
|
+
if (!options.skipFormat) {
|
|
32
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
33
|
+
}
|
|
34
|
+
return () => {
|
|
35
|
+
installTask();
|
|
36
|
+
};
|
|
40
37
|
}
|
|
41
38
|
exports.cypressComponentConfigGenerator = cypressComponentConfigGenerator;
|
|
42
39
|
exports.default = cypressComponentConfigGenerator;
|
|
@@ -1,54 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addFiles = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const versions_1 = require("nx/src/utils/versions");
|
|
7
6
|
const component_test_1 = require("../../component-test/component-test");
|
|
8
7
|
const ct_utils_1 = require("../../../utils/ct-utils");
|
|
9
|
-
function addFiles(tree, projectConfig, options, found) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (options.bundler && options.bundler !== actualBundler) {
|
|
20
|
-
devkit_1.logger.warn(`You have specified ${options.bundler} as the bundler but this project is configured to use ${actualBundler}.
|
|
8
|
+
async function addFiles(tree, projectConfig, options, found) {
|
|
9
|
+
// must dyanmicaly import to prevent packages not using cypress from erroring out
|
|
10
|
+
// when importing react
|
|
11
|
+
const { addMountDefinition, addDefaultCTConfig } = await Promise.resolve().then(() => require('@nx/cypress/src/utils/config'));
|
|
12
|
+
// Specifically undefined to allow Remix workaround of passing an empty string
|
|
13
|
+
const actualBundler = options.buildTarget !== undefined && options.bundler
|
|
14
|
+
? options.bundler
|
|
15
|
+
: await (0, ct_utils_1.getBundlerFromTarget)(found, tree);
|
|
16
|
+
if (options.bundler && options.bundler !== actualBundler) {
|
|
17
|
+
devkit_1.logger.warn(`You have specified ${options.bundler} as the bundler but this project is configured to use ${actualBundler}.
|
|
21
18
|
This may cause errors. If you are seeing errors, try removing the --bundler option.`);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
for (const filePath of filePaths) {
|
|
46
|
-
yield (0, component_test_1.componentTestGenerator)(tree, {
|
|
47
|
-
project: options.project,
|
|
48
|
-
componentPath: filePath,
|
|
49
|
-
});
|
|
19
|
+
}
|
|
20
|
+
const bundlerToUse = options.bundler ?? actualBundler;
|
|
21
|
+
const commandFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'support', 'component.ts');
|
|
22
|
+
const updatedCommandFile = await addMountDefinition(tree.read(commandFile, 'utf-8'));
|
|
23
|
+
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
|
+
if (options.bundler === 'webpack' ||
|
|
28
|
+
(!options.bundler && actualBundler === 'webpack')) {
|
|
29
|
+
(0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@nx/webpack': versions_1.nxVersion });
|
|
30
|
+
}
|
|
31
|
+
if (options.bundler === 'vite' ||
|
|
32
|
+
(!options.bundler && actualBundler === 'vite')) {
|
|
33
|
+
(0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@nx/vite': versions_1.nxVersion });
|
|
34
|
+
}
|
|
35
|
+
if (options.generateTests) {
|
|
36
|
+
const filePaths = [];
|
|
37
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, projectConfig.sourceRoot, (filePath) => {
|
|
38
|
+
if ((0, ct_utils_1.isComponent)(tree, filePath)) {
|
|
39
|
+
filePaths.push(filePath);
|
|
50
40
|
}
|
|
41
|
+
});
|
|
42
|
+
for (const filePath of filePaths) {
|
|
43
|
+
await (0, component_test_1.componentTestGenerator)(tree, {
|
|
44
|
+
project: options.project,
|
|
45
|
+
componentPath: filePath,
|
|
46
|
+
});
|
|
51
47
|
}
|
|
52
|
-
}
|
|
48
|
+
}
|
|
53
49
|
}
|
|
54
50
|
exports.addFiles = addFiles;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hookSchematic = exports.hookGenerator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
// TODO(jack): Remove inline renderHook function when RTL releases with its own version
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
7
6
|
const ast_utils_1 = require("../../utils/ast-utils");
|
|
8
7
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
9
8
|
const path_1 = require("path");
|
|
10
|
-
function hookGenerator(host, schema) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return yield (0, devkit_1.formatFiles)(host);
|
|
16
|
-
});
|
|
9
|
+
async function hookGenerator(host, schema) {
|
|
10
|
+
const options = await normalizeOptions(host, schema);
|
|
11
|
+
createFiles(host, options);
|
|
12
|
+
addExportsToBarrel(host, options);
|
|
13
|
+
return await (0, devkit_1.formatFiles)(host);
|
|
17
14
|
}
|
|
18
15
|
exports.hookGenerator = hookGenerator;
|
|
19
16
|
function createFiles(host, options) {
|
|
20
17
|
const hookDir = (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.directory);
|
|
21
|
-
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), hookDir,
|
|
18
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), hookDir, {
|
|
19
|
+
...options,
|
|
20
|
+
tmpl: '',
|
|
21
|
+
});
|
|
22
22
|
for (const c of host.listChanges()) {
|
|
23
23
|
let deleteFile = false;
|
|
24
24
|
if (options.skipTests && /.*spec.ts/.test(c.path)) {
|
|
@@ -49,56 +49,57 @@ function addExportsToBarrel(host, options) {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
function normalizeOptions(host, options) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
52
|
+
async function normalizeOptions(host, options) {
|
|
53
|
+
assertValidOptions(options);
|
|
54
|
+
let base = options.name;
|
|
55
|
+
if (base.startsWith('use-')) {
|
|
56
|
+
base = base.substring(4);
|
|
57
|
+
}
|
|
58
|
+
else if (base.startsWith('use')) {
|
|
59
|
+
base = base.substring(3);
|
|
60
|
+
}
|
|
61
|
+
const { className, fileName } = (0, devkit_1.names)(base);
|
|
62
|
+
const hookFilename = options.pascalCaseFiles
|
|
63
|
+
? 'use'.concat(className)
|
|
64
|
+
: 'use-'.concat(fileName);
|
|
65
|
+
const hookName = 'use'.concat(className);
|
|
66
|
+
const hookTypeName = 'Use'.concat(className);
|
|
67
|
+
const project = (0, devkit_1.getProjects)(host).get(options.project);
|
|
68
|
+
if (!project) {
|
|
69
|
+
devkit_1.logger.error(`Cannot find the ${options.project} project. Please double check the project name.`);
|
|
70
|
+
throw new Error();
|
|
71
|
+
}
|
|
72
|
+
const { sourceRoot: projectSourceRoot, projectType } = project;
|
|
73
|
+
const directory = await getDirectory(host, options, base);
|
|
74
|
+
if (options.export && projectType === 'application') {
|
|
75
|
+
devkit_1.logger.warn(`The "--export" option should not be used with applications and will do nothing.`);
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
...options,
|
|
79
|
+
directory,
|
|
80
|
+
hookName,
|
|
81
|
+
hookTypeName,
|
|
82
|
+
fileName: hookFilename,
|
|
83
|
+
projectSourceRoot,
|
|
84
|
+
};
|
|
82
85
|
}
|
|
83
|
-
function getDirectory(host, options, baseHookName) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return options.flat ? baseDir : (0, devkit_1.joinPathFragments)(baseDir, hookFileName);
|
|
101
|
-
});
|
|
86
|
+
async function getDirectory(host, options, baseHookName) {
|
|
87
|
+
const { className, fileName } = (0, devkit_1.names)(baseHookName);
|
|
88
|
+
const hookFileName = options.pascalCaseDirectory === true
|
|
89
|
+
? 'use'.concat(className)
|
|
90
|
+
: 'use-'.concat(fileName);
|
|
91
|
+
const workspace = (0, devkit_1.getProjects)(host);
|
|
92
|
+
let baseDir;
|
|
93
|
+
if (options.directory) {
|
|
94
|
+
baseDir = options.directory;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
baseDir =
|
|
98
|
+
workspace.get(options.project).projectType === 'application'
|
|
99
|
+
? 'app'
|
|
100
|
+
: 'lib';
|
|
101
|
+
}
|
|
102
|
+
return options.flat ? baseDir : (0, devkit_1.joinPathFragments)(baseDir, hookFileName);
|
|
102
103
|
}
|
|
103
104
|
function assertValidOptions(options) {
|
|
104
105
|
const slashes = ['/', '\\'];
|