From e7096f1f2b4cc001789d15995b1a810d1565614a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mat=C3=ADas=20Apolonio?= <matias@mapolonio.dev>
Date: Wed, 1 Nov 2023 10:33:52 +0000
Subject: [PATCH] Fixed issues with Nx 17 (#108)

* moved runTasksInSerial import and fixed issue with undefined value when updating package.json

* bumped version

* updated failing test

* updated github setup

* bumped pnpm in engines

* updated create nx-workspace step in PR validation

* rolled back changes to prepare.yml
---
 .github/workflows/pr.yml                              |  1 +
 package.json                                          |  4 ++--
 packages/nx-playwright/package.json                   |  2 +-
 .../src/generators/init/generator.spec.ts             |  5 +++--
 .../nx-playwright/src/generators/init/generator.ts    | 11 ++++++++---
 .../nx-playwright/src/generators/project/generator.ts |  2 +-
 .../src/generators/project/lib/add-linting.ts         |  9 +++++++--
 7 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml
index 8e7c313..e6cf375 100644
--- a/.github/workflows/pr.yml
+++ b/.github/workflows/pr.yml
@@ -69,6 +69,7 @@ jobs:
           pnpm create nx-workspace \
             --name=$NX_WORKSPACE --appName=$NX_APP \
             --preset=next --style=@emotion/styled \
+            --e2eTestRunner=playwright --nextAppDir=false \
             --nxCloud=false --interactive=false < /dev/null
 
           pushd $NX_WORKSPACE
diff --git a/package.json b/package.json
index 1af17c7..fb28826 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@mands/nx-plugins",
-  "version": "0.6.2",
+  "version": "0.6.3",
   "description": "Nx plugins by M&S engineering",
   "license": "MIT",
   "private": false,
@@ -16,7 +16,7 @@
     "npm": "please-use-pnpm",
     "yarn": "please-use-pnpm",
     "node": ">=16",
-    "pnpm": ">=7.28"
+    "pnpm": ">=8.9"
   },
   "dependencies": {
     "glob": "^7.2.0"
diff --git a/packages/nx-playwright/package.json b/packages/nx-playwright/package.json
index 7c1c8de..546647f 100644
--- a/packages/nx-playwright/package.json
+++ b/packages/nx-playwright/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@mands/nx-playwright",
-  "version": "0.6.2",
+  "version": "0.6.3",
   "license": "MIT",
   "publishConfig": {
     "registry": "https://registry.npmjs.org"
diff --git a/packages/nx-playwright/src/generators/init/generator.spec.ts b/packages/nx-playwright/src/generators/init/generator.spec.ts
index b8396ea..ff685ba 100644
--- a/packages/nx-playwright/src/generators/init/generator.spec.ts
+++ b/packages/nx-playwright/src/generators/init/generator.spec.ts
@@ -17,6 +17,7 @@ const MOCK_HOST: Tree = {
 const treeFactory = () => MOCK_HOST;
 
 jest.mock('@nx/devkit', () => ({
+  ...jest.requireActual('@nx/devkit'),
   addDependenciesToPackageJson: jest.fn(),
   updateJson: jest.fn(),
   formatFiles: jest.fn(),
@@ -64,8 +65,8 @@ describe('generator', () => {
     expect(addDependenciesToPackageJsonMock).toHaveBeenCalledWith(
       host,
       {},
-      expect.objectContaining({
-        'axe-playwright': undefined,
+      expect.not.objectContaining({
+        'axe-playwright': expect.anything(),
       }),
     );
   });
diff --git a/packages/nx-playwright/src/generators/init/generator.ts b/packages/nx-playwright/src/generators/init/generator.ts
index 2b9e68b..c14e1c6 100644
--- a/packages/nx-playwright/src/generators/init/generator.ts
+++ b/packages/nx-playwright/src/generators/init/generator.ts
@@ -1,5 +1,10 @@
-import { addDependenciesToPackageJson, formatFiles, Tree, updateJson } from '@nx/devkit';
-import { runTasksInSerial } from '@nx/workspace/src/utilities/run-tasks-in-serial';
+import {
+  addDependenciesToPackageJson,
+  formatFiles,
+  runTasksInSerial,
+  Tree,
+  updateJson,
+} from '@nx/devkit';
 import { playwrightAxeVersion, playwrightTestVersion, playwrightVersion } from '../../versions';
 import { addGitIgnoreEntry } from './lib/add-git-ignore-entry';
 import { InitGeneratorSchema } from './schema';
@@ -15,9 +20,9 @@ export default async function playwrightInitGenerator(host: Tree, options: InitG
     host,
     {},
     {
-      'axe-playwright': options.includeAxe ? playwrightAxeVersion : undefined,
       '@playwright/test': playwrightTestVersion,
       playwright: playwrightVersion,
+      ...(options.includeAxe ? { 'axe-playwright': playwrightAxeVersion } : {}),
     },
   );
 
diff --git a/packages/nx-playwright/src/generators/project/generator.ts b/packages/nx-playwright/src/generators/project/generator.ts
index 4818199..7ed26fd 100644
--- a/packages/nx-playwright/src/generators/project/generator.ts
+++ b/packages/nx-playwright/src/generators/project/generator.ts
@@ -5,9 +5,9 @@ import {
   getProjects,
   names,
   offsetFromRoot,
+  runTasksInSerial,
   Tree,
 } from '@nx/devkit';
-import { runTasksInSerial } from '@nx/workspace/src/utilities/run-tasks-in-serial';
 import { existsSync } from 'fs';
 import * as path from 'path';
 import playwrightInitGenerator from '../init/generator';
diff --git a/packages/nx-playwright/src/generators/project/lib/add-linting.ts b/packages/nx-playwright/src/generators/project/lib/add-linting.ts
index c008cdd..eaf5632 100644
--- a/packages/nx-playwright/src/generators/project/lib/add-linting.ts
+++ b/packages/nx-playwright/src/generators/project/lib/add-linting.ts
@@ -1,6 +1,11 @@
-import { GeneratorCallback, joinPathFragments, Tree, updateJson } from '@nx/devkit';
+import {
+  GeneratorCallback,
+  joinPathFragments,
+  runTasksInSerial,
+  Tree,
+  updateJson,
+} from '@nx/devkit';
 import { Linter, lintProjectGenerator } from '@nx/linter';
-import { runTasksInSerial } from '@nx/workspace/src/utilities/run-tasks-in-serial';
 import { NxPlaywrightGeneratorNormalizedSchema } from './normalize-options';
 
 type EslintIgnoreFile = {