Skip to content

Commit 8856a3c

Browse files
Merge pull request #4802 from NativeScript/vladimirov/fix-run-preview
fix: preview and run do not work correctly
2 parents 49a148f + 33c5192 commit 8856a3c

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

lib/controllers/prepare-controller.ts

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as child_process from "child_process";
21
import * as choki from "chokidar";
32
import { hook } from "../common/helpers";
43
import { performanceLog } from "../common/decorators";
@@ -7,7 +6,7 @@ import * as path from "path";
76
import { PREPARE_READY_EVENT_NAME, WEBPACK_COMPILATION_COMPLETE, PACKAGE_JSON_FILE_NAME, PLATFORMS_DIR_NAME } from "../constants";
87

98
interface IPlatformWatcherData {
10-
webpackCompilerProcess: child_process.ChildProcess;
9+
hasWebpackCompilerProcess: boolean;
1110
nativeFilesWatcher: choki.FSWatcher;
1211
}
1312

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

66-
if (this.watchersData && this.watchersData[projectDir] && this.watchersData[projectDir][platformLowerCase] && this.watchersData[projectDir][platformLowerCase].webpackCompilerProcess) {
65+
if (this.watchersData && this.watchersData[projectDir] && this.watchersData[projectDir][platformLowerCase] && this.watchersData[projectDir][platformLowerCase].hasWebpackCompilerProcess) {
6766
await this.$webpackCompilerService.stopWebpackCompiler(platform);
68-
this.watchersData[projectDir][platformLowerCase].webpackCompilerProcess = null;
67+
this.watchersData[projectDir][platformLowerCase].hasWebpackCompilerProcess = false;
6968
}
7069
}
7170

@@ -78,38 +77,39 @@ export class PrepareController extends EventEmitter {
7877
if (!this.watchersData[projectData.projectDir][platformData.platformNameLowerCase]) {
7978
this.watchersData[projectData.projectDir][platformData.platformNameLowerCase] = {
8079
nativeFilesWatcher: null,
81-
webpackCompilerProcess: null
80+
hasWebpackCompilerProcess: false
8281
};
83-
await this.startJSWatcherWithPrepare(platformData, projectData, prepareData); // -> start watcher + initial compilation
84-
const hasNativeChanges = await this.startNativeWatcherWithPrepare(platformData, projectData, prepareData); // -> start watcher + initial prepare
85-
const result = { platform: platformData.platformNameLowerCase, hasNativeChanges };
82+
}
8683

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

92-
// TODO: Do not persist this in `this` context. Also it should be per platform.
93-
this.isInitialPrepareReady = true;
88+
const hasPersistedDataWithNativeChanges = this.persistedData.find(data => data.platform === result.platform && data.hasNativeChanges);
89+
if (hasPersistedDataWithNativeChanges) {
90+
result.hasNativeChanges = true;
91+
}
9492

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

99-
return result;
96+
if (this.persistedData && this.persistedData.length) {
97+
this.emitPrepareEvent({ files: [], hasOnlyHotUpdateFiles: false, hasNativeChanges: result.hasNativeChanges, hmrData: null, platform: platformData.platformNameLowerCase });
10098
}
99+
100+
return result;
101101
}
102102

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

111-
const childProcess = await this.$webpackCompilerService.compileWithWatch(platformData, projectData, prepareData);
112-
this.watchersData[projectData.projectDir][platformData.platformNameLowerCase].webpackCompilerProcess = childProcess;
111+
this.watchersData[projectData.projectDir][platformData.platformNameLowerCase].hasWebpackCompilerProcess = true;
112+
await this.$webpackCompilerService.compileWithWatch(platformData, projectData, prepareData);
113113
}
114114
}
115115

lib/controllers/preview-app-controller.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ export class PreviewAppController extends EventEmitter implements IPreviewAppCon
7979
this.platformPrepareHandlers[device.platform] = true;
8080

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

8688
}

lib/services/ios-log-filter.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
1313

1414
private partialLine: string = null;
1515

16-
constructor(private $logger: ILogger,
17-
private $loggingLevels: Mobile.ILoggingLevels) {
16+
constructor(private $loggingLevels: Mobile.ILoggingLevels) {
1817
}
1918

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

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

0 commit comments

Comments
 (0)