From f43634611b9dee0593e452f4ada52f8228839b89 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Thu, 29 Feb 2024 13:54:57 -0800 Subject: [PATCH] chore: call getImport*Declarations from has* --- src/transforms/v2-to-v3/modules/hasImport.ts | 10 ++-------- .../v2-to-v3/modules/hasImportEquals.ts | 17 ++--------------- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/transforms/v2-to-v3/modules/hasImport.ts b/src/transforms/v2-to-v3/modules/hasImport.ts index 185cfbb35..072a78838 100644 --- a/src/transforms/v2-to-v3/modules/hasImport.ts +++ b/src/transforms/v2-to-v3/modules/hasImport.ts @@ -1,11 +1,5 @@ import { Collection, JSCodeshift } from "jscodeshift"; -import { PACKAGE_NAME } from "../config"; +import { getImportDeclarations } from "./importModule"; export const hasImport = (j: JSCodeshift, source: Collection) => - source - .find(j.ImportDeclaration) - .filter((importDeclaration) => { - const { value: sourceValue } = importDeclaration.value.source; - return typeof sourceValue === "string" && sourceValue.startsWith(PACKAGE_NAME); - }) - .size() > 0; + getImportDeclarations(j, source).size() > 0; diff --git a/src/transforms/v2-to-v3/modules/hasImportEquals.ts b/src/transforms/v2-to-v3/modules/hasImportEquals.ts index 1aca2aec2..b47be286e 100644 --- a/src/transforms/v2-to-v3/modules/hasImportEquals.ts +++ b/src/transforms/v2-to-v3/modules/hasImportEquals.ts @@ -1,18 +1,5 @@ import { Collection, JSCodeshift } from "jscodeshift"; - -import { PACKAGE_NAME } from "../config"; +import { getImportEqualsDeclarations } from "./importEqualsModule"; export const hasImportEquals = (j: JSCodeshift, source: Collection) => - source - .find(j.TSImportEqualsDeclaration) - .filter((importEqualsDeclaration) => { - const { moduleReference } = importEqualsDeclaration.value; - if (moduleReference.type !== "TSExternalModuleReference") return false; - const { expression } = moduleReference; - return ( - expression.type === "StringLiteral" && - typeof expression.value === "string" && - expression.value.startsWith(PACKAGE_NAME) - ); - }) - .size() > 0; + getImportEqualsDeclarations(j, source).size() > 0;