@tamagui/cli 1.2.8 → 1.2.10

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 (99) hide show
  1. package/dist/esm/build.mjs +49 -0
  2. package/dist/esm/build.mjs.map +7 -0
  3. package/dist/esm/cli.mjs +138 -0
  4. package/dist/esm/cli.mjs.map +7 -0
  5. package/dist/esm/create.mjs +1 -0
  6. package/dist/esm/create.mjs.map +7 -0
  7. package/dist/esm/dev/createDevServer.mjs +141 -0
  8. package/dist/esm/dev/createDevServer.mjs.map +7 -0
  9. package/dist/esm/dev.mjs +151 -0
  10. package/dist/esm/dev.mjs.map +7 -0
  11. package/dist/esm/generate.mjs +49 -0
  12. package/dist/esm/generate.mjs.map +7 -0
  13. package/dist/esm/index.mjs +9 -0
  14. package/dist/esm/index.mjs.map +7 -0
  15. package/dist/esm/studio.mjs +61 -0
  16. package/dist/esm/studio.mjs.map +7 -0
  17. package/dist/esm/tamaguiConfigUtils.mjs +52 -0
  18. package/dist/esm/tamaguiConfigUtils.mjs.map +7 -0
  19. package/dist/esm/test.mjs +9 -0
  20. package/dist/esm/test.mjs.map +7 -0
  21. package/dist/esm/types.mjs +1 -0
  22. package/dist/esm/types.mjs.map +7 -0
  23. package/dist/esm/update.mjs +6 -0
  24. package/dist/esm/update.mjs.map +7 -0
  25. package/dist/esm/utils/constants.mjs +5 -0
  26. package/dist/esm/utils/constants.mjs.map +7 -0
  27. package/dist/esm/utils.mjs +78 -0
  28. package/dist/esm/utils.mjs.map +7 -0
  29. package/dist/esm/vendor/debugger-app/index.mjs +6 -0
  30. package/dist/esm/vendor/debugger-app/index.mjs.map +7 -0
  31. package/dist/esm/vendor/debugger-app/src/debuggerWorker.mjs +63 -0
  32. package/dist/esm/vendor/debugger-app/src/debuggerWorker.mjs.map +7 -0
  33. package/dist/esm/vendor/debugger-app/src/index.mjs +142 -0
  34. package/dist/esm/vendor/debugger-app/src/index.mjs.map +7 -0
  35. package/dist/esm/vendor/repack/dev-server/src/createServer.mjs +95 -0
  36. package/dist/esm/vendor/repack/dev-server/src/createServer.mjs.map +7 -0
  37. package/dist/esm/vendor/repack/dev-server/src/index.mjs +3 -0
  38. package/dist/esm/vendor/repack/dev-server/src/index.mjs.map +7 -0
  39. package/dist/esm/vendor/repack/dev-server/src/plugins/api/apiPlugin.mjs +37 -0
  40. package/dist/esm/vendor/repack/dev-server/src/plugins/api/apiPlugin.mjs.map +7 -0
  41. package/dist/esm/vendor/repack/dev-server/src/plugins/api/index.mjs +5 -0
  42. package/dist/esm/vendor/repack/dev-server/src/plugins/api/index.mjs.map +7 -0
  43. package/dist/esm/vendor/repack/dev-server/src/plugins/compiler/compilerPlugin.mjs +67 -0
  44. package/dist/esm/vendor/repack/dev-server/src/plugins/compiler/compilerPlugin.mjs.map +7 -0
  45. package/dist/esm/vendor/repack/dev-server/src/plugins/compiler/index.mjs +6 -0
  46. package/dist/esm/vendor/repack/dev-server/src/plugins/compiler/index.mjs.map +7 -0
  47. package/dist/esm/vendor/repack/dev-server/src/plugins/compiler/types.mjs +1 -0
  48. package/dist/esm/vendor/repack/dev-server/src/plugins/compiler/types.mjs.map +7 -0
  49. package/dist/esm/vendor/repack/dev-server/src/plugins/devtools/devtoolsPlugin.mjs +87 -0
  50. package/dist/esm/vendor/repack/dev-server/src/plugins/devtools/devtoolsPlugin.mjs.map +7 -0
  51. package/dist/esm/vendor/repack/dev-server/src/plugins/devtools/index.mjs +5 -0
  52. package/dist/esm/vendor/repack/dev-server/src/plugins/devtools/index.mjs.map +7 -0
  53. package/dist/esm/vendor/repack/dev-server/src/plugins/favicon/faviconPlugin.mjs +13 -0
  54. package/dist/esm/vendor/repack/dev-server/src/plugins/favicon/faviconPlugin.mjs.map +7 -0
  55. package/dist/esm/vendor/repack/dev-server/src/plugins/favicon/index.mjs +5 -0
  56. package/dist/esm/vendor/repack/dev-server/src/plugins/favicon/index.mjs.map +7 -0
  57. package/dist/esm/vendor/repack/dev-server/src/plugins/multipart/index.mjs +6 -0
  58. package/dist/esm/vendor/repack/dev-server/src/plugins/multipart/index.mjs.map +7 -0
  59. package/dist/esm/vendor/repack/dev-server/src/plugins/multipart/multipartPlugin.mjs +50 -0
  60. package/dist/esm/vendor/repack/dev-server/src/plugins/multipart/multipartPlugin.mjs.map +7 -0
  61. package/dist/esm/vendor/repack/dev-server/src/plugins/multipart/types.mjs +1 -0
  62. package/dist/esm/vendor/repack/dev-server/src/plugins/multipart/types.mjs.map +7 -0
  63. package/dist/esm/vendor/repack/dev-server/src/plugins/symbolicate/Symbolicator.mjs +186 -0
  64. package/dist/esm/vendor/repack/dev-server/src/plugins/symbolicate/Symbolicator.mjs.map +7 -0
  65. package/dist/esm/vendor/repack/dev-server/src/plugins/symbolicate/index.mjs +7 -0
  66. package/dist/esm/vendor/repack/dev-server/src/plugins/symbolicate/index.mjs.map +7 -0
  67. package/dist/esm/vendor/repack/dev-server/src/plugins/symbolicate/sybmolicatePlugin.mjs +35 -0
  68. package/dist/esm/vendor/repack/dev-server/src/plugins/symbolicate/sybmolicatePlugin.mjs.map +7 -0
  69. package/dist/esm/vendor/repack/dev-server/src/plugins/symbolicate/types.mjs +1 -0
  70. package/dist/esm/vendor/repack/dev-server/src/plugins/symbolicate/types.mjs.map +7 -0
  71. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/WebSocketRouter.mjs +50 -0
  72. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/WebSocketRouter.mjs.map +7 -0
  73. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/WebSocketServer.mjs +32 -0
  74. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/WebSocketServer.mjs.map +7 -0
  75. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/index.mjs +7 -0
  76. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/index.mjs.map +7 -0
  77. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/servers/HermesInspectorProxy.mjs +110 -0
  78. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/servers/HermesInspectorProxy.mjs.map +7 -0
  79. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketApiServer.mjs +52 -0
  80. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketApiServer.mjs.map +7 -0
  81. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketDebuggerServer.mjs +106 -0
  82. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketDebuggerServer.mjs.map +7 -0
  83. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketDevClientServer.mjs +62 -0
  84. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketDevClientServer.mjs.map +7 -0
  85. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketEventsServer.mjs +154 -0
  86. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketEventsServer.mjs.map +7 -0
  87. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketHMRServer.mjs +76 -0
  88. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketHMRServer.mjs.map +7 -0
  89. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketMessageServer.mjs +330 -0
  90. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketMessageServer.mjs.map +7 -0
  91. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/types.mjs +1 -0
  92. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/types.mjs.map +7 -0
  93. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/wssPlugin.mjs +47 -0
  94. package/dist/esm/vendor/repack/dev-server/src/plugins/wss/wssPlugin.mjs.map +7 -0
  95. package/dist/esm/vendor/repack/dev-server/src/types.mjs +13 -0
  96. package/dist/esm/vendor/repack/dev-server/src/types.mjs.map +7 -0
  97. package/dist/esm/vendor/repack/dev-server/vendor/metro-inspector-proxy/src/Device.mjs +5 -0
  98. package/dist/esm/vendor/repack/dev-server/vendor/metro-inspector-proxy/src/Device.mjs.map +7 -0
  99. package/package.json +6 -6
