@nx/cypress 16.8.0-beta.1 → 16.8.0-beta.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/cypress",
3
- "version": "16.8.0-beta.1",
3
+ "version": "16.8.0-beta.3",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Cypress contains executors and generators allowing your workspace to use the powerful Cypress integration testing capabilities.",
6
6
  "repository": {
@@ -34,13 +34,12 @@
34
34
  "migrations": "./migrations.json"
35
35
  },
36
36
  "dependencies": {
37
- "@nrwl/cypress": "16.8.0-beta.1",
38
- "@nx/devkit": "16.8.0-beta.1",
39
- "@nx/js": "16.8.0-beta.1",
40
- "@nx/linter": "16.8.0-beta.1",
37
+ "@nrwl/cypress": "16.8.0-beta.3",
38
+ "@nx/devkit": "16.8.0-beta.3",
39
+ "@nx/js": "16.8.0-beta.3",
40
+ "@nx/linter": "16.8.0-beta.3",
41
41
  "@phenomnomnominal/tsquery": "~5.0.1",
42
42
  "detect-port": "^1.5.1",
43
- "dotenv": "~16.3.1",
44
43
  "semver": "7.5.3",
45
44
  "tslib": "^2.3.0"
46
45
  },
@@ -56,5 +55,5 @@
56
55
  "access": "public"
57
56
  },
58
57
  "type": "commonjs",
59
- "gitHead": "231a998e004c13e559c171ba6c164a9127886153"
58
+ "gitHead": "dcd48165a485bc8db57a1fb02b96a0772de3b7e9"
60
59
  }
@@ -1,5 +1,4 @@
1
1
  import { ExecutorContext } from '@nx/devkit';
2
- import 'dotenv/config';
3
2
  export type Json = {
4
3
  [k: string]: any;
5
4
  };
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const executor_utils_1 = require("nx/src/command-line/run/executor-utils");
6
- require("dotenv/config");
7
6
  const fs_1 = require("fs");
8
7
  const path_1 = require("path");
9
8
  const ct_helpers_1 = require("../../utils/ct-helpers");
@@ -4,9 +4,10 @@ exports.addLinterToCyProject = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const linter_1 = require("@nx/linter");
7
- const global_eslint_config_1 = require("@nx/linter/src/generators/init/global-eslint-config");
8
7
  const cypress_version_1 = require("./cypress-version");
9
8
  const versions_1 = require("./versions");
