change server build process to respect babel transforms
Summary: The build process for the server was a simple ts-node that compiled all deps. However, that didn't do any source transformations we need, like replacing `fb-stubs` with `fb` in facebook builds. This diff works out the dev build process to align more with how other parts of the code base is build, by starting metro to build and bundle the server (only the sources of flipper-server, flipper-server-core and other flipper packages are bundled, node-deps are left as is). To achieve this, since metro doesn't have support for 'external' packages like any arbitrarily other bundler, we recycle the electronRequire work around that is used in the desktop app as well Reviewed By: aigoncharov Differential Revision: D32949677 fbshipit-source-id: 00d326bb17b68aece6fb43af98d0def13b335e74
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1ffd845fb2
commit
ae56f2b62f
@@ -7,13 +7,11 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import chalk from 'chalk';
|
||||
import express, {Express} from 'express';
|
||||
import http from 'http';
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import socketio from 'socket.io';
|
||||
import {hostname} from 'os';
|
||||
|
||||
type Config = {
|
||||
port: number;
|
||||
@@ -26,7 +24,6 @@ export async function startBaseServer(config: Config): Promise<{
|
||||
server: http.Server;
|
||||
socket: socketio.Server;
|
||||
}> {
|
||||
checkDevServer();
|
||||
const {app, server} = await startAssetServer(config);
|
||||
const socket = addWebsocket(server);
|
||||
return {
|
||||
@@ -67,24 +64,3 @@ function addWebsocket(server: http.Server) {
|
||||
const io = new socketio.Server(server);
|
||||
return io;
|
||||
}
|
||||
|
||||
function looksLikeDevServer(): boolean {
|
||||
const hn = hostname();
|
||||
if (/^devvm.*\.facebook\.com$/.test(hn)) {
|
||||
return true;
|
||||
}
|
||||
if (hn.endsWith('.od.fbinfra.net')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkDevServer() {
|
||||
if (looksLikeDevServer()) {
|
||||
console.log(
|
||||
chalk.red(
|
||||
`✖ It looks like you're trying to start Flipper on your OnDemand or DevServer, which is not supported. Please run this in a local checkout on your laptop or desktop instead.`,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ export async function startFlipperServer(
|
||||
// which are signed using some internal self-issued FB certificates. These certificates
|
||||
// are automatically installed to MacOS system store on FB machines, so here we're using
|
||||
// this "mac-ca" library to load them into Node.JS.
|
||||
require('mac-ca');
|
||||
electronRequire('mac-ca');
|
||||
}
|
||||
|
||||
const execPath = process.execPath;
|
||||
@@ -57,11 +57,13 @@ export async function startFlipperServer(
|
||||
let keytar: any = undefined;
|
||||
try {
|
||||
if (!isTest()) {
|
||||
keytar = require(path.join(
|
||||
staticPath,
|
||||
'native-modules',
|
||||
`keytar-${process.platform}.node`,
|
||||
));
|
||||
keytar = electronRequire(
|
||||
path.join(
|
||||
staticPath,
|
||||
'native-modules',
|
||||
`keytar-${process.platform}.node`,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to load keytar:', e);
|
||||
|
||||
@@ -110,7 +110,7 @@ async function startMetroServer(
|
||||
const babelTransformationsDir = path.resolve(
|
||||
rootDir,
|
||||
'babel-transformer',
|
||||
'src',
|
||||
'lib', // Note: required pre-compiled!
|
||||
);
|
||||
const watchFolders = await dedupeFolders(
|
||||
(
|
||||
@@ -143,9 +143,6 @@ async function startMetroServer(
|
||||
type: 'empty',
|
||||
};
|
||||
}
|
||||
// if (moduleName.includes('pluginPaths')) {
|
||||
// console.error('got ' + moduleName, rest);
|
||||
// }
|
||||
return MetroResolver.resolve(
|
||||
{
|
||||
...context,
|
||||
|
||||
Reference in New Issue
Block a user