Skip to content

Commit 91b67f0

Browse files
authored
Add import equals declaration for named imports (#615)
1 parent a01e797 commit 91b67f0

File tree

44 files changed

+307
-295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+307
-295
lines changed

.changeset/rotten-dragons-obey.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 import equals declaration for named imports
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { CLIENT_NAMES_MAP } from "../../src/transforms/v2-to-v3/config";
2-
import { getDefaultLocalName } from "../../src/transforms/v2-to-v3/utils";
31
import { CLIENTS_TO_TEST } from "./config";
42
import { getClientNamesSortedByPackageName } from "./getClientNamesSortedByPackageName";
53
import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
@@ -10,11 +8,7 @@ export const getGlobalImportEqualsOutput = () => {
108

119
content += getV3PackageImportEqualsCode(getClientNamesSortedByPackageName(CLIENTS_TO_TEST));
1210
content += "\n";
13-
content += getV3ClientsNewExpressionCode(
14-
CLIENTS_TO_TEST.map((clientName) =>
15-
[getDefaultLocalName(clientName), CLIENT_NAMES_MAP[clientName]].join(".")
16-
)
17-
);
11+
content += getV3ClientsNewExpressionCode(CLIENTS_TO_TEST);
1812

1913
return content;
2014
};
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { CLIENT_NAMES_MAP } from "../../src/transforms/v2-to-v3/config";
2-
import { getDefaultLocalName } from "../../src/transforms/v2-to-v3/utils";
31
import { CLIENTS_TO_TEST } from "./config";
42
import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
53
import { getV3PackageImportEqualsCode } from "./getV3PackageImportEqualsCode";
@@ -9,11 +7,7 @@ export const getServiceImportEqualsOutput = () => {
97

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

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

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

scripts/generateNewClientTests/getV3PackageImportEqualsCode.ts

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

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

720
for (const v2ClientName of clientsToTest) {
821
const v3ClientDefaultLocalName = getDefaultLocalName(v2ClientName);
922
const v3ClientPackageName = `@aws-sdk/${CLIENT_PACKAGE_NAMES_MAP[v2ClientName]}`;
1023
content += `import ${v3ClientDefaultLocalName} = require("${v3ClientPackageName}");\n`;
24+
25+
const v3ClientName = CLIENT_NAMES_MAP[v2ClientName];
26+
const importName = useLocalSuffix ? getClientNameWithLocalSuffix(v2ClientName) : v3ClientName;
27+
content += `import ${importName} = ${[v3ClientDefaultLocalName, v3ClientName].join(".")};\n`;
1128
}
1229

1330
return content;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import AWS_S3 = require("@aws-sdk/client-s3");
2+
import Tag = AWS_S3.Tag;
23

3-
const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];
4+
const testTags: Tag[] = [{ Key: "key", Value: "value" }];
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import AWS_S3 = require("@aws-sdk/client-s3");
2+
import Tag = AWS_S3.Tag;
23

3-
const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];
4+
const testTags: Tag[] = [{ Key: "key", Value: "value" }];
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
import AWS_DynamoDB = require("@aws-sdk/client-dynamodb");
2+
import DynamoDB = AWS_DynamoDB.DynamoDB;
3+
import ListTablesCommandOutput = AWS_DynamoDB.ListTablesCommandOutput;
4+
import ListTablesCommandInput = AWS_DynamoDB.ListTablesCommandInput;
25
import AWS_Lambda = require("@aws-sdk/client-lambda");
6+
import Lambda = AWS_Lambda.Lambda;
7+
import InvokeCommandOutput = AWS_Lambda.InvokeCommandOutput;
8+
import InvokeCommandInput = AWS_Lambda.InvokeCommandInput;
39
import AWS_STS = require("@aws-sdk/client-sts");
10+
import STS = AWS_STS.STS;
11+
import GetCallerIdentityCommandOutput = AWS_STS.GetCallerIdentityCommandOutput;
12+
import GetCallerIdentityCommandInput = AWS_STS.GetCallerIdentityCommandInput;
413

5-
const ddbClient = new AWS_DynamoDB.DynamoDB({ region: "us-west-2" });
6-
const listTablesInput: AWS_DynamoDB.ListTablesCommandInput = { Limit: 10 };
7-
const listTablesOutput: AWS_DynamoDB.ListTablesCommandOutput = await ddbClient
14+
const ddbClient = new DynamoDB({ region: "us-west-2" });
15+
const listTablesInput: ListTablesCommandInput = { Limit: 10 };
16+
const listTablesOutput: ListTablesCommandOutput = await ddbClient
817
.listTables(listTablesInput);
918

