Skip to content

Commit

Permalink
fix(core): only migrate projects with project.json (#10251)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed May 11, 2022
1 parent ecf88a6 commit 9cdcf17
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
22 changes: 20 additions & 2 deletions 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 >', () => {
Expand All @@ -28,7 +28,7 @@ describe('remove-roots >', () => {
});
});

describe('projects with project.json configs', () => {
describe('projects with workspace.json configs', () => {
beforeEach(() => {
tree = createTreeWithEmptyWorkspace(1);
});
Expand All @@ -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',
});
});
});
});
5 changes: 4 additions & 1 deletion packages/nx/src/migrations/update-14-0-6/remove-roots.ts
Expand Up @@ -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);
Expand Down

1 comment on commit 9cdcf17

@vercel
Copy link

@vercel vercel bot commented on 9cdcf17 May 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app

Please sign in to comment.