'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _regenerator;

function _load_regenerator() {
  return _regenerator = _interopRequireDefault(require('babel-runtime/regenerator'));
}

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _ramda;

function _load_ramda() {
  return _ramda = _interopRequireDefault(require('ramda'));
}

var _path;

function _load_path() {
  return _path = _interopRequireDefault(require('path'));
}

var _stringFormat;

function _load_stringFormat() {
  return _stringFormat = _interopRequireDefault(require('string-format'));
}

var _baseExtension;

function _load_baseExtension() {
  return _baseExtension = _interopRequireDefault(require('./base-extension'));
}

var _scope;

function _load_scope() {
  return _scope = _interopRequireDefault(require('../scope/scope'));
}

var _bitId;

function _load_bitId() {
  return _bitId = _interopRequireDefault(require('../bit-id/bit-id'));
}

var _extensionFile;

function _load_extensionFile() {
  return _extensionFile = _interopRequireDefault(require('./extension-file'));
}

var _objects;

function _load_objects() {
  return _objects = require('../scope/objects');
}

var _utils;

function _load_utils() {
  return _utils = require('../utils');
}

var _scope2;

function _load_scope2() {
  return _scope2 = require('../scope');
}

var _analytics;

function _load_analytics() {
  return _analytics = require('../analytics/analytics');
}

var _extensionGetDynamicPackagesError;

function _load_extensionGetDynamicPackagesError() {
  return _extensionGetDynamicPackagesError = _interopRequireDefault(require('./exceptions/extension-get-dynamic-packages-error'));
}

var _compilerExtension;

function _load_compilerExtension() {
  return _compilerExtension = _interopRequireDefault(require('./compiler-extension'));
}

var _compilerExtension2;

function _load_compilerExtension2() {
  return _compilerExtension2 = require('./compiler-extension');
}

var _testerExtension;

function _load_testerExtension() {
  return _testerExtension = _interopRequireDefault(require('./tester-extension'));
}

var _testerExtension2;

function _load_testerExtension2() {
  return _testerExtension2 = require('./tester-extension');
}

var _constants;

function _load_constants() {
  return _constants = require('../constants');
}

var _component;

function _load_component() {
  return _component = _interopRequireDefault(require('../consumer/component'));
}

var _consumerBitJson;

function _load_consumerBitJson() {
  return _consumerBitJson = _interopRequireDefault(require('../consumer/bit-json/consumer-bit-json'));
}

var _bitJson;

function _load_bitJson() {
  return _bitJson = _interopRequireDefault(require('../consumer/bit-json'));
}

var _logger;

function _load_logger() {
  return _logger = _interopRequireDefault(require('../logger/logger'));
}

var _dependencies;

