@nx/cypress 21.0.0-beta.0 → 21.0.0-beta.10

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 (28) hide show
  1. package/migrations.json +57 -24
  2. package/package.json +7 -5
  3. package/plugins/cypress-preset.js +12 -5
  4. package/src/executors/cypress/cypress.impl.js +17 -17
  5. package/src/generators/component-configuration/component-configuration.d.ts +1 -1
  6. package/src/generators/component-configuration/component-configuration.js +14 -11
  7. package/src/generators/configuration/configuration.js +11 -11
  8. package/src/generators/migrate-to-cypress-11/migrate-to-cypress-11.js +3 -3
  9. package/src/migrations/update-20-8-0/remove-experimental-fetch-polyfill.js +48 -0
  10. package/src/migrations/update-20-8-0/replace-experimental-just-in-time-compile.d.ts +2 -0
  11. package/src/migrations/update-20-8-0/replace-experimental-just-in-time-compile.js +94 -0
  12. package/src/migrations/update-20-8-0/set-inject-document-domain.d.ts +2 -0
  13. package/src/migrations/update-20-8-0/set-inject-document-domain.js +160 -0
  14. package/src/migrations/update-20-8-0/update-component-testing-mount-imports.d.ts +2 -0
  15. package/src/migrations/update-20-8-0/update-component-testing-mount-imports.js +151 -0
  16. package/src/plugins/plugin.js +68 -6
  17. package/src/utils/add-linter.js +7 -7
  18. package/src/utils/config.d.ts +2 -0
  19. package/src/utils/config.js +46 -0
  20. package/src/utils/cypress-version.d.ts +6 -0
  21. package/src/utils/cypress-version.js +6 -0
  22. package/src/utils/migrations.d.ts +13 -0
  23. package/src/utils/migrations.js +71 -0
  24. package/src/utils/start-dev-server.js +1 -1
  25. package/src/utils/versions.d.ts +17 -4
  26. package/src/utils/versions.js +83 -4
  27. package/src/migrations/update-18-1-0/update-cypress-version-13-6-6.js +0 -12
  28. /package/src/migrations/{update-18-1-0/update-cypress-version-13-6-6.d.ts → update-20-8-0/remove-experimental-fetch-polyfill.d.ts} +0 -0
