weapp-vite 7.5.0 → 7.7.0

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.
Files changed (135) hide show
  1. package/README.md +14 -6
  2. package/THIRD_PARTY_NOTICES.md +60 -0
  3. package/bin/bootstrap.js +9 -4
  4. package/bin/bootstrap.test.ts +82 -1
  5. package/bin/nodeVersionWarning.js +17 -0
  6. package/bin/nodeVersionWarning.test.ts +30 -0
  7. package/dist/action-BD56SQh4.mjs +254 -0
  8. package/dist/action-CPtgEl6p.mjs +94 -0
  9. package/dist/action-le0bNff_.mjs +1102 -0
  10. package/dist/action-ytG5oFAw.mjs +138 -0
  11. package/dist/action-zmJrU8PC.mjs +245 -0
  12. package/dist/{analyze-ZJUvEdaY.mjs → analyze-DCZo-sJd.mjs} +4 -71
  13. package/dist/artifacts-TrTX9_jj.mjs +104 -0
  14. package/dist/assets-XyhpYtGl.mjs +630 -0
  15. package/dist/auto-import-components/resolvers.d.mts +1 -1
  16. package/dist/auto-import-components/resolvers.mjs +1 -1
  17. package/dist/auto-import-presets/wevu-router.d.mts +1 -1
  18. package/dist/auto-import-presets/wevu-router.mjs +1 -1
  19. package/dist/auto-import-presets/wevu.d.mts +1 -1
  20. package/dist/auto-import-presets/wevu.mjs +1 -1
  21. package/dist/auto-import-presets.d.mts +2 -2
  22. package/dist/auto-import-presets.mjs +2 -2
  23. package/dist/auto-routes.d.mts +1 -3
  24. package/dist/auto-routes.mjs +3 -4
  25. package/dist/{budget-BD7VqLCl.d.mts → budget-DTPngJU0.d.mts} +1 -10
  26. package/dist/budget-_Mu-4GKn.mjs +63 -0
  27. package/dist/builtProject-B145uOt5.mjs +534 -0
  28. package/dist/{package-7swhyLmf.mjs → classifier-CNTJOYQL.mjs} +5 -9
  29. package/dist/cli-acceptance.mjs +3 -4
  30. package/dist/cli.mjs +142 -4569
  31. package/dist/{config-DRGcCi3h.mjs → config-59ZWhCIf.mjs} +1 -2
  32. package/dist/{config-V0L-IAJf.d.mts → config-BNx2BODw.d.mts} +145 -150
  33. package/dist/config.d.mts +2 -2
  34. package/dist/config.mjs +3 -3
  35. package/dist/{constants-DEZdcsMn.mjs → constants-BOe8mgqL.mjs} +2 -4
  36. package/dist/{createCompilerContextInstance-DJH_P_nZ.mjs → createCompilerContextInstance-BXSdH2E8.mjs} +19930 -14019
  37. package/dist/{createContext-BqYzHhY9.mjs → createContext-W0TeXxbo.mjs} +7 -5
  38. package/dist/dashboard/analyze.d.mts +1 -7
  39. package/dist/dashboard/analyze.mjs +3 -1
  40. package/dist/dashboard/vite.d.mts +2 -4
  41. package/dist/dashboard/vite.mjs +1 -2
  42. package/dist/dashboard.d.mts +2 -2
  43. package/dist/dashboard.mjs +1733 -1
  44. package/dist/dashboardTransport-C9290QgS.mjs +15 -0
  45. package/dist/{dashboardViteBridge-Dy3nAD4m.mjs → dashboardViteBridge-B7QgQo94.mjs} +11 -11
  46. package/dist/{dev-fR5GiJRO.mjs → dev-D1QSExwk.mjs} +6 -3
  47. package/dist/devProvider-Bcvz5nu4.mjs +4966 -0
  48. package/dist/docs/README.md +14 -6
  49. package/dist/docs/ai-workflows.md +2 -0
  50. package/dist/docs/mcp.md +11 -1
  51. package/dist/docs/troubleshooting.md +16 -0
  52. package/dist/docs/vue-sfc.md +25 -2
  53. package/dist/docs/weapp-config.md +29 -0
  54. package/dist/docs/wevu-authoring.md +2 -0
  55. package/dist/doctor-worker.mjs +5 -5
  56. package/dist/doctor.d.mts +2 -8
  57. package/dist/doctor.mjs +24 -31
  58. package/dist/engine-Mnnm_ALP.mjs +53 -0
  59. package/dist/file-5eEfbK60.mjs +1 -0
  60. package/dist/{file-sC3jD7Fh.mjs → file-D8mp5GmB.mjs} +50 -26
  61. package/dist/{files-BqxFIPRp.mjs → files-Cy9jURJu.mjs} +1 -2
  62. package/dist/forwardConsole-D2Q0RIqc.mjs +509 -0
  63. package/dist/getInstance-BXNVH7sU.mjs +1 -0
  64. package/dist/{getInstance-DiGSzBNI.mjs → getInstance-DfNlbr-X.mjs} +2 -3
  65. package/dist/history-dKxzoHmN.mjs +774 -0
  66. package/dist/i18n.d.mts +1 -3
  67. package/dist/i18n.mjs +1 -2
  68. package/dist/{index-C9HjUX5c.d.mts → index-DIZJRrvK.d.mts} +1 -24
  69. package/dist/{index-CaXAtb9e.d.mts → index-SnaW3cvA.d.mts} +0 -12
  70. package/dist/index.d.mts +3 -7
  71. package/dist/index.mjs +6 -6
  72. package/dist/{json-BL8Dhhk6.mjs → json-Cvon2mw5.mjs} +1 -2
  73. package/dist/json.d.mts +1 -1
  74. package/dist/json.mjs +1 -1
  75. package/dist/lib-CJyMBzoe.mjs +140 -0
  76. package/dist/{lifecycle-BROTlwSL.mjs → lifecycle-CUo8PMQc.mjs} +123 -33
  77. package/dist/{loadConfig-C3BQhz7F.mjs → loadConfig-CKIdfW4o.mjs} +2 -3
  78. package/dist/loadConfig-D4WGJcYp.mjs +1 -0
  79. package/dist/logBuildAppFinish-DOBoof6S.mjs +54 -0
  80. package/dist/mcp-D88QvQgG.mjs +84 -0
  81. package/dist/{mcp-Cj8Maqo6.mjs → mcp-ovJgl1N9.mjs} +2 -4
  82. package/dist/mcp.d.mts +1 -3
  83. package/dist/mcp.mjs +1 -1
  84. package/dist/mcpClient-C8JzVZ46.mjs +283 -0
  85. package/dist/{processCleanup-B6KA30Zc.mjs → metadata-HlDKtlsu.mjs} +2 -21
  86. package/dist/nodeEnv-zq1EymWj.mjs +6 -0
  87. package/dist/openIde-QoYKhuuM.mjs +643 -0
  88. package/dist/options-Cz8vZ-0w.mjs +33 -0
  89. package/dist/{chunkStrategy-DRA5WpB-.mjs → package-DR62fAzP.mjs} +32 -31
  90. package/dist/path-E1OjBJAl.mjs +43 -0
  91. package/dist/{platform-CnkySBKz.mjs → platform-BiMpsZIb.mjs} +1 -2
  92. package/dist/{pluginHost--CaeyWpA.mjs → pluginHost-vn8Vty1J.mjs} +1 -2
  93. package/dist/processCleanup-DzB64WI8.mjs +18 -0
  94. package/dist/{protocol-vg8HGJ4n.mjs → protocol-HiSJRrSO.mjs} +43 -41
  95. package/dist/reader-wzPH_W8A.mjs +92 -0
  96. package/dist/realpathScope-DwlLaCk3.mjs +22 -0
  97. package/dist/report-PJVyo-UZ.mjs +105 -0
  98. package/dist/{path-doV773b7.mjs → resolvedId-DaxPh_yV.mjs} +5 -50
  99. package/dist/{resolvers-Dod-euqX.mjs → resolvers-CKYqmRD_.mjs} +10 -20
  100. package/dist/resolvers.d.mts +1 -1
  101. package/dist/resolvers.mjs +1 -1
  102. package/dist/{routes-C7fCmf92.d.mts → routes-DvAFX29h.d.mts} +0 -2
  103. package/dist/{runtime-Ee2HY6gR.d.mts → runtime-BL4RjBRa.d.mts} +1 -9
  104. package/dist/runtime-CKtMVERT.mjs +42 -0
  105. package/dist/{runtime-D6VCNhNY.mjs → runtime-DDUCb7pP.mjs} +4 -8
  106. package/dist/runtime.d.mts +1 -1
  107. package/dist/runtime.mjs +1 -1
  108. package/dist/schematics-DikfOjMD.mjs +90 -0
  109. package/dist/{session-PskhD-nZ.mjs → session-COrQJYif.mjs} +81 -21
  110. package/dist/test.d.mts +1 -3
  111. package/dist/test.mjs +54 -30
  112. package/dist/types-BK2EQ3Jm.d.mts +37 -0
  113. package/dist/{types-CgZn5X6j.d.mts → types-e2BMP9NU.d.mts} +1 -4
  114. package/dist/types.d.mts +4 -4
  115. package/dist/{upload-D4msblBf.mjs → upload-Chal5b3w.mjs} +118 -24
  116. package/dist/upload-worker.mjs +3 -5
  117. package/dist/{utils-CJSCgEj6.mjs → utils-CTGSZp4j.mjs} +72 -146
  118. package/dist/vite.d.mts +2 -4
  119. package/dist/vite.mjs +55 -21
  120. package/dist/volar.mjs +1 -2
  121. package/dist/{wevu-BQWUU7br.mjs → wevu-BaihCXO9.mjs} +1 -2
  122. package/dist/wevu-DTtSOyxB.d.mts +3 -0
  123. package/dist/{wevu-router-Dg1LnBlg.mjs → wevu-router-BIoxDbnu.mjs} +1 -2
  124. package/dist/wevu-router-CdWurGQ4.d.mts +3 -0
  125. package/dist/wxs-7V7MPzeW.mjs +1 -0
  126. package/dist/wxs-BdHHXltv.mjs +110 -0
  127. package/package.json +62 -53
  128. package/dist/dashboard-DvqF3Key.mjs +0 -1842
  129. package/dist/devProvider-BGBkw28J.mjs +0 -1050
  130. package/dist/file-DRb4eWqw.mjs +0 -1
  131. package/dist/getInstance-SiE6WZRh.mjs +0 -1
  132. package/dist/loadConfig-VGtBF4qm.mjs +0 -1
  133. package/dist/mcp-D3Yh24Cj.mjs +0 -529
  134. package/dist/wevu-C4KEC5kO.d.mts +0 -5
  135. package/dist/wevu-router-Cg2sIkIE.d.mts +0 -5
