Skip to content

Commit 51597bc

Browse files
chore: Add logging in projectChangesService
Add logging in projectChangesService's checkForChanges method in order to know which files are changed. This will help us to understand why prepare is triggered.
1 parent a397430 commit 51597bc

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

lib/services/project-changes-service.ts

+23-4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class ProjectChangesService implements IProjectChangesService {
5454
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
5555
private $fs: IFileSystem,
5656
private $filesHashService: IFilesHashService,
57+
private $logger: ILogger,
5758
private $injector: IInjector) {
5859
}
5960

@@ -83,9 +84,13 @@ export class ProjectChangesService implements IProjectChangesService {
8384
projectData,
8485
this.fileChangeRequiresBuild);
8586

87+
this.$logger.trace(`Set nativeChanged to ${this._changesInfo.nativeChanged}. skipModulesNativeCheck is: ${projectChangesOptions.skipModulesNativeCheck}`);
88+
8689
if (this._newFiles > 0 || this._changesInfo.nativeChanged) {
90+
this.$logger.trace(`Setting modulesChanged to true, newFiles: ${this._newFiles}, nativeChanged: ${this._changesInfo.nativeChanged}`);
8791
this._changesInfo.modulesChanged = true;
8892
}
93+
8994
if (platform === this.$devicePlatformsConstants.iOS.toLowerCase()) {
9095
this._changesInfo.configChanged = this.filesChanged([path.join(platformResourcesDir, platformData.configurationFileName),
9196
path.join(platformResourcesDir, "LaunchScreen.storyboard"),
@@ -97,12 +102,15 @@ export class ProjectChangesService implements IProjectChangesService {
97102
path.join(platformResourcesDir, APP_GRADLE_FILE_NAME)
98103
]);
99104
}
105+
106+
this.$logger.trace(`Set value of configChanged to ${this._changesInfo.configChanged}`);
100107
}
101108

102109
const projectService = platformData.platformProjectService;
103110
await projectService.checkForChanges(this._changesInfo, projectChangesOptions, projectData);
104111

