Skip to content

Commit 38a16cc

Browse files
authored
Add utils get(Require|Import)IdentifierName (#73)
1 parent d0d459a commit 38a16cc

File tree

7 files changed

+27
-52
lines changed

7 files changed

+27
-52
lines changed

.changeset/spicy-maps-bow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"aws-sdk-js-codemod": patch
3+
---
4+
5+
Add utils get(Require|Import)IdentifierName
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Collection, JSCodeshift } from "jscodeshift";
22

3-
export const getV2DefaultImportName = (
3+
export const getImportIdentifierName = (
44
j: JSCodeshift,
5-
source: Collection<any>
5+
source: Collection<any>,
6+
literalValue: string
67
): string | undefined =>
78
source
89
.find(j.ImportDeclaration, {
9-
source: { value: "aws-sdk" },
10+
source: { type: "Literal", value: literalValue },
1011
})
1112
.nodes()[0]?.specifiers[0]?.local.name;

src/transforms/v2-to-v3/utils/getV2DefaultRequireName.ts renamed to src/transforms/v2-to-v3/utils/getRequireIdentifierName.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Collection, Identifier, JSCodeshift } from "jscodeshift";
22

3-
export const getV2DefaultRequireName = (
3+
export const getRequireIdentifierName = (
44
j: JSCodeshift,
5-
source: Collection<any>
5+
source: Collection<any>,
6+
literalValue: string
67
): string | undefined =>
78
(
89
source
@@ -11,7 +12,7 @@ export const getV2DefaultRequireName = (
1112
init: {
1213
type: "CallExpression",
1314
callee: { type: "Identifier", name: "require" },
14-
arguments: [{ type: "Literal", value: "aws-sdk" }],
15+
arguments: [{ type: "Literal", value: literalValue }],
1516
},
1617
})
1718
.nodes()[0]?.id as Identifier

src/transforms/v2-to-v3/utils/getV2ClientImportNames.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import { Collection, JSCodeshift } from "jscodeshift";
22

3+
import { CLIENT_NAMES } from "./config";
34
import { containsRequire } from "./containsRequire";
4-
import { getV2ClientImportNames } from "./getV2ClientImportNames";
5-
import { getV2ClientRequireNames } from "./getV2ClientRequireNames";
5+
import { getImportIdentifierName } from "./getImportIdentifierName";
6+
import { getRequireIdentifierName } from "./getRequireIdentifierName";
67

78
export const getV2ClientModuleNames = (j: JSCodeshift, source: Collection<any>): string[] =>
8-
containsRequire(j, source)
9-
? getV2ClientRequireNames(j, source)
10-
: getV2ClientImportNames(j, source);
9+
CLIENT_NAMES.map((clientName) => `aws-sdk/clients/${clientName.toLowerCase()}`)
10+
.map((v2ClientLiteralValue) =>
11+
containsRequire(j, source)
12+
? getRequireIdentifierName(j, source, v2ClientLiteralValue)
13+
: getImportIdentifierName(j, source, v2ClientLiteralValue)
14+
)
15+
.filter((v2ClientModuleName) => v2ClientModuleName !== undefined);

src/transforms/v2-to-v3/utils/getV2ClientRequireNames.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Collection, JSCodeshift } from "jscodeshift";
22

33
import { containsRequire } from "./containsRequire";
4-
import { getV2DefaultImportName } from "./getV2DefaultImportName";
5-
import { getV2DefaultRequireName } from "./getV2DefaultRequireName";
4+
import { getImportIdentifierName } from "./getImportIdentifierName";
5+
import { getRequireIdentifierName } from "./getRequireIdentifierName";
66

77
export const getV2DefaultModuleName = (
88
j: JSCodeshift,
99
source: Collection<any>
1010
): string | undefined =>
1111
containsRequire(j, source)
12-
? getV2DefaultRequireName(j, source)
13-
: getV2DefaultImportName(j, source);
12+
? getRequireIdentifierName(j, source, "aws-sdk")
13+
: getImportIdentifierName(j, source, "aws-sdk");

0 commit comments

Comments
 (0)