Remove babel transforms for flipper-server
Summary: Flipper server itself requires no babel transforms. We applied extra transforms only for the bundled plugins. However, we pack and ship all plugins in the /static folder. They are always available on the FS. Therefore we could stop bundling any plugins into flipper-server's source code. Reviewed By: lblasa Differential Revision: D38910251 fbshipit-source-id: b3e9fe5ae2ab69ce5579b01b6793ebf7e88baf66
This commit is contained in:
committed by
Facebook GitHub Bot
parent
218cb6abf2
commit
a67a4e5d0f
@@ -16,8 +16,9 @@ import {
|
||||
genMercurialRevision,
|
||||
getVersionNumber,
|
||||
prepareDefaultPlugins,
|
||||
prepareHeadlessPlugins,
|
||||
buildHeadlessPlugins,
|
||||
moveServerSourceMaps,
|
||||
buildServerAddOns,
|
||||
} from './build-utils';
|
||||
import {defaultPluginsDir, distDir, serverDir, staticDir} from './paths';
|
||||
import isFB from './isFB';
|
||||
@@ -217,7 +218,7 @@ async function copyStaticResources(outDir: string, versionNumber: string) {
|
||||
console.log(`⚙️ Copying package resources...`);
|
||||
|
||||
// static folder, without the things that are only for Electron
|
||||
const packageFilesToCopy = ['README.md', 'package.json', 'server.js', 'dist'];
|
||||
const packageFilesToCopy = ['README.md', 'package.json', 'server.js', 'lib'];
|
||||
|
||||
await Promise.all(
|
||||
packageFilesToCopy.map((e) =>
|
||||
@@ -352,8 +353,9 @@ async function buildServerRelease() {
|
||||
// create plugin output dir
|
||||
await fs.mkdirp(path.join(dir, 'static', 'defaultPlugins'));
|
||||
|
||||
await prepareDefaultPlugins(argv.channel === 'insiders');
|
||||
await prepareHeadlessPlugins();
|
||||
await prepareDefaultPlugins(argv.channel === 'insiders', true);
|
||||
await buildServerAddOns(false);
|
||||
await buildHeadlessPlugins(false);
|
||||
await compileServerMain(false);
|
||||
await copyStaticResources(dir, versionNumber);
|
||||
await downloadIcons(path.join(dir, 'static'));
|
||||
|
||||
@@ -16,7 +16,7 @@ import MetroResolver from 'metro-resolver';
|
||||
import tmp from 'tmp';
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import {spawn} from 'promisify-child-process';
|
||||
import {spawn, exec} from 'promisify-child-process';
|
||||
import {
|
||||
getWatchFolders,
|
||||
runBuild,
|
||||
@@ -37,7 +37,6 @@ import {
|
||||
rootDir,
|
||||
browserUiDir,
|
||||
serverCoreDir,
|
||||
serverCompanionDir,
|
||||
} from './paths';
|
||||
import pFilter from 'p-filter';
|
||||
import child from 'child_process';
|
||||
@@ -76,7 +75,10 @@ export function die(err: Error) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
export async function prepareDefaultPlugins(isInsidersBuild: boolean = false) {
|
||||
export async function prepareDefaultPlugins(
|
||||
isInsidersBuild: boolean = false,
|
||||
flipperServerBuild = false,
|
||||
) {
|
||||
console.log(
|
||||
`⚙️ Preparing default plugins (isInsidersBuild=${isInsidersBuild})...`,
|
||||
);
|
||||
@@ -105,18 +107,29 @@ export async function prepareDefaultPlugins(isInsidersBuild: boolean = false) {
|
||||
await buildDefaultPlugins(defaultPlugins);
|
||||
await generateDefaultPluginEntryPoints([]); // calling it here just to generate empty indexes
|
||||
} else {
|
||||
await generateDefaultPluginEntryPoints(defaultPlugins);
|
||||
await generateDefaultPluginEntryPoints(
|
||||
defaultPlugins,
|
||||
flipperServerBuild,
|
||||
);
|
||||
}
|
||||
}
|
||||
console.log('✅ Prepared default plugins.');
|
||||
}
|
||||
|
||||
export async function prepareHeadlessPlugins() {
|
||||
console.log(`⚙️ Preparing headless plugins...`);
|
||||
export async function buildHeadlessPlugins(dev: boolean) {
|
||||
console.log(`⚙️ Building headless plugins...`);
|
||||
const sourcePlugins = await getSourcePlugins();
|
||||
const headlessPlugins = sourcePlugins.filter((p) => p.headless);
|
||||
await generateHeadlessPluginEntryPoints(headlessPlugins);
|
||||
console.log('✅ Prepared headless plugins.');
|
||||
await Promise.all(headlessPlugins.map((p) => runBuild(p.dir, dev)));
|
||||
console.log('✅ Built headless plugins.');
|
||||
}
|
||||
|
||||
export async function buildServerAddOns(dev: boolean) {
|
||||
console.log(`⚙️ Building plugins with server add-ons plugins...`);
|
||||
const sourcePlugins = await getSourcePlugins();
|
||||
const serverAddOns = sourcePlugins.filter((p) => p.serverAddOnSource);
|
||||
await Promise.all(serverAddOns.map((p) => runBuild(p.dir, dev)));
|
||||
console.log('✅ Built plugins with server add-ons plugins.');
|
||||
}
|
||||
|
||||
function getGeneratedIndex(pluginRequires: string) {
|
||||
@@ -142,6 +155,7 @@ function getGeneratedIndex(pluginRequires: string) {
|
||||
|
||||
async function generateDefaultPluginEntryPoints(
|
||||
defaultPlugins: InstalledPluginDetails[],
|
||||
flipperServerBuild?: boolean,
|
||||
) {
|
||||
console.log(
|
||||
`⚙️ Generating entry points for ${defaultPlugins.length} bundled plugins...`,
|
||||
@@ -181,9 +195,9 @@ async function generateDefaultPluginEntryPoints(
|
||||
generatedIndex,
|
||||
);
|
||||
|
||||
const serverAddOns = defaultPlugins.filter(
|
||||
({serverAddOnSource}) => !!serverAddOnSource,
|
||||
);
|
||||
const serverAddOns = flipperServerBuild
|
||||
? []
|
||||
: defaultPlugins.filter(({serverAddOnSource}) => !!serverAddOnSource);
|
||||
const serverAddOnRequires = serverAddOns
|
||||
.map(
|
||||
(x) =>
|
||||
@@ -200,28 +214,6 @@ async function generateDefaultPluginEntryPoints(
|
||||
console.log('✅ Generated bundled plugin entry points.');
|
||||
}
|
||||
|
||||
async function generateHeadlessPluginEntryPoints(
|
||||
headlessPlugins: InstalledPluginDetails[],
|
||||
) {
|
||||
console.log(
|
||||
`⚙️ Generating entry points for ${headlessPlugins.length} headless plugins...`,
|
||||
);
|
||||
const headlessRequires = headlessPlugins
|
||||
.map(
|
||||
(x) =>
|
||||
` '${x.name}': tryRequire('${x.name}', () => require('${x.name}'))`,
|
||||
)
|
||||
.join(',\n');
|
||||
const generatedIndexHeadless = getGeneratedIndex(headlessRequires);
|
||||
await fs.ensureDir(path.join(serverCompanionDir, 'src', 'defaultPlugins'));
|
||||
await fs.writeFile(
|
||||
path.join(serverCompanionDir, 'src', 'defaultPlugins', 'index.tsx'),
|
||||
generatedIndexHeadless,
|
||||
);
|
||||
|
||||
console.log('✅ Generated headless plugin entry points.');
|
||||
}
|
||||
|
||||
async function buildDefaultPlugins(defaultPlugins: InstalledPluginDetails[]) {
|
||||
if (process.env.FLIPPER_NO_REBUILD_PLUGINS) {
|
||||
console.log(
|
||||
@@ -468,40 +460,7 @@ export function genMercurialRevision(): Promise<string | null> {
|
||||
}
|
||||
|
||||
export async function compileServerMain(dev: boolean) {
|
||||
await fs.promises.mkdir(path.join(serverDir, 'dist'), {recursive: true});
|
||||
const out = path.join(serverDir, 'dist', 'index.js');
|
||||
console.log('⚙️ Compiling server bundle...');
|
||||
const config = Object.assign({}, await Metro.loadConfig(), {
|
||||
reporter: {update: () => {}},
|
||||
projectRoot: rootDir,
|
||||
transformer: {
|
||||
babelTransformerPath: path.join(
|
||||
babelTransformationsDir,
|
||||
'transform-server-' + (dev ? 'dev' : 'prod'),
|
||||
),
|
||||
...minifierConfig,
|
||||
},
|
||||
resolver: {
|
||||
// no 'mjs' / 'module'; it caused issues
|
||||
sourceExts: ['tsx', 'ts', 'js', 'json', 'cjs'],
|
||||
resolverMainFields: ['flipperBundlerEntry', 'main'],
|
||||
resolveRequest(context: any, moduleName: string, ...rest: any[]) {
|
||||
assertSaneImport(context, moduleName);
|
||||
return defaultResolve(context, moduleName, ...rest);
|
||||
},
|
||||
},
|
||||
});
|
||||
await Metro.runBuild(config, {
|
||||
platform: 'node',
|
||||
entry: path.join(serverDir, 'src', 'index.tsx'),
|
||||
out,
|
||||
dev,
|
||||
minify: false, // !dev,
|
||||
sourceMap: true,
|
||||
sourceMapUrl: dev ? 'index.map' : undefined,
|
||||
inlineSourceMap: false,
|
||||
resetCache: !dev,
|
||||
});
|
||||
await exec(`cd ${serverDir} && yarn build`);
|
||||
console.log('✅ Compiled server bundle.');
|
||||
}
|
||||
|
||||
@@ -611,7 +570,6 @@ export async function launchServer(
|
||||
if (proc) {
|
||||
console.log('⚙️ Killing old flipper-server...');
|
||||
proc.kill(9);
|
||||
await sleep(1000);
|
||||
}
|
||||
console.log('⚙️ Launching flipper-server...');
|
||||
proc = child.spawn(
|
||||
|
||||
@@ -9,11 +9,9 @@
|
||||
|
||||
/* eslint-disable flipper/no-console-error-without-context */
|
||||
|
||||
import {prepareDefaultPlugins, prepareHeadlessPlugins} from './build-utils';
|
||||
import {prepareDefaultPlugins} from './build-utils';
|
||||
|
||||
Promise.all([prepareDefaultPlugins(), prepareHeadlessPlugins()]).catch(
|
||||
(err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
},
|
||||
);
|
||||
prepareDefaultPlugins().catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
@@ -23,7 +23,7 @@ import {hostname} from 'os';
|
||||
import {
|
||||
compileMain,
|
||||
prepareDefaultPlugins,
|
||||
prepareHeadlessPlugins,
|
||||
buildHeadlessPlugins,
|
||||
} from './build-utils';
|
||||
import Watchman from './watchman';
|
||||
// @ts-ignore no typings for metro
|
||||
@@ -445,7 +445,7 @@ function checkDevServer() {
|
||||
await prepareDefaultPlugins(
|
||||
process.env.FLIPPER_RELEASE_CHANNEL === 'insiders',
|
||||
);
|
||||
await prepareHeadlessPlugins();
|
||||
await buildHeadlessPlugins(true);
|
||||
await ensurePluginFoldersWatchable();
|
||||
const port = await detect(DEFAULT_PORT);
|
||||
const {app, server} = await startAssetServer(port);
|
||||
|
||||
@@ -14,7 +14,8 @@ import {
|
||||
compileServerMain,
|
||||
launchServer,
|
||||
prepareDefaultPlugins,
|
||||
prepareHeadlessPlugins,
|
||||
buildHeadlessPlugins,
|
||||
buildServerAddOns,
|
||||
} from './build-utils';
|
||||
import Watchman from './watchman';
|
||||
import isFB from './isFB';
|
||||
@@ -59,11 +60,6 @@ const argv = yargs
|
||||
'[FB-internal only] Will force using public sources only, to be able to iterate quickly on the public version. If sources are checked out from GitHub this is already the default. Setting env var "FLIPPER_FORCE_PUBLIC_BUILD" is equivalent.',
|
||||
type: 'boolean',
|
||||
},
|
||||
open: {
|
||||
describe: 'Open Flipper in the default browser after starting',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
tcp: {
|
||||
describe: 'Enable TCP connections on flipper-server.',
|
||||
type: 'boolean',
|
||||
@@ -136,7 +132,7 @@ let startCount = 0;
|
||||
async function restartServer() {
|
||||
try {
|
||||
await compileServerMain(true);
|
||||
await launchServer(true, argv.open && ++startCount === 1, argv.tcp); // only open on the first time
|
||||
await launchServer(true, ++startCount === 1, argv.tcp); // only open on the first time
|
||||
} catch (e) {
|
||||
console.error(
|
||||
chalk.red(
|
||||
@@ -190,12 +186,14 @@ async function startWatchChanges() {
|
||||
}
|
||||
await prepareDefaultPlugins(
|
||||
process.env.FLIPPER_RELEASE_CHANNEL === 'insiders',
|
||||
true,
|
||||
);
|
||||
await prepareHeadlessPlugins();
|
||||
await buildHeadlessPlugins(true);
|
||||
await buildServerAddOns(true);
|
||||
|
||||
// watch
|
||||
await startWatchChanges();
|
||||
await ensurePluginFoldersWatchable();
|
||||
// builds and starts
|
||||
await restartServer();
|
||||
// watch
|
||||
await startWatchChanges();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user