@nx/playwright 18.0.0-canary.20240202-ea5befb → 18.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/generators.json CHANGED
@@ -3,12 +3,12 @@
3
3
  "version": "0.1",
4
4
  "generators": {
5
5
  "configuration": {
6
- "factory": "./src/generators/configuration/configuration",
6
+ "factory": "./src/generators/configuration/configuration#configurationGeneratorInternal",
7
7
  "schema": "./src/generators/configuration/schema.json",
8
8
  "description": "Add Nx Playwright configuration to your project"
9
9
  },
10
10
  "init": {
11
- "factory": "./src/generators/init/init",
11
+ "factory": "./src/generators/init/init#initGeneratorInternal",
12
12
  "schema": "./src/generators/init/schema.json",
13
13
  "description": "Initializes a Playwright project in the current workspace"
14
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/playwright",
3
- "version": "18.0.0-canary.20240202-ea5befb",
3
+ "version": "18.0.0",
4
4
  "type": "commonjs",
5
5
  "homepage": "https://nx.dev",
6
6
  "private": false,
@@ -33,9 +33,9 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@phenomnomnominal/tsquery": "~5.0.1",
36
- "@nx/devkit": "18.0.0-canary.20240202-ea5befb",
37
- "@nx/eslint": "18.0.0-canary.20240202-ea5befb",
38
- "@nx/js": "18.0.0-canary.20240202-ea5befb",
36
+ "@nx/devkit": "18.0.0",
37
+ "@nx/eslint": "18.0.0",
38
+ "@nx/js": "18.0.0",
39
39
  "tslib": "^2.3.0",
40
40
  "minimatch": "9.0.3"
41
41
  },
package/plugin.d.ts CHANGED
@@ -1 +1 @@
1
- export { createNodes, PlaywrightPluginOptions } from './src/plugins/plugin';
1
+ export { createNodes, PlaywrightPluginOptions, createDependencies, } from './src/plugins/plugin';
package/plugin.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createNodes = void 0;
3
+ exports.createDependencies = 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; } });
@@ -1,4 +1,5 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { ConfigurationGeneratorSchema } from './schema';
3
3
  export declare function configurationGenerator(tree: Tree, options: ConfigurationGeneratorSchema): Promise<GeneratorCallback>;
4
+ export declare function configurationGeneratorInternal(tree: Tree, options: ConfigurationGeneratorSchema): Promise<GeneratorCallback>;
4
5
  export default configurationGenerator;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.configurationGenerator = void 0;
3
+ exports.configurationGeneratorInternal = exports.configurationGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const js_1 = require("@nx/js");
6
6
  const versions_1 = require("@nx/js/src/utils/versions");
@@ -9,11 +9,17 @@ const path = require("path");
9
9
  const add_linter_1 = require("../../utils/add-linter");
10
10
  const versions_2 = require("../../utils/versions");
11
11
  const init_1 = require("../init/init");
12
- async function configurationGenerator(tree, options) {
12
+ function configurationGenerator(tree, options) {
13
+ return configurationGeneratorInternal(tree, { addPlugin: false, ...options });
14
+ }
15
+ exports.configurationGenerator = configurationGenerator;
16
+ async function configurationGeneratorInternal(tree, options) {
17
+ options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
13
18
  const tasks = [];
14
19
  tasks.push(await (0, init_1.initGenerator)(tree, {
15
20
  skipFormat: true,
16
21
  skipPackageJson: options.skipPackageJson,
22
+ addPlugin: options.addPlugin,
17
23
  }));
18
24
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
19
25
  const hasTsConfig = tree.exists((0, devkit_1.joinPathFragments)(projectConfig.root, 'tsconfig.json'));
@@ -59,6 +65,7 @@ async function configurationGenerator(tree, options) {
59
65
  directory: options.directory,
60
66
  setParserOptionsProject: options.setParserOptionsProject,
61
67
  rootProject: options.rootProject ?? projectConfig.root === '.',
68
+ addPlugin: options.addPlugin,
62
69
  }));
63
70
  if (options.js) {
64
71
  const { ModuleKind } = (0, devkit_1.ensurePackage)('typescript', versions_1.typescriptVersion);
@@ -79,7 +86,7 @@ async function configurationGenerator(tree, options) {
79
86
  }
80
87
  return (0, devkit_1.runTasksInSerial)(...tasks);
81
88
  }
