@teardown/cli 1.2.38 → 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 (182) 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.js +0 -55
  145. package/dist/commands/init/init-teardown.js +0 -26
  146. package/dist/index.js +0 -20
  147. package/dist/modules/dev/dev-menu/keyboard-handler.js +0 -138
  148. package/dist/modules/dev/dev-menu/open-debugger-keyboard-handler.js +0 -105
  149. package/dist/modules/dev/dev-server/cdp/cdp.adapter.js +0 -12
  150. package/dist/modules/dev/dev-server/cdp/index.js +0 -18
  151. package/dist/modules/dev/dev-server/cdp/types.js +0 -2
  152. package/dist/modules/dev/dev-server/dev-server-checker.js +0 -72
  153. package/dist/modules/dev/dev-server/dev-server.js +0 -269
  154. package/dist/modules/dev/dev-server/inspector/device.event-reporter.js +0 -165
  155. package/dist/modules/dev/dev-server/inspector/device.js +0 -577
  156. package/dist/modules/dev/dev-server/inspector/inspector.js +0 -204
  157. package/dist/modules/dev/dev-server/inspector/types.js +0 -2
  158. package/dist/modules/dev/dev-server/inspector/wss/servers/debugger-connection.server.js +0 -61
  159. package/dist/modules/dev/dev-server/inspector/wss/servers/device-connection.server.js +0 -64
  160. package/dist/modules/dev/dev-server/plugins/devtools.plugin.js +0 -50
  161. package/dist/modules/dev/dev-server/plugins/favicon.plugin.js +0 -19
  162. package/dist/modules/dev/dev-server/plugins/multipart.plugin.js +0 -62
  163. package/dist/modules/dev/dev-server/plugins/systrace.plugin.js +0 -28
  164. package/dist/modules/dev/dev-server/plugins/types.js +0 -2
  165. package/dist/modules/dev/dev-server/plugins/wss/index.js +0 -19
  166. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-api.server.js +0 -66
  167. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-debugger.server.js +0 -128
  168. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-dev-client.server.js +0 -75
  169. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-events.server.js +0 -198
  170. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-hmr.server.js +0 -120
  171. package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-message.server.js +0 -357
  172. package/dist/modules/dev/dev-server/plugins/wss/types.js +0 -2
  173. package/dist/modules/dev/dev-server/plugins/wss/web-socket-router.js +0 -57
  174. package/dist/modules/dev/dev-server/plugins/wss/web-socket-server-adapter.js +0 -26
  175. package/dist/modules/dev/dev-server/plugins/wss/web-socket-server.js +0 -46
  176. package/dist/modules/dev/dev-server/plugins/wss/wss.plugin.js +0 -55
  177. package/dist/modules/dev/dev-server/sybmolicate/sybmolicate.plugin.js +0 -36
  178. package/dist/modules/dev/dev-server/sybmolicate/types.js +0 -2
  179. package/dist/modules/dev/terminal/base.terminal.reporter.js +0 -78
  180. package/dist/modules/dev/terminal/terminal.reporter.js +0 -76
  181. package/dist/modules/dev/types.js +0 -2
  182. package/dist/modules/dev/utils/log.js +0 -73
