Skip to content

Commit d989203

Browse files
authored
Add require declaration per client (#625)
1 parent 16505e2 commit d989203

38 files changed

+233
-188
lines changed

.changeset/great-laws-sit.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+
Add require declaration per client

scripts/generateNewClientTests/getGlobalRequireOutput.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
44
import { getV3PackageRequiresCode } from "./getV3PackageRequiresCode";
55

66
export const getGlobalRequireOutput = () => {
7-
let content = ``;
7+
let content = `\n\n`;
88

99
content += getV3PackageRequiresCode(getClientNamesSortedByPackageName(CLIENTS_TO_TEST));
1010
content += getV3ClientsNewExpressionCode(CLIENTS_TO_TEST);

scripts/generateNewClientTests/getServiceRequireDeepOutput.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
33
import { getV3PackageRequiresCode } from "./getV3PackageRequiresCode";
44

55
export const getServiceRequireDeepOutput = () => {
6-
let content = ``;
6+
let content = `\n\n`;
77

8-
content += getV3PackageRequiresCode(CLIENTS_TO_TEST, { declarationPerClient: true });
9-
content += `\n`;
8+
content += getV3PackageRequiresCode(CLIENTS_TO_TEST);
109
content += getV3ClientsNewExpressionCode(CLIENTS_TO_TEST);
1110

1211
return content;

scripts/generateNewClientTests/getServiceRequireDeepWithNameOutput.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
44
import { getV3PackageRequiresCode } from "./getV3PackageRequiresCode";
55

66
export const getServiceRequireDeepWithNameOutput = () => {
7-
let content = ``;
7+
let content = `\n\n`;
88

9-
content += getV3PackageRequiresCode(CLIENTS_TO_TEST, {
10-
declarationPerClient: true,
11-
useLocalSuffix: true,
12-
});
13-
content += `\n`;
9+
content += getV3PackageRequiresCode(CLIENTS_TO_TEST, { useLocalSuffix: true });
1410
content += getV3ClientsNewExpressionCode(CLIENTS_TO_TEST.map(getClientNameWithLocalSuffix));
1511

1612
return content;

scripts/generateNewClientTests/getServiceRequireWithNameOutput.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
55
import { getV3PackageRequiresCode } from "./getV3PackageRequiresCode";
66

77
export const getServiceRequireWithNameOutput = () => {
8-
let content = ``;
8+
let content = `\n\n`;
99

1010
content += getV3PackageRequiresCode(getClientNamesSortedByPackageName(CLIENTS_TO_TEST), {
1111
useLocalSuffix: true,

scripts/generateNewClientTests/getV3PackageRequiresCode.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,14 @@ import { getClientNameWithLocalSuffix } from "./getClientNameWithLocalSuffix";
77

88
export interface V3PackageRequiresCodeOptions {
99
useLocalSuffix?: boolean;
10-
declarationPerClient?: boolean;
1110
}
1211

1312
export const getV3PackageRequiresCode = (
1413
clientsToTest: typeof CLIENT_NAMES,
1514
options?: V3PackageRequiresCodeOptions
1615
) => {
1716
let content = ``;
18-
const { useLocalSuffix = false, declarationPerClient = false } = options || {};
19-
20-
if (!declarationPerClient) {
21-
content += `const `;
22-
}
17+
const { useLocalSuffix = false } = options || {};
2318

2419
for (const v2ClientName of clientsToTest) {
2520
const v3ClientName = CLIENT_NAMES_MAP[v2ClientName];
@@ -30,13 +25,7 @@ export const getV3PackageRequiresCode = (
3025

3126
const v3RequireKeyValuePair =
3227
v2ClientName === v2ClientLocalName ? v3ClientName : `${v3ClientName}: ${v2ClientLocalName}`;
33-
content += declarationPerClient
34-
? `const {\n ${v3RequireKeyValuePair}\n} = require("${v3ClientPackageName}");\n`
35-
: `{\n ${v3RequireKeyValuePair}\n } = require("${v3ClientPackageName}"),\n `;
36-
}
37-
38-
if (!declarationPerClient) {
39-
content = content.replace(/,\n {6}$/, ";\n\n");
28+
content += `const {\n ${v3RequireKeyValuePair}\n} = require("${v3ClientPackageName}");\n\n`;
4029
}
4130

4231
return content;
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const {
2-
DynamoDBDocument
3-
} = require("@aws-sdk/lib-dynamodb"),
4-
{
5-
DynamoDB
6-
} = require("@aws-sdk/client-dynamodb");
2+
DynamoDBDocument
3+
} = require("@aws-sdk/lib-dynamodb");
4+
5+
const {
6+
DynamoDB
7+
} = require("@aws-sdk/client-dynamodb");
78

89
const documentClient = DynamoDBDocument.from(new DynamoDB({ region: "us-west-2" }));
910
const response = await documentClient.scan({ TableName: "TABLE_NAME" });
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const {
2-
DynamoDBDocument
3-
} = require("@aws-sdk/lib-dynamodb"),
4-
{
5-
DynamoDB: DynamoDBClient
6-
} = require("@aws-sdk/client-dynamodb");
2+
DynamoDBDocument
3+
} = require("@aws-sdk/lib-dynamodb");
4+
5+
const {
6+
DynamoDB: DynamoDBClient
7+
} = require("@aws-sdk/client-dynamodb");
78

89
const documentClient = DynamoDBDocument.from(new DynamoDBClient({ region: "us-west-2" }));
910
const response = await documentClient.scan({ TableName: "TABLE_NAME" });
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const {
2-
DynamoDBDocument
3-
} = require("@aws-sdk/lib-dynamodb"),
4-
{
5-
DynamoDB
6-
} = require("@aws-sdk/client-dynamodb");
2+
DynamoDBDocument
3+
} = require("@aws-sdk/lib-dynamodb");
4+
5+
const {
6+
DynamoDB
7+
} = require("@aws-sdk/client-dynamodb");
78

89
const documentClient = DynamoDBDocument.from(new DynamoDB({ region: "us-west-2" }));
910
const response = await documentClient.scan({ TableName: "TABLE_NAME" });
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const {
2-
DynamoDBDocument
3-
} = require("@aws-sdk/lib-dynamodb"),
4-
{
5-
DynamoDB: DynamoDBClient
6-
} = require("@aws-sdk/client-dynamodb");
2+
DynamoDBDocument
3+
} = require("@aws-sdk/lib-dynamodb");
4+
5+
const {
6+
DynamoDB: DynamoDBClient
7+
} = require("@aws-sdk/client-dynamodb");
78

89
const documentClient = DynamoDBDocument.from(new DynamoDBClient({ region: "us-west-2" }));
910
const response = await documentClient.scan({ TableName: "TABLE_NAME" });

0 commit comments

Comments
 (0)