UNPKG

find-node-modules

Version:

Return an array of all parent node_modules directories

882 lines (856 loc) 16.1 kB
"use strict"; var cov_242ewvhlu5 = function () { var path = "/home/travis/build/commitizen/cz-cli/src/common/util.js"; var hash = "bc100f0514e392d8356e6e0e1abc901d83a3961e"; var global = new Function("return this")(); var gcv = "__coverage__"; var coverageData = { path: "/home/travis/build/commitizen/cz-cli/src/common/util.js", statementMap: { "0": { start: { line: 19, column: 2 }, end: { line: 19, column: 14 } }, "1": { start: { line: 20, column: 2 }, end: { line: 20, column: 26 } }, "2": { start: { line: 27, column: 2 }, end: { line: 32, column: 3 } }, "3": { start: { line: 28, column: 30 }, end: { line: 28, column: 86 } }, "4": { start: { line: 29, column: 4 }, end: { line: 29, column: 43 } }, "5": { start: { line: 31, column: 4 }, end: { line: 31, column: 21 } }, "6": { start: { line: 39, column: 2 }, end: { line: 39, column: 53 } }, "7": { start: { line: 46, column: 4 }, end: { line: 53, column: 3 } }, "8": { start: { line: 48, column: 4 }, end: { line: 48, column: 17 } }, "9": { start: { line: 49, column: 9 }, end: { line: 53, column: 3 } }, "10": { start: { line: 50, column: 4 }, end: { line: 50, column: 17 } }, "11": { start: { line: 52, column: 4 }, end: { line: 52, column: 37 } }, "12": { start: { line: 60, column: 2 }, end: { line: 68, column: 3 } }, "13": { start: { line: 62, column: 4 }, end: { line: 62, column: 17 } }, "14": { start: { line: 63, column: 9 }, end: { line: 68, column: 3 } }, "15": { start: { line: 64, column: 4 }, end: { line: 64, column: 17 } }, "16": { start: { line: 66, column: 18 }, end: { line: 66, column: 20 } }, "17": { start: { line: 67, column: 4 }, end: { line: 67, column: 93 } }, "18": { start: { line: 75, column: 2 }, end: { line: 82, column: 3 } }, "19": { start: { line: 77, column: 4 }, end: { line: 77, column: 17 } }, "20": { start: { line: 78, column: 9 }, end: { line: 82, column: 3 } }, "21": { start: { line: 79, column: 4 }, end: { line: 79, column: 17 } }, "22": { start: { line: 81, column: 4 }, end: { line: 81, column: 69 } }, "23": { start: { line: 86, column: 2 }, end: { line: 86, column: 41 } } }, fnMap: { "0": { name: "executeShellCommand", decl: { start: { line: 18, column: 9 }, end: { line: 18, column: 28 } }, loc: { start: { line: 18, column: 56 }, end: { line: 21, column: 1 } }, line: 18 }, "1": { name: "getParsedJsonFromFile", decl: { start: { line: 26, column: 9 }, end: { line: 26, column: 30 } }, loc: { start: { line: 26, column: 71 }, end: { line: 33, column: 1 } }, line: 26 }, "2": { name: "getParsedPackageJsonFromPath", decl: { start: { line: 38, column: 9 }, end: { line: 38, column: 37 } }, loc: { start: { line: 38, column: 45 }, end: { line: 40, column: 1 } }, line: 38 }, "3": { name: "isArray", decl: { start: { line: 45, column: 9 }, end: { line: 45, column: 16 } }, loc: { start: { line: 45, column: 23 }, end: { line: 54, column: 1 } }, line: 45 }, "4": { name: "isFunction", decl: { start: { line: 59, column: 9 }, end: { line: 59, column: 19 } }, loc: { start: { line: 59, column: 38 }, end: { line: 69, column: 1 } }, line: 59 }, "5": { name: "isString", decl: { start: { line: 74, column: 9 }, end: { line: 74, column: 17 } }, loc: { start: { line: 74, column: 24 }, end: { line: 83, column: 1 } }, line: 74 }, "6": { name: "isInTest", decl: { start: { line: 85, column: 9 }, end: { line: 85, column: 17 } }, loc: { start: { line: 85, column: 21 }, end: { line: 87, column: 1 } }, line: 85 } }, branchMap: { "0": { loc: { start: { line: 26, column: 52 }, end: { line: 26, column: 69 } }, type: "default-arg", locations: [{ start: { line: 26, column: 63 }, end: { line: 26, column: 69 } }], line: 26 }, "1": { loc: { start: { line: 46, column: 4 }, end: { line: 53, column: 3 } }, type: "if", locations: [{ start: { line: 46, column: 4 }, end: { line: 53, column: 3 } }, { start: { line: 46, column: 4 }, end: { line: 53, column: 3 } }], line: 46 }, "2": { loc: { start: { line: 49, column: 9 }, end: { line: 53, column: 3 } }, type: "if", locations: [{ start: { line: 49, column: 9 }, end: { line: 53, column: 3 } }, { start: { line: 49, column: 9 }, end: { line: 53, column: 3 } }], line: 49 }, "3": { loc: { start: { line: 60, column: 2 }, end: { line: 68, column: 3 } }, type: "if", locations: [{ start: { line: 60, column: 2 }, end: { line: 68, column: 3 } }, { start: { line: 60, column: 2 }, end: { line: 68, column: 3 } }], line: 60 }, "4": { loc: { start: { line: 63, column: 9 }, end: { line: 68, column: 3 } }, type: "if", locations: [{ start: { line: 63, column: 9 }, end: { line: 68, column: 3 } }, { start: { line: 63, column: 9 }, end: { line: 68, column: 3 } }], line: 63 }, "5": { loc: { start: { line: 67, column: 11 }, end: { line: 67, column: 92 } }, type: "binary-expr", locations: [{ start: { line: 67, column: 11 }, end: { line: 67, column: 26 } }, { start: { line: 67, column: 30 }, end: { line: 67, column: 92 } }], line: 67 }, "6": { loc: { start: { line: 75, column: 2 }, end: { line: 82, column: 3 } }, type: "if", locations: [{ start: { line: 75, column: 2 }, end: { line: 82, column: 3 } }, { start: { line: 75, column: 2 }, end: { line: 82, column: 3 } }], line: 75 }, "7": { loc: { start: { line: 78, column: 9 }, end: { line: 82, column: 3 } }, type: "if", locations: [{ start: { line: 78, column: 9 }, end: { line: 82, column: 3 } }, { start: { line: 78, column: 9 }, end: { line: 82, column: 3 } }], line: 78 } }, s: { "0": 0, "1": 0, "2": 0, "3": 0, "4": 0, "5": 0, "6": 0, "7": 0, "8": 0, "9": 0, "10": 0, "11": 0, "12": 0, "13": 0, "14": 0, "15": 0, "16": 0, "17": 0, "18": 0, "19": 0, "20": 0, "21": 0, "22": 0, "23": 0 }, f: { "0": 0, "1": 0, "2": 0, "3": 0, "4": 0, "5": 0, "6": 0 }, b: { "0": [0], "1": [0, 0], "2": [0, 0], "3": [0, 0], "4": [0, 0], "5": [0, 0], "6": [0, 0], "7": [0, 0] }, _coverageSchema: "43e27e138ebf9cfc5966b082cf9a028302ed4184", hash: "bc100f0514e392d8356e6e0e1abc901d83a3961e" }; var coverage = global[gcv] || (global[gcv] = {}); if (coverage[path] && coverage[path].hash === hash) { return coverage[path]; } return coverage[path] = coverageData; }(); Object.defineProperty(exports, "__esModule", { value: true }); exports.executeShellCommand = executeShellCommand; exports.getParsedJsonFromFile = getParsedJsonFromFile; exports.getParsedPackageJsonFromPath = getParsedPackageJsonFromPath; exports.isArray = isArray; exports.isFunction = isFunction; exports.isString = isString; exports.isInTest = isInTest; var _fs = _interopRequireDefault(require("fs")); var _path = _interopRequireDefault(require("path")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Executes the command passed to it at the path requested * using the instance of shelljs passed in */ function executeShellCommand(sh, path, installCommand) { cov_242ewvhlu5.f[0]++; cov_242ewvhlu5.s[0]++; sh.cd(path); cov_242ewvhlu5.s[1]++; sh.exec(installCommand); } /** * Gets the parsed contents of a json file */ function getParsedJsonFromFile(filePath, fileName, encoding = (cov_242ewvhlu5.b[0][0]++, 'utf8')) { cov_242ewvhlu5.f[1]++; cov_242ewvhlu5.s[2]++; try { var packageJsonContents = (cov_242ewvhlu5.s[3]++, _fs.default.readFileSync(_path.default.join(filePath, fileName), encoding)); cov_242ewvhlu5.s[4]++; return JSON.parse(packageJsonContents); } catch (e) { cov_242ewvhlu5.s[5]++; console.error(e); } } /** * A helper method for getting the contents of package.json at a given path */ function getParsedPackageJsonFromPath(path) { cov_242ewvhlu5.f[2]++; cov_242ewvhlu5.s[6]++; return getParsedJsonFromFile(path, 'package.json'); } /** * Test if the passed argument is an array */ function isArray(arr) { cov_242ewvhlu5.f[3]++; cov_242ewvhlu5.s[7]++; if (typeof arr === "undefined") { cov_242ewvhlu5.b[1][0]++; cov_242ewvhlu5.s[8]++; return false; } else { cov_242ewvhlu5.b[1][1]++; cov_242ewvhlu5.s[9]++; if (arr === null) { cov_242ewvhlu5.b[2][0]++; cov_242ewvhlu5.s[10]++; return false; } else { cov_242ewvhlu5.b[2][1]++; cov_242ewvhlu5.s[11]++; return arr.constructor === Array; } } } /** * Test if the passed argument is a function */ function isFunction(functionToCheck) { cov_242ewvhlu5.f[4]++; cov_242ewvhlu5.s[12]++; if (typeof functionToCheck === "undefined") { cov_242ewvhlu5.b[3][0]++; cov_242ewvhlu5.s[13]++; return false; } else { cov_242ewvhlu5.b[3][1]++; cov_242ewvhlu5.s[14]++; if (functionToCheck === null) { cov_242ewvhlu5.b[4][0]++; cov_242ewvhlu5.s[15]++; return false; } else { cov_242ewvhlu5.b[4][1]++; var getType = (cov_242ewvhlu5.s[16]++, {}); cov_242ewvhlu5.s[17]++; return (cov_242ewvhlu5.b[5][0]++, functionToCheck) && (cov_242ewvhlu5.b[5][1]++, getType.toString.call(functionToCheck) === '[object Function]'); } } } /** * Test if the passed argument is a string */ function isString(str) { cov_242ewvhlu5.f[5]++; cov_242ewvhlu5.s[18]++; if (typeof str === "undefined") { cov_242ewvhlu5.b[6][0]++; cov_242ewvhlu5.s[19]++; return false; } else { cov_242ewvhlu5.b[6][1]++; cov_242ewvhlu5.s[20]++; if (str === null) { cov_242ewvhlu5.b[7][0]++; cov_242ewvhlu5.s[21]++; return false; } else { cov_242ewvhlu5.b[7][1]++; cov_242ewvhlu5.s[22]++; return Object.prototype.toString.call(str) === '[object String]'; } } } function isInTest() { cov_242ewvhlu5.f[6]++; cov_242ewvhlu5.s[23]++; return typeof global.it === 'function'; }