Skip to content

fix: remove using of $options for hmr usage #3877

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 2 commits into from
Sep 10, 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: 0 additions & 1 deletion lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ interface IOptions extends ICommonOptions, IBundleString, IPlatformTemplate, IHa
production: boolean; //npm flag
sdk: string;
syncAllFiles: boolean;
liveEdit: boolean;
chrome: boolean;
inspector: boolean; // the counterpart to --chrome
background: string;
Expand Down
26 changes: 12 additions & 14 deletions lib/definitions/livesync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,13 @@ interface IOptionalSkipWatcher {
/**
* Describes a LiveSync operation.
*/
interface ILiveSyncInfo extends IProjectDir, IEnvOptions, IBundle, IRelease, IOptionalSkipWatcher {
interface ILiveSyncInfo extends IProjectDir, IEnvOptions, IBundle, IRelease, IOptionalSkipWatcher, IHasUseHotModuleReloadOption {
/**
* Defines if all project files should be watched for changes. In case it is not passed, only `app` dir of the project will be watched for changes.
* In case it is set to true, the package.json of the project and node_modules directory will also be watched, so any change there will be transferred to device(s).
*/
watchAllFiles?: boolean;

/**
* Defines if the liveEdit functionality should be used, i.e. LiveSync of .js files without restart.
* NOTE: Currently this is available only for iOS.
*/
useLiveEdit?: boolean;

/**
* Forces a build before the initial livesync.
*/
Expand All @@ -167,6 +161,13 @@ interface ILiveSyncInfo extends IProjectDir, IEnvOptions, IBundle, IRelease, IOp
timeout: string;
}

interface IHasUseHotModuleReloadOption {
/**
* Defines if the hot module reload should be used.
*/
useHotModuleReload?: boolean;
}

interface ILatestAppPackageInstalledSettings extends IDictionary<IDictionary<boolean>> { /* empty */ }

interface IIsEmulator {
Expand Down Expand Up @@ -317,28 +318,25 @@ interface IShouldSkipEmitLiveSyncNotification {
interface IAttachDebuggerOptions extends IDebuggingAdditionalOptions, IEnableDebuggingDeviceOptions, IIsEmulator, IPlatform, IOptionalOutputPath {
}

interface ILiveSyncWatchInfo extends IProjectDataComposition {
interface ILiveSyncWatchInfo extends IProjectDataComposition, IHasUseHotModuleReloadOption {
filesToRemove: string[];
filesToSync: string[];
isReinstalled: boolean;
syncAllFiles: boolean;
useLiveEdit?: boolean;
}

interface ILiveSyncResultInfo {
interface ILiveSyncResultInfo extends IHasUseHotModuleReloadOption {
modifiedFilesData: Mobile.ILocalToDevicePathData[];
isFullSync: boolean;
deviceAppData: Mobile.IDeviceAppData;
useLiveEdit?: boolean;
}

interface IAndroidLiveSyncResultInfo extends ILiveSyncResultInfo, IAndroidLivesyncSyncOperationResult { }

interface IFullSyncInfo extends IProjectDataComposition {
interface IFullSyncInfo extends IProjectDataComposition, IHasUseHotModuleReloadOption {
device: Mobile.IDevice;
watch: boolean;
syncAllFiles: boolean;
useLiveEdit?: boolean;
}

interface IPlatformLiveSyncService {
Expand Down Expand Up @@ -434,7 +432,7 @@ interface IAndroidLivesyncTool {
*/
removeFile(filePath: string): Promise<boolean>;
/**
* Removes files
* Removes files
* @param filePaths - Array of files that will be removed.
* @returns {Promise<boolean[]>}
*/
Expand Down
5 changes: 3 additions & 2 deletions lib/helpers/livesync-command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
emulator: d.isEmulator,
projectDir: this.$projectData.projectDir
}),
skipNativePrepare: additionalOptions && additionalOptions.skipNativePrepare
skipNativePrepare: additionalOptions && additionalOptions.skipNativePrepare,
};

return info;
Expand All @@ -116,7 +116,8 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
bundle: !!this.$options.bundle,
release: this.$options.release,
env: this.$options.env,
timeout: this.$options.timeout
timeout: this.$options.timeout,
useHotModuleReload: this.$options.hmr
};

await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
Expand Down
1 change: 0 additions & 1 deletion lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class Options extends commonOptionsLibPath.OptionsBase {
all: { type: OptionType.Boolean },
teamId: { type: OptionType.Object },
syncAllFiles: { type: OptionType.Boolean, default: false },
liveEdit: { type: OptionType.Boolean },
chrome: { type: OptionType.Boolean },
inspector: { type: OptionType.Boolean },
clean: { type: OptionType.Boolean },
Expand Down
7 changes: 3 additions & 4 deletions lib/services/livesync/android-device-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ export class AndroidDeviceLiveSyncService extends DeviceLiveSyncServiceBase impl
private $injector: IInjector,
private $androidProcessService: Mobile.IAndroidProcessService,
protected $platformsData: IPlatformsData,
protected device: Mobile.IAndroidDevice,
protected $options: IOptions) {
super($platformsData, device, $options);
protected device: Mobile.IAndroidDevice) {
super($platformsData, device);
}

public async refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<void> {
Expand All @@ -40,7 +39,7 @@ export class AndroidDeviceLiveSyncService extends DeviceLiveSyncServiceBase impl
const reloadedSuccessfully = await this.reloadApplicationFiles(deviceAppData, localToDevicePaths);

const canExecuteFastSync = reloadedSuccessfully && !liveSyncInfo.isFullSync && !_.some(localToDevicePaths,
(localToDevicePath: Mobile.ILocalToDevicePathData) => !this.canExecuteFastSync(localToDevicePath.getLocalPath(), projectData, this.device.deviceInfo.platform));
(localToDevicePath: Mobile.ILocalToDevicePathData) => !this.canExecuteFastSync(liveSyncInfo, localToDevicePath.getLocalPath(), projectData, this.device.deviceInfo.platform));

if (!canExecuteFastSync) {
return this.restartApplication(deviceAppData, projectData.projectName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
protected $staticConfig: Config.IStaticConfig,
private $logger: ILogger,
protected device: Mobile.IAndroidDevice,
protected $options: IOptions,
private $options: IOptions,
private $processService: IProcessService,
private $fs: IFileSystem,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants) {
super($platformsData, device, $options);
super($platformsData, device);
this.livesyncTool = this.$injector.resolve(AndroidLivesyncTool);
}

Expand Down Expand Up @@ -58,7 +58,7 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
let result = { operationId, didRefresh: true };

if (liveSyncInfo.modifiedFilesData.length) {
const canExecuteFastSync = !liveSyncInfo.isFullSync && this.canExecuteFastSyncForPaths(liveSyncInfo.modifiedFilesData, projectData, this.device.deviceInfo.platform);
const canExecuteFastSync = !liveSyncInfo.isFullSync && this.canExecuteFastSyncForPaths(liveSyncInfo, liveSyncInfo.modifiedFilesData, projectData, this.device.deviceInfo.platform);
const doSyncPromise = this.livesyncTool.sendDoSyncOperation(canExecuteFastSync, null, operationId);

const syncInterval: NodeJS.Timer = setInterval(() => {
Expand Down Expand Up @@ -86,7 +86,7 @@ export class AndroidDeviceSocketsLiveSyncService extends DeviceLiveSyncServiceBa
}

public async refreshApplication(projectData: IProjectData, liveSyncInfo: IAndroidLiveSyncResultInfo) {
const canExecuteFastSync = !liveSyncInfo.isFullSync && this.canExecuteFastSyncForPaths(liveSyncInfo.modifiedFilesData, projectData, this.device.deviceInfo.platform);
const canExecuteFastSync = !liveSyncInfo.isFullSync && this.canExecuteFastSyncForPaths(liveSyncInfo, liveSyncInfo.modifiedFilesData, projectData, this.device.deviceInfo.platform);
if (!canExecuteFastSync || !liveSyncInfo.didRefresh) {
await this.device.applicationManager.restartApplication({ appId: liveSyncInfo.deviceAppData.appIdentifier, projectName: projectData.projectName });
if (!this.$options.justlaunch && this.livesyncTool.protocolVersion && semver.gte(this.livesyncTool.protocolVersion, AndroidDeviceSocketsLiveSyncService.MINIMAL_VERSION_LONG_LIVING_CONNECTION)) {
Expand Down
13 changes: 6 additions & 7 deletions lib/services/livesync/device-livesync-service-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ export abstract class DeviceLiveSyncServiceBase {

constructor(
protected $platformsData: IPlatformsData,
protected device: Mobile.IDevice,
protected $options: IOptions
protected device: Mobile.IDevice
) { }

public canExecuteFastSync(filePath: string, projectData: IProjectData, platform: string): boolean {
public canExecuteFastSync(liveSyncResult: ILiveSyncResultInfo, filePath: string, projectData: IProjectData, platform: string): boolean {
const fastSyncFileExtensions = this.getFastLiveSyncFileExtensions(platform, projectData);
return this.$options.hmr || _.includes(fastSyncFileExtensions, path.extname(filePath));
return liveSyncResult.useHotModuleReload || _.includes(fastSyncFileExtensions, path.extname(filePath));
}

protected canExecuteFastSyncForPaths(localToDevicePaths: Mobile.ILocalToDevicePathData[], projectData: IProjectData, platform: string) {
protected canExecuteFastSyncForPaths(liveSyncResult: ILiveSyncResultInfo, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectData: IProjectData, platform: string) {
return !_.some(localToDevicePaths,
(localToDevicePath: Mobile.ILocalToDevicePathData) =>
!this.canExecuteFastSync(localToDevicePath.getLocalPath(), projectData, this.device.deviceInfo.platform));
!this.canExecuteFastSync(liveSyncResult, localToDevicePath.getLocalPath(), projectData, this.device.deviceInfo.platform));
}

@cache()
Expand All @@ -43,7 +42,7 @@ export abstract class DeviceLiveSyncServiceBase {
public async finalizeSync(liveSyncInfo: ILiveSyncResultInfo, projectData: IProjectData): Promise<IAndroidLivesyncSyncOperationResult> {
//implement in case a sync point for all remove/create operation is needed
return {
didRefresh:true,
didRefresh: true,
operationId: ""
};
}
Expand Down
9 changes: 4 additions & 5 deletions lib/services/livesync/ios-device-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ export class IOSDeviceLiveSyncService extends DeviceLiveSyncServiceBase implemen
private $fs: IFileSystem,
private $processService: IProcessService,
protected $platformsData: IPlatformsData,
protected device: Mobile.IiOSDevice,
protected $options: IOptions) {
super($platformsData, device, $options);
protected device: Mobile.IiOSDevice) {
super($platformsData, device);
}

private async setupSocketIfNeeded(projectData: IProjectData): Promise<boolean> {
Expand Down Expand Up @@ -62,9 +61,9 @@ export class IOSDeviceLiveSyncService extends DeviceLiveSyncServiceBase implemen
constants.LIVESYNC_EXCLUDED_FILE_PATTERNS.forEach(pattern => scriptRelatedFiles = _.concat(scriptRelatedFiles, localToDevicePaths.filter(file => minimatch(file.getDevicePath(), pattern, { nocase: true }))));

const otherFiles = _.difference(localToDevicePaths, _.concat(scriptFiles, scriptRelatedFiles));
const canExecuteFastSync = this.canExecuteFastSyncForPaths(otherFiles, projectData, deviceAppData.platform);
const canExecuteFastSync = this.canExecuteFastSyncForPaths(liveSyncInfo, otherFiles, projectData, deviceAppData.platform);

if (!canExecuteFastSync || (!liveSyncInfo.useLiveEdit && !this.$options.hmr && scriptFiles.length)) {
if (!canExecuteFastSync) {
await this.restartApplication(deviceAppData, projectData.projectName);
return;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/services/livesync/ios-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I
return {
deviceAppData,
isFullSync: true,
modifiedFilesData: []
modifiedFilesData: [],
useHotModuleReload: syncInfo.useHotModuleReload
};
}

Expand Down
4 changes: 2 additions & 2 deletions lib/services/livesync/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
const liveSyncResultInfo = await platformLiveSyncService.fullSync({
projectData, device,
syncAllFiles: liveSyncData.watchAllFiles,
useLiveEdit: liveSyncData.useLiveEdit,
useHotModuleReload: liveSyncData.useHotModuleReload,
watch: !liveSyncData.skipWatcher
});

Expand Down Expand Up @@ -597,7 +597,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
filesToSync: currentFilesToSync,
isReinstalled: appInstalledOnDeviceResult.appInstalled,
syncAllFiles: liveSyncData.watchAllFiles,
useLiveEdit: liveSyncData.useLiveEdit
useHotModuleReload: liveSyncData.useHotModuleReload
};

const liveSyncResultInfo = await service.liveSyncWatchAction(device, settings);
Expand Down
6 changes: 4 additions & 2 deletions lib/services/livesync/platform-livesync-service-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export abstract class PlatformLiveSyncServiceBase {
return {
modifiedFilesData,
isFullSync: true,
deviceAppData
deviceAppData,
useHotModuleReload: syncInfo.useHotModuleReload
};
}

Expand Down Expand Up @@ -107,7 +108,8 @@ export abstract class PlatformLiveSyncServiceBase {
return {
modifiedFilesData: modifiedLocalToDevicePaths,
isFullSync: liveSyncInfo.isReinstalled,
deviceAppData
deviceAppData,
useHotModuleReload: liveSyncInfo.useHotModuleReload
};
}

Expand Down