Skip to content

fix: preview shouldn't start native watch #5016

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
Sep 12, 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
19 changes: 16 additions & 3 deletions lib/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ export class PrepareController extends EventEmitter {
}

private async startNativeWatcherWithPrepare(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<boolean> {
let newNativeWatchStarted = false;
let hasNativeChanges = false;

if (prepareData.watchNative) {
newNativeWatchStarted = await this.startNativeWatcher(platformData, projectData);
}

if (newNativeWatchStarted) {
hasNativeChanges = await this.$prepareNativePlatformService.prepareNativePlatform(platformData, projectData, prepareData);
}

return hasNativeChanges;
}

private async startNativeWatcher(platformData: IPlatformData, projectData: IProjectData): Promise<boolean> {
if (this.watchersData[projectData.projectDir][platformData.platformNameLowerCase].nativeFilesWatcher) {
return false;
}
Expand Down Expand Up @@ -155,9 +170,7 @@ export class PrepareController extends EventEmitter {

this.watchersData[projectData.projectDir][platformData.platformNameLowerCase].nativeFilesWatcher = watcher;

const hasNativeChanges = await this.$prepareNativePlatformService.prepareNativePlatform(platformData, projectData, prepareData);

return hasNativeChanges;
return true;
}

@hook('watchPatterns')
Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/preview-app-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class PreviewAppController extends EventEmitter implements IPreviewAppCon
data.env = data.env || {};
data.env.externals = this.$previewAppPluginsService.getExternalPlugins(device);

const prepareData = this.$prepareDataService.getPrepareData(data.projectDir, device.platform.toLowerCase(), { ...data, nativePrepare: { skipNativePrepare: true }, watch: true });
const prepareData = this.$prepareDataService.getPrepareData(data.projectDir, device.platform.toLowerCase(), { ...data, nativePrepare: { skipNativePrepare: true }, watch: true, watchNative: false });
await this.$prepareController.prepare(prepareData);

try {
Expand Down
4 changes: 4 additions & 0 deletions lib/data/prepare-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export class PrepareData extends ControllerDataBase {
public hmr: boolean;
public env: any;
public watch?: boolean;
public watchNative: boolean = true;

constructor(public projectDir: string, public platform: string, data: any) {
super(projectDir, platform, data);
Expand All @@ -16,6 +17,9 @@ export class PrepareData extends ControllerDataBase {
hmr: data.hmr || data.useHotModuleReload
};
this.watch = data.watch;
if (_.isBoolean(data.watchNative)) {
this.watchNative = data.watchNative;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/definitions/prepare.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare global {
hmr: boolean;
env: any;
watch?: boolean;
watchNative: boolean
}

interface IiOSCodeSigningData {
Expand Down
3 changes: 2 additions & 1 deletion test/controllers/prepare-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const prepareData = {
release: false,
hmr: false,
env: {},
watch: true
watch: true,
watchNative: true
};

let isCompileWithWatchCalled = false;
Expand Down