weapp-vite 7.5.0 → 7.6.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 (93) hide show
  1. package/README.md +8 -2
  2. package/THIRD_PARTY_NOTICES.md +60 -0
  3. package/dist/action-B3YZMA-h.mjs +255 -0
  4. package/dist/action-BELcDNNv.mjs +139 -0
  5. package/dist/action-BOk3vGI7.mjs +1110 -0
  6. package/dist/action-DlC6JYpt.mjs +95 -0
  7. package/dist/action-zEDY7oh_.mjs +247 -0
  8. package/dist/{analyze-ZJUvEdaY.mjs → analyze-DN79YOAH.mjs} +1 -65
  9. package/dist/artifacts-BOyC9Fy-.mjs +106 -0
  10. package/dist/assets-C5_YYXNk.mjs +637 -0
  11. package/dist/auto-routes.mjs +2 -2
  12. package/dist/{budget-BD7VqLCl.d.mts → budget-CTLOHwgI.d.mts} +1 -2
  13. package/dist/budget-EOeEycc_.mjs +65 -0
  14. package/dist/builtProject-C29udgXY.mjs +541 -0
  15. package/dist/{chunkStrategy-DRA5WpB-.mjs → chunkStrategy-DY_LZIIe.mjs} +15 -3
  16. package/dist/{package-7swhyLmf.mjs → classifier-DBJY__kg.mjs} +4 -7
  17. package/dist/cli-acceptance.mjs +1 -1
  18. package/dist/cli.mjs +110 -4506
  19. package/dist/{config-V0L-IAJf.d.mts → config-Bf6DWhyb.d.mts} +136 -49
  20. package/dist/config.d.mts +2 -2
  21. package/dist/{createCompilerContextInstance-DJH_P_nZ.mjs → createCompilerContextInstance-aYwi8wQt.mjs} +15235 -9523
  22. package/dist/{createContext-BqYzHhY9.mjs → createContext-tApLtII-.mjs} +6 -3
  23. package/dist/dashboard/analyze.d.mts +1 -1
  24. package/dist/dashboard/analyze.mjs +3 -1
  25. package/dist/dashboard/vite.d.mts +1 -1
  26. package/dist/dashboard.d.mts +2 -2
  27. package/dist/dashboard.mjs +1749 -1
  28. package/dist/dashboardTransport-C_Y6jMp-.mjs +16 -0
  29. package/dist/{dashboardViteBridge-Dy3nAD4m.mjs → dashboardViteBridge-DCGR43aM.mjs} +8 -5
  30. package/dist/{dev-fR5GiJRO.mjs → dev-C2fgr_Xd.mjs} +5 -1
  31. package/dist/devProvider-D-hTfsEO.mjs +3027 -0
  32. package/dist/docs/README.md +8 -2
  33. package/dist/docs/mcp.md +10 -0
  34. package/dist/docs/troubleshooting.md +8 -0
  35. package/dist/docs/vue-sfc.md +25 -2
  36. package/dist/doctor-worker.mjs +3 -2
  37. package/dist/doctor.d.mts +2 -2
  38. package/dist/doctor.mjs +15 -13
  39. package/dist/engine-C66J0HLz.mjs +54 -0
  40. package/dist/{file-sC3jD7Fh.mjs → file-CcIOmqhC.mjs} +47 -19
  41. package/dist/file-DtcteQ4G.mjs +1 -0
  42. package/dist/forwardConsole-B0Reo8Lf.mjs +511 -0
  43. package/dist/getInstance-BAIaU2y9.mjs +1 -0
  44. package/dist/{getInstance-DiGSzBNI.mjs → getInstance-Dt9IQDKr.mjs} +1 -1
  45. package/dist/history-BIiRCzbq.mjs +784 -0
  46. package/dist/i18n.d.mts +1 -1
  47. package/dist/{index-C9HjUX5c.d.mts → index-D5rgBzYZ.d.mts} +1 -2
  48. package/dist/index.d.mts +3 -3
  49. package/dist/index.mjs +2 -2
  50. package/dist/json.d.mts +1 -1
  51. package/dist/lib-DjccSI1B.mjs +143 -0
  52. package/dist/{lifecycle-BROTlwSL.mjs → lifecycle-C36WSbQS.mjs} +120 -27
  53. package/dist/{loadConfig-C3BQhz7F.mjs → loadConfig-BWIsDXR4.mjs} +1 -1
  54. package/dist/loadConfig-D-BpBgsk.mjs +1 -0
  55. package/dist/logBuildAppFinish-ChjwATMv.mjs +57 -0
  56. package/dist/mcp-CYgX9HpO.mjs +86 -0
  57. package/dist/mcp.d.mts +1 -1
  58. package/dist/mcpClient-DVLvFLZv.mjs +287 -0
  59. package/dist/{processCleanup-B6KA30Zc.mjs → metadata-hwF7QRcS.mjs} +1 -19
  60. package/dist/nodeEnv-BmH8UZPR.mjs +7 -0
  61. package/dist/openIde-CroqOgk5.mjs +648 -0
  62. package/dist/options-jqFwfD1G.mjs +34 -0
  63. package/dist/package-Cmakyy3J.mjs +4 -0
  64. package/dist/path-CYYIQGS7.mjs +44 -0
  65. package/dist/processCleanup-BQn2kTcK.mjs +19 -0
  66. package/dist/{protocol-vg8HGJ4n.mjs → protocol-Cg6Jdlvb.mjs} +42 -39
  67. package/dist/reader-sh_POQ9-.mjs +93 -0
  68. package/dist/realpathScope-Tf9mz-fh.mjs +23 -0
  69. package/dist/report-hyonPGbZ.mjs +107 -0
  70. package/dist/{path-doV773b7.mjs → resolvedId-CiDl7SC1.mjs} +3 -46
  71. package/dist/runtime-CLUhQsdA.mjs +43 -0
  72. package/dist/{runtime-Ee2HY6gR.d.mts → runtime-DpVf714f.d.mts} +1 -1
  73. package/dist/runtime.d.mts +1 -1
  74. package/dist/schematics-kO26eQRT.mjs +91 -0
  75. package/dist/{session-PskhD-nZ.mjs → session-D3zsdzIy.mjs} +71 -9
  76. package/dist/test.mjs +10 -8
  77. package/dist/{types-CgZn5X6j.d.mts → types-D-kfuyVa.d.mts} +1 -2
  78. package/dist/types-D0FFexRF.d.mts +39 -0
  79. package/dist/types.d.mts +2 -2
  80. package/dist/{upload-D4msblBf.mjs → upload-DozK8UdN.mjs} +109 -5
  81. package/dist/upload-worker.mjs +1 -1
  82. package/dist/{utils-CJSCgEj6.mjs → utils-Dy51PYAC.mjs} +56 -116
  83. package/dist/vite.d.mts +1 -1
  84. package/dist/vite.mjs +51 -12
  85. package/dist/wxs-BT8btflA.mjs +112 -0
  86. package/dist/wxs-Z4VQDeJ_.mjs +1 -0
  87. package/package.json +52 -46
  88. package/dist/dashboard-DvqF3Key.mjs +0 -1842
  89. package/dist/devProvider-BGBkw28J.mjs +0 -1050
  90. package/dist/file-DRb4eWqw.mjs +0 -1
  91. package/dist/getInstance-SiE6WZRh.mjs +0 -1
  92. package/dist/loadConfig-VGtBF4qm.mjs +0 -1
  93. package/dist/mcp-D3Yh24Cj.mjs +0 -529
