@nx/cypress 16.8.0-beta.4 → 16.8.0-beta.6

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.
Files changed (35) hide show
  1. package/migrations.json +6 -0
  2. package/package.json +7 -7
  3. package/plugins/cypress-preset.d.ts +0 -3
  4. package/plugins/cypress-preset.js +15 -7
  5. package/src/executors/cypress/cypress.impl.d.ts +1 -0
  6. package/src/executors/cypress/cypress.impl.js +180 -210
  7. package/src/executors/cypress/schema.json +4 -0
  8. package/src/generators/base-setup/base-setup.js +15 -5
  9. package/src/generators/component-configuration/component-configuration.js +42 -30
  10. package/src/generators/configuration/configuration.js +87 -70
  11. package/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.js +75 -78
  12. package/src/generators/cypress-project/cypress-project.js +76 -63
  13. package/src/generators/init/init.js +16 -18
  14. package/src/generators/migrate-to-cypress-11/conversion.util.js +22 -16
  15. package/src/generators/migrate-to-cypress-11/migrate-to-cypress-11.js +38 -35
  16. package/src/migrations/update-12-8-0/remove-typescript-plugin.js +23 -26
  17. package/src/migrations/update-14-6-1/update-cypress-configs-presets.js +79 -68
  18. package/src/migrations/update-14-7-0/update-cypress-version-if-10.js +1 -2
  19. package/src/migrations/update-15-0-0/add-cypress-inputs.js +24 -29
  20. package/src/migrations/update-15-0-0/update-cy-mount-usage.js +25 -29
  21. package/src/migrations/update-15-1-0/cypress-11.js +34 -37
  22. package/src/migrations/update-15-5-0/update-to-cypress-12.js +3 -5
  23. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
  24. package/src/migrations/update-16-2-0/update-cy-tsconfig.js +25 -24
  25. package/src/migrations/update-16-4-0/tsconfig-sourcemaps.js +52 -49
  26. package/src/migrations/update-16-8-0/cypress-13.d.ts +7 -0
  27. package/src/migrations/update-16-8-0/cypress-13.js +179 -0
  28. package/src/plugins/preprocessor-vite.js +7 -5
  29. package/src/utils/add-linter.js +78 -81
  30. package/src/utils/config.js +54 -62
  31. package/src/utils/ct-helpers.js +6 -8
  32. package/src/utils/cypress-version.js +1 -1
  33. package/src/utils/find-target-options.js +37 -43
  34. package/src/utils/versions.d.ts +1 -1
  35. package/src/utils/versions.js +1 -1
@@ -1,35 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addMountDefinition = exports.addDefaultCTConfig = exports.addDefaultE2EConfig = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const TS_QUERY_EXPORT_CONFIG_PREFIX = ':matches(ExportAssignment, BinaryExpression:has(Identifier[name="module"]):has(Identifier[name="exports"]))';
6
- function addDefaultE2EConfig(cyConfigContents, options) {
7
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
8
- if (!cyConfigContents) {
9
- throw new Error('The passed in cypress config file is empty!');
10
- }
11
- const { tsquery } = yield Promise.resolve().then(() => require('@phenomnomnominal/tsquery'));
12
- const testingTypeConfig = tsquery.query(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} PropertyAssignment:has(Identifier[name="e2e"])`);
13
- let updatedConfigContents = cyConfigContents;
14
- if (testingTypeConfig.length === 0) {
15
- const configValue = options.bundler === 'vite'
16
- ? `nxE2EPreset(__filename, { cypressDir: '${options.directory}', bundler: 'vite' })`
17
- : `nxE2EPreset(__filename, { cypressDir: '${options.directory}' })`;
18
- updatedConfigContents = tsquery.replace(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} ObjectLiteralExpression:first-child`, (node) => {
19
- if (node.properties.length > 0) {
20
- return `{
5
+ async function addDefaultE2EConfig(cyConfigContents, options) {
6
+ if (!cyConfigContents) {
7
+ throw new Error('The passed in cypress config file is empty!');
8
+ }
9
+ const { tsquery } = await Promise.resolve().then(() => require('@phenomnomnominal/tsquery'));
10
+ const testingTypeConfig = tsquery.query(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} PropertyAssignment:has(Identifier[name="e2e"])`);
11
+ let updatedConfigContents = cyConfigContents;
12
+ if (testingTypeConfig.length === 0) {
13
+ const configValue = options.bundler === 'vite'
14
+ ? `nxE2EPreset(__filename, { cypressDir: '${options.directory}', bundler: 'vite' })`
15
+ : `nxE2EPreset(__filename, { cypressDir: '${options.directory}' })`;
16
+ updatedConfigContents = tsquery.replace(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} ObjectLiteralExpression:first-child`, (node) => {
17
+ if (node.properties.length > 0) {
18
+ return `{
21
19
  ${node.properties.map((p) => p.getText()).join(',\n')},
22
20
  e2e: ${configValue}
23
21
  }`;
24
- }
25
- return `{
22
+ }
23
+ return `{
26
24
  e2e: ${configValue}
27
25
  }`;
28
- });
29
- updatedConfigContents = `import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';\n${updatedConfigContents}`;
30
- }
31
- return updatedConfigContents;
32
- });
26
+ });
27
+ updatedConfigContents = `import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';\n${updatedConfigContents}`;
28
+ }
29
+ return updatedConfigContents;
33
30
  }
