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

const fs = require("fs");

const WRONG_CODE = /^if\s\(module\.hot\)[\s\S]+/gm;

const reactGiphyPlugin = () => ({
  name: "react-giphy-searchbox",
  configResolved() {
    try {
      const file = require.resolve(
        "react-giphy-searchbox/es/style/useStyle.js"
      );
      const code = fs.readFileSync(file, "utf-8");
      const modified = code.replace(WRONG_CODE, "");
      fs.writeFileSync(file, modified);
    } catch {}
  },
});

module.exports = { reactGiphyPlugin };
