@nx/playwright 19.6.0-canary.20240801-2111841 → 19.6.0-canary.20240803-bd7a2c9
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
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
"version": "18.1.0-beta.3",
|
|
12
12
|
"description": "Remove invalid baseUrl option from @nx/playwright:playwright targets in project.json.",
|
|
13
13
|
"implementation": "./src/migrations/update-18-1-0/remove-baseUrl-from-project-json"
|
|
14
|
+
},
|
|
15
|
+
"19-6-0-use-serve-static-preview-for-command": {
|
|
16
|
+
"cli": "nx",
|
|
17
|
+
"version": "19.6.0-beta.0",
|
|
18
|
+
"description": "Use serve-static or preview for webServerCommand.",
|
|
19
|
+
"implementation": "./src/migrations/update-19-6-0/use-serve-static-preview-for-command"
|
|
14
20
|
}
|
|
15
21
|
}
|
|
16
22
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/playwright",
|
|
3
|
-
"version": "19.6.0-canary.
|
|
3
|
+
"version": "19.6.0-canary.20240803-bd7a2c9",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"homepage": "https://nx.dev",
|
|
6
6
|
"private": false,
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
38
|
-
"@nx/devkit": "19.6.0-canary.
|
|
39
|
-
"@nx/eslint": "19.6.0-canary.
|
|
40
|
-
"@nx/js": "19.6.0-canary.
|
|
38
|
+
"@nx/devkit": "19.6.0-canary.20240803-bd7a2c9",
|
|
39
|
+
"@nx/eslint": "19.6.0-canary.20240803-bd7a2c9",
|
|
40
|
+
"@nx/js": "19.6.0-canary.20240803-bd7a2c9",
|
|
41
41
|
"tslib": "^2.3.0",
|
|
42
42
|
"minimatch": "9.0.3"
|
|
43
43
|
},
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
async function default_1(tree) {
|
|
7
|
+
const graph = await (0, devkit_1.createProjectGraphAsync)();
|
|
8
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, '', (path) => {
|
|
9
|
+
if (!path.endsWith('playwright.config.ts')) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
let playwrightConfigFileContents = tree.read(path, 'utf-8');
|
|
13
|
+
const WEBSERVER_COMMAND_SELECTOR = 'PropertyAssignment:has(Identifier[name=webServer]) PropertyAssignment:has(Identifier[name=command]) > StringLiteral';
|
|
14
|
+
let ast = tsquery_1.tsquery.ast(playwrightConfigFileContents);
|
|
15
|
+
const nodes = (0, tsquery_1.tsquery)(ast, WEBSERVER_COMMAND_SELECTOR, {
|
|
16
|
+
visitAllChildren: true,
|
|
17
|
+
});
|
|
18
|
+
if (!nodes.length) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const commandValueNode = nodes[0];
|
|
22
|
+
const command = commandValueNode.getText();
|
|
23
|
+
let project;
|
|
24
|
+
if (command.includes('nx run')) {
|
|
25
|
+
const NX_TARGET_REGEX = "(?<=nx run )[^']+";
|
|
26
|
+
const matches = command.match(NX_TARGET_REGEX);
|
|
27
|
+
if (!matches) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const targetString = matches[0];
|
|
31
|
+
const parsedTargetString = (0, devkit_1.parseTargetString)(targetString, graph);
|
|
32
|
+
if (parsedTargetString.target === 'serve-static' ||
|
|
33
|
+
parsedTargetString.target === 'preview') {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
project = parsedTargetString.project;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const NX_PROJECT_REGEX = "(?<=nx [^ ]+ )[^']+";
|
|
40
|
+
const matches = command.match(NX_PROJECT_REGEX);
|
|
41
|
+
if (!matches) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
project = matches[0];
|
|
45
|
+
}
|
|
46
|
+
const pathToViteConfig = [
|
|
47
|
+
(0, devkit_1.joinPathFragments)(graph.nodes[project].data.root, 'vite.config.ts'),
|
|
48
|
+
(0, devkit_1.joinPathFragments)(graph.nodes[project].data.root, 'vite.config.js'),
|
|
49
|
+
].find((p) => tree.exists(p));
|
|
50
|
+
if (!pathToViteConfig) {
|
|
51
|
+
const newCommand = `${(0, devkit_1.getPackageManagerCommand)().exec} nx run ${project}:serve-static`;
|
|
52
|
+
tree.write(path, `${playwrightConfigFileContents.slice(0, commandValueNode.getStart())}"${newCommand}"${playwrightConfigFileContents.slice(commandValueNode.getEnd())}`);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const newCommand = `${(0, devkit_1.getPackageManagerCommand)().exec} nx run ${project}:preview`;
|
|
56
|
+
tree.write(path, `${playwrightConfigFileContents.slice(0, commandValueNode.getStart())}"${newCommand}"${playwrightConfigFileContents.slice(commandValueNode.getEnd())}`);
|
|
57
|
+
playwrightConfigFileContents = tree.read(path, 'utf-8');
|
|
58
|
+
ast = tsquery_1.tsquery.ast(playwrightConfigFileContents);
|
|
59
|
+
const BASE_URL_SELECTOR = 'VariableDeclaration:has(Identifier[name=baseURL])';
|
|
60
|
+
const baseUrlNodes = (0, tsquery_1.tsquery)(ast, BASE_URL_SELECTOR, {
|
|
61
|
+
visitAllChildren: true,
|
|
62
|
+
});
|
|
63
|
+
if (!baseUrlNodes.length) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const baseUrlNode = baseUrlNodes[0];
|
|
67
|
+
const newBaseUrlVariableDeclaration = "baseURL = process.env['BASE_URL'] || 'http://localhost:4300';";
|
|
68
|
+
tree.write(path, `${playwrightConfigFileContents.slice(0, baseUrlNode.getStart())}${newBaseUrlVariableDeclaration}${playwrightConfigFileContents.slice(baseUrlNode.getEnd())}`);
|
|
69
|
+
playwrightConfigFileContents = tree.read(path, 'utf-8');
|
|
70
|
+
ast = tsquery_1.tsquery.ast(playwrightConfigFileContents);
|
|
71
|
+
const WEB_SERVER_URL_SELECTOR = 'PropertyAssignment:has(Identifier[name=webServer]) PropertyAssignment:has(Identifier[name=url]) > StringLiteral';
|
|
72
|
+
const webServerUrlNodes = (0, tsquery_1.tsquery)(ast, WEB_SERVER_URL_SELECTOR, {
|
|
73
|
+
visitAllChildren: true,
|
|
74
|
+
});
|
|
75
|
+
if (!webServerUrlNodes.length) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const webServerUrlNode = webServerUrlNodes[0];
|
|
79
|
+
const newWebServerUrl = "'http://localhost:4300'";
|
|
80
|
+
tree.write(path, `${playwrightConfigFileContents.slice(0, webServerUrlNode.getStart())}${newWebServerUrl}${playwrightConfigFileContents.slice(webServerUrlNode.getEnd())}`);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
84
|
+
}
|