From d019de0e39c6e6ec0286dddf6a91cc12f4a630ca Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Tue, 22 Aug 2023 13:32:09 +0200 Subject: [PATCH] fix(linter): do not break migration if eslint file is missing --- .../src/generators/init/init-migration.ts | 20 +++++++++---------- .../src/generators/utils/eslint-file.ts | 4 ++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/linter/src/generators/init/init-migration.ts b/packages/linter/src/generators/init/init-migration.ts index 1951efab243f3..0cd75497eca6b 100644 --- a/packages/linter/src/generators/init/init-migration.ts +++ b/packages/linter/src/generators/init/init-migration.ts @@ -26,11 +26,12 @@ export function migrateConfigToMonorepoStyle( projects.forEach((project) => { const lintTarget = findLintTarget(project); if (lintTarget) { - const projectEslintPath = joinPathFragments( - project.root, - lintTarget.options.eslintConfig || findEslintFile(tree, project.root) - ); - migrateEslintFile(projectEslintPath, tree); + const eslintFile = + lintTarget.options.eslintConfig || findEslintFile(tree, project.root); + if (eslintFile) { + const projectEslintPath = joinPathFragments(project.root, eslintFile); + migrateEslintFile(projectEslintPath, tree); + } } }); } @@ -38,12 +39,11 @@ export function migrateConfigToMonorepoStyle( export function findLintTarget( project: ProjectConfiguration ): TargetConfiguration { - return Object.entries(project.targets ?? {}).find( - ([name, target]) => - name === 'lint' || + return Object.values(project.targets ?? {}).find( + (target) => target.executor === '@nx/linter:eslint' || target.executor === '@nrwl/linter:eslint' - )?.[1]; + ); } function migrateEslintFile(projectEslintPath: string, tree: Tree) { @@ -99,6 +99,6 @@ function migrateEslintFile(projectEslintPath: string, tree: Tree) { console.warn('YAML eslint config is not supported yet for migration'); } if (projectEslintPath.endsWith('.js') || projectEslintPath.endsWith('.cjs')) { - console.warn('YAML eslint config is not supported yet for migration'); + console.warn('JS eslint config is not supported yet for migration'); } } diff --git a/packages/linter/src/generators/utils/eslint-file.ts b/packages/linter/src/generators/utils/eslint-file.ts index 3867121bcc631..a43631391a9ef 100644 --- a/packages/linter/src/generators/utils/eslint-file.ts +++ b/packages/linter/src/generators/utils/eslint-file.ts @@ -11,11 +11,15 @@ export const eslintConfigFileWhitelist = [ ]; export const baseEsLintConfigFile = '.eslintrc.base.json'; +export const baseEsLintFlatConfigFile = 'eslint.base.config.js'; export function findEslintFile(tree: Tree, projectRoot = ''): string | null { if (projectRoot === '' && tree.exists(baseEsLintConfigFile)) { return baseEsLintConfigFile; } + if (projectRoot === '' && tree.exists(baseEsLintFlatConfigFile)) { + return baseEsLintFlatConfigFile; + } for (const file of eslintConfigFileWhitelist) { if (tree.exists(joinPathFragments(projectRoot, file))) { return file;