@@ -0,0 +1,186 @@
1
+ import { URL } from "url";
2
+ import { codeFrameColumns } from "@babel/code-frame";
3
+ import { SourceMapConsumer } from "source-map";
4
+ class Symbolicator {
5
+ /**
6
+ * Constructs new `Symbolicator` instance.
7
+ *
8
+ * @param delegate Delegate instance with symbolication functions.
9
+ */
10
+ constructor(delegate) {
11
+ this.delegate = delegate;
12
+ /**
13
+ * Cache with initialized `SourceMapConsumer` to improve symbolication performance.
14
+ */
15
+ this.sourceMapConsumerCache = {};
16
+ }
17
+ /**
18
+ * Infer platform from stack frames.
19
+ * Usually at least one frame has `file` field with the bundle URL eg:
20
+ * `http://localhost:8081/index.bundle?platform=ios&...`, which can be used to infer platform.
21
+ *
22
+ * @param stack Array of stack frames.
23
+ * @returns Inferred platform or `undefined` if cannot infer.
24
+ */
25
+ static inferPlatformFromStack(stack) {
26
+ for (const frame of stack) {
27
+ if (!frame.file) {
28
+ return;
29
+ }
30
+ const { searchParams, pathname } = new URL(frame.file, "file://");
31
+ const platform = searchParams.get("platform");
32
+ if (platform) {
33
+ return platform;
34
+ } else {
35
+ const [bundleFilename] = pathname.split("/").reverse();
36
+ const [, platformOrExtension, extension] = bundleFilename.split(".");
37
+ if (extension) {
38
+ return platformOrExtension;
39
+ }
40
+ }
41
+ }
42
+ }
43
+ /**
44
+ * Process raw React Native stack frames and transform them using Source Maps.
45
+ * Method will try to symbolicate as much data as possible, but if the Source Maps
46
+ * are not available, invalid or the original positions/data is not found in Source Maps,
47
+ * the method will return raw values - the same as supplied with `stack` parameter.
48
+ * For example out of 10 frames, it's possible that only first 7 will be symbolicated and the
49
+ * remaining 3 will be unchanged.
50
+ *
51
+ * @param logger Fastify logger instance.
52
+ * @param stack Raw stack frames.
53
+ * @returns Symbolicated stack frames.
54
+ */
55
+ async process(logger, stack) {
56
+ logger.debug({ msg: "Filtering out unnecessary frames" });
57
+ const frames = [];
58
+ for (const frame of stack) {
59
+ const { file } = frame;
60
+ if ((file == null ? void 0 : file.startsWith("http")) && !file.includes("debuggerWorker")) {
61
+ frames.push(frame);
62
+ }
63
+ }
64
+ try {
65
+ logger.debug({ msg: "Processing frames", frames });
66
+ const processedFrames = [];
67
+ for (const frame of frames) {
68
+ if (!this.sourceMapConsumerCache[frame.file]) {
69
+ logger.debug({
70
+ msg: "Loading raw source map data",
71
+ fileUrl: frame.file
72
+ });
73
+ const rawSourceMap = await this.delegate.getSourceMap(frame.file);
74
+ logger.debug({
75
+ msg: "Creating source map instance",
76
+ fileUrl: frame.file,
77
+ sourceMapLength: rawSourceMap.length
78
+ });
79
+ const sourceMapConsumer = await new SourceMapConsumer(rawSourceMap.toString());
80
+ logger.debug({
81
+ msg: "Saving source map instance into cache",
82
+ fileUrl: frame.file
83
+ });
84
+ this.sourceMapConsumerCache[frame.file] = sourceMapConsumer;
85
+ }
86
+ logger.debug({
87
+ msg: "Symbolicating frame",
88
+ frame
89
+ });
90
+ const processedFrame = this.processFrame(frame);
91
+ logger.debug({
92
+ msg: "Finished symbolicating frame",
93
+ frame
94
+ });
95
+ processedFrames.push(processedFrame);
96
+ }
97
+ const codeFrame = await this.getCodeFrame(logger, processedFrames) ?? null;
98
+ logger.debug({
99
+ msg: "Finished symbolicating frames",
100
+ processedFrames,
101
+ codeFrame
102
+ });
103
+ return {
104
+ stack: processedFrames,
105
+ codeFrame
106
+ };
107
+ } finally {
108
+ for (const key in this.sourceMapConsumerCache) {
109
+ this.sourceMapConsumerCache[key].destroy();
110
+ delete this.sourceMapConsumerCache[key];
111
+ }
112
+ }
113
+ }
114
+ processFrame(frame) {
115
+ if (!frame.lineNumber || !frame.column) {
116
+ return {
117
+ ...frame,
118
+ collapse: false
119
+ };
120
+ }
121
+ const consumer = this.sourceMapConsumerCache[frame.file];
122
+ if (!consumer) {
123
+ return {
124
+ ...frame,
125
+ collapse: false
126
+ };
127
+ }
128
+ const lookup = consumer.originalPositionFor({
129
+ line: frame.lineNumber,
130
+ column: frame.column
131
+ });
132
+ if (!lookup.source) {
133
+ return {
134
+ ...frame,
135
+ collapse: false
136
+ };
137
+ }
138
+ return {
139
+ lineNumber: lookup.line || frame.lineNumber,
140
+ column: lookup.column || frame.column,
141
+ file: lookup.source,
142
+ methodName: lookup.name || frame.methodName,
143
+ collapse: false
144
+ };
145
+ }
146
+ async getCodeFrame(logger, processedFrames) {
147
+ for (const frame of processedFrames) {
148
+ if (frame.collapse || !frame.lineNumber || !frame.column) {
149
+ continue;
150
+ }
151
+ if (!this.delegate.shouldIncludeFrame(frame)) {
152
+ return void 0;
153
+ }
154
+ logger.debug({
155
+ msg: "Generating code frame",
156
+ frame
157
+ });
158
+ try {
159
+ return {
160
+ content: codeFrameColumns(
161
+ (await this.delegate.getSource(frame.file)).toString(),
162
+ {
163
+ start: { column: frame.column, line: frame.lineNumber }
164
+ },
165
+ { forceColor: true }
166
+ ),
167
+ location: {
168
+ row: frame.lineNumber,
169
+ column: frame.column
170
+ },
171
+ fileName: frame.file
172
+ };
173
+ } catch (error) {
174
+ logger.error({
175
+ msg: "Failed to create code frame",
176
+ error: error.message
177
+ });
178
+ }
179
+ return void 0;
180
+ }
181
+ }
182
+ }
183
+ export {
184
+ Symbolicator
185
+ };
186
+ //# sourceMappingURL=Symbolicator.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../../src/vendor/repack/dev-server/src/plugins/symbolicate/Symbolicator.ts"],
4
+ "sourcesContent": ["import { URL } from 'url'\n\nimport { codeFrameColumns } from '@babel/code-frame'\nimport type { FastifyLoggerInstance } from 'fastify'\nimport { SourceMapConsumer } from 'source-map'\n\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(rawSourceMap.toString())\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 = (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"],
5
+ "mappings": "AAAA,SAAS,WAAW;AAEpB,SAAS,wBAAwB;AAEjC,SAAS,yBAAyB;AAiB3B,MAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuCxB,YAAoB,UAAgC;AAAhC;AAPpB;AAAA;AAAA;AAAA,kCAA4D,CAAC;AAAA,EAOR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA9BrD,OAAO,uBAAuB,OAAgC;AAC5D,eAAW,SAAS,OAAO;AACzB,UAAI,CAAC,MAAM,MAAM;AACf;AAAA,MACF;AAEA,YAAM,EAAE,cAAc,SAAS,IAAI,IAAI,IAAI,MAAM,MAAM,SAAS;AAChE,YAAM,WAAW,aAAa,IAAI,UAAU;AAC5C,UAAI,UAAU;AACZ,eAAO;AAAA,MACT,OAAO;AACL,cAAM,CAAC,cAAc,IAAI,SAAS,MAAM,GAAG,EAAE,QAAQ;AACrD,cAAM,CAAC,EAAE,qBAAqB,SAAS,IAAI,eAAe,MAAM,GAAG;AACnE,YAAI,WAAW;AACb,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0BA,MAAM,QACJ,QACA,OAC8B;AAC9B,WAAO,MAAM,EAAE,KAAK,mCAAmC,CAAC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,YAAY,KAAK;AAAA,UACrB;AAAA,UACA,UAAU;AAAA,YACR,KAAK,MAAM;AAAA,YACX,QAAQ,MAAM;AAAA,UAChB;AAAA,UACA,UAAU,MAAM;AAAA,QAClB;AAAA,MACF,SAAS,OAAP;AACA,eAAO,MAAM;AAAA,UACX,KAAK;AAAA,UACL,OAAQ,MAAgB;AAAA,QAC1B,CAAC;AAAA,MACH;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ import { default as default2 } from "./sybmolicatePlugin";
2
+ export * from "./Symbolicator";
3
+ export * from "./types";
4
+ export {
5
+ default2 as default
6
+ };
7
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../../src/vendor/repack/dev-server/src/plugins/symbolicate/index.ts"],
4
+ "sourcesContent": ["export { default } from './sybmolicatePlugin'\nexport * from './Symbolicator'\nexport * from './types'\n"],
5
+ "mappings": "AAAA,SAAS,WAAAA,gBAAe;AACxB,cAAc;AACd,cAAc;",
6
+ "names": ["default"]
7
+ }
@@ -0,0 +1,35 @@
1
+ import fastifyPlugin from "fastify-plugin";
2
+ import { Symbolicator } from "./Symbolicator";
3
+ async function symbolicatePlugin(instance, {
4
+ delegate
5
+ }) {
6
+ const symbolicator = new Symbolicator(delegate.symbolicator);
7
+ instance.post("/symbolicate", async (request, reply) => {
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
+ } else {
15
+ request.log.debug({ msg: "Starting symbolication", platform, stack });
16
+ const results = await symbolicator.process(request.log, stack);
17
+ reply.send(results);
18
+ }
19
+ } catch (error) {
20
+ request.log.error({
21
+ msg: "Failed to symbolicate",
22
+ error: error.message
23
+ });
24
+ reply.internalServerError();
25
+ }
26
+ });
27
+ }
28
+ var sybmolicatePlugin_default = fastifyPlugin(symbolicatePlugin, {
29
+ name: "symbolicate-plugin",
30
+ dependencies: ["fastify-sensible"]
31
+ });
32
+ export {
33
+ sybmolicatePlugin_default as default
34
+ };
35
+ //# sourceMappingURL=sybmolicatePlugin.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../../src/vendor/repack/dev-server/src/plugins/symbolicate/sybmolicatePlugin.ts"],
4
+ "sourcesContent": ["import type { FastifyInstance } from 'fastify'\nimport fastifyPlugin from 'fastify-plugin'\n\nimport type { Server } from '../../types'\nimport { Symbolicator } from './Symbolicator'\nimport type { ReactNativeStackFrame } from './types'\n\nasync function symbolicatePlugin(\n instance: FastifyInstance,\n {\n delegate,\n }: {\n delegate: Server.Delegate\n }\n) {\n const symbolicator = new Symbolicator(delegate.symbolicator)\n\n instance.post('/symbolicate', async (request, reply) => {\n // React Native sends stack as JSON but tests content-type to text/plain, so\n // we cannot use JSON schema to validate the body.\n\n try {\n const { stack } = JSON.parse(request.body as string) as {\n stack: ReactNativeStackFrame[]\n }\n const platform = Symbolicator.inferPlatformFromStack(stack)\n if (!platform) {\n request.log.debug({ msg: 'Received stack', stack })\n reply.badRequest('Cannot infer platform from stack trace')\n } else {\n request.log.debug({ msg: 'Starting symbolication', platform, stack })\n const results = await symbolicator.process(request.log, stack)\n reply.send(results)\n }\n } catch (error) {\n request.log.error({\n msg: 'Failed to symbolicate',\n error: (error as Error).message,\n })\n reply.internalServerError()\n }\n })\n}\n\nexport default fastifyPlugin(symbolicatePlugin, {\n name: 'symbolicate-plugin',\n dependencies: ['fastify-sensible'],\n})\n"],
5
+ "mappings": "AACA,OAAO,mBAAmB;AAG1B,SAAS,oBAAoB;AAG7B,eAAe,kBACb,UACA;AAAA,EACE;AACF,GAGA;AACA,QAAM,eAAe,IAAI,aAAa,SAAS,YAAY;AAE3D,WAAS,KAAK,gBAAgB,OAAO,SAAS,UAAU;AAItD,QAAI;AACF,YAAM,EAAE,MAAM,IAAI,KAAK,MAAM,QAAQ,IAAc;AAGnD,YAAM,WAAW,aAAa,uBAAuB,KAAK;AAC1D,UAAI,CAAC,UAAU;AACb,gBAAQ,IAAI,MAAM,EAAE,KAAK,kBAAkB,MAAM,CAAC;AAClD,cAAM,WAAW,wCAAwC;AAAA,MAC3D,OAAO;AACL,gBAAQ,IAAI,MAAM,EAAE,KAAK,0BAA0B,UAAU,MAAM,CAAC;AACpE,cAAM,UAAU,MAAM,aAAa,QAAQ,QAAQ,KAAK,KAAK;AAC7D,cAAM,KAAK,OAAO;AAAA,MACpB;AAAA,IACF,SAAS,OAAP;AACA,cAAQ,IAAI,MAAM;AAAA,QAChB,KAAK;AAAA,QACL,OAAQ,MAAgB;AAAA,MAC1B,CAAC;AACD,YAAM,oBAAoB;AAAA,IAC5B;AAAA,EACF,CAAC;AACH;AAEA,IAAO,4BAAQ,cAAc,mBAAmB;AAAA,EAC9C,MAAM;AAAA,EACN,cAAc,CAAC,kBAAkB;AACnC,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,50 @@
1
+ class WebSocketRouter {
2
+ /**
3
+ * Create new instance of `WebSocketRouter` and attach it to the given Fastify instance.
4
+ * Any logging information, will be passed through standard `fastify.log` API.
5
+ *
6
+ * @param fastify Fastify instance to attach the WebSocket router to.
7
+ */
8
+ constructor(fastify) {
9
+ this.fastify = fastify;
10
+ /** The list of all register WebSocket servers. */
11
+ this.servers = [];
12
+ this.fastify.server.on(
13
+ "upgrade",
14
+ (request, socket, head) => {
15
+ const { pathname } = new URL(request.url || "", "http://localhost");
16
+ let matched = false;
17
+ console.log("check for upgrade", pathname);
18
+ for (const server of this.servers) {
19
+ if (server.shouldUpgrade(pathname)) {
20
+ matched = true;
21
+ server.upgrade(request, socket, head);
22
+ break;
23
+ }
24
+ }
25
+ if (!matched) {
26
+ this.fastify.log.debug({
27
+ msg: "Destroying socket connection as no server was matched",
28
+ pathname
29
+ });
30
+ socket.destroy();
31
+ }
32
+ }
33
+ );
34
+ }
35
+ /**
36
+ * Register a new {@link WebSocketServer}. New connection will now
37
+ * check if the given server will accept them and forward them.
38
+ *
39
+ * @param server WebSocket server to register.
40
+ * @returns The same instance of the WebSocket server after it's been registered.
41
+ */
42
+ registerServer(server) {
43
+ this.servers.push(server);
44
+ return server;
45
+ }
46
+ }
47
+ export {
48
+ WebSocketRouter
49
+ };
50
+ //# sourceMappingURL=WebSocketRouter.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../../src/vendor/repack/dev-server/src/plugins/wss/WebSocketRouter.ts"],
4
+ "sourcesContent": ["import type { IncomingMessage } from 'http'\nimport type { Socket } from 'net'\n\nimport type { FastifyInstance } from 'fastify'\n\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\n console.log('check for upgrade', pathname)\n\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"],
5
+ "mappings": "AAiBO,MAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAU3B,YAAoB,SAA0B;AAA1B;AARpB;AAAA,SAAU,UAA6B,CAAC;AAStC,SAAK,QAAQ,OAAO;AAAA,MAClB;AAAA,MACA,CAAC,SAA0B,QAAgB,SAAiB;AAC1D,cAAM,EAAE,SAAS,IAAI,IAAI,IAAI,QAAQ,OAAO,IAAI,kBAAkB;AAClE,YAAI,UAAU;AAEd,gBAAQ,IAAI,qBAAqB,QAAQ;AAEzC,mBAAW,UAAU,KAAK,SAAS;AACjC,cAAI,OAAO,cAAc,QAAQ,GAAG;AAClC,sBAAU;AACV,mBAAO,QAAQ,SAAS,QAAQ,IAAI;AACpC;AAAA,UACF;AAAA,QACF;AAEA,YAAI,CAAC,SAAS;AACZ,eAAK,QAAQ,IAAI,MAAM;AAAA,YACrB,KAAK;AAAA,YACL;AAAA,UACF,CAAC;AACD,iBAAO,QAAQ;AAAA,QACjB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,eAA0C,QAAc;AACtD,SAAK,QAAQ,KAAK,MAAM;AACxB,WAAO;AAAA,EACT;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,32 @@
1
+ import { WebSocketServer as WebSocketServerImpl } from "ws";
2
+ class WebSocketServer {
3
+ /**
4
+ * Create a new instance of the WebSocketServer.
5
+ * Any logging information, will be passed through standard `fastify.log` API.
6
+ *
7
+ * @param fastify Fastify instance to which the WebSocket will be attached to.
8
+ * @param path Path on which this WebSocketServer will be accepting connections.
9
+ * @param wssOptions WebSocket Server options.
10
+ */
11
+ constructor(fastify, path, wssOptions = {}) {
12
+ this.fastify = fastify;
13
+ this.server = new WebSocketServerImpl({
14
+ noServer: true,
15
+ ...wssOptions
16
+ });
17
+ this.server.on("connection", this.onConnection.bind(this));
18
+ this.paths = Array.isArray(path) ? path : [path];
19
+ }
20
+ shouldUpgrade(pathname) {
21
+ return this.paths.includes(pathname);
22
+ }
23
+ upgrade(request, socket, head) {
24
+ this.server.handleUpgrade(request, socket, head, (webSocket) => {
25
+ this.server.emit("connection", webSocket, request);
26
+ });
27
+ }
28
+ }
29
+ export {
30
+ WebSocketServer
31
+ };
32
+ //# sourceMappingURL=WebSocketServer.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../../src/vendor/repack/dev-server/src/plugins/wss/WebSocketServer.ts"],
4
+ "sourcesContent": ["import type { IncomingMessage } from 'http'\nimport type { Socket } from 'net'\n\nimport type { FastifyInstance } from 'fastify'\nimport { ServerOptions, WebSocket, WebSocketServer as WebSocketServerImpl } 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<ServerOptions, 'noServer' | 'server' | 'host' | 'port' | 'path'> = {}\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"],
5
+ "mappings": "AAIA,SAAmC,mBAAmB,2BAA2B;AAO1E,MAAe,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBpC,YACE,SACA,MACA,aAAoF,CAAC,GACrF;AACA,SAAK,UAAU;AACf,SAAK,SAAS,IAAI,oBAAoB;AAAA,MACpC,UAAU;AAAA,MACV,GAAG;AAAA,IACL,CAAC;AACD,SAAK,OAAO,GAAG,cAAc,KAAK,aAAa,KAAK,IAAI,CAAC;AACzD,SAAK,QAAQ,MAAM,QAAQ,IAAI,IAAI,OAAO,CAAC,IAAI;AAAA,EACjD;AAAA,EAEA,cAAc,UAAkB;AAC9B,WAAO,KAAK,MAAM,SAAS,QAAQ;AAAA,EACrC;AAAA,EAEA,QAAQ,SAA0B,QAAgB,MAAc;AAC9D,SAAK,OAAO,cAAc,SAAS,QAAQ,MAAM,CAAC,cAAc;AAC9D,WAAK,OAAO,KAAK,cAAc,WAAW,OAAO;AAAA,IACnD,CAAC;AAAA,EACH;AASF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ import { default as default2 } from "./wssPlugin";
2
+ export * from "./WebSocketServer";
3
+ export * from "./types";
4
+ export {
5
+ default2 as default
6
+ };
7
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../../src/vendor/repack/dev-server/src/plugins/wss/index.ts"],
4
+ "sourcesContent": ["export { default } from './wssPlugin'\nexport * from './WebSocketServer'\nexport * from './types'\n"],
5
+ "mappings": "AAAA,SAAS,WAAAA,gBAAe;AACxB,cAAc;AACd,cAAc;",
6
+ "names": ["default"]
7
+ }
@@ -0,0 +1,110 @@
1
+ import { URL } from "url";
2
+ import Device from "../../../../vendor/metro-inspector-proxy/src/Device.js";
3
+ import { WebSocketServer } from "../WebSocketServer";
4
+ const WS_DEVICE_URL = "/inspector/device";
5
+ const WS_DEBUGGER_URL = "/inspector/debug";
6
+ class HermesInspectorProxy extends WebSocketServer {
7
+ constructor(fastify, config) {
8
+ super(fastify, [WS_DEVICE_URL, WS_DEBUGGER_URL]);
9
+ this.config = config;
10
+ this.devices = /* @__PURE__ */ new Map();
11
+ this.deviceCounter = 0;
12
+ this.serverHost = `${this.config.host || "localhost"}:${this.config.port}`;
13
+ this.setup();
14
+ }
15
+ setup() {
16
+ const onSend = (_request, reply, _payload, done) => {
17
+ reply.headers({
18
+ "Content-Type": "application/json; charset=UTF-8",
19
+ "Cache-Control": "no-cache",
20
+ Connection: "close"
21
+ });
22
+ done();
23
+ };
24
+ this.fastify.get("/json/version", { onSend }, async () => {
25
+ return {
26
+ Browser: "Mobile JavaScript",
27
+ "Protocol-Version": "1.1"
28
+ };
29
+ });
30
+ const pageListHandler = async () => {
31
+ const pages = [];
32
+ for (const [deviceId, device] of this.devices) {
33
+ const devicePages = device.getPagesList();
34
+ for (const page of devicePages) {
35
+ pages.push(this.buildPageDescription(deviceId, page));
36
+ }
37
+ }
38
+ return pages;
39
+ };
40
+ this.fastify.get("/json/list", { onSend }, pageListHandler);
41
+ this.fastify.get("/json", { onSend, logLevel: "silent" }, pageListHandler);
42
+ }
43
+ buildPageDescription(deviceId, page) {
44
+ const debuggerUrl = `${this.serverHost}${WS_DEBUGGER_URL}?device=${deviceId}&page=${page.id}`;
45
+ const webSocketDebuggerUrl = "ws://" + debuggerUrl;
46
+ const devtoolsFrontendUrl = "chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=" + encodeURIComponent(debuggerUrl);
47
+ return {
48
+ id: `${deviceId}-${page.id}`,
49
+ description: page.app,
50
+ title: page.title,
51
+ faviconUrl: "https://reactjs.org/favicon.ico",
52
+ devtoolsFrontendUrl,
53
+ type: "node",
54
+ webSocketDebuggerUrl,
55
+ vm: page.vm
56
+ };
57
+ }
58
+ /**
59
+ * Process new WebSocket connection from device.
60
+ *
61
+ * @param socket Incoming device's WebSocket connection.
62
+ * @param request Upgrade request for the connection.
63
+ */
64
+ onConnection(socket, request) {
65
+ try {
66
+ const { url = "" } = request;
67
+ const { searchParams } = new URL(url, "http://localhost");
68
+ if (url.startsWith("/inspector/device")) {
69
+ const deviceName = searchParams.get("name") ?? "Unknown";
70
+ const appName = searchParams.get("app") ?? "Unknown";
71
+ const deviceId = this.deviceCounter++;
72
+ this.devices.set(
73
+ deviceId,
74
+ new Device(deviceId, deviceName, appName, socket, this.config.rootDir)
75
+ );
76
+ this.fastify.log.info({ msg: "Hermes device connected", deviceId });
77
+ const onClose = () => {
78
+ this.fastify.log.info({
79
+ msg: "Hermes device disconnected",
80
+ deviceId
81
+ });
82
+ this.devices.delete(deviceId);
83
+ };
84
+ socket.addEventListener("error", onClose);
85
+ socket.addEventListener("close", onClose);
86
+ } else {
87
+ const deviceId = searchParams.get("device") ?? void 0;
88
+ const pageId = searchParams.get("page") ?? void 0;
89
+ if (deviceId === void 0 || pageId === void 0) {
90
+ throw new Error("Incorrect URL - must provide device and page IDs");
91
+ }
92
+ const device = this.devices.get(parseInt(deviceId, 10));
93
+ if (!device) {
94
+ throw new Error("Unknown device with ID " + deviceId);
95
+ }
96
+ device.handleDebuggerConnection(socket, pageId);
97
+ }
98
+ } catch (error) {
99
+ this.fastify.log.error({
100
+ msg: "Failed to establish connection with Hermes device",
101
+ error: error.message
102
+ });
103
+ socket.close(1011, error.toString());
104
+ }
105
+ }
106
+ }
107
+ export {
108
+ HermesInspectorProxy
109
+ };
110
+ //# sourceMappingURL=HermesInspectorProxy.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../../../src/vendor/repack/dev-server/src/plugins/wss/servers/HermesInspectorProxy.ts"],
4
+ "sourcesContent": ["import type { IncomingMessage } from 'http'\nimport { URL } from 'url'\n\nimport type { FastifyInstance, FastifyReply, FastifyRequest, LogLevel } from 'fastify'\nimport WebSocket from 'ws'\n\nimport Device from '../../../../vendor/metro-inspector-proxy/src/Device.js'\nimport { Server } from '../../../types'\nimport { WebSocketServer } from '../WebSocketServer'\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(fastify: FastifyInstance, private config: InspectorProxyConfig) {\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('/json', { onSend, logLevel: 'silent' as LogLevel }, pageListHandler)\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"],
5
+ "mappings": "AACA,SAAS,WAAW;AAKpB,OAAO,YAAY;AAEnB,SAAS,uBAAuB;AAEhC,MAAM,gBAAgB;AACtB,MAAM,kBAAkB;AAuBjB,MAAM,6BAA6B,gBAAgB;AAAA,EAKxD,YAAY,SAAkC,QAA8B;AAC1E,UAAM,SAAS,CAAC,eAAe,eAAe,CAAC;AADH;AAJ9C,SAAQ,UAAU,oBAAI,IAAiB;AACvC,SAAQ,gBAAgB;AAKtB,SAAK,aAAa,GAAG,KAAK,OAAO,QAAQ,eAAe,KAAK,OAAO;AACpE,SAAK,MAAM;AAAA,EACb;AAAA,EAEQ,QAAQ;AACd,UAAM,SAAS,CACb,UACA,OACA,UACA,SACG;AACH,YAAM,QAAQ;AAAA,QACZ,gBAAgB;AAAA,QAChB,iBAAiB;AAAA,QACjB,YAAY;AAAA,MACd,CAAC;AACD,WAAK;AAAA,IACP;AAEA,SAAK,QAAQ,IAAI,iBAAiB,EAAE,OAAO,GAAG,YAAY;AACxD,aAAO;AAAA,QACL,SAAS;AAAA,QACT,oBAAoB;AAAA,MACtB;AAAA,IACF,CAAC;AAED,UAAM,kBAAkB,YAAY;AAClC,YAAM,QAA2B,CAAC;AAClC,iBAAW,CAAC,UAAU,MAAM,KAAK,KAAK,SAAS;AAC7C,cAAM,cAAc,OAAO,aAAa;AACxC,mBAAW,QAAQ,aAAa;AAC9B,gBAAM,KAAK,KAAK,qBAAqB,UAAU,IAAI,CAAC;AAAA,QACtD;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAEA,SAAK,QAAQ,IAAI,cAAc,EAAE,OAAO,GAAG,eAAe;AAC1D,SAAK,QAAQ,IAAI,SAAS,EAAE,QAAQ,UAAU,SAAqB,GAAG,eAAe;AAAA,EACvF;AAAA,EAEQ,qBAAqB,UAAkB,MAAY;AACzD,UAAM,cAAc,GAAG,K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,UAAU,EAAE,CAAC;AACtD,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI,MAAM,4BAA4B,QAAQ;AAAA,QACtD;AAEA,eAAO,yBAAyB,QAAQ,MAAM;AAAA,MAChD;AAAA,IACF,SAAS,OAAP;AACA,WAAK,QAAQ,IAAI,MAAM;AAAA,QACrB,KAAK;AAAA,QACL,OAAQ,MAAgB;AAAA,MAC1B,CAAC;AACD,aAAO,MAAM,MAAO,MAAgB,SAAS,CAAC;AAAA,IAChD;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,52 @@
1
+ import { WebSocketServer } from "../WebSocketServer";
2
+ class WebSocketApiServer extends WebSocketServer {
3
+ /**
4
+ * Create new instance of WebSocketApiServer and attach it to the given Fastify instance.
5
+ * Any logging information, will be passed through standard `fastify.log` API.
6
+ *
7
+ * @param fastify Fastify instance to attach the WebSocket server to.
8
+ */
9
+ constructor(fastify) {
10
+ super(fastify, "/api");
11
+ this.clients = /* @__PURE__ */ new Map();
12
+ this.nextClientId = 0;
13
+ }
14
+ /**
15
+ * Send message to all connected API clients.
16
+ *
17
+ * @param event Event string or object to send.
18
+ */
19
+ send(event) {
20
+ const data = typeof event === "string" ? event : JSON.stringify(event);
21
+ for (const [, socket] of this.clients.entries()) {
22
+ try {
23
+ socket.send(data);
24
+ } catch {
25
+ }
26
+ }
27
+ }
28
+ /**
29
+ * Process new WebSocket connection from client application.
30
+ *
31
+ * @param socket Incoming client's WebSocket connection.
32
+ */
33
+ onConnection(socket) {
34
+ const clientId = `client#${this.nextClientId++}`;
35
+ this.clients.set(clientId, socket);
36
+ this.fastify.log.info({ msg: "API client connected", clientId });
37
+ this.clients.set(clientId, socket);
38
+ const onClose = () => {
39
+ this.fastify.log.info({
40
+ msg: "API client disconnected",
41
+ clientId
42
+ });
43
+ this.clients.delete(clientId);
44
+ };
45
+ socket.addEventListener("error", onClose);
46
+ socket.addEventListener("close", onClose);
47
+ }
48
+ }
49
+ export {
50
+ WebSocketApiServer
51
+ };
52
+ //# sourceMappingURL=WebSocketApiServer.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../../../src/vendor/repack/dev-server/src/plugins/wss/servers/WebSocketApiServer.ts"],
4
+ "sourcesContent": ["import { FastifyInstance } from 'fastify'\nimport WebSocket from 'ws'\n\nimport { WebSocketServer } from '../WebSocketServer'\n\n/**\n * Class for creating a WebSocket server for API clients.\n * Useful to listening for compilation events and new logs.\n *\n * @category Development server\n */\nexport class WebSocketApiServer extends WebSocketServer {\n private clients = new Map<string, WebSocket>()\n private nextClientId = 0\n\n /**\n * Create new instance of WebSocketApiServer and attach it to the given Fastify instance.\n * Any logging information, will be passed through standard `fastify.log` API.\n *\n * @param fastify Fastify instance to attach the WebSocket server to.\n */\n constructor(fastify: FastifyInstance) {\n super(fastify, '/api')\n }\n\n /**\n * Send message to all connected API clients.\n *\n * @param event Event string or object to send.\n */\n send(event: any) {\n const data = typeof event === 'string' ? event : JSON.stringify(event)\n\n for (const [, socket] of this.clients.entries()) {\n try {\n socket.send(data)\n } catch {\n // NOOP\n }\n }\n }\n\n /**\n * Process new WebSocket connection from client application.\n *\n * @param socket Incoming client's WebSocket connection.\n */\n onConnection(socket: WebSocket) {\n const clientId = `client#${this.nextClientId++}`\n this.clients.set(clientId, socket)\n\n this.fastify.log.info({ msg: 'API client connected', clientId })\n this.clients.set(clientId, socket)\n\n const onClose = () => {\n this.fastify.log.info({\n msg: 'API client disconnected',\n clientId,\n })\n this.clients.delete(clientId)\n }\n\n socket.addEventListener('error', onClose)\n socket.addEventListener('close', onClose)\n }\n}\n"],
5
+ "mappings": "AAGA,SAAS,uBAAuB;AAQzB,MAAM,2BAA2B,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUtD,YAAY,SAA0B;AACpC,UAAM,SAAS,MAAM;AAVvB,SAAQ,UAAU,oBAAI,IAAuB;AAC7C,SAAQ,eAAe;AAAA,EAUvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,KAAK,OAAY;AACf,UAAM,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,KAAK;AAErE,eAAW,CAAC,EAAE,MAAM,KAAK,KAAK,QAAQ,QAAQ,GAAG;AAC/C,UAAI;AACF,eAAO,KAAK,IAAI;AAAA,MAClB,QAAE;AAAA,MAEF;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAa,QAAmB;AAC9B,UAAM,WAAW,UAAU,KAAK;AAChC,SAAK,QAAQ,IAAI,UAAU,MAAM;AAEjC,SAAK,QAAQ,IAAI,KAAK,EAAE,KAAK,wBAAwB,SAAS,CAAC;AAC/D,SAAK,QAAQ,IAAI,UAAU,MAAM;AAEjC,UAAM,UAAU,MAAM;AACpB,WAAK,QAAQ,IAAI,KAAK;AAAA,QACpB,KAAK;AAAA,QACL;AAAA,MACF,CAAC;AACD,WAAK,QAAQ,OAAO,QAAQ;AAAA,IAC9B;AAEA,WAAO,iBAAiB,SAAS,OAAO;AACxC,WAAO,iBAAiB,SAAS,OAAO;AAAA,EAC1C;AACF;",
6
+ "names": []
7
+ }