@nx/playwright 19.2.0-beta.4 → 19.2.0-beta.6

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/playwright",
3
- "version": "19.2.0-beta.4",
3
+ "version": "19.2.0-beta.6",
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.2.0-beta.4",
39
- "@nx/eslint": "19.2.0-beta.4",
40
- "@nx/js": "19.2.0-beta.4",
38
+ "@nx/devkit": "19.2.0-beta.6",
39
+ "@nx/eslint": "19.2.0-beta.6",
40
+ "@nx/js": "19.2.0-beta.6",
41
41
  "tslib": "^2.3.0",
42
42
  "minimatch": "9.0.3"
43
43
  },
package/plugin.d.ts CHANGED
@@ -1 +1 @@
1
- export { createNodes, PlaywrightPluginOptions, createDependencies, } from './src/plugins/plugin';
1
+ export { createNodes, createNodesV2, PlaywrightPluginOptions, } from './src/plugins/plugin';
package/plugin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDependencies = exports.createNodes = void 0;
3
+ exports.createNodesV2 = exports.createNodes = void 0;
4
4
  var plugin_1 = require("./src/plugins/plugin");
5
5
  Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
6
- Object.defineProperty(exports, "createDependencies", { enumerable: true, get: function () { return plugin_1.createDependencies; } });
6
+ Object.defineProperty(exports, "createNodesV2", { enumerable: true, get: function () { return plugin_1.createNodesV2; } });
@@ -6,7 +6,7 @@ const plugin_1 = require("../../plugins/plugin");
6
6
  const executor_to_plugin_migrator_1 = require("@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator");
7
7
  async function convertToInferred(tree, options) {
8
8
  const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
9
- const migratedProjects = await (0, executor_to_plugin_migrator_1.migrateExecutorToPlugin)(tree, projectGraph, '@nx/playwright:playwright', '@nx/playwright/plugin', (targetName) => ({ targetName, ciTargetName: 'e2e-ci' }), postTargetTransformer, plugin_1.createNodes, options.project);
9
+ const migratedProjects = await (0, executor_to_plugin_migrator_1.migrateExecutorToPlugin)(tree, projectGraph, '@nx/playwright:playwright', '@nx/playwright/plugin', (targetName) => ({ targetName, ciTargetName: 'e2e-ci' }), postTargetTransformer, plugin_1.createNodesV2, options.project);
10
10
  if (migratedProjects.size === 0) {
11
11
  throw new Error('Could not find any targets to migrate.');
12
12
  }
@@ -22,7 +22,7 @@ async function initGeneratorInternal(tree, options) {
22
22
  }, undefined, options.keepExistingVersions));
23
23
  }
