Skip to content

Commit

Permalink
Update core import to NEW_CORE_IMPORT_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
rivka-ungar committed Oct 16, 2024
1 parent 2b5bee5 commit 1541e5e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/codemod/src/utils/import-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export function getImports(root: Collection, path: string): Collection<ImportDec
/**
* Retrieves all "monday-ui-react-core" import declarations for a root.
*/
export function getCoreImportsForFile(root: Collection): Collection<ImportDeclaration> {
return getImports(root, CORE_IMPORT_PATH);
export function getCoreImportsForFile(root: Collection, path = CORE_IMPORT_PATH): Collection<ImportDeclaration> {
return getImports(root, path);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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<string, string> = 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)
Expand All @@ -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;
Expand Down

0 comments on commit 1541e5e

Please sign in to comment.