@callstack/repack-dev-server 5.0.0-rc.2 → 5.0.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/dist/createServer.d.ts +3 -2
  2. package/dist/createServer.js +110 -123
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.js +2 -3
  5. package/dist/plugins/api/apiPlugin.d.ts +1 -1
  6. package/dist/plugins/api/apiPlugin.js +21 -28
  7. package/dist/plugins/api/index.d.ts +1 -1
  8. package/dist/plugins/api/index.js +1 -2
  9. package/dist/plugins/compiler/compilerPlugin.d.ts +1 -1
  10. package/dist/plugins/compiler/compilerPlugin.js +53 -62
  11. package/dist/plugins/compiler/index.d.ts +2 -2
  12. package/dist/plugins/compiler/index.js +2 -3
  13. package/dist/plugins/compiler/types.d.ts +1 -1
  14. package/dist/plugins/compiler/types.js +0 -1
  15. package/dist/plugins/devtools/devtoolsPlugin.d.ts +1 -1
  16. package/dist/plugins/devtools/devtoolsPlugin.js +16 -19
  17. package/dist/plugins/devtools/index.d.ts +1 -1
  18. package/dist/plugins/devtools/index.js +1 -2
  19. package/dist/plugins/favicon/faviconPlugin.js +3 -7
  20. package/dist/plugins/favicon/index.d.ts +1 -1
  21. package/dist/plugins/favicon/index.js +1 -2
  22. package/dist/plugins/multipart/index.d.ts +2 -2
  23. package/dist/plugins/multipart/index.js +2 -3
  24. package/dist/plugins/multipart/multipartPlugin.js +44 -42
  25. package/dist/plugins/multipart/types.js +0 -1
  26. package/dist/plugins/symbolicate/Symbolicator.d.ts +1 -1
  27. package/dist/plugins/symbolicate/Symbolicator.js +172 -190
  28. package/dist/plugins/symbolicate/index.d.ts +3 -3
  29. package/dist/plugins/symbolicate/index.js +3 -4
  30. package/dist/plugins/symbolicate/sybmolicatePlugin.d.ts +1 -1
  31. package/dist/plugins/symbolicate/sybmolicatePlugin.js +29 -40
  32. package/dist/plugins/symbolicate/types.js +0 -1
  33. package/dist/plugins/wss/WebSocketRouter.d.ts +1 -1
  34. package/dist/plugins/wss/WebSocketRouter.js +39 -44
  35. package/dist/plugins/wss/WebSocketServer.d.ts +1 -1
  36. package/dist/plugins/wss/WebSocketServer.js +23 -38
  37. package/dist/plugins/wss/WebSocketServerAdapter.d.ts +1 -1
  38. package/dist/plugins/wss/WebSocketServerAdapter.js +16 -19
  39. package/dist/plugins/wss/index.d.ts +3 -3
  40. package/dist/plugins/wss/index.js +3 -4
  41. package/dist/plugins/wss/servers/WebSocketApiServer.d.ts +1 -1
  42. package/dist/plugins/wss/servers/WebSocketApiServer.js +47 -53
  43. package/dist/plugins/wss/servers/WebSocketDevClientServer.d.ts +1 -1
  44. package/dist/plugins/wss/servers/WebSocketDevClientServer.js +58 -80
  45. package/dist/plugins/wss/servers/WebSocketEventsServer.d.ts +2 -2
  46. package/dist/plugins/wss/servers/WebSocketEventsServer.js +146 -164
  47. package/dist/plugins/wss/servers/WebSocketHMRServer.d.ts +2 -2
  48. package/dist/plugins/wss/servers/WebSocketHMRServer.js +72 -79
  49. package/dist/plugins/wss/servers/WebSocketMessageServer.d.ts +1 -1
  50. package/dist/plugins/wss/servers/WebSocketMessageServer.js +309 -326
  51. package/dist/plugins/wss/types.js +0 -1
  52. package/dist/plugins/wss/wssPlugin.d.ts +8 -8
  53. package/dist/plugins/wss/wssPlugin.js +37 -42
  54. package/dist/types.d.ts +6 -6
  55. package/dist/types.js +8 -18
  56. package/package.json +4 -8
  57. package/CHANGELOG.md +0 -160
  58. package/dist/createServer.js.map +0 -1
  59. package/dist/index.js.map +0 -1
  60. package/dist/plugins/api/apiPlugin.js.map +0 -1
  61. package/dist/plugins/api/index.js.map +0 -1
  62. package/dist/plugins/compiler/compilerPlugin.js.map +0 -1
  63. package/dist/plugins/compiler/index.js.map +0 -1
  64. package/dist/plugins/compiler/types.js.map +0 -1
  65. package/dist/plugins/devtools/devtoolsPlugin.js.map +0 -1
  66. package/dist/plugins/devtools/index.js.map +0 -1
  67. package/dist/plugins/favicon/faviconPlugin.js.map +0 -1
  68. package/dist/plugins/favicon/index.js.map +0 -1
  69. package/dist/plugins/multipart/index.js.map +0 -1
  70. package/dist/plugins/multipart/multipartPlugin.js.map +0 -1
  71. package/dist/plugins/multipart/types.js.map +0 -1
  72. package/dist/plugins/symbolicate/Symbolicator.js.map +0 -1
  73. package/dist/plugins/symbolicate/index.js.map +0 -1
  74. package/dist/plugins/symbolicate/sybmolicatePlugin.js.map +0 -1
  75. package/dist/plugins/symbolicate/types.js.map +0 -1
  76. package/dist/plugins/wss/WebSocketRouter.js.map +0 -1
  77. package/dist/plugins/wss/WebSocketServer.js.map +0 -1
  78. package/dist/plugins/wss/WebSocketServerAdapter.js.map +0 -1
  79. package/dist/plugins/wss/index.js.map +0 -1
  80. package/dist/plugins/wss/servers/WebSocketApiServer.js.map +0 -1
  81. package/dist/plugins/wss/servers/WebSocketDevClientServer.js.map +0 -1
  82. package/dist/plugins/wss/servers/WebSocketEventsServer.js.map +0 -1
  83. package/dist/plugins/wss/servers/WebSocketHMRServer.js.map +0 -1
  84. package/dist/plugins/wss/servers/WebSocketMessageServer.js.map +0 -1
  85. package/dist/plugins/wss/types.js.map +0 -1
  86. package/dist/plugins/wss/wssPlugin.js.map +0 -1
  87. package/dist/types.js.map +0 -1
  88. /package/{dist/img → static}/favicon.ico +0 -0
