Skip to content

Commit e64574d

Browse files
authored
Remove client require if clients are not created (#302)
1 parent 0542a8c commit e64574d

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

.changeset/lazy-rabbits-tickle.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+
Remove client require if clients are not created
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
const AWS_S3 = require("@aws-sdk/client-s3"),
2-
{
3-
S3
4-
} = AWS_S3;
1+
const AWS_S3 = require("@aws-sdk/client-s3");
52

63
const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
const AWS_S3 = require("@aws-sdk/client-s3"),
2-
{
3-
S3
4-
} = AWS_S3;
1+
const AWS_S3 = require("@aws-sdk/client-s3");
52

63
const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
const AWS_S3 = require("@aws-sdk/client-s3"),
2-
{
3-
S3
4-
} = AWS_S3;
1+
const AWS_S3 = require("@aws-sdk/client-s3");
52

63
const testTags: AWS_S3.Tag[] = [{ Key: "key", Value: "value" }];
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Collection, JSCodeshift } from "jscodeshift";
22

33
import { getV3ClientTypeNames } from "../ts-type";
4+
import { getV2ClientNewExpression } from "../utils";
45
import { addV3ClientDefaultRequire } from "./addV3ClientDefaultRequire";
56
import { addV3ClientNamedRequire } from "./addV3ClientNamedRequire";
67
import { V3ClientModulesOptions } from "./types";
@@ -10,13 +11,20 @@ export const addV3ClientRequires = (
1011
source: Collection<unknown>,
1112
options: V3ClientModulesOptions
1213
): void => {
13-
const { v2ClientName, v2GlobalName } = options;
14+
const { v2ClientName, v2ClientLocalName, v2GlobalName } = options;
1415
const v3ClientTypeNames = getV3ClientTypeNames(j, source, { v2ClientName, v2GlobalName });
1516

1617
// Add default require for types, if needed.
1718
if (v3ClientTypeNames.length > 0) {
1819
addV3ClientDefaultRequire(j, source, options);
1920
}
2021

21-
addV3ClientNamedRequire(j, source, options);
22+
const newExpressions = source.find(
23+
j.NewExpression,
24+
getV2ClientNewExpression({ v2ClientName, v2ClientLocalName, v2GlobalName })
25+
);
26+
27+
if (newExpressions.length) {
28+
addV3ClientNamedRequire(j, source, options);
29+
}
2230
};

0 commit comments

Comments
 (0)