package/dist/i18n.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as WeappI18nConfig } from "./types-CgZn5X6j.mjs";
1
+ import { t as WeappI18nConfig } from "./types-D-kfuyVa.mjs";
2
2
  import { I18nGlobal, I18nGlobal as I18nGlobal$1, I18nInstance, I18nInstance as I18nInstance$1, I18nLocaleChangeSubscription } from "@weapp-vite/i18n";
3
3
  //#region src/i18n.d.ts
4
4
  export declare const behavior: I18nInstance$1["behavior"];
@@ -1,5 +1,4 @@
1
- import "./config-V0L-IAJf.mjs";
2
- import { a as AnalyzeSubpackagesResult } from "./budget-BD7VqLCl.mjs";
1
+ import { a as AnalyzeSubpackagesResult } from "./budget-CTLOHwgI.mjs";
3
2
  import { DevframeDefinition } from "devframe";
4
3
  import { z } from "zod";
5
4
  //#region src/dashboard/artifacts.d.ts
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { $ as WeappCompilerHmrRequest, A as PluginOption, B as ViteDevServer, Br as WeappVitePlatform, Ct as WeappViteConfig, D as InlineConfig, E as ConfigEnv, F as RolldownOutput, Fr as isWeappViteHost, Gn as JsonConfig, Gr as WebPlatform, Hr as WeappViteTargetDescriptor, I as RolldownPlugin, Ir as resolveWeappViteHostMeta, Jn as JsonMergeStage, Jr as isWebPlatform, Kn as JsonMergeContext, Kr as getSupportedWeappVitePlatforms, L as RolldownPluginOption, Lr as ResolveWeappViteTargetOptions, M as ResolvedConfig, Mr as WeappViteHostMeta, N as RolldownBuild, Nr as applyWeappViteHostMeta, O as MethodDefinitions, P as RolldownOptions, Pr as createWeappViteHostMeta, Q as WeappCompilerHmrPreparation, R as RolldownWatchOptions, Rr as ResolvedWeappViteTarget, S as CompilerContext, Sn as MultiPlatformProjectConfigs, T as ComputedDefinitions, Ur as WeappViteTargetInput, Vr as WeappViteRuntime, Wr as WeappViteTargetKind, Yn as JsonMergeStrategy, Yr as resolveWeappViteTarget, Z as WeappCompilerHmrAsset, _ as definePageJson, _n as WxmlTransformContext, a as UserConfigFnNoEnvPlain, at as WeappCompilerPluginFactory, bn as WxmlTransformVisitor, c as UserConfigFnPromise, cn as WxmlValidate, ct as WeappCompilerResourceKind, d as Component, dn as WxmlValidationVisitor, dt as WeappCompilerTransformResult, et as WeappCompilerOutputRequest, f as Page, fn as WxmlAttribute, g as defineComponentJson, gn as WxmlTransform, h as defineAppJson, hn as WxmlSourceLocation, i as UserConfigFnNoEnv, it as WeappCompilerPluginController, j as Ref, jr as WEAPP_VITE_HOST_NAME, k as Plugin, l as defineConfig, ln as WxmlValidationContext, lt as WeappCompilerSourceClaim, m as Theme, mn as WxmlElementInfo, n as UserConfigExport, nt as WeappCompilerPluginCapabilities, o as UserConfigFnObject, on as WxmlRemoveAttrRule, ot as WeappCompilerPluginOption, p as Sitemap, pn as WxmlAttributeValue, qn as JsonMergeFunction, qr as getSupportedWeappViteTargetDescriptors, r as UserConfigFn, rt as WeappCompilerPluginContext, s as UserConfigFnObjectPlain, sn as WxmlRemoveOptions, st as WeappCompilerPluginPhase, t as UserConfig, tt as WeappCompilerPlugin, u as App, un as WxmlValidationDiagnostic, ut as WeappCompilerSourceRequest, v as defineSitemapJson, vn as WxmlTransformNode, w as LoadConfigOptions, xn as MultiPlatformProjectConfig, y as defineThemeJson, yn as WxmlTransformResult, z as RolldownWatcher, zr as WEB_PLATFORM_ALIASES } from "./config-V0L-IAJf.mjs";
2
- import { t as WeappI18nConfig } from "./types-CgZn5X6j.mjs";
3
- import { a as LayoutHostContext, c as LayoutHostResolver, d as unregisterLayoutHosts, f as waitForLayoutHost, i as LayoutHostBridge, l as registerLayoutHosts, m as createWevuComponent, n as defineProps, o as LayoutHostEntry, p as WevuComponentOptions, r as setPageLayout, s as LayoutHostResolveOptions, t as defineEmits, u as resolveLayoutHost } from "./runtime-Ee2HY6gR.mjs";
1
+ import { $ as WeappCompilerOutputRequest, A as Ref, Ar as WEAPP_VITE_HOST_NAME, Br as WeappViteRuntime, C as LoadConfigOptions, D as MethodDefinitions, E as InlineConfig, F as RolldownPlugin, Fr as resolveWeappViteHostMeta, Gn as JsonMergeContext, Gr as getSupportedWeappVitePlatforms, Hr as WeappViteTargetInput, I as RolldownPluginOption, Ir as ResolveWeappViteTargetOptions, Jn as JsonMergeStrategy, Jr as resolveWeappViteTarget, Kn as JsonMergeFunction, Kr as getSupportedWeappViteTargetDescriptors, L as RolldownWatchOptions, Lr as ResolvedWeappViteTarget, M as RolldownBuild, Mr as applyWeappViteHostMeta, N as RolldownOptions, Nr as createWeappViteHostMeta, O as Plugin, P as RolldownOutput, Pr as isWeappViteHost, Q as WeappCompilerHmrRequest, R as RolldownWatcher, Rr as WEB_PLATFORM_ALIASES, S as CompilerContext, St as WeappViteConfig, T as ConfigEnv, Ur as WeappViteTargetKind, Vr as WeappViteTargetDescriptor, Wn as JsonConfig, Wr as WebPlatform, X as WeappCompilerHmrAsset, Z as WeappCompilerHmrPreparation, _ as definePageJson, _n as WxmlTransformNode, a as UserConfigFnNoEnvPlain, an as WxmlRemoveAttrRule, at as WeappCompilerPluginOption, bn as MultiPlatformProjectConfig, c as UserConfigFnPromise, cn as WxmlValidationContext, ct as WeappCompilerSourceClaim, d as Component, dn as WxmlAttribute, et as WeappCompilerPlugin, f as Page, fn as WxmlAttributeValue, g as defineComponentJson, gn as WxmlTransformContext, h as defineAppJson, hn as WxmlTransform, i as UserConfigFnNoEnv, it as WeappCompilerPluginFactory, j as ResolvedConfig, jr as WeappViteHostMeta, k as PluginOption, l as defineConfig, ln as WxmlValidationDiagnostic, lt as WeappCompilerSourceRequest, m as Theme, mn as WxmlSourceLocation, n as UserConfigExport, nt as WeappCompilerPluginContext, o as UserConfigFnObject, on as WxmlRemoveOptions, ot as WeappCompilerPluginPhase, p as Sitemap, pn as WxmlElementInfo, qn as JsonMergeStage, qr as isWebPlatform, r as UserConfigFn, rt as WeappCompilerPluginController, s as UserConfigFnObjectPlain, sn as WxmlValidate, st as WeappCompilerResourceKind, t as UserConfig, tt as WeappCompilerPluginCapabilities, u as App, un as WxmlValidationVisitor, ut as WeappCompilerTransformResult, v as defineSitemapJson, vn as WxmlTransformResult, w as ComputedDefinitions, xn as MultiPlatformProjectConfigs, y as defineThemeJson, yn as WxmlTransformVisitor, z as ViteDevServer, zr as WeappVitePlatform } from "./config-Bf6DWhyb.mjs";
2
+ import { t as WeappI18nConfig } from "./types-D-kfuyVa.mjs";
3
+ import { a as LayoutHostContext, c as LayoutHostResolver, d as unregisterLayoutHosts, f as waitForLayoutHost, i as LayoutHostBridge, l as registerLayoutHosts, m as createWevuComponent, n as defineProps, o as LayoutHostEntry, p as WevuComponentOptions, r as setPageLayout, s as LayoutHostResolveOptions, t as defineEmits, u as resolveLayoutHost } from "./runtime-DpVf714f.mjs";
4
4
  //#region src/runtime/compilerSession/context.d.ts
