@nx/cypress 22.0.0-beta.0 → 22.0.0-beta.2

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 CHANGED
@@ -1,11 +1,5 @@
1
1
  {
2
2
  "generators": {
3
- "update-19-6-0-update-ci-webserver-for-vite": {
4
- "cli": "nx",
5
- "version": "19.6.0-beta.4",
6
- "description": "Update ciWebServerCommand to use static serve for the application.",
7
- "implementation": "./src/migrations/update-19-6-0/update-ci-webserver-for-static-serve"
8
- },
9
3
  "set-inject-document-domain": {
10
4
  "cli": "nx",
11
5
  "version": "20.8.0-beta.0",
@@ -49,34 +43,6 @@
49
43
  }
50
44
  },
51
45
  "packageJsonUpdates": {
52
- "19.1.0": {
53
- "version": "19.1.0-beta.0",
54
- "requires": {
55
- "cypress": "^13.0.0"
56
- },
57
- "packages": {
58
- "cypress": {
59
- "version": "^13.8.0",
60
- "alwaysAddToPackageJson": false
61
- },
62
- "@cypress/webpack-dev-server": {
63
- "version": "^3.8.0",
64
- "alwaysAddToPackageJson": false
65
- }
66
- }
67
- },
68
- "19.4.1": {
69
- "version": "19.4.1-beta.0",
70
- "requires": {
71
- "cypress": "^13.0.0"
72
- },
73
- "packages": {
74
- "cypress": {
75
- "version": "^13.13.0",
76
- "alwaysAddToPackageJson": false
77
- }
78
- }
79
- },
80
46
  "20.8.0": {
81
47
  "version": "20.8.0-beta.0",
82
48
  "x-prompt": "Do you want to update the Cypress version to v14?",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/cypress",
3
- "version": "22.0.0-beta.0",
3
+ "version": "22.0.0-beta.2",
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,9 +36,9 @@
36
36
  "migrations": "./migrations.json"
37
37
  },
38
38
  "dependencies": {
39
- "@nx/devkit": "22.0.0-beta.0",
40
- "@nx/eslint": "22.0.0-beta.0",
41
- "@nx/js": "22.0.0-beta.0",
39
+ "@nx/devkit": "22.0.0-beta.2",
40
+ "@nx/eslint": "22.0.0-beta.2",
41
+ "@nx/js": "22.0.0-beta.2",
42
42
  "@phenomnomnominal/tsquery": "~5.0.1",
43
43
  "detect-port": "^1.5.1",
44
44
  "semver": "^7.6.3",
@@ -46,7 +46,7 @@
46
46
  "tslib": "^2.3.0"
47
47
  },
48
48
  "devDependencies": {
49
- "nx": "22.0.0-beta.0"
49
+ "nx": "22.0.0-beta.2"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "cypress": ">= 3 < 15"
@@ -1,3 +0,0 @@
1
- import { type Tree } from '@nx/devkit';
2
- export default function addE2eCiTargetDefaults(tree: Tree): Promise<void>;
3
- //# sourceMappingURL=add-e2e-ci-target-defaults.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"add-e2e-ci-target-defaults.d.ts","sourceRoot":"","sources":["../../../../../../packages/cypress/src/migrations/update-19-6-0/add-e2e-ci-target-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,EAMV,MAAM,YAAY,CAAC;AAYpB,wBAA8B,sBAAsB,CAAC,IAAI,EAAE,IAAI,iBA2F9D"}
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = addE2eCiTargetDefaults;
4
- const devkit_1 = require("@nx/devkit");
5
- const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
6
- const loaded_nx_plugin_1 = require("nx/src/project-graph/plugins/loaded-nx-plugin");
7
- const devkit_internals_1 = require("nx/src/devkit-internals");
8
- const tsquery_1 = require("@phenomnomnominal/tsquery");
9
- const path_1 = require("path");
10
- async function addE2eCiTargetDefaults(tree) {
11
- const pluginName = '@nx/cypress/plugin';
12
- const graph = await (0, devkit_1.createProjectGraphAsync)();
13
- const nxJson = (0, devkit_1.readNxJson)(tree);
14
- const matchingPluginRegistrations = nxJson.plugins?.filter((p) => typeof p === 'string' ? p === pluginName : p.plugin === pluginName);
15
- if (!matchingPluginRegistrations) {
16
- return;
17
- }
18
- const { createNodesV2, } = await Promise.resolve(`${pluginName}`).then(s => require(s));
19
- for (const plugin of matchingPluginRegistrations) {
20
- let projectConfigs;
21
- try {
22
- const loadedPlugin = new loaded_nx_plugin_1.LoadedNxPlugin({ createNodesV2, name: pluginName }, plugin);
23
- projectConfigs = await (0, devkit_internals_1.retrieveProjectConfigurations)([loadedPlugin], tree.root, nxJson);
24
- }
25
- catch (e) {
26
- if (e instanceof devkit_internals_1.ProjectConfigurationsError) {
27
- projectConfigs = e.partialProjectConfigurationsResult;
28
- }
29
- else {
30
- throw e;
31
- }
32
- }
33
- for (const configFile of projectConfigs.matchingProjectFiles) {
34
- const configFileContents = tree.read(configFile, 'utf-8');
35
- if (!configFileContents.includes('ciWebServerCommand')) {
36
- continue;
37
- }
38
- const ast = tsquery_1.tsquery.ast(configFileContents);
39
- const CI_WEBSERVER_COMMAND_SELECTOR = 'ObjectLiteralExpression PropertyAssignment:has(Identifier[name=ciWebServerCommand]) > StringLiteral';
40
- const nodes = (0, tsquery_1.tsquery)(ast, CI_WEBSERVER_COMMAND_SELECTOR, {
41
- visitAllChildren: true,
42
- });
43
- if (!nodes.length) {
44
- continue;
45
- }
46
- const ciWebServerCommand = nodes[0].getText();
47
- const NX_TARGET_REGEX = "(?<=nx run )[^']+";
48
- const matches = ciWebServerCommand.match(NX_TARGET_REGEX);
49
- if (!matches) {
50
- continue;
51
- }
52
- const targetString = matches[0];
53
- const { project, target, configuration } = (0, devkit_1.parseTargetString)(targetString, graph);
54
- const targetDependsOnSelf = graph.nodes[project].data.root === (0, path_1.dirname)(configFile);
55
- const serveStaticTarget = graph.nodes[project].data.targets[target];
56
- if (!serveStaticTarget) {
57
- continue;
58
- }
59
- let resolvedBuildTarget;
60
- if (serveStaticTarget?.dependsOn) {
61
- resolvedBuildTarget = serveStaticTarget.dependsOn.join(',');
62
- }
63
- else {
64
- resolvedBuildTarget =
65
- (configuration
66
- ? serveStaticTarget.configurations[configuration].buildTarget
67
- : serveStaticTarget.options.buildTarget) ?? 'build';
68
- }
69
- const buildTarget = `${targetDependsOnSelf ? '' : '^'}${resolvedBuildTarget}`;
70
- await (0, target_defaults_utils_1.addE2eCiTargetDefaults)(tree, pluginName, buildTarget, configFile);
71
- }
72
- }
73
- await (0, devkit_1.formatFiles)(tree);
74
- }
@@ -1,3 +0,0 @@
1
- import { type Tree } from '@nx/devkit';
2
- export default function (tree: Tree): Promise<void>;
3
- //# sourceMappingURL=update-ci-webserver-for-static-serve.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"update-ci-webserver-for-static-serve.d.ts","sourceRoot":"","sources":["../../../../../../packages/cypress/src/migrations/update-19-6-0/update-ci-webserver-for-static-serve.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,EAUV,MAAM,YAAY,CAAC;AAYpB,yBAA+B,IAAI,EAAE,IAAI,iBAiLxC"}
@@ -1,150 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = default_1;
4
- const devkit_1 = require("@nx/devkit");
5
- const devkit_internals_1 = require("nx/src/devkit-internals");
6
- const tsquery_1 = require("@phenomnomnominal/tsquery");
7
- const add_e2e_ci_target_defaults_1 = require("./add-e2e-ci-target-defaults");
8
- async function default_1(tree) {
9
- const pluginName = '@nx/cypress/plugin';
10
- const graph = await (0, devkit_1.createProjectGraphAsync)();
11
- const nxJson = (0, devkit_1.readNxJson)(tree);
12
- const matchingPluginRegistrations = nxJson.plugins?.filter((p) => typeof p === 'string' ? p === pluginName : p.plugin === pluginName);
13
- if (!matchingPluginRegistrations?.length) {
14
- return;
15
- }
16
- const { createNodesV2, } = await Promise.resolve(`${pluginName}`).then(s => require(s));
17
- for (const plugin of matchingPluginRegistrations) {
18
- let projectConfigs;
19
- try {
20
- const loadedPlugin = new devkit_internals_1.LoadedNxPlugin({ createNodesV2, name: pluginName }, plugin);
21
- projectConfigs = await (0, devkit_internals_1.retrieveProjectConfigurations)([loadedPlugin], tree.root, nxJson);
22
- }
23
- catch (e) {
24
- if (e instanceof devkit_internals_1.ProjectConfigurationsError) {
25
- projectConfigs = e.partialProjectConfigurationsResult;
26
- }
27
- else {
28
- throw e;
29
- }
30
- }
31
- for (const configFile of projectConfigs.matchingProjectFiles) {
32
- const configFileContents = tree.read(configFile, 'utf-8');
33
- if (!configFileContents.includes('ciWebServerCommand')) {
34
- continue;
35
- }
36
- const ast = tsquery_1.tsquery.ast(configFileContents);
37
- const CI_WEBSERVER_COMMAND_SELECTOR = 'ObjectLiteralExpression PropertyAssignment:has(Identifier[name=ciWebServerCommand]) > StringLiteral';
38
- const nodes = (0, tsquery_1.tsquery)(ast, CI_WEBSERVER_COMMAND_SELECTOR, {
39
- visitAllChildren: true,
40
- });
41
- if (!nodes.length) {
42
- continue;
43
- }
44
- const ciWebServerCommand = nodes[0].getText();
45
- let project;
46
- let portFlagValue;
47
- if (ciWebServerCommand.includes('nx run')) {
48
- const NX_TARGET_REGEX = /(?<=nx run )([^' ]+)(?: [^']*--port[= ](\d+))?/;
49
- const matches = ciWebServerCommand.match(NX_TARGET_REGEX);
50
- if (!matches) {
51
- continue;
52
- }
53
- const targetString = matches[1];
54
- project = (0, devkit_1.parseTargetString)(targetString, graph).project;
55
- portFlagValue = matches[2];
56
- }
57
- else {
58
- const NX_PROJECT_REGEX = /(?<=nx [^ ]+ )([^' ]+)(?: [^']*--port[= ](\d+))?/;
59
- const matches = ciWebServerCommand.match(NX_PROJECT_REGEX);
60
- if (!matches) {
61
- continue;
62
- }
63
- project = matches[1];
64
- portFlagValue = matches[2];
65
- }
66
- if (!project || !graph.nodes[project]) {
67
- continue;
68
- }
69
- const pathToViteConfig = [
70
- (0, devkit_1.joinPathFragments)(graph.nodes[project].data.root, 'vite.config.ts'),
71
- (0, devkit_1.joinPathFragments)(graph.nodes[project].data.root, 'vite.config.js'),
72
- ].find((p) => tree.exists(p));
73
- const pathToWebpackConfig = [
74
- (0, devkit_1.joinPathFragments)(graph.nodes[project].data.root, 'webpack.config.ts'),
75
- (0, devkit_1.joinPathFragments)(graph.nodes[project].data.root, 'webpack.config.js'),
76
- ].find((p) => tree.exists(p));
77
- if (!pathToViteConfig && !pathToWebpackConfig) {
78
- continue;
79
- }
80
- if (pathToWebpackConfig) {
81
- const matchingWebpackPlugin = await findPluginForConfigFile(tree, '@nx/webpack/plugin', pathToWebpackConfig);
82
- const serveStaticTargetName = matchingWebpackPlugin
83
- ? typeof matchingWebpackPlugin === 'string'
84
- ? 'serve-static'
85
- : matchingWebpackPlugin.options?.serveStaticTargetName ??
86
- 'serve-static'
87
- : getServeStaticLikeTarget(tree, graph, project, '@nx/web:file-server') ?? undefined;
88
- if (!serveStaticTargetName) {
89
- continue;
90
- }
91
- const newCommand = ciWebServerCommand.replace(/nx.*[^"']/, `nx run ${project}:${serveStaticTargetName}${portFlagValue ? ` --port=${portFlagValue}` : ''}`);
92
- tree.write(configFile, `${configFileContents.slice(0, nodes[0].getStart())}${newCommand}${configFileContents.slice(nodes[0].getEnd())}`);
93
- }
94
- else if (pathToViteConfig) {
95
- const viteConfigContents = tree.read(pathToViteConfig, 'utf-8');
96
- if (!viteConfigContents.includes('preview:')) {
97
- continue;
98
- }
99
- const matchingVitePlugin = await findPluginForConfigFile(tree, '@nx/vite/plugin', pathToViteConfig);
100
- const previewTargetName = matchingVitePlugin
101
- ? typeof matchingVitePlugin === 'string'
102
- ? 'preview'
103
- : matchingVitePlugin.options?.previewTargetName ??
104
- 'preview'
105
- : getServeStaticLikeTarget(tree, graph, project, '@nx/vite:preview-server') ?? undefined;
106
- if (!previewTargetName) {
107
- continue;
108
- }
109
- const newCommand = ciWebServerCommand.replace(/nx.*[^"']/, `nx run ${project}:${previewTargetName}${portFlagValue ? ` --port=${portFlagValue}` : ''}`);
110
- tree.write(configFile, `${configFileContents.slice(0, nodes[0].getStart())}${newCommand},
111
- ciBaseUrl: "http://localhost:${portFlagValue ?? '4300'}"${configFileContents.slice(nodes[0].getEnd())}`);
112
- }
113
- }
114
- }
115
- await (0, add_e2e_ci_target_defaults_1.default)(tree);
116
- await (0, devkit_1.formatFiles)(tree);
117
- }
118
- async function findPluginForConfigFile(tree, pluginName, pathToConfigFile) {
119
- const nxJson = (0, devkit_1.readNxJson)(tree);
120
- if (!nxJson.plugins) {
121
- return;
122
- }
123
- const pluginRegistrations = nxJson.plugins.filter((p) => (typeof p === 'string' ? p === pluginName : p.plugin === pluginName));
124
- for (const plugin of pluginRegistrations) {
125
- if (typeof plugin === 'string') {
126
- return plugin;
127
- }
128
- if (!plugin.include && !plugin.exclude) {
129
- return plugin;
130
- }
131
- if (plugin.include || plugin.exclude) {
132
- const resolvedPlugin = await Promise.resolve(`${pluginName}`).then(s => require(s));
133
- const pluginGlob = resolvedPlugin.createNodesV2?.[0] ?? resolvedPlugin.createNodes?.[0];
134
- const matchingConfigFile = (0, devkit_internals_1.findMatchingConfigFiles)([pathToConfigFile], pluginGlob, plugin.include, plugin.exclude);
135
- if (matchingConfigFile.length) {
136
- return plugin;
137
- }
138
- }
139
- }
140
- }
141
- function getServeStaticLikeTarget(tree, graph, projectName, executorName) {
142
- if (!graph.nodes[projectName]?.data?.targets) {
143
- return;
144
- }
145
- for (const [targetName, targetOptions] of Object.entries(graph.nodes[projectName].data.targets)) {
146
- if (targetOptions.executor && targetOptions.executor === executorName) {
147
- return targetName;
148
- }
149
- }
150
- }