|
1 | 1 | # aws-sdk-js-codemod
|
2 |
| -Codemod scripts for AWS SDK for JavaScript |
| 2 | + |
| 3 | +This repository contains a collection of codemod scripts for use with |
| 4 | +[JSCodeshift][jscodeshift] that help update [AWS SDK for JavaScript][aws-sdk-js] |
| 5 | +APIs. |
| 6 | + |
| 7 | +The `aws-sdk-js-codemod` CLI is a lightweight wrapper over jscodeshift. |
| 8 | +It processes `--help`, `--version` and `--transform` options before passing them |
| 9 | +downstream. |
| 10 | + |
| 11 | +You can provide names of the custom transforms instead of a local path or url: |
| 12 | + |
| 13 | + v2-to-v3 Converts AWS SDK for JavaScript APIs in a Javascript/TypeScript |
| 14 | + codebase from version 2 (v2) to version 3 (v3). |
| 15 | + |
| 16 | +## Prerequisites |
| 17 | + |
| 18 | +To use aws-sdk-js-codemod, please install [Node.js][install-nodejs]. |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +- Optionally execute dry-run for the transform, and print transformed files on stdout: |
| 23 | + ```console |
| 24 | + npx aws-sdk-js-codemod --dry --print -t v2-to-v3 PATH... |
| 25 | + ``` |
| 26 | +- Run transform: |
| 27 | + ```console |
| 28 | + npx aws-sdk-js-codemod -t v2-to-v3 PATH... |
| 29 | + ``` |
| 30 | + |
| 31 | +## Example |
| 32 | + |
| 33 | +```console |
| 34 | +$ cat example.ts |
| 35 | +import AWS from "aws-sdk"; |
| 36 | + |
| 37 | +const region = "us-west-2"; |
| 38 | +const client = new AWS.DynamoDB({ region }); |
| 39 | +client.listTables({}, (err, data) => { |
| 40 | + if (err) console.log(err, err.stack); |
| 41 | + else console.log(data); |
| 42 | +}); |
| 43 | + |
| 44 | +$ npx aws-sdk-js-codemod -t v2-to-v3 example.ts |
| 45 | + |
| 46 | +$ cat example.ts |
| 47 | +import AWS from "aws-sdk"; |
| 48 | + |
| 49 | +import { DynamoDB } from "@aws-sdk/client-dynamodb"; |
| 50 | + |
| 51 | +const region = "us-west-2"; |
| 52 | +const client = new DynamoDB({ region }); |
| 53 | +client.listTables({}, (err, data) => { |
| 54 | + if (err) console.log(err, err.stack); |
| 55 | + else console.log(data); |
| 56 | +}); |
| 57 | + |
| 58 | +``` |
| 59 | + |
| 60 | +[aws-sdk-js]: https://aws.amazon.com/sdk-for-javascript/ |
| 61 | +[install-nodejs]: https://nodejs.dev/learn/how-to-install-nodejs |
| 62 | +[jscodeshift]: https://github.com/facebook/jscodeshift |
0 commit comments