5
5
  interface InitializeCompilerContextOptions extends Partial<LoadConfigOptions> {
6
6
  syncSupportFiles?: boolean;
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { a as resolveWeappViteHostMeta, i as isWeappViteHost, n as applyWeappViteHostMeta, r as createWeappViteHostMeta, t as WEAPP_VITE_HOST_NAME } from "./pluginHost--CaeyWpA.mjs";
2
2
  import { a as defineThemeJson, i as defineSitemapJson, n as defineComponentJson, r as definePageJson, t as defineAppJson } from "./json-BL8Dhhk6.mjs";
3
3
  import { t as defineConfig } from "./config-DRGcCi3h.mjs";
4
- import { a as getSupportedWeappViteTargetDescriptors, i as getSupportedWeappVitePlatforms, o as isWebPlatform, r as WEB_PLATFORM_ALIASES, s as resolveWeappViteTarget } from "./createCompilerContextInstance-DJH_P_nZ.mjs";
5
- import { t as createCompilerContext } from "./createContext-BqYzHhY9.mjs";
4
+ import { a as getSupportedWeappViteTargetDescriptors, i as getSupportedWeappVitePlatforms, o as isWebPlatform, r as WEB_PLATFORM_ALIASES, s as resolveWeappViteTarget } from "./createCompilerContextInstance-aYwi8wQt.mjs";
5
+ import { t as createCompilerContext } from "./createContext-tApLtII-.mjs";
6
6
  import { a as resolveLayoutHost, c as createWevuComponent, i as registerLayoutHosts, n as defineProps, o as unregisterLayoutHosts, r as setPageLayout, s as waitForLayoutHost, t as defineEmits } from "./runtime-D6VCNhNY.mjs";
7
7
  export { WEAPP_VITE_HOST_NAME, WEB_PLATFORM_ALIASES, applyWeappViteHostMeta, createCompilerContext, createWeappViteHostMeta, createWevuComponent, defineAppJson, defineComponentJson, defineConfig, defineEmits, definePageJson, defineProps, defineSitemapJson, defineThemeJson, getSupportedWeappVitePlatforms, getSupportedWeappViteTargetDescriptors, isWeappViteHost, isWebPlatform, registerLayoutHosts, resolveLayoutHost, resolveWeappViteHostMeta, resolveWeappViteTarget, setPageLayout, unregisterLayoutHosts, waitForLayoutHost };
package/dist/json.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as definePageJson, d as Component, f as Page, g as defineComponentJson, h as defineAppJson, m as Theme, p as Sitemap, u as App, v as defineSitemapJson, y as defineThemeJson } from "./config-V0L-IAJf.mjs";
1
+ import { _ as definePageJson, d as Component, f as Page, g as defineComponentJson, h as defineAppJson, m as Theme, p as Sitemap, u as App, v as defineSitemapJson, y as defineThemeJson } from "./config-Bf6DWhyb.mjs";
2
2
  export { type App, type Component, type Page, type Sitemap, type Theme, defineAppJson, defineComponentJson, definePageJson, defineSitemapJson, defineThemeJson };
