'use strict';

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

var _path;

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

var _generalError;

function _load_generalError() {
  return _generalError = _interopRequireDefault(require('../../error/general-error'));
}

var _constants;

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

var _bitId;

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

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

function getNodeModulesPathOfComponent(bindingPrefix, id) {
  if (!id.scope) {
    throw new (_generalError || _load_generalError()).default(`Failed creating a path in node_modules for ${id.toString()}, as it does not have a scope yet`);
  }
  if (!bindingPrefix) bindingPrefix = (_constants || _load_constants()).DEFAULT_BINDINGS_PREFIX;
  // Temp fix to support old components before the migration has been running
  bindingPrefix = bindingPrefix === 'bit' ? '@bit' : bindingPrefix;
  var allSlashes = new RegExp('/', 'g');
  var name = id.name.replace(allSlashes, (_constants || _load_constants()).NODE_PATH_COMPONENT_SEPARATOR);
  return (_path || _load_path()).default.join('node_modules', bindingPrefix, [id.scope, name].join((_constants || _load_constants()).NODE_PATH_COMPONENT_SEPARATOR));
}