package/migrations.json CHANGED
@@ -1,37 +1,49 @@
1
1
  {
2
2
  "generators": {
3
- "update-cypress-version-13-6-6": {
4
- "cli": "nx",
5
- "version": "18.1.0-beta.3",
6
- "description": "Update to Cypress ^13.6.6 if the workspace is using Cypress v13 to ensure workspaces don't use v13.6.5 which has an issue when verifying Cypress.",
7
- "implementation": "./src/migrations/update-18-1-0/update-cypress-version-13-6-6"
8
- },
9
3
  "update-19-6-0-update-ci-webserver-for-vite": {
10
4
  "cli": "nx",
11
5
  "version": "19.6.0-beta.4",
12
6
  "description": "Update ciWebServerCommand to use static serve for the application.",
13
7
  "implementation": "./src/migrations/update-19-6-0/update-ci-webserver-for-static-serve"
8
+ },
9
+ "set-inject-document-domain": {
10
+ "cli": "nx",
11
+ "version": "20.8.0-beta.0",
12
+ "requires": {
13
+ "cypress": ">=14.0.0"
14
+ },
15
+ "description": "Replaces the `experimentalSkipDomainInjection` configuration option with the new `injectDocumentDomain` configuration option.",
16
+ "implementation": "./src/migrations/update-20-8-0/set-inject-document-domain"
17
+ },
18
+ "remove-experimental-fetch-polyfill": {
19
+ "cli": "nx",
20
+ "version": "20.8.0-beta.0",
21
+ "requires": {
22
+ "cypress": ">=14.0.0"
23
+ },
24
+ "description": "Removes the `experimentalFetchPolyfill` configuration option.",
25
+ "implementation": "./src/migrations/update-20-8-0/remove-experimental-fetch-polyfill"
26
+ },
27
+ "replace-experimental-just-in-time-compile": {
28
+ "cli": "nx",
29
+ "version": "20.8.0-beta.0",
30
+ "requires": {
31
+ "cypress": ">=14.0.0"
32
+ },
33
+ "description": "Replaces the `experimentalJustInTimeCompile` configuration option with the new `justInTimeCompile` configuration option.",
34
+ "implementation": "./src/migrations/update-20-8-0/replace-experimental-just-in-time-compile"
35
+ },
36
+ "update-component-testing-mount-imports": {
37
+ "cli": "nx",
38
+ "version": "20.8.0-beta.0",
39
+ "requires": {
40
+ "cypress": ">=14.0.0"
41
+ },
42
+ "description": "Updates the module specifier for the Component Testing `mount` function.",
43
+ "implementation": "./src/migrations/update-20-8-0/update-component-testing-mount-imports"
14
44
  }
15
45
  },
16
46
  "packageJsonUpdates": {
17
- "17.2.0-beta.2": {
18
- "version": "17.2.0-beta.2",
19
- "packages": {
20
- "vite": {
21
- "version": "^5.0.0",
22
- "alwaysAddToPackageJson": false
23
- }
24
- }
25
- },
26
- "17.3.0": {
27
- "version": "17.3.0-beta.3",
28
- "packages": {
29
- "@types/node": {
30
- "version": "18.16.9",
31
- "alwaysAddToPackageJson": false
32
- }
33
- }
34
- },
35
47
  "19.1.0": {
36
48
  "version": "19.1.0-beta.0",
37
49
  "requires": {
@@ -59,6 +71,27 @@
59
71
  "alwaysAddToPackageJson": false
60
72
  }
61
73
  }
74
+ },
75
+ "20.8.0": {
76
+ "version": "20.8.0-beta.0",
77
+ "x-prompt": "Do you want to update the Cypress version to v14?",
78
+ "requires": {
79
+ "cypress": ">=13.0.0 <14.0.0"
80
+ },
81
+ "packages": {
82
+ "cypress": {
83
+ "version": "^14.2.1",
84
+ "alwaysAddToPackageJson": false
85
+ },
86
+ "@cypress/vite-dev-server": {
87
+ "version": "^6.0.3",
88
+ "alwaysAddToPackageJson": false
89
+ },
90
+ "@cypress/webpack-dev-server": {
91
+ "version": "^4.0.2",
92
+ "alwaysAddToPackageJson": false
93
+ }
94
+ }
62
95
  }
63
96
  }
64
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/cypress",
3
- "version": "21.0.0-beta.0",
3
+ "version": "21.0.0-beta.10",
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": {
@@ -36,15 +36,17 @@
36
36
  "migrations": "./migrations.json"
37
37
  },
38
38
  "dependencies": {
39
- "@nx/devkit": "21.0.0-beta.0",
40
- "@nx/eslint": "21.0.0-beta.0",
41
- "@nx/js": "21.0.0-beta.0",
39
+ "@nx/devkit": "21.0.0-beta.10",
40
+ "@nx/eslint": "21.0.0-beta.10",
41
+ "@nx/js": "21.0.0-beta.10",
42
42
  "@phenomnomnominal/tsquery": "~5.0.1",
43
43
  "detect-port": "^1.5.1",
44
+ "semver": "^7.6.3",
45
+ "tree-kill": "1.2.2",
44
46
  "tslib": "^2.3.0"
45
47
  },
46
48
  "peerDependencies": {
47
- "cypress": ">= 3 < 14"
49
+ "cypress": ">= 3 < 15"
48
50
  },
