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);