Rush StackShopBlogEvents
Skip to main content

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

PackageJsonLookup.tryLoadPackageJsonFor() method

If the specified file or folder is part of a package, this loads and returns the associated package.json file.

Signature:

tryLoadPackageJsonFor(fileOrFolderPath: string): IPackageJson | undefined;

Parameters

ParameterTypeDescription
fileOrFolderPathstringa relative or absolute path to a source file or folder that may be part of a package

Returns:

IPackageJson | undefined

an IPackageJson object, or undefined if the fileOrFolderPath does not belong to a package

Remarks

The package folder is determined using the same algorithm as PackageJsonLookup.tryGetPackageFolderFor().