Migrate packageMetadata

Summary: _typescript_

Reviewed By: danielbuechele

Differential Revision: D16782045

fbshipit-source-id: cfbabc036eb707f76a375f451ccc831b25c6d462
This commit is contained in:
Pascal Hartig
2019-08-14 04:36:51 -07:00
committed by Facebook Github Bot
parent 610a926611
commit 0f270c9f48
4 changed files with 18 additions and 14 deletions

View File

@@ -5,7 +5,7 @@
* @format * @format
*/ */
import {readCurrentRevision} from '../packageMetadata.js'; import {readCurrentRevision} from '../packageMetadata.tsx';
test('readCurrentRevision does not return something meaningful in dev mode', async () => { test('readCurrentRevision does not return something meaningful in dev mode', async () => {
const ret = await readCurrentRevision(); const ret = await readCurrentRevision();

View File

@@ -20,7 +20,7 @@ import fs from 'fs';
import uuid from 'uuid'; import uuid from 'uuid';
import {remote} from 'electron'; import {remote} from 'electron';
import {serialize, deserialize} from './serialization'; import {serialize, deserialize} from './serialization';
import {readCurrentRevision} from './packageMetadata.js'; import {readCurrentRevision} from './packageMetadata';
import {tryCatchReportPlatformFailures} from './metrics'; import {tryCatchReportPlatformFailures} from './metrics';
import {promisify} from 'util'; import {promisify} from 'util';
import promiseTimeout from './promiseTimeout'; import promiseTimeout from './promiseTimeout';

View File

@@ -7,7 +7,7 @@
import electron from 'electron'; import electron from 'electron';
import lodash from 'lodash'; import lodash from 'lodash';
import isProduction from './isProduction.tsx'; import isProduction from './isProduction';
import path from 'path'; import path from 'path';
import fs from 'fs'; import fs from 'fs';
import {promisify} from 'util'; import {promisify} from 'util';
@@ -17,17 +17,20 @@ const getPackageJSON = async () => {
isProduction() && electron.remote isProduction() && electron.remote
? electron.remote.app.getAppPath() ? electron.remote.app.getAppPath()
: process.cwd(); : process.cwd();
const content = await promisify(fs.readFile)(path.join(base, 'package.json')); const content = await promisify(fs.readFile)(
path.join(base, 'package.json'),
'utf-8',
);
return JSON.parse(content); return JSON.parse(content);
}; };
export const readCurrentRevision: () => Promise<?string> = lodash.memoize( export const readCurrentRevision: () => Promise<
async () => { string | undefined
// This is provided as part of the bundling process for headless. > = lodash.memoize(async () => {
if (global.__REVISION__) { // This is provided as part of the bundling process for headless.
return global.__REVISION__; if (global.__REVISION__) {
} return global.__REVISION__;
const json = await getPackageJSON(); }
return json.revision; const json = await getPackageJSON();
}, return json.revision;
); });

View File

@@ -7,6 +7,7 @@
declare module NodeJS { declare module NodeJS {
interface Global { interface Global {
__REVISION__: string | undefined;
electronRequire: (name: string) => void; electronRequire: (name: string) => void;
window: Window | undefined; window: Window | undefined;
} }