mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Drop legacy cli-server-api reference in dev server (#57653)
Summary: Pull Request resolved: https://github.com/react/react-native/pull/57653 Actions TODO comment dependant on https://github.com/react-native-community/cli/pull/2605 (landed). This drops our local dependency on `react-native-community/cli-server-api` Flow types, as well as avoiding this transient dependency in end user projects. **Other changes** - Promote `debug` log to a user-facing `warn` — several features in RN will break/degrade in this case and we want to flag explicitly. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D113412986 fbshipit-source-id: a47c9cfea53a3f77259fd6c5fdbf48d953616377
This commit is contained in:
1 parent
aee0ec3bd5
commit
14c3bd831d
2 files changed
+5
-60
No files matched your search
@@ -1,44 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict
|
||||
* @format
|
||||
*/
|
||||
|
||||
declare module '@react-native-community/cli-server-api' {
|
||||
import type {NextHandleFunction, Server} from 'connect';
|
||||
|
||||
declare type MiddlewareOptions = {
|
||||
host?: string,
|
||||
watchFolders: ReadonlyArray<string>,
|
||||
port: number,
|
||||
};
|
||||
|
||||
declare export function createDevServerMiddleware(
|
||||
options: MiddlewareOptions,
|
||||
): {
|
||||
middleware: Server,
|
||||
websocketEndpoints: {
|
||||
[path: string]: ws$WebSocketServer,
|
||||
},
|
||||
debuggerProxyEndpoint: {
|
||||
server: ws$WebSocketServer,
|
||||
isDebuggerConnected: () => boolean,
|
||||
},
|
||||
messageSocketEndpoint: {
|
||||
server: ws$WebSocketServer,
|
||||
broadcast: (
|
||||
method: string,
|
||||
params?: Record<string, unknown> | null,
|
||||
) => void,
|
||||
},
|
||||
eventsSocketEndpoint: {
|
||||
server: ws$WebSocketServer,
|
||||
reportEvent: (event: any) => void,
|
||||
},
|
||||
...
|
||||
};
|
||||
}
|
||||
@@ -11,8 +11,6 @@
|
||||
import type {Server} from 'connect';
|
||||
import type {TerminalReportableEvent} from 'metro';
|
||||
|
||||
const debug = require('debug')('ReactNative:CommunityCliPlugin');
|
||||
|
||||
type DevServerMiddlewareFactory = (params: {
|
||||
host?: string,
|
||||
port: number,
|
||||
@@ -73,21 +71,12 @@ export default function loadCommunityMiddleware(): DevServerMiddlewareFactory {
|
||||
// `@react-native-community/cli` is an optional peer dependency of this
|
||||
// package, and should be a dev dependency of the host project (via the
|
||||
// community template's package.json).
|
||||
const communityCliPath = require.resolve('@react-native-community/cli');
|
||||
|
||||
// Until https://github.com/react-native-community/cli/pull/2605 lands,
|
||||
// we need to find `@react-native-community/cli-server-api` via
|
||||
// `@react-native-community/cli`. Once that lands, we can simply
|
||||
// require('@react-native-community/cli').
|
||||
const communityCliServerApiPath = require.resolve(
|
||||
'@react-native-community/cli-server-api',
|
||||
{paths: [communityCliPath]},
|
||||
);
|
||||
// $FlowFixMe[unsupported-syntax] dynamic import
|
||||
return require(communityCliServerApiPath).createDevServerMiddleware;
|
||||
// $FlowFixMe[prop-missing]
|
||||
// $FlowFixMe[untyped-import]
|
||||
return require('@react-native-community/cli').createDevServerMiddleware;
|
||||
} catch {
|
||||
debug(`⚠️ Unable to find @react-native-community/cli-server-api
|
||||
Starting the server without the community middleware.`);
|
||||
console.warn(`⚠️ Unable to find @react-native-community/cli.
|
||||
Starting dev server without community middleware endpoints - some functionality may be broken.`);
|
||||
return communityMiddlewareFallback;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user