Skip to content

fix(preview-api): remove mandatory release option from IPreviewAppLiveSyncData interface #4106

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
Nov 14, 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
2 changes: 1 addition & 1 deletion lib/definitions/preview-app-livesync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare global {
stopLiveSync(): Promise<void>;
}

interface IPreviewAppLiveSyncData extends IProjectDir, IAppFilesUpdaterOptionsComposition, IEnvOptions { }
interface IPreviewAppLiveSyncData extends IProjectDir, IHasUseHotModuleReloadOption, IBundle, IEnvOptions { }

interface IPreviewSdkService extends EventEmitter {
getQrCodeUrl(options: IHasUseHotModuleReloadOption): string;
Expand Down
28 changes: 11 additions & 17 deletions lib/services/livesync/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
await this.liveSync([], {
syncToPreviewApp: true,
projectDir: data.projectDir,
bundle: data.appFilesUpdaterOptions.bundle,
useHotModuleReload: data.appFilesUpdaterOptions.useHotModuleReload,
bundle: data.bundle,
useHotModuleReload: data.useHotModuleReload,
release: false,
env: data.env,
});

const url = this.$previewSdkService.getQrCodeUrl({ useHotModuleReload: data.appFilesUpdaterOptions.useHotModuleReload });
const url = this.$previewSdkService.getQrCodeUrl({ useHotModuleReload: data.useHotModuleReload });
const result = await this.$previewQrCodeService.getLiveSyncQrCode(url);
return result;
}
Expand Down Expand Up @@ -362,13 +362,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi

if (liveSyncData.syncToPreviewApp) {
await this.$previewAppLiveSyncService.initialize({
appFilesUpdaterOptions: {
bundle: liveSyncData.bundle,
release: liveSyncData.release,
useHotModuleReload: liveSyncData.useHotModuleReload
},
env: liveSyncData.env,
projectDir: projectData.projectDir
projectDir: projectData.projectDir,
bundle: liveSyncData.bundle,
useHotModuleReload: liveSyncData.useHotModuleReload,
env: liveSyncData.env
});
} else {
// In case liveSync is called for a second time for the same projectDir.
Expand Down Expand Up @@ -641,13 +638,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
if (liveSyncData.syncToPreviewApp) {
await this.addActionToChain(projectData.projectDir, async () => {
await this.$previewAppLiveSyncService.syncFiles({
appFilesUpdaterOptions: {
bundle: liveSyncData.bundle,
release: liveSyncData.release,
useHotModuleReload: liveSyncData.useHotModuleReload
},
env: liveSyncData.env,
projectDir: projectData.projectDir
projectDir: projectData.projectDir,
bundle: liveSyncData.bundle,
useHotModuleReload: liveSyncData.useHotModuleReload,
env: liveSyncData.env
}, currentFilesToSync, currentFilesToRemove);
});
} else {
Expand Down
25 changes: 17 additions & 8 deletions lib/services/livesync/playground/preview-app-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
.uniq()
.value();
for (const platform of platforms) {
await this.syncFilesForPlatformSafe(data, platform, { filesToSync, filesToRemove, useHotModuleReload: data.appFilesUpdaterOptions.useHotModuleReload });
await this.syncFilesForPlatformSafe(data, platform, { filesToSync, filesToRemove, useHotModuleReload: data.useHotModuleReload });
}
}

Expand All @@ -78,7 +78,7 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
const hookArgs = this.getHookArgs(data, device);
await this.$hooksService.executeBeforeHooks("preview-sync", { hookArgs });
await this.$previewAppPluginsService.comparePluginsOnDevice(data, device);
const payloads = await this.syncFilesForPlatformSafe(data, device.platform, { isInitialSync: true, useHotModuleReload: data.appFilesUpdaterOptions.useHotModuleReload });
const payloads = await this.syncFilesForPlatformSafe(data, device.platform, { isInitialSync: true, useHotModuleReload: data.useHotModuleReload });
return payloads;
}

Expand All @@ -92,7 +92,11 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
config: {
env: data.env,
platform: device.platform,
appFilesUpdaterOptions: data.appFilesUpdaterOptions,
appFilesUpdaterOptions: {
bundle: data.bundle,
useHotModuleReload: data.useHotModuleReload,
release: false
},
},
externals: this.$previewAppPluginsService.getExternalPlugins(device),
filesToSyncMap,
Expand All @@ -109,10 +113,10 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
const platformHmrData = currentHmrData[platform] || <any>{};
const filesToSync = _.cloneDeep(filesToSyncMap[platform]);
// We don't need to prepare when webpack emits changed files. We just need to send a message to pubnub.
promise = this.syncFilesForPlatformSafe(data, platform, { filesToSync, skipPrepare: true, useHotModuleReload: data.appFilesUpdaterOptions.useHotModuleReload });
promise = this.syncFilesForPlatformSafe(data, platform, { filesToSync, skipPrepare: true, useHotModuleReload: data.useHotModuleReload });
await promise;

