@teardown/cli 1.2.39 → 2.0.41

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 (260) hide show
  1. package/bin/teardown.js +11 -1
  2. package/package.json +77 -57
  3. package/src/cli/commands/init.ts +254 -0
  4. package/src/cli/commands/plugins.ts +93 -0
  5. package/src/cli/commands/prebuild.ts +168 -0
  6. package/src/cli/commands/run.ts +727 -0
  7. package/src/cli/commands/start.ts +87 -0
  8. package/src/cli/commands/validate.ts +62 -0
  9. package/src/cli/index.ts +59 -0
  10. package/src/config/index.ts +45 -0
  11. package/src/config/loader.ts +366 -0
  12. package/src/config/schema.ts +235 -0
  13. package/src/config/types.ts +322 -0
  14. package/src/index.ts +177 -0
  15. package/src/pipeline/cache.ts +179 -0
  16. package/src/pipeline/index.ts +10 -0
  17. package/src/pipeline/stages.ts +692 -0
  18. package/src/plugins/base.ts +370 -0
  19. package/src/plugins/capabilities/biometrics.ts +64 -0
  20. package/src/plugins/capabilities/bluetooth.ts +86 -0
  21. package/src/plugins/capabilities/calendar.ts +57 -0
  22. package/src/plugins/capabilities/camera.ts +77 -0
  23. package/src/plugins/capabilities/contacts.ts +57 -0
  24. package/src/plugins/capabilities/deep-linking.ts +124 -0
  25. package/src/plugins/capabilities/firebase.ts +138 -0
  26. package/src/plugins/capabilities/index.ts +96 -0
  27. package/src/plugins/capabilities/location.ts +87 -0
  28. package/src/plugins/capabilities/photo-library.ts +80 -0
  29. package/src/plugins/capabilities/push-notifications.ts +98 -0
  30. package/src/plugins/capabilities/sign-in-with-apple.ts +53 -0
  31. package/src/plugins/context.ts +220 -0
  32. package/src/plugins/index.ts +26 -0
  33. package/src/plugins/resolver.ts +321 -0
  34. package/src/templates/generator.ts +507 -0
  35. package/src/templates/index.ts +9 -0
  36. package/src/templates/paths.ts +25 -0
  37. package/src/transformers/android/gradle.ts +400 -0
  38. package/src/transformers/android/index.ts +19 -0
  39. package/src/transformers/android/manifest.ts +506 -0
  40. package/src/transformers/index.ts +39 -0
  41. package/src/transformers/ios/entitlements.ts +283 -0
  42. package/src/transformers/ios/index.ts +10 -0
  43. package/src/transformers/ios/pbxproj.ts +267 -0
  44. package/src/transformers/ios/plist.ts +198 -0
  45. package/src/utils/fs.ts +429 -0
  46. package/src/utils/index.ts +21 -0
  47. package/src/utils/logger.ts +203 -0
  48. package/templates/.gitignore +63 -0
  49. package/templates/Gemfile +3 -0
  50. package/templates/android/app/build.gradle.kts +97 -0
  51. package/templates/android/app/proguard-rules.pro +10 -0
  52. package/templates/android/app/src/main/AndroidManifest.xml +26 -0
  53. package/templates/android/app/src/main/java/com/appname/MainActivity.kt +22 -0
  54. package/templates/android/app/src/main/java/com/appname/MainApplication.kt +44 -0
  55. package/templates/android/app/src/main/res/values/strings.xml +3 -0
  56. package/templates/android/app/src/main/res/values/styles.xml +7 -0
  57. package/templates/android/build.gradle.kts +44 -0
  58. package/templates/android/gradle.properties +39 -0
  59. package/templates/android/settings.gradle.kts +12 -0
  60. package/templates/babel.config.js +15 -0
  61. package/templates/index.js +7 -0
  62. package/templates/ios/.xcode.env +11 -0
  63. package/templates/ios/AppName/AppDelegate.swift +25 -0
  64. package/templates/ios/AppName/AppName-Bridging-Header.h +4 -0
  65. package/templates/ios/AppName/AppName.entitlements +6 -0
  66. package/templates/ios/AppName/Images.xcassets/AppIcon.appiconset/Contents.json +35 -0
  67. package/templates/ios/AppName/Images.xcassets/Contents.json +6 -0
  68. package/templates/ios/AppName/Info.plist +49 -0
  69. package/templates/ios/AppName/LaunchScreen.storyboard +38 -0
  70. package/templates/ios/AppName.xcodeproj/project.pbxproj +402 -0
  71. package/templates/ios/AppName.xcodeproj/xcshareddata/xcschemes/AppName.xcscheme +78 -0
  72. package/templates/ios/Podfile +35 -0
  73. package/templates/metro.config.js +41 -0
  74. package/templates/package.json +57 -0
  75. package/templates/react-native.config.js +8 -0
  76. package/templates/src/app/index.tsx +34 -0
  77. package/templates/src/assets/fonts/.gitkeep +1 -0
  78. package/templates/src/assets/images/.gitkeep +1 -0
  79. package/templates/src/components/ui/accordion.tsx +114 -0
  80. package/templates/src/components/ui/avatar.tsx +75 -0
  81. package/templates/src/components/ui/button.tsx +93 -0
  82. package/templates/src/components/ui/card.tsx +120 -0
  83. package/templates/src/components/ui/checkbox.tsx +133 -0
  84. package/templates/src/components/ui/chip.tsx +95 -0
  85. package/templates/src/components/ui/dialog.tsx +134 -0
  86. package/templates/src/components/ui/divider.tsx +67 -0
  87. package/templates/src/components/ui/error-view.tsx +82 -0
  88. package/templates/src/components/ui/form-field.tsx +101 -0
  89. package/templates/src/components/ui/index.ts +100 -0
  90. package/templates/src/components/ui/popover.tsx +92 -0
  91. package/templates/src/components/ui/pressable-feedback.tsx +88 -0
  92. package/templates/src/components/ui/radio-group.tsx +153 -0
  93. package/templates/src/components/ui/scroll-shadow.tsx +108 -0
  94. package/templates/src/components/ui/select.tsx +165 -0
  95. package/templates/src/components/ui/skeleton-group.tsx +97 -0
  96. package/templates/src/components/ui/skeleton.tsx +87 -0
  97. package/templates/src/components/ui/spinner.tsx +87 -0
  98. package/templates/src/components/ui/surface.tsx +95 -0
  99. package/templates/src/components/ui/switch.tsx +124 -0
  100. package/templates/src/components/ui/tabs.tsx +154 -0
  101. package/templates/src/components/ui/text-field.tsx +106 -0
  102. package/templates/src/components/ui/toast.tsx +129 -0
  103. package/templates/src/contexts/.gitkeep +2 -0
  104. package/templates/src/core/clients/api/api.client.ts +113 -0
  105. package/templates/src/core/clients/api/index.ts +1 -0
  106. package/templates/src/core/clients/storage/index.ts +1 -0
  107. package/templates/src/core/clients/storage/storage.client.ts +121 -0
  108. package/templates/src/core/constants/index.ts +19 -0
  109. package/templates/src/core/core.ts +40 -0
  110. package/templates/src/core/index.ts +10 -0
  111. package/templates/src/global.css +87 -0
  112. package/templates/src/hooks/index.ts +6 -0
  113. package/templates/src/hooks/use-debounce.ts +23 -0
  114. package/templates/src/hooks/use-mounted.ts +21 -0
  115. package/templates/src/index.ts +28 -0
  116. package/templates/src/lib/index.ts +5 -0
  117. package/templates/src/lib/utils.ts +115 -0
  118. package/templates/src/modules/.gitkeep +6 -0
  119. package/templates/src/navigation/index.ts +8 -0
  120. package/templates/src/navigation/navigation-provider.tsx +36 -0
  121. package/templates/src/navigation/router.tsx +137 -0
  122. package/templates/src/providers/app.provider.tsx +29 -0
  123. package/templates/src/providers/index.ts +5 -0
  124. package/templates/src/routes/(tabs)/_layout.tsx +42 -0
  125. package/templates/src/routes/(tabs)/explore.tsx +161 -0
  126. package/templates/src/routes/(tabs)/home.tsx +138 -0
  127. package/templates/src/routes/(tabs)/profile.tsx +151 -0
  128. package/templates/src/routes/_layout.tsx +18 -0
  129. package/templates/src/routes/settings.tsx +194 -0
  130. package/templates/src/screens/auth/index.ts +6 -0
  131. package/templates/src/screens/auth/login.tsx +165 -0
  132. package/templates/src/screens/auth/register.tsx +203 -0
  133. package/templates/src/screens/home.tsx +204 -0
  134. package/templates/src/screens/index.ts +17 -0
  135. package/templates/src/screens/profile.tsx +210 -0
  136. package/templates/src/screens/settings.tsx +216 -0
  137. package/templates/src/screens/welcome.tsx +101 -0
  138. package/templates/src/styles/index.ts +103 -0
  139. package/templates/src/types/common.ts +71 -0
  140. package/templates/src/types/index.ts +5 -0
  141. package/templates/tsconfig.json +14 -0
  142. package/README.md +0 -15
  143. package/assets/favicon.ico +0 -0
  144. package/dist/commands/dev/dev.d.ts +0 -22
  145. package/dist/commands/dev/dev.js +0 -56
  146. package/dist/commands/dev/dev.js.map +0 -1
  147. package/dist/commands/init/init-teardown.d.ts +0 -9
  148. package/dist/commands/init/init-teardown.js +0 -27
  149. package/dist/commands/init/init-teardown.js.map +0 -1
  150. package/dist/index.d.ts +0 -1
  151. package/dist/index.js +0 -21
  152. package/dist/index.js.map +0 -1
  153. package/dist/modules/dev/dev-menu/keyboard-handler.d.ts +0 -21
  154. package/dist/modules/dev/dev-menu/keyboard-handler.js +0 -139
  155. package/dist/modules/dev/dev-menu/keyboard-handler.js.map +0 -1
  156. package/dist/modules/dev/dev-menu/open-debugger-keyboard-handler.d.ts +0 -18
  157. package/dist/modules/dev/dev-menu/open-debugger-keyboard-handler.js +0 -106
  158. package/dist/modules/dev/dev-menu/open-debugger-keyboard-handler.js.map +0 -1
  159. package/dist/modules/dev/dev-server/cdp/cdp.adapter.d.ts +0 -6
  160. package/dist/modules/dev/dev-server/cdp/cdp.adapter.js +0 -13
  161. package/dist/modules/dev/dev-server/cdp/cdp.adapter.js.map +0 -1
  162. package/dist/modules/dev/dev-server/cdp/index.d.ts +0 -2
  163. package/dist/modules/dev/dev-server/cdp/index.js +0 -19
  164. package/dist/modules/dev/dev-server/cdp/index.js.map +0 -1
  165. package/dist/modules/dev/dev-server/cdp/types.d.ts +0 -107
  166. package/dist/modules/dev/dev-server/cdp/types.js +0 -3
  167. package/dist/modules/dev/dev-server/cdp/types.js.map +0 -1
  168. package/dist/modules/dev/dev-server/dev-server-checker.d.ts +0 -22
  169. package/dist/modules/dev/dev-server/dev-server-checker.js +0 -73
  170. package/dist/modules/dev/dev-server/dev-server-checker.js.map +0 -1
  171. package/dist/modules/dev/dev-server/dev-server.d.ts +0 -74
  172. package/dist/modules/dev/dev-server/dev-server.js +0 -272
  173. package/dist/modules/dev/dev-server/dev-server.js.map +0 -1
  174. package/dist/modules/dev/dev-server/inspector/device.d.ts +0 -46
  175. package/dist/modules/dev/dev-server/inspector/device.event-reporter.d.ts +0 -37
  176. package/dist/modules/dev/dev-server/inspector/device.event-reporter.js +0 -166
  177. package/dist/modules/dev/dev-server/inspector/device.event-reporter.js.map +0 -1
  178. package/dist/modules/dev/dev-server/inspector/device.js +0 -578
  179. package/dist/modules/dev/dev-server/inspector/device.js.map +0 -1
  180. package/dist/modules/dev/dev-server/inspector/inspector.d.ts +0 -27
  181. package/dist/modules/dev/dev-server/inspector/inspector.js +0 -225
  182. package/dist/modules/dev/dev-server/inspector/inspector.js.map +0 -1
  183. package/dist/modules/dev/dev-server/inspector/types.d.ts +0 -156
  184. package/dist/modules/dev/dev-server/inspector/types.js +0 -3
  185. package/dist/modules/dev/dev-server/inspector/types.js.map +0 -1
  186. package/dist/modules/dev/dev-server/inspector/wss/servers/debugger-connection.server.d.ts +0 -14
  187. package/dist/modules/dev/dev-server/inspector/wss/servers/debugger-connection.server.js +0 -63
  188. package/dist/modules/dev/dev-server/inspector/wss/servers/debugger-connection.server.js.map +0 -1
  189. package/dist/modules/dev/dev-server/inspector/wss/servers/device-connection.server.d.ts +0 -19
  190. package/dist/modules/dev/dev-server/inspector/wss/servers/device-connection.server.js +0 -66
  191. package/dist/modules/dev/dev-server/inspector/wss/servers/device-connection.server.js.map +0 -1
  192. package/dist/modules/dev/dev-server/plugins/devtools.plugin.d.ts +0 -1
  193. package/dist/modules/dev/dev-server/plugins/devtools.plugin.js +0 -51
  194. package/dist/modules/dev/dev-server/plugins/devtools.plugin.js.map +0 -1
  195. package/dist/modules/dev/dev-server/plugins/favicon.plugin.d.ts +0 -1
  196. package/dist/modules/dev/dev-server/plugins/favicon.plugin.js +0 -19
  197. package/dist/modules/dev/dev-server/plugins/favicon.plugin.js.map +0 -1
  198. package/dist/modules/dev/dev-server/plugins/multipart.plugin.d.ts +0 -1
  199. package/dist/modules/dev/dev-server/plugins/multipart.plugin.js +0 -63
  200. package/dist/modules/dev/dev-server/plugins/multipart.plugin.js.map +0 -1
  201. package/dist/modules/dev/dev-server/plugins/systrace.plugin.d.ts +0 -1
  202. package/dist/modules/dev/dev-server/plugins/systrace.plugin.js +0 -29
  203. package/dist/modules/dev/dev-server/plugins/systrace.plugin.js.map +0 -1
  204. package/dist/modules/dev/dev-server/plugins/types.d.ts +0 -11
  205. package/dist/modules/dev/dev-server/plugins/types.js +0 -3
  206. package/dist/modules/dev/dev-server/plugins/types.js.map +0 -1
  207. package/dist/modules/dev/dev-server/plugins/wss/index.d.ts +0 -3
  208. package/dist/modules/dev/dev-server/plugins/wss/index.js +0 -20
  209. package/dist/modules/dev/dev-server/plugins/wss/index.js.map +0 -1
  210. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-api.server.d.ts +0 -37
  211. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-api.server.js +0 -67
  212. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-api.server.js.map +0 -1
  213. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-debugger.server.d.ts +0 -63
  214. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-debugger.server.js +0 -129
  215. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-debugger.server.js.map +0 -1
  216. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-dev-client.server.d.ts +0 -32
  217. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-dev-client.server.js +0 -76
  218. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-dev-client.server.js.map +0 -1
  219. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-events.server.d.ts +0 -75
  220. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-events.server.js +0 -199
  221. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-events.server.js.map +0 -1
  222. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-hmr.server.d.ts +0 -44
  223. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-hmr.server.js +0 -121
  224. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-hmr.server.js.map +0 -1
  225. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-message.server.d.ts +0 -135
  226. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-message.server.js +0 -364
  227. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-message.server.js.map +0 -1
  228. package/dist/modules/dev/dev-server/plugins/wss/types.d.ts +0 -6
  229. package/dist/modules/dev/dev-server/plugins/wss/types.js +0 -3
  230. package/dist/modules/dev/dev-server/plugins/wss/types.js.map +0 -1
  231. package/dist/modules/dev/dev-server/plugins/wss/web-socket-router.d.ts +0 -32
  232. package/dist/modules/dev/dev-server/plugins/wss/web-socket-router.js +0 -58
  233. package/dist/modules/dev/dev-server/plugins/wss/web-socket-router.js.map +0 -1
  234. package/dist/modules/dev/dev-server/plugins/wss/web-socket-server-adapter.d.ts +0 -13
  235. package/dist/modules/dev/dev-server/plugins/wss/web-socket-server-adapter.js +0 -27
  236. package/dist/modules/dev/dev-server/plugins/wss/web-socket-server-adapter.js.map +0 -1
  237. package/dist/modules/dev/dev-server/plugins/wss/web-socket-server.d.ts +0 -39
  238. package/dist/modules/dev/dev-server/plugins/wss/web-socket-server.js +0 -47
  239. package/dist/modules/dev/dev-server/plugins/wss/web-socket-server.js.map +0 -1
  240. package/dist/modules/dev/dev-server/plugins/wss/wss.plugin.d.ts +0 -24
  241. package/dist/modules/dev/dev-server/plugins/wss/wss.plugin.js +0 -56
  242. package/dist/modules/dev/dev-server/plugins/wss/wss.plugin.js.map +0 -1
  243. package/dist/modules/dev/dev-server/sybmolicate/sybmolicate.plugin.d.ts +0 -7
  244. package/dist/modules/dev/dev-server/sybmolicate/sybmolicate.plugin.js +0 -41
  245. package/dist/modules/dev/dev-server/sybmolicate/sybmolicate.plugin.js.map +0 -1
  246. package/dist/modules/dev/dev-server/sybmolicate/types.d.ts +0 -64
  247. package/dist/modules/dev/dev-server/sybmolicate/types.js +0 -3
  248. package/dist/modules/dev/dev-server/sybmolicate/types.js.map +0 -1
  249. package/dist/modules/dev/terminal/base.terminal.reporter.d.ts +0 -25
  250. package/dist/modules/dev/terminal/base.terminal.reporter.js +0 -79
  251. package/dist/modules/dev/terminal/base.terminal.reporter.js.map +0 -1
  252. package/dist/modules/dev/terminal/terminal.reporter.d.ts +0 -13
  253. package/dist/modules/dev/terminal/terminal.reporter.js +0 -83
  254. package/dist/modules/dev/terminal/terminal.reporter.js.map +0 -1
  255. package/dist/modules/dev/types.d.ts +0 -20
  256. package/dist/modules/dev/types.js +0 -3
  257. package/dist/modules/dev/types.js.map +0 -1
  258. package/dist/modules/dev/utils/log.d.ts +0 -23
  259. package/dist/modules/dev/utils/log.js +0 -74
  260. package/dist/modules/dev/utils/log.js.map +0 -1
