Skip to content

Commit

Permalink
Replace types when named require is used from aws-sdk (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Jan 4, 2023
1 parent fd445ad commit 6d29b35
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-islands-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": patch
---

Replace types for requires
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const AWS = require("aws-sdk");

const testTags: AWS.S3.Tag[] = [{ Key: "key", Value: "value" }];
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const AWS_S3 = require("@aws-sdk/client-s3"),
{
S3
} = AWS_S3;

const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const S3 = require("aws-sdk/clients/s3");

const testTags: S3.Tag[] = [{ Key: "key", Value: "value" }];
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const AWS_S3 = require("@aws-sdk/client-s3"),
{
S3
} = AWS_S3;

const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { S3 } = require("aws-sdk");

const testTags: S3.Tag[] = [{ Key: "key", Value: "value" }];
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const AWS_S3 = require("@aws-sdk/client-s3"),
{
S3
} = AWS_S3;

const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getV2ClientNamesRecordFromRequire = (
.flat() as Property[];

for (const idProperty of idPropertiesFromObjectPattern) {
if (idProperty.type !== "Property") {
if (!["Property", "ObjectProperty"].includes(idProperty.type)) {
continue;
}
const key = idProperty.key as Identifier;
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/v2-to-v3/modules/getV2RequireDeclarator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const getV2RequireDeclarator = (

const v2ClientLocalNameObject = {
type: "ObjectPattern",
properties: [{ type: "Property", value: { type: "Identifier", name: v2ClientLocalName } }],
properties: [{ value: { type: "Identifier", name: v2ClientLocalName } }],
} as ObjectPattern;
// prettier-ignore
const v2ClientLocalNameObjectDeclarators =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const removeRequireObjectProperty = (
) => {
const id = {
type: "ObjectPattern",
properties: [{ type: "Property", value: { type: "Identifier", name: localName } }],
properties: [{ value: { type: "Identifier", name: localName } }],
} as ObjectPattern;
const requireDeclarators = getRequireVariableDeclarators(j, source, sourceValue, id);

Expand All @@ -25,7 +25,7 @@ export const removeRequireObjectProperty = (
const varDeclaratorId = varDeclarator.value.id as ObjectPattern;
varDeclaratorId.properties = varDeclaratorId.properties.filter(
(property) =>
property.type !== "Property" ||
(property.type !== "Property" && property.type !== "ObjectProperty") ||
property.value.type !== "Identifier" ||
property.value.name !== localName
);
Expand Down

0 comments on commit 6d29b35

Please sign in to comment.