weapp-vite 7.3.0 → 7.5.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 (91) hide show
  1. package/README.md +154 -6
  2. package/bin/bootstrap.js +14 -1
  3. package/dist/adapters-CcHrsYaj.mjs +1 -0
  4. package/dist/analyze-ZJUvEdaY.mjs +248 -0
  5. package/dist/auto-import-components/resolvers.mjs +1 -2
  6. package/dist/auto-import-presets/wevu-router.mjs +1 -2
  7. package/dist/auto-import-presets/wevu.mjs +1 -2
  8. package/dist/auto-routes.mjs +2 -1
  9. package/dist/budget-BD7VqLCl.d.mts +178 -0
  10. package/dist/chunkStrategy-DRA5WpB-.mjs +1436 -0
  11. package/dist/cli-acceptance.d.mts +1 -0
  12. package/dist/cli-acceptance.mjs +21 -0
  13. package/dist/cli.mjs +1918 -2089
  14. package/dist/compatibility.mjs +1 -2
  15. package/dist/{config-1J4rToMR.d.mts → config-V0L-IAJf.d.mts} +419 -39
  16. package/dist/config.d.mts +2 -2
  17. package/dist/config.mjs +1 -1
  18. package/dist/constants-DEZdcsMn.mjs +85 -0
  19. package/dist/{createContext-cqr9Y4EV.mjs → createCompilerContextInstance-DJH_P_nZ.mjs} +17602 -15886
  20. package/dist/createContext-BqYzHhY9.mjs +12 -0
  21. package/dist/dashboard/analyze.d.mts +48 -0
  22. package/dist/dashboard/analyze.mjs +1 -0
  23. package/dist/dashboard/vite.d.mts +9 -0
  24. package/dist/dashboard/vite.mjs +44 -0
  25. package/dist/dashboard-DvqF3Key.mjs +1842 -0
  26. package/dist/dashboard.d.mts +3 -0
  27. package/dist/dashboard.mjs +1 -0
  28. package/dist/dashboardViteBridge-Dy3nAD4m.mjs +299 -0
  29. package/dist/dev-fR5GiJRO.mjs +63 -0
  30. package/dist/devProvider-BGBkw28J.mjs +1050 -0
  31. package/dist/docs/README.md +154 -6
  32. package/dist/docs/ai-workflows.md +4 -0
  33. package/dist/docs/doctor.md +38 -0
  34. package/dist/docs/getting-started.md +52 -1
  35. package/dist/docs/index.md +6 -2
  36. package/dist/docs/mcp.md +94 -1
  37. package/dist/docs/testing.md +29 -2
  38. package/dist/docs/troubleshooting.md +8 -0
  39. package/dist/docs/uni-app-component-libraries.md +8 -7
  40. package/dist/docs/upload.md +226 -0
  41. package/dist/docs/vite-plugin.md +171 -0
  42. package/dist/docs/vue-sfc.md +19 -0
  43. package/dist/docs/weapp-config.md +374 -2
  44. package/dist/docs/wevu-authoring.md +10 -0
  45. package/dist/doctor-worker.d.mts +1 -0
  46. package/dist/doctor-worker.mjs +59 -0
  47. package/dist/doctor.d.mts +144 -0
  48. package/dist/doctor.mjs +848 -0
  49. package/dist/eslint.mjs +1 -2
  50. package/dist/file-DRb4eWqw.mjs +1 -0
  51. package/dist/{file-CKB0Tn8Z.mjs → file-sC3jD7Fh.mjs} +16 -93
  52. package/dist/files-BqxFIPRp.mjs +45 -0
  53. package/dist/getInstance-DiGSzBNI.mjs +28 -0
  54. package/dist/getInstance-SiE6WZRh.mjs +1 -0
  55. package/dist/index-C9HjUX5c.d.mts +741 -0
  56. package/dist/index.d.mts +10 -8
  57. package/dist/index.mjs +3 -2
  58. package/dist/json.d.mts +1 -1
  59. package/dist/json.mjs +1 -2
  60. package/dist/lifecycle-BROTlwSL.mjs +320 -0
  61. package/dist/loadConfig-C3BQhz7F.mjs +59 -0
  62. package/dist/loadConfig-VGtBF4qm.mjs +1 -0
  63. package/dist/logger-DGn5iEVN.mjs +1 -0
  64. package/dist/{mcp-BG6TliEg.mjs → mcp-Cj8Maqo6.mjs} +16 -7
  65. package/dist/mcp-D3Yh24Cj.mjs +529 -0
  66. package/dist/mcp.d.mts +6 -3
  67. package/dist/mcp.mjs +1 -2
  68. package/dist/package-7swhyLmf.mjs +91 -0
  69. package/dist/path-doV773b7.mjs +103 -0
  70. package/dist/platform-CnkySBKz.mjs +175 -0
  71. package/dist/processCleanup-B6KA30Zc.mjs +77 -0
  72. package/dist/protocol-vg8HGJ4n.mjs +138 -0
  73. package/dist/{resolvers-icNxkpcy.mjs → resolvers-Dod-euqX.mjs} +4 -1
  74. package/dist/resolvers.mjs +1 -2
  75. package/dist/runtime.mjs +1 -2
  76. package/dist/session-PskhD-nZ.mjs +390 -0
  77. package/dist/test.d.mts +1 -0
  78. package/dist/test.mjs +201 -44
  79. package/dist/types.d.mts +2 -2
  80. package/dist/upload-D4msblBf.mjs +562 -0
  81. package/dist/upload-worker.d.mts +1 -0
  82. package/dist/upload-worker.mjs +161 -0
  83. package/dist/utils-CJSCgEj6.mjs +1094 -0
  84. package/dist/vite.d.mts +9 -0
  85. package/dist/vite.mjs +270 -0
  86. package/dist/volar.d.mts +2 -2
  87. package/dist/web-apis.mjs +1 -2
  88. package/package.json +85 -37
  89. package/dist/file-CvgkbGIx.mjs +0 -2
  90. package/dist/getInstance-CZ1s63zd.mjs +0 -2
  91. package/dist/logger-mt4mSTqV.mjs +0 -2
