@nx/playwright 22.0.0-beta.0 → 22.0.0-canary.20251001-e28a97a
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 +1 -14
- package/package.json +5 -6
- package/src/migrations/update-19-6-0/add-e2e-ci-target-defaults.d.ts +0 -3
- package/src/migrations/update-19-6-0/add-e2e-ci-target-defaults.d.ts.map +0 -1
- package/src/migrations/update-19-6-0/add-e2e-ci-target-defaults.js +0 -88
- package/src/migrations/update-19-6-0/use-serve-static-preview-for-command.d.ts +0 -3
- package/src/migrations/update-19-6-0/use-serve-static-preview-for-command.d.ts.map +0 -1
- package/src/migrations/update-19-6-0/use-serve-static-preview-for-command.js +0 -175
package/migrations.json
CHANGED
@@ -1,16 +1,3 @@
|
|
1
1
|
{
|
2
|
-
"generators": {
|
3
|
-
"19-6-0-use-serve-static-preview-for-command": {
|
4
|
-
"cli": "nx",
|
5
|
-
"version": "19.6.0-beta.0",
|
6
|
-
"description": "Use serve-static or preview for webServerCommand.",
|
7
|
-
"implementation": "./src/migrations/update-19-6-0/use-serve-static-preview-for-command"
|
8
|
-
},
|
9
|
-
"update-19-6-0-add-e2e-ci-target-defaults": {
|
10
|
-
"cli": "nx",
|
11
|
-
"version": "19.6.0-beta.1",
|
12
|
-
"description": "Add inferred ciTargetNames to targetDefaults with dependsOn to ensure dependent application builds are scheduled before atomized tasks.",
|
13
|
-
"implementation": "./src/migrations/update-19-6-0/add-e2e-ci-target-defaults"
|
14
|
-
}
|
15
|
-
}
|
2
|
+
"generators": {}
|
16
3
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/playwright",
|
3
|
-
"version": "22.0.0-
|
3
|
+
"version": "22.0.0-canary.20251001-e28a97a",
|
4
4
|
"type": "commonjs",
|
5
5
|
"homepage": "https://nx.dev",
|
6
6
|
"private": false,
|
@@ -34,15 +34,14 @@
|
|
34
34
|
"directory": "packages/playwright"
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"@
|
38
|
-
"@nx/
|
39
|
-
"@nx/
|
40
|
-
"@nx/js": "22.0.0-beta.0",
|
37
|
+
"@nx/devkit": "22.0.0-canary.20251001-e28a97a",
|
38
|
+
"@nx/eslint": "22.0.0-canary.20251001-e28a97a",
|
39
|
+
"@nx/js": "22.0.0-canary.20251001-e28a97a",
|
41
40
|
"tslib": "^2.3.0",
|
42
41
|
"minimatch": "9.0.3"
|
43
42
|
},
|
44
43
|
"devDependencies": {
|
45
|
-
"nx": "22.0.0-
|
44
|
+
"nx": "22.0.0-canary.20251001-e28a97a"
|
46
45
|
},
|
47
46
|
"peerDependencies": {
|
48
47
|
"@playwright/test": "^1.36.0"
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"add-e2e-ci-target-defaults.d.ts","sourceRoot":"","sources":["../../../../../../packages/playwright/src/migrations/update-19-6-0/add-e2e-ci-target-defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,EAKV,MAAM,YAAY,CAAC;AAYpB,wBAA8B,sBAAsB,CAAC,IAAI,EAAE,IAAI,iBAuG9D"}
|
@@ -1,88 +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/playwright/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
|
-
const ast = tsquery_1.tsquery.ast(configFileContents);
|
36
|
-
const CI_WEBSERVER_COMMAND_SELECTOR = 'PropertyAssignment:has(Identifier[name=webServer]) PropertyAssignment:has(Identifier[name=command]) > StringLiteral';
|
37
|
-
const nodes = (0, tsquery_1.tsquery)(ast, CI_WEBSERVER_COMMAND_SELECTOR, {
|
38
|
-
visitAllChildren: true,
|
39
|
-
});
|
40
|
-
if (!nodes.length) {
|
41
|
-
continue;
|
42
|
-
}
|
43
|
-
const ciWebServerCommand = nodes[0].getText().replace(/['"]/g, '');
|
44
|
-
let serveStaticProject;
|
45
|
-
let serveStaticTarget;
|
46
|
-
let serveStaticConfiguration;
|
47
|
-
if (ciWebServerCommand.includes('nx run')) {
|
48
|
-
const NX_TARGET_REGEX = "(?<=nx run )[^']+";
|
49
|
-
const matches = ciWebServerCommand.match(NX_TARGET_REGEX);
|
50
|
-
if (!matches) {
|
51
|
-
continue;
|
52
|
-
}
|
53
|
-
const targetString = matches[0];
|
54
|
-
const { project, target, configuration } = (0, devkit_1.parseTargetString)(targetString, graph);
|
55
|
-
serveStaticProject = project;
|
56
|
-
serveStaticTarget = target;
|
57
|
-
serveStaticConfiguration = configuration;
|
58
|
-
}
|
59
|
-
else {
|
60
|
-
const NX_PROJECT_REGEX = 'nx\\s+([^ ]+)\\s+([^ ]+)';
|
61
|
-
const matches = ciWebServerCommand.match(NX_PROJECT_REGEX);
|
62
|
-
if (!matches) {
|
63
|
-
return;
|
64
|
-
}
|
65
|
-
serveStaticTarget = matches[1];
|
66
|
-
serveStaticProject = matches[2];
|
67
|
-
}
|
68
|
-
const resolvedServeStaticTarget = graph.nodes[serveStaticProject]?.data?.targets?.[serveStaticTarget];
|
69
|
-
if (!resolvedServeStaticTarget) {
|
70
|
-
continue;
|
71
|
-
}
|
72
|
-
let resolvedBuildTarget;
|
73
|
-
if (resolvedServeStaticTarget.dependsOn) {
|
74
|
-
resolvedBuildTarget = resolvedServeStaticTarget.dependsOn.join(',');
|
75
|
-
}
|
76
|
-
else {
|
77
|
-
resolvedBuildTarget =
|
78
|
-
(serveStaticConfiguration
|
79
|
-
? resolvedServeStaticTarget.configurations[serveStaticConfiguration]
|
80
|
-
.buildTarget
|
81
|
-
: resolvedServeStaticTarget.options.buildTarget) ?? 'build';
|
82
|
-
}
|
83
|
-
const targetDependsOnSelf = graph.nodes[serveStaticProject].data.root === (0, path_1.dirname)(configFile);
|
84
|
-
const buildTarget = `${targetDependsOnSelf ? '' : '^'}${resolvedBuildTarget}`;
|
85
|
-
await (0, target_defaults_utils_1.addE2eCiTargetDefaults)(tree, pluginName, buildTarget, configFile);
|
86
|
-
}
|
87
|
-
}
|
88
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"use-serve-static-preview-for-command.d.ts","sourceRoot":"","sources":["../../../../../../packages/playwright/src/migrations/update-19-6-0/use-serve-static-preview-for-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,IAAI,EAEV,MAAM,YAAY,CAAC;AASpB,yBAA+B,IAAI,EAAE,IAAI,iBA0NxC"}
|
@@ -1,175 +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 tsquery_1 = require("@phenomnomnominal/tsquery");
|
6
|
-
const add_e2e_ci_target_defaults_1 = require("./add-e2e-ci-target-defaults");
|
7
|
-
const loaded_nx_plugin_1 = require("nx/src/project-graph/plugins/loaded-nx-plugin");
|
8
|
-
const retrieve_workspace_files_1 = require("nx/src/project-graph/utils/retrieve-workspace-files");
|
9
|
-
const error_types_1 = require("nx/src/project-graph/error-types");
|
10
|
-
async function default_1(tree) {
|
11
|
-
const graph = await (0, devkit_1.createProjectGraphAsync)();
|
12
|
-
const collectedProjects = [];
|
13
|
-
(0, devkit_1.visitNotIgnoredFiles)(tree, '', async (path) => {
|
14
|
-
if (!path.endsWith('playwright.config.ts')) {
|
15
|
-
return;
|
16
|
-
}
|
17
|
-
let playwrightConfigFileContents = tree.read(path, 'utf-8');
|
18
|
-
const WEBSERVER_COMMAND_SELECTOR = 'PropertyAssignment:has(Identifier[name=webServer]) PropertyAssignment:has(Identifier[name=command]) > StringLiteral';
|
19
|
-
let ast = tsquery_1.tsquery.ast(playwrightConfigFileContents);
|
20
|
-
const nodes = (0, tsquery_1.tsquery)(ast, WEBSERVER_COMMAND_SELECTOR, {
|
21
|
-
visitAllChildren: true,
|
22
|
-
});
|
23
|
-
if (!nodes.length) {
|
24
|
-
return;
|
25
|
-
}
|
26
|
-
const commandValueNode = nodes[0];
|
27
|
-
const command = commandValueNode.getText();
|
28
|
-
let project;
|
29
|
-
let portFlagValue;
|
30
|
-
if (command.includes('nx run')) {
|
31
|
-
const NX_RUN_TARGET_REGEX = /(?<=nx run )([^' ]+)(?: [^']*--port[= ](\d+))?/;
|
32
|
-
const matches = command.match(NX_RUN_TARGET_REGEX);
|
33
|
-
if (!matches) {
|
34
|
-
return;
|
35
|
-
}
|
36
|
-
const targetString = matches[1];
|
37
|
-
const parsedTargetString = (0, devkit_1.parseTargetString)(targetString, graph);
|
38
|
-
if (parsedTargetString.target === 'serve-static' ||
|
39
|
-
parsedTargetString.target === 'preview') {
|
40
|
-
return;
|
41
|
-
}
|
42
|
-
project = parsedTargetString.project;
|
43
|
-
portFlagValue = matches[2];
|
44
|
-
}
|
45
|
-
else {
|
46
|
-
const NX_PROJECT_REGEX = /(?<=nx [^ ]+ )([^' ]+)(?: [^']*--port[= ](\d+))?/;
|
47
|
-
const matches = command.match(NX_PROJECT_REGEX);
|
48
|
-
if (!matches) {
|
49
|
-
return;
|
50
|
-
}
|
51
|
-
project = matches[1];
|
52
|
-
portFlagValue = matches[2];
|
53
|
-
}
|
54
|
-
if (!project || !graph.nodes[project]) {
|
55
|
-
return;
|
56
|
-
}
|
57
|
-
const pathToViteConfig = [
|
58
|
-
(0, devkit_1.joinPathFragments)(graph.nodes[project].data.root, 'vite.config.ts'),
|
59
|
-
(0, devkit_1.joinPathFragments)(graph.nodes[project].data.root, 'vite.config.js'),
|
60
|
-
].find((p) => tree.exists(p));
|
61
|
-
const pathToWebpackConfig = [
|
62
|
-
(0, devkit_1.joinPathFragments)(graph.nodes[project].data.root, 'webpack.config.ts'),
|
63
|
-
(0, devkit_1.joinPathFragments)(graph.nodes[project].data.root, 'webpack.config.js'),
|
64
|
-
].find((p) => tree.exists(p));
|
65
|
-
const configFile = pathToWebpackConfig ?? pathToViteConfig;
|
66
|
-
// Only migrate projects that have a webpack or vite config file
|
67
|
-
if (configFile) {
|
68
|
-
collectedProjects.push({
|
69
|
-
projectName: project,
|
70
|
-
configFile,
|
71
|
-
configFileType: pathToWebpackConfig ? 'webpack' : 'vite',
|
72
|
-
playwrightConfigFile: path,
|
73
|
-
commandValueNode,
|
74
|
-
portFlagValue,
|
75
|
-
});
|
76
|
-
}
|
77
|
-
});
|
78
|
-
for (const projectToMigrate of collectedProjects) {
|
79
|
-
let playwrightConfigFileContents = tree.read(projectToMigrate.playwrightConfigFile, 'utf-8');
|
80
|
-
const targetName = (await getServeStaticTargetNameForConfigFile(tree, projectToMigrate.configFileType === 'webpack'
|
81
|
-
? '@nx/webpack/plugin'
|
82
|
-
: '@nx/vite/plugin', projectToMigrate.configFile, projectToMigrate.configFileType === 'webpack'
|
83
|
-
? 'serve-static'
|
84
|
-
: 'preview', projectToMigrate.configFileType === 'webpack'
|
85
|
-
? 'serveStaticTargetName'
|
86
|
-
: 'previewTargetName', projectToMigrate.configFileType === 'webpack'
|
87
|
-
? require('@nx/webpack/plugin').createNodesV2
|
88
|
-
: require('@nx/vite/plugin')
|
89
|
-
.createNodesV2)) ??
|
90
|
-
getServeStaticLikeTarget(tree, graph, projectToMigrate.projectName, projectToMigrate.configFileType === 'webpack'
|
91
|
-
? '@nx/web:file-server'
|
92
|
-
: '@nx/vite:preview-server');
|
93
|
-
if (!targetName) {
|
94
|
-
continue;
|
95
|
-
}
|
96
|
-
const oldCommand = projectToMigrate.commandValueNode.getText();
|
97
|
-
const newCommand = oldCommand.replace(/nx.*[^"']/, `nx run ${projectToMigrate.projectName}:${targetName}${projectToMigrate.portFlagValue
|
98
|
-
? ` --port=${projectToMigrate.portFlagValue}`
|
99
|
-
: ''}`);
|
100
|
-
if (projectToMigrate.configFileType === 'webpack') {
|
101
|
-
tree.write(projectToMigrate.playwrightConfigFile, `${playwrightConfigFileContents.slice(0, projectToMigrate.commandValueNode.getStart())}${newCommand}${playwrightConfigFileContents.slice(projectToMigrate.commandValueNode.getEnd())}`);
|
102
|
-
}
|
103
|
-
else {
|
104
|
-
tree.write(projectToMigrate.playwrightConfigFile, `${playwrightConfigFileContents.slice(0, projectToMigrate.commandValueNode.getStart())}${newCommand}${playwrightConfigFileContents.slice(projectToMigrate.commandValueNode.getEnd())}`);
|
105
|
-
playwrightConfigFileContents = tree.read(projectToMigrate.playwrightConfigFile, 'utf-8');
|
106
|
-
let ast = tsquery_1.tsquery.ast(playwrightConfigFileContents);
|
107
|
-
const BASE_URL_SELECTOR = 'VariableDeclaration:has(Identifier[name=baseURL])';
|
108
|
-
const baseUrlNodes = (0, tsquery_1.tsquery)(ast, BASE_URL_SELECTOR, {
|
109
|
-
visitAllChildren: true,
|
110
|
-
});
|
111
|
-
if (!baseUrlNodes.length) {
|
112
|
-
return;
|
113
|
-
}
|
114
|
-
const serverUrl = `http://localhost:${projectToMigrate.portFlagValue ?? '4300'}`;
|
115
|
-
const baseUrlNode = baseUrlNodes[0];
|
116
|
-
const newBaseUrlVariableDeclaration = `baseURL = process.env['BASE_URL'] || '${serverUrl}';`;
|
117
|
-
tree.write(projectToMigrate.playwrightConfigFile, `${playwrightConfigFileContents.slice(0, baseUrlNode.getStart())}${newBaseUrlVariableDeclaration}${playwrightConfigFileContents.slice(baseUrlNode.getEnd())}`);
|
118
|
-
playwrightConfigFileContents = tree.read(projectToMigrate.playwrightConfigFile, 'utf-8');
|
119
|
-
ast = tsquery_1.tsquery.ast(playwrightConfigFileContents);
|
120
|
-
const WEB_SERVER_URL_SELECTOR = 'PropertyAssignment:has(Identifier[name=webServer]) PropertyAssignment:has(Identifier[name=url]) > StringLiteral';
|
121
|
-
const webServerUrlNodes = (0, tsquery_1.tsquery)(ast, WEB_SERVER_URL_SELECTOR, {
|
122
|
-
visitAllChildren: true,
|
123
|
-
});
|
124
|
-
if (!webServerUrlNodes.length) {
|
125
|
-
return;
|
126
|
-
}
|
127
|
-
const webServerUrlNode = webServerUrlNodes[0];
|
128
|
-
const newWebServerUrl = `'${serverUrl}'`;
|
129
|
-
tree.write(projectToMigrate.playwrightConfigFile, `${playwrightConfigFileContents.slice(0, webServerUrlNode.getStart())}${newWebServerUrl}${playwrightConfigFileContents.slice(webServerUrlNode.getEnd())}`);
|
130
|
-
}
|
131
|
-
}
|
132
|
-
await (0, add_e2e_ci_target_defaults_1.default)(tree);
|
133
|
-
await (0, devkit_1.formatFiles)(tree);
|
134
|
-
}
|
135
|
-
async function getServeStaticTargetNameForConfigFile(tree, pluginName, configFile, defaultTargetName, targetNamePluginOption, createNodesV2) {
|
136
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
137
|
-
const matchingPluginRegistrations = nxJson.plugins?.filter((p) => typeof p === 'string' ? p === pluginName : p.plugin === pluginName);
|
138
|
-
if (!matchingPluginRegistrations) {
|
139
|
-
return undefined;
|
140
|
-
}
|
141
|
-
let targetName = undefined;
|
142
|
-
for (const plugin of matchingPluginRegistrations) {
|
143
|
-
let projectConfigs;
|
144
|
-
try {
|
145
|
-
const loadedPlugin = new loaded_nx_plugin_1.LoadedNxPlugin({ createNodesV2, name: pluginName }, plugin);
|
146
|
-
projectConfigs = await (0, retrieve_workspace_files_1.retrieveProjectConfigurations)([loadedPlugin], tree.root, nxJson);
|
147
|
-
}
|
148
|
-
catch (e) {
|
149
|
-
if (e instanceof error_types_1.ProjectConfigurationsError) {
|
150
|
-
projectConfigs = e.partialProjectConfigurationsResult;
|
151
|
-
}
|
152
|
-
else {
|
153
|
-
throw e;
|
154
|
-
}
|
155
|
-
}
|
156
|
-
if (projectConfigs.matchingProjectFiles.includes(configFile)) {
|
157
|
-
targetName =
|
158
|
-
typeof plugin === 'string'
|
159
|
-
? defaultTargetName
|
160
|
-
: plugin.options?.[targetNamePluginOption] ??
|
161
|
-
defaultTargetName;
|
162
|
-
}
|
163
|
-
}
|
164
|
-
return targetName;
|
165
|
-
}
|
166
|
-
function getServeStaticLikeTarget(tree, graph, projectName, executorName) {
|
167
|
-
if (!graph.nodes[projectName]?.data?.targets) {
|
168
|
-
return;
|
169
|
-
}
|
170
|
-
for (const [targetName, targetOptions] of Object.entries(graph.nodes[projectName].data.targets)) {
|
171
|
-
if (targetOptions.executor && targetOptions.executor === executorName) {
|
172
|
-
return targetName;
|
173
|
-
}
|
174
|
-
}
|
175
|
-
}
|