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

const PkgTranslations = require("../../scripts/getPkgTranslations.js");

const PREVAL_IMPORT =
  'preval.require("../../configs/scripts/getPkgTranslations.js")';

const prevalPlugin = () => ({
  name: "preval-plugin",
  transform(code, id) {
    if (id.includes("node_modules") && code.includes(PREVAL_IMPORT)) {
      const replacedCode = code.replace(
        PREVAL_IMPORT,
        JSON.stringify(PkgTranslations)
      );

      return { code: replacedCode, map: null };
    }

    return null;
  },
});

module.exports = { prevalPlugin };