@@ -0,0 +1,143 @@
1
+ import { o as stripLeadingSlashes, r as normalizeRelativePath } from "./path-CYYIQGS7.mjs";
2
+ import { c as findJsEntry, d as findVueEntry } from "./file-CcIOmqhC.mjs";
3
+ import path from "pathe";
4
+ import { isObject, removeExtensionDeep } from "@weapp-core/shared";
5
+ import { fs } from "@weapp-core/shared/fs";
6
+ //#region src/runtime/compilerSession/tasks.ts
7
+ /** 任一子构建失败后仍等待所有已启动任务,保留最先排列的原始错误。 */
8
+ async function waitForBuildTasks(tasks) {
9
+ const results = await Promise.allSettled(tasks);
10
+ const failure = results.find((result) => result.status === "rejected");
11
+ if (failure?.status === "rejected") throw failure.reason;
12
+ return results.map((result) => result.value);
13
+ }
14
+ //#endregion
15
+ //#region src/runtime/utils/object.ts
16
+ function hasOwn(source, key) {
17
+ return Object.prototype.hasOwnProperty.call(source, key);
18
+ }
19
+ //#endregion
20
+ //#region src/runtime/lib.ts
21
+ function hasLibEntry(entry) {
22
+ if (!entry) return false;
23
+ if (typeof entry === "string") return entry.trim().length > 0;
24
+ if (Array.isArray(entry)) return entry.length > 0;
25
+ if (isObject(entry)) return Object.keys(entry).length > 0;
26
+ return false;
27
+ }
28
+ function resolveWeappLibConfig(options) {
29
+ const { cwd, srcRoot, config } = options;
30
+ if (!config) return;
31
+ const root = config.root ?? srcRoot ?? "";
32
+ const resolvedRoot = path.resolve(cwd, root || ".");
33
+ const userDtsOptions = typeof config.dts === "object" && config.dts ? config.dts : void 0;
34
+ const resolvedDtsEnabled = typeof config.dts === "boolean" ? config.dts : userDtsOptions?.enabled !== false;
35
+ const resolvedDtsMode = userDtsOptions?.mode ?? "internal";
36
+ const resolvedDts = {
37
+ ...userDtsOptions,
38
+ enabled: resolvedDtsEnabled,
39
+ mode: resolvedDtsMode
40
+ };
41
+ return {
42
+ enabled: hasLibEntry(config.entry),
43
+ entry: config.entry,
44
+ root: resolvedRoot,
45
+ outDir: config.outDir,
46
+ preservePath: config.preservePath !== false,
47
+ fileName: config.fileName,
48
+ componentJson: config.componentJson ?? "auto",
49
+ dts: resolvedDts,
50
+ source: config
51
+ };
52
+ }
53
+ function normalizeLibName(value) {
54
+ return stripLeadingSlashes(normalizeRelativePath(value));
55
+ }
56
+ async function resolveEntryFile(root, entry) {
57
+ const resolved = path.isAbsolute(entry) ? entry : path.resolve(root, entry);
58
+ if (path.extname(resolved)) {
59
+ if (await fs.pathExists(resolved)) return resolved;
60
+ }
61
+ const jsEntry = await findJsEntry(resolved);
62
+ if (jsEntry.path) return jsEntry.path;
63
+ const vueEntry = await findVueEntry(resolved);
64
+ if (vueEntry) return vueEntry;
65
+ if (await fs.pathExists(resolved)) return resolved;
66
+ }
67
+ function resolveEntryName(options) {
68
+ const { explicitName, preservePath, relativeId } = options;
69
+ if (explicitName) return normalizeLibName(explicitName);
70
+ const base = removeExtensionDeep(relativeId);
71
+ if (!preservePath) return normalizeLibName(path.basename(base));
72
+ return normalizeLibName(base);
73
+ }
74
+ function resolveOutputBase(options) {
75
+ const { entryName, entryPath, config } = options;
76
+ const fileName = config.fileName;
77
+ if (!fileName) return normalizeLibName(entryName);
78
+ let resolved;
79
+ if (typeof fileName === "function") {
80
+ resolved = fileName({
81
+ name: entryName,
82
+ input: entryPath
83
+ });
84
+ if (typeof resolved !== "string") throw new TypeError("`weapp.lib.fileName` 必须返回字符串。");
85
+ } else resolved = fileName.includes("[name]") ? fileName.replace(/\[name\]/g, entryName) : fileName;
86
+ const normalized = normalizeLibName(resolved);
87
+ if (!normalized) throw new Error("`weapp.lib.fileName` 解析结果为空,请检查配置。");
88
+ return normalizeLibName(removeExtensionDeep(normalized));
89
+ }
90
+ function createLibEntryFileNameResolver(libConfig) {
91
+ if (!libConfig.fileName) return;
92
+ return (chunkInfo) => {
93
+ return `${resolveOutputBase({
94
+ entryName: chunkInfo.name,
95
+ entryPath: chunkInfo.facadeModuleId ?? "",
96
+ config: libConfig
97
+ })}.js`;
98
+ };
99
+ }
100
+ async function resolveWeappLibEntries(configService, libConfig) {
101
+ const entry = libConfig.entry;
102
+ const root = libConfig.root || configService.absoluteSrcRoot;
103
+ const preservePath = libConfig.preservePath;
104
+ const entries = [];
105
+ if (typeof entry === "string") entries.push({ path: entry });
106
+ else if (Array.isArray(entry)) for (const item of entry) entries.push({ path: item });
107
+ else if (isObject(entry)) for (const [name, value] of Object.entries(entry)) entries.push({
108
+ name,
109
+ path: value
110
+ });
111
+ if (!entries.length) throw new Error("`weapp.lib.entry` 不能为空,请配置库模式入口。");
112
+ if (typeof libConfig.fileName === "string" && !libConfig.fileName.includes("[name]") && entries.length > 1) throw new Error("`weapp.lib.fileName` 在多入口模式下必须包含 `[name]` 占位符。");
113
+ const outputNames = /* @__PURE__ */ new Set();
114
+ const resolved = [];
115
+ for (const item of entries) {
116
+ const entryPath = await resolveEntryFile(root, item.path);
117
+ if (!entryPath) throw new Error(`未找到 lib 入口文件:${item.path}`);
118
+ const relativeId = normalizeRelativePath(configService.relativeAbsoluteSrcRoot(entryPath));
119
+ const entryName = resolveEntryName({
120
+ explicitName: item.name,
121
+ preservePath,
122
+ relativeId
123
+ });
124
+ if (!entryName) throw new Error(`lib 入口解析失败:${item.path}`);
125
+ const outputBase = resolveOutputBase({
126
+ entryName,
127
+ entryPath,
128
+ config: libConfig
129
+ });
130
+ if (outputNames.has(outputBase)) throw new Error(`lib 输出路径冲突:${outputBase}`);
131
+ outputNames.add(outputBase);
132
+ const relativeBase = normalizeLibName(removeExtensionDeep(relativeId));
133
+ resolved.push({
134
+ name: entryName,
135
+ input: entryPath,
136
+ relativeBase,
137
+ outputBase
138
+ });
139
+ }
140
+ return resolved;
141
+ }
142
+ //#endregion
143
+ export { hasOwn as a, resolveWeappLibEntries as i, hasLibEntry as n, waitForBuildTasks as o, resolveWeappLibConfig as r, createLibEntryFileNameResolver as t };
@@ -1,7 +1,8 @@
1
1
  import process from "node:process";
