@callstack/repack-dev-server 4.0.0-rc.2 → 5.0.0-next.0

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +4 -4
  3. package/dist/createServer.js +37 -12
  4. package/dist/createServer.js.map +1 -1
  5. package/dist/plugins/compiler/compilerPlugin.js +1 -12
  6. package/dist/plugins/compiler/compilerPlugin.js.map +1 -1
  7. package/dist/plugins/compiler/types.d.ts +1 -3
  8. package/dist/plugins/compiler/types.js.map +1 -1
  9. package/dist/plugins/devtools/devtoolsPlugin.js +0 -60
  10. package/dist/plugins/devtools/devtoolsPlugin.js.map +1 -1
  11. package/dist/plugins/symbolicate/Symbolicator.js +3 -2
  12. package/dist/plugins/symbolicate/Symbolicator.js.map +1 -1
  13. package/dist/plugins/wss/WebSocketRouter.d.ts +3 -3
  14. package/dist/plugins/wss/WebSocketRouter.js.map +1 -1
  15. package/dist/plugins/wss/WebSocketServer.d.ts +4 -3
  16. package/dist/plugins/wss/WebSocketServer.js +0 -1
  17. package/dist/plugins/wss/WebSocketServer.js.map +1 -1
  18. package/dist/plugins/wss/WebSocketServerAdapter.d.ts +16 -0
  19. package/dist/plugins/wss/WebSocketServerAdapter.js +22 -0
  20. package/dist/plugins/wss/WebSocketServerAdapter.js.map +1 -0
  21. package/dist/plugins/wss/servers/WebSocketApiServer.js +2 -2
  22. package/dist/plugins/wss/servers/WebSocketApiServer.js.map +1 -1
  23. package/dist/plugins/wss/servers/WebSocketDevClientServer.js +9 -4
  24. package/dist/plugins/wss/servers/WebSocketDevClientServer.js.map +1 -1
  25. package/dist/plugins/wss/servers/WebSocketHMRServer.js +10 -14
  26. package/dist/plugins/wss/servers/WebSocketHMRServer.js.map +1 -1
  27. package/dist/plugins/wss/types.d.ts +9 -0
  28. package/dist/plugins/wss/types.js.map +1 -1
  29. package/dist/plugins/wss/wssPlugin.d.ts +3 -2
  30. package/dist/plugins/wss/wssPlugin.js +15 -4
  31. package/dist/plugins/wss/wssPlugin.js.map +1 -1
  32. package/dist/types.d.ts +12 -17
  33. package/dist/types.js +0 -7
  34. package/dist/types.js.map +1 -1
  35. package/package.json +17 -5
  36. package/dist/plugins/wss/servers/HermesInspectorProxy.d.ts +0 -24
  37. package/dist/plugins/wss/servers/HermesInspectorProxy.js +0 -120
  38. package/dist/plugins/wss/servers/HermesInspectorProxy.js.map +0 -1
  39. package/vendor/metro-inspector-proxy/src/Device.cjs +0 -1
  40. package/vendor/metro-inspector-proxy/src/Device.js +0 -1
