Skip to content

fix(livesync): delete files during livesync #3388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/definitions/livesync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ interface IProjectDataComposition {
/**
* Desribes object that can be passed to ensureLatestAppPackageIsInstalledOnDevice method.
*/
interface IEnsureLatestAppPackageIsInstalledOnDeviceOptions extends IProjectDataComposition, IEnvOptions, IBundle, IRelease, ISkipNativeCheckOptional {
interface IEnsureLatestAppPackageIsInstalledOnDeviceOptions extends IProjectDataComposition, IEnvOptions, IBundle, IRelease, ISkipNativeCheckOptional, IOptionalFilesToRemove, IOptionalFilesToSync {
device: Mobile.IDevice;
preparedPlatforms: string[];
rebuiltInformation: ILiveSyncBuildInfo[];
Expand Down
12 changes: 10 additions & 2 deletions lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ interface IPlatformDataComposition {
platformData: IPlatformData;
}

interface ICopyAppFilesData extends IProjectDataComposition, IAppFilesUpdaterOptionsComposition, IPlatformDataComposition, IOptionalFilesToSync { }
interface ICopyAppFilesData extends IProjectDataComposition, IAppFilesUpdaterOptionsComposition, IPlatformDataComposition, IOptionalFilesToSync, IOptionalFilesToRemove { }

interface IPreparePlatformService {
addPlatform(info: IAddPlatformInfo): Promise<void>;
Expand Down Expand Up @@ -329,10 +329,18 @@ interface IOptionalFilesToSync {
filesToSync?: string[];
}

interface IPreparePlatformInfoBase extends IPlatform, IAppFilesUpdaterOptionsComposition, IProjectDataComposition, IEnvOptions, IOptionalFilesToSync {
interface IOptionalFilesToRemove {
filesToRemove?: string[];
}

interface IPreparePlatformInfoBase extends IPlatform, IAppFilesUpdaterOptionsComposition, IProjectDataComposition, IEnvOptions, IOptionalFilesToSync, IOptionalFilesToRemove {
nativePrepare?: INativePrepare;
}

interface IDeployPlatformInfo extends IPlatform, IAppFilesUpdaterOptionsComposition, IProjectDataComposition, IPlatformConfig, IEnvOptions {
deployOptions: IDeployPlatformOptions
}

interface IUpdateAppOptions extends IOptionalFilesToSync, IOptionalFilesToRemove {
beforeCopyAction: (sourceFiles: string[]) => void;
}
29 changes: 20 additions & 9 deletions lib/services/app-files-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,31 @@ export class AppFilesUpdater {
) {
}

public updateApp(beforeCopyAction: (sourceFiles: string[]) => void, filesToSync?: string[]): void {
const sourceFiles = filesToSync || this.resolveAppSourceFiles();
public updateApp(updateAppOptions: IUpdateAppOptions): void {
this.cleanDestinationApp(updateAppOptions);
const sourceFiles = updateAppOptions.filesToSync || this.resolveAppSourceFiles();

beforeCopyAction(sourceFiles);
updateAppOptions.beforeCopyAction(sourceFiles);
this.copyAppSourceFiles(sourceFiles);
}

public cleanDestinationApp(): void {
// Delete the destination app in order to prevent EEXIST errors when symlinks are used.
let destinationAppContents = this.readDestinationDir();
destinationAppContents = destinationAppContents.filter(
(directoryName: string) => directoryName !== constants.TNS_MODULES_FOLDER_NAME);
public cleanDestinationApp(updateAppOptions?: IUpdateAppOptions): void {
let itemsToRemove: string[];

_(destinationAppContents).each((directoryItem: string) => {
if (updateAppOptions && updateAppOptions.filesToRemove) {
// We get here during LiveSync - we only want to get rid of files, that the file system watcher detected were deleted
itemsToRemove = updateAppOptions.filesToRemove.map(fileToRemove => path.relative(this.appSourceDirectoryPath, fileToRemove));
} else {
// We get here during the initial sync before the file system watcher is even started
// delete everything and prepare everything anew just to be sure
// Delete the destination app in order to prevent EEXIST errors when symlinks are used.
itemsToRemove = this.readDestinationDir();
itemsToRemove = itemsToRemove.filter(
(directoryName: string) => directoryName !== constants.TNS_MODULES_FOLDER_NAME);

}

_(itemsToRemove).each((directoryItem: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just _.each(...

this.deleteDestinationItem(directoryItem);
});
}
Expand Down
5 changes: 4 additions & 1 deletion lib/services/livesync/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
projectData: options.projectData,
env: options.env,
nativePrepare: nativePrepare,
filesToSync: options.modifiedFiles,
filesToSync: options.filesToSync,
filesToRemove: options.filesToRemove,
platformTemplate: null,
skipModulesNativeCheck: options.skipModulesNativeCheck,
config: platformSpecificOptions
Expand Down Expand Up @@ -568,6 +569,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
deviceBuildInfoDescriptor,
settings: latestAppPackageInstalledSettings,
modifiedFiles: allModifiedFiles,
filesToRemove: currentFilesToRemove,
filesToSync: currentFilesToSync,
bundle: liveSyncData.bundle,
release: liveSyncData.release,
env: liveSyncData.env,
Expand Down
4 changes: 3 additions & 1 deletion lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
platformInfo.env,
changesInfo,
platformInfo.filesToSync,
platformInfo.filesToRemove,
platformInfo.nativePrepare,
);
this.$projectChangesService.savePrepareInfo(platformInfo.platform, platformInfo.projectData);
Expand Down Expand Up @@ -269,7 +270,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {

/* Hooks are expected to use "filesToSync" parameter, as to give plugin authors additional information about the sync process.*/
@helpers.hook('prepare')
private async preparePlatformCore(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, env: Object, changesInfo?: IProjectChangesInfo, filesToSync?: string[], nativePrepare?: INativePrepare): Promise<void> {
private async preparePlatformCore(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, env: Object, changesInfo?: IProjectChangesInfo, filesToSync?: string[], filesToRemove?: string[], nativePrepare?: INativePrepare): Promise<void> {
this.$logger.out("Preparing project...");

const platformData = this.$platformsData.getPlatformData(platform, projectData);
Expand All @@ -283,6 +284,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
platformSpecificData,
changesInfo,
filesToSync,
filesToRemove,
env
});

Expand Down
11 changes: 8 additions & 3 deletions lib/services/prepare-platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ export class PreparePlatformService {
const appSourceDirectoryPath = path.join(copyAppFilesData.projectData.projectDir, constants.APP_FOLDER_NAME);

const appUpdater = new AppFilesUpdater(appSourceDirectoryPath, appDestinationDirectoryPath, copyAppFilesData.appFilesUpdaterOptions, this.$fs);
appUpdater.updateApp(sourceFiles => {
this.$xmlValidator.validateXmlFiles(sourceFiles);
}, copyAppFilesData.filesToSync);
const appUpdaterOptions: IUpdateAppOptions = {
beforeCopyAction: sourceFiles => {
this.$xmlValidator.validateXmlFiles(sourceFiles);
},
filesToSync: copyAppFilesData.filesToSync,
filesToRemove: copyAppFilesData.filesToRemove
};
appUpdater.updateApp(appUpdaterOptions);
}
}