Home > @rushstack/node-core-library > PackageJsonLookup > tryGetPackageFolderFor
PackageJsonLookup.tryGetPackageFolderFor() method
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.
Signature:
tryGetPackageFolderFor(fileOrFolderPath: string): string | undefined;
Parameters
Parameter | Type | Description |
---|---|---|
fileOrFolderPath | string | a relative or absolute path to a source file or folder that may be part of a package |
Returns:
string | undefined
an absolute path to a folder containing a package.json file
Remarks
The fileOrFolderPath is not required to actually exist on disk. The fileOrFolderPath itself can be the return value, if it is a folder containing a package.json file. Both positive and negative lookup results are cached.