Skip to content

Commit 1daa7aa

Browse files
authored
Merge pull request #5016 from NativeScript/kddimitrov/fix-preview-watches-native-changes
fix: preview shouldn't start native watch
2 parents 119f663 + 984468d commit 1daa7aa

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

lib/controllers/prepare-controller.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,21 @@ export class PrepareController extends EventEmitter {
127127
}
128128

129129
private async startNativeWatcherWithPrepare(platformData: IPlatformData, projectData: IProjectData, prepareData: IPrepareData): Promise<boolean> {
130+
let newNativeWatchStarted = false;
131+
let hasNativeChanges = false;
132+
133+
if (prepareData.watchNative) {
134+
newNativeWatchStarted = await this.startNativeWatcher(platformData, projectData);
135+
}
136+
137+
if (newNativeWatchStarted) {
138+
hasNativeChanges = await this.$prepareNativePlatformService.prepareNativePlatform(platformData, projectData, prepareData);
139+
}
140+
141+
return hasNativeChanges;
142+
}
143+
144+
private async startNativeWatcher(platformData: IPlatformData, projectData: IProjectData): Promise<boolean> {
130145
if (this.watchersData[projectData.projectDir][platformData.platformNameLowerCase].nativeFilesWatcher) {
131146
return false;
132147
}
@@ -155,9 +170,7 @@ export class PrepareController extends EventEmitter {
155170

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

158-
const hasNativeChanges = await this.$prepareNativePlatformService.prepareNativePlatform(platformData, projectData, prepareData);
159-
160-
return hasNativeChanges;
173+
return true;
161174
}
162175

163176
@hook('watchPatterns')

lib/controllers/preview-app-controller.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class PreviewAppController extends EventEmitter implements IPreviewAppCon
9999
data.env = data.env || {};
100100
data.env.externals = this.$previewAppPluginsService.getExternalPlugins(device);
101101

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

105105
try {

lib/data/prepare-data.ts

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export class PrepareData extends ControllerDataBase {
55
public hmr: boolean;
66
public env: any;
77
public watch?: boolean;
8+
public watchNative: boolean = true;
89

910
constructor(public projectDir: string, public platform: string, data: any) {
1011
super(projectDir, platform, data);
@@ -16,6 +17,9 @@ export class PrepareData extends ControllerDataBase {
1617
hmr: data.hmr || data.useHotModuleReload
1718
};
1819
this.watch = data.watch;
20+
if (_.isBoolean(data.watchNative)) {
21+
this.watchNative = data.watchNative;
22+
}
1923
}
2024
}
2125

lib/definitions/prepare.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ declare global {
77
hmr: boolean;
88
env: any;
99
watch?: boolean;
10+
watchNative: boolean
1011
}
1112

1213
interface IiOSCodeSigningData {

test/controllers/prepare-controller.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const prepareData = {
99
release: false,
1010
hmr: false,
1111
env: {},
12-
watch: true
12+
watch: true,
13+
watchNative: true
1314
};
1415

1516
let isCompileWithWatchCalled = false;

0 commit comments

Comments
 (0)