All files / lib/internal resolveModule.js

100% Statements 31/31
100% Branches 8/8
100% Functions 2/2
100% Lines 31/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 6716x 6716x 6716x 6716x 7403x 7403x 7403x 7403x 7403x 6716x 6716x 10x 10x 10x 10x 9x 9x 1x 1x 1x 6716x  
"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;
  }
};