fix(core): keep existing name when converting project to a monorepo (#18910)

This commit is contained in:
Jack Hsu 2023-08-30 10:08:20 -04:00 committed by GitHub
parent 660f0a6d60
commit ec647e7250
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 11 deletions

View File

@ -29,7 +29,7 @@ describe('monorepo generator', () => {
libsDir: 'packages', libsDir: 'packages',
}); });
expect(readJson(tree, 'packages/my-lib/project.json')).toMatchObject({ expect(readProjectConfiguration(tree, 'my-lib')).toMatchObject({
sourceRoot: 'packages/my-lib/src', sourceRoot: 'packages/my-lib/src',
targets: { targets: {
build: { build: {
@ -41,7 +41,8 @@ describe('monorepo generator', () => {
}, },
}, },
}); });
expect(readJson(tree, 'packages/other-lib/project.json')).toMatchObject({ expect(readProjectConfiguration(tree, 'other-lib')).toMatchObject({
name: 'other-lib',
sourceRoot: 'packages/other-lib/src', sourceRoot: 'packages/other-lib/src',
}); });
@ -67,7 +68,7 @@ describe('monorepo generator', () => {
await monorepoGenerator(tree, {}); await monorepoGenerator(tree, {});
expect(readJson(tree, 'apps/demo/project.json')).toMatchObject({ expect(readProjectConfiguration(tree, 'demo')).toMatchObject({
sourceRoot: 'apps/demo/src', sourceRoot: 'apps/demo/src',
}); });
@ -117,7 +118,7 @@ describe('monorepo generator', () => {
await monorepoGenerator(tree, {}); await monorepoGenerator(tree, {});
expect(readJson(tree, 'apps/demo/project.json')).toMatchObject({ expect(readProjectConfiguration(tree, 'demo')).toMatchObject({
sourceRoot: 'apps/demo/src', sourceRoot: 'apps/demo/src',
targets: { targets: {
build: { build: {
@ -157,11 +158,11 @@ describe('monorepo generator', () => {
await monorepoGenerator(tree, {}); await monorepoGenerator(tree, {});
expect(readJson(tree, 'apps/demo/project.json')).toMatchObject({ expect(readProjectConfiguration(tree, 'demo')).toMatchObject({
sourceRoot: 'apps/demo', sourceRoot: 'apps/demo',
}); });
expect(tree.read('apps/demo/app/page.tsx', 'utf-8')).toContain('demo'); expect(tree.read('apps/demo/app/page.tsx', 'utf-8')).toContain('demo');
expect(readJson(tree, 'libs/util/project.json')).toMatchObject({ expect(readProjectConfiguration(tree, 'util')).toMatchObject({
sourceRoot: 'libs/util/src', sourceRoot: 'libs/util/src',
}); });
expect(tree.read('libs/util/src/lib/util.ts', 'utf-8')).toContain('util'); expect(tree.read('libs/util/src/lib/util.ts', 'utf-8')).toContain('util');

View File

@ -34,13 +34,13 @@ export async function monorepoGenerator(tree: Tree, options: {}) {
for (const project of projectsToMove) { for (const project of projectsToMove) {
await moveGenerator(tree, { await moveGenerator(tree, {
projectName: project.name, projectName: project.name,
newProjectName: newProjectName: project.name,
project.projectType === 'application' || project.root === '.'
? project.name
: project.root,
destination: destination:
project.projectType === 'application' project.projectType === 'application'
? joinPathFragments(appsDir, project.name) ? joinPathFragments(
appsDir,
project.root === '.' ? project.name : project.root
)
: joinPathFragments( : joinPathFragments(
libsDir, libsDir,
project.root === '.' ? project.name : project.root project.root === '.' ? project.name : project.root