Skip to content

Commit 26eb091

Browse files
authored
Add comments for unsupported S3 ManagedUpload with callback (#447)
1 parent 6e6c41f commit 26eb091

File tree

8 files changed

+108
-8
lines changed

8 files changed

+108
-8
lines changed

.changeset/big-dogs-appear.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 comments for unsupported S3 ManagedUpload with callback
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import AWS from "aws-sdk";
2+
3+
const client = new AWS.S3({ region: "REGION" });
4+
const uploadParams = {
5+
Body: "BODY",
6+
Bucket: "Bucket",
7+
ContentType: "ContentType",
8+
Key: "Key",
9+
};
10+
11+
client.upload(uploadParams, (err, data) => {
12+
if (err) console.log(err, err.stack); // an error occurred
13+
else console.log(data); // successful response
14+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import AWS from "aws-sdk";
2+
3+
const client = new AWS.S3({ region: "REGION" });
4+
const uploadParams = {
5+
Body: "BODY",
6+
Bucket: "Bucket",
7+
ContentType: "ContentType",
8+
Key: "Key",
9+
};
10+
11+
// S3 ManagedUpload with callbacks are not supported in AWS SDK for JavaScript (v3).
12+
// Please convert to `await client.upload(params, options).promise()`, and re-run aws-sdk-js-codemod.
13+
client.upload(uploadParams, (err, data) => {
14+
if (err) console.log(err, err.stack); // an error occurred
15+
else console.log(data); // successful response
16+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import AWS from "aws-sdk";
2+
3+
const client = new AWS.S3({ region: "REGION" });
4+
const uploadParams = {
5+
Body: "BODY",
6+
Bucket: "Bucket",
7+
ContentType: "ContentType",
8+
Key: "Key",
9+
};
10+
11+
client.upload(uploadParams, function (err, data) {
12+
if (err) console.log(err, err.stack); // an error occurred
13+
else console.log(data); // successful response
14+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import AWS from "aws-sdk";
2+
3+
const client = new AWS.S3({ region: "REGION" });
4+
const uploadParams = {
5+
Body: "BODY",
6+
Bucket: "Bucket",
7+
ContentType: "ContentType",
8+
Key: "Key",
9+
};
10+
11+
// S3 ManagedUpload with callbacks are not supported in AWS SDK for JavaScript (v3).
12+
// Please convert to `await client.upload(params, options).promise()`, and re-run aws-sdk-js-codemod.
13+
client.upload(uploadParams, function (err, data) {
14+
if (err) console.log(err, err.stack); // an error occurred
15+
else console.log(data); // successful response
16+
});

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Collection, JSCodeshift } from "jscodeshift";
33
import { FUNCTION_TYPE_LIST } from "../config";
44
import { getClientWaiterStates } from "./getClientWaiterStates";
55
import { getV2ClientIdentifiers } from "./getV2ClientIdentifiers";
6+
import { getV2ClientS3UploadCallExpression } from "./getV2ClientS3UploadCallExpression";
67
import { getV2ClientWaiterCallExpression } from "./getV2ClientWaiterCallExpression";
78

89
export interface CommentsForUnsupportedAPIsOptions {
@@ -44,4 +45,29 @@ export const addNotSupportedComments = (
4445
});
4546
}
4647
}
48+
49+
if (options.v2ClientName === "S3") {
50+
for (const v2ClientId of v2ClientIdentifiers) {
51+
source
52+
.find(j.CallExpression, getV2ClientS3UploadCallExpression(v2ClientId))
53+
.forEach((callExpression) => {
54+
const args = callExpression.node.arguments;
55+
56+
if (FUNCTION_TYPE_LIST.includes(args[args.length - 1].type)) {
57+
const comments = callExpression.node.comments || [];
58+
comments.push(
59+
j.commentLine(
60+
" S3 ManagedUpload with callbacks are not supported in AWS SDK for JavaScript (v3)."
61+
)
62+
);
63+
comments.push(
64+
j.commentLine(
65+
" Please convert to `await client.upload(params, options).promise()`, and re-run aws-sdk-js-codemod."
66+
)
67+
);
68+
callExpression.node.comments = comments;
69+
}
70+
});
71+
}
72+
}
4773
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { CallExpression } from "jscodeshift";
2+
3+
import { V2ClientIdentifier } from "./getV2ClientIdentifiers";
4+
5+
export const getV2ClientS3UploadCallExpression = (
6+
v2ClientId: V2ClientIdentifier
7+
// @ts-expect-error Property 'arguments' is missing in type
8+
): CallExpression => ({
9+
type: "CallExpression",
10+
callee: {
11+
type: "MemberExpression",
12+
object: v2ClientId,
13+
property: { type: "Identifier", name: "upload" },
14+
},
15+
});

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

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

33
import { getV2ClientIdentifiers } from "./getV2ClientIdentifiers";
4+
import { getV2ClientS3UploadCallExpression } from "./getV2ClientS3UploadCallExpression";
45

56
export interface ReplaceS3UploadApiOptions {
67
v2ClientName: string;
@@ -20,14 +21,7 @@ export const replaceS3UploadApi = (
2021

2122
for (const v2ClientId of v2ClientIdentifiers) {
2223
source
23-
.find(j.CallExpression, {
24-
type: "CallExpression",
25-
callee: {
26-
type: "MemberExpression",
27-
object: v2ClientId,
28-
property: { type: "Identifier", name: "upload" },
29-
},
30-
})
24+
.find(j.CallExpression, getV2ClientS3UploadCallExpression(v2ClientId))
3125
.replaceWith((callExpression) => {
3226
const params = callExpression.node.arguments[0];
3327

0 commit comments

Comments
 (0)