Skip to content

Commit

Permalink
Support updating variable declaration with require CallExpression (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Jan 2, 2023
1 parent e3d2c5a commit 3c5197d
Show file tree
Hide file tree
Showing 21 changed files with 1,221 additions and 1,493 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-steaks-watch.md
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": patch
---

Support updating variable declaration with require CallExpression
21 changes: 16 additions & 5 deletions scripts/generateNewClientTests/getGlobalRequireOutput.ts
@@ -1,13 +1,24 @@
import { CLIENT_NAMES_MAP, CLIENT_PACKAGE_NAMES_MAP } from "../../src/transforms/v2-to-v3/config";
import { getClientNamesSortedByPackageName } from "./getClientNamesSortedByPackageName";
import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
import { getV3PackageRequireCode } from "./getV3PackageRequireCode";

export const getGlobalRequireOutput = (codegenComment: string) => {
let globalRequireOutputContent = `${codegenComment}\n\n`;
let globalRequireOutputContent = `${codegenComment}\n`;

globalRequireOutputContent += getV3PackageRequireCode(getClientNamesSortedByPackageName(), {
extraNewLine: true,
});
const sortedClientNames = getClientNamesSortedByPackageName();
globalRequireOutputContent += `const `;
for (const v2ClientName of sortedClientNames) {
const v3ClientName = CLIENT_NAMES_MAP[v2ClientName];
const v3ClientPackageName = `@aws-sdk/${CLIENT_PACKAGE_NAMES_MAP[v2ClientName]}`;
const v3RequireKeyValuePair =
v3ClientName === v2ClientName ? v3ClientName : `${v3ClientName}: ${v2ClientName}`;
globalRequireOutputContent +=
`{\n` +
` ${v3RequireKeyValuePair}\n` +
` } = require("${v3ClientPackageName}"),\n` +
` `;
}
globalRequireOutputContent = globalRequireOutputContent.replace(/,\n {6}$/, ";\n\n");
globalRequireOutputContent += getV3ClientsNewExpressionCode();

return globalRequireOutputContent;
Expand Down
15 changes: 12 additions & 3 deletions scripts/generateNewClientTests/getServiceRequireOutput.ts
@@ -1,11 +1,20 @@
import { CLIENT_NAMES } from "../../src/transforms/v2-to-v3/config";
import {
CLIENT_NAMES,
CLIENT_NAMES_MAP,
CLIENT_PACKAGE_NAMES_MAP,
} from "../../src/transforms/v2-to-v3/config";
import { getV3ClientsNewExpressionCode } from "./getV3ClientsNewExpressionCode";
import { getV3PackageRequireCode } from "./getV3PackageRequireCode";

export const getServiceRequireOutput = (codegenComment: string) => {
let serviceRequireOutputContent = `${codegenComment}\n`;

serviceRequireOutputContent += getV3PackageRequireCode(CLIENT_NAMES);
for (const v2ClientName of CLIENT_NAMES) {
const v3ClientName = CLIENT_NAMES_MAP[v2ClientName];
const v3ClientPackageName = `@aws-sdk/${CLIENT_PACKAGE_NAMES_MAP[v2ClientName]}`;
const v3RequireKeyValuePair =
v3ClientName === v2ClientName ? v3ClientName : `${v3ClientName}: ${v2ClientName}`;
serviceRequireOutputContent += `const {\n ${v3RequireKeyValuePair}\n} = require("${v3ClientPackageName}");\n`;
}
serviceRequireOutputContent += `\n`;
serviceRequireOutputContent += getV3ClientsNewExpressionCode();

Expand Down
21 changes: 0 additions & 21 deletions scripts/generateNewClientTests/getV3PackageRequireCode.ts

This file was deleted.

@@ -1,14 +1,13 @@
const {
DynamoDB,
ListTablesCommandInput,
ListTablesCommandOutput
} = require("@aws-sdk/client-dynamodb");

const {
STS,
GetCallerIdentityCommandInput,
GetCallerIdentityCommandOutput
} = require("@aws-sdk/client-sts");
DynamoDB,
ListTablesCommandInput,
ListTablesCommandOutput
} = require("@aws-sdk/client-dynamodb"),
{
STS,
GetCallerIdentityCommandInput,
GetCallerIdentityCommandOutput
} = require("@aws-sdk/client-sts");

const ddbClient = new DynamoDB({ region: "us-west-2" });
const listTablesInput: ListTablesCommandInput = { Limit: 10 };
Expand Down
@@ -0,0 +1,6 @@
const AWS = require("aws-sdk"),
ddbClient = new AWS.DynamoDB(),
discoveryClient = new AWS.Discovery();

const ddbResponse = await ddbClient.listTables().promise();
const discoveryResponse = await discoveryClient.describeAgents().promise();
@@ -0,0 +1,11 @@
const {
ApplicationDiscoveryService: Discovery
} = require("@aws-sdk/client-application-discovery-service"),
{
DynamoDB
} = require("@aws-sdk/client-dynamodb"),
ddbClient = new DynamoDB(),
discoveryClient = new Discovery();

const ddbResponse = await ddbClient.listTables();
const discoveryResponse = await discoveryClient.describeAgents();
@@ -0,0 +1,6 @@
const { DynamoDB, Discovery } = require("aws-sdk"),
ddbClient = new DynamoDB(),
discoveryClient = new Discovery();

const ddbResponse = await ddbClient.listTables().promise();
const discoveryResponse = await discoveryClient.describeAgents().promise();
@@ -0,0 +1,11 @@
const {
ApplicationDiscoveryService: Discovery
} = require("@aws-sdk/client-application-discovery-service"),
{
DynamoDB
} = require("@aws-sdk/client-dynamodb"),
ddbClient = new DynamoDB(),
discoveryClient = new Discovery();

const ddbResponse = await ddbClient.listTables();
const discoveryResponse = await discoveryClient.describeAgents();
@@ -0,0 +1,7 @@
const DynamoDB = require("aws-sdk/clients/dynamodb"),
Discovery = require("aws-sdk/clients/discovery"),
ddbClient = new DynamoDB(),
discoveryClient = new Discovery();

const ddbResponse = await ddbClient.listTables().promise();
const discoveryResponse = await discoveryClient.describeAgents().promise();
@@ -0,0 +1,11 @@
const {
DynamoDB
} = require("@aws-sdk/client-dynamodb"),
{
ApplicationDiscoveryService: Discovery
} = require("@aws-sdk/client-application-discovery-service"),
ddbClient = new DynamoDB(),
discoveryClient = new Discovery();

const ddbResponse = await ddbClient.listTables();
const discoveryResponse = await discoveryClient.describeAgents();

0 comments on commit 3c5197d

Please sign in to comment.