/* eslint-disable @bigbinary/neeto/no-dangling-constants */

const fs = require("fs");
const path = require("path");

const WRONG_CODE = `import { bpfrpt_proptype_WindowScroller } from "../WindowScroller.js";`;

const virtualizedPlugin = () => ({
  name: "flat:react-virtualized",
  configResolved() {
    try {
      const file = require
        .resolve("react-virtualized")
        .replace(
          path.join("dist", "commonjs", "index.js"),
          path.join("dist", "es", "WindowScroller", "utils", "onScroll.js")
        );
      const code = fs.readFileSync(file, "utf-8");
      const modified = code.replace(WRONG_CODE, "");
      fs.writeFileSync(file, modified);
    } catch {}
  },
});

module.exports = { virtualizedPlugin };