105112
if (projectChangesOptions.bundle !== this._prepareInfo.bundle || projectChangesOptions.release !== this._prepareInfo.release) {
113+
this.$logger.trace(`Setting all setting to true. Current options are: `, projectChangesOptions, " old prepare info is: ", this._prepareInfo);
106114
this._changesInfo.appFilesChanged = true;
107115
this._changesInfo.appResourcesChanged = true;
108116
this._changesInfo.modulesChanged = true;
@@ -112,9 +120,11 @@ export class ProjectChangesService implements IProjectChangesService {
112120
this._prepareInfo.bundle = projectChangesOptions.bundle;
113121
}
114122
if (this._changesInfo.packageChanged) {
123+
this.$logger.trace("Set modulesChanged to true as packageChanged is true");
115124
this._changesInfo.modulesChanged = true;
116125
}
117126
if (this._changesInfo.modulesChanged || this._changesInfo.appResourcesChanged) {
127+
this.$logger.trace(`Set configChanged to true, current value of moduleChanged is: ${this._changesInfo.modulesChanged}, appResourcesChanged is: ${this._changesInfo.appResourcesChanged}`);
118128
this._changesInfo.configChanged = true;
119129
}
120130
if (this._changesInfo.hasChanges) {
@@ -129,6 +139,7 @@ export class ProjectChangesService implements IProjectChangesService {
129139

130140
this._changesInfo.nativePlatformStatus = this._prepareInfo.nativePlatformStatus;
131141

142+
this.$logger.trace("checkForChanges returns", this._changesInfo);
132143
return this._changesInfo;
133144
}
134145

@@ -234,14 +245,16 @@ export class ProjectChangesService implements IProjectChangesService {
234245
}
235246

236247
private containsNewerFiles(dir: string, skipDir: string, projectData: IProjectData, processFunc?: (filePath: string, projectData: IProjectData) => boolean): boolean {
237-
238248
const dirName = path.basename(dir);
249+
this.$logger.trace(`containsNewerFiles will check ${dir}`);
239250
if (_.startsWith(dirName, '.')) {
251+
this.$logger.trace(`containsNewerFiles returns false for ${dir} as its name starts with dot (.) .`);
240252
return false;
241253
}
242254

243255
const dirFileStat = this.$fs.getFsStats(dir);
244256
if (this.isFileModified(dirFileStat, dir)) {
257+
this.$logger.trace(`containsNewerFiles returns true for ${dir} as the dir itself has been modified.`);
245258
return true;
246259
}
247260

@@ -256,24 +269,30 @@ export class ProjectChangesService implements IProjectChangesService {
256269
const changed = this.isFileModified(fileStats, filePath);
257270

258271
if (changed) {
272+
this.$logger.trace(`File ${filePath} has been changed.`);
259273
if (processFunc) {
260274
this._newFiles++;
275+
this.$logger.trace(`Incremented the newFiles counter. Current value is ${this._newFiles}`);
261276
const filePathRelative = path.relative(projectData.projectDir, filePath);
262277
if (processFunc.call(this, filePathRelative, projectData)) {
278+
this.$logger.trace(`containsNewerFiles returns true for ${dir}. The modified file is ${filePath}`);
263279
return true;
264280
}
265281
} else {
282+
this.$logger.trace(`containsNewerFiles returns true for ${dir}. The modified file is ${filePath}`);
266283
return true;
267284
}
268285
}
269286

270287
if (fileStats.isDirectory()) {
271288
if (this.containsNewerFiles(filePath, skipDir, projectData, processFunc)) {
289+
this.$logger.trace(`containsNewerFiles returns true for ${dir}.`);
272290
return true;
273291
}
274292
}
275-
276293
}
294+
295+
this.$logger.trace(`containsNewerFiles returns false for ${dir}.`);
277296
return false;
278297
}
279298

@@ -291,7 +310,7 @@ export class ProjectChangesService implements IProjectChangesService {
291310
}
292311

293312
private fileChangeRequiresBuild(file: string, projectData: IProjectData) {
294-
if (path.basename(file) === "package.json") {
313+
if (path.basename(file) === PACKAGE_JSON_FILE_NAME) {
295314
return true;
296315
}
297316
const projectDir = projectData.projectDir;
@@ -302,7 +321,7 @@ export class ProjectChangesService implements IProjectChangesService {
302321
let filePath = file;
303322
while (filePath !== NODE_MODULES_FOLDER_NAME) {
304323
filePath = path.dirname(filePath);
305-
const fullFilePath = path.join(projectDir, path.join(filePath, "package.json"));
324+
const fullFilePath = path.join(projectDir, path.join(filePath, PACKAGE_JSON_FILE_NAME));
306325
if (this.$fs.exists(fullFilePath)) {
307326
const json = this.$fs.readJson(fullFilePath);
308327
if (json["nativescript"] && _.startsWith(file, path.join(filePath, "platforms"))) {

test/project-changes-service.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { PlatformsData } from "../lib/platforms-data";
66
import { ProjectChangesService } from "../lib/services/project-changes-service";
77
import * as Constants from "../lib/constants";
88
import { FileSystem } from "../lib/common/file-system";
9-
import { HooksServiceStub } from "./stubs";
9+
import { HooksServiceStub, LoggerStub } from "./stubs";
1010

1111
// start tracking temporary folders/files
1212
temp.track();
@@ -34,9 +34,7 @@ class ProjectChangesServiceTest extends BaseServiceTest {
3434
this.injector.register("filesHashService", {
3535
generateHashes: () => Promise.resolve({})
3636
});
37-
this.injector.register("logger", {
38-
warn: () => ({})
39-
});
37+
this.injector.register("logger", LoggerStub);
4038
this.injector.register("hooksService", HooksServiceStub);
4139

4240
const fs = this.injector.resolve<IFileSystem>("fs");

0 commit comments

Comments
 (0)