34
31
  exports.addDefaultE2EConfig = addDefaultE2EConfig;
35
32
  /**
@@ -37,32 +34,30 @@ exports.addDefaultE2EConfig = addDefaultE2EConfig;
37
34
  * Make sure after calling this the correct import statement is addeda
38
35
  * to bring in the nxComponentTestingPreset function
39
36
  **/
40
- function addDefaultCTConfig(cyConfigContents, options = {}) {
41
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
42
- if (!cyConfigContents) {
43
- throw new Error('The passed in cypress config file is empty!');
44
- }
45
- const { tsquery } = yield Promise.resolve().then(() => require('@phenomnomnominal/tsquery'));
46
- const testingTypeConfig = tsquery.query(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} PropertyAssignment:has(Identifier[name="component"])`);
47
- let updatedConfigContents = cyConfigContents;
48
- if (testingTypeConfig.length === 0) {
49
- const configValue = (options === null || options === void 0 ? void 0 : options.bundler) === 'vite'
50
- ? "nxComponentTestingPreset(__filename, { bundler: 'vite' })"
51
- : 'nxComponentTestingPreset(__filename)';
52
- updatedConfigContents = tsquery.replace(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} ObjectLiteralExpression:first-child`, (node) => {
53
- if (node.properties.length > 0) {
54
- return `{
37
+ async function addDefaultCTConfig(cyConfigContents, options = {}) {
38
+ if (!cyConfigContents) {
39
+ throw new Error('The passed in cypress config file is empty!');
40
+ }
41
+ const { tsquery } = await Promise.resolve().then(() => require('@phenomnomnominal/tsquery'));
42
+ const testingTypeConfig = tsquery.query(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} PropertyAssignment:has(Identifier[name="component"])`);
43
+ let updatedConfigContents = cyConfigContents;
44
+ if (testingTypeConfig.length === 0) {
45
+ const configValue = options?.bundler === 'vite'
46
+ ? "nxComponentTestingPreset(__filename, { bundler: 'vite' })"
47
+ : 'nxComponentTestingPreset(__filename)';
48
+ updatedConfigContents = tsquery.replace(cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} ObjectLiteralExpression:first-child`, (node) => {
49
+ if (node.properties.length > 0) {
50
+ return `{
55
51
  ${node.properties.map((p) => p.getText()).join(',\n')},
56
52
  component: ${configValue}
57
53
  }`;
58
- }
59
- return `{
54
+ }
55
+ return `{
60
56
  component: ${configValue}
61
57
  }`;
62
- });
63
- }
64
- return updatedConfigContents;
65
- });
58
+ });
59
+ }
60
+ return updatedConfigContents;
66
61
  }
67
62
  exports.addDefaultCTConfig = addDefaultCTConfig;
68
63
  /**
@@ -70,27 +65,24 @@ exports.addDefaultCTConfig = addDefaultCTConfig;
70
65
  * Make sure after calling this the correct import statement is added
71
66
  * to bring in the correct mount from cypress.
72
67
  **/
