@oxog/react-check 1.0.2 → 1.0.3
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/browser-inject.global.js +3 -3
- package/dist/cli.js +735 -53
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +47 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +47 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import { access, readFile, writeFile, mkdir, stat, rm, readdir } from 'fs/promises';
|
|
3
3
|
import { constants } from 'fs';
|
|
4
4
|
import { dirname, resolve, join, extname, basename } from 'path';
|
|
5
|
+
import { createServer } from 'http';
|
|
6
|
+
import { createHash } from 'crypto';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
5
8
|
|
|
6
9
|
var __defProp = Object.defineProperty;
|
|
7
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -2321,13 +2324,13 @@ var EventEmitter = class {
|
|
|
2321
2324
|
* @returns Promise that resolves with the event data
|
|
2322
2325
|
*/
|
|
2323
2326
|
waitFor(event, timeout) {
|
|
2324
|
-
return new Promise((
|
|
2327
|
+
return new Promise((resolve3, reject) => {
|
|
2325
2328
|
let timeoutId;
|
|
2326
2329
|
const listener = (data) => {
|
|
2327
2330
|
if (timeoutId) {
|
|
2328
2331
|
clearTimeout(timeoutId);
|
|
2329
2332
|
}
|
|
2330
|
-
|
|
2333
|
+
resolve3(data);
|
|
2331
2334
|
};
|
|
2332
2335
|
this.once(event, listener);
|
|
2333
2336
|
if (timeout !== void 0 && timeout > 0) {
|
|
@@ -4711,13 +4714,13 @@ var InputHandler = class _InputHandler extends EventEmitter {
|
|
|
4711
4714
|
* @returns Promise that resolves when key is pressed
|
|
4712
4715
|
*/
|
|
4713
4716
|
waitForKey(key, timeout) {
|
|
4714
|
-
return new Promise((
|
|
4717
|
+
return new Promise((resolve3, reject) => {
|
|
4715
4718
|
let timeoutId;
|
|
4716
4719
|
const handler = (event) => {
|
|
4717
4720
|
if (_InputHandler.matches(event, key)) {
|
|
4718
4721
|
if (timeoutId) clearTimeout(timeoutId);
|
|
4719
4722
|
this.off("key", handler);
|
|
4720
|
-
|
|
4723
|
+
resolve3(event);
|
|
4721
4724
|
}
|
|
4722
4725
|
};
|
|
4723
4726
|
this.on("key", handler);
|
|
@@ -4735,12 +4738,12 @@ var InputHandler = class _InputHandler extends EventEmitter {
|
|
|
4735
4738
|
* @returns Promise that resolves with the pressed key
|
|
4736
4739
|
*/
|
|
4737
4740
|
waitForAnyKey(timeout) {
|
|
4738
|
-
return new Promise((
|
|
4741
|
+
return new Promise((resolve3, reject) => {
|
|
4739
4742
|
let timeoutId;
|
|
4740
4743
|
const handler = (event) => {
|
|
4741
4744
|
if (timeoutId) clearTimeout(timeoutId);
|
|
4742
4745
|
this.off("key", handler);
|
|
4743
|
-
|
|
4746
|
+
resolve3(event);
|
|
4744
4747
|
};
|
|
4745
4748
|
this.once("key", handler);
|
|
4746
4749
|
if (timeout) {
|
|
@@ -4757,12 +4760,12 @@ var InputHandler = class _InputHandler extends EventEmitter {
|
|
|
4757
4760
|
* @returns Promise that resolves with the input line
|
|
4758
4761
|
*/
|
|
4759
4762
|
waitForLine(timeout) {
|
|
4760
|
-
return new Promise((
|
|
4763
|
+
return new Promise((resolve3, reject) => {
|
|
4761
4764
|
let timeoutId;
|
|
4762
4765
|
const handler = (line) => {
|
|
4763
4766
|
if (timeoutId) clearTimeout(timeoutId);
|
|
4764
4767
|
this.off("line", handler);
|
|
4765
|
-
|
|
4768
|
+
resolve3(line);
|
|
4766
4769
|
};
|
|
4767
4770
|
this.once("line", handler);
|
|
4768
4771
|
if (timeout) {
|
|
@@ -5172,7 +5175,570 @@ var TUI = class extends EventEmitter {
|
|
|
5172
5175
|
|
|
5173
5176
|
// src/cli/commands/scan.ts
|
|
5174
5177
|
init_format();
|
|
5175
|
-
var
|
|
5178
|
+
var OPCODE = {
|
|
5179
|
+
TEXT: 1,
|
|
5180
|
+
BINARY: 2,
|
|
5181
|
+
CLOSE: 8,
|
|
5182
|
+
PING: 9,
|
|
5183
|
+
PONG: 10
|
|
5184
|
+
};
|
|
5185
|
+
var WS_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
5186
|
+
var WebSocketClient = class extends EventEmitter {
|
|
5187
|
+
/** Socket connection */
|
|
5188
|
+
socket;
|
|
5189
|
+
/** Whether connection is open */
|
|
5190
|
+
isOpen = true;
|
|
5191
|
+
/** Partial frame buffer */
|
|
5192
|
+
frameBuffer = Buffer.alloc(0);
|
|
5193
|
+
/**
|
|
5194
|
+
* Create a new WebSocket client
|
|
5195
|
+
* @param socket - TCP socket
|
|
5196
|
+
*/
|
|
5197
|
+
constructor(socket) {
|
|
5198
|
+
super();
|
|
5199
|
+
this.socket = socket;
|
|
5200
|
+
this.setupSocketHandlers();
|
|
5201
|
+
}
|
|
5202
|
+
/**
|
|
5203
|
+
* Set up socket event handlers
|
|
5204
|
+
*/
|
|
5205
|
+
setupSocketHandlers() {
|
|
5206
|
+
this.socket.on("data", (data) => {
|
|
5207
|
+
this.frameBuffer = Buffer.concat([this.frameBuffer, data]);
|
|
5208
|
+
this.processFrames();
|
|
5209
|
+
});
|
|
5210
|
+
this.socket.on("close", () => {
|
|
5211
|
+
this.isOpen = false;
|
|
5212
|
+
this.emit("close", { code: 1e3, reason: "Connection closed" });
|
|
5213
|
+
});
|
|
5214
|
+
this.socket.on("error", (error) => {
|
|
5215
|
+
this.emit("error", error);
|
|
5216
|
+
});
|
|
5217
|
+
}
|
|
5218
|
+
/**
|
|
5219
|
+
* Process received frames
|
|
5220
|
+
*/
|
|
5221
|
+
processFrames() {
|
|
5222
|
+
while (this.frameBuffer.length >= 2) {
|
|
5223
|
+
const frame = this.parseFrame();
|
|
5224
|
+
if (!frame) break;
|
|
5225
|
+
switch (frame.opcode) {
|
|
5226
|
+
case OPCODE.TEXT:
|
|
5227
|
+
this.emit("message", frame.payload.toString("utf8"));
|
|
5228
|
+
break;
|
|
5229
|
+
case OPCODE.BINARY:
|
|
5230
|
+
this.emit("binary", frame.payload);
|
|
5231
|
+
break;
|
|
5232
|
+
case OPCODE.CLOSE:
|
|
5233
|
+
this.handleClose(frame.payload);
|
|
5234
|
+
break;
|
|
5235
|
+
case OPCODE.PING:
|
|
5236
|
+
this.sendPong(frame.payload);
|
|
5237
|
+
break;
|
|
5238
|
+
case OPCODE.PONG:
|
|
5239
|
+
this.emit("pong", void 0);
|
|
5240
|
+
break;
|
|
5241
|
+
}
|
|
5242
|
+
}
|
|
5243
|
+
}
|
|
5244
|
+
/**
|
|
5245
|
+
* Parse a WebSocket frame
|
|
5246
|
+
* @returns Parsed frame or null if incomplete
|
|
5247
|
+
*/
|
|
5248
|
+
parseFrame() {
|
|
5249
|
+
if (this.frameBuffer.length < 2) return null;
|
|
5250
|
+
const firstByte = this.frameBuffer[0];
|
|
5251
|
+
const secondByte = this.frameBuffer[1];
|
|
5252
|
+
const opcode = firstByte & 15;
|
|
5253
|
+
const masked = (secondByte & 128) !== 0;
|
|
5254
|
+
let payloadLength = secondByte & 127;
|
|
5255
|
+
let offset = 2;
|
|
5256
|
+
if (payloadLength === 126) {
|
|
5257
|
+
if (this.frameBuffer.length < 4) return null;
|
|
5258
|
+
payloadLength = this.frameBuffer.readUInt16BE(2);
|
|
5259
|
+
offset = 4;
|
|
5260
|
+
} else if (payloadLength === 127) {
|
|
5261
|
+
if (this.frameBuffer.length < 10) return null;
|
|
5262
|
+
payloadLength = this.frameBuffer.readUInt32BE(6);
|
|
5263
|
+
offset = 10;
|
|
5264
|
+
}
|
|
5265
|
+
let maskingKey = null;
|
|
5266
|
+
if (masked) {
|
|
5267
|
+
if (this.frameBuffer.length < offset + 4) return null;
|
|
5268
|
+
maskingKey = this.frameBuffer.subarray(offset, offset + 4);
|
|
5269
|
+
offset += 4;
|
|
5270
|
+
}
|
|
5271
|
+
if (this.frameBuffer.length < offset + payloadLength) return null;
|
|
5272
|
+
let payload = this.frameBuffer.subarray(offset, offset + payloadLength);
|
|
5273
|
+
if (masked && maskingKey) {
|
|
5274
|
+
payload = Buffer.from(payload);
|
|
5275
|
+
for (let i = 0; i < payload.length; i++) {
|
|
5276
|
+
payload[i] = payload[i] ^ maskingKey[i % 4];
|
|
5277
|
+
}
|
|
5278
|
+
}
|
|
5279
|
+
this.frameBuffer = this.frameBuffer.subarray(offset + payloadLength);
|
|
5280
|
+
return { opcode, payload };
|
|
5281
|
+
}
|
|
5282
|
+
/**
|
|
5283
|
+
* Handle close frame
|
|
5284
|
+
* @param payload - Close frame payload
|
|
5285
|
+
*/
|
|
5286
|
+
handleClose(payload) {
|
|
5287
|
+
let code = 1e3;
|
|
5288
|
+
let reason = "";
|
|
5289
|
+
if (payload.length >= 2) {
|
|
5290
|
+
code = payload.readUInt16BE(0);
|
|
5291
|
+
reason = payload.subarray(2).toString("utf8");
|
|
5292
|
+
}
|
|
5293
|
+
this.close(code, reason);
|
|
5294
|
+
this.emit("close", { code, reason });
|
|
5295
|
+
}
|
|
5296
|
+
/**
|
|
5297
|
+
* Send a pong frame
|
|
5298
|
+
* @param payload - Pong payload (echo of ping)
|
|
5299
|
+
*/
|
|
5300
|
+
sendPong(payload) {
|
|
5301
|
+
this.sendFrame(OPCODE.PONG, payload);
|
|
5302
|
+
}
|
|
5303
|
+
/**
|
|
5304
|
+
* Send a WebSocket frame
|
|
5305
|
+
* @param opcode - Frame opcode
|
|
5306
|
+
* @param payload - Frame payload
|
|
5307
|
+
*/
|
|
5308
|
+
sendFrame(opcode, payload) {
|
|
5309
|
+
if (!this.isOpen) return;
|
|
5310
|
+
const data = typeof payload === "string" ? Buffer.from(payload, "utf8") : payload;
|
|
5311
|
+
const length = data.length;
|
|
5312
|
+
let header;
|
|
5313
|
+
if (length < 126) {
|
|
5314
|
+
header = Buffer.alloc(2);
|
|
5315
|
+
header[0] = 128 | opcode;
|
|
5316
|
+
header[1] = length;
|
|
5317
|
+
} else if (length < 65536) {
|
|
5318
|
+
header = Buffer.alloc(4);
|
|
5319
|
+
header[0] = 128 | opcode;
|
|
5320
|
+
header[1] = 126;
|
|
5321
|
+
header.writeUInt16BE(length, 2);
|
|
5322
|
+
} else {
|
|
5323
|
+
header = Buffer.alloc(10);
|
|
5324
|
+
header[0] = 128 | opcode;
|
|
5325
|
+
header[1] = 127;
|
|
5326
|
+
header.writeUInt32BE(0, 2);
|
|
5327
|
+
header.writeUInt32BE(length, 6);
|
|
5328
|
+
}
|
|
5329
|
+
this.socket.write(Buffer.concat([header, data]));
|
|
5330
|
+
}
|
|
5331
|
+
/**
|
|
5332
|
+
* Send a text message
|
|
5333
|
+
* @param message - Message to send
|
|
5334
|
+
*/
|
|
5335
|
+
send(message) {
|
|
5336
|
+
this.sendFrame(OPCODE.TEXT, message);
|
|
5337
|
+
}
|
|
5338
|
+
/**
|
|
5339
|
+
* Send a binary message
|
|
5340
|
+
* @param data - Binary data to send
|
|
5341
|
+
*/
|
|
5342
|
+
sendBinary(data) {
|
|
5343
|
+
this.sendFrame(OPCODE.BINARY, data);
|
|
5344
|
+
}
|
|
5345
|
+
/**
|
|
5346
|
+
* Send a ping frame
|
|
5347
|
+
* @param payload - Optional ping payload
|
|
5348
|
+
*/
|
|
5349
|
+
ping(payload = Buffer.alloc(0)) {
|
|
5350
|
+
this.sendFrame(OPCODE.PING, payload);
|
|
5351
|
+
}
|
|
5352
|
+
/**
|
|
5353
|
+
* Close the connection
|
|
5354
|
+
* @param code - Close code
|
|
5355
|
+
* @param reason - Close reason
|
|
5356
|
+
*/
|
|
5357
|
+
close(code = 1e3, reason = "") {
|
|
5358
|
+
if (!this.isOpen) return;
|
|
5359
|
+
const reasonBuffer = Buffer.from(reason, "utf8");
|
|
5360
|
+
const payload = Buffer.alloc(2 + reasonBuffer.length);
|
|
5361
|
+
payload.writeUInt16BE(code, 0);
|
|
5362
|
+
reasonBuffer.copy(payload, 2);
|
|
5363
|
+
this.sendFrame(OPCODE.CLOSE, payload);
|
|
5364
|
+
this.isOpen = false;
|
|
5365
|
+
setTimeout(() => {
|
|
5366
|
+
this.socket.end();
|
|
5367
|
+
}, 100);
|
|
5368
|
+
}
|
|
5369
|
+
/**
|
|
5370
|
+
* Check if connection is open
|
|
5371
|
+
* @returns true if open
|
|
5372
|
+
*/
|
|
5373
|
+
isConnected() {
|
|
5374
|
+
return this.isOpen;
|
|
5375
|
+
}
|
|
5376
|
+
};
|
|
5377
|
+
var WebSocketServer = class extends EventEmitter {
|
|
5378
|
+
/** HTTP server */
|
|
5379
|
+
server;
|
|
5380
|
+
/** Connected clients */
|
|
5381
|
+
clients = /* @__PURE__ */ new Set();
|
|
5382
|
+
/** Server port */
|
|
5383
|
+
port;
|
|
5384
|
+
/**
|
|
5385
|
+
* Create a new WebSocket server
|
|
5386
|
+
* @param port - Port to listen on
|
|
5387
|
+
*/
|
|
5388
|
+
constructor(port) {
|
|
5389
|
+
super();
|
|
5390
|
+
this.port = port;
|
|
5391
|
+
this.server = createServer();
|
|
5392
|
+
this.setupServer();
|
|
5393
|
+
}
|
|
5394
|
+
/**
|
|
5395
|
+
* Set up HTTP server for WebSocket upgrade
|
|
5396
|
+
*/
|
|
5397
|
+
setupServer() {
|
|
5398
|
+
this.server.on("upgrade", (req, socket, head) => {
|
|
5399
|
+
this.handleUpgrade(req, socket, head);
|
|
5400
|
+
});
|
|
5401
|
+
this.server.on("error", (error) => {
|
|
5402
|
+
this.emit("error", error);
|
|
5403
|
+
});
|
|
5404
|
+
this.server.on("close", () => {
|
|
5405
|
+
this.emit("close", void 0);
|
|
5406
|
+
});
|
|
5407
|
+
}
|
|
5408
|
+
/**
|
|
5409
|
+
* Handle WebSocket upgrade request
|
|
5410
|
+
* @param req - HTTP request
|
|
5411
|
+
* @param socket - TCP socket
|
|
5412
|
+
* @param head - Upgrade head
|
|
5413
|
+
*/
|
|
5414
|
+
handleUpgrade(req, socket, head) {
|
|
5415
|
+
const upgrade = req.headers["upgrade"];
|
|
5416
|
+
if (!upgrade || upgrade.toLowerCase() !== "websocket") {
|
|
5417
|
+
socket.destroy();
|
|
5418
|
+
return;
|
|
5419
|
+
}
|
|
5420
|
+
const key = req.headers["sec-websocket-key"];
|
|
5421
|
+
if (!key) {
|
|
5422
|
+
socket.destroy();
|
|
5423
|
+
return;
|
|
5424
|
+
}
|
|
5425
|
+
const acceptKey = this.generateAcceptKey(key);
|
|
5426
|
+
const response = [
|
|
5427
|
+
"HTTP/1.1 101 Switching Protocols",
|
|
5428
|
+
"Upgrade: websocket",
|
|
5429
|
+
"Connection: Upgrade",
|
|
5430
|
+
`Sec-WebSocket-Accept: ${acceptKey}`,
|
|
5431
|
+
"",
|
|
5432
|
+
""
|
|
5433
|
+
].join("\r\n");
|
|
5434
|
+
socket.write(response);
|
|
5435
|
+
if (head.length > 0) {
|
|
5436
|
+
socket.unshift(head);
|
|
5437
|
+
}
|
|
5438
|
+
const client = new WebSocketClient(socket);
|
|
5439
|
+
this.clients.add(client);
|
|
5440
|
+
client.on("close", () => {
|
|
5441
|
+
this.clients.delete(client);
|
|
5442
|
+
});
|
|
5443
|
+
this.emit("connection", client);
|
|
5444
|
+
}
|
|
5445
|
+
/**
|
|
5446
|
+
* Generate WebSocket accept key
|
|
5447
|
+
* @param key - Client key
|
|
5448
|
+
* @returns Accept key
|
|
5449
|
+
*/
|
|
5450
|
+
generateAcceptKey(key) {
|
|
5451
|
+
return createHash("sha1").update(key + WS_GUID).digest("base64");
|
|
5452
|
+
}
|
|
5453
|
+
/**
|
|
5454
|
+
* Start the server
|
|
5455
|
+
*/
|
|
5456
|
+
start() {
|
|
5457
|
+
return new Promise((resolve3, reject) => {
|
|
5458
|
+
this.server.once("error", reject);
|
|
5459
|
+
this.server.listen(this.port, () => {
|
|
5460
|
+
this.server.removeListener("error", reject);
|
|
5461
|
+
this.emit("listening", { port: this.port });
|
|
5462
|
+
resolve3();
|
|
5463
|
+
});
|
|
5464
|
+
});
|
|
5465
|
+
}
|
|
5466
|
+
/**
|
|
5467
|
+
* Stop the server
|
|
5468
|
+
*/
|
|
5469
|
+
stop() {
|
|
5470
|
+
return new Promise((resolve3) => {
|
|
5471
|
+
for (const client of this.clients) {
|
|
5472
|
+
client.close(1001, "Server shutting down");
|
|
5473
|
+
}
|
|
5474
|
+
this.clients.clear();
|
|
5475
|
+
this.server.close(() => {
|
|
5476
|
+
resolve3();
|
|
5477
|
+
});
|
|
5478
|
+
});
|
|
5479
|
+
}
|
|
5480
|
+
/**
|
|
5481
|
+
* Broadcast message to all clients
|
|
5482
|
+
* @param message - Message to broadcast
|
|
5483
|
+
*/
|
|
5484
|
+
broadcast(message) {
|
|
5485
|
+
for (const client of this.clients) {
|
|
5486
|
+
if (client.isConnected()) {
|
|
5487
|
+
client.send(message);
|
|
5488
|
+
}
|
|
5489
|
+
}
|
|
5490
|
+
}
|
|
5491
|
+
/**
|
|
5492
|
+
* Broadcast CLI message to all clients
|
|
5493
|
+
* @param message - CLI message to broadcast
|
|
5494
|
+
*/
|
|
5495
|
+
broadcastCLIMessage(message) {
|
|
5496
|
+
this.broadcast(JSON.stringify(message));
|
|
5497
|
+
}
|
|
5498
|
+
/**
|
|
5499
|
+
* Get connected client count
|
|
5500
|
+
* @returns Number of connected clients
|
|
5501
|
+
*/
|
|
5502
|
+
getClientCount() {
|
|
5503
|
+
return this.clients.size;
|
|
5504
|
+
}
|
|
5505
|
+
/**
|
|
5506
|
+
* Get all connected clients
|
|
5507
|
+
* @returns Array of connected clients
|
|
5508
|
+
*/
|
|
5509
|
+
getClients() {
|
|
5510
|
+
return Array.from(this.clients);
|
|
5511
|
+
}
|
|
5512
|
+
};
|
|
5513
|
+
function handleBrowserMessages(client, handler) {
|
|
5514
|
+
client.on("message", (data) => {
|
|
5515
|
+
try {
|
|
5516
|
+
const message = JSON.parse(data);
|
|
5517
|
+
handler(message);
|
|
5518
|
+
} catch (error) {
|
|
5519
|
+
}
|
|
5520
|
+
});
|
|
5521
|
+
}
|
|
5522
|
+
|
|
5523
|
+
// src/server/browser.ts
|
|
5524
|
+
var logger3 = new Logger({ prefix: "browser", level: 0 /* DEBUG */ });
|
|
5525
|
+
var BrowserLauncher = class extends EventEmitter {
|
|
5526
|
+
/** Puppeteer browser instance */
|
|
5527
|
+
browser = null;
|
|
5528
|
+
/** Active page */
|
|
5529
|
+
page = null;
|
|
5530
|
+
/** Launch options */
|
|
5531
|
+
options;
|
|
5532
|
+
/** Injection script */
|
|
5533
|
+
injectionScript = null;
|
|
5534
|
+
/**
|
|
5535
|
+
* Create a new browser launcher
|
|
5536
|
+
* @param options - Launch options
|
|
5537
|
+
*/
|
|
5538
|
+
constructor(options) {
|
|
5539
|
+
super();
|
|
5540
|
+
this.options = {
|
|
5541
|
+
url: options.url,
|
|
5542
|
+
headless: options.headless ?? false,
|
|
5543
|
+
width: options.width ?? 1280,
|
|
5544
|
+
height: options.height ?? 800,
|
|
5545
|
+
wsPort: options.wsPort ?? 3099,
|
|
5546
|
+
args: options.args ?? [],
|
|
5547
|
+
slowMo: options.slowMo ?? 0,
|
|
5548
|
+
timeout: options.timeout ?? 3e4
|
|
5549
|
+
};
|
|
5550
|
+
}
|
|
5551
|
+
/**
|
|
5552
|
+
* Set the injection script
|
|
5553
|
+
* @param script - Script to inject before page loads
|
|
5554
|
+
*/
|
|
5555
|
+
setInjectionScript(script) {
|
|
5556
|
+
this.injectionScript = script;
|
|
5557
|
+
}
|
|
5558
|
+
/**
|
|
5559
|
+
* Launch the browser
|
|
5560
|
+
*/
|
|
5561
|
+
async launch() {
|
|
5562
|
+
try {
|
|
5563
|
+
const puppeteer = await import('puppeteer');
|
|
5564
|
+
const args = [
|
|
5565
|
+
"--no-sandbox",
|
|
5566
|
+
"--disable-setuid-sandbox",
|
|
5567
|
+
"--disable-dev-shm-usage",
|
|
5568
|
+
"--disable-gpu",
|
|
5569
|
+
`--window-size=${this.options.width},${this.options.height}`,
|
|
5570
|
+
...this.options.args
|
|
5571
|
+
];
|
|
5572
|
+
this.browser = await puppeteer.default.launch({
|
|
5573
|
+
headless: this.options.headless,
|
|
5574
|
+
args,
|
|
5575
|
+
slowMo: this.options.slowMo,
|
|
5576
|
+
defaultViewport: {
|
|
5577
|
+
width: this.options.width,
|
|
5578
|
+
height: this.options.height
|
|
5579
|
+
}
|
|
5580
|
+
});
|
|
5581
|
+
const pages = await this.browser.pages();
|
|
5582
|
+
this.page = pages[0] ?? await this.browser.newPage();
|
|
5583
|
+
this.setupPageHandlers();
|
|
5584
|
+
if (this.injectionScript) {
|
|
5585
|
+
await this.page.evaluateOnNewDocument(this.injectionScript);
|
|
5586
|
+
}
|
|
5587
|
+
const wsPort = this.options.wsPort;
|
|
5588
|
+
await this.page.evaluateOnNewDocument(`
|
|
5589
|
+
window.__REACTCHECK_PORT__ = ${wsPort};
|
|
5590
|
+
window.__REACTCHECK_INJECTED__ = true;
|
|
5591
|
+
`);
|
|
5592
|
+
this.emit("launched", void 0);
|
|
5593
|
+
logger3.info("Browser launched");
|
|
5594
|
+
await this.navigate(this.options.url);
|
|
5595
|
+
} catch (error) {
|
|
5596
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
5597
|
+
this.emit("error", err);
|
|
5598
|
+
throw err;
|
|
5599
|
+
}
|
|
5600
|
+
}
|
|
5601
|
+
/**
|
|
5602
|
+
* Set up page event handlers
|
|
5603
|
+
*/
|
|
5604
|
+
setupPageHandlers() {
|
|
5605
|
+
if (!this.page) return;
|
|
5606
|
+
this.page.on("console", (msg) => {
|
|
5607
|
+
this.emit("console", {
|
|
5608
|
+
type: msg.type(),
|
|
5609
|
+
text: msg.text()
|
|
5610
|
+
});
|
|
5611
|
+
});
|
|
5612
|
+
this.page.on("pageerror", (error) => {
|
|
5613
|
+
this.emit("error", error);
|
|
5614
|
+
});
|
|
5615
|
+
this.page.on("framenavigated", (frame) => {
|
|
5616
|
+
if (frame === this.page?.mainFrame()) {
|
|
5617
|
+
this.emit("navigated", { url: frame.url() });
|
|
5618
|
+
}
|
|
5619
|
+
});
|
|
5620
|
+
this.page.on("load", () => {
|
|
5621
|
+
this.emit("loaded", void 0);
|
|
5622
|
+
});
|
|
5623
|
+
}
|
|
5624
|
+
/**
|
|
5625
|
+
* Navigate to a URL
|
|
5626
|
+
* @param url - URL to navigate to
|
|
5627
|
+
*/
|
|
5628
|
+
async navigate(url) {
|
|
5629
|
+
if (!this.page) {
|
|
5630
|
+
throw new Error("Browser not launched");
|
|
5631
|
+
}
|
|
5632
|
+
try {
|
|
5633
|
+
await this.page.goto(url, {
|
|
5634
|
+
waitUntil: "networkidle2",
|
|
5635
|
+
timeout: this.options.timeout
|
|
5636
|
+
});
|
|
5637
|
+
this.emit("navigated", { url });
|
|
5638
|
+
logger3.info(`Navigated to ${url}`);
|
|
5639
|
+
} catch (error) {
|
|
5640
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
5641
|
+
this.emit("error", err);
|
|
5642
|
+
throw err;
|
|
5643
|
+
}
|
|
5644
|
+
}
|
|
5645
|
+
/**
|
|
5646
|
+
* Execute script in page context
|
|
5647
|
+
* @param script - Script to execute
|
|
5648
|
+
* @returns Script result
|
|
5649
|
+
*/
|
|
5650
|
+
async evaluate(script) {
|
|
5651
|
+
if (!this.page) {
|
|
5652
|
+
throw new Error("Browser not launched");
|
|
5653
|
+
}
|
|
5654
|
+
return this.page.evaluate(script);
|
|
5655
|
+
}
|
|
5656
|
+
/**
|
|
5657
|
+
* Wait for selector
|
|
5658
|
+
* @param selector - CSS selector
|
|
5659
|
+
* @param timeout - Timeout in ms
|
|
5660
|
+
*/
|
|
5661
|
+
async waitForSelector(selector, timeout) {
|
|
5662
|
+
if (!this.page) {
|
|
5663
|
+
throw new Error("Browser not launched");
|
|
5664
|
+
}
|
|
5665
|
+
await this.page.waitForSelector(selector, {
|
|
5666
|
+
timeout: timeout ?? this.options.timeout
|
|
5667
|
+
});
|
|
5668
|
+
}
|
|
5669
|
+
/**
|
|
5670
|
+
* Take a screenshot
|
|
5671
|
+
* @param path - File path to save screenshot
|
|
5672
|
+
*/
|
|
5673
|
+
async screenshot(path) {
|
|
5674
|
+
if (!this.page) {
|
|
5675
|
+
throw new Error("Browser not launched");
|
|
5676
|
+
}
|
|
5677
|
+
await this.page.screenshot({ path, fullPage: true });
|
|
5678
|
+
logger3.info(`Screenshot saved to ${path}`);
|
|
5679
|
+
}
|
|
5680
|
+
/**
|
|
5681
|
+
* Reload the page
|
|
5682
|
+
*/
|
|
5683
|
+
async reload() {
|
|
5684
|
+
if (!this.page) {
|
|
5685
|
+
throw new Error("Browser not launched");
|
|
5686
|
+
}
|
|
5687
|
+
await this.page.reload({ waitUntil: "networkidle2" });
|
|
5688
|
+
}
|
|
5689
|
+
/**
|
|
5690
|
+
* Get current URL
|
|
5691
|
+
* @returns Current page URL
|
|
5692
|
+
*/
|
|
5693
|
+
getUrl() {
|
|
5694
|
+
return this.page?.url() ?? null;
|
|
5695
|
+
}
|
|
5696
|
+
/**
|
|
5697
|
+
* Close the browser
|
|
5698
|
+
*/
|
|
5699
|
+
async close() {
|
|
5700
|
+
if (this.browser) {
|
|
5701
|
+
await this.browser.close();
|
|
5702
|
+
this.browser = null;
|
|
5703
|
+
this.page = null;
|
|
5704
|
+
this.emit("closed", void 0);
|
|
5705
|
+
logger3.info("Browser closed");
|
|
5706
|
+
}
|
|
5707
|
+
}
|
|
5708
|
+
/**
|
|
5709
|
+
* Check if browser is open
|
|
5710
|
+
* @returns true if browser is open
|
|
5711
|
+
*/
|
|
5712
|
+
isOpen() {
|
|
5713
|
+
return this.browser !== null && this.browser.connected;
|
|
5714
|
+
}
|
|
5715
|
+
/**
|
|
5716
|
+
* Get the page instance (for advanced usage)
|
|
5717
|
+
* @returns Puppeteer page or null
|
|
5718
|
+
*/
|
|
5719
|
+
getPage() {
|
|
5720
|
+
return this.page;
|
|
5721
|
+
}
|
|
5722
|
+
/**
|
|
5723
|
+
* Get the browser instance (for advanced usage)
|
|
5724
|
+
* @returns Puppeteer browser or null
|
|
5725
|
+
*/
|
|
5726
|
+
getBrowser() {
|
|
5727
|
+
return this.browser;
|
|
5728
|
+
}
|
|
5729
|
+
};
|
|
5730
|
+
async function isPuppeteerAvailable() {
|
|
5731
|
+
try {
|
|
5732
|
+
await import('puppeteer');
|
|
5733
|
+
return true;
|
|
5734
|
+
} catch {
|
|
5735
|
+
return false;
|
|
5736
|
+
}
|
|
5737
|
+
}
|
|
5738
|
+
|
|
5739
|
+
// src/cli/commands/scan.ts
|
|
5740
|
+
init_fs();
|
|
5741
|
+
var logger4 = new Logger({ prefix: "scan", level: 1 /* INFO */ });
|
|
5176
5742
|
function parseScanOptions(args) {
|
|
5177
5743
|
return {
|
|
5178
5744
|
target: normalizeTarget(args.target ?? "localhost:3000"),
|
|
@@ -5194,11 +5760,48 @@ function parseScanOptions(args) {
|
|
|
5194
5760
|
configPath: getStringFlag(args, "config")
|
|
5195
5761
|
};
|
|
5196
5762
|
}
|
|
5763
|
+
async function getInjectionScript(wsPort) {
|
|
5764
|
+
try {
|
|
5765
|
+
const currentFile = fileURLToPath(import.meta.url);
|
|
5766
|
+
const currentDir = dirname(currentFile);
|
|
5767
|
+
const scriptPath = resolve(currentDir, "browser-inject.global.js");
|
|
5768
|
+
logger4.debug(`Loading injection script from: ${scriptPath}`);
|
|
5769
|
+
const script = await readTextFile(scriptPath);
|
|
5770
|
+
return `window.__REACTCHECK_PORT__ = ${wsPort};
|
|
5771
|
+
${script}`;
|
|
5772
|
+
} catch (error) {
|
|
5773
|
+
logger4.debug(`Failed to load injection script: ${error}`);
|
|
5774
|
+
logger4.warn("Could not load injection script, using minimal version");
|
|
5775
|
+
return `
|
|
5776
|
+
window.__REACTCHECK_PORT__ = ${wsPort};
|
|
5777
|
+
window.__REACTCHECK_INJECTED__ = true;
|
|
5778
|
+
|
|
5779
|
+
// Install React DevTools hook
|
|
5780
|
+
if (!window.__REACT_DEVTOOLS_GLOBAL_HOOK__) {
|
|
5781
|
+
const hook = {
|
|
5782
|
+
renderers: new Map(),
|
|
5783
|
+
supportsFiber: true,
|
|
5784
|
+
inject: function(renderer) {
|
|
5785
|
+
const id = this.renderers.size + 1;
|
|
5786
|
+
this.renderers.set(id, renderer);
|
|
5787
|
+
return id;
|
|
5788
|
+
},
|
|
5789
|
+
onCommitFiberRoot: function(id, root) {
|
|
5790
|
+
// Will be overwritten by full script
|
|
5791
|
+
},
|
|
5792
|
+
onCommitFiberUnmount: function() {},
|
|
5793
|
+
};
|
|
5794
|
+
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = hook;
|
|
5795
|
+
console.log('[ReactCheck] DevTools hook installed (minimal)');
|
|
5796
|
+
}
|
|
5797
|
+
`;
|
|
5798
|
+
}
|
|
5799
|
+
}
|
|
5197
5800
|
async function runScanCommand(args) {
|
|
5198
5801
|
const options = parseScanOptions(args);
|
|
5199
5802
|
const { config, configPath, fromFile } = await loadConfig(options.configPath);
|
|
5200
5803
|
if (fromFile) {
|
|
5201
|
-
|
|
5804
|
+
logger4.info(`Using config: ${configPath}`);
|
|
5202
5805
|
}
|
|
5203
5806
|
const configOptions = configToOptions(config);
|
|
5204
5807
|
const mergedOptions = {
|
|
@@ -5219,36 +5822,103 @@ async function runScanCommand(args) {
|
|
|
5219
5822
|
}
|
|
5220
5823
|
}),
|
|
5221
5824
|
tui: null,
|
|
5825
|
+
wsServer: null,
|
|
5826
|
+
browser: null,
|
|
5222
5827
|
options: mergedOptions,
|
|
5223
5828
|
active: true,
|
|
5224
5829
|
chains: [],
|
|
5225
5830
|
suggestions: []
|
|
5226
5831
|
};
|
|
5227
5832
|
setupScannerEvents(session);
|
|
5228
|
-
|
|
5833
|
+
const useTUI = !mergedOptions.silent && !mergedOptions.proxy;
|
|
5834
|
+
if (useTUI) {
|
|
5229
5835
|
session.tui = new TUI(mergedOptions.target);
|
|
5230
5836
|
setupTUIEvents(session);
|
|
5231
5837
|
session.tui.start();
|
|
5232
5838
|
}
|
|
5233
|
-
if (
|
|
5234
|
-
|
|
5839
|
+
if (!useTUI) {
|
|
5840
|
+
logger4.info(`Starting scan of ${mergedOptions.target}`);
|
|
5841
|
+
}
|
|
5842
|
+
if (useTUI) {
|
|
5843
|
+
logger4.setLevel(4 /* SILENT */);
|
|
5235
5844
|
}
|
|
5236
5845
|
try {
|
|
5846
|
+
session.wsServer = new WebSocketServer(mergedOptions.port);
|
|
5847
|
+
await session.wsServer.start();
|
|
5848
|
+
logger4.info(`WebSocket server listening on port ${mergedOptions.port}`);
|
|
5849
|
+
session.wsServer.on("connection", (client) => {
|
|
5850
|
+
logger4.info("Browser connected");
|
|
5851
|
+
handleBrowserMessages(client, (message) => {
|
|
5852
|
+
switch (message.type) {
|
|
5853
|
+
case "render":
|
|
5854
|
+
session.scanner.addRender(message.payload);
|
|
5855
|
+
break;
|
|
5856
|
+
case "ready":
|
|
5857
|
+
logger4.info(`React detected: ${message.payload.reactVersion}`);
|
|
5858
|
+
client.send(JSON.stringify({ type: "start" }));
|
|
5859
|
+
break;
|
|
5860
|
+
case "error":
|
|
5861
|
+
logger4.error("Browser error:", message.payload.message);
|
|
5862
|
+
break;
|
|
5863
|
+
}
|
|
5864
|
+
});
|
|
5865
|
+
client.on("close", () => {
|
|
5866
|
+
logger4.info("Browser disconnected");
|
|
5867
|
+
});
|
|
5868
|
+
});
|
|
5237
5869
|
session.scanner.start();
|
|
5238
|
-
if (mergedOptions.
|
|
5239
|
-
|
|
5870
|
+
if (mergedOptions.proxy) {
|
|
5871
|
+
console.log("");
|
|
5872
|
+
console.log(colors.cyan + colors.bold + "\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557" + colors.reset);
|
|
5873
|
+
console.log(colors.cyan + colors.bold + "\u2551 PROXY MODE ACTIVE \u2551" + colors.reset);
|
|
5874
|
+
console.log(colors.cyan + colors.bold + "\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D" + colors.reset);
|
|
5875
|
+
console.log("");
|
|
5876
|
+
console.log(` Add this script to your HTML before React loads:`);
|
|
5877
|
+
console.log("");
|
|
5878
|
+
console.log(colors.yellow + ` <script>window.__REACTCHECK_PORT__ = ${mergedOptions.port};</script>` + colors.reset);
|
|
5879
|
+
console.log(colors.yellow + ` <script src="http://localhost:${mergedOptions.port + 1}/reactcheck.js"></script>` + colors.reset);
|
|
5880
|
+
console.log("");
|
|
5881
|
+
console.log(` Or open: ${colors.cyan}${mergedOptions.target}${colors.reset}`);
|
|
5882
|
+
console.log("");
|
|
5883
|
+
console.log(` Press ${colors.bold}Ctrl+C${colors.reset} to stop scanning`);
|
|
5884
|
+
console.log("");
|
|
5885
|
+
} else {
|
|
5886
|
+
const hasPuppeteer = await isPuppeteerAvailable();
|
|
5887
|
+
if (!hasPuppeteer) {
|
|
5888
|
+
logger4.error("Puppeteer is not installed. Install it with: npm install puppeteer");
|
|
5889
|
+
logger4.info("Alternatively, use --proxy mode to scan with your own browser");
|
|
5890
|
+
await session.wsServer.stop();
|
|
5891
|
+
return 2;
|
|
5892
|
+
}
|
|
5893
|
+
const injectionScript = await getInjectionScript(mergedOptions.port);
|
|
5894
|
+
session.browser = new BrowserLauncher({
|
|
5895
|
+
url: mergedOptions.target,
|
|
5896
|
+
headless: mergedOptions.headless,
|
|
5897
|
+
wsPort: mergedOptions.port
|
|
5898
|
+
});
|
|
5899
|
+
session.browser.setInjectionScript(injectionScript);
|
|
5900
|
+
session.browser.on("console", ({ type, text }) => {
|
|
5901
|
+
if (text.includes("[ReactCheck]")) {
|
|
5902
|
+
logger4.info(`Browser: ${text}`);
|
|
5903
|
+
}
|
|
5904
|
+
});
|
|
5905
|
+
session.browser.on("error", (error) => {
|
|
5906
|
+
logger4.error("Browser error:", error.message);
|
|
5907
|
+
});
|
|
5908
|
+
logger4.info("Launching browser...");
|
|
5909
|
+
await session.browser.launch();
|
|
5910
|
+
logger4.info("Browser launched, scanning...");
|
|
5911
|
+
}
|
|
5912
|
+
if (mergedOptions.duration) {
|
|
5913
|
+
await new Promise((resolve3) => setTimeout(resolve3, mergedOptions.duration * 1e3));
|
|
5240
5914
|
session.active = false;
|
|
5241
|
-
} else if (
|
|
5915
|
+
} else if (session.tui) {
|
|
5242
5916
|
await waitForQuit(session);
|
|
5243
5917
|
} else {
|
|
5244
|
-
logger3.info("Press Ctrl+C to stop scanning");
|
|
5245
5918
|
await waitForSignal();
|
|
5246
5919
|
session.active = false;
|
|
5247
5920
|
}
|
|
5248
|
-
session
|
|
5249
|
-
if (session.tui) {
|
|
5250
|
-
session.tui.stop();
|
|
5251
|
-
}
|
|
5921
|
+
await cleanupSession(session);
|
|
5252
5922
|
if (mergedOptions.report) {
|
|
5253
5923
|
const report = generateReport(session);
|
|
5254
5924
|
await saveReport(report, mergedOptions);
|
|
@@ -5260,28 +5930,40 @@ async function runScanCommand(args) {
|
|
|
5260
5930
|
const summary = session.scanner.getSummary();
|
|
5261
5931
|
return summary.criticalIssues > 0 ? 1 : 0;
|
|
5262
5932
|
} catch (error) {
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
}
|
|
5266
|
-
logger3.error("Scan failed:", error);
|
|
5933
|
+
await cleanupSession(session);
|
|
5934
|
+
logger4.error("Scan failed:", error);
|
|
5267
5935
|
return 2;
|
|
5268
5936
|
}
|
|
5269
5937
|
}
|
|
5938
|
+
async function cleanupSession(session) {
|
|
5939
|
+
session.scanner.stop();
|
|
5940
|
+
if (session.tui) {
|
|
5941
|
+
session.tui.stop();
|
|
5942
|
+
}
|
|
5943
|
+
if (session.browser) {
|
|
5944
|
+
await session.browser.close();
|
|
5945
|
+
}
|
|
5946
|
+
if (session.wsServer) {
|
|
5947
|
+
await session.wsServer.stop();
|
|
5948
|
+
}
|
|
5949
|
+
}
|
|
5270
5950
|
function setupScannerEvents(session) {
|
|
5271
|
-
const { scanner
|
|
5951
|
+
const { scanner } = session;
|
|
5272
5952
|
scanner.on("render", (info) => {
|
|
5273
|
-
if (tui) {
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5953
|
+
if (session.tui) {
|
|
5954
|
+
const snapshot = scanner.getSnapshot();
|
|
5955
|
+
const summary = scanner.getSummary();
|
|
5956
|
+
session.tui.update({
|
|
5957
|
+
components: snapshot,
|
|
5958
|
+
summary,
|
|
5277
5959
|
fps: scanner.getFps()
|
|
5278
5960
|
});
|
|
5279
5961
|
}
|
|
5280
5962
|
});
|
|
5281
5963
|
scanner.on("chain", (chain) => {
|
|
5282
5964
|
session.chains.push(chain);
|
|
5283
|
-
if (tui) {
|
|
5284
|
-
tui.update({ chains: session.chains.slice(-10) });
|
|
5965
|
+
if (session.tui) {
|
|
5966
|
+
session.tui.update({ chains: session.chains.slice(-10) });
|
|
5285
5967
|
}
|
|
5286
5968
|
});
|
|
5287
5969
|
scanner.on("fix", (suggestion) => {
|
|
@@ -5289,19 +5971,19 @@ function setupScannerEvents(session) {
|
|
|
5289
5971
|
(s) => s.componentName === suggestion.componentName && s.fix === suggestion.fix
|
|
5290
5972
|
)) {
|
|
5291
5973
|
session.suggestions.push(suggestion);
|
|
5292
|
-
if (tui) {
|
|
5293
|
-
tui.update({ suggestions: session.suggestions });
|
|
5974
|
+
if (session.tui) {
|
|
5975
|
+
session.tui.update({ suggestions: session.suggestions });
|
|
5294
5976
|
}
|
|
5295
5977
|
}
|
|
5296
5978
|
});
|
|
5297
5979
|
scanner.on("fps-drop", (fps) => {
|
|
5298
5980
|
if (session.options.verbose) {
|
|
5299
|
-
|
|
5981
|
+
logger4.warn(`FPS dropped to ${fps}`);
|
|
5300
5982
|
}
|
|
5301
5983
|
});
|
|
5302
5984
|
scanner.on("severityChange", ({ component, to }) => {
|
|
5303
5985
|
if (session.options.verbose && to === "critical") {
|
|
5304
|
-
|
|
5986
|
+
logger4.warn(`Component ${component} reached critical severity`);
|
|
5305
5987
|
}
|
|
5306
5988
|
});
|
|
5307
5989
|
}
|
|
@@ -5332,19 +6014,19 @@ function setupTUIEvents(session) {
|
|
|
5332
6014
|
});
|
|
5333
6015
|
}
|
|
5334
6016
|
async function waitForQuit(session) {
|
|
5335
|
-
return new Promise((
|
|
6017
|
+
return new Promise((resolve3) => {
|
|
5336
6018
|
if (session.tui) {
|
|
5337
6019
|
session.tui.on("quit", () => {
|
|
5338
6020
|
session.active = false;
|
|
5339
|
-
|
|
6021
|
+
resolve3();
|
|
5340
6022
|
});
|
|
5341
6023
|
}
|
|
5342
6024
|
});
|
|
5343
6025
|
}
|
|
5344
6026
|
async function waitForSignal() {
|
|
5345
|
-
return new Promise((
|
|
5346
|
-
process.once("SIGINT", () =>
|
|
5347
|
-
process.once("SIGTERM", () =>
|
|
6027
|
+
return new Promise((resolve3) => {
|
|
6028
|
+
process.once("SIGINT", () => resolve3());
|
|
6029
|
+
process.once("SIGTERM", () => resolve3());
|
|
5348
6030
|
});
|
|
5349
6031
|
}
|
|
5350
6032
|
function generateReport(session) {
|
|
@@ -5400,7 +6082,7 @@ async function saveReport(report, options) {
|
|
|
5400
6082
|
const filename = `reactcheck-report-${timestamp}.${extension}`;
|
|
5401
6083
|
const filepath = joinPath2(options.output, filename);
|
|
5402
6084
|
await writeTextFile2(filepath, content);
|
|
5403
|
-
|
|
6085
|
+
logger4.info(`Report saved: ${filepath}`);
|
|
5404
6086
|
}
|
|
5405
6087
|
}
|
|
5406
6088
|
function printSummary(session) {
|
|
@@ -5452,32 +6134,32 @@ function printFixSuggestions(suggestions) {
|
|
|
5452
6134
|
|
|
5453
6135
|
// src/cli/commands/init.ts
|
|
5454
6136
|
init_fs();
|
|
5455
|
-
var
|
|
6137
|
+
var logger5 = new Logger({ prefix: "init", level: 1 /* INFO */ });
|
|
5456
6138
|
var DEFAULT_CONFIG_NAME = "reactcheck.config.js";
|
|
5457
6139
|
async function runInitCommand(args) {
|
|
5458
6140
|
const configPath = args.positional[0] ?? DEFAULT_CONFIG_NAME;
|
|
5459
6141
|
if (await exists(configPath)) {
|
|
5460
|
-
|
|
6142
|
+
logger5.warn(`Config file already exists: ${configPath}`);
|
|
5461
6143
|
try {
|
|
5462
6144
|
const content2 = await readTextFile(configPath);
|
|
5463
6145
|
if (configPath.endsWith(".json")) {
|
|
5464
6146
|
const config = JSON.parse(content2);
|
|
5465
6147
|
const errors = validateConfig(config);
|
|
5466
6148
|
if (errors.length > 0) {
|
|
5467
|
-
|
|
6149
|
+
logger5.warn("Existing config has validation errors:");
|
|
5468
6150
|
for (const error of errors) {
|
|
5469
|
-
|
|
6151
|
+
logger5.warn(` - ${error}`);
|
|
5470
6152
|
}
|
|
5471
6153
|
} else {
|
|
5472
|
-
|
|
6154
|
+
logger5.info("Existing config is valid.");
|
|
5473
6155
|
}
|
|
5474
6156
|
}
|
|
5475
6157
|
} catch (error) {
|
|
5476
|
-
|
|
6158
|
+
logger5.warn("Could not validate existing config:", error);
|
|
5477
6159
|
}
|
|
5478
6160
|
console.log("");
|
|
5479
6161
|
console.log(colors.yellow + "? Overwrite existing config? (y/N) " + colors.reset);
|
|
5480
|
-
|
|
6162
|
+
logger5.info("To overwrite, delete the existing file and run init again.");
|
|
5481
6163
|
return 0;
|
|
5482
6164
|
}
|
|
5483
6165
|
const format = configPath.endsWith(".json") ? "json" : "js";
|
|
@@ -5503,13 +6185,13 @@ async function runInitCommand(args) {
|
|
|
5503
6185
|
console.log("");
|
|
5504
6186
|
return 0;
|
|
5505
6187
|
} catch (error) {
|
|
5506
|
-
|
|
6188
|
+
logger5.error(`Failed to create config file:`, error);
|
|
5507
6189
|
return 1;
|
|
5508
6190
|
}
|
|
5509
6191
|
}
|
|
5510
6192
|
|
|
5511
6193
|
// src/cli/index.ts
|
|
5512
|
-
var
|
|
6194
|
+
var logger6 = new Logger({ prefix: "ReactCheck", level: 1 /* INFO */ });
|
|
5513
6195
|
var VERSION = "1.0.0";
|
|
5514
6196
|
function printVersion() {
|
|
5515
6197
|
console.log(`@oxog/react-check v${VERSION}`);
|
|
@@ -5560,7 +6242,7 @@ var CLI = class {
|
|
|
5560
6242
|
const errors = validateArgs(args);
|
|
5561
6243
|
if (errors.length > 0) {
|
|
5562
6244
|
for (const error of errors) {
|
|
5563
|
-
|
|
6245
|
+
logger6.error(error);
|
|
5564
6246
|
}
|
|
5565
6247
|
console.log("");
|
|
5566
6248
|
console.log("Run " + colors.cyan + "react-check --help" + colors.reset + " for usage information.");
|
|
@@ -5569,7 +6251,7 @@ var CLI = class {
|
|
|
5569
6251
|
return await runScanCommand(args);
|
|
5570
6252
|
}
|
|
5571
6253
|
} catch (error) {
|
|
5572
|
-
|
|
6254
|
+
logger6.error("Unexpected error:", error);
|
|
5573
6255
|
return 1;
|
|
5574
6256
|
}
|
|
5575
6257
|
}
|