@nx/playwright 19.2.0-canary.20240530-316dcb9 → 19.2.0-canary.20240601-6f22300
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-canary.
|
3
|
+
"version": "19.2.0-canary.20240601-6f22300",
|
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-canary.
|
39
|
-
"@nx/eslint": "19.2.0-canary.
|
40
|
-
"@nx/js": "19.2.0-canary.
|
38
|
+
"@nx/devkit": "19.2.0-canary.20240601-6f22300",
|
39
|
+
"@nx/eslint": "19.2.0-canary.20240601-6f22300",
|
40
|
+
"@nx/js": "19.2.0-canary.20240601-6f22300",
|
41
41
|
"tslib": "^2.3.0",
|
42
42
|
"minimatch": "9.0.3"
|
43
43
|
},
|
package/plugin.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export { createNodes,
|
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.
|
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, "
|
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.
|
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.
|
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);
|
package/src/plugins/plugin.d.ts
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
import {
|
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
|
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>;
|
package/src/plugins/plugin.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.createNodes = exports.
|
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
|
15
|
-
|
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
|
-
|
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
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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.
|
@@ -77,18 +88,24 @@ async function buildPlaywrightTargets(configFilePath, projectRoot, options, cont
|
|
77
88
|
targets[options.targetName] = {
|
78
89
|
...baseTargetConfig,
|
79
90
|
cache: true,
|
80
|
-
inputs:
|
81
|
-
|
82
|
-
|
91
|
+
inputs: [
|
92
|
+
...('production' in namedInputs
|
93
|
+
? ['default', '^production']
|
94
|
+
: ['default', '^default']),
|
95
|
+
{ externalDependencies: ['@playwright/test'] },
|
96
|
+
],
|
83
97
|
outputs: getOutputs(projectRoot, playwrightConfig),
|
84
98
|
};
|
85
99
|
if (options.ciTargetName) {
|
86
100
|
const ciBaseTargetConfig = {
|
87
101
|
...baseTargetConfig,
|
88
102
|
cache: true,
|
89
|
-
inputs:
|
90
|
-
|
91
|
-
|
103
|
+
inputs: [
|
104
|
+
...('production' in namedInputs
|
105
|
+
? ['default', '^production']
|
106
|
+
: ['default', '^default']),
|
107
|
+
{ externalDependencies: ['@playwright/test'] },
|
108
|
+
],
|
92
109
|
outputs: getOutputs(projectRoot, playwrightConfig),
|
93
110
|
};
|
94
111
|
const groupName = 'E2E (CI)';
|
@@ -100,7 +117,7 @@ async function buildPlaywrightTargets(configFilePath, projectRoot, options, cont
|
|
100
117
|
// Playwright defaults to the following pattern.
|
101
118
|
playwrightConfig.testMatch ??= '**/*.@(spec|test).?(c|m)[jt]s?(x)';
|
102
119
|
const dependsOn = [];
|
103
|
-
forEachTestFile((testFile) => {
|
120
|
+
await forEachTestFile((testFile) => {
|
104
121
|
const relativeSpecFilePath = (0, devkit_1.normalizePath)((0, path_1.relative)(projectRoot, testFile));
|
105
122
|
const targetName = `${options.ciTargetName}--${relativeSpecFilePath}`;
|
106
123
|
ciTargetGroup.push(targetName);
|
@@ -138,8 +155,8 @@ async function buildPlaywrightTargets(configFilePath, projectRoot, options, cont
|
|
138
155
|
}
|
139
156
|
return { targets, metadata };
|
140
157
|
}
|
141
|
-
function forEachTestFile(cb, opts) {
|
142
|
-
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);
|
143
160
|
const matcher = createMatcher(opts.config.testMatch);
|
144
161
|
const ignoredMatcher = opts.config.testIgnore
|
145
162
|
? createMatcher(opts.config.testIgnore)
|