Skip to content

Commit 81d863f

Browse files
authored
Transform clients imported from aws-sdk/clients/all (#845)
1 parent 64f1f38 commit 81d863f

13 files changed

+83
-6
lines changed

.changeset/poor-badgers-battle.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+
Transform clients imported from aws-sdk/clients/all
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { getServiceImportInput } from "./getServiceImportInput";
2+
3+
export const getServiceImportDeepAllInput = () => getServiceImportInput("aws-sdk/clients/all");

scripts/generateNewClientTests/getServiceImportInput.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { CLIENTS_TO_TEST } from "./config";
22
import { getV2ClientsNewExpressionCode } from "./getV2ClientsNewExpressionCode";
33

4-
export const getServiceImportInput = () => {
4+
export const getServiceImportInput = (path?: string) => {
55
let content = ``;
66

7-
content += `import { ${CLIENTS_TO_TEST.join(", ")} } from "aws-sdk";\n`;
7+
content += `import { ${CLIENTS_TO_TEST.join(", ")} } from "${path ? path : "aws-sdk"}";\n`;
88
content += `\n`;
99
content += getV2ClientsNewExpressionCode(CLIENTS_TO_TEST);
1010

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { getServiceRequireInput } from "./getServiceRequireInput";
2+
3+
export const getServiceRequireDeepAllInput = () => getServiceRequireInput("aws-sdk/clients/all");

scripts/generateNewClientTests/getServiceRequireInput.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { CLIENTS_TO_TEST } from "./config";
22
import { getV2ClientsNewExpressionCode } from "./getV2ClientsNewExpressionCode";
33

4-
export const getServiceRequireInput = () => {
4+
export const getServiceRequireInput = (path?: string) => {
55
let content = ``;
66

7-
content += `const { ${CLIENTS_TO_TEST.join(", ")} } = require("aws-sdk");\n`;
7+
content += `const { ${CLIENTS_TO_TEST.join(", ")} } = require("${path ? path : "aws-sdk"}");\n`;
88
content += `\n`;
99
content += getV2ClientsNewExpressionCode(CLIENTS_TO_TEST);
1010

scripts/generateNewClientTests/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { getGlobalRequirePropertyInput } from "./getGlobalRequirePropertyInput";
1515
import { getGlobalRequirePropertyOutput } from "./getGlobalRequirePropertyOutput";
1616
import { getGlobalRequirePropertyWithNameInput } from "./getGlobalRequirePropertyWithNameInput";
1717
import { getGlobalRequirePropertyWithNameOutput } from "./getGlobalRequirePropertyWithNameOutput";
18+
import { getServiceImportDeepAllInput } from "./getServiceImportDeepAllInput";
1819
import { getServiceImportDeepInput } from "./getServiceImportDeepInput";
1920
import { getServiceImportDeepOutput } from "./getServiceImportDeepOutput";
2021
import { getServiceImportDeepStarInput } from "./getServiceImportDeepStarInput";
@@ -31,6 +32,7 @@ import { getServiceImportInput } from "./getServiceImportInput";
3132
import { getServiceImportOutput } from "./getServiceImportOutput";
3233
import { getServiceImportWithNameInput } from "./getServiceImportWithNameInput";
3334
import { getServiceImportWithNameOutput } from "./getServiceImportWithNameOutput";
35+
import { getServiceRequireDeepAllInput } from "./getServiceRequireDeepAllInput";
3436
import { getServiceRequireDeepInput } from "./getServiceRequireDeepInput";
3537
import { getServiceRequireDeepOutput } from "./getServiceRequireDeepOutput";
3638
import { getServiceRequireDeepWithNameInput } from "./getServiceRequireDeepWithNameInput";
@@ -68,6 +70,8 @@ const newClientTestsPath = join(__dirname, "..", "..", newClientsTestsFolder);
6870
["service-import-equals-with-name.output.ts", getServiceImportEqualsWithNameOutput],
6971
["service-import-deep.input.js", getServiceImportDeepInput],
7072
["service-import-deep.output.js", getServiceImportDeepOutput],
73+
["service-import-deep-all.input.js", getServiceImportDeepAllInput],
74+
["service-import-deep-all.output.js", getServiceImportDeepOutput],
7175
["service-import-deep-with-name.input.js", getServiceImportDeepWithNameInput],
7276
["service-import-deep-with-name.output.js", getServiceImportDeepWithNameOutput],
7377
["service-import-deep-star.input.js", getServiceImportDeepStarInput],
@@ -78,6 +82,8 @@ const newClientTestsPath = join(__dirname, "..", "..", newClientsTestsFolder);
7882
["service-import-with-name.output.js", getServiceImportWithNameOutput],
7983
["service-require.input.js", getServiceRequireInput],
8084
["service-require.output.js", getServiceRequireOutput],
85+
["service-require-deep-all.input.js", getServiceRequireDeepAllInput],
86+
["service-require-deep-all.output.js", getServiceRequireOutput],
8187
["service-require-deep.input.js", getServiceRequireDeepInput],
8288
["service-require-deep.output.js", getServiceRequireDeepOutput],
8389
["service-require-deep-with-name.input.js", getServiceRequireDeepWithNameInput],
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This file is generated by scripts/generateNewClientTests/index.ts
2+
// Do not edit this file directly. Instead, edit the script and run it to regenerate this file.
3+
import { AccessAnalyzer, Discovery, ACM } from "aws-sdk/clients/all";
4+
5+
new AccessAnalyzer();
6+
new Discovery();
7+
new ACM();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This file is generated by scripts/generateNewClientTests/index.ts
2+
// Do not edit this file directly. Instead, edit the script and run it to regenerate this file.
3+
4+
5+
import { AccessAnalyzer } from "@aws-sdk/client-accessanalyzer";
6+
import { ACM } from "@aws-sdk/client-acm";
7+
import { ApplicationDiscoveryService } from "@aws-sdk/client-application-discovery-service";
8+
9+
new AccessAnalyzer();
10+
new ApplicationDiscoveryService();
11+
new ACM();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This file is generated by scripts/generateNewClientTests/index.ts
2+
// Do not edit this file directly. Instead, edit the script and run it to regenerate this file.
3+
const { AccessAnalyzer, Discovery, ACM } = require("aws-sdk/clients/all");
4+
5+
new AccessAnalyzer();
6+
new Discovery();
7+
new ACM();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This file is generated by scripts/generateNewClientTests/index.ts
2+
// Do not edit this file directly. Instead, edit the script and run it to regenerate this file.
3+
4+
5+
const { AccessAnalyzer } = require("@aws-sdk/client-accessanalyzer");
6+
const { ACM } = require("@aws-sdk/client-acm");
7+
const { ApplicationDiscoveryService } = require("@aws-sdk/client-application-discovery-service");
8+
9+
new AccessAnalyzer();
10+
new ApplicationDiscoveryService();
11+
new ACM();

src/transforms/v2-to-v3/modules/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export * from "./getGlobalNameFromModule";
44
export * from "./getImportType";
55
export * from "./getRequireDeclaratorsWithProperty";
66
export * from "./removeModules";
7+
export * from "./replaceDeepImport";
78
export * from "./types";
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Collection, JSCodeshift } from "jscodeshift";
2+
3+
export interface ReplaceDeepImportOptions {
4+
fromPath: string;
5+
toPath: string;
6+
}
7+
8+
export const replaceDeepImport = (
9+
j: JSCodeshift,
10+
source: Collection<unknown>,
11+
{ fromPath, toPath }: ReplaceDeepImportOptions
12+
) => {
13+
source.find(j.Literal, { value: fromPath }).replaceWith(j.literal(toPath));
14+
source.find(j.StringLiteral, { value: fromPath }).replaceWith(j.stringLiteral(toPath));
15+
};

src/transforms/v2-to-v3/transformer.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ import {
2525
getClientNamesFromGlobal,
2626
getClientNamesRecord,
2727
} from "./client-names";
28-
import { NOT_SUPPORTED_COMMENT, S3 } from "./config";
29-
import { addClientModules, getGlobalNameFromModule, getImportType, removeModules } from "./modules";
28+
import { NOT_SUPPORTED_COMMENT, PACKAGE_NAME, S3 } from "./config";
29+
import {
30+
addClientModules,
31+
getGlobalNameFromModule,
32+
getImportType,
33+
removeModules,
34+
replaceDeepImport,
35+
} from "./modules";
3036
import { removeTypesFromTSQualifiedName, replaceTSTypeReference } from "./ts-type";
3137
import {
3238
IndentationType,
@@ -48,6 +54,8 @@ const transformer = async (file: FileInfo, api: API) => {
4854
return file.source;
4955
}
5056

57+
replaceDeepImport(j, source, { fromPath: "aws-sdk/clients/all", toPath: PACKAGE_NAME });
58+
5159
const v2GlobalName = getGlobalNameFromModule(j, source);
5260
const v2ClientNamesRecord = getClientNamesRecord(j, source, importType);
5361

0 commit comments

Comments
 (0)