Skip to content

Commit 2abae5f

Browse files
author
Dimitar Tachev
authored
Merge pull request #3907 from NativeScript/tachev/preview-hmr
Pass the HMR option to the hooks and preview URL
2 parents 3c77d2a + c2a47b9 commit 2abae5f

25 files changed

+178
-47
lines changed

lib/commands/appstore-upload.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ export class PublishIOS implements ICommand {
5656
if (!ipaFilePath) {
5757
const platform = this.$devicePlatformsConstants.iOS;
5858
// No .ipa path provided, build .ipa on out own.
59-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
59+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
60+
bundle: !!this.$options.bundle,
61+
release: this.$options.release,
62+
useHotModuleReload: false
63+
};
6064
const platformInfo: IPreparePlatformInfo = {
6165
platform,
6266
appFilesUpdaterOptions,

lib/commands/build.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
1515

1616
public async executeCore(args: string[]): Promise<void> {
1717
const platform = args[0].toLowerCase();
18-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
18+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
19+
bundle: !!this.$options.bundle,
20+
release: this.$options.release,
21+
useHotModuleReload: this.$options.hmr
22+
};
1923
const platformInfo: IPreparePlatformInfo = {
2024
platform,
2125
appFilesUpdaterOptions,

lib/commands/clean-app.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ export class CleanAppCommandBase extends ValidatePlatformCommandBase implements
1616
}
1717

1818
public async execute(args: string[]): Promise<void> {
19-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
19+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
20+
bundle: !!this.$options.bundle,
21+
release: this.$options.release,
22+
useHotModuleReload: false
23+
};
2024
const platformInfo: IPreparePlatformInfo = {
2125
appFilesUpdaterOptions,
2226
platform: this.platform.toLowerCase(),

lib/commands/prepare.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
1313
}
1414

1515
public async execute(args: string[]): Promise<void> {
16-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
16+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
17+
bundle: !!this.$options.bundle,
18+
release: this.$options.release,
19+
useHotModuleReload: this.$options.hmr
20+
};
1721
const platformInfo: IPreparePlatformInfo = {
1822
platform: args[0],
1923
appFilesUpdaterOptions,

lib/commands/preview.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ export class PreviewCommand implements ICommand {
2121
bundle: !!this.$options.bundle,
2222
release: this.$options.release,
2323
env: this.$options.env,
24-
timeout: this.$options.timeout
24+
timeout: this.$options.timeout,
25+
useHotModuleReload: this.$options.hmr
2526
});
2627

27-
await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp();
28+
await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp({ useHotModuleReload: this.$options.hmr });
2829
}
2930

3031
public async canExecute(args: string[]): Promise<boolean> {

lib/declarations.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ interface IEnvOptions {
486486

487487
interface IAndroidBuildOptionsSettings extends IAndroidReleaseOptions, IRelease { }
488488

489-
interface IAppFilesUpdaterOptions extends IBundle, IRelease, IOptionalWatchAllFiles { }
489+
interface IAppFilesUpdaterOptions extends IBundle, IRelease, IOptionalWatchAllFiles, IHasUseHotModuleReloadOption { }
490490

491491
interface IPlatformBuildData extends IAppFilesUpdaterOptions, IBuildConfig, IEnvOptions { }
492492

lib/definitions/livesync.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ interface IHasUseHotModuleReloadOption {
180180
/**
181181
* Defines if the hot module reload should be used.
182182
*/
183-
useHotModuleReload?: boolean;
183+
useHotModuleReload: boolean;
184184
}
185185

186186
interface ILatestAppPackageInstalledSettings extends IDictionary<IDictionary<boolean>> { /* empty */ }

lib/definitions/preview-app-livesync.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare global {
1010
interface IPreviewAppLiveSyncData extends IProjectDir, IAppFilesUpdaterOptionsComposition, IEnvOptions { }
1111

1212
interface IPreviewSdkService {
13-
qrCodeUrl: string;
13+
getQrCodeUrl(options: IHasUseHotModuleReloadOption): string;
1414
connectedDevices: Device[];
1515
initialize(getInitialFiles: (device: Device) => Promise<FilesPayload>): void;
1616
applyChanges(filesPayload: FilesPayload): Promise<void>;
@@ -29,6 +29,6 @@ declare global {
2929
interface IPlaygroundQrCodeGenerator {
3030
generateQrCodeForiOS(): Promise<void>;
3131
generateQrCodeForAndroid(): Promise<void>;
32-
generateQrCodeForCurrentApp(): Promise<void>;
32+
generateQrCodeForCurrentApp(options: IHasUseHotModuleReloadOption): Promise<void>;
3333
}
3434
}

lib/helpers/deploy-command-helper.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ export class DeployCommandHelper implements IDeployCommandHelper {
77
}
88

99
public getDeployPlatformInfo(platform: string): IDeployPlatformInfo {
10-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
10+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
11+
bundle: !!this.$options.bundle,
12+
release: this.$options.release,
13+
useHotModuleReload: this.$options.hmr
14+
};
1115
const deployOptions: IDeployPlatformOptions = {
1216
clean: this.$options.clean,
1317
device: this.$options.device,

lib/helpers/livesync-command-helper.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
156156
platform: currentPlatform,
157157
appFilesUpdaterOptions: {
158158
bundle: !!this.$options.bundle,
159-
release: this.$options.release
159+
release: this.$options.release,
160+
useHotModuleReload: this.$options.hmr
160161
},
161162
deployOptions,
162163
buildPlatform: this.$platformService.buildPlatform.bind(this.$platformService),

lib/helpers/preview-command-helper.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export class PreviewCommandHelper implements IPreviewCommandHelper {
66
private ctrlcReader: readline.ReadLine;
77

88
constructor(private $playgroundQrCodeGenerator: IPlaygroundQrCodeGenerator,
9+
private $options: IOptions,
910
private $processService: IProcessService) {
1011
this.$processService.attachToProcessExitSignals(this, () => {
1112
this.stopWaitingForCommand();
@@ -49,7 +50,7 @@ export class PreviewCommandHelper implements IPreviewCommandHelper {
4950
await this.$playgroundQrCodeGenerator.generateQrCodeForiOS();
5051
return;
5152
case "c":
52-
await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp();
53+
await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp({ useHotModuleReload: this.$options.hmr });
5354
return;
5455
}
5556
}

lib/services/livesync/ios-livesync-service.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I
1414
$logger: ILogger,
1515
$projectFilesProvider: IProjectFilesProvider,
1616
private $iOSDebuggerPortService: IIOSDebuggerPortService) {
17-
super($fs, $logger, $platformsData, $projectFilesManager, $devicePathProvider, $projectFilesProvider);
18-
}
17+
super($fs, $logger, $platformsData, $projectFilesManager, $devicePathProvider, $projectFilesProvider);
18+
}
1919

2020
public async fullSync(syncInfo: IFullSyncInfo): Promise<ILiveSyncResultInfo> {
2121
const device = syncInfo.device;
@@ -60,7 +60,13 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I
6060
public liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<ILiveSyncResultInfo> {
6161
if (liveSyncInfo.isReinstalled) {
6262
// In this case we should execute fullsync because iOS Runtime requires the full content of app dir to be extracted in the root of sync dir.
63-
return this.fullSync({ projectData: liveSyncInfo.projectData, device, syncAllFiles: liveSyncInfo.syncAllFiles, liveSyncDeviceInfo: liveSyncInfo.liveSyncDeviceInfo, watch: true });
63+
return this.fullSync({
64+
projectData: liveSyncInfo.projectData,
65+
device, syncAllFiles: liveSyncInfo.syncAllFiles,
66+
liveSyncDeviceInfo: liveSyncInfo.liveSyncDeviceInfo,
67+
watch: true,
68+
useHotModuleReload: liveSyncInfo.useHotModuleReload
69+
});
6470
} else {
6571
return super.liveSyncWatchAction(device, liveSyncInfo);
6672
}

lib/services/livesync/livesync-service.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
328328
this.$previewAppLiveSyncService.initialize({
329329
appFilesUpdaterOptions: {
330330
bundle: liveSyncData.bundle,
331-
release: liveSyncData.release
331+
release: liveSyncData.release,
332+
useHotModuleReload: liveSyncData.useHotModuleReload
332333
},
333334
env: liveSyncData.env,
334335
projectDir: projectData.projectDir
@@ -389,7 +390,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
389390
appFilesUpdaterOptions: {
390391
bundle: options.bundle,
391392
release: options.release,
392-
watchAllFiles: options.liveSyncData.watchAllFiles
393+
watchAllFiles: options.liveSyncData.watchAllFiles,
394+
useHotModuleReload: options.liveSyncData.useHotModuleReload
393395
},
394396
projectData: options.projectData,
395397
env: options.env,
@@ -589,7 +591,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
589591
await this.$previewAppLiveSyncService.syncFiles({
590592
appFilesUpdaterOptions: {
591593
bundle: liveSyncData.bundle,
592-
release: liveSyncData.release
594+
release: liveSyncData.release,
595+
useHotModuleReload: liveSyncData.useHotModuleReload
593596
},
594597
env: liveSyncData.env,
595598
projectDir: projectData.projectDir
@@ -691,7 +694,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
691694
appFilesUpdaterOptions: {
692695
bundle: liveSyncData.bundle,
693696
release: liveSyncData.release,
694-
watchAllFiles: liveSyncData.watchAllFiles
697+
watchAllFiles: liveSyncData.watchAllFiles,
698+
useHotModuleReload: liveSyncData.useHotModuleReload
695699
},
696700
platforms
697701
},

lib/services/livesync/playground/preview-sdk-service.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ export class PreviewSdkService implements IPreviewSdkService {
1313
private $config: IConfiguration) {
1414
}
1515

16-
public get qrCodeUrl(): string {
17-
return `nsplay://boot?instanceId=${this.instanceId}&pKey=${PubnubKeys.PUBLISH_KEY}&sKey=${PubnubKeys.SUBSCRIBE_KEY}&template=play-ng`;
16+
public getQrCodeUrl(options: IHasUseHotModuleReloadOption): string {
17+
const hmrValue = options.useHotModuleReload ? "1" : "0";
18+
return `nsplay://boot?instanceId=${this.instanceId}&pKey=${PubnubKeys.PUBLISH_KEY}&sKey=${PubnubKeys.SUBSCRIBE_KEY}&template=play-ng&hmr=${hmrValue}`;
1819
}
1920

2021
public initialize(getInitialFiles: (device: Device) => Promise<FilesPayload>): void {

lib/services/livesync/playground/qr-code-generator.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export class PlaygroundQrCodeGenerator implements IPlaygroundQrCodeGenerator {
1818
await this.generateQrCode(PlaygroundStoreUrls.GOOGLE_PLAY_URL);
1919
}
2020

21-
public async generateQrCodeForCurrentApp(): Promise<void> {
22-
await this.generateQrCode(this.$previewSdkService.qrCodeUrl);
21+
public async generateQrCodeForCurrentApp(options: IHasUseHotModuleReloadOption): Promise<void> {
22+
await this.generateQrCode(this.$previewSdkService.getQrCodeUrl(options));
2323
}
2424

2525
private async generateQrCode(url: string): Promise<void> {

lib/services/platform-environment-requirements.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
195195
bundle: !!options.bundle,
196196
release: options.release,
197197
env: options.env,
198-
timeout: options.timeout
198+
timeout: options.timeout,
199+
useHotModuleReload: options.hmr
199200
});
200201
}
201202
}

lib/services/platform-service.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ export class PlatformService extends EventEmitter implements IPlatformService {
213213
provision: config.provision,
214214
teamId: config.teamId,
215215
nativePlatformStatus,
216-
skipModulesNativeCheck: preparePlatformInfo.skipModulesNativeCheck
216+
skipModulesNativeCheck: preparePlatformInfo.skipModulesNativeCheck,
217+
useHotModuleReload: appFilesUpdaterOptions.useHotModuleReload
217218
}
218219
});
219220

lib/services/test-execution-service.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ class TestExecutionService implements ITestExecutionService {
5555
const socketIoJsUrl = `http://localhost:${this.$options.port}/socket.io/socket.io.js`;
5656
const socketIoJs = (await this.$httpClient.httpRequest(socketIoJsUrl)).body;
5757
this.$fs.writeFile(path.join(projectDir, TestExecutionService.SOCKETIO_JS_FILE_NAME), socketIoJs);
58-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
58+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
59+
bundle: !!this.$options.bundle,
60+
release: this.$options.release,
61+
useHotModuleReload: this.$options.hmr
62+
};
5963
const preparePlatformInfo: IPreparePlatformInfo = {
6064
platform,
6165
appFilesUpdaterOptions,
@@ -125,7 +129,8 @@ class TestExecutionService implements ITestExecutionService {
125129
bundle: !!this.$options.bundle,
126130
release: this.$options.release,
127131
env: this.$options.env,
128-
timeout: this.$options.timeout
132+
timeout: this.$options.timeout,
133+
useHotModuleReload: this.$options.hmr
129134
};
130135

131136
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
@@ -183,7 +188,11 @@ class TestExecutionService implements ITestExecutionService {
183188
this.$fs.writeFile(path.join(projectDir, TestExecutionService.CONFIG_FILE_NAME), configJs);
184189
}
185190

186-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
191+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
192+
bundle: !!this.$options.bundle,
193+
release: this.$options.release,
194+
useHotModuleReload: this.$options.hmr
195+
};
187196
const preparePlatformInfo: IPreparePlatformInfo = {
188197
platform,
189198
appFilesUpdaterOptions,
@@ -253,7 +262,8 @@ class TestExecutionService implements ITestExecutionService {
253262
bundle: !!this.$options.bundle,
254263
release: this.$options.release,
255264
env: this.$options.env,
256-
timeout: this.$options.timeout
265+
timeout: this.$options.timeout,
266+
useHotModuleReload: this.$options.hmr
257267
};
258268

259269
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);

test/helpers/preview-command-helper.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ function createTestInjector() {
1919
injector.register("logger", {
2020
info: () => ({})
2121
});
22+
injector.register("options", {});
2223
injector.register("playgroundQrCodeGenerator", {
2324
generateQrCodeForAndroid: async () => {
2425
qrCodesData.isGeneratedForAndroid = true;
2526
},
2627
generateQrCodeForiOS: async () => {
2728
qrCodesData.isGeneratedForiOS = true;
2829
},
29-
generateQrCodeForCurrentApp: async () => {
30+
generateQrCodeForCurrentApp: async (options: IHasUseHotModuleReloadOption) => {
3031
qrCodesData.isGeneratedForCurrentApp = true;
3132
}
3233
});

test/ios-project-service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ describe("iOS Project Service Signing", () => {
773773
describe("Check for Changes", () => {
774774
it("sets signingChanged if no Xcode project exists", async () => {
775775
const changes = <IProjectChangesInfo>{};
776-
await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined }, projectData);
776+
await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined, useHotModuleReload: false }, projectData);
777777
assert.isTrue(!!changes.signingChanged);
778778
});
779779
it("sets signingChanged if the Xcode projects is configured with Automatic signing, but proivsion is specified", async () => {
@@ -787,7 +787,7 @@ describe("iOS Project Service Signing", () => {
787787
};
788788
};
789789
const changes = <IProjectChangesInfo>{};
790-
await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined }, projectData);
790+
await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined, useHotModuleReload: false }, projectData);
791791
assert.isTrue(!!changes.signingChanged);
792792
});
793793
it("sets signingChanged if the Xcode projects is configured with Manual signing, but the proivsion specified differs the selected in the pbxproj", async () => {
@@ -806,7 +806,7 @@ describe("iOS Project Service Signing", () => {
806806
};
807807
};
808808
const changes = <IProjectChangesInfo>{};
809-
await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined }, projectData);
809+
await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined, useHotModuleReload: false }, projectData);
810810
assert.isTrue(!!changes.signingChanged);
811811
});
812812
it("does not set signingChanged if the Xcode projects is configured with Manual signing and proivsion matches", async () => {
@@ -825,7 +825,7 @@ describe("iOS Project Service Signing", () => {
825825
};
826826
};
827827
const changes = <IProjectChangesInfo>{};
828-
await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined }, projectData);
828+
await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined, useHotModuleReload: false }, projectData);
829829
assert.isFalse(!!changes.signingChanged);
830830
});
831831
});

