All files resolveModule.js

90.32% Statements 28/31
77.78% Branches 7/9
100% Functions 2/2
90.32% Lines 28/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 321x 1x 1x 1x 1x 1x 1x 1x 1x 1x 507x 507x 507x 507x 812x 812x 812x 812x 812x 507x 507x 2x 2x 2x 2x 2x 2x       507x  
"use strict";
 
const resolve = require("resolve");
 
/**
 * @param {string} fileName
 * @param {string} [basedir]
 * @returns {null | string}
 */
module.exports = function resolveModule(fileName, basedir) {
  try {
    return resolve.sync(fileName, {
      basedir,
      packageFilter(pkg) {
        return {
          ...pkg,
          main: pkg.module || pkg.esnext || pkg["jsnext:main"] || pkg.main,
        };
      },
    });
  } catch (error) {
    if (
      error instanceof Error &&
      /** @type {NodeJS.ErrnoException} */ (error).code === "MODULE_NOT_FOUND"
    ) {
      return null;
    }

    throw error;
  }
};