2
+ import { WEAPP_VITE_DEV_SERVER_CLOSE_KEY, WEAPP_VITE_HOST_RESTART_CONFIG_KEY } from "@weapp-core/constants";
2
3
  import { AsyncLocalStorage } from "node:async_hooks";
3
4
  //#region src/devLifecycle/server.ts
4
- const serverCloseRecord = Symbol("weapp-vite:dev-server-close");
5
+ const serverCloseRecord = Symbol.for(WEAPP_VITE_DEV_SERVER_CLOSE_KEY);
5
6
  const dispatchedRecords = /* @__PURE__ */ new WeakMap();
6
7
  const dispatchedCloses = /* @__PURE__ */ new WeakMap();
7
8
  function onceClose(close) {
@@ -105,7 +106,7 @@ var DevShutdownScope = class {
105
106
  process.on("SIGTERM", this.onSigterm);
106
107
  process.on("disconnect", this.onDisconnect);
107
108
  process.stdin?.on?.("end", this.onStdinEnd);
108
- if (process.connected === false) this.request("disconnect");
109
+ if (process.connected === false && typeof process.disconnect === "function") this.request("disconnect");
109
110
  }
110
111
  get stopping() {
111
112
  return this.reason !== void 0;
@@ -205,9 +206,26 @@ function createDevShutdownScope(options) {
205
206
  //#endregion
206
207
  //#region src/vite/lifecycle.ts
207
208
  const hostLifecycleKey = Symbol.for("weapp-vite:host-lifecycle");
209
+ function createHostOperations() {
210
+ const operations = new AsyncLocalStorage();
211
+ return {
212
+ isInternal: () => operations.getStore()?.active === true,
213
+ run: (action) => {
214
+ const operation = { active: true };
215
+ return operations.run(operation, async () => {
216
+ try {
217
+ return await action();
218
+ } finally {
219
+ operation.active = false;
220
+ }
221
+ });
222
+ }
223
+ };
224
+ }
208
225
  const hostData = /* @__PURE__ */ new WeakMap();
209
226
  async function settleHostCleanup(tasks) {
210
- const errors = (await Promise.allSettled(tasks)).flatMap((result) => result.status === "rejected" ? [result.reason] : []);
227
+ const results = await Promise.allSettled(tasks);
228
+ const errors = [...new Set(results.flatMap((result) => result.status === "rejected" ? [result.reason] : []))];
211
229
  if (errors.length) throw errors.length === 1 ? errors[0] : new AggregateError(errors, "Host cleanup failed");
212
230
  }
213
231
  async function discardRestartData(data, status) {
@@ -215,6 +233,23 @@ async function discardRestartData(data, status) {
215
233
  data?.clear();
216
234
  await settleHostCleanup(entries.map(async (entry) => await entry.dispose?.(status)));
217
235
  }
236
+ /** 在配置合并后、编译准备前接管重启链;函数载体不会被 Vite 深拷贝。 */
237
+ function takeHostLifecycle(config) {
238
+ const inline = config;
239
+ const carrier = inline[WEAPP_VITE_HOST_RESTART_CONFIG_KEY];
240
+ const inherited = typeof carrier === "function" ? carrier[hostLifecycleKey] : inline[hostLifecycleKey];
241
+ if (inherited) {
242
+ delete inline[WEAPP_VITE_HOST_RESTART_CONFIG_KEY];
243
+ delete inline[hostLifecycleKey];
244
+ }
245
+ return inherited;
246
+ }
247
+ /** 需要参与配置准备的数据在 configureServer 之前读取,且只能接管一次。 */
248
+ function takeHostConfigRestartData(lifecycle, key) {
249
+ const value = lifecycle?.data.get(key)?.value;
250
+ lifecycle?.data.delete(key);
251
+ return value;
252
+ }
218
253
  /** 重启附带数据仅属于这一条宿主链,不写入调用方配置或共享的进程缓存。 */
219
254
  async function setHostRestartData(server, key, value, dispose) {
220
255
  const data = hostData.get(server);
@@ -234,46 +269,99 @@ function takeHostRestartData(server, key) {
234
269
  return value;
235
270
  }
236
271
  /** 关闭等待正在替换服务器的重启,避免旧入口返回后新会话继续写出。 */
237
- function bindHostLifecycle(server, closeSession) {
272
+ function bindHostLifecycle(server, closeSession, preparedLifecycle, isRetired, finalize) {
238
273
  const nativeRestart = server.restart.bind(server);
239
274
  const generation = getDevServerCloseRecord(server);
240
275
  const nativeClose = generation.close;
276
+ const hostWatcher = server.watcher;
277
+ const nativeWatcherClose = hostWatcher?.close.bind(hostWatcher);
278
+ let watcherCloseTask;
279
+ const closeHostWatcher = () => watcherCloseTask ??= Promise.resolve().then(() => nativeWatcherClose?.()).then(() => {});
280
+ if (hostWatcher) hostWatcher.close = closeHostWatcher;
241
281
  const scope = getDevShutdownScope();
242
282
  const inlineConfig = server.config.inlineConfig;
243
- const inherited = inlineConfig[hostLifecycleKey];
283
+ const inherited = preparedLifecycle ?? takeHostLifecycle(inlineConfig);
284
+ const operations = inherited?.operations ?? createHostOperations();
244
285
  const inheritedRestart = inherited?.restartTask;
286
+ let inheritedRestartSettled = !inheritedRestart;
287
+ inheritedRestart?.then(() => {
288
+ inheritedRestartSettled = true;
289
+ }, () => {
290
+ inheritedRestartSettled = true;
291
+ });
245
292
  const data = /* @__PURE__ */ new Map();
246
293
  hostData.set(server, {
247
294
  incoming: inherited?.data,
248
295
  outgoing: data
249
296
  });
250
- delete inlineConfig[hostLifecycleKey];
251
297
  const stopping = Promise.withResolvers();
252
298
  let restartTask;
253
299
  let closeTask;
254
- const lifecycle = {
255
- data,
256
- get restartTask() {
257
- return restartTask;
258
- }
300
+ let retired = false;
301
+ for (const environment of Object.values(server.environments ?? {})) {
302
+ const listen = environment.listen.bind(environment);
303
+ environment.listen = async (...args) => {
304
+ if (!retired && !isRetired?.()) await listen(...args);
305
+ };
306
+ }
307
+ const replacements = /* @__PURE__ */ new Set();
308
+ let restartCleanupFailure;
309
+ const discardRestartResources = async (status) => {
310
+ const active = getDevServerCloseRecord(server);
311
+ const abandoned = [...replacements].filter((replacement) => replacement !== active);
312
+ replacements.clear();
313
+ await settleHostCleanup([discardRestartData(data, status), ...abandoned.map((replacement) => Promise.resolve().then(() => replacement.close()))]).catch((error) => {
314
+ restartCleanupFailure ??= { error };
315
+ throw error;
316
+ });
259
317
  };
260
318
  const closeResources = async () => {
319
+ retired = true;
261
320
  stopping.resolve();
321
+ const pendingRestart = restartTask;
262
322
  const sessionCleanup = settleHostCleanup([
263
- Promise.resolve().then(closeSession),
323
+ Promise.resolve().then(() => closeSession("close")),
264
324
  discardRestartData(data, "incomplete"),
265
325
  discardRestartData(inherited?.data, "incomplete")
266
326
  ]);
267
- await settleHostCleanup([sessionCleanup, (async () => {
327
+ const hostCleanup = (async () => {
268
328
  await sessionCleanup.catch(() => {});
269
- await restartTask?.catch(() => {});
329
+ await pendingRestart?.catch(() => {});
270
330
  const current = getDevServerCloseRecord(server);
271
- if (current !== generation) await current.close();
272
- else await nativeClose();
273
- })()]);
331
+ await settleHostCleanup([closeHostWatcher(), Promise.resolve().then(() => current !== generation ? current.close() : nativeClose())]);
332
+ })();
333
+ const restartCleanup = (async () => {
334
+ await pendingRestart;
335
+ if (restartCleanupFailure) throw restartCleanupFailure.error;
336
+ })();
337
+ await settleHostCleanup([(async () => {
338
+ await settleHostCleanup([sessionCleanup, hostCleanup]);
339
+ if (!restartCleanupFailure && inheritedRestartSettled) await finalize?.();
340
+ })(), restartCleanup]);
341
+ };
342
+ const closeLocal = () => operations.run(closeResources);
343
+ const close = () => closeTask ??= scope ? scope.run("cleanup", closeLocal) : closeLocal();
344
+ const lifecycle = {
345
+ data,
346
+ operations,
347
+ close: inherited?.close ?? close,
348
+ registerReplacement(replacement) {
349
+ replacements.delete(getDevServerCloseRecord(server));
350
+ replacements.add(replacement);
351
+ },
352
+ get restartTask() {
353
+ return restartTask;
354
+ }
274
355
  };
275
- const close = () => closeTask ??= scope ? scope.run("cleanup", closeResources) : closeResources();
276
356
  replaceDevServerClose(server, close);
357
+ if (inherited) {
358
+ const previousGate = generation.gate;
359
+ generation.gate = (closeResources) => {
360
+ const dispatch = () => operations.isInternal() ? closeResources() : inherited.close();
361
+ return previousGate ? previousGate(dispatch) : dispatch();
362
+ };
363
+ }
364
+ inherited?.registerReplacement(generation);
277
365
  server.restart = (force) => {
278
366
  if (closeTask || scope?.stopping) return close();
279
367
  const restart = async () => {
@@ -282,12 +370,16 @@ function bindHostLifecycle(server, closeSession) {
282
370
  if (closeTask || scope?.stopping) return;
283
371
  }
284
372
  try {
285
- await closeSession();
373
+ retired = true;
374
+ await closeSession("restart");
375
+ if (closeTask || scope?.stopping) return;
376
+ await closeHostWatcher();
286
377
  if (closeTask || scope?.stopping) return;
287
378
  const config = server.config;
379
+ const carrier = Object.assign(() => {}, { [hostLifecycleKey]: lifecycle });
288
380
  const restartConfig = {
289
381
  ...config.inlineConfig,
290
- [hostLifecycleKey]: lifecycle
382
+ [WEAPP_VITE_HOST_RESTART_CONFIG_KEY]: carrier
291
383
  };
292
384
  const restartHostConfig = {
293
385
  ...config,
@@ -296,25 +388,26 @@ function bindHostLifecycle(server, closeSession) {
296
388
  server.config = restartHostConfig;
297
389
  try {
298
390
  await nativeRestart(force);
391
+ if (getDevServerCloseRecord(server) === generation) throw new Error("[weapp-vite] Vite 重启未完成替换宿主交接,请查看原始初始化错误。");
299
392
  } finally {
300
- delete restartConfig[hostLifecycleKey];
393
+ delete restartConfig[WEAPP_VITE_HOST_RESTART_CONFIG_KEY];
301
394
  if (server.config === restartHostConfig) server.config = config;
302
395
  }
303
396
  } catch (error) {
304
397
  try {
305
- await discardRestartData(data, "failed");
398
+ await discardRestartResources("failed");
306
399
  } catch (cleanupError) {
307
- throw new AggregateError([error, cleanupError], "Host restart and handoff cleanup failed", { cause: error });
400
+ throw new AggregateError([error, cleanupError], "Host restart and resource cleanup failed", { cause: error });
308
401
  }
309
402
  throw error;
310
- } finally {
311
- await discardRestartData(data, "incomplete");
312
403
  }
404
+ await discardRestartResources("incomplete");
313
405
  };
314
- return restartTask ??= (scope ? scope.run("restart", restart) : restart()).finally(() => {
406
+ const runRestart = () => operations.run(restart);
407
+ return restartTask ??= (scope ? scope.run("restart", runRestart) : runRestart()).finally(() => {
315
408
  restartTask = void 0;
316
409
  });
317
410
  };
318
411
  }
319
412
  //#endregion
320
- export { getDevShutdownScope as a, createDevShutdownScope as i, setHostRestartData as n, getDevServerCloseRecord as o, takeHostRestartData as r, replaceDevServerClose as s, bindHostLifecycle as t };
413
+ export { takeHostRestartData as a, getDevServerCloseRecord as c, takeHostLifecycle as i, replaceDevServerClose as l, setHostRestartData as n, createDevShutdownScope as o, takeHostConfigRestartData as r, getDevShutdownScope as s, bindHostLifecycle as t };
@@ -1,4 +1,4 @@
1
- import { E as loadViteConfigFile, M as createCjsConfigLoadError, t as resolveWeappConfigFile } from "./utils-CJSCgEj6.mjs";
1
+ import { A as createCjsConfigLoadError, C as loadViteConfigFile, t as resolveWeappConfigFile } from "./utils-Dy51PYAC.mjs";
2
2
  import process from "node:process";
3
3
  import path from "pathe";
4
4
  import { defu } from "@weapp-core/shared";
@@ -0,0 +1 @@
1
+ export { t as loadConfig } from "./loadConfig-BWIsDXR4.mjs";
@@ -0,0 +1,57 @@
1
+ import { s as getProjectConfigFileName } from "./utils-Dy51PYAC.mjs";
2
+ import { r as logger_default, t as colors } from "./logger-DGn5iEVN.mjs";
3
+ import process from "node:process";
4
+ import { resolveCommand } from "package-manager-detector/commands";
5
+ //#region src/cli/commands/build/completion.ts
6
+ function shouldScheduleCompletedProductionBuildExit(options, analyzeHandle) {
7
+ return process.env.VITEST !== "true" && process.env.NODE_ENV !== "test" && process.env.WEAPP_VITE_DISABLE_COMPLETED_BUILD_EXIT !== "1" && options.watch !== true && options.open !== true && analyzeHandle === void 0;
8
+ }
9
+ function scheduleCompletedProductionBuildExit(options, analyzeHandle) {
10
+ if (!shouldScheduleCompletedProductionBuildExit(options, analyzeHandle)) return;
11
+ setTimeout(() => {
12
+ if (process.exitCode === void 0 || process.exitCode === 0) process.exit(0);
13
+ }, 0).unref?.();
14
+ }
15
+ //#endregion
16
+ //#region src/cli/formatDuration.ts
17
+ /**
18
+ * 将毫秒耗时格式化为适合 CLI 展示的文本。
19
+ */
20
+ function formatDuration(durationMs) {
21
+ return `${durationMs}ms`;
22
+ }
23
+ //#endregion
24
+ //#region src/cli/logBuildAppFinish.ts
25
+ let logBuildAppFinishOnlyShowOnce = false;
26
+ function collectServerUrls(webServer) {
27
+ const urls = webServer?.resolvedUrls;
28
+ if (!urls) return [];
29
+ return [...urls.local ?? [], ...urls.network ?? []];
30
+ }
31
+ function logBuildAppFinish(configService, webServer, options = {}) {
32
+ if (logBuildAppFinishOnlyShowOnce) return;
33
+ const { skipMini = false, skipWeb = false, uiUrls = [] } = options;
34
+ const webUrls = skipWeb ? [] : collectServerUrls(webServer);
35
+ if (skipMini) {
36
+ logger_default.success("开发服务已就绪:");
37
+ if (webUrls.length > 0) logger_default.info(`Web:${colors.cyan(webUrls[0])}`);
38
+ else logger_default.info("Web:已启动");
39
+ logBuildAppFinishOnlyShowOnce = true;
40
+ return;
41
+ }
42
+ const { command, args } = resolveCommand(configService.packageManager.agent, "run", ["open"]) ?? {
43
+ command: "npm",
44
+ args: ["run", "open"]
45
+ };
46
+ const devCommand = `${command} ${args.join(" ")}`;
47
+ logger_default.success("开发服务已就绪:");
48
+ logger_default.info(`小程序:执行 ${colors.bold(colors.green(devCommand))},或手动导入 ${colors.green(getProjectConfigFileName(configService.platform))}`);
49
+ if (uiUrls.length > 0) logger_default.info(`UI:${colors.cyan(uiUrls[0])}`);
50
+ else if (!skipMini) logger_default.info("UI:未启用");
51
+ if (webUrls.length > 0) logger_default.info(`Web:${colors.cyan(webUrls[0])}`);
52
+ const projectConfigFileName = getProjectConfigFileName(configService.platform);
53
+ if (!uiUrls.length && !webUrls.length) logger_default.info(`提示:手动打开对应平台开发者工具,导入根目录(${colors.green(projectConfigFileName)} 文件所在目录)`);
54
+ logBuildAppFinishOnlyShowOnce = true;
55
+ }
56
+ //#endregion
57
+ export { formatDuration as n, scheduleCompletedProductionBuildExit as r, logBuildAppFinish as t };
@@ -0,0 +1,86 @@
1
+ import process from "node:process";
2
+ import path from "node:path";
3
+ import { writeFile } from "node:fs/promises";
4
+ //#region src/cli/commands/accept.ts
5
+ function registerAcceptCommand(cli) {
6
+ cli.command("accept [root]", "run deterministic mini-program acceptance without a model").option("--init", "create acceptance configuration without overwriting").option("--inspect", "inspect acceptance prerequisites without executing project code").option("--report <jobId>", "read a saved report and check source freshness").option("--acceptance-config <file>", "select an acceptance JSON configuration").option("--trust", "authorize the reviewed configuration for this invocation").option("--json", "write protocol data only to stdout").action(async (root = ".", options) => {
7
+ try {
8
+ const directory = path.resolve(root);
9
+ const { defaultVerification, detectProject, safePath } = await import("@weapp-vite/acceptance");
10
+ if (options.init) {
11
+ const target = await safePath(directory, options.acceptanceConfig ?? "weapp-acceptance.config.json");
12
+ const config = {
13
+ version: 1,
14
+ verification: defaultVerification(await detectProject(directory)),
15
+ acceptance: {
16
+ requiredChecks: ["build", "devtools"],
17
+ scenarios: [],
18
+ timeoutMs: 6e5
19
+ }
20
+ };
21
+ await writeFile(target, `${JSON.stringify(config, null, 2)}\n`, { flag: "wx" });
22
+ process.stdout.write(`${JSON.stringify({
23
+ created: target,
24
+ modelRequired: false
25
+ })}\n`);
26
+ return;
27
+ }
28
+ const { createRuntimeAcceptanceService } = await import("@weapp-vite/mcp");
29
+ const { connectMiniProgram, prepareAcceptanceProject, resolveAutomatorSessionOptions } = await import("weapp-ide-cli");
30
+ const service = await createRuntimeAcceptanceService(directory, {
31
+ trust: Boolean(options.trust && !options.inspect && !options.report),
32
+ configFile: options.acceptanceConfig
33
+ }, {
34
+ connectMiniProgram,
35
+ resolveSessionOptions: resolveAutomatorSessionOptions,
36
+ prepareProject: prepareAcceptanceProject
37
+ });
38
+ let jobId;
39
+ let cancelRequested = false;
40
+ const cancel = () => {
41
+ cancelRequested = true;
42
+ if (jobId) service.cancel(jobId);
43
+ };
44
+ process.once("SIGINT", cancel);
45
+ try {
46
+ let result;
47
+ if (options.inspect) result = await service.inspect();
48
+ else if (options.report) result = await service.report(options.report);
49
+ else {
50
+ let report = await service.start();
51
+ jobId = report.jobId;
52
+ if (cancelRequested) await service.cancel(jobId);
53
+ while (report.status === "running") {
54
+ await new Promise((resolve) => setTimeout(resolve, 100));
55
+ report = await service.report(jobId);
56
+ }
57
+ result = report;
58
+ }
59
+ process.stdout.write(`${JSON.stringify(result, null, options.json ? void 0 : 2)}\n`);
60
+ if ("passed" in result && (!result.passed || result.snapshot.stale)) process.exitCode = 1;
61
+ } finally {
62
+ process.off("SIGINT", cancel);
63
+ await service.close();
64
+ }
65
+ } catch (error) {
66
+ const message = error instanceof Error ? error.message : String(error);
67
+ if (options.json) process.stdout.write(`${JSON.stringify({
68
+ status: "failed",
69
+ passed: false,
70
+ reason: message
71
+ })}\n`);
72
+ else process.stderr.write(`${message}\n`);
73
+ process.exitCode = 1;
74
+ }
75
+ });
76
+ }
77
+ //#endregion
78
+ //#region src/cli/commands/mcp/index.ts
79
+ function registerMcpCommand(cli) {
80
+ cli.command("mcp [...args]", "start weapp-vite MCP server or manage MCP client onboarding").option("--transport <type>", "[string] stdio | streamable-http | command | http", { default: "stdio" }).option("--host <host>", "[string] streamable-http host").option("--port <port>", "[number] streamable-http port").option("--endpoint <path>", "[string] streamable-http endpoint path").option("--rest-endpoint <path>", "[string] streamable-http REST runtime endpoint path").option("--no-rest", "[boolean] disable streamable-http REST runtime endpoints").option("--unref", "[boolean] unref HTTP server to not block process exit").option("--url <url>", "[string] explicit HTTP MCP url").option("--workspace-root <path>", "[string] workspace root path, defaults to cwd").option("-y, --yes", "[boolean] write config without prompt").action(async (args, options) => {
81
+ const { runMcpCommand } = await import("./action-BELcDNNv.mjs");
82
+ return runMcpCommand(args, options);
83
+ });
84
+ }
85
+ //#endregion
86
+ export { registerAcceptCommand as n, registerMcpCommand as t };
package/dist/mcp.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { Wt as WeappMcpConfig } from "./config-V0L-IAJf.mjs";
1
+ import { Ut as WeappMcpConfig } from "./config-Bf6DWhyb.mjs";
2
2
  import { DEFAULT_MCP_ENDPOINT, DEFAULT_MCP_HOST, DEFAULT_MCP_PORT, DEFAULT_RUNTIME_REST_ENDPOINT } from "@weapp-core/constants";
3
3
  import { CreateServerOptions, McpServerHandle, StartMcpServerOptions, createWeappViteMcpServer as createWeappViteMcpServer$1 } from "@weapp-vite/mcp";
4
4
  //#region src/mcp.d.ts