weapp-vite 7.4.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.
- package/README.md +59 -3
- package/THIRD_PARTY_NOTICES.md +60 -0
- package/bin/bootstrap.js +14 -1
- package/dist/action-B3YZMA-h.mjs +255 -0
- package/dist/action-BELcDNNv.mjs +139 -0
- package/dist/action-BOk3vGI7.mjs +1110 -0
- package/dist/action-DlC6JYpt.mjs +95 -0
- package/dist/action-zEDY7oh_.mjs +247 -0
- package/dist/adapters-CcHrsYaj.mjs +1 -0
- package/dist/analyze-DN79YOAH.mjs +184 -0
- package/dist/artifacts-BOyC9Fy-.mjs +106 -0
- package/dist/assets-C5_YYXNk.mjs +637 -0
- package/dist/auto-import-components/resolvers.mjs +1 -2
- package/dist/auto-import-presets/wevu-router.mjs +1 -2
- package/dist/auto-import-presets/wevu.mjs +1 -2
- package/dist/auto-routes.mjs +2 -1
- package/dist/budget-CTLOHwgI.d.mts +177 -0
- package/dist/budget-EOeEycc_.mjs +65 -0
- package/dist/builtProject-C29udgXY.mjs +541 -0
- package/dist/chunkStrategy-DY_LZIIe.mjs +1448 -0
- package/dist/classifier-DBJY__kg.mjs +88 -0
- package/dist/cli-acceptance.d.mts +1 -0
- package/dist/cli-acceptance.mjs +21 -0
- package/dist/cli.mjs +519 -5049
- package/dist/compatibility.mjs +1 -2
- package/dist/{config-Dbvj5yK7.d.mts → config-Bf6DWhyb.d.mts} +220 -76
- package/dist/config.d.mts +3 -3
- package/dist/config.mjs +1 -1
- package/dist/{constants-WOsG3Eqd.mjs → constants-DEZdcsMn.mjs} +1 -1
- package/dist/{createContext-UOEgeYnA.mjs → createCompilerContextInstance-aYwi8wQt.mjs} +36862 -32020
- package/dist/createContext-tApLtII-.mjs +15 -0
- package/dist/dashboard/analyze.d.mts +48 -0
- package/dist/dashboard/analyze.mjs +3 -0
- package/dist/dashboard/vite.d.mts +1 -1
- package/dist/dashboard.d.mts +3 -2
- package/dist/dashboard.mjs +1748 -1
- package/dist/dashboardTransport-C_Y6jMp-.mjs +16 -0
- package/dist/dashboardViteBridge-DCGR43aM.mjs +302 -0
- package/dist/dev-C2fgr_Xd.mjs +67 -0
- package/dist/devProvider-D-hTfsEO.mjs +3027 -0
- package/dist/docs/README.md +59 -3
- package/dist/docs/ai-workflows.md +4 -0
- package/dist/docs/doctor.md +38 -0
- package/dist/docs/getting-started.md +3 -1
- package/dist/docs/index.md +3 -1
- package/dist/docs/mcp.md +104 -1
- package/dist/docs/testing.md +29 -2
- package/dist/docs/troubleshooting.md +16 -0
- package/dist/docs/uni-app-component-libraries.md +8 -7
- package/dist/docs/upload.md +40 -3
- package/dist/docs/vite-plugin.md +171 -0
- package/dist/docs/vue-sfc.md +42 -0
- package/dist/docs/weapp-config.md +54 -0
- package/dist/docs/wevu-authoring.md +10 -0
- package/dist/doctor-worker.d.mts +1 -0
- package/dist/doctor-worker.mjs +60 -0
- package/dist/doctor.d.mts +144 -0
- package/dist/doctor.mjs +850 -0
- package/dist/engine-C66J0HLz.mjs +54 -0
- package/dist/eslint.mjs +1 -2
- package/dist/{file-giE9UMZa.mjs → file-CcIOmqhC.mjs} +58 -24
- package/dist/file-DtcteQ4G.mjs +1 -0
- package/dist/files-BqxFIPRp.mjs +45 -0
- package/dist/forwardConsole-B0Reo8Lf.mjs +511 -0
- package/dist/getInstance-BAIaU2y9.mjs +1 -0
- package/dist/getInstance-Dt9IQDKr.mjs +28 -0
- package/dist/history-BIiRCzbq.mjs +784 -0
- package/dist/i18n.d.mts +1 -1
- package/dist/index-D5rgBzYZ.d.mts +740 -0
- package/dist/index.d.mts +12 -10
- package/dist/index.mjs +3 -2
- package/dist/json.d.mts +1 -1
- package/dist/json.mjs +1 -2
- package/dist/lib-DjccSI1B.mjs +143 -0
- package/dist/lifecycle-C36WSbQS.mjs +413 -0
- package/dist/loadConfig-BWIsDXR4.mjs +59 -0
- package/dist/loadConfig-D-BpBgsk.mjs +1 -0
- package/dist/logBuildAppFinish-ChjwATMv.mjs +57 -0
- package/dist/logger-DGn5iEVN.mjs +1 -0
- package/dist/mcp-CYgX9HpO.mjs +86 -0
- package/dist/{mcp-BG6TliEg.mjs → mcp-Cj8Maqo6.mjs} +16 -7
- package/dist/mcp.d.mts +6 -3
- package/dist/mcp.mjs +1 -2
- package/dist/mcpClient-DVLvFLZv.mjs +287 -0
- package/dist/metadata-hwF7QRcS.mjs +59 -0
- package/dist/nodeEnv-BmH8UZPR.mjs +7 -0
- package/dist/openIde-CroqOgk5.mjs +648 -0
- package/dist/options-jqFwfD1G.mjs +34 -0
- package/dist/package-Cmakyy3J.mjs +4 -0
- package/dist/path-CYYIQGS7.mjs +44 -0
- package/dist/{platform-DTWs5QRi.mjs → platform-CnkySBKz.mjs} +1 -1
- package/dist/processCleanup-BQn2kTcK.mjs +19 -0
- package/dist/protocol-Cg6Jdlvb.mjs +141 -0
- package/dist/reader-sh_POQ9-.mjs +93 -0
- package/dist/realpathScope-Tf9mz-fh.mjs +23 -0
- package/dist/report-hyonPGbZ.mjs +107 -0
- package/dist/resolvedId-CiDl7SC1.mjs +60 -0
- package/dist/{resolvers-icNxkpcy.mjs → resolvers-Dod-euqX.mjs} +4 -1
- package/dist/resolvers.mjs +1 -2
- package/dist/runtime-CLUhQsdA.mjs +43 -0
- package/dist/{runtime-Ee2HY6gR.d.mts → runtime-DpVf714f.d.mts} +1 -1
- package/dist/runtime.d.mts +1 -1
- package/dist/runtime.mjs +1 -2
- package/dist/schematics-kO26eQRT.mjs +91 -0
- package/dist/session-D3zsdzIy.mjs +452 -0
- package/dist/test.d.mts +1 -0
- package/dist/test.mjs +204 -45
- package/dist/{types-CgZn5X6j.d.mts → types-D-kfuyVa.d.mts} +1 -2
- package/dist/types-D0FFexRF.d.mts +39 -0
- package/dist/types.d.mts +3 -3
- package/dist/{upload-D0RcEWrq.mjs → upload-DozK8UdN.mjs} +278 -15
- package/dist/upload-worker.mjs +136 -3
- package/dist/utils-Dy51PYAC.mjs +1034 -0
- package/dist/vite.d.mts +9 -0
- package/dist/vite.mjs +309 -0
- package/dist/volar.d.mts +2 -2
- package/dist/web-apis.mjs +1 -2
- package/dist/wxs-BT8btflA.mjs +112 -0
- package/dist/wxs-Z4VQDeJ_.mjs +1 -0
- package/package.json +80 -48
- package/dist/adapters-BwnMMIZR.mjs +0 -2
- package/dist/dashboard-BzaVesmQ.mjs +0 -558
- package/dist/file-D19nbDoN.mjs +0 -2
- package/dist/getInstance-CYF1vl5l.mjs +0 -2
- package/dist/index-DbqVupg0.d.mts +0 -246
- package/dist/logger-mt4mSTqV.mjs +0 -2
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
//#region src/runtime/viteHost/engine.ts
|
|
5
|
+
function readIdentity(file) {
|
|
6
|
+
const value = JSON.parse(readFileSync(file, "utf8"));
|
|
7
|
+
if (!value || typeof value !== "object" || !("name" in value) || typeof value.name !== "string" || !("version" in value) || typeof value.version !== "string") throw new Error("[weapp-vite] Vite 宿主 package.json 缺少 name/version。");
|
|
8
|
+
return {
|
|
9
|
+
name: value.name,
|
|
10
|
+
version: value.version
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** 按宿主的真实导出解析引擎,不依赖扁平 node_modules 布局或版本号相等。 */
|
|
14
|
+
function resolveViteHost(importer = import.meta.url) {
|
|
15
|
+
const packagePath = createRequire(importer).resolve("vite/package.json");
|
|
16
|
+
const identity = readIdentity(packagePath);
|
|
17
|
+
const hostRequire = createRequire(packagePath);
|
|
18
|
+
if (identity.name === "@voidzero-dev/vite-plus-core") return {
|
|
19
|
+
kind: "vite-plus",
|
|
20
|
+
packagePath,
|
|
21
|
+
packageVersion: identity.version,
|
|
22
|
+
experimentalPath: hostRequire.resolve("@voidzero-dev/vite-plus-core/rolldown/experimental")
|
|
23
|
+
};
|
|
24
|
+
if (identity.name !== "vite") throw new Error(`[weapp-vite] 不支持的 Vite 宿主:${identity.name}@${identity.version}。`);
|
|
25
|
+
return {
|
|
26
|
+
kind: "vite",
|
|
27
|
+
packagePath,
|
|
28
|
+
packageVersion: identity.version,
|
|
29
|
+
experimentalPath: hostRequire.resolve("rolldown/experimental")
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** 加载与宿主绑定的引擎;缺失能力时保留原始错误,禁止回退到另一套引擎。 */
|
|
33
|
+
async function loadHostRolldown(importer) {
|
|
34
|
+
let identity;
|
|
35
|
+
try {
|
|
36
|
+
identity = resolveViteHost(importer);
|
|
37
|
+
const runtime = await import(pathToFileURL(identity.experimentalPath).href);
|
|
38
|
+
if (typeof runtime.dev !== "function" || typeof runtime.scan !== "function") throw new TypeError("Rolldown 缺少 dev/scan 能力");
|
|
39
|
+
return runtime;
|
|
40
|
+
} catch (cause) {
|
|
41
|
+
const host = identity ? `${identity.kind}@${identity.packageVersion}` : "vite";
|
|
42
|
+
throw new Error(`[weapp-vite] 无法加载 ${host} 配套的 Rolldown;请检查宿主依赖和 Vite+ alias 配置。`, { cause });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** 原生输出写出也绑定宿主引擎,避免 Vite+ 额外加载包内另一套 Rolldown。 */
|
|
46
|
+
async function loadHostRolldownBuild(importer) {
|
|
47
|
+
const identity = resolveViteHost(importer);
|
|
48
|
+
const entry = createRequire(identity.packagePath).resolve(identity.kind === "vite-plus" ? "@voidzero-dev/vite-plus-core/rolldown" : "rolldown");
|
|
49
|
+
const runtime = await import(pathToFileURL(entry).href);
|
|
50
|
+
if (typeof runtime.rolldown !== "function") throw new TypeError(`[weapp-vite] ${identity.kind}@${identity.packageVersion} 缺少 Rolldown 原生写出能力。`);
|
|
51
|
+
return runtime;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { loadHostRolldownBuild as n, loadHostRolldown as t };
|
package/dist/eslint.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { createMiniProgramRuntimeConfig, miniProgramRuntimeApiCatalog, miniProgramRuntimePlugin, miniProgramRuntimeRecommended, wevuCompatibilityPlugin, wevuCompatibilityRecommended };
|
|
1
|
+
export { createMiniProgramRuntimeConfig, miniProgramRuntimeApiCatalog, miniProgramRuntimePlugin, miniProgramRuntimeRecommended, wevuCompatibilityPlugin, wevuCompatibilityRecommended } from "@weapp-vite/eslint";
|
|
@@ -1,8 +1,9 @@
|
|
|
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-
|
|
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";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
+
import process from "node:process";
|
|
3
4
|
import path from "pathe";
|
|
4
5
|
import { fs } from "@weapp-core/shared/fs";
|
|
5
|
-
import
|
|
6
|
+
import { createBabelBackendLoader } from "@weapp-vite/ast/babelLoader";
|
|
6
7
|
import { recursive } from "merge";
|
|
7
8
|
import { parse } from "vue/compiler-sfc";
|
|
8
9
|
//#region src/utils/file/autoRoutes.ts
|
|
@@ -52,10 +53,9 @@ function resolveAutoRoutesMacroImportPath() {
|
|
|
52
53
|
for (const candidate of fallbackCandidates) if (fs.existsSync(candidate)) return candidate;
|
|
53
54
|
throw new Error("无法解析 auto-routes 模块路径。");
|
|
54
55
|
}
|
|
55
|
-
async function resolveAutoRoutesInlineSnapshot() {
|
|
56
|
+
async function resolveAutoRoutesInlineSnapshot(context) {
|
|
56
57
|
try {
|
|
57
|
-
const
|
|
58
|
-
const compilerContext = getCompilerContext();
|
|
58
|
+
const compilerContext = context ?? (await import("./getInstance-BAIaU2y9.mjs")).getCompilerContext();
|
|
59
59
|
const service = compilerContext.autoRoutesService;
|
|
60
60
|
const reference = service?.getReference?.();
|
|
61
61
|
if (!compilerContext.runtimeState.autoRoutes.loadingAppConfig) await service?.ensureFresh?.();
|
|
@@ -160,8 +160,30 @@ async function touch(filename) {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
//#endregion
|
|
163
|
+
//#region src/plugins/utils/sourceSnapshot/registry.ts
|
|
164
|
+
const snapshots = /* @__PURE__ */ new WeakMap();
|
|
165
|
+
function getCompilerSourceSnapshotView(owner) {
|
|
166
|
+
return snapshots.get(owner);
|
|
167
|
+
}
|
|
168
|
+
function replaceCompilerSourceSnapshotView(owner, snapshot) {
|
|
169
|
+
if (snapshot) snapshots.set(owner, snapshot);
|
|
170
|
+
else snapshots.delete(owner);
|
|
171
|
+
}
|
|
172
|
+
function getCompilerSourceSnapshot(owner) {
|
|
173
|
+
return snapshots.get(owner)?.sources;
|
|
174
|
+
}
|
|
175
|
+
function getCompilerSourceResolutions(owner) {
|
|
176
|
+
return snapshots.get(owner)?.resolutions;
|
|
177
|
+
}
|
|
178
|
+
/** 轻量消费者只读取已登记的代际;源码身份由登记方沿用原编译器规则解析。 */
|
|
179
|
+
function readCompilerSourceSnapshotInput(owner, id) {
|
|
180
|
+
return snapshots.get(owner)?.readSource(id);
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
163
183
|
//#region src/utils/file/vueConfig.ts
|
|
184
|
+
const loadVueCompiler = createBabelBackendLoader(() => import("wevu/compiler"));
|
|
164
185
|
const vueConfigCache = /* @__PURE__ */ new Map();
|
|
186
|
+
const contextConfigCaches = /* @__PURE__ */ new WeakMap();
|
|
165
187
|
const configMtimeInFlight = /* @__PURE__ */ new Map();
|
|
166
188
|
const NODE_MODULES_RE = /[\\/]node_modules[\\/]/;
|
|
167
189
|
const JSON_MACRO_HINT_RE = /\bdefine(?:App|Page|Component|Sitemap|Theme)Json\s*\(/;
|
|
@@ -193,9 +215,18 @@ async function isVueConfigCacheValid(vueFilePath, cache) {
|
|
|
193
215
|
*/
|
|
194
216
|
async function extractConfigFromVue(vueFilePath, options) {
|
|
195
217
|
try {
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
218
|
+
const context = options?.compilerContext;
|
|
219
|
+
const hasExplicitSource = options?.source !== void 0 || options?.readSource !== void 0;
|
|
220
|
+
let snapshotSource;
|
|
221
|
+
if (!hasExplicitSource && context?.configService) snapshotSource = readCompilerSourceSnapshotInput(context.configService, vueFilePath);
|
|
222
|
+
const useDiskCache = !hasExplicitSource && snapshotSource === void 0;
|
|
223
|
+
const cache = context ? contextConfigCaches.get(context) ?? /* @__PURE__ */ new Map() : vueConfigCache;
|
|
224
|
+
if (context) contextConfigCaches.set(context, cache);
|
|
225
|
+
const cached = options?.force || !useDiskCache ? void 0 : cache.get(vueFilePath);
|
|
226
|
+
let autoRoutesInline;
|
|
227
|
+
if (cached?.autoRoutesSignature !== void 0) autoRoutesInline = await resolveAutoRoutesInlineSnapshot(context);
|
|
228
|
+
if (cached && (cached.autoRoutesSignature === void 0 || cached.autoRoutesSignature === JSON.stringify(autoRoutesInline)) && await isVueConfigCacheValid(vueFilePath, cached)) return cached.config;
|
|
229
|
+
const content = options?.source ?? (options?.readSource ? await options.readSource() : snapshotSource ?? await fs.readFile(vueFilePath, "utf-8"));
|
|
199
230
|
if (content === void 0) return;
|
|
200
231
|
const { descriptor, errors } = parse(content, { filename: vueFilePath });
|
|
201
232
|
if (errors.length > 0) return;
|
|
@@ -213,10 +244,10 @@ async function extractConfigFromVue(vueFilePath, options) {
|
|
|
213
244
|
} catch {}
|
|
214
245
|
const setupContent = descriptor.scriptSetup?.content;
|
|
215
246
|
if (typeof setupContent === "string" && JSON_MACRO_HINT_RE.test(setupContent)) {
|
|
216
|
-
const { extractJsonMacroFromScriptSetup } = await
|
|
247
|
+
const { extractJsonMacroFromScriptSetup } = await loadVueCompiler();
|
|
217
248
|
try {
|
|
218
249
|
const preambleContent = descriptor.script?.content;
|
|
219
|
-
|
|
250
|
+
autoRoutesInline = hasAutoRoutesMacroImport(setupContent) || preambleContent !== void 0 && hasAutoRoutesMacroImport(preambleContent) ? autoRoutesInline ?? await resolveAutoRoutesInlineSnapshot(options?.compilerContext) : void 0;
|
|
220
251
|
const macroEvalPreamble = preambleContent && autoRoutesInline ? inlineAutoRoutesImports(preambleContent, autoRoutesInline) : preambleContent;
|
|
221
252
|
const extracted = await extractJsonMacroFromScriptSetup(autoRoutesInline ? inlineAutoRoutesImports(setupContent, autoRoutesInline) : setupContent, vueFilePath, descriptor.scriptSetup?.lang, { preambleContent: macroEvalPreamble });
|
|
222
253
|
if (extracted.dependencies?.length) macroDependencies.push(...extracted.dependencies);
|
|
@@ -225,20 +256,23 @@ async function extractConfigFromVue(vueFilePath, options) {
|
|
|
225
256
|
if (jsonBlocks.length === 0) throw error;
|
|
226
257
|
}
|
|
227
258
|
}
|
|
228
|
-
const normalizedDependencies = [...new Set(macroDependencies.filter((dep) => dep && !NODE_MODULES_RE.test(dep)).map((dep) => path.normalize(dep)))];
|
|
229
|
-
const dependencyMtimeMs = /* @__PURE__ */ new Map();
|
|
230
|
-
await Promise.all(normalizedDependencies.map(async (dep) => {
|
|
231
|
-
const mtime = await getMtimeCached(dep);
|
|
232
|
-
if (mtime !== void 0) dependencyMtimeMs.set(dep, mtime);
|
|
233
|
-
}));
|
|
234
|
-
const fileMtimeMs = await getMtimeCached(vueFilePath);
|
|
235
259
|
const hasConfig = Object.keys(mergedConfig).length > 0;
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
260
|
+
if (useDiskCache) {
|
|
261
|
+
const normalizedDependencies = [...new Set(macroDependencies.filter((dep) => dep && !NODE_MODULES_RE.test(dep)).map((dep) => path.normalize(dep)))];
|
|
262
|
+
const dependencyMtimeMs = /* @__PURE__ */ new Map();
|
|
263
|
+
await Promise.all(normalizedDependencies.map(async (dep) => {
|
|
264
|
+
const mtime = await getMtimeCached(dep);
|
|
265
|
+
if (mtime !== void 0) dependencyMtimeMs.set(dep, mtime);
|
|
266
|
+
}));
|
|
267
|
+
const fileMtimeMs = await getMtimeCached(vueFilePath);
|
|
268
|
+
cache.set(vueFilePath, {
|
|
269
|
+
config: hasConfig ? mergedConfig : void 0,
|
|
270
|
+
autoRoutesSignature: autoRoutesInline && JSON.stringify(autoRoutesInline),
|
|
271
|
+
fileMtimeMs,
|
|
272
|
+
dependencies: normalizedDependencies,
|
|
273
|
+
dependencyMtimeMs
|
|
274
|
+
});
|
|
275
|
+
}
|
|
242
276
|
return hasConfig ? mergedConfig : void 0;
|
|
243
277
|
} catch (error) {
|
|
244
278
|
if (process.env.__WEAPP_VITE_DEBUG_VUE_CONFIG__) console.error("[extractConfigFromVue] failed:", vueFilePath, error);
|
|
@@ -246,4 +280,4 @@ async function extractConfigFromVue(vueFilePath, options) {
|
|
|
246
280
|
}
|
|
247
281
|
}
|
|
248
282
|
//#endregion
|
|
249
|
-
export {
|
|
283
|
+
export { hasAutoRoutesMacroImport as _, replaceCompilerSourceSnapshotView as a, findJsEntry as c, findVueEntry as d, isJsOrTs as f, getAutoRoutesMacroImportCandidates as g, touch as h, getCompilerSourceSnapshotView as i, findJsonEntry as l, normalizeFileExtension as m, getCompilerSourceResolutions as n, changeFileExtension as o, isTemplate as p, getCompilerSourceSnapshot as r, findCssEntry as s, extractConfigFromVue as t, findTemplateEntry as u, inlineAutoRoutesImports as v, resolveAutoRoutesInlineSnapshot as y };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as extractConfigFromVue } from "./file-CcIOmqhC.mjs";
|
|
@@ -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 };
|