From 1541e5eb401fffbe2a6ba8fb63c7055c689d45c7 Mon Sep 17 00:00:00 2001 From: Rivka Ungar Date: Wed, 16 Oct 2024 12:27:27 +0300 Subject: [PATCH] Update core import to NEW_CORE_IMPORT_PATH --- packages/codemod/src/utils/import-utils.ts | 4 ++-- .../core/v2-to-v3/optional/Enums-migration.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/codemod/src/utils/import-utils.ts b/packages/codemod/src/utils/import-utils.ts index d8002bf4dc..7ed7674db6 100644 --- a/packages/codemod/src/utils/import-utils.ts +++ b/packages/codemod/src/utils/import-utils.ts @@ -15,8 +15,8 @@ export function getImports(root: Collection, path: string): Collection { - return getImports(root, CORE_IMPORT_PATH); +export function getCoreImportsForFile(root: Collection, path = CORE_IMPORT_PATH): Collection { + return getImports(root, path); } /** diff --git a/packages/codemod/transformations/core/v2-to-v3/optional/Enums-migration.ts b/packages/codemod/transformations/core/v2-to-v3/optional/Enums-migration.ts index 5b576d6518..09fb5e122d 100644 --- a/packages/codemod/transformations/core/v2-to-v3/optional/Enums-migration.ts +++ b/packages/codemod/transformations/core/v2-to-v3/optional/Enums-migration.ts @@ -1,6 +1,7 @@ import { TransformationContext } from "../../../../types"; import { getCoreImportsForFile, getPropValue, setPropValue, wrap } from "../../../../src/utils"; import enumToStringMapping from "./enumMappings.json"; +import { NEW_CORE_IMPORT_PATH } from "../../../../src/consts"; const enumToString: Record = enumToStringMapping; @@ -8,7 +9,8 @@ const enumToString: Record = enumToStringMapping; * Replace enums with string equivalent */ function transform({ j, root }: TransformationContext) { - const coreImports = getCoreImportsForFile(root); + // Since it runs after the imports are updated need to get the new import path + const coreImports = getCoreImportsForFile(root, NEW_CORE_IMPORT_PATH); const importedComponents = coreImports .find(j.ImportSpecifier) @@ -21,7 +23,7 @@ function transform({ j, root }: TransformationContext) { }) .filter(Boolean); - const allElements = root.find(j.JSXElement).nodes(); // Get the nodes array + const allElements = root.find(j.JSXElement).nodes(); const elements = allElements.filter(path => { const openingElement = path.openingElement;