@nx/cypress 17.0.5 → 17.0.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 (57) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -9
  3. package/generators.json +3 -3
  4. package/index.d.ts +2 -2
  5. package/index.js +4 -4
  6. package/migrations.json +0 -24
  7. package/package.json +6 -6
  8. package/plugins/cypress-preset.d.ts +19 -27
  9. package/plugins/cypress-preset.js +11 -102
  10. package/src/executors/cypress/cypress.impl.d.ts +1 -1
  11. package/src/executors/cypress/cypress.impl.js +152 -6
  12. package/src/executors/cypress/schema.json +1 -11
  13. package/src/generators/base-setup/base-setup.d.ts +0 -1
  14. package/src/generators/base-setup/base-setup.js +3 -26
  15. package/src/generators/component-configuration/component-configuration.d.ts +2 -3
  16. package/src/generators/component-configuration/component-configuration.js +27 -50
  17. package/src/generators/component-configuration/files/__directory__/support/component-index.html +1 -4
  18. package/src/generators/component-configuration/schema.d.ts +0 -7
  19. package/src/generators/component-configuration/schema.json +1 -1
  20. package/src/generators/configuration/configuration.d.ts +0 -4
  21. package/src/generators/configuration/configuration.js +26 -90
  22. package/src/generators/configuration/schema.json +1 -1
  23. package/src/generators/cypress-project/cypress-project.js +5 -25
  24. package/src/generators/cypress-project/schema.d.ts +0 -1
  25. package/src/generators/cypress-project/schema.json +1 -1
  26. package/src/generators/init/init.d.ts +0 -2
  27. package/src/generators/init/init.js +15 -71
  28. package/src/generators/init/schema.d.ts +2 -4
  29. package/src/generators/init/schema.json +1 -19
  30. package/src/generators/migrate-to-cypress-11/schema.json +1 -1
  31. package/src/utils/add-linter.d.ts +0 -1
  32. package/src/utils/add-linter.js +4 -4
  33. package/src/utils/config.d.ts +7 -6
  34. package/src/utils/config.js +12 -39
  35. package/src/utils/ct-helpers.d.ts +1 -1
  36. package/src/utils/ct-helpers.js +2 -6
  37. package/src/utils/versions.d.ts +3 -3
  38. package/src/utils/versions.js +3 -3
  39. package/plugin.d.ts +0 -1
  40. package/plugin.js +0 -6
  41. package/src/generators/base-setup/files/config-js-cjs/__directory__/support/commands.js__ext__ +0 -35
  42. package/src/generators/base-setup/files/config-js-cjs/cypress.config.js__ext__ +0 -3
  43. package/src/generators/base-setup/files/config-js-esm/__directory__/support/commands.js__ext__ +0 -35
  44. package/src/generators/base-setup/files/config-js-esm/cypress.config.js__ext__ +0 -3
  45. package/src/generators/base-setup/files/config-ts/__directory__/support/commands.ts__ext__ +0 -35
  46. package/src/migrations/update-18-1-0/update-cypress-version-13-6-6.d.ts +0 -2
  47. package/src/migrations/update-18-1-0/update-cypress-version-13-6-6.js +0 -12
  48. package/src/plugins/plugin.d.ts +0 -9
  49. package/src/plugins/plugin.js +0 -227
  50. package/src/utils/constants.d.ts +0 -4
  51. package/src/utils/constants.js +0 -7
  52. package/src/utils/start-dev-server.d.ts +0 -9
  53. package/src/utils/start-dev-server.js +0 -157
  54. /package/src/generators/base-setup/files/{common/__directory__ → __directory__}/fixtures/example.json +0 -0
  55. /package/src/generators/base-setup/files/{common/__directory__ → __directory__}/support/commands.ts__ext__ +0 -0
  56. /package/src/generators/base-setup/files/{common/__directory__ → __directory__}/tsconfig.json__ext__ +0 -0
  57. /package/src/generators/base-setup/files/{config-ts/cypress.config.ts__ext__ → cypress.config.ts__ext__} +0 -0