73
- function addMountDefinition(cmpCommandFileContents) {
74
- var _a;
75
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
76
- if (!cmpCommandFileContents) {
77
- throw new Error('The passed in cypress component file is empty!');
78
- }
79
- const { tsquery } = yield Promise.resolve().then(() => require('@phenomnomnominal/tsquery'));
80
- const hasMountCommand = ((_a = tsquery.query(cmpCommandFileContents, 'CallExpression StringLiteral[value="mount"]')) === null || _a === void 0 ? void 0 : _a.length) > 0;
81
- if (hasMountCommand) {
82
- return cmpCommandFileContents;
83
- }
84
- const mountCommand = `Cypress.Commands.add('mount', mount);`;
85
- const updatedInterface = tsquery.replace(cmpCommandFileContents, 'InterfaceDeclaration', (node) => {
86
- return `interface ${node.name.getText()}${node.typeParameters
87
- ? `<${node.typeParameters.map((p) => p.getText()).join(', ')}>`
88
- : ''} {
68
+ async function addMountDefinition(cmpCommandFileContents) {
69
+ if (!cmpCommandFileContents) {
70
+ throw new Error('The passed in cypress component file is empty!');
71
+ }
72
+ const { tsquery } = await Promise.resolve().then(() => require('@phenomnomnominal/tsquery'));
73
+ const hasMountCommand = tsquery.query(cmpCommandFileContents, 'CallExpression StringLiteral[value="mount"]')?.length > 0;
74
+ if (hasMountCommand) {
75
+ return cmpCommandFileContents;
76
+ }
77
+ const mountCommand = `Cypress.Commands.add('mount', mount);`;
78
+ const updatedInterface = tsquery.replace(cmpCommandFileContents, 'InterfaceDeclaration', (node) => {
79
+ return `interface ${node.name.getText()}${node.typeParameters
80
+ ? `<${node.typeParameters.map((p) => p.getText()).join(', ')}>`
81
+ : ''} {
89
82
  ${node.members.map((m) => m.getText()).join('\n ')}
90
83
  mount: typeof mount;
91
84
  }`;
92
- });
93
- return `${updatedInterface}\n${mountCommand}`;
94
85
  });
86
+ return `${updatedInterface}\n${mountCommand}`;
95
87
  }
96
88
  exports.addMountDefinition = addMountDefinition;
@@ -14,15 +14,14 @@ exports.CY_FILE_MATCHER = new RegExp(/\.cy\.[tj]sx?$/);
14
14
  * i.e. <context.root>/tmp/<project-root>/ct-styles.css
15
15
  */
16
16
  function getTempTailwindPath(context) {
17
- var _a;
18
17
  if (!context.projectName) {
19
18
  throw new Error('No project name found in context');
20
19
  }
21
- const project = context === null || context === void 0 ? void 0 : context.projectGraph.nodes[context.projectName];
20
+ const project = context?.projectGraph.nodes[context.projectName];
22
21
  if (!project) {
23
22
  throw new Error(`No project found in project graph for ${context.projectName}`);
24
23
  }
25
- if ((_a = project === null || project === void 0 ? void 0 : project.data) === null || _a === void 0 ? void 0 : _a.root) {
24
+ if (project?.data?.root) {
26
25
  return (0, path_1.join)(context.root, 'tmp', project.data.root, 'ct-styles.css');
27
26
  }
28
27
  }
@@ -46,8 +45,6 @@ function isCtProjectUsingBuildProject(graph, parentProjectName, childProjectName
46
45
  }
47
46
  exports.isCtProjectUsingBuildProject = isCtProjectUsingBuildProject;
48
47
  function getProjectConfigByPath(graph, configPath) {
49
- var _a, _b, _c;
50
- var _d;
51
48
  const configFileFromWorkspaceRoot = (0, path_1.relative)(devkit_1.workspaceRoot, configPath);
52
49
  const normalizedPathFromWorkspaceRoot = (0, devkit_1.normalizePath)((0, fs_1.lstatSync)(configPath).isFile()
53
50
  ? configFileFromWorkspaceRoot.replace((0, path_1.extname)(configPath), '')
@@ -55,13 +52,14 @@ function getProjectConfigByPath(graph, configPath) {
55
52
  const projectRootMappings = (0, find_project_for_path_1.createProjectRootMappings)(graph.nodes);
56
53
  const componentTestingProjectName = (0, find_project_for_path_1.findProjectForPath)(normalizedPathFromWorkspaceRoot, projectRootMappings);
57
54
  if (!componentTestingProjectName ||
58
- !((_a = graph.nodes[componentTestingProjectName]) === null || _a === void 0 ? void 0 : _a.data)) {
55
+ !graph.nodes[componentTestingProjectName]?.data) {
59
56
  throw new Error((0, devkit_1.stripIndents) `Unable to find the project configuration that includes ${normalizedPathFromWorkspaceRoot}.
60
57
  Found project name? ${componentTestingProjectName}.
61
- Graph has data? ${!!((_b = graph.nodes[componentTestingProjectName]) === null || _b === void 0 ? void 0 : _b.data)}`);
58
+ Graph has data? ${!!graph.nodes[componentTestingProjectName]?.data}`);
62
59
  }
63
60
  // make sure name is set since it can be undefined
64
- (_c = (_d = graph.nodes[componentTestingProjectName].data).name) !== null && _c !== void 0 ? _c : (_d.name = componentTestingProjectName);
61
+ graph.nodes[componentTestingProjectName].data.name ??=
62
+ componentTestingProjectName;
65
63
  return graph.nodes[componentTestingProjectName].data;
66
64
  }
