Skip to content

Commit 6d29b35

Browse files
authored
Replace types when named require is used from aws-sdk (#298)
1 parent fd445ad commit 6d29b35

10 files changed

+36
-4
lines changed

.changeset/eleven-islands-train.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+
Replace types for requires
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const AWS = require("aws-sdk");
2+
3+
const testTags: AWS.S3.Tag[] = [{ Key: "key", Value: "value" }];
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const AWS_S3 = require("@aws-sdk/client-s3"),
2+
{
3+
S3
4+
} = AWS_S3;
5+
6+
const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const S3 = require("aws-sdk/clients/s3");
2+
3+
const testTags: S3.Tag[] = [{ Key: "key", Value: "value" }];
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const AWS_S3 = require("@aws-sdk/client-s3"),
2+
{
3+
S3
4+
} = AWS_S3;
5+
6+
const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { S3 } = require("aws-sdk");
2+
3+
const testTags: S3.Tag[] = [{ Key: "key", Value: "value" }];
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const AWS_S3 = require("@aws-sdk/client-s3"),
2+
{
3+
S3
4+
} = AWS_S3;
5+
6+
const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];

src/transforms/v2-to-v3/client-names/getV2ClientNamesRecordFromRequire.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const getV2ClientNamesRecordFromRequire = (
1717
.flat() as Property[];
1818

1919
for (const idProperty of idPropertiesFromObjectPattern) {
20-
if (idProperty.type !== "Property") {
20+
if (!["Property", "ObjectProperty"].includes(idProperty.type)) {
2121
continue;
2222
}
2323
const key = idProperty.key as Identifier;

src/transforms/v2-to-v3/modules/getV2RequireDeclarator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const getV2RequireDeclarator = (
2828

2929
const v2ClientLocalNameObject = {
3030
type: "ObjectPattern",
31-
properties: [{ type: "Property", value: { type: "Identifier", name: v2ClientLocalName } }],
31+
properties: [{ value: { type: "Identifier", name: v2ClientLocalName } }],
3232
} as ObjectPattern;
3333
// prettier-ignore
3434
const v2ClientLocalNameObjectDeclarators =

src/transforms/v2-to-v3/modules/removeRequireObjectProperty.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const removeRequireObjectProperty = (
1414
) => {
1515
const id = {
1616
type: "ObjectPattern",
17-
properties: [{ type: "Property", value: { type: "Identifier", name: localName } }],
17+
properties: [{ value: { type: "Identifier", name: localName } }],
1818
} as ObjectPattern;
1919
const requireDeclarators = getRequireVariableDeclarators(j, source, sourceValue, id);
2020

@@ -25,7 +25,7 @@ export const removeRequireObjectProperty = (
2525
const varDeclaratorId = varDeclarator.value.id as ObjectPattern;
2626
varDeclaratorId.properties = varDeclaratorId.properties.filter(
2727
(property) =>
28-
property.type !== "Property" ||
28+
(property.type !== "Property" && property.type !== "ObjectProperty") ||
2929
property.value.type !== "Identifier" ||
3030
property.value.name !== localName
3131
);

0 commit comments

Comments
 (0)