Skip to content

Commit

Permalink
Set-up stage for adding package imports
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Oct 20, 2023
1 parent dcc2137 commit 129501d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface GetAwsCredentialsNewExpressionOptions {
className: string;
}

export const getAwsCredentialsNewExpression = (
export const getAwsCredentialsNewExpressions = (
j: JSCodeshift,
source: Collection<unknown>,
{ v2GlobalName, className }: GetAwsCredentialsNewExpressionOptions
Expand Down
18 changes: 15 additions & 3 deletions src/transforms/v2-to-v3/apis/replaceAwsCredentials.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Collection, JSCodeshift } from "jscodeshift";
import { AWS_CREDENTIALS_MAP } from "../config";
import { getAwsCredentialsNewExpression } from "./getAwsCredentialsNewExpression";
import { getAwsCredentialsNewExpressions } from "./getAwsCredentialsNewExpressions";

export const replaceAwsCredentials = (
j: JSCodeshift,
Expand All @@ -10,9 +10,21 @@ export const replaceAwsCredentials = (
if (!v2GlobalName) return;

for (const [v2CredentialsName, v3ProviderName] of Object.entries(AWS_CREDENTIALS_MAP)) {
getAwsCredentialsNewExpression(j, source, {
const credsNewExpressions = getAwsCredentialsNewExpressions(j, source, {
v2GlobalName,
className: v2CredentialsName,
}).replaceWith(({ node }) => j.callExpression(j.identifier(v3ProviderName), node.arguments));
});
const credsNewExpressionCount = credsNewExpressions.size();

if (credsNewExpressionCount > 0) {
// addClientNamedModule(j, source, {
// ...options,
// importedName: v3ProviderName,
// v3ClientPackageName: "@aws-sdk/credential-provider",
// });
credsNewExpressions.replaceWith(({ node }) =>
j.callExpression(j.identifier(v3ProviderName), node.arguments)
);
}
}
};

0 comments on commit 129501d

Please sign in to comment.