67
65
  exports.getProjectConfigByPath = getProjectConfigByPath;
@@ -8,7 +8,7 @@ function installedCypressVersion() {
8
8
  try {
9
9
  cypressPackageJson = require('cypress/package.json');
10
10
  }
11
- catch (_a) { }
11
+ catch { }
12
12
  }
13
13
  if (!cypressPackageJson) {
14
14
  return null;
@@ -1,46 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findBuildConfig = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const configuration_1 = require("nx/src/config/configuration");
7
6
  const project_graph_1 = require("nx/src/project-graph/project-graph");
8
- function findBuildConfig(tree, options) {
9
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
- try {
11
- // attempt to use the provided target
12
- const graph = yield (0, devkit_1.createProjectGraphAsync)();
13
- if (options.buildTarget) {
14
- return {
15
- target: options.buildTarget,
16
- config: findInTarget(tree, graph, options),
17
- };
18
- }
19
- // check to see if there is a valid config in the given project
20
- const selfProject = findTargetOptionsInProject(tree, graph, options.project, options);
21
- if (selfProject) {
22
- return selfProject;
23
- }
24
- // attempt to find any projects with the valid config in the graph that consumes this project
25
- return yield findInGraph(tree, graph, options);
7
+ async function findBuildConfig(tree, options) {
8
+ try {
9
+ // attempt to use the provided target
10
+ const graph = await (0, devkit_1.createProjectGraphAsync)();
11
+ if (options.buildTarget) {
12
+ return {
13
+ target: options.buildTarget,
14
+ config: findInTarget(tree, graph, options),
15
+ };
16
+ }
17
+ // check to see if there is a valid config in the given project
18
+ const selfProject = findTargetOptionsInProject(tree, graph, options.project, options);
19
+ if (selfProject) {
20
+ return selfProject;
26
21
  }
27
- catch (e) {
28
- devkit_1.logger.error(e);
29
- throw new Error((0, devkit_1.stripIndents) `Error trying to find build configuration. ${options.buildTarget
30
- ? 'Try using an app of the same framework for the --build-target.'
31
- : 'Try manually specifying the build target with the --build-target flag.'}
22
+ // attempt to find any projects with the valid config in the graph that consumes this project
23
+ return await findInGraph(tree, graph, options);
24
+ }
25
+ catch (e) {
26
+ devkit_1.logger.error(e);
27
+ throw new Error((0, devkit_1.stripIndents) `Error trying to find build configuration. ${options.buildTarget
28
+ ? 'Try using an app of the same framework for the --build-target.'
29
+ : 'Try manually specifying the build target with the --build-target flag.'}
32
30
  Provided project? ${options.project}
33
31
  Provided build target? ${options.buildTarget}
34
32
  Provided Executors? ${[...options.validExecutorNames].join(', ')}`);
35
- }
36
- });
33
+ }
37
34
  }
38
35
  exports.findBuildConfig = findBuildConfig;
39
36
  function findInTarget(tree, graph, options) {
40
- var _a, _b, _c, _d;
41
37
  const { project, target, configuration } = (0, devkit_1.parseTargetString)(options.buildTarget);
42
38
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
43
- const executorName = (_b = (_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.targets) === null || _a === void 0 ? void 0 : _a[target]) === null || _b === void 0 ? void 0 : _b.executor;
39
+ const executorName = projectConfig?.targets?.[target]?.executor;
44
40
  if (!options.validExecutorNames.has(executorName)) {
45
41
  devkit_1.logger.error((0, devkit_1.stripIndents) `NX The provided build target, ${options.buildTarget}, uses the '${executorName}' executor.
46
42
  But only the follow executors are allowed
@@ -58,7 +54,7 @@ If you do not have an app in the workspace to you can make a new app with 'nx g
58
54
  `);
59
55
  throw new Error('The provided --build-target does not use an executor in the allow list of executors defined.');
60
56
  }
61
- const foundConfig = configuration || ((_d = (_c = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.targets) === null || _c === void 0 ? void 0 : _c[target]) === null || _d === void 0 ? void 0 : _d.defaultConfiguration);
57
+ const foundConfig = configuration || projectConfig?.targets?.[target]?.defaultConfiguration;
62
58
  return (0, devkit_1.readTargetOptions)({ project, target, configuration: foundConfig }, createExecutorContext(graph, projectConfig.targets, project, target, foundConfig));
63
59
  }
64
60
  function frameworkHelperMessage(validExecutorNames, executorName) {
@@ -84,24 +80,22 @@ Try using @nx/${buildTargetFramework} instead.`;
84
80
  }
85
81
  return '';
86
82
  }
87
- function findInGraph(tree, graph, options) {
88
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
89
- const parents = findParentsOfProject(graph, options.project);
90
- const potentialTargets = [];
91
- for (const parent of parents) {
92
- const parentProject = findTargetOptionsInProject(tree, graph, parent.target, options);
93
- if (parentProject) {
94
- potentialTargets.push(parentProject);
95
- }
83
+ async function findInGraph(tree, graph, options) {
84
+ const parents = findParentsOfProject(graph, options.project);
85
+ const potentialTargets = [];
86
+ for (const parent of parents) {
87
+ const parentProject = findTargetOptionsInProject(tree, graph, parent.target, options);
88
+ if (parentProject) {
89
+ potentialTargets.push(parentProject);
96
90
  }
97
- if (potentialTargets.length > 1) {
98
- devkit_1.logger.warn((0, devkit_1.stripIndents) `Multiple potential targets found for ${options.project}. Found ${potentialTargets.length}.
91
+ }
92
+ if (potentialTargets.length > 1) {
93
+ devkit_1.logger.warn((0, devkit_1.stripIndents) `Multiple potential targets found for ${options.project}. Found ${potentialTargets.length}.
99
94
  Using ${potentialTargets[0].target}.
100
95
  To specify a different target use the --build-target flag.
101
96
  `);
102
- }
103
- return potentialTargets[0];
104
- });
97
+ }
98
+ return potentialTargets[0];
105
99
  }
106
100
  function findParentsOfProject(graph, projectName) {
107
101
  const reversedGraph = (0, devkit_1.reverse)(graph);
@@ -2,7 +2,7 @@ export declare const nxVersion: any;
2
2
  export declare const eslintPluginCypressVersion = "^2.13.4";
3
3
  export declare const typesNodeVersion = "16.11.7";
4
4
  export declare const cypressViteDevServerVersion = "^2.2.1";
5
- export declare const cypressVersion = "^12.16.0";
5
+ export declare const cypressVersion = "^13.0.0";
6
6
  export declare const cypressWebpackVersion = "^2.0.0";
7
7
  export declare const webpackHttpPluginVersion = "^5.5.0";
8
8
  export declare const viteVersion = "~4.3.9";
@@ -5,7 +5,7 @@ exports.nxVersion = require('../../package.json').version;
5
5
  exports.eslintPluginCypressVersion = '^2.13.4';
6
6
  exports.typesNodeVersion = '16.11.7';
7
7
  exports.cypressViteDevServerVersion = '^2.2.1';
8
- exports.cypressVersion = '^12.16.0';
8
+ exports.cypressVersion = '^13.0.0';
9
9
  exports.cypressWebpackVersion = '^2.0.0';
10
10
  exports.webpackHttpPluginVersion = '^5.5.0';
11
11
  exports.viteVersion = '~4.3.9';