@nx/playwright 19.5.6 → 19.6.0-beta.0

Sign up to get free protection for your applications and to get access to all the features.
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.5.6",
3
+ "version": "19.6.0-beta.0",
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.5.6",
39
- "@nx/eslint": "19.5.6",
40
- "@nx/js": "19.5.6",
38
+ "@nx/devkit": "19.6.0-beta.0",
39
+ "@nx/eslint": "19.6.0-beta.0",
40
+ "@nx/js": "19.6.0-beta.0",
41
41
  "tslib": "^2.3.0",
42
42
  "minimatch": "9.0.3"
43
43
  },
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export default function addE2eCiTargetDefaults(tree: Tree): Promise<void>;
@@ -0,0 +1,83 @@
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 internal_api_1 = require("nx/src/project-graph/plugins/internal-api");
7
+ const devkit_internals_1 = require("nx/src/devkit-internals");
8
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
9
+ async function addE2eCiTargetDefaults(tree) {
10
+ const pluginName = '@nx/playwright/plugin';
11
+ const graph = await (0, devkit_1.createProjectGraphAsync)();
12
+ const nxJson = (0, devkit_1.readNxJson)(tree);
13
+ const matchingPluginRegistrations = nxJson.plugins?.filter((p) => typeof p === 'string' ? p === pluginName : p.plugin === pluginName);
14
+ if (!matchingPluginRegistrations) {
15
+ return;
16
+ }
17
+ const { createNodesV2, } = await Promise.resolve(`${pluginName}`).then(s => require(s));
18
+ for (const plugin of matchingPluginRegistrations) {
19
+ let projectConfigs;
20
+ try {
21
+ const loadedPlugin = new internal_api_1.LoadedNxPlugin({ createNodesV2, name: pluginName }, plugin);
22
+ projectConfigs = await (0, devkit_internals_1.retrieveProjectConfigurations)([loadedPlugin], tree.root, nxJson);
23
+ }
24
+ catch (e) {
25
+ if (e instanceof devkit_internals_1.ProjectConfigurationsError) {
26
+ projectConfigs = e.partialProjectConfigurationsResult;
27
+ }
28
+ else {
29
+ throw e;
30
+ }
31
+ }
32
+ for (const configFile of projectConfigs.matchingProjectFiles) {
33
+ const configFileContents = tree.read(configFile, 'utf-8');
34
+ const ast = tsquery_1.tsquery.ast(configFileContents);
35
+ const CI_WEBSERVER_COMMAND_SELECTOR = 'PropertyAssignment:has(Identifier[name=webServer]) PropertyAssignment:has(Identifier[name=command]) > StringLiteral';
36
+ const nodes = (0, tsquery_1.tsquery)(ast, CI_WEBSERVER_COMMAND_SELECTOR, {
37
+ visitAllChildren: true,
38
+ });
39
+ if (!nodes.length) {
40
+ continue;
41
+ }
42
+ const ciWebServerCommand = nodes[0].getText();
43
+ let serveStaticProject;
44
+ let serveStaticTarget;
45
+ let serveStaticConfiguration;
46
+ if (ciWebServerCommand.includes('nx run')) {
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
+ serveStaticProject = project;
55
+ serveStaticTarget = target;
56
+ serveStaticConfiguration = configuration;
57
+ }
58
+ else {
59
+ const NX_PROJECT_REGEX = 'nx\\s+([^ ]+)\\s+([^ ]+)';
60
+ const matches = ciWebServerCommand.match(NX_PROJECT_REGEX);
61
+ if (!matches) {
62
+ return;
63
+ }
64
+ serveStaticTarget = matches[1];
65
+ serveStaticProject = matches[2];
66
+ }
67
+ const resolvedServeStaticTarget = graph.nodes[serveStaticProject].data.targets[serveStaticTarget];
68
+ let resolvedBuildTarget;
69
+ if (resolvedServeStaticTarget.dependsOn) {
70
+ resolvedBuildTarget = resolvedServeStaticTarget.dependsOn.join(',');
71
+ }
72
+ else {
73
+ resolvedBuildTarget =
74
+ (serveStaticConfiguration
75
+ ? resolvedServeStaticTarget.configurations[serveStaticConfiguration]
76
+ .buildTarget
77
+ : resolvedServeStaticTarget.options.buildTarget) ?? 'build';
78
+ }
79
+ const buildTarget = `^${resolvedBuildTarget}`;
80
+ await (0, target_defaults_utils_1.addE2eCiTargetDefaults)(tree, pluginName, buildTarget, configFile);
81
+ }
82
+ }
83
+ }
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export default function (tree: Tree): Promise<void>;
@@ -0,0 +1,86 @@
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
+ async function default_1(tree) {
8
+ const graph = await (0, devkit_1.createProjectGraphAsync)();
9
+ (0, devkit_1.visitNotIgnoredFiles)(tree, '', (path) => {
10
+ if (!path.endsWith('playwright.config.ts')) {
11
+ return;
12
+ }
13
+ let playwrightConfigFileContents = tree.read(path, 'utf-8');
14
+ const WEBSERVER_COMMAND_SELECTOR = 'PropertyAssignment:has(Identifier[name=webServer]) PropertyAssignment:has(Identifier[name=command]) > StringLiteral';
15
+ let ast = tsquery_1.tsquery.ast(playwrightConfigFileContents);
16
+ const nodes = (0, tsquery_1.tsquery)(ast, WEBSERVER_COMMAND_SELECTOR, {
17
+ visitAllChildren: true,
18
+ });
19
+ if (!nodes.length) {
20
+ return;
21
+ }
22
+ const commandValueNode = nodes[0];
23
+ const command = commandValueNode.getText();
24
+ let project;
25
+ if (command.includes('nx run')) {
26
+ const NX_TARGET_REGEX = "(?<=nx run )[^']+";
27
+ const matches = command.match(NX_TARGET_REGEX);
28
+ if (!matches) {
29
+ return;
30
+ }
31
+ const targetString = matches[0];
32
+ const parsedTargetString = (0, devkit_1.parseTargetString)(targetString, graph);
33
+ if (parsedTargetString.target === 'serve-static' ||
34
+ parsedTargetString.target === 'preview') {
35
+ return;
36
+ }
37
+ project = parsedTargetString.project;
38
+ }
39
+ else {
40
+ const NX_PROJECT_REGEX = "(?<=nx [^ ]+ )[^']+";
41
+ const matches = command.match(NX_PROJECT_REGEX);
42
+ if (!matches) {
43
+ return;
44
+ }
45
+ project = matches[0];
46
+ }
47
+ const pathToViteConfig = [
48
+ (0, devkit_1.joinPathFragments)(graph.nodes[project].data.root, 'vite.config.ts'),
49
+ (0, devkit_1.joinPathFragments)(graph.nodes[project].data.root, 'vite.config.js'),
50
+ ].find((p) => tree.exists(p));
51
+ if (!pathToViteConfig) {
52
+ const newCommand = `${(0, devkit_1.getPackageManagerCommand)().exec} nx run ${project}:serve-static`;
53
+ tree.write(path, `${playwrightConfigFileContents.slice(0, commandValueNode.getStart())}"${newCommand}"${playwrightConfigFileContents.slice(commandValueNode.getEnd())}`);
54
+ }
55
+ else {
56
+ const newCommand = `${(0, devkit_1.getPackageManagerCommand)().exec} nx run ${project}:preview`;
57
+ tree.write(path, `${playwrightConfigFileContents.slice(0, commandValueNode.getStart())}"${newCommand}"${playwrightConfigFileContents.slice(commandValueNode.getEnd())}`);
58
+ playwrightConfigFileContents = tree.read(path, 'utf-8');
59
+ ast = tsquery_1.tsquery.ast(playwrightConfigFileContents);
60
+ const BASE_URL_SELECTOR = 'VariableDeclaration:has(Identifier[name=baseURL])';
61
+ const baseUrlNodes = (0, tsquery_1.tsquery)(ast, BASE_URL_SELECTOR, {
62
+ visitAllChildren: true,
63
+ });
64
+ if (!baseUrlNodes.length) {
65
+ return;
66
+ }
67
+ const baseUrlNode = baseUrlNodes[0];
68
+ const newBaseUrlVariableDeclaration = "baseURL = process.env['BASE_URL'] || 'http://localhost:4300';";
69
+ tree.write(path, `${playwrightConfigFileContents.slice(0, baseUrlNode.getStart())}${newBaseUrlVariableDeclaration}${playwrightConfigFileContents.slice(baseUrlNode.getEnd())}`);
70
+ playwrightConfigFileContents = tree.read(path, 'utf-8');
71
+ ast = tsquery_1.tsquery.ast(playwrightConfigFileContents);
72
+ const WEB_SERVER_URL_SELECTOR = 'PropertyAssignment:has(Identifier[name=webServer]) PropertyAssignment:has(Identifier[name=url]) > StringLiteral';
73
+ const webServerUrlNodes = (0, tsquery_1.tsquery)(ast, WEB_SERVER_URL_SELECTOR, {
74
+ visitAllChildren: true,
75
+ });
76
+ if (!webServerUrlNodes.length) {
77
+ return;
78
+ }
79
+ const webServerUrlNode = webServerUrlNodes[0];
80
+ const newWebServerUrl = "'http://localhost:4300'";
81
+ tree.write(path, `${playwrightConfigFileContents.slice(0, webServerUrlNode.getStart())}${newWebServerUrl}${playwrightConfigFileContents.slice(webServerUrlNode.getEnd())}`);
82
+ }
83
+ });
84
+ await (0, add_e2e_ci_target_defaults_1.default)(tree);
85
+ await (0, devkit_1.formatFiles)(tree);
86
+ }