package/dist/eslint.mjs CHANGED
@@ -1,2 +1 @@
1
- import { createMiniProgramRuntimeConfig, miniProgramRuntimeApiCatalog, miniProgramRuntimePlugin, miniProgramRuntimeRecommended, wevuCompatibilityPlugin, wevuCompatibilityRecommended } from "@weapp-vite/eslint";
2
- export { createMiniProgramRuntimeConfig, miniProgramRuntimeApiCatalog, miniProgramRuntimePlugin, miniProgramRuntimeRecommended, wevuCompatibilityPlugin, wevuCompatibilityRecommended };
1
+ export { createMiniProgramRuntimeConfig, miniProgramRuntimeApiCatalog, miniProgramRuntimePlugin, miniProgramRuntimeRecommended, wevuCompatibilityPlugin, wevuCompatibilityRecommended } from "@weapp-vite/eslint";
@@ -0,0 +1 @@
1
+ export { t as extractConfigFromVue } from "./file-sC3jD7Fh.mjs";
@@ -1,8 +1,8 @@
1
+ import { a as supportedCssLangs, i as scriptExtensions, l as getSourceStyleExtensions, n as configExtensions, o as templateExtensions, p as isSourceTemplateExtension, s as vueExtensions, u as getSourceTemplateExtensions } from "./constants-DEZdcsMn.mjs";
1
2
  import { createRequire } from "node:module";
3
+ import process from "node:process";
2
4
  import path from "pathe";
3
- import { MINI_PROGRAM_PLATFORM_DESCRIPTORS as MINI_PROGRAM_PLATFORM_ADAPTERS } from "@weapp-core/shared";
4
5
  import { fs } from "@weapp-core/shared/fs";
