aws-sdk-js-codemod icon indicating copy to clipboard operation
aws-sdk-js-codemod copied to clipboard

[Feature]: Dynamic imports

Open kuhe opened this issue 1 year ago • 2 comments

Self-service

  • [ ] I'd be willing to implement this feature

Input code

import("aws-sdk")
  .then((module) => {
    return module.S3;
  })
  .then(() => {
    const AWS = require("aws-sdk");
    const s3 = new AWS.S3({});
  });

Expected Output

import("@aws-sdk/client-s3")
  .then((module) => {
    return module.S3;
  })
  .then(async () => {
    const { S3 } = require("@aws-sdk/client-s3");
    const s3 = new S3({});
  });

Additional context

Can be observed by checking out this change: https://github.com/awslabs/aws-sdk-js-codemod/compare/main...kuhe:aws-sdk-js-codemod:example/imports?expand=1

And running npx jest -t dynamic

kuhe avatar Nov 18 '22 22:11 kuhe

Example production code: https://github.com/stream-labs/desktop/blob/428dc21e9dfe73e30640d9d3d629a65d13c30a63/app/util/slow-imports.ts#L4-L6

trivikr avatar Nov 06 '23 06:11 trivikr

https://github.com/urbit/urbit/blob/410f491938b8361da59b7c5dcd02dfe08d6732ba/pkg/interface/src/logic/lib/S3Client.ts#L33

trivikr avatar Nov 08 '23 03:11 trivikr