@@ -4,52 +4,54 @@ import fastifyPlugin from 'fastify-plugin';
4
4
  * Implementation is based on:
5
5
  * https://github.com/facebook/metro/blob/347b1d7ed87995d7951aaa9fd597c04b06013dac/packages/metro/src/Server/MultipartResponse.js
6
6
  */
7
-
8
7
  const CRLF = '\r\n';
9
8
  const BOUNDARY = '3beqjf3apnqeu3h5jqorms4i';
10
9
  async function multipartPlugin(instance) {
11
- function asMultipart() {
12
- // We should check if is included in accept or if accept has multipart/* or */*,
13
- // but React Native will set accept to exactly `multipart/mixed`, so a simple check
14
- // will suffice.
15
- if (this.request.headers.accept !== 'multipart/mixed') {
16
- return undefined;
10
+ function asMultipart() {
11
+ // We should check if is included in accept or if accept has multipart/* or */*,
12
+ // but React Native will set accept to exactly `multipart/mixed`, so a simple check
13
+ // will suffice.
14
+ if (this.request.headers.accept !== 'multipart/mixed') {
15
+ return undefined;
16
+ }
17
+ const headers = {};
18
+ const stream = new PassThrough();
19
+ this.code(200)
20
+ .header('Content-Type', `multipart/mixed; boundary="${BOUNDARY}"`)
21
+ .send(stream);
22
+ function serializeHeaders(headers) {
23
+ return Object.keys(headers)
24
+ .map((key) => `${key}: ${headers[key]}`)
25
+ .join(CRLF);
26
+ }
27
+ function writeChunk(headers, data, isLast) {
28
+ let chunk = `${CRLF}--${BOUNDARY}${CRLF}`;
29
+ if (headers) {
30
+ chunk += serializeHeaders(headers) + CRLF + CRLF;
31
+ }
32
+ if (data) {
33
+ chunk += data;
34
+ }
35
+ if (isLast) {
36
+ chunk += `${CRLF}--${BOUNDARY}--${CRLF}`;
37
+ }
38
+ stream.write(chunk);
39
+ }
40
+ function setHeader(name, value) {
41
+ headers[name] = value;
42
+ }
43
+ function end(data) {
44
+ writeChunk(headers, data, true);
45
+ stream.end();
46
+ }
47
+ return {
48
+ writeChunk,
49
+ setHeader,
50
+ end,
51
+ };
17
52
  }
18
- const headers = {};
19
- const stream = new PassThrough();
20
- this.code(200).header('Content-Type', `multipart/mixed; boundary="${BOUNDARY}"`).send(stream);
21
- function serializeHeaders(headers) {
22
- return Object.keys(headers).map(key => `${key}: ${headers[key]}`).join(CRLF);
23
- }
24
- function writeChunk(headers, data, isLast) {
25
- let chunk = `${CRLF}--${BOUNDARY}${CRLF}`;
26
- if (headers) {
27
- chunk += serializeHeaders(headers) + CRLF + CRLF;
28
- }
29
- if (data) {
30
- chunk += data;
31
- }
32
- if (isLast) {
33
- chunk += `${CRLF}--${BOUNDARY}--${CRLF}`;
34
- }
35
- stream.write(chunk);
36
- }
37
- function setHeader(name, value) {
38
- headers[name] = value;
39
- }
40
- function end(data) {
41
- writeChunk(headers, data, true);
42
- stream.end();
43
- }
44
- return {
45
- writeChunk,
46
- setHeader,
47
- end
48
- };
49
- }
50
- instance.decorateReply('asMultipart', asMultipart);
53
+ instance.decorateReply('asMultipart', asMultipart);
51
54
  }
52
55
  export default fastifyPlugin(multipartPlugin, {
53
- name: 'multipart-plugin'
56
+ name: 'multipart-plugin',
54
57
  });
55
- //# sourceMappingURL=multipartPlugin.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map
@@ -1,6 +1,6 @@
1
1
  import type { FastifyLoggerInstance } from 'fastify';
2
2
  import { SourceMapConsumer } from 'source-map';
3
- import type { ReactNativeStackFrame, SymbolicatorDelegate, SymbolicatorResults } from './types';
3
+ import type { ReactNativeStackFrame, SymbolicatorDelegate, SymbolicatorResults } from './types.js';
4
4
  /**
5
5
  * Class for transforming stack traces from React Native application with using Source Map.
6
6
  * Raw stack frames produced by React Native, points to some location from the bundle
@@ -8,201 +8,183 @@ import { SourceMapConsumer } from 'source-map';
8
8
  * produces frames that point to source code inside your project eg `Hello.tsx:10:9`.
9
9
  */
10
10
  export class Symbolicator {
11
- /**
12
- * Infer platform from stack frames.
13
- * Usually at least one frame has `file` field with the bundle URL eg:
14
- * `http://localhost:8081/index.bundle?platform=ios&...`, which can be used to infer platform.
15
- *
16
- * @param stack Array of stack frames.
17
- * @returns Inferred platform or `undefined` if cannot infer.
18
- */
19
- static inferPlatformFromStack(stack) {
20
- for (const frame of stack) {
21
- if (!frame.file) {
22
- continue;
23
- }
24
- const {
25
- searchParams,
26
- pathname
27
- } = new URL(frame.file, 'file://');
28
- const platform = searchParams.get('platform');
29
- if (platform) {
30
- return platform;
31
- }
32
- const [bundleFilename] = pathname.split('/').reverse();
33
- const [, platformOrExtension, extension] = bundleFilename.split('.');
34
- if (extension) {
35
- return platformOrExtension;
36
- }
37
- }
38
- }
39
-
40
- /**
41
- * Cache with initialized `SourceMapConsumer` to improve symbolication performance.
42
- */
43
- sourceMapConsumerCache = {};
44
-
45
- /**
46
- * Constructs new `Symbolicator` instance.
47
- *
48
- * @param delegate Delegate instance with symbolication functions.
49
- */
50
- constructor(delegate) {
51
- this.delegate = delegate;
52
- }
53
-
54
- /**
55
- * Process raw React Native stack frames and transform them using Source Maps.
56
- * Method will try to symbolicate as much data as possible, but if the Source Maps
57
- * are not available, invalid or the original positions/data is not found in Source Maps,
58
- * the method will return raw values - the same as supplied with `stack` parameter.
59
- * For example out of 10 frames, it's possible that only first 7 will be symbolicated and the
60
- * remaining 3 will be unchanged.
61
- *
62
- * @param logger Fastify logger instance.
63
- * @param stack Raw stack frames.
64
- * @returns Symbolicated stack frames.
65
- */
66
- async process(logger, stack) {
67
- logger.debug({
68
- msg: 'Filtering out unnecessary frames'
69
- });
70
- const frames = [];
71
- for (const frame of stack) {
72
- const {
73
- file
74
- } = frame;
75
- if (file?.startsWith('http')) {
76
- frames.push(frame);
77
- }
78
- }
79
- try {
80
- logger.debug({
81
- msg: 'Processing frames',
82
- frames
83
- });
84
- const processedFrames = [];
85
- for (const frame of frames) {
86
- if (!this.sourceMapConsumerCache[frame.file]) {
87
- logger.debug({
88
- msg: 'Loading raw source map data',
89
- fileUrl: frame.file
90
- });
91
- const rawSourceMap = await this.delegate.getSourceMap(frame.file);
92
- logger.debug({
93
- msg: 'Creating source map instance',
94
- fileUrl: frame.file,
95
- sourceMapLength: rawSourceMap.length
96
- });
97
- const sourceMapConsumer = await new SourceMapConsumer(rawSourceMap.toString());
98
- logger.debug({
99
- msg: 'Saving source map instance into cache',
100
- fileUrl: frame.file
101
- });
102
- this.sourceMapConsumerCache[frame.file] = sourceMapConsumer;
11
+ /**
12
+ * Infer platform from stack frames.
13
+ * Usually at least one frame has `file` field with the bundle URL eg:
14
+ * `http://localhost:8081/index.bundle?platform=ios&...`, which can be used to infer platform.
15
+ *
16
+ * @param stack Array of stack frames.
17
+ * @returns Inferred platform or `undefined` if cannot infer.
18
+ */
19
+ static inferPlatformFromStack(stack) {
20
+ for (const frame of stack) {
21
+ if (!frame.file) {
22
+ continue;
23
+ }
24
+ const { searchParams, pathname } = new URL(frame.file, 'file://');
25
+ const platform = searchParams.get('platform');
26
+ if (platform) {
27
+ return platform;
28
+ }
29
+ const [bundleFilename] = pathname.split('/').reverse();
30
+ const [, platformOrExtension, extension] = bundleFilename.split('.');
31
+ if (extension) {
32
+ return platformOrExtension;
33
+ }
103
34
  }
104
- logger.debug({
105
- msg: 'Symbolicating frame',
106
- frame
107
- });
108
- const processedFrame = this.processFrame(frame);
109
- logger.debug({
110
- msg: 'Finished symbolicating frame',
111
- frame
112
- });
113
- processedFrames.push(processedFrame);
114
- }
115
- const codeFrame = (await this.getCodeFrame(logger, processedFrames)) ?? null;
116
- logger.debug({
117
- msg: 'Finished symbolicating frames',
118
- processedFrames,
119
- codeFrame
120
- });
121
- return {
122
- stack: processedFrames,
123
- codeFrame
124
- };
125
- } finally {
126
- for (const key in this.sourceMapConsumerCache) {
127
- this.sourceMapConsumerCache[key].destroy();
128
- delete this.sourceMapConsumerCache[key];
129
- }
130
35
  }
131
- }
132
- processFrame(frame) {
133
- if (!frame.lineNumber || !frame.column) {
134
- return {
135
- ...frame,
136
- collapse: false
137
- };
36
+ /**
37
+ * Constructs new `Symbolicator` instance.
38
+ *
39
+ * @param delegate Delegate instance with symbolication functions.
40
+ */
41
+ constructor(delegate) {
42
+ this.delegate = delegate;
43
+ /**
44
+ * Cache with initialized `SourceMapConsumer` to improve symbolication performance.
45
+ */
46
+ this.sourceMapConsumerCache = {};
138
47
  }
139
- const consumer = this.sourceMapConsumerCache[frame.file];
140
- if (!consumer) {
141
- return {
142
- ...frame,
143
- collapse: false
144
- };
145
- }
146
- const lookup = consumer.originalPositionFor({
147
- line: frame.lineNumber,
148
- column: frame.column,
149
- bias: SourceMapConsumer.LEAST_UPPER_BOUND
150
- });
151
-
152
- // If lookup fails, we get the same shape object, but with
153
- // all values set to null
154
- if (!lookup.source) {
155
- // It is better to gracefully return the original frame
156
- // than to throw an exception
157
- return {
158
- ...frame,
159
- collapse: false
160
- };
48
+ /**
49
+ * Process raw React Native stack frames and transform them using Source Maps.
50
+ * Method will try to symbolicate as much data as possible, but if the Source Maps
51
+ * are not available, invalid or the original positions/data is not found in Source Maps,
52
+ * the method will return raw values - the same as supplied with `stack` parameter.
53
+ * For example out of 10 frames, it's possible that only first 7 will be symbolicated and the
54
+ * remaining 3 will be unchanged.
55
+ *
56
+ * @param logger Fastify logger instance.
57
+ * @param stack Raw stack frames.
58
+ * @returns Symbolicated stack frames.
59
+ */
60
+ async process(logger, stack) {
61
+ logger.debug({ msg: 'Filtering out unnecessary frames' });
62
+ const frames = [];
63
+ for (const frame of stack) {
64
+ const { file } = frame;
65
+ if (file?.startsWith('http')) {
66
+ frames.push(frame);
67
+ }
68
+ }
69
+ try {
70
+ logger.debug({ msg: 'Processing frames', frames });
71
+ const processedFrames = [];
72
+ for (const frame of frames) {
73
+ if (!this.sourceMapConsumerCache[frame.file]) {
74
+ logger.debug({
75
+ msg: 'Loading raw source map data',
76
+ fileUrl: frame.file,
77
+ });
78
+ const rawSourceMap = await this.delegate.getSourceMap(frame.file);
79
+ logger.debug({
80
+ msg: 'Creating source map instance',
81
+ fileUrl: frame.file,
82
+ sourceMapLength: rawSourceMap.length,
83
+ });
84
+ const sourceMapConsumer = await new SourceMapConsumer(rawSourceMap.toString());
85
+ logger.debug({
86
+ msg: 'Saving source map instance into cache',
87
+ fileUrl: frame.file,
88
+ });
89
+ this.sourceMapConsumerCache[frame.file] = sourceMapConsumer;
90
+ }
91
+ logger.debug({
92
+ msg: 'Symbolicating frame',
93
+ frame,
94
+ });
95
+ const processedFrame = this.processFrame(frame);
96
+ logger.debug({
97
+ msg: 'Finished symbolicating frame',
98
+ frame,
99
+ });
100
+ processedFrames.push(processedFrame);
101
+ }
102
+ const codeFrame = (await this.getCodeFrame(logger, processedFrames)) ?? null;
103
+ logger.debug({
104
+ msg: 'Finished symbolicating frames',
105
+ processedFrames,
106
+ codeFrame,
107
+ });
108
+ return {
109
+ stack: processedFrames,
110
+ codeFrame,
111
+ };
112
+ }
113
+ finally {
114
+ for (const key in this.sourceMapConsumerCache) {
115
+ this.sourceMapConsumerCache[key].destroy();
116
+ delete this.sourceMapConsumerCache[key];
117
+ }
118
+ }
161
119
  }
162
- return {
163
- lineNumber: lookup.line || frame.lineNumber,
164
- column: lookup.column || frame.column,
165
- file: lookup.source,
166
- methodName: lookup.name || frame.methodName,
167
- collapse: false
168
- };
169
- }
170
- async getCodeFrame(logger, processedFrames) {
171
- for (const frame of processedFrames) {
172
- if (frame.collapse || !frame.lineNumber || !frame.column) {
173
- continue;
174
- }
175
- if (!this.delegate.shouldIncludeFrame(frame)) {
176
- return undefined;
177
- }
178
- logger.debug({
179
- msg: 'Generating code frame',
180
- frame
181
- });
182
- try {
120
+ processFrame(frame) {
121
+ if (!frame.lineNumber || !frame.column) {
122
+ return {
123
+ ...frame,
124
+ collapse: false,
125
+ };
126
+ }
127
+ const consumer = this.sourceMapConsumerCache[frame.file];
128
+ if (!consumer) {
129
+ return {
130
+ ...frame,
131
+ collapse: false,
132
+ };
133
+ }
134
+ const lookup = consumer.originalPositionFor({
135
+ line: frame.lineNumber,
136
+ column: frame.column,
137
+ bias: SourceMapConsumer.LEAST_UPPER_BOUND,
138
+ });
139
+ // If lookup fails, we get the same shape object, but with
140
+ // all values set to null
141
+ if (!lookup.source) {
142
+ // It is better to gracefully return the original frame
143
+ // than to throw an exception
144
+ return {
145
+ ...frame,
146
+ collapse: false,
147
+ };
148
+ }
183
149
  return {
184
- content: codeFrameColumns((await this.delegate.getSource(frame.file)).toString(), {
185
- start: {
186
- column: frame.column,
187
- line: frame.lineNumber
188
- }
189
- }, {
190
- forceColor: true
191
- }),
192
- location: {
193
- row: frame.lineNumber,
194
- column: frame.column
195
- },
196
- fileName: frame.file
150
+ lineNumber: lookup.line || frame.lineNumber,
151
+ column: lookup.column || frame.column,
152
+ file: lookup.source,
153
+ methodName: lookup.name || frame.methodName,
154
+ collapse: false,
197
155
  };
198
- } catch (error) {
199
- logger.error({
200
- msg: 'Failed to create code frame',
201
- error: error.message
202
- });
203
- }
204
- return undefined;
205
156
  }
206
- }
157
+ async getCodeFrame(logger, processedFrames) {
158
+ for (const frame of processedFrames) {
159
+ if (frame.collapse || !frame.lineNumber || !frame.column) {
160
+ continue;
161
+ }
162
+ if (!this.delegate.shouldIncludeFrame(frame)) {
163
+ return undefined;
164
+ }
165
+ logger.debug({
166
+ msg: 'Generating code frame',
167
+ frame,
168
+ });
169
+ try {
170
+ return {
171
+ content: codeFrameColumns((await this.delegate.getSource(frame.file)).toString(), {
172
+ start: { column: frame.column, line: frame.lineNumber },
173
+ }, { forceColor: true }),
174
+ location: {
175
+ row: frame.lineNumber,
176
+ column: frame.column,
177
+ },
178
+ fileName: frame.file,
179
+ };
180
+ }
181
+ catch (error) {
182
+ logger.error({
183
+ msg: 'Failed to create code frame',
184
+ error: error.message,
185
+ });
186
+ }
187
+ return undefined;
188
+ }
189
+ }
207
190
  }
208
- //# sourceMappingURL=Symbolicator.js.map
@@ -1,3 +1,3 @@
1
- export { default } from './sybmolicatePlugin';
2
- export * from './Symbolicator';
3
- export * from './types';
1
+ export { default } from './sybmolicatePlugin.js';
2
+ export * from './Symbolicator.js';
3
+ export * from './types.js';
@@ -1,4 +1,3 @@
1
- export { default } from "./sybmolicatePlugin.js";
2
- export * from "./Symbolicator.js";
3
- export * from "./types.js";
4
- //# sourceMappingURL=index.js.map
1
+ export { default } from './sybmolicatePlugin.js';
2
+ export * from './Symbolicator.js';
3
+ export * from './types.js';
@@ -1,5 +1,5 @@
1
1
  import type { FastifyInstance } from 'fastify';
2
- import type { Server } from '../../types';
2
+ import type { Server } from '../../types.js';
3
3
  declare function symbolicatePlugin(instance: FastifyInstance, { delegate, }: {
4
4
  delegate: Server.Delegate;
5
5
  }): Promise<void>;
@@ -1,44 +1,33 @@
1
1
  import fastifyPlugin from 'fastify-plugin';
2
- import { Symbolicator } from "./Symbolicator.js";
3
- async function symbolicatePlugin(instance, {
4
- delegate
5
- }) {
6
- const symbolicator = new Symbolicator(delegate.symbolicator);
7
- instance.post('/symbolicate', async (request, reply) => {
8
- // React Native sends stack as JSON but tests content-type to text/plain, so
9
- // we cannot use JSON schema to validate the body.
10
-
11
- try {
12
- const {
13
- stack
14
- } = JSON.parse(request.body);
15
- const platform = Symbolicator.inferPlatformFromStack(stack);
16
- if (!platform) {
17
- request.log.debug({
18
- msg: 'Received stack',
19
- stack
20
- });
21
- reply.badRequest('Cannot infer platform from stack trace');
22
- } else {
23
- request.log.debug({
24
- msg: 'Starting symbolication',
25
- platform,
26
- stack
27
- });
28
- const results = await symbolicator.process(request.log, stack);
29
- reply.send(results);
30
- }
31
- } catch (error) {
32
- request.log.error({
33
- msg: 'Failed to symbolicate',
34
- error: error.message
35
- });
36
- reply.internalServerError();
37
- }
38
- });
2
+ import { Symbolicator } from './Symbolicator.js';
3
+ async function symbolicatePlugin(instance, { delegate, }) {
4
+ const symbolicator = new Symbolicator(delegate.symbolicator);
5
+ instance.post('/symbolicate', async (request, reply) => {
6
+ // React Native sends stack as JSON but tests content-type to text/plain, so
7
+ // we cannot use JSON schema to validate the body.
8
+ try {
9
+ const { stack } = JSON.parse(request.body);
10
+ const platform = Symbolicator.inferPlatformFromStack(stack);
11
+ if (!platform) {
12
+ request.log.debug({ msg: 'Received stack', stack });
13
+ reply.badRequest('Cannot infer platform from stack trace');
14
+ }
15
+ else {
16
+ request.log.debug({ msg: 'Starting symbolication', platform, stack });
17
+ const results = await symbolicator.process(request.log, stack);
18
+ reply.send(results);
19
+ }
20
+ }
21
+ catch (error) {
22
+ request.log.error({
23
+ msg: 'Failed to symbolicate',
24
+ error: error.message,
25
+ });
26
+ reply.internalServerError();
27
+ }
28
+ });
39
29
  }
40
30
  export default fastifyPlugin(symbolicatePlugin, {
41
- name: 'symbolicate-plugin',
42
- dependencies: ['@fastify/sensible']
31
+ name: 'symbolicate-plugin',
32
+ dependencies: ['@fastify/sensible'],
43
33
  });
44
- //# sourceMappingURL=sybmolicatePlugin.js.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=types.js.map
@@ -1,5 +1,5 @@
1
1
  import type { FastifyInstance } from 'fastify';
2
- import type { WebSocketServerInterface } from './types';
2
+ import type { WebSocketServerInterface } from './types.js';
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