function _load_dependencies() {
  return _dependencies = require('../consumer/component/dependencies');
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

// Couldn't find a good way to do this with consts
// see https://github.com/facebook/flow/issues/627
// I would expect something like:
// type EnvType = CompilerEnvType | TesterEnvType would work
var EnvExtension = function (_BaseExtension) {
  _inherits(EnvExtension, _BaseExtension);

  _createClass(EnvExtension, [{
    key: 'action',


    /**
     * Return the action
     */
    get: function get() {
      if (this.script && this.script.action && typeof this.script.action === 'function') {
        return this.script.action;
      }
      return undefined;
    }

    /**
     * return old actions (to support old compilers / testers which uses run / compile functions)
     */

  }, {
    key: 'oldAction',
    get: function get() {
      if (this.script && this.script.run && typeof this.script.run === 'function') {
        return this.script.run;
      }
      if (this.script && this.script.compile && typeof this.script.compile === 'function') {
        return this.script.compile;
      }
      return undefined;
    }
  }]);

  function EnvExtension(extensionProps) {
    _classCallCheck(this, EnvExtension);

    var _this = _possibleConstructorReturn(this, (EnvExtension.__proto__ || Object.getPrototypeOf(EnvExtension)).call(this, extensionProps));

    _this.envType = extensionProps.envType;
    _this.dynamicPackageDependencies = extensionProps.dynamicPackageDependencies;
    _this.files = extensionProps.files;
    return _this;
  }

  _createClass(EnvExtension, [{
    key: 'install',
    value: function () {
      var _ref = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee(scope, opts, context) {
        var dependentId, installOpts, installResult;
        return (_regenerator || _load_regenerator()).default.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                (_analytics || _load_analytics()).Analytics.addBreadCrumb('env-extension', 'install env extension');
                (_logger || _load_logger()).default.debug('env-extension - install env extension');

                // Skip the installation in case of using specific file
                // options.file usually used for develop your extension

                if (!this.options.file) {
                  _context.next = 4;
                  break;
                }

                return _context.abrupt('return', undefined);

              case 4:
                dependentId = (_ramda || _load_ramda()).default.path(['dependentId'], context);
                installOpts = _extends({
                  ids: [{ componentId: (_bitId || _load_bitId()).default.parse(this.name, true), type: this.envType.toLowerCase() }], // @todo: make sure it always has a scope name
                  dependentId
                }, opts);
                _context.next = 8;
                return scope.installEnvironment(installOpts);

              case 8:
                installResult = _context.sent;

                this.setExtensionPathInScope(scope.getPath());
                _context.next = 12;
                return this.reload(scope.getPath(), context);

              case 12:
                return _context.abrupt('return', installResult);

              case 13:
              case 'end':
                return _context.stop();
            }
          }
        }, _callee, this);
      }));

      function install(_x, _x2, _x3) {
        return _ref.apply(this, arguments);
      }

      return install;
    }()
  }, {
    key: 'toModelObject',
    value: function toModelObject() {
      (_analytics || _load_analytics()).Analytics.addBreadCrumb('env-extension', 'toModelObject');
      (_logger || _load_logger()).default.debug('env-extension - toModelObject');
      var baseObject = _get(EnvExtension.prototype.__proto__ || Object.getPrototypeOf(EnvExtension.prototype), 'toModelObject', this).call(this);
      var files = this.files.map(function (file) {
        return file.toModelObject();
      });
      var modelObject = _extends({ files }, baseObject);
      return modelObject;
    }
  }, {
    key: 'toObject',
    value: function toObject() {
      (_analytics || _load_analytics()).Analytics.addBreadCrumb('env-extension', 'toObject');
      (_logger || _load_logger()).default.debug('env-extension - toObject');
      var baseObject = _get(EnvExtension.prototype.__proto__ || Object.getPrototypeOf(EnvExtension.prototype), 'toObject', this).call(this);
      var files = this.files;
      var object = _extends({}, baseObject, { files });
      return object;
    }

    /**
     * Get a bit.json representation of the env instance
     * @param {string} ejectedEnvDirectory - The base path of where the env config files are stored
     * $FlowFixMe seems to be an issue opened for this https://github.com/facebook/flow/issues/4953
     */

  }, {
    key: 'toBitJsonObject',
    value: function toBitJsonObject(ejectedEnvDirectory) {
      (_analytics || _load_analytics()).Analytics.addBreadCrumb('env-extension', 'toBitJsonObject');
      (_logger || _load_logger()).default.debug('env-extension - toBitJsonObject');
      var files = {};
      this.files.forEach(function (file) {
        var relativePath = (0, (_utils || _load_utils()).pathJoinLinux)(ejectedEnvDirectory, file.relative);
        files[file.name] = `./${relativePath}`;
      });
      var envVal = {
        rawConfig: this.dynamicConfig,
        options: this.options,
        files
      };
      return {
        [this.name]: envVal
      };
    }

    /**
     * Write the env files to the file system according to the template dir
     * used for ejecting env for imported component
     * @param {*} param
     */

  }, {
    key: 'writeFilesToFs',
    value: function () {
      var _ref3 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee2(_ref2) {
        var configDir = _ref2.configDir,
            envType = _ref2.envType,
            deleteOldFiles = _ref2.deleteOldFiles,
            _ref2$verbose = _ref2.verbose,
            verbose = _ref2$verbose === undefined ? false : _ref2$verbose;
        var resolvedEjectedEnvsDirectory, writeP, filePaths;
        return (_regenerator || _load_regenerator()).default.wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                (_analytics || _load_analytics()).Analytics.addBreadCrumb('env-extension', 'writeFilesToFs');
                (_logger || _load_logger()).default.debug('env-extension - writeFilesToFs');
                resolvedEjectedEnvsDirectory = (0, (_stringFormat || _load_stringFormat()).default)(configDir, { ENV_TYPE: envType });
                writeP = [];
                filePaths = [];

                this.files.forEach(function (file) {
                  if (deleteOldFiles) {
                    filePaths.push(file.path);
                  }
                  file.updatePaths({ newBase: resolvedEjectedEnvsDirectory, newRelative: file.relative });
                  writeP.push(file.write(null, true, verbose));
                });
                _context2.next = 8;
                return Promise.all(writeP);

              case 8:
                _context2.next = 10;
                return (0, (_utils || _load_utils()).removeFilesAndEmptyDirsRecursively)(filePaths);

              case 10:
                return _context2.abrupt('return', resolvedEjectedEnvsDirectory);

              case 11:
              case 'end':
                return _context2.stop();
            }
          }
        }, _callee2, this);
      }));

      function writeFilesToFs(_x4) {
        return _ref3.apply(this, arguments);
      }

      return writeFilesToFs;
    }()

    /**
     * Delete env files from file system
     */

  }, {
    key: 'removeFilesFromFs',
    value: function () {
      var _ref4 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee3(dependencies) {
        var filePaths, relativeSourcePaths, componentDir, linkPaths;
        return (_regenerator || _load_regenerator()).default.wrap(function _callee3$(_context3) {
          while (1) {
            switch (_context3.prev = _context3.next) {
              case 0:
                (_analytics || _load_analytics()).Analytics.addBreadCrumb('env-extension', 'removeFilesFromFs');
                filePaths = this.files.map(function (file) {
                  return file.path;
                });
                relativeSourcePaths = dependencies.getSourcesPaths();

                if (this.context) {
                  _context3.next = 5;
                  break;
                }

                throw new Error('env-extension.removeFilesFromFs, this.context is missing');

              case 5:
                componentDir = this.context.componentDir;
                linkPaths = relativeSourcePaths.map(function (relativePath) {
                  return (_path || _load_path()).default.join(componentDir, relativePath);
                });
                return _context3.abrupt('return', (0, (_utils || _load_utils()).removeFilesAndEmptyDirsRecursively)([].concat(_toConsumableArray(filePaths), _toConsumableArray(linkPaths))));

              case 8:
              case 'end':
                return _context3.stop();
            }
          }
        }, _callee3, this);
      }));

      function removeFilesFromFs(_x5) {
        return _ref4.apply(this, arguments);
      }

      return removeFilesFromFs;
    }()
  }, {
    key: 'reload',
    value: function () {
      var _ref5 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee4(scopePath, context) {
        var throws, dynamicPackageDependencies;
        return (_regenerator || _load_regenerator()).default.wrap(function _callee4$(_context4) {
          while (1) {
            switch (_context4.prev = _context4.next) {
              case 0:
                (_analytics || _load_analytics()).Analytics.addBreadCrumb('env-extension', 'reload');
                (_logger || _load_logger()).default.debug('env-extension - reload');
                if (context) {
                  this.context = context;
                }
                throws = true;
                _context4.next = 6;
                return _get(EnvExtension.prototype.__proto__ || Object.getPrototypeOf(EnvExtension.prototype), 'reload', this).call(this, scopePath, { throws });

              case 6:
                _context4.next = 8;
                return EnvExtension.loadDynamicPackageDependencies(this);

              case 8:
                dynamicPackageDependencies = _context4.sent;

                this.dynamicPackageDependencies = dynamicPackageDependencies;

              case 10:
              case 'end':
                return _context4.stop();
            }
          }
        }, _callee4, this);
      }));

      function reload(_x6, _x7) {
        return _ref5.apply(this, arguments);
      }

      return reload;
    }()

    /**
     * Loading from props (usually from bit.json)
     * @param {*} props
     * $FlowFixMe seems to be an issue opened for this https://github.com/facebook/flow/issues/4953
     */

  }], [{
    key: 'load',
    value: function () {
      var _ref6 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee5(props) {
        var baseExtensionProps, files, envExtensionProps, dynamicPackageDependencies;
        return (_regenerator || _load_regenerator()).default.wrap(function _callee5$(_context5) {
          while (1) {
            switch (_context5.prev = _context5.next) {
              case 0:
                (_analytics || _load_analytics()).Analytics.addBreadCrumb('env-extension', 'load');
                (_logger || _load_logger()).default.debug('env-extension - load');
                _context5.next = 4;
                return _get(EnvExtension.__proto__ || Object.getPrototypeOf(EnvExtension), 'load', this).call(this, props);

              case 4:
                baseExtensionProps = _context5.sent;
                _context5.next = 7;
                return (_extensionFile || _load_extensionFile()).default.loadFromBitJsonObject(
                // $FlowFixMe
                props.files, // $FlowFixMe
                props.consumerPath, props.bitJsonPath, props.envType);

              case 7:
                files = _context5.sent;
                envExtensionProps = _extends({ envType: props.envType, files }, baseExtensionProps);
                _context5.next = 11;
                return EnvExtension.loadDynamicPackageDependencies(envExtensionProps);

              case 11:
                dynamicPackageDependencies = _context5.sent;

                envExtensionProps.dynamicPackageDependencies = dynamicPackageDependencies;
                return _context5.abrupt('return', envExtensionProps);

              case 14:
              case 'end':
                return _context5.stop();
            }
          }
        }, _callee5, this);
      }));

      function load(_x8) {
        return _ref6.apply(this, arguments);
      }

      return load;
    }()
  }, {
    key: 'loadDynamicPackageDependencies',
    value: function () {
      var _ref7 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee6(envExtensionProps) {
        var getDynamicPackageDependencies, _dynamicPackageDependencies;

        return (_regenerator || _load_regenerator()).default.wrap(function _callee6$(_context6) {
          while (1) {
            switch (_context6.prev = _context6.next) {
              case 0:
                (_analytics || _load_analytics()).Analytics.addBreadCrumb('env-extension', 'loadDynamicPackageDependencies');
                (_logger || _load_logger()).default.debug('env-extension - loadDynamicPackageDependencies');
                getDynamicPackageDependencies = (_ramda || _load_ramda()).default.path(['script', 'getDynamicPackageDependencies'], envExtensionProps);

                if (!(getDynamicPackageDependencies && typeof getDynamicPackageDependencies === 'function')) {
                  _context6.next = 14;
                  break;
                }

                _context6.prev = 4;
                _context6.next = 7;
                return getDynamicPackageDependencies({
                  rawConfig: envExtensionProps.rawConfig,
                  dynamicConfig: envExtensionProps.dynamicConfig,
                  configFiles: envExtensionProps.files,
                  context: envExtensionProps.context
                });

              case 7:
                _dynamicPackageDependencies = _context6.sent;
                return _context6.abrupt('return', _dynamicPackageDependencies);

              case 11:
                _context6.prev = 11;
                _context6.t0 = _context6['catch'](4);
                throw new (_extensionGetDynamicPackagesError || _load_extensionGetDynamicPackagesError()).default(_context6.t0, envExtensionProps.name);

              case 14:
                return _context6.abrupt('return', undefined);

              case 15:
              case 'end':
                return _context6.stop();
            }
          }
        }, _callee6, this, [[4, 11]]);
      }));

      function loadDynamicPackageDependencies(_x9) {
        return _ref7.apply(this, arguments);
      }

      return loadDynamicPackageDependencies;
    }()

    /**
     * $FlowFixMe seems to be an issue opened for this https://github.com/facebook/flow/issues/4953
     */

  }, {
    key: 'loadFromModelObject',
    value: function () {
      var _ref8 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee7(
      // $FlowFixMe
      modelObject, repository) {
        var baseExtensionProps, files, loadFilesP, envExtensionProps;
        return (_regenerator || _load_regenerator()).default.wrap(function _callee7$(_context7) {
          while (1) {
            switch (_context7.prev = _context7.next) {
              case 0:
                (_analytics || _load_analytics()).Analytics.addBreadCrumb('env-extension', 'loadFromModelObject');
                (_logger || _load_logger()).default.debug('env-extension - loadFromModelObject');
                // $FlowFixMe
                baseExtensionProps = _get(EnvExtension.__proto__ || Object.getPrototypeOf(EnvExtension), 'loadFromModelObject', this).call(this, modelObject);
                files = [];

                if (!(modelObject.files && !(_ramda || _load_ramda()).default.isEmpty(modelObject.files))) {
                  _context7.next = 9;
                  break;
                }

                loadFilesP = modelObject.files.map(function (file) {
                  return (_extensionFile || _load_extensionFile()).default.loadFromExtensionFileModel(file, repository);
                });
                _context7.next = 8;
                return Promise.all(loadFilesP);

              case 8:
                files = _context7.sent;

              case 9:
                envExtensionProps = _extends({ envType: modelObject.envType, files }, baseExtensionProps);
                return _context7.abrupt('return', envExtensionProps);

              case 11:
              case 'end':
                return _context7.stop();
            }
          }
        }, _callee7, this);
      }));

      function loadFromModelObject(_x10, _x11) {
        return _ref8.apply(this, arguments);
      }

      return loadFromModelObject;
    }()

    /**
     * Load the compiler / tester from the correct place
     * This take into account the component origin (authored / imported)
     * And the detach status of the env
     * If a component has a bit.json with compiler defined take it
     * Else if a component is not authored take if from the models
     * Else, for authored component check if the compiler has been changed
     *
     */

  }, {
    key: 'loadFromCorrectSource',
    value: function () {
      var _ref10 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee8(_ref9) {
        var consumerPath = _ref9.consumerPath,
            scopePath = _ref9.scopePath,
            componentOrigin = _ref9.componentOrigin,
            componentFromModel = _ref9.componentFromModel,
            consumerBitJson = _ref9.consumerBitJson,
            componentBitJson = _ref9.componentBitJson,
            detached = _ref9.detached,
            envType = _ref9.envType,
            context = _ref9.context;
        return (_regenerator || _load_regenerator()).default.wrap(function _callee8$(_context8) {
          while (1) {
            switch (_context8.prev = _context8.next) {
              case 0:
                (_analytics || _load_analytics()).Analytics.addBreadCrumb('env-extension', 'loadFromCorrectSource');
                (_logger || _load_logger()).default.debug(`env-extension (${envType}) loadFromCorrectSource`);

                // Authored component

                if (!(componentOrigin === (_constants || _load_constants()).COMPONENT_ORIGINS.AUTHORED)) {
                  _context8.next = 6;
                  break;
                }

                if (detached) {
                  _context8.next = 5;
                  break;
                }

                return _context8.abrupt('return', loadFromBitJson({ bitJson: consumerBitJson, envType, consumerPath, scopePath, context }));

              case 5:
                return _context8.abrupt('return', loadFromComponentBitJsonOrFromModel({
                  modelComponent: componentFromModel,
                  componentBitJson,
                  envType,
                  consumerPath,
                  scopePath,
                  context
                }));

              case 6:
                if (!(detached === false)) {
                  _context8.next = 8;
                  break;
                }

                return _context8.abrupt('return', loadFromBitJson({ bitJson: consumerBitJson, envType, consumerPath, scopePath, context }));

              case 8:
                return _context8.abrupt('return', loadFromComponentBitJsonOrFromModel({
                  modelComponent: componentFromModel,
                  componentBitJson,
                  envType,
                  consumerPath,
                  scopePath,
                  context
                }));

              case 9:
              case 'end':
                return _context8.stop();
            }
          }
        }, _callee8, this);
      }));

      function loadFromCorrectSource(_x12) {
        return _ref10.apply(this, arguments);
      }

      return loadFromCorrectSource;
    }()
  }]);

  return EnvExtension;
}((_baseExtension || _load_baseExtension()).default);

