Skip to content

Commit 27c2f0c

Browse files
authored
perf: initialize project data only if uninitialized (#5478)
* perf: initialize project data if needed * refactor: move validation to initializeProjectData * refactor: check initialization in the beginning of initializeProjectData * fix: negate type-o fix
1 parent 2d6683c commit 27c2f0c

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

lib/definitions/project.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ interface IProjectData extends ICreateProjectData {
165165
infoPlistPath: string;
166166
buildXcconfigPath: string;
167167
podfilePath: string;
168+
initialized?: boolean;
168169
/**
169170
* Defines if the project is a code sharing one.
170171
* Value is true when project has nativescript.config and it has `shared: true` in it.

lib/project-data.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export class ProjectData implements IProjectData {
9898
public isShared: boolean;
9999
public previewAppSchema: string;
100100
public webpackConfigPath: string;
101+
public initialized: boolean;
101102

102103
constructor(
103104
private $fs: IFileSystem,
@@ -116,6 +117,9 @@ export class ProjectData implements IProjectData {
116117
}
117118

118119
public initializeProjectData(projectDir?: string): void {
120+
if (this.initialized) {
121+
return;
122+
}
119123
projectDir = projectDir || this.$projectHelper.projectDir;
120124

121125
// If no project found, projectDir should be null
@@ -126,6 +130,7 @@ export class ProjectData implements IProjectData {
126130
const packageJsonContent = this.$fs.readText(projectFilePath);
127131

128132
this.initializeProjectDataFromContent(packageJsonContent, projectDir);
133+
this.initialized = true;
129134
}
130135

131136
return;

lib/services/project-data-service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ export class ProjectDataService implements IProjectDataService {
120120
this.projectDataCache[projectDir] ||
121121
this.$injector.resolve<IProjectData>(ProjectData);
122122
this.projectDataCache[projectDir].initializeProjectData(projectDir);
123-
124123
return this.projectDataCache[projectDir];
125124
}
126125

0 commit comments

Comments
 (0)