10-
const stsClient = new AWS_STS.STS({ region: "us-west-2" });
11-
const getCallerIdentityInput: AWS_STS.GetCallerIdentityCommandInput = {};
12-
const getCallerIdentityOutput: AWS_STS.GetCallerIdentityCommandOutput = await stsClient
19+
const stsClient = new STS({ region: "us-west-2" });
20+
const getCallerIdentityInput: GetCallerIdentityCommandInput = {};
21+
const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient
1322
.getCallerIdentity(getCallerIdentityInput);
1423

15-
const lambdaClient = new AWS_Lambda.Lambda({ region: "us-west-2" });
16-
const invokeInput: AWS_Lambda.InvokeCommandInput = { FunctionName: "my-function" };
17-
const invokeOutput: AWS_Lambda.InvokeCommandOutput = await lambdaClient
24+
const lambdaClient = new Lambda({ region: "us-west-2" });
25+
const invokeInput: InvokeCommandInput = { FunctionName: "my-function" };
26+
const invokeOutput: InvokeCommandOutput = await lambdaClient
1827
.invoke(invokeInput);
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
import AWS_DynamoDB = require("@aws-sdk/client-dynamodb");
2+
import DynamoDB = AWS_DynamoDB.DynamoDB;
3+
import ListTablesCommandOutput = AWS_DynamoDB.ListTablesCommandOutput;
4+
import ListTablesCommandInput = AWS_DynamoDB.ListTablesCommandInput;
25
import AWS_Lambda = require("@aws-sdk/client-lambda");
6+
import Lambda = AWS_Lambda.Lambda;
7+
import InvokeCommandOutput = AWS_Lambda.InvokeCommandOutput;
8+
import InvokeCommandInput = AWS_Lambda.InvokeCommandInput;
39
import AWS_STS = require("@aws-sdk/client-sts");
10+
import STS = AWS_STS.STS;
11+
import GetCallerIdentityCommandOutput = AWS_STS.GetCallerIdentityCommandOutput;
12+
import GetCallerIdentityCommandInput = AWS_STS.GetCallerIdentityCommandInput;
413

5-
const ddbClient = new AWS_DynamoDB.DynamoDB({ region: "us-west-2" });
6-
const listTablesInput: AWS_DynamoDB.ListTablesCommandInput = { Limit: 10 };
7-
const listTablesOutput: AWS_DynamoDB.ListTablesCommandOutput = await ddbClient
14+
const ddbClient = new DynamoDB({ region: "us-west-2" });
15+
const listTablesInput: ListTablesCommandInput = { Limit: 10 };
16+
const listTablesOutput: ListTablesCommandOutput = await ddbClient
817
.listTables(listTablesInput);
918

10-
const stsClient = new AWS_STS.STS({ region: "us-west-2" });
11-
const getCallerIdentityInput: AWS_STS.GetCallerIdentityCommandInput = {};
12-
const getCallerIdentityOutput: AWS_STS.GetCallerIdentityCommandOutput = await stsClient
19+
const stsClient = new STS({ region: "us-west-2" });
20+
const getCallerIdentityInput: GetCallerIdentityCommandInput = {};
21+
const getCallerIdentityOutput: GetCallerIdentityCommandOutput = await stsClient
1322
.getCallerIdentity(getCallerIdentityInput);
1423

15-
const lambdaClient = new AWS_Lambda.Lambda({ region: "us-west-2" });
16-
const invokeInput: AWS_Lambda.InvokeCommandInput = { FunctionName: "my-function" };
17-
const invokeOutput: AWS_Lambda.InvokeCommandOutput = await lambdaClient
24+
const lambdaClient = new Lambda({ region: "us-west-2" });
25+
const invokeInput: InvokeCommandInput = { FunctionName: "my-function" };
26+
const invokeOutput: InvokeCommandOutput = await lambdaClient
1827
.invoke(invokeInput);
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import AWS_DynamoDB = require("@aws-sdk/client-dynamodb");
2+
import DynamoDB = AWS_DynamoDB.DynamoDB;
23

3-
const client = new AWS_DynamoDB.DynamoDB();
4+
const client = new DynamoDB();
45
const data = await client.listTables();

0 commit comments

Comments
 (0)