UNPKG

@microsoft/api-extractor

Version:

Validate, document, and review the exported API for a TypeScript library

64 lines 2.69 kB
"use strict"; // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. Object.defineProperty(exports, "__esModule", { value: true }); /** * Represents analyzed information for a package.json file. * This object is constructed and returned by PackageMetadataManager. */ class PackageMetadata { constructor(packageJsonPath, packageJsonLookup) { this._packageJsonLookup = packageJsonLookup; this.packageJsonPath = packageJsonPath; this.packageJson = this._packageJsonLookup.loadPackageJson(packageJsonPath); this.aedocSupported = false; if (this.packageJson.tsdoc) { if (this.packageJson.tsdoc.tsdocFlavor) { if (this.packageJson.tsdoc.tsdocFlavor.toUpperCase() === 'AEDOC') { this.aedocSupported = true; } } } } } exports.PackageMetadata = PackageMetadata; /** * This class maintains a cache of analyzed information obtained from package.json * files. It is built on top of the PackageJsonLookup class. */ class PackageMetadataManager { constructor(packageJsonLookup) { this._packageMetadataByPackageJsonPath = new Map(); this._packageJsonLookup = packageJsonLookup; } /** * Finds the package.json in a parent folder of the specified source file, and * returns a PackageMetadata object. If no package.json was found, then undefined * is returned. The results are cached. */ tryFetchPackageMetadata(sourceFilePath) { const packageJsonFilePath = this._packageJsonLookup.tryGetPackageJsonFilePathFor(sourceFilePath); if (!packageJsonFilePath) { return undefined; } let packageMetadata = this._packageMetadataByPackageJsonPath.get(packageJsonFilePath); if (!packageMetadata) { packageMetadata = new PackageMetadata(packageJsonFilePath, this._packageJsonLookup); this._packageMetadataByPackageJsonPath.set(packageJsonFilePath, packageMetadata); } return packageMetadata; } /** * Returns true if the source file has an associated PackageMetadata object * with aedocSupported=true. */ isAedocSupportedFor(sourceFilePath) { const packageMetadata = this.tryFetchPackageMetadata(sourceFilePath); if (!packageMetadata) { return false; } return packageMetadata.aedocSupported; } } exports.PackageMetadataManager = PackageMetadataManager; //# sourceMappingURL=PackageMetadataManager.js.map