Skip to content

feat: add --hmr option #3876

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 5 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ interface IOptions extends ICommonOptions, IBundleString, IPlatformTemplate, IHa
chrome: boolean;
inspector: boolean; // the counterpart to --chrome
background: string;
hmr: boolean;
}

interface IEnvOptions {
Expand Down
7 changes: 6 additions & 1 deletion lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export class Options extends commonOptionsLibPath.OptionsBase {
watch: { type: OptionType.Boolean, default: true },
background: { type: OptionType.String },
username: { type: OptionType.String },
pluginName: { type: OptionType.String }
pluginName: { type: OptionType.String },
hmr: {type: OptionType.Boolean}
},
$errors, $staticConfig, $settingsService);

Expand All @@ -50,6 +51,10 @@ export class Options extends commonOptionsLibPath.OptionsBase {
if (that.justlaunch) {
that.watch = false;
}

if (that.hmr) {
that.bundle = "webpack";
}
}
}
$injector.register("options", Options);
5 changes: 3 additions & 2 deletions lib/services/livesync/android-device-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export class AndroidDeviceLiveSyncService extends DeviceLiveSyncServiceBase impl
private $injector: IInjector,
private $androidProcessService: Mobile.IAndroidProcessService,
protected $platformsData: IPlatformsData,
protected device: Mobile.IAndroidDevice) {
super($platformsData, device);
protected device: Mobile.IAndroidDevice,
protected $options: IOptions) {
super($platformsData, device, $options);
}

public async refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<void> {
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,
private $options: ICommonOptions,
protected $options: IOptions,
private $processService: IProcessService,
private $fs: IFileSystem,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants) {
super($platformsData, device);
super($platformsData, device, $options);
this.livesyncTool = this.$injector.resolve(AndroidLivesyncTool);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/services/livesync/device-livesync-service-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ export abstract class DeviceLiveSyncServiceBase {

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

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

protected canExecuteFastSyncForPaths(localToDevicePaths: Mobile.ILocalToDevicePathData[], projectData: IProjectData, platform: string) {
Expand Down
7 changes: 4 additions & 3 deletions lib/services/livesync/ios-device-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ export class IOSDeviceLiveSyncService extends DeviceLiveSyncServiceBase implemen
private $fs: IFileSystem,
private $processService: IProcessService,
protected $platformsData: IPlatformsData,
protected device: Mobile.IiOSDevice) {
super($platformsData, device);
protected device: Mobile.IiOSDevice,
protected $options: IOptions) {
super($platformsData, device, $options);
}

private async setupSocketIfNeeded(projectData: IProjectData): Promise<boolean> {
Expand Down Expand Up @@ -63,7 +64,7 @@ export class IOSDeviceLiveSyncService extends DeviceLiveSyncServiceBase implemen
const otherFiles = _.difference(localToDevicePaths, _.concat(scriptFiles, scriptRelatedFiles));
const canExecuteFastSync = this.canExecuteFastSyncForPaths(otherFiles, projectData, deviceAppData.platform);

if (!canExecuteFastSync || (!liveSyncInfo.useLiveEdit && scriptFiles.length)) {
if (!canExecuteFastSync || (!liveSyncInfo.useLiveEdit && !this.$options.hmr && scriptFiles.length)) {
await this.restartApplication(deviceAppData, projectData.projectName);
return;
}
Expand Down