@teardown/cli 1.2.30 → 1.2.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/dev/dev-server/dev-server.d.ts +1 -5
- package/dist/modules/dev/dev-server/dev-server.js +8 -36
- package/dist/modules/dev/dev-server/inspector/inspector.d.ts +1 -1
- package/dist/modules/dev/dev-server/inspector/inspector.js +5 -6
- package/dist/modules/dev/dev-server/plugins/favicon.plugin.js +3 -2
- package/dist/modules/dev/dev-server/plugins/wss/servers/web-socket-api.server.d.ts +6 -1
- package/package.json +1 -1
|
@@ -2,10 +2,10 @@ import { type FastifyInstance } from "fastify";
|
|
|
2
2
|
import type { TerminalReportableEvent } from "metro/src/lib/TerminalReporter";
|
|
3
3
|
import { KeyboardHandlerManager } from "../dev-menu/keyboard-handler";
|
|
4
4
|
import { TeardownTerminalReporter } from "../terminal/terminal.reporter";
|
|
5
|
+
import { Inspector } from "./inspector/inspector";
|
|
5
6
|
import { WebSocketApiServer } from "./plugins/wss/servers/web-socket-api.server";
|
|
6
7
|
import { WebSocketEventsServer } from "./plugins/wss/servers/web-socket-events.server";
|
|
7
8
|
import { WebSocketMessageServer } from "./plugins/wss/servers/web-socket-message.server";
|
|
8
|
-
import { Inspector } from "./inspector/inspector";
|
|
9
9
|
export type DevServerOptions = {
|
|
10
10
|
projectRoot: string;
|
|
11
11
|
host: string;
|
|
@@ -32,16 +32,12 @@ export declare class DevServer {
|
|
|
32
32
|
onInitializeDone(): void;
|
|
33
33
|
reportMetroEvent(event: TerminalReportableEvent): void;
|
|
34
34
|
private onBundleBuilt;
|
|
35
|
-
private onMessage;
|
|
36
35
|
private onClientConnected;
|
|
37
36
|
private loadMetroConfig;
|
|
38
37
|
private _metroConfig;
|
|
39
38
|
private getMetroConfig;
|
|
40
39
|
private registerPlugins;
|
|
41
40
|
private onSymbolicate;
|
|
42
|
-
private customInspectorMessageHandler;
|
|
43
|
-
private onDeviceMessage;
|
|
44
|
-
private onDebuggerMessage;
|
|
45
41
|
private registerHooks;
|
|
46
42
|
private registerRoutes;
|
|
47
43
|
initialize(): Promise<void>;
|
|
@@ -16,6 +16,7 @@ const metro_1 = __importDefault(require("metro"));
|
|
|
16
16
|
const node_stream_1 = require("node:stream");
|
|
17
17
|
const keyboard_handler_1 = require("../dev-menu/keyboard-handler");
|
|
18
18
|
const terminal_reporter_1 = require("../terminal/terminal.reporter");
|
|
19
|
+
const inspector_1 = require("./inspector/inspector");
|
|
19
20
|
const devtools_plugin_1 = require("./plugins/devtools.plugin");
|
|
20
21
|
const favicon_plugin_1 = require("./plugins/favicon.plugin");
|
|
21
22
|
const multipart_plugin_1 = require("./plugins/multipart.plugin");
|
|
@@ -25,7 +26,6 @@ const web_socket_api_server_1 = require("./plugins/wss/servers/web-socket-api.se
|
|
|
25
26
|
const web_socket_events_server_1 = require("./plugins/wss/servers/web-socket-events.server");
|
|
26
27
|
const web_socket_message_server_1 = require("./plugins/wss/servers/web-socket-message.server");
|
|
27
28
|
const sybmolicate_plugin_1 = require("./sybmolicate/sybmolicate.plugin");
|
|
28
|
-
const inspector_1 = require("./inspector/inspector");
|
|
29
29
|
class DevServer {
|
|
30
30
|
config;
|
|
31
31
|
terminalReporter;
|
|
@@ -67,7 +67,7 @@ class DevServer {
|
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
const log = JSON.parse(chunk.toString());
|
|
70
|
-
this.
|
|
70
|
+
this.apiServer.send(log);
|
|
71
71
|
callback();
|
|
72
72
|
}
|
|
73
73
|
getDevServerUrl() {
|
|
@@ -78,6 +78,10 @@ class DevServer {
|
|
|
78
78
|
this.keyboardHandler.initialize();
|
|
79
79
|
}
|
|
80
80
|
reportMetroEvent(event) {
|
|
81
|
+
this.apiServer.send({
|
|
82
|
+
type: "metro_event",
|
|
83
|
+
event,
|
|
84
|
+
});
|
|
81
85
|
switch (event.type) {
|
|
82
86
|
case "client_log":
|
|
83
87
|
this.eventsServer.broadcastEvent(event);
|
|
@@ -86,16 +90,7 @@ class DevServer {
|
|
|
86
90
|
}
|
|
87
91
|
onBundleBuilt(bundlePath) {
|
|
88
92
|
// console.log("onBundleBuilt", bundlePath);
|
|
89
|
-
this.messageServer.broadcast("reload");
|
|
90
|
-
}
|
|
91
|
-
onMessage(log) {
|
|
92
|
-
this.apiServer.send(log);
|
|
93
|
-
// console.log(log.msg, log.level);
|
|
94
|
-
// this.terminalReporter.update({
|
|
95
|
-
// type: "client_log",
|
|
96
|
-
// level: "info",
|
|
97
|
-
// data: [log.msg],
|
|
98
|
-
// });
|
|
93
|
+
// this.messageServer.broadcast("reload");
|
|
99
94
|
}
|
|
100
95
|
onClientConnected(platform, clientId) {
|
|
101
96
|
// this.messageServer.broadcast("reload", undefined, []);
|
|
@@ -196,36 +191,13 @@ class DevServer {
|
|
|
196
191
|
watchFolders: [this.config.projectRoot],
|
|
197
192
|
}));
|
|
198
193
|
this.instance.use(serverInstance.metroServer.processRequest);
|
|
199
|
-
this.instance.use(inspector.handleHttpRequest);
|
|
194
|
+
this.instance.use((req, resp, next) => this.inspector.handleHttpRequest(req, resp, next));
|
|
200
195
|
}
|
|
201
196
|
onSymbolicate(request, reply) {
|
|
202
197
|
const result = JSON.parse(request.rawBody);
|
|
203
198
|
const { codeFrame, stack } = result;
|
|
204
199
|
this.instance.log.info("onSymbolicate", { codeFrame, stack });
|
|
205
200
|
}
|
|
206
|
-
customInspectorMessageHandler(connection) {
|
|
207
|
-
this.instance.log.info("Creating custom inspector message handler", {
|
|
208
|
-
connection,
|
|
209
|
-
});
|
|
210
|
-
return {
|
|
211
|
-
handleDeviceMessage: (message) => this.onDeviceMessage(connection, message),
|
|
212
|
-
handleDebuggerMessage: (message) => this.onDebuggerMessage(connection, message),
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
onDeviceMessage(connection, message) {
|
|
216
|
-
this.instance.log.info("Device -> Debugger", {
|
|
217
|
-
message,
|
|
218
|
-
});
|
|
219
|
-
connection.debugger.sendMessage(message);
|
|
220
|
-
return true;
|
|
221
|
-
}
|
|
222
|
-
onDebuggerMessage(connection, message) {
|
|
223
|
-
this.instance.log.info("Debugger -> Device", {
|
|
224
|
-
message,
|
|
225
|
-
});
|
|
226
|
-
connection.device.sendMessage(message);
|
|
227
|
-
return true;
|
|
228
|
-
}
|
|
229
201
|
registerHooks() {
|
|
230
202
|
this.instance.log.info("Registering hooks");
|
|
231
203
|
this.instance = this.instance.addHook("onSend", async (request, reply, payload) => {
|
|
@@ -17,7 +17,7 @@ export declare class Inspector {
|
|
|
17
17
|
private readonly cdpAdapter?;
|
|
18
18
|
constructor(options: InspectorOptions);
|
|
19
19
|
getPageDescriptions(): PageDescription[];
|
|
20
|
-
handleHttpRequest
|
|
20
|
+
handleHttpRequest(req: IncomingMessage, res: ServerResponse, next: (error?: Error) => void): void;
|
|
21
21
|
createWebSocketServers(): Record<string, WebSocketServer>;
|
|
22
22
|
private createPageDescription;
|
|
23
23
|
private createDeviceWebSocketServer;
|
|
@@ -28,8 +28,6 @@ class Inspector {
|
|
|
28
28
|
this.serverBaseUrl = options.serverBaseUrl;
|
|
29
29
|
this.eventReporter = options.eventReporter;
|
|
30
30
|
this.cdpAdapter = options.cdpAdapter;
|
|
31
|
-
this.handleHttpRequest = this.handleHttpRequest.bind(this);
|
|
32
|
-
this.sendJsonResponse = this.sendJsonResponse.bind(this);
|
|
33
31
|
}
|
|
34
32
|
getPageDescriptions() {
|
|
35
33
|
const descriptions = [];
|
|
@@ -41,8 +39,9 @@ class Inspector {
|
|
|
41
39
|
}
|
|
42
40
|
return descriptions;
|
|
43
41
|
}
|
|
44
|
-
handleHttpRequest
|
|
42
|
+
handleHttpRequest(req, res, next) {
|
|
45
43
|
const pathname = new node_url_1.URL(req.url || "", "http://localhost").pathname;
|
|
44
|
+
console.log("handleHttpRequest", { pathname });
|
|
46
45
|
if (pathname === JSON_LIST_PATH || pathname === JSON_LIST_PATH_2) {
|
|
47
46
|
this.sendJsonResponse(res, this.getPageDescriptions());
|
|
48
47
|
}
|
|
@@ -55,7 +54,7 @@ class Inspector {
|
|
|
55
54
|
else {
|
|
56
55
|
next();
|
|
57
56
|
}
|
|
58
|
-
}
|
|
57
|
+
}
|
|
59
58
|
createWebSocketServers() {
|
|
60
59
|
return {
|
|
61
60
|
[WS_DEVICE_PATH]: this.createDeviceWebSocketServer(),
|
|
@@ -191,7 +190,7 @@ class Inspector {
|
|
|
191
190
|
resetHeartbeat();
|
|
192
191
|
});
|
|
193
192
|
}
|
|
194
|
-
sendJsonResponse
|
|
193
|
+
sendJsonResponse(res, data) {
|
|
195
194
|
const json = JSON.stringify(data, null, 2);
|
|
196
195
|
res.writeHead(200, {
|
|
197
196
|
"Content-Type": "application/json; charset=UTF-8",
|
|
@@ -200,6 +199,6 @@ class Inspector {
|
|
|
200
199
|
Connection: "close",
|
|
201
200
|
});
|
|
202
201
|
res.end(json);
|
|
203
|
-
}
|
|
202
|
+
}
|
|
204
203
|
}
|
|
205
204
|
exports.Inspector = Inspector;
|
|
@@ -4,15 +4,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.faviconPlugin = void 0;
|
|
7
|
+
const fastify_favicon_1 = __importDefault(require("fastify-favicon"));
|
|
7
8
|
const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
|
|
8
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
10
|
const node_url_1 = require("node:url");
|
|
10
11
|
// @ts-ignore
|
|
11
12
|
const dirname = node_path_1.default.dirname((0, node_url_1.fileURLToPath)(import.meta.url));
|
|
13
|
+
console.log("dirname", dirname);
|
|
12
14
|
const pathToImgDir = node_path_1.default.join(dirname, "../img");
|
|
13
15
|
exports.faviconPlugin = (0, fastify_plugin_1.default)(async (instance) => {
|
|
14
|
-
|
|
15
|
-
// instance.register(fastifyFavicon, { path: pathToImgDir });
|
|
16
|
+
instance.register(fastify_favicon_1.default, { path: pathToImgDir });
|
|
16
17
|
}, {
|
|
17
18
|
name: "favicon-plugin",
|
|
18
19
|
});
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { FastifyInstance } from "fastify";
|
|
2
|
+
import type { TerminalReportableEvent } from "metro/src/lib/TerminalReporter";
|
|
2
3
|
import type WebSocket from "ws";
|
|
3
4
|
import { WebSocketServer } from "../web-socket-server";
|
|
5
|
+
export type WebSocketApiEvent = {
|
|
6
|
+
type: "metro_event";
|
|
7
|
+
event: TerminalReportableEvent;
|
|
8
|
+
};
|
|
4
9
|
/**
|
|
5
10
|
* Class for creating a WebSocket server for API clients.
|
|
6
11
|
* Useful to listening for compilation events and new logs.
|
|
@@ -22,7 +27,7 @@ export declare class WebSocketApiServer extends WebSocketServer {
|
|
|
22
27
|
*
|
|
23
28
|
* @param event Event string or object to send.
|
|
24
29
|
*/
|
|
25
|
-
send(event: unknown): void;
|
|
30
|
+
send(event: unknown | WebSocketApiEvent): void;
|
|
26
31
|
/**
|
|
27
32
|
* Process new WebSocket connection from client application.
|
|
28
33
|
*
|