"use strict";

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

var _constants = require("../constants");

var _logger = require("../logger");

var _requireLocalOrGlobal = require("../servers/requireLocalOrGlobal");

var _libAlias = require("./libAlias");

var _client_packages_group = require("@zohodesk/client_packages_group");

function moduleResolver(options) {
  const {
    moduleResolvePath,
    disableES5Transpile
  } = options.app;
  let required = moduleResolvePath && (0, _requireLocalOrGlobal.requireLocal)(moduleResolvePath);

  if (!required) {
    required = (0, _requireLocalOrGlobal.requireGlobal)('@zohodesk/client_packages_group');

    if (required) {
      (0, _logger.messageLogger)('global `@zohodesk/client_packages_group` package taken as client_packages_group');
    }
  }

  const nodeModulesPath = required ? required.nodeModulesPath : _client_packages_group.nodeModulesPath;
  return {
    modules: [nodeModulesPath, _constants.cliNodeModulesPath, 'node_modules'].filter(Boolean),
    alias: disableES5Transpile ? _libAlias.libAlias : {} // alias: { ...libAlias, ...clientDependenies }

  };
}

function loaderResolver(options) {
  // const unstableDepsInverse = false;
  const {
    unstableDepsInverse
  } = options;
  return {
    modules: unstableDepsInverse ? ['node_modules', _constants.cliNodeModulesPath] : [_constants.cliNodeModulesPath, 'node_modules'] // alias:  libAlias

  };
}