@callstack/repack-dev-server 4.0.0-rc.2 → 5.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +4 -4
- package/dist/createServer.js +37 -12
- package/dist/createServer.js.map +1 -1
- package/dist/plugins/compiler/compilerPlugin.js +1 -12
- package/dist/plugins/compiler/compilerPlugin.js.map +1 -1
- package/dist/plugins/compiler/types.d.ts +1 -3
- package/dist/plugins/compiler/types.js.map +1 -1
- package/dist/plugins/devtools/devtoolsPlugin.js +0 -60
- package/dist/plugins/devtools/devtoolsPlugin.js.map +1 -1
- package/dist/plugins/symbolicate/Symbolicator.js +3 -2
- package/dist/plugins/symbolicate/Symbolicator.js.map +1 -1
- package/dist/plugins/wss/WebSocketRouter.d.ts +3 -3
- package/dist/plugins/wss/WebSocketRouter.js.map +1 -1
- package/dist/plugins/wss/WebSocketServer.d.ts +4 -3
- package/dist/plugins/wss/WebSocketServer.js +0 -1
- package/dist/plugins/wss/WebSocketServer.js.map +1 -1
- package/dist/plugins/wss/WebSocketServerAdapter.d.ts +16 -0
- package/dist/plugins/wss/WebSocketServerAdapter.js +22 -0
- package/dist/plugins/wss/WebSocketServerAdapter.js.map +1 -0
- package/dist/plugins/wss/servers/WebSocketApiServer.js +2 -2
- package/dist/plugins/wss/servers/WebSocketApiServer.js.map +1 -1
- package/dist/plugins/wss/servers/WebSocketDevClientServer.js +9 -4
- package/dist/plugins/wss/servers/WebSocketDevClientServer.js.map +1 -1
- package/dist/plugins/wss/servers/WebSocketHMRServer.js +10 -14
- package/dist/plugins/wss/servers/WebSocketHMRServer.js.map +1 -1
- package/dist/plugins/wss/types.d.ts +9 -0
- package/dist/plugins/wss/types.js.map +1 -1
- package/dist/plugins/wss/wssPlugin.d.ts +3 -2
- package/dist/plugins/wss/wssPlugin.js +15 -4
- package/dist/plugins/wss/wssPlugin.js.map +1 -1
- package/dist/types.d.ts +12 -17
- package/dist/types.js +0 -7
- package/dist/types.js.map +1 -1
- package/package.json +17 -5
- package/dist/plugins/wss/servers/HermesInspectorProxy.d.ts +0 -24
- package/dist/plugins/wss/servers/HermesInspectorProxy.js +0 -120
- package/dist/plugins/wss/servers/HermesInspectorProxy.js.map +0 -1
- package/vendor/metro-inspector-proxy/src/Device.cjs +0 -1
- package/vendor/metro-inspector-proxy/src/Device.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @callstack/repack-dev-server
|
|
2
2
|
|
|
3
|
+
## 5.0.0-next.0
|
|
4
|
+
|
|
5
|
+
## 4.0.0
|
|
6
|
+
|
|
7
|
+
### Major Changes
|
|
8
|
+
|
|
9
|
+
- [#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
|
|
10
|
+
|
|
11
|
+
- [#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:
|
|
12
|
+
- Removed vendored code and used middlewares from `@react-native-community/cli-server-api`
|
|
13
|
+
- Removed `package/debugger-app` and replaced it with `@react-native-community/cli-debugger-ui`
|
|
14
|
+
- Removed vendored code responsible for integration with Flipper debugger & custom implementation of the Hermes Inspector Proxy
|
|
15
|
+
- Added integration with `@react-native/dev-middleware` which enables us to use both Flipper and new experimental debugger
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#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
|
|
20
|
+
|
|
21
|
+
- [#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
|
|
22
|
+
|
|
23
|
+
- [#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
|
|
24
|
+
|
|
3
25
|
## 4.0.0-rc.2
|
|
4
26
|
|
|
5
27
|
## 4.0.0-rc.1
|
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.
|
|
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-
|
|
26
|
-
[version]: https://www.npmjs.com/package/@callstack/repack-
|
|
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
|
package/dist/createServer.js
CHANGED
|
@@ -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
|
|
5
|
-
import
|
|
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
|
*
|
|
@@ -22,6 +25,7 @@ export async function createServer(config) {
|
|
|
22
25
|
|
|
23
26
|
/** Fastify instance powering the development server. */
|
|
24
27
|
const instance = Fastify({
|
|
28
|
+
disableRequestLogging: !config.options.logRequests,
|
|
25
29
|
logger: {
|
|
26
30
|
level: 'trace',
|
|
27
31
|
stream: new Writable({
|
|
@@ -37,7 +41,7 @@ export async function createServer(config) {
|
|
|
37
41
|
https: config.options.https
|
|
38
42
|
} : undefined)
|
|
39
43
|
});
|
|
40
|
-
delegate = config.delegate({
|
|
44
|
+
delegate = await config.delegate({
|
|
41
45
|
log: instance.log,
|
|
42
46
|
notifyBuildStart: platform => {
|
|
43
47
|
instance.wss.apiServer.send({
|
|
@@ -61,11 +65,23 @@ export async function createServer(config) {
|
|
|
61
65
|
instance.wss.messageServer.broadcast(method, params);
|
|
62
66
|
}
|
|
63
67
|
});
|
|
68
|
+
const devMiddleware = createDevMiddleware({
|
|
69
|
+
projectRoot: config.options.rootDir,
|
|
70
|
+
serverBaseUrl: `http://${config.options.host}:${config.options.port}`,
|
|
71
|
+
logger: instance.log,
|
|
72
|
+
unstable_experiments: {
|
|
73
|
+
enableNewDebugger: config.experiments?.experimentalDebugger
|
|
74
|
+
}
|
|
75
|
+
});
|
|
64
76
|
|
|
65
77
|
// Register plugins
|
|
66
78
|
await instance.register(fastifySensible);
|
|
79
|
+
await instance.register(middie);
|
|
67
80
|
await instance.register(wssPlugin, {
|
|
68
|
-
options:
|
|
81
|
+
options: {
|
|
82
|
+
...config.options,
|
|
83
|
+
endpoints: devMiddleware.websocketEndpoints
|
|
84
|
+
},
|
|
69
85
|
delegate
|
|
70
86
|
});
|
|
71
87
|
await instance.register(multipartPlugin);
|
|
@@ -76,17 +92,23 @@ export async function createServer(config) {
|
|
|
76
92
|
await instance.register(compilerPlugin, {
|
|
77
93
|
delegate
|
|
78
94
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
95
|
+
|
|
96
|
+
// TODO: devtoolsPlugin and the following deprecated remote debugger middlewares should be removed after
|
|
97
|
+
// the new (experimental) debugger is stable AND the remote debugger is finally removed from the React Native core.
|
|
98
|
+
// When that happens remember to remove @react-native-community/cli-server-api & @react-native-community/cli-debugger-ui
|
|
99
|
+
// from the dependencies.
|
|
82
100
|
await instance.register(devtoolsPlugin, {
|
|
83
101
|
options: config.options
|
|
84
102
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
103
|
+
instance.use('/debugger-ui', debuggerUIMiddleware());
|
|
104
|
+
instance.use('/open-url', openURLMiddleware);
|
|
105
|
+
instance.use('/open-stack-frame', openStackFrameInEditorMiddleware({
|
|
106
|
+
watchFolders: [config.options.rootDir]
|
|
107
|
+
}));
|
|
108
|
+
await instance.register(symbolicatePlugin, {
|
|
109
|
+
delegate
|
|
89
110
|
});
|
|
111
|
+
|
|
90
112
|
// below is to prevent showing `GET 400 /favicon.ico`
|
|
91
113
|
// errors in console when requesting the bundle via browser
|
|
92
114
|
await instance.register(faviconPlugin);
|
|
@@ -100,6 +122,9 @@ export async function createServer(config) {
|
|
|
100
122
|
return payload;
|
|
101
123
|
});
|
|
102
124
|
|
|
125
|
+
// Register dev middleware
|
|
126
|
+
instance.use(devMiddleware.middleware);
|
|
127
|
+
|
|
103
128
|
// Register routes
|
|
104
129
|
instance.get('/', async () => delegate.messages.getHello());
|
|
105
130
|
instance.get('/status', async () => delegate.messages.getStatus());
|
package/dist/createServer.js.map
CHANGED
|
@@ -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,I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,QAAQ,CAACgD,GAAG,CAAC,SAAS,EAAE,YAAYjD,QAAQ,CAACkD,QAAQ,CAACE,SAAS,CAAC,CAAC,CAAC;;EAElE;EACA,eAAeC,KAAKA,CAAA,EAAG;IACrB,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","disableRequestLogging","options","logRequests","logger","level","stream","write","chunk","_encoding","callback","log","JSON","parse","toString","onMessage","wss","apiServer","send","https","undefined","notifyBuildStart","platform","event","EventTypes","BuildStart","notifyBuildEnd","BuildEnd","broadcastToHmrClients","clientIds","hmrServer","broadcastToMessageClients","method","params","messageServer","broadcast","devMiddleware","projectRoot","rootDir","serverBaseUrl","host","port","unstable_experiments","enableNewDebugger","experiments","experimentalDebugger","register","endpoints","websocketEndpoints","prefix","use","watchFolders","addHook","request","reply","payload","header","pathname","url","split","endsWith","middleware","get","messages","getHello","getStatus","start","listen","stop","close"],"sources":["../src/createServer.ts"],"sourcesContent":["import { Writable } from '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 disableRequestLogging: !config.options.logRequests,\n logger: {\n level: 'trace',\n stream: new Writable({\n write: (chunk, _encoding, callback) => {\n const log = JSON.parse(chunk.toString());\n delegate?.logger.onMessage(log);\n instance.wss?.apiServer.send(log);\n callback();\n },\n }),\n },\n ...(config.options.https ? { https: config.options.https } : undefined),\n });\n\n delegate = await config.delegate({\n log: instance.log,\n notifyBuildStart: (platform) => {\n instance.wss.apiServer.send({\n event: Internal.EventTypes.BuildStart,\n platform,\n });\n },\n notifyBuildEnd: (platform) => {\n instance.wss.apiServer.send({\n event: Internal.EventTypes.BuildEnd,\n platform,\n });\n },\n broadcastToHmrClients: (event, platform, clientIds) => {\n instance.wss.hmrServer.send(event, platform, clientIds);\n },\n broadcastToMessageClients: ({ method, params }) => {\n instance.wss.messageServer.broadcast(method, params);\n },\n });\n\n const devMiddleware = createDevMiddleware({\n projectRoot: config.options.rootDir,\n serverBaseUrl: `http://${config.options.host}:${config.options.port}`,\n logger: instance.log,\n unstable_experiments: {\n enableNewDebugger: config.experiments?.experimentalDebugger,\n },\n });\n\n // Register plugins\n await instance.register(fastifySensible);\n await instance.register(middie);\n await instance.register(wssPlugin, {\n options: {\n ...config.options,\n endpoints: devMiddleware.websocketEndpoints,\n },\n delegate,\n });\n await instance.register(multipartPlugin);\n await instance.register(apiPlugin, {\n delegate,\n prefix: '/api',\n });\n await instance.register(compilerPlugin, {\n delegate,\n });\n\n // TODO: devtoolsPlugin and the following deprecated remote debugger middlewares should be removed after\n // the new (experimental) debugger is stable AND the remote debugger is finally removed from the React Native core.\n // When that happens remember to remove @react-native-community/cli-server-api & @react-native-community/cli-debugger-ui\n // from the dependencies.\n await instance.register(devtoolsPlugin, {\n options: config.options,\n });\n instance.use('/debugger-ui', debuggerUIMiddleware());\n instance.use('/open-url', openURLMiddleware);\n instance.use(\n '/open-stack-frame',\n openStackFrameInEditorMiddleware({\n watchFolders: [config.options.rootDir],\n })\n );\n\n await instance.register(symbolicatePlugin, {\n delegate,\n });\n\n // below is to prevent showing `GET 400 /favicon.ico`\n // errors in console when requesting the bundle via browser\n await instance.register(faviconPlugin);\n\n instance.addHook('onSend', async (request, reply, payload) => {\n reply.header('X-Content-Type-Options', 'nosniff');\n reply.header('X-React-Native-Project-Root', config.options.rootDir);\n\n const [pathname] = request.url.split('?');\n if (pathname.endsWith('.map')) {\n reply.header('Access-Control-Allow-Origin', 'devtools://devtools');\n }\n\n return payload;\n });\n\n // Register dev middleware\n instance.use(devMiddleware.middleware);\n\n // Register routes\n instance.get('/', async () => delegate.messages.getHello());\n instance.get('/status', async () => delegate.messages.getStatus());\n\n /** Start the development server. */\n async function start() {\n await instance.listen({\n port: config.options.port,\n host: config.options.host,\n });\n }\n\n /** Stop the development server. */\n async function stop() {\n await instance.close();\n }\n\n return {\n start,\n stop,\n instance,\n };\n}\n"],"mappings":"AAAA,SAASA,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,O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,CAACd,aAAa,CAACyB,UAAU,CAAC;;EAEtC;EACA7D,QAAQ,CAAC8D,GAAG,CAAC,GAAG,EAAE,YAAY/D,QAAQ,CAACgE,QAAQ,CAACC,QAAQ,CAAC,CAAC,CAAC;EAC3DhE,QAAQ,CAAC8D,GAAG,CAAC,SAAS,EAAE,YAAY/D,QAAQ,CAACgE,QAAQ,CAACE,SAAS,CAAC,CAAC,CAAC;;EAElE;EACA,eAAeC,KAAKA,CAAA,EAAG;IACrB,MAAMlE,QAAQ,CAACmE,MAAM,CAAC;MACpB1B,IAAI,EAAE3C,MAAM,CAACI,OAAO,CAACuC,IAAI;MACzBD,IAAI,EAAE1C,MAAM,CAACI,OAAO,CAACsC;IACvB,CAAC,CAAC;EACJ;;EAEA;EACA,eAAe4B,IAAIA,CAAA,EAAG;IACpB,MAAMpE,QAAQ,CAACqE,KAAK,CAAC,CAAC;EACxB;EAEA,OAAO;IACLH,KAAK;IACLE,IAAI;IACJpE;EACF,CAAC;AACH"}
|
|
@@ -39,19 +39,8 @@ async function compilerPlugin(instance, {
|
|
|
39
39
|
file = file.replace(`${platform}/`, '');
|
|
40
40
|
}
|
|
41
41
|
const multipart = reply.asMultipart();
|
|
42
|
-
const sendProgress = ({
|
|
43
|
-
completed,
|
|
44
|
-
total
|
|
45
|
-
}) => {
|
|
46
|
-
multipart?.writeChunk({
|
|
47
|
-
'Content-Type': 'application/json'
|
|
48
|
-
}, JSON.stringify({
|
|
49
|
-
done: completed,
|
|
50
|
-
total
|
|
51
|
-
}));
|
|
52
|
-
};
|
|
53
42
|
try {
|
|
54
|
-
const asset = await delegate.compiler.getAsset(file, platform
|
|
43
|
+
const asset = await delegate.compiler.getAsset(file, platform);
|
|
55
44
|
const mimeType = delegate.compiler.getMimeType(file, platform, asset);
|
|
56
45
|
if (multipart) {
|
|
57
46
|
const buffer = Buffer.isBuffer(asset) ? asset : Buffer.from(asset);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compilerPlugin.js","names":["fastifyPlugin","compilerPlugin","instance","delegate","route","method","url","schema","querystring","type","properties","platform","handler","request","reply","file","params","query","log","error","notFound","compiler","inferPlatform","badRequest","startsWith","replace","multipart","asMultipart","
|
|
1
|
+
{"version":3,"file":"compilerPlugin.js","names":["fastifyPlugin","compilerPlugin","instance","delegate","route","method","url","schema","querystring","type","properties","platform","handler","request","reply","file","params","query","log","error","notFound","compiler","inferPlatform","badRequest","startsWith","replace","multipart","asMultipart","asset","getAsset","mimeType","getMimeType","buffer","Buffer","isBuffer","from","setHeader","String","byteLength","end","code","send","message","name","dependencies"],"sources":["../../../src/plugins/compiler/compilerPlugin.ts"],"sourcesContent":["import type { FastifyInstance } from 'fastify';\nimport fastifyPlugin from 'fastify-plugin';\nimport type { Server } from '../../types';\n\nasync function compilerPlugin(\n instance: FastifyInstance,\n { delegate }: { delegate: Server.Delegate }\n) {\n instance.route({\n method: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD'],\n url: '/*',\n schema: {\n querystring: {\n type: 'object',\n properties: {\n platform: {\n type: 'string',\n },\n },\n },\n },\n handler: async (request, reply) => {\n let file = (request.params as { '*'?: string })['*'];\n let { platform } = request.query as { platform?: string };\n\n if (!file) {\n // This technically should never happen - this route should not be called if file is missing.\n request.log.error(`File was not provided`);\n return reply.notFound();\n }\n\n // Let consumer infer the platform. If function is not provided fallback\n // to platform query param.\n platform = delegate.compiler.inferPlatform?.(request.url) ?? platform;\n\n if (!platform) {\n request.log.error('Cannot detect platform');\n return reply.badRequest('Cannot detect platform');\n }\n\n // If platform happens to be in front of an asset remove it.\n if (file.startsWith(`${platform}/`)) {\n file = file.replace(`${platform}/`, '');\n }\n\n const multipart = reply.asMultipart();\n\n try {\n const asset = await delegate.compiler.getAsset(file, platform);\n const mimeType = delegate.compiler.getMimeType(file, platform, asset);\n\n if (multipart) {\n const buffer = Buffer.isBuffer(asset) ? asset : Buffer.from(asset);\n multipart.setHeader('Content-Type', `${mimeType}; charset=UTF-8`);\n multipart.setHeader(\n 'Content-Length',\n String(Buffer.byteLength(buffer))\n );\n multipart.end(buffer);\n } else {\n return reply.code(200).type(mimeType).send(asset);\n }\n } catch (error) {\n request.log.error(error);\n return reply.notFound((error as Error).message);\n }\n },\n });\n}\n\nexport default fastifyPlugin(compilerPlugin, {\n name: 'compiler-plugin',\n dependencies: ['@fastify/sensible', 'multipart-plugin'],\n});\n"],"mappings":"AACA,OAAOA,aAAa,MAAM,gBAAgB;AAG1C,eAAeC,cAAcA,CAC3BC,QAAyB,EACzB;EAAEC;AAAwC,CAAC,EAC3C;EACAD,QAAQ,CAACE,KAAK,CAAC;IACbC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC;IAC3DC,GAAG,EAAE,IAAI;IACTC,MAAM,EAAE;MACNC,WAAW,EAAE;QACXC,IAAI,EAAE,QAAQ;QACdC,UAAU,EAAE;UACVC,QAAQ,EAAE;YACRF,IAAI,EAAE;UACR;QACF;MACF;IACF,CAAC;IACDG,OAAO,EAAE,MAAAA,CAAOC,OAAO,EAAEC,KAAK,KAAK;MACjC,IAAIC,IAAI,GAAIF,OAAO,CAACG,MAAM,CAAsB,GAAG,CAAC;MACpD,IAAI;QAAEL;MAAS,CAAC,GAAGE,OAAO,CAACI,KAA8B;MAEzD,IAAI,CAACF,IAAI,EAAE;QACT;QACAF,OAAO,CAACK,GAAG,CAACC,KAAK,CAAE,uBAAsB,CAAC;QAC1C,OAAOL,KAAK,CAACM,QAAQ,CAAC,CAAC;MACzB;;MAEA;MACA;MACAT,QAAQ,GAAGR,QAAQ,CAACkB,QAAQ,CAACC,aAAa,GAAGT,OAAO,CAACP,GAAG,CAAC,IAAIK,QAAQ;MAErE,IAAI,CAACA,QAAQ,EAAE;QACbE,OAAO,CAACK,GAAG,CAACC,KAAK,CAAC,wBAAwB,CAAC;QAC3C,OAAOL,KAAK,CAACS,UAAU,CAAC,wBAAwB,CAA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AY,EAAE,CAAC,mBAAmB,EAAE,kBAAkB;AACxD,CAAC,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { SendProgress } from '../../types';
|
|
3
2
|
/**
|
|
4
3
|
* Delegate with implementation for compiler-specific functions.
|
|
5
4
|
*/
|
|
@@ -11,9 +10,8 @@ export interface CompilerDelegate {
|
|
|
11
10
|
*
|
|
12
11
|
* @param filename Filename of the asset to get.
|
|
13
12
|
* @param platform Platform of the asset to get.
|
|
14
|
-
* @param sendProgress Function to notify the client who requested the asset about compilation progress.
|
|
15
13
|
*/
|
|
16
|
-
getAsset: (filename: string, platform: string
|
|
14
|
+
getAsset: (filename: string, platform: string) => Promise<string | Buffer>;
|
|
17
15
|
/**
|
|
18
16
|
* Detect MIME type of the asset from `filename`, `platform` or `data` (or from combination of either).
|
|
19
17
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/compiler/types.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/plugins/compiler/types.ts"],"sourcesContent":["/**\n * Delegate with implementation for compiler-specific functions.\n */\nexport interface CompilerDelegate {\n /**\n * Get compiled asset content.\n *\n * If the compilation is in progress, it should wait until compilation finishes and then return the asset.\n *\n * @param filename Filename of the asset to get.\n * @param platform Platform of the asset to get.\n */\n getAsset: (filename: string, platform: string) => Promise<string | Buffer>;\n\n /**\n * Detect MIME type of the asset from `filename`, `platform` or `data` (or from combination of either).\n *\n * @param filename Filename of the asset.\n * @param platform Platform of the asset.\n * @param data Asset's content.\n */\n getMimeType: (\n filename: string,\n platform: string,\n data: string | Buffer\n ) => string;\n\n /**\n * Detect the platform from the URI - either from filename, query params or both.\n *\n * @param uri URI string.\n */\n inferPlatform?: (uri: string) => string | undefined;\n}\n"],"mappings":""}
|
|
@@ -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":["
|
|
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',\n dependencies: ['wss-plugin'],\n});\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;AAEvB,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,EAAEL,KAAK,KAAK;MACjC,MAAMM,cAAc,GAAGC,OAAO,CAACC,GAAG,CAACC,cAAc;MACjD,IAAIH,cAAc,EAAE;QAClB;MAAA,CACD,MAAM,IAAI,CAACb,QAAQ,CAACQ,GAAG,CAACS,cAAc,CAACC,mBAAmB,CAAC,CAAC,EAAE;QAC7D,MAAMd,GAAG,GAAI,GAAEH,OAAO,CAACkB,KAAK,GAAG,OAAO,GAAG,MAAO,MAC9ClB,OAAO,CAACmB,IAAI,IAAI,WACjB,IAAGnB,OAAO,CAACoB,IAAK,cAAa;QAC9B,IAAI;UACFT,OAAO,CAACU,GAAG,CAACC,IAAI,CAAC;YAAEC,GAAG,EAAE,qBAAqB;YAAEpB;UAAI,CAAC,CAAC;UACrD,MAAMP,IAAI,CAACO,GAAG,CAAC;QACjB,CAAC,CAAC,OAAOqB,KAAK,EAAE;UACd,IAAIA,KAAK,EAAE;YACTb,OAAO,CAACU,GAAG,CAACG,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"}
|
|
@@ -19,7 +19,7 @@ export class Symbolicator {
|
|
|
19
19
|
static inferPlatformFromStack(stack) {
|
|
20
20
|
for (const frame of stack) {
|
|
21
21
|
if (!frame.file) {
|
|
22
|
-
|
|
22
|
+
continue;
|
|
23
23
|
}
|
|
24
24
|
const {
|
|
25
25
|
searchParams,
|
|
@@ -146,7 +146,8 @@ export class Symbolicator {
|
|
|
146
146
|
}
|
|
147
147
|
const lookup = consumer.originalPositionFor({
|
|
148
148
|
line: frame.lineNumber,
|
|
149
|
-
column: frame.column
|
|
149
|
+
column: frame.column,
|
|
150
|
+
bias: SourceMapConsumer.LEAST_UPPER_BOUND
|
|
150
151
|
});
|
|
151
152
|
|
|
152
153
|
// If lookup fails, we get the same shape object, but with
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Symbolicator.js","names":["URL","codeFrameColumns","SourceMapConsumer","Symbolicator","inferPlatformFromStack","stack","frame","file","searchParams","pathname","platform","get","bundleFilename","split","reverse","platformOrExtension","extension","sourceMapConsumerCache","constructor","delegate","process","logger","debug","msg","frames","startsWith","includes","push","processedFrames","fileUrl","rawSourceMap","getSourceMap","sourceMapLength","length","sourceMapConsumer","toString","processedFrame","processFrame","codeFrame","getCodeFrame","key","destroy","lineNumber","column","collapse","consumer","lookup","originalPositionFor","line","source","methodName","name","shouldIncludeFrame","undefined","content","getSource","start","forceColor","location","row","fileName","error","message"],"sources":["../../../src/plugins/symbolicate/Symbolicator.ts"],"sourcesContent":["import { URL } from 'url';\nimport { codeFrameColumns } from '@babel/code-frame';\nimport { SourceMapConsumer } from 'source-map';\nimport type { FastifyLoggerInstance } from 'fastify';\nimport type {\n CodeFrame,\n InputStackFrame,\n ReactNativeStackFrame,\n StackFrame,\n SymbolicatorDelegate,\n SymbolicatorResults,\n} from './types';\n\n/**\n * Class for transforming stack traces from React Native application with using Source Map.\n * Raw stack frames produced by React Native, points to some location from the bundle\n * eg `index.bundle?platform=ios:567:1234`. By using Source Map for that bundle `Symbolicator`\n * produces frames that point to source code inside your project eg `Hello.tsx:10:9`.\n */\nexport class Symbolicator {\n /**\n * Infer platform from stack frames.\n * Usually at least one frame has `file` field with the bundle URL eg:\n * `http://localhost:8081/index.bundle?platform=ios&...`, which can be used to infer platform.\n *\n * @param stack Array of stack frames.\n * @returns Inferred platform or `undefined` if cannot infer.\n */\n static inferPlatformFromStack(stack: ReactNativeStackFrame[]) {\n for (const frame of stack) {\n if (!frame.file) {\n return;\n }\n\n const { searchParams, pathname } = new URL(frame.file, 'file://');\n const platform = searchParams.get('platform');\n if (platform) {\n return platform;\n } else {\n const [bundleFilename] = pathname.split('/').reverse();\n const [, platformOrExtension, extension] = bundleFilename.split('.');\n if (extension) {\n return platformOrExtension;\n }\n }\n }\n }\n\n /**\n * Cache with initialized `SourceMapConsumer` to improve symbolication performance.\n */\n sourceMapConsumerCache: Record<string, SourceMapConsumer> = {};\n\n /**\n * Constructs new `Symbolicator` instance.\n *\n * @param delegate Delegate instance with symbolication functions.\n */\n constructor(private delegate: SymbolicatorDelegate) {}\n\n /**\n * Process raw React Native stack frames and transform them using Source Maps.\n * Method will try to symbolicate as much data as possible, but if the Source Maps\n * are not available, invalid or the original positions/data is not found in Source Maps,\n * the method will return raw values - the same as supplied with `stack` parameter.\n * For example out of 10 frames, it's possible that only first 7 will be symbolicated and the\n * remaining 3 will be unchanged.\n *\n * @param logger Fastify logger instance.\n * @param stack Raw stack frames.\n * @returns Symbolicated stack frames.\n */\n async process(\n logger: FastifyLoggerInstance,\n stack: ReactNativeStackFrame[]\n ): Promise<SymbolicatorResults> {\n logger.debug({ msg: 'Filtering out unnecessary frames' });\n\n const frames: InputStackFrame[] = [];\n for (const frame of stack) {\n const { file } = frame;\n if (file?.startsWith('http') && !file.includes('debuggerWorker')) {\n frames.push(frame as InputStackFrame);\n }\n }\n\n try {\n logger.debug({ msg: 'Processing frames', frames });\n\n const processedFrames: StackFrame[] = [];\n for (const frame of frames) {\n if (!this.sourceMapConsumerCache[frame.file]) {\n logger.debug({\n msg: 'Loading raw source map data',\n fileUrl: frame.file,\n });\n\n const rawSourceMap = await this.delegate.getSourceMap(frame.file);\n\n logger.debug({\n msg: 'Creating source map instance',\n fileUrl: frame.file,\n sourceMapLength: rawSourceMap.length,\n });\n const sourceMapConsumer = await new SourceMapConsumer(\n rawSourceMap.toString()\n );\n\n logger.debug({\n msg: 'Saving source map instance into cache',\n fileUrl: frame.file,\n });\n this.sourceMapConsumerCache[frame.file] = sourceMapConsumer;\n }\n\n logger.debug({\n msg: 'Symbolicating frame',\n frame,\n });\n const processedFrame = this.processFrame(frame);\n\n logger.debug({\n msg: 'Finished symbolicating frame',\n frame,\n });\n processedFrames.push(processedFrame);\n }\n\n const codeFrame =\n (await this.getCodeFrame(logger, processedFrames)) ?? null;\n\n logger.debug({\n msg: 'Finished symbolicating frames',\n processedFrames,\n codeFrame,\n });\n\n return {\n stack: processedFrames,\n codeFrame,\n };\n } finally {\n for (const key in this.sourceMapConsumerCache) {\n this.sourceMapConsumerCache[key].destroy();\n delete this.sourceMapConsumerCache[key];\n }\n }\n }\n\n private processFrame(frame: InputStackFrame): StackFrame {\n if (!frame.lineNumber || !frame.column) {\n return {\n ...frame,\n collapse: false,\n };\n }\n\n const consumer = this.sourceMapConsumerCache[frame.file];\n if (!consumer) {\n return {\n ...frame,\n collapse: false,\n };\n }\n\n const lookup = consumer.originalPositionFor({\n line: frame.lineNumber,\n column: frame.column,\n });\n\n // If lookup fails, we get the same shape object, but with\n // all values set to null\n if (!lookup.source) {\n // It is better to gracefully return the original frame\n // than to throw an exception\n return {\n ...frame,\n collapse: false,\n };\n }\n\n return {\n lineNumber: lookup.line || frame.lineNumber,\n column: lookup.column || frame.column,\n file: lookup.source,\n methodName: lookup.name || frame.methodName,\n collapse: false,\n };\n }\n\n private async getCodeFrame(\n logger: FastifyLoggerInstance,\n processedFrames: StackFrame[]\n ): Promise<CodeFrame | undefined> {\n for (const frame of processedFrames) {\n if (frame.collapse || !frame.lineNumber || !frame.column) {\n continue;\n }\n\n if (!this.delegate.shouldIncludeFrame(frame)) {\n return undefined;\n }\n\n logger.debug({\n msg: 'Generating code frame',\n frame,\n });\n\n try {\n return {\n content: codeFrameColumns(\n (await this.delegate.getSource(frame.file)).toString(),\n {\n start: { column: frame.column, line: frame.lineNumber },\n },\n { forceColor: true }\n ),\n location: {\n row: frame.lineNumber,\n column: frame.column,\n },\n fileName: frame.file,\n };\n } catch (error) {\n logger.error({\n msg: 'Failed to create code frame',\n error: (error as Error).message,\n });\n }\n\n return undefined;\n }\n }\n}\n"],"mappings":"AAAA,SAASA,GAAG,QAAQ,KAAK;AACzB,SAASC,gBAAgB,QAAQ,mBAAmB;AACpD,SAASC,iBAAiB,QAAQ,YAAY;AAW9C;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,CAAC;EACxB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,sBAAsBA,CAACC,KAA8B,EAAE;IAC5D,KAAK,MAAMC,KAAK,IAAID,KAAK,EAAE;MACzB,IAAI,CAACC,KAAK,CAACC,IAAI,EAAE;QACf;MACF;MAEA,MAAM;QAAEC,YAAY;QAAEC;MAAS,CAAC,GAAG,IAAIT,GAAG,CAACM,KAAK,CAACC,IAAI,EAAE,SAAS,CAAC;MACjE,MAAMG,QAAQ,GAAGF,YAAY,CAACG,GAAG,CAAC,UAAU,CAA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AI,CAACpC,KAAK,CAACqC,MAAM,EAAE;QACxD;MACF;MAEA,IAAI,CAAC,IAAI,CAACxB,QAAQ,CAACiC,kBAAkB,CAAC9C,KAAK,CAAC,EAAE;QAC5C,OAAO+C,SAAS;MAClB;MAEAhC,MAAM,CAACC,KAAK,CAAC;QACXC,GAAG,EAAE,uBAAuB;QAC5BjB;MACF,CAAC,CAAC;MAEF,IAAI;QACF,OAAO;UACLgD,OAAO,EAAErD,gBAAgB,CACvB,CAAC,MAAM,IAAI,CAACkB,QAAQ,CAACoC,SAAS,CAACjD,KAAK,CAACC,IAAI,CAAC,EAAE4B,QAAQ,CAAC,CAAC,EACtD;YACEqB,KAAK,EAAE;cAAEb,MAAM,EAAErC,KAAK,CAACqC,MAAM;cAAEK,IAAI,EAAE1C,KAAK,CAACoC;YAAW;UACxD,CAAC,EACD;YAAEe,UAAU,EAAE;UAAK,CACrB,CAAC;UACDC,QAAQ,EAAE;YACRC,GAAG,EAAErD,KAAK,CAACoC,UAAU;YACrBC,MAAM,EAAErC,KAAK,CAACqC;UAChB,CAAC;UACDiB,QAAQ,EAAEtD,KAAK,CAACC;QAClB,CAAC;MACH,CAAC,CAAC,OAAOsD,KAAK,EAAE;QACdxC,MAAM,CAACwC,KAAK,CAAC;UACXtC,GAAG,EAAE,6BAA6B;UAClCsC,KAAK,EAAGA,KAAK,CAAWC;QAC1B,CAAC,CAAC;MACJ;MAEA,OAAOT,SAAS;IAClB;EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"Symbolicator.js","names":["URL","codeFrameColumns","SourceMapConsumer","Symbolicator","inferPlatformFromStack","stack","frame","file","searchParams","pathname","platform","get","bundleFilename","split","reverse","platformOrExtension","extension","sourceMapConsumerCache","constructor","delegate","process","logger","debug","msg","frames","startsWith","includes","push","processedFrames","fileUrl","rawSourceMap","getSourceMap","sourceMapLength","length","sourceMapConsumer","toString","processedFrame","processFrame","codeFrame","getCodeFrame","key","destroy","lineNumber","column","collapse","consumer","lookup","originalPositionFor","line","bias","LEAST_UPPER_BOUND","source","methodName","name","shouldIncludeFrame","undefined","content","getSource","start","forceColor","location","row","fileName","error","message"],"sources":["../../../src/plugins/symbolicate/Symbolicator.ts"],"sourcesContent":["import { URL } from 'url';\nimport { codeFrameColumns } from '@babel/code-frame';\nimport { SourceMapConsumer } from 'source-map';\nimport type { FastifyLoggerInstance } from 'fastify';\nimport type {\n CodeFrame,\n InputStackFrame,\n ReactNativeStackFrame,\n StackFrame,\n SymbolicatorDelegate,\n SymbolicatorResults,\n} from './types';\n\n/**\n * Class for transforming stack traces from React Native application with using Source Map.\n * Raw stack frames produced by React Native, points to some location from the bundle\n * eg `index.bundle?platform=ios:567:1234`. By using Source Map for that bundle `Symbolicator`\n * produces frames that point to source code inside your project eg `Hello.tsx:10:9`.\n */\nexport class Symbolicator {\n /**\n * Infer platform from stack frames.\n * Usually at least one frame has `file` field with the bundle URL eg:\n * `http://localhost:8081/index.bundle?platform=ios&...`, which can be used to infer platform.\n *\n * @param stack Array of stack frames.\n * @returns Inferred platform or `undefined` if cannot infer.\n */\n static inferPlatformFromStack(stack: ReactNativeStackFrame[]) {\n for (const frame of stack) {\n if (!frame.file) {\n continue;\n }\n\n const { searchParams, pathname } = new URL(frame.file, 'file://');\n const platform = searchParams.get('platform');\n if (platform) {\n return platform;\n } else {\n const [bundleFilename] = pathname.split('/').reverse();\n const [, platformOrExtension, extension] = bundleFilename.split('.');\n if (extension) {\n return platformOrExtension;\n }\n }\n }\n }\n\n /**\n * Cache with initialized `SourceMapConsumer` to improve symbolication performance.\n */\n sourceMapConsumerCache: Record<string, SourceMapConsumer> = {};\n\n /**\n * Constructs new `Symbolicator` instance.\n *\n * @param delegate Delegate instance with symbolication functions.\n */\n constructor(private delegate: SymbolicatorDelegate) {}\n\n /**\n * Process raw React Native stack frames and transform them using Source Maps.\n * Method will try to symbolicate as much data as possible, but if the Source Maps\n * are not available, invalid or the original positions/data is not found in Source Maps,\n * the method will return raw values - the same as supplied with `stack` parameter.\n * For example out of 10 frames, it's possible that only first 7 will be symbolicated and the\n * remaining 3 will be unchanged.\n *\n * @param logger Fastify logger instance.\n * @param stack Raw stack frames.\n * @returns Symbolicated stack frames.\n */\n async process(\n logger: FastifyLoggerInstance,\n stack: ReactNativeStackFrame[]\n ): Promise<SymbolicatorResults> {\n logger.debug({ msg: 'Filtering out unnecessary frames' });\n\n const frames: InputStackFrame[] = [];\n for (const frame of stack) {\n const { file } = frame;\n if (file?.startsWith('http') && !file.includes('debuggerWorker')) {\n frames.push(frame as InputStackFrame);\n }\n }\n\n try {\n logger.debug({ msg: 'Processing frames', frames });\n\n const processedFrames: StackFrame[] = [];\n for (const frame of frames) {\n if (!this.sourceMapConsumerCache[frame.file]) {\n logger.debug({\n msg: 'Loading raw source map data',\n fileUrl: frame.file,\n });\n\n const rawSourceMap = await this.delegate.getSourceMap(frame.file);\n\n logger.debug({\n msg: 'Creating source map instance',\n fileUrl: frame.file,\n sourceMapLength: rawSourceMap.length,\n });\n const sourceMapConsumer = await new SourceMapConsumer(\n rawSourceMap.toString()\n );\n\n logger.debug({\n msg: 'Saving source map instance into cache',\n fileUrl: frame.file,\n });\n this.sourceMapConsumerCache[frame.file] = sourceMapConsumer;\n }\n\n logger.debug({\n msg: 'Symbolicating frame',\n frame,\n });\n const processedFrame = this.processFrame(frame);\n\n logger.debug({\n msg: 'Finished symbolicating frame',\n frame,\n });\n processedFrames.push(processedFrame);\n }\n\n const codeFrame =\n (await this.getCodeFrame(logger, processedFrames)) ?? null;\n\n logger.debug({\n msg: 'Finished symbolicating frames',\n processedFrames,\n codeFrame,\n });\n\n return {\n stack: processedFrames,\n codeFrame,\n };\n } finally {\n for (const key in this.sourceMapConsumerCache) {\n this.sourceMapConsumerCache[key].destroy();\n delete this.sourceMapConsumerCache[key];\n }\n }\n }\n\n private processFrame(frame: InputStackFrame): StackFrame {\n if (!frame.lineNumber || !frame.column) {\n return {\n ...frame,\n collapse: false,\n };\n }\n\n const consumer = this.sourceMapConsumerCache[frame.file];\n if (!consumer) {\n return {\n ...frame,\n collapse: false,\n };\n }\n\n const lookup = consumer.originalPositionFor({\n line: frame.lineNumber,\n column: frame.column,\n bias: SourceMapConsumer.LEAST_UPPER_BOUND,\n });\n\n // If lookup fails, we get the same shape object, but with\n // all values set to null\n if (!lookup.source) {\n // It is better to gracefully return the original frame\n // than to throw an exception\n return {\n ...frame,\n collapse: false,\n };\n }\n\n return {\n lineNumber: lookup.line || frame.lineNumber,\n column: lookup.column || frame.column,\n file: lookup.source,\n methodName: lookup.name || frame.methodName,\n collapse: false,\n };\n }\n\n private async getCodeFrame(\n logger: FastifyLoggerInstance,\n processedFrames: StackFrame[]\n ): Promise<CodeFrame | undefined> {\n for (const frame of processedFrames) {\n if (frame.collapse || !frame.lineNumber || !frame.column) {\n continue;\n }\n\n if (!this.delegate.shouldIncludeFrame(frame)) {\n return undefined;\n }\n\n logger.debug({\n msg: 'Generating code frame',\n frame,\n });\n\n try {\n return {\n content: codeFrameColumns(\n (await this.delegate.getSource(frame.file)).toString(),\n {\n start: { column: frame.column, line: frame.lineNumber },\n },\n { forceColor: true }\n ),\n location: {\n row: frame.lineNumber,\n column: frame.column,\n },\n fileName: frame.file,\n };\n } catch (error) {\n logger.error({\n msg: 'Failed to create code frame',\n error: (error as Error).message,\n });\n }\n\n return undefined;\n }\n }\n}\n"],"mappings":"AAAA,SAASA,GAAG,QAAQ,KAAK;AACzB,SAASC,gBAAgB,QAAQ,mBAAmB;AACpD,SAASC,iBAAiB,QAAQ,YAAY;AAW9C;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,CAAC;EACxB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,sBAAsBA,CAACC,KAA8B,EAAE;IAC5D,KAAK,MAAMC,KAAK,IAAID,KAAK,EAAE;MACzB,IAAI,CAACC,KAAK,CAACC,IAAI,EAAE;QACf;MACF;MAEA,MAAM;QAAEC,YAAY;QAAEC;MAAS,CAAC,GAAG,IAAIT,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A,CACxBlB,MAA6B,EAC7BO,eAA6B,EACG;IAChC,KAAK,MAAMtB,KAAK,IAAIsB,eAAe,EAAE;MACnC,IAAItB,KAAK,CAACsC,QAAQ,IAAI,CAACtC,KAAK,CAACoC,UAAU,IAAI,CAACpC,KAAK,CAACqC,MAAM,EAAE;QACxD;MACF;MAEA,IAAI,CAAC,IAAI,CAACxB,QAAQ,CAACmC,kBAAkB,CAAChD,KAAK,CAAC,EAAE;QAC5C,OAAOiD,SAAS;MAClB;MAEAlC,MAAM,CAACC,KAAK,CAAC;QACXC,GAAG,EAAE,uBAAuB;QAC5BjB;MACF,CAAC,CAAC;MAEF,IAAI;QACF,OAAO;UACLkD,OAAO,EAAEvD,gBAAgB,CACvB,CAAC,MAAM,IAAI,CAACkB,QAAQ,CAACsC,SAAS,CAACnD,KAAK,CAACC,IAAI,CAAC,EAAE4B,QAAQ,CAAC,CAAC,EACtD;YACEuB,KAAK,EAAE;cAAEf,MAAM,EAAErC,KAAK,CAACqC,MAAM;cAAEK,IAAI,EAAE1C,KAAK,CAACoC;YAAW;UACxD,CAAC,EACD;YAAEiB,UAAU,EAAE;UAAK,CACrB,CAAC;UACDC,QAAQ,EAAE;YACRC,GAAG,EAAEvD,KAAK,CAACoC,UAAU;YACrBC,MAAM,EAAErC,KAAK,CAACqC;UAChB,CAAC;UACDmB,QAAQ,EAAExD,KAAK,CAACC;QAClB,CAAC;MACH,CAAC,CAAC,OAAOwD,KAAK,EAAE;QACd1C,MAAM,CAAC0C,KAAK,CAAC;UACXxC,GAAG,EAAE,6BAA6B;UAClCwC,KAAK,EAAGA,KAAK,CAAWC;QAC1B,CAAC,CAAC;MACJ;MAEA,OAAOT,SAAS;IAClB;EACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FastifyInstance } from 'fastify';
|
|
2
|
-
import {
|
|
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:
|
|
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
|
|
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 {
|
|
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
|
-
|
|
16
|
+
protected server: WebSocketServerImpl;
|
|
16
17
|
/** Fastify instance from which {@link server} will receive upgrade connections. */
|
|
17
18
|
protected fastify: FastifyInstance;
|
|
18
|
-
|
|
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 +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
|
|
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"}
|