5
- import process from "node:process";
6
6
  import { recursive } from "merge";
7
7
  import { parse } from "vue/compiler-sfc";
8
8
  //#region src/utils/file/autoRoutes.ts
@@ -52,10 +52,9 @@ function resolveAutoRoutesMacroImportPath() {
52
52
  for (const candidate of fallbackCandidates) if (fs.existsSync(candidate)) return candidate;
53
53
  throw new Error("无法解析 auto-routes 模块路径。");
54
54
  }
55
- async function resolveAutoRoutesInlineSnapshot() {
55
+ async function resolveAutoRoutesInlineSnapshot(context) {
56
56
  try {
57
- const { getCompilerContext } = await import("./getInstance-CZ1s63zd.mjs");
58
- const compilerContext = getCompilerContext();
57
+ const compilerContext = context ?? (await import("./getInstance-SiE6WZRh.mjs")).getCompilerContext();
59
58
  const service = compilerContext.autoRoutesService;
60
59
  const reference = service?.getReference?.();
61
60
  if (!compilerContext.runtimeState.autoRoutes.loadingAppConfig) await service?.ensureFresh?.();
@@ -86,89 +85,6 @@ function inlineAutoRoutesImports(source, inlineRoutes) {
86
85
  }).join("\n").replace(AUTO_ROUTES_DYNAMIC_IMPORT_RE, `Promise.resolve(${JSON.stringify(inlineRoutes)})`).replace(AUTO_ROUTES_SPECIFIER_RE, JSON.stringify(resolveAutoRoutesMacroImportPath()));
87
86
  }
88
87
  //#endregion
89
- //#region src/platforms/sourceAssets.ts
90
- const PORTABLE_TEMPLATE_EXTENSIONS = ["wxml", "html"];
91
- const PORTABLE_STYLE_EXTENSIONS = [
92
- "wxss",
93
- "css",
94
- "scss",
95
- "less",
96
- "sass",
97
- "styl"
98
- ];
99
- function uniqueExtensions(extensions) {
100
- return Array.from(new Set(extensions.filter((extension) => Boolean(extension))));
101
- }
102
- const ALL_NATIVE_TEMPLATE_EXTENSIONS = uniqueExtensions(MINI_PROGRAM_PLATFORM_ADAPTERS.map((adapter) => adapter.outputExtensions.wxml));
103
- const ALL_NATIVE_STYLE_EXTENSIONS = uniqueExtensions(MINI_PROGRAM_PLATFORM_ADAPTERS.map((adapter) => adapter.outputExtensions.wxss));
104
- const ALL_NATIVE_STYLE_RESOLVER_EXTENSIONS = ALL_NATIVE_STYLE_EXTENSIONS.filter((extension) => extension !== "css");
105
- const ALL_SOURCE_TEMPLATE_EXTENSIONS = uniqueExtensions([...PORTABLE_TEMPLATE_EXTENSIONS, ...ALL_NATIVE_TEMPLATE_EXTENSIONS]);
106
- const ALL_SOURCE_STYLE_EXTENSIONS = uniqueExtensions([...PORTABLE_STYLE_EXTENSIONS, ...ALL_NATIVE_STYLE_EXTENSIONS]);
107
- function getAdapter(platform) {
108
- return platform ? MINI_PROGRAM_PLATFORM_ADAPTERS.find((adapter) => adapter.id === platform) : void 0;
109
- }
110
- /**
111
- * 返回当前平台的模板源码选择顺序。
112
- * 原生平台后缀优先,便携源码后缀作为兼容回退。
113
- */
114
- function getSourceTemplateExtensions(platform) {
115
- const nativeExtension = getAdapter(platform)?.outputExtensions.wxml;
116
- return platform ? uniqueExtensions([nativeExtension, ...PORTABLE_TEMPLATE_EXTENSIONS]) : ALL_SOURCE_TEMPLATE_EXTENSIONS;
117
- }
118
- /**
119
- * 返回当前平台的样式源码选择顺序。
120
- * 原生平台后缀优先,预处理器和便携样式后缀继续可用。
121
- */
122
- function getSourceStyleExtensions(platform) {
123
- const nativeExtension = getAdapter(platform)?.outputExtensions.wxss;
124
- return platform ? uniqueExtensions([nativeExtension, ...PORTABLE_STYLE_EXTENSIONS]) : ALL_SOURCE_STYLE_EXTENSIONS;
125
- }
126
- function isSourceTemplateExtension(extension) {
127
- const normalized = extension.startsWith(".") ? extension.slice(1) : extension;
128
- return getSourceTemplateExtensions().includes(normalized);
129
- }
130
- function isSourceStyleExtension(extension) {
131
- const normalized = extension.startsWith(".") ? extension.slice(1) : extension;
132
- return getSourceStyleExtensions().includes(normalized);
133
- }
134
- function isNativeTemplateSource(filePath, platform) {
135
- const nativeExtension = getAdapter(platform)?.outputExtensions.wxml;
136
- return Boolean(nativeExtension && filePath.endsWith(`.${nativeExtension}`));
137
- }
138
- //#endregion
139
- //#region src/constants.ts
140
- const VERSION = "__VERSION__";
141
- /**
142
- * 源代码支持的 js 文件格式
143
- */
144
- const jsExtensions = ["ts", "js"];
145
- const scriptExtensions = [
146
- "ts",
147
- "js",
148
- "tsx",
149
- "jsx"
150
- ];
151
- /**
152
- * 源代码支持的 vue 文件格式
153
- */
154
- const vueExtensions = ["vue"];
155
- /**
156
- * 源代码支持的 json 文件格式
157
- */
158
- const configExtensions = [
159
- "jsonc",
160
- "json",
161
- ...jsExtensions.map((x) => `json.${x}`)
162
- ];
163
- /**
164
- * 源代码支持的 css 文件格式
165
- */
166
- const supportedCssLangs = ALL_SOURCE_STYLE_EXTENSIONS;
167
- /**
168
- * 源代码支持的 wxml 文件格式
169
- */
170
- const templateExtensions = ALL_SOURCE_TEMPLATE_EXTENSIONS;
171
- //#endregion
172
88
  //#region src/utils/file/entry.ts
173
89
  const pathExistsInFlight = /* @__PURE__ */ new Map();
174
90
  const JS_OR_TS_RE = /\.[jt]s$/;
@@ -245,6 +161,7 @@ async function touch(filename) {
245
161
  //#endregion
246
162
  //#region src/utils/file/vueConfig.ts
247
163
  const vueConfigCache = /* @__PURE__ */ new Map();
164
+ const contextConfigCaches = /* @__PURE__ */ new WeakMap();
248
165
  const configMtimeInFlight = /* @__PURE__ */ new Map();
249
166
  const NODE_MODULES_RE = /[\\/]node_modules[\\/]/;
250
167
  const JSON_MACRO_HINT_RE = /\bdefine(?:App|Page|Component|Sitemap|Theme)Json\s*\(/;
@@ -276,8 +193,13 @@ async function isVueConfigCacheValid(vueFilePath, cache) {
276
193
  */
277
194
  async function extractConfigFromVue(vueFilePath, options) {
278
195
  try {
279
- const cached = options?.force ? void 0 : vueConfigCache.get(vueFilePath);
280
- if (cached && await isVueConfigCacheValid(vueFilePath, cached)) return cached.config;
196
+ const context = options?.compilerContext;
197
+ const cache = context ? contextConfigCaches.get(context) ?? /* @__PURE__ */ new Map() : vueConfigCache;
198
+ if (context) contextConfigCaches.set(context, cache);
199
+ const cached = options?.force ? void 0 : cache.get(vueFilePath);
200
+ let autoRoutesInline;
201
+ if (cached?.autoRoutesSignature !== void 0) autoRoutesInline = await resolveAutoRoutesInlineSnapshot(context);
202
+ if (cached && (cached.autoRoutesSignature === void 0 || cached.autoRoutesSignature === JSON.stringify(autoRoutesInline)) && await isVueConfigCacheValid(vueFilePath, cached)) return cached.config;
281
203
  const content = options?.source ?? (options?.readSource ? await options.readSource() : await fs.readFile(vueFilePath, "utf-8"));
282
204
  if (content === void 0) return;
283
205
  const { descriptor, errors } = parse(content, { filename: vueFilePath });
@@ -299,7 +221,7 @@ async function extractConfigFromVue(vueFilePath, options) {
299
221
  const { extractJsonMacroFromScriptSetup } = await import("wevu/compiler");
300
222
  try {
301
223
  const preambleContent = descriptor.script?.content;
302
- const autoRoutesInline = hasAutoRoutesMacroImport(setupContent) || preambleContent !== void 0 && hasAutoRoutesMacroImport(preambleContent) ? await resolveAutoRoutesInlineSnapshot() : void 0;
224
+ autoRoutesInline = hasAutoRoutesMacroImport(setupContent) || preambleContent !== void 0 && hasAutoRoutesMacroImport(preambleContent) ? autoRoutesInline ?? await resolveAutoRoutesInlineSnapshot(options?.compilerContext) : void 0;
303
225
  const macroEvalPreamble = preambleContent && autoRoutesInline ? inlineAutoRoutesImports(preambleContent, autoRoutesInline) : preambleContent;
304
226
  const extracted = await extractJsonMacroFromScriptSetup(autoRoutesInline ? inlineAutoRoutesImports(setupContent, autoRoutesInline) : setupContent, vueFilePath, descriptor.scriptSetup?.lang, { preambleContent: macroEvalPreamble });
305
227
  if (extracted.dependencies?.length) macroDependencies.push(...extracted.dependencies);
@@ -316,8 +238,9 @@ async function extractConfigFromVue(vueFilePath, options) {
316
238
  }));
317
239
  const fileMtimeMs = await getMtimeCached(vueFilePath);
318
240
  const hasConfig = Object.keys(mergedConfig).length > 0;
319
- vueConfigCache.set(vueFilePath, {
241
+ cache.set(vueFilePath, {
320
242
  config: hasConfig ? mergedConfig : void 0,
243
+ autoRoutesSignature: autoRoutesInline && JSON.stringify(autoRoutesInline),
321
244
  fileMtimeMs,
322
245
  dependencies: normalizedDependencies,
323
246
  dependencyMtimeMs
@@ -329,4 +252,4 @@ async function extractConfigFromVue(vueFilePath, options) {
329
252
  }
330
253
  }
331
254
  //#endregion
332
- export { hasAutoRoutesMacroImport as C, MINI_PROGRAM_PLATFORM_ADAPTERS as E, getAutoRoutesMacroImportCandidates as S, resolveAutoRoutesInlineSnapshot as T, templateExtensions as _, findJsonEntry as a, isNativeTemplateSource as b, isJsOrTs as c, touch as d, VERSION as f, supportedCssLangs as g, scriptExtensions as h, findJsEntry as i, isTemplate as l, jsExtensions as m, changeFileExtension as n, findTemplateEntry as o, configExtensions as p, findCssEntry as r, findVueEntry as s, extractConfigFromVue as t, normalizeFileExtension as u, vueExtensions as v, inlineAutoRoutesImports as w, isSourceStyleExtension as x, ALL_NATIVE_STYLE_RESOLVER_EXTENSIONS as y };
255
+ export { findJsonEntry as a, isJsOrTs as c, touch as d, getAutoRoutesMacroImportCandidates as f, resolveAutoRoutesInlineSnapshot as h, findJsEntry as i, isTemplate as l, inlineAutoRoutesImports as m, changeFileExtension as n, findTemplateEntry as o, hasAutoRoutesMacroImport as p, findCssEntry as r, findVueEntry as s, extractConfigFromVue as t, normalizeFileExtension as u };
@@ -0,0 +1,45 @@
1
+ import path from "node:path";
2
+ import { readFile, readdir } from "node:fs/promises";
3
+ import { createHash } from "node:crypto";
4
+ //#region src/doctor/files.ts
5
+ const excluded = /* @__PURE__ */ new Set([
6
+ "node_modules",
7
+ ".git",
8
+ ".weapp-vite",
9
+ ".codex-tmp",
10
+ "dist",
11
+ "coverage"
12
+ ]);
13
+ /** 不跟随符号链接;快照只包含所选目录内的普通文件。 */
14
+ async function readDoctorFiles(root, source = false) {
15
+ const result = [];
16
+ async function visit(directory) {
17
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
18
+ if (entry.isSymbolicLink()) throw new Error("扫描范围含符号链接,无法证明覆盖完整");
19
+ const absolute = path.join(directory, entry.name);
20
+ if (entry.isDirectory()) {
21
+ if (!source || !excluded.has(entry.name)) await visit(absolute);
22
+ } else if (entry.isFile()) {
23
+ const bytes = await readFile(absolute);
24
+ result.push({
25
+ path: path.relative(root, absolute).split(path.sep).join("/"),
26
+ size: bytes.length,
27
+ sha256: createHash("sha256").update(bytes).digest("hex"),
28
+ text: /\.(?:json|[cm]?[jt]sx?|vue|wxml|axml|swan|ttml|jxml|wxss|acss|css|wxs|sjs)$/.test(entry.name) ? bytes.toString("utf8") : void 0
29
+ });
30
+ }
31
+ }
32
+ }
33
+ await visit(root);
34
+ return result.sort((a, b) => a.path.localeCompare(b.path));
35
+ }
36
+ function objectValue(value) {
37
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
38
+ }
39
+ function parseObject(text) {
40
+ const value = text === void 0 ? void 0 : objectValue(JSON.parse(text));
41
+ if (!value) throw new Error("需要 JSON 对象");
42
+ return value;
43
+ }
44
+ //#endregion
45
+ export { parseObject as n, readDoctorFiles as r, objectValue as t };
@@ -0,0 +1,28 @@
1
+ import { t as createCompilerContextInstance } from "./createCompilerContextInstance-DJH_P_nZ.mjs";
2
+ //#region src/context/getInstance.ts
3
+ const compilerContextMap = /* @__PURE__ */ new Map();
4
+ const DEFAULT_KEY = "default";
5
+ let activeCompilerContextKey = DEFAULT_KEY;
6
+ function setActiveCompilerContextKey(key) {
7
+ activeCompilerContextKey = key;
8
+ }
9
+ function getCompilerContext(key = activeCompilerContextKey) {
10
+ let ctx = compilerContextMap.get(key);
11
+ if (!ctx) {
12
+ ctx = createCompilerContextInstance();
13
+ compilerContextMap.set(key, ctx);
14
+ setActiveCompilerContextKey(key);
15
+ }
16
+ return ctx;
17
+ }
18
+ function resetCompilerContext(key) {
19
+ if (key) {
20
+ compilerContextMap.delete(key);
21
+ if (activeCompilerContextKey === key) activeCompilerContextKey = DEFAULT_KEY;
22
+ return;
23
+ }
24
+ compilerContextMap.clear();
25
+ activeCompilerContextKey = DEFAULT_KEY;
26
+ }
27
+ //#endregion
28
+ export { resetCompilerContext as n, setActiveCompilerContextKey as r, getCompilerContext as t };
@@ -0,0 +1 @@
1
+ export { t as getCompilerContext } from "./getInstance-DiGSzBNI.mjs";