From 903c4607d9710f389091382f2d00e1675d932972 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Mon, 12 Aug 2024 16:13:21 -0400 Subject: [PATCH] fix(react-native): migration handles case where plugins is missing from nx.json (#27387) Otherwise, the migration will fail with an error. ## Current Behavior ## Expected Behavior ## Related Issue(s) Fixes # --- .../update-19-6-0/rename-upgrade-target-name.spec.ts | 4 ++++ .../migrations/update-19-6-0/rename-upgrade-target-name.ts | 1 + 2 files changed, 5 insertions(+) diff --git a/packages/react-native/src/migrations/update-19-6-0/rename-upgrade-target-name.spec.ts b/packages/react-native/src/migrations/update-19-6-0/rename-upgrade-target-name.spec.ts index 7f52c9714864b..a074d139adb43 100644 --- a/packages/react-native/src/migrations/update-19-6-0/rename-upgrade-target-name.spec.ts +++ b/packages/react-native/src/migrations/update-19-6-0/rename-upgrade-target-name.spec.ts @@ -9,6 +9,10 @@ describe('rename-upgrade-target-name', () => { tree = createTreeWithEmptyWorkspace(); }); + it('should skip if no plugins', async () => { + expect(update(tree)).resolves.not.toThrow(); + }); + it('should fix upgrade target name option', async () => { const nxJson = readNxJson(tree); nxJson.plugins = [ diff --git a/packages/react-native/src/migrations/update-19-6-0/rename-upgrade-target-name.ts b/packages/react-native/src/migrations/update-19-6-0/rename-upgrade-target-name.ts index 6ea9b9e89b490..0e2c903ee8be6 100644 --- a/packages/react-native/src/migrations/update-19-6-0/rename-upgrade-target-name.ts +++ b/packages/react-native/src/migrations/update-19-6-0/rename-upgrade-target-name.ts @@ -5,6 +5,7 @@ import { formatFiles, readNxJson, Tree, updateNxJson } from '@nx/devkit'; */ export default async function update(tree: Tree) { const nxJson = readNxJson(tree); + if (!nxJson.plugins) return; let updated = false; for (const plugin of nxJson.plugins) { if (typeof plugin === 'string') continue;