@@ -1,6 +1,5 @@
1
- import { ProjectConfiguration, Tree, GeneratorCallback } from '@nx/devkit';
1
+ import { ProjectConfiguration, Tree } from '@nx/devkit';
2
2
  import { CypressComponentConfigurationSchema } from './schema';
3
- export declare function componentConfigurationGenerator(tree: Tree, options: CypressComponentConfigurationSchema): Promise<GeneratorCallback>;
4
- export declare function componentConfigurationGeneratorInternal(tree: Tree, options: CypressComponentConfigurationSchema): Promise<GeneratorCallback>;
3
+ export declare function componentConfigurationGenerator(tree: Tree, options: CypressComponentConfigurationSchema): Promise<() => void>;
5
4
  export declare function updateTsConfigForComponentTesting(tree: Tree, projectConfig: ProjectConfiguration): void;
6
5
  export default componentConfigurationGenerator;
@@ -1,55 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateTsConfigForComponentTesting = exports.componentConfigurationGeneratorInternal = exports.componentConfigurationGenerator = void 0;
3
+ exports.updateTsConfigForComponentTesting = exports.componentConfigurationGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const cypress_version_1 = require("../../utils/cypress-version");
6
6
  const versions_1 = require("../../utils/versions");
7
7
  const base_setup_1 = require("../base-setup/base-setup");
8
- const init_1 = require("../init/init");
9
- function componentConfigurationGenerator(tree, options) {
10
- return componentConfigurationGeneratorInternal(tree, {
11
- addPlugin: false,
12
- ...options,
13
- });
14
- }
15
- exports.componentConfigurationGenerator = componentConfigurationGenerator;
16
- async function componentConfigurationGeneratorInternal(tree, options) {
17
- const tasks = [];
18
- const opts = normalizeOptions(tree, options);
19
- tasks.push(await (0, init_1.default)(tree, {
20
- ...opts,
21
- skipFormat: true,
22
- }));
23
- const nxJson = (0, devkit_1.readNxJson)(tree);
24
- const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
25
- ? p === '@nx/cypress/plugin'
26
- : p.plugin === '@nx/cypress/plugin');
8
+ async function componentConfigurationGenerator(tree, options) {
9
+ const opts = normalizeOptions(options);
27
10
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, opts.project);
28
- tasks.push(updateDeps(tree, opts));
11
+ const installDepsTask = updateDeps(tree, opts);
29
12
  addProjectFiles(tree, projectConfig, opts);
30
- if (!hasPlugin || opts.addExplicitTargets) {
31
- addTargetToProject(tree, projectConfig, opts);
32
- }
33
- updateNxJsonConfiguration(tree, hasPlugin);
13
+ addTargetToProject(tree, projectConfig, opts);
14
+ updateNxJsonConfiguration(tree);
34
15
  updateTsConfigForComponentTesting(tree, projectConfig);
35
16
  if (!opts.skipFormat) {
36
17
  await (0, devkit_1.formatFiles)(tree);
37
18
  }
38
- return (0, devkit_1.runTasksInSerial)(...tasks);
19
+ return () => {
20
+ installDepsTask();
21
+ };
39
22
  }
40
- exports.componentConfigurationGeneratorInternal = componentConfigurationGeneratorInternal;
41
- function normalizeOptions(tree, options) {
23
+ exports.componentConfigurationGenerator = componentConfigurationGenerator;
24
+ function normalizeOptions(options) {
42
25
  const cyVersion = (0, cypress_version_1.installedCypressVersion)();
43
26
  if (cyVersion && cyVersion < 10) {
44
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');
45
28
  }
46
- const nxJson = (0, devkit_1.readNxJson)(tree);
47
- const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
48
- nxJson.useInferencePlugins !== false;
49
29
  return {
50
- addPlugin,
51
30
  ...options,
52
- framework: options.framework ?? null,
53
31
  directory: options.directory ?? 'cypress',
54
32
  };
55
33
  }
@@ -89,26 +67,25 @@ function addTargetToProject(tree, projectConfig, opts) {
89
67
  };
90
68
  (0, devkit_1.updateProjectConfiguration)(tree, opts.project, projectConfig);
91
69
  }
