Skip to content

Commit 69ec95e

Browse files
committed
fix: resolve Metro websocket type errors
Align Metro endpoint typing and test fixtures with the merged startup APIs so package typecheck passes again.
1 parent 405a77a commit 69ec95e

6 files changed

Lines changed: 24 additions & 17 deletions

File tree

packages/bundler-metro/src/__tests__/startup.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const createMetroInstance = (
2727
overrides: Partial<MetroInstance> = {}
2828
): MetroInstance => ({
2929
events: getEmitter<ReportableEvent>(),
30+
httpServer: {} as never,
31+
websocketEndpoints: {},
3032
waitUntilHealthy: vi.fn(async () => 'HTTP 200: packager-status:running'),
3133
prewarm: vi.fn(async () => false),
3234
dispose: vi.fn(async () => undefined),

packages/bundler-metro/src/types.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
import type { Server as HttpServer, IncomingMessage } from 'node:http';
1+
import type { Server as HttpServer } from 'node:http';
22
import type { Server as HttpsServer } from 'node:https';
3-
import type { Duplex } from 'node:stream';
3+
import type { RunServerOptions } from 'metro';
44
import type { Reporter } from './reporter.js';
55
import type { Config as HarnessConfig } from '@react-native-harness/config';
66

7-
export type MetroWebSocketEndpoint = {
8-
handleUpgrade: (
9-
request: IncomingMessage,
10-
socket: Duplex,
11-
upgradeHead: Buffer,
12-
callback: (client: unknown, request: IncomingMessage) => void
13-
) => void;
14-
emit: (event: 'connection', client: unknown, request: IncomingMessage) => void;
15-
};
7+
export type MetroWebSocketEndpoints = NonNullable<
8+
RunServerOptions['websocketEndpoints']
9+
>;
10+
export type MetroWebSocketEndpoint = MetroWebSocketEndpoints[string];
1611

1712
export type MetroOptions = {
1813
projectRoot: string;
1914
harnessConfig: HarnessConfig;
20-
websocketEndpoints?: Record<string, MetroWebSocketEndpoint>;
15+
websocketEndpoints?: MetroWebSocketEndpoints;
2116
};
2217

2318
export type WaitForMetroHealthOptions = {
@@ -33,7 +28,7 @@ export type PrewarmMetroBundleOptions = {
3328
export type MetroInstance = {
3429
events: Reporter;
3530
httpServer: HttpServer | HttpsServer;
36-
websocketEndpoints: Record<string, MetroWebSocketEndpoint>;
31+
websocketEndpoints: MetroWebSocketEndpoints;
3732
waitUntilHealthy: (options: WaitForMetroHealthOptions) => Promise<string>;
3833
prewarm: (options: PrewarmMetroBundleOptions) => Promise<boolean>;
3934
dispose: () => Promise<void>;

packages/bundler-metro/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
{
1313
"path": "../tools"
1414
},
15+
{
16+
"path": "../bridge"
17+
},
1518
{
1619
"path": "../babel-preset"
1720
},

packages/bundler-metro/tsconfig.lib.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@
1313
"include": ["src/**/*.ts"],
1414
"references": [
1515
{
16-
"path": "../babel-preset/tsconfig.lib.json"
16+
"path": "../runtime/tsconfig.lib.json"
1717
},
1818
{
1919
"path": "../config/tsconfig.lib.json"
2020
},
2121
{
22-
"path": "../runtime/tsconfig.lib.json"
22+
"path": "../tools/tsconfig.lib.json"
2323
},
2424
{
25-
"path": "../tools/tsconfig.lib.json"
25+
"path": "../bridge/tsconfig.lib.json"
26+
},
27+
{
28+
"path": "../babel-preset/tsconfig.lib.json"
2629
}
2730
]
2831
}

packages/jest/src/__tests__/harness.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ const createMetroInstance = (
119119
overrides: Partial<MetroInstance> = {}
120120
): MetroInstance => ({
121121
events: createReporter(),
122+
httpServer: {} as never,
123+
websocketEndpoints: {},
122124
waitUntilHealthy: vi.fn(async () => 'HTTP 200: packager-status:running'),
123125
prewarm: vi.fn(async () => false),
124126
dispose: vi.fn(async () => undefined),

packages/jest/src/harness.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
isMetroCacheReusable,
2222
waitForMetroBackedAppReady,
2323
type MetroInstance,
24+
type MetroWebSocketEndpoint,
2425
type ReportableEvent,
2526
} from '@react-native-harness/bundler-metro';
2627
import {
@@ -293,7 +294,8 @@ const getHarnessInternal = async (
293294
projectRoot,
294295
harnessConfig: config,
295296
websocketEndpoints: {
296-
[HARNESS_BRIDGE_PATH]: serverBridge.ws,
297+
[HARNESS_BRIDGE_PATH]:
298+
serverBridge.ws as unknown as MetroWebSocketEndpoint,
297299
},
298300
},
299301
signal

0 commit comments

Comments
 (0)