Skip to content

Commit dd5dc44

Browse files
authored
Merge pull request #3410 from NativeScript/kerezov/rapid-file-changes
fix(livesync): respect rapid file changes
2 parents c640f95 + 47d3e0d commit dd5dc44

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

lib/services/livesync/platform-livesync-service-base.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export abstract class PlatformLiveSyncServiceBase {
5858
const syncInfo = _.merge<IFullSyncInfo>({ device, watch: true }, liveSyncInfo);
5959
const deviceAppData = await this.getAppData(syncInfo);
6060

61-
const modifiedLocalToDevicePaths: Mobile.ILocalToDevicePathData[] = [];
61+
let modifiedLocalToDevicePaths: Mobile.ILocalToDevicePathData[] = [];
6262
if (liveSyncInfo.filesToSync.length) {
6363
const filesToSync = liveSyncInfo.filesToSync;
6464
const mappedFiles = _.map(filesToSync, filePath => this.$projectFilesProvider.mapFilePath(filePath, device.deviceInfo.platform, projectData));
@@ -77,7 +77,7 @@ export abstract class PlatformLiveSyncServiceBase {
7777
const localToDevicePaths = await this.$projectFilesManager.createLocalToDevicePaths(deviceAppData,
7878
projectFilesPath, existingFiles, []);
7979
modifiedLocalToDevicePaths.push(...localToDevicePaths);
80-
await this.transferFiles(deviceAppData, localToDevicePaths, projectFilesPath, false);
80+
modifiedLocalToDevicePaths = await this.transferFiles(deviceAppData, localToDevicePaths, projectFilesPath, false);
8181
}
8282
}
8383

@@ -105,11 +105,11 @@ export abstract class PlatformLiveSyncServiceBase {
105105
}
106106

107107
protected async transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string, isFullSync: boolean): Promise<Mobile.ILocalToDevicePathData[]> {
108-
let transferredFiles = localToDevicePaths;
108+
let transferredFiles: Mobile.ILocalToDevicePathData[] = [];
109109
if (isFullSync) {
110110
transferredFiles = await deviceAppData.device.fileSystem.transferDirectory(deviceAppData, localToDevicePaths, projectFilesPath);
111111
} else {
112-
await deviceAppData.device.fileSystem.transferFiles(deviceAppData, localToDevicePaths);
112+
transferredFiles = await deviceAppData.device.fileSystem.transferFiles(deviceAppData, localToDevicePaths);
113113
}
114114

115115
this.logFilesSyncInformation(transferredFiles, "Successfully transferred %s.", this.$logger.info);

lib/services/prepare-platform-service.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ export class PreparePlatformService {
2626
beforeCopyAction: sourceFiles => {
2727
this.$xmlValidator.validateXmlFiles(sourceFiles);
2828
},
29-
filesToSync: copyAppFilesData.filesToSync,
3029
filesToRemove: copyAppFilesData.filesToRemove
3130
};
31+
// TODO: consider passing filesToSync in appUpdaterOptions
32+
// this would currently lead to the following problem: imagine changing two files rapidly one after the other (transpilation for example)
33+
// the first file would trigger the whole LiveSync process and the second will be queued
34+
// after the first LiveSync is done the .nsprepare file is written and the second file is later on wrongly assumed as having been prepared
35+
// because .nsprepare was written after both file changes
3236
appUpdater.updateApp(appUpdaterOptions, copyAppFilesData.projectData);
3337
}
3438
}

0 commit comments

Comments
 (0)