Skip to content

Commit

Permalink
fix(core): only migrate projects with project.json
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed May 11, 2022
1 parent 93c7ea5 commit 8cbf166
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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

0 comments on commit 8cbf166

Please sign in to comment.