move node types, stub node modules

Summary: This diff stubs all node modules when running in the browser, so that, albeit with a lot of errors and without plugins, the UI loads in a browser. To be continued in the rest of this diff

Reviewed By: antonk52

Differential Revision: D32665705

fbshipit-source-id: 4632e241f59c5b9712a41d01a26878afb01f69b5
This commit is contained in:
Michel Weststrate
2021-12-08 04:25:28 -08:00
committed by Facebook GitHub Bot
parent d0402d7268
commit ad4a55f263
20 changed files with 137 additions and 50 deletions

View File

@@ -39,7 +39,8 @@ async function start() {
start()
.then(() => {
console.log(
`Flipper DEV server started at http://localhost:${PORT}/index.web.dev.html`,
'Flipper DEV server started at ' +
chalk.green(chalk.bold(`http://localhost:${PORT}/index.web.dev.html`)),
);
})
.catch((e) => {

View File

@@ -16,6 +16,9 @@ import socketio from 'socket.io';
import {getWatchFolders} from 'flipper-pkg-lib';
import Metro from 'metro';
import pFilter from 'p-filter';
// provided by Metro
// eslint-disable-next-line
import MetroResolver from 'metro-resolver';
const uiSourceDirs = [
'flipper-ui-browser',
@@ -24,6 +27,53 @@ const uiSourceDirs = [
'flipper-common',
];
const stubModules = new Set([
'fs',
'path',
'crypto',
'process',
'os',
'util',
'child_process',
'assert',
'adbkit', // TODO: factor out!
'zlib',
'events',
'fs-extra',
'archiver',
'graceful-fs',
'stream',
'url',
'node-fetch',
'net',
'vm',
'debug',
'lockfile',
'constants',
'https',
'plugin-lib', // TODO: we only want the types?
'flipper-plugin-lib',
'tar',
'minipass',
'live-plugin-manager',
'decompress-tar',
'readable-stream',
'archiver-utils',
'metro',
'decompress',
'temp',
'tmp',
'promisify-child-process',
'jsdom',
'extract-zip',
'yauzl',
'fd-slicer',
'envinfo',
'bser',
'fb-watchman',
// TODO fix me
]);
// This file is heavily inspired by scripts/start-dev-server.ts!
export async function startWebServerDev(
app: Express,
@@ -84,8 +134,27 @@ async function startMetroServer(
resolver: {
...baseConfig.resolver,
resolverMainFields: ['flipperBundlerEntry', 'browser', 'module', 'main'],
blacklistRE: /\.native\.js$/,
blacklistRE: [/\.native\.js$/],
sourceExts: ['js', 'jsx', 'ts', 'tsx', 'json', 'mjs', 'cjs'],
resolveRequest(context: any, moduleName: string, ...rest: any[]) {
if (stubModules.has(moduleName)) {
// console.warn("Found reference to ", moduleName)
return {
type: 'empty',
};
}
// if (moduleName.includes('pluginPaths')) {
// console.error('got ' + moduleName, rest);
// }
return MetroResolver.resolve(
{
...context,
resolveRequest: null,
},
moduleName,
...rest,
);
},
},
watch: true,
// only needed when medling with babel transforms