From 9cdcf1720ac79e980a6802d8e3dc43317865de1a Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Wed, 11 May 2022 16:57:33 -0400 Subject: [PATCH] fix(core): only migrate projects with project.json (#10251) --- .../update-14-0-6/remove-roots.spec.ts | 22 +++++++++++++++++-- .../migrations/update-14-0-6/remove-roots.ts | 5 ++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/nx/src/migrations/update-14-0-6/remove-roots.spec.ts b/packages/nx/src/migrations/update-14-0-6/remove-roots.spec.ts index b06468af31689..b41211adc8e6f 100644 --- a/packages/nx/src/migrations/update-14-0-6/remove-roots.spec.ts +++ b/packages/nx/src/migrations/update-14-0-6/remove-roots.spec.ts @@ -1,7 +1,7 @@ import { Tree } from '../../generators/tree'; import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/create-tree-with-empty-workspace'; import { addProjectConfiguration } from '../../generators/utils/project-configuration'; -import { readJson, updateJson } from '../../generators/utils/json'; +import { readJson, updateJson, writeJson } from '../../generators/utils/json'; import removeRoots from './remove-roots'; describe('remove-roots >', () => { @@ -28,7 +28,7 @@ describe('remove-roots >', () => { }); }); - describe('projects with project.json configs', () => { + describe('projects with workspace.json configs', () => { beforeEach(() => { tree = createTreeWithEmptyWorkspace(1); }); @@ -45,4 +45,22 @@ describe('remove-roots >', () => { ); }); }); + + describe('projects with package.json configs', () => { + beforeEach(() => { + tree = createTreeWithEmptyWorkspace(2); + }); + + it('should remove the root property', async () => { + writeJson(tree, 'proj1/package.json', { + name: 'proj1', + }); + + await removeRoots(tree); + + expect(readJson(tree, 'proj1/package.json')).toEqual({ + name: 'proj1', + }); + }); + }); }); diff --git a/packages/nx/src/migrations/update-14-0-6/remove-roots.ts b/packages/nx/src/migrations/update-14-0-6/remove-roots.ts index 279a9cd1dbf4a..1b8e1a6b143ed 100644 --- a/packages/nx/src/migrations/update-14-0-6/remove-roots.ts +++ b/packages/nx/src/migrations/update-14-0-6/remove-roots.ts @@ -4,11 +4,14 @@ import { updateProjectConfiguration, } from '../../generators/utils/project-configuration'; import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; +import { join } from 'path'; export default async function (tree: Tree) { // This looks like it does nothing, but this will actually effectively migrate over all the configs that need to be moved over, but won't touch configs that don't need to be moved for (const [projName, projConfig] of getProjects(tree)) { - updateProjectConfiguration(tree, projName, projConfig); + if (tree.exists(join(projConfig.root, 'project.json'))) { + updateProjectConfiguration(tree, projName, projConfig); + } } await formatChangedFilesWithPrettierIfAvailable(tree);