Skip to content

Commit 1f46ca1

Browse files
authored
make livesync work with renamed files and folders (#3042)
* added special check for file changes on Mac * fix missing imports in tests * add dir check, modified file check * check isDirModified before anything else to save time * updates after review * bring back check for symlinks * add check for modification in bot files and folders * fixed lint
1 parent 4d5bcfb commit 1f46ca1

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

lib/services/project-changes-service.ts

+22-7
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export class ProjectChangesService implements IProjectChangesService {
6868
path.join(projectData.projectDir, NODE_MODULES_FOLDER_NAME, "tns-ios-inspector"),
6969
projectData,
7070
this.fileChangeRequiresBuild);
71+
7172
if (this._newFiles > 0) {
7273
this._changesInfo.modulesChanged = true;
7374
}
@@ -218,20 +219,20 @@ export class ProjectChangesService implements IProjectChangesService {
218219
}
219220

220221
private containsNewerFiles(dir: string, skipDir: string, projectData: IProjectData, processFunc?: (filePath: string, projectData: IProjectData) => boolean): boolean {
222+
const dirFileStat = this.$fs.getFsStats(dir);
223+
if (this.isFileModified(dirFileStat, dir)) {
224+
return true;
225+
}
226+
221227
let files = this.$fs.readDirectory(dir);
222228
for (let file of files) {
223229
let filePath = path.join(dir, file);
224230
if (filePath === skipDir) {
225231
continue;
226232
}
227233

228-
let fileStats = this.$fs.getFsStats(filePath);
229-
230-
let changed = fileStats.mtime.getTime() >= this._outputProjectMtime || fileStats.ctime.getTime() >= this._outputProjectCTime;
231-
if (!changed) {
232-
let lFileStats = this.$fs.getLsStats(filePath);
233-
changed = lFileStats.mtime.getTime() >= this._outputProjectMtime || lFileStats.ctime.getTime() >= this._outputProjectCTime;
234-
}
234+
const fileStats = this.$fs.getFsStats(filePath);
235+
let changed = this.isFileModified(fileStats, filePath);
235236

236237
if (changed) {
237238
if (processFunc) {
@@ -250,10 +251,24 @@ export class ProjectChangesService implements IProjectChangesService {
250251
return true;
251252
}
252253
}
254+
253255
}
254256
return false;
255257
}
256258

259+
private isFileModified(filePathStat: IFsStats, filePath: string): boolean {
260+
let changed = filePathStat.mtime.getTime() >= this._outputProjectMtime ||
261+
filePathStat.ctime.getTime() >= this._outputProjectCTime;
262+
263+
if (!changed) {
264+
let lFileStats = this.$fs.getLsStats(filePath);
265+
changed = lFileStats.mtime.getTime() >= this._outputProjectMtime ||
266+
lFileStats.ctime.getTime() >= this._outputProjectCTime;
267+
}
268+
269+
return changed;
270+
}
271+
257272
private fileChangeRequiresBuild(file: string, projectData: IProjectData) {
258273
if (path.basename(file) === "package.json") {
259274
return true;

test/project-changes-service.ts

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class ProjectChangesServiceTest extends BaseServiceTest {
2626
this.injector.register("platformsData", PlatformsData);
2727
this.injector.register("androidProjectService", {});
2828
this.injector.register("iOSProjectService", {});
29-
3029
this.injector.register("fs", FileSystem);
3130
this.injector.register("devicePlatformsConstants", {});
3231
this.injector.register("devicePlatformsConstants", {});

0 commit comments

Comments
 (0)