Repository navigation
Fix a perf issue where API Extractor would reread package.json - #236
Conversation
| * and retrieving the name of the package. The results are cached. | ||
| */ | ||
| export default class PackageJsonLookup { | ||
| private _tryFindPackagePathUpwardsCache: Map<string, string>; |
There was a problem hiding this comment.
_tryFindPackagePathUpwardsCache [](start = 10, length = 31)
How about naming those two as packagePathCache and packageNameCache? #Resolved
| * This class provides methods for finding the nearest "package.json" for a folder | ||
| * and retrieving the name of the package. The results are cached. | ||
| */ | ||
| export default class PackageJsonLookup { |
There was a problem hiding this comment.
PackageJsonLookup [](start = 21, length = 17)
If this one is reusable, please add a test class as well. #Resolved
There was a problem hiding this comment.
This code is already heavily covered by the other unit tests, but I can add a dedicated test as well.
In reply to: 122495182 [](ancestors = 122495182)
| // represent "undefined". | ||
| let result: string = this._tryFindPackagePathUpwardsCache.get(currentPath); | ||
| if (result !== undefined) { | ||
| return result === null ? undefined : result; // tslint:disable-line: no-null-keyword |
There was a problem hiding this comment.
result === null ? undefined : result [](start = 13, length = 36)
This can be put in a function. Two copies of the same code here. #Resolved
There was a problem hiding this comment.
QZ (@qz2017) actually the code is not the same. However since that wasn't obvious, I suppose it would be more readable to move it into a function. :-)
In reply to: 122495414 [](ancestors = 122495414)
There was a problem hiding this comment.
I chatted with some other people about this, and it turns out that you CAN store 'undefined' in a Map. You just have to use the has() function (i.e. two lookups) to handle that case.
In reply to: 122506976 [](ancestors = 122506976,122495414)
When determining which NPM package a source file belongs to, API Extractor was repeatedly reading the same package.json files. This PR adds a cache to avoid performance issues.