@callstack/repack-dev-server 5.2.5-canary-20260305211900 → 5.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/createServer.js
CHANGED
|
@@ -12,6 +12,7 @@ import multipartPlugin from './plugins/multipart/multipartPlugin.js';
|
|
|
12
12
|
import symbolicatePlugin from './plugins/symbolicate/sybmolicatePlugin.js';
|
|
13
13
|
import wssPlugin from './plugins/wss/wssPlugin.js';
|
|
14
14
|
import { Internal } from './types.js';
|
|
15
|
+
import { handleCustomNetworkLoadResource } from './utils/networkLoadResourceHandler.js';
|
|
15
16
|
import { normalizeOptions } from './utils/normalizeOptions.js';
|
|
16
17
|
/**
|
|
17
18
|
* Create instance of development server, powered by Fastify.
|
|
@@ -93,15 +94,13 @@ export async function createServer(config) {
|
|
|
93
94
|
}
|
|
94
95
|
},
|
|
95
96
|
},
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
// prevent fetching source maps over the network for MF2 remotes
|
|
97
|
+
// Preserve RN default handling for same-origin resources while
|
|
98
|
+
// allowing remote-origin source maps/resources to be loaded here.
|
|
99
99
|
unstable_customInspectorMessageHandler: (connection) => {
|
|
100
100
|
return {
|
|
101
101
|
handleDeviceMessage: () => { },
|
|
102
102
|
handleDebuggerMessage: (msg) => {
|
|
103
|
-
if (msg
|
|
104
|
-
connection.device.sendMessage(msg);
|
|
103
|
+
if (handleCustomNetworkLoadResource(connection, msg, options.url)) {
|
|
105
104
|
return true;
|
|
106
105
|
}
|
|
107
106
|
},
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const NETWORK_LOAD_RESOURCE_ERROR = {
|
|
2
|
+
success: false,
|
|
3
|
+
netErrorName: 'net::ERR_FAILED',
|
|
4
|
+
netError: -2,
|
|
5
|
+
httpStatusCode: 500,
|
|
6
|
+
};
|
|
7
|
+
async function sendNetworkLoadResourceResponse(connection, id, url) {
|
|
8
|
+
// DevTools expects the loaded resource body to be returned as Base64-encoded
|
|
9
|
+
// bytes in the CDP response payload.
|
|
10
|
+
const response = await fetch(url).catch(() => null);
|
|
11
|
+
const resource = !response
|
|
12
|
+
? NETWORK_LOAD_RESOURCE_ERROR
|
|
13
|
+
: {
|
|
14
|
+
success: true,
|
|
15
|
+
httpStatusCode: response.status,
|
|
16
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
17
|
+
content: Buffer.from(await response.text()).toString('base64'),
|
|
18
|
+
base64Encoded: true,
|
|
19
|
+
};
|
|
20
|
+
connection.debugger.sendMessage({ id, result: { resource } });
|
|
21
|
+
}
|
|
22
|
+
// RN dev-middleware already handles same-origin requests. We only intercept
|
|
23
|
+
// cross-origin requests here so the original debugger behavior stays intact for
|
|
24
|
+
// the local server while MF-style remote resources can still be fetched.
|
|
25
|
+
//
|
|
26
|
+
// The custom inspector hook must synchronously return `true` when it takes
|
|
27
|
+
// ownership of a message, so we start the async fetch and report handling now.
|
|
28
|
+
export function handleCustomNetworkLoadResource(connection, message, serverBaseUrl) {
|
|
29
|
+
if (typeof message !== 'object' || message === null) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const request = message;
|
|
33
|
+
if (request.method !== 'Network.loadNetworkResource' ||
|
|
34
|
+
typeof request.id !== 'number' ||
|
|
35
|
+
typeof request.params?.url !== 'string' ||
|
|
36
|
+
!URL.canParse(request.params.url) ||
|
|
37
|
+
!URL.canParse(serverBaseUrl)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (new URL(request.params.url).origin === new URL(serverBaseUrl).origin) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
void sendNetworkLoadResourceResponse(connection, request.id, request.params.url).catch(() => console.error('[DevServer] Failed to send Network.loadNetworkResource response'));
|
|
44
|
+
return true;
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@callstack/repack-dev-server",
|
|
3
3
|
"description": "A bundler-agnostic development server for React Native applications as part of @callstack/repack.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "5.2.5
|
|
5
|
+
"version": "5.2.5",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
@@ -50,11 +50,14 @@
|
|
|
50
50
|
"@types/babel__code-frame": "^7.0.6",
|
|
51
51
|
"@types/node": "^20.19.31",
|
|
52
52
|
"@types/ws": "^8.18.0",
|
|
53
|
-
"typescript": "^5.
|
|
53
|
+
"typescript": "^5.9.3",
|
|
54
|
+
"vitest": "^4.1.0"
|
|
54
55
|
},
|
|
55
56
|
"scripts": {
|
|
56
|
-
"build": "tsc -b",
|
|
57
|
+
"build": "tsc -b tsconfig.build.json",
|
|
57
58
|
"typecheck": "tsc --noEmit",
|
|
59
|
+
"test": "vitest run",
|
|
60
|
+
"test:watch": "vitest",
|
|
58
61
|
"archive": "pnpm build && pnpm pack"
|
|
59
62
|
}
|
|
60
63
|
}
|