@@ -0,0 +1,509 @@
1
+ import { l as resolveHmrProfileJsonPath } from "./devProvider-Bcvz5nu4.mjs";
2
+ import { r as logger_default, t as colors } from "./logger-DGn5iEVN.mjs";
3
+ import { a as resolveIdeProjectRoot, o as shouldUseAutomatorProjectWrapper } from "./openIde-QoYKhuuM.mjs";
4
+ import { t as readHmrProfileLines } from "./reader-wzPH_W8A.mjs";
5
+ import process from "node:process";
6
+ import { fs } from "@weapp-core/shared/fs";
7
+ import { isRetryableAutomatorLaunchError, resolveProjectAutomatorPort, startForwardConsole } from "weapp-ide-cli";
8
+ import { determineAgent } from "@vercel/detect-agent";
9
+ // src/cli/hmrProfileSummary.ts
10
+ function isFiniteNumber(value) {
11
+ return typeof value === "number" && Number.isFinite(value);
12
+ }
13
+ function formatPhaseHint(sample) {
14
+ const topPhase = [
15
+ {
16
+ label: "build-core",
17
+ value: sample.buildCoreMs
18
+ },
19
+ {
20
+ label: "transform",
21
+ value: sample.transformMs
22
+ },
23
+ {
24
+ label: "build-start",
25
+ value: sample.buildStartMs
26
+ },
27
+ {
28
+ label: "plugin-resolve",
29
+ value: sample.pluginResolveMs
30
+ },
31
+ {
32
+ label: "core-transform",
33
+ value: sample.coreTransformMs
34
+ },
35
+ {
36
+ label: "wevu-transform",
37
+ value: sample.wevuTransformMs
38
+ },
39
+ {
40
+ label: "vue-transform",
41
+ value: sample.vueTransformMs
42
+ },
43
+ {
44
+ label: "vue-read",
45
+ value: sample.vueReadSourceMs
46
+ },
47
+ {
48
+ label: "vue-compile",
49
+ value: sample.vueCompileMs
50
+ },
51
+ {
52
+ label: "vue-finalize-compiled",
53
+ value: sample.vueFinalizeCompiledMs
54
+ },
55
+ {
56
+ label: "vue-finalize-code",
57
+ value: sample.vueFinalizeCodeMs
58
+ },
59
+ {
60
+ label: "core-load",
61
+ value: sample.coreLoadMs
62
+ },
63
+ {
64
+ label: "entry-load",
65
+ value: sample.entryLoadMs
66
+ },
67
+ {
68
+ label: "entry-emit-output",
69
+ value: sample.entryEmitOutputMs
70
+ },
71
+ {
72
+ label: "entry-template-scan",
73
+ value: sample.entryTemplateScanMs
74
+ },
75
+ {
76
+ label: "entry-auto-import",
77
+ value: sample.entryAutoImportMs
78
+ },
79
+ {
80
+ label: "entry-script-setup",
81
+ value: sample.entryScriptSetupMs
82
+ },
83
+ {
84
+ label: "entry-vue-signature",
85
+ value: sample.entryVueSignatureMs
86
+ },
87
+ {
88
+ label: "entry-sidecar-resolve",
89
+ value: sample.entrySidecarResolveMs
90
+ },
91
+ {
92
+ label: "entry-json-read",
93
+ value: sample.entryJsonReadMs
94
+ },
95
+ {
96
+ label: "entry-vue-config",
97
+ value: sample.entryVueConfigMs
98
+ },
99
+ {
100
+ label: "entry-prepare",
101
+ value: sample.entryPrepareMs
102
+ },
103
+ {
104
+ label: "entry-resolve",
105
+ value: sample.entryResolveMs
106
+ },
107
+ {
108
+ label: "entry-style-scan",
109
+ value: sample.entryStyleScanMs
110
+ },
111
+ {
112
+ label: "entry-style-read",
113
+ value: sample.entryStyleReadMs
114
+ },
115
+ {
116
+ label: "entry-code-read",
117
+ value: sample.entryCodeReadMs
118
+ },
119
+ {
120
+ label: "entry-chunk-emit",
121
+ value: sample.entryChunkEmitMs
122
+ },
123
+ {
124
+ label: "entry-chunk-load",
125
+ value: sample.entryChunkLoadMs
126
+ },
127
+ {
128
+ label: "entry-chunk-emit-file",
129
+ value: sample.entryChunkEmitFileMs
130
+ },
131
+ {
132
+ label: "entry-layout",
133
+ value: sample.entryLayoutMs
134
+ },
135
+ {
136
+ label: "request-globals",
137
+ value: sample.requestGlobalsMs
138
+ },
139
+ {
140
+ label: "weapi-resolve",
141
+ value: sample.weapiResolveMs
142
+ },
143
+ {
144
+ label: "render-start",
145
+ value: sample.renderStartMs
146
+ },
147
+ {
148
+ label: "generate",
149
+ value: sample.generateBundleMs
150
+ },
151
+ {
152
+ label: "generate-shared",
153
+ value: sample.generateSharedMs
154
+ },
155
+ {
156
+ label: "generate-rewrite",
157
+ value: sample.generateRewriteMs
158
+ },
159
+ {
160
+ label: "module-graph",
161
+ value: sample.generateModuleGraphMs
162
+ },
163
+ {
164
+ label: "snapshot-resolve",
165
+ value: sample.snapshotResolveMs
166
+ },
167
+ {
168
+ label: "snapshot-build",
169
+ value: sample.snapshotBuildMs
170
+ },
171
+ {
172
+ label: "watch->dirty",
173
+ value: sample.watchToDirtyMs
174
+ },
175
+ {
176
+ label: "emit",
177
+ value: sample.emitMs
178
+ },
179
+ {
180
+ label: "shared",
181
+ value: sample.sharedChunkResolveMs
182
+ },
183
+ {
184
+ label: "write",
185
+ value: sample.writeMs
186
+ }
187
+ ].filter((phase) => isFiniteNumber(phase.value)).sort((left, right) => (right.value ?? 0) - (left.value ?? 0))[0];
188
+ if (!topPhase || (topPhase.value ?? 0) < 5) return;
189
+ return `${topPhase.label} ${topPhase.value.toFixed(2)} ms`;
190
+ }
191
+ /**
192
+ * @description 读取最近一次 HMR profile,并格式化为 IDE 日志启动前的单行摘要。
193
+ */
194
+ async function readLatestHmrProfileSummary(options) {
195
+ const profilePath = resolveHmrProfileJsonPath({
196
+ cwd: options.cwd,
197
+ option: options.weappViteConfig?.hmr?.profileJson
198
+ });
199
+ if (!profilePath) return;
200
+ const content = await fs.readFile(profilePath, "utf8").catch(() => void 0);
201
+ if (!content) return;
202
+ const { samples, skippedLineCount } = readHmrProfileLines(content);
203
+ const sample = samples.at(-1);
204
+ if (!sample || !isFiniteNumber(sample.totalMs)) return;
205
+ const relativeCwd = options.relativeCwd ?? ((value) => value);
206
+ const segments = [`[hmr] 最近一次热更新 ${sample.totalMs.toFixed(2)} ms`];
207
+ if (sample.event) segments.push(sample.event);
208
+ if (sample.file) segments.push(relativeCwd(sample.file));
209
+ const phaseHint = formatPhaseHint(sample);
210
+ if (phaseHint) segments.push(`主耗时 ${phaseHint}`);
211
+ if (isFiniteNumber(sample.loadCount) || isFiniteNumber(sample.resolveCount) || isFiniteNumber(sample.chunkEmitCount) || isFiniteNumber(sample.skippedLoadedCount)) segments.push(`load/resolve/chunk/skip ${sample.loadCount ?? "unknown"}/${sample.resolveCount ?? "unknown"}/${sample.chunkEmitCount ?? "unknown"}/${sample.skippedLoadedCount ?? "unknown"}`);
212
+ if (skippedLineCount) segments.push(`忽略 ${skippedLineCount} 条不兼容、未完成或无效记录`);
213
+ return {
214
+ file: sample.file,
215
+ profilePath,
216
+ line: segments.join(",")
217
+ };
218
+ }
219
+ // src/cli/forwardConsole.ts
220
+ const DEFAULT_FORWARD_CONSOLE_LEVELS = [
221
+ "log",
222
+ "info",
223
+ "warn",
224
+ "error"
225
+ ];
226
+ let activeForwardConsoleSession;
227
+ let activeForwardConsoleBridgeOptions;
228
+ let activeForwardConsoleStart;
229
+ let activeForwardConsoleClose;
230
+ let forwardConsoleLifecycle = 0;
231
+ const FORWARD_CONSOLE_RETRY_DELAY_MS = 1e3;
232
+ const FORWARD_CONSOLE_RETRY_TIMES = 5;
233
+ const FORWARD_CONSOLE_RETRY_WINDOW_MS = 1e4;
234
+ const FORWARD_CONSOLE_RECOVERABLE_START_TIMEOUT_MS = 6e4;
235
+ const FORWARD_CONSOLE_START_TIMEOUT_MS = 12e4;
236
+ async function detectAgent() {
237
+ try {
238
+ const result = await determineAgent();
239
+ return {
240
+ isAgent: result.isAgent,
241
+ agentName: result.isAgent ? result.agent.name : void 0
242
+ };
243
+ } catch {
244
+ return {
245
+ isAgent: false,
246
+ agentName: void 0
247
+ };
248
+ }
249
+ }
250
+ function formatForwardConsolePrefix(level, color) {
251
+ const label = `[mini:${level.padEnd(5)}]`;
252
+ if (!color) return label;
253
+ if (level === "error") return colors.bold(colors.red(label));
254
+ if (level === "warn") return colors.bold(colors.yellow(label));
255
+ if (level === "info") return colors.bold(colors.cyan(label));
256
+ if (level === "debug") return colors.dim(label);
257
+ return colors.bold(colors.green(label));
258
+ }
259
+ function formatForwardConsoleMessage(level, message, color) {
260
+ if (!color) return message;
261
+ if (level === "error") return colors.red(message);
262
+ if (level === "warn") return colors.yellow(message);
263
+ if (level === "debug") return colors.dim(message);
264
+ return message;
265
+ }
266
+ function writeForwardConsoleLine(line) {
267
+ process.stdout.write(`${line}\n`);
268
+ }
269
+ function isDevtoolsPortNotReadyError(error) {
270
+ return error instanceof Error && (error.message === "DEVTOOLS_HTTP_PORT_ERROR" || error.message === "DEVTOOLS_WS_CONNECT_ERROR" || error.message === "DEVTOOLS_EXTENSION_CONTEXT_INVALIDATED");
271
+ }
272
+ function isDevtoolsProtocolTimeoutError(error) {
273
+ return error instanceof Error && (error.message === "DEVTOOLS_PROTOCOL_TIMEOUT" || /DevTools did not respond to protocol method \S+ within \d+ms/i.test(error.message));
274
+ }
275
+ function isRecoverableAutomatorStartError(error) {
276
+ return isDevtoolsPortNotReadyError(error) || isDevtoolsProtocolTimeoutError(error) || isRetryableAutomatorLaunchError(error);
277
+ }
278
+ function sleep(ms) {
279
+ return new Promise((resolve) => setTimeout(resolve, ms));
280
+ }
281
+ async function withForwardConsoleRetry(runner) {
282
+ let lastError;
283
+ const startedAt = Date.now();
284
+ for (let attempt = 0; attempt <= FORWARD_CONSOLE_RETRY_TIMES; attempt++) try {
285
+ return await runner();
286
+ } catch (error) {
287
+ lastError = error;
288
+ if (!isDevtoolsPortNotReadyError(error) || attempt === FORWARD_CONSOLE_RETRY_TIMES || Date.now() - startedAt >= FORWARD_CONSOLE_RETRY_WINDOW_MS) break;
289
+ await sleep(FORWARD_CONSOLE_RETRY_DELAY_MS);
290
+ }
291
+ throw lastError instanceof Error ? lastError : new Error(String(lastError));
292
+ }
293
+ /**
294
+ * @description 解析 forwardConsole 配置,并在 auto 模式下检测 AI 终端。
295
+ */
296
+ async function resolveForwardConsoleOptions(config) {
297
+ const rawConfig = config?.forwardConsole;
298
+ const defaults = {
299
+ logLevels: DEFAULT_FORWARD_CONSOLE_LEVELS,
300
+ unhandledErrors: true
301
+ };
302
+ if (rawConfig === false) return {
303
+ enabled: false,
304
+ ...defaults
305
+ };
306
+ if (rawConfig === true) return {
307
+ enabled: true,
308
+ ...defaults
309
+ };
310
+ const normalizedConfig = rawConfig ?? {};
311
+ const enabledMode = normalizedConfig.enabled ?? "auto";
312
+ const logLevels = normalizedConfig.logLevels?.length ? normalizedConfig.logLevels : defaults.logLevels;
313
+ const unhandledErrors = normalizedConfig.unhandledErrors ?? defaults.unhandledErrors;
314
+ if (enabledMode === true) return {
315
+ enabled: true,
316
+ logLevels,
317
+ unhandledErrors
318
+ };
319
+ if (enabledMode === false) return {
320
+ enabled: false,
321
+ logLevels,
322
+ unhandledErrors
323
+ };
324
+ const agentResult = await detectAgent();
325
+ return {
326
+ enabled: agentResult.isAgent,
327
+ agentName: agentResult.agentName,
328
+ logLevels,
329
+ unhandledErrors
330
+ };
331
+ }
332
+ /**
333
+ * @description 统一启动 DevTools 日志桥,并在 IDE 刚启动时做短暂重试。
334
+ */
335
+ async function startForwardConsoleBridge(options) {
336
+ return await withForwardConsoleRetry(async () => {
337
+ const color = options.color ?? true;
338
+ return await startForwardConsole({
339
+ projectPath: options.projectPath,
340
+ logLevels: options.logLevels,
341
+ openedOnly: options.openedOnly,
342
+ preferOpenedSession: options.preferOpenedSession,
343
+ preserveProjectRoot: options.preserveProjectRoot,
344
+ port: options.port,
345
+ timeout: options.timeout,
346
+ unhandledErrors: options.unhandledErrors,
347
+ onReady: () => {
348
+ const suffix = options.agentName ? `(AI 终端:${options.agentName})` : "";
349
+ logger_default.info(`${options.onReadyMessage}${suffix}`);
350
+ },
351
+ onLog: (event) => {
352
+ writeForwardConsoleLine(`${formatForwardConsolePrefix(event.level, color)} ${formatForwardConsoleMessage(event.level, event.message, color)}`);
353
+ }
354
+ });
355
+ });
356
+ }
357
+ /**
358
+ * @description 暂停当前 DevTools 日志桥,并返回恢复函数。
359
+ */
360
+ async function pauseActiveForwardConsole() {
361
+ const lifecycle = forwardConsoleLifecycle;
362
+ await activeForwardConsoleStart;
363
+ if (lifecycle !== forwardConsoleLifecycle) return;
364
+ const session = activeForwardConsoleSession;
365
+ const bridgeOptions = activeForwardConsoleBridgeOptions;
366
+ if (!session || !bridgeOptions) return;
367
+ activeForwardConsoleSession = void 0;
368
+ activeForwardConsoleBridgeOptions = void 0;
369
+ await session.close();
370
+ return async () => {
371
+ if (lifecycle !== forwardConsoleLifecycle) return false;
372
+ if (activeForwardConsoleStart) return await activeForwardConsoleStart;
373
+ if (activeForwardConsoleSession) return true;
374
+ const startTask = (async () => {
375
+ let resumedSession;
376
+ try {
377
+ resumedSession = await startForwardConsoleBridge(bridgeOptions);
378
+ } catch (error) {
379
+ if (lifecycle === forwardConsoleLifecycle) {
380
+ const message = error instanceof Error ? error.message : String(error);
381
+ logger_default.warn(`[forwardConsole] 恢复失败:${message}`);
382
+ }
383
+ return false;
384
+ }
385
+ if (lifecycle !== forwardConsoleLifecycle) {
386
+ await resumedSession.close();
387
+ return false;
388
+ }
389
+ activeForwardConsoleSession = resumedSession;
390
+ activeForwardConsoleBridgeOptions = bridgeOptions;
391
+ return true;
392
+ })();
393
+ activeForwardConsoleStart = startTask;
394
+ try {
395
+ return await startTask;
396
+ } finally {
397
+ if (activeForwardConsoleStart === startTask) activeForwardConsoleStart = void 0;
398
+ }
399
+ };
400
+ }
401
+ /**
402
+ * @description 关闭当前 DevTools 日志桥并释放共享 automator 会话。
403
+ */
404
+ function closeActiveForwardConsole() {
405
+ if (activeForwardConsoleClose) return activeForwardConsoleClose;
406
+ forwardConsoleLifecycle += 1;
407
+ const session = activeForwardConsoleSession;
408
+ const pendingStart = activeForwardConsoleStart;
409
+ activeForwardConsoleSession = void 0;
410
+ activeForwardConsoleBridgeOptions = void 0;
411
+ const closing = (async () => {
412
+ const errors = (await Promise.allSettled([Promise.resolve().then(() => session?.close()), pendingStart])).filter((result) => result.status === "rejected").map((result) => result.reason);
413
+ if (errors.length === 1) throw errors[0];
414
+ if (errors.length > 1) throw new AggregateError(errors, "DevTools 日志桥关闭失败");
415
+ })();
416
+ activeForwardConsoleClose = closing;
417
+ closing.finally(() => {
418
+ if (activeForwardConsoleClose === closing) activeForwardConsoleClose = void 0;
419
+ }).catch(() => {});
420
+ return closing;
421
+ }
422
+ /**
423
+ * @description 在 weapp 开发态按需启动控制台转发。
424
+ */
425
+ async function maybeStartForwardConsole(options) {
426
+ if (options.platform !== "weapp" || activeForwardConsoleClose) return false;
427
+ const multiPlatform = options.weappViteConfig?.multiPlatform;
428
+ const generatedProjectConfig = typeof multiPlatform === "object" && multiPlatform.projectConfigs !== void 0;
429
+ const projectPath = resolveIdeProjectRoot(options.mpDistRoot, options.cwd, generatedProjectConfig);
430
+ if (!projectPath) return false;
431
+ if (activeForwardConsoleSession) return true;
432
+ if (activeForwardConsoleStart) return await activeForwardConsoleStart;
433
+ const lifecycle = forwardConsoleLifecycle;
434
+ const startTask = (async () => {
435
+ const resolved = await resolveForwardConsoleOptions(options.weappViteConfig);
436
+ if (!resolved.enabled || lifecycle !== forwardConsoleLifecycle) return false;
437
+ const bridgeOptions = {
438
+ agentName: resolved.agentName,
439
+ color: !resolved.agentName,
440
+ projectPath,
441
+ port: resolveProjectAutomatorPort(projectPath),
442
+ timeout: options.recoverAutomatorSession ? FORWARD_CONSOLE_RECOVERABLE_START_TIMEOUT_MS : FORWARD_CONSOLE_START_TIMEOUT_MS,
443
+ logLevels: resolved.logLevels,
444
+ openedOnly: options.openedOnly,
445
+ preferOpenedSession: options.preferOpenedSession,
446
+ preserveProjectRoot: options.preserveProjectRoot ?? !shouldUseAutomatorProjectWrapper(projectPath),
447
+ unhandledErrors: resolved.unhandledErrors,
448
+ onReadyMessage: "[forwardConsole] 已连接微信开发者工具日志"
449
+ };
450
+ const activateSession = async (session, activeOptions) => {
451
+ if (lifecycle !== forwardConsoleLifecycle) {
452
+ await session.close();
453
+ return false;
454
+ }
455
+ activeForwardConsoleSession = session;
456
+ activeForwardConsoleBridgeOptions = activeOptions;
457
+ return true;
458
+ };
459
+ const recoverAutomatorSession = async () => {
460
+ try {
461
+ await options.recoverAutomatorSession?.();
462
+ if (lifecycle !== forwardConsoleLifecycle) return false;
463
+ const recoveredOptions = {
464
+ ...bridgeOptions,
465
+ openedOnly: true,
466
+ preferOpenedSession: true
467
+ };
468
+ return activateSession(await startForwardConsoleBridge(recoveredOptions), recoveredOptions);
469
+ } catch (recoveryError) {
470
+ if (lifecycle !== forwardConsoleLifecycle) return false;
471
+ const message = recoveryError instanceof Error ? recoveryError.message : String(recoveryError);
472
+ logger_default.warn(`[forwardConsole] automator 会话恢复失败,回退到普通 IDE 打开流程:${message}`);
473
+ return false;
474
+ }
475
+ };
476
+ try {
477
+ return activateSession(await startForwardConsoleBridge(bridgeOptions), bridgeOptions);
478
+ } catch (error) {
479
+ if (lifecycle !== forwardConsoleLifecycle) return false;
480
+ if (options.recoverAutomatorSession && isRecoverableAutomatorStartError(error)) return await recoverAutomatorSession();
481
+ if (!isDevtoolsPortNotReadyError(error)) {
482
+ const message = error instanceof Error ? error.message : String(error);
483
+ logger_default.warn(`[forwardConsole] 启动失败,回退到普通 IDE 打开流程:${message}`);
484
+ return false;
485
+ }
486
+ const fallbackOptions = {
487
+ ...bridgeOptions,
488
+ openedOnly: true,
489
+ port: void 0,
490
+ preferOpenedSession: true
491
+ };
492
+ try {
493
+ return activateSession(await startForwardConsoleBridge(fallbackOptions), fallbackOptions);
494
+ } catch (fallbackError) {
495
+ if (lifecycle !== forwardConsoleLifecycle) return false;
496
+ const message = fallbackError instanceof Error ? fallbackError.message : String(fallbackError);
497
+ logger_default.warn(`[forwardConsole] 启动失败,回退到普通 IDE 打开流程:${message}`);
498
+ return false;
499
+ }
500
+ }
501
+ })();
502
+ activeForwardConsoleStart = startTask;
503
+ try {
504
+ return await startTask;
505
+ } finally {
506
+ if (activeForwardConsoleStart === startTask) activeForwardConsoleStart = void 0;
507
+ }
508
+ }
509
+ export { startForwardConsoleBridge as a, resolveForwardConsoleOptions as i, maybeStartForwardConsole as n, readLatestHmrProfileSummary as o, pauseActiveForwardConsole as r, closeActiveForwardConsole as t };
@@ -0,0 +1 @@
1
+ export { t as getCompilerContext } from "./getInstance-DfNlbr-X.mjs";
@@ -1,5 +1,5 @@
1
- import { t as createCompilerContextInstance } from "./createCompilerContextInstance-DJH_P_nZ.mjs";
2
- //#region src/context/getInstance.ts
1
+ import { t as createCompilerContextInstance } from "./createCompilerContextInstance-BXSdH2E8.mjs";
2
+ // src/context/getInstance.ts
3
3
  const compilerContextMap = /* @__PURE__ */ new Map();
4
4
  const DEFAULT_KEY = "default";
5
5
  let activeCompilerContextKey = DEFAULT_KEY;
@@ -24,5 +24,4 @@ function resetCompilerContext(key) {
24
24
  compilerContextMap.clear();
25
25
  activeCompilerContextKey = DEFAULT_KEY;
26
26
  }
27
- //#endregion
28
27
  export { resetCompilerContext as n, setActiveCompilerContextKey as r, getCompilerContext as t };