Skip to content

Commit 73264e6

Browse files
authored
Use only default import while transforming import equals (#608)
1 parent b541e88 commit 73264e6

40 files changed

+209
-334
lines changed

.changeset/tall-roses-hunt.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": minor
3+
---
4+
5+
Use only default import while transforming import equals

scripts/generateNewClientTests/getGlobalImportEqualsOutput.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { CLIENT_NAMES_MAP } from "../../src/transforms/v2-to-v3/config";
2+
import { getDefaultLocalName } from "../../src/transforms/v2-to-v3/utils";
13
import { CLIENTS_TO_TEST } from "./config";
24
import { getClientNamesSortedByPackageName } from "./getClientNamesSortedByPackageName";
35
import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
@@ -7,7 +9,12 @@ export const getGlobalImportEqualsOutput = () => {
79
let content = ``;
810

911
content += getV3PackageImportEqualsCode(getClientNamesSortedByPackageName(CLIENTS_TO_TEST));
10-
content += getV3ClientsNewExpressionCode(CLIENTS_TO_TEST);
12+
content += "\n";
13+
content += getV3ClientsNewExpressionCode(
14+
CLIENTS_TO_TEST.map((clientName) =>
15+
[getDefaultLocalName(clientName), CLIENT_NAMES_MAP[clientName]].join(".")
16+
)
17+
);
1118

1219
return content;
1320
};

scripts/generateNewClientTests/getServiceImportEqualsInput.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const getServiceImportEqualsInput = () => {
88
for (const clientName of CLIENTS_TO_TEST) {
99
content += `import ${clientName} = require("${getClientDeepImportPath(clientName)}");\n`;
1010
}
11+
content += `\n`;
1112
content += getV2ClientsNewExpressionCode(CLIENTS_TO_TEST);
1213

1314
return content;
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { CLIENT_NAMES_MAP } from "../../src/transforms/v2-to-v3/config";
2+
import { getDefaultLocalName } from "../../src/transforms/v2-to-v3/utils";
13
import { CLIENTS_TO_TEST } from "./config";
24
import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
35
import { getV3PackageImportEqualsCode } from "./getV3PackageImportEqualsCode";
@@ -6,7 +8,12 @@ export const getServiceImportEqualsOutput = () => {
68
let content = ``;
79

810
content += getV3PackageImportEqualsCode(CLIENTS_TO_TEST);
9-
content += getV3ClientsNewExpressionCode(CLIENTS_TO_TEST);
11+
content += "\n";
12+
content += getV3ClientsNewExpressionCode(
13+
CLIENTS_TO_TEST.map((clientName) =>
14+
[getDefaultLocalName(clientName), CLIENT_NAMES_MAP[clientName]].join(".")
15+
)
16+
);
1017

1118
return content;
1219
};

scripts/generateNewClientTests/getServiceImportEqualsWithNameInput.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const getServiceImportEqualsWithNameInput = () => {
1010
const importName = getClientNameWithLocalSuffix(clientName);
1111
content += `import ${importName} = require("${getClientDeepImportPath(clientName)}");\n`;
1212
}
13+
content += `\n`;
1314
content += getV2ClientsNewExpressionCode(CLIENTS_TO_TEST.map(getClientNameWithLocalSuffix));
1415

1516
return content;
Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
import { CLIENTS_TO_TEST } from "./config";
2-
import { getClientNameWithLocalSuffix } from "./getClientNameWithLocalSuffix";
3-
import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
4-
import { getV3PackageImportEqualsCode } from "./getV3PackageImportEqualsCode";
1+
import { getServiceImportEqualsOutput } from "./getServiceImportEqualsOutput";
52

6-
export const getServiceImportEqualsWithNameOutput = () => {
7-
let content = ``;
8-
9-
content += getV3PackageImportEqualsCode(CLIENTS_TO_TEST, { useLocalSuffix: true });
10-
content += getV3ClientsNewExpressionCode(CLIENTS_TO_TEST.map(getClientNameWithLocalSuffix));
11-
12-
return content;
13-
};
3+
export const getServiceImportEqualsWithNameOutput = getServiceImportEqualsOutput;

scripts/generateNewClientTests/getV3PackageImportEqualsCode.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,13 @@
1-
import {
2-
CLIENT_NAMES,
3-
CLIENT_NAMES_MAP,
4-
CLIENT_PACKAGE_NAMES_MAP,
5-
} from "../../src/transforms/v2-to-v3/config";
1+
import { CLIENT_NAMES, CLIENT_PACKAGE_NAMES_MAP } from "../../src/transforms/v2-to-v3/config";
62
import { getDefaultLocalName } from "../../src/transforms/v2-to-v3/utils";
7-
import { getClientNameWithLocalSuffix } from "./getClientNameWithLocalSuffix";
83

9-
export interface V3PackageImportEqualsCodeOptions {
10-
useLocalSuffix?: boolean;
11-
}
12-
13-
export const getV3PackageImportEqualsCode = (
14-
clientsToTest: typeof CLIENT_NAMES,
15-
options?: V3PackageImportEqualsCodeOptions
16-
) => {
4+
export const getV3PackageImportEqualsCode = (clientsToTest: typeof CLIENT_NAMES) => {
175
let content = ``;
18-
const { useLocalSuffix = false } = options || {};
196

207
for (const v2ClientName of clientsToTest) {
218
const v3ClientDefaultLocalName = getDefaultLocalName(v2ClientName);
229
const v3ClientPackageName = `@aws-sdk/${CLIENT_PACKAGE_NAMES_MAP[v2ClientName]}`;
23-
content += `import ${v3ClientDefaultLocalName} = require("${v3ClientPackageName}");\n\n`;
24-
25-
const v3ClientName = CLIENT_NAMES_MAP[v2ClientName];
26-
const v2ClientLocalName = useLocalSuffix
27-
? getClientNameWithLocalSuffix(v2ClientName)
28-
: v2ClientName;
29-
30-
const v3ObjectPattern =
31-
v2ClientName === v2ClientLocalName ? v3ClientName : `${v3ClientName}: ${v2ClientLocalName}`;
32-
33-
content +=
34-
`const {\n` + ` ${v3ObjectPattern}\n` + `} = ${getDefaultLocalName(v2ClientName)};\n\n`;
10+
content += `import ${v3ClientDefaultLocalName} = require("${v3ClientPackageName}");\n`;
3511
}
3612

3713
return content;
Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
11
import AWS_DynamoDB = require("@aws-sdk/client-dynamodb");
2-
3-
const {
4-
DynamoDB
5-
} = AWS_DynamoDB;
6-
72
import AWS_Lambda = require("@aws-sdk/client-lambda");
8-
9-
const {
10-
Lambda
11-
} = AWS_Lambda;
12-
133
import AWS_STS = require("@aws-sdk/client-sts");
144

15-
const {
16-
STS
17-
} = AWS_STS;
18-
19-
const ddbClient = new DynamoDB({ region: "us-west-2" });
5+
const ddbClient = new AWS_DynamoDB.DynamoDB({ region: "us-west-2" });
206
const listTablesInput: AWS_DynamoDB.ListTablesCommandInput = { Limit: 10 };
217
const listTablesOutput: AWS_DynamoDB.ListTablesCommandOutput = await ddbClient
228
.listTables(listTablesInput);
239

24-
const stsClient = new STS({ region: "us-west-2" });
10+
const stsClient = new AWS_STS.STS({ region: "us-west-2" });
2511
const getCallerIdentityInput: AWS_STS.GetCallerIdentityCommandInput = {};
2612
const getCallerIdentityOutput: AWS_STS.GetCallerIdentityCommandOutput = await stsClient
2713
.getCallerIdentity(getCallerIdentityInput);
2814

29-
const lambdaClient = new Lambda({ region: "us-west-2" });
15+
const lambdaClient = new AWS_Lambda.Lambda({ region: "us-west-2" });
3016
const invokeInput: AWS_Lambda.InvokeCommandInput = { FunctionName: "my-function" };
3117
const invokeOutput: AWS_Lambda.InvokeCommandOutput = await lambdaClient
3218
.invoke(invokeInput);
Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
11
import AWS_DynamoDB = require("@aws-sdk/client-dynamodb");
2-
3-
const {
4-
DynamoDB
5-
} = AWS_DynamoDB;
6-
72
import AWS_Lambda = require("@aws-sdk/client-lambda");
8-
9-
const {
10-
Lambda
11-
} = AWS_Lambda;
12-
133
import AWS_STS = require("@aws-sdk/client-sts");
144

15-
const {
16-
STS
17-
} = AWS_STS;
18-
19-
const ddbClient = new DynamoDB({ region: "us-west-2" });
5+
const ddbClient = new AWS_DynamoDB.DynamoDB({ region: "us-west-2" });
206
const listTablesInput: AWS_DynamoDB.ListTablesCommandInput = { Limit: 10 };
217
const listTablesOutput: AWS_DynamoDB.ListTablesCommandOutput = await ddbClient
228
.listTables(listTablesInput);
239

24-
const stsClient = new STS({ region: "us-west-2" });
10+
const stsClient = new AWS_STS.STS({ region: "us-west-2" });
2511
const getCallerIdentityInput: AWS_STS.GetCallerIdentityCommandInput = {};
2612
const getCallerIdentityOutput: AWS_STS.GetCallerIdentityCommandOutput = await stsClient
2713
.getCallerIdentity(getCallerIdentityInput);
2814

29-
const lambdaClient = new Lambda({ region: "us-west-2" });
15+
const lambdaClient = new AWS_Lambda.Lambda({ region: "us-west-2" });
3016
const invokeInput: AWS_Lambda.InvokeCommandInput = { FunctionName: "my-function" };
3117
const invokeOutput: AWS_Lambda.InvokeCommandOutput = await lambdaClient
3218
.invoke(invokeInput);
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
import AWS_DynamoDB = require("@aws-sdk/client-dynamodb");
22

3-
const {
4-
DynamoDB
5-
} = AWS_DynamoDB;
6-
7-
const client = new DynamoDB();
3+
const client = new AWS_DynamoDB.DynamoDB();
84
const data = await client.listTables();

0 commit comments

Comments
 (0)