@nx/cypress 16.8.0-beta.4 → 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,59 +1,62 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fixLegacyCypressTsconfig = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
5
  const devkit_1 = require("@nx/devkit");
7
6
  const path_1 = require("path");
8
- function fixLegacyCypressTsconfig(tree) {
9
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
- const projects = (0, devkit_1.getProjects)(tree);
11
- (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/cypress:cypress', (options, projectName, targetName, configName) => {
12
- var _a, _b, _c;
13
- const projectConfig = projects.get(projectName);
14
- if (options.testingType !== 'e2e' &&
15
- ((_b = (_a = projectConfig.targets[targetName]) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.testingType) !== 'e2e') {
16
- return;
17
- }
18
- const tsconfigToRemove = (_c = options.tsConfig) !== null && _c !== void 0 ? _c : (0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.e2e.json');
19
- const projectLevelConfigPath = (0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.json');
20
- if (!tree.exists(projectLevelConfigPath) ||
21
- !tree.exists(tsconfigToRemove)) {
22
- return;
23
- }
24
- if (tsconfigToRemove === projectLevelConfigPath) {
25
- (0, devkit_1.updateJson)(tree, projectLevelConfigPath, (json) => {
26
- json.compilerOptions = Object.assign({ sourceMap: false }, json.compilerOptions);
27
- return json;
28
- });
29
- }
30
- else {
31
- const e2eConfig = (0, devkit_1.readJson)(tree, tsconfigToRemove);
32
- (0, devkit_1.updateJson)(tree, projectLevelConfigPath, (json) => {
33
- var _a, _b, _c, _d, _e, _f, _g;
34
- json.compilerOptions = Object.assign(Object.assign({ sourceMap: false }, json.compilerOptions), e2eConfig.compilerOptions);
35
- json.files = Array.from(new Set([...((_a = json.files) !== null && _a !== void 0 ? _a : []), ...((_b = e2eConfig.files) !== null && _b !== void 0 ? _b : [])]));
36
- json.include = Array.from(new Set([...((_c = json.include) !== null && _c !== void 0 ? _c : []), ...((_d = e2eConfig.include) !== null && _d !== void 0 ? _d : [])]));
37
- json.exclude = Array.from(new Set([...((_e = json.exclude) !== null && _e !== void 0 ? _e : []), ...((_f = e2eConfig.exclude) !== null && _f !== void 0 ? _f : [])]));
38
- // these paths will always be 'unix style'
39
- // and on windows relative will not work on these paths
40
- const tsConfigFromProjRoot = path_1.posix.relative(projectConfig.root, tsconfigToRemove);
41
- json.references = ((_g = json.references) !== null && _g !== void 0 ? _g : []).filter(({ path }) => !path.includes(tsConfigFromProjRoot));
42
- return json;
43
- });
44
- tree.delete(tsconfigToRemove);
45
- }
46
- if (configName) {
47
- delete projectConfig.targets[targetName].configurations[configName]
48
- .tsConfig;
49
- }
50
- else {
51
- delete projectConfig.targets[targetName].options.tsConfig;
52
- }
53
- (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfig);
54
- });
55
- yield (0, devkit_1.formatFiles)(tree);
7
+ async function fixLegacyCypressTsconfig(tree) {
8
+ const projects = (0, devkit_1.getProjects)(tree);
9
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/cypress:cypress', (options, projectName, targetName, configName) => {
10
+ const projectConfig = projects.get(projectName);
11
+ if (options.testingType !== 'e2e' &&
12
+ projectConfig.targets[targetName]?.options?.testingType !== 'e2e') {
13
+ return;
14
+ }
15
+ const tsconfigToRemove = options.tsConfig ??
16
+ (0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.e2e.json');
17
+ const projectLevelConfigPath = (0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.json');
18
+ if (!tree.exists(projectLevelConfigPath) ||
19
+ !tree.exists(tsconfigToRemove)) {
20
+ return;
21
+ }
22
+ if (tsconfigToRemove === projectLevelConfigPath) {
23
+ (0, devkit_1.updateJson)(tree, projectLevelConfigPath, (json) => {
24
+ json.compilerOptions = {
25
+ sourceMap: false,
26
+ ...json.compilerOptions,
27
+ };
28
+ return json;
29
+ });
30
+ }
31
+ else {
32
+ const e2eConfig = (0, devkit_1.readJson)(tree, tsconfigToRemove);
33
+ (0, devkit_1.updateJson)(tree, projectLevelConfigPath, (json) => {
34
+ json.compilerOptions = {
35
+ sourceMap: false,
36
+ ...json.compilerOptions,
37
+ ...e2eConfig.compilerOptions,
38
+ };
39
+ json.files = Array.from(new Set([...(json.files ?? []), ...(e2eConfig.files ?? [])]));
40
+ json.include = Array.from(new Set([...(json.include ?? []), ...(e2eConfig.include ?? [])]));
41
+ json.exclude = Array.from(new Set([...(json.exclude ?? []), ...(e2eConfig.exclude ?? [])]));
42
+ // these paths will always be 'unix style'
43
+ // and on windows relative will not work on these paths
44
+ const tsConfigFromProjRoot = path_1.posix.relative(projectConfig.root, tsconfigToRemove);
45
+ json.references = (json.references ?? []).filter(({ path }) => !path.includes(tsConfigFromProjRoot));
46
+ return json;
47
+ });
48
+ tree.delete(tsconfigToRemove);
49
+ }
50
+ if (configName) {
51
+ delete projectConfig.targets[targetName].configurations[configName]
52
+ .tsConfig;
53
+ }
54
+ else {
55
+ delete projectConfig.targets[targetName].options.tsConfig;
56
+ }
57
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfig);
56
58
  });
59
+ await (0, devkit_1.formatFiles)(tree);
57
60
  }
58
61
  exports.fixLegacyCypressTsconfig = fixLegacyCypressTsconfig;
59
62
  exports.default = fixLegacyCypressTsconfig;
@@ -24,7 +24,6 @@
24
24
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
25
  **/
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
- const tslib_1 = require("tslib");
28
27
  const path_1 = require("path");
29
28
  const cache = new Map();
30
29
  /**
@@ -33,7 +32,7 @@ const cache = new Map();
33
32
  * Instead, use the nxE2EPreset(__filename, { bundler: 'vite' }) function instead.
34
33
  */
35
34
  function vitePreprocessor(userConfigPath) {
36
- return (file) => tslib_1.__awaiter(this, void 0, void 0, function* () {
35
+ return async (file) => {
37
36
  const { outputPath, filePath, shouldWatch } = file;
38
37
  if (cache.has(filePath)) {
39
38
  return cache.get(filePath);
@@ -61,8 +60,11 @@ function vitePreprocessor(userConfigPath) {
61
60
  },
62
61
  };
63
62
  cache.set(filePath, outputPath);
64
- const { build } = yield Function('return import("vite")')();
65
- const watcher = (yield build(Object.assign({ configFile: userConfigPath }, defaultConfig)));
63
+ const { build } = await Function('return import("vite")')();
64
+ const watcher = (await build({
65
+ configFile: userConfigPath,
66
+ ...defaultConfig,
67
+ }));
66
68
  return new Promise((resolve, reject) => {
67
69
  if (shouldWatch && isWatcher(watcher)) {
68
70
  watcher.on('event', (event) => {
@@ -84,7 +86,7 @@ function vitePreprocessor(userConfigPath) {
84
86
  resolve(outputPath);
85
87
  }
86
88
  });
87
- });
89
+ };
88
90
  }
89
91
  function isWatcher(maybeWatcher) {
90
92
  return maybeWatcher.on !== undefined;
@@ -1,96 +1,93 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addLinterToCyProject = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const linter_1 = require("@nx/linter");
7
6
  const cypress_version_1 = require("./cypress-version");
8
7
  const versions_1 = require("./versions");
9
8
  const eslint_file_1 = require("@nx/linter/src/generators/utils/eslint-file");
10
9
  const global_eslint_config_1 = require("@nx/linter/src/generators/init/global-eslint-config");
11
- function addLinterToCyProject(tree, options) {
12
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
- if (options.linter === linter_1.Linter.None) {
14
- return () => { };
15
- }
16
- const tasks = [];
17
- const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
18
- const eslintFile = (0, eslint_file_1.findEslintFile)(tree, projectConfig.root);
19
- if (!eslintFile) {
20
- tasks.push(yield (0, linter_1.lintProjectGenerator)(tree, {
21
- project: options.project,
22
- linter: options.linter,
23
- skipFormat: true,
24
- tsConfigPaths: [(0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.json')],
25
- eslintFilePatterns: [
26
- `${projectConfig.root}/**/*.${options.js ? 'js' : '{js,ts}'}`,
27
- ],
28
- setParserOptionsProject: options.setParserOptionsProject,
29
- skipPackageJson: options.skipPackageJson,
30
- rootProject: options.rootProject,
31
- }));
32
- }
33
- if (!options.linter || options.linter !== linter_1.Linter.EsLint) {
34
- return (0, devkit_1.runTasksInSerial)(...tasks);
10
+ async function addLinterToCyProject(tree, options) {
11
+ if (options.linter === linter_1.Linter.None) {
12
+ return () => { };
13
+ }
14
+ const tasks = [];
15
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
16
+ const eslintFile = (0, eslint_file_1.findEslintFile)(tree, projectConfig.root);
17
+ if (!eslintFile) {
18
+ tasks.push(await (0, linter_1.lintProjectGenerator)(tree, {
19
+ project: options.project,
20
+ linter: options.linter,
21
+ skipFormat: true,
22
+ tsConfigPaths: [(0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.json')],
23
+ eslintFilePatterns: [
24
+ `${projectConfig.root}/**/*.${options.js ? 'js' : '{js,ts}'}`,
25
+ ],
26
+ setParserOptionsProject: options.setParserOptionsProject,
27
+ skipPackageJson: options.skipPackageJson,
28
+ rootProject: options.rootProject,
29
+ }));
30
+ }
31
+ if (!options.linter || options.linter !== linter_1.Linter.EsLint) {
32
+ return (0, devkit_1.runTasksInSerial)(...tasks);
33
+ }
34
+ tasks.push(!options.skipPackageJson
35
+ ? (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { 'eslint-plugin-cypress': versions_1.eslintPluginCypressVersion })
36
+ : () => { });
37
+ if ((0, eslint_file_1.isEslintConfigSupported)(tree)) {
38
+ const overrides = [];
39
+ if (options.rootProject) {
40
+ (0, eslint_file_1.addPluginsToLintConfig)(tree, projectConfig.root, '@nx');
41
+ overrides.push(global_eslint_config_1.javaScriptOverride);
35
42
  }
36
- tasks.push(!options.skipPackageJson
37
- ? (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { 'eslint-plugin-cypress': versions_1.eslintPluginCypressVersion })
38
- : () => { });
39
- if ((0, eslint_file_1.isEslintConfigSupported)(tree)) {
40
- const overrides = [];
41
- if (options.rootProject) {
42
- (0, eslint_file_1.addPluginsToLintConfig)(tree, projectConfig.root, '@nx');
43
- overrides.push(global_eslint_config_1.javaScriptOverride);
43
+ (0, eslint_file_1.addExtendsToLintConfig)(tree, projectConfig.root, 'plugin:cypress/recommended');
44
+ const cyVersion = (0, cypress_version_1.installedCypressVersion)();
45
+ /**
46
+ * We need this override because we enabled allowJS in the tsconfig to allow for JS based Cypress tests.
47
+ * That however leads to issues with the CommonJS Cypress plugin file.
48
+ */
49
+ const cy6Override = {
50
+ files: [`${options.cypressDir}/plugins/index.js`],
51
+ rules: {
52
+ '@typescript-eslint/no-var-requires': 'off',
53
+ 'no-undef': 'off',
54
+ },
55
+ };
56
+ const addCy6Override = cyVersion && cyVersion < 7;
57
+ if (options.overwriteExisting) {
58
+ overrides.push({
59
+ files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
60
+ parserOptions: !options.setParserOptionsProject
61
+ ? undefined
62
+ : {
63
+ project: `${projectConfig.root}/tsconfig.*?.json`,
64
+ },
65
+ rules: {},
66
+ });
67
+ if (addCy6Override) {
68
+ overrides.push(cy6Override);
44
69
  }
45
- (0, eslint_file_1.addExtendsToLintConfig)(tree, projectConfig.root, 'plugin:cypress/recommended');
46
- const cyVersion = (0, cypress_version_1.installedCypressVersion)();
47
- /**
48
- * We need this override because we enabled allowJS in the tsconfig to allow for JS based Cypress tests.
49
- * That however leads to issues with the CommonJS Cypress plugin file.
50
- */
51
- const cy6Override = {
52
- files: [`${options.cypressDir}/plugins/index.js`],
53
- rules: {
54
- '@typescript-eslint/no-var-requires': 'off',
55
- 'no-undef': 'off',
56
- },
57
- };
58
- const addCy6Override = cyVersion && cyVersion < 7;
59
- if (options.overwriteExisting) {
60
- overrides.push({
61
- files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
62
- parserOptions: !options.setParserOptionsProject
63
- ? undefined
64
- : {
65
- project: `${projectConfig.root}/tsconfig.*?.json`,
66
- },
67
- rules: {},
68
- });
69
- if (addCy6Override) {
70
- overrides.push(cy6Override);
71
- }
72
- (0, eslint_file_1.replaceOverridesInLintConfig)(tree, projectConfig.root, overrides);
73
- }
74
- else {
75
- overrides.unshift({
76
- files: [
77
- '*.cy.{ts,js,tsx,jsx}',
78
- `${options.cypressDir}/**/*.{ts,js,tsx,jsx}`,
79
- ],
80
- parserOptions: !options.setParserOptionsProject
81
- ? undefined
82
- : {
83
- project: `${projectConfig.root}/tsconfig.*?.json`,
84
- },
85
- rules: {},
86
- });
87
- if (addCy6Override) {
88
- overrides.push(cy6Override);
89
- }
90
- overrides.forEach((override) => (0, eslint_file_1.addOverrideToLintConfig)(tree, projectConfig.root, override));
70
+ (0, eslint_file_1.replaceOverridesInLintConfig)(tree, projectConfig.root, overrides);
71
+ }
72
+ else {
73
+ overrides.unshift({
74
+ files: [
75
+ '*.cy.{ts,js,tsx,jsx}',
76
+ `${options.cypressDir}/**/*.{ts,js,tsx,jsx}`,
77
+ ],
78
+ parserOptions: !options.setParserOptionsProject
79
+ ? undefined
80
+ : {
81
+ project: `${projectConfig.root}/tsconfig.*?.json`,
82
+ },
83
+ rules: {},
84
+ });
85
+ if (addCy6Override) {
86
+ overrides.push(cy6Override);
91
87
  }
88
+ overrides.forEach((override) => (0, eslint_file_1.addOverrideToLintConfig)(tree, projectConfig.root, override));
92
89
  }
93
- return (0, devkit_1.runTasksInSerial)(...tasks);
94
- });
90
+ }
91
+ return (0, devkit_1.runTasksInSerial)(...tasks);
95
92
  }
96
93
  exports.addLinterToCyProject = addLinterToCyProject;
@@ -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;