"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.NodeMain = void 0;
function _typescript() {
  const data = require("@teambit/typescript");
  _typescript = function () {
    return data;
  };
  return data;
}
function _application() {
  const data = require("@teambit/application");
  _application = function () {
    return data;
  };
  return data;
}
function _lodash() {
  const data = require("lodash");
  _lodash = function () {
    return data;
  };
  return data;
}
function _logger() {
  const data = require("@teambit/logger");
  _logger = function () {
    return data;
  };
  return data;
}
function _cli() {
  const data = require("@teambit/cli");
  _cli = function () {
    return data;
  };
  return data;
}
function _generator() {
  const data = require("@teambit/generator");
  _generator = function () {
    return data;
  };
  return data;
}
function _componentId() {
  const data = require("@teambit/component-id");
  _componentId = function () {
    return data;
  };
  return data;
}
function _worker() {
  const data = require("@teambit/worker");
  _worker = function () {
    return data;
  };
  return data;
}
function _envs() {
  const data = require("@teambit/envs");
  _envs = function () {
    return data;
  };
  return data;
}
function _react() {
  const data = require("@teambit/react");
  _react = function () {
    return data;
  };
  return data;
}
function _node() {
  const data = require("./node.aspect");
  _node = function () {
    return data;
  };
  return data;
}
function _node2() {
  const data = require("./node.env");
  _node2 = function () {
    return data;
  };
  return data;
}
function _node3() {
  const data = require("./node.templates");
  _node3 = function () {
    return data;
  };
  return data;
}
function _node4() {
  const data = require("./node.app-type");
  _node4 = function () {
    return data;
  };
  return data;
}
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
class NodeMain {
  constructor(react, tsAspect, nodeEnv, envs) {
    this.react = react;
    this.tsAspect = tsAspect;
    this.nodeEnv = nodeEnv;
    this.envs = envs;
    /**
     * @deprecated use useTypescript()
     * override the TS config of the environment.
     */
    _defineProperty(this, "overrideTsConfig", this.react.overrideTsConfig.bind(this.react));
    /**
     * override the jest config of the environment.
     */
    _defineProperty(this, "overrideJestConfig", this.react.overrideJestConfig.bind(this.react));
    /**
     * override the env build pipeline.
     */
    _defineProperty(this, "overrideBuildPipe", this.react.overrideBuildPipe.bind(this.react));
    /**
     * override the env compilers list.
     */
    _defineProperty(this, "overrideCompiler", this.react.overrideCompiler.bind(this.react));
    /**
     * override the env compilers tasks in the build pipe.
     */
    _defineProperty(this, "overrideCompilerTasks", this.react.overrideCompilerTasks.bind(this.react));
    /**
     * @deprecated use useTypescript()
     * override the build ts config.
     */
    _defineProperty(this, "overrideBuildTsConfig", this.react.overrideBuildTsConfig.bind(this.react));
    /**
     * override package json properties.
     */
    _defineProperty(this, "overridePackageJsonProps", this.react.overridePackageJsonProps.bind(this.react));
    /**
     * @deprecated - use useWebpack
     * override the preview config in the env.
     */
    _defineProperty(this, "overridePreviewConfig", this.react.overridePreviewConfig.bind(this.react));
    /**
     * @deprecated - use useWebpack
     * override the dev server configuration.
     */
    _defineProperty(this, "overrideDevServerConfig", this.react.overrideDevServerConfig.bind(this.react));
    /**
     * override the env's dev server and preview webpack configurations.
     * Replaces both overrideDevServerConfig and overridePreviewConfig
     */
    _defineProperty(this, "useWebpack", this.react.useWebpack.bind(this.react));
    /**
     * An API to mutate the prettier config
     */
    _defineProperty(this, "usePrettier", this.react.usePrettier.bind(this.react));
    /**
     * An API to mutate the eslint config
     */
    _defineProperty(this, "useEslint", this.react.useEslint.bind(this.react));
    _defineProperty(this, "overrideMounter", this.react.overrideMounter.bind(this.react));
  }
  icon() {
    return 'https://static.bit.dev/extensions-icons/nodejs.svg';
  }
  /**
   * override the env's typescript config for both dev and build time.
   * Replaces both overrideTsConfig (devConfig) and overrideBuildTsConfig (buildConfig)
   */
  useTypescript(modifiers, tsModule) {
    const overrides = {};
    const devTransformers = modifiers === null || modifiers === void 0 ? void 0 : modifiers.devConfig;
    if (devTransformers) {
      overrides.getCompiler = () => this.nodeEnv.getCompiler(devTransformers, tsModule);
    }
    const buildTransformers = modifiers === null || modifiers === void 0 ? void 0 : modifiers.buildConfig;
    if (buildTransformers) {
      const buildPipeModifiers = {
        tsModifier: {
          transformers: buildTransformers,
          module: tsModule
        }
      };
      overrides.getBuildPipe = () => this.nodeEnv.getBuildPipe(buildPipeModifiers);
    }
    return this.envs.override(overrides);
  }
  /**
   * override the dependency configuration of the component environment.
   */
  overrideDependencies(dependencyPolicy) {
    return this.envs.override({
      getDependencies: () => (0, _lodash().merge)(this.nodeEnv.getDependencies(), dependencyPolicy)
    });
  }
  /**
   * create a new composition of the node environment.
   */
  compose(transformers, targetEnv = {}) {
    return this.envs.compose(this.envs.merge(targetEnv, this.nodeEnv), transformers);
  }
  static async provider([loggerAspect, envs, application, react, generator, tsAspect, workerMain], config, slots, harmony) {
    const logger = loggerAspect.createLogger(_node().NodeAspect.id);
    const nodeEnv = envs.merge(new (_node2().NodeEnv)(tsAspect, react), react.reactEnv);
    envs.registerEnv(nodeEnv);
    const nodeAppType = new (_node4().NodeAppType)('node-app', nodeEnv, logger);
    application.registerAppType(nodeAppType);
    if (generator) {
      const envContext = new (_envs().EnvContext)(_componentId().ComponentID.fromString(_react().ReactAspect.id), loggerAspect, workerMain, harmony);
      generator.registerComponentTemplate(() => (0, _node3().getTemplates)(envContext));
    }
    return new NodeMain(react, tsAspect, nodeEnv, envs);
  }
}
exports.NodeMain = NodeMain;
_defineProperty(NodeMain, "runtime", _cli().MainRuntime);
_defineProperty(NodeMain, "dependencies", [_logger().LoggerAspect, _envs().EnvsAspect, _application().ApplicationAspect, _react().ReactAspect, _generator().GeneratorAspect, _typescript().TypescriptAspect, _worker().WorkerAspect]);
_node().NodeAspect.addRuntime(NodeMain);

//# sourceMappingURL=node.main.runtime.js.map