@callstack/repack-dev-server 5.0.0-rc.0 → 5.0.0-rc.2
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/CHANGELOG.md +4 -0
- package/dist/createServer.js +2 -13
- package/dist/createServer.js.map +1 -1
- package/dist/plugins/devtools/devtoolsPlugin.js +5 -29
- package/dist/plugins/devtools/devtoolsPlugin.js.map +1 -1
- package/dist/plugins/symbolicate/Symbolicator.js +1 -1
- package/dist/plugins/symbolicate/Symbolicator.js.map +1 -1
- package/dist/plugins/wss/wssPlugin.d.ts +0 -2
- package/dist/plugins/wss/wssPlugin.js +0 -4
- package/dist/plugins/wss/wssPlugin.js.map +1 -1
- package/dist/types.d.ts +0 -4
- package/dist/types.js.map +1 -1
- package/package.json +4 -10
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.d.ts +0 -63
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.js +0 -142
- package/dist/plugins/wss/servers/WebSocketDebuggerServer.js.map +0 -1
package/CHANGELOG.md
CHANGED
package/dist/createServer.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Writable } from 'node:stream';
|
|
2
2
|
import middie from '@fastify/middie';
|
|
3
3
|
import fastifySensible from '@fastify/sensible';
|
|
4
|
-
import { debuggerUIMiddleware } from '@react-native-community/cli-debugger-ui';
|
|
5
|
-
import { openStackFrameInEditorMiddleware, openURLMiddleware } from '@react-native-community/cli-server-api';
|
|
6
4
|
import { createDevMiddleware } from '@react-native/dev-middleware';
|
|
7
5
|
import Fastify from 'fastify';
|
|
8
6
|
import apiPlugin from "./plugins/api/index.js";
|
|
@@ -70,7 +68,8 @@ export async function createServer(config) {
|
|
|
70
68
|
serverBaseUrl: `http://${config.options.host}:${config.options.port}`,
|
|
71
69
|
logger: instance.log,
|
|
72
70
|
unstable_experiments: {
|
|
73
|
-
|
|
71
|
+
// @ts-expect-error removed in 0.76, keep this for backkwards compatibility
|
|
72
|
+
enableNewDebugger: true
|
|
74
73
|
}
|
|
75
74
|
});
|
|
76
75
|
|
|
@@ -92,19 +91,9 @@ export async function createServer(config) {
|
|
|
92
91
|
await instance.register(compilerPlugin, {
|
|
93
92
|
delegate
|
|
94
93
|
});
|
|
95
|
-
|
|
96
|
-
// TODO: devtoolsPlugin and the following deprecated remote debugger middlewares should be removed after
|
|
97
|
-
// the new (experimental) debugger is stable AND the remote debugger is finally removed from the React Native core.
|
|
98
|
-
// When that happens remember to remove @react-native-community/cli-server-api & @react-native-community/cli-debugger-ui
|
|
99
|
-
// from the dependencies.
|
|
100
94
|
await instance.register(devtoolsPlugin, {
|
|
101
95
|
options: config.options
|
|
102
96
|
});
|
|
103
|
-
instance.use('/debugger-ui', debuggerUIMiddleware());
|
|
104
|
-
instance.use('/open-url', openURLMiddleware);
|
|
105
|
-
instance.use('/open-stack-frame', openStackFrameInEditorMiddleware({
|
|
106
|
-
watchFolders: [config.options.rootDir]
|
|
107
|
-
}));
|
|
108
97
|
await instance.register(symbolicatePlugin, {
|
|
109
98
|
delegate
|
|
110
99
|
});
|
package/dist/createServer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createServer.js","names":["Writable","middie","fastifySensible","debuggerUIMiddleware","openStackFrameInEditorMiddleware","openURLMiddleware","createDevMiddleware","Fastify","apiPlugin","compilerPlugin","devtoolsPlugin","faviconPlugin","multipartPlugin","symbolicatePlugin","wssPlugin","Internal","createServer","config","delegate","instance","disableRequestLogging","options","logRequests","logger","level","stream","write","chunk","_encoding","callback","log","JSON","parse","toString","onMessage","wss","apiServer","send","https","undefined","notifyBuildStart","platform","event","EventTypes","BuildStart","notifyBuildEnd","BuildEnd","broadcastToHmrClients","clientIds","hmrServer","broadcastToMessageClients","method","params","messageServer","broadcast","devMiddleware","projectRoot","rootDir","serverBaseUrl","host","port","unstable_experiments","enableNewDebugger","experiments","experimentalDebugger","register","endpoints","websocketEndpoints","prefix","use","watchFolders","addHook","request","reply","payload","header","pathname","url","split","endsWith","middleware","get","messages","getHello","getStatus","start","listen","stop","close"],"sources":["../src/createServer.ts"],"sourcesContent":["import { Writable } from 'node:stream';\nimport middie from '@fastify/middie';\nimport fastifySensible from '@fastify/sensible';\nimport { debuggerUIMiddleware } from '@react-native-community/cli-debugger-ui';\nimport {\n openStackFrameInEditorMiddleware,\n openURLMiddleware,\n} from '@react-native-community/cli-server-api';\nimport { createDevMiddleware } from '@react-native/dev-middleware';\nimport Fastify from 'fastify';\nimport apiPlugin from './plugins/api';\nimport compilerPlugin from './plugins/compiler';\nimport devtoolsPlugin from './plugins/devtools';\nimport faviconPlugin from './plugins/favicon';\nimport multipartPlugin from './plugins/multipart';\nimport symbolicatePlugin from './plugins/symbolicate';\nimport wssPlugin from './plugins/wss';\nimport { Internal, type Server } from './types';\n\n/**\n * Create instance of development server, powered by Fastify.\n *\n * @param config Server configuration.\n * @returns `start` and `stop` functions as well as an underlying Fastify `instance`.\n */\nexport async function createServer(config: Server.Config) {\n // biome-ignore lint/style/useConst: needed in fastify constructor\n let delegate: Server.Delegate;\n\n /** Fastify instance powering the development server. */\n const instance = Fastify({\n disableRequestLogging: !config.options.logRequests,\n logger: {\n level: 'trace',\n stream: new Writable({\n write: (chunk, _encoding, callback) => {\n const log = JSON.parse(chunk.toString());\n delegate?.logger.onMessage(log);\n instance.wss?.apiServer.send(log);\n callback();\n },\n }),\n },\n ...(config.options.https ? { https: config.options.https } : undefined),\n });\n\n delegate = await config.delegate({\n log: instance.log,\n notifyBuildStart: (platform) => {\n instance.wss.apiServer.send({\n event: Internal.EventTypes.BuildStart,\n platform,\n });\n },\n notifyBuildEnd: (platform) => {\n instance.wss.apiServer.send({\n event: Internal.EventTypes.BuildEnd,\n platform,\n });\n },\n broadcastToHmrClients: (event, platform, clientIds) => {\n instance.wss.hmrServer.send(event, platform, clientIds);\n },\n broadcastToMessageClients: ({ method, params }) => {\n instance.wss.messageServer.broadcast(method, params);\n },\n });\n\n const devMiddleware = createDevMiddleware({\n projectRoot: config.options.rootDir,\n serverBaseUrl: `http://${config.options.host}:${config.options.port}`,\n logger: instance.log,\n unstable_experiments: {\n enableNewDebugger: config.experiments?.experimentalDebugger,\n },\n });\n\n // Register plugins\n await instance.register(fastifySensible);\n await instance.register(middie);\n await instance.register(wssPlugin, {\n options: {\n ...config.options,\n endpoints: devMiddleware.websocketEndpoints,\n },\n delegate,\n });\n await instance.register(multipartPlugin);\n await instance.register(apiPlugin, {\n delegate,\n prefix: '/api',\n });\n await instance.register(compilerPlugin, {\n delegate,\n });\n\n // TODO: devtoolsPlugin and the following deprecated remote debugger middlewares should be removed after\n // the new (experimental) debugger is stable AND the remote debugger is finally removed from the React Native core.\n // When that happens remember to remove @react-native-community/cli-server-api & @react-native-community/cli-debugger-ui\n // from the dependencies.\n await instance.register(devtoolsPlugin, {\n options: config.options,\n });\n instance.use('/debugger-ui', debuggerUIMiddleware());\n instance.use('/open-url', openURLMiddleware);\n instance.use(\n '/open-stack-frame',\n openStackFrameInEditorMiddleware({\n watchFolders: [config.options.rootDir],\n })\n );\n\n await instance.register(symbolicatePlugin, {\n delegate,\n });\n\n // below is to prevent showing `GET 400 /favicon.ico`\n // errors in console when requesting the bundle via browser\n await instance.register(faviconPlugin);\n\n instance.addHook('onSend', async (request, reply, payload) => {\n reply.header('X-Content-Type-Options', 'nosniff');\n reply.header('X-React-Native-Project-Root', config.options.rootDir);\n\n const [pathname] = request.url.split('?');\n if (pathname.endsWith('.map')) {\n reply.header('Access-Control-Allow-Origin', 'devtools://devtools');\n }\n\n return payload;\n });\n\n // Register dev middleware\n instance.use(devMiddleware.middleware);\n\n // Register routes\n instance.get('/', async () => delegate.messages.getHello());\n instance.get('/status', async () => delegate.messages.getStatus());\n\n /** Start the development server. */\n async function start() {\n await instance.listen({\n port: config.options.port,\n host: config.options.host,\n });\n }\n\n /** Stop the development server. */\n async function stop() {\n await instance.close();\n }\n\n return {\n start,\n stop,\n instance,\n };\n}\n"],"mappings":"AAAA,SAASA,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AAC,GAAGJ,OAAO,CAACK,GAAG,CAACC,KAAK,CAAC,GAAG,CAAC;IACzC,IAAIF,QAAQ,CAACG,QAAQ,CAAC,MAAM,CAAC,EAAE;MAC7BN,KAAK,CAACE,MAAM,CAAC,6BAA6B,EAAE,qBAAqB,CAAC;IACpE;IAEA,OAAOD,OAAO;EAChB,CAAC,CAAC;;EAEF;EACAvD,QAAQ,CAACkD,GAAG,CAACd,aAAa,CAACyB,UAAU,CAAC;;EAEtC;EACA7D,QAAQ,CAAC8D,GAAG,CAAC,GAAG,EAAE,YAAY/D,QAAQ,CAACgE,QAAQ,CAACC,QAAQ,CAAC,CAAC,CAAC;EAC3DhE,QAAQ,CAAC8D,GAAG,CAAC,SAAS,EAAE,YAAY/D,QAAQ,CAACgE,QAAQ,CAACE,SAAS,CAAC,CAAC,CAAC;;EAElE;EACA,eAAeC,KAAKA,CAAA,EAAG;IACrB,MAAMlE,QAAQ,CAACmE,MAAM,CAAC;MACpB1B,IAAI,EAAE3C,MAAM,CAACI,OAAO,CAACuC,IAAI;MACzBD,IAAI,EAAE1C,MAAM,CAACI,OAAO,CAACsC;IACvB,CAAC,CAAC;EACJ;;EAEA;EACA,eAAe4B,IAAIA,CAAA,EAAG;IACpB,MAAMpE,QAAQ,CAACqE,KAAK,CAAC,CAAC;EACxB;EAEA,OAAO;IACLH,KAAK;IACLE,IAAI;IACJpE;EACF,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"createServer.js","names":["Writable","middie","fastifySensible","createDevMiddleware","Fastify","apiPlugin","compilerPlugin","devtoolsPlugin","faviconPlugin","multipartPlugin","symbolicatePlugin","wssPlugin","Internal","createServer","config","delegate","instance","disableRequestLogging","options","logRequests","logger","level","stream","write","chunk","_encoding","callback","log","JSON","parse","toString","onMessage","wss","apiServer","send","https","undefined","notifyBuildStart","platform","event","EventTypes","BuildStart","notifyBuildEnd","BuildEnd","broadcastToHmrClients","clientIds","hmrServer","broadcastToMessageClients","method","params","messageServer","broadcast","devMiddleware","projectRoot","rootDir","serverBaseUrl","host","port","unstable_experiments","enableNewDebugger","register","endpoints","websocketEndpoints","prefix","addHook","request","reply","payload","header","pathname","url","split","endsWith","use","middleware","get","messages","getHello","getStatus","start","listen","stop","close"],"sources":["../src/createServer.ts"],"sourcesContent":["import { Writable } from 'node:stream';\nimport middie from '@fastify/middie';\nimport fastifySensible from '@fastify/sensible';\nimport { createDevMiddleware } from '@react-native/dev-middleware';\nimport Fastify from 'fastify';\nimport apiPlugin from './plugins/api';\nimport compilerPlugin from './plugins/compiler';\nimport devtoolsPlugin from './plugins/devtools';\nimport faviconPlugin from './plugins/favicon';\nimport multipartPlugin from './plugins/multipart';\nimport symbolicatePlugin from './plugins/symbolicate';\nimport wssPlugin from './plugins/wss';\nimport { Internal, type Server } from './types';\n\n/**\n * Create instance of development server, powered by Fastify.\n *\n * @param config Server configuration.\n * @returns `start` and `stop` functions as well as an underlying Fastify `instance`.\n */\nexport async function createServer(config: Server.Config) {\n // biome-ignore lint/style/useConst: needed in fastify constructor\n let delegate: Server.Delegate;\n\n /** Fastify instance powering the development server. */\n const instance = Fastify({\n disableRequestLogging: !config.options.logRequests,\n logger: {\n level: 'trace',\n stream: new Writable({\n write: (chunk, _encoding, callback) => {\n const log = JSON.parse(chunk.toString());\n delegate?.logger.onMessage(log);\n instance.wss?.apiServer.send(log);\n callback();\n },\n }),\n },\n ...(config.options.https ? { https: config.options.https } : undefined),\n });\n\n delegate = await config.delegate({\n log: instance.log,\n notifyBuildStart: (platform) => {\n instance.wss.apiServer.send({\n event: Internal.EventTypes.BuildStart,\n platform,\n });\n },\n notifyBuildEnd: (platform) => {\n instance.wss.apiServer.send({\n event: Internal.EventTypes.BuildEnd,\n platform,\n });\n },\n broadcastToHmrClients: (event, platform, clientIds) => {\n instance.wss.hmrServer.send(event, platform, clientIds);\n },\n broadcastToMessageClients: ({ method, params }) => {\n instance.wss.messageServer.broadcast(method, params);\n },\n });\n\n const devMiddleware = createDevMiddleware({\n projectRoot: config.options.rootDir,\n serverBaseUrl: `http://${config.options.host}:${config.options.port}`,\n logger: instance.log,\n unstable_experiments: {\n // @ts-expect-error removed in 0.76, keep this for backkwards compatibility\n enableNewDebugger: true,\n },\n });\n\n // Register plugins\n await instance.register(fastifySensible);\n await instance.register(middie);\n await instance.register(wssPlugin, {\n options: {\n ...config.options,\n endpoints: devMiddleware.websocketEndpoints,\n },\n delegate,\n });\n await instance.register(multipartPlugin);\n await instance.register(apiPlugin, {\n delegate,\n prefix: '/api',\n });\n await instance.register(compilerPlugin, {\n delegate,\n });\n await instance.register(devtoolsPlugin, {\n options: config.options,\n });\n await instance.register(symbolicatePlugin, {\n delegate,\n });\n\n // below is to prevent showing `GET 400 /favicon.ico`\n // errors in console when requesting the bundle via browser\n await instance.register(faviconPlugin);\n\n instance.addHook('onSend', async (request, reply, payload) => {\n reply.header('X-Content-Type-Options', 'nosniff');\n reply.header('X-React-Native-Project-Root', config.options.rootDir);\n\n const [pathname] = request.url.split('?');\n if (pathname.endsWith('.map')) {\n reply.header('Access-Control-Allow-Origin', 'devtools://devtools');\n }\n\n return payload;\n });\n\n // Register dev middleware\n instance.use(devMiddleware.middleware);\n\n // Register routes\n instance.get('/', async () => delegate.messages.getHello());\n instance.get('/status', async () => delegate.messages.getStatus());\n\n /** Start the development server. */\n async function start() {\n await instance.listen({\n port: config.options.port,\n host: config.options.host,\n });\n }\n\n /** Stop the development server. */\n async function stop() {\n await instance.close();\n }\n\n return {\n start,\n stop,\n instance,\n };\n}\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,aAAa;AACtC,OAAOC,MAAM,MAAM,iBAAiB;AACpC,OAAOC,eAAe,MAAM,mBAAmB;AAC/C,SAASC,mBAAmB,QAAQ,8BAA8B;AAClE,OAAOC,OAAO,MAAM,SAAS;AAAC,OACvBC,SAAS;AAAA,OACTC,cAAc;AAAA,OACdC,cAAc;AAAA,OACdC,aAAa;AAAA,OACbC,eAAe;AAAA,OACfC,iBAAiB;AAAA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IACvB,CAAC,CAAC;EACJ;;EAEA;EACA,eAAeyB,IAAIA,CAAA,EAAG;IACpB,MAAMjE,QAAQ,CAACkE,KAAK,CAAC,CAAC;EACxB;EAEA,OAAO;IACLH,KAAK;IACLE,IAAI;IACJjE;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { openStackFrameInEditorMiddleware, openURLMiddleware } from '@react-native-community/cli-server-api';
|
|
1
2
|
import fastifyPlugin from 'fastify-plugin';
|
|
2
|
-
import open from 'open';
|
|
3
3
|
async function devtoolsPlugin(instance, {
|
|
4
4
|
options
|
|
5
5
|
}) {
|
|
6
|
+
instance.use('/open-url', openURLMiddleware);
|
|
7
|
+
instance.use('/open-stack-frame', openStackFrameInEditorMiddleware({
|
|
8
|
+
watchFolders: [options.rootDir]
|
|
9
|
+
}));
|
|
6
10
|
instance.route({
|
|
7
11
|
method: ['GET', 'POST', 'PUT'],
|
|
8
12
|
url: '/reload',
|
|
@@ -11,34 +15,6 @@ async function devtoolsPlugin(instance, {
|
|
|
11
15
|
reply.send('OK');
|
|
12
16
|
}
|
|
13
17
|
});
|
|
14
|
-
instance.route({
|
|
15
|
-
method: ['GET', 'POST', 'PUT'],
|
|
16
|
-
url: '/launch-js-devtools',
|
|
17
|
-
handler: async (request, reply) => {
|
|
18
|
-
const customDebugger = process.env.REACT_DEBUGGER;
|
|
19
|
-
if (customDebugger) {
|
|
20
|
-
// NOOP for now
|
|
21
|
-
} else if (!instance.wss.debuggerServer.isDebuggerConnected()) {
|
|
22
|
-
const url = `${options.https ? 'https' : 'http'}://${options.host || 'localhost'}:${options.port}/debugger-ui`;
|
|
23
|
-
try {
|
|
24
|
-
request.log.info({
|
|
25
|
-
msg: 'Opening debugger UI',
|
|
26
|
-
url
|
|
27
|
-
});
|
|
28
|
-
await open(url);
|
|
29
|
-
} catch (error) {
|
|
30
|
-
if (error) {
|
|
31
|
-
request.log.error({
|
|
32
|
-
msg: 'Cannot open debugger UI',
|
|
33
|
-
url,
|
|
34
|
-
error
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
reply.send('OK');
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
18
|
}
|
|
43
19
|
export default fastifyPlugin(devtoolsPlugin, {
|
|
44
20
|
name: 'devtools-plugin',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtoolsPlugin.js","names":["
|
|
1
|
+
{"version":3,"file":"devtoolsPlugin.js","names":["openStackFrameInEditorMiddleware","openURLMiddleware","fastifyPlugin","devtoolsPlugin","instance","options","use","watchFolders","rootDir","route","method","url","handler","_request","reply","wss","messageServer","broadcast","send","name","dependencies"],"sources":["../../../src/plugins/devtools/devtoolsPlugin.ts"],"sourcesContent":["import {\n openStackFrameInEditorMiddleware,\n openURLMiddleware,\n} from '@react-native-community/cli-server-api';\nimport type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { Server } from '../../types';\n\nasync function devtoolsPlugin(\n instance: FastifyInstance,\n { options }: { options: Server.Options }\n) {\n instance.use('/open-url', openURLMiddleware);\n\n instance.use(\n '/open-stack-frame',\n openStackFrameInEditorMiddleware({\n watchFolders: [options.rootDir],\n })\n );\n\n instance.route({\n method: ['GET', 'POST', 'PUT'],\n url: '/reload',\n handler: (_request, reply) => {\n instance.wss.messageServer.broadcast('reload');\n reply.send('OK');\n },\n });\n}\n\nexport default fastifyPlugin(devtoolsPlugin, {\n name: 'devtools-plugin',\n dependencies: ['wss-plugin'],\n});\n"],"mappings":"AAAA,SACEA,gCAAgC,EAChCC,iBAAiB,QACZ,wCAAwC;AAE/C,OAAOC,aAAa,MAAM,gBAAgB;AAG1C,eAAeC,cAAcA,CAC3BC,QAAyB,EACzB;EAAEC;AAAqC,CAAC,EACxC;EACAD,QAAQ,CAACE,GAAG,CAAC,WAAW,EAAEL,iBAAiB,CAAC;EAE5CG,QAAQ,CAACE,GAAG,CACV,mBAAmB,EACnBN,gCAAgC,CAAC;IAC/BO,YAAY,EAAE,CAACF,OAAO,CAACG,OAAO;EAChC,CAAC,CACH,CAAC;EAEDJ,QAAQ,CAACK,KAAK,CAAC;IACbC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;IAC9BC,GAAG,EAAE,SAAS;IACdC,OAAO,EAAEA,CAACC,QAAQ,EAAEC,KAAK,KAAK;MAC5BV,QAAQ,CAACW,GAAG,CAACC,aAAa,CAACC,SAAS,CAAC,QAAQ,CAAC;MAC9CH,KAAK,CAACI,IAAI,CAAC,IAAI,CAAC;IAClB;EACF,CAAC,CAAC;AACJ;AAEA,eAAehB,aAAa,CAACC,cAAc,EAAE;EAC3CgB,IAAI,EAAE,iBAAiB;EACvBC,YAAY,EAAE,CAAC,YAAY;AAC7B,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Symbolicator.js","names":["URL","codeFrameColumns","SourceMapConsumer","Symbolicator","inferPlatformFromStack","stack","frame","file","searchParams","pathname","platform","get","bundleFilename","split","reverse","platformOrExtension","extension","sourceMapConsumerCache","constructor","delegate","process","logger","debug","msg","frames","startsWith","includes","push","processedFrames","fileUrl","rawSourceMap","getSourceMap","sourceMapLength","length","sourceMapConsumer","toString","processedFrame","processFrame","codeFrame","getCodeFrame","key","destroy","lineNumber","column","collapse","consumer","lookup","originalPositionFor","line","bias","LEAST_UPPER_BOUND","source","methodName","name","shouldIncludeFrame","undefined","content","getSource","start","forceColor","location","row","fileName","error","message"],"sources":["../../../src/plugins/symbolicate/Symbolicator.ts"],"sourcesContent":["import { URL } from 'node:url';\nimport { codeFrameColumns } from '@babel/code-frame';\nimport type { FastifyLoggerInstance } from 'fastify';\nimport { SourceMapConsumer } from 'source-map';\nimport type {\n CodeFrame,\n InputStackFrame,\n ReactNativeStackFrame,\n StackFrame,\n SymbolicatorDelegate,\n SymbolicatorResults,\n} from './types';\n\n/**\n * Class for transforming stack traces from React Native application with using Source Map.\n * Raw stack frames produced by React Native, points to some location from the bundle\n * eg `index.bundle?platform=ios:567:1234`. By using Source Map for that bundle `Symbolicator`\n * produces frames that point to source code inside your project eg `Hello.tsx:10:9`.\n */\nexport class Symbolicator {\n /**\n * Infer platform from stack frames.\n * Usually at least one frame has `file` field with the bundle URL eg:\n * `http://localhost:8081/index.bundle?platform=ios&...`, which can be used to infer platform.\n *\n * @param stack Array of stack frames.\n * @returns Inferred platform or `undefined` if cannot infer.\n */\n static inferPlatformFromStack(stack: ReactNativeStackFrame[]) {\n for (const frame of stack) {\n if (!frame.file) {\n continue;\n }\n\n const { searchParams, pathname } = new URL(frame.file, 'file://');\n const platform = searchParams.get('platform');\n if (platform) {\n return platform;\n }\n const [bundleFilename] = pathname.split('/').reverse();\n const [, platformOrExtension, extension] = bundleFilename.split('.');\n if (extension) {\n return platformOrExtension;\n }\n }\n }\n\n /**\n * Cache with initialized `SourceMapConsumer` to improve symbolication performance.\n */\n sourceMapConsumerCache: Record<string, SourceMapConsumer> = {};\n\n /**\n * Constructs new `Symbolicator` instance.\n *\n * @param delegate Delegate instance with symbolication functions.\n */\n constructor(private delegate: SymbolicatorDelegate) {}\n\n /**\n * Process raw React Native stack frames and transform them using Source Maps.\n * Method will try to symbolicate as much data as possible, but if the Source Maps\n * are not available, invalid or the original positions/data is not found in Source Maps,\n * the method will return raw values - the same as supplied with `stack` parameter.\n * For example out of 10 frames, it's possible that only first 7 will be symbolicated and the\n * remaining 3 will be unchanged.\n *\n * @param logger Fastify logger instance.\n * @param stack Raw stack frames.\n * @returns Symbolicated stack frames.\n */\n async process(\n logger: FastifyLoggerInstance,\n stack: ReactNativeStackFrame[]\n ): Promise<SymbolicatorResults> {\n logger.debug({ msg: 'Filtering out unnecessary frames' });\n\n const frames: InputStackFrame[] = [];\n for (const frame of stack) {\n const { file } = frame;\n if (file?.startsWith('http') && !file.includes('debuggerWorker')) {\n frames.push(frame as InputStackFrame);\n }\n }\n\n try {\n logger.debug({ msg: 'Processing frames', frames });\n\n const processedFrames: StackFrame[] = [];\n for (const frame of frames) {\n if (!this.sourceMapConsumerCache[frame.file]) {\n logger.debug({\n msg: 'Loading raw source map data',\n fileUrl: frame.file,\n });\n\n const rawSourceMap = await this.delegate.getSourceMap(frame.file);\n\n logger.debug({\n msg: 'Creating source map instance',\n fileUrl: frame.file,\n sourceMapLength: rawSourceMap.length,\n });\n const sourceMapConsumer = await new SourceMapConsumer(\n rawSourceMap.toString()\n );\n\n logger.debug({\n msg: 'Saving source map instance into cache',\n fileUrl: frame.file,\n });\n this.sourceMapConsumerCache[frame.file] = sourceMapConsumer;\n }\n\n logger.debug({\n msg: 'Symbolicating frame',\n frame,\n });\n const processedFrame = this.processFrame(frame);\n\n logger.debug({\n msg: 'Finished symbolicating frame',\n frame,\n });\n processedFrames.push(processedFrame);\n }\n\n const codeFrame =\n (await this.getCodeFrame(logger, processedFrames)) ?? null;\n\n logger.debug({\n msg: 'Finished symbolicating frames',\n processedFrames,\n codeFrame,\n });\n\n return {\n stack: processedFrames,\n codeFrame,\n };\n } finally {\n for (const key in this.sourceMapConsumerCache) {\n this.sourceMapConsumerCache[key].destroy();\n delete this.sourceMapConsumerCache[key];\n }\n }\n }\n\n private processFrame(frame: InputStackFrame): StackFrame {\n if (!frame.lineNumber || !frame.column) {\n return {\n ...frame,\n collapse: false,\n };\n }\n\n const consumer = this.sourceMapConsumerCache[frame.file];\n if (!consumer) {\n return {\n ...frame,\n collapse: false,\n };\n }\n\n const lookup = consumer.originalPositionFor({\n line: frame.lineNumber,\n column: frame.column,\n bias: SourceMapConsumer.LEAST_UPPER_BOUND,\n });\n\n // If lookup fails, we get the same shape object, but with\n // all values set to null\n if (!lookup.source) {\n // It is better to gracefully return the original frame\n // than to throw an exception\n return {\n ...frame,\n collapse: false,\n };\n }\n\n return {\n lineNumber: lookup.line || frame.lineNumber,\n column: lookup.column || frame.column,\n file: lookup.source,\n methodName: lookup.name || frame.methodName,\n collapse: false,\n };\n }\n\n private async getCodeFrame(\n logger: FastifyLoggerInstance,\n processedFrames: StackFrame[]\n ): Promise<CodeFrame | undefined> {\n for (const frame of processedFrames) {\n if (frame.collapse || !frame.lineNumber || !frame.column) {\n continue;\n }\n\n if (!this.delegate.shouldIncludeFrame(frame)) {\n return undefined;\n }\n\n logger.debug({\n msg: 'Generating code frame',\n frame,\n });\n\n try {\n return {\n content: codeFrameColumns(\n (await this.delegate.getSource(frame.file)).toString(),\n {\n start: { column: frame.column, line: frame.lineNumber },\n },\n { forceColor: true }\n ),\n location: {\n row: frame.lineNumber,\n column: frame.column,\n },\n fileName: frame.file,\n };\n } catch (error) {\n logger.error({\n msg: 'Failed to create code frame',\n error: (error as Error).message,\n });\n }\n\n return undefined;\n }\n }\n}\n"],"mappings":"AAAA,SAASA,GAAG,QAAQ,UAAU;AAC9B,SAASC,gBAAgB,QAAQ,mBAAmB;AAEpD,SAASC,iBAAiB,QAAQ,YAAY;AAU9C;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,CAAC;EACxB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,sBAAsBA,CAACC,KAA8B,EAAE;IAC5D,KAAK,MAAMC,KAAK,IAAID,KAAK,EAAE;MACzB,IAAI,CAACC,KAAK,CAACC,IAAI,EAAE;QACf;MACF;MAEA,MAAM;QAAEC,YAAY;QAAEC;MAAS,CAAC,GAAG,IAAIT,GAAG,CAACM,KAAK,CAACC,IAAI,EAAE,SAAS,CAAC;MACjE,MAAMG,QAAQ,GAAGF,YAAY,CAACG,GAAG,CAAC,UAAU,CAAC;MAC7C,IAAID,QAAQ,EAAE;QACZ,OAAOA,QAAQ;MACjB;MACA,MAAM,CAACE,cAAc,CAAC,GAAGH,QAAQ,CAACI,KAAK,CAAC,GAAG,CAAC,CAACC,OAAO,CAAC,CAAC;MACtD,MAAM,GAAGC,mBAAmB,EAAEC,SAAS,CAAC,GAAGJ,cAAc,CAACC,KAAK,CAAC,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uBAAuB;QAC5BjB;MACF,CAAC,CAAC;MAEF,IAAI;QACF,OAAO;UACLkD,OAAO,EAAEvD,gBAAgB,CACvB,CAAC,MAAM,IAAI,CAACkB,QAAQ,CAACsC,SAAS,CAACnD,KAAK,CAACC,IAAI,CAAC,EAAE4B,QAAQ,CAAC,CAAC,EACtD;YACEuB,KAAK,EAAE;cAAEf,MAAM,EAAErC,KAAK,CAACqC,MAAM;cAAEK,IAAI,EAAE1C,KAAK,CAACoC;YAAW;UACxD,CAAC,EACD;YAAEiB,UAAU,EAAE;UAAK,CACrB,CAAC;UACDC,QAAQ,EAAE;YACRC,GAAG,EAAEvD,KAAK,CAACoC,UAAU;YACrBC,MAAM,EAAErC,KAAK,CAACqC;UAChB,CAAC;UACDmB,QAAQ,EAAExD,KAAK,CAACC;QAClB,CAAC;MACH,CAAC,CAAC,OAAOwD,KAAK,EAAE;QACd1C,MAAM,CAAC0C,KAAK,CAAC;UACXxC,GAAG,EAAE,6BAA6B;UAClCwC,KAAK,EAAGA,KAAK,CAAWC;QAC1B,CAAC,CAAC;MACJ;MAEA,OAAOT,SAAS;IAClB;EACF;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"Symbolicator.js","names":["URL","codeFrameColumns","SourceMapConsumer","Symbolicator","inferPlatformFromStack","stack","frame","file","searchParams","pathname","platform","get","bundleFilename","split","reverse","platformOrExtension","extension","sourceMapConsumerCache","constructor","delegate","process","logger","debug","msg","frames","startsWith","push","processedFrames","fileUrl","rawSourceMap","getSourceMap","sourceMapLength","length","sourceMapConsumer","toString","processedFrame","processFrame","codeFrame","getCodeFrame","key","destroy","lineNumber","column","collapse","consumer","lookup","originalPositionFor","line","bias","LEAST_UPPER_BOUND","source","methodName","name","shouldIncludeFrame","undefined","content","getSource","start","forceColor","location","row","fileName","error","message"],"sources":["../../../src/plugins/symbolicate/Symbolicator.ts"],"sourcesContent":["import { URL } from 'node:url';\nimport { codeFrameColumns } from '@babel/code-frame';\nimport type { FastifyLoggerInstance } from 'fastify';\nimport { SourceMapConsumer } from 'source-map';\nimport type {\n CodeFrame,\n InputStackFrame,\n ReactNativeStackFrame,\n StackFrame,\n SymbolicatorDelegate,\n SymbolicatorResults,\n} from './types';\n\n/**\n * Class for transforming stack traces from React Native application with using Source Map.\n * Raw stack frames produced by React Native, points to some location from the bundle\n * eg `index.bundle?platform=ios:567:1234`. By using Source Map for that bundle `Symbolicator`\n * produces frames that point to source code inside your project eg `Hello.tsx:10:9`.\n */\nexport class Symbolicator {\n /**\n * Infer platform from stack frames.\n * Usually at least one frame has `file` field with the bundle URL eg:\n * `http://localhost:8081/index.bundle?platform=ios&...`, which can be used to infer platform.\n *\n * @param stack Array of stack frames.\n * @returns Inferred platform or `undefined` if cannot infer.\n */\n static inferPlatformFromStack(stack: ReactNativeStackFrame[]) {\n for (const frame of stack) {\n if (!frame.file) {\n continue;\n }\n\n const { searchParams, pathname } = new URL(frame.file, 'file://');\n const platform = searchParams.get('platform');\n if (platform) {\n return platform;\n }\n const [bundleFilename] = pathname.split('/').reverse();\n const [, platformOrExtension, extension] = bundleFilename.split('.');\n if (extension) {\n return platformOrExtension;\n }\n }\n }\n\n /**\n * Cache with initialized `SourceMapConsumer` to improve symbolication performance.\n */\n sourceMapConsumerCache: Record<string, SourceMapConsumer> = {};\n\n /**\n * Constructs new `Symbolicator` instance.\n *\n * @param delegate Delegate instance with symbolication functions.\n */\n constructor(private delegate: SymbolicatorDelegate) {}\n\n /**\n * Process raw React Native stack frames and transform them using Source Maps.\n * Method will try to symbolicate as much data as possible, but if the Source Maps\n * are not available, invalid or the original positions/data is not found in Source Maps,\n * the method will return raw values - the same as supplied with `stack` parameter.\n * For example out of 10 frames, it's possible that only first 7 will be symbolicated and the\n * remaining 3 will be unchanged.\n *\n * @param logger Fastify logger instance.\n * @param stack Raw stack frames.\n * @returns Symbolicated stack frames.\n */\n async process(\n logger: FastifyLoggerInstance,\n stack: ReactNativeStackFrame[]\n ): Promise<SymbolicatorResults> {\n logger.debug({ msg: 'Filtering out unnecessary frames' });\n\n const frames: InputStackFrame[] = [];\n for (const frame of stack) {\n const { file } = frame;\n if (file?.startsWith('http')) {\n frames.push(frame as InputStackFrame);\n }\n }\n\n try {\n logger.debug({ msg: 'Processing frames', frames });\n\n const processedFrames: StackFrame[] = [];\n for (const frame of frames) {\n if (!this.sourceMapConsumerCache[frame.file]) {\n logger.debug({\n msg: 'Loading raw source map data',\n fileUrl: frame.file,\n });\n\n const rawSourceMap = await this.delegate.getSourceMap(frame.file);\n\n logger.debug({\n msg: 'Creating source map instance',\n fileUrl: frame.file,\n sourceMapLength: rawSourceMap.length,\n });\n const sourceMapConsumer = await new SourceMapConsumer(\n rawSourceMap.toString()\n );\n\n logger.debug({\n msg: 'Saving source map instance into cache',\n fileUrl: frame.file,\n });\n this.sourceMapConsumerCache[frame.file] = sourceMapConsumer;\n }\n\n logger.debug({\n msg: 'Symbolicating frame',\n frame,\n });\n const processedFrame = this.processFrame(frame);\n\n logger.debug({\n msg: 'Finished symbolicating frame',\n frame,\n });\n processedFrames.push(processedFrame);\n }\n\n const codeFrame =\n (await this.getCodeFrame(logger, processedFrames)) ?? null;\n\n logger.debug({\n msg: 'Finished symbolicating frames',\n processedFrames,\n codeFrame,\n });\n\n return {\n stack: processedFrames,\n codeFrame,\n };\n } finally {\n for (const key in this.sourceMapConsumerCache) {\n this.sourceMapConsumerCache[key].destroy();\n delete this.sourceMapConsumerCache[key];\n }\n }\n }\n\n private processFrame(frame: InputStackFrame): StackFrame {\n if (!frame.lineNumber || !frame.column) {\n return {\n ...frame,\n collapse: false,\n };\n }\n\n const consumer = this.sourceMapConsumerCache[frame.file];\n if (!consumer) {\n return {\n ...frame,\n collapse: false,\n };\n }\n\n const lookup = consumer.originalPositionFor({\n line: frame.lineNumber,\n column: frame.column,\n bias: SourceMapConsumer.LEAST_UPPER_BOUND,\n });\n\n // If lookup fails, we get the same shape object, but with\n // all values set to null\n if (!lookup.source) {\n // It is better to gracefully return the original frame\n // than to throw an exception\n return {\n ...frame,\n collapse: false,\n };\n }\n\n return {\n lineNumber: lookup.line || frame.lineNumber,\n column: lookup.column || frame.column,\n file: lookup.source,\n methodName: lookup.name || frame.methodName,\n collapse: false,\n };\n }\n\n private async getCodeFrame(\n logger: FastifyLoggerInstance,\n processedFrames: StackFrame[]\n ): Promise<CodeFrame | undefined> {\n for (const frame of processedFrames) {\n if (frame.collapse || !frame.lineNumber || !frame.column) {\n continue;\n }\n\n if (!this.delegate.shouldIncludeFrame(frame)) {\n return undefined;\n }\n\n logger.debug({\n msg: 'Generating code frame',\n frame,\n });\n\n try {\n return {\n content: codeFrameColumns(\n (await this.delegate.getSource(frame.file)).toString(),\n {\n start: { column: frame.column, line: frame.lineNumber },\n },\n { forceColor: true }\n ),\n location: {\n row: frame.lineNumber,\n column: frame.column,\n },\n fileName: frame.file,\n };\n } catch (error) {\n logger.error({\n msg: 'Failed to create code frame',\n error: (error as Error).message,\n });\n }\n\n return undefined;\n }\n }\n}\n"],"mappings":"AAAA,SAASA,GAAG,QAAQ,UAAU;AAC9B,SAASC,gBAAgB,QAAQ,mBAAmB;AAEpD,SAASC,iBAAiB,QAAQ,YAAY;AAU9C;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,CAAC;EACxB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,sBAAsBA,CAACC,KAA8B,EAAE;IAC5D,KAAK,MAAMC,KAAK,IAAID,KAAK,EAAE;MACzB,IAAI,CAACC,KAAK,CAACC,IAAI,EAAE;QACf;MACF;MAEA,MAAM;QAAEC,YAAY;QAAEC;MAAS,CAAC,GAAG,IAAIT,GAAG,CAACM,KAAK,CAACC,IAAI,EAAE,SAAS,CAAC;MACjE,MAAMG,QAAQ,GAAGF,YAAY,CAACG,GAAG,CAAC,UAAU,CAAC;MAC7C,IAAID,QAAQ,EAAE;QACZ,OAAOA,QAAQ;MACjB;MACA,MAAM,CAACE,cAAc,CAAC,GAAGH,QAAQ,CAACI,K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E;QAC5C,OAAOgD,SAAS;MAClB;MAEAjC,MAAM,CAACC,KAAK,CAAC;QACXC,GAAG,EAAE,uBAAuB;QAC5BjB;MACF,CAAC,CAAC;MAEF,IAAI;QACF,OAAO;UACLiD,OAAO,EAAEtD,gBAAgB,CACvB,CAAC,MAAM,IAAI,CAACkB,QAAQ,CAACqC,SAAS,CAAClD,KAAK,CAACC,IAAI,CAAC,EAAE2B,QAAQ,CAAC,CAAC,EACtD;YACEuB,KAAK,EAAE;cAAEf,MAAM,EAAEpC,KAAK,CAACoC,MAAM;cAAEK,IAAI,EAAEzC,KAAK,CAACmC;YAAW;UACxD,CAAC,EACD;YAAEiB,UAAU,EAAE;UAAK,CACrB,CAAC;UACDC,QAAQ,EAAE;YACRC,GAAG,EAAEtD,KAAK,CAACmC,UAAU;YACrBC,MAAM,EAAEpC,KAAK,CAACoC;UAChB,CAAC;UACDmB,QAAQ,EAAEvD,KAAK,CAACC;QAClB,CAAC;MACH,CAAC,CAAC,OAAOuD,KAAK,EAAE;QACdzC,MAAM,CAACyC,KAAK,CAAC;UACXvC,GAAG,EAAE,6BAA6B;UAClCuC,KAAK,EAAGA,KAAK,CAAWC;QAC1B,CAAC,CAAC;MACJ;MAEA,OAAOT,SAAS;IAClB;EACF;AACF","ignoreList":[]}
|
|
@@ -3,7 +3,6 @@ import type { Server } from '../../types';
|
|
|
3
3
|
import { WebSocketRouter } from './WebSocketRouter';
|
|
4
4
|
import { WebSocketServerAdapter } from './WebSocketServerAdapter';
|
|
5
5
|
import { WebSocketApiServer } from './servers/WebSocketApiServer';
|
|
6
|
-
import { WebSocketDebuggerServer } from './servers/WebSocketDebuggerServer';
|
|
7
6
|
import { WebSocketDevClientServer } from './servers/WebSocketDevClientServer';
|
|
8
7
|
import { WebSocketEventsServer } from './servers/WebSocketEventsServer';
|
|
9
8
|
import { WebSocketHMRServer } from './servers/WebSocketHMRServer';
|
|
@@ -11,7 +10,6 @@ import { WebSocketMessageServer } from './servers/WebSocketMessageServer';
|
|
|
11
10
|
declare module 'fastify' {
|
|
12
11
|
interface FastifyInstance {
|
|
13
12
|
wss: {
|
|
14
|
-
debuggerServer: WebSocketDebuggerServer;
|
|
15
13
|
devClientServer: WebSocketDevClientServer;
|
|
16
14
|
messageServer: WebSocketMessageServer;
|
|
17
15
|
eventsServer: WebSocketEventsServer;
|
|
@@ -2,7 +2,6 @@ import fastifyPlugin from 'fastify-plugin';
|
|
|
2
2
|
import { WebSocketRouter } from "./WebSocketRouter.js";
|
|
3
3
|
import { WebSocketServerAdapter } from "./WebSocketServerAdapter.js";
|
|
4
4
|
import { WebSocketApiServer } from "./servers/WebSocketApiServer.js";
|
|
5
|
-
import { WebSocketDebuggerServer } from "./servers/WebSocketDebuggerServer.js";
|
|
6
5
|
import { WebSocketDevClientServer } from "./servers/WebSocketDevClientServer.js";
|
|
7
6
|
import { WebSocketEventsServer } from "./servers/WebSocketEventsServer.js";
|
|
8
7
|
import { WebSocketHMRServer } from "./servers/WebSocketHMRServer.js";
|
|
@@ -18,7 +17,6 @@ async function wssPlugin(instance, {
|
|
|
18
17
|
delegate
|
|
19
18
|
}) {
|
|
20
19
|
const router = new WebSocketRouter(instance);
|
|
21
|
-
const debuggerServer = new WebSocketDebuggerServer(instance);
|
|
22
20
|
const devClientServer = new WebSocketDevClientServer(instance);
|
|
23
21
|
const messageServer = new WebSocketMessageServer(instance);
|
|
24
22
|
const eventsServer = new WebSocketEventsServer(instance, {
|
|
@@ -30,7 +28,6 @@ async function wssPlugin(instance, {
|
|
|
30
28
|
// @react-native/dev-middleware servers
|
|
31
29
|
const deviceConnectionServer = new WebSocketServerAdapter(instance, WS_DEVICE_URL, options.endpoints?.[WS_DEVICE_URL]);
|
|
32
30
|
const debuggerConnectionServer = new WebSocketServerAdapter(instance, WS_DEBUGGER_URL, options.endpoints?.[WS_DEBUGGER_URL]);
|
|
33
|
-
router.registerServer(debuggerServer);
|
|
34
31
|
router.registerServer(devClientServer);
|
|
35
32
|
router.registerServer(messageServer);
|
|
36
33
|
router.registerServer(eventsServer);
|
|
@@ -39,7 +36,6 @@ async function wssPlugin(instance, {
|
|
|
39
36
|
router.registerServer(deviceConnectionServer);
|
|
40
37
|
router.registerServer(debuggerConnectionServer);
|
|
41
38
|
instance.decorate('wss', {
|
|
42
|
-
debuggerServer,
|
|
43
39
|
devClientServer,
|
|
44
40
|
messageServer,
|
|
45
41
|
eventsServer,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wssPlugin.js","names":["fastifyPlugin","WebSocketRouter","WebSocketServerAdapter","WebSocketApiServer","
|
|
1
|
+
{"version":3,"file":"wssPlugin.js","names":["fastifyPlugin","WebSocketRouter","WebSocketServerAdapter","WebSocketApiServer","WebSocketDevClientServer","WebSocketEventsServer","WebSocketHMRServer","WebSocketMessageServer","WS_DEVICE_URL","WS_DEBUGGER_URL","wssPlugin","instance","options","delegate","router","devClientServer","messageServer","eventsServer","webSocketMessageServer","apiServer","hmrServer","hmr","deviceConnectionServer","endpoints","debuggerConnectionServer","registerServer","decorate","name"],"sources":["../../../src/plugins/wss/wssPlugin.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { Server } from '../../types';\nimport { WebSocketRouter } from './WebSocketRouter';\nimport { WebSocketServerAdapter } from './WebSocketServerAdapter';\nimport { WebSocketApiServer } from './servers/WebSocketApiServer';\nimport { WebSocketDevClientServer } from './servers/WebSocketDevClientServer';\nimport { WebSocketEventsServer } from './servers/WebSocketEventsServer';\nimport { WebSocketHMRServer } from './servers/WebSocketHMRServer';\nimport { WebSocketMessageServer } from './servers/WebSocketMessageServer';\n\ndeclare module 'fastify' {\n interface FastifyInstance {\n wss: {\n devClientServer: WebSocketDevClientServer;\n messageServer: WebSocketMessageServer;\n eventsServer: WebSocketEventsServer;\n apiServer: WebSocketApiServer;\n hmrServer: WebSocketHMRServer;\n deviceConnectionServer: WebSocketServerAdapter;\n debuggerConnectionServer: WebSocketServerAdapter;\n router: WebSocketRouter;\n };\n }\n}\n\n/**\n * Defined in @react-native/dev-middleware\n * Reference: https://github.com/facebook/react-native/blob/main/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js\n */\nconst WS_DEVICE_URL = '/inspector/device';\nconst WS_DEBUGGER_URL = '/inspector/debug';\n\nasync function wssPlugin(\n instance: FastifyInstance,\n {\n options,\n delegate,\n }: {\n options: Server.Options;\n delegate: Server.Delegate;\n }\n) {\n const router = new WebSocketRouter(instance);\n\n const devClientServer = new WebSocketDevClientServer(instance);\n const messageServer = new WebSocketMessageServer(instance);\n const eventsServer = new WebSocketEventsServer(instance, {\n webSocketMessageServer: messageServer,\n });\n const apiServer = new WebSocketApiServer(instance);\n const hmrServer = new WebSocketHMRServer(instance, delegate.hmr);\n\n // @react-native/dev-middleware servers\n const deviceConnectionServer = new WebSocketServerAdapter(\n instance,\n WS_DEVICE_URL,\n options.endpoints?.[WS_DEVICE_URL]\n );\n\n const debuggerConnectionServer = new WebSocketServerAdapter(\n instance,\n WS_DEBUGGER_URL,\n options.endpoints?.[WS_DEBUGGER_URL]\n );\n\n router.registerServer(devClientServer);\n router.registerServer(messageServer);\n router.registerServer(eventsServer);\n router.registerServer(apiServer);\n router.registerServer(hmrServer);\n router.registerServer(deviceConnectionServer);\n router.registerServer(debuggerConnectionServer);\n\n instance.decorate('wss', {\n devClientServer,\n messageServer,\n eventsServer,\n apiServer,\n hmrServer,\n deviceConnectionServer,\n debuggerConnectionServer,\n router,\n });\n}\n\nexport default fastifyPlugin(wssPlugin, {\n name: 'wss-plugin',\n});\n"],"mappings":"AACA,OAAOA,aAAa,MAAM,gBAAgB;AAAC,SAElCC,eAAe;AAAA,SACfC,sBAAsB;AAAA,SACtBC,kBAAkB;AAAA,SAClBC,wBAAwB;AAAA,SACxBC,qBAAqB;AAAA,SACrBC,kBAAkB;AAAA,SAClBC,sBAAsB;AAiB/B;AACA;AACA;AACA;AACA,MAAMC,aAAa,GAAG,mBAAmB;AACzC,MAAMC,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ACF,CAAC,CAAC;AACJ;AAEA,eAAed,aAAa,CAACU,SAAS,EAAE;EACtCiB,IAAI,EAAE;AACR,CAAC,CAAC","ignoreList":[]}
|
package/dist/types.d.ts
CHANGED
|
@@ -11,13 +11,9 @@ export declare namespace Server {
|
|
|
11
11
|
interface Config {
|
|
12
12
|
/** Development server options to configure e.g: `port`, `host` etc. */
|
|
13
13
|
options: Options;
|
|
14
|
-
experiments?: Experiments;
|
|
15
14
|
/** Function to create a delegate, which implements crucial functionalities. */
|
|
16
15
|
delegate: (context: DelegateContext) => Delegate;
|
|
17
16
|
}
|
|
18
|
-
interface Experiments {
|
|
19
|
-
experimentalDebugger?: boolean;
|
|
20
|
-
}
|
|
21
17
|
/** Development server options. */
|
|
22
18
|
interface Options {
|
|
23
19
|
/** Root directory of the project. */
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["Server","Internal","_Internal","EventTypes"],"sources":["../src/types.ts"],"sourcesContent":["import type { FastifyBaseLogger } from 'fastify';\nimport type { WebSocketServer } from 'ws';\nimport type { CompilerDelegate } from './plugins/compiler';\nimport type { SymbolicatorDelegate } from './plugins/symbolicate';\nimport type { HmrDelegate } from './plugins/wss';\n\nexport type { CompilerDelegate } from './plugins/compiler';\nexport type {\n SymbolicatorDelegate,\n ReactNativeStackFrame,\n InputStackFrame,\n StackFrame,\n CodeFrame,\n SymbolicatorResults,\n} from './plugins/symbolicate';\nexport type { HmrDelegate } from './plugins/wss';\n\nexport namespace Server {\n /** Development server configuration. */\n export interface Config {\n /** Development server options to configure e.g: `port`, `host` etc. */\n options: Options;\n\n
|
|
1
|
+
{"version":3,"file":"types.js","names":["Server","Internal","_Internal","EventTypes"],"sources":["../src/types.ts"],"sourcesContent":["import type { FastifyBaseLogger } from 'fastify';\nimport type { WebSocketServer } from 'ws';\nimport type { CompilerDelegate } from './plugins/compiler';\nimport type { SymbolicatorDelegate } from './plugins/symbolicate';\nimport type { HmrDelegate } from './plugins/wss';\n\nexport type { CompilerDelegate } from './plugins/compiler';\nexport type {\n SymbolicatorDelegate,\n ReactNativeStackFrame,\n InputStackFrame,\n StackFrame,\n CodeFrame,\n SymbolicatorResults,\n} from './plugins/symbolicate';\nexport type { HmrDelegate } from './plugins/wss';\n\nexport namespace Server {\n /** Development server configuration. */\n export interface Config {\n /** Development server options to configure e.g: `port`, `host` etc. */\n options: Options;\n\n /** Function to create a delegate, which implements crucial functionalities. */\n delegate: (context: DelegateContext) => Delegate;\n }\n\n /** Development server options. */\n export interface Options {\n /** Root directory of the project. */\n rootDir: string;\n\n /** Port under which to run the development server. */\n port: number;\n\n /**\n * Hostname or IP address under which to run the development server.\n * When left unspecified, it will listen on all available network interfaces, similarly to listening on '0.0.0.0'.\n */\n host?: string;\n\n /** Options for running the server as HTTPS. If `undefined`, the server will run as HTTP. */\n https?: {\n /** Path to certificate when running server as HTTPS. */\n cert?: string;\n\n /** Path to certificate key when running server as HTTPS. */\n key?: string;\n };\n\n /** Additional endpoints with pre-configured servers */\n endpoints?: Record<string, WebSocketServer>;\n\n /** Whether to enable logging requests. */\n logRequests?: boolean;\n }\n\n /**\n * A complete delegate with implementations for all server functionalities.\n */\n export interface Delegate {\n /** A compiler delegate. */\n compiler: CompilerDelegate;\n\n /** A symbolicator delegate. */\n symbolicator: SymbolicatorDelegate;\n\n /** A logger delegate. */\n logger: LoggerDelegate;\n\n /** An HMR delegate. */\n hmr: HmrDelegate;\n\n /** An messages delegate. */\n messages: MessagesDelegate;\n\n /** An API delegate. */\n api?: Api.Delegate;\n }\n\n /**\n * A delegate context used in `delegate` builder in {@link Config}.\n *\n * Allows to emit logs, notify about compilation events and broadcast events to connected clients.\n */\n export interface DelegateContext {\n /** A logger instance, useful for emitting logs from the delegate. */\n log: FastifyBaseLogger;\n\n /** Send notification about compilation start for given `platform`. */\n notifyBuildStart: (platform: string) => void;\n\n /** Send notification about compilation end for given `platform`. */\n notifyBuildEnd: (platform: string) => void;\n\n /**\n * Broadcast arbitrary event to all connected HMR clients for given `platform`.\n *\n * @param event Arbitrary event to broadcast.\n * @param platform Platform of the clients to which broadcast should be sent.\n * @param clientIds Ids of the client to which broadcast should be sent.\n * If `undefined` the broadcast will be sent to all connected clients for the given `platform`.\n */\n broadcastToHmrClients: <E = any>(\n event: E,\n platform: string,\n clientIds?: string[]\n ) => void;\n\n /**\n * Broadcast arbitrary method-like event to all connected message clients.\n *\n * @param event Arbitrary method-like event to broadcast.\n */\n broadcastToMessageClients: <\n E extends { method: string; params?: Record<string, any> },\n >(\n event: E\n ) => void;\n }\n\n /**\n * Delegate with implementation for logging functions.\n */\n export interface LoggerDelegate {\n /**\n * Callback for when a new log is emitted.\n *\n * @param log An object with log data.\n */\n onMessage: (log: any) => void;\n }\n\n /**\n * Delegate with implementation for messages used in route handlers.\n */\n export interface MessagesDelegate {\n /** Get message to send as a reply for `GET /` route. */\n getHello: () => string;\n\n /** Get message to send as a reply for `GET /status` route. */\n getStatus: () => string;\n }\n\n export namespace Api {\n /** A compilation asset representation for API clients. */\n export interface Asset {\n name: string;\n size: number;\n [key: string]: any;\n }\n\n /** A compilation stats representation for API clients. */\n export interface CompilationStats {\n [key: string]: any;\n }\n\n /**\n * Delegate with implementation for API endpoints.\n */\n export interface Delegate {\n /** Get all platforms - either with already existing compilations or all supported platforms. */\n getPlatforms: () => Promise<string[]>;\n\n /**\n * Get all assets from compilation for given platform.\n * Should return `[]` if the compilation does not exists for given platform.\n */\n getAssets: (platform: string) => Promise<Asset[]>;\n\n /**\n * Get compilation stats for a given platform.\n * Should return `null` if the compilation does not exists for given platform.\n */\n getCompilationStats: (\n platform: string\n ) => Promise<CompilationStats | null>;\n }\n }\n}\n\n/** Representation of the compilation progress. */\nexport interface ProgressData {\n /** Number of modules built. */\n completed: number;\n\n /** Total number of modules detect as part of compilation. */\n total: number;\n}\n\n/**\n * Type representing a function to send the progress.\n *\n * Used by {@link CompilerDelegate} in `getAsset` function to send the compilation\n * progress to the client who requested the asset.\n */\nexport type SendProgress = (data: ProgressData) => void;\n\n/**\n * Internal types. Do not use.\n *\n * @internal\n */\nexport namespace Internal {\n export enum EventTypes {\n BuildStart = 'BuildStart',\n BuildEnd = 'BuildEnd',\n HmrEvent = 'HmrEvent',\n }\n}\n"],"mappings":"WAiBiBA,MAAM;AAoKvB;AASA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AAJA,WAKiBC,QAAQ;AAAA,WAAAC,SAAA;EAAA,IACXC,UAAU,0BAAVA,UAAU;IAAVA,UAAU;IAAVA,UAAU;IAAVA,UAAU;IAAA,OAAVA,UAAU;EAAA;EAAAD,SAAA,CAAAC,UAAA,GAAAA,UAAA;AAAA,GADPF,QAAQ,KAARA,QAAQ","ignoreList":[]}
|
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.0.0-rc.
|
|
5
|
+
"version": "5.0.0-rc.2",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
@@ -37,11 +37,10 @@
|
|
|
37
37
|
"@babel/code-frame": "^7.16.7",
|
|
38
38
|
"@fastify/middie": "^8.3.0",
|
|
39
39
|
"@fastify/sensible": "^5.5.0",
|
|
40
|
-
"@react-native/dev-middleware": "^0.
|
|
40
|
+
"@react-native/dev-middleware": "^0.76.1",
|
|
41
41
|
"fastify": "^4.24.3",
|
|
42
42
|
"fastify-favicon": "^4.3.0",
|
|
43
43
|
"fastify-plugin": "^4.5.1",
|
|
44
|
-
"open": "^8.4.0",
|
|
45
44
|
"pretty-format": "^28.1.0",
|
|
46
45
|
"source-map": "^0.7.4",
|
|
47
46
|
"ws": "^8.7.0"
|
|
@@ -49,8 +48,7 @@
|
|
|
49
48
|
"devDependencies": {
|
|
50
49
|
"@babel/cli": "^7.23.9",
|
|
51
50
|
"@babel/core": "^7.23.9",
|
|
52
|
-
"@react-native-community/cli-
|
|
53
|
-
"@react-native-community/cli-server-api": ">=11.3.1",
|
|
51
|
+
"@react-native-community/cli-server-api": "15.0.1",
|
|
54
52
|
"@types/babel__code-frame": "^7.0.3",
|
|
55
53
|
"@types/node": "18",
|
|
56
54
|
"@types/ws": "^8.5.3",
|
|
@@ -58,13 +56,9 @@
|
|
|
58
56
|
"typescript": "^5.5.3"
|
|
59
57
|
},
|
|
60
58
|
"peerDependencies": {
|
|
61
|
-
"@react-native-community/cli-
|
|
62
|
-
"@react-native-community/cli-server-api": ">=11.3.1"
|
|
59
|
+
"@react-native-community/cli-server-api": ">=13.6.4"
|
|
63
60
|
},
|
|
64
61
|
"peerDependenciesMeta": {
|
|
65
|
-
"@react-native-community/cli-debugger-ui": {
|
|
66
|
-
"optional": true
|
|
67
|
-
},
|
|
68
62
|
"@react-native-community/cli-server-api": {
|
|
69
63
|
"optional": true
|
|
70
64
|
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { IncomingMessage } from 'node:http';
|
|
2
|
-
import type { FastifyInstance } from 'fastify';
|
|
3
|
-
import type WebSocket from 'ws';
|
|
4
|
-
import { WebSocketServer } from '../WebSocketServer';
|
|
5
|
-
/**
|
|
6
|
-
* Class for creating a WebSocket server and providing a bridge between
|
|
7
|
-
* debugger UI (Remote JS debugger) and the running React Native application.
|
|
8
|
-
*
|
|
9
|
-
* React Native application (aka client) will send and receive messages from the debugger UI
|
|
10
|
-
* which runs inside a browser.
|
|
11
|
-
*
|
|
12
|
-
* @category Development server
|
|
13
|
-
*/
|
|
14
|
-
export declare class WebSocketDebuggerServer extends WebSocketServer {
|
|
15
|
-
/**
|
|
16
|
-
* A WebSocket connection with the debugger UI.
|
|
17
|
-
*/
|
|
18
|
-
private debuggerSocket;
|
|
19
|
-
/**
|
|
20
|
-
* A WebSocket connection with the client (React Native app).
|
|
21
|
-
*/
|
|
22
|
-
private clientSocket;
|
|
23
|
-
/**
|
|
24
|
-
* Create new instance of WebSocketDebuggerServer and attach it to the given Fastify instance.
|
|
25
|
-
* Any logging information, will be passed through standard `fastify.log` API.
|
|
26
|
-
*
|
|
27
|
-
* @param fastify Fastify instance to attach the WebSocket server to.
|
|
28
|
-
*/
|
|
29
|
-
constructor(fastify: FastifyInstance);
|
|
30
|
-
/**
|
|
31
|
-
* Check if debugger UI is connected to the WebSocketDebuggerServer.
|
|
32
|
-
*/
|
|
33
|
-
isDebuggerConnected(): boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Send a message to a given WebSocket connection.
|
|
36
|
-
*
|
|
37
|
-
* @param socket WebSocket connection to send the message to.
|
|
38
|
-
* @param message Message to send.
|
|
39
|
-
*/
|
|
40
|
-
send(socket: WebSocket | undefined, message: string): void;
|
|
41
|
-
/**
|
|
42
|
-
* Process new WebSocket connection. The upgrade request should contain `role` query param
|
|
43
|
-
* for determining the type of the connection.
|
|
44
|
-
*
|
|
45
|
-
* @param socket Incoming WebSocket connection.
|
|
46
|
-
* @param request Upgrade request for the connection.
|
|
47
|
-
*/
|
|
48
|
-
onConnection(socket: WebSocket, request: IncomingMessage): void;
|
|
49
|
-
/**
|
|
50
|
-
* Process new WebSocket connection from Debugger UI (Remote JS Debugger).
|
|
51
|
-
* If there's already open connection, the new one gets closed automatically.
|
|
52
|
-
*
|
|
53
|
-
* @param socket Incoming debugger WebSocket connection.
|
|
54
|
-
*/
|
|
55
|
-
onDebuggerConnection(socket: WebSocket): void;
|
|
56
|
-
/**
|
|
57
|
-
* Process new WebSocket connection from React Native app (client)
|
|
58
|
-
* and close any previous connection.
|
|
59
|
-
*
|
|
60
|
-
* @param socket Incoming client WebSocket connection.
|
|
61
|
-
*/
|
|
62
|
-
onClientConnection(socket: WebSocket): void;
|
|
63
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { WebSocketServer } from "../WebSocketServer.js";
|
|
2
|
-
/**
|
|
3
|
-
* Class for creating a WebSocket server and providing a bridge between
|
|
4
|
-
* debugger UI (Remote JS debugger) and the running React Native application.
|
|
5
|
-
*
|
|
6
|
-
* React Native application (aka client) will send and receive messages from the debugger UI
|
|
7
|
-
* which runs inside a browser.
|
|
8
|
-
*
|
|
9
|
-
* @category Development server
|
|
10
|
-
*/
|
|
11
|
-
export class WebSocketDebuggerServer extends WebSocketServer {
|
|
12
|
-
/**
|
|
13
|
-
* A WebSocket connection with the debugger UI.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A WebSocket connection with the client (React Native app).
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Create new instance of WebSocketDebuggerServer and attach it to the given Fastify instance.
|
|
22
|
-
* Any logging information, will be passed through standard `fastify.log` API.
|
|
23
|
-
*
|
|
24
|
-
* @param fastify Fastify instance to attach the WebSocket server to.
|
|
25
|
-
*/
|
|
26
|
-
constructor(fastify) {
|
|
27
|
-
super(fastify, '/debugger-proxy');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Check if debugger UI is connected to the WebSocketDebuggerServer.
|
|
32
|
-
*/
|
|
33
|
-
isDebuggerConnected() {
|
|
34
|
-
return Boolean(this.debuggerSocket);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Send a message to a given WebSocket connection.
|
|
39
|
-
*
|
|
40
|
-
* @param socket WebSocket connection to send the message to.
|
|
41
|
-
* @param message Message to send.
|
|
42
|
-
*/
|
|
43
|
-
send(socket, message) {
|
|
44
|
-
try {
|
|
45
|
-
socket?.send(message);
|
|
46
|
-
} catch (error) {
|
|
47
|
-
this.fastify.log.warn({
|
|
48
|
-
msg: 'Failed to send data to socket',
|
|
49
|
-
error
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Process new WebSocket connection. The upgrade request should contain `role` query param
|
|
56
|
-
* for determining the type of the connection.
|
|
57
|
-
*
|
|
58
|
-
* @param socket Incoming WebSocket connection.
|
|
59
|
-
* @param request Upgrade request for the connection.
|
|
60
|
-
*/
|
|
61
|
-
onConnection(socket, request) {
|
|
62
|
-
const {
|
|
63
|
-
url = ''
|
|
64
|
-
} = request;
|
|
65
|
-
if (url.indexOf('role=debugger') >= 0) {
|
|
66
|
-
this.fastify.log.info({
|
|
67
|
-
msg: 'Chrome Remote JS debugger connected'
|
|
68
|
-
});
|
|
69
|
-
this.onDebuggerConnection(socket);
|
|
70
|
-
} else if (url.indexOf('role=client') >= 0) {
|
|
71
|
-
this.fastify.log.info({
|
|
72
|
-
msg: 'React Native app connected to debugger'
|
|
73
|
-
});
|
|
74
|
-
this.onClientConnection(socket);
|
|
75
|
-
} else {
|
|
76
|
-
socket.close(1011, 'Missing role param');
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Process new WebSocket connection from Debugger UI (Remote JS Debugger).
|
|
82
|
-
* If there's already open connection, the new one gets closed automatically.
|
|
83
|
-
*
|
|
84
|
-
* @param socket Incoming debugger WebSocket connection.
|
|
85
|
-
*/
|
|
86
|
-
onDebuggerConnection(socket) {
|
|
87
|
-
if (this.debuggerSocket) {
|
|
88
|
-
socket.close(1011, 'Another debugger is already connected');
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
this.debuggerSocket = socket;
|
|
92
|
-
const onClose = () => {
|
|
93
|
-
this.fastify.log.info({
|
|
94
|
-
msg: 'Chrome Remote JS debugger disconnected'
|
|
95
|
-
});
|
|
96
|
-
this.debuggerSocket = undefined;
|
|
97
|
-
if (this.clientSocket) {
|
|
98
|
-
this.clientSocket.removeAllListeners();
|
|
99
|
-
this.clientSocket.close(1011, 'Debugger was disconnected');
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
this.debuggerSocket.addEventListener('error', onClose);
|
|
103
|
-
this.debuggerSocket.addEventListener('close', onClose);
|
|
104
|
-
this.debuggerSocket.addEventListener('message', ({
|
|
105
|
-
data
|
|
106
|
-
}) => {
|
|
107
|
-
this.send(this.clientSocket, data.toString());
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Process new WebSocket connection from React Native app (client)
|
|
113
|
-
* and close any previous connection.
|
|
114
|
-
*
|
|
115
|
-
* @param socket Incoming client WebSocket connection.
|
|
116
|
-
*/
|
|
117
|
-
onClientConnection(socket) {
|
|
118
|
-
if (this.clientSocket) {
|
|
119
|
-
this.clientSocket.removeAllListeners();
|
|
120
|
-
this.clientSocket.close(1011, 'Another client is connected');
|
|
121
|
-
this.clientSocket = undefined;
|
|
122
|
-
}
|
|
123
|
-
const onClose = () => {
|
|
124
|
-
this.fastify.log.info({
|
|
125
|
-
msg: 'React Native app disconnected from debugger'
|
|
126
|
-
});
|
|
127
|
-
this.clientSocket = undefined;
|
|
128
|
-
this.send(this.debuggerSocket, JSON.stringify({
|
|
129
|
-
method: '$disconnected'
|
|
130
|
-
}));
|
|
131
|
-
};
|
|
132
|
-
this.clientSocket = socket;
|
|
133
|
-
this.clientSocket.addEventListener('error', onClose);
|
|
134
|
-
this.clientSocket.addEventListener('close', onClose);
|
|
135
|
-
this.clientSocket.addEventListener('message', ({
|
|
136
|
-
data
|
|
137
|
-
}) => {
|
|
138
|
-
this.send(this.debuggerSocket, data.toString());
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
//# sourceMappingURL=WebSocketDebuggerServer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketDebuggerServer.js","names":["WebSocketServer","WebSocketDebuggerServer","constructor","fastify","isDebuggerConnected","Boolean","debuggerSocket","send","socket","message","error","log","warn","msg","onConnection","request","url","indexOf","info","onDebuggerConnection","onClientConnection","close","onClose","undefined","clientSocket","removeAllListeners","addEventListener","data","toString","JSON","stringify","method"],"sources":["../../../../src/plugins/wss/servers/WebSocketDebuggerServer.ts"],"sourcesContent":["import type { IncomingMessage } from 'node:http';\nimport type { FastifyInstance } from 'fastify';\nimport type WebSocket from 'ws';\nimport { WebSocketServer } from '../WebSocketServer';\n\n/**\n * Class for creating a WebSocket server and providing a bridge between\n * debugger UI (Remote JS debugger) and the running React Native application.\n *\n * React Native application (aka client) will send and receive messages from the debugger UI\n * which runs inside a browser.\n *\n * @category Development server\n */\nexport class WebSocketDebuggerServer extends WebSocketServer {\n /**\n * A WebSocket connection with the debugger UI.\n */\n private debuggerSocket: WebSocket | undefined;\n\n /**\n * A WebSocket connection with the client (React Native app).\n */\n private clientSocket: WebSocket | undefined;\n\n /**\n * Create new instance of WebSocketDebuggerServer and attach it to the given Fastify instance.\n * Any logging information, will be passed through standard `fastify.log` API.\n *\n * @param fastify Fastify instance to attach the WebSocket server to.\n */\n constructor(fastify: FastifyInstance) {\n super(fastify, '/debugger-proxy');\n }\n\n /**\n * Check if debugger UI is connected to the WebSocketDebuggerServer.\n */\n isDebuggerConnected() {\n return Boolean(this.debuggerSocket);\n }\n\n /**\n * Send a message to a given WebSocket connection.\n *\n * @param socket WebSocket connection to send the message to.\n * @param message Message to send.\n */\n send(socket: WebSocket | undefined, message: string) {\n try {\n socket?.send(message);\n } catch (error) {\n this.fastify.log.warn({ msg: 'Failed to send data to socket', error });\n }\n }\n\n /**\n * Process new WebSocket connection. The upgrade request should contain `role` query param\n * for determining the type of the connection.\n *\n * @param socket Incoming WebSocket connection.\n * @param request Upgrade request for the connection.\n */\n onConnection(socket: WebSocket, request: IncomingMessage) {\n const { url = '' } = request;\n if (url.indexOf('role=debugger') >= 0) {\n this.fastify.log.info({ msg: 'Chrome Remote JS debugger connected' });\n this.onDebuggerConnection(socket);\n } else if (url.indexOf('role=client') >= 0) {\n this.fastify.log.info({ msg: 'React Native app connected to debugger' });\n this.onClientConnection(socket);\n } else {\n socket.close(1011, 'Missing role param');\n }\n }\n\n /**\n * Process new WebSocket connection from Debugger UI (Remote JS Debugger).\n * If there's already open connection, the new one gets closed automatically.\n *\n * @param socket Incoming debugger WebSocket connection.\n */\n onDebuggerConnection(socket: WebSocket) {\n if (this.debuggerSocket) {\n socket.close(1011, 'Another debugger is already connected');\n return;\n }\n this.debuggerSocket = socket;\n const onClose = () => {\n this.fastify.log.info({ msg: 'Chrome Remote JS debugger disconnected' });\n this.debuggerSocket = undefined;\n if (this.clientSocket) {\n this.clientSocket.removeAllListeners();\n this.clientSocket.close(1011, 'Debugger was disconnected');\n }\n };\n this.debuggerSocket.addEventListener('error', onClose);\n this.debuggerSocket.addEventListener('close', onClose);\n this.debuggerSocket.addEventListener('message', ({ data }) => {\n this.send(this.clientSocket, data.toString());\n });\n }\n\n /**\n * Process new WebSocket connection from React Native app (client)\n * and close any previous connection.\n *\n * @param socket Incoming client WebSocket connection.\n */\n onClientConnection(socket: WebSocket) {\n if (this.clientSocket) {\n this.clientSocket.removeAllListeners();\n this.clientSocket.close(1011, 'Another client is connected');\n this.clientSocket = undefined;\n }\n\n const onClose = () => {\n this.fastify.log.info({\n msg: 'React Native app disconnected from debugger',\n });\n this.clientSocket = undefined;\n this.send(\n this.debuggerSocket,\n JSON.stringify({ method: '$disconnected' })\n );\n };\n\n this.clientSocket = socket;\n this.clientSocket.addEventListener('error', onClose);\n this.clientSocket.addEventListener('close', onClose);\n this.clientSocket.addEventListener('message', ({ data }) => {\n this.send(this.debuggerSocket, data.toString());\n });\n }\n}\n"],"mappings":"SAGSA,eAAe;AAExB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,uBAAuB,SAASD,eAAe,CAAC;EAC3D;AACF;AACA;;EAGE;AACF;AACA;;EAGE;AACF;AACA;AACA;AACA;AACA;EACEE,WAAWA,CAACC,OAAwB,EAAE;IACpC,KAAK,CAACA,OAAO,EAAE,iBAAiB,CAAC;EACnC;;EAEA;AACF;AACA;EACEC,mBAAmBA,CAAA,EAAG;IACpB,OAAOC,OA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