@lark-apaas/devtool-kits 1.0.5-alpha.4 → 1.0.5-alpha.6

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/index.cjs CHANGED
@@ -28406,8 +28406,6 @@ __name(collapseExtraBlankLines, "collapseExtraBlankLines");
28406
28406
  // src/helpers/proxy-error/index.ts
28407
28407
  var import_node_fs2 = __toESM(require("fs"), 1);
28408
28408
  var import_node_path2 = __toESM(require("path"), 1);
28409
- var import_node_fs3 = require("fs");
28410
- var import_node_readline = require("readline");
28411
28409
  var import_node_http = __toESM(require("http"), 1);
28412
28410
  var import_node_https = __toESM(require("https"), 1);
28413
28411
  var errorHtmlTemplate = null;
@@ -28483,63 +28481,82 @@ function parseLogLine(line) {
28483
28481
  if (!trimmed) return null;
28484
28482
  const match = trimmed.match(/^\[\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\]\s+\[server\]\s+(.*)$/);
28485
28483
  if (match) {
28486
- return match[1];
28484
+ const content = match[1].trim();
28485
+ return content || null;
28487
28486
  }
28488
- return trimmed;
28487
+ return null;
28489
28488
  }
28490
28489
  __name(parseLogLine, "parseLogLine");
28491
28490
  async function readRecentErrorLogs(logDir, maxLogs, fileName) {
28492
28491
  const logFilePath = import_node_path2.default.join(logDir, fileName);
28492
+ let fileStats;
28493
28493
  try {
28494
- await import_node_fs2.default.promises.access(logFilePath);
28494
+ fileStats = await import_node_fs2.default.promises.stat(logFilePath);
28495
28495
  } catch {
28496
28496
  return {
28497
28497
  logs: [],
28498
28498
  hasCompileError: false
28499
28499
  };
28500
28500
  }
28501
- const allLines = [];
28502
- const stream = (0, import_node_fs3.createReadStream)(logFilePath, {
28503
- encoding: "utf8"
28504
- });
28505
- const rl = (0, import_node_readline.createInterface)({
28506
- input: stream,
28507
- crlfDelay: Infinity
28508
- });
28501
+ const fileSize = fileStats.size;
28502
+ const maxReadSize = 1024 * 1024;
28503
+ const readSize = Math.min(fileSize, maxReadSize);
28504
+ const startPosition = Math.max(0, fileSize - readSize);
28505
+ const buffer = Buffer.allocUnsafe(readSize);
28506
+ let fileHandle;
28509
28507
  try {
28510
- for await (const line of rl) {
28511
- const parsed = parseLogLine(line);
28512
- if (parsed !== null) {
28513
- allLines.push(parsed);
28514
- }
28515
- }
28508
+ fileHandle = await import_node_fs2.default.promises.open(logFilePath, "r");
28509
+ await fileHandle.read(buffer, 0, readSize, startPosition);
28510
+ } catch (error) {
28511
+ console.error("[Proxy Error]: Failed to read log file:", error);
28512
+ return {
28513
+ logs: [],
28514
+ hasCompileError: false
28515
+ };
28516
28516
  } finally {
28517
- rl.close();
28518
- stream.destroy();
28517
+ if (fileHandle) {
28518
+ await fileHandle.close();
28519
+ }
28520
+ }
28521
+ const content = buffer.toString("utf8");
28522
+ const lines = content.split("\n");
28523
+ if (startPosition > 0 && lines.length > 0) {
28524
+ lines.shift();
28525
+ }
28526
+ const allLines = [];
28527
+ for (const line of lines) {
28528
+ const parsed = parseLogLine(line);
28529
+ if (parsed !== null) {
28530
+ allLines.push(parsed);
28531
+ }
28519
28532
  }
28520
28533
  let startIndex = -1;
28521
28534
  for (let i = allLines.length - 1; i >= 0; i--) {
28522
- if (allLines[i].includes("dev:server")) {
28535
+ const line = allLines[i];
28536
+ if (line.includes("Starting compilation in watch mode") || line.includes("File change detected. Starting incremental compilation")) {
28523
28537
  startIndex = i;
28524
28538
  break;
28525
28539
  }
28526
28540
  }
28527
28541
  if (startIndex === -1) {
28542
+ console.log("[Proxy Error]: No compilation start marker found, returning last logs");
28543
+ const fallbackLogs = allLines.slice(-maxLogs);
28544
+ const hasCompileError2 = checkForErrors(fallbackLogs);
28528
28545
  return {
28529
- logs: [],
28530
- hasCompileError: false
28546
+ logs: fallbackLogs,
28547
+ hasCompileError: hasCompileError2
28531
28548
  };
28532
28549
  }
28533
28550
  let endIndex = allLines.length;
28534
- let hasCompileError = false;
28535
- for (let i = startIndex; i < allLines.length; i++) {
28536
- if (/Found \d+ errors?\./.test(allLines[i])) {
28537
- endIndex = i + 1;
28538
- hasCompileError = true;
28551
+ for (let i = startIndex + 1; i < allLines.length; i++) {
28552
+ const line = allLines[i];
28553
+ if (line.includes("Starting compilation in watch mode") || line.includes("File change detected. Starting incremental compilation")) {
28554
+ endIndex = i;
28539
28555
  break;
28540
28556
  }
28541
28557
  }
28542
28558
  const errorSection = allLines.slice(startIndex, endIndex);
28559
+ const hasCompileError = checkForErrors(errorSection);
28543
28560
  const logs = errorSection.length > maxLogs ? errorSection.slice(-maxLogs) : errorSection;
28544
28561
  return {
28545
28562
  logs,
@@ -28547,6 +28564,20 @@ async function readRecentErrorLogs(logDir, maxLogs, fileName) {
28547
28564
  };
28548
28565
  }
28549
28566
  __name(readRecentErrorLogs, "readRecentErrorLogs");
28567
+ function checkForErrors(logs) {
28568
+ for (const line of logs) {
28569
+ const compileErrorMatch = line.match(/Found (\d+) errors?\. Watching for file changes/);
28570
+ if (compileErrorMatch) {
28571
+ const errorCount = parseInt(compileErrorMatch[1], 10);
28572
+ if (errorCount > 0) {
28573
+ console.log(`[Proxy Error]: Found ${errorCount} compilation error(s)`);
28574
+ return true;
28575
+ }
28576
+ }
28577
+ }
28578
+ return false;
28579
+ }
28580
+ __name(checkForErrors, "checkForErrors");
28550
28581
  function injectErrorData(template, errorLogs, clientBasePath) {
28551
28582
  let logsText = "";
28552
28583
  if (errorLogs.length > 0) {
@@ -28559,9 +28590,9 @@ function injectErrorData(template, errorLogs, clientBasePath) {
28559
28590
  }
28560
28591
  __name(injectErrorData, "injectErrorData");
28561
28592
  function handleDevProxyError(err, req, res, options) {
28562
- const { logDir = import_node_path2.default.join(process.cwd(), "logs"), maxErrorLogs = 100, logFileName = "server.log", retryTimeout = 5e3, retryInterval = 500, target, clientBasePath = process.env.CLIENT_BASE_PATH || "/" } = options || {};
28593
+ const { logDir = import_node_path2.default.join(process.cwd(), "logs"), maxErrorLogs = 100, logFileName = "server.log", retryTimeout = 5e3, retryInterval = 500, target = `http://localhost:${process.env.SERVER_PORT || 3e3}`, clientBasePath = process.env.CLIENT_BASE_PATH || "/" } = options || {};
28563
28594
  const clientBasePathWithoutSlash = normalizeBasePath(clientBasePath);
28564
- console.error("[Proxy Error]:", err.message);
28595
+ console.error("[Proxy Error]:", err.message, clientBasePathWithoutSlash);
28565
28596
  if (res.headersSent) {
28566
28597
  console.error("[Proxy Error]: Headers already sent, cannot send error page");
28567
28598
  return;
@@ -28570,7 +28601,7 @@ function handleDevProxyError(err, req, res, options) {
28570
28601
  try {
28571
28602
  const isConnError = isConnectionError(err);
28572
28603
  const { logs: errorLogs, hasCompileError } = await readRecentErrorLogs(logDir, maxErrorLogs, logFileName);
28573
- if (isConnError && !hasCompileError && target) {
28604
+ if (isConnError && !hasCompileError) {
28574
28605
  console.log("[Proxy Error]: Connection error without compile errors, possibly server restarting...");
28575
28606
  try {
28576
28607
  new URL(target);
@@ -28726,17 +28757,17 @@ var import_promises = __toESM(require("fs/promises"), 1);
28726
28757
  var import_node_crypto = __toESM(require("crypto"), 1);
28727
28758
 
28728
28759
  // src/middlewares/openapi/services.ts
28729
- var import_node_fs5 = require("fs");
28760
+ var import_node_fs4 = require("fs");
28730
28761
  var import_node_path4 = __toESM(require("path"), 1);
28731
28762
  var import_typescript = __toESM(require("typescript"), 1);
28732
28763
 
28733
28764
  // src/middlewares/openapi/utils.ts
28734
28765
  var import_node_path3 = __toESM(require("path"), 1);
28735
- var import_node_fs4 = require("fs");
28766
+ var import_node_fs3 = require("fs");
28736
28767
  async function findControllerFiles(dir) {
28737
28768
  const files = [];
28738
28769
  async function scan(currentDir) {
28739
- const entries = await import_node_fs4.promises.readdir(currentDir, {
28770
+ const entries = await import_node_fs3.promises.readdir(currentDir, {
28740
28771
  withFileTypes: true
28741
28772
  });
28742
28773
  for (const entry of entries) {
@@ -28820,14 +28851,14 @@ async function enhanceOpenApiWithSourceInfo(options = {}) {
28820
28851
  if (options.openapiData) {
28821
28852
  openapi = JSON.parse(JSON.stringify(options.openapiData));
28822
28853
  } else {
28823
- const openapiContent = await import_node_fs5.promises.readFile(openapiPath, "utf-8");
28854
+ const openapiContent = await import_node_fs4.promises.readFile(openapiPath, "utf-8");
28824
28855
  openapi = JSON.parse(openapiContent);
28825
28856
  }
28826
28857
  const controllerFiles = await findControllerFiles(serverDir);
28827
28858
  const sourceMap = await buildSourceMap(controllerFiles, processControllerFile);
28828
28859
  const enhanced = enhanceOpenApiPaths(openapi, sourceMap);
28829
28860
  if (writeFile) {
28830
- await import_node_fs5.promises.writeFile(openapiPath, JSON.stringify(openapi, null, 2) + "\n", "utf-8");
28861
+ await import_node_fs4.promises.writeFile(openapiPath, JSON.stringify(openapi, null, 2) + "\n", "utf-8");
28831
28862
  }
28832
28863
  const duration = Date.now() - startTime;
28833
28864
  return {
@@ -28843,7 +28874,7 @@ async function enhanceOpenApiWithSourceInfo(options = {}) {
28843
28874
  __name(enhanceOpenApiWithSourceInfo, "enhanceOpenApiWithSourceInfo");
28844
28875
  async function processControllerFile(filePath) {
28845
28876
  const relativePath = import_node_path4.default.relative(process.cwd(), filePath);
28846
- const content = await import_node_fs5.promises.readFile(filePath, "utf-8");
28877
+ const content = await import_node_fs4.promises.readFile(filePath, "utf-8");
28847
28878
  const sourceFile = import_typescript.default.createSourceFile(filePath, content, import_typescript.default.ScriptTarget.Latest, true);
28848
28879
  return extractControllerMetadata(sourceFile, relativePath);
28849
28880
  }
@@ -29003,7 +29034,7 @@ __name(createOpenapiMiddleware, "createOpenapiMiddleware");
29003
29034
  var import_express3 = __toESM(require_express2(), 1);
29004
29035
 
29005
29036
  // src/middlewares/dev-logs/utils.ts
29006
- var import_node_fs6 = require("fs");
29037
+ var import_node_fs5 = require("fs");
29007
29038
  var import_node_path5 = require("path");
29008
29039
 
29009
29040
  // src/middlewares/dev-logs/helper/path-matcher.ts
@@ -29055,7 +29086,7 @@ function getRelativePath(filePath) {
29055
29086
  __name(getRelativePath, "getRelativePath");
29056
29087
  async function fileExists(filePath) {
29057
29088
  try {
29058
- await import_node_fs6.promises.access(filePath);
29089
+ await import_node_fs5.promises.access(filePath);
29059
29090
  return true;
29060
29091
  } catch {
29061
29092
  return false;
@@ -29138,18 +29169,18 @@ __name(serializeError, "serializeError");
29138
29169
  var import_node_path6 = require("path");
29139
29170
 
29140
29171
  // src/middlewares/dev-logs/services.ts
29141
- var import_node_fs7 = require("fs");
29142
- var import_node_readline2 = require("readline");
29172
+ var import_node_fs6 = require("fs");
29173
+ var import_node_readline = require("readline");
29143
29174
  async function readLogEntriesByTrace(filePath, traceId, limit) {
29144
29175
  const exists = await fileExists(filePath);
29145
29176
  if (!exists) {
29146
29177
  return void 0;
29147
29178
  }
29148
29179
  const matches = [];
29149
- const stream = (0, import_node_fs7.createReadStream)(filePath, {
29180
+ const stream = (0, import_node_fs6.createReadStream)(filePath, {
29150
29181
  encoding: "utf8"
29151
29182
  });
29152
- const rl = (0, import_node_readline2.createInterface)({
29183
+ const rl = (0, import_node_readline.createInterface)({
29153
29184
  input: stream,
29154
29185
  crlfDelay: Infinity
29155
29186
  });
@@ -29238,7 +29269,7 @@ async function readRecentTraceCalls(filePath, page, pageSize, pathFilter, method
29238
29269
  }
29239
29270
  __name(readRecentTraceCalls, "readRecentTraceCalls");
29240
29271
  async function readFileReverse(filePath, chunkSize, processLine) {
29241
- const handle = await import_node_fs7.promises.open(filePath, "r");
29272
+ const handle = await import_node_fs6.promises.open(filePath, "r");
29242
29273
  try {
29243
29274
  const stats = await handle.stat();
29244
29275
  let position = stats.size;
@@ -29300,10 +29331,10 @@ async function readLogFilePage(filePath, page, pageSize) {
29300
29331
  const capacity = page * pageSize;
29301
29332
  const buffer = [];
29302
29333
  let totalLines = 0;
29303
- const stream = (0, import_node_fs7.createReadStream)(filePath, {
29334
+ const stream = (0, import_node_fs6.createReadStream)(filePath, {
29304
29335
  encoding: "utf8"
29305
29336
  });
29306
- const rl = (0, import_node_readline2.createInterface)({
29337
+ const rl = (0, import_node_readline.createInterface)({
29307
29338
  input: stream,
29308
29339
  crlfDelay: Infinity
29309
29340
  });
@@ -29496,7 +29527,7 @@ var import_fs = __toESM(require("fs"), 1);
29496
29527
 
29497
29528
  // src/middlewares/collect-logs/utils.ts
29498
29529
  var import_node_path7 = require("path");
29499
- var import_node_fs8 = __toESM(require("fs"), 1);
29530
+ var import_node_fs7 = __toESM(require("fs"), 1);
29500
29531
  function resolveLogDir2(provided) {
29501
29532
  if (!provided) {
29502
29533
  return (0, import_node_path7.join)(process.cwd(), "logs");
@@ -29505,8 +29536,8 @@ function resolveLogDir2(provided) {
29505
29536
  }
29506
29537
  __name(resolveLogDir2, "resolveLogDir");
29507
29538
  function ensureDir(dir) {
29508
- if (!import_node_fs8.default.existsSync(dir)) {
29509
- import_node_fs8.default.mkdirSync(dir, {
29539
+ if (!import_node_fs7.default.existsSync(dir)) {
29540
+ import_node_fs7.default.mkdirSync(dir, {
29510
29541
  recursive: true
29511
29542
  });
29512
29543
  }