@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.
- package/migrations.json +6 -0
- package/package.json +7 -7
- package/plugins/cypress-preset.d.ts +0 -3
- package/plugins/cypress-preset.js +15 -7
- package/src/executors/cypress/cypress.impl.d.ts +1 -0
- package/src/executors/cypress/cypress.impl.js +180 -210
- package/src/executors/cypress/schema.json +4 -0
- package/src/generators/base-setup/base-setup.js +15 -5
- package/src/generators/component-configuration/component-configuration.js +42 -30
- package/src/generators/configuration/configuration.js +87 -70
- package/src/generators/convert-tslint-to-eslint/convert-tslint-to-eslint.js +75 -78
- package/src/generators/cypress-project/cypress-project.js +76 -63
- package/src/generators/init/init.js +16 -18
- package/src/generators/migrate-to-cypress-11/conversion.util.js +22 -16
- package/src/generators/migrate-to-cypress-11/migrate-to-cypress-11.js +38 -35
- package/src/migrations/update-12-8-0/remove-typescript-plugin.js +23 -26
- package/src/migrations/update-14-6-1/update-cypress-configs-presets.js +79 -68
- package/src/migrations/update-14-7-0/update-cypress-version-if-10.js +1 -2
- package/src/migrations/update-15-0-0/add-cypress-inputs.js +24 -29
- package/src/migrations/update-15-0-0/update-cy-mount-usage.js +25 -29
- package/src/migrations/update-15-1-0/cypress-11.js +34 -37
- package/src/migrations/update-15-5-0/update-to-cypress-12.js +3 -5
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
- package/src/migrations/update-16-2-0/update-cy-tsconfig.js +25 -24
- package/src/migrations/update-16-4-0/tsconfig-sourcemaps.js +52 -49
- package/src/migrations/update-16-8-0/cypress-13.d.ts +7 -0
- package/src/migrations/update-16-8-0/cypress-13.js +179 -0
- package/src/plugins/preprocessor-vite.js +7 -5
- package/src/utils/add-linter.js +78 -81
- package/src/utils/config.js +54 -62
- package/src/utils/ct-helpers.js +6 -8
- package/src/utils/cypress-version.js +1 -1
- package/src/utils/find-target-options.js +37 -43
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
|
@@ -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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
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;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
export declare function updateToCypress13(tree: Tree): Promise<void>;
|
|
3
|
+
/**
|
|
4
|
+
* leave a comment on all usages of overriding built-ins that are now banned
|
|
5
|
+
**/
|
|
6
|
+
export declare function shouldNotOverrideReadFile(tree: Tree, filePath: string): void;
|
|
7
|
+
export default updateToCypress13;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shouldNotOverrideReadFile = exports.updateToCypress13 = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const cypress_version_1 = require("../../utils/cypress-version");
|
|
6
|
+
const typescript_1 = require("typescript");
|
|
7
|
+
const tsquery_1 = require("@phenomnomnominal/tsquery");
|
|
8
|
+
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
9
|
+
const JS_TS_FILE_MATCHER = /\.[jt]sx?$/;
|
|
10
|
+
async function updateToCypress13(tree) {
|
|
11
|
+
if ((0, cypress_version_1.installedCypressVersion)() < 12) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
15
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/cypress:cypress', (options, projectName) => {
|
|
16
|
+
if (!options.cypressConfig || !tree.exists(options.cypressConfig)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const projectConfig = projects.get(projectName);
|
|
20
|
+
removeNodeVersionOption(tree, options.cypressConfig);
|
|
21
|
+
removeVideoUploadOnPassesOption(tree, options.cypressConfig);
|
|
22
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, projectConfig.root, (filePath) => {
|
|
23
|
+
if (!JS_TS_FILE_MATCHER.test(filePath)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
shouldNotOverrideReadFile(tree, filePath);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
(0, devkit_1.updateJson)(tree, 'package.json', (json) => {
|
|
30
|
+
json.devDependencies ??= {};
|
|
31
|
+
json.devDependencies.cypress = '^13.0.0';
|
|
32
|
+
return json;
|
|
33
|
+
});
|
|
34
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
35
|
+
}
|
|
36
|
+
exports.updateToCypress13 = updateToCypress13;
|
|
37
|
+
function removeVideoUploadOnPassesOption(tree, configPath) {
|
|
38
|
+
const config = tree.read(configPath, 'utf-8');
|
|
39
|
+
const isUsingDeprecatedOption = tsquery_1.tsquery.query(config, getPropertyQuery('videoUploadOnPasses'))?.length > 0;
|
|
40
|
+
if (!isUsingDeprecatedOption) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const importStatement = configPath.endsWith('.ts')
|
|
44
|
+
? "import fs from 'fs';"
|
|
45
|
+
: "const fs = require('fs');";
|
|
46
|
+
const replacementFunction = `/**
|
|
47
|
+
* Delete videos for specs that do not contain failing or retried tests.
|
|
48
|
+
* This function is to be used in the 'setupNodeEvents' configuration option as a replacement to
|
|
49
|
+
* 'videoUploadOnPasses' which has been removed.
|
|
50
|
+
*
|
|
51
|
+
* https://docs.cypress.io/guides/guides/screenshots-and-videos#Delete-videos-for-specs-without-failing-or-retried-tests
|
|
52
|
+
**/
|
|
53
|
+
function removePassedSpecs(on) {
|
|
54
|
+
on('after:spec', (spec, results) => {
|
|
55
|
+
if(results && results.vide) {
|
|
56
|
+
const hasFailures = results.tests.some(t => t.attempts.some(a => a.state === 'failed'));
|
|
57
|
+
|
|
58
|
+
if(!hasFailures) {
|
|
59
|
+
fs.unlinkSync(results.video);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
}`;
|
|
64
|
+
const withReplacementFn = `${importStatement}\n${config}\n${replacementFunction}`;
|
|
65
|
+
// setupNodeEvents can be a property or method.
|
|
66
|
+
const setupNodeEventsQuery = 'ExportAssignment ObjectLiteralExpression > :matches(PropertyAssignment:has(Identifier[name="setupNodeEvents"]), MethodDeclaration:has(Identifier[name="setupNodeEvents"]))';
|
|
67
|
+
const hasSetupNodeEvents = tsquery_1.tsquery.query(withReplacementFn, setupNodeEventsQuery)?.length > 0;
|
|
68
|
+
let updatedWithSetupNodeEvents = withReplacementFn;
|
|
69
|
+
if (hasSetupNodeEvents) {
|
|
70
|
+
// if have setupNodeEvents, update existing fn to use removePassedSpecs helper and remove videoUploadOnPasses
|
|
71
|
+
const noVideoUploadOption = tsquery_1.tsquery.replace(withReplacementFn, getPropertyQuery('videoUploadOnPasses'), (node) => {
|
|
72
|
+
if ((0, typescript_1.isObjectLiteralExpression)(node.initializer)) {
|
|
73
|
+
// is a nested config object
|
|
74
|
+
const key = node.name.getText().trim();
|
|
75
|
+
const listOfProperties = node.initializer.properties
|
|
76
|
+
.map((j) => j.getText())
|
|
77
|
+
.filter((j) => !j.includes('videoUploadOnPasses'))
|
|
78
|
+
.join(',\n');
|
|
79
|
+
return `${key}: {
|
|
80
|
+
${listOfProperties}
|
|
81
|
+
}
|
|
82
|
+
`;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
if (isPropertyTopLevel(node)) {
|
|
86
|
+
return `// ${node.getText()} `;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
updatedWithSetupNodeEvents = tsquery_1.tsquery.replace(noVideoUploadOption, `${setupNodeEventsQuery} Block`, (node) => {
|
|
91
|
+
const blockWithoutBraces = node
|
|
92
|
+
.getFullText()
|
|
93
|
+
.trim()
|
|
94
|
+
.slice(1, -1)
|
|
95
|
+
.trim();
|
|
96
|
+
return `{
|
|
97
|
+
${blockWithoutBraces}
|
|
98
|
+
removePassedSpecs(on);
|
|
99
|
+
}
|
|
100
|
+
`;
|
|
101
|
+
}, { visitAllChildren: false });
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// if don't have setupNodeEvents, replace videoUploadOnPasses with setupNodeEvents method
|
|
105
|
+
updatedWithSetupNodeEvents = tsquery_1.tsquery.replace(withReplacementFn, getPropertyQuery('videoUploadOnPasses'), () => {
|
|
106
|
+
return `setupNodeEvents(on, config) {
|
|
107
|
+
removePassedSpecs(on);
|
|
108
|
+
}`;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
tree.write(configPath, updatedWithSetupNodeEvents);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* remove the nodeVersion option from the config file
|
|
115
|
+
**/
|
|
116
|
+
function removeNodeVersionOption(tree, configPath) {
|
|
117
|
+
const config = tree.read(configPath, 'utf-8');
|
|
118
|
+
const updated = tsquery_1.tsquery.replace(config, getPropertyQuery('nodeVersion'), (node) => {
|
|
119
|
+
if ((0, typescript_1.isObjectLiteralExpression)(node.initializer)) {
|
|
120
|
+
// is a nested config object
|
|
121
|
+
const key = node.name.getText().trim();
|
|
122
|
+
const listOfProperties = node.initializer.properties
|
|
123
|
+
.map((j) => j.getFullText())
|
|
124
|
+
.filter((j) => !j.includes('nodeVersion'))
|
|
125
|
+
.join(', ');
|
|
126
|
+
return `${key}: {
|
|
127
|
+
${listOfProperties}
|
|
128
|
+
}`;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
if (isPropertyTopLevel(node)) {
|
|
132
|
+
return `// ${node.getText()}`;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
if (updated !== config) {
|
|
137
|
+
tree.write(configPath, updated);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* leave a comment on all usages of overriding built-ins that are now banned
|
|
142
|
+
**/
|
|
143
|
+
function shouldNotOverrideReadFile(tree, filePath) {
|
|
144
|
+
const content = tree.read(filePath, 'utf-8');
|
|
145
|
+
const markedOverrideUsage = tsquery_1.tsquery.replace(content, 'PropertyAccessExpression:has(Identifier[name="overwrite"]):has(Identifier[name="Cypress"])', (node) => {
|
|
146
|
+
if (isAlreadyCommented(node)) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const expression = node.expression.getText().trim();
|
|
150
|
+
// prevent grabbing other Cypress.<something>.defaults
|
|
151
|
+
if (expression === 'Cypress.Commands') {
|
|
152
|
+
// get value.
|
|
153
|
+
const overwriteExpression = node.parent;
|
|
154
|
+
const command = overwriteExpression.arguments?.[0]?.text; // need string without quotes
|
|
155
|
+
if (command === 'readFile') {
|
|
156
|
+
// overwrite
|
|
157
|
+
return `/**
|
|
158
|
+
* TODO(@nx/cypress): This command can no longer be overridden
|
|
159
|
+
* Consider using a different name like 'custom_${command}'
|
|
160
|
+
* More info: https://docs.cypress.io/guides/references/migration-guide#readFile-can-no-longer-be-overwritten-with-CypressCommandsoverwrite
|
|
161
|
+
**/
|
|
162
|
+
${node.getText()}`;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
tree.write(filePath, markedOverrideUsage);
|
|
167
|
+
}
|
|
168
|
+
exports.shouldNotOverrideReadFile = shouldNotOverrideReadFile;
|
|
169
|
+
function isAlreadyCommented(node) {
|
|
170
|
+
return node.getFullText().includes('TODO(@nx/cypress)');
|
|
171
|
+
}
|
|
172
|
+
function isPropertyTopLevel(node) {
|
|
173
|
+
return (node.parent &&
|
|
174
|
+
(0, typescript_1.isObjectLiteralExpression)(node.parent) &&
|
|
175
|
+
node.parent.parent &&
|
|
176
|
+
(0, typescript_1.isCallExpression)(node.parent.parent));
|
|
177
|
+
}
|
|
178
|
+
const getPropertyQuery = (propertyName) => `ExportAssignment ObjectLiteralExpression > PropertyAssignment:has(Identifier[name="${propertyName}"])`;
|
|
179
|
+
exports.default = updateToCypress13;
|
|
@@ -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) =>
|
|
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 } =
|
|
65
|
-
const watcher = (
|
|
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;
|
package/src/utils/add-linter.js
CHANGED
|
@@ -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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
94
|
-
|
|
90
|
+
}
|
|
91
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
95
92
|
}
|
|
96
93
|
exports.addLinterToCyProject = addLinterToCyProject;
|