if (data.appFilesUpdaterOptions.useHotModuleReload && platformHmrData.hash) {
if (data.useHotModuleReload && platformHmrData.hash) {
const devices = this.$previewDevicesService.getDevicesForPlatform(platform);

await Promise.all(_.map(devices, async (previewDevice: Device) => {
Expand All @@ -133,12 +137,12 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
let payloads = null;

try {
const { appFilesUpdaterOptions, env, projectDir } = data;
const { env, projectDir } = data;
const projectData = this.$projectDataService.getProjectData(projectDir);
const platformData = this.$platformsData.getPlatformData(platform, projectData);

if (!opts.skipPrepare) {
await this.preparePlatform(platform, appFilesUpdaterOptions, env, projectData);
await this.preparePlatform(platform, data, env, projectData);
}

if (opts.isInitialSync) {
Expand Down Expand Up @@ -178,7 +182,12 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
return { files: payloads, platform: platformData.normalizedPlatformName.toLowerCase(), hmrMode, deviceId };
}

private async preparePlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, env: Object, projectData: IProjectData): Promise<void> {
private async preparePlatform(platform: string, data: IPreviewAppLiveSyncData, env: Object, projectData: IProjectData): Promise<void> {
const appFilesUpdaterOptions = {
bundle: data.bundle,
useHotModuleReload: data.useHotModuleReload,
release: false
};
const nativePrepare = { skipNativePrepare: true };
const config = <IPlatformOptions>{};
const platformTemplate = <string>null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class PreviewAppPluginsService implements IPreviewAppPluginsService {
}

private getWarningForPlugin(data: IPreviewAppLiveSyncData, localPlugin: string, localPluginVersion: string, devicePluginVersion: string, device: Device): string {
if (data && data.appFilesUpdaterOptions && data.appFilesUpdaterOptions.bundle) {
if (data && data.bundle) {
const pluginPackageJsonPath = path.join(data.projectDir, NODE_MODULES_DIR_NAME, localPlugin, PACKAGE_JSON_FILE_NAME);
const isNativeScriptPlugin = this.$pluginsService.isNativeScriptPlugin(pluginPackageJsonPath);
if (!isNativeScriptPlugin || (isNativeScriptPlugin && !this.hasNativeCode(localPlugin, device.platform, data.projectDir))) {
Expand Down
11 changes: 4 additions & 7 deletions test/services/playground/preview-app-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ const defaultProjectFiles = [
];
const syncFilesMockData = {
projectDir: projectDirPath,
appFilesUpdaterOptions: {
release: false,
bundle: false,
useHotModuleReload: false
},
bundle: false,
useHotModuleReload: false,
env: {}
};

Expand Down Expand Up @@ -182,7 +179,7 @@ async function initialSync(input?: IActInput) {

const { previewAppLiveSyncService, previewSdkService, actOptions } = input;
const syncFilesData = _.cloneDeep(syncFilesMockData);
syncFilesData.appFilesUpdaterOptions.useHotModuleReload = actOptions.hmr;
syncFilesData.useHotModuleReload = actOptions.hmr;
await previewAppLiveSyncService.initialize(syncFilesData);
if (actOptions.callGetInitialFiles) {
await previewSdkService.getInitialFiles(deviceMockData);
Expand All @@ -195,7 +192,7 @@ async function syncFiles(input?: IActInput) {
const { previewAppLiveSyncService, previewSdkService, projectFiles, actOptions } = input;

const syncFilesData = _.cloneDeep(syncFilesMockData);
syncFilesData.appFilesUpdaterOptions.useHotModuleReload = actOptions.hmr;
syncFilesData.useHotModuleReload = actOptions.hmr;
await previewAppLiveSyncService.initialize(syncFilesData);
if (actOptions.callGetInitialFiles) {
await previewSdkService.getInitialFiles(deviceMockData);
Expand Down
6 changes: 2 additions & 4 deletions test/services/playground/preview-app-plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ function createDevice(plugins: string): Device {
function createPreviewLiveSyncData(options?: { bundle: boolean }) {
return {
projectDir,
appFilesUpdaterOptions: {
release: false,
bundle: options.bundle
},
release: false,
bundle: options.bundle,
env: {}
};
}
Expand Down