Skip to content

Commit d8a511c

Browse files
authored
Use utilities from importModule (#791)
1 parent 05b4714 commit d8a511c

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

src/transforms/v2-to-v3/apis/getNodesWithDocClientNamedImportFromDeepPath.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "jscodeshift";
88
import { DOCUMENT_CLIENT, DYNAMODB, OBJECT_PROPERTY_TYPE_LIST } from "../config";
99
import { ImportType } from "../modules";
10+
import { getImportDeclarations } from "../modules/importModule";
1011
import { getRequireDeclarators } from "../modules/requireModule";
1112
import { getClientDeepImportPath } from "../utils";
1213

@@ -35,16 +36,11 @@ export const getNodesWithDocClientNamedImportFromDeepPath = (
3536
) as Collection<VariableDeclaration>;
3637
}
3738

38-
return source
39-
.find(j.ImportDeclaration, {
40-
type: "ImportDeclaration",
41-
source: { value: deepImportPath },
42-
})
43-
.filter((importDeclaration) =>
44-
(importDeclaration.value.specifiers || []).some(
45-
(importDeclaration) =>
46-
importDeclaration.type === "ImportSpecifier" &&
47-
importDeclaration.imported.name === DOCUMENT_CLIENT
48-
)
49-
);
39+
return getImportDeclarations(j, source, deepImportPath).filter((importDeclaration) =>
40+
(importDeclaration.value.specifiers || []).some(
41+
(importSpecifier) =>
42+
importSpecifier.type === "ImportSpecifier" &&
43+
importSpecifier.imported.name === DOCUMENT_CLIENT
44+
)
45+
);
5046
};
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { Collection, JSCodeshift } from "jscodeshift";
2-
import { PACKAGE_NAME } from "../config";
2+
import { getImportDeclarations } from "./importModule";
33

44
export const hasImport = (j: JSCodeshift, source: Collection<unknown>) =>
5-
source
6-
.find(j.ImportDeclaration)
7-
.filter((importDeclaration) => {
8-
const { value: sourceValue } = importDeclaration.value.source;
9-
return typeof sourceValue === "string" && sourceValue.startsWith(PACKAGE_NAME);
10-
})
11-
.size() > 0;
5+
getImportDeclarations(j, source).size() > 0;

0 commit comments

Comments
 (0)