chore(core): fix migration for new config locations (#7390)

This commit is contained in:
Craigory Coppola 2021-10-15 18:45:46 -05:00 committed by GitHub
parent bdcbac4445
commit 892dfa0bcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 2 deletions

View File

@ -96,14 +96,22 @@ function ensurePropertiesAreInNewLocations(tree: Tree) {
return; return;
} }
const wc = readWorkspaceConfiguration(tree); const wc = readWorkspaceConfiguration(tree);
updateWorkspaceConfiguration(tree, wc);
updateJson<WorkspaceConfiguration>(tree, workspacePath, (json) => { updateJson<WorkspaceConfiguration>(tree, workspacePath, (json) => {
wc.generators ??= json.generators ?? (json as any).schematics;
if (wc.cli) {
wc.cli.defaultCollection ??= json.cli?.defaultCollection;
wc.cli.packageManager ??= json.cli?.packageManager;
} else if (json.cli) {
wc.cli ??= json.cli;
}
wc.defaultProject ??= json.defaultProject;
delete json.cli; delete json.cli;
delete json.defaultProject; delete json.defaultProject;
delete (json as any).schematics; delete (json as any).schematics;
delete json.generators; delete json.generators;
return json; return json;
}); });
updateWorkspaceConfiguration(tree, wc);
} }
function sortTsConfig(tree: Tree) { function sortTsConfig(tree: Tree) {

View File

@ -194,7 +194,8 @@ function movePropertiesToNewLocations() {
nxJson.defaultProject nxJson.defaultProject
) { ) {
nxJson.cli ??= workspaceJson.cli; nxJson.cli ??= workspaceJson.cli;
nxJson.generators ??= workspaceJson.generators; nxJson.generators ??=
workspaceJson.generators ?? (workspaceJson as any).schematics;
nxJson.defaultProject ??= workspaceJson.defaultProject; nxJson.defaultProject ??= workspaceJson.defaultProject;
delete workspaceJson['cli']; delete workspaceJson['cli'];
delete workspaceJson['generators']; delete workspaceJson['generators'];

View File

@ -47,4 +47,51 @@ describe('update to v13 config locations', () => {
expect(workspaceJson.cli).not.toBeDefined(); expect(workspaceJson.cli).not.toBeDefined();
expect(workspaceJson.defaultProject).not.toBeDefined(); expect(workspaceJson.defaultProject).not.toBeDefined();
}); });
describe('v1 workspace', () => {
beforeEach(() => {
tree = createTreeWithEmptyWorkspace(1);
updateJson(tree, 'workspace.json', (json) => ({
...json,
cli: {
defaultCollection: '@nrwl/workspace',
packageManager: 'npm',
},
schematics: {
'@nrwl/workspace:lib': {
name: 'This is a wierd default',
},
},
defaultProject: 'a',
projects: {
a: {},
},
}));
writeJson(tree, 'nx.json', {
npmScope: 'test',
projects: {
a: {
tags: ['test'],
},
},
});
});
it('should move properties to correct place', async () => {
await update(tree);
const workspaceJson = readJson(tree, 'workspace.json');
const nxJson = readJson(tree, 'nx.json');
expect(nxJson.projects).not.toBeDefined();
expect(nxJson.cli?.defaultCollection).toEqual('@nrwl/workspace');
expect(nxJson.cli?.packageManager).toEqual('npm');
expect(nxJson.generators).toEqual({
'@nrwl/workspace:lib': {
name: 'This is a wierd default',
},
});
expect(workspaceJson.projects.a.tags).toEqual(['test']);
expect(workspaceJson.cli).not.toBeDefined();
expect(workspaceJson.defaultProject).not.toBeDefined();
});
});
}); });