test/npm-support.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ async function preparePlatform(testInjector: IInjector): Promise<void> {
218218

219219
await platformService.preparePlatform({
220220
platform: "android",
221-
appFilesUpdaterOptions: { bundle: !!options.bundle, release: options.release },
221+
appFilesUpdaterOptions: { bundle: !!options.bundle, release: options.release, useHotModuleReload: false },
222222
platformTemplate: "",
223223
projectData,
224224
config: options,

test/platform-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ describe('Platform Service Tests', () => {
466466
projectData.appResourcesDirectoryPath = path.join(testDirData.appFolderPath, "App_Resources");
467467

468468
platformService = testInjector.resolve("platformService");
469-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: release };
469+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: release, useHotModuleReload: false };
470470
await platformService.preparePlatform({
471471
platform: platformToTest,
472472
appFilesUpdaterOptions,
@@ -903,7 +903,7 @@ describe('Platform Service Tests', () => {
903903
let warnings: string = "";
904904
try {
905905
testInjector.resolve("$logger").warn = (text: string) => warnings += text;
906-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: false };
906+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: false, useHotModuleReload: false };
907907
await platformService.preparePlatform({
908908
platform: "android",
909909
appFilesUpdaterOptions,

test/project-changes-service.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ describe("Project Changes Service Tests", () => {
156156
bundle: false,
157157
release: false,
158158
provision: undefined,
159-
teamId: undefined
159+
teamId: undefined,
160+
useHotModuleReload: false
160161
}
161162
});
162163
assert.isTrue(!!iOSChanges.signingChanged, "iOS signingChanged expected to be true");
@@ -168,7 +169,8 @@ describe("Project Changes Service Tests", () => {
168169
bundle: false,
169170
release: false,
170171
provision: undefined,
171-
teamId: undefined
172+
teamId: undefined,
173+
useHotModuleReload: false
172174
}
173175
});
174176
assert.isFalse(!!androidChanges.signingChanged, "Android signingChanged expected to be false");

0 commit comments

Comments
 (0)