// https://github.com/bvaughn/react-virtualized/issues/1632
const virtualizedPlugin = () => ({
  name: "esbuild-plugin-react-virtualized",
  setup(build) {
    build.onLoad(
      {
        filter:
          /node_modules\/react-virtualized\/dist\/es\/WindowScroller\/utils\/onScroll\.js/,
      },
      async args => {
        const fs = require("fs").promises;
        const contents = await fs.readFile(args.path, "utf8");
        const broken = `import { bpfrpt_proptype_WindowScroller } from "../WindowScroller.js";`;

        return { contents: contents.replace(broken, ""), loader: "js" };
      }
    );
  },
});

module.exports = { virtualizedPlugin };
