"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.MdxEnvType = exports.MdxEnv = void 0;
function _lodash() {
  const data = require("lodash");
  _lodash = function () {
    return data;
  };
  return data;
}
function _compilation() {
  const data = require("@teambit/compilation.babel-compiler");
  _compilation = function () {
    return data;
  };
  return data;
}
function _babel() {
  const data = require("./babel/babel.config");
  _babel = function () {
    return data;
  };
  return data;
}
function _mdx() {
  const data = require("./mdx.aspect");
  _mdx = function () {
    return data;
  };
  return data;
}
function _mdx2() {
  const data = require("./mdx.compiler");
  _mdx2 = function () {
    return data;
  };
  return data;
}
const MdxEnvType = exports.MdxEnvType = 'mdx';
class MdxEnv {
  constructor(react, logger, multiCompiler, compiler, docs) {
    this.react = react;
    this.logger = logger;
    this.multiCompiler = multiCompiler;
    this.compiler = compiler;
    this.docs = docs;
  }
  getCompiler() {
    const tsTransformer = tsconfig => {
      // set the shouldCopyNonSupportedFiles to false since we don't want ts to copy the .mdx file to the dist folder (it will conflict with the .mdx.js file created by the mdx compiler)
      tsconfig.setCompileJs(false).setCompileJsx(false).setShouldCopyNonSupportedFiles(false);
      return tsconfig;
    };
    const tsCompiler = this.react.env.getCompiler([tsTransformer]);
    const babelCompiler = _compilation().BabelCompiler.create({
      babelTransformOptions: _babel().babelConfig,
      // set the shouldCopyNonSupportedFiles to false since we don't want babel to copy the .mdx file to the dist
      // folder (it will conflict with the .mdx.js file created by the mdx compiler)
      shouldCopyNonSupportedFiles: false
    }, {
      logger: this.logger
    });
    return this.multiCompiler.createCompiler([babelCompiler, this.createMdxCompiler({
      ignoredPatterns: this.docs.getPatterns(),
      babelTransformOptions: _babel().babelConfig
    }), tsCompiler], {});
  }
  getBuildPipe() {
    const mdxCompiler = this.getCompiler();
    return [this.compiler.createTask('MDXCompiler', mdxCompiler), ...this.react.reactEnv.createBuildPipeWithoutCompiler()];
  }
  async getDependencies() {
    const mdxDeps = {
      dependencies: {
        '@teambit/mdx.ui.mdx-scope-context': '1.0.0',
        '@mdx-js/react': '1.6.22'
      }
    };
    return (0, _lodash().merge)(this.react.reactEnv.getDependencies(), mdxDeps);
  }

  /**
   * create an instance of the MDX compiler.
   */
  createMdxCompiler(opts = {}) {
    const mdxCompiler = new (_mdx2().MDXCompiler)(_mdx().MDXAspect.id, opts);
    return mdxCompiler;
  }
  async __getDescriptor() {
    return {
      type: 'mdx'
    };
  }
}
exports.MdxEnv = MdxEnv;

//# sourceMappingURL=mdx.env.js.map