All files / lib/internal resolveModule.js

100% Statements 8/8
100% Branches 8/8
100% Functions 2/2
100% Lines 8/8

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 32    14x             14x 7159x 7159x     8102x             11x       10x     1x      
"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;
  }
};