Skip to content

refactor(livesync): speedup livesync #3362

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 19, 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
1 change: 1 addition & 0 deletions lib/commands/appstore-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class PublishIOS implements ICommand {
const platformInfo: IPreparePlatformInfo = {
platform,
appFilesUpdaterOptions,
skipModulesNativeCheck: !this.$options.syncAllFiles,
platformTemplate: this.$options.platformTemplate,
projectData: this.$projectData,
config: this.$options,
Expand Down
1 change: 1 addition & 0 deletions lib/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class BuildCommandBase extends BundleBase {
const platformInfo: IPreparePlatformInfo = {
platform,
appFilesUpdaterOptions,
skipModulesNativeCheck: !this.$options.syncAllFiles,
platformTemplate: this.$options.platformTemplate,
projectData: this.$projectData,
config: this.$options,
Expand Down
1 change: 1 addition & 0 deletions lib/commands/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class PrepareCommand implements ICommand {
const platformInfo: IPreparePlatformInfo = {
platform: args[0],
appFilesUpdaterOptions,
skipModulesNativeCheck: !this.$options.syncAllFiles,
platformTemplate: this.$options.platformTemplate,
projectData: this.$projectData,
config: this.$options,
Expand Down
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 {
interface IEnsureLatestAppPackageIsInstalledOnDeviceOptions extends IProjectDataComposition, IEnvOptions, IBundle, IRelease, ISkipNativeCheckOptional {
device: Mobile.IDevice;
preparedPlatforms: string[];
rebuiltInformation: ILiveSyncBuildInfo[];
Expand Down
9 changes: 6 additions & 3 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 { }
interface ICopyAppFilesData extends IProjectDataComposition, IAppFilesUpdaterOptionsComposition, IPlatformDataComposition, IOptionalFilesToSync { }

interface IPreparePlatformService {
addPlatform(info: IAddPlatformInfo): Promise<void>;
Expand All @@ -319,14 +319,17 @@ interface IPreparePlatformCoreInfo extends IPreparePlatformInfoBase {
changesInfo?: IProjectChangesInfo;
}

interface IPreparePlatformInfo extends IPreparePlatformInfoBase, IPlatformConfig, IPlatformTemplate { }
interface IPreparePlatformInfo extends IPreparePlatformInfoBase, IPlatformConfig, IPlatformTemplate, ISkipNativeCheckOptional { }

interface IPlatformConfig {
config: IPlatformOptions;
}

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

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

Expand Down
12 changes: 11 additions & 1 deletion lib/definitions/project-changes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ interface IProjectChangesInfo extends IAddedNativePlatform {
readonly changesRequirePrepare: boolean;
}

interface IProjectChangesOptions extends IAppFilesUpdaterOptions, IProvision, ITeamIdentifier {
/**
* Describes interface for controlling checking node_modules for native changes.
*/
interface ISkipNativeCheckOptional {
/**
* Designates node_modules should not be checked for native changes.
*/
skipModulesNativeCheck?: boolean;
}

interface IProjectChangesOptions extends IAppFilesUpdaterOptions, IProvision, ITeamIdentifier, ISkipNativeCheckOptional {
nativePlatformStatus?: "1" | "2" | "3";
}

Expand Down
8 changes: 3 additions & 5 deletions lib/services/app-files-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import * as constants from "../constants";
import * as fs from "fs";

export class AppFilesUpdater {
constructor(
private appSourceDirectoryPath: string,
constructor(private appSourceDirectoryPath: string,
private appDestinationDirectoryPath: string,
public options: IAppFilesUpdaterOptions,
public fs: IFileSystem
) {
}

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

beforeCopyAction(sourceFiles);
this.copyAppSourceFiles(sourceFiles);
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 @@ -370,6 +370,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
nativePrepare: nativePrepare,
filesToSync: options.modifiedFiles,
platformTemplate: null,
skipModulesNativeCheck: options.skipModulesNativeCheck,
config: platformSpecificOptions
};

Expand Down Expand Up @@ -459,6 +460,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
deviceBuildInfoDescriptor,
liveSyncData,
settings,
skipModulesNativeCheck: !liveSyncData.watchAllFiles,
bundle: liveSyncData.bundle,
release: liveSyncData.release,
env: liveSyncData.env
Expand Down Expand Up @@ -568,7 +570,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
modifiedFiles: allModifiedFiles,
bundle: liveSyncData.bundle,
release: liveSyncData.release,
env: liveSyncData.env
env: liveSyncData.env,
skipModulesNativeCheck: !liveSyncData.watchAllFiles
}, { skipNativePrepare: deviceBuildInfoDescriptor.skipNativePrepare });

const service = this.getLiveSyncService(device.deviceInfo.platform);
Expand Down
13 changes: 10 additions & 3 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
public async preparePlatform(platformInfo: IPreparePlatformInfo): Promise<boolean> {
const platformData = this.$platformsData.getPlatformData(platformInfo.platform, platformInfo.projectData);

const changesInfo = await this.initialPrepare(platformInfo.platform, platformData, platformInfo.appFilesUpdaterOptions, platformInfo.platformTemplate, platformInfo.projectData, platformInfo.config, platformInfo.nativePrepare);
const changesInfo = await this.initialPrepare(platformInfo.platform, platformData, platformInfo.appFilesUpdaterOptions, platformInfo.platformTemplate, platformInfo.projectData, platformInfo.config, platformInfo.nativePrepare, platformInfo);
const requiresNativePrepare = (!platformInfo.nativePrepare || !platformInfo.nativePrepare.skipNativePrepare) && changesInfo.nativePlatformStatus === constants.NativePlatformStatus.requiresPrepare;

if (changesInfo.hasChanges || platformInfo.appFilesUpdaterOptions.bundle || requiresNativePrepare) {
Expand Down Expand Up @@ -237,7 +237,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
}
}

private async initialPrepare(platform: string, platformData: IPlatformData, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions, nativePrepare?: INativePrepare): Promise<IProjectChangesInfo> {
private async initialPrepare(platform: string, platformData: IPlatformData, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions, nativePrepare?: INativePrepare, skipNativeCheckOptions?: ISkipNativeCheckOptional): Promise<IProjectChangesInfo> {
this.validatePlatform(platform, projectData);

await this.trackProjectType(projectData);
Expand All @@ -254,7 +254,14 @@ export class PlatformService extends EventEmitter implements IPlatformService {

const bundle = appFilesUpdaterOptions.bundle;
const nativePlatformStatus = (nativePrepare && nativePrepare.skipNativePrepare) ? constants.NativePlatformStatus.requiresPlatformAdd : constants.NativePlatformStatus.requiresPrepare;
const changesInfo = await this.$projectChangesService.checkForChanges(platform, projectData, { bundle, release: appFilesUpdaterOptions.release, provision: config.provision, teamId: config.teamId, nativePlatformStatus });
const changesInfo = await this.$projectChangesService.checkForChanges(platform, projectData, {
bundle,
release: appFilesUpdaterOptions.release,
provision: config.provision,
teamId: config.teamId,
nativePlatformStatus,
skipModulesNativeCheck: skipNativeCheckOptions.skipModulesNativeCheck
});

this.$logger.trace("Changes info in prepare platform:", changesInfo);
return changesInfo;
Expand Down
2 changes: 1 addition & 1 deletion lib/services/prepare-platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export class PreparePlatformService {
const appUpdater = new AppFilesUpdater(appSourceDirectoryPath, appDestinationDirectoryPath, copyAppFilesData.appFilesUpdaterOptions, this.$fs);
appUpdater.updateApp(sourceFiles => {
this.$xmlValidator.validateXmlFiles(sourceFiles);
});
}, copyAppFilesData.filesToSync);
}
}
3 changes: 1 addition & 2 deletions lib/services/project-changes-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ export class ProjectChangesService implements IProjectChangesService {
this._changesInfo.appFilesChanged = this.containsNewerFiles(projectData.appDirectoryPath, projectData.appResourcesDirectoryPath, projectData);
this._changesInfo.packageChanged = this.isProjectFileChanged(projectData, platform);
this._changesInfo.appResourcesChanged = this.containsNewerFiles(projectData.appResourcesDirectoryPath, null, projectData);
/*done because currently all node_modules are traversed, a possible improvement could be traversing only the production dependencies*/
this._changesInfo.nativeChanged = this.containsNewerFiles(
this._changesInfo.nativeChanged = projectChangesOptions.skipModulesNativeCheck ? false : this.containsNewerFiles(
path.join(projectData.projectDir, NODE_MODULES_FOLDER_NAME),
path.join(projectData.projectDir, NODE_MODULES_FOLDER_NAME, "tns-ios-inspector"),
projectData,
Expand Down
2 changes: 2 additions & 0 deletions lib/services/test-execution-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class TestExecutionService implements ITestExecutionService {
const preparePlatformInfo: IPreparePlatformInfo = {
platform,
appFilesUpdaterOptions,
skipModulesNativeCheck: !this.$options.syncAllFiles,
platformTemplate: this.$options.platformTemplate,
projectData,
config: this.$options,
Expand Down Expand Up @@ -187,6 +188,7 @@ class TestExecutionService implements ITestExecutionService {
const preparePlatformInfo: IPreparePlatformInfo = {
platform,
appFilesUpdaterOptions,
skipModulesNativeCheck: !this.$options.syncAllFiles,
platformTemplate: this.$options.platformTemplate,
projectData,
config: this.$options,
Expand Down