@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,36 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.compat = exports.updateTsConfigForComponentTesting = exports.componentConfigurationGenerator = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const cypress_version_1 = require("../../utils/cypress-version");
7
6
  const versions_1 = require("../../utils/versions");
8
7
  const base_setup_1 = require("../base-setup/base-setup");
9
- function componentConfigurationGenerator(tree, options) {
10
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
11
- const opts = normalizeOptions(options);
12
- const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, opts.project);
13
- const installDepsTask = updateDeps(tree, opts);
14
- addProjectFiles(tree, projectConfig, opts);
15
- addTargetToProject(tree, projectConfig, opts);
16
- updateNxJsonConfiguration(tree);
17
- updateTsConfigForComponentTesting(tree, projectConfig);
18
- if (!opts.skipFormat) {
19
- yield (0, devkit_1.formatFiles)(tree);
20
- }
21
- return () => {
22
- installDepsTask();
23
- };
24
- });
8
+ async function componentConfigurationGenerator(tree, options) {
9
+ const opts = normalizeOptions(options);
10
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, opts.project);
11
+ const installDepsTask = updateDeps(tree, opts);
12
+ addProjectFiles(tree, projectConfig, opts);
13
+ addTargetToProject(tree, projectConfig, opts);
14
+ updateNxJsonConfiguration(tree);
15
+ updateTsConfigForComponentTesting(tree, projectConfig);
16
+ if (!opts.skipFormat) {
17
+ await (0, devkit_1.formatFiles)(tree);
18
+ }
19
+ return () => {
20
+ installDepsTask();
21
+ };
25
22
  }
26
23
  exports.componentConfigurationGenerator = componentConfigurationGenerator;
27
24
  function normalizeOptions(options) {
28
- var _a;
29
25
  const cyVersion = (0, cypress_version_1.installedCypressVersion)();
30
26
  if (cyVersion && cyVersion < 10) {
31
27
  throw new Error('Cypress version of 10 or higher is required to use component testing. See the migration guide to upgrade. https://nx.dev/cypress/v11-migration-guide');
32
28
  }
33
- return Object.assign(Object.assign({}, options), { directory: (_a = options.directory) !== null && _a !== void 0 ? _a : 'cypress' });
29
+ return {
30
+ ...options,
31
+ directory: options.directory ?? 'cypress',
32
+ };
34
33
  }
35
34
  function updateDeps(tree, opts) {
36
35
  const devDeps = {
@@ -50,7 +49,12 @@ function addProjectFiles(tree, projectConfig, opts) {
50
49
  project: opts.project,
51
50
  directory: opts.directory,
52
51
  });
53
- (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files'), projectConfig.root, Object.assign(Object.assign({}, opts), { projectRoot: projectConfig.root, offsetFromRoot: (0, devkit_1.offsetFromRoot)(projectConfig.root), ext: '' }));
52
+ (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files'), projectConfig.root, {
53
+ ...opts,
54
+ projectRoot: projectConfig.root,
55
+ offsetFromRoot: (0, devkit_1.offsetFromRoot)(projectConfig.root),
56
+ ext: '',
57
+ });
54
58
  }
