Skip to content

fix: get correct hmr hash when more than one webpacks are started #4021

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
Oct 12, 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/hmr-status-service.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface IHmrStatusService {
getHmrStatus(deviceId: string, operationHash: string): Promise<number>;
attachToHrmStatusEvent(): void;
attachToHmrStatusEvent(): void;
}
7 changes: 6 additions & 1 deletion lib/definitions/livesync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ interface ILiveSyncWatchInfo extends IProjectDataComposition, IHasUseHotModuleRe
isReinstalled: boolean;
syncAllFiles: boolean;
liveSyncDeviceInfo: ILiveSyncDeviceInfo;
hmrData: { hash: string; fallbackFiles: IDictionary<string[]> };
hmrData: IPlatformHmrData;
force?: boolean;
}

Expand All @@ -377,6 +377,11 @@ interface IFullSyncInfo extends IProjectDataComposition, IHasUseHotModuleReloadO
force?: boolean;
}

interface IPlatformHmrData {
hash: string;
fallbackFiles: string[];
}

interface ITransferFilesOptions {
isFullSync: boolean;
force?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions lib/services/hmr-status-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class HmrStatusService implements IHmrStatusService {
}

@cache()
public attachToHrmStatusEvent(): void {
public attachToHmrStatusEvent(): void {
this.$logParserService.addParseRule({
regex: HmrStatusService.HMR_STATUS_LOG_REGEX,
handler: this.handleHmrStatusFound.bind(this),
Expand Down Expand Up @@ -62,7 +62,7 @@ export class HmrStatusService implements IHmrStatusService {
}
}

this.$logger.trace("Found hmr status.", {status, hash});
this.$logger.trace("Found hmr status.", { status, hash });

if (status) {
this.setData(status, hash, deviceId);
Expand Down
2 changes: 1 addition & 1 deletion lib/services/livesync/android-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class AndroidLiveSyncService extends PlatformLiveSyncServiceBase implemen
// This is the case when the app has crashed and is in ErrorActivity.
// As the app might not have time to apply the patches, we will send the whole bundle.js(fallbackFiles)
if (liveSyncInfo.useHotModuleReload && !result.didRefresh && liveSyncInfo.hmrData && liveSyncInfo.hmrData.hash) {
liveSyncInfo.filesToSync = liveSyncInfo.hmrData.fallbackFiles[device.deviceInfo.platform];
liveSyncInfo.filesToSync = liveSyncInfo.hmrData.fallbackFiles;
result = await this.liveSyncWatchActionCore(device, liveSyncInfo);
result.didRecover = true;
}
Expand Down
19 changes: 8 additions & 11 deletions lib/services/livesync/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
const patterns = await this.getWatcherPatterns(liveSyncData, projectData, platforms);

if (liveSyncData.useHotModuleReload) {
this.$hmrStatusService.attachToHrmStatusEvent();
this.$hmrStatusService.attachToHmrStatusEvent();
}

if (liveSyncData.watchAllFiles) {
Expand All @@ -586,10 +586,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
}

let filesToSync: string[] = [];
const hmrData: { hash: string; fallbackFiles: IDictionary<string[]> } = {
hash: "",
fallbackFiles: {}
};
const hmrData: IDictionary<IPlatformHmrData> = {};
const filesToSyncMap: IDictionary<string[]> = {};
let filesToRemove: string[] = [];
let timeoutTimer: NodeJS.Timer;
Expand Down Expand Up @@ -635,6 +632,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
await this.$devicesService.execute(async (device: Mobile.IDevice) => {
const liveSyncProcessInfo = this.liveSyncProcessesInfo[projectData.projectDir];
const deviceBuildInfoDescriptor = _.find(liveSyncProcessInfo.deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);
const platformHmrData = (currentHmrData && currentHmrData[device.deviceInfo.platform]) || <any>{};

const settings: ILiveSyncWatchInfo = {
liveSyncDeviceInfo: deviceBuildInfoDescriptor,
Expand All @@ -643,7 +641,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
filesToSync: currentFilesToSync,
isReinstalled: false,
syncAllFiles: liveSyncData.watchAllFiles,
hmrData: currentHmrData,
hmrData: platformHmrData,
useHotModuleReload: liveSyncData.useHotModuleReload,
force: liveSyncData.force,
connectTimeout: 1000
Expand All @@ -657,10 +655,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
await this.refreshApplication(projectData, liveSyncResultInfo, deviceBuildInfoDescriptor.debugOptions, deviceBuildInfoDescriptor.outputPath);

// If didRecover is true, this means we were in ErrorActivity and fallback files were already transfered and app will be restarted.
if (!liveSyncResultInfo.didRecover && liveSyncData.useHotModuleReload && currentHmrData.hash) {
const status = await this.$hmrStatusService.getHmrStatus(device.deviceInfo.identifier, currentHmrData.hash);
if (!liveSyncResultInfo.didRecover && liveSyncData.useHotModuleReload && platformHmrData.hash) {
const status = await this.$hmrStatusService.getHmrStatus(device.deviceInfo.identifier, platformHmrData.hash);
if (status === HmrConstants.HMR_ERROR_STATUS) {
watchInfo.filesToSync = currentHmrData.fallbackFiles[device.deviceInfo.platform];
watchInfo.filesToSync = platformHmrData.fallbackFiles;
liveSyncResultInfo = await service.liveSyncWatchAction(device, watchInfo);
// We want to force a restart of the application.
liveSyncResultInfo.isFullSync = true;
Expand Down Expand Up @@ -703,8 +701,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
settings.connectTimeout = null;

if (liveSyncData.useHotModuleReload && appInstalledOnDeviceResult.appInstalled) {
const additionalFilesToSync = currentHmrData && currentHmrData.fallbackFiles && currentHmrData.fallbackFiles[device.deviceInfo.platform];
_.each(additionalFilesToSync, fileToSync => currentFilesToSync.push(fileToSync));
_.each(platformHmrData.fallbackFiles, fileToSync => currentFilesToSync.push(fileToSync));
}

await watchAction(settings);
Expand Down
12 changes: 5 additions & 7 deletions lib/services/livesync/playground/preview-app-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,25 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {

private async initializePreviewForDevice(data: IPreviewAppLiveSyncData, device: Device): Promise<FilesPayload> {
const filesToSyncMap: IDictionary<string[]> = {};
const hmrData: { hash: string; fallbackFiles: IDictionary<string[]> } = {
hash: "",
fallbackFiles: {}
};
const hmrData: IDictionary<IPlatformHmrData> = {};
let promise = Promise.resolve<FilesPayload>(null);
const startSyncFilesTimeout = async (platform: string) => {
await promise
.then(async () => {
const currentHmrData = _.cloneDeep(hmrData);
const platformHmrData = currentHmrData[platform] || <any>{};
const filesToSync = _.cloneDeep(filesToSyncMap[platform]);
// We don't need to prepare when webpack emits changed files. We just need to send a message to pubnub.
promise = this.syncFilesForPlatformSafe(data, platform, { filesToSync, skipPrepare: true, useHotModuleReload: data.appFilesUpdaterOptions.useHotModuleReload });
await promise;

if (data.appFilesUpdaterOptions.useHotModuleReload && currentHmrData.hash) {
if (data.appFilesUpdaterOptions.useHotModuleReload && platformHmrData.hash) {
const devices = _.filter(this.$previewSdkService.connectedDevices, { platform: platform.toLowerCase() });

await Promise.all(_.map(devices, async (previewDevice: Device) => {
const status = await this.$hmrStatusService.getHmrStatus(previewDevice.id, currentHmrData.hash);
const status = await this.$hmrStatusService.getHmrStatus(previewDevice.id, platformHmrData.hash);
if (status === HmrConstants.HMR_ERROR_STATUS) {
await this.syncFilesForPlatformSafe(data, platform, { filesToSync: currentHmrData.fallbackFiles[platform], useHotModuleReload: false, deviceId: previewDevice.id });
await this.syncFilesForPlatformSafe(data, platform, { filesToSync: platformHmrData.fallbackFiles, useHotModuleReload: false, deviceId: previewDevice.id });
}
}));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/services/log-parser-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class LogParserService extends EventEmitter implements ILogParserService
private processDeviceLogResponse(message: string, deviceIdentifier: string, devicePlatform: string) {
const lines = message.split("\n");
_.forEach(lines, line => {
_.forEach(this.parseRules, (parseRule) => {
_.forEach(this.parseRules, parseRule => {
if (!devicePlatform || !parseRule.platform || parseRule.platform.toLowerCase() === devicePlatform.toLowerCase()) {
const matches = parseRule.regex.exec(line);

Expand Down