'use strict';

const upath = require('./upath.js');

function getModulePaths(paths) {
  return [].concat(global.__NUXT_PREPATHS__, ...Array.isArray(paths) ? paths : [paths], process.cwd(), global.__NUXT_PATHS__).filter(Boolean);
}
function resolveModule(id, paths) {
  return upath.upath.normalize(require.resolve(id, { paths: getModulePaths(paths) }));
}
function requireModule(id, paths) {
  return require(resolveModule(id, paths));
}
function getNearestPackage(id, paths) {
  while (upath.upath.dirname(id) !== id) {
    try {
      return requireModule(id + "/package.json", paths);
    } catch {
    }
    id = upath.upath.dirname(id);
  }
  return null;
}

exports.getModulePaths = getModulePaths;
exports.getNearestPackage = getNearestPackage;
exports.requireModule = requireModule;
