UNPKG

@microsoft/api-extractor

Version:

Validatation, documentation, and auditing for the exported API of a TypeScript package

53 lines (51 loc) 1.94 kB
/* tslint:disable:no-constant-condition */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var fsx = require("fs-extra"); var path = require("path"); var JsonFile_1 = require("./JsonFile"); /** * Utilities for navigating packages. */ var PackageJsonHelpers = (function () { function PackageJsonHelpers() { } /** * Finds the path to the package folder of a given currentPath, by probing * upwards from the currentPath until a package.json file is found. * If no package.json can be found, undefined is returned. * * @param currentPath - a path (relative or absolute) of the current location * @returns a relative path to the package folder */ PackageJsonHelpers.tryFindPackagePathUpwards = function (currentPath) { var packageFolder = ''; // no-constant-condition while (true) { var folder = path.dirname(currentPath); if (!folder || folder === currentPath) { return undefined; } currentPath = folder; if (fsx.existsSync(path.join(currentPath, 'package.json'))) { packageFolder = path.normalize(currentPath); break; } } return packageFolder; }; /** * Loads the package.json file and returns the name of the package. * * @param packageJsonPath - an absolute path to the folder containing the * package.json file, it does not include the 'package.json' suffix. * @returns the name of the package (E.g. @microsoft/api-extractor) */ PackageJsonHelpers.readPackageName = function (packageJsonPath) { var packageJson = JsonFile_1.default.loadJsonFile(path.join(packageJsonPath, 'package.json')); return packageJson.name; }; return PackageJsonHelpers; }()); exports.default = PackageJsonHelpers; //# sourceMappingURL=PackageJsonHelpers.js.map