92
- function updateNxJsonConfiguration(tree, hasPlugin) {
70
+ function updateNxJsonConfiguration(tree) {
93
71
  const nxJson = (0, devkit_1.readNxJson)(tree);
94
- const productionFileSet = nxJson.namedInputs?.production;
95
- if (productionFileSet) {
96
- nxJson.namedInputs.production = Array.from(new Set([
97
- ...productionFileSet,
98
- '!{projectRoot}/cypress/**/*',
99
- '!{projectRoot}/**/*.cy.[jt]s?(x)',
100
- '!{projectRoot}/cypress.config.[jt]s',
101
- ]));
72
+ const cacheableOperations = nxJson.tasksRunnerOptions?.default?.options?.cacheableOperations;
73
+ if (cacheableOperations && !cacheableOperations.includes('component-test')) {
74
+ cacheableOperations.push('component-test');
102
75
  }
103
- if (!hasPlugin) {
104
- const cacheableOperations = nxJson.tasksRunnerOptions?.default?.options?.cacheableOperations;
105
- if (cacheableOperations &&
106
- !cacheableOperations.includes('component-test')) {
107
- cacheableOperations.push('component-test');
76
+ nxJson.targetDefaults ??= {};
77
+ nxJson.targetDefaults['component-test'] ??= {};
78
+ nxJson.targetDefaults['component-test'].cache ??= true;
79
+ if (nxJson.namedInputs) {
80
+ const productionFileSet = nxJson.namedInputs?.production;
81
+ if (productionFileSet) {
82
+ nxJson.namedInputs.production = Array.from(new Set([
83
+ ...productionFileSet,
84
+ '!{projectRoot}/cypress/**/*',
85
+ '!{projectRoot}/**/*.cy.[jt]s?(x)',
86
+ '!{projectRoot}/cypress.config.[jt]s',
87
+ ]));
108
88
  }
109
- nxJson.targetDefaults ??= {};
110
- nxJson.targetDefaults['component-test'] ??= {};
111
- nxJson.targetDefaults['component-test'].cache ??= true;
112
89
  nxJson.targetDefaults['component-test'] ??= {};
113
90
  nxJson.targetDefaults['component-test'].inputs ??= [
114
91
  'default',
@@ -5,10 +5,7 @@
5
5
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
6
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
7
7
  <title><%= project %> Components App</title>
8
- <% if(framework === 'next') { %>
9
- <!-- Used by Next.js to inject CSS. -->
10
- <div id="__next_css__DO_NOT_USE__"></div>
11
- <% } %>
8
+
12
9
  </head>
13
10
  <body>
14
11
  <div data-cy-root></div>
@@ -4,11 +4,4 @@ export interface CypressComponentConfigurationSchema {
4
4
  directory?: string;
5
5
  bundler?: 'webpack' | 'vite';
6
6
  jsx?: boolean;
7
- addPlugin?: boolean;
8
-
9
- /**
10
- * @internal
11
- */
12
- addExplicitTargets?: boolean;
13
- framework?: 'next';
14
7
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "$id": "NxCypressComponentConfiguration",
4
4
  "cli": "nx",
5
5
  "title": "Set up Cypress component testing for a project",
@@ -14,10 +14,6 @@ export interface CypressE2EConfigSchema {
14
14
  port?: number | 'cypress-auto';
15
15
  jsx?: boolean;
16
16
  rootProject?: boolean;
17
- webServerCommands?: Record<string, string>;
18
- ciWebServerCommand?: string;
19
- addPlugin?: boolean;
20
17
  }
21
18
  export declare function configurationGenerator(tree: Tree, options: CypressE2EConfigSchema): Promise<GeneratorCallback>;
22
- export declare function configurationGeneratorInternal(tree: Tree, options: CypressE2EConfigSchema): Promise<GeneratorCallback>;
23
19
  export default configurationGenerator;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.configurationGeneratorInternal = exports.configurationGenerator = void 0;
3
+ exports.configurationGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const js_1 = require("@nx/js");
6
6
  const eslint_1 = require("@nx/eslint");
@@ -11,59 +11,28 @@ const cypress_version_1 = require("../../utils/cypress-version");
11
11
  const versions_1 = require("../../utils/versions");
12
12
  const init_1 = require("../init/init");
13
13
  const base_setup_1 = require("../base-setup/base-setup");
14
- function configurationGenerator(tree, options) {
15
- return configurationGeneratorInternal(tree, {
16
- addPlugin: false,
17
- ...options,
18
- });
19
- }
20
- exports.configurationGenerator = configurationGenerator;
21
- async function configurationGeneratorInternal(tree, options) {
14
+ async function configurationGenerator(tree, options) {
22
15
  const opts = normalizeOptions(tree, options);
23
- opts.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
24
16
  const tasks = [];
25
17
  if (!(0, cypress_version_1.installedCypressVersion)()) {
26
- tasks.push(await (0, js_1.initGenerator)(tree, { ...options, skipFormat: true }));
27
- tasks.push(await (0, init_1.default)(tree, {
28
- ...opts,
29
- skipFormat: true,
30
- }));
18
+ tasks.push(await (0, init_1.default)(tree, opts));
31
19
  }
32
- else if (opts.addPlugin) {
33
- (0, init_1.addPlugin)(tree);
34
- }
35
- const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
36
- const nxJson = (0, devkit_1.readNxJson)(tree);
37
- const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
38
- ? p === '@nx/cypress/plugin'
39
- : p.plugin === '@nx/cypress/plugin');
40
- await addFiles(tree, opts, projectGraph, hasPlugin);
41
- if (!hasPlugin) {
42
- addTarget(tree, opts);
20
+ if (opts.bundler === 'vite') {
21
+ tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, { vite: versions_1.viteVersion }));
43
22
  }
23
+ await addFiles(tree, opts);
24
+ addTarget(tree, opts);
44
25
  const linterTask = await (0, add_linter_1.addLinterToCyProject)(tree, {
45
26
  ...opts,
46
27
  cypressDir: opts.directory,
47
28
  });
48
29
  tasks.push(linterTask);
49
- if (!opts.skipPackageJson) {
50
- tasks.push(ensureDependencies(tree, opts));
51
- }
52
30
  if (!opts.skipFormat) {
53
31
  await (0, devkit_1.formatFiles)(tree);
54
32
  }
55
33
  return (0, devkit_1.runTasksInSerial)(...tasks);
56
34
  }
57
- exports.configurationGeneratorInternal = configurationGeneratorInternal;
58
- function ensureDependencies(tree, options) {
59
- const devDependencies = {
60
- '@types/node': versions_1.typesNodeVersion,
61
- };
62
- if (options.bundler === 'vite') {
63
- devDependencies['vite'] = versions_1.viteVersion;
64
- }
65
- return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies);
66
- }
35
+ exports.configurationGenerator = configurationGenerator;
67
36
  function normalizeOptions(tree, options) {
68
37
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
69
38
  if (projectConfig?.targets?.e2e) {
@@ -72,29 +41,21 @@ Rename or remove the existing e2e target.`);
72
41
  }
73
42
  if (!options.baseUrl &&
74
43
  !options.devServerTarget &&
75
- !projectConfig?.targets?.serve) {
44
+ !projectConfig.targets.serve) {
76
45
  throw new Error(`The project ${options.project} does not have a 'serve' target.
77
46
  In this case you need to provide a devServerTarget,'<projectName>:<targetName>[:<configName>]', or a baseUrl option`);
78
47
  }
79
48
  options.directory ??= 'src';
80
- const devServerTarget = options.devServerTarget ??
81
- (projectConfig?.targets?.serve ? `${options.project}:serve` : undefined);
82
- if (!options.baseUrl && !devServerTarget) {
83
- throw new Error('Either baseUrl or devServerTarget must be provided');
84
- }
85
- const nxJson = (0, devkit_1.readNxJson)(tree);
86
- options.addPlugin ??=
87
- process.env.NX_ADD_PLUGINS !== 'false' &&
88
- nxJson.useInferencePlugins !== false;
89
49
  return {
90
50
  ...options,
91
51
  bundler: options.bundler ?? 'webpack',
92
52
  rootProject: options.rootProject ?? projectConfig.root === '.',
93
53
  linter: options.linter ?? eslint_1.Linter.EsLint,
94
- devServerTarget,
54
+ devServerTarget: options.devServerTarget ??
55
+ (projectConfig.targets.serve ? `${options.project}:serve` : undefined),
95
56
  };
96
57
  }
97
- async function addFiles(tree, options, projectGraph, hasPlugin) {
58
+ async function addFiles(tree, options) {
98
59
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
99
60
  const cyVersion = (0, cypress_version_1.installedCypressVersion)();
100
61
  const filesToUse = cyVersion && cyVersion < 10 ? 'v9' : 'v10';
@@ -121,37 +82,12 @@ async function addFiles(tree, options, projectGraph, hasPlugin) {
121
82
  project: options.project,
122
83
  directory: options.directory,
123
84
  jsx: options.jsx,
124
- js: options.js,
125
85
  });
126
- const cyFile = (0, devkit_1.joinPathFragments)(projectConfig.root, options.js ? 'cypress.config.js' : 'cypress.config.ts');
127
- let webServerCommands;
128
- let ciWebServerCommand;
129
- if (hasPlugin && options.webServerCommands && options.ciWebServerCommand) {
130
- webServerCommands = options.webServerCommands;
131
- ciWebServerCommand = options.ciWebServerCommand;
132
- }
133
- else if (hasPlugin && options.devServerTarget) {
134
- webServerCommands = {};
135
- webServerCommands.default = 'nx run ' + options.devServerTarget;
136
- const parsedTarget = (0, devkit_1.parseTargetString)(options.devServerTarget, projectGraph);
137
- const devServerProjectConfig = (0, devkit_1.readProjectConfiguration)(tree, parsedTarget.project);
138
- // Add production e2e target if serve target is found
139
- if (parsedTarget.configuration !== 'production' &&
140
- devServerProjectConfig?.targets?.[parsedTarget.target]
141
- ?.configurations?.['production']) {
142
- webServerCommands.production = `nx run ${parsedTarget.project}:${parsedTarget.target}:production`;
143
- }
144
- // Add ci/static e2e target if serve target is found
145
- if (devServerProjectConfig?.targets?.['serve-static']) {
146
- ciWebServerCommand = `nx run ${parsedTarget.project}:serve-static`;
147
- }
148
- }
86
+ const cyFile = (0, devkit_1.joinPathFragments)(projectConfig.root, 'cypress.config.ts');
149
87
  const updatedCyConfig = await (0, config_1.addDefaultE2EConfig)(tree.read(cyFile, 'utf-8'), {
150
- cypressDir: options.directory,
151
- bundler: options.bundler === 'vite' ? 'vite' : undefined,
152
- webServerCommands,
153
- ciWebServerCommand: ciWebServerCommand,
154
- }, options.baseUrl);
88
+ directory: options.directory,
89
+ bundler: options.bundler,
90
+ });
155
91
  tree.write(cyFile, updatedCyConfig);
156
92
  }
157
93
  if (cyVersion &&
@@ -175,17 +111,20 @@ async function addFiles(tree, options, projectGraph, hasPlugin) {
175
111
  function addTarget(tree, opts) {
176
112
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, opts.project);
177
113
  const cyVersion = (0, cypress_version_1.installedCypressVersion)();
178
- projectConfig.targets ??= {};
179
114
  projectConfig.targets.e2e = {
180
115
  executor: '@nx/cypress:cypress',
181
116
  options: {
182
- cypressConfig: (0, devkit_1.joinPathFragments)(projectConfig.root, cyVersion && cyVersion < 10
183
- ? 'cypress.json'
184
- : `cypress.config.${opts.js ? 'js' : 'ts'}`),
117
+ cypressConfig: (0, devkit_1.joinPathFragments)(projectConfig.root, cyVersion && cyVersion < 10 ? 'cypress.json' : 'cypress.config.ts'),
185
118
  testingType: 'e2e',
186
119
  },
187
120
  };
188
- if (opts.devServerTarget) {
121
+ if (opts.baseUrl) {
122
+ projectConfig.targets.e2e.options = {
123
+ ...projectConfig.targets.e2e.options,
124
+ baseUrl: opts.baseUrl,
125
+ };
126
+ }
127
+ else if (opts.devServerTarget) {
189
128
  const parsedTarget = (0, devkit_1.parseTargetString)(opts.devServerTarget);
190
129
  projectConfig.targets.e2e.options = {
191
130
  ...projectConfig.targets.e2e.options,
@@ -209,11 +148,8 @@ function addTarget(tree, opts) {
209
148
  };
210
149
  }
211
150
  }
212
- else if (opts.baseUrl) {
213
- projectConfig.targets.e2e.options = {
214
- ...projectConfig.targets.e2e.options,
215
- baseUrl: opts.baseUrl,
216
- };
151
+ else {
152
+ throw new Error('Either baseUrl or devServerTarget must be provided');
217
153
  }
218
154
  (0, devkit_1.updateProjectConfiguration)(tree, opts.project, projectConfig);
219
155
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "$id": "NxCypressE2EConfigGenerator",
4
4
  "cli": "nx",
5
5
  "title": "Add a Cypress Configuration.",
@@ -12,7 +12,6 @@ const add_linter_1 = require("../../utils/add-linter");
12
12
  const cypress_version_1 = require("../../utils/cypress-version");
13
13
  const versions_1 = require("../../utils/versions");
14
14
  const init_1 = require("../init/init");
15
- const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
16
15
  function createFiles(tree, options) {
17
16
  // if not installed or >v10 use v10 folder
18
17
  // else use v9 folder
@@ -120,7 +119,6 @@ function addProject(tree, options) {
120
119
  async function cypressProjectGenerator(host, schema) {
121
120
  return await cypressProjectGeneratorInternal(host, {
122
121
  projectNameAndRootFormat: 'derived',
123
- addPlugin: false,
124
122
  ...schema,
125
123
  });
126
124
  }
@@ -135,11 +133,11 @@ async function cypressProjectGeneratorInternal(host, schema) {
135
133
  // if there is an installed cypress version, then we don't call
136
134
  // init since we want to keep the existing version that is installed
137
135
  if (!cypressVersion) {
138
- tasks.push(await (0, js_1.initGenerator)(host, { ...options, skipFormat: true }));
139
- tasks.push(await (0, init_1.cypressInitGenerator)(host, {
140
- ...options,
141
- skipFormat: true,
142
- addPlugin: options.addPlugin,
136
+ tasks.push(await (0, init_1.cypressInitGenerator)(host, options));
137
+ }
138
+ if (schema.bundler === 'vite') {
139
+ tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {}, {
140
+ vite: versions_1.viteVersion,
143
141
  }));
144
142
  }
145
143
  createFiles(host, options);
@@ -152,29 +150,12 @@ async function cypressProjectGeneratorInternal(host, schema) {
152
150
  overwriteExisting: true,
153
151
  });
154
152
  tasks.push(installTask);
155
- if (!options.skipPackageJson) {
156
- tasks.push(ensureDependencies(host, options));
157
- }
158
153
  if (!options.skipFormat) {
159
154
  await (0, devkit_1.formatFiles)(host);
160
155
  }
161
156
  return (0, devkit_1.runTasksInSerial)(...tasks);
162
157
  }
163
158
  exports.cypressProjectGeneratorInternal = cypressProjectGeneratorInternal;
164
- function ensureDependencies(tree, options) {
165
- const devDependencies = {
166
- '@types/node': versions_1.typesNodeVersion,
167
- };
168
- if (options.bundler === 'vite') {
169
- devDependencies['vite'] = versions_1.viteVersion;
170
- }
171
- return (0, devkit_1.runTasksInSerial)(...[
172
- (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies),
173
- () => {
174
- (0, log_show_project_command_1.logShowProjectCommand)(options.projectName);
175
- },
176
- ]);
177
- }
178
159
  async function normalizeOptions(host, options) {
179
160
  let maybeRootProject;
180
161
  let isRootProject = false;
@@ -201,7 +182,6 @@ async function normalizeOptions(host, options) {
201
182
  });
202
183
  options.linter = options.linter || eslint_1.Linter.EsLint;
203
184
  options.bundler = options.bundler || 'webpack';
204
- options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
205
185
  return {
206
186
  ...options,
207
187
  // other generators depend on the rootProject flag down stream
@@ -13,5 +13,4 @@ export interface Schema {
13
13
  setParserOptionsProject?: boolean;
14
14
  skipPackageJson?: boolean;
15
15
  bundler?: 'webpack' | 'vite' | 'none';
16
- addPlugin?: boolean;
17
16
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "$id": "NxCypressProjectGeneratorSchema",
4
4
  "cli": "nx",
5
5
  "title": "Create Cypress Configuration for the workspace",
@@ -1,6 +1,4 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { Schema } from './schema';
3
- export declare function addPlugin(tree: Tree): void;
4
3
  export declare function cypressInitGenerator(tree: Tree, options: Schema): Promise<GeneratorCallback>;
5
- export declare function cypressInitGeneratorInternal(tree: Tree, options: Schema): Promise<GeneratorCallback>;
6
4
  export default cypressInitGenerator;
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cypressInitGeneratorInternal = exports.cypressInitGenerator = exports.addPlugin = void 0;
3
+ exports.cypressInitGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
6
- const plugin_1 = require("../../plugins/plugin");
7
5
  const versions_1 = require("../../utils/versions");
6
+ const js_1 = require("@nx/js");
8
7
  function setupE2ETargetDefaults(tree) {
9
8
  const nxJson = (0, devkit_1.readNxJson)(tree);
10
9
  if (!nxJson.namedInputs) {
@@ -14,86 +13,31 @@ function setupE2ETargetDefaults(tree) {
14
13
  nxJson.targetDefaults ??= {};
15
14
  const productionFileSet = !!nxJson.namedInputs?.production;
16
15
  nxJson.targetDefaults.e2e ??= {};
17
- nxJson.targetDefaults.e2e.cache ??= true;
18
16
  nxJson.targetDefaults.e2e.inputs ??= [
19
17
  'default',
20
18
  productionFileSet ? '^production' : '^default',
21
19
  ];
22
20
  (0, devkit_1.updateNxJson)(tree, nxJson);
23
21
  }
24
- function updateDependencies(tree, options) {
25
- const tasks = [];
26
- tasks.push((0, devkit_1.removeDependenciesFromPackageJson)(tree, ['@nx/cypress'], []));
27
- tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
22
+ function updateDependencies(tree) {
23
+ (0, devkit_1.removeDependenciesFromPackageJson)(tree, ['@nx/cypress'], []);
24
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
28
25
  ['@nx/cypress']: versions_1.nxVersion,
29
26
  cypress: versions_1.cypressVersion,
30
- }, undefined, options.keepExistingVersions));
31
- return (0, devkit_1.runTasksInSerial)(...tasks);
32
- }
33
- function addPlugin(tree) {
34
- const nxJson = (0, devkit_1.readNxJson)(tree);
35
- nxJson.plugins ??= [];
36
- for (const plugin of nxJson.plugins) {
37
- if (typeof plugin === 'string'
38
- ? plugin === '@nx/cypress/plugin'
39
- : plugin.plugin === '@nx/cypress/plugin') {
40
- return;
41
- }
42
- }
43
- nxJson.plugins.push({
44
- plugin: '@nx/cypress/plugin',
45
- options: {
46
- targetName: 'e2e',
47
- componentTestingTargetName: 'component-test',
48
- ciTargetName: 'e2e-ci',
49
- openTargetName: 'open-cypress',
50
- },
27
+ '@types/node': versions_1.typesNodeVersion,
51
28
  });
52
- (0, devkit_1.updateNxJson)(tree, nxJson);
53
- }
54
- exports.addPlugin = addPlugin;
55
- function updateProductionFileset(tree) {
56
- const nxJson = (0, devkit_1.readNxJson)(tree);
57
- const productionFileset = nxJson.namedInputs?.production;
58
- if (productionFileset) {
59
- nxJson.namedInputs.production = Array.from(new Set([
60
- ...productionFileset,
61
- '!{projectRoot}/cypress/**/*',
62
- '!{projectRoot}/**/*.cy.[jt]s?(x)',
63
- '!{projectRoot}/cypress.config.[jt]s',
64
- ]));
65
- }
66
- (0, devkit_1.updateNxJson)(tree, nxJson);
67
29
  }
68
30
  async function cypressInitGenerator(tree, options) {
69
- return cypressInitGeneratorInternal(tree, { addPlugin: false, ...options });
70
- }
71
- exports.cypressInitGenerator = cypressInitGenerator;
72
- async function cypressInitGeneratorInternal(tree, options) {
73
- updateProductionFileset(tree);
74
- const nxJson = (0, devkit_1.readNxJson)(tree);
75
- options.addPlugin ??=
76
- process.env.NX_ADD_PLUGINS !== 'false' &&
77
- nxJson.useInferencePlugins !== false;
78
- if (options.addPlugin) {
79
- addPlugin(tree);
80
- }
81
- else {
82
- setupE2ETargetDefaults(tree);
83
- }
84
- let installTask = () => { };
31
+ setupE2ETargetDefaults(tree);
32
+ const tasks = [];
33
+ tasks.push(await (0, js_1.initGenerator)(tree, {
34
+ ...options,
35
+ skipFormat: true,
36
+ }));
85
37
  if (!options.skipPackageJson) {
86
- installTask = updateDependencies(tree, options);
87
- }
88
- if (options.updatePackageScripts) {
89
- global.NX_CYPRESS_INIT_GENERATOR_RUNNING = true;
90
- await (0, update_package_scripts_1.updatePackageScripts)(tree, plugin_1.createNodes);
91
- global.NX_CYPRESS_INIT_GENERATOR_RUNNING = false;
92
- }
93
- if (!options.skipFormat) {
94
- await (0, devkit_1.formatFiles)(tree);
38
+ tasks.push(updateDependencies(tree));
95
39
  }
96
- return installTask;
40
+ return (0, devkit_1.runTasksInSerial)(...tasks);
97
41
  }
98
- exports.cypressInitGeneratorInternal = cypressInitGeneratorInternal;
42
+ exports.cypressInitGenerator = cypressInitGenerator;
99
43
  exports.default = cypressInitGenerator;
@@ -1,7 +1,5 @@
1
1
  export interface Schema {
2
- skipFormat?: boolean;
3
2
  skipPackageJson?: boolean;
4
- keepExistingVersions?: boolean;
5
- updatePackageScripts?: boolean;
6
- addPlugin?: boolean;
3
+
4
+ skipFormat?: boolean;
7
5
  }
@@ -1,34 +1,16 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "$id": "NxCypressInit",
4
4
  "cli": "nx",
5
5
  "title": "Add Cypress Configuration to the workspace",
6
6
  "description": "Add Cypress Configuration to the workspace.",
7
7
  "type": "object",
8
8
  "properties": {
9
- "skipFormat": {
10
- "description": "Skip formatting files.",
11
- "type": "boolean",
12
- "default": false,
13
- "x-priority": "internal"
14
- },
15
9
  "skipPackageJson": {
16
10
  "type": "boolean",
17
11
  "default": false,
18
12
  "description": "Do not add dependencies to `package.json`.",
19
13
  "x-priority": "internal"
20
- },
21
- "keepExistingVersions": {
22
- "type": "boolean",
23
- "x-priority": "internal",
24
- "description": "Keep existing dependencies versions",
25
- "default": false
26
- },
27
- "updatePackageScripts": {
28
- "type": "boolean",
29
- "x-priority": "internal",
30
- "description": "Update `package.json` scripts with inferred targets",
31
- "default": false
32
14
  }
33
15
  }
34
16
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "$id": "NxCypressMigrateTo11",
4
4
  "cli": "nx",
5
5
  "title": "Migrate e2e project to Cypress 11",
@@ -17,6 +17,5 @@ export interface CyLinterOptions {
17
17
  * This is useful when adding linting to a brand new project vs an existing one
18
18
  **/
19
19
  overwriteExisting?: boolean;
20
- addPlugin?: boolean;
21
20
  }
22
21
  export declare function addLinterToCyProject(tree: Tree, options: CyLinterOptions): Promise<() => void>;