From e184af7f2afe42eaf8b4dcc3a644636c5667b0e5 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Fri, 15 Mar 2019 09:46:34 -0700 Subject: [PATCH] fix the parsing error Summary: The headless version used to use `JSON.stringify` to serialize the output of `serializeStore` which basically transformed the store to a specific format which is serializable. But we have written the custom serialize function which cateres to the non serializable object types. Headless didn't use it, so thats why it exported Flipper trace in an unrecognizable format for the flipper. I have also renamed `serializeStore` to `prepareToSerializeStore` so that the confusion doesn't occur in future. I have used an `exportStore` function in headless which exports the store to the `Promise` Reviewed By: jknoxville Differential Revision: D14480096 fbshipit-source-id: f312d7637aa082d96c3bc1dfd00eefb19182e97f --- headless/index.js | 4 ++-- src/utils/exportData.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/headless/index.js b/headless/index.js index f74614d2b..0661824a9 100644 --- a/headless/index.js +++ b/headless/index.js @@ -13,7 +13,7 @@ import path from 'path'; // $FlowFixMe this file exist, trust me, flow! import setup from '../static/setup.js'; import yargs from 'yargs'; -import {serializeStore} from '../src/utils/exportData.js'; +import {exportStore} from '../src/utils/exportData.js'; yargs .usage('$0 [args]') @@ -98,7 +98,7 @@ function startFlipper({ dispatcher(store, logger); process.on('SIGINT', async () => { - originalConsole.log(JSON.stringify(await serializeStore(store), null, 2)); + originalConsole.log(await exportStore(store)); process.exit(); }); } diff --git a/src/utils/exportData.js b/src/utils/exportData.js index 034b8fda5..8ed33d332 100644 --- a/src/utils/exportData.js +++ b/src/utils/exportData.js @@ -178,7 +178,7 @@ export const processStore = ( return null; }; -export async function serializeStore(store: Store): Promise { +export async function getStoreExport(store: Store): Promise { const state = store.getState(); const {clients} = state.connections; const {pluginStates} = state; @@ -232,12 +232,12 @@ export async function serializeStore(store: Store): Promise { export function exportStore(store: Store): Promise { getLogger().track('usage', EXPORT_FLIPPER_TRACE_EVENT); return new Promise(async (resolve, reject) => { - const json = await serializeStore(store); - if (!json) { + const storeExport = await getStoreExport(store); + if (!storeExport) { console.error('Make sure a device is connected'); reject('No device is selected'); } - const serializedString = serialize(json); + const serializedString = serialize(storeExport); if (serializedString.length <= 0) { reject('Serialize function returned empty string'); }