Skip to content

Commit 06a91b7

Browse files
authored
Add comment to investigate removal of .promise() (#859)
1 parent 13dc42a commit 06a91b7

File tree

8 files changed

+44
-3
lines changed

8 files changed

+44
-3
lines changed

.changeset/popular-ties-arrive.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 comment to investigate removal of .promise()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// client is AWS SDK JS v2 client here, but jscodeshift can't detect it because of lack of types/import.
2+
export const listTables = (client) => {
3+
return client.listTables().promise();
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// client is AWS SDK JS v2 client here, but jscodeshift can't detect it because of lack of types/import.
2+
export const listTables = (client) => {
3+
return (
4+
// The `.promise()` call might be on an JS SDK v2 client API.
5+
// If yes, please remove .promise(). If not, remove this comment.
6+
client.listTables().promise()
7+
);
8+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
const env = {...process.env, ...this.config.env || {}}
1+
const env = {...process.env, ...(this.config.env || {})}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
const env = {...process.env, ...this.config.env || {}}
1+
const env = {...process.env, ...(this.config.env || {})}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Collection, JSCodeshift } from "jscodeshift";
2+
3+
export const addPromiseRemovalComments = (j: JSCodeshift, source: Collection<unknown>): void => {
4+
// Add comment for .promise() calls which weren't removed.
5+
source
6+
.find(j.CallExpression, {
7+
callee: {
8+
type: "MemberExpression",
9+
property: { type: "Identifier", name: "promise" },
10+
},
11+
})
12+
.forEach(({ node }) => {
13+
const comments = node.comments || [];
14+
comments.push(j.commentLine(" The `.promise()` call might be on an JS SDK v2 client API."));
15+
comments.push(
16+
j.commentLine(" If yes, please remove .promise(). If not, remove this comment.")
17+
);
18+
node.comments = comments;
19+
});
20+
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export * from "./getClientWaiterStates";
55
export * from "./getCommandName";
66
export * from "./getS3SignedUrlApiNames";
77
export * from "./getV3ClientWaiterApiName";
8+
export * from "./addPromiseRemovalComments";
89
export * from "./isS3GetSignedUrlApiUsed";
910
export * from "./isS3UploadApiUsed";
1011
export * from "./removePromiseCalls";

src/transforms/v2-to-v3/transformer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
replaceAwsError,
1313
addEmptyObjectForUndefined,
1414
renameErrorCodeWithName,
15+
addPromiseRemovalComments,
1516
} from "./apis";
1617
import { replaceAwsUtilFunctions } from "./aws-util";
1718
import {
@@ -50,8 +51,9 @@ const transformer = async (file: FileInfo, api: API) => {
5051
const importType = getImportType(j, source);
5152

5253
if (importType === null) {
54+
addPromiseRemovalComments(j, source);
5355
// Skip transformation, since no import/require statements found for "aws-sdk" package.
54-
return file.source;
56+
return source.toSource();
5557
}
5658

5759
replaceDeepImport(j, source, { fromPath: "aws-sdk/global", toPath: PACKAGE_NAME });
@@ -126,6 +128,7 @@ const transformer = async (file: FileInfo, api: API) => {
126128
replaceAwsError(j, source, { v2GlobalName, importType });
127129
replaceAwsEndpoint(j, source, v2GlobalName);
128130
removeModules(j, source, importType);
131+
addPromiseRemovalComments(j, source);
129132

130133
const sourceString = getFormattedSourceString(source.toSource({ quote, useTabs, trailingComma }));
131134

0 commit comments

Comments
 (0)