All files resolvePackageEntry.js

61.29% Statements 19/31
50% Branches 1/2
100% Functions 1/1
61.29% Lines 19/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 1x 1x 3x 3x 3x 3x 3x 3x 3x                          
"use strict";
 
const path = require("path");
const assert = require("assert");
const resolveModule = require("./resolveModule");
 
/**
 * @param {string} name
 * @param {string} [indexFile]
 * @returns {string}
 */
module.exports = function resolvePackageEntry(name, indexFile) {
  if (!indexFile) {
    const entry = resolveModule(name);
 
    assert.ok(entry, `failed to find 'indexFile' of '${name}'.`);
 
    return entry;
  }

  const pkgJSONPath = resolveModule(`${name}/package.json`);

  assert.ok(pkgJSONPath, `failed to resolve 'package.json' for '${name}'.`);

  const pkgDir = path.dirname(pkgJSONPath);
  const entry = resolveModule(path.join(pkgDir, indexFile));

  assert.ok(entry, `failed to resolve 'indexFile' specified for '${name}'.`);

  return entry;
};