exports.default = EnvExtension;


var loadFromBitJson = function loadFromBitJson(_ref11) {
  var bitJson = _ref11.bitJson,
      envType = _ref11.envType,
      consumerPath = _ref11.consumerPath,
      scopePath = _ref11.scopePath,
      context = _ref11.context;

  (_logger || _load_logger()).default.debug(`env-extension (${envType}) loadFromBitJson`);
  if (envType === (_compilerExtension2 || _load_compilerExtension2()).COMPILER_ENV_TYPE) {
    return bitJson.loadCompiler(consumerPath, scopePath, context);
  }
  return bitJson.loadTester(consumerPath, scopePath, context);
};

var loadFromComponentBitJsonOrFromModel = function () {
  var _ref13 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee9(_ref12) {
    var modelComponent = _ref12.modelComponent,
        componentBitJson = _ref12.componentBitJson,
        envType = _ref12.envType,
        consumerPath = _ref12.consumerPath,
        scopePath = _ref12.scopePath,
        context = _ref12.context;
    return (_regenerator || _load_regenerator()).default.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            (_logger || _load_logger()).default.debug(`env-extension (${envType}) loadFromComponentBitJsonOrFromModel`);

            if (!componentBitJson) {
              _context9.next = 3;
              break;
            }

            return _context9.abrupt('return', loadFromBitJson({ bitJson: componentBitJson, envType, consumerPath, scopePath, context }));

          case 3:
            (_logger || _load_logger()).default.debug(`env-extension (${envType}) loadFromComponentBitJsonOrFromModel. loading from the model`);

            if (!(envType === (_compilerExtension2 || _load_compilerExtension2()).COMPILER_ENV_TYPE)) {
              _context9.next = 6;
              break;
            }

            return _context9.abrupt('return', modelComponent ? modelComponent.compiler : undefined);

          case 6:
            if (!(envType === (_testerExtension2 || _load_testerExtension2()).TESTER_ENV_TYPE)) {
              _context9.next = 8;
              break;
            }

            return _context9.abrupt('return', modelComponent ? modelComponent.tester : undefined);

          case 8:
            return _context9.abrupt('return', undefined);

          case 9:
          case 'end':
            return _context9.stop();
        }
      }
    }, _callee9, undefined);
  }));

  return function loadFromComponentBitJsonOrFromModel(_x13) {
    return _ref13.apply(this, arguments);
  };
}();