49
51
  "peerDependenciesMeta": {
50
52
  "cypress": {
@@ -11,6 +11,7 @@ const https_1 = require("https");
11
11
  const path_1 = require("path");
12
12
  const preprocessor_vite_1 = require("../src/plugins/preprocessor-vite");
13
13
  const constants_1 = require("../src/utils/constants");
14
+ const treeKill = require("tree-kill");
14
15
  function nxBaseCypressPreset(pathToConfig, options) {
15
16
  // used to set babel settings for react CT.
16
17
  process.env.NX_CYPRESS_COMPONENT_TEST =
@@ -45,7 +46,7 @@ function startWebServer(webServerCommand) {
45
46
  stdio: 'inherit',
46
47
  windowsHide: false,
47
48
  });
48
- return () => {
49
+ return async () => {
49
50
  if (process.platform === 'win32') {
50
51
  try {
51
52
  (0, child_process_1.execSync)('taskkill /pid ' + serverProcess.pid + ' /T /F', {
@@ -59,9 +60,14 @@ function startWebServer(webServerCommand) {
59
60
  }
60
61
  }
61
62
  else {
62
- // child.kill() does not work on linux
63
- // process.kill will kill the whole process group on unix
64
- process.kill(-serverProcess.pid, 'SIGKILL');
63
+ return new Promise((res, rej) => {
64
+ treeKill(serverProcess.pid, (err) => {
65
+ if (err) {
66
+ rej(err);
67
+ }
68
+ res();
69
+ });
70
+ });
65
71
  }
66
72
  };
67
73
  }
@@ -95,6 +101,7 @@ function nxE2EPreset(pathToConfig, options) {
95
101
  webServerCommands: options?.webServerCommands,
96
102
  ciWebServerCommand: options?.ciWebServerCommand,
97
103
  ciBaseUrl: options?.ciBaseUrl,
104
+ reuseExistingServer: options?.webServerConfig?.reuseExistingServer,
98
105
  },
99
106
  async setupNodeEvents(on, config) {
100
107
  const webServerCommands = config.env?.webServerCommands ?? options?.webServerCommands;
@@ -122,7 +129,7 @@ function nxE2EPreset(pathToConfig, options) {
122
129
  }
123
130
  const killWebServer = startWebServer(webServerCommand);
124
131
  on('after:run', () => {
125
- killWebServer();
132
+ return killWebServer();
126
133
  });
127
134
  await waitForServer(config.baseUrl, options.webServerConfig);
128
135
  }
@@ -5,11 +5,12 @@ const devkit_1 = require("@nx/devkit");
5
5
  const fs_1 = require("fs");
6
6
  const path_1 = require("path");
7
7
  const ct_helpers_1 = require("../../utils/ct-helpers");
8
- const cypress_version_1 = require("../../utils/cypress-version");
8
+ const versions_1 = require("../../utils/versions");
9
9
  const start_dev_server_1 = require("../../utils/start-dev-server");
10
10
  const Cypress = require('cypress'); // @NOTE: Importing via ES6 messes the whole test dependencies.
11
11
  async function cypressExecutor(options, context) {
12
- options = normalizeOptions(options, context);
12
+ const installedCypressMajorVersion = (0, versions_1.getInstalledCypressMajorVersion)();
13
+ options = normalizeOptions(options, context, installedCypressMajorVersion);
13
14
  // this is used by cypress component testing presets to build the executor contexts with the correct configuration options.
14
15
  process.env.NX_CYPRESS_TARGET_CONFIGURATION = context.configurationName;
15
16
  let success;
@@ -19,7 +20,7 @@ async function cypressExecutor(options, context) {
19
20
  success = await runCypress(devServerValues.baseUrl, {
20
21
  ...options,
21
22
  portLockFilePath: devServerValues.portLockFilePath,
22
- });
23
+ }, installedCypressMajorVersion);
23
24
  if (!options.watch) {
24
25
  generatorInstance.return();
25
26
  break;
@@ -34,7 +35,7 @@ async function cypressExecutor(options, context) {
34
35
  }
35
36
  return { success };
36
37
  }
37
- function normalizeOptions(options, context) {
38
+ function normalizeOptions(options, context, installedCypressMajorVersion) {
38
39
  options.env = options.env || {};
39
40
  if (options.testingType === 'component') {
40
41
  const project = context?.projectGraph?.nodes?.[context.projectName];
@@ -42,17 +43,17 @@ function normalizeOptions(options, context) {
42
43
  options.ctTailwindPath = (0, ct_helpers_1.getTempTailwindPath)(context);
43
44
  }
44
45
  }
45
- checkSupportedBrowser(options);
46
- warnDeprecatedHeadless(options);
47
- warnDeprecatedCypressVersion();
46
+ checkSupportedBrowser(options, installedCypressMajorVersion);
47
+ warnDeprecatedHeadless(options, installedCypressMajorVersion);
48
+ warnDeprecatedCypressVersion(installedCypressMajorVersion);
48
49
  return options;
49
50
  }
50
- function checkSupportedBrowser({ browser }) {
51
+ function checkSupportedBrowser({ browser }, installedCypressMajorVersion) {
51
52
  // Browser was not passed in as an option, cypress will use whatever default it has set and we dont need to check it
52
53
  if (!browser) {
53
54
  return;
54
55
  }
55
- if ((0, cypress_version_1.installedCypressVersion)() >= 4 && browser == 'canary') {
56
+ if (installedCypressMajorVersion >= 4 && browser == 'canary') {
56
57
  devkit_1.logger.warn((0, devkit_1.stripIndents) `
57
58
  Warning:
58
59
  You are using a browser that is not supported by cypress v4+.
@@ -63,7 +64,7 @@ function checkSupportedBrowser({ browser }) {
63
64
  return;
64
65
  }
65
66
  const supportedV3Browsers = ['electron', 'chrome', 'canary', 'chromium'];
66
- if ((0, cypress_version_1.installedCypressVersion)() <= 3 &&
67
+ if (installedCypressMajorVersion <= 3 &&
67
68
  !supportedV3Browsers.includes(browser)) {
68
69
  devkit_1.logger.warn((0, devkit_1.stripIndents) `
69
70
  Warning:
@@ -72,8 +73,8 @@ function checkSupportedBrowser({ browser }) {
72
73
  return;
73
74
  }
74
75
  }
75
- function warnDeprecatedHeadless({ headless }) {
76
- if ((0, cypress_version_1.installedCypressVersion)() < 8 || headless === undefined) {
76
+ function warnDeprecatedHeadless({ headless }, installedCypressMajorVersion) {
77
+ if (installedCypressMajorVersion < 8 || headless === undefined) {
77
78
  return;
78
79
  }
79
80
  if (headless) {
@@ -83,8 +84,8 @@ function warnDeprecatedHeadless({ headless }) {
83
84
  devkit_1.logger.warn(deprecatedMsg);
84
85
  }
85
86
  }
86
- function warnDeprecatedCypressVersion() {
87
- if ((0, cypress_version_1.installedCypressVersion)() < 10) {
87
+ function warnDeprecatedCypressVersion(installedCypressMajorVersion) {
88
+ if (installedCypressMajorVersion < 10) {
88
89
  devkit_1.logger.warn((0, devkit_1.stripIndents) `
89
90
  NOTE:
90
91
  Support for Cypress versions < 10 is deprecated. Please upgrade to at least Cypress version 10.
@@ -97,8 +98,7 @@ A generator to migrate from v8 to v10 is provided. See https://nx.dev/cypress/v1
97
98
  * By default, Cypress will run tests from the CLI without the GUI and provide directly the results in the console output.
98
99
  * If `watch` is `true`: Open Cypress in the interactive GUI to interact directly with the application.
99
100
  */
100
- async function runCypress(baseUrl, opts) {
101
- const cypressVersion = (0, cypress_version_1.installedCypressVersion)();
101
+ async function runCypress(baseUrl, opts, installedCypressMajorVersion) {
102
102
  // Cypress expects the folder where a cypress config is present
103
103
  const projectFolderPath = (0, path_1.dirname)(opts.cypressConfig);
104
104
  const options = {
@@ -134,7 +134,7 @@ async function runCypress(baseUrl, opts) {
134
134
  options.ciBuildId = opts.ciBuildId?.toString();
135
135
  options.group = opts.group;
136
136
  // renamed in cy 10
137
- if (cypressVersion >= 10) {
137
+ if (installedCypressMajorVersion >= 10) {
138
138
  options.config ??= {};
139
139
  options.config[opts.testingType] = {
140
140
  excludeSpecPattern: opts.ignoreTestFiles,
@@ -1,4 +1,4 @@
1
- import { ProjectConfiguration, Tree, GeneratorCallback } from '@nx/devkit';
1
+ import { GeneratorCallback, ProjectConfiguration, Tree } from '@nx/devkit';
2
2
  import { CypressComponentConfigurationSchema } from './schema';
3
3
  export declare function componentConfigurationGenerator(tree: Tree, options: CypressComponentConfigurationSchema): Promise<GeneratorCallback>;
4
4
  export declare function componentConfigurationGeneratorInternal(tree: Tree, options: CypressComponentConfigurationSchema): Promise<GeneratorCallback>;
@@ -5,7 +5,6 @@ exports.componentConfigurationGeneratorInternal = componentConfigurationGenerato
5
5
  exports.updateTsConfigForComponentTesting = updateTsConfigForComponentTesting;
6
6
  const devkit_1 = require("@nx/devkit");
7
7
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
8
- const cypress_version_1 = require("../../utils/cypress-version");
9
8
  const versions_1 = require("../../utils/versions");
10
9
  const base_setup_1 = require("../base-setup/base-setup");
11
10
  const init_1 = require("../init/init");
@@ -19,10 +18,12 @@ async function componentConfigurationGeneratorInternal(tree, options) {
19
18
  (0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(tree, 'cypress', 'component-configuration');
20
19
  const tasks = [];
21
20
  const opts = normalizeOptions(tree, options);
22
- tasks.push(await (0, init_1.default)(tree, {
23
- ...opts,
24
- skipFormat: true,
25
- }));
21
+ if (!(0, versions_1.getInstalledCypressMajorVersion)(tree)) {
22
+ tasks.push(await (0, init_1.default)(tree, {
23
+ ...opts,
24
+ skipFormat: true,
25
+ }));
26
+ }
26
27
  const nxJson = (0, devkit_1.readNxJson)(tree);
27
28
  const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
28
29
  ? p === '@nx/cypress/plugin'
@@ -41,7 +42,7 @@ async function componentConfigurationGeneratorInternal(tree, options) {
41
42
  return (0, devkit_1.runTasksInSerial)(...tasks);
42
43
  }
43
44
  function normalizeOptions(tree, options) {
44
- const cyVersion = (0, cypress_version_1.installedCypressVersion)();
45
+ const cyVersion = (0, versions_1.getInstalledCypressMajorVersion)(tree);
45
46
  if (cyVersion && cyVersion < 10) {
46
47
  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');
47
48
  }
@@ -56,17 +57,19 @@ function normalizeOptions(tree, options) {
56
57
  };
57
58
  }
58
59
  function updateDeps(tree, opts) {
60
+ const pkgVersions = (0, versions_1.versions)(tree);
59
61
  const devDeps = {
60
- cypress: versions_1.cypressVersion,
62
+ cypress: pkgVersions.cypressVersion,
61
63
  };
62
64
  if (opts.bundler === 'vite') {
63
- devDeps['@cypress/vite-dev-server'] = versions_1.cypressViteDevServerVersion;
65
+ devDeps['@cypress/vite-dev-server'] =
66
+ pkgVersions.cypressViteDevServerVersion;
64
67
  }
65
68
  else {
66
- devDeps['@cypress/webpack-dev-server'] = versions_1.cypressWebpackVersion;
67
- devDeps['html-webpack-plugin'] = versions_1.htmlWebpackPluginVersion;
69
+ devDeps['@cypress/webpack-dev-server'] = pkgVersions.cypressWebpackVersion;
70
+ devDeps['html-webpack-plugin'] = pkgVersions.htmlWebpackPluginVersion;
68
71
  }
69
- return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDeps);
72
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDeps, undefined, true);
70
73
  }
71
74
  function addProjectFiles(tree, projectConfig, opts) {
72
75
  (0, base_setup_1.addBaseCypressSetup)(tree, {
@@ -4,6 +4,7 @@ exports.configurationGenerator = configurationGenerator;
4
4
  exports.configurationGeneratorInternal = configurationGeneratorInternal;
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
7
+ const prompt_1 = require("@nx/devkit/src/generators/prompt");
7
8
  const js_1 = require("@nx/js");
8
9
  const generator_prompts_1 = require("@nx/js/src/utils/generator-prompts");
9
10
  const package_manager_workspaces_1 = require("@nx/js/src/utils/package-manager-workspaces");
@@ -11,11 +12,9 @@ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-set
11
12
  const path_1 = require("path");
12
13
  const add_linter_1 = require("../../utils/add-linter");
13
14
  const config_1 = require("../../utils/config");
14
- const cypress_version_1 = require("../../utils/cypress-version");
15
15
  const versions_1 = require("../../utils/versions");
16
16
  const base_setup_1 = require("../base-setup/base-setup");
17
17
  const init_1 = require("../init/init");
18
- const prompt_1 = require("@nx/devkit/src/generators/prompt");
19
18
  function configurationGenerator(tree, options) {
20
19
  return configurationGeneratorInternal(tree, {
21
20
  addPlugin: false,
@@ -26,7 +25,7 @@ async function configurationGeneratorInternal(tree, options) {
26
25
  const opts = await normalizeOptions(tree, options);
27
26
  const tasks = [];
28
27
  const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
29
- if (!(0, cypress_version_1.installedCypressVersion)()) {
28
+ if (!(0, versions_1.getInstalledCypressMajorVersion)(tree)) {
30
29
  tasks.push(await (0, js_1.initGenerator)(tree, { ...options, skipFormat: true }));
31
30
  tasks.push(await (0, init_1.default)(tree, {
32
31
  ...opts,
@@ -92,13 +91,14 @@ async function configurationGeneratorInternal(tree, options) {
92
91
  return (0, devkit_1.runTasksInSerial)(...tasks);
93
92
  }
94
93
  function ensureDependencies(tree, options) {
94
+ const pkgVersions = (0, versions_1.versions)(tree);
95
95
  const devDependencies = {
96
- '@types/node': versions_1.typesNodeVersion,
96
+ '@types/node': pkgVersions.typesNodeVersion,
97
97
  };
98
98
  if (options.bundler === 'vite') {
99
- devDependencies['vite'] = versions_1.viteVersion;
99
+ devDependencies['vite'] = pkgVersions.viteVersion;
100
100
  }
101
- return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies);
101
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies, undefined, true);
102
102
  }
103
103
  async function normalizeOptions(tree, options) {
104
104
  const linter = await (0, generator_prompts_1.normalizeLinterOption)(tree, options.linter);
@@ -164,7 +164,7 @@ async function promptForMissingServeData(projectName) {
164
164
  }
165
165
  async function addFiles(tree, options, projectGraph, hasPlugin) {
166
166
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
167
- const cyVersion = (0, cypress_version_1.installedCypressVersion)();
167
+ const cyVersion = (0, versions_1.getInstalledCypressMajorVersion)(tree);
168
168
  const filesToUse = cyVersion && cyVersion < 10 ? 'v9' : 'v10';
169
169
  const hasTsConfig = tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.json'));
170
170
  const offsetFromProjectRoot = options.directory
@@ -245,7 +245,7 @@ async function addFiles(tree, options, projectGraph, hasPlugin) {
245
245
  }
246
246
  function addTarget(tree, opts, projectGraph) {
247
247
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, opts.project);
248
- const cyVersion = (0, cypress_version_1.installedCypressVersion)();
248
+ const cyVersion = (0, versions_1.getInstalledCypressMajorVersion)(tree);
249
249
  projectConfig.targets ??= {};
250
250
  projectConfig.targets.e2e = {
251
251
  executor: '@nx/cypress:cypress',
@@ -299,10 +299,10 @@ function createPackageJson(tree, options) {
299
299
  name: importPath,
300
300
  version: '0.0.1',
301
301
  private: true,
302
- nx: {
303
- name: options.project,
304
- },
305
302
  };
303
+ if (options.project !== importPath) {
304
+ packageJson.nx = { name: options.project };
305
+ }
306
306
  (0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
307
307
  }
308
308
  function ignoreTestOutput(tree) {
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.migrateCypressProject = migrateCypressProject;
4
- const cypress_version_1 = require("../../utils/cypress-version");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
+ const versions_1 = require("../../utils/versions");
7
7
  const conversion_util_1 = require("./conversion.util");
8
8
  function migrateCypressExecutorOptions(tree, projectName, target, configuration, previousCypressConfigs) {
9
9
  try {
@@ -57,8 +57,8 @@ https://nx.dev/cypress/v10-migration-guide
57
57
  }
58
58
  }
59
59
  async function migrateCypressProject(tree) {
60
- (0, cypress_version_1.assertMinimumCypressVersion)(8);
61
- if ((0, cypress_version_1.installedCypressVersion)() >= 10) {
60
+ (0, versions_1.assertMinimumCypressVersion)(8);
61
+ if ((0, versions_1.getInstalledCypressMajorVersion)(tree) >= 10) {
62
62
  devkit_1.logger.info('NX This workspace is already using Cypress v10+');
63
63
  return;
64
64
  }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
6
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
7
+ const config_1 = require("../../utils/config");
8
+ const migrations_1 = require("../../utils/migrations");
9
+ let printer;
10
+ let ts;
11
+ // https://docs.cypress.io/app/references/changelog#:~:text=The%20experimentalFetchPolyfill%20configuration%20option%20was,cy.intercept()%20for%20handling%20fetch%20requests
12
+ async function default_1(tree) {
13
+ for await (const { cypressConfigPath } of (0, migrations_1.cypressProjectConfigs)(tree)) {
14
+ if (!tree.exists(cypressConfigPath)) {
15
+ // cypress config file doesn't exist, so skip
16
+ continue;
17
+ }
18
+ ts ??= (0, ensure_typescript_1.ensureTypescript)();
19
+ printer ??= ts.createPrinter();
20
+ const cypressConfig = tree.read(cypressConfigPath, 'utf-8');
21
+ const updatedConfig = removeExperimentalFetchPolyfill(cypressConfig);
22
+ tree.write(cypressConfigPath, updatedConfig);
23
+ }
24
+ await (0, devkit_1.formatFiles)(tree);
25
+ }
26
+ function removeExperimentalFetchPolyfill(cypressConfig) {
27
+ const config = (0, config_1.resolveCypressConfigObject)(cypressConfig);
28
+ if (!config) {
29
+ // couldn't find the config object, leave as is
30
+ return cypressConfig;
31
+ }
32
+ const sourceFile = tsquery_1.tsquery.ast(cypressConfig);
33
+ const updatedConfig = ts.factory.updateObjectLiteralExpression(config, config.properties
34
+ // remove the experimentalFetchPolyfill property from the top level config object
35
+ .filter((p) => !ts.isPropertyAssignment(p) ||
36
+ p.name.getText() !== 'experimentalFetchPolyfill')
37
+ .map((p) => {
38
+ if (ts.isPropertyAssignment(p) &&
39
+ ['component', 'e2e'].includes(p.name.getText()) &&
40
+ ts.isObjectLiteralExpression(p.initializer)) {
41
+ // remove the experimentalFetchPolyfill property from the component or e2e config object
42
+ return ts.factory.updatePropertyAssignment(p, p.name, ts.factory.updateObjectLiteralExpression(p.initializer, p.initializer.properties.filter((ip) => !ts.isPropertyAssignment(ip) ||
43
+ ip.name.getText() !== 'experimentalFetchPolyfill')));
44
+ }
45
+ return p;
46
+ }));
47
+ return cypressConfig.replace(config.getText(), printer.printNode(ts.EmitHint.Unspecified, updatedConfig, sourceFile));
48
+ }
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export default function (tree: Tree): Promise<void>;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
6
+ const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
7
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
8
+ const node_path_1 = require("node:path");
9
+ const config_1 = require("../../utils/config");
10
+ const migrations_1 = require("../../utils/migrations");
11
+ let printer;
12
+ let ts;
13
+ // https://docs.cypress.io/app/references/migration-guide#CT-Just-in-Time-Compile-changes
14
+ async function default_1(tree) {
15
+ for await (const { cypressConfigPath } of (0, migrations_1.cypressProjectConfigs)(tree)) {
16
+ if (!tree.exists(cypressConfigPath)) {
17
+ // cypress config file doesn't exist, so skip
18
+ continue;
19
+ }
20
+ const updatedConfig = await updateCtJustInTimeCompile(tree, cypressConfigPath);
21
+ tree.write(cypressConfigPath, updatedConfig);
22
+ }
23
+ await (0, devkit_1.formatFiles)(tree);
24
+ }
25
+ async function updateCtJustInTimeCompile(tree, cypressConfigPath) {
26
+ const cypressConfig = tree.read(cypressConfigPath, 'utf-8');
27
+ const config = (0, config_1.resolveCypressConfigObject)(cypressConfig);
28
+ if (!config) {
29
+ // couldn't find the config object, leave as is
30
+ return cypressConfig;
31
+ }
32
+ if (!(0, migrations_1.getObjectProperty)(config, 'component')) {
33
+ // no component config, leave as is
34
+ return cypressConfig;
35
+ }
36
+ ts ??= (0, ensure_typescript_1.ensureTypescript)();
37
+ printer ??= ts.createPrinter();
38
+ const sourceFile = tsquery_1.tsquery.ast(cypressConfig);
39
+ let updatedConfig = config;
40
+ const bundler = await resolveBundler(updatedConfig, cypressConfigPath);
41
+ const isViteBundler = bundler === 'vite';
42
+ const existingJustInTimeCompileProperty = (0, migrations_1.getObjectProperty)(updatedConfig, 'experimentalJustInTimeCompile');
43
+ if (existingJustInTimeCompileProperty) {
44
+ if (isViteBundler ||
45
+ existingJustInTimeCompileProperty.initializer.kind ===
46
+ ts.SyntaxKind.TrueKeyword) {
47
+ // if it's using vite or it's set to true (the new default value), remove it
48
+ updatedConfig = (0, migrations_1.removeObjectProperty)(updatedConfig, existingJustInTimeCompileProperty);
49
+ }
50
+ else {
51
+ // rename to justInTimeCompile
52
+ updatedConfig = (0, migrations_1.updateObjectProperty)(updatedConfig, existingJustInTimeCompileProperty, { newName: 'justInTimeCompile' });
53
+ }
54
+ }
55
+ const componentProperty = (0, migrations_1.getObjectProperty)(updatedConfig, 'component');
56
+ if (componentProperty &&
57
+ ts.isObjectLiteralExpression(componentProperty.initializer)) {
58
+ const componentConfigObject = componentProperty.initializer;
59
+ const existingJustInTimeCompileProperty = (0, migrations_1.getObjectProperty)(componentConfigObject, 'experimentalJustInTimeCompile');
60
+ if (existingJustInTimeCompileProperty) {
61
+ if (isViteBundler ||
62
+ existingJustInTimeCompileProperty.initializer.kind ===
63
+ ts.SyntaxKind.TrueKeyword) {
64
+ // if it's using vite or it's set to true (the new default value), remove it
65
+ updatedConfig = (0, migrations_1.updateObjectProperty)(updatedConfig, componentProperty, {
66
+ newValue: (0, migrations_1.removeObjectProperty)(componentConfigObject, existingJustInTimeCompileProperty),
67
+ });
68
+ }
69
+ else {
70
+ // rename to justInTimeCompile
71
+ updatedConfig = (0, migrations_1.updateObjectProperty)(updatedConfig, componentProperty, {
72
+ newValue: (0, migrations_1.updateObjectProperty)(componentConfigObject, existingJustInTimeCompileProperty, { newName: 'justInTimeCompile' }),
73
+ });
74
+ }
75
+ }
76
+ }
77
+ return cypressConfig.replace(config.getText(), printer.printNode(ts.EmitHint.Unspecified, updatedConfig, sourceFile));
78
+ }
79
+ async function resolveBundler(config, cypressConfigPath) {
80
+ const bundlerProperty = tsquery_1.tsquery.query(config, 'PropertyAssignment:has(Identifier[name=component]) PropertyAssignment:has(Identifier[name=devServer]) PropertyAssignment:has(Identifier[name=bundler])')[0];
81
+ if (bundlerProperty) {
82
+ return ts.isStringLiteral(bundlerProperty.initializer)
83
+ ? bundlerProperty.initializer.getText().replace(/['"`]/g, '')
84
+ : null;
85
+ }
86
+ try {
87
+ // we can't statically resolve the bundler from the config, so we load the config
88
+ const cypressConfig = await (0, config_utils_1.loadConfigFile)((0, node_path_1.join)(devkit_1.workspaceRoot, cypressConfigPath));
89
+ return cypressConfig.component?.devServer?.bundler;
90
+ }
91
+ catch {
92
+ return null;
93
+ }
94
+ }
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export default function (tree: Tree): Promise<void>;