diff --git a/e2e/nx-misc/src/workspace.test.ts b/e2e/nx-misc/src/workspace.test.ts index 1e33185b2a25b7..dd467eb0af1b12 100644 --- a/e2e/nx-misc/src/workspace.test.ts +++ b/e2e/nx-misc/src/workspace.test.ts @@ -39,6 +39,8 @@ describe('@nx/workspace:convert-to-monorepo', () => { expect(() => runCLI(`build ${reactApp}`)).not.toThrow(); expect(() => runCLI(`test ${reactApp}`)).not.toThrow(); + expect(() => runCLI(`lint ${reactApp}`)).not.toThrow(); + expect(() => runCLI(`lint e2e`)).not.toThrow(); expect(() => runCLI(`e2e e2e`)).not.toThrow(); }); }); diff --git a/packages/eslint/src/generators/utils/eslint-file.ts b/packages/eslint/src/generators/utils/eslint-file.ts index cc1040f37600f8..fc0f543ae09d65 100644 --- a/packages/eslint/src/generators/utils/eslint-file.ts +++ b/packages/eslint/src/generators/utils/eslint-file.ts @@ -82,15 +82,15 @@ export function updateRelativePathsInConfig( const config = tree.read(configPath, 'utf-8'); tree.write( configPath, - replaceFlatConfigPaths(config, sourcePath, offset, destinationPath) + replaceFlatConfigPaths(config, sourcePath, offset, destinationPath, tree) ); } else { updateJson(tree, configPath, (json) => { if (typeof json.extends === 'string') { - json.extends = offsetFilePath(sourcePath, json.extends, offset); + json.extends = offsetFilePath(sourcePath, json.extends, offset, tree); } else if (json.extends) { json.extends = json.extends.map((extend: string) => - offsetFilePath(sourcePath, extend, offset) + offsetFilePath(sourcePath, extend, offset, tree) ); } @@ -114,7 +114,8 @@ function replaceFlatConfigPaths( config: string, sourceRoot: string, offset: string, - destinationRoot: string + destinationRoot: string, + tree: Tree ): string { let match; let newConfig = config; @@ -122,7 +123,7 @@ function replaceFlatConfigPaths( // replace requires const requireRegex = RegExp(/require\(['"](.*)['"]\)/g); while ((match = requireRegex.exec(newConfig)) !== null) { - const newPath = offsetFilePath(sourceRoot, match[1], offset); + const newPath = offsetFilePath(sourceRoot, match[1], offset, tree); newConfig = newConfig.slice(0, match.index) + `require('${newPath}')` + @@ -143,12 +144,25 @@ function replaceFlatConfigPaths( function offsetFilePath( projectRoot: string, pathToFile: string, - offset: string + offset: string, + tree: Tree ): string { - if (!pathToFile.startsWith('..')) { + if (!pathToFile.startsWith('..') && !pathToFile.startsWith('./')) { // not a relative path return pathToFile; } + if ( + eslintConfigFileWhitelist.some((eslintFile) => + pathToFile.includes(eslintFile) + ) && + !tree.exists(joinPathFragments(projectRoot, pathToFile)) + ) { + // if the file is point to eslint + const rootEslint = findEslintFile(tree); + if (rootEslint) { + return joinPathFragments(offset, rootEslint); + } + } return joinPathFragments(offset, projectRoot, pathToFile); } diff --git a/packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.ts b/packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.ts index fdea588dd0d481..8f7c1f2568163e 100644 --- a/packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.ts +++ b/packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.ts @@ -20,7 +20,7 @@ export async function monorepoGenerator(tree: Tree, options: {}) { // Need to determine libs vs packages directory base on the type of root project. for (const [, project] of projects) { if (project.root === '.') rootProject = project; - projectsToMove.push(project); + projectsToMove.unshift(project); // move the root project 1st } // Currently, Nx only handles apps+libs or packages. You cannot mix and match them. diff --git a/packages/workspace/src/generators/move/lib/extract-base-configs.ts b/packages/workspace/src/generators/move/lib/extract-base-configs.ts index 3f61010168d825..37b9c4affab6dc 100644 --- a/packages/workspace/src/generators/move/lib/extract-base-configs.ts +++ b/packages/workspace/src/generators/move/lib/extract-base-configs.ts @@ -38,7 +38,7 @@ export function maybeExtractEslintConfigIfRootProject( // Only need to handle migrating the root rootProject. // If other libs/apps exist, then this migration is already done by `@nx/eslint:lint-rootProject` generator. migrateConfigToMonorepoStyle?.( - [rootProject.name], + [rootProject], tree, tree.exists(joinPathFragments(rootProject.root, 'jest.config.ts')) || tree.exists(joinPathFragments(rootProject.root, 'jest.config.js')) diff --git a/packages/workspace/src/generators/move/lib/update-eslint-config.ts b/packages/workspace/src/generators/move/lib/update-eslint-config.ts index cb2c7aeb49ad96..4dd03c8c0e1793 100644 --- a/packages/workspace/src/generators/move/lib/update-eslint-config.ts +++ b/packages/workspace/src/generators/move/lib/update-eslint-config.ts @@ -12,7 +12,12 @@ export function updateEslintConfig( project: ProjectConfiguration ) { // if there is no suitable eslint config, we don't need to do anything - if (!tree.exists('.eslintrc.json') && !tree.exists('eslint.config.js')) { + if ( + !tree.exists('.eslintrc.json') && + !tree.exists('eslint.config.js') && + !tree.exists('.eslintrc.base.json') && + !tree.exists('eslint.base.config.js') + ) { return; } try {