Skip to content

Commit

Permalink
Transform AWS.Endpoint to URL (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Apr 11, 2024
1 parent 2197eb2 commit cbf9c21
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-houses-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": minor
---

Transform AWS.Endpoint to URL
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import AWS = require("aws-sdk");

const endpoint = new AWS.Endpoint("http://localhost:8000/");
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const endpoint = new URL("http://localhost:8000/");
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import AWS from "aws-sdk";

const endpoint = new AWS.Endpoint("http://localhost:8000/");
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const endpoint = new URL("http://localhost:8000/");
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Endpoint } from "aws-sdk";

const endpoint = new Endpoint("http://localhost:8000/");
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const endpoint = new URL("http://localhost:8000/");
5 changes: 5 additions & 0 deletions src/transforms/v2-to-v3/__fixtures__/config/endpoint.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import AWS from "aws-sdk";

const config = new AWS.Config({
endpoint: "http://localhost"
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const config = {
endpoint: "http://localhost"
};
1 change: 1 addition & 0 deletions src/transforms/v2-to-v3/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from "./isS3GetSignedUrlApiUsed";
export * from "./isS3UploadApiUsed";
export * from "./removePromiseCalls";
export * from "./renameErrorCodeWithName";
export * from "./replaceAwsEndpoint";
export * from "./replaceAwsError";
export * from "./replaceAwsIdentity";
export * from "./replaceS3GetSignedUrlApi";
Expand Down
31 changes: 31 additions & 0 deletions src/transforms/v2-to-v3/apis/replaceAwsEndpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Collection, JSCodeshift } from "jscodeshift";

export const replaceAwsEndpoint = (
j: JSCodeshift,
source: Collection<unknown>,
v2GlobalName?: string
) => {
const endpointCtr = "Endpoint";

if (v2GlobalName) {
source
.find(j.NewExpression, {
callee: {
type: "MemberExpression",
object: { type: "Identifier", name: v2GlobalName },
property: { type: "Identifier", name: endpointCtr },
},
})
.replaceWith((newExpression) =>
j.newExpression(j.identifier("URL"), newExpression.node.arguments)
);
}

source
.find(j.NewExpression, {
callee: { type: "Identifier", name: endpointCtr },
})
.replaceWith((newExpression) =>
j.newExpression(j.identifier("URL"), newExpression.node.arguments)
);
};
1 change: 1 addition & 0 deletions src/transforms/v2-to-v3/config/AWS_CONFIG_KEY_MAP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const AWS_CONFIG_KEY_MAP: Record<string, AwsConfigKeyStatus> = {
deprecationMessage: "The clock skew correction is applied by default.",
},
credentials: {},
endpoint: {},
endpointCacheSize: {},
endpointDiscoveryEnabled: {},
hostPrefixEnabled: {
Expand Down
2 changes: 2 additions & 0 deletions src/transforms/v2-to-v3/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
replaceS3GetSignedUrlApi,
getClientIdentifiersRecord,
replaceAwsIdentity,
replaceAwsEndpoint,
replaceAwsError,
addEmptyObjectForUndefined,
renameErrorCodeWithName,
Expand Down Expand Up @@ -116,6 +117,7 @@ const transformer = async (file: FileInfo, api: API) => {
replaceAwsIdentity(j, source, { v2GlobalName, importType });
replaceAwsUtilFunctions(j, source, v2GlobalName);
replaceAwsError(j, source, { v2GlobalName, importType });
replaceAwsEndpoint(j, source, v2GlobalName);
removeModules(j, source, importType);

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

0 comments on commit cbf9c21

Please sign in to comment.