vite-plugin-ai-diagnostic 1.0.3 → 1.0.4
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.js +184 -152
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +126 -119
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import { StateGraph, START, END } from '@langchain/langgraph';
|
|
3
|
-
import { ChatOpenAI } from '@langchain/openai';
|
|
4
|
-
import { SystemMessage, HumanMessage } from '@langchain/core/messages';
|
|
5
|
-
import { extractSourceFile } from 'vite-plugin-ai-shared';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
|
|
8
1
|
// src/index.ts
|
|
2
|
+
import fs2 from "fs";
|
|
3
|
+
|
|
4
|
+
// src/langgraph.ts
|
|
5
|
+
import { StateGraph, END, START } from "@langchain/langgraph";
|
|
6
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
7
|
+
import { HumanMessage, SystemMessage } from "@langchain/core/messages";
|
|
9
8
|
var DiagnosticGraph = class {
|
|
10
9
|
constructor(apiKey, apiUrl, model = "gpt-4", maxRetries = 3) {
|
|
11
10
|
this.maxRetries = maxRetries;
|
|
12
|
-
console.log("
|
|
13
|
-
console.log("
|
|
14
|
-
console.log("
|
|
15
|
-
console.log("
|
|
11
|
+
console.log("🔧 [LangGraph] 初始化 LLM...");
|
|
12
|
+
console.log("📝 [配置] 模型:", model);
|
|
13
|
+
console.log("📝 [配置] API URL:", apiUrl);
|
|
14
|
+
console.log("📝 [配置] API Key:", apiKey ? "已配置" : "未配置");
|
|
16
15
|
this.llm = new ChatOpenAI({
|
|
17
16
|
openAIApiKey: apiKey,
|
|
18
17
|
configuration: {
|
|
@@ -45,21 +44,21 @@ var DiagnosticGraph = class {
|
|
|
45
44
|
return workflow.compile();
|
|
46
45
|
}
|
|
47
46
|
async analyzeNode(state) {
|
|
48
|
-
console.log("
|
|
47
|
+
console.log("🔍 [LangGraph] 正在分析错误...");
|
|
49
48
|
const systemPrompt = new SystemMessage(
|
|
50
|
-
"
|
|
49
|
+
"你是一个专业的前端代码诊断专家,精通 Vue3、TypeScript、Vite 和 uni-app。请简洁明了地分析问题。"
|
|
51
50
|
);
|
|
52
51
|
const userPrompt = new HumanMessage(`
|
|
53
|
-
|
|
52
|
+
请分析以下构建错误:
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
错误类型: ${state.error.type}
|
|
55
|
+
错误信息: ${state.error.message}
|
|
56
|
+
文件路径: ${state.error.file || "未知"}
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
1.
|
|
61
|
-
2.
|
|
62
|
-
3.
|
|
58
|
+
请简洁地说明(3-5句话):
|
|
59
|
+
1. 错误的根本原因
|
|
60
|
+
2. 影响范围
|
|
61
|
+
3. 严重程度
|
|
63
62
|
`);
|
|
64
63
|
const response = await this.llm.invoke([systemPrompt, userPrompt]);
|
|
65
64
|
const analysis = response.content.toString();
|
|
@@ -69,25 +68,25 @@ var DiagnosticGraph = class {
|
|
|
69
68
|
};
|
|
70
69
|
}
|
|
71
70
|
async suggestNode(state) {
|
|
72
|
-
console.log("
|
|
71
|
+
console.log("💡 [LangGraph] 正在生成修复建议...");
|
|
73
72
|
const userPrompt = new HumanMessage(`
|
|
74
|
-
|
|
73
|
+
基于以下错误分析,请提供具体的修复建议:
|
|
75
74
|
|
|
76
|
-
|
|
75
|
+
错误分析:
|
|
77
76
|
${state.analysis}
|
|
78
77
|
|
|
79
|
-
|
|
80
|
-
-
|
|
81
|
-
-
|
|
82
|
-
-
|
|
78
|
+
错误详情:
|
|
79
|
+
- 类型: ${state.error.type}
|
|
80
|
+
- 信息: ${state.error.message}
|
|
81
|
+
- 文件: ${state.error.file || "未知"}
|
|
83
82
|
|
|
84
|
-
|
|
85
|
-
1.
|
|
86
|
-
2.
|
|
87
|
-
3.
|
|
88
|
-
4.
|
|
83
|
+
请简洁地提供:
|
|
84
|
+
1. 具体的修复步骤(3-5步即可)
|
|
85
|
+
2. 需要修改的代码位置(行号)
|
|
86
|
+
3. 修改后的代码示例(只显示关键部分)
|
|
87
|
+
4. 一句话预防建议
|
|
89
88
|
|
|
90
|
-
|
|
89
|
+
注意:请直接给出建议,不要重复错误分析的内容。
|
|
91
90
|
`);
|
|
92
91
|
const response = await this.llm.invoke([...state.messages, userPrompt]);
|
|
93
92
|
const suggestion = response.content.toString();
|
|
@@ -177,12 +176,12 @@ ${state.analysis}
|
|
|
177
176
|
messages: []
|
|
178
177
|
};
|
|
179
178
|
try {
|
|
180
|
-
console.log("
|
|
179
|
+
console.log("🚀 [LangGraph] 启动诊断工作流...\n");
|
|
181
180
|
const result = await this.graph.invoke(initialState);
|
|
182
|
-
console.log("
|
|
181
|
+
console.log("✨ [LangGraph] 诊断工作流完成\n");
|
|
183
182
|
return result;
|
|
184
183
|
} catch (error2) {
|
|
185
|
-
console.error("
|
|
184
|
+
console.error("❌ [LangGraph] 工作流执行失败:", error2.message);
|
|
186
185
|
throw error2;
|
|
187
186
|
}
|
|
188
187
|
}
|
|
@@ -202,8 +201,8 @@ var AIErrorDiagnostic = class {
|
|
|
202
201
|
async diagnose(error, autoFix = false) {
|
|
203
202
|
if (!this.options.apiKey) {
|
|
204
203
|
return {
|
|
205
|
-
analysis: "
|
|
206
|
-
suggestion: "
|
|
204
|
+
analysis: "未配置 API Key,无法使用 AI 诊断功能",
|
|
205
|
+
suggestion: "请在 .env 文件中配置 OPENAI_API_KEY",
|
|
207
206
|
fixedCode: void 0,
|
|
208
207
|
filePath: void 0
|
|
209
208
|
};
|
|
@@ -218,10 +217,10 @@ var AIErrorDiagnostic = class {
|
|
|
218
217
|
filePath: void 0
|
|
219
218
|
};
|
|
220
219
|
} catch (error2) {
|
|
221
|
-
console.error("
|
|
220
|
+
console.error("❌ AI 诊断失败:", error2.message);
|
|
222
221
|
return {
|
|
223
|
-
analysis:
|
|
224
|
-
suggestion: "
|
|
222
|
+
analysis: `诊断过程出错: ${error2.message}`,
|
|
223
|
+
suggestion: "请检查 API 配置和网络连接",
|
|
225
224
|
fixedCode: void 0,
|
|
226
225
|
filePath: void 0
|
|
227
226
|
};
|
|
@@ -243,6 +242,13 @@ var AIErrorDiagnostic = class {
|
|
|
243
242
|
// }
|
|
244
243
|
// }
|
|
245
244
|
};
|
|
245
|
+
|
|
246
|
+
// src/index.ts
|
|
247
|
+
import { extractSourceFile } from "vite-plugin-ai-shared";
|
|
248
|
+
|
|
249
|
+
// src/reporter.ts
|
|
250
|
+
import fs from "fs";
|
|
251
|
+
import path from "path";
|
|
246
252
|
var DiagnosticReporter = class {
|
|
247
253
|
/**
|
|
248
254
|
* 生成报告(根据配置生成多种格式)
|
|
@@ -268,7 +274,7 @@ var DiagnosticReporter = class {
|
|
|
268
274
|
<head>
|
|
269
275
|
<meta charset="UTF-8">
|
|
270
276
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
271
|
-
<title>AI
|
|
277
|
+
<title>AI 诊断报告</title>
|
|
272
278
|
<style>
|
|
273
279
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
274
280
|
body {
|
|
@@ -427,48 +433,48 @@ var DiagnosticReporter = class {
|
|
|
427
433
|
<body>
|
|
428
434
|
<div class="container">
|
|
429
435
|
<div class="header">
|
|
430
|
-
<h1
|
|
431
|
-
<div class="time"
|
|
436
|
+
<h1>🤖 AI 诊断报告</h1>
|
|
437
|
+
<div class="time">生成时间: ${report.timestamp}</div>
|
|
432
438
|
</div>
|
|
433
439
|
|
|
434
440
|
<div class="content">
|
|
435
|
-
<!--
|
|
441
|
+
<!-- 错误信息 -->
|
|
436
442
|
<div class="section">
|
|
437
|
-
<div class="section-title"
|
|
443
|
+
<div class="section-title">❌ 错误信息</div>
|
|
438
444
|
<div class="error-box">
|
|
439
445
|
<span class="error-type">${report.error.type}</span>
|
|
440
446
|
<div class="error-message">${this.escapeHtml(
|
|
441
447
|
report.error.message
|
|
442
448
|
)}</div>
|
|
443
|
-
<div class="error-file"
|
|
449
|
+
<div class="error-file">📂 ${report.error.file}</div>
|
|
444
450
|
${report.error.stack ? `<div class="stack-trace">${this.escapeHtml(
|
|
445
451
|
report.error.stack
|
|
446
452
|
)}</div>` : ""}
|
|
447
453
|
</div>
|
|
448
454
|
</div>
|
|
449
455
|
|
|
450
|
-
<!-- AI
|
|
456
|
+
<!-- AI 分析 -->
|
|
451
457
|
<div class="section">
|
|
452
|
-
<div class="section-title"
|
|
458
|
+
<div class="section-title">🔍 AI 分析</div>
|
|
453
459
|
<div class="analysis-box">
|
|
454
460
|
${this.formatText(report.analysis)}
|
|
455
461
|
</div>
|
|
456
462
|
</div>
|
|
457
463
|
|
|
458
|
-
<!--
|
|
464
|
+
<!-- 修复建议 -->
|
|
459
465
|
<div class="section">
|
|
460
|
-
<div class="section-title"
|
|
466
|
+
<div class="section-title">💡 修复建议</div>
|
|
461
467
|
<div class="suggestion-box">
|
|
462
468
|
${this.formatText(report.suggestion)}
|
|
463
469
|
</div>
|
|
464
470
|
</div>
|
|
465
471
|
|
|
466
|
-
<!--
|
|
472
|
+
<!-- 修复状态 -->
|
|
467
473
|
<div class="section">
|
|
468
|
-
<div class="section-title"
|
|
469
|
-
${report.fixed ? `<div class="fixed-badge"
|
|
470
|
-
<div style="margin-top: 10px; color: #666;"
|
|
471
|
-
<div style="margin-top: 10px; color: #666;"
|
|
474
|
+
<div class="section-title">🔧 修复状态</div>
|
|
475
|
+
${report.fixed ? `<div class="fixed-badge">✅ 已自动修复</div>
|
|
476
|
+
<div style="margin-top: 10px; color: #666;">修复文件: <code>${report.fixedFilePath}</code></div>` : `<div class="not-fixed-badge">⚠️ 未自动修复</div>
|
|
477
|
+
<div style="margin-top: 10px; color: #666;">请根据上述建议手动修复</div>`}
|
|
472
478
|
</div>
|
|
473
479
|
</div>
|
|
474
480
|
|
|
@@ -487,7 +493,7 @@ var DiagnosticReporter = class {
|
|
|
487
493
|
const reportPath = path.resolve(reportsDir, "diagnostic-report.html");
|
|
488
494
|
fs.writeFileSync(reportPath, html, "utf-8");
|
|
489
495
|
console.log(`
|
|
490
|
-
|
|
496
|
+
📄 诊断报告已生成: ${reportPath}
|
|
491
497
|
`);
|
|
492
498
|
}
|
|
493
499
|
/**
|
|
@@ -525,22 +531,22 @@ var DiagnosticReporter = class {
|
|
|
525
531
|
* 生成 Markdown 报告
|
|
526
532
|
*/
|
|
527
533
|
static async generateMarkdownReport(report) {
|
|
528
|
-
const markdown = `#
|
|
534
|
+
const markdown = `# 🤖 AI 诊断报告
|
|
529
535
|
|
|
530
|
-
|
|
536
|
+
**生成时间**: ${report.timestamp}
|
|
531
537
|
|
|
532
538
|
---
|
|
533
539
|
|
|
534
|
-
##
|
|
540
|
+
## ❌ 错误信息
|
|
535
541
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
542
|
+
**类型**: \`${report.error.type}\`
|
|
543
|
+
**文件**: \`${report.error.file}\`
|
|
544
|
+
**消息**:
|
|
539
545
|
\`\`\`
|
|
540
546
|
${report.error.message}
|
|
541
547
|
\`\`\`
|
|
542
548
|
|
|
543
|
-
${report.error.stack ?
|
|
549
|
+
${report.error.stack ? `**堆栈跟踪**:
|
|
544
550
|
\`\`\`
|
|
545
551
|
${report.error.stack}
|
|
546
552
|
\`\`\`
|
|
@@ -548,25 +554,25 @@ ${report.error.stack}
|
|
|
548
554
|
|
|
549
555
|
---
|
|
550
556
|
|
|
551
|
-
##
|
|
557
|
+
## 🔍 AI 分析
|
|
552
558
|
|
|
553
559
|
${report.analysis}
|
|
554
560
|
|
|
555
561
|
---
|
|
556
562
|
|
|
557
|
-
##
|
|
563
|
+
## 💡 修复建议
|
|
558
564
|
|
|
559
565
|
${report.suggestion}
|
|
560
566
|
|
|
561
567
|
---
|
|
562
568
|
|
|
563
|
-
##
|
|
569
|
+
## 🔧 修复状态
|
|
564
570
|
|
|
565
|
-
${report.fixed ?
|
|
571
|
+
${report.fixed ? `✅ **已自动修复**
|
|
566
572
|
|
|
567
|
-
|
|
573
|
+
修复文件: \`${report.fixedFilePath}\`` : `⚠️ **未自动修复**
|
|
568
574
|
|
|
569
|
-
|
|
575
|
+
请根据上述建议手动修复`}
|
|
570
576
|
|
|
571
577
|
---
|
|
572
578
|
|
|
@@ -579,7 +585,7 @@ ${report.fixed ? `\u2705 **\u5DF2\u81EA\u52A8\u4FEE\u590D**
|
|
|
579
585
|
}
|
|
580
586
|
const reportPath = path.resolve(reportsDir, "diagnostic-report.md");
|
|
581
587
|
fs.writeFileSync(reportPath, markdown, "utf-8");
|
|
582
|
-
console.log(
|
|
588
|
+
console.log(`📄 Markdown 报告已生成: ${reportPath}`);
|
|
583
589
|
}
|
|
584
590
|
/**
|
|
585
591
|
* 生成 JSON 报告
|
|
@@ -609,7 +615,7 @@ ${report.fixed ? `\u2705 **\u5DF2\u81EA\u52A8\u4FEE\u590D**
|
|
|
609
615
|
}
|
|
610
616
|
const reportPath = path.resolve(reportsDir, "diagnostic-report.json");
|
|
611
617
|
fs.writeFileSync(reportPath, JSON.stringify(jsonReport, null, 2), "utf-8");
|
|
612
|
-
console.log(
|
|
618
|
+
console.log(`📄 JSON 报告已生成: ${reportPath}`);
|
|
613
619
|
}
|
|
614
620
|
};
|
|
615
621
|
|
|
@@ -640,38 +646,38 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
640
646
|
async function processError(error) {
|
|
641
647
|
const errorKey = `${error.file}:${error.message}`;
|
|
642
648
|
if (processedErrors.has(errorKey)) {
|
|
643
|
-
console.log("
|
|
649
|
+
console.log("🔍 [调试] 跳过重复错误:", errorKey);
|
|
644
650
|
return;
|
|
645
651
|
}
|
|
646
652
|
processedErrors.add(errorKey);
|
|
647
653
|
try {
|
|
648
|
-
console.log("\n
|
|
649
|
-
console.log(
|
|
650
|
-
console.log(
|
|
654
|
+
console.log("\n⚠️ 检测到错误,正在使用 AI 分析...\n");
|
|
655
|
+
console.log(`📝 错误信息: ${error.message}`);
|
|
656
|
+
console.log(`📂 文件路径: ${error.file || "未知"}`);
|
|
651
657
|
console.log(
|
|
652
|
-
|
|
658
|
+
`📄 代码长度: ${error.code ? error.code.length + " 字符" : "无"}`
|
|
653
659
|
);
|
|
654
|
-
console.log(
|
|
660
|
+
console.log(`🔧 自动修复: ${autoFix ? "是" : "否"}
|
|
655
661
|
`);
|
|
656
662
|
if (!error.file || !error.code) {
|
|
657
|
-
console.log("
|
|
663
|
+
console.log("⚠️ 跳过此错误:缺少文件路径或代码内容\n");
|
|
658
664
|
return;
|
|
659
665
|
}
|
|
660
666
|
const result = await diagnostic.diagnose(error, autoFix);
|
|
661
667
|
if (output.console !== false) {
|
|
662
|
-
console.log("
|
|
663
|
-
console.log("
|
|
668
|
+
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
669
|
+
console.log("🔍 错误分析:");
|
|
664
670
|
console.log(result.analysis);
|
|
665
|
-
console.log("\n
|
|
671
|
+
console.log("\n💡 修复建议:");
|
|
666
672
|
console.log(result.suggestion);
|
|
667
673
|
if (result.fixedCode && result.filePath) {
|
|
668
|
-
console.log("\n
|
|
669
|
-
console.log("
|
|
670
|
-
console.log("\n
|
|
674
|
+
console.log("\n✅ 已自动修复代码");
|
|
675
|
+
console.log("修复的文件:", result.filePath);
|
|
676
|
+
console.log("\n💡 请重新运行构建命令");
|
|
671
677
|
} else if (autoFix) {
|
|
672
|
-
console.log("\n
|
|
678
|
+
console.log("\n⚠️ 无法自动修复:AI 未生成修复代码");
|
|
673
679
|
}
|
|
674
|
-
console.log("
|
|
680
|
+
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
|
|
675
681
|
}
|
|
676
682
|
const report = {
|
|
677
683
|
timestamp: (/* @__PURE__ */ new Date()).toLocaleString("zh-CN"),
|
|
@@ -688,7 +694,7 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
688
694
|
};
|
|
689
695
|
await DiagnosticReporter.generate(report, output);
|
|
690
696
|
} catch (err) {
|
|
691
|
-
console.error("
|
|
697
|
+
console.error("❌ AI 诊断失败:", err.message);
|
|
692
698
|
}
|
|
693
699
|
}
|
|
694
700
|
return {
|
|
@@ -696,18 +702,18 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
696
702
|
// 确保插件在其他插件之后执行,以捕获更多错误
|
|
697
703
|
enforce: "post",
|
|
698
704
|
configResolved(config) {
|
|
699
|
-
console.log("\n
|
|
700
|
-
console.log(
|
|
701
|
-
console.log(
|
|
705
|
+
console.log("\n🤖 AI 诊断助手已启动...");
|
|
706
|
+
console.log(`⚙️ 自动修复: ${autoFix ? "✅ 已启用" : "❌ 未启用"}`);
|
|
707
|
+
console.log(`📝 根目录: ${config.root}`);
|
|
702
708
|
console.log(
|
|
703
|
-
|
|
709
|
+
`📝 入口: ${config.build.rollupOptions?.input || "index.html"}
|
|
704
710
|
`
|
|
705
711
|
);
|
|
706
712
|
},
|
|
707
713
|
buildStart() {
|
|
708
714
|
buildErrors = [];
|
|
709
715
|
processedErrors.clear();
|
|
710
|
-
console.log("
|
|
716
|
+
console.log("🔍 [调试] buildStart 已执行");
|
|
711
717
|
},
|
|
712
718
|
// 解析模块时捕获错误
|
|
713
719
|
async resolveId(source, importer, options2) {
|
|
@@ -720,10 +726,10 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
720
726
|
// Rollup 钩子:模块解析完成后调用
|
|
721
727
|
moduleParsed(moduleInfo) {
|
|
722
728
|
if (moduleInfo.meta && moduleInfo.meta.error) {
|
|
723
|
-
console.log("\n
|
|
729
|
+
console.log("\n⚠️ moduleParsed 检测到错误:", moduleInfo.id);
|
|
724
730
|
let code = void 0;
|
|
725
|
-
if (moduleInfo.id &&
|
|
726
|
-
code =
|
|
731
|
+
if (moduleInfo.id && fs2.existsSync(moduleInfo.id)) {
|
|
732
|
+
code = fs2.readFileSync(moduleInfo.id, "utf-8");
|
|
727
733
|
}
|
|
728
734
|
const errorInfo = {
|
|
729
735
|
type: "module",
|
|
@@ -736,18 +742,18 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
736
742
|
}
|
|
737
743
|
},
|
|
738
744
|
buildEnd(error) {
|
|
739
|
-
console.log("
|
|
745
|
+
console.log("🔍 [调试] buildEnd 已执行, 有错误:", !!error);
|
|
740
746
|
if (error) {
|
|
741
|
-
console.log("\n
|
|
747
|
+
console.log("\n⚠️ buildEnd 捕获到错误:", error.message);
|
|
742
748
|
const realFilePath = extractSourceFile(error, lastTransformFile);
|
|
743
749
|
let code = void 0;
|
|
744
|
-
if (realFilePath &&
|
|
750
|
+
if (realFilePath && fs2.existsSync(realFilePath)) {
|
|
745
751
|
try {
|
|
746
|
-
code =
|
|
747
|
-
console.log(
|
|
748
|
-
console.log(
|
|
752
|
+
code = fs2.readFileSync(realFilePath, "utf-8");
|
|
753
|
+
console.log(`📂 读取源文件成功: ${realFilePath}`);
|
|
754
|
+
console.log(`📄 源文件长度: ${code.length} 字符`);
|
|
749
755
|
} catch (e) {
|
|
750
|
-
console.warn("
|
|
756
|
+
console.warn("⚠️ 无法读取文件:", realFilePath);
|
|
751
757
|
}
|
|
752
758
|
}
|
|
753
759
|
const errorInfo = {
|
|
@@ -762,21 +768,21 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
762
768
|
},
|
|
763
769
|
// Rollup 输出生成阶段的钩子
|
|
764
770
|
renderStart(outputOptions, inputOptions) {
|
|
765
|
-
console.log("
|
|
771
|
+
console.log("🔍 [调试] renderStart 已执行");
|
|
766
772
|
},
|
|
767
773
|
renderError(error) {
|
|
768
|
-
console.log("
|
|
774
|
+
console.log("🔍 [调试] renderError 已执行");
|
|
769
775
|
if (!error) return;
|
|
770
|
-
console.log("\n
|
|
776
|
+
console.log("\n⚠️ renderError 捕获到错误:", error.message);
|
|
771
777
|
const realFilePath = extractSourceFile(error, lastTransformFile);
|
|
772
778
|
let code = void 0;
|
|
773
|
-
if (realFilePath &&
|
|
779
|
+
if (realFilePath && fs2.existsSync(realFilePath)) {
|
|
774
780
|
try {
|
|
775
|
-
code =
|
|
776
|
-
console.log(
|
|
777
|
-
console.log(
|
|
781
|
+
code = fs2.readFileSync(realFilePath, "utf-8");
|
|
782
|
+
console.log(`📂 读取源文件成功: ${realFilePath}`);
|
|
783
|
+
console.log(`📄 源文件长度: ${code.length} 字符`);
|
|
778
784
|
} catch (e) {
|
|
779
|
-
console.warn("
|
|
785
|
+
console.warn("⚠️ 无法读取文件:", realFilePath);
|
|
780
786
|
}
|
|
781
787
|
}
|
|
782
788
|
const errorInfo = {
|
|
@@ -790,20 +796,20 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
790
796
|
},
|
|
791
797
|
// 监听所有阶段的错误
|
|
792
798
|
watchChange(id, change) {
|
|
793
|
-
console.log("
|
|
799
|
+
console.log("🔍 [调试] watchChange:", id);
|
|
794
800
|
},
|
|
795
801
|
async closeBundle() {
|
|
796
802
|
if (buildErrors.length > 0) {
|
|
797
803
|
console.log(
|
|
798
804
|
`
|
|
799
|
-
|
|
805
|
+
🔍 [调试] closeBundle 检测到 ${buildErrors.length} 个错误
|
|
800
806
|
`
|
|
801
807
|
);
|
|
802
808
|
for (const error of buildErrors) {
|
|
803
809
|
await processError(error);
|
|
804
810
|
}
|
|
805
811
|
} else {
|
|
806
|
-
console.log("
|
|
812
|
+
console.log("✨ 构建完成,未检测到错误\n");
|
|
807
813
|
}
|
|
808
814
|
},
|
|
809
815
|
transform(code, id) {
|
|
@@ -811,7 +817,7 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
811
817
|
try {
|
|
812
818
|
return null;
|
|
813
819
|
} catch (error) {
|
|
814
|
-
console.log("\n
|
|
820
|
+
console.log("\n⚠️ transform 捕获到错误:", error.message);
|
|
815
821
|
buildErrors.push({
|
|
816
822
|
type: "transform",
|
|
817
823
|
message: error.message,
|
|
@@ -825,7 +831,8 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
825
831
|
};
|
|
826
832
|
}
|
|
827
833
|
var index_default = vitePluginAIDiagnostic;
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
834
|
+
export {
|
|
835
|
+
index_default as default,
|
|
836
|
+
vitePluginAIDiagnostic
|
|
837
|
+
};
|
|
831
838
|
//# sourceMappingURL=index.mjs.map
|