@nx/cypress 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.
Files changed (27) hide show
  1. package/package.json +6 -6
  2. package/plugins/cypress-preset.js +15 -6
  3. package/src/executors/cypress/cypress.impl.js +179 -210
  4. package/src/generators/base-setup/base-setup.js +15 -5
  5. package/src/generators/component-configuration/component-configuration.js +42 -30
  6. package/src/generators/configuration/configuration.js +87 -70
  7. package/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.js +75 -78
  8. package/src/generators/cypress-project/cypress-project.js +76 -63
  9. package/src/generators/init/init.js +16 -18
  10. package/src/generators/migrate-to-cypress-11/conversion.util.js +22 -16
  11. package/src/generators/migrate-to-cypress-11/migrate-to-cypress-11.js +38 -35
  12. package/src/migrations/update-12-8-0/remove-typescript-plugin.js +23 -26
  13. package/src/migrations/update-14-6-1/update-cypress-configs-presets.js +79 -68
  14. package/src/migrations/update-14-7-0/update-cypress-version-if-10.js +1 -2
  15. package/src/migrations/update-15-0-0/add-cypress-inputs.js +24 -29
  16. package/src/migrations/update-15-0-0/update-cy-mount-usage.js +25 -29
  17. package/src/migrations/update-15-1-0/cypress-11.js +34 -37
  18. package/src/migrations/update-15-5-0/update-to-cypress-12.js +3 -5
  19. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
  20. package/src/migrations/update-16-2-0/update-cy-tsconfig.js +25 -24
  21. package/src/migrations/update-16-4-0/tsconfig-sourcemaps.js +52 -49
  22. package/src/plugins/preprocessor-vite.js +7 -5
  23. package/src/utils/add-linter.js +78 -81
  24. package/src/utils/config.js +54 -62
  25. package/src/utils/ct-helpers.js +6 -8
  26. package/src/utils/cypress-version.js +1 -1
  27. package/src/utils/find-target-options.js +37 -43
@@ -1,45 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateCypressConfigsPresets = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
7
6
  const tsquery_1 = require("@phenomnomnominal/tsquery");
8
7
  const cypress_version_1 = require("../../utils/cypress-version");
9
8
  const find_target_options_1 = require("../../utils/find-target-options");
