From d4274b3e6f5b5d50269fb21b928fa1fecb6b1a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Wed, 8 Jun 2022 11:17:59 +0100 Subject: [PATCH] fix(core): handle non-existing cli entry in nx.json in migration to remove default collection (#10632) --- .../update-14-2-0/remove-default-collection.spec.ts | 8 ++++++++ .../migrations/update-14-2-0/remove-default-collection.ts | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/nx/src/migrations/update-14-2-0/remove-default-collection.spec.ts b/packages/nx/src/migrations/update-14-2-0/remove-default-collection.spec.ts index f4880ad359cea..81679611a1b1e 100644 --- a/packages/nx/src/migrations/update-14-2-0/remove-default-collection.spec.ts +++ b/packages/nx/src/migrations/update-14-2-0/remove-default-collection.spec.ts @@ -41,4 +41,12 @@ describe('remove-default-collection', () => { readWorkspaceConfiguration(tree).cli?.defaultCollection ).toBeUndefined(); }); + + it('should not error when "cli" is not defined', async () => { + const config = readWorkspaceConfiguration(tree); + delete config.cli; + updateWorkspaceConfiguration(tree, config); + + await expect(removeDefaultCollection(tree)).resolves.not.toThrow(); + }); }); diff --git a/packages/nx/src/migrations/update-14-2-0/remove-default-collection.ts b/packages/nx/src/migrations/update-14-2-0/remove-default-collection.ts index 2ffd88e4eb6db..4f4208f8ecedf 100644 --- a/packages/nx/src/migrations/update-14-2-0/remove-default-collection.ts +++ b/packages/nx/src/migrations/update-14-2-0/remove-default-collection.ts @@ -9,7 +9,10 @@ export default async function (tree: Tree) { const workspaceConfiguration = readWorkspaceConfiguration(tree); delete workspaceConfiguration.cli?.defaultCollection; - if (Object.keys(workspaceConfiguration.cli).length === 0) { + if ( + workspaceConfiguration.cli && + Object.keys(workspaceConfiguration.cli).length === 0 + ) { delete workspaceConfiguration.cli; }