From 413e57f99a911da83857b6516a7b80bb6c2d9355 Mon Sep 17 00:00:00 2001 From: Nicholas Cunningham Date: Fri, 25 Aug 2023 10:25:06 -0600 Subject: [PATCH] fix(core): convert to monorepo generator should respect nested libs (#18795) --- .../convert-to-monorepo.spec.ts | 28 +++++++++++++++++++ .../convert-to-monorepo.ts | 8 ++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.spec.ts b/packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.spec.ts index fc3c1d881f36d..7d940b243b97b 100644 --- a/packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.spec.ts +++ b/packages/workspace/src/generators/convert-to-monorepo/convert-to-monorepo.spec.ts @@ -76,6 +76,34 @@ describe('monorepo generator', () => { expect(tree.exists('.eslintrc.base.json')).toBeTruthy(); }); + it('should respect nested libraries', async () => { + await reactAppGenerator(tree, { + name: 'demo', + style: 'css', + bundler: 'vite', + unitTestRunner: 'vitest', + e2eTestRunner: 'none', + linter: 'eslint', + rootProject: true, + }); + + await libraryGenerator(tree, { + name: 'my-lib', + directory: 'inner', + style: 'css', + bundler: 'vite', + unitTestRunner: 'none', + e2eTestRunner: 'none', + linter: 'eslint', + rootProject: true, + }); + + await monorepoGenerator(tree, {}); + + expect(tree.exists('libs/inner/my-lib/tsconfig.json')).toBeTruthy(); + expect(tree.exists('libs/inner/my-lib/src/index.ts')).toBeTruthy(); + }); + it('should convert root React app (Webpack, Jest)', async () => { await reactAppGenerator(tree, { name: 'demo', 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 5cf42d6d55248..9203ddd351dd5 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 @@ -34,11 +34,15 @@ export async function monorepoGenerator(tree: Tree, options: {}) { for (const project of projectsToMove) { await moveGenerator(tree, { projectName: project.name, - newProjectName: project.name, + newProjectName: + project.projectType === 'application' ? project.name : project.root, destination: project.projectType === 'application' ? joinPathFragments(appsDir, project.name) - : joinPathFragments(libsDir, project.name), + : joinPathFragments( + libsDir, + project.root === '.' ? project.name : project.root + ), destinationRelativeToRoot: true, updateImportPath: project.projectType === 'library', });