55
59
  function addTargetToProject(tree, projectConfig, opts) {
56
60
  projectConfig.targets['component-test'] = {
@@ -63,16 +67,24 @@ function addTargetToProject(tree, projectConfig, opts) {
63
67
  (0, devkit_1.updateProjectConfiguration)(tree, opts.project, projectConfig);
64
68
  }
65
69
  function updateNxJsonConfiguration(tree) {
66
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
67
- var _m, _o;
68
70
  const nxJson = (0, devkit_1.readNxJson)(tree);
69
- nxJson.tasksRunnerOptions = Object.assign(Object.assign({}, nxJson === null || nxJson === void 0 ? void 0 : nxJson.tasksRunnerOptions), { default: Object.assign(Object.assign({}, (_a = nxJson === null || nxJson === void 0 ? void 0 : nxJson.tasksRunnerOptions) === null || _a === void 0 ? void 0 : _a.default), { options: Object.assign(Object.assign({}, (_c = (_b = nxJson === null || nxJson === void 0 ? void 0 : nxJson.tasksRunnerOptions) === null || _b === void 0 ? void 0 : _b.default) === null || _c === void 0 ? void 0 : _c.options), { cacheableOperations: Array.from(new Set([
70
- ...((_g = (_f = (_e = (_d = nxJson === null || nxJson === void 0 ? void 0 : nxJson.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 : []),
71
+ nxJson.tasksRunnerOptions = {
72
+ ...nxJson?.tasksRunnerOptions,
73
+ default: {
74
+ ...nxJson?.tasksRunnerOptions?.default,
75
+ options: {
76
+ ...nxJson?.tasksRunnerOptions?.default?.options,
77
+ cacheableOperations: Array.from(new Set([
78
+ ...(nxJson?.tasksRunnerOptions?.default?.options
79
+ ?.cacheableOperations ?? []),
71
80
  'component-test',
72
- ])) }) }) });
81
+ ])),
82
+ },
83
+ },
84
+ };
73
85
  if (nxJson.namedInputs) {
74
- (_h = nxJson.targetDefaults) !== null && _h !== void 0 ? _h : (nxJson.targetDefaults = {});
75
- const productionFileSet = (_j = nxJson.namedInputs) === null || _j === void 0 ? void 0 : _j.production;
86
+ nxJson.targetDefaults ??= {};
87
+ const productionFileSet = nxJson.namedInputs?.production;
76
88
  if (productionFileSet) {
77
89
  nxJson.namedInputs.production = Array.from(new Set([
78
90
  ...productionFileSet,
@@ -81,11 +93,11 @@ function updateNxJsonConfiguration(tree) {
81
93
  '!{projectRoot}/cypress.config.[jt]s',
82
94
  ]));
83
95
  }
84
- (_k = (_m = nxJson.targetDefaults)['component-test']) !== null && _k !== void 0 ? _k : (_m['component-test'] = {});
85
- (_l = (_o = nxJson.targetDefaults['component-test']).inputs) !== null && _l !== void 0 ? _l : (_o.inputs = [
96
+ nxJson.targetDefaults['component-test'] ??= {};
97
+ nxJson.targetDefaults['component-test'].inputs ??= [
86
98
  'default',
87
99
  productionFileSet ? '^production' : '^default',
88
- ]);
100
+ ];
89
101
  }
90
102
  (0, devkit_1.updateNxJson)(tree, nxJson);
91
103
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.compat = exports.configurationGenerator = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const js_1 = require("@nx/js");
7
6
  const linter_1 = require("@nx/linter");
@@ -12,30 +11,30 @@ const cypress_version_1 = require("../../utils/cypress-version");
12
11
  const versions_1 = require("../../utils/versions");
13
12
  const init_1 = require("../init/init");
14
13
  const base_setup_1 = require("../base-setup/base-setup");
15
- function configurationGenerator(tree, options) {
16
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
17
- const opts = normalizeOptions(tree, options);
18
- const tasks = [];
19
- if (!(0, cypress_version_1.installedCypressVersion)()) {
20
- tasks.push(yield (0, init_1.default)(tree, opts));
21
- }
22
- if (opts.bundler === 'vite') {
23
- tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, { vite: versions_1.viteVersion }));
24
- }
25
- yield addFiles(tree, opts);
26
- addTarget(tree, opts);
27
- (0, add_linter_1.addLinterToCyProject)(tree, Object.assign(Object.assign({}, opts), { cypressDir: opts.directory }));
28
- if (!opts.skipFormat) {
29
- yield (0, devkit_1.formatFiles)(tree);
30
- }
31
- return (0, devkit_1.runTasksInSerial)(...tasks);
14
+ async function configurationGenerator(tree, options) {
15
+ const opts = normalizeOptions(tree, options);
16
+ const tasks = [];
17
+ if (!(0, cypress_version_1.installedCypressVersion)()) {
18
+ tasks.push(await (0, init_1.default)(tree, opts));
19
+ }
20
+ if (opts.bundler === 'vite') {
21
+ tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, { vite: versions_1.viteVersion }));
22
+ }
23
+ await addFiles(tree, opts);
24
+ addTarget(tree, opts);
25
+ (0, add_linter_1.addLinterToCyProject)(tree, {
26
+ ...opts,
27
+ cypressDir: opts.directory,
32
28
  });
29
+ if (!opts.skipFormat) {
30
+ await (0, devkit_1.formatFiles)(tree);
31
+ }
32
+ return (0, devkit_1.runTasksInSerial)(...tasks);
33
33
  }
34
34
  exports.configurationGenerator = configurationGenerator;
35
35
  function normalizeOptions(tree, options) {
36
- var _a, _b, _c, _d, _e;
37
36
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
38
- if ((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.targets) === null || _a === void 0 ? void 0 : _a.e2e) {
37
+ if (projectConfig?.targets?.e2e) {
39
38
  throw new Error(`Project ${options.project} already has an e2e target.
40
39
  Rename or remove the existing e2e target.`);
41
40
  }
@@ -45,57 +44,68 @@ Rename or remove the existing e2e target.`);
45
44
  throw new Error(`The project ${options.project} does not have a 'serve' target.
46
45
  In this case you need to provide a devServerTarget,'<projectName>:<targetName>[:<configName>]', or a baseUrl option`);
47
46
  }
48
- (_b = options.directory) !== null && _b !== void 0 ? _b : (options.directory = 'src');
49
- return Object.assign(Object.assign({}, options), { bundler: (_c = options.bundler) !== null && _c !== void 0 ? _c : 'webpack', rootProject: projectConfig.root === '.', linter: (_d = options.linter) !== null && _d !== void 0 ? _d : linter_1.Linter.EsLint, devServerTarget: (_e = options.devServerTarget) !== null && _e !== void 0 ? _e : (projectConfig.targets.serve ? `${options.project}:serve` : undefined) });
47
+ options.directory ??= 'src';
48
+ return {
49
+ ...options,
50
+ bundler: options.bundler ?? 'webpack',
51
+ rootProject: projectConfig.root === '.',
52
+ linter: options.linter ?? linter_1.Linter.EsLint,
53
+ devServerTarget: options.devServerTarget ??
54
+ (projectConfig.targets.serve ? `${options.project}:serve` : undefined),
55
+ };
50
56
  }
51
- function addFiles(tree, options) {
52
- var _a;
53
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
54
- const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
55
- const cyVersion = (0, cypress_version_1.installedCypressVersion)();
56
- const filesToUse = cyVersion && cyVersion < 10 ? 'v9' : 'v10';
57
- const hasTsConfig = tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.json'));
58
- const offsetFromProjectRoot = options.directory
59
- .split('/')
60
- .map((_) => '..')
61
- .join('/');
62
- const fileOpts = Object.assign(Object.assign({}, options), { dir: (_a = options.directory) !== null && _a !== void 0 ? _a : 'src', ext: options.js ? 'js' : 'ts', offsetFromRoot: (0, devkit_1.offsetFromRoot)(projectConfig.root), offsetFromProjectRoot, tsConfigPath: hasTsConfig
63
- ? `${offsetFromProjectRoot}/tsconfig.json`
64
- : (0, js_1.getRelativePathToRootTsConfig)(tree, projectConfig.root), tmpl: '' });
65
- (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files', filesToUse), projectConfig.root, fileOpts);
66
- if (filesToUse === 'v10') {
67
- (0, base_setup_1.addBaseCypressSetup)(tree, {
68
- project: options.project,
69
- directory: options.directory,
70
- });
71
- const cyFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress.config.ts');
72
- const updatedCyConfig = yield (0, config_1.addDefaultE2EConfig)(tree.read(cyFile, 'utf-8'), {
73
- directory: options.directory,
74
- bundler: options.bundler,
75
- });
76
- tree.write(cyFile, updatedCyConfig);
77
- }
78
- if (cyVersion &&
79
- cyVersion < 7 &&
80
- tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, 'src', 'plugins', 'index.js'))) {
81
- (0, devkit_1.updateJson)(tree, (0, path_1.join)(projectConfig.root, 'cypress.json'), (json) => {
82
- json.pluginsFile = './src/plugins/index';
83
- return json;
84
- });
85
- }
86
- else if (cyVersion < 10) {
87
- const pluginPath = (0, path_1.join)(projectConfig.root, 'src/plugins/index.js');
88
- if (tree.exists(pluginPath)) {
89
- tree.delete(pluginPath);
90
- }
91
- }
92
- if (options.js) {
93
- (0, devkit_1.toJS)(tree);
57
+ async function addFiles(tree, options) {
58
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
59
+ const cyVersion = (0, cypress_version_1.installedCypressVersion)();
60
+ const filesToUse = cyVersion && cyVersion < 10 ? 'v9' : 'v10';
61
+ const hasTsConfig = tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.json'));
62
+ const offsetFromProjectRoot = options.directory
63
+ .split('/')
64
+ .map((_) => '..')
65
+ .join('/');
66
+ const fileOpts = {
67
+ ...options,
68
+ dir: options.directory ?? 'src',
69
+ ext: options.js ? 'js' : 'ts',
70
+ offsetFromRoot: (0, devkit_1.offsetFromRoot)(projectConfig.root),
71
+ offsetFromProjectRoot,
72
+ tsConfigPath: hasTsConfig
73
+ ? `${offsetFromProjectRoot}/tsconfig.json`
74
+ : (0, js_1.getRelativePathToRootTsConfig)(tree, projectConfig.root),
75
+ tmpl: '',
76
+ };
77
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files', filesToUse), projectConfig.root, fileOpts);
78
+ if (filesToUse === 'v10') {
79
+ (0, base_setup_1.addBaseCypressSetup)(tree, {
80
+ project: options.project,
81
+ directory: options.directory,
82
+ });
83
+ const cyFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress.config.ts');
84
+ const updatedCyConfig = await (0, config_1.addDefaultE2EConfig)(tree.read(cyFile, 'utf-8'), {
85
+ directory: options.directory,
86
+ bundler: options.bundler,
87
+ });
88
+ tree.write(cyFile, updatedCyConfig);
89
+ }
90
+ if (cyVersion &&
91
+ cyVersion < 7 &&
92
+ tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, 'src', 'plugins', 'index.js'))) {
93
+ (0, devkit_1.updateJson)(tree, (0, path_1.join)(projectConfig.root, 'cypress.json'), (json) => {
94
+ json.pluginsFile = './src/plugins/index';
95
+ return json;
96
+ });
97
+ }
98
+ else if (cyVersion < 10) {
99
+ const pluginPath = (0, path_1.join)(projectConfig.root, 'src/plugins/index.js');
100
+ if (tree.exists(pluginPath)) {
101
+ tree.delete(pluginPath);
94
102
  }
95
- });
103
+ }
104
+ if (options.js) {
105
+ (0, devkit_1.toJS)(tree);
106
+ }
96
107
  }
97
108
  function addTarget(tree, opts) {
98
- var _a;
99
109
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, opts.project);
100
110
  const cyVersion = (0, cypress_version_1.installedCypressVersion)();
101
111
  projectConfig.targets.e2e = {
@@ -106,18 +116,25 @@ function addTarget(tree, opts) {
106
116
  },
107
117
  };
108
118
  if (opts.baseUrl) {
109
- projectConfig.targets.e2e.options = Object.assign(Object.assign({}, projectConfig.targets.e2e.options), { baseUrl: opts.baseUrl });
119
+ projectConfig.targets.e2e.options = {
120
+ ...projectConfig.targets.e2e.options,
121
+ baseUrl: opts.baseUrl,
122
+ };
110
123
  }
111
124
  else if (opts.devServerTarget) {
112
125
  const parsedTarget = (0, devkit_1.parseTargetString)(opts.devServerTarget);
113
- projectConfig.targets.e2e.options = Object.assign(Object.assign({}, projectConfig.targets.e2e.options), { devServerTarget: opts.devServerTarget, port: opts.port });
126
+ projectConfig.targets.e2e.options = {
127
+ ...projectConfig.targets.e2e.options,
128
+ devServerTarget: opts.devServerTarget,
129
+ port: opts.port,
130
+ };
114
131
  projectConfig.targets.e2e.configurations = {
115
132
  [parsedTarget.configuration || 'production']: {
116
133
  devServerTarget: `${opts.devServerTarget}${parsedTarget.configuration ? '' : ':production'}`,
117
134
  },
118
135
  };
119
136
  const devServerProjectConfig = (0, devkit_1.readProjectConfiguration)(tree, parsedTarget.project);
120
- if ((_a = devServerProjectConfig.targets) === null || _a === void 0 ? void 0 : _a['serve-static']) {
137
+ if (devServerProjectConfig.targets?.['serve-static']) {
121
138
  projectConfig.targets.e2e.configurations.ci = {
122
139
  devServerTarget: `${parsedTarget.project}:serve-static`,
123
140
  };
@@ -1,91 +1,88 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.conversionSchematic = exports.conversionGenerator = 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 add_linter_1 = require("../../utils/add-linter");
8
7
  /**
9
8
  * @deprecated This generator will be removed in v17
10
9
  */
11
- function conversionGenerator(host, options) {
12
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
- /**
14
- * The ProjectConverter instance encapsulates all the standard operations we need
15
- * to perform in order to convert a project from TSLint to ESLint, as well as some
16
- * extensibility points for adjusting the behavior on a per package basis.
17
- *
18
- * E.g. @nx/angular projects might need to make different changes to the final
19
- * ESLint config when compared with @nx/next projects.
20
- *
21
- * See the ProjectConverter implementation for a full breakdown of what it does.
22
- */
23
- const projectConverter = new linter_1.ProjectConverter({
24
- host,
25
- projectName: options.project,
26
- ignoreExistingTslintConfig: options.ignoreExistingTslintConfig,
27
- eslintInitializer: ({ projectName, projectConfig }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
28
- yield (0, add_linter_1.addLinterToCyProject)(host, {
29
- linter: linter_1.Linter.EsLint,
30
- project: projectName,
31
- /**
32
- * We set the parserOptions.project config just in case the converted config uses
33
- * rules which require type-checking. Later in the conversion we check if it actually
34
- * does and remove the config again if it doesn't, so that it is most efficient.
35
- */
36
- setParserOptionsProject: true,
37
- cypressDir: 'src',
38
- overwriteExisting: true,
39
- });
40
- }),
41
- });
42
- /**
43
- * If root eslint configuration already exists it will not be recreated
44
- * but we also don't want to re-run the tslint config conversion
45
- * as it was likely already done
46
- */
47
- const rootEslintConfigExists = host.exists('.eslintrc.json');
48
- /**
49
- * Create the standard (which is applicable to the current package) ESLint setup
50
- * for converting the project.
51
- */
52
- const eslintInitInstallTask = yield projectConverter.initESLint();
53
- /**
54
- * Convert the root tslint.json and apply the converted rules to the root .eslintrc.json.
55
- */
56
- const rootConfigInstallTask = yield projectConverter.convertRootTSLintConfig((json) => removeCodelyzerRelatedRules(json), rootEslintConfigExists);
57
- /**
58
- * Convert the project's tslint.json to an equivalent ESLint config.
59
- */
60
- const projectConfigInstallTask = yield projectConverter.convertProjectConfig((json) => json);
61
- /**
62
- * Clean up the original TSLint configuration for the project.
63
- */
64
- projectConverter.removeProjectTSLintFile();
65
- // Only project shouldn't be added as a default
66
- const { project } = options, defaults = tslib_1.__rest(options, ["project"]);
67
- /**
68
- * Store user preferences for the collection
69
- */
70
- projectConverter.setDefaults('@nx/cypress', defaults);
71
- /**
72
- * Based on user preference and remaining usage, remove TSLint from the workspace entirely.
73
- */
74
- let uninstallTSLintTask = () => Promise.resolve(undefined);
75
- if (options.removeTSLintIfNoMoreTSLintTargets &&
76
- !projectConverter.isTSLintUsedInWorkspace()) {
77
- uninstallTSLintTask = projectConverter.removeTSLintFromWorkspace();
78
- }
79
- if (!options.skipFormat) {
80
- yield (0, devkit_1.formatFiles)(host);
81
- }
82
- return () => tslib_1.__awaiter(this, void 0, void 0, function* () {
83
- yield eslintInitInstallTask();
84
- yield rootConfigInstallTask();
85
- yield projectConfigInstallTask();
86
- yield uninstallTSLintTask();
87
- });
10
+ async function conversionGenerator(host, options) {
11
+ /**
12
+ * The ProjectConverter instance encapsulates all the standard operations we need
13
+ * to perform in order to convert a project from TSLint to ESLint, as well as some
14
+ * extensibility points for adjusting the behavior on a per package basis.
15
+ *
16
+ * E.g. @nx/angular projects might need to make different changes to the final
17
+ * ESLint config when compared with @nx/next projects.
18
+ *
19
+ * See the ProjectConverter implementation for a full breakdown of what it does.
20
+ */
21
+ const projectConverter = new linter_1.ProjectConverter({
22
+ host,
23
+ projectName: options.project,
24
+ ignoreExistingTslintConfig: options.ignoreExistingTslintConfig,
25
+ eslintInitializer: async ({ projectName, projectConfig }) => {
26
+ await (0, add_linter_1.addLinterToCyProject)(host, {
27
+ linter: linter_1.Linter.EsLint,
28
+ project: projectName,
29
+ /**
30
+ * We set the parserOptions.project config just in case the converted config uses
31
+ * rules which require type-checking. Later in the conversion we check if it actually
32
+ * does and remove the config again if it doesn't, so that it is most efficient.
33
+ */
34
+ setParserOptionsProject: true,
35
+ cypressDir: 'src',
36
+ overwriteExisting: true,
37
+ });
38
+ },
88
39
  });
40
+ /**
41
+ * If root eslint configuration already exists it will not be recreated
42
+ * but we also don't want to re-run the tslint config conversion
43
+ * as it was likely already done
44
+ */
45
+ const rootEslintConfigExists = host.exists('.eslintrc.json');
46
+ /**
47
+ * Create the standard (which is applicable to the current package) ESLint setup
48
+ * for converting the project.
49
+ */
50
+ const eslintInitInstallTask = await projectConverter.initESLint();
51
+ /**
52
+ * Convert the root tslint.json and apply the converted rules to the root .eslintrc.json.
53
+ */
54
+ const rootConfigInstallTask = await projectConverter.convertRootTSLintConfig((json) => removeCodelyzerRelatedRules(json), rootEslintConfigExists);
55
+ /**
56
+ * Convert the project's tslint.json to an equivalent ESLint config.
57
+ */
58
+ const projectConfigInstallTask = await projectConverter.convertProjectConfig((json) => json);
59
+ /**
60
+ * Clean up the original TSLint configuration for the project.
61
+ */
62
+ projectConverter.removeProjectTSLintFile();
63
+ // Only project shouldn't be added as a default
64
+ const { project, ...defaults } = options;
65
+ /**
66
+ * Store user preferences for the collection
67
+ */
68
+ projectConverter.setDefaults('@nx/cypress', defaults);
69
+ /**
70
+ * Based on user preference and remaining usage, remove TSLint from the workspace entirely.
71
+ */
72
+ let uninstallTSLintTask = () => Promise.resolve(undefined);
73
+ if (options.removeTSLintIfNoMoreTSLintTargets &&
74
+ !projectConverter.isTSLintUsedInWorkspace()) {
75
+ uninstallTSLintTask = projectConverter.removeTSLintFromWorkspace();
76
+ }
77
+ if (!options.skipFormat) {
78
+ await (0, devkit_1.formatFiles)(host);
79
+ }
80
+ return async () => {
81
+ await eslintInitInstallTask();
82
+ await rootConfigInstallTask();
83
+ await projectConfigInstallTask();
84
+ await uninstallTSLintTask();
85
+ };
89
86
  }
90
87
  exports.conversionGenerator = conversionGenerator;
91
88
  exports.conversionSchematic = (0, devkit_1.convertNxGenerator)(conversionGenerator);