All files package-reader.ts

71.43% Statements 5/7
75% Branches 6/8
50% Functions 1/2
71.43% Lines 5/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 211x             1x   2x 2x   2x                
import * as fs from "fs";
/**
 * @param  packageJsonPath Path to package.json
 * @param  loadPackageJson Function that reads and parses package.json.
 * @param  fileExists Function that checks for existance of a file.
 * @returns string
 */
export function readPackage(
  packageJsonPath: string,
  IloadPackageJson: (file: string) => any = loadJsonFromDisk,
  IfileExists: (path: string) => boolean = fs.existsSync
): { main: string } | undefined {
return (packageJsonPath.match(/package\.json$/) && fileExists(packageJsonPath) && loadPackageJson(packageJsonPath)) || undefined;
}
 
function loadJsonFromDisk(file: string) {
  const packageJson = require(file);
 
  return packageJson;
}