Fix re-loading of source maps with "-fast-refresh" flag enabled
Summary: Fixed loading of source maps when dev server is running with --fast-refresh flag set. Looks like it was broken after last metro upgrade because it changed the way how module paths are passed to dev server. We also had a hack to workaround bug when requested module paths were malformed, but it looks this hack is not needed now, so I deleted it as well. Reviewed By: passy Differential Revision: D28120080 fbshipit-source-id: 03a39c9840da8f4c8c72be6189c0b71c62fac7f0
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1447ae0c18
commit
763eda8f6b
@@ -12,7 +12,7 @@ import {default as ReactRefreshRuntime} from 'react-refresh/runtime';
|
|||||||
|
|
||||||
HmrClient.setup(
|
HmrClient.setup(
|
||||||
'web',
|
'web',
|
||||||
'/src/init-fast-refresh.bundle',
|
'/app/src/init-fast-refresh.bundle',
|
||||||
'localhost',
|
'localhost',
|
||||||
'3000',
|
'3000',
|
||||||
true,
|
true,
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ import {hostname} from 'os';
|
|||||||
import {compileMain, generatePluginEntryPoints} from './build-utils';
|
import {compileMain, generatePluginEntryPoints} from './build-utils';
|
||||||
import Watchman from './watchman';
|
import Watchman from './watchman';
|
||||||
import Metro from 'metro';
|
import Metro from 'metro';
|
||||||
import MetroResolver from 'metro-resolver';
|
import {staticDir, babelTransformationsDir, rootDir} from './paths';
|
||||||
import {staticDir, appDir, babelTransformationsDir} from './paths';
|
|
||||||
import isFB from './isFB';
|
import isFB from './isFB';
|
||||||
import getAppWatchFolders from './get-app-watch-folders';
|
import getAppWatchFolders from './get-app-watch-folders';
|
||||||
import {getPluginSourceFolders} from 'flipper-plugin-lib';
|
import {getPluginSourceFolders} from 'flipper-plugin-lib';
|
||||||
@@ -167,7 +166,7 @@ function looksLikeDevServer(): boolean {
|
|||||||
function launchElectron(port: number) {
|
function launchElectron(port: number) {
|
||||||
const entry = process.env.FLIPPER_FAST_REFRESH ? 'init-fast-refresh' : 'init';
|
const entry = process.env.FLIPPER_FAST_REFRESH ? 'init-fast-refresh' : 'init';
|
||||||
const devServerURL = `http://localhost:${port}`;
|
const devServerURL = `http://localhost:${port}`;
|
||||||
const bundleURL = `http://localhost:${port}/src/${entry}.bundle?platform=web&dev=true&minify=false`;
|
const bundleURL = `http://localhost:${port}/app/src/${entry}.bundle?platform=web&dev=true&minify=false`;
|
||||||
const electronURL = `http://localhost:${port}/index.dev.html`;
|
const electronURL = `http://localhost:${port}/index.dev.html`;
|
||||||
const args = [
|
const args = [
|
||||||
path.join(staticDir, 'index.js'),
|
path.join(staticDir, 'index.js'),
|
||||||
@@ -210,7 +209,7 @@ async function startMetroServer(app: Express, server: http.Server) {
|
|||||||
);
|
);
|
||||||
const baseConfig = await Metro.loadConfig();
|
const baseConfig = await Metro.loadConfig();
|
||||||
const config = Object.assign({}, baseConfig, {
|
const config = Object.assign({}, baseConfig, {
|
||||||
projectRoot: appDir,
|
projectRoot: rootDir,
|
||||||
watchFolders,
|
watchFolders,
|
||||||
transformer: {
|
transformer: {
|
||||||
...baseConfig.transformer,
|
...baseConfig.transformer,
|
||||||
@@ -220,16 +219,6 @@ async function startMetroServer(app: Express, server: http.Server) {
|
|||||||
...baseConfig.resolver,
|
...baseConfig.resolver,
|
||||||
resolverMainFields: ['flipperBundlerEntry', 'module', 'main'],
|
resolverMainFields: ['flipperBundlerEntry', 'module', 'main'],
|
||||||
blacklistRE: /\.native\.js$/,
|
blacklistRE: /\.native\.js$/,
|
||||||
resolveRequest: (context: any, moduleName: string, platform: string) => {
|
|
||||||
if (moduleName.startsWith('./localhost:3000')) {
|
|
||||||
moduleName = moduleName.replace('./localhost:3000', '.');
|
|
||||||
}
|
|
||||||
return MetroResolver.resolve(
|
|
||||||
{...context, resolveRequest: null},
|
|
||||||
moduleName,
|
|
||||||
platform,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
sourceExts: ['js', 'jsx', 'ts', 'tsx', 'json', 'mjs', 'cjs'],
|
sourceExts: ['js', 'jsx', 'ts', 'tsx', 'json', 'mjs', 'cjs'],
|
||||||
},
|
},
|
||||||
watch: true,
|
watch: true,
|
||||||
@@ -376,6 +365,7 @@ function outputScreen(socket?: socketIo.Server) {
|
|||||||
// output screen
|
// output screen
|
||||||
if (hasErrors()) {
|
if (hasErrors()) {
|
||||||
const errorScreen = buildErrorScreen();
|
const errorScreen = buildErrorScreen();
|
||||||
|
// eslint-disable-next-line flipper/no-console-error-without-context
|
||||||
console.error(errorScreen);
|
console.error(errorScreen);
|
||||||
|
|
||||||
// notify live clients of errors
|
// notify live clients of errors
|
||||||
|
|||||||
Reference in New Issue
Block a user