diff --git a/packages/next/src/generators/application/application.spec.ts b/packages/next/src/generators/application/application.spec.ts index f858a6760700f..656bd5fa931f0 100644 --- a/packages/next/src/generators/application/application.spec.ts +++ b/packages/next/src/generators/application/application.spec.ts @@ -364,6 +364,7 @@ describe('app', () => { ], "ignorePatterns": Array [ "!**/*", + ".next/**/*", ], "overrides": Array [ Object { diff --git a/packages/next/src/generators/application/lib/add-linting.ts b/packages/next/src/generators/application/lib/add-linting.ts index 3394d277c6218..df510e7c62216 100644 --- a/packages/next/src/generators/application/lib/add-linting.ts +++ b/packages/next/src/generators/application/lib/add-linting.ts @@ -36,6 +36,11 @@ export async function addLinting( // Turn off @next/next/no-html-link-for-pages since there is an issue with nextjs throwing linting errors // TODO(nicholas): remove after Vercel updates nextjs linter to only lint ["*.ts", "*.tsx", "*.js", "*.jsx"] + reactEslintJson.ignorePatterns = [ + ...reactEslintJson.ignorePatterns, + '.next/**/*', + ]; + reactEslintJson.rules = { '@next/next/no-html-link-for-pages': 'off', ...reactEslintJson.rules, diff --git a/packages/next/src/migrations/update-14-5-7/update-next-eslint.spec.ts b/packages/next/src/migrations/update-14-5-7/update-next-eslint.spec.ts new file mode 100644 index 0000000000000..95e5a34349287 --- /dev/null +++ b/packages/next/src/migrations/update-14-5-7/update-next-eslint.spec.ts @@ -0,0 +1,60 @@ +import { addProjectConfiguration, readJson, Tree } from '@nrwl/devkit'; +import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; +import { updateNextEslint } from './update-next-eslint'; + +describe('Add next eslint 14.5.7', () => { + let tree: Tree; + + beforeEach(async () => { + tree = createTreeWithEmptyWorkspace(); + + addProjectConfiguration(tree, 'app1', { + root: 'apps/app1', + targets: { + build: { + executor: '@nrwl/next:build', + }, + }, + }); + + tree.write( + 'nx.json', + JSON.stringify({ + projects: { + app1: {}, + }, + }) + ); + }); + + it('should update "next" config ignorePattern', async () => { + tree.write( + 'apps/app1/.eslintrc.json', + JSON.stringify({ + extends: ['../../.eslintrc.json'], + ignorePatterns: ['!**/*'], + }) + ); + + await updateNextEslint(tree); + + const result = readJson(tree, 'apps/app1/.eslintrc.json'); + expect(result.ignorePatterns).toContain('.next/**/*'); + }); + + it('should not update "next" config ignorePattern if .next pattern already exists', async () => { + tree.write( + 'apps/app1/.eslintrc.json', + JSON.stringify({ + extends: ['../../.eslintrc.json'], + ignorePatterns: ['!**/*', '.next/**/*', '/foo/bar'], + }) + ); + const before = readJson(tree, 'apps/app1/.eslintrc.json'); + + await updateNextEslint(tree); + + const result = readJson(tree, 'apps/app1/.eslintrc.json'); + expect(result.ignorePatterns).toEqual(before.ignorePatterns); + }); +}); diff --git a/packages/next/src/migrations/update-14-5-7/update-next-eslint.ts b/packages/next/src/migrations/update-14-5-7/update-next-eslint.ts new file mode 100644 index 0000000000000..e21930a6ad5f9 --- /dev/null +++ b/packages/next/src/migrations/update-14-5-7/update-next-eslint.ts @@ -0,0 +1,28 @@ +import { formatFiles, getProjects, Tree, updateJson } from '@nrwl/devkit'; + +export async function updateNextEslint(host: Tree) { + const projects = getProjects(host); + + projects.forEach((project) => { + if (project.targets?.build?.executor !== '@nrwl/next:build') return; + + const eslintPath = `${project.root}/.eslintrc.json`; + + if (!host.exists(eslintPath)) return; + + updateJson(host, eslintPath, (eslintConfig) => { + const nextIgnorePattern = '.next/**/*'; + + if (eslintConfig.ignorePatterns.indexOf(nextIgnorePattern) < 0) { + eslintConfig.ignorePatterns = [ + ...eslintConfig.ignorePatterns, + nextIgnorePattern, + ]; + } + return eslintConfig; + }); + }); + await formatFiles(host); +} + +export default updateNextEslint;