@callstack/repack-dev-server 4.0.0-rc.1 → 4.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @callstack/repack-dev-server
2
2
 
3
+ ## 4.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#430](https://github.com/callstack/repack/pull/430) [`0d96b11`](https://github.com/callstack/repack/commit/0d96b11ff3a6e2c21eb622e21ff7947db29a3272) Thanks [@jbroma](https://github.com/jbroma)! - Upgrade to Node 18, drop support for Node 16
8
+
9
+ - [#508](https://github.com/callstack/repack/pull/508) [`fec8962`](https://github.com/callstack/repack/commit/fec8962b45f3d744d7c41e8f6eeae0a2310c7693) Thanks [@RafikiTiki](https://github.com/RafikiTiki)! - - Fixed deprecated remote debugger integration:
10
+ - Removed vendored code and used middlewares from `@react-native-community/cli-server-api`
11
+ - Removed `package/debugger-app` and replaced it with `@react-native-community/cli-debugger-ui`
12
+ - Removed vendored code responsible for integration with Flipper debugger & custom implementation of the Hermes Inspector Proxy
13
+ - Added integration with `@react-native/dev-middleware` which enables us to use both Flipper and new experimental debugger
14
+
15
+ ### Patch Changes
16
+
17
+ - [#567](https://github.com/callstack/repack/pull/567) [`6417da7`](https://github.com/callstack/repack/commit/6417da7ba72e39602735062198165c998e4e19cf) Thanks [@kerm1it](https://github.com/kerm1it)! - Notify clients on all platforms when sending an HMR event update
18
+
19
+ - [#554](https://github.com/callstack/repack/pull/554) [`ed82e29`](https://github.com/callstack/repack/commit/ed82e29c2871411fd73616f29a7d4b75ff3dd913) Thanks [@jbroma](https://github.com/jbroma)! - Fix path to `favicon.ico` on Windows
20
+
21
+ - [#464](https://github.com/callstack/repack/pull/464) [`72c770b`](https://github.com/callstack/repack/commit/72c770bb4ac5540a3c73cf244ca861069a37b045) Thanks [@jbroma](https://github.com/jbroma)! - Upgrade TypeScript, ESLint, TypeDoc in the repository
22
+
23
+ ## 4.0.0-rc.2
24
+
3
25
  ## 4.0.0-rc.1
4
26
 
5
27
  ### Patch Changes
package/README.md CHANGED
@@ -15,15 +15,15 @@ A Webpack-based toolkit to build your React Native application with full support
15
15
 
16
16
  `@callstack/repack-dev-sever` is bundler-agnostic development server for React Native applications as part of `@callstack/repack`.
17
17
 
18
- Check out our website at https://re-pack.netlify.app/ for more info and documentation or out GitHub: https://github.com/callstack/repack.
18
+ Check out our website at https://re-pack.dev for more info and documentation or out GitHub: https://github.com/callstack/repack.
19
19
 
20
20
  <!-- badges -->
21
- [callstack-readme-with-love]: https://callstack.com/?utm_source=github.com&utm_medium=referral&utm_campaign=react-native-paper&utm_term=readme-with-love
22
21
 
22
+ [callstack-readme-with-love]: https://callstack.com/?utm_source=github.com&utm_medium=referral&utm_campaign=react-native-paper&utm_term=readme-with-love
23
23
  [build-badge]: https://img.shields.io/github/workflow/status/callstack/repack/CI/main?style=flat-square
24
24
  [build]: https://github.com/callstack/repack/actions/workflows/main.yml
25
- [version-badge]: https://img.shields.io/npm/v/@callstack/repack-debugger-app?style=flat-square
26
- [version]: https://www.npmjs.com/package/@callstack/repack-debugger-app
25
+ [version-badge]: https://img.shields.io/npm/v/@callstack/repack-dev-server?style=flat-square
26
+ [version]: https://www.npmjs.com/package/@callstack/repack-dev-server
27
27
  [license-badge]: https://img.shields.io/npm/l/@callstack/repack-debugger-app?style=flat-square
28
28
  [license]: https://github.com/callstack/repack/blob/master/LICENSE
29
29
  [prs-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
@@ -1,16 +1,19 @@
1
1
  import { Writable } from 'stream';
2
2
  import Fastify from 'fastify';
3
3
  import fastifySensible from '@fastify/sensible';
4
- import fastifyStatic from '@fastify/static';
5
- import debuggerAppPath from '@callstack/repack-debugger-app';
4
+ import middie from '@fastify/middie';
5
+ // eslint-disable-next-line import/no-unresolved -- no main field in package.json
6
+ import { createDevMiddleware } from '@react-native/dev-middleware';
7
+ import { debuggerUIMiddleware } from '@react-native-community/cli-debugger-ui';
8
+ import { openURLMiddleware, openStackFrameInEditorMiddleware } from '@react-native-community/cli-server-api';
6
9
  import multipartPlugin from "./plugins/multipart/index.js";
7
10
  import compilerPlugin from "./plugins/compiler/index.js";
8
- import devtoolsPlugin from "./plugins/devtools/index.js";
9
11
  import apiPlugin from "./plugins/api/index.js";
10
12
  import wssPlugin from "./plugins/wss/index.js";
11
13
  import faviconPlugin from "./plugins/favicon/index.js";
12
14
  import { Internal } from "./types.js";
13
15
  import symbolicatePlugin from "./plugins/symbolicate/index.js";
16
+ import devtoolsPlugin from "./plugins/devtools/index.js";
14
17
  /**
15
18
  * Create instance of development server, powered by Fastify.
16
19
  *
@@ -61,11 +64,23 @@ export async function createServer(config) {
61
64
  instance.wss.messageServer.broadcast(method, params);
62
65
  }
63
66
  });
67
+ const devMiddleware = createDevMiddleware({
68
+ projectRoot: config.options.rootDir,
69
+ serverBaseUrl: `http://${config.options.host}:${config.options.port}`,
70
+ logger: instance.log,
71
+ unstable_experiments: {
72
+ enableNewDebugger: config.experiments?.experimentalDebugger
73
+ }
74
+ });
64
75
 
65
76
  // Register plugins
66
77
  await instance.register(fastifySensible);
78
+ await instance.register(middie);
67
79
  await instance.register(wssPlugin, {
68
- options: config.options,
80
+ options: {
81
+ ...config.options,
82
+ endpoints: devMiddleware.websocketEndpoints
83
+ },
69
84
  delegate
70
85
  });
71
86
  await instance.register(multipartPlugin);
@@ -76,17 +91,21 @@ export async function createServer(config) {
76
91
  await instance.register(compilerPlugin, {
77
92
  delegate
78
93
  });
79
- await instance.register(symbolicatePlugin, {
80
- delegate
81
- });
94
+
95
+ // TODO: devtoolsPlugin and the following deprecated remote debugger middlewares should be removed after
96
+ // the new (experimental) debugger is stable AND the remote debugger is finally removed from the React Native core.
97
+ // When that happens remember to remove @react-native-community/cli-server-api & @react-native-community/cli-debugger-ui
98
+ // from the dependencies.
82
99
  await instance.register(devtoolsPlugin, {
83
100
  options: config.options
84
101
  });
85
- await instance.register(fastifyStatic, {
86
- root: debuggerAppPath,
87
- prefix: '/debugger-ui',
88
- prefixAvoidTrailingSlash: true
102
+ instance.use('/debugger-ui', debuggerUIMiddleware());
103
+ instance.use('/open-url', openURLMiddleware);
104
+ instance.use('/open-stack-frame', openStackFrameInEditorMiddleware);
105
+ await instance.register(symbolicatePlugin, {
106
+ delegate
89
107
  });
108
+
90
109
  // below is to prevent showing `GET 400 /favicon.ico`
91
110
  // errors in console when requesting the bundle via browser
92
111
  await instance.register(faviconPlugin);
@@ -100,6 +119,9 @@ export async function createServer(config) {
100
119
  return payload;
101
120
  });
102
121
 
122
+ // Register dev middleware
123
+ instance.use(devMiddleware.middleware);
124
+
103
125
  // Register routes
104
126
  instance.get('/', async () => delegate.messages.getHello());
105
127
  instance.get('/status', async () => delegate.messages.getStatus());
@@ -1 +1 @@
1
- {"version":3,"file":"createServer.js","names":["Writable","Fastify","fastifySensible","fastifyStatic","debuggerAppPath","multipartPlugin","compilerPlugin","devtoolsPlugin","apiPlugin","wssPlugin","faviconPlugin","Internal","symbolicatePlugin","createServer","config","delegate","instance","logger","level","stream","write","chunk","_encoding","callback","log","JSON","parse","toString","onMessage","wss","apiServer","send","options","https","undefined","notifyBuildStart","platform","event","EventTypes","BuildStart","notifyBuildEnd","BuildEnd","broadcastToHmrClients","clientIds","hmrServer","broadcastToMessageClients","method","params","messageServer","broadcast","register","prefix","root","prefixAvoidTrailingSlash","addHook","request","reply","payload","header","rootDir","pathname","url","split","endsWith","get","messages","getHello","getStatus","start","listen","port","host","stop","close"],"sources":["../src/createServer.ts"],"sourcesContent":["import { Writable } from 'stream';\nimport Fastify from 'fastify';\nimport fastifySensible from '@fastify/sensible';\nimport fastifyStatic from '@fastify/static';\nimport debuggerAppPath from '@callstack/repack-debugger-app';\nimport multipartPlugin from './plugins/multipart';\nimport compilerPlugin from './plugins/compiler';\nimport devtoolsPlugin from './plugins/devtools';\nimport apiPlugin from './plugins/api';\nimport wssPlugin from './plugins/wss';\nimport faviconPlugin from './plugins/favicon';\nimport { Internal, Server } from './types';\nimport symbolicatePlugin from './plugins/symbolicate';\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 let delegate: Server.Delegate;\n\n /** Fastify instance powering the development server. */\n const instance = Fastify({\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 = 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 // Register plugins\n await instance.register(fastifySensible);\n await instance.register(wssPlugin, {\n options: config.options,\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(symbolicatePlugin, {\n delegate,\n });\n await instance.register(devtoolsPlugin, {\n options: config.options,\n });\n\n await instance.register(fastifyStatic, {\n root: debuggerAppPath,\n prefix: '/debugger-ui',\n prefixAvoidTrailingSlash: true,\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 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,QAAQ;AACjC,OAAOC,OAAO,MAAM,SAAS;AAC7B,OAAOC,eAAe,MAAM,mBAAmB;AAC/C,OAAOC,aAAa,MAAM,iBAAiB;AAC3C,OAAOC,eAAe,MAAM,gCAAgC;AAAC,OACtDC,eAAe;AAAA,OACfC,cAAc;AAAA,OACdC,cAAc;AAAA,OACdC,SAAS;AAAA,OACTC,SAAS;AAAA,OACTC,aAAa;AAAA,SACXC,QAAQ;AAAA,OACVC,iBAAiB;AAExB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,YAAYA,CAACC,MAAqB,EAAE;EACxD,IAAIC,QAAyB;;EAE7B;EACA,MAAMC,QAAQ,GAAGf,OAAO,CAAC;IACvBgB,MAAM,EAAE;MACNC,KAAK,EAAE,OAAO;MACdC,MAAM,EAAE,IAAInB,QAAQ,CAAC;QACnBoB,KAAK,EAAEA,CAACC,KAAK,EAAEC,SAAS,EAAEC,QAAQ,KAAK;UACrC,MAAMC,GAAG,GAAGC,IAAI,CAACC,KAAK,CAACL,KAAK,CAACM,QAAQ,CAAC,CAAC,CAAC;UACxCZ,QAAQ,EAAEE,MAAM,CAACW,SAAS,CAACJ,GAAG,CAAC;UAC/BR,QAAQ,CAACa,GAAG,EAAEC,SAAS,CAACC,IAAI,CAACP,GAAG,CAAC;UACjCD,QAAQ,CAAC,CAAC;QACZ;MACF,CAAC;IACH,CAAC;IACD,IAAIT,MAAM,CAACkB,OAAO,CAACC,KAAK,GAAG;MAAEA,KAAK,EA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B,MAAMpD,QAAQ,CAACqD,MAAM,CAAC;MACpBC,IAAI,EAAExD,MAAM,CAACkB,OAAO,CAACsC,IAAI;MACzBC,IAAI,EAAEzD,MAAM,CAACkB,OAAO,CAACuC;IACvB,CAAC,CAAC;EACJ;;EAEA;EACA,eAAeC,IAAIA,CAAA,EAAG;IACpB,MAAMxD,QAAQ,CAACyD,KAAK,CAAC,CAAC;EACxB;EAEA,OAAO;IACLL,KAAK;IACLI,IAAI;IACJxD;EACF,CAAC;AACH"}
1
+ {"version":3,"file":"createServer.js","names":["Writable","Fastify","fastifySensible","middie","createDevMiddleware","debuggerUIMiddleware","openURLMiddleware","openStackFrameInEditorMiddleware","multipartPlugin","compilerPlugin","apiPlugin","wssPlugin","faviconPlugin","Internal","symbolicatePlugin","devtoolsPlugin","createServer","config","delegate","instance","logger","level","stream","write","chunk","_encoding","callback","log","JSON","parse","toString","onMessage","wss","apiServer","send","options","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","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 'stream';\nimport Fastify from 'fastify';\nimport fastifySensible from '@fastify/sensible';\nimport middie from '@fastify/middie';\n// eslint-disable-next-line import/no-unresolved -- no main field in package.json\nimport { createDevMiddleware } from '@react-native/dev-middleware';\nimport { debuggerUIMiddleware } from '@react-native-community/cli-debugger-ui';\nimport {\n openURLMiddleware,\n openStackFrameInEditorMiddleware,\n} from '@react-native-community/cli-server-api';\nimport multipartPlugin from './plugins/multipart';\nimport compilerPlugin from './plugins/compiler';\nimport apiPlugin from './plugins/api';\nimport wssPlugin from './plugins/wss';\nimport faviconPlugin from './plugins/favicon';\nimport { Internal, Server } from './types';\nimport symbolicatePlugin from './plugins/symbolicate';\nimport devtoolsPlugin from './plugins/devtools';\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 let delegate: Server.Delegate;\n\n /** Fastify instance powering the development server. */\n const instance = Fastify({\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 = 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('/open-stack-frame', openStackFrameInEditorMiddleware);\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,QAAQ;AACjC,OAAOC,OAAO,MAAM,SAAS;AAC7B,OAAOC,eAAe,MAAM,mBAAmB;AAC/C,OAAOC,MAAM,MAAM,iBAAiB;AACpC;AACA,SAASC,mBAAmB,QAAQ,8BAA8B;AAClE,SAASC,oBAAoB,QAAQ,yCAAyC;AAC9E,SACEC,iBAAiB,EACjBC,gCAAgC,QAC3B,wCAAwC;AAAC,OACzCC,eAAe;AAAA,OACfC,cAAc;AAAA,OACdC,SAAS;AAAA,OACTC,SAAS;AAAA,OACTC,aAAa;AAAA,SACXC,QAAQ;AAAA,OACVC,iBAAiB;AAAA,OACjBC,cAAc;AAErB;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,YAAYA,CAACC,MAAqB,EAAE;EACxD,IAAIC,QAA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O,CAACuB,IAAI;MACzBD,IAAI,EAAExC,MAAM,CAACkB,OAAO,CAACsB;IACvB,CAAC,CAAC;EACJ;;EAEA;EACA,eAAe2B,IAAIA,CAAA,EAAG;IACpB,MAAMjE,QAAQ,CAACkE,KAAK,CAAC,CAAC;EACxB;EAEA,OAAO;IACLH,KAAK;IACLE,IAAI;IACJjE;EACF,CAAC;AACH"}
@@ -1,6 +1,4 @@
1
- import path from 'path';
2
1
  import open from 'open';
3
- import openEditor from 'open-editor';
4
2
  import fastifyPlugin from 'fastify-plugin';
5
3
  async function devtoolsPlugin(instance, {
6
4
  options
@@ -41,64 +39,6 @@ async function devtoolsPlugin(instance, {
41
39
  reply.send('OK');
42
40
  }
43
41
  });
44
- instance.route({
45
- method: ['GET', 'POST', 'PUT'],
46
- url: '/open-stack-frame',
47
- handler: async (request, reply) => {
48
- try {
49
- const {
50
- file,
51
- lineNumber,
52
- column
53
- } = typeof request.body === 'string' ? JSON.parse(request.body) : request.body;
54
- const url = `${path.join(options.rootDir,
55
- // TODO: make it generic
56
- file.replace('webpack://', ''))}:${lineNumber}:${column ?? 1}`;
57
- request.log.info({
58
- msg: 'Opening stack frame in editor',
59
- url
60
- });
61
- openEditor([url]);
62
- reply.send('OK');
63
- } catch (error) {
64
- request.log.error({
65
- msg: 'Failed to open stack frame in editor',
66
- error: error.message
67
- });
68
- reply.code(400).send();
69
- }
70
- }
71
- });
72
- instance.route({
73
- method: ['GET', 'POST', 'PUT'],
74
- url: '/open-url',
75
- handler: async (request, reply) => {
76
- try {
77
- const {
78
- url
79
- } = JSON.parse(request.body);
80
- request.log.info({
81
- msg: 'Opening URL',
82
- url
83
- });
84
- await open(url);
85
- reply.send('OK');
86
- } catch (error) {
87
- request.log.error({
88
- msg: 'Failed to open URL',
89
- error
90
- });
91
- reply.code(400).send();
92
- }
93
- }
94
- });
95
-
96
- // Silence this route
97
- instance.get('/inspector/device', {
98
- logLevel: 'silent'
99
- }, (_request, reply) => {
100
- reply.code(404).send();
101
- });
102
42
  }
103
43
  export default fastifyPlugin(devtoolsPlugin, {
104
44
  name: 'devtools-plugin',
@@ -1 +1 @@
1
- {"version":3,"file":"devtoolsPlugin.js","names":["path","open","openEditor","fastifyPlugin","devtoolsPlugin","instance","options","route","method","url","handler","_request","reply","wss","messageServer","broadcast","send","request","customDebugger","process","env","REACT_DEBUGGER","debuggerServer","isDebuggerConnected","https","host","port","log","info","msg","error","file","lineNumber","column","body","JSON","parse","join","rootDir","replace","message","code","get","logLevel","name","dependencies"],"sources":["../../../src/plugins/devtools/devtoolsPlugin.ts"],"sourcesContent":["import path from 'path';\nimport open from 'open';\nimport openEditor from 'open-editor';\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.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 instance.route({\n method: ['GET', 'POST', 'PUT'],\n url: '/launch-js-devtools',\n handler: async (request, reply) => {\n const customDebugger = process.env.REACT_DEBUGGER;\n if (customDebugger) {\n // NOOP for now\n } else if (!instance.wss.debuggerServer.isDebuggerConnected()) {\n const url = `${options.https ? 'https' : 'http'}://${\n options.host || 'localhost'\n }:${options.port}/debugger-ui`;\n try {\n request.log.info({ msg: 'Opening debugger UI', url });\n await open(url);\n } catch (error) {\n if (error) {\n request.log.error({\n msg: 'Cannot open debugger UI',\n url,\n error,\n });\n }\n }\n }\n reply.send('OK');\n },\n });\n\n instance.route({\n method: ['GET', 'POST', 'PUT'],\n url: '/open-stack-frame',\n handler: async (request, reply) => {\n try {\n const { file, lineNumber, column } = (\n typeof request.body === 'string'\n ? JSON.parse(request.body)\n : request.body\n ) as {\n file: string;\n lineNumber: number;\n column?: number;\n };\n const url = `${path.join(\n options.rootDir,\n // TODO: make it generic\n file.replace('webpack://', '')\n )}:${lineNumber}:${column ?? 1}`;\n\n request.log.info({ msg: 'Opening stack frame in editor', url });\n openEditor([url]);\n reply.send('OK');\n } catch (error) {\n request.log.error({\n msg: 'Failed to open stack frame in editor',\n error: (error as Error).message,\n });\n reply.code(400).send();\n }\n },\n });\n\n instance.route({\n method: ['GET', 'POST', 'PUT'],\n url: '/open-url',\n handler: async (request, reply) => {\n try {\n const { url } = JSON.parse(request.body as string) as { url: string };\n request.log.info({ msg: 'Opening URL', url });\n await open(url);\n reply.send('OK');\n } catch (error) {\n request.log.error({ msg: 'Failed to open URL', error });\n reply.code(400).send();\n }\n },\n });\n\n // Silence this route\n instance.get(\n '/inspector/device',\n { logLevel: 'silent' as any },\n (_request, reply) => {\n reply.code(404).send();\n }\n );\n}\n\nexport default fastifyPlugin(devtoolsPlugin, {\n name: 'devtools-plugin',\n dependencies: ['wss-plugin'],\n});\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;AACvB,OAAOC,IAAI,MAAM,MAAM;AACvB,OAAOC,UAAU,MAAM,aAAa;AAEpC,OAAOC,aAAa,MAAM,gBAAgB;AAG1C,eAAeC,cAAcA,CAC3BC,QAAyB,EACzB;EAAEC;AAAqC,CAAC,EACxC;EACAD,QAAQ,CAACE,KAAK,CAAC;IACbC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;IAC9BC,GAAG,EAAE,SAAS;IACdC,OAAO,EAAEA,CAACC,QAAQ,EAAEC,KAAK,KAAK;MAC5BP,QAAQ,CAACQ,GAAG,CAACC,aAAa,CAACC,SAAS,CAAC,QAAQ,CAAC;MAC9CH,KAAK,CAACI,IAAI,CAAC,IAAI,CAAC;IAClB;EACF,CAAC,CAAC;EAEFX,QAAQ,CAACE,KAAK,CAAC;IACbC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;IAC9BC,GAAG,EAAE,qBAAqB;IAC1BC,OAAO,EAAE,MAAAA,CAAOO,OAAO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;;EAEF;EACAX,QAAQ,CAACqC,GAAG,CACV,mBAAmB,EACnB;IAAEC,QAAQ,EAAE;EAAgB,CAAC,EAC7B,CAAChC,QAAQ,EAAEC,KAAK,KAAK;IACnBA,KAAK,CAAC6B,IAAI,CAAC,GAAG,CAAC,CAACzB,IAAI,CAAC,CAAC;EACxB,CACF,CAAC;AACH;AAEA,eAAeb,aAAa,CAACC,cAAc,EAAE;EAC3CwC,IAAI,EAAE,iBAAiB;EACvBC,YAAY,EAAE,CAAC,YAAY;AAC7B,CAAC,CAAC"}
1
+ {"version":3,"file":"devtoolsPlugin.js","names":["open","fastifyPlugin","devtoolsPlugin","instance","options","route","method","url","handler","_request","reply","wss","messageServer","broadcast","send","request","customDebugger","process","env","REACT_DEBUGGER","debuggerServer","isDebuggerConnected","https","host","port","log","info","msg","error","name","dependencies"],"sources":["../../../src/plugins/devtools/devtoolsPlugin.ts"],"sourcesContent":["import open from 'open';\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.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 instance.route({\n method: ['GET', 'POST', 'PUT'],\n url: '/launch-js-devtools',\n handler: async (request, reply) => {\n const customDebugger = process.env.REACT_DEBUGGER;\n if (customDebugger) {\n // NOOP for now\n } else if (!instance.wss.debuggerServer.isDebuggerConnected()) {\n const url = `${options.https ? 'https' : 'http'}://${\n options.host || 'localhost'\n }:${options.port}/debugger-ui`;\n try {\n request.log.info({ msg: 'Opening debugger UI', url });\n await open(url);\n } catch (error) {\n if (error) {\n request.log.error({\n msg: 'Cannot open debugger UI',\n url,\n error,\n });\n }\n }\n }\n reply.send('OK');\n },\n });\n}\n\nexport default fastifyPlugin(devtoolsPlugin, {\n name: 'devtools-plugin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AACG,KAAK,CAAC;cAChBD,GAAG,EAAE,yBAAyB;cAC9BpB,GAAG;cACHqB;YACF,CAAC,CAAC;UACJ;QACF;MACF;MACAlB,KAAK,CAACI,IAAI,CAAC,IAAI,CAAC;IAClB;EACF,CAAC,CAAC;AACJ;AAEA,eAAeb,aAAa,CAACC,cAAc,EAAE;EAC3C2B,IAAI,EAAE,iBAAiB;EACvBC,YAAY,EAAE,CAAC,YAAY;AAC7B,CAAC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { FastifyInstance } from 'fastify';
2
- import { WebSocketServer } from './WebSocketServer';
2
+ import { WebSocketServerInterface } from './types';
3
3
  /**
4
4
  * Class for creating a WebSocket router to forward connections to the
5
5
  * respective {@link WebSocketServer} as long as the connection is accepted for the upgrade by the
@@ -13,7 +13,7 @@ import { WebSocketServer } from './WebSocketServer';
13
13
  export declare class WebSocketRouter {
14
14
  private fastify;
15
15
  /** The list of all register WebSocket servers. */
16
- protected servers: WebSocketServer[];
16
+ protected servers: WebSocketServerInterface[];
17
17
  /**
18
18
  * Create new instance of `WebSocketRouter` and attach it to the given Fastify instance.
19
19
  * Any logging information, will be passed through standard `fastify.log` API.
@@ -28,5 +28,5 @@ export declare class WebSocketRouter {
28
28
  * @param server WebSocket server to register.
29
29
  * @returns The same instance of the WebSocket server after it's been registered.
30
30
  */
31
- registerServer<T extends WebSocketServer>(server: T): T;
31
+ registerServer<T extends WebSocketServerInterface>(server: T): T;
32
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"WebSocketRouter.js","names":["WebSocketRouter","servers","constructor","fastify","server","on","request","socket","head","pathname","URL","url","matched","shouldUpgrade","upgrade","log","debug","msg","destroy","registerServer","push"],"sources":["../../../src/plugins/wss/WebSocketRouter.ts"],"sourcesContent":["import type { IncomingMessage } from 'http';\nimport type { Socket } from 'net';\nimport type { FastifyInstance } from 'fastify';\nimport { WebSocketServer } from './WebSocketServer';\n\n/**\n * Class for creating a WebSocket router to forward connections to the\n * respective {@link WebSocketServer} as long as the connection is accepted for the upgrade by the\n * server.\n *\n * If the connection is not accepted by any `WebSocketServer`, it will be destroyed to avoid\n * creating handling connections and potentially throwing `ECONNRESET` errors.\n *\n * @category Development server\n */\nexport class WebSocketRouter {\n /** The list of all register WebSocket servers. */\n protected servers: WebSocketServer[] = [];\n\n /**\n * Create new instance of `WebSocketRouter` 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 router to.\n */\n constructor(private fastify: FastifyInstance) {\n this.fastify.server.on(\n 'upgrade',\n (request: IncomingMessage, socket: Socket, head: Buffer) => {\n const { pathname } = new URL(request.url || '', 'http://localhost');\n let matched = false;\n for (const server of this.servers) {\n if (server.shouldUpgrade(pathname)) {\n matched = true;\n server.upgrade(request, socket, head);\n break;\n }\n }\n\n if (!matched) {\n this.fastify.log.debug({\n msg: 'Destroying socket connection as no server was matched',\n pathname,\n });\n socket.destroy();\n }\n }\n );\n }\n\n /**\n * Register a new {@link WebSocketServer}. New connection will now\n * check if the given server will accept them and forward them.\n *\n * @param server WebSocket server to register.\n * @returns The same instance of the WebSocket server after it's been registered.\n */\n registerServer<T extends WebSocketServer>(server: T): T {\n this.servers.push(server);\n return server;\n }\n}\n"],"mappings":"AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,eAAe,CAAC;EAC3B;EACUC,OAAO,GAAsB,EAAE;;EAEzC;AACF;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAASC,OAAwB,EAAE;IAAA,KAA1BA,OAAwB,GAAxBA,OAAwB;IAC1C,IAAI,CAACA,OAAO,CAACC,MAAM,CAACC,EAAE,CACpB,SAAS,EACT,CAACC,OAAwB,EAAEC,MAAc,EAAEC,IAAY,KAAK;MAC1D,MAAM;QAAEC;MAAS,CAAC,GAAG,IAAIC,GAAG,CAACJ,OAAO,CAACK,GAAG,IAAI,EAAE,EAAE,kBAAkB,CAAC;MACnE,IAAIC,OAAO,GAAG,KAAK;MACnB,KAAK,MAAMR,MAAM,IAAI,IAAI,CAACH,OAAO,EAAE;QACjC,IAAIG,MAAM,CAACS,aAAa,CAACJ,QAAQ,CAAC,EAAE;UAClCG,OAAO,GAAG,IAAI;UACdR,MAAM,CAACU,OAAO,CAACR,OAAO,EAAEC,MAAM,EAAEC,IAAI,CAAC;UACrC;QACF;MACF;MAEA,IAAI,CAACI,OAAO,EAAE;QACZ,IAAI,CAACT,OAAO,CAACY,GAAG,CAACC,KAAK,CAAC;UACrBC,GAAG,EAAE,uDAAuD;UAC5DR;QACF,CAAC,CAAC;QACFF,MAAM,CAACW,OAAO,CAAC,CAAC;MAClB;IACF,CACF,CAAC;EACH;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,cAAcA,CAA4Bf,MAAS,EAAK;IACtD,IAAI,CAACH,OAAO,CAACmB,IAAI,CAAChB,MAAM,CAAC;IACzB,OAAOA,MAAM;EACf;AACF"}
1
+ {"version":3,"file":"WebSocketRouter.js","names":["WebSocketRouter","servers","constructor","fastify","server","on","request","socket","head","pathname","URL","url","matched","shouldUpgrade","upgrade","log","debug","msg","destroy","registerServer","push"],"sources":["../../../src/plugins/wss/WebSocketRouter.ts"],"sourcesContent":["import type { IncomingMessage } from 'node:http';\nimport type { Socket } from 'node:net';\nimport type { FastifyInstance } from 'fastify';\nimport { WebSocketServerInterface } from './types';\n\n/**\n * Class for creating a WebSocket router to forward connections to the\n * respective {@link WebSocketServer} as long as the connection is accepted for the upgrade by the\n * server.\n *\n * If the connection is not accepted by any `WebSocketServer`, it will be destroyed to avoid\n * creating handling connections and potentially throwing `ECONNRESET` errors.\n *\n * @category Development server\n */\nexport class WebSocketRouter {\n /** The list of all register WebSocket servers. */\n protected servers: WebSocketServerInterface[] = [];\n\n /**\n * Create new instance of `WebSocketRouter` 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 router to.\n */\n constructor(private fastify: FastifyInstance) {\n this.fastify.server.on(\n 'upgrade',\n (request: IncomingMessage, socket: Socket, head: Buffer) => {\n const { pathname } = new URL(request.url || '', 'http://localhost');\n let matched = false;\n for (const server of this.servers) {\n if (server.shouldUpgrade(pathname)) {\n matched = true;\n server.upgrade(request, socket, head);\n break;\n }\n }\n\n if (!matched) {\n this.fastify.log.debug({\n msg: 'Destroying socket connection as no server was matched',\n pathname,\n });\n socket.destroy();\n }\n }\n );\n }\n\n /**\n * Register a new {@link WebSocketServer}. New connection will now\n * check if the given server will accept them and forward them.\n *\n * @param server WebSocket server to register.\n * @returns The same instance of the WebSocket server after it's been registered.\n */\n registerServer<T extends WebSocketServerInterface>(server: T): T {\n this.servers.push(server);\n return server;\n }\n}\n"],"mappings":"AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,eAAe,CAAC;EAC3B;EACUC,OAAO,GAA+B,EAAE;;EAElD;AACF;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAASC,OAAwB,EAAE;IAAA,KAA1BA,OAAwB,GAAxBA,OAAwB;IAC1C,IAAI,CAACA,OAAO,CAACC,MAAM,CAACC,EAAE,CACpB,SAAS,EACT,CAACC,OAAwB,EAAEC,MAAc,EAAEC,IAAY,KAAK;MAC1D,MAAM;QAAEC;MAAS,CAAC,GAAG,IAAIC,GAAG,CAACJ,OAAO,CAACK,GAAG,IAAI,EAAE,EAAE,kBAAkB,CAAC;MACnE,IAAIC,OAAO,GAAG,KAAK;MACnB,KAAK,MAAMR,MAAM,IAAI,IAAI,CAACH,OAAO,EAAE;QACjC,IAAIG,MAAM,CAACS,aAAa,CAACJ,QAAQ,CAAC,EAAE;UAClCG,OAAO,GAAG,IAAI;UACdR,MAAM,CAACU,OAAO,CAACR,OAAO,EAAEC,MAAM,EAAEC,IAAI,CAAC;UACrC;QACF;MACF;MAEA,IAAI,CAACI,OAAO,EAAE;QACZ,IAAI,CAACT,OAAO,CAACY,GAAG,CAACC,KAAK,CAAC;UACrBC,GAAG,EAAE,uDAAuD;UAC5DR;QACF,CAAC,CAAC;QACFF,MAAM,CAACW,OAAO,CAAC,CAAC;MAClB;IACF,CACF,CAAC;EACH;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,cAAcA,CAAqCf,MAAS,EAAK;IAC/D,IAAI,CAACH,OAAO,CAACmB,IAAI,CAAChB,MAAM,CAAC;IACzB,OAAOA,MAAM;EACf;AACF"}
@@ -5,17 +5,18 @@ import type { IncomingMessage } from 'http';
5
5
  import type { Socket } from 'net';
6
6
  import type { FastifyInstance } from 'fastify';
7
7
  import { ServerOptions, WebSocket, WebSocketServer as WebSocketServerImpl } from 'ws';
8
+ import { WebSocketServerInterface } from './types';
8
9
  /**
9
10
  * Abstract class for providing common logic (eg routing) for all WebSocket servers.
10
11
  *
11
12
  * @category Development server
12
13
  */
13
- export declare abstract class WebSocketServer {
14
+ export declare abstract class WebSocketServer implements WebSocketServerInterface {
14
15
  /** An instance of the underlying WebSocket server. */
15
- readonly server: WebSocketServerImpl;
16
+ protected server: WebSocketServerImpl;
16
17
  /** Fastify instance from which {@link server} will receive upgrade connections. */
17
18
  protected fastify: FastifyInstance;
18
- readonly paths: string[];
19
+ protected paths: string[];
19
20
  /**
20
21
  * Create a new instance of the WebSocketServer.
21
22
  * Any logging information, will be passed through standard `fastify.log` API.
@@ -1,5 +1,4 @@
1
1
  import { WebSocketServer as WebSocketServerImpl } from 'ws';
2
-
3
2
  /**
4
3
  * Abstract class for providing common logic (eg routing) for all WebSocket servers.
5
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"WebSocketServer.js","names":["WebSocketServer","WebSocketServerImpl","constructor","fastify","path","wssOptions","server","noServer","on","onConnection","bind","paths","Array","isArray","shouldUpgrade","pathname","includes","upgrade","request","socket","head","handleUpgrade","webSocket","emit"],"sources":["../../../src/plugins/wss/WebSocketServer.ts"],"sourcesContent":["import type { IncomingMessage } from 'http';\nimport type { Socket } from 'net';\nimport type { FastifyInstance } from 'fastify';\nimport {\n ServerOptions,\n WebSocket,\n WebSocketServer as WebSocketServerImpl,\n} from 'ws';\n\n/**\n * Abstract class for providing common logic (eg routing) for all WebSocket servers.\n *\n * @category Development server\n */\nexport abstract class WebSocketServer {\n /** An instance of the underlying WebSocket server. */\n public readonly server: WebSocketServerImpl;\n\n /** Fastify instance from which {@link server} will receive upgrade connections. */\n protected fastify: FastifyInstance;\n\n public readonly paths: string[];\n\n /**\n * Create a new instance of the WebSocketServer.\n * Any logging information, will be passed through standard `fastify.log` API.\n *\n * @param fastify Fastify instance to which the WebSocket will be attached to.\n * @param path Path on which this WebSocketServer will be accepting connections.\n * @param wssOptions WebSocket Server options.\n */\n constructor(\n fastify: FastifyInstance,\n path: string | string[],\n wssOptions: Omit<\n ServerOptions,\n 'noServer' | 'server' | 'host' | 'port' | 'path'\n > = {}\n ) {\n this.fastify = fastify;\n this.server = new WebSocketServerImpl({\n noServer: true,\n ...wssOptions,\n });\n this.server.on('connection', this.onConnection.bind(this));\n this.paths = Array.isArray(path) ? path : [path];\n }\n\n shouldUpgrade(pathname: string) {\n return this.paths.includes(pathname);\n }\n\n upgrade(request: IncomingMessage, socket: Socket, head: Buffer) {\n this.server.handleUpgrade(request, socket, head, (webSocket) => {\n this.server.emit('connection', webSocket, request);\n });\n }\n\n /**\n * Process incoming WebSocket connection.\n *\n * @param socket Incoming WebSocket connection.\n * @param request Upgrade request for the connection.\n */\n abstract onConnection(socket: WebSocket, request: IncomingMessage): void;\n}\n"],"mappings":"AAGA,SAGEA,eAAe,IAAIC,mBAAmB,QACjC,IAAI;;AAEX;AACA;AACA;AACA;AACA;AACA,OAAO,MAAeD,eAAe,CAAC;EACpC;;EAGA;;EAKA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEE,WAAWA,CACTC,OAAwB,EACxBC,IAAuB,EACvBC,UAGC,GAAG,CAAC,CAAC,EACN;IACA,IAAI,CAACF,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACG,MAAM,GAAG,IAAIL,mBAAmB,CAAC;MACpCM,QAAQ,EAAE,IAAI;MACd,GAAGF;IACL,CAAC,CAAC;IACF,IAAI,CAACC,MAAM,CAACE,EAAE,CAAC,YAAY,EAAE,IAAI,CAACC,YAAY,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1D,IAAI,CAACC,KAAK,GAAGC,KAAK,CAACC,OAAO,CAACT,IAAI,CAAC,GAAGA,IAAI,GAAG,CAACA,IAAI,CAAC;EAClD;EAEAU,aAAaA,CAACC,QAAgB,EAAE;IAC9B,OAAO,IAAI,CAACJ,KAAK,CAACK,QAAQ,CAACD,QAAQ,CAAC;EACtC;EAEAE,OAAOA,CAACC,OAAwB,EAAEC,MAAc,EAAEC,IAAY,EAAE;IAC9D,IAAI,CAACd,MAAM,CAACe,aAAa,CAACH,OAAO,EAAEC,MAAM,EAAEC,IAAI,EAAGE,SAAS,IAAK;MAC9D,IAAI,CAAChB,MAAM,CAACiB,IAAI,CAAC,YAAY,EAAED,SAAS,EAAEJ,OAAO,CAAC;IACpD,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;AAEA"}
1
+ {"version":3,"file":"WebSocketServer.js","names":["WebSocketServer","WebSocketServerImpl","constructor","fastify","path","wssOptions","server","noServer","on","onConnection","bind","paths","Array","isArray","shouldUpgrade","pathname","includes","upgrade","request","socket","head","handleUpgrade","webSocket","emit"],"sources":["../../../src/plugins/wss/WebSocketServer.ts"],"sourcesContent":["import type { IncomingMessage } from 'http';\nimport type { Socket } from 'net';\nimport type { FastifyInstance } from 'fastify';\nimport {\n ServerOptions,\n WebSocket,\n WebSocketServer as WebSocketServerImpl,\n} from 'ws';\nimport { WebSocketServerInterface } from './types';\n\n/**\n * Abstract class for providing common logic (eg routing) for all WebSocket servers.\n *\n * @category Development server\n */\nexport abstract class WebSocketServer implements WebSocketServerInterface {\n /** An instance of the underlying WebSocket server. */\n protected server: WebSocketServerImpl;\n\n /** Fastify instance from which {@link server} will receive upgrade connections. */\n protected fastify: FastifyInstance;\n\n protected paths: string[];\n\n /**\n * Create a new instance of the WebSocketServer.\n * Any logging information, will be passed through standard `fastify.log` API.\n *\n * @param fastify Fastify instance to which the WebSocket will be attached to.\n * @param path Path on which this WebSocketServer will be accepting connections.\n * @param wssOptions WebSocket Server options.\n */\n constructor(\n fastify: FastifyInstance,\n path: string | string[],\n wssOptions: Omit<\n ServerOptions,\n 'noServer' | 'server' | 'host' | 'port' | 'path'\n > = {}\n ) {\n this.fastify = fastify;\n this.server = new WebSocketServerImpl({ noServer: true, ...wssOptions });\n this.server.on('connection', this.onConnection.bind(this));\n this.paths = Array.isArray(path) ? path : [path];\n }\n\n shouldUpgrade(pathname: string) {\n return this.paths.includes(pathname);\n }\n\n upgrade(request: IncomingMessage, socket: Socket, head: Buffer) {\n this.server.handleUpgrade(request, socket, head, (webSocket) => {\n this.server.emit('connection', webSocket, request);\n });\n }\n\n /**\n * Process incoming WebSocket connection.\n *\n * @param socket Incoming WebSocket connection.\n * @param request Upgrade request for the connection.\n */\n abstract onConnection(socket: WebSocket, request: IncomingMessage): void;\n}\n"],"mappings":"AAGA,SAGEA,eAAe,IAAIC,mBAAmB,QACjC,IAAI;AAGX;AACA;AACA;AACA;AACA;AACA,OAAO,MAAeD,eAAe,CAAqC;EACxE;;EAGA;;EAKA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEE,WAAWA,CACTC,OAAwB,EACxBC,IAAuB,EACvBC,UAGC,GAAG,CAAC,CAAC,EACN;IACA,IAAI,CAACF,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACG,MAAM,GAAG,IAAIL,mBAAmB,CAAC;MAAEM,QAAQ,EAAE,IAAI;MAAE,GAAGF;IAAW,CAAC,CAAC;IACxE,IAAI,CAACC,MAAM,CAACE,EAAE,CAAC,YAAY,EAAE,IAAI,CAACC,YAAY,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1D,IAAI,CAACC,KAAK,GAAGC,KAAK,CAACC,OAAO,CAACT,IAAI,CAAC,GAAGA,IAAI,GAAG,CAACA,IAAI,CAAC;EAClD;EAEAU,aAAaA,CAACC,QAAgB,EAAE;IAC9B,OAAO,IAAI,CAACJ,KAAK,CAACK,QAAQ,CAACD,QAAQ,CAAC;EACtC;EAEAE,OAAOA,CAACC,OAAwB,EAAEC,MAAc,EAAEC,IAAY,EAAE;IAC9D,IAAI,CAACd,MAAM,CAACe,aAAa,CAACH,OAAO,EAAEC,MAAM,EAAEC,IAAI,EAAGE,SAAS,IAAK;MAC9D,IAAI,CAAChB,MAAM,CAACiB,IAAI,CAAC,YAAY,EAAED,SAAS,EAAEJ,OAAO,CAAC;IACpD,CAAC,CAAC;EACJ;;EAEA;AACF;AACA;AACA;AACA;AACA;AAEA"}
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import type { IncomingMessage } from 'node:http';
5
+ import type { Socket } from 'node:net';
6
+ import type { FastifyInstance } from 'fastify';
7
+ import type { WebSocketServer as WebSocketServer } from 'ws';
8
+ import type { WebSocketServerInterface } from './types';
9
+ export declare class WebSocketServerAdapter implements WebSocketServerInterface {
10
+ private fastify;
11
+ private path;
12
+ private server?;
13
+ constructor(fastify: FastifyInstance, path: string, server?: WebSocketServer | undefined);
14
+ shouldUpgrade(pathname: string): boolean;
15
+ upgrade(request: IncomingMessage, socket: Socket, head: Buffer): void;
16
+ }
@@ -0,0 +1,22 @@
1
+ export class WebSocketServerAdapter {
2
+ constructor(fastify, path, server) {
3
+ this.fastify = fastify;
4
+ this.path = path;
5
+ this.server = server;
6
+ }
7
+ shouldUpgrade(pathname) {
8
+ if (!this.server) {
9
+ this.fastify.log.warn({
10
+ msg: `No handler active for ${this.path}`
11
+ });
12
+ return false;
13
+ }
14
+ return this.path === pathname;
15
+ }
16
+ upgrade(request, socket, head) {
17
+ this.server.handleUpgrade(request, socket, head, webSocket => {
18
+ this.server.emit('connection', webSocket, request);
19
+ });
20
+ }
21
+ }
22
+ //# sourceMappingURL=WebSocketServerAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebSocketServerAdapter.js","names":["WebSocketServerAdapter","constructor","fastify","path","server","shouldUpgrade","pathname","log","warn","msg","upgrade","request","socket","head","handleUpgrade","webSocket","emit"],"sources":["../../../src/plugins/wss/WebSocketServerAdapter.ts"],"sourcesContent":["import type { IncomingMessage } from 'node:http';\nimport type { Socket } from 'node:net';\nimport type { FastifyInstance } from 'fastify';\nimport type { WebSocketServer as WebSocketServer } from 'ws';\nimport type { WebSocketServerInterface } from './types';\n\nexport class WebSocketServerAdapter implements WebSocketServerInterface {\n constructor(\n private fastify: FastifyInstance,\n private path: string,\n private server?: WebSocketServer\n ) {}\n\n shouldUpgrade(pathname: string) {\n if (!this.server) {\n this.fastify.log.warn({ msg: `No handler active for ${this.path}` });\n return false;\n }\n return this.path === pathname;\n }\n\n upgrade(request: IncomingMessage, socket: Socket, head: Buffer) {\n this.server!.handleUpgrade(request, socket, head, (webSocket) => {\n this.server!.emit('connection', webSocket, request);\n });\n }\n}\n"],"mappings":"AAMA,OAAO,MAAMA,sBAAsB,CAAqC;EACtEC,WAAWA,CACDC,OAAwB,EACxBC,IAAY,EACZC,MAAwB,EAChC;IAAA,KAHQF,OAAwB,GAAxBA,OAAwB;IAAA,KACxBC,IAAY,GAAZA,IAAY;IAAA,KACZC,MAAwB,GAAxBA,MAAwB;EAC/B;EAEHC,aAAaA,CAACC,QAAgB,EAAE;IAC9B,IAAI,CAAC,IAAI,CAACF,MAAM,EAAE;MAChB,IAAI,CAACF,OAAO,CAACK,GAAG,CAACC,IAAI,CAAC;QAAEC,GAAG,EAAG,yBAAwB,IAAI,CAACN,IAAK;MAAE,CAAC,CAAC;MACpE,OAAO,KAAK;IACd;IACA,OAAO,IAAI,CAACA,IAAI,KAAKG,QAAQ;EAC/B;EAEAI,OAAOA,CAACC,OAAwB,EAAEC,MAAc,EAAEC,IAAY,EAAE;IAC9D,IAAI,CAACT,MAAM,CAAEU,aAAa,CAACH,OAAO,EAAEC,MAAM,EAAEC,IAAI,EAAGE,SAAS,IAAK;MAC/D,IAAI,CAACX,MAAM,CAAEY,IAAI,CAAC,YAAY,EAAED,SAAS,EAAEJ,OAAO,CAAC;IACrD,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);
@@ -65,25 +65,21 @@ export class WebSocketHMRServer extends WebSocketServer {
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);
71
+ };
72
+ this.clients.set(client, socket);
72
73
  this.fastify.log.info({
73
74
  msg: 'HMR client connected',
74
- clientId,
75
- platform
75
+ ...client
76
76
  });
77
77
  const onClose = () => {
78
78
  this.fastify.log.info({
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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B,OAAO,CAACE,GAAG,IAAI,EAAE,EAAE,kBAAkB,CAAC;IACvE,MAAMf,QAAQ,GAAGc,YAAY,CAACE,GAAG,CAAC,UAAU,CAAC;IAE7C,IAAI,CAAChB,QAAQ,EAAE;MACb,IAAI,CAACL,OAAO,CAACe,GAAG,CAACO,IAAI,CAAC;QACpBN,GAAG,EAAE;MACP,CAAC,CAAC;MACFL,MAAM,CAACY,KAAK,CAAC,CAAC;MACd;IACF;IAEA,MAAMX,QAAQ,GAAI,UAAS,IAAI,CAACd,YAAY,EAAG,EAAC;IAChD,IAAI,CAACF,OAAO,CAAC4B,GAAG,CAAC;MAAEZ,QAAQ;MAAEP;IAAS,CAAC,EAAEM,MAAM,CAAC;IAEhD,IAAI,CAACX,OAAO,CAACe,GAAG,CAACO,IAAI,CAAC;MAAEN,GAAG,EAAE,sBAAsB;MAAEJ,QAAQ;MAAEP;IAAS,CAAC,CAAC;IAE1E,MAAMoB,OAAO,GAAGA,CAAA,KAAM;MACpB,IAAI,CAACzB,OAAO,CAACe,GAAG,CAACO,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","info","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.info({\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.info({ msg: 'HMR client connected', ...client });\n\n const onClose = () => {\n this.fastify.log.info({\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,EAAE;IACvD,MAAMC,IAAI,GAAG,OAAOH,KAAK,KAAK,QAAQ,GAAGA,KAAK,GAAGI,IAAI,CAACC,SAAS,CAACL,KAAK,CAAC;IAEtE,KAAK,MAAM,CAACM,GAAG,EAAEC,MAAM,CAAC,IAAI,IAAI,CAACf,OAAO,EAAE;MACxC,IACEc,GAAG,CAACL,QAAQ,KAAKA,QAAQ,IACzB,CAAC,CAACC,SAAS,IAAI,CAACI,GAAG,CAACE,QAAQ,CAAC,EAAEC,QAAQ,CAACH,GAAG,CAACE,QAAQ,CAAC,EACrD;QACA;MACF;MAEA,IAAI;QACFD,MAAM,CAACR,IAAI,CAACI,IAAI,CAAC;MACnB,CAAC,CAAC,OAAOO,KAAK,EAAE;QACd,IAAI,CAACd,OAAO,CAACe,GAAG,CAACD,KAAK,CAAC;UACrBE,GAAG,EAAE,8BAA8B;UACnCZ,KAAK;UACLU,KAAK;UACL,GAAGJ;QACL,CAAC,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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,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ACJ;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,MAAM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,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,9 +11,13 @@ 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
16
  delegate: (context: DelegateContext) => Delegate;
15
17
  }
18
+ interface Experiments {
19
+ experimentalDebugger?: boolean;
20
+ }
16
21
  /** Development server options. */
17
22
  interface Options {
18
23
  /** Root directory of the project. */
@@ -31,6 +36,8 @@ 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>;
34
41
  }
35
42
  /**
36
43
  * A complete delegate with implementations for all server functionalities.
@@ -56,7 +63,7 @@ export declare namespace Server {
56
63
  */
57
64
  interface DelegateContext {
58
65
  /** A logger instance, useful for emitting logs from the delegate. */
59
- log: FastifyLoggerInstance;
66
+ log: FastifyBaseLogger;
60
67
  /** Send notification about compilation start for given `platform`. */
61
68
  notifyBuildStart: (platform: string) => void;
62
69
  /** Send notification about compilation end for given `platform`. */
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) => 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\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;AAuKvB;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"}
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.1",
5
+ "version": "4.0.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
@@ -1 +0,0 @@
1
- {"version":3,"file":"HermesInspectorProxy.js","names":["URL","WebSocketServer","Device","WS_DEVICE_URL","WS_DEBUGGER_URL","HermesInspectorProxy","devices","Map","deviceCounter","constructor","fastify","config","serverHost","host","port","setup","onSend","_request","reply","_payload","done","headers","Connection","get","Browser","pageListHandler","pages","deviceId","device","devicePages","getPagesList","page","push","buildPageDescription","logLevel","debuggerUrl","id","webSocketDebuggerUrl","devtoolsFrontendUrl","encodeURIComponent","description","app","title","faviconUrl","type","vm","onConnection","socket","request","url","searchParams","startsWith","deviceName","appName","set","rootDir","log","info","msg","onClose","delete","addEventListener","undefined","pageId","Error","parseInt","handleDebuggerConnection","error","message","close","toString"],"sources":["../../../../src/plugins/wss/servers/HermesInspectorProxy.ts"],"sourcesContent":["import type { IncomingMessage } from 'http';\nimport { URL } from 'url';\nimport WebSocket from 'ws';\nimport type {\n FastifyInstance,\n FastifyReply,\n FastifyRequest,\n LogLevel,\n} from 'fastify';\nimport { WebSocketServer } from '../WebSocketServer';\nimport { Server } from '../../../types';\n// @ts-ignore\nimport Device from '../../../../vendor/metro-inspector-proxy/src/Device.js';\n\nconst WS_DEVICE_URL = '/inspector/device';\nconst WS_DEBUGGER_URL = '/inspector/debug';\n\ninterface PageDescription {\n id: string;\n description: string;\n title: string;\n faviconUrl: string;\n devtoolsFrontendUrl: string;\n type: string;\n webSocketDebuggerUrl: string;\n vm?: string;\n}\n\ninterface Page {\n id: string;\n title: string;\n app: string;\n vm?: string;\n}\n\nexport interface InspectorProxyConfig\n extends Pick<Server.Options, 'port' | 'host' | 'rootDir'> {}\n\nexport class HermesInspectorProxy extends WebSocketServer {\n private devices = new Map<number, any>();\n private deviceCounter = 0;\n public readonly serverHost: string;\n\n constructor(\n fastify: FastifyInstance,\n private config: InspectorProxyConfig\n ) {\n super(fastify, [WS_DEVICE_URL, WS_DEBUGGER_URL]);\n this.serverHost = `${this.config.host || 'localhost'}:${this.config.port}`;\n this.setup();\n }\n\n private setup() {\n const onSend = (\n _request: FastifyRequest,\n reply: FastifyReply,\n _payload: unknown,\n done: () => void\n ) => {\n reply.headers({\n 'Content-Type': 'application/json; charset=UTF-8',\n 'Cache-Control': 'no-cache',\n Connection: 'close',\n });\n done();\n };\n\n this.fastify.get('/json/version', { onSend }, async () => {\n return {\n Browser: 'Mobile JavaScript',\n 'Protocol-Version': '1.1',\n };\n });\n\n const pageListHandler = async () => {\n const pages: PageDescription[] = [];\n for (const [deviceId, device] of this.devices) {\n const devicePages = device.getPagesList();\n for (const page of devicePages) {\n pages.push(this.buildPageDescription(deviceId, page));\n }\n }\n\n return pages;\n };\n\n this.fastify.get('/json/list', { onSend }, pageListHandler);\n this.fastify.get(\n '/json',\n { onSend, logLevel: 'silent' as LogLevel },\n pageListHandler\n );\n }\n\n private buildPageDescription(deviceId: number, page: Page) {\n const debuggerUrl = `${this.serverHost}${WS_DEBUGGER_URL}?device=${deviceId}&page=${page.id}`;\n const webSocketDebuggerUrl = 'ws://' + debuggerUrl;\n const devtoolsFrontendUrl =\n 'chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=' +\n encodeURIComponent(debuggerUrl);\n return {\n id: `${deviceId}-${page.id}`,\n description: page.app,\n title: page.title,\n faviconUrl: 'https://reactjs.org/favicon.ico',\n devtoolsFrontendUrl,\n type: 'node',\n webSocketDebuggerUrl,\n vm: page.vm,\n };\n }\n\n /**\n * Process new WebSocket connection from device.\n *\n * @param socket Incoming device's WebSocket connection.\n * @param request Upgrade request for the connection.\n */\n onConnection(socket: WebSocket, request: IncomingMessage) {\n try {\n const { url = '' } = request;\n const { searchParams } = new URL(url, 'http://localhost');\n\n if (url.startsWith('/inspector/device')) {\n const deviceName = searchParams.get('name') ?? 'Unknown';\n const appName = searchParams.get('app') ?? 'Unknown';\n const deviceId = this.deviceCounter++;\n\n this.devices.set(\n deviceId,\n new Device(deviceId, deviceName, appName, socket, this.config.rootDir)\n );\n\n this.fastify.log.info({ msg: 'Hermes device connected', deviceId });\n\n const onClose = () => {\n this.fastify.log.info({\n msg: 'Hermes device disconnected',\n deviceId,\n });\n this.devices.delete(deviceId);\n };\n\n socket.addEventListener('error', onClose);\n socket.addEventListener('close', onClose);\n } else {\n const deviceId = searchParams.get('device') ?? undefined;\n const pageId = searchParams.get('page') ?? undefined;\n\n if (deviceId === undefined || pageId === undefined) {\n throw new Error('Incorrect URL - must provide device and page IDs');\n }\n\n const device = this.devices.get(parseInt(deviceId, 10));\n if (!device) {\n throw new Error('Unknown device with ID ' + deviceId);\n }\n\n device.handleDebuggerConnection(socket, pageId);\n }\n } catch (error) {\n this.fastify.log.error({\n msg: 'Failed to establish connection with Hermes device',\n error: (error as Error).message,\n });\n socket.close(1011, (error as Error).toString());\n }\n }\n}\n"],"mappings":"AACA,SAASA,GAAG,QAAQ,KAAK;AAAC,SAQjBC,eAAe;AAExB;AACA,OAAOC,MAAM,MAAM,wDAAwD;AAE3E,MAAMC,aAAa,GAAG,mBAAmB;AACzC,MAAMC,eAAe,GAAG,kBAAkB;AAuB1C,OAAO,MAAMC,oBAAoB,SAASJ,eAAe,CAAC;EAChDK,OAAO,GAAG,IAAIC,GAAG,CAAc,CAAC;EAChCC,aAAa,GAAG,CAAC;EAGzBC,WAAWA,CACTC,OAAwB,EAChBC,MAA4B,EACpC;IACA,KAAK,CAACD,OAAO,EAAE,CAACP,aAAa,EAAEC,eAAe,CAAC,CAAC;IAAC,KAFzCO,MAA4B,GAA5BA,MAA4B;IAGpC,IAAI,CAACC,UAAU,GAAI,GAAE,IAAI,CAACD,MAAM,CAACE,IAAI,IAAI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