82
- exports.configurationGenerator = configurationGenerator;
89
+ exports.configurationGeneratorInternal = configurationGeneratorInternal;
83
90
  function getBrowsersInstallTask() {
84
91
  return () => {
85
92
  devkit_1.output.log({
@@ -23,4 +23,5 @@ export interface ConfigurationGeneratorSchema {
23
23
  **/
24
24
  webServerAddress?: string;
25
25
  rootProject?: boolean;
26
+ addPlugin?: boolean;
26
27
  }
@@ -1,4 +1,5 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { InitGeneratorSchema } from './schema';
3
3
  export declare function initGenerator(tree: Tree, options: InitGeneratorSchema): Promise<GeneratorCallback>;
4
+ export declare function initGeneratorInternal(tree: Tree, options: InitGeneratorSchema): Promise<GeneratorCallback>;
4
5
  export default initGenerator;
@@ -1,19 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initGenerator = void 0;
3
+ exports.initGeneratorInternal = exports.initGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
6
6
  const plugin_1 = require("../../plugins/plugin");
7
7
  const versions_1 = require("../../utils/versions");
8
- async function initGenerator(tree, options) {
8
+ function initGenerator(tree, options) {
9
+ return initGeneratorInternal(tree, { addPlugin: false, ...options });
10
+ }
11
+ exports.initGenerator = initGenerator;
12
+ async function initGeneratorInternal(tree, options) {
9
13
  const tasks = [];
14
+ options.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
10
15
  if (!options.skipPackageJson) {
11
16
  tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
12
17
  '@nx/playwright': versions_1.nxVersion,
13
18
  '@playwright/test': versions_1.playwrightVersion,
14
19
  }, undefined, options.keepExistingVersions));
15
20
  }
16
- if (process.env.NX_PCV3 === 'true') {
21
+ if (options.addPlugin) {
17
22
  addPlugin(tree);
18
23
  }
19
24
  if (options.updatePackageScripts) {
@@ -24,7 +29,7 @@ async function initGenerator(tree, options) {
24
29
  }
25
30
  return (0, devkit_1.runTasksInSerial)(...tasks);
26
31
  }
27
- exports.initGenerator = initGenerator;
32
+ exports.initGeneratorInternal = initGeneratorInternal;
28
33
  function addPlugin(tree) {
29
34
  const nxJson = (0, devkit_1.readNxJson)(tree);
30
35
  nxJson.plugins ??= [];
@@ -3,4 +3,5 @@ export interface InitGeneratorSchema {
3
3
  skipPackageJson?: boolean;
4
4
  keepExistingVersions?: boolean;
5
5
  updatePackageScripts?: boolean;
6
+ addPlugin?: boolean;
6
7
  }
@@ -8,9 +8,9 @@ const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
8
8
  const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
9
9
  const workspace_context_1 = require("nx/src/utils/workspace-context");
10
10
  const minimatch_1 = require("minimatch");
11
- const load_config_file_1 = require("../utils/load-config-file");
12
11
  const cache_directory_1 = require("nx/src/utils/cache-directory");
13
12
  const js_1 = require("@nx/js");
13
+ const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
14
14
  const cachePath = (0, path_1.join)(cache_directory_1.projectGraphCacheDirectory, 'playwright.hash');
15
15
  const targetsCache = (0, fs_1.existsSync)(cachePath) ? readTargetsCache() : {};
16
16
  const calculatedTargets = {};
@@ -53,7 +53,11 @@ exports.createNodes = [
53
53
  },
54
54
  ];
55
55
  async function buildPlaywrightTargets(configFilePath, projectRoot, options, context) {
56
- const playwrightConfig = await (0, load_config_file_1.loadPlaywrightConfig)((0, path_1.join)(context.workspaceRoot, configFilePath));
56
+ // Playwright forbids importing the `@playwright/test` module twice. This would affect running the tests,
57
+ // but we're just reading the config so let's delete the variable they are using to detect this.
58
+ // See: https://github.com/microsoft/playwright/pull/11218/files
59
+ delete process['__pw_initiator__'];
60
+ const playwrightConfig = await (0, config_utils_1.loadConfigFile)((0, path_1.join)(context.workspaceRoot, configFilePath));
57
61
  const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
58
62
  const targets = {};
59
63
  const baseTargetConfig = {
@@ -11,5 +11,6 @@ export interface PlaywrightLinterOptions {
11
11
  * Directory from the project root, where the playwright files will be located.
12
12
  **/
13
13
  directory: string;
14
+ addPlugin?: boolean;
14
15
  }
15
16
  export declare function addLinterToPlaywrightProject(tree: Tree, options: PlaywrightLinterOptions): Promise<GeneratorCallback>;
@@ -22,6 +22,7 @@ async function addLinterToPlaywrightProject(tree, options) {
22
22
  setParserOptionsProject: options.setParserOptionsProject,
23
23
  skipPackageJson: options.skipPackageJson,
24
24
  rootProject: options.rootProject,
25
+ addPlugin: options.addPlugin,
25
26
  }));
26
27
  }
27
28
  if (!options.linter || options.linter !== eslint_1.Linter.EsLint) {
@@ -1,3 +0,0 @@
1
- import type { PlaywrightTestConfig } from '@playwright/test';
2
- export declare let dynamicImport: Function;
3
- export declare function loadPlaywrightConfig(configFilePath: any): Promise<PlaywrightTestConfig>;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadPlaywrightConfig = exports.dynamicImport = void 0;
4
- const path_1 = require("path");
5
- const js_1 = require("@nx/js");
6
- const internal_1 = require("@nx/js/src/internal");
7
- exports.dynamicImport = new Function('modulePath', 'return import(modulePath);');
8
- async function loadPlaywrightConfig(configFilePath) {
9
- {
10
- let module;
11
- const configPathWithTimestamp = `${configFilePath}?t=${Date.now()}`;
12
- if ((0, path_1.extname)(configFilePath) === '.ts') {
13
- const tsConfigPath = (0, js_1.getRootTsConfigPath)();
14
- if (tsConfigPath) {
15
- const unregisterTsProject = (0, internal_1.registerTsProject)(tsConfigPath);
16
- try {
17
- module = await (0, exports.dynamicImport)(configPathWithTimestamp);
18
- }
19
- finally {
20
- unregisterTsProject();
21
- }
22
- }
23
- else {
24
- module = await (0, exports.dynamicImport)(configPathWithTimestamp);
25
- }
26
- }
27
- else {
28
- module = await (0, exports.dynamicImport)(configPathWithTimestamp);
29
- }
30
- return module.default ?? module;
31
- }
32
- }
33
- exports.loadPlaywrightConfig = loadPlaywrightConfig;
34
- const packageInstallationDirectories = ['node_modules', '.yarn'];