10
- function updateCypressConfigsPresets(tree) {
11
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
- if ((0, cypress_version_1.installedCypressVersion)() < 10) {
13
- return;
9
+ async function updateCypressConfigsPresets(tree) {
10
+ if ((0, cypress_version_1.installedCypressVersion)() < 10) {
11
+ return;
12
+ }
13
+ const projectsWithoutDevServerTarget = new Set();
14
+ const updateTasks = [];
15
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/cypress:cypress', (options, projectName, targetName, configName) => {
16
+ if (options.cypressConfig && tree.exists(options.cypressConfig)) {
17
+ updatePreset(tree, options, targetName);
14
18
  }
15
- const projectsWithoutDevServerTarget = new Set();
16
- const updateTasks = [];
17
- (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/cypress:cypress', (options, projectName, targetName, configName) => {
18
- var _a, _b, _c, _d;
19
- if (options.cypressConfig && tree.exists(options.cypressConfig)) {
20
- updatePreset(tree, options, targetName);
21
- }
22
- const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, projectName);
23
- const testingType = options.testingType ||
24
- ((_b = (_a = projectConfig.targets[targetName]) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.testingType);
25
- const devServerTarget = options.devServerTarget ||
26
- ((_d = (_c = projectConfig.targets[targetName]) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.devServerTarget);
27
- if (!devServerTarget && testingType === 'component') {
28
- updateTasks.push(addBuildTargetToConfig(tree, projectName, targetName, configName).then((didUpdate) => {
29
- if (!didUpdate) {
30
- projectsWithoutDevServerTarget.add(projectName);
31
- }
32
- }));
33
- }
34
- });
35
- if (updateTasks.length > 0) {
36
- cacheComponentTestTarget(tree);
19
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, projectName);
20
+ const testingType = options.testingType ||
21
+ projectConfig.targets[targetName]?.options?.testingType;
22
+ const devServerTarget = options.devServerTarget ||
23
+ projectConfig.targets[targetName]?.options?.devServerTarget;
24
+ if (!devServerTarget && testingType === 'component') {
25
+ updateTasks.push(addBuildTargetToConfig(tree, projectName, targetName, configName).then((didUpdate) => {
26
+ if (!didUpdate) {
27
+ projectsWithoutDevServerTarget.add(projectName);
28
+ }
29
+ }));
37
30
  }
38
- yield Promise.all(updateTasks);
39
- if (projectsWithoutDevServerTarget.size > 0) {
40
- devkit_1.logger.warn(`Unable to find a build target to add to the component testing target in the following projects:`);
41
- devkit_1.logger.warn(`- ${Array.from(projectsWithoutDevServerTarget).join('\n- ')}`);
42
- devkit_1.logger.warn((0, devkit_1.stripIndents) `
31
+ });
32
+ if (updateTasks.length > 0) {
33
+ cacheComponentTestTarget(tree);
34
+ }
35
+ await Promise.all(updateTasks);
36
+ if (projectsWithoutDevServerTarget.size > 0) {
37
+ devkit_1.logger.warn(`Unable to find a build target to add to the component testing target in the following projects:`);
38
+ devkit_1.logger.warn(`- ${Array.from(projectsWithoutDevServerTarget).join('\n- ')}`);
39
+ devkit_1.logger.warn((0, devkit_1.stripIndents) `
43
40
  You can manually add the 'devServerTarget' option to the
44
41
  component testing target to specify the build target to use.
45
42
  The build configuration should be using @nrwl/web:webpack as the executor.
@@ -47,8 +44,7 @@ Usually this is a React app in your workspace.
47
44
  Component testing will fallback to a default configuration if one isn't provided,
48
45
  but might require modifications if your projects are more complex.
49
46
  `);
50
- }
51
- });
47
+ }
52
48
  }
53
49
  exports.updateCypressConfigsPresets = updateCypressConfigsPresets;
54
50
  function updatePreset(tree, options, targetName) {
@@ -70,42 +66,57 @@ function updatePreset(tree, options, targetName) {
70
66
  });
71
67
  tree.write(options.cypressConfig, contents);
72
68
  }
73
- function addBuildTargetToConfig(tree, projectName, targetName, configName) {
74
- var _a, _b;
75
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
76
- const projectWithBuild = yield (0, find_target_options_1.findBuildConfig)(tree, {
77
- project: projectName,
78
- validExecutorNames: new Set(['@nrwl/web:webpack']),
79
- skipGetOptions: true,
80
- });
81
- // didn't find the config so can't update. consumer should collect list of them and display a warning at the end
82
- // no reason to fail since the preset will fallback to a default config so should still keep working.
83
- if (!(projectWithBuild === null || projectWithBuild === void 0 ? void 0 : projectWithBuild.target)) {
84
- return false;
85
- }
86
- const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, projectName);
87
- // if using a custom config and the devServerTarget default args
88
- // has a different target, then add it to the custom target config
89
- // otherwise add it to the default options
90
- if (configName &&
91
- projectWithBuild.target !==
92
- ((_b = (_a = projectConfig.targets[targetName]) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.devServerTarget)) {
93
- projectConfig.targets[targetName].configurations[configName] = Object.assign(Object.assign({}, projectConfig.targets[targetName].configurations[configName]), { devServerTarget: projectWithBuild.target, skipServe: true });
94
- }
95
- else {
96
- projectConfig.targets[targetName].options = Object.assign(Object.assign({}, projectConfig.targets[targetName].options), { devServerTarget: projectWithBuild.target, skipServe: true });
97
- }
98
- (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfig);
99
- return true;
69
+ async function addBuildTargetToConfig(tree, projectName, targetName, configName) {
70
+ const projectWithBuild = await (0, find_target_options_1.findBuildConfig)(tree, {
71
+ project: projectName,
72
+ validExecutorNames: new Set(['@nrwl/web:webpack']),
73
+ skipGetOptions: true,
100
74
  });
75
+ // didn't find the config so can't update. consumer should collect list of them and display a warning at the end
76
+ // no reason to fail since the preset will fallback to a default config so should still keep working.
77
+ if (!projectWithBuild?.target) {
78
+ return false;
79
+ }
80
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, projectName);
81
+ // if using a custom config and the devServerTarget default args
82
+ // has a different target, then add it to the custom target config
83
+ // otherwise add it to the default options
84
+ if (configName &&
85
+ projectWithBuild.target !==
86
+ projectConfig.targets[targetName]?.options?.devServerTarget) {
87
+ projectConfig.targets[targetName].configurations[configName] = {
88
+ ...projectConfig.targets[targetName].configurations[configName],
89
+ devServerTarget: projectWithBuild.target,
90
+ skipServe: true,
91
+ };
92
+ }
93
+ else {
94
+ projectConfig.targets[targetName].options = {
95
+ ...projectConfig.targets[targetName].options,
96
+ devServerTarget: projectWithBuild.target,
97
+ skipServe: true,
98
+ };
99
+ }
100
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfig);
101
+ return true;
101
102
  }
102
103
  function cacheComponentTestTarget(tree) {
103
- (0, devkit_1.updateJson)(tree, 'nx.json', (json) => {
104
- var _a, _b, _c, _d, _e, _f, _g;
105
- return (Object.assign(Object.assign({}, json), { tasksRunnerOptions: Object.assign(Object.assign({}, json.tasksRunnerOptions), { default: Object.assign(Object.assign({}, (_a = json.tasksRunnerOptions) === null || _a === void 0 ? void 0 : _a.default), { options: Object.assign(Object.assign({}, (_c = (_b = json.tasksRunnerOptions) === null || _b === void 0 ? void 0 : _b.default) === null || _c === void 0 ? void 0 : _c.options), { cacheableOperations: Array.from(new Set([
106
- ...((_g = (_f = (_e = (_d = json.tasksRunnerOptions) === null || _d === void 0 ? void 0 : _d.default) === null || _e === void 0 ? void 0 : _e.options) === null || _f === void 0 ? void 0 : _f.cacheableOperations) !== null && _g !== void 0 ? _g : []),
107
- 'component-test',
108
- ])) }) }) }) }));
109
- });
104
+ (0, devkit_1.updateJson)(tree, 'nx.json', (json) => ({
105
+ ...json,
106
+ tasksRunnerOptions: {
107
+ ...json.tasksRunnerOptions,
108
+ default: {
109
+ ...json.tasksRunnerOptions?.default,
110
+ options: {
111
+ ...json.tasksRunnerOptions?.default?.options,
112
+ cacheableOperations: Array.from(new Set([
113
+ ...(json.tasksRunnerOptions?.default?.options
114
+ ?.cacheableOperations ?? []),
115
+ 'component-test',
116
+ ])),
117
+ },
118
+ },
119
+ },
120
+ }));
110
121
  }
111
122
  exports.default = updateCypressConfigsPresets;
@@ -6,8 +6,7 @@ const devkit_1 = require("@nx/devkit");
6
6
  const semver_1 = require("@nx/devkit/src/utils/semver");
7
7
  const semver_2 = require("semver");
8
8
  function updateCypressVersionIf10(tree) {
9
- var _a;
10
- const installedVersion = (_a = (0, devkit_1.readJson)(tree, 'package.json').devDependencies) === null || _a === void 0 ? void 0 : _a['cypress'];
9
+ const installedVersion = (0, devkit_1.readJson)(tree, 'package.json').devDependencies?.['cypress'];
11
10
  if (!installedVersion) {
12
11
  return;
13
12
  }
@@ -1,37 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
- function default_1(tree) {
7
- var _a, _b, _c, _d;
8
- var _e;
9
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
- const nxJson = (0, devkit_1.readNxJson)(tree);
11
- const { cypressTargets, hasComponentTesting } = getCypressTargetNames(tree);
12
- const hasProductionFileset = !!((_a = nxJson.namedInputs) === null || _a === void 0 ? void 0 : _a.production);
13
- if (hasComponentTesting && hasProductionFileset && cypressTargets.size > 0) {
14
- const productionFileset = new Set(nxJson.namedInputs.production);
15
- for (const exclusion of [
16
- '!{projectRoot}/cypress/**/*',
17
- '!{projectRoot}/**/*.cy.[jt]s?(x)',
18
- '!{projectRoot}/cypress.config.[jt]s',
19
- ]) {
20
- productionFileset.add(exclusion);
21
- }
22
- nxJson.namedInputs.production = Array.from(productionFileset);
5
+ async function default_1(tree) {
6
+ const nxJson = (0, devkit_1.readNxJson)(tree);
7
+ const { cypressTargets, hasComponentTesting } = getCypressTargetNames(tree);
8
+ const hasProductionFileset = !!nxJson.namedInputs?.production;
9
+ if (hasComponentTesting && hasProductionFileset && cypressTargets.size > 0) {
10
+ const productionFileset = new Set(nxJson.namedInputs.production);
11
+ for (const exclusion of [
12
+ '!{projectRoot}/cypress/**/*',
13
+ '!{projectRoot}/**/*.cy.[jt]s?(x)',
14
+ '!{projectRoot}/cypress.config.[jt]s',
15
+ ]) {
16
+ productionFileset.add(exclusion);
23
17
  }
24
- for (const targetName of cypressTargets) {
25
- (_b = nxJson.targetDefaults) !== null && _b !== void 0 ? _b : (nxJson.targetDefaults = {});
26
- const cypressTargetDefaults = ((_c = (_e = nxJson.targetDefaults)[targetName]) !== null && _c !== void 0 ? _c : (_e[targetName] = {}));
27
- (_d = cypressTargetDefaults.inputs) !== null && _d !== void 0 ? _d : (cypressTargetDefaults.inputs = [
28
- 'default',
29
- hasProductionFileset ? '^production' : '^default',
30
- ]);
31
- }
32
- (0, devkit_1.updateNxJson)(tree, nxJson);
33
- yield (0, devkit_1.formatFiles)(tree);
34
- });
18
+ nxJson.namedInputs.production = Array.from(productionFileset);
19
+ }
20
+ for (const targetName of cypressTargets) {
21
+ nxJson.targetDefaults ??= {};
22
+ const cypressTargetDefaults = (nxJson.targetDefaults[targetName] ??= {});
23
+ cypressTargetDefaults.inputs ??= [
24
+ 'default',
25
+ hasProductionFileset ? '^production' : '^default',
26
+ ];
27
+ }
28
+ (0, devkit_1.updateNxJson)(tree, nxJson);
29
+ await (0, devkit_1.formatFiles)(tree);
35
30
  }
36
31
  exports.default = default_1;
37
32
  function getCypressTargetNames(tree) {
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateCyFile = exports.addMountCommand = exports.updateCyMountUsage = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const ct_helpers_1 = require("../../utils/ct-helpers");
6
5
  const cypress_version_1 = require("../../utils/cypress-version");
7
6
  const devkit_1 = require("@nx/devkit");
@@ -9,35 +8,33 @@ const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-opt
9
8
  const semver_1 = require("@nx/devkit/src/utils/semver");
10
9
  const tsquery_1 = require("@phenomnomnominal/tsquery");
11
10
  const semver_2 = require("semver");
12
- function updateCyMountUsage(tree) {
13
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
- if ((0, cypress_version_1.installedCypressVersion)() < 10) {
11
+ async function updateCyMountUsage(tree) {
12
+ if ((0, cypress_version_1.installedCypressVersion)() < 10) {
13
+ return;
14
+ }
15
+ const projects = (0, devkit_1.getProjects)(tree);
16
+ const graph = await (0, devkit_1.createProjectGraphAsync)();
17
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/cypress:cypress', (options, projectName) => {
18
+ if (options.testingType !== 'component' || !options.devServerTarget) {
15
19
  return;
16
20
  }
17
- const projects = (0, devkit_1.getProjects)(tree);
18
- const graph = yield (0, devkit_1.createProjectGraphAsync)();
19
- (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/cypress:cypress', (options, projectName) => {
20
- if (options.testingType !== 'component' || !options.devServerTarget) {
21
- return;
22
- }
23
- const parsed = (0, devkit_1.parseTargetString)(options.devServerTarget, graph);
24
- if (!(parsed === null || parsed === void 0 ? void 0 : parsed.project) || !(parsed === null || parsed === void 0 ? void 0 : parsed.target)) {
25
- return;
21
+ const parsed = (0, devkit_1.parseTargetString)(options.devServerTarget, graph);
22
+ if (!parsed?.project || !parsed?.target) {
23
+ return;
24
+ }
25
+ const buildProjectConfig = projects.get(parsed.project);
26
+ const framework = getFramework(tree, parsed.configuration
27
+ ? buildProjectConfig.targets[parsed.target].configurations[parsed.configuration]
28
+ : buildProjectConfig.targets[parsed.target]);
29
+ const ctProjectConfig = projects.get(projectName);
30
+ addMountCommand(tree, ctProjectConfig.root, framework);
31
+ (0, devkit_1.visitNotIgnoredFiles)(tree, ctProjectConfig.sourceRoot, (filePath) => {
32
+ if (ct_helpers_1.CY_FILE_MATCHER.test(filePath)) {
33
+ updateCyFile(tree, filePath, framework);
26
34
  }
27
- const buildProjectConfig = projects.get(parsed.project);
28
- const framework = getFramework(tree, parsed.configuration
29
- ? buildProjectConfig.targets[parsed.target].configurations[parsed.configuration]
30
- : buildProjectConfig.targets[parsed.target]);
31
- const ctProjectConfig = projects.get(projectName);
32
- addMountCommand(tree, ctProjectConfig.root, framework);
33
- (0, devkit_1.visitNotIgnoredFiles)(tree, ctProjectConfig.sourceRoot, (filePath) => {
34
- if (ct_helpers_1.CY_FILE_MATCHER.test(filePath)) {
35
- updateCyFile(tree, filePath, framework);
36
- }
37
- });
38
35
  });
39
- yield (0, devkit_1.formatFiles)(tree);
40
36
  });
37
+ await (0, devkit_1.formatFiles)(tree);
41
38
  }
42
39
  exports.updateCyMountUsage = updateCyMountUsage;
43
40
  function addMountCommand(tree, projectRoot, framework) {
@@ -47,7 +44,7 @@ function addMountCommand(tree, projectRoot, framework) {
47
44
  }
48
45
  const commandFile = tree.read(commandFilePath, 'utf-8');
49
46
  const mountCommand = tsquery_1.tsquery.query(commandFile, 'CallExpression:has(StringLiteral[value="mount"]) PropertyAccessExpression:has(Identifier[name="add"])');
50
- if ((mountCommand === null || mountCommand === void 0 ? void 0 : mountCommand.length) > 0) {
47
+ if (mountCommand?.length > 0) {
51
48
  return;
52
49
  }
53
50
  const existingCommands = tsquery_1.tsquery.query(commandFile, 'InterfaceDeclaration:has(Identifier[name="Chainable"]) > MethodSignature, InterfaceDeclaration:has(Identifier[name="Chainable"]) > PropertySignature');
@@ -74,7 +71,7 @@ function addMountCommand(tree, projectRoot, framework) {
74
71
  * or if the node is the global declaration, then add it,
75
72
  * but not to the cypress module declaration inside the global declaration
76
73
  */
77
- if ((isGlobalDeclaration === null || isGlobalDeclaration === void 0 ? void 0 : isGlobalDeclaration.length) === 0 ||
74
+ if (isGlobalDeclaration?.length === 0 ||
78
75
  node.name.getText() === 'global') {
79
76
  return newModuleDelcaration;
80
77
  }
@@ -84,13 +81,12 @@ function addMountCommand(tree, projectRoot, framework) {
84
81
  }
85
82
  exports.addMountCommand = addMountCommand;
86
83
  function getFramework(tree, target) {
87
- var _a;
88
84
  if (target.executor === '@nrwl/angular:webpack-browser' ||
89
85
  target.executor === '@angular-devkit/build-angular:browser') {
90
86
  return 'angular';
91
87
  }
92
88
  const pkgJson = (0, devkit_1.readJson)(tree, 'package.json');
93
- const reactDomVersion = (_a = pkgJson === null || pkgJson === void 0 ? void 0 : pkgJson.dependencies) === null || _a === void 0 ? void 0 : _a['react-dom'];
89
+ const reactDomVersion = pkgJson?.dependencies?.['react-dom'];
94
90
  const hasReact18 = reactDomVersion &&
95
91
  (0, semver_2.gte)((0, semver_1.checkAndCleanWithSemver)('react-dom', reactDomVersion), '18.0.0');
96
92
  if (hasReact18) {
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateProviderUsage = exports.updateUnmountUsage = exports.updateMountHookUsage = exports.updateToCypress11 = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const ct_helpers_1 = require("../../utils/ct-helpers");
6
5
  const devkit_1 = require("@nx/devkit");
7
6
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
@@ -10,43 +9,41 @@ const path_1 = require("path");
10
9
  const ts = require("typescript");
11
10
  const cypress_version_1 = require("../../utils/cypress-version");
12
11
  const versions_1 = require("../../utils/versions");
13
- function updateToCypress11(tree) {
14
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
15
- const installedVersion = (0, cypress_version_1.installedCypressVersion)();
16
- if (installedVersion < 10) {
12
+ async function updateToCypress11(tree) {
13
+ const installedVersion = (0, cypress_version_1.installedCypressVersion)();
14
+ if (installedVersion < 10) {
15
+ return;
16
+ }
17
+ const projects = (0, devkit_1.getProjects)(tree);
18
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/cypress:cypress', (options, projectName, targetName, configurationName) => {
19
+ if (options.testingType !== 'component' ||
20
+ !(options.cypressConfig && tree.exists(options.cypressConfig))) {
17
21
  return;
18
22
  }
19
- const projects = (0, devkit_1.getProjects)(tree);
20
- (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/cypress:cypress', (options, projectName, targetName, configurationName) => {
21
- if (options.testingType !== 'component' ||
22
- !(options.cypressConfig && tree.exists(options.cypressConfig))) {
23
+ const projectConfig = projects.get(projectName);
24
+ const commandsFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'support', 'commands.ts');
25
+ const framework = getFramework(tree.exists(commandsFile)
26
+ ? tree.read(commandsFile, 'utf-8')
27
+ : tree.read(options.cypressConfig, 'utf-8'));
28
+ (0, devkit_1.visitNotIgnoredFiles)(tree, projectConfig.sourceRoot, (filePath) => {
29
+ if (!ct_helpers_1.CY_FILE_MATCHER.test(filePath)) {
23
30
  return;
24
31
  }
25
- const projectConfig = projects.get(projectName);
26
- const commandsFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'support', 'commands.ts');
27
- const framework = getFramework(tree.exists(commandsFile)
28
- ? tree.read(commandsFile, 'utf-8')
29
- : tree.read(options.cypressConfig, 'utf-8'));
30
- (0, devkit_1.visitNotIgnoredFiles)(tree, projectConfig.sourceRoot, (filePath) => {
31
- if (!ct_helpers_1.CY_FILE_MATCHER.test(filePath)) {
32
- return;
33
- }
34
- const frameworkFromFile = getFramework(tree.read(filePath, 'utf-8'));
35
- if (framework === 'react' || frameworkFromFile === 'react') {
36
- updateUnmountUsage(tree, filePath);
37
- updateMountHookUsage(tree, filePath);
38
- }
39
- if (framework === 'angular' || frameworkFromFile === 'angular') {
40
- updateProviderUsage(tree, filePath);
41
- }
42
- });
32
+ const frameworkFromFile = getFramework(tree.read(filePath, 'utf-8'));
33
+ if (framework === 'react' || frameworkFromFile === 'react') {
34
+ updateUnmountUsage(tree, filePath);
35
+ updateMountHookUsage(tree, filePath);
36
+ }
37
+ if (framework === 'angular' || frameworkFromFile === 'angular') {
38
+ updateProviderUsage(tree, filePath);
39
+ }
43
40
  });
44
- const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { cypress: versions_1.cypressVersion });
45
- yield (0, devkit_1.formatFiles)(tree);
46
- return () => {
47
- installTask();
48
- };
49
41
  });
42
+ const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { cypress: versions_1.cypressVersion });
43
+ await (0, devkit_1.formatFiles)(tree);
44
+ return () => {
45
+ installTask();
46
+ };
50
47
  }
51
48
  exports.updateToCypress11 = updateToCypress11;
52
49
  function updateMountHookUsage(tree, filePath) {
@@ -78,16 +75,16 @@ ${reactDomImport}`;
78
75
  }
79
76
  exports.updateUnmountUsage = updateUnmountUsage;
80
77
  function updateProviderUsage(tree, filePath) {
81
- var _a;
82
78
  const originalContents = tree.read(filePath, 'utf-8');
83
- const isTestBedImported = ((_a = tsquery_1.tsquery.query(originalContents, ':matches(ImportDeclaration, VariableStatement):has(Identifier[name="TestBed"]):has(StringLiteral[value="@angular/core/testing"])')) === null || _a === void 0 ? void 0 : _a.length) > 0;
79
+ const isTestBedImported = tsquery_1.tsquery.query(originalContents, ':matches(ImportDeclaration, VariableStatement):has(Identifier[name="TestBed"]):has(StringLiteral[value="@angular/core/testing"])')?.length > 0;
84
80
  let updatedProviders = tsquery_1.tsquery.replace(originalContents, 'CallExpression:has(PropertyAccessExpression:has(Identifier[name="mount"]))', (node) => {
85
- var _a, _b, _c, _d;
86
81
  const expressionName = node.expression.getText();
87
- if (expressionName === 'cy.mount' && ((_a = node === null || node === void 0 ? void 0 : node.arguments) === null || _a === void 0 ? void 0 : _a.length) > 1) {
82
+ if (expressionName === 'cy.mount' && node?.arguments?.length > 1) {
88
83
  const component = node.arguments[0].getText();
89
84
  if (ts.isObjectLiteralExpression(node.arguments[1])) {
90
- const providers = (_d = (_c = (_b = node.arguments[1]) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c.find((p) => { var _a; return ((_a = p.name) === null || _a === void 0 ? void 0 : _a.getText()) === 'providers'; })) === null || _d === void 0 ? void 0 : _d.getText();
85
+ const providers = node.arguments[1]?.properties
86
+ ?.find((p) => p.name?.getText() === 'providers')
87
+ ?.getText();
91
88
  const noProviders = tsquery_1.tsquery.replace(node.getText(), 'PropertyAssignment:has(Identifier[name="providers"])', (n) => {
92
89
  // set it to undefined so we don't run into a hanging comma causing invalid syntax
93
90
  return 'providers: undefined';
@@ -125,16 +125,15 @@ exports.shouldUseCySession = shouldUseCySession;
125
125
  function shouldNotUseCyInShouldCB(tree, filePath) {
126
126
  const content = tree.read(filePath, 'utf-8');
127
127
  const markedNestedCyCommands = tsquery_1.tsquery.replace(content, 'CallExpression > PropertyAccessExpression:has(Identifier[name="cy"]):has(Identifier[name="should"])', (node) => {
128
- var _a, _b;
129
128
  if ((0, helpers_1.isAlreadyCommented)(node) ||
130
129
  (node.parent && !(0, typescript_1.isCallExpression)(node.parent))) {
131
130
  return;
132
131
  }
133
132
  const parentExpression = node.parent;
134
- if (((_a = parentExpression === null || parentExpression === void 0 ? void 0 : parentExpression.arguments) === null || _a === void 0 ? void 0 : _a[0]) &&
133
+ if (parentExpression?.arguments?.[0] &&
135
134
  ((0, typescript_1.isArrowFunction)(parentExpression.arguments[0]) ||
136
135
  (0, typescript_1.isFunctionExpression)(parentExpression.arguments[0]))) {
137
- const isUsingNestedCyCommand = ((_b = tsquery_1.tsquery.query(parentExpression.arguments[0], 'CallExpression > PropertyAccessExpression:has(Identifier[name="cy"])')) === null || _b === void 0 ? void 0 : _b.length) > 0;
136
+ const isUsingNestedCyCommand = tsquery_1.tsquery.query(parentExpression.arguments[0], 'CallExpression > PropertyAccessExpression:has(Identifier[name="cy"])')?.length > 0;
138
137
  if (isUsingNestedCyCommand) {
139
138
  return `/**
140
139
  * TODO(@nrwl/cypress): Nesting Cypress commands in a should assertion now throws.
@@ -155,7 +154,6 @@ exports.shouldNotUseCyInShouldCB = shouldNotUseCyInShouldCB;
155
154
  function shouldNotOverrideCommands(tree, filePath) {
156
155
  const content = tree.read(filePath, 'utf-8');
157
156
  const markedOverrideUsage = tsquery_1.tsquery.replace(content, 'PropertyAccessExpression:has(Identifier[name="overwrite"]):has(Identifier[name="Cypress"])', (node) => {
158
- var _a, _b;
159
157
  if ((0, helpers_1.isAlreadyCommented)(node)) {
160
158
  return;
161
159
  }
@@ -164,7 +162,7 @@ function shouldNotOverrideCommands(tree, filePath) {
164
162
  if (expression === 'Cypress.Commands') {
165
163
  // get value.
166
164
  const overwriteExpression = node.parent;
167
- const command = (_b = (_a = overwriteExpression.arguments) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.text; // need string without quotes
165
+ const command = overwriteExpression.arguments?.[0]?.text; // need string without quotes
168
166
  if (helpers_1.BANNED_COMMANDS.includes(command)) {
169
167
  // overwrite
170
168
  return `/**
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
6
- function replacePackage(tree) {
7
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
8
- yield (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/cypress', '@nx/cypress');
9
- yield (0, devkit_1.formatFiles)(tree);
10
- });
5
+ async function replacePackage(tree) {
6
+ await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/cypress', '@nx/cypress');
7
+ await (0, devkit_1.formatFiles)(tree);
11
8
  }
12
9
  exports.default = replacePackage;
@@ -1,35 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeCyTsConfigNames = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
7
- function normalizeCyTsConfigNames(tree) {
8
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
- const projects = (0, devkit_1.getProjects)(tree);
10
- (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/cypress:cypress', (_, projectName) => {
11
- const projectConfig = projects.get(projectName);
12
- const newTsConfigPath = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'tsconfig.json');
13
- // if there is already a tsconfig.json in the cypress folder, then assume things are setup already
14
- if (!tree.exists(newTsConfigPath)) {
15
- moveProjectTsCyConfig(tree, projectConfig, newTsConfigPath);
16
- moveCyDirTsCyConfig(tree, projectConfig, newTsConfigPath);
17
- updateCyDirTsConfigReferences(tree, projectConfig);
18
- }
19
- });
20
- yield (0, devkit_1.formatFiles)(tree);
6
+ async function normalizeCyTsConfigNames(tree) {
7
+ const projects = (0, devkit_1.getProjects)(tree);
8
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/cypress:cypress', (_, projectName) => {
9
+ const projectConfig = projects.get(projectName);
10
+ const newTsConfigPath = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'tsconfig.json');
11
+ // if there is already a tsconfig.json in the cypress folder, then assume things are setup already
12
+ if (!tree.exists(newTsConfigPath)) {
13
+ moveProjectTsCyConfig(tree, projectConfig, newTsConfigPath);
14
+ moveCyDirTsCyConfig(tree, projectConfig, newTsConfigPath);
15
+ updateCyDirTsConfigReferences(tree, projectConfig);
16
+ }
21
17
  });
18
+ await (0, devkit_1.formatFiles)(tree);
22
19
  }
23
20
  exports.normalizeCyTsConfigNames = normalizeCyTsConfigNames;
24
21
  function moveProjectTsCyConfig(tree, projectConfig, newTsConfigPath) {
25
22
  if (tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.cy.json'))) {
26
23
  tree.rename((0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.cy.json'), newTsConfigPath);
27
24
  (0, devkit_1.updateJson)(tree, newTsConfigPath, (json) => {
28
- var _a, _b;
29
25
  json.extends = '../tsconfig.json';
30
- (_a = json.compilerOptions) !== null && _a !== void 0 ? _a : (json.compilerOptions = {});
31
- json.compilerOptions = Object.assign(Object.assign({}, json.compilerOptions), { sourceMap: false, outDir: '../../../dist/out-tsc' });
32
- (_b = json.include) !== null && _b !== void 0 ? _b : (json.include = []);
26
+ json.compilerOptions ??= {};
27
+ json.compilerOptions = {
28
+ ...json.compilerOptions,
29
+ sourceMap: false,
30
+ outDir: '../../../dist/out-tsc',
31
+ };
32
+ json.include ??= [];
33
33
  json.include = json.include.map((p) => {
34
34
  if (p.startsWith('cypress/')) {
35
35
  return p.replace('cypress/', '');
@@ -44,9 +44,11 @@ function moveCyDirTsCyConfig(tree, projectConfig, newTsConfigPath) {
44
44
  if (tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'tsconfig.cy.json'))) {
45
45
  tree.rename((0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress', 'tsconfig.cy.json'), newTsConfigPath);
46
46
  (0, devkit_1.updateJson)(tree, newTsConfigPath, (json) => {
47
- var _a;
48
- (_a = json.compilerOptions) !== null && _a !== void 0 ? _a : (json.compilerOptions = {});
49
- json.compilerOptions = Object.assign(Object.assign({}, json.compilerOptions), { sourceMap: false });
47
+ json.compilerOptions ??= {};
48
+ json.compilerOptions = {
49
+ ...json.compilerOptions,
50
+ sourceMap: false,
51
+ };
50
52
  return json;
51
53
  });
52
54
  }
@@ -56,8 +58,7 @@ function updateCyDirTsConfigReferences(tree, projectConfig) {
56
58
  return;
57
59
  }
58
60
  (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.json'), (json) => {
59
- var _a;
60
- (_a = json.references) !== null && _a !== void 0 ? _a : (json.references = []);
61
+ json.references ??= [];
61
62
  if (!json.references) {
62
63
  return json;
63
64
  }