@@ -43,13 +43,13 @@ export class WebSocketApiServer extends WebSocketServer {
43
43
  onConnection(socket) {
44
44
  const clientId = `client#${this.nextClientId++}`;
45
45
  this.clients.set(clientId, socket);
46
- this.fastify.log.info({
46
+ this.fastify.log.debug({
47
47
  msg: 'API client connected',
48
48
  clientId
49
49
  });
50
50
  this.clients.set(clientId, socket);
51
51
  const onClose = () => {
52
- this.fastify.log.info({
52
+ this.fastify.log.debug({
53
53
  msg: 'API client disconnected',
54
54
  clientId
55
55
  });
@@ -1 +1 @@
1
- {"version":3,"file":"WebSocketApiServer.js","names":["WebSocketServer","WebSocketApiServer","clients","Map","nextClientId","constructor","fastify","send","event","data","JSON","stringify","socket","entries","onConnection","clientId","set","log","info","msg","onClose","delete","addEventListener"],"sources":["../../../../src/plugins/wss/servers/WebSocketApiServer.ts"],"sourcesContent":["import { FastifyInstance } from 'fastify';\nimport WebSocket from 'ws';\nimport { WebSocketServer } from '../WebSocketServer';\n\n/**\n * Class for creating a WebSocket server for API clients.\n * Useful to listening for compilation events and new logs.\n *\n * @category Development server\n */\nexport class WebSocketApiServer extends WebSocketServer {\n private clients = new Map<string, WebSocket>();\n private nextClientId = 0;\n\n /**\n * Create new instance of WebSocketApiServer 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, '/api');\n }\n\n /**\n * Send message to all connected API clients.\n *\n * @param event Event string or object to send.\n */\n send(event: any) {\n const data = typeof event === 'string' ? event : JSON.stringify(event);\n\n for (const [, socket] of this.clients.entries()) {\n try {\n socket.send(data);\n } catch {\n // NOOP\n }\n }\n }\n\n /**\n * Process new WebSocket connection from client application.\n *\n * @param socket Incoming client's WebSocket connection.\n */\n onConnection(socket: WebSocket) {\n const clientId = `client#${this.nextClientId++}`;\n this.clients.set(clientId, socket);\n\n this.fastify.log.info({ msg: 'API client connected', clientId });\n this.clients.set(clientId, socket);\n\n const onClose = () => {\n this.fastify.log.info({\n msg: 'API client disconnected',\n clientId,\n });\n this.clients.delete(clientId);\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n }\n}\n"],"mappings":"SAESA,eAAe;AAExB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,SAASD,eAAe,CAAC;EAC9CE,OAAO,GAAG,IAAIC,GAAG,CAAoB,CAAC;EACtCC,YAAY,GAAG,CAAC;;EAExB;AACF;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAACC,OAAwB,EAAE;IACpC,KAAK,CAACA,OAAO,EAAE,MAAM,CAAC;EACxB;;EAEA;AACF;AACA;AACA;AACA;EACEC,IAAIA,CAACC,KAAU,EAAE;IACf,MAAMC,IAAI,GAAG,OAAOD,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAGE,IAAI,CAACC,SAAS,CAACH,KAAK,CAAC;IAEtE,KAAK,MAAM,GAAGI,MAAM,CAAC,IAAI,IAAI,CAACV,OAAO,CAACW,OAAO,CAAC,CAAC,EAAE;MAC/C,IAAI;QACFD,MAAM,CAACL,IAAI,CAACE,IAAI,CAAC;MACnB,CAAC,CAAC,MAAM;QACN;MAAA;IAEJ;EACF;;EAEA;AACF;AACA;AACA;AACA;EACEK,YAAYA,CAACF,MAAiB,EAAE;IAC9B,MAAMG,QAAQ,GAAI,UAAS,IAAI,CAACX,YAAY,EAAG,EAAC;IAChD,IAAI,CAACF,OAAO,CAACc,GAAG,CAACD,QAAQ,EAAEH,MAAM,CAAC;IAElC,IAAI,CAACN,OAAO,CAACW,GAAG,CAACC,IAAI,CAAC;MAAEC,GAAG,EAAE,sBAAsB;MAAEJ;IAAS,CAAC,CAAC;IAChE,IAAI,CAACb,OAAO,CAACc,GAAG,CAACD,QAAQ,EAAEH,MAAM,CAAC;IAElC,MAAMQ,OAAO,GAAGA,CAAA,KAAM;MACpB,IAAI,CAACd,OAAO,CAACW,GAAG,CAACC,IAAI,CAAC;QACpBC,GAAG,EAAE,yBAAyB;QAC9BJ;MACF,CAAC,CAAC;MACF,IAAI,CAACb,OAAO,CAACmB,MAAM,CAACN,QAAQ,CAAC;IAC/B,CAAC;IAEDH,MAAM,CAACU,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IACzCR,MAAM,CAACU,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;EAC3C;AACF"}
1
+ {"version":3,"file":"WebSocketApiServer.js","names":["WebSocketServer","WebSocketApiServer","clients","Map","nextClientId","constructor","fastify","send","event","data","JSON","stringify","socket","entries","onConnection","clientId","set","log","debug","msg","onClose","delete","addEventListener"],"sources":["../../../../src/plugins/wss/servers/WebSocketApiServer.ts"],"sourcesContent":["import { FastifyInstance } from 'fastify';\nimport WebSocket from 'ws';\nimport { WebSocketServer } from '../WebSocketServer';\n\n/**\n * Class for creating a WebSocket server for API clients.\n * Useful to listening for compilation events and new logs.\n *\n * @category Development server\n */\nexport class WebSocketApiServer extends WebSocketServer {\n private clients = new Map<string, WebSocket>();\n private nextClientId = 0;\n\n /**\n * Create new instance of WebSocketApiServer 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, '/api');\n }\n\n /**\n * Send message to all connected API clients.\n *\n * @param event Event string or object to send.\n */\n send(event: any) {\n const data = typeof event === 'string' ? event : JSON.stringify(event);\n\n for (const [, socket] of this.clients.entries()) {\n try {\n socket.send(data);\n } catch {\n // NOOP\n }\n }\n }\n\n /**\n * Process new WebSocket connection from client application.\n *\n * @param socket Incoming client's WebSocket connection.\n */\n onConnection(socket: WebSocket) {\n const clientId = `client#${this.nextClientId++}`;\n this.clients.set(clientId, socket);\n\n this.fastify.log.debug({ msg: 'API client connected', clientId });\n this.clients.set(clientId, socket);\n\n const onClose = () => {\n this.fastify.log.debug({\n msg: 'API client disconnected',\n clientId,\n });\n this.clients.delete(clientId);\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n }\n}\n"],"mappings":"SAESA,eAAe;AAExB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,SAASD,eAAe,CAAC;EAC9CE,OAAO,GAAG,IAAIC,GAAG,CAAoB,CAAC;EACtCC,YAAY,GAAG,CAAC;;EAExB;AACF;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAACC,OAAwB,EAAE;IACpC,KAAK,CAACA,OAAO,EAAE,MAAM,CAAC;EACxB;;EAEA;AACF;AACA;AACA;AACA;EACEC,IAAIA,CAACC,KAAU,EAAE;IACf,MAAMC,IAAI,GAAG,OAAOD,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAGE,IAAI,CAACC,SAAS,CAACH,KAAK,CAAC;IAEtE,KAAK,MAAM,GAAGI,MAAM,CAAC,IAAI,IAAI,CAACV,OAAO,CAACW,OAAO,CAAC,CAAC,EAAE;MAC/C,IAAI;QACFD,MAAM,CAACL,IAAI,CAACE,IAAI,CAAC;MACnB,CAAC,CAAC,MAAM;QACN;MAAA;IAEJ;EACF;;EAEA;AACF;AACA;AACA;AACA;EACEK,YAAYA,CAACF,MAAiB,EAAE;IAC9B,MAAMG,QAAQ,GAAI,UAAS,IAAI,CAACX,YAAY,EAAG,EAAC;IAChD,IAAI,CAACF,OAAO,CAACc,GAAG,CAACD,QAAQ,EAAEH,MAAM,CAAC;IAElC,IAAI,CAACN,OAAO,CAACW,GAAG,CAACC,KAAK,CAAC;MAAEC,GAAG,EAAE,sBAAsB;MAAEJ;IAAS,CAAC,CAAC;IACjE,IAAI,CAACb,OAAO,CAACc,GAAG,CAACD,QAAQ,EAAEH,MAAM,CAAC;IAElC,MAAMQ,OAAO,GAAGA,CAAA,KAAM;MACpB,IAAI,CAACd,OAAO,CAACW,GAAG,CAACC,KAAK,CAAC;QACrBC,GAAG,EAAE,yBAAyB;QAC9BJ;MACF,CAAC,CAAC;MACF,IAAI,CAACb,OAAO,CAACmB,MAAM,CAACN,QAAQ,CAAC;IAC/B,CAAC;IAEDH,MAAM,CAACU,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IACzCR,MAAM,CAACU,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;EAC3C;AACF"}
@@ -41,11 +41,17 @@ export class WebSocketDevClientServer extends WebSocketServer {
41
41
  issuer: 'Console',
42
42
  msg: body.data
43
43
  });
44
- } else {
44
+ } else if (body.level === 'info' || body.level === 'log') {
45
45
  this.fastify.log.info({
46
46
  issuer: 'Console',
47
47
  msg: body.data
48
48
  });
49
+ } else {
50
+ // body.level === 'debug' || body.level === 'trace'
51
+ this.fastify.log.debug({
52
+ issuer: 'Console',
53
+ msg: body.data
54
+ });
49
55
  }
50
56
  break;
51
57
  default:
@@ -64,13 +70,12 @@ export class WebSocketDevClientServer extends WebSocketServer {
64
70
  onConnection(socket) {
65
71
  const clientId = `client#${this.nextClientId++}`;
66
72
  this.clients.set(clientId, socket);
67
- this.fastify.log.info({
73
+ this.fastify.log.debug({
68
74
  msg: 'React Native client connected',
69
75
  clientId
70
76
  });
71
- this.clients.set(clientId, socket);
72
77
  const onClose = () => {
73
- this.fastify.log.info({
78
+ this.fastify.log.debug({
74
79
  msg: 'React Native client disconnected',
75
80
  clientId
76
81
  });
@@ -1 +1 @@
1
- {"version":3,"file":"WebSocketDevClientServer.js","names":["WebSocketServer","WebSocketDevClientServer","clients","Map","nextClientId","constructor","fastify","processMessage","message","type","body","JSON","parse","level","log","error","issuer","msg","data","warn","info","onConnection","socket","clientId","set","onClose","delete","addEventListener","event","toString"],"sources":["../../../../src/plugins/wss/servers/WebSocketDevClientServer.ts"],"sourcesContent":["import WebSocket from 'ws';\nimport type { FastifyInstance } from 'fastify';\nimport { WebSocketServer } from '../WebSocketServer';\n\n/**\n * Class for creating a WebSocket server for communication with React Native clients.\n * All client logs - logs from React Native application - are processed here.\n *\n * @category Development server\n */\nexport class WebSocketDevClientServer extends WebSocketServer {\n private clients = new Map<string, WebSocket>();\n private nextClientId = 0;\n\n /**\n * Create new instance of WebSocketDevClientServer 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, '/__client');\n }\n\n /**\n * Process client message.\n *\n * @param message Stringified client message.\n */\n processMessage(message: string) {\n const { type, ...body } = JSON.parse(message);\n switch (type) {\n case 'client-log':\n if (body.level === 'error') {\n this.fastify.log.error({ issuer: 'Console', msg: body.data });\n } else if (body.level === 'warn') {\n this.fastify.log.warn({ issuer: 'Console', msg: body.data });\n } else {\n this.fastify.log.info({ issuer: 'Console', msg: body.data });\n }\n break;\n default:\n this.fastify.log.warn({ msg: 'Unknown client message', message });\n }\n }\n\n /**\n * Process new WebSocket connection from client application.\n *\n * @param socket Incoming client's WebSocket connection.\n */\n onConnection(socket: WebSocket) {\n const clientId = `client#${this.nextClientId++}`;\n this.clients.set(clientId, socket);\n\n this.fastify.log.info({ msg: 'React Native client connected', clientId });\n this.clients.set(clientId, socket);\n\n const onClose = () => {\n this.fastify.log.info({\n msg: 'React Native client disconnected',\n clientId,\n });\n this.clients.delete(clientId);\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n socket.addEventListener('message', (event) => {\n this.processMessage(event.data.toString());\n });\n }\n}\n"],"mappings":"SAESA,eAAe;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,EAAC;IAChD,IAAI,CAACF,OAAO,CAACsB,GAAG,CAACD,QAAQ,EAAED,MAAM,CAAC;IAElC,IAAI,CAAChB,OAAO,CAACQ,GAAG,CAACM,IAAI,CAAC;MAAEH,GAAG,EAAE,+BAA+B;MAAEM;IAAS,CAAC,CAAC;IACzE,IAAI,CAACrB,OAAO,CAACsB,GAAG,CAACD,QAAQ,EAAED,MAAM,CAAC;IAElC,MAAMG,OAAO,GAAGA,CAAA,KAAM;MACpB,IAAI,CAACnB,OAAO,CAACQ,GAAG,CAACM,IAAI,CAAC;QACpBH,GAAG,EAAE,kCAAkC;QACvCM;MACF,CAAC,CAAC;MACF,IAAI,CAACrB,OAAO,CAACwB,MAAM,CAACH,QAAQ,CAAC;IAC/B,CAAC;IAEDD,MAAM,CAACK,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IACzCH,MAAM,CAACK,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IACzCH,MAAM,CAACK,gBAAgB,CAAC,SAAS,EAAGC,KAAK,IAAK;MAC5C,IAAI,CAACrB,cAAc,CAACqB,KAAK,CAACV,IAAI,CAACW,QAAQ,CAAC,CAAC,CAAC;IAC5C,CAAC,CAAC;EACJ;AACF"}
1
+ {"version":3,"file":"WebSocketDevClientServer.js","names":["WebSocketServer","WebSocketDevClientServer","clients","Map","nextClientId","constructor","fastify","processMessage","message","type","body","JSON","parse","level","log","error","issuer","msg","data","warn","info","debug","onConnection","socket","clientId","set","onClose","delete","addEventListener","event","toString"],"sources":["../../../../src/plugins/wss/servers/WebSocketDevClientServer.ts"],"sourcesContent":["import WebSocket from 'ws';\nimport type { FastifyInstance } from 'fastify';\nimport { WebSocketServer } from '../WebSocketServer';\n\n/**\n * Class for creating a WebSocket server for communication with React Native clients.\n * All client logs - logs from React Native application - are processed here.\n *\n * @category Development server\n */\nexport class WebSocketDevClientServer extends WebSocketServer {\n private clients = new Map<string, WebSocket>();\n private nextClientId = 0;\n\n /**\n * Create new instance of WebSocketDevClientServer 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, '/__client');\n }\n\n /**\n * Process client message.\n *\n * @param message Stringified client message.\n */\n processMessage(message: string) {\n const { type, ...body } = JSON.parse(message);\n switch (type) {\n case 'client-log':\n if (body.level === 'error') {\n this.fastify.log.error({ issuer: 'Console', msg: body.data });\n } else if (body.level === 'warn') {\n this.fastify.log.warn({ issuer: 'Console', msg: body.data });\n } else if (body.level === 'info' || body.level === 'log') {\n this.fastify.log.info({ issuer: 'Console', msg: body.data });\n } else {\n // body.level === 'debug' || body.level === 'trace'\n this.fastify.log.debug({ issuer: 'Console', msg: body.data });\n }\n break;\n default:\n this.fastify.log.warn({ msg: 'Unknown client message', message });\n }\n }\n\n /**\n * Process new WebSocket connection from client application.\n *\n * @param socket Incoming client's WebSocket connection.\n */\n onConnection(socket: WebSocket) {\n const clientId = `client#${this.nextClientId++}`;\n this.clients.set(clientId, socket);\n this.fastify.log.debug({ msg: 'React Native client connected', clientId });\n\n const onClose = () => {\n this.fastify.log.debug({\n msg: 'React Native client disconnected',\n clientId,\n });\n this.clients.delete(clientId);\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n socket.addEventListener('message', (event) => {\n this.processMessage(event.data.toString());\n });\n }\n}\n"],"mappings":"SAESA,eAAe;AAExB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,wBAAwB,SAASD,eAAe,CAAC;EACpDE,OAAO,GAAG,IAAIC,GAAG,CAAoB,CAAC;EACtCC,YAAY,GAAG,CAAC;;EAExB;AACF;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAACC,OAAwB,EAAE;IACpC,KAAK,CAACA,OAAO,EAAE,WAAW,CAAC;EAC7B;;EAEA;AACF;AACA;AACA;AACA;EACEC,cAAcA,CAACC,OAAe,EAAE;IAC9B,MAAM;MAAEC,IAAI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Q,GAAG,CAACO,KAAK,CAAC;MAAEJ,GAAG,EAAE,+BAA+B;MAAEO;IAAS,CAAC,CAAC;IAE1E,MAAME,OAAO,GAAGA,CAAA,KAAM;MACpB,IAAI,CAACpB,OAAO,CAACQ,GAAG,CAACO,KAAK,CAAC;QACrBJ,GAAG,EAAE,kCAAkC;QACvCO;MACF,CAAC,CAAC;MACF,IAAI,CAACtB,OAAO,CAACyB,MAAM,CAACH,QAAQ,CAAC;IAC/B,CAAC;IAEDD,MAAM,CAACK,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IACzCH,MAAM,CAACK,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IACzCH,MAAM,CAACK,gBAAgB,CAAC,SAAS,EAAGC,KAAK,IAAK;MAC5C,IAAI,CAACtB,cAAc,CAACsB,KAAK,CAACX,IAAI,CAACY,QAAQ,CAAC,CAAC,CAAC;IAC5C,CAAC,CAAC;EACJ;AACF"}
@@ -32,7 +32,7 @@ export class WebSocketHMRServer extends WebSocketServer {
32
32
  const data = typeof event === 'string' ? event : JSON.stringify(event);
33
33
  for (const [key, socket] of this.clients) {
34
34
  if (key.platform !== platform || !(clientIds ?? [key.clientId]).includes(key.clientId)) {
35
- return;
35
+ continue;
36
36
  }
37
37
  try {
38
38
  socket.send(data);
@@ -58,32 +58,28 @@ export class WebSocketHMRServer extends WebSocketServer {
58
58
  } = new URL(request.url || '', 'http://localhost');
59
59
  const platform = searchParams.get('platform');
60
60
  if (!platform) {
61
- this.fastify.log.info({
61
+ this.fastify.log.debug({
62
62
  msg: 'HMR connection disconnected - missing platform'
63
63
  });
64
64
  socket.close();
65
65
  return;
66
66
  }
67
67
  const clientId = `client#${this.nextClientId++}`;
68
- this.clients.set({
68
+ const client = {
69
69
  clientId,
70
70
  platform
71
- }, socket);
72
- this.fastify.log.info({
71
+ };
72
+ this.clients.set(client, socket);
73
+ this.fastify.log.debug({
73
74
  msg: 'HMR client connected',
74
- clientId,
75
- platform
75
+ ...client
76
76
  });
77
77
  const onClose = () => {
78
- this.fastify.log.info({
78
+ this.fastify.log.debug({
79
79
  msg: 'HMR client disconnected',
80
- clientId,
81
- platform
82
- });
83
- this.clients.delete({
84
- clientId,
85
- platform
80
+ ...client
86
81
  });
82
+ this.clients.delete(client);
87
83
  };
88
84
  socket.addEventListener('error', onClose);
89
85
  socket.addEventListener('close', onClose);
@@ -1 +1 @@
1
- {"version":3,"file":"WebSocketHMRServer.js","names":["URL","WebSocketServer","WebSocketHMRServer","clients","Map","nextClientId","constructor","fastify","delegate","getUriPath","send","event","platform","clientIds","data","JSON","stringify","key","socket","clientId","includes","error","log","msg","onConnection","request","searchParams","url","get","info","close","set","onClose","delete","addEventListener","onClientConnected"],"sources":["../../../../src/plugins/wss/servers/WebSocketHMRServer.ts"],"sourcesContent":["import { URL } from 'url';\nimport { IncomingMessage } from 'http';\nimport { FastifyInstance } from 'fastify';\nimport WebSocket from 'ws';\nimport { HmrDelegate } from '../types';\nimport { WebSocketServer } from '../WebSocketServer';\n\n/**\n * Class for creating a WebSocket server for Hot Module Replacement.\n *\n * @category Development server\n */\nexport class WebSocketHMRServer extends WebSocketServer {\n private clients = new Map<\n { clientId: string; platform: string },\n WebSocket\n >();\n private nextClientId = 0;\n\n /**\n * Create new instance of WebSocketHMRServer 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 * @param delegate HMR delegate instance.\n */\n constructor(\n fastify: FastifyInstance,\n private delegate: HmrDelegate\n ) {\n super(fastify, delegate.getUriPath());\n }\n\n /**\n * Send action to all connected HMR clients.\n *\n * @param event Event to send to the clients.\n * @param platform Platform of clients to send the event to.\n * @param clientIds Ids of clients who should receive the event.\n */\n send(event: any, platform: string, clientIds?: string[]) {\n const data = typeof event === 'string' ? event : JSON.stringify(event);\n\n for (const [key, socket] of this.clients) {\n if (\n key.platform !== platform ||\n !(clientIds ?? [key.clientId]).includes(key.clientId)\n ) {\n return;\n }\n\n try {\n socket.send(data);\n } catch (error) {\n this.fastify.log.error({\n msg: 'Cannot send action to client',\n event,\n error,\n ...key,\n });\n }\n }\n }\n\n /**\n * Process new WebSocket connection from HMR client.\n *\n * @param socket Incoming HMR client's WebSocket connection.\n */\n onConnection(socket: WebSocket, request: IncomingMessage) {\n const { searchParams } = new URL(request.url || '', 'http://localhost');\n const platform = searchParams.get('platform');\n\n if (!platform) {\n this.fastify.log.info({\n msg: 'HMR connection disconnected - missing platform',\n });\n socket.close();\n return;\n }\n\n const clientId = `client#${this.nextClientId++}`;\n this.clients.set({ clientId, platform }, socket);\n\n this.fastify.log.info({ msg: 'HMR client connected', clientId, platform });\n\n const onClose = () => {\n this.fastify.log.info({\n msg: 'HMR client disconnected',\n clientId,\n platform,\n });\n this.clients.delete({ clientId, platform });\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n\n this.delegate.onClientConnected(platform, clientId);\n }\n}\n"],"mappings":"AAAA,SAASA,GAAG,QAAQ,KAAK;AAAC,SAKjBC,eAAe;AAExB;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,SAASD,eAAe,CAAC;EAC9CE,OAAO,GAAG,IAAIC,GAAG,CAGvB,CAAC;EACKC,YAAY,GAAG,CAAC;;EAExB;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,WAAWA,CACTC,OAAwB,EAChBC,QAAqB,EAC7B;IACA,KAAK,CAACD,OAAO,EAAEC,QAAQ,CAACC,UAAU,CAAC,CAAC,CAAC;IAAC,KAF9BD,QAAqB,GAArBA,QAAqB;EAG/B;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEE,IAAIA,CAACC,KAAU,EAAEC,QAAgB,EAAEC,SAAoB,EAAE;IACvD,MAAMC,IAAI,GAAG,OAAOH,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAGI,IAAI,CAACC,SAAS,CAACL,KAAK,CAAC;IAEtE,KAAK,MAAM,CAACM,GAAG,EAAEC,MA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AACO,IAAI,CAAC;QACpBN,GAAG,EAAE,yBAAyB;QAC9BJ,QAAQ;QACRP;MACF,CAAC,CAAC;MACF,IAAI,CAACT,OAAO,CAAC8B,MAAM,CAAC;QAAEd,QAAQ;QAAEP;MAAS,CAAC,CAAC;IAC7C,CAAC;IAEDM,MAAM,CAACgB,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IACzCd,MAAM,CAACgB,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IAEzC,IAAI,CAACxB,QAAQ,CAAC2B,iBAAiB,CAACvB,QAAQ,EAAEO,QAAQ,CAAC;EACrD;AACF"}
1
+ {"version":3,"file":"WebSocketHMRServer.js","names":["URL","WebSocketServer","WebSocketHMRServer","clients","Map","nextClientId","constructor","fastify","delegate","getUriPath","send","event","platform","clientIds","data","JSON","stringify","key","socket","clientId","includes","error","log","msg","onConnection","request","searchParams","url","get","debug","close","client","set","onClose","delete","addEventListener","onClientConnected"],"sources":["../../../../src/plugins/wss/servers/WebSocketHMRServer.ts"],"sourcesContent":["import { URL } from 'url';\nimport { IncomingMessage } from 'http';\nimport { FastifyInstance } from 'fastify';\nimport WebSocket from 'ws';\nimport { HmrDelegate } from '../types';\nimport { WebSocketServer } from '../WebSocketServer';\n\n/**\n * Class for creating a WebSocket server for Hot Module Replacement.\n *\n * @category Development server\n */\nexport class WebSocketHMRServer extends WebSocketServer {\n private clients = new Map<\n { clientId: string; platform: string },\n WebSocket\n >();\n private nextClientId = 0;\n\n /**\n * Create new instance of WebSocketHMRServer 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 * @param delegate HMR delegate instance.\n */\n constructor(\n fastify: FastifyInstance,\n private delegate: HmrDelegate\n ) {\n super(fastify, delegate.getUriPath());\n }\n\n /**\n * Send action to all connected HMR clients.\n *\n * @param event Event to send to the clients.\n * @param platform Platform of clients to send the event to.\n * @param clientIds Ids of clients who should receive the event.\n */\n send(event: any, platform: string, clientIds?: string[]) {\n const data = typeof event === 'string' ? event : JSON.stringify(event);\n\n for (const [key, socket] of this.clients) {\n if (\n key.platform !== platform ||\n !(clientIds ?? [key.clientId]).includes(key.clientId)\n ) {\n continue;\n }\n\n try {\n socket.send(data);\n } catch (error) {\n this.fastify.log.error({\n msg: 'Cannot send action to client',\n event,\n error,\n ...key,\n });\n }\n }\n }\n\n /**\n * Process new WebSocket connection from HMR client.\n *\n * @param socket Incoming HMR client's WebSocket connection.\n */\n onConnection(socket: WebSocket, request: IncomingMessage) {\n const { searchParams } = new URL(request.url || '', 'http://localhost');\n const platform = searchParams.get('platform');\n\n if (!platform) {\n this.fastify.log.debug({\n msg: 'HMR connection disconnected - missing platform',\n });\n socket.close();\n return;\n }\n\n const clientId = `client#${this.nextClientId++}`;\n\n const client = {\n clientId,\n platform,\n };\n\n this.clients.set(client, socket);\n\n this.fastify.log.debug({ msg: 'HMR client connected', ...client });\n\n const onClose = () => {\n this.fastify.log.debug({\n msg: 'HMR client disconnected',\n ...client,\n });\n this.clients.delete(client);\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n\n this.delegate.onClientConnected(platform, clientId);\n }\n}\n"],"mappings":"AAAA,SAASA,GAAG,QAAQ,KAAK;AAAC,SAKjBC,eAAe;AAExB;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,SAASD,eAAe,CAAC;EAC9CE,OAAO,GAAG,IAAIC,GAAG,CAGvB,CAAC;EACKC,YAAY,GAAG,CAAC;;EAExB;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,WAAWA,CACTC,OAAwB,EAChBC,QAAqB,EAC7B;IACA,KAAK,CAACD,OAAO,EAAEC,QAAQ,CAACC,UAAU,CAAC,CAAC,CAAC;IAAC,KAF9BD,QAAqB,GAArBA,QAAqB;EAG/B;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEE,IAAIA,CAACC,KAAU,EAAEC,QAAgB,EAAEC,SAAoB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,OAAO,CAACe,GAAG,CAACO,KAAK,CAAC;MAAEN,GAAG,EAAE,sBAAsB;MAAE,GAAGQ;IAAO,CAAC,CAAC;IAElE,MAAME,OAAO,GAAGA,CAAA,KAAM;MACpB,IAAI,CAAC1B,OAAO,CAACe,GAAG,CAACO,KAAK,CAAC;QACrBN,GAAG,EAAE,yBAAyB;QAC9B,GAAGQ;MACL,CAAC,CAAC;MACF,IAAI,CAAC5B,OAAO,CAAC+B,MAAM,CAACH,MAAM,CAAC;IAC7B,CAAC;IAEDb,MAAM,CAACiB,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IACzCf,MAAM,CAACiB,gBAAgB,CAAC,OAAO,EAAEF,OAAO,CAAC;IAEzC,IAAI,CAACzB,QAAQ,CAAC4B,iBAAiB,CAACxB,QAAQ,EAAEO,QAAQ,CAAC;EACrD;AACF"}
@@ -1,3 +1,8 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import { IncomingMessage } from 'node:http';
5
+ import { Socket } from 'node:net';
1
6
  /**
2
7
  * Delegate with implementation for HMR-specific functions.
3
8
  */
@@ -14,3 +19,7 @@ export interface HmrDelegate {
14
19
  */
15
20
  onClientConnected: (platform: string, clientId: string) => void;
16
21
  }
22
+ export interface WebSocketServerInterface {
23
+ shouldUpgrade(pathname: string): boolean;
24
+ upgrade(request: IncomingMessage, socket: Socket, head: Buffer): void;
25
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/wss/types.ts"],"sourcesContent":["/**\n * Delegate with implementation for HMR-specific functions.\n */\nexport interface HmrDelegate {\n /** Get URI under which HMR server will be running, e.g: `/hmr` */\n getUriPath: () => string;\n\n /**\n * Callback for when the new HMR client is connected.\n *\n * Useful for running initial synchronization or any other side effect.\n *\n * @param platform Platform of the connected client.\n * @param clientId Id of the connected client.\n */\n onClientConnected: (platform: string, clientId: string) => void;\n}\n"],"mappings":""}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/wss/types.ts"],"sourcesContent":["import { IncomingMessage } from 'node:http';\nimport { Socket } from 'node:net';\n\n/**\n * Delegate with implementation for HMR-specific functions.\n */\nexport interface HmrDelegate {\n /** Get URI under which HMR server will be running, e.g: `/hmr` */\n getUriPath: () => string;\n\n /**\n * Callback for when the new HMR client is connected.\n *\n * Useful for running initial synchronization or any other side effect.\n *\n * @param platform Platform of the connected client.\n * @param clientId Id of the connected client.\n */\n onClientConnected: (platform: string, clientId: string) => void;\n}\n\nexport interface WebSocketServerInterface {\n shouldUpgrade(pathname: string): boolean;\n upgrade(request: IncomingMessage, socket: Socket, head: Buffer): void;\n}\n"],"mappings":""}
@@ -4,10 +4,10 @@ import { WebSocketDebuggerServer } from './servers/WebSocketDebuggerServer';
4
4
  import { WebSocketDevClientServer } from './servers/WebSocketDevClientServer';
5
5
  import { WebSocketMessageServer } from './servers/WebSocketMessageServer';
6
6
  import { WebSocketEventsServer } from './servers/WebSocketEventsServer';
7
- import { HermesInspectorProxy } from './servers/HermesInspectorProxy';
8
7
  import { WebSocketApiServer } from './servers/WebSocketApiServer';
9
8
  import { WebSocketHMRServer } from './servers/WebSocketHMRServer';
10
9
  import { WebSocketRouter } from './WebSocketRouter';
10
+ import { WebSocketServerAdapter } from './WebSocketServerAdapter';
11
11
  declare module 'fastify' {
12
12
  interface FastifyInstance {
13
13
  wss: {
@@ -15,9 +15,10 @@ declare module 'fastify' {
15
15
  devClientServer: WebSocketDevClientServer;
16
16
  messageServer: WebSocketMessageServer;
17
17
  eventsServer: WebSocketEventsServer;
18
- hermesInspectorProxy: HermesInspectorProxy;
19
18
  apiServer: WebSocketApiServer;
20
19
  hmrServer: WebSocketHMRServer;
20
+ deviceConnectionServer: WebSocketServerAdapter;
21
+ debuggerConnectionServer: WebSocketServerAdapter;
21
22
  router: WebSocketRouter;
22
23
  };
23
24
  }
@@ -3,10 +3,16 @@ import { WebSocketDebuggerServer } from "./servers/WebSocketDebuggerServer.js";
3
3
  import { WebSocketDevClientServer } from "./servers/WebSocketDevClientServer.js";
4
4
  import { WebSocketMessageServer } from "./servers/WebSocketMessageServer.js";
5
5
  import { WebSocketEventsServer } from "./servers/WebSocketEventsServer.js";
6
- import { HermesInspectorProxy } from "./servers/HermesInspectorProxy.js";
7
6
  import { WebSocketApiServer } from "./servers/WebSocketApiServer.js";
8
7
  import { WebSocketHMRServer } from "./servers/WebSocketHMRServer.js";
9
8
  import { WebSocketRouter } from "./WebSocketRouter.js";
9
+ import { WebSocketServerAdapter } from "./WebSocketServerAdapter.js";
10
+ /**
11
+ * Defined in @react-native/dev-middleware
12
+ * Reference: https://github.com/facebook/react-native/blob/main/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js
13
+ */
14
+ const WS_DEVICE_URL = '/inspector/device';
15
+ const WS_DEBUGGER_URL = '/inspector/debug';
10
16
  async function wssPlugin(instance, {
11
17
  options,
12
18
  delegate
@@ -18,24 +24,29 @@ async function wssPlugin(instance, {
18
24
  const eventsServer = new WebSocketEventsServer(instance, {
19
25
  webSocketMessageServer: messageServer
20
26
  });
21
- const hermesInspectorProxy = new HermesInspectorProxy(instance, options);
22
27
  const apiServer = new WebSocketApiServer(instance);
23
28
  const hmrServer = new WebSocketHMRServer(instance, delegate.hmr);
29
+
30
+ // @react-native/dev-middleware servers
31
+ const deviceConnectionServer = new WebSocketServerAdapter(instance, WS_DEVICE_URL, options.endpoints?.[WS_DEVICE_URL]);
32
+ const debuggerConnectionServer = new WebSocketServerAdapter(instance, WS_DEBUGGER_URL, options.endpoints?.[WS_DEBUGGER_URL]);
24
33
  router.registerServer(debuggerServer);
25
34
  router.registerServer(devClientServer);
26
35
  router.registerServer(messageServer);
27
36
  router.registerServer(eventsServer);
28
- router.registerServer(hermesInspectorProxy);
29
37
  router.registerServer(apiServer);
30
38
  router.registerServer(hmrServer);
39
+ router.registerServer(deviceConnectionServer);
40
+ router.registerServer(debuggerConnectionServer);
31
41
  instance.decorate('wss', {
32
42
  debuggerServer,
33
43
  devClientServer,
34
44
  messageServer,
35
45
  eventsServer,
36
- hermesInspectorProxy,
37
46
  apiServer,
38
47
  hmrServer,
48
+ deviceConnectionServer,
49
+ debuggerConnectionServer,
39
50
  router
40
51
  });
41
52
  }
@@ -1 +1 @@
1
- {"version":3,"file":"wssPlugin.js","names":["fastifyPlugin","WebSocketDebuggerServer","WebSocketDevClientServer","WebSocketMessageServer","WebSocketEventsServer","HermesInspectorProxy","WebSocketApiServer","WebSocketHMRServer","WebSocketRouter","wssPlugin","instance","options","delegate","router","debuggerServer","devClientServer","messageServer","eventsServer","webSocketMessageServer","hermesInspectorProxy","apiServer","hmrServer","hmr","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 { WebSocketDebuggerServer } from './servers/WebSocketDebuggerServer';\nimport { WebSocketDevClientServer } from './servers/WebSocketDevClientServer';\nimport { WebSocketMessageServer } from './servers/WebSocketMessageServer';\nimport { WebSocketEventsServer } from './servers/WebSocketEventsServer';\nimport { HermesInspectorProxy } from './servers/HermesInspectorProxy';\nimport { WebSocketApiServer } from './servers/WebSocketApiServer';\nimport { WebSocketHMRServer } from './servers/WebSocketHMRServer';\nimport { WebSocketRouter } from './WebSocketRouter';\n\ndeclare module 'fastify' {\n interface FastifyInstance {\n wss: {\n debuggerServer: WebSocketDebuggerServer;\n devClientServer: WebSocketDevClientServer;\n messageServer: WebSocketMessageServer;\n eventsServer: WebSocketEventsServer;\n hermesInspectorProxy: HermesInspectorProxy;\n apiServer: WebSocketApiServer;\n hmrServer: WebSocketHMRServer;\n router: WebSocketRouter;\n };\n }\n}\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 debuggerServer = new WebSocketDebuggerServer(instance);\n const devClientServer = new WebSocketDevClientServer(instance);\n const messageServer = new WebSocketMessageServer(instance);\n const eventsServer = new WebSocketEventsServer(instance, {\n webSocketMessageServer: messageServer,\n });\n const hermesInspectorProxy = new HermesInspectorProxy(instance, options);\n const apiServer = new WebSocketApiServer(instance);\n const hmrServer = new WebSocketHMRServer(instance, delegate.hmr);\n\n router.registerServer(debuggerServer);\n router.registerServer(devClientServer);\n router.registerServer(messageServer);\n router.registerServer(eventsServer);\n router.registerServer(hermesInspectorProxy);\n router.registerServer(apiServer);\n router.registerServer(hmrServer);\n\n instance.decorate('wss', {\n debuggerServer,\n devClientServer,\n messageServer,\n eventsServer,\n hermesInspectorProxy,\n apiServer,\n hmrServer,\n router,\n });\n}\n\nexport default fastifyPlugin(wssPlugin, {\n name: 'wss-plugin',\n});\n"],"mappings":"AACA,OAAOA,aAAa,MAAM,gBAAgB;AAAC,SAElCC,uBAAuB;AAAA,SACvBC,wBAAwB;AAAA,SACxBC,sBAAsB;AAAA,SACtBC,qBAAqB;AAAA,SACrBC,oBAAoB;AAAA,SACpBC,kBAAkB;AAAA,SAClBC,kBAAkB;AAAA,SAClBC,eAAe;AAiBxB,eAAeC,SAASA,CACtBC,QAAyB,EACzB;EACEC,OAAO;EACPC;AAIF,CAAC,EACD;EACA,MAAMC,MAAM,GAAG,IAAIL,eAAe,CAACE,QAAQ,CAAC;EAE5C,MAAMI,cAAc,GAAG,IAAIb,uBAAuB,CAACS,QAAQ,CAAC;EAC5D,MAAMK,eAAe,GAAG,IAAIb,wBAAwB,CAACQ,QAAQ,CAAC;EAC9D,MAAMM,aAAa,GAAG,IAAIb,sBAAsB,CAACO,QAAQ,CAAC;EAC1D,MAAMO,YAAY,GAAG,IAAIb,qBAAqB,CAACM,QAAQ,EAAE;IACvDQ,sBAAsB,EAAEF;EAC1B,CAAC,CAAC;EACF,MAAMG,oBAAoB,GAAG,IAAId,oBAAoB,CAACK,QAAQ,EAAEC,OAAO,CAAC;EACxE,MAAMS,SAAS,GAAG,IAAId,kBAAkB,CAACI,QAAQ,CAAC;EAClD,MAAMW,SAAS,GAAG,IAAId,kBAAkB,CAACG,QAAQ,EAAEE,QAAQ,CAACU,GAAG,CAAC;EAEhET,MAAM,CAACU,cAAc,CAACT,cAAc,CAAC;EACrCD,MAAM,CAACU,cAAc,CAACR,eAAe,CAAC;EACtCF,MAAM,CAACU,cAAc,CAACP,aAAa,CAAC;EACpCH,MAAM,CAACU,cAAc,CAACN,YAAY,CAAC;EACnCJ,MAAM,CAACU,cAAc,CAACJ,oBAAoB,CAAC;EAC3CN,MAAM,CAACU,cAAc,CAACH,SAAS,CAAC;EAChCP,MAAM,CAACU,cAAc,CAACF,SAAS,CAAC;EAEhCX,QAAQ,CAACc,QAAQ,CAAC,KAAK,EAAE;IACvBV,cAAc;IACdC,eAAe;IACfC,aAAa;IACbC,YAAY;IACZE,oBAAoB;IACpBC,SAAS;IACTC,SAAS;IACTR;EACF,CAAC,CAAC;AACJ;AAEA,eAAeb,aAAa,CAACS,SAAS,EAAE;EACtCgB,IAAI,EAAE;AACR,CAAC,CAAC"}
1
+ {"version":3,"file":"wssPlugin.js","names":["fastifyPlugin","WebSocketDebuggerServer","WebSocketDevClientServer","WebSocketMessageServer","WebSocketEventsServer","WebSocketApiServer","WebSocketHMRServer","WebSocketRouter","WebSocketServerAdapter","WS_DEVICE_URL","WS_DEBUGGER_URL","wssPlugin","instance","options","delegate","router","debuggerServer","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 { WebSocketDebuggerServer } from './servers/WebSocketDebuggerServer';\nimport { WebSocketDevClientServer } from './servers/WebSocketDevClientServer';\nimport { WebSocketMessageServer } from './servers/WebSocketMessageServer';\nimport { WebSocketEventsServer } from './servers/WebSocketEventsServer';\nimport { WebSocketApiServer } from './servers/WebSocketApiServer';\nimport { WebSocketHMRServer } from './servers/WebSocketHMRServer';\nimport { WebSocketRouter } from './WebSocketRouter';\nimport { WebSocketServerAdapter } from './WebSocketServerAdapter';\n\ndeclare module 'fastify' {\n interface FastifyInstance {\n wss: {\n debuggerServer: WebSocketDebuggerServer;\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 debuggerServer = new WebSocketDebuggerServer(instance);\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(debuggerServer);\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 debuggerServer,\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,uBAAuB;AAAA,SACvBC,wBAAwB;AAAA,SACxBC,sBAAsB;AAAA,SACtBC,qBAAqB;AAAA,SACrBC,kBAAkB;AAAA,SAClBC,kBAAkB;AAAA,SAClBC,eAAe;AAAA,SACfC,sBAAsB;AAkB/B;AACA;AACA;AACA;AACA,MAAMC,aAAa,GAAG,mBAAmB;AACzC,MAAMC,eAAe,GAAG,kBAAkB;AAE1C,eAAeC,SAASA,CACtBC,QAAyB,EACzB;EACEC,OAAO;EACPC;AAIF,CAAC,EACD;EACA,MAAMC,MAAM,GAAG,IAAIR,eAAe,CAACK,QAAQ,CAAC;EAE5C,MAAMI,cAAc,GAAG,IAAIf,uBAAuB,CAACW,QAAQ,CAAC;EAC5D,MAAMK,eAAe,GAAG,IAAIf,wBAAwB,CAACU,QAAQ,CAAC;EAC9D,MAAMM,aAAa,GAAG,IAAIf,sBAAsB,CAACS,QAAQ,CAAC;EAC1D,MAAMO,YAAY,GAAG,IAAIf,qBAAqB,CAACQ,QAAQ,EAAE;IACvDQ,sBAAsB,EAAEF;EAC1B,CAAC,CAAC;EACF,MAAMG,SAAS,GAAG,IAAIhB,kBAAkB,CAACO,QAAQ,CAAC;EAClD,MAAMU,SAAS,GAAG,IAAIhB,kBAAkB,CAACM,QAAQ,EAAEE,QAAQ,CAACS,GAAG,CAAC;;EAEhE;EACA,MAAMC,sBAAsB,GAAG,IAAIhB,sBAAsB,CACvDI,QAAQ,EACRH,aAAa,EACbI,OAAO,CAACY,SAAS,GAAGhB,aAAa,CACnC,CAAC;EAED,MAAMiB,wBAAwB,GAAG,IAAIlB,sBAAsB,CACzDI,QAAQ,EACRF,eAAe,EACfG,OAAO,CAACY,SAAS,GAAGf,eAAe,CACrC,CAAC;EAEDK,MAAM,CAACY,cAAc,CAACX,cAAc,CAAC;EACrCD,MAAM,CAACY,cAAc,CAACV,eAAe,CAAC;EACtCF,MAAM,CAACY,cAAc,CAACT,aAAa,CAAC;EACpCH,MAAM,CAACY,cAAc,CAACR,YAAY,CAAC;EACnCJ,MAAM,CAACY,cAAc,CAACN,SAAS,CAAC;EAChCN,MAAM,CAACY,cAAc,CAACL,SAAS,CAAC;EAChCP,MAAM,CAACY,cAAc,CAACH,sBAAsB,CAAC;EAC7CT,MAAM,CAACY,cAAc,CAACD,wBAAwB,CAAC;EAE/Cd,QAAQ,CAACgB,QAAQ,CAAC,KAAK,EAAE;IACvBZ,cAAc;IACdC,eAAe;IACfC,aAAa;IACbC,YAAY;IACZE,SAAS;IACTC,SAAS;IACTE,sBAAsB;IACtBE,wBAAwB;IACxBX;EACF,CAAC,CAAC;AACJ;AAEA,eAAef,aAAa,CAACW,SAAS,EAAE;EACtCkB,IAAI,EAAE;AACR,CAAC,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { FastifyLoggerInstance } from 'fastify';
1
+ import type { FastifyBaseLogger } from 'fastify';
2
+ import type { WebSocketServer } from 'ws';
2
3
  import type { CompilerDelegate } from './plugins/compiler';
3
4
  import type { SymbolicatorDelegate } from './plugins/symbolicate';
4
5
  import type { HmrDelegate } from './plugins/wss';
@@ -10,8 +11,12 @@ export declare namespace Server {
10
11
  interface Config {
11
12
  /** Development server options to configure e.g: `port`, `host` etc. */
12
13
  options: Options;
14
+ experiments?: Experiments;
13
15
  /** Function to create a delegate, which implements crucial functionalities. */
14
- delegate: (context: DelegateContext) => Delegate;
16
+ delegate: (context: DelegateContext) => Promise<Delegate>;
17
+ }
18
+ interface Experiments {
19
+ experimentalDebugger?: boolean;
15
20
  }
16
21
  /** Development server options. */
17
22
  interface Options {
@@ -31,6 +36,10 @@ export declare namespace Server {
31
36
  /** Path to certificate key when running server as HTTPS. */
32
37
  key?: string;
33
38
  };
39
+ /** Additional endpoints with pre-configured servers */
40
+ endpoints?: Record<string, WebSocketServer>;
41
+ /** Whether to enable logging requests. */
42
+ logRequests?: boolean;
34
43
  }
35
44
  /**
36
45
  * A complete delegate with implementations for all server functionalities.
@@ -56,7 +65,7 @@ export declare namespace Server {
56
65
  */
57
66
  interface DelegateContext {
58
67
  /** A logger instance, useful for emitting logs from the delegate. */
59
- log: FastifyLoggerInstance;
68
+ log: FastifyBaseLogger;
60
69
  /** Send notification about compilation start for given `platform`. */
61
70
  notifyBuildStart: (platform: string) => void;
62
71
  /** Send notification about compilation end for given `platform`. */
@@ -130,20 +139,6 @@ export declare namespace Server {
130
139
  }
131
140
  }
132
141
  }
133
- /** Representation of the compilation progress. */
134
- export interface ProgressData {
135
- /** Number of modules built. */
136
- completed: number;
137
- /** Total number of modules detect as part of compilation. */
138
- total: number;
139
- }
140
- /**
141
- * Type representing a function to send the progress.
142
- *
143
- * Used by {@link CompilerDelegate} in `getAsset` function to send the compilation
144
- * progress to the client who requested the asset.
145
- */
146
- export type SendProgress = (data: ProgressData) => void;
147
142
  /**
148
143
  * Internal types. Do not use.
149
144
  *
package/dist/types.js CHANGED
@@ -1,11 +1,4 @@
1
1
  export let Server;
2
- /** Representation of the compilation progress. */
3
- /**
4
- * Type representing a function to send the progress.
5
- *
6
- * Used by {@link CompilerDelegate} in `getAsset` function to send the compilation
7
- * progress to the client who requested the asset.
8
- */
9
2
  /**
10
3
  * Internal types. Do not use.
11
4
  *
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 { FastifyLoggerInstance } from 'fastify';\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\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: FastifyLoggerInstance;\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":"WAgBiBA,MAAM;AA8JvB;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"}
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 experiments?: Experiments;\n\n /** Function to create a delegate, which implements crucial functionalities. */\n delegate: (context: DelegateContext) => Promise<Delegate>;\n }\n\n export interface Experiments {\n experimentalDebugger?: boolean;\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/**\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;AA0KvB;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"}
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": "4.0.0-rc.2",
5
+ "version": "5.0.0-next.0",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
@@ -35,15 +35,13 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@babel/code-frame": "^7.16.7",
38
- "@callstack/repack-debugger-app": "^1.0.2",
38
+ "@fastify/middie": "^8.3.0",
39
39
  "@fastify/sensible": "^5.5.0",
40
- "@fastify/static": "^6.12.0",
40
+ "@react-native/dev-middleware": "^0.73.8",
41
41
  "fastify": "^4.24.3",
42
42
  "fastify-favicon": "^4.3.0",
43
43
  "fastify-plugin": "^4.5.1",
44
- "metro-inspector-proxy": "^0.71.0",
45
44
  "open": "^8.4.0",
46
- "open-editor": "^4.0.0",
47
45
  "pretty-format": "^28.1.0",
48
46
  "source-map": "^0.7.4",
49
47
  "ws": "^8.7.0"
@@ -51,6 +49,8 @@
51
49
  "devDependencies": {
52
50
  "@babel/cli": "^7.23.9",
53
51
  "@babel/core": "^7.23.9",
52
+ "@react-native-community/cli-debugger-ui": ">=11.3.1",
53
+ "@react-native-community/cli-server-api": ">=11.3.1",
54
54
  "@types/babel__code-frame": "^7.0.3",
55
55
  "@types/node": "18",
56
56
  "@types/ws": "^8.5.3",
@@ -60,6 +60,18 @@
60
60
  "typedoc-plugin-markdown": "^3.17.1",
61
61
  "typescript": "^5.2.2"
62
62
  },
63
+ "peerDependencies": {
64
+ "@react-native-community/cli-debugger-ui": ">=11.3.1",
65
+ "@react-native-community/cli-server-api": ">=11.3.1"
66
+ },
67
+ "peerDependenciesMeta": {
68
+ "@react-native-community/cli-debugger-ui": {
69
+ "optional": true
70
+ },
71
+ "@react-native-community/cli-server-api": {
72
+ "optional": true
73
+ }
74
+ },
63
75
  "scripts": {
64
76
  "build:js": "babel src --out-dir dist --extensions \".js,.cjs,.ts\" --source-maps --ignore \"**/__tests__/**\" --delete-dir-on-start --copy-files",
65
77
  "build:js:watch": "pnpm build:js --watch",
@@ -1,24 +0,0 @@
1
- /// <reference types="node" />
2
- import type { IncomingMessage } from 'http';
3
- import WebSocket from 'ws';
4
- import type { FastifyInstance } from 'fastify';
5
- import { WebSocketServer } from '../WebSocketServer';
6
- import { Server } from '../../../types';
7
- export interface InspectorProxyConfig extends Pick<Server.Options, 'port' | 'host' | 'rootDir'> {
8
- }
9
- export declare class HermesInspectorProxy extends WebSocketServer {
10
- private config;
11
- private devices;
12
- private deviceCounter;
13
- readonly serverHost: string;
14
- constructor(fastify: FastifyInstance, config: InspectorProxyConfig);
15
- private setup;
16
- private buildPageDescription;
17
- /**
18
- * Process new WebSocket connection from device.
19
- *
20
- * @param socket Incoming device's WebSocket connection.
21
- * @param request Upgrade request for the connection.
22
- */
23
- onConnection(socket: WebSocket, request: IncomingMessage): void;
24
- }
@@ -1,120 +0,0 @@
1
- import { URL } from 'url';
2
- import { WebSocketServer } from "../WebSocketServer.js";
3
- // @ts-ignore
4
- import Device from '../../../../vendor/metro-inspector-proxy/src/Device.js';
5
- const WS_DEVICE_URL = '/inspector/device';
6
- const WS_DEBUGGER_URL = '/inspector/debug';
7
- export class HermesInspectorProxy extends WebSocketServer {
8
- devices = new Map();
9
- deviceCounter = 0;
10
- constructor(fastify, config) {
11
- super(fastify, [WS_DEVICE_URL, WS_DEBUGGER_URL]);
12
- this.config = config;
13
- this.serverHost = `${this.config.host || 'localhost'}:${this.config.port}`;
14
- this.setup();
15
- }
16
- setup() {
17
- const onSend = (_request, reply, _payload, done) => {
18
- reply.headers({
19
- 'Content-Type': 'application/json; charset=UTF-8',
20
- 'Cache-Control': 'no-cache',
21
- Connection: 'close'
22
- });
23
- done();
24
- };
25
- this.fastify.get('/json/version', {
26
- onSend
27
- }, async () => {
28
- return {
29
- Browser: 'Mobile JavaScript',
30
- 'Protocol-Version': '1.1'
31
- };
32
- });
33
- const pageListHandler = async () => {
34
- const pages = [];
35
- for (const [deviceId, device] of this.devices) {
36
- const devicePages = device.getPagesList();
37
- for (const page of devicePages) {
38
- pages.push(this.buildPageDescription(deviceId, page));
39
- }
40
- }
41
- return pages;
42
- };
43
- this.fastify.get('/json/list', {
44
- onSend
45
- }, pageListHandler);
46
- this.fastify.get('/json', {
47
- onSend,
48
- logLevel: 'silent'
49
- }, pageListHandler);
50
- }
51
- buildPageDescription(deviceId, page) {
52
- const debuggerUrl = `${this.serverHost}${WS_DEBUGGER_URL}?device=${deviceId}&page=${page.id}`;
53
- const webSocketDebuggerUrl = 'ws://' + debuggerUrl;
54
- const devtoolsFrontendUrl = 'chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=' + encodeURIComponent(debuggerUrl);
55
- return {
56
- id: `${deviceId}-${page.id}`,
57
- description: page.app,
58
- title: page.title,
59
- faviconUrl: 'https://reactjs.org/favicon.ico',
60
- devtoolsFrontendUrl,
61
- type: 'node',
62
- webSocketDebuggerUrl,
63
- vm: page.vm
64
- };
65
- }
66
-
67
- /**
68
- * Process new WebSocket connection from device.
69
- *
70
- * @param socket Incoming device's WebSocket connection.
71
- * @param request Upgrade request for the connection.
72
- */
73
- onConnection(socket, request) {
74
- try {
75
- const {
76
- url = ''
77
- } = request;
78
- const {
79
- searchParams
80
- } = new URL(url, 'http://localhost');
81
- if (url.startsWith('/inspector/device')) {
82
- const deviceName = searchParams.get('name') ?? 'Unknown';
83
- const appName = searchParams.get('app') ?? 'Unknown';
84
- const deviceId = this.deviceCounter++;
85
- this.devices.set(deviceId, new Device(deviceId, deviceName, appName, socket, this.config.rootDir));
86
- this.fastify.log.info({
87
- msg: 'Hermes device connected',
88
- deviceId
89
- });
90
- const onClose = () => {
91
- this.fastify.log.info({
92
- msg: 'Hermes device disconnected',
93
- deviceId
94
- });
95
- this.devices.delete(deviceId);
96
- };
97
- socket.addEventListener('error', onClose);
98
- socket.addEventListener('close', onClose);
99
- } else {
100
- const deviceId = searchParams.get('device') ?? undefined;
101
- const pageId = searchParams.get('page') ?? undefined;
102
- if (deviceId === undefined || pageId === undefined) {
103
- throw new Error('Incorrect URL - must provide device and page IDs');
104
- }
105
- const device = this.devices.get(parseInt(deviceId, 10));
106
- if (!device) {
107
- throw new Error('Unknown device with ID ' + deviceId);
108
- }
109
- device.handleDebuggerConnection(socket, pageId);
110
- }
111
- } catch (error) {
112
- this.fastify.log.error({
113
- msg: 'Failed to establish connection with Hermes device',
114
- error: error.message
115
- });
116
- socket.close(1011, error.toString());
117
- }
118
- }
119
- }
120
- //# sourceMappingURL=HermesInspectorProxy.js.map