Skip to content

Pass the HMR option to the hooks and preview URL #3907

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 18, 2018
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
6 changes: 5 additions & 1 deletion lib/commands/appstore-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ export class PublishIOS implements ICommand {
if (!ipaFilePath) {
const platform = this.$devicePlatformsConstants.iOS;
// No .ipa path provided, build .ipa on out own.
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
bundle: !!this.$options.bundle,
release: this.$options.release,
useHotModuleReload: false
};
const platformInfo: IPreparePlatformInfo = {
platform,
appFilesUpdaterOptions,
Expand Down
6 changes: 5 additions & 1 deletion lib/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {

public async executeCore(args: string[]): Promise<void> {
const platform = args[0].toLowerCase();
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
bundle: !!this.$options.bundle,
release: this.$options.release,
useHotModuleReload: this.$options.hmr
};
const platformInfo: IPreparePlatformInfo = {
platform,
appFilesUpdaterOptions,
Expand Down
6 changes: 5 additions & 1 deletion lib/commands/clean-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export class CleanAppCommandBase extends ValidatePlatformCommandBase implements
}

public async execute(args: string[]): Promise<void> {
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
bundle: !!this.$options.bundle,
release: this.$options.release,
useHotModuleReload: false
};
const platformInfo: IPreparePlatformInfo = {
appFilesUpdaterOptions,
platform: this.platform.toLowerCase(),
Expand Down
6 changes: 5 additions & 1 deletion lib/commands/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
}

public async execute(args: string[]): Promise<void> {
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
bundle: !!this.$options.bundle,
release: this.$options.release,
useHotModuleReload: this.$options.hmr
};
const platformInfo: IPreparePlatformInfo = {
platform: args[0],
appFilesUpdaterOptions,
Expand Down
5 changes: 3 additions & 2 deletions lib/commands/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ export class PreviewCommand implements ICommand {
bundle: !!this.$options.bundle,
release: this.$options.release,
env: this.$options.env,
timeout: this.$options.timeout
timeout: this.$options.timeout,
useHotModuleReload: this.$options.hmr
});

await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp();
await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp({ useHotModuleReload: this.$options.hmr });
}

public async canExecute(args: string[]): Promise<boolean> {
Expand Down
2 changes: 1 addition & 1 deletion lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ interface IEnvOptions {

interface IAndroidBuildOptionsSettings extends IAndroidReleaseOptions, IRelease { }

interface IAppFilesUpdaterOptions extends IBundle, IRelease, IOptionalWatchAllFiles { }
interface IAppFilesUpdaterOptions extends IBundle, IRelease, IOptionalWatchAllFiles, IHasUseHotModuleReloadOption { }

interface IPlatformBuildData extends IAppFilesUpdaterOptions, IBuildConfig, IEnvOptions { }

Expand Down
2 changes: 1 addition & 1 deletion lib/definitions/livesync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ interface IHasUseHotModuleReloadOption {
/**
* Defines if the hot module reload should be used.
*/
useHotModuleReload?: boolean;
useHotModuleReload: boolean;
}

interface ILatestAppPackageInstalledSettings extends IDictionary<IDictionary<boolean>> { /* empty */ }
Expand Down
4 changes: 2 additions & 2 deletions lib/definitions/preview-app-livesync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare global {
interface IPreviewAppLiveSyncData extends IProjectDir, IAppFilesUpdaterOptionsComposition, IEnvOptions { }

interface IPreviewSdkService {
qrCodeUrl: string;
getQrCodeUrl(options: IHasUseHotModuleReloadOption): string;
connectedDevices: Device[];
initialize(getInitialFiles: (device: Device) => Promise<FilesPayload>): void;
applyChanges(filesPayload: FilesPayload): Promise<void>;
Expand All @@ -29,6 +29,6 @@ declare global {
interface IPlaygroundQrCodeGenerator {
generateQrCodeForiOS(): Promise<void>;
generateQrCodeForAndroid(): Promise<void>;
generateQrCodeForCurrentApp(): Promise<void>;
generateQrCodeForCurrentApp(options: IHasUseHotModuleReloadOption): Promise<void>;
}
}
6 changes: 5 additions & 1 deletion lib/helpers/deploy-command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export class DeployCommandHelper implements IDeployCommandHelper {
}

public getDeployPlatformInfo(platform: string): IDeployPlatformInfo {
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
bundle: !!this.$options.bundle,
release: this.$options.release,
useHotModuleReload: this.$options.hmr
};
const deployOptions: IDeployPlatformOptions = {
clean: this.$options.clean,
device: this.$options.device,
Expand Down
3 changes: 2 additions & 1 deletion lib/helpers/livesync-command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
platform: currentPlatform,
appFilesUpdaterOptions: {
bundle: !!this.$options.bundle,
release: this.$options.release
release: this.$options.release,
useHotModuleReload: this.$options.hmr
},
deployOptions,
buildPlatform: this.$platformService.buildPlatform.bind(this.$platformService),
Expand Down
3 changes: 2 additions & 1 deletion lib/helpers/preview-command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export class PreviewCommandHelper implements IPreviewCommandHelper {
private ctrlcReader: readline.ReadLine;

constructor(private $playgroundQrCodeGenerator: IPlaygroundQrCodeGenerator,
private $options: IOptions,
private $processService: IProcessService) {
this.$processService.attachToProcessExitSignals(this, () => {
this.stopWaitingForCommand();
Expand Down Expand Up @@ -49,7 +50,7 @@ export class PreviewCommandHelper implements IPreviewCommandHelper {
await this.$playgroundQrCodeGenerator.generateQrCodeForiOS();
return;
case "c":
await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp();
await this.$playgroundQrCodeGenerator.generateQrCodeForCurrentApp({ useHotModuleReload: this.$options.hmr });
return;
}
}
Expand Down
12 changes: 9 additions & 3 deletions lib/services/livesync/ios-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I
$logger: ILogger,
$projectFilesProvider: IProjectFilesProvider,
private $iOSDebuggerPortService: IIOSDebuggerPortService) {
super($fs, $logger, $platformsData, $projectFilesManager, $devicePathProvider, $projectFilesProvider);
}
super($fs, $logger, $platformsData, $projectFilesManager, $devicePathProvider, $projectFilesProvider);
}

public async fullSync(syncInfo: IFullSyncInfo): Promise<ILiveSyncResultInfo> {
const device = syncInfo.device;
Expand Down Expand Up @@ -60,7 +60,13 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I
public liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<ILiveSyncResultInfo> {
if (liveSyncInfo.isReinstalled) {
// 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.
return this.fullSync({ projectData: liveSyncInfo.projectData, device, syncAllFiles: liveSyncInfo.syncAllFiles, liveSyncDeviceInfo: liveSyncInfo.liveSyncDeviceInfo, watch: true });
return this.fullSync({
projectData: liveSyncInfo.projectData,
device, syncAllFiles: liveSyncInfo.syncAllFiles,
liveSyncDeviceInfo: liveSyncInfo.liveSyncDeviceInfo,
watch: true,
useHotModuleReload: liveSyncInfo.useHotModuleReload
});
} else {
return super.liveSyncWatchAction(device, liveSyncInfo);
}
Expand Down
12 changes: 8 additions & 4 deletions lib/services/livesync/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
this.$previewAppLiveSyncService.initialize({
appFilesUpdaterOptions: {
bundle: liveSyncData.bundle,
release: liveSyncData.release
release: liveSyncData.release,
useHotModuleReload: liveSyncData.useHotModuleReload
},
env: liveSyncData.env,
projectDir: projectData.projectDir
Expand Down Expand Up @@ -389,7 +390,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
appFilesUpdaterOptions: {
bundle: options.bundle,
release: options.release,
watchAllFiles: options.liveSyncData.watchAllFiles
watchAllFiles: options.liveSyncData.watchAllFiles,
useHotModuleReload: options.liveSyncData.useHotModuleReload
},
projectData: options.projectData,
env: options.env,
Expand Down Expand Up @@ -589,7 +591,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
await this.$previewAppLiveSyncService.syncFiles({
appFilesUpdaterOptions: {
bundle: liveSyncData.bundle,
release: liveSyncData.release
release: liveSyncData.release,
useHotModuleReload: liveSyncData.useHotModuleReload
},
env: liveSyncData.env,
projectDir: projectData.projectDir
Expand Down Expand Up @@ -691,7 +694,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
appFilesUpdaterOptions: {
bundle: liveSyncData.bundle,
release: liveSyncData.release,
watchAllFiles: liveSyncData.watchAllFiles
watchAllFiles: liveSyncData.watchAllFiles,
useHotModuleReload: liveSyncData.useHotModuleReload
},
platforms
},
Expand Down
5 changes: 3 additions & 2 deletions lib/services/livesync/playground/preview-sdk-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export class PreviewSdkService implements IPreviewSdkService {
private $config: IConfiguration) {
}

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

public initialize(getInitialFiles: (device: Device) => Promise<FilesPayload>): void {
Expand Down
4 changes: 2 additions & 2 deletions lib/services/livesync/playground/qr-code-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export class PlaygroundQrCodeGenerator implements IPlaygroundQrCodeGenerator {
await this.generateQrCode(PlaygroundStoreUrls.GOOGLE_PLAY_URL);
}

public async generateQrCodeForCurrentApp(): Promise<void> {
await this.generateQrCode(this.$previewSdkService.qrCodeUrl);
public async generateQrCodeForCurrentApp(options: IHasUseHotModuleReloadOption): Promise<void> {
await this.generateQrCode(this.$previewSdkService.getQrCodeUrl(options));
}

private async generateQrCode(url: string): Promise<void> {
Expand Down
3 changes: 2 additions & 1 deletion lib/services/platform-environment-requirements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
bundle: !!options.bundle,
release: options.release,
env: options.env,
timeout: options.timeout
timeout: options.timeout,
useHotModuleReload: options.hmr
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ export class PlatformService extends EventEmitter implements IPlatformService {
provision: config.provision,
teamId: config.teamId,
nativePlatformStatus,
skipModulesNativeCheck: preparePlatformInfo.skipModulesNativeCheck
skipModulesNativeCheck: preparePlatformInfo.skipModulesNativeCheck,
useHotModuleReload: appFilesUpdaterOptions.useHotModuleReload
}
});

Expand Down
18 changes: 14 additions & 4 deletions lib/services/test-execution-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ class TestExecutionService implements ITestExecutionService {
const socketIoJsUrl = `http://localhost:${this.$options.port}/socket.io/socket.io.js`;
const socketIoJs = (await this.$httpClient.httpRequest(socketIoJsUrl)).body;
this.$fs.writeFile(path.join(projectDir, TestExecutionService.SOCKETIO_JS_FILE_NAME), socketIoJs);
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
bundle: !!this.$options.bundle,
release: this.$options.release,
useHotModuleReload: this.$options.hmr
};
const preparePlatformInfo: IPreparePlatformInfo = {
platform,
appFilesUpdaterOptions,
Expand Down Expand Up @@ -125,7 +129,8 @@ class TestExecutionService implements ITestExecutionService {
bundle: !!this.$options.bundle,
release: this.$options.release,
env: this.$options.env,
timeout: this.$options.timeout
timeout: this.$options.timeout,
useHotModuleReload: this.$options.hmr
};

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

const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
bundle: !!this.$options.bundle,
release: this.$options.release,
useHotModuleReload: this.$options.hmr
};
const preparePlatformInfo: IPreparePlatformInfo = {
platform,
appFilesUpdaterOptions,
Expand Down Expand Up @@ -253,7 +262,8 @@ class TestExecutionService implements ITestExecutionService {
bundle: !!this.$options.bundle,
release: this.$options.release,
env: this.$options.env,
timeout: this.$options.timeout
timeout: this.$options.timeout,
useHotModuleReload: this.$options.hmr
};

await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
Expand Down
3 changes: 2 additions & 1 deletion test/helpers/preview-command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ function createTestInjector() {
injector.register("logger", {
info: () => ({})
});
injector.register("options", {});
injector.register("playgroundQrCodeGenerator", {
generateQrCodeForAndroid: async () => {
qrCodesData.isGeneratedForAndroid = true;
},
generateQrCodeForiOS: async () => {
qrCodesData.isGeneratedForiOS = true;
},
generateQrCodeForCurrentApp: async () => {
generateQrCodeForCurrentApp: async (options: IHasUseHotModuleReloadOption) => {
qrCodesData.isGeneratedForCurrentApp = true;
}
});
Expand Down
8 changes: 4 additions & 4 deletions test/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ describe("iOS Project Service Signing", () => {
describe("Check for Changes", () => {
it("sets signingChanged if no Xcode project exists", async () => {
const changes = <IProjectChangesInfo>{};
await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined }, projectData);
await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined, useHotModuleReload: false }, projectData);
assert.isTrue(!!changes.signingChanged);
});
it("sets signingChanged if the Xcode projects is configured with Automatic signing, but proivsion is specified", async () => {
Expand All @@ -787,7 +787,7 @@ describe("iOS Project Service Signing", () => {
};
};
const changes = <IProjectChangesInfo>{};
await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined }, projectData);
await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined, useHotModuleReload: false }, projectData);
assert.isTrue(!!changes.signingChanged);
});
it("sets signingChanged if the Xcode projects is configured with Manual signing, but the proivsion specified differs the selected in the pbxproj", async () => {
Expand All @@ -806,7 +806,7 @@ describe("iOS Project Service Signing", () => {
};
};
const changes = <IProjectChangesInfo>{};
await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined }, projectData);
await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined, useHotModuleReload: false }, projectData);
assert.isTrue(!!changes.signingChanged);
});
it("does not set signingChanged if the Xcode projects is configured with Manual signing and proivsion matches", async () => {
Expand All @@ -825,7 +825,7 @@ describe("iOS Project Service Signing", () => {
};
};
const changes = <IProjectChangesInfo>{};
await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined }, projectData);
await iOSProjectService.checkForChanges(changes, { bundle: false, release: false, provision: "NativeScriptDev", teamId: undefined, useHotModuleReload: false }, projectData);
assert.isFalse(!!changes.signingChanged);
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/npm-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ async function preparePlatform(testInjector: IInjector): Promise<void> {

await platformService.preparePlatform({
platform: "android",
appFilesUpdaterOptions: { bundle: !!options.bundle, release: options.release },
appFilesUpdaterOptions: { bundle: !!options.bundle, release: options.release, useHotModuleReload: false },
platformTemplate: "",
projectData,
config: options,
Expand Down
4 changes: 2 additions & 2 deletions test/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ describe('Platform Service Tests', () => {
projectData.appResourcesDirectoryPath = path.join(testDirData.appFolderPath, "App_Resources");

platformService = testInjector.resolve("platformService");
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: release };
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: release, useHotModuleReload: false };
await platformService.preparePlatform({
platform: platformToTest,
appFilesUpdaterOptions,
Expand Down Expand Up @@ -903,7 +903,7 @@ describe('Platform Service Tests', () => {
let warnings: string = "";
try {
testInjector.resolve("$logger").warn = (text: string) => warnings += text;
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: false };
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: false, release: false, useHotModuleReload: false };
await platformService.preparePlatform({
platform: "android",
appFilesUpdaterOptions,
Expand Down
6 changes: 4 additions & 2 deletions test/project-changes-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ describe("Project Changes Service Tests", () => {
bundle: false,
release: false,
provision: undefined,
teamId: undefined
teamId: undefined,
useHotModuleReload: false
}
});
assert.isTrue(!!iOSChanges.signingChanged, "iOS signingChanged expected to be true");
Expand All @@ -168,7 +169,8 @@ describe("Project Changes Service Tests", () => {
bundle: false,
release: false,
provision: undefined,
teamId: undefined
teamId: undefined,
useHotModuleReload: false
}
});
assert.isFalse(!!androidChanges.signingChanged, "Android signingChanged expected to be false");
Expand Down
Loading