RoadmapShopEvents
Skip to main content

Home > @rushstack/node-core-library > PackageJsonLookup

PackageJsonLookup class

This class provides methods for finding the nearest "package.json" for a folder and retrieving the name of the package. The results are cached.

Signature:

export declare class PackageJsonLookup 

Constructors

ConstructorModifiersDescription
(constructor)(parameters)Constructs a new instance of the PackageJsonLookup class

Properties

PropertyModifiersTypeDescription
instance

readonly

static

PackageJsonLookupA singleton instance of PackageJsonLookup, which is useful for short-lived processes that can reasonably assume that the file system will not be modified after the cache is populated.

Methods

MethodModifiersDescription
clearCache()Clears the internal file cache.
loadNodePackageJson(jsonFilename)This function is similar to PackageJsonLookup.loadPackageJson(), except that it does not report an error if the version field is missing from the package.json file.
loadOwnPackageJson(dirnameOfCaller)staticA helper for loading the caller's own package.json file.
loadPackageJson(jsonFilename)Loads the specified package.json file, if it is not already present in the cache.
tryGetPackageFolderFor(fileOrFolderPath)Returns the absolute path of a folder containing a package.json file, by looking upwards from the specified fileOrFolderPath. If no package.json can be found, undefined is returned.
tryGetPackageJsonFilePathFor(fileOrFolderPath)If the specified file or folder is part of a package, this returns the absolute path to the associated package.json file.
tryLoadNodePackageJsonFor(fileOrFolderPath)This function is similar to PackageJsonLookup.tryLoadPackageJsonFor(), except that it does not report an error if the version field is missing from the package.json file.
tryLoadPackageJsonFor(fileOrFolderPath)If the specified file or folder is part of a package, this loads and returns the associated package.json file.