-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace jscodeshift-find-imports with source.find() call (#59)
- Loading branch information
Showing
7 changed files
with
31 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"aws-sdk-js-codemod": patch | ||
--- | ||
|
||
Replace jscodeshift-find-imports with source.find() call |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/transforms/v2-to-v3/__fixtures__/clients-star-import.input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import * as AWS from "aws-sdk"; | ||
|
||
const client = new AWS.DynamoDB(); |
3 changes: 3 additions & 0 deletions
3
src/transforms/v2-to-v3/__fixtures__/clients-star-import.output.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { DynamoDB } from "@aws-sdk/client-dynamodb"; | ||
|
||
const client = new DynamoDB(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
import { Collection, JSCodeshift } from "jscodeshift"; | ||
import findImports from "jscodeshift-find-imports"; | ||
|
||
export const getV2DefaultImportName = ( | ||
j: JSCodeshift, | ||
source: Collection<any> | ||
): string | undefined => { | ||
const { statement } = j.template; | ||
const imports = findImports(source, statement`import AWS from 'aws-sdk'`); | ||
let v2DefaultImportName = undefined; | ||
|
||
for (const importObj of Object.values(imports)) { | ||
if (importObj.type === "Identifier") return importObj.name; | ||
} | ||
// Set specifier name in v2DefaultImportName if it is imported in the source. | ||
source | ||
.find(j.ImportDeclaration, { | ||
source: { value: "aws-sdk" }, | ||
}) | ||
.forEach((declerationPath) => { | ||
declerationPath.value.specifiers.forEach((specifier) => { | ||
if ( | ||
specifier.type === "ImportDefaultSpecifier" || | ||
specifier.type === "ImportNamespaceSpecifier" | ||
) { | ||
v2DefaultImportName = specifier.local.name; | ||
} | ||
}); | ||
}); | ||
|
||
return undefined; | ||
return v2DefaultImportName; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters