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.js
CHANGED
|
@@ -1,28 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
29
|
|
|
17
30
|
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
default: () => index_default,
|
|
34
|
+
vitePluginAIDiagnostic: () => vitePluginAIDiagnostic
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
var import_fs2 = __toESM(require("fs"));
|
|
38
|
+
|
|
39
|
+
// src/langgraph.ts
|
|
40
|
+
var import_langgraph = require("@langchain/langgraph");
|
|
41
|
+
var import_openai = require("@langchain/openai");
|
|
42
|
+
var import_messages = require("@langchain/core/messages");
|
|
18
43
|
var DiagnosticGraph = class {
|
|
19
44
|
constructor(apiKey, apiUrl, model = "gpt-4", maxRetries = 3) {
|
|
20
45
|
this.maxRetries = maxRetries;
|
|
21
|
-
console.log("
|
|
22
|
-
console.log("
|
|
23
|
-
console.log("
|
|
24
|
-
console.log("
|
|
25
|
-
this.llm = new
|
|
46
|
+
console.log("🔧 [LangGraph] 初始化 LLM...");
|
|
47
|
+
console.log("📝 [配置] 模型:", model);
|
|
48
|
+
console.log("📝 [配置] API URL:", apiUrl);
|
|
49
|
+
console.log("📝 [配置] API Key:", apiKey ? "已配置" : "未配置");
|
|
50
|
+
this.llm = new import_openai.ChatOpenAI({
|
|
26
51
|
openAIApiKey: apiKey,
|
|
27
52
|
configuration: {
|
|
28
53
|
baseURL: apiUrl
|
|
@@ -34,7 +59,7 @@ var DiagnosticGraph = class {
|
|
|
34
59
|
this.graph = this.buildGraph();
|
|
35
60
|
}
|
|
36
61
|
buildGraph() {
|
|
37
|
-
const workflow = new
|
|
62
|
+
const workflow = new import_langgraph.StateGraph({
|
|
38
63
|
channels: {
|
|
39
64
|
error: null,
|
|
40
65
|
analysis: null,
|
|
@@ -48,27 +73,27 @@ var DiagnosticGraph = class {
|
|
|
48
73
|
});
|
|
49
74
|
workflow.addNode("analyze", this.analyzeNode.bind(this));
|
|
50
75
|
workflow.addNode("suggest", this.suggestNode.bind(this));
|
|
51
|
-
workflow.addEdge(
|
|
76
|
+
workflow.addEdge(import_langgraph.START, "analyze");
|
|
52
77
|
workflow.addEdge("analyze", "suggest");
|
|
53
|
-
workflow.addEdge("suggest",
|
|
78
|
+
workflow.addEdge("suggest", import_langgraph.END);
|
|
54
79
|
return workflow.compile();
|
|
55
80
|
}
|
|
56
81
|
async analyzeNode(state) {
|
|
57
|
-
console.log("
|
|
58
|
-
const systemPrompt = new
|
|
59
|
-
"
|
|
82
|
+
console.log("🔍 [LangGraph] 正在分析错误...");
|
|
83
|
+
const systemPrompt = new import_messages.SystemMessage(
|
|
84
|
+
"你是一个专业的前端代码诊断专家,精通 Vue3、TypeScript、Vite 和 uni-app。请简洁明了地分析问题。"
|
|
60
85
|
);
|
|
61
|
-
const userPrompt = new
|
|
62
|
-
|
|
86
|
+
const userPrompt = new import_messages.HumanMessage(`
|
|
87
|
+
请分析以下构建错误:
|
|
63
88
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
89
|
+
错误类型: ${state.error.type}
|
|
90
|
+
错误信息: ${state.error.message}
|
|
91
|
+
文件路径: ${state.error.file || "未知"}
|
|
67
92
|
|
|
68
|
-
|
|
69
|
-
1.
|
|
70
|
-
2.
|
|
71
|
-
3.
|
|
93
|
+
请简洁地说明(3-5句话):
|
|
94
|
+
1. 错误的根本原因
|
|
95
|
+
2. 影响范围
|
|
96
|
+
3. 严重程度
|
|
72
97
|
`);
|
|
73
98
|
const response = await this.llm.invoke([systemPrompt, userPrompt]);
|
|
74
99
|
const analysis = response.content.toString();
|
|
@@ -78,25 +103,25 @@ var DiagnosticGraph = class {
|
|
|
78
103
|
};
|
|
79
104
|
}
|
|
80
105
|
async suggestNode(state) {
|
|
81
|
-
console.log("
|
|
82
|
-
const userPrompt = new
|
|
83
|
-
|
|
106
|
+
console.log("💡 [LangGraph] 正在生成修复建议...");
|
|
107
|
+
const userPrompt = new import_messages.HumanMessage(`
|
|
108
|
+
基于以下错误分析,请提供具体的修复建议:
|
|
84
109
|
|
|
85
|
-
|
|
110
|
+
错误分析:
|
|
86
111
|
${state.analysis}
|
|
87
112
|
|
|
88
|
-
|
|
89
|
-
-
|
|
90
|
-
-
|
|
91
|
-
-
|
|
113
|
+
错误详情:
|
|
114
|
+
- 类型: ${state.error.type}
|
|
115
|
+
- 信息: ${state.error.message}
|
|
116
|
+
- 文件: ${state.error.file || "未知"}
|
|
92
117
|
|
|
93
|
-
|
|
94
|
-
1.
|
|
95
|
-
2.
|
|
96
|
-
3.
|
|
97
|
-
4.
|
|
118
|
+
请简洁地提供:
|
|
119
|
+
1. 具体的修复步骤(3-5步即可)
|
|
120
|
+
2. 需要修改的代码位置(行号)
|
|
121
|
+
3. 修改后的代码示例(只显示关键部分)
|
|
122
|
+
4. 一句话预防建议
|
|
98
123
|
|
|
99
|
-
|
|
124
|
+
注意:请直接给出建议,不要重复错误分析的内容。
|
|
100
125
|
`);
|
|
101
126
|
const response = await this.llm.invoke([...state.messages, userPrompt]);
|
|
102
127
|
const suggestion = response.content.toString();
|
|
@@ -186,12 +211,12 @@ ${state.analysis}
|
|
|
186
211
|
messages: []
|
|
187
212
|
};
|
|
188
213
|
try {
|
|
189
|
-
console.log("
|
|
214
|
+
console.log("🚀 [LangGraph] 启动诊断工作流...\n");
|
|
190
215
|
const result = await this.graph.invoke(initialState);
|
|
191
|
-
console.log("
|
|
216
|
+
console.log("✨ [LangGraph] 诊断工作流完成\n");
|
|
192
217
|
return result;
|
|
193
218
|
} catch (error2) {
|
|
194
|
-
console.error("
|
|
219
|
+
console.error("❌ [LangGraph] 工作流执行失败:", error2.message);
|
|
195
220
|
throw error2;
|
|
196
221
|
}
|
|
197
222
|
}
|
|
@@ -211,8 +236,8 @@ var AIErrorDiagnostic = class {
|
|
|
211
236
|
async diagnose(error, autoFix = false) {
|
|
212
237
|
if (!this.options.apiKey) {
|
|
213
238
|
return {
|
|
214
|
-
analysis: "
|
|
215
|
-
suggestion: "
|
|
239
|
+
analysis: "未配置 API Key,无法使用 AI 诊断功能",
|
|
240
|
+
suggestion: "请在 .env 文件中配置 OPENAI_API_KEY",
|
|
216
241
|
fixedCode: void 0,
|
|
217
242
|
filePath: void 0
|
|
218
243
|
};
|
|
@@ -227,10 +252,10 @@ var AIErrorDiagnostic = class {
|
|
|
227
252
|
filePath: void 0
|
|
228
253
|
};
|
|
229
254
|
} catch (error2) {
|
|
230
|
-
console.error("
|
|
255
|
+
console.error("❌ AI 诊断失败:", error2.message);
|
|
231
256
|
return {
|
|
232
|
-
analysis:
|
|
233
|
-
suggestion: "
|
|
257
|
+
analysis: `诊断过程出错: ${error2.message}`,
|
|
258
|
+
suggestion: "请检查 API 配置和网络连接",
|
|
234
259
|
fixedCode: void 0,
|
|
235
260
|
filePath: void 0
|
|
236
261
|
};
|
|
@@ -252,6 +277,13 @@ var AIErrorDiagnostic = class {
|
|
|
252
277
|
// }
|
|
253
278
|
// }
|
|
254
279
|
};
|
|
280
|
+
|
|
281
|
+
// src/index.ts
|
|
282
|
+
var import_vite_plugin_ai_shared = require("vite-plugin-ai-shared");
|
|
283
|
+
|
|
284
|
+
// src/reporter.ts
|
|
285
|
+
var import_fs = __toESM(require("fs"));
|
|
286
|
+
var import_path = __toESM(require("path"));
|
|
255
287
|
var DiagnosticReporter = class {
|
|
256
288
|
/**
|
|
257
289
|
* 生成报告(根据配置生成多种格式)
|
|
@@ -277,7 +309,7 @@ var DiagnosticReporter = class {
|
|
|
277
309
|
<head>
|
|
278
310
|
<meta charset="UTF-8">
|
|
279
311
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
280
|
-
<title>AI
|
|
312
|
+
<title>AI 诊断报告</title>
|
|
281
313
|
<style>
|
|
282
314
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
283
315
|
body {
|
|
@@ -436,48 +468,48 @@ var DiagnosticReporter = class {
|
|
|
436
468
|
<body>
|
|
437
469
|
<div class="container">
|
|
438
470
|
<div class="header">
|
|
439
|
-
<h1
|
|
440
|
-
<div class="time"
|
|
471
|
+
<h1>🤖 AI 诊断报告</h1>
|
|
472
|
+
<div class="time">生成时间: ${report.timestamp}</div>
|
|
441
473
|
</div>
|
|
442
474
|
|
|
443
475
|
<div class="content">
|
|
444
|
-
<!--
|
|
476
|
+
<!-- 错误信息 -->
|
|
445
477
|
<div class="section">
|
|
446
|
-
<div class="section-title"
|
|
478
|
+
<div class="section-title">❌ 错误信息</div>
|
|
447
479
|
<div class="error-box">
|
|
448
480
|
<span class="error-type">${report.error.type}</span>
|
|
449
481
|
<div class="error-message">${this.escapeHtml(
|
|
450
482
|
report.error.message
|
|
451
483
|
)}</div>
|
|
452
|
-
<div class="error-file"
|
|
484
|
+
<div class="error-file">📂 ${report.error.file}</div>
|
|
453
485
|
${report.error.stack ? `<div class="stack-trace">${this.escapeHtml(
|
|
454
486
|
report.error.stack
|
|
455
487
|
)}</div>` : ""}
|
|
456
488
|
</div>
|
|
457
489
|
</div>
|
|
458
490
|
|
|
459
|
-
<!-- AI
|
|
491
|
+
<!-- AI 分析 -->
|
|
460
492
|
<div class="section">
|
|
461
|
-
<div class="section-title"
|
|
493
|
+
<div class="section-title">🔍 AI 分析</div>
|
|
462
494
|
<div class="analysis-box">
|
|
463
495
|
${this.formatText(report.analysis)}
|
|
464
496
|
</div>
|
|
465
497
|
</div>
|
|
466
498
|
|
|
467
|
-
<!--
|
|
499
|
+
<!-- 修复建议 -->
|
|
468
500
|
<div class="section">
|
|
469
|
-
<div class="section-title"
|
|
501
|
+
<div class="section-title">💡 修复建议</div>
|
|
470
502
|
<div class="suggestion-box">
|
|
471
503
|
${this.formatText(report.suggestion)}
|
|
472
504
|
</div>
|
|
473
505
|
</div>
|
|
474
506
|
|
|
475
|
-
<!--
|
|
507
|
+
<!-- 修复状态 -->
|
|
476
508
|
<div class="section">
|
|
477
|
-
<div class="section-title"
|
|
478
|
-
${report.fixed ? `<div class="fixed-badge"
|
|
479
|
-
<div style="margin-top: 10px; color: #666;"
|
|
480
|
-
<div style="margin-top: 10px; color: #666;"
|
|
509
|
+
<div class="section-title">🔧 修复状态</div>
|
|
510
|
+
${report.fixed ? `<div class="fixed-badge">✅ 已自动修复</div>
|
|
511
|
+
<div style="margin-top: 10px; color: #666;">修复文件: <code>${report.fixedFilePath}</code></div>` : `<div class="not-fixed-badge">⚠️ 未自动修复</div>
|
|
512
|
+
<div style="margin-top: 10px; color: #666;">请根据上述建议手动修复</div>`}
|
|
481
513
|
</div>
|
|
482
514
|
</div>
|
|
483
515
|
|
|
@@ -489,14 +521,14 @@ var DiagnosticReporter = class {
|
|
|
489
521
|
</body>
|
|
490
522
|
</html>
|
|
491
523
|
`.trim();
|
|
492
|
-
const reportsDir =
|
|
493
|
-
if (!
|
|
494
|
-
|
|
524
|
+
const reportsDir = import_path.default.resolve(process.cwd(), "ai-reports");
|
|
525
|
+
if (!import_fs.default.existsSync(reportsDir)) {
|
|
526
|
+
import_fs.default.mkdirSync(reportsDir, { recursive: true });
|
|
495
527
|
}
|
|
496
|
-
const reportPath =
|
|
497
|
-
|
|
528
|
+
const reportPath = import_path.default.resolve(reportsDir, "diagnostic-report.html");
|
|
529
|
+
import_fs.default.writeFileSync(reportPath, html, "utf-8");
|
|
498
530
|
console.log(`
|
|
499
|
-
|
|
531
|
+
📄 诊断报告已生成: ${reportPath}
|
|
500
532
|
`);
|
|
501
533
|
}
|
|
502
534
|
/**
|
|
@@ -534,22 +566,22 @@ var DiagnosticReporter = class {
|
|
|
534
566
|
* 生成 Markdown 报告
|
|
535
567
|
*/
|
|
536
568
|
static async generateMarkdownReport(report) {
|
|
537
|
-
const markdown = `#
|
|
569
|
+
const markdown = `# 🤖 AI 诊断报告
|
|
538
570
|
|
|
539
|
-
|
|
571
|
+
**生成时间**: ${report.timestamp}
|
|
540
572
|
|
|
541
573
|
---
|
|
542
574
|
|
|
543
|
-
##
|
|
575
|
+
## ❌ 错误信息
|
|
544
576
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
577
|
+
**类型**: \`${report.error.type}\`
|
|
578
|
+
**文件**: \`${report.error.file}\`
|
|
579
|
+
**消息**:
|
|
548
580
|
\`\`\`
|
|
549
581
|
${report.error.message}
|
|
550
582
|
\`\`\`
|
|
551
583
|
|
|
552
|
-
${report.error.stack ?
|
|
584
|
+
${report.error.stack ? `**堆栈跟踪**:
|
|
553
585
|
\`\`\`
|
|
554
586
|
${report.error.stack}
|
|
555
587
|
\`\`\`
|
|
@@ -557,38 +589,38 @@ ${report.error.stack}
|
|
|
557
589
|
|
|
558
590
|
---
|
|
559
591
|
|
|
560
|
-
##
|
|
592
|
+
## 🔍 AI 分析
|
|
561
593
|
|
|
562
594
|
${report.analysis}
|
|
563
595
|
|
|
564
596
|
---
|
|
565
597
|
|
|
566
|
-
##
|
|
598
|
+
## 💡 修复建议
|
|
567
599
|
|
|
568
600
|
${report.suggestion}
|
|
569
601
|
|
|
570
602
|
---
|
|
571
603
|
|
|
572
|
-
##
|
|
604
|
+
## 🔧 修复状态
|
|
573
605
|
|
|
574
|
-
${report.fixed ?
|
|
606
|
+
${report.fixed ? `✅ **已自动修复**
|
|
575
607
|
|
|
576
|
-
|
|
608
|
+
修复文件: \`${report.fixedFilePath}\`` : `⚠️ **未自动修复**
|
|
577
609
|
|
|
578
|
-
|
|
610
|
+
请根据上述建议手动修复`}
|
|
579
611
|
|
|
580
612
|
---
|
|
581
613
|
|
|
582
614
|
*AI Diagnostic Plugin v1.0.0*
|
|
583
615
|
*Powered by LangGraph & OpenAI*
|
|
584
616
|
`;
|
|
585
|
-
const reportsDir =
|
|
586
|
-
if (!
|
|
587
|
-
|
|
617
|
+
const reportsDir = import_path.default.resolve(process.cwd(), "ai-reports");
|
|
618
|
+
if (!import_fs.default.existsSync(reportsDir)) {
|
|
619
|
+
import_fs.default.mkdirSync(reportsDir, { recursive: true });
|
|
588
620
|
}
|
|
589
|
-
const reportPath =
|
|
590
|
-
|
|
591
|
-
console.log(
|
|
621
|
+
const reportPath = import_path.default.resolve(reportsDir, "diagnostic-report.md");
|
|
622
|
+
import_fs.default.writeFileSync(reportPath, markdown, "utf-8");
|
|
623
|
+
console.log(`📄 Markdown 报告已生成: ${reportPath}`);
|
|
592
624
|
}
|
|
593
625
|
/**
|
|
594
626
|
* 生成 JSON 报告
|
|
@@ -612,13 +644,13 @@ ${report.fixed ? `\u2705 **\u5DF2\u81EA\u52A8\u4FEE\u590D**
|
|
|
612
644
|
filePath: report.fixedFilePath || null
|
|
613
645
|
}
|
|
614
646
|
};
|
|
615
|
-
const reportsDir =
|
|
616
|
-
if (!
|
|
617
|
-
|
|
647
|
+
const reportsDir = import_path.default.resolve(process.cwd(), "ai-reports");
|
|
648
|
+
if (!import_fs.default.existsSync(reportsDir)) {
|
|
649
|
+
import_fs.default.mkdirSync(reportsDir, { recursive: true });
|
|
618
650
|
}
|
|
619
|
-
const reportPath =
|
|
620
|
-
|
|
621
|
-
console.log(
|
|
651
|
+
const reportPath = import_path.default.resolve(reportsDir, "diagnostic-report.json");
|
|
652
|
+
import_fs.default.writeFileSync(reportPath, JSON.stringify(jsonReport, null, 2), "utf-8");
|
|
653
|
+
console.log(`📄 JSON 报告已生成: ${reportPath}`);
|
|
622
654
|
}
|
|
623
655
|
};
|
|
624
656
|
|
|
@@ -649,38 +681,38 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
649
681
|
async function processError(error) {
|
|
650
682
|
const errorKey = `${error.file}:${error.message}`;
|
|
651
683
|
if (processedErrors.has(errorKey)) {
|
|
652
|
-
console.log("
|
|
684
|
+
console.log("🔍 [调试] 跳过重复错误:", errorKey);
|
|
653
685
|
return;
|
|
654
686
|
}
|
|
655
687
|
processedErrors.add(errorKey);
|
|
656
688
|
try {
|
|
657
|
-
console.log("\n
|
|
658
|
-
console.log(
|
|
659
|
-
console.log(
|
|
689
|
+
console.log("\n⚠️ 检测到错误,正在使用 AI 分析...\n");
|
|
690
|
+
console.log(`📝 错误信息: ${error.message}`);
|
|
691
|
+
console.log(`📂 文件路径: ${error.file || "未知"}`);
|
|
660
692
|
console.log(
|
|
661
|
-
|
|
693
|
+
`📄 代码长度: ${error.code ? error.code.length + " 字符" : "无"}`
|
|
662
694
|
);
|
|
663
|
-
console.log(
|
|
695
|
+
console.log(`🔧 自动修复: ${autoFix ? "是" : "否"}
|
|
664
696
|
`);
|
|
665
697
|
if (!error.file || !error.code) {
|
|
666
|
-
console.log("
|
|
698
|
+
console.log("⚠️ 跳过此错误:缺少文件路径或代码内容\n");
|
|
667
699
|
return;
|
|
668
700
|
}
|
|
669
701
|
const result = await diagnostic.diagnose(error, autoFix);
|
|
670
702
|
if (output.console !== false) {
|
|
671
|
-
console.log("
|
|
672
|
-
console.log("
|
|
703
|
+
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
704
|
+
console.log("🔍 错误分析:");
|
|
673
705
|
console.log(result.analysis);
|
|
674
|
-
console.log("\n
|
|
706
|
+
console.log("\n💡 修复建议:");
|
|
675
707
|
console.log(result.suggestion);
|
|
676
708
|
if (result.fixedCode && result.filePath) {
|
|
677
|
-
console.log("\n
|
|
678
|
-
console.log("
|
|
679
|
-
console.log("\n
|
|
709
|
+
console.log("\n✅ 已自动修复代码");
|
|
710
|
+
console.log("修复的文件:", result.filePath);
|
|
711
|
+
console.log("\n💡 请重新运行构建命令");
|
|
680
712
|
} else if (autoFix) {
|
|
681
|
-
console.log("\n
|
|
713
|
+
console.log("\n⚠️ 无法自动修复:AI 未生成修复代码");
|
|
682
714
|
}
|
|
683
|
-
console.log("
|
|
715
|
+
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
|
|
684
716
|
}
|
|
685
717
|
const report = {
|
|
686
718
|
timestamp: (/* @__PURE__ */ new Date()).toLocaleString("zh-CN"),
|
|
@@ -697,7 +729,7 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
697
729
|
};
|
|
698
730
|
await DiagnosticReporter.generate(report, output);
|
|
699
731
|
} catch (err) {
|
|
700
|
-
console.error("
|
|
732
|
+
console.error("❌ AI 诊断失败:", err.message);
|
|
701
733
|
}
|
|
702
734
|
}
|
|
703
735
|
return {
|
|
@@ -705,18 +737,18 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
705
737
|
// 确保插件在其他插件之后执行,以捕获更多错误
|
|
706
738
|
enforce: "post",
|
|
707
739
|
configResolved(config) {
|
|
708
|
-
console.log("\n
|
|
709
|
-
console.log(
|
|
710
|
-
console.log(
|
|
740
|
+
console.log("\n🤖 AI 诊断助手已启动...");
|
|
741
|
+
console.log(`⚙️ 自动修复: ${autoFix ? "✅ 已启用" : "❌ 未启用"}`);
|
|
742
|
+
console.log(`📝 根目录: ${config.root}`);
|
|
711
743
|
console.log(
|
|
712
|
-
|
|
744
|
+
`📝 入口: ${config.build.rollupOptions?.input || "index.html"}
|
|
713
745
|
`
|
|
714
746
|
);
|
|
715
747
|
},
|
|
716
748
|
buildStart() {
|
|
717
749
|
buildErrors = [];
|
|
718
750
|
processedErrors.clear();
|
|
719
|
-
console.log("
|
|
751
|
+
console.log("🔍 [调试] buildStart 已执行");
|
|
720
752
|
},
|
|
721
753
|
// 解析模块时捕获错误
|
|
722
754
|
async resolveId(source, importer, options2) {
|
|
@@ -729,10 +761,10 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
729
761
|
// Rollup 钩子:模块解析完成后调用
|
|
730
762
|
moduleParsed(moduleInfo) {
|
|
731
763
|
if (moduleInfo.meta && moduleInfo.meta.error) {
|
|
732
|
-
console.log("\n
|
|
764
|
+
console.log("\n⚠️ moduleParsed 检测到错误:", moduleInfo.id);
|
|
733
765
|
let code = void 0;
|
|
734
|
-
if (moduleInfo.id &&
|
|
735
|
-
code =
|
|
766
|
+
if (moduleInfo.id && import_fs2.default.existsSync(moduleInfo.id)) {
|
|
767
|
+
code = import_fs2.default.readFileSync(moduleInfo.id, "utf-8");
|
|
736
768
|
}
|
|
737
769
|
const errorInfo = {
|
|
738
770
|
type: "module",
|
|
@@ -745,18 +777,18 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
745
777
|
}
|
|
746
778
|
},
|
|
747
779
|
buildEnd(error) {
|
|
748
|
-
console.log("
|
|
780
|
+
console.log("🔍 [调试] buildEnd 已执行, 有错误:", !!error);
|
|
749
781
|
if (error) {
|
|
750
|
-
console.log("\n
|
|
751
|
-
const realFilePath =
|
|
782
|
+
console.log("\n⚠️ buildEnd 捕获到错误:", error.message);
|
|
783
|
+
const realFilePath = (0, import_vite_plugin_ai_shared.extractSourceFile)(error, lastTransformFile);
|
|
752
784
|
let code = void 0;
|
|
753
|
-
if (realFilePath &&
|
|
785
|
+
if (realFilePath && import_fs2.default.existsSync(realFilePath)) {
|
|
754
786
|
try {
|
|
755
|
-
code =
|
|
756
|
-
console.log(
|
|
757
|
-
console.log(
|
|
787
|
+
code = import_fs2.default.readFileSync(realFilePath, "utf-8");
|
|
788
|
+
console.log(`📂 读取源文件成功: ${realFilePath}`);
|
|
789
|
+
console.log(`📄 源文件长度: ${code.length} 字符`);
|
|
758
790
|
} catch (e) {
|
|
759
|
-
console.warn("
|
|
791
|
+
console.warn("⚠️ 无法读取文件:", realFilePath);
|
|
760
792
|
}
|
|
761
793
|
}
|
|
762
794
|
const errorInfo = {
|
|
@@ -771,21 +803,21 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
771
803
|
},
|
|
772
804
|
// Rollup 输出生成阶段的钩子
|
|
773
805
|
renderStart(outputOptions, inputOptions) {
|
|
774
|
-
console.log("
|
|
806
|
+
console.log("🔍 [调试] renderStart 已执行");
|
|
775
807
|
},
|
|
776
808
|
renderError(error) {
|
|
777
|
-
console.log("
|
|
809
|
+
console.log("🔍 [调试] renderError 已执行");
|
|
778
810
|
if (!error) return;
|
|
779
|
-
console.log("\n
|
|
780
|
-
const realFilePath =
|
|
811
|
+
console.log("\n⚠️ renderError 捕获到错误:", error.message);
|
|
812
|
+
const realFilePath = (0, import_vite_plugin_ai_shared.extractSourceFile)(error, lastTransformFile);
|
|
781
813
|
let code = void 0;
|
|
782
|
-
if (realFilePath &&
|
|
814
|
+
if (realFilePath && import_fs2.default.existsSync(realFilePath)) {
|
|
783
815
|
try {
|
|
784
|
-
code =
|
|
785
|
-
console.log(
|
|
786
|
-
console.log(
|
|
816
|
+
code = import_fs2.default.readFileSync(realFilePath, "utf-8");
|
|
817
|
+
console.log(`📂 读取源文件成功: ${realFilePath}`);
|
|
818
|
+
console.log(`📄 源文件长度: ${code.length} 字符`);
|
|
787
819
|
} catch (e) {
|
|
788
|
-
console.warn("
|
|
820
|
+
console.warn("⚠️ 无法读取文件:", realFilePath);
|
|
789
821
|
}
|
|
790
822
|
}
|
|
791
823
|
const errorInfo = {
|
|
@@ -799,20 +831,20 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
799
831
|
},
|
|
800
832
|
// 监听所有阶段的错误
|
|
801
833
|
watchChange(id, change) {
|
|
802
|
-
console.log("
|
|
834
|
+
console.log("🔍 [调试] watchChange:", id);
|
|
803
835
|
},
|
|
804
836
|
async closeBundle() {
|
|
805
837
|
if (buildErrors.length > 0) {
|
|
806
838
|
console.log(
|
|
807
839
|
`
|
|
808
|
-
|
|
840
|
+
🔍 [调试] closeBundle 检测到 ${buildErrors.length} 个错误
|
|
809
841
|
`
|
|
810
842
|
);
|
|
811
843
|
for (const error of buildErrors) {
|
|
812
844
|
await processError(error);
|
|
813
845
|
}
|
|
814
846
|
} else {
|
|
815
|
-
console.log("
|
|
847
|
+
console.log("✨ 构建完成,未检测到错误\n");
|
|
816
848
|
}
|
|
817
849
|
},
|
|
818
850
|
transform(code, id) {
|
|
@@ -820,7 +852,7 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
820
852
|
try {
|
|
821
853
|
return null;
|
|
822
854
|
} catch (error) {
|
|
823
|
-
console.log("\n
|
|
855
|
+
console.log("\n⚠️ transform 捕获到错误:", error.message);
|
|
824
856
|
buildErrors.push({
|
|
825
857
|
type: "transform",
|
|
826
858
|
message: error.message,
|
|
@@ -834,8 +866,8 @@ function vitePluginAIDiagnostic(options = {}) {
|
|
|
834
866
|
};
|
|
835
867
|
}
|
|
836
868
|
var index_default = vitePluginAIDiagnostic;
|
|
837
|
-
|
|
838
|
-
exports
|
|
839
|
-
|
|
840
|
-
|
|
869
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
870
|
+
0 && (module.exports = {
|
|
871
|
+
vitePluginAIDiagnostic
|
|
872
|
+
});
|
|
841
873
|
//# sourceMappingURL=index.js.map
|