9
+ const eslint_file_1 = require("@nx/linter/src/generators/utils/eslint-file");
10
+ const global_eslint_config_1 = require("@nx/linter/src/generators/init/global-eslint-config");
10
11
  function addLinterToCyProject(tree, options) {
11
12
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
13
  if (options.linter === linter_1.Linter.None) {
@@ -14,7 +15,8 @@ function addLinterToCyProject(tree, options) {
14
15
  }
15
16
  const tasks = [];
16
17
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
17
- if (!tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, '.eslintrc.json'))) {
18
+ const eslintFile = (0, eslint_file_1.findEslintFile)(tree, projectConfig.root);
19
+ if (!eslintFile) {
18
20
  tasks.push(yield (0, linter_1.lintProjectGenerator)(tree, {
19
21
  project: options.project,
20
22
  linter: options.linter,
@@ -34,55 +36,60 @@ function addLinterToCyProject(tree, options) {
34
36
  tasks.push(!options.skipPackageJson
35
37
  ? (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { 'eslint-plugin-cypress': versions_1.eslintPluginCypressVersion })
36
38
  : () => { });
37
- (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(projectConfig.root, '.eslintrc.json'), (json) => {
38
- var _a;
39
+ if ((0, eslint_file_1.isEslintConfigSupported)(tree)) {
40
+ const overrides = [];
39
41
  if (options.rootProject) {
40
- json.plugins = ['@nx'];
41
- json.extends = ['plugin:cypress/recommended'];
42
- }
43
- else {
44
- json.extends = ['plugin:cypress/recommended', ...json.extends];
42
+ (0, eslint_file_1.addPluginsToLintConfig)(tree, projectConfig.root, '@nx');
43
+ overrides.push(global_eslint_config_1.javaScriptOverride);
45
44
  }
46
- (_a = json.overrides) !== null && _a !== void 0 ? _a : (json.overrides = []);
47
- const globals = options.rootProject ? [global_eslint_config_1.globalJavaScriptOverrides] : [];
48
- const override = {
49
- files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
50
- parserOptions: !options.setParserOptionsProject
51
- ? undefined
52
- : {
53
- project: `${projectConfig.root}/tsconfig.*?.json`,
54
- },
55
- rules: {},
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
+ },
56
57
  };
57
- const cyFiles = [
58
- Object.assign(Object.assign({}, override), { files: [
59
- '*.cy.{ts,js,tsx,jsx}',
60
- `${options.cypressDir}/**/*.{ts,js,tsx,jsx}`,
61
- ] }),
62
- ];
58
+ const addCy6Override = cyVersion && cyVersion < 7;
63
59
  if (options.overwriteExisting) {
64
- json.overrides = [...globals, override];
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);
65
73
  }
66
74
  else {
67
- json.overrides.push(...globals);
68
- json.overrides.push(...cyFiles);
69
- }
70
- const cyVersion = (0, cypress_version_1.installedCypressVersion)();
71
- if (cyVersion && cyVersion < 7) {
72
- /**
73
- * We need this override because we enabled allowJS in the tsconfig to allow for JS based Cypress tests.
74
- * That however leads to issues with the CommonJS Cypress plugin file.
75
- */
76
- json.overrides.push({
77
- files: [`${options.cypressDir}/plugins/index.js`],
78
- rules: {
79
- '@typescript-eslint/no-var-requires': 'off',
80
- 'no-undef': 'off',
81
- },
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: {},
82
86
  });
87
+ if (addCy6Override) {
88
+ overrides.push(cy6Override);
89
+ }
90
+ overrides.forEach((override) => (0, eslint_file_1.addOverrideToLintConfig)(tree, projectConfig.root, override));
83
91
  }
84
- return json;
85
- });
92
+ }
86
93
  return (0, devkit_1.runTasksInSerial)(...tasks);
87
94
  });
88
95
  }
@@ -26,7 +26,9 @@ function findBuildConfig(tree, options) {
26
26
  }
27
27
  catch (e) {
28
28
  devkit_1.logger.error(e);
29
- throw new Error((0, devkit_1.stripIndents) `Error trying to find build configuration. Try manually specifying the build target with the --build-target flag.
29
+ throw new Error((0, devkit_1.stripIndents) `Error trying to find build configuration. ${options.buildTarget
30
+ ? 'Try using an app of the same framework for the --build-target.'
31
+ : 'Try manually specifying the build target with the --build-target flag.'}
30
32
  Provided project? ${options.project}
31
33
  Provided build target? ${options.buildTarget}
32
34
  Provided Executors? ${[...options.validExecutorNames].join(', ')}`);
@@ -46,10 +48,11 @@ ${Array.from(options.validExecutorNames)
46
48
  .map((ve) => ` - ${ve}`)
47
49
  .join('\n')}
48
50
 
49
- This is most likely because the provided --build-target is not a build target for an application.
51
+ ${frameworkHelperMessage(Array.from(options.buildTarget), executorName)}
52
+ This is most likely because the provided --build-target is not a build target for an application or framework.
50
53
  For example, the provide build target, '${options.buildTarget}' is:
51
54
  - the build target for a buildable/publishable library instead of an app.
52
- - using a different framework than expected like react library using an angular app build target.
55
+ - using a different framework than expected like react library using an angular or next app build target.
53
56
 
54
57
  If you do not have an app in the workspace to you can make a new app with 'nx g app' and use it just for component testing
55
58
  `);
@@ -58,6 +61,29 @@ If you do not have an app in the workspace to you can make a new app with 'nx g
58
61
  const foundConfig = configuration || ((_d = (_c = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.targets) === null || _c === void 0 ? void 0 : _c[target]) === null || _d === void 0 ? void 0 : _d.defaultConfiguration);
59
62
  return (0, devkit_1.readTargetOptions)({ project, target, configuration: foundConfig }, createExecutorContext(graph, projectConfig.targets, project, target, foundConfig));
60
63
  }
64
+ function frameworkHelperMessage(validExecutorNames, executorName) {
65
+ const executorsToFramework = {
66
+ '@nx/webpack:webpack': 'react',
67
+ '@nx/vite:build': 'react',
68
+ '@nrwl/webpack:webpack': 'react',
69
+ '@nrwl/vite:build': 'react',
70
+ '@nx/angular:webpack-browser': 'angular',
71
+ '@nrwl/angular:webpack-browser': 'angular',
72
+ '@angular-devkit/build-angular:browser': 'angular',
73
+ '@nx/next:build': 'next',
74
+ '@nrwl/next:build': 'next',
75
+ };
76
+ const buildTargetFramework = executorsToFramework[executorName];
77
+ const invokedGeneratorFramework = validExecutorNames.find((e) => !!executorsToFramework[e]);
78
+ if (buildTargetFramework &&
79
+ invokedGeneratorFramework &&
80
+ buildTargetFramework !== invokedGeneratorFramework) {
81
+ return `It looks like you're using a different plugin generator than the --build-target framework is set up for.
82
+ The provided build target is configured for ${buildTargetFramework} instead of ${invokedGeneratorFramework}.
83
+ Try using @nx/${buildTargetFramework} instead.`;
84
+ }
85
+ return '';
86
+ }
61
87
  function findInGraph(tree, graph, options) {
62
88
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
63
89
  const parents = findParentsOfProject(graph, options.project);