@@ -1,75 +0,0 @@
1
- import type { FastifyInstance } from "fastify";
2
- import type WebSocket from "ws";
3
- import { WebSocketServer } from "../web-socket-server";
4
- import type { WebSocketMessageServer } from "./web-socket-message.server";
5
- /**
6
- * {@link WebSocketEventsServer} configuration options.
7
- */
8
- export interface WebSocketEventsServerConfig {
9
- /** Instance of a {@link WebSocketMessageServer} which can be used for broadcasting. */
10
- webSocketMessageServer: WebSocketMessageServer;
11
- }
12
- /**
13
- * Represents a command that connected clients can send to the {@link WebSocketEventsServer}.
14
- */
15
- export interface Command {
16
- version: number;
17
- type: "command";
18
- command: string;
19
- params?: any;
20
- }
21
- /**
22
- * Represents an event message.
23
- */
24
- export interface EventMessage {
25
- error?: Error | string;
26
- type?: string;
27
- data?: any;
28
- }
29
- /**
30
- * Class for creating a WebSocket server to process events and reports.
31
- *
32
- * Based on: https://github.com/react-native-community/cli/blob/v4.14.0/packages/cli-server-api/src/websocket/eventsSocketServer.ts
33
- *
34
- * @category Development server
35
- */
36
- export declare class WebSocketEventsServer extends WebSocketServer {
37
- private config;
38
- static readonly PROTOCOL_VERSION = 2;
39
- private clients;
40
- private nextClientId;
41
- /**
42
- * Create new instance of WebSocketHMRServer and attach it to the given Fastify instance.
43
- * Any logging information, will be passed through standard `fastify.log` API.
44
- *
45
- * @param fastify Fastify instance to attach the WebSocket server to.
46
- * @param config Configuration object.
47
- */
48
- constructor(fastify: FastifyInstance, config: WebSocketEventsServerConfig);
49
- /**
50
- * Parse received command message from connected client.
51
- *
52
- * @param data Stringified command message to parse.
53
- * @returns Parsed command or `undefined` if parsing failed.
54
- */
55
- parseMessage(data: string): Command | undefined;
56
- /**
57
- * Stringify `message` into a format that can be transported as a `string`.
58
- *
59
- * @param message Message to serialize.
60
- * @returns String representation of a `message` or `undefined` if serialization failed.
61
- */
62
- serializeMessage(message: EventMessage, clientId?: string): string;
63
- /**
64
- * Broadcast event to all connected clients.
65
- *
66
- * @param event Event message to broadcast.
67
- */
68
- broadcastEvent(event: EventMessage): void;
69
- /**
70
- * Process new client's WebSocket connection.
71
- *
72
- * @param socket Incoming WebSocket connection.
73
- */
74
- onConnection(socket: WebSocket): void;
75
- }
@@ -1,199 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.WebSocketEventsServer = void 0;
27
- const prettyFormat = __importStar(require("pretty-format"));
28
- const web_socket_server_1 = require("../web-socket-server");
29
- /**
30
- * Class for creating a WebSocket server to process events and reports.
31
- *
32
- * Based on: https://github.com/react-native-community/cli/blob/v4.14.0/packages/cli-server-api/src/websocket/eventsSocketServer.ts
33
- *
34
- * @category Development server
35
- */
36
- class WebSocketEventsServer extends web_socket_server_1.WebSocketServer {
37
- config;
38
- static PROTOCOL_VERSION = 2;
39
- clients = new Map();
40
- nextClientId = 0;
41
- /**
42
- * Create new instance of WebSocketHMRServer and attach it to the given Fastify instance.
43
- * Any logging information, will be passed through standard `fastify.log` API.
44
- *
45
- * @param fastify Fastify instance to attach the WebSocket server to.
46
- * @param config Configuration object.
47
- */
48
- constructor(fastify, config) {
49
- super(fastify, "/events", {
50
- verifyClient: (({ origin }) => {
51
- return /^(https?:\/\/localhost|file:\/\/)/.test(origin);
52
- }),
53
- });
54
- this.config = config;
55
- }
56
- /**
57
- * Parse received command message from connected client.
58
- *
59
- * @param data Stringified command message to parse.
60
- * @returns Parsed command or `undefined` if parsing failed.
61
- */
62
- parseMessage(data) {
63
- try {
64
- const message = JSON.parse(data);
65
- if (message.version === WebSocketEventsServer.PROTOCOL_VERSION) {
66
- return message;
67
- }
68
- this.fastify.log.error({
69
- msg: "Received message had wrong protocol version",
70
- message,
71
- });
72
- }
73
- catch {
74
- this.fastify.log.error({
75
- msg: "Failed to parse the message as JSON",
76
- data,
77
- });
78
- }
79
- return undefined;
80
- }
81
- /**
82
- * Stringify `message` into a format that can be transported as a `string`.
83
- *
84
- * @param message Message to serialize.
85
- * @returns String representation of a `message` or `undefined` if serialization failed.
86
- */
87
- serializeMessage(message, clientId) {
88
- let toSerialize = message;
89
- if (message.error && message.error instanceof Error) {
90
- toSerialize = {
91
- ...message,
92
- error: prettyFormat.default(message.error, {
93
- escapeString: true,
94
- highlight: true,
95
- maxDepth: 3,
96
- min: true,
97
- }),
98
- };
99
- }
100
- else if (message && message.type === "client_log") {
101
- toSerialize = {
102
- ...message,
103
- data: message.data.map((item) => typeof item === "string"
104
- ? item
105
- : prettyFormat.default(item, {
106
- escapeString: true,
107
- highlight: true,
108
- maxDepth: 3,
109
- min: true,
110
- plugins: [prettyFormat.plugins.ReactElement],
111
- })),
112
- };
113
- }
114
- try {
115
- return JSON.stringify({
116
- ...toSerialize,
117
- clientId,
118
- });
119
- }
120
- catch (error) {
121
- this.fastify.log.error({ msg: "Failed to serialize", error });
122
- return undefined;
123
- }
124
- }
125
- /**
126
- * Broadcast event to all connected clients.
127
- *
128
- * @param event Event message to broadcast.
129
- */
130
- broadcastEvent(event) {
131
- if (!this.clients.size) {
132
- return;
133
- }
134
- const serialized = this.serializeMessage(event);
135
- if (!serialized) {
136
- console.log("Failed to serialize event");
137
- return;
138
- }
139
- for (const [clientId, socket] of this.clients.entries()) {
140
- try {
141
- const clientMessage = this.serializeMessage(event, clientId);
142
- if (!clientMessage) {
143
- continue;
144
- }
145
- socket.send(clientMessage);
146
- }
147
- catch (error) {
148
- this.fastify.log.error({
149
- msg: "Failed to send broadcast to client",
150
- clientId,
151
- error,
152
- _skipBroadcast: true,
153
- });
154
- }
155
- }
156
- }
157
- /**
158
- * Process new client's WebSocket connection.
159
- *
160
- * @param socket Incoming WebSocket connection.
161
- */
162
- onConnection(socket) {
163
- const clientId = `client#${this.nextClientId++}`;
164
- this.clients.set(clientId, socket);
165
- this.fastify.log.debug({ msg: "Events client connected", clientId });
166
- const onClose = () => {
167
- this.fastify.log.debug({ msg: "Events client disconnected", clientId });
168
- socket.removeAllListeners();
169
- this.clients.delete(clientId);
170
- };
171
- socket.addEventListener("error", onClose);
172
- socket.addEventListener("close", onClose);
173
- socket.addEventListener("message", (event) => {
174
- const message = this.parseMessage(event.data.toString());
175
- if (!message) {
176
- return;
177
- }
178
- if (message.type === "command") {
179
- try {
180
- this.config.webSocketMessageServer.broadcast(message.command, message.params);
181
- }
182
- catch (error) {
183
- this.fastify.log.error({
184
- msg: "Failed to forward message to clients",
185
- error,
186
- });
187
- }
188
- }
189
- else {
190
- this.fastify.log.error({
191
- msg: "Unknown message type",
192
- message,
193
- });
194
- }
195
- });
196
- }
197
- }
198
- exports.WebSocketEventsServer = WebSocketEventsServer;
199
- //# sourceMappingURL=web-socket-events.server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"web-socket-events.server.js","sourceRoot":"","sources":["../../../../../../../src/modules/dev/dev-server/plugins/wss/servers/web-socket-events.server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4DAA8C;AAE9C,4DAAuD;AA8BvD;;;;;;G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AO,EAAE,OAAO,CAAC,CAAC;QAC1C,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;YAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YAEzD,IAAI,CAAC,OAAO,EAAE,CAAC;gBACd,OAAO;YACR,CAAC;YAED,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBAChC,IAAI,CAAC;oBACJ,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,SAAS,CAC3C,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,MAAM,CACd,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBAChB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;wBACtB,GAAG,EAAE,sCAAsC;wBAC3C,KAAK;qBACL,CAAC,CAAC;gBACJ,CAAC;YACF,CAAC;iBAAM,CAAC;gBACP,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;oBACtB,GAAG,EAAE,sBAAsB;oBAC3B,OAAO;iBACP,CAAC,CAAC;YACJ,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;;AA7KF,sDA8KC"}
@@ -1,44 +0,0 @@
1
- import type { IncomingMessage } from "node:http";
2
- import type { FastifyInstance } from "fastify";
3
- import type WebSocket from "ws";
4
- import { WebSocketServer } from "../web-socket-server";
5
- import type { ConfigT } from "metro-config";
6
- import type MetroServer from "metro/src/Server";
7
- /**
8
- * Class for creating a WebSocket server for Hot Module Replacement.
9
- *
10
- * @category Development server
11
- */
12
- export declare class WebSocketHMRServer extends WebSocketServer {
13
- private options;
14
- private clients;
15
- private nextClientId;
16
- private hmrServer;
17
- /**
18
- * Create new instance of WebSocketHMRServer and attach it to the given Fastify instance.
19
- * Any logging information, will be passed through standard `fastify.log` API.
20
- *
21
- * @param fastify Fastify instance to attach the WebSocket server to.
22
- * @param delegate HMR delegate instance.
23
- */
24
- constructor(fastify: FastifyInstance, options: {
25
- metroConfig: ConfigT;
26
- metroServer: MetroServer;
27
- onClientConnected: (platform: string, clientId: string) => void;
28
- });
29
- /**
30
- * Send action to all connected HMR clients.
31
- *
32
- * @param event Event to send to the clients.
33
- * @param platform Platform of clients to send the event to.
34
- * @param clientIds Ids of clients who should receive the event.
35
- */
36
- send(event: any, platform: string, clientIds?: string[]): void;
37
- /**
38
- * Process new WebSocket connection from HMR client.
39
- *
40
- * @param socket Incoming HMR client's WebSocket connection.
41
- */
42
- onConnection(socket: WebSocket, request: IncomingMessage): Promise<void>;
43
- registerHMRClient(socket: WebSocket, requestUrl: string): Promise<void>;
44
- }
@@ -1,121 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.WebSocketHMRServer = void 0;
7
- const node_url_1 = require("node:url");
8
- const web_socket_server_1 = require("../web-socket-server");
9
- // @ts-ignore
10
- const HmrServer_1 = __importDefault(require("metro/src/HmrServer"));
11
- /**
12
- * Class for creating a WebSocket server for Hot Module Replacement.
13
- *
14
- * @category Development server
15
- */
16
- class WebSocketHMRServer extends web_socket_server_1.WebSocketServer {
17
- options;
18
- clients = new Map();
19
- nextClientId = 0;
20
- hmrServer;
21
- /**
22
- * Create new instance of WebSocketHMRServer and attach it to the given Fastify instance.
23
- * Any logging information, will be passed through standard `fastify.log` API.
24
- *
25
- * @param fastify Fastify instance to attach the WebSocket server to.
26
- * @param delegate HMR delegate instance.
27
- */
28
- constructor(fastify, options) {
29
- super(fastify, "/hot");
30
- this.options = options;
31
- this.hmrServer = new HmrServer_1.default(this.options.metroServer.getBundler(), this.options.metroServer.getCreateModuleId(), this.options.metroConfig);
32
- }
33
- /**
34
- * Send action to all connected HMR clients.
35
- *
36
- * @param event Event to send to the clients.
37
- * @param platform Platform of clients to send the event to.
38
- * @param clientIds Ids of clients who should receive the event.
39
- */
40
- send(event, platform, clientIds) {
41
- const data = typeof event === "string" ? event : JSON.stringify(event);
42
- for (const [key, socket] of this.clients) {
43
- if (key.platform !== platform ||
44
- !(clientIds ?? [key.clientId]).includes(key.clientId)) {
45
- continue;
46
- }
47
- try {
48
- socket.send(data);
49
- }
50
- catch (error) {
51
- this.fastify.log.error({
52
- msg: "Cannot send action to client",
53
- event,
54
- error,
55
- ...key,
56
- });
57
- }
58
- }
59
- }
60
- /**
61
- * Process new WebSocket connection from HMR client.
62
- *
63
- * @param socket Incoming HMR client's WebSocket connection.
64
- */
65
- async onConnection(socket, request) {
66
- const requestUrl = request.url || "";
67
- const { searchParams } = new node_url_1.URL(requestUrl, "http://localhost");
68
- const platform = searchParams.get("platform") ?? "unknown";
69
- if (!platform) {
70
- this.fastify.log.debug({
71
- msg: "HMR connection disconnected - missing platform",
72
- });
73
- socket.close();
74
- return;
75
- }
76
- const clientId = `client#${this.nextClientId++}`;
77
- const client = {
78
- clientId,
79
- platform,
80
- };
81
- this.clients.set(client, socket);
82
- this.fastify.log.debug({ msg: "HMR client connected", ...client });
83
- const onClose = () => {
84
- this.fastify.log.debug({
85
- msg: "HMR client disconnected",
86
- ...client,
87
- });
88
- this.clients.delete(client);
89
- };
90
- socket.addEventListener("error", onClose);
91
- socket.addEventListener("close", onClose);
92
- await this.registerHMRClient(socket, requestUrl);
93
- this.options.onClientConnected(platform, clientId);
94
- }
95
- async registerHMRClient(socket, requestUrl) {
96
- const sendFn = (...args) => {
97
- // @ts-ignore
98
- socket.send(...args);
99
- };
100
- const hmrClient = await this.hmrServer.onClientConnect(requestUrl, sendFn);
101
- socket.on("error", (error) => {
102
- this.fastify.log.error({
103
- msg: "HMR client error",
104
- error,
105
- });
106
- this.hmrServer.onClientError(hmrClient, error);
107
- });
108
- socket.on("close", () => {
109
- this.fastify.log.debug({
110
- msg: "HMR client disconnected",
111
- ...hmrClient,
112
- });
113
- this.hmrServer.onClientDisconnect(hmrClient);
114
- });
115
- socket.on("message", (data) => {
116
- this.hmrServer.onClientMessage(hmrClient, data, sendFn);
117
- });
118
- }
119
- }
120
- exports.WebSocketHMRServer = WebSocketHMRServer;
121
- //# sourceMappingURL=web-socket-hmr.server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"web-socket-hmr.server.js","sourceRoot":"","sources":["../../../../../../../src/modules/dev/dev-server/plugins/wss/servers/web-socket-hmr.server.ts"],"names":[],"mappings":";;;;;;AACA,uCAA+B;AAG/B,4DAAuD;AACvD,aAAa;AACb,oEAAiD;AAMjD;;;;GAIG;AACH,MAAa,kBAAmB,SAAQ,mCAAe;IAkB7C;IAjBD,OAAO,GAAG,IAAI,GAAG,EAGtB,CAAC;IACI,YAAY,GAAG,CAAC,CAAC;IAEjB,SAAS,CAAiB;IAElC;;;;;;OAMG;IACH,YACC,OAAwB,EAChB,OAIP;QAED,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QANf,YAAO,GAAP,OAAO,CAId;QAID,IAAI,CAAC,SAAS,GAAG,IAAI,mBAAc,CAClC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE,EACrC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,iBAAiB,EAAE,EAC5C,IAAI,CAAC,OAAO,CAAC,WAAW,CACxB,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,IAAI,CAAC,KAAU,EAAE,QAAgB,EAAE,SAAoB;QACtD,MAAM,IAAI,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAEvE,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC1C,IACC,GAAG,CAAC,QAAQ,KAAK,QAAQ;gBACzB,CAAC,CAAC,SAAS,IAAI,CAAC,G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AAC,SAAS,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE;YAC7B,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AAnJD,gDAmJC"}
@@ -1,135 +0,0 @@
1
- import type { IncomingMessage } from "node:http";
2
- import type { FastifyInstance } from "fastify";
3
- import type WebSocket from "ws";
4
- import { WebSocketServer } from "../web-socket-server";
5
- /**
6
- * Holds {@link ReactNativeMessage} `id` data.
7
- */
8
- export interface ReactNativeIdObject {
9
- requestId: string;
10
- clientId: string;
11
- }
12
- /**
13
- * Message representation used by {@link WebSocketMessageServer}.
14
- */
15
- export interface ReactNativeMessage {
16
- version?: string;
17
- id?: ReactNativeIdObject;
18
- method?: string;
19
- target: string;
20
- result?: any;
21
- error?: Error;
22
- params?: Record<string, any>;
23
- }
24
- /**
25
- * Class for creating a WebSocket server and sending messages between development server
26
- * and the React Native applications.
27
- *
28
- * Based on: https://github.com/react-native-community/cli/blob/v4.14.0/packages/cli-server-api/src/websocket/messageSocketServer.ts
29
- *
30
- * @category Development server
31
- */
32
- export declare class WebSocketMessageServer extends WebSocketServer {
33
- static readonly PROTOCOL_VERSION = 2;
34
- /**
35
- * Check if message is a broadcast request.
36
- *
37
- * @param message Message to check.
38
- * @returns True if message is a broadcast request and should be broadcasted
39
- * with {@link sendBroadcast}.
40
- */
41
- static isBroadcast(message: Partial<ReactNativeMessage>): boolean;
42
- /**
43
- * Check if message is a method request.
44
- *
45
- * @param message Message to check.
46
- * @returns True if message is a request.
47
- */
48
- static isRequest(message: Partial<ReactNativeMessage>): boolean;
49
- /**
50
- * Check if message is a response with results of performing some request.
51
- *
52
- * @param message Message to check.
53
- * @returns True if message is a response.
54
- */
55
- static isResponse(message: Partial<ReactNativeMessage>): boolean;
56
- private clients;
57
- private nextClientId;
58
- /**
59
- * Create new instance of WebSocketMessageServer and attach it to the given Fastify instance.
60
- * Any logging information, will be passed through standard `fastify.log` API.
61
- *
62
- * @param fastify Fastify instance to attach the WebSocket server to.
63
- */
64
- constructor(fastify: FastifyInstance);
65
- /**
66
- * Parse stringified message into a {@link ReactNativeMessage}.
67
- *
68
- * @param data Stringified message.
69
- * @param binary Additional binary data if any.
70
- * @returns Parsed message or `undefined` if parsing failed.
71
- */
72
- parseMessage(data: string, binary: any): Partial<ReactNativeMessage> | undefined;
73
- /**
74
- * Get client's WebSocket connection for given `clientId`.
75
- * Throws if no such client is connected.
76
- *
77
- * @param clientId Id of the client.
78
- * @returns WebSocket connection.
79
- */
80
- getClientSocket(clientId: string): any;
81
- /**
82
- * Process error by sending an error message to the client whose message caused the error
83
- * to occur.
84
- *
85
- * @param clientId Id of the client whose message caused an error.
86
- * @param message Original message which caused the error.
87
- * @param error Concrete instance of an error that occurred.
88
- */
89
- handleError(clientId: string, message: Partial<ReactNativeMessage>, error: Error): void;
90
- /**
91
- * Send given request `message` to it's designated client's socket based on `message.target`.
92
- * The target client must be connected, otherwise it will throw an error.
93
- *
94
- * @param clientId Id of the client that requested the forward.
95
- * @param message Message to forward.
96
- */
97
- forwardRequest(clientId: string, message: Partial<ReactNativeMessage>): void;
98
- /**
99
- * Send given response `message` to it's designated client's socket based
100
- * on `message.id.clientId`.
101
- * The target client must be connected, otherwise it will throw an error.
102
- *
103
- * @param message Message to forward.
104
- */
105
- forwardResponse(message: Partial<ReactNativeMessage>): void;
106
- /**
107
- * Process request message targeted towards this {@link WebSocketMessageServer}
108
- * and send back the results.
109
- *
110
- * @param clientId Id of the client who send the message.
111
- * @param message The message to process by the server.
112
- */
113
- processServerRequest(clientId: string, message: Partial<ReactNativeMessage>): void;
114
- /**
115
- * Broadcast given message to all connected clients.
116
- *
117
- * @param broadcasterId Id of the client who is broadcasting.
118
- * @param message Message to broadcast.
119
- */
120
- sendBroadcast(broadcasterId: string | undefined, message: Partial<ReactNativeMessage>): void;
121
- /**
122
- * Send method broadcast to all connected clients.
123
- *
124
- * @param method Method name to broadcast.
125
- * @param params Method parameters.
126
- */
127
- broadcast(method: string, params?: Record<string, any>): void;
128
- /**
129
- * Process new client's WebSocket connection.
130
- *
131
- * @param socket Incoming WebSocket connection.
132
- * @param request Upgrade request for the connection.
133
- */
134
- onConnection(socket: WebSocket, request: IncomingMessage): void;
135
- }