import type { Plugin } from "vite"; import fs from "fs"; import path from "path"; // Patches the react-virtualized library which is pulled in by react-lazylog to remove // a broken import in it. See https://github.com/bvaughn/react-virtualized/issues/1632 const WRONG_CODE = `import { bpfrpt_proptype_WindowScroller } from "../WindowScroller.js";`; export function patchReactVirtualized(): Plugin { return { name: "airbyte/patch-react-virtualized", // Note: we cannot use the `transform` hook here // because libraries are pre-bundled in vite directly, // plugins aren't able to hack that step currently. // so instead we manually edit the file in node_modules. // all we need is to find the timing before pre-bundling. configResolved() { const file = require .resolve("react-lazylog/node_modules/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); }, }; }