Skip to content

fix: fix issues with Sidekick, cloud builds and multiple projects/devices #4806

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
Jul 5, 2019
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
6 changes: 1 addition & 5 deletions lib/controllers/build-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,8 @@ export class BuildController extends EventEmitter implements IBuildController {
const projectData = this.$projectDataService.getProjectData(buildData.projectDir);
const platformData = this.$platformsDataService.getPlatformData(buildData.platform, projectData);
const outputPath = buildData.outputPath || platformData.getBuildOutputPath(buildData);

if (buildData.release && this.$projectChangesService.currentChanges.hasChanges) {
return true;
}

const changesInfo = this.$projectChangesService.currentChanges || await this.$projectChangesService.checkForChanges(platformData, projectData, buildData);

if (changesInfo.changesRequireBuild) {
return true;
}
Expand Down
30 changes: 26 additions & 4 deletions lib/controllers/run-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { cache, performanceLog } from "../common/decorators";
import { EventEmitter } from "events";

export class RunController extends EventEmitter implements IRunController {
private prepareReadyEventHandler: any = null;

constructor(
protected $analyticsService: IAnalyticsService,
private $buildController: IBuildController,
Expand All @@ -23,6 +25,7 @@ export class RunController extends EventEmitter implements IRunController {
private $prepareController: IPrepareController,
private $prepareDataService: IPrepareDataService,
private $prepareNativePlatformService: IPrepareNativePlatformService,
private $projectChangesService: IProjectChangesService,
protected $projectDataService: IProjectDataService
) {
super();
Expand All @@ -45,9 +48,21 @@ export class RunController extends EventEmitter implements IRunController {
this.$hmrStatusService.attachToHmrStatusEvent();
}

this.$prepareController.on(PREPARE_READY_EVENT_NAME, async data => {
await this.syncChangedDataOnDevices(data, projectData, liveSyncInfo, deviceDescriptors);
});
if (!this.prepareReadyEventHandler) {
this.prepareReadyEventHandler = async (data: IFilesChangeEventData) => {
if (data.hasNativeChanges) {
const platformData = this.$platformsDataService.getPlatformData(data.platform, projectData);
const prepareData = this.$prepareDataService.getPrepareData(liveSyncInfo.projectDir, data.platform, { ...liveSyncInfo, watch: !liveSyncInfo.skipWatcher });
const changesInfo = await this.$projectChangesService.checkForChanges(platformData, projectData, prepareData);
if (changesInfo.hasChanges) {
await this.syncChangedDataOnDevices(data, projectData, liveSyncInfo);
}
} else {
await this.syncChangedDataOnDevices(data, projectData, liveSyncInfo);
}
};
this.$prepareController.on(PREPARE_READY_EVENT_NAME, this.prepareReadyEventHandler.bind(this));
}

await this.syncInitialDataOnDevices(projectData, liveSyncInfo, deviceDescriptorsForInitialSync);

Expand All @@ -58,6 +73,7 @@ export class RunController extends EventEmitter implements IRunController {
const { projectDir, deviceIdentifiers, stopOptions } = data;
const liveSyncProcessInfo = this.$liveSyncProcessDataService.getPersistedData(projectDir);
if (liveSyncProcessInfo && !liveSyncProcessInfo.isStopped) {

// In case we are coming from error during livesync, the current action is the one that erred (but we are still executing it),
// so we cannot await it as this will cause infinite loop.
const shouldAwaitPendingOperation = !stopOptions || stopOptions.shouldAwaitAllActions;
Expand Down Expand Up @@ -94,6 +110,11 @@ export class RunController extends EventEmitter implements IRunController {

liveSyncProcessInfo.deviceDescriptors = [];

if (this.prepareReadyEventHandler) {
this.removeListener(PREPARE_READY_EVENT_NAME, this.prepareReadyEventHandler);
this.prepareReadyEventHandler = null;
}

const projectData = this.$projectDataService.getProjectData(projectDir);
await this.$hooksService.executeAfterHooks('watch', {
hookArgs: {
Expand Down Expand Up @@ -313,10 +334,11 @@ export class RunController extends EventEmitter implements IRunController {
await this.addActionToChain(projectData.projectDir, () => this.$devicesService.execute(deviceAction, (device: Mobile.IDevice) => _.some(deviceDescriptors, deviceDescriptor => deviceDescriptor.identifier === device.deviceInfo.identifier)));
}

private async syncChangedDataOnDevices(data: IFilesChangeEventData, projectData: IProjectData, liveSyncInfo: ILiveSyncInfo, deviceDescriptors: ILiveSyncDeviceDescriptor[]): Promise<void> {
private async syncChangedDataOnDevices(data: IFilesChangeEventData, projectData: IProjectData, liveSyncInfo: ILiveSyncInfo): Promise<void> {
const rebuiltInformation: IDictionary<{ packageFilePath: string, platform: string, isEmulator: boolean }> = { };

const deviceAction = async (device: Mobile.IDevice) => {
const deviceDescriptors = this.$liveSyncProcessDataService.getDeviceDescriptors(projectData.projectDir);
const deviceDescriptor = _.find(deviceDescriptors, dd => dd.identifier === device.deviceInfo.identifier);
const platformData = this.$platformsDataService.getPlatformData(data.platform, projectData);
const prepareData = this.$prepareDataService.getPrepareData(liveSyncInfo.projectDir, device.deviceInfo.platform,
Expand Down
5 changes: 2 additions & 3 deletions lib/services/platform/prepare-native-platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ export class PrepareNativePlatformService implements IPrepareNativePlatformServi
@hook('prepareNativeApp')
public async prepareNativePlatform(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<boolean> {
const { nativePrepare, release } = prepareData;
const changesInfo = await this.$projectChangesService.checkForChanges(platformData, projectData, prepareData);
if (nativePrepare && nativePrepare.skipNativePrepare) {
return false;
return changesInfo.hasChanges;
}

const changesInfo = await this.$projectChangesService.checkForChanges(platformData, projectData, prepareData);

const hasNativeModulesChange = !changesInfo || changesInfo.nativeChanged;
const hasConfigChange = !changesInfo || changesInfo.configChanged;
const hasChangesRequirePrepare = !changesInfo || changesInfo.changesRequirePrepare;
Expand Down