Skip to content

fix: preview and run do not work correctly #4802

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
Jul 4, 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
42 changes: 21 additions & 21 deletions lib/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as child_process from "child_process";
import * as choki from "chokidar";
import { hook } from "../common/helpers";
import { performanceLog } from "../common/decorators";
Expand All @@ -7,7 +6,7 @@ import * as path from "path";
import { PREPARE_READY_EVENT_NAME, WEBPACK_COMPILATION_COMPLETE, PACKAGE_JSON_FILE_NAME, PLATFORMS_DIR_NAME } from "../constants";

interface IPlatformWatcherData {
webpackCompilerProcess: child_process.ChildProcess;
hasWebpackCompilerProcess: boolean;
nativeFilesWatcher: choki.FSWatcher;
}

Expand Down Expand Up @@ -63,9 +62,9 @@ export class PrepareController extends EventEmitter {
this.watchersData[projectDir][platformLowerCase].nativeFilesWatcher = null;
}

if (this.watchersData && this.watchersData[projectDir] && this.watchersData[projectDir][platformLowerCase] && this.watchersData[projectDir][platformLowerCase].webpackCompilerProcess) {
if (this.watchersData && this.watchersData[projectDir] && this.watchersData[projectDir][platformLowerCase] && this.watchersData[projectDir][platformLowerCase].hasWebpackCompilerProcess) {
await this.$webpackCompilerService.stopWebpackCompiler(platform);
this.watchersData[projectDir][platformLowerCase].webpackCompilerProcess = null;
this.watchersData[projectDir][platformLowerCase].hasWebpackCompilerProcess = false;
}
}

Expand All @@ -78,38 +77,39 @@ export class PrepareController extends EventEmitter {
if (!this.watchersData[projectData.projectDir][platformData.platformNameLowerCase]) {
this.watchersData[projectData.projectDir][platformData.platformNameLowerCase] = {
nativeFilesWatcher: null,
webpackCompilerProcess: null
hasWebpackCompilerProcess: false
};
await this.startJSWatcherWithPrepare(platformData, projectData, prepareData); // -> start watcher + initial compilation
const hasNativeChanges = await this.startNativeWatcherWithPrepare(platformData, projectData, prepareData); // -> start watcher + initial prepare
const result = { platform: platformData.platformNameLowerCase, hasNativeChanges };
}

const hasPersistedDataWithNativeChanges = this.persistedData.find(data => data.platform === result.platform && data.hasNativeChanges);
if (hasPersistedDataWithNativeChanges) {
result.hasNativeChanges = true;
}
await this.startJSWatcherWithPrepare(platformData, projectData, prepareData); // -> start watcher + initial compilation
const hasNativeChanges = await this.startNativeWatcherWithPrepare(platformData, projectData, prepareData); // -> start watcher + initial prepare
const result = { platform: platformData.platformNameLowerCase, hasNativeChanges };

// TODO: Do not persist this in `this` context. Also it should be per platform.
this.isInitialPrepareReady = true;
const hasPersistedDataWithNativeChanges = this.persistedData.find(data => data.platform === result.platform && data.hasNativeChanges);
if (hasPersistedDataWithNativeChanges) {
result.hasNativeChanges = true;
}

if (this.persistedData && this.persistedData.length) {
this.emitPrepareEvent({ files: [], hasOnlyHotUpdateFiles: false, hasNativeChanges: result.hasNativeChanges, hmrData: null, platform: platformData.platformNameLowerCase });
}
// TODO: Do not persist this in `this` context. Also it should be per platform.
this.isInitialPrepareReady = true;

return result;
if (this.persistedData && this.persistedData.length) {
this.emitPrepareEvent({ files: [], hasOnlyHotUpdateFiles: false, hasNativeChanges: result.hasNativeChanges, hmrData: null, platform: platformData.platformNameLowerCase });
}

return result;
}

private async startJSWatcherWithPrepare(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<void> {
if (!this.watchersData[projectData.projectDir][platformData.platformNameLowerCase].webpackCompilerProcess) {
if (!this.watchersData[projectData.projectDir][platformData.platformNameLowerCase].hasWebpackCompilerProcess) {
this.$webpackCompilerService.on(WEBPACK_COMPILATION_COMPLETE, data => {
if (data.platform.toLowerCase() === platformData.platformNameLowerCase) {
this.emitPrepareEvent({ ...data, hasNativeChanges: false });
}
});

const childProcess = await this.$webpackCompilerService.compileWithWatch(platformData, projectData, prepareData);
this.watchersData[projectData.projectDir][platformData.platformNameLowerCase].webpackCompilerProcess = childProcess;
this.watchersData[projectData.projectDir][platformData.platformNameLowerCase].hasWebpackCompilerProcess = true;
await this.$webpackCompilerService.compileWithWatch(platformData, projectData, prepareData);
}
}

Expand Down
6 changes: 4 additions & 2 deletions lib/controllers/preview-app-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ export class PreviewAppController extends EventEmitter implements IPreviewAppCon
this.platformPrepareHandlers[device.platform] = true;

// TODO: Remove the handler once the preview operation for this platform is stopped
this.$prepareController.on(PREPARE_READY_EVENT_NAME, async currentPrepareData => {
await this.handlePrepareReadyEvent(data, currentPrepareData.hmrData, currentPrepareData.files, device.platform);
this.$prepareController.on(PREPARE_READY_EVENT_NAME, async (currentPrepareData: IFilesChangeEventData) => {
if (currentPrepareData.platform.toLowerCase() === device.platform.toLowerCase()) {
await this.handlePrepareReadyEvent(data, currentPrepareData.hmrData, currentPrepareData.files, device.platform);
}
});

}
Expand Down
4 changes: 1 addition & 3 deletions lib/services/ios-log-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {

private partialLine: string = null;

constructor(private $logger: ILogger,
private $loggingLevels: Mobile.ILoggingLevels) {
constructor(private $loggingLevels: Mobile.ILoggingLevels) {
}

public filterData(data: string, loggingOptions: Mobile.IDeviceLogOptions = <any>{}): string {
const specifiedLogLevel = (loggingOptions.logLevel || '').toUpperCase();
this.$logger.trace("Logging options", loggingOptions);

if (specifiedLogLevel !== this.$loggingLevels.info || !data) {
return data;
Expand Down