24
24
  if (options.addPlugin) {
25
- await (0, add_plugin_1.addPluginV1)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/playwright/plugin', plugin_1.createNodes, { targetName: ['e2e', 'playwright:e2e', 'playwright-e2e'] }, options.updatePackageScripts);
25
+ await (0, add_plugin_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/playwright/plugin', plugin_1.createNodesV2, { targetName: ['e2e', 'playwright:e2e', 'playwright-e2e'] }, options.updatePackageScripts);
26
26
  }
27
27
  if (!options.skipFormat) {
28
28
  await (0, devkit_1.formatFiles)(tree);
@@ -1,7 +1,11 @@
1
- import { CreateDependencies, CreateNodes } from '@nx/devkit';
1
+ import { CreateNodes, CreateNodesV2 } from '@nx/devkit';
2
2
  export interface PlaywrightPluginOptions {
3
3
  targetName?: string;
4
4
  ciTargetName?: string;
5
5
  }
6
- export declare const createDependencies: CreateDependencies;
6
+ export declare const createNodesV2: CreateNodesV2<PlaywrightPluginOptions>;
7
+ /**
8
+ * @deprecated This is replaced with {@link createNodesV2}. Update your plugin to export its own `createNodesV2` function that wraps this one instead.
9
+ * This function will change to the v2 function in Nx 20.
10
+ */
7
11
  export declare const createNodes: CreateNodes<PlaywrightPluginOptions>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createNodes = exports.createDependencies = void 0;
3
+ exports.createNodes = exports.createNodesV2 = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
6
  const devkit_1 = require("@nx/devkit");
@@ -11,50 +11,61 @@ const minimatch_1 = require("minimatch");
11
11
  const cache_directory_1 = require("nx/src/utils/cache-directory");
12
12
  const js_1 = require("@nx/js");
13
13
  const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
14
- const cachePath = (0, path_1.join)(cache_directory_1.projectGraphCacheDirectory, 'playwright.hash');
15
- const targetsCache = readTargetsCache();
16
- function readTargetsCache() {
14
+ const file_hasher_1 = require("nx/src/hasher/file-hasher");
15
+ function readTargetsCache(cachePath) {
17
16
  return (0, fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
18
17
  }
19
- function writeTargetsToCache() {
20
- const oldCache = readTargetsCache();
21
- (0, devkit_1.writeJsonFile)(cachePath, {
22
- ...readTargetsCache,
23
- targetsCache,
24
- });
18
+ function writeTargetsToCache(cachePath, results) {
19
+ (0, devkit_1.writeJsonFile)(cachePath, results);
25
20
  }
26
- const createDependencies = () => {
27
- writeTargetsToCache();
28
- return [];
29
- };
30
- exports.createDependencies = createDependencies;
31
- exports.createNodes = [
32
- '**/playwright.config.{js,ts,cjs,cts,mjs,mts}',
33
- async (configFilePath, options, context) => {
34
- const projectRoot = (0, path_1.dirname)(configFilePath);
35
- // Do not create a project if package.json and project.json isn't there.
36
- const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
37
- if (!siblingFiles.includes('package.json') &&
38
- !siblingFiles.includes('project.json')) {
39
- return {};
21
+ const playwrightConfigGlob = '**/playwright.config.{js,ts,cjs,cts,mjs,mts}';
22
+ exports.createNodesV2 = [
23
+ playwrightConfigGlob,
24
+ async (configFilePaths, options, context) => {
25
+ const optionsHash = (0, file_hasher_1.hashObject)(options);
26
+ const cachePath = (0, path_1.join)(cache_directory_1.projectGraphCacheDirectory, `playwright-${optionsHash}.hash`);
27
+ const targetsCache = readTargetsCache(cachePath);
28
+ try {
29
+ return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => createNodesInternal(configFile, options, context, targetsCache), configFilePaths, options, context);
40
30
  }
41
- const normalizedOptions = normalizeOptions(options);
42
- const hash = (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [
43
- (0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot)),
44
- ]);
45
- targetsCache[hash] ??= await buildPlaywrightTargets(configFilePath, projectRoot, normalizedOptions, context);
46
- const { targets, metadata } = targetsCache[hash];
47
- return {
48
- projects: {
49
- [projectRoot]: {
50
- root: projectRoot,
51
- targets,
52
- metadata,
53
- },
54
- },
55
- };
31
+ finally {
32
+ writeTargetsToCache(cachePath, targetsCache);
33
+ }
34
+ },
35
+ ];
36
+ /**
37
+ * @deprecated This is replaced with {@link createNodesV2}. Update your plugin to export its own `createNodesV2` function that wraps this one instead.
38
+ * This function will change to the v2 function in Nx 20.
39
+ */
40
+ exports.createNodes = [
41
+ playwrightConfigGlob,
42
+ async (configFile, options, context) => {
43
+ devkit_1.logger.warn('`createNodes` is deprecated. Update your plugin to utilize createNodesV2 instead. In Nx 20, this will change to the createNodesV2 API.');
44
+ return createNodesInternal(configFile, options, context, {});
56
45
  },
57
46
  ];
47
+ async function createNodesInternal(configFilePath, options, context, targetsCache) {
48
+ const projectRoot = (0, path_1.dirname)(configFilePath);
49
+ // Do not create a project if package.json and project.json isn't there.
50
+ const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
51
+ if (!siblingFiles.includes('package.json') &&
52
+ !siblingFiles.includes('project.json')) {
53
+ return {};
54
+ }
55
+ const normalizedOptions = normalizeOptions(options);
56
+ const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))]);
57
+ targetsCache[hash] ??= await buildPlaywrightTargets(configFilePath, projectRoot, normalizedOptions, context);
58
+ const { targets, metadata } = targetsCache[hash];
59
+ return {
60
+ projects: {
61
+ [projectRoot]: {
62
+ root: projectRoot,
63
+ targets,
64
+ metadata,
65
+ },
66
+ },
67
+ };
68
+ }
58
69
  async function buildPlaywrightTargets(configFilePath, projectRoot, options, context) {
59
70
  // Playwright forbids importing the `@playwright/test` module twice. This would affect running the tests,
60
71
  // but we're just reading the config so let's delete the variable they are using to detect this.
@@ -106,7 +117,7 @@ async function buildPlaywrightTargets(configFilePath, projectRoot, options, cont
106
117
  // Playwright defaults to the following pattern.
107
118
  playwrightConfig.testMatch ??= '**/*.@(spec|test).?(c|m)[jt]s?(x)';
108
119
  const dependsOn = [];
109
- forEachTestFile((testFile) => {
120
+ await forEachTestFile((testFile) => {
110
121
  const relativeSpecFilePath = (0, devkit_1.normalizePath)((0, path_1.relative)(projectRoot, testFile));
111
122
  const targetName = `${options.ciTargetName}--${relativeSpecFilePath}`;
112
123
  ciTargetGroup.push(targetName);
@@ -144,8 +155,8 @@ async function buildPlaywrightTargets(configFilePath, projectRoot, options, cont
144
155
  }
145
156
  return { targets, metadata };
146
157
  }
147
- function forEachTestFile(cb, opts) {
148
- const files = (0, workspace_context_1.getFilesInDirectoryUsingContext)(opts.context.workspaceRoot, opts.path);
158
+ async function forEachTestFile(cb, opts) {
159
+ const files = await (0, workspace_context_1.getFilesInDirectoryUsingContext)(opts.context.workspaceRoot, opts.path);
149
160
  const matcher = createMatcher(opts.config.testMatch);
150
161
  const ignoredMatcher = opts.config.testIgnore
151
162
  ? createMatcher(opts.config.testIgnore)