Skip to content

Commit

Permalink
improve performance by caching more getters (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW authored Aug 14, 2023
1 parent 52933c1 commit 7e45df7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/workspace/node-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export default class NodeModule {
_remoteData: RemoteData | null;
_packageJson: PackageJson | null;
_stats: Stats | null;
_path: string | null;
_realpath: string | null;
_yarnRequiredBy: Set<string> | null;
_symlink: string | null;
_maxVersionInSameMajor: string | null;

constructor({
nodeModulesPath,
Expand All @@ -48,11 +50,13 @@ export default class NodeModule {
this.parent = parent;
this.workspace = workspace;
this._stats = null;
this._path = null;
this._realpath = null;
this._remoteData = null;
this._packageJson = null;
this._yarnRequiredBy = null;
this._symlink = null;
this._maxVersionInSameMajor = null;
}

get packageJson(): PackageJson {
Expand Down Expand Up @@ -80,7 +84,10 @@ export default class NodeModule {
}

get path() {
return path.join(this.nodeModulesPath, this.name);
if (!this._path) {
this._path = path.join(this.nodeModulesPath, this.name);
}
return this._path;
}

get realpath() {
Expand Down Expand Up @@ -143,10 +150,13 @@ export default class NodeModule {
}

get maxVersionInSameMajor(): string | null {
return semverMaxSatisfying(
this.remoteData.versions,
`^${semver.clean(this.version)}`
);
if (!this._maxVersionInSameMajor) {
this._maxVersionInSameMajor = semverMaxSatisfying(
this.remoteData.versions,
`^${semver.clean(this.version)}`
);
}
return this._maxVersionInSameMajor;
}

get maxVersionInSameMajorLastModified(): Date | null {
Expand Down
2 changes: 1 addition & 1 deletion src/workspace/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default class Workspace {
}
}

return this._isPnpm!;
return this._isPnpm;
}

get resolutionsList(): any {
Expand Down

0 comments on commit 7e45df7

Please sign in to comment.