@nx/playwright 19.2.0-beta.3 → 19.2.0-beta.5

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.3",
3
+ "version": "19.2.0-beta.5",
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.3",
39
- "@nx/eslint": "19.2.0-beta.3",
40
- "@nx/js": "19.2.0-beta.3",
38
+ "@nx/devkit": "19.2.0-beta.5",
39
+ "@nx/eslint": "19.2.0-beta.5",
40
+ "@nx/js": "19.2.0-beta.5",
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.addPlugin)(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,63 @@ 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 = (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [
57
+ (0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot)),
58
+ ]);
59
+ targetsCache[hash] ??= await buildPlaywrightTargets(configFilePath, projectRoot, normalizedOptions, context);
60
+ const { targets, metadata } = targetsCache[hash];
61
+ return {
62
+ projects: {
63
+ [projectRoot]: {
64
+ root: projectRoot,
65
+ targets,
66
+ metadata,
67
+ },
68
+ },
69
+ };
70
+ }
58
71
  async function buildPlaywrightTargets(configFilePath, projectRoot, options, context) {
59
72
  // Playwright forbids importing the `@playwright/test` module twice. This would affect running the tests,
60
73
  // but we're just reading the config so let's delete the variable they are using to detect this.
@@ -77,18 +90,24 @@ async function buildPlaywrightTargets(configFilePath, projectRoot, options, cont
77
90
  targets[options.targetName] = {
78
91
  ...baseTargetConfig,
79
92
  cache: true,
80
- inputs: 'production' in namedInputs
81
- ? ['default', '^production']
82
- : ['default', '^default'],
93
+ inputs: [
94
+ ...('production' in namedInputs
95
+ ? ['default', '^production']
96
+ : ['default', '^default']),
97
+ { externalDependencies: ['@playwright/test'] },
98
+ ],
83
99
  outputs: getOutputs(projectRoot, playwrightConfig),
84
100
  };
85
101
  if (options.ciTargetName) {
86
102
  const ciBaseTargetConfig = {
87
103
  ...baseTargetConfig,
88
104
  cache: true,
89
- inputs: 'production' in namedInputs
90
- ? ['default', '^production']
91
- : ['default', '^default'],
105
+ inputs: [
106
+ ...('production' in namedInputs
107
+ ? ['default', '^production']
108
+ : ['default', '^default']),
109
+ { externalDependencies: ['@playwright/test'] },
110
+ ],
92
111
  outputs: getOutputs(projectRoot, playwrightConfig),
93
112
  };
94
113
  const groupName = 'E2E (CI)';