Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): only migrate projects with project.json #10251

Merged
merged 1 commit into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

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

You probably need a tree.remove('workspace.json'), since createTreeWithEmptyWorkspace creates workspace.json, and as such project inference isn't active.

});

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