@@ -1,204 +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.Inspector = void 0;
7
- const ws_1 = require("ws");
8
- const node_url_1 = require("node:url");
9
- const node_url_2 = __importDefault(require("node:url"));
10
- const device_1 = require("./device");
11
- const WS_DEVICE_PATH = "/inspector/device";
12
- const WS_DEBUGGER_PATH = "/inspector/debug";
13
- const JSON_VERSION_PATH = "/json/version";
14
- const JSON_LIST_PATH = "/json";
15
- const JSON_LIST_PATH_2 = "/json/list";
16
- const HEARTBEAT_INTERVAL = 10000;
17
- const MAX_PONG_TIMEOUT = 5000;
18
- const INTERNAL_ERROR_CODE = 1011;
19
- class Inspector {
20
- devices = new Map();
21
- deviceCounter = 0;
22
- projectRoot;
23
- serverBaseUrl;
24
- eventReporter;
25
- cdpAdapter;
26
- constructor(options) {
27
- this.projectRoot = options.projectRoot;
28
- this.serverBaseUrl = options.serverBaseUrl;
29
- this.eventReporter = options.eventReporter;
30
- this.cdpAdapter = options.cdpAdapter;
31
- }
32
- getPageDescriptions() {
33
- const descriptions = [];
34
- for (const [deviceId, device] of this.devices.entries()) {
35
- const devicePages = device
36
- .getPagesList()
37
- .map((page) => this.createPageDescription(deviceId, device, page));
38
- descriptions.push(...devicePages);
39
- }
40
- return descriptions;
41
- }
42
- handleHttpRequest(req, res, next) {
43
- const pathname = new node_url_1.URL(req.url || "", "http://localhost").pathname;
44
- console.log("handleHttpRequest", { pathname });
45
- if (pathname === JSON_LIST_PATH || pathname === JSON_LIST_PATH_2) {
46
- this.sendJsonResponse(res, this.getPageDescriptions());
47
- }
48
- else if (pathname === JSON_VERSION_PATH) {
49
- this.sendJsonResponse(res, {
50
- Browser: "Mobile JavaScript",
51
- "Protocol-Version": "1.1",
52
- });
53
- }
54
- else {
55
- next();
56
- }
57
- }
58
- createWebSocketServers() {
59
- return {
60
- [WS_DEVICE_PATH]: this.createDeviceWebSocketServer(),
61
- [WS_DEBUGGER_PATH]: this.createDebuggerWebSocketServer(),
62
- };
63
- }
64
- createPageDescription(deviceId, device, page) {
65
- const { host, protocol } = new node_url_1.URL(this.serverBaseUrl);
66
- const wsProtocol = protocol === "https:" ? "wss" : "ws";
67
- const wsPath = `${host}${WS_DEBUGGER_PATH}?device=${deviceId}&page=${page.id}`;
68
- return {
69
- id: `${deviceId}-${page.id}`,
70
- title: page.title,
71
- // @ts-ignore
72
- description: page.description || page.app,
73
- type: "node",
74
- webSocketDebuggerUrl: `${wsProtocol}://${wsPath}`,
75
- devtoolsFrontendUrl: `devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&${wsProtocol}=${encodeURIComponent(wsPath)}`,
76
- deviceName: device.getName(),
77
- appId: page.app,
78
- vm: page.vm,
79
- reactNative: {
80
- logicalDeviceId: deviceId,
81
- capabilities: page.capabilities,
82
- },
83
- };
84
- }
85
- createDeviceWebSocketServer() {
86
- const wss = new ws_1.WebSocketServer({
87
- noServer: true,
88
- perMessageDeflate: true,
89
- maxPayload: 0,
90
- });
91
- wss.on("connection", (socket, req) => {
92
- try {
93
- const fallbackDeviceId = String(this.deviceCounter++);
94
- const query = node_url_2.default.parse(req.url || "", true).query || {};
95
- const deviceId = query.device || fallbackDeviceId;
96
- const deviceName = query.name || "Unknown";
97
- const appName = query.app || "Unknown";
98
- const actualDeviceId = Array.isArray(deviceId) ? deviceId[0] : deviceId;
99
- const actualDeviceName = Array.isArray(deviceName)
100
- ? deviceName[0]
101
- : deviceName;
102
- const actualAppName = Array.isArray(appName) ? appName[0] : appName;
103
- const oldDevice = this.devices.get(actualDeviceId);
104
- let newDevice;
105
- if (oldDevice) {
106
- oldDevice.dangerouslyRecreateDevice(actualDeviceId, actualDeviceName, actualAppName, socket, this.projectRoot, this.eventReporter);
107
- newDevice = oldDevice;
108
- }
109
- else {
110
- newDevice = new device_1.Device(actualDeviceId, actualDeviceName, actualAppName, socket, this.projectRoot, this.eventReporter);
111
- }
112
- this.devices.set(actualDeviceId, newDevice);
113
- socket.on("close", () => {
114
- if (this.devices.get(actualDeviceId)?.dangerouslyGetSocket() === socket) {
115
- this.devices.delete(actualDeviceId);
116
- }
117
- // debug(`Device ${deviceName} disconnected.`);
118
- });
119
- }
120
- catch (e) {
121
- console.error("error", e);
122
- socket.close(INTERNAL_ERROR_CODE, e?.toString() ?? "Unknown error");
123
- }
124
- });
125
- return wss;
126
- }
127
- createDebuggerWebSocketServer() {
128
- const wss = new ws_1.WebSocketServer({
129
- noServer: true,
130
- maxPayload: 0,
131
- });
132
- wss.on("connection", (ws, req) => {
133
- try {
134
- const query = new node_url_1.URL(req.url || "", "http://localhost").searchParams;
135
- const deviceId = query.get("device");
136
- const pageId = query.get("page");
137
- if (!deviceId || !pageId) {
138
- throw new Error("Missing device or page ID");
139
- }
140
- const device = this.devices.get(deviceId);
141
- if (!device) {
142
- throw new Error(`Unknown device: ${deviceId}`);
143
- }
144
- this.setupHeartbeat(ws);
145
- device.handleDebuggerConnection(ws, pageId, {
146
- userAgent: req.headers["user-agent"] || null,
147
- });
148
- }
149
- catch (err) {
150
- console.error(err);
151
- ws.close(INTERNAL_ERROR_CODE, err instanceof Error ? err.message : "Unknown error");
152
- this.eventReporter?.logEvent({
153
- type: "connect_debugger_frontend",
154
- status: "error",
155
- error: err,
156
- });
157
- }
158
- });
159
- return wss;
160
- }
161
- setupHeartbeat(ws) {
162
- let pendingPong = false;
163
- let terminateTimeout = null;
164
- const heartbeat = setInterval(() => {
165
- if (ws.readyState !== ws_1.WebSocket.OPEN) {
166
- return;
167
- }
168
- pendingPong = true;
169
- ws.ping(() => {
170
- if (!pendingPong)
171
- return;
172
- terminateTimeout = setTimeout(() => {
173
- if (ws.readyState === ws_1.WebSocket.OPEN) {
174
- ws.terminate();
175
- }
176
- }, MAX_PONG_TIMEOUT);
177
- });
178
- }, HEARTBEAT_INTERVAL);
179
- const resetHeartbeat = () => {
180
- pendingPong = false;
181
- if (terminateTimeout) {
182
- clearTimeout(terminateTimeout);
183
- terminateTimeout = null;
184
- }
185
- };
186
- ws.on("pong", resetHeartbeat);
187
- ws.on("message", resetHeartbeat);
188
- ws.on("close", () => {
189
- clearInterval(heartbeat);
190
- resetHeartbeat();
191
- });
192
- }
193
- sendJsonResponse(res, data) {
194
- const json = JSON.stringify(data, null, 2);
195
- res.writeHead(200, {
196
- "Content-Type": "application/json; charset=UTF-8",
197
- "Cache-Control": "no-cache",
198
- "Content-Length": Buffer.byteLength(json),
199
- Connection: "close",
200
- });
201
- res.end(json);
202
- }
203
- }
204
- exports.Inspector = Inspector;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,61 +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
- const node_url_1 = __importDefault(require("node:url"));
7
- const ws_1 = __importDefault(require("ws"));
8
- const debug = require("debug")("Metro:InspectorProxy");
9
- const INTERNAL_ERROR_CODE = 1011;
10
- const DEBUGGER_HEARTBEAT_INTERVAL_MS = 10000;
11
- const MAX_PONG_LATENCY_MS = 5000;
12
- class DebuggerConnectionServer {
13
- #devices;
14
- #eventReporter;
15
- #startHeartbeat;
16
- constructor({ devices, eventReporter, startHeartbeat, }) {
17
- this.#devices = devices;
18
- this.#eventReporter = eventReporter;
19
- this.#startHeartbeat = startHeartbeat;
20
- }
21
- createServer() {
22
- const wss = new ws_1.default.Server({
23
- noServer: true,
24
- perMessageDeflate: false,
25
- // Don't crash on exceptionally large messages - assume the debugger is
26
- // well-behaved and the device is prepared to handle large messages.
27
- maxPayload: 0,
28
- });
29
- wss.on("connection", async (socket, req) => {
30
- try {
31
- const query = node_url_1.default.parse(req.url || "", true).query || {};
32
- const deviceId = query.device;
33
- const pageId = query.page;
34
- if (deviceId == null || pageId == null) {
35
- throw new Error("Incorrect URL - must provide device and page IDs");
36
- }
37
- const device = this.#devices.get(deviceId);
38
- if (device == null) {
39
- throw new Error(`Unknown device with ID ${deviceId}`);
40
- }
41
- this.#startHeartbeat(socket, DEBUGGER_HEARTBEAT_INTERVAL_MS);
42
- device.handleDebuggerConnection(socket, pageId, {
43
- userAgent: Array.isArray(req.headers["user-agent"])
44
- ? req.headers["user-agent"][0]
45
- : req.headers["user-agent"] || query.userAgent || null,
46
- });
47
- }
48
- catch (e) {
49
- console.error(e);
50
- socket.close(INTERNAL_ERROR_CODE, e?.toString() ?? "Unknown error");
51
- this.#eventReporter?.logEvent({
52
- type: "connect_debugger_frontend",
53
- status: "error",
54
- error: e,
55
- });
56
- }
57
- });
58
- return wss;
59
- }
60
- }
61
- exports.default = DebuggerConnectionServer;
@@ -1,64 +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
- const ws_1 = __importDefault(require("ws"));
7
- const node_url_1 = __importDefault(require("node:url"));
8
- const device_1 = require("../../device");
9
- const debug = require("debug")("Metro:InspectorProxy");
10
- const INTERNAL_ERROR_CODE = 1011;
11
- class DeviceConnectionServer {
12
- #devices;
13
- #deviceCounter;
14
- #projectRoot;
15
- #eventReporter;
16
- #customMessageHandler;
17
- constructor({ devices, deviceCounter, projectRoot, eventReporter, customMessageHandler, }) {
18
- this.#devices = devices;
19
- this.#deviceCounter = deviceCounter;
20
- this.#projectRoot = projectRoot;
21
- this.#eventReporter = eventReporter;
22
- this.#customMessageHandler = customMessageHandler;
23
- }
24
- createServer() {
25
- const wss = new ws_1.default.Server({
26
- noServer: true,
27
- perMessageDeflate: true,
28
- maxPayload: 0,
29
- });
30
- wss.on("connection", async (socket, req) => {
31
- try {
32
- const fallbackDeviceId = String(this.#deviceCounter.value++);
33
- const query = node_url_1.default.parse(req.url || "", true).query || {};
34
- const deviceId = query.device || fallbackDeviceId;
35
- const deviceName = query.name || "Unknown";
36
- const appName = query.app || "Unknown";
37
- const oldDevice = this.#devices.get(deviceId);
38
- let newDevice;
39
- if (oldDevice) {
40
- oldDevice.dangerouslyRecreateDevice(deviceId, deviceName, appName, socket, this.#projectRoot, this.#eventReporter);
41
- newDevice = oldDevice;
42
- }
43
- else {
44
- newDevice = new device_1.Device(deviceId, deviceName, appName, socket, this.#projectRoot, this.#eventReporter);
45
- }
46
- this.#devices.set(deviceId, newDevice);
47
- debug(`Got new connection: name=${deviceName}, app=${appName}, device=${deviceId}`);
48
- socket.on("close", () => {
49
- const device = this.#devices.get(deviceId);
50
- if (device?.dangerouslyGetSocket() === socket) {
51
- this.#devices.delete(deviceId);
52
- }
53
- debug(`Device ${deviceName} disconnected.`);
54
- });
55
- }
56
- catch (e) {
57
- console.error("error", e);
58
- socket.close(INTERNAL_ERROR_CODE, e?.toString() ?? "Unknown error");
59
- }
60
- });
61
- return wss;
62
- }
63
- }
64
- exports.default = DeviceConnectionServer;
@@ -1,50 +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.devtoolsPlugin = void 0;
7
- const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
8
- const open_1 = __importDefault(require("open"));
9
- exports.devtoolsPlugin = (0, fastify_plugin_1.default)(async (instance, options) => {
10
- instance.route({
11
- method: ["GET", "POST", "PUT"],
12
- url: "/reload",
13
- handler: (_request, reply) => {
14
- console.log("Reload endpoint hit", instance.wss.messageServer.broadcast != null);
15
- instance.wss.messageServer.broadcast("reload");
16
- reply.send("OK");
17
- },
18
- });
19
- instance.route({
20
- method: ["GET", "POST", "PUT"],
21
- url: "/launch-js-devtools",
22
- handler: async (request, reply) => {
23
- const customDebugger = process.env.REACT_DEBUGGER;
24
- if (customDebugger) {
25
- // NOOP for now
26
- // TODO implement opening teardown here
27
- }
28
- else if (!instance.wss.debuggerServer.isDebuggerConnected()) {
29
- const url = `${options.https ? "https" : "http"}://${options.host || "localhost"}:${options.port}/debugger-ui`;
30
- try {
31
- request.log.info({ msg: "Opening debugger UI", url });
32
- await (0, open_1.default)(url);
33
- }
34
- catch (error) {
35
- if (error) {
36
- request.log.error({
37
- msg: "Cannot open debugger UI",
38
- url,
39
- error,
40
- });
41
- }
42
- }
43
- }
44
- reply.send("OK");
45
- },
46
- });
47
- }, {
48
- name: "devtools-plugin",
49
- dependencies: ["wss-plugin"],
50
- });
@@ -1,19 +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.faviconPlugin = void 0;
7
- const fastify_favicon_1 = __importDefault(require("fastify-favicon"));
8
- const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
9
- const node_path_1 = __importDefault(require("node:path"));
10
- const node_url_1 = require("node:url");
11
- // @ts-ignore
12
- const dirname = node_path_1.default.dirname((0, node_url_1.fileURLToPath)(import.meta.url));
13
- console.log("dirname", dirname);
14
- const pathToImgDir = node_path_1.default.join(dirname, "../../../../../assets");
15
- exports.faviconPlugin = (0, fastify_plugin_1.default)(async (instance) => {
16
- instance.register(fastify_favicon_1.default, { path: pathToImgDir });
17
- }, {
18
- name: "favicon-plugin",
19
- });
@@ -1,62 +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.multipartPlugin = void 0;
7
- const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
8
- const node_stream_1 = require("node:stream");
9
- /**
10
- * Implementation is based on:
11
- * https://github.com/facebook/metro/blob/347b1d7ed87995d7951aaa9fd597c04b06013dac/packages/metro/src/Server/MultipartResponse.js
12
- */
13
- const CRLF = "\r\n";
14
- const BOUNDARY = "3beqjf3apnqeu3h5jqorms4i";
15
- exports.multipartPlugin = (0, fastify_plugin_1.default)(async (instance) => {
16
- function asMultipart() {
17
- // We should check if is included in accept or if accept has multipart/* or */*,
18
- // but React Native will set accept to exactly `multipart/mixed`, so a simple check
19
- // will suffice.
20
- if (this.request.headers.accept !== "multipart/mixed") {
21
- return undefined;
22
- }
23
- const headers = {};
24
- const stream = new node_stream_1.PassThrough();
25
- this.code(200)
26
- .header("Content-Type", `multipart/mixed; boundary="${BOUNDARY}"`)
27
- .send(stream);
28
- function serializeHeaders(headers) {
29
- return Object.keys(headers)
30
- .map((key) => `${key}: ${headers[key]}`)
31
- .join(CRLF);
32
- }
33
- function writeChunk(headers, data, isLast) {
34
- let chunk = `${CRLF}--${BOUNDARY}${CRLF}`;
35
- if (headers) {
36
- chunk += serializeHeaders(headers) + CRLF + CRLF;
37
- }
38
- if (data) {
39
- chunk += data;
40
- }
41
- if (isLast) {
42
- chunk += `${CRLF}--${BOUNDARY}--${CRLF}`;
43
- }
44
- stream.write(chunk);
45
- }
46
- function setHeader(name, value) {
47
- headers[name] = value;
48
- }
49
- function end(data) {
50
- writeChunk(headers, data, true);
51
- stream.end();
52
- }
53
- return {
54
- writeChunk,
55
- setHeader,
56
- end,
57
- };
58
- }
59
- instance.decorateReply("asMultipart", asMultipart);
60
- }, {
61
- name: "multipart-plugin",
62
- });
@@ -1,28 +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.systracePlugin = void 0;
7
- const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
8
- const node_fs_1 = __importDefault(require("node:fs"));
9
- const cli_tools_1 = require("@react-native-community/cli-tools");
10
- exports.systracePlugin = (0, fastify_plugin_1.default)(async (instance) => {
11
- instance.post("/systrace", async (request, reply) => {
12
- cli_tools_1.logger.info("Dumping profile information...");
13
- const dumpName = `/tmp/dump_${Date.now()}.json`;
14
- // Get the raw body from the request
15
- const rawBody = await request.body;
16
- node_fs_1.default.writeFileSync(dumpName, JSON.stringify(rawBody));
17
- const response =
18
- // biome-ignore lint/style/useTemplate: <explanation>
19
- `Your profile was saved at:\n${dumpName}\n\n` +
20
- 'On Google Chrome navigate to chrome://tracing and then click on "load" ' +
21
- "to load and visualise your profile.\n\n" +
22
- "This message is also printed to your console by the packager so you can copy it :)";
23
- cli_tools_1.logger.info(response);
24
- return reply.send(response);
25
- });
26
- }, {
27
- name: "systrace-plugin",
28
- });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,19 +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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./wss.plugin"), exports);
18
- __exportStar(require("./web-socket-server"), exports);
19
- __exportStar(require("./types"), exports);
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebSocketApiServer = void 0;
4
- const web_socket_server_1 = require("../web-socket-server");
5
- /**
6
- * Class for creating a WebSocket server for API clients.
7
- * Useful to listening for compilation events and new logs.
8
- *
9
- * @category Development server
10
- */
11
- class WebSocketApiServer extends web_socket_server_1.WebSocketServer {
12
- clients = new Map();
13
- nextClientId = 0;
14
- /**
15
- * Create new instance of WebSocketApiServer and attach it to the given Fastify instance.
16
- * Any logging information, will be passed through standard `fastify.log` API.
17
- *
18
- * @param fastify Fastify instance to attach the WebSocket server to.
19
- */
20
- constructor(fastify) {
21
- super(fastify, "/api-console");
22
- }
23
- /**
24
- * Send message to all connected API clients.
25
- *
26
- * @param event Event string or object to send.
27
- */
28
- send(event) {
29
- if (this.clients.size === 0) {
30
- return;
31
- }
32
- const data = typeof event === "string" ? event : JSON.stringify(event);
33
- for (const [, socket] of this.clients.entries()) {
34
- try {
35
- socket.send(data);
36
- }
37
- catch (error) {
38
- this.fastify.log.error("Error sending message to API client", {
39
- error,
40
- });
41
- }
42
- }
43
- }
44
- /**
45
- * Process new WebSocket connection from client application.
46
- *
47
- * @param socket Incoming client's WebSocket connection.
48
- */
49
- onConnection(socket) {
50
- const clientId = `client#${this.nextClientId++}`;
51
- this.clients.set(clientId, socket);
52
- this.fastify.log.info("API client connected", {
53
- clientId,
54
- });
55
- this.clients.set(clientId, socket);
56
- const onClose = () => {
57
- this.fastify.log.info("API client disconnected", {
58
- clientId,
59
- });
60
- this.clients.delete(clientId);
61
- };
62
- socket.addEventListener("error", onClose);
63
- socket.addEventListener("close", onClose);
64
- }
65
- }
66
- exports.WebSocketApiServer = WebSocketApiServer;