From 9cc72df82b4734b785eef17a965b075a8bcae79d Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Wed, 27 Dec 2023 14:03:24 -0500 Subject: [PATCH] fix(nextjs): update migration to handle projects without eslintrc (#20932) --- .../update-17-2-7/remove-eslint-rules-patch.spec.ts | 13 +++++++++++-- .../update-17-2-7/remove-eslint-rules-patch.ts | 8 ++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/next/src/migrations/update-17-2-7/remove-eslint-rules-patch.spec.ts b/packages/next/src/migrations/update-17-2-7/remove-eslint-rules-patch.spec.ts index cf91c1e1abcbd..6737d41a51e1c 100644 --- a/packages/next/src/migrations/update-17-2-7/remove-eslint-rules-patch.spec.ts +++ b/packages/next/src/migrations/update-17-2-7/remove-eslint-rules-patch.spec.ts @@ -1,8 +1,7 @@ -import { Tree, addProjectConfiguration, writeJson } from '@nx/devkit'; +import { addProjectConfiguration, readJson, Tree, writeJson } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports'; import update from './remove-eslint-rules-patch'; -import { readJson } from '@nx/devkit'; describe('update-nx-next-dependency', () => { let tree: Tree; @@ -11,6 +10,16 @@ describe('update-nx-next-dependency', () => { tree = createTreeWithEmptyWorkspace(); }); + it('should handle projects without eslintrc file', async () => { + tree.write('.eslintrc.json', '{}'); + + addProjectConfiguration(tree, 'my-pkg', { + root: 'packages/my-pkg', + }); + + await expect(update(tree)).resolves.not.toThrow(); + }); + it('should remove @next/next/no-html-link-for-pages in json configs', async () => { tree.write('.eslintrc.json', '{}'); diff --git a/packages/next/src/migrations/update-17-2-7/remove-eslint-rules-patch.ts b/packages/next/src/migrations/update-17-2-7/remove-eslint-rules-patch.ts index 8b9ff201ebd1a..f436e9719b763 100644 --- a/packages/next/src/migrations/update-17-2-7/remove-eslint-rules-patch.ts +++ b/packages/next/src/migrations/update-17-2-7/remove-eslint-rules-patch.ts @@ -1,9 +1,13 @@ -import { Tree, formatFiles, getProjects } from '@nx/devkit'; -import { updateOverrideInLintConfig } from '@nx/eslint/src/generators/utils/eslint-file'; +import { formatFiles, getProjects, Tree } from '@nx/devkit'; +import { + isEslintConfigSupported, + updateOverrideInLintConfig, +} from '@nx/eslint/src/generators/utils/eslint-file'; export default async function update(tree: Tree) { const projects = getProjects(tree); projects.forEach((project) => { + if (!isEslintConfigSupported(tree, project.root)) return; updateOverrideInLintConfig( tree, project.root,