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.
- package/README.md +8 -2
- package/THIRD_PARTY_NOTICES.md +60 -0
- 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/{analyze-ZJUvEdaY.mjs → analyze-DN79YOAH.mjs} +1 -65
- package/dist/artifacts-BOyC9Fy-.mjs +106 -0
- package/dist/assets-C5_YYXNk.mjs +637 -0
- package/dist/auto-routes.mjs +2 -2
- package/dist/{budget-BD7VqLCl.d.mts → budget-CTLOHwgI.d.mts} +1 -2
- package/dist/budget-EOeEycc_.mjs +65 -0
- package/dist/builtProject-C29udgXY.mjs +541 -0
- package/dist/{chunkStrategy-DRA5WpB-.mjs → chunkStrategy-DY_LZIIe.mjs} +15 -3
- package/dist/{package-7swhyLmf.mjs → classifier-DBJY__kg.mjs} +4 -7
- package/dist/cli-acceptance.mjs +1 -1
- package/dist/cli.mjs +110 -4506
- package/dist/{config-V0L-IAJf.d.mts → config-Bf6DWhyb.d.mts} +136 -49
- package/dist/config.d.mts +2 -2
- package/dist/{createCompilerContextInstance-DJH_P_nZ.mjs → createCompilerContextInstance-aYwi8wQt.mjs} +15235 -9523
- package/dist/{createContext-BqYzHhY9.mjs → createContext-tApLtII-.mjs} +6 -3
- package/dist/dashboard/analyze.d.mts +1 -1
- package/dist/dashboard/analyze.mjs +3 -1
- package/dist/dashboard/vite.d.mts +1 -1
- package/dist/dashboard.d.mts +2 -2
- package/dist/dashboard.mjs +1749 -1
- package/dist/dashboardTransport-C_Y6jMp-.mjs +16 -0
- package/dist/{dashboardViteBridge-Dy3nAD4m.mjs → dashboardViteBridge-DCGR43aM.mjs} +8 -5
- package/dist/{dev-fR5GiJRO.mjs → dev-C2fgr_Xd.mjs} +5 -1
- package/dist/devProvider-D-hTfsEO.mjs +3027 -0
- package/dist/docs/README.md +8 -2
- package/dist/docs/mcp.md +10 -0
- package/dist/docs/troubleshooting.md +8 -0
- package/dist/docs/vue-sfc.md +25 -2
- package/dist/doctor-worker.mjs +3 -2
- package/dist/doctor.d.mts +2 -2
- package/dist/doctor.mjs +15 -13
- package/dist/engine-C66J0HLz.mjs +54 -0
- package/dist/{file-sC3jD7Fh.mjs → file-CcIOmqhC.mjs} +47 -19
- package/dist/file-DtcteQ4G.mjs +1 -0
- package/dist/forwardConsole-B0Reo8Lf.mjs +511 -0
- package/dist/getInstance-BAIaU2y9.mjs +1 -0
- package/dist/{getInstance-DiGSzBNI.mjs → getInstance-Dt9IQDKr.mjs} +1 -1
- package/dist/history-BIiRCzbq.mjs +784 -0
- package/dist/i18n.d.mts +1 -1
- package/dist/{index-C9HjUX5c.d.mts → index-D5rgBzYZ.d.mts} +1 -2
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/json.d.mts +1 -1
- package/dist/lib-DjccSI1B.mjs +143 -0
- package/dist/{lifecycle-BROTlwSL.mjs → lifecycle-C36WSbQS.mjs} +120 -27
- package/dist/{loadConfig-C3BQhz7F.mjs → loadConfig-BWIsDXR4.mjs} +1 -1
- package/dist/loadConfig-D-BpBgsk.mjs +1 -0
- package/dist/logBuildAppFinish-ChjwATMv.mjs +57 -0
- package/dist/mcp-CYgX9HpO.mjs +86 -0
- package/dist/mcp.d.mts +1 -1
- package/dist/mcpClient-DVLvFLZv.mjs +287 -0
- package/dist/{processCleanup-B6KA30Zc.mjs → metadata-hwF7QRcS.mjs} +1 -19
- 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/processCleanup-BQn2kTcK.mjs +19 -0
- package/dist/{protocol-vg8HGJ4n.mjs → protocol-Cg6Jdlvb.mjs} +42 -39
- 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/{path-doV773b7.mjs → resolvedId-CiDl7SC1.mjs} +3 -46
- 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/schematics-kO26eQRT.mjs +91 -0
- package/dist/{session-PskhD-nZ.mjs → session-D3zsdzIy.mjs} +71 -9
- package/dist/test.mjs +10 -8
- 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 +2 -2
- package/dist/{upload-D4msblBf.mjs → upload-DozK8UdN.mjs} +109 -5
- package/dist/upload-worker.mjs +1 -1
- package/dist/{utils-CJSCgEj6.mjs → utils-Dy51PYAC.mjs} +56 -116
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +51 -12
- package/dist/wxs-BT8btflA.mjs +112 -0
- package/dist/wxs-Z4VQDeJ_.mjs +1 -0
- package/package.json +52 -46
- package/dist/dashboard-DvqF3Key.mjs +0 -1842
- package/dist/devProvider-BGBkw28J.mjs +0 -1050
- package/dist/file-DRb4eWqw.mjs +0 -1
- package/dist/getInstance-SiE6WZRh.mjs +0 -1
- package/dist/loadConfig-VGtBF4qm.mjs +0 -1
- package/dist/mcp-D3Yh24Cj.mjs +0 -529
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { r as logger_default } from "./logger-DGn5iEVN.mjs";
|
|
2
|
+
import { t as createCompilerContext } from "./createContext-tApLtII-.mjs";
|
|
3
|
+
import { i as resolveRuntimeTargets, t as createInlineConfig } from "./runtime-CLUhQsdA.mjs";
|
|
4
|
+
import { o as resolveConfigFile, r as filterDuplicateOptions } from "./options-jqFwfD1G.mjs";
|
|
5
|
+
import { t as setCommandNodeEnv } from "./nodeEnv-BmH8UZPR.mjs";
|
|
6
|
+
import { o as resolveUploadTimeout, t as UploadCommandError } from "./report-hyonPGbZ.mjs";
|
|
7
|
+
import { n as resolveUploadPlatforms } from "./upload-DozK8UdN.mjs";
|
|
8
|
+
import { t as terminateStaleSassEmbeddedProcess } from "./processCleanup-BQn2kTcK.mjs";
|
|
9
|
+
import { i as prepareAutoUploadMetadata, n as executeUploadTarget, r as UploadExecutionError, t as createUploadTarget } from "./builtProject-C29udgXY.mjs";
|
|
10
|
+
import process from "node:process";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
//#region src/cli/commands/upload/action.ts
|
|
13
|
+
async function buildUploadTarget(cwd, platform, options, action, item) {
|
|
14
|
+
const targets = resolveRuntimeTargets({ platform });
|
|
15
|
+
const ctx = await createCompilerContext({
|
|
16
|
+
cwd,
|
|
17
|
+
mode: options.mode ?? "production",
|
|
18
|
+
configFile: resolveConfigFile(options),
|
|
19
|
+
inlineConfig: createInlineConfig(targets),
|
|
20
|
+
cliPlatform: platform,
|
|
21
|
+
projectConfigPath: options.projectConfig,
|
|
22
|
+
emitDefaultAutoImportOutputs: false,
|
|
23
|
+
preloadAppEntry: false
|
|
24
|
+
});
|
|
25
|
+
try {
|
|
26
|
+
const target = await createUploadTarget(ctx.configService, options, action);
|
|
27
|
+
if (item) {
|
|
28
|
+
item.platform = target.platform;
|
|
29
|
+
item.requestedVersion = target.context.version;
|
|
30
|
+
item.stage = "build";
|
|
31
|
+
}
|
|
32
|
+
logger_default.info(`[${action}:${target.platform}] 构建${target.context.version ? ` ${target.context.version}` : ""}`);
|
|
33
|
+
await ctx.buildService.build({});
|
|
34
|
+
return target;
|
|
35
|
+
} finally {
|
|
36
|
+
ctx.watcherService.closeAll();
|
|
37
|
+
terminateStaleSassEmbeddedProcess();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function runUploadCommand(root, options, action = "upload") {
|
|
41
|
+
filterDuplicateOptions(options);
|
|
42
|
+
const platforms = resolveUploadPlatforms(options.platform ?? options.p);
|
|
43
|
+
setCommandNodeEnv("production");
|
|
44
|
+
const cwd = path.resolve(root ?? process.cwd());
|
|
45
|
+
if (action === "preview") {
|
|
46
|
+
options = await prepareAutoUploadMetadata(cwd, options, action);
|
|
47
|
+
for (const platform of platforms) {
|
|
48
|
+
const target = await buildUploadTarget(cwd, platform, options, action);
|
|
49
|
+
await executeUploadTarget(target, options, action);
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const report = {
|
|
54
|
+
schemaVersion: 1,
|
|
55
|
+
action: "upload",
|
|
56
|
+
status: "success",
|
|
57
|
+
results: platforms.map((platform) => ({
|
|
58
|
+
platform: platform ?? null,
|
|
59
|
+
stage: "prepare",
|
|
60
|
+
status: "not-run"
|
|
61
|
+
}))
|
|
62
|
+
};
|
|
63
|
+
let active = report.results[0];
|
|
64
|
+
try {
|
|
65
|
+
const timeoutMs = resolveUploadTimeout(options.timeout);
|
|
66
|
+
options = await prepareAutoUploadMetadata(cwd, options, action);
|
|
67
|
+
for (const item of report.results) item.requestedVersion = options.uv?.trim();
|
|
68
|
+
for (const [index, platform] of platforms.entries()) {
|
|
69
|
+
active = report.results[index];
|
|
70
|
+
const target = await buildUploadTarget(cwd, platform, options, action, active);
|
|
71
|
+
active.stage = "validate";
|
|
72
|
+
const result = await executeUploadTarget(target, options, action, {
|
|
73
|
+
timeoutMs,
|
|
74
|
+
onUpload: () => {
|
|
75
|
+
active.stage = "upload";
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
active.status = options.dryRun ? "dry-run" : "success";
|
|
79
|
+
if (!options.dryRun) active.result = result;
|
|
80
|
+
}
|
|
81
|
+
return report;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
report.status = "failed";
|
|
84
|
+
report.error = error instanceof Error ? error.message : String(error);
|
|
85
|
+
active.status = "failed";
|
|
86
|
+
active.error = report.error;
|
|
87
|
+
if (error instanceof UploadExecutionError) {
|
|
88
|
+
active.remoteOutcome = error.remoteOutcome;
|
|
89
|
+
if (error.remoteOutcome === "unknown" && error.reason !== "failed") active.status = "unknown";
|
|
90
|
+
}
|
|
91
|
+
throw new UploadCommandError(report);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
export { runUploadCommand };
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { c as getBackendForCapability, n as formatBytes, u as CompilerSession } from "./createCompilerContextInstance-aYwi8wQt.mjs";
|
|
2
|
+
import { r as logger_default, t as colors } from "./logger-DGn5iEVN.mjs";
|
|
3
|
+
import { i as resolveRuntimeTargets, n as logRuntimeTarget, r as resolveConfiguredRuntimeTargets, t as createInlineConfig } from "./runtime-CLUhQsdA.mjs";
|
|
4
|
+
import { i as resolveIdeProjectPath, n as openIde } from "./openIde-CroqOgk5.mjs";
|
|
5
|
+
import { a as parseDashboardUiHost, i as isUiEnabled, o as resolveConfigFile, r as filterDuplicateOptions } from "./options-jqFwfD1G.mjs";
|
|
6
|
+
import { n as formatDuration, r as scheduleCompletedProductionBuildExit, t as logBuildAppFinish } from "./logBuildAppFinish-ChjwATMv.mjs";
|
|
7
|
+
import { n as createDashboardArtifactSnapshot } from "./artifacts-BOyC9Fy-.mjs";
|
|
8
|
+
import { i as startAnalyzeDashboard, n as writeAnalyzeHistorySnapshot, r as analyzeSubpackages, t as readLatestAnalyzeHistorySnapshot } from "./history-BIiRCzbq.mjs";
|
|
9
|
+
import { t as setCommandNodeEnv } from "./nodeEnv-BmH8UZPR.mjs";
|
|
10
|
+
import { a as resolveBuildUploadOptions } from "./report-hyonPGbZ.mjs";
|
|
11
|
+
import { a as prepareAutoUploadMetadataWithRollback, n as executeUploadTarget, o as validateAutoUploadMetadata, t as createUploadTarget } from "./builtProject-C29udgXY.mjs";
|
|
12
|
+
import process from "node:process";
|
|
13
|
+
import { Buffer } from "node:buffer";
|
|
14
|
+
const WINDOWS_SEPARATOR_RE = /\\/g;
|
|
15
|
+
function normalizeFileName(fileName) {
|
|
16
|
+
return fileName.replace(WINDOWS_SEPARATOR_RE, "/");
|
|
17
|
+
}
|
|
18
|
+
function getOutputItemBytes(item) {
|
|
19
|
+
if (item.type === "chunk") return typeof item.code === "string" ? Buffer.byteLength(item.code, "utf8") : 0;
|
|
20
|
+
if (typeof item.source === "string") return Buffer.byteLength(item.source, "utf8");
|
|
21
|
+
if (item.source instanceof Uint8Array) return item.source.byteLength;
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
function resolveSubPackageRoot(fileName, roots) {
|
|
25
|
+
const normalized = normalizeFileName(fileName);
|
|
26
|
+
return roots.find((root) => normalized === root || normalized.startsWith(`${root}/`));
|
|
27
|
+
}
|
|
28
|
+
function collectPackageSizeReports(output, subPackageMap) {
|
|
29
|
+
const outputs = Array.isArray(output) ? output : [output];
|
|
30
|
+
const roots = [...subPackageMap?.keys() ?? []].filter(Boolean).sort((a, b) => b.length - a.length || a.localeCompare(b));
|
|
31
|
+
const packageBytes = /* @__PURE__ */ new Map([["__main__", 0]]);
|
|
32
|
+
for (const root of roots) packageBytes.set(root, 0);
|
|
33
|
+
for (const current of outputs) for (const item of current.output ?? []) {
|
|
34
|
+
const root = resolveSubPackageRoot(item.fileName, roots) ?? "__main__";
|
|
35
|
+
packageBytes.set(root, (packageBytes.get(root) ?? 0) + getOutputItemBytes(item));
|
|
36
|
+
}
|
|
37
|
+
const reports = [{
|
|
38
|
+
root: "__main__",
|
|
39
|
+
label: "主包",
|
|
40
|
+
bytes: packageBytes.get("__main__") ?? 0
|
|
41
|
+
}];
|
|
42
|
+
for (const root of roots) {
|
|
43
|
+
const meta = subPackageMap?.get(root);
|
|
44
|
+
const isIndependent = Boolean(meta?.subPackage.independent);
|
|
45
|
+
reports.push({
|
|
46
|
+
root,
|
|
47
|
+
label: `${isIndependent ? "独立分包" : "分包"} ${root}`,
|
|
48
|
+
bytes: packageBytes.get(root) ?? 0
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return reports;
|
|
52
|
+
}
|
|
53
|
+
function logBuildPackageSizeReport(options) {
|
|
54
|
+
const warningBytes = Number(options.warningBytes ?? 2097152);
|
|
55
|
+
const reports = collectPackageSizeReports(options.output, options.subPackageMap);
|
|
56
|
+
logger_default.success("主包/分包体积报告:");
|
|
57
|
+
for (const report of reports) logger_default.info(`${report.label}:${formatBytes(report.bytes)}`);
|
|
58
|
+
if (!(Number.isFinite(warningBytes) && warningBytes > 0)) return;
|
|
59
|
+
for (const report of reports) {
|
|
60
|
+
if (report.bytes <= warningBytes) continue;
|
|
61
|
+
logger_default.warn(`[包体积] ${colors.yellow(report.label)} 体积 ${colors.yellow(formatBytes(report.bytes))},已超过阈值 ${colors.yellow(formatBytes(warningBytes))}。`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/cli/commands/build/action.ts
|
|
66
|
+
function emitDashboardEvents(handle, events) {
|
|
67
|
+
handle?.emitRuntimeEvents(events);
|
|
68
|
+
}
|
|
69
|
+
function normalizeBuildSourcemap(value) {
|
|
70
|
+
if (value === "true") return true;
|
|
71
|
+
if (value === "false") return false;
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
function normalizeBuildMinify(value) {
|
|
75
|
+
if (value === "true") return true;
|
|
76
|
+
if (value === "false") return false;
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
function hasCliOption(options, key) {
|
|
80
|
+
return Object.prototype.hasOwnProperty.call(options, key);
|
|
81
|
+
}
|
|
82
|
+
function createBuildInlineConfig(options) {
|
|
83
|
+
const build = {};
|
|
84
|
+
if (typeof options.outDir === "string") build.outDir = options.outDir;
|
|
85
|
+
if (hasCliOption(options, "sourcemap")) build.sourcemap = normalizeBuildSourcemap(options.sourcemap);
|
|
86
|
+
if (hasCliOption(options, "minify")) build.minify = normalizeBuildMinify(options.minify);
|
|
87
|
+
if (typeof options.emptyOutDir === "boolean") build.emptyOutDir = options.emptyOutDir;
|
|
88
|
+
return Object.keys(build).length ? { build } : void 0;
|
|
89
|
+
}
|
|
90
|
+
/** 执行已完成参数校验的生产构建,复用注册器持有的原始命令参数。 */
|
|
91
|
+
async function runBuildCommand(cli, root, options) {
|
|
92
|
+
let analyzeHandle;
|
|
93
|
+
let session;
|
|
94
|
+
let ctx;
|
|
95
|
+
let targets;
|
|
96
|
+
let uploadMetadataRollback;
|
|
97
|
+
let buildCompleted = false;
|
|
98
|
+
let buildFailed = false;
|
|
99
|
+
try {
|
|
100
|
+
options = { ...options };
|
|
101
|
+
filterDuplicateOptions(options);
|
|
102
|
+
options.uiHost = parseDashboardUiHost(options.uiHost);
|
|
103
|
+
let uploadOptions = resolveBuildUploadOptions(cli, options);
|
|
104
|
+
setCommandNodeEnv("production");
|
|
105
|
+
const cwd = root ?? process.cwd();
|
|
106
|
+
const configFile = resolveConfigFile(options);
|
|
107
|
+
targets = resolveRuntimeTargets(options);
|
|
108
|
+
if (uploadOptions) validateAutoUploadMetadata(uploadOptions, "upload");
|
|
109
|
+
if (uploadOptions && !getBackendForCapability(targets, "miniprogram", "build")) throw new Error("--upload 仅支持包含小程序目标的构建,不能用于纯 Web 构建。");
|
|
110
|
+
const inlineConfig = createInlineConfig(targets, {
|
|
111
|
+
scope: options.scope,
|
|
112
|
+
inlineConfig: createBuildInlineConfig(options)
|
|
113
|
+
});
|
|
114
|
+
if (uploadOptions) {
|
|
115
|
+
const prepared = await prepareAutoUploadMetadataWithRollback(cwd, uploadOptions, "upload");
|
|
116
|
+
uploadOptions = prepared.options;
|
|
117
|
+
uploadMetadataRollback = prepared.rollback;
|
|
118
|
+
}
|
|
119
|
+
session = new CompilerSession();
|
|
120
|
+
ctx = await session.initialize({
|
|
121
|
+
cwd,
|
|
122
|
+
mode: options.mode ?? "production",
|
|
123
|
+
configFile,
|
|
124
|
+
inlineConfig,
|
|
125
|
+
cliPlatform: targets.rawPlatform,
|
|
126
|
+
projectConfigPath: options.projectConfig,
|
|
127
|
+
emitDefaultAutoImportOutputs: false,
|
|
128
|
+
preloadAppEntry: false
|
|
129
|
+
});
|
|
130
|
+
targets = resolveConfiguredRuntimeTargets(targets, ctx.configService.options?.sourceConfig?.weapp?.platform);
|
|
131
|
+
if (uploadOptions && !getBackendForCapability(targets, "miniprogram", "build")) {
|
|
132
|
+
await uploadMetadataRollback?.();
|
|
133
|
+
uploadMetadataRollback = void 0;
|
|
134
|
+
throw new Error("--upload 仅支持包含小程序目标的构建,不能用于纯 Web 构建。");
|
|
135
|
+
}
|
|
136
|
+
uploadMetadataRollback = void 0;
|
|
137
|
+
for (const backend of targets.select("build")) session.onClose(() => backend.driver.close(ctx));
|
|
138
|
+
const { configService } = ctx;
|
|
139
|
+
const uploadTarget = uploadOptions ? await createUploadTarget(configService, uploadOptions, "upload") : void 0;
|
|
140
|
+
const miniBackend = getBackendForCapability(targets, "miniprogram", "build");
|
|
141
|
+
const webBackend = getBackendForCapability(targets, "web", "build");
|
|
142
|
+
logRuntimeTarget(targets, { resolvedConfigPlatform: configService.platform });
|
|
143
|
+
const enableAnalyze = Boolean(isUiEnabled(options) && miniBackend);
|
|
144
|
+
for (const backend of targets.select("build")) {
|
|
145
|
+
if (backend.descriptor.id === "miniprogram") {
|
|
146
|
+
const miniBuildStartedAt = Date.now();
|
|
147
|
+
const output = await session.run(() => backend.driver.build(ctx, options));
|
|
148
|
+
const miniBuildDurationMs = Date.now() - miniBuildStartedAt;
|
|
149
|
+
logger_default.success(`小程序构建完成,耗时:${colors.green(formatDuration(miniBuildDurationMs))}`);
|
|
150
|
+
if (!Array.isArray(output) && "output" in output) logBuildPackageSizeReport({
|
|
151
|
+
output,
|
|
152
|
+
subPackageMap: ctx.scanService?.subPackageMap,
|
|
153
|
+
warningBytes: configService.weappViteConfig.packageSizeWarningBytes
|
|
154
|
+
});
|
|
155
|
+
if (enableAnalyze) {
|
|
156
|
+
const analyzeStartedAt = Date.now();
|
|
157
|
+
const previousAnalyzeResult = await readLatestAnalyzeHistorySnapshot(configService);
|
|
158
|
+
const artifactSnapshot = createDashboardArtifactSnapshot();
|
|
159
|
+
const analyzeResult = await analyzeSubpackages(ctx, { onArtifact: artifactSnapshot.capture });
|
|
160
|
+
await writeAnalyzeHistorySnapshot(analyzeResult, configService);
|
|
161
|
+
const analyzeDurationMs = Date.now() - analyzeStartedAt;
|
|
162
|
+
analyzeHandle = await startAnalyzeDashboard(analyzeResult, {
|
|
163
|
+
watch: true,
|
|
164
|
+
uiHost: options.uiHost,
|
|
165
|
+
artifacts: artifactSnapshot.files,
|
|
166
|
+
cwd: configService.cwd,
|
|
167
|
+
packageManagerAgent: configService.packageManager.agent,
|
|
168
|
+
pluginRoot: configService.absolutePluginRoot,
|
|
169
|
+
srcRoot: configService.absoluteSrcRoot,
|
|
170
|
+
previousResult: previousAnalyzeResult,
|
|
171
|
+
initialEvents: [{
|
|
172
|
+
kind: "build",
|
|
173
|
+
level: "success",
|
|
174
|
+
title: "mini build completed",
|
|
175
|
+
detail: `生产构建已完成,当前 analyze 结果包含 ${analyzeResult.packages.length} 个包。`,
|
|
176
|
+
durationMs: miniBuildDurationMs,
|
|
177
|
+
tags: ["build", "mini"]
|
|
178
|
+
}, {
|
|
179
|
+
kind: "build",
|
|
180
|
+
level: "success",
|
|
181
|
+
title: "analyze completed",
|
|
182
|
+
detail: `分析已完成,当前包含 ${analyzeResult.packages.length} 个包与 ${analyzeResult.modules.length} 个模块。`,
|
|
183
|
+
durationMs: analyzeDurationMs,
|
|
184
|
+
tags: ["build", "analyze"]
|
|
185
|
+
}]
|
|
186
|
+
}) ?? void 0;
|
|
187
|
+
}
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const webConfig = configService.weappWebConfig;
|
|
191
|
+
if (backend.descriptor.id !== "web" || !webConfig?.enabled) continue;
|
|
192
|
+
const webBuildStartedAt = Date.now();
|
|
193
|
+
try {
|
|
194
|
+
await session.run(() => backend.driver.build(ctx, options));
|
|
195
|
+
const webBuildDurationMs = Date.now() - webBuildStartedAt;
|
|
196
|
+
logger_default.success(`Web 构建完成,输出目录:${colors.green(configService.relativeCwd(webConfig.outDir))},耗时:${colors.green(formatDuration(webBuildDurationMs))}`);
|
|
197
|
+
emitDashboardEvents(analyzeHandle, [{
|
|
198
|
+
kind: "build",
|
|
199
|
+
level: "success",
|
|
200
|
+
title: "web build completed",
|
|
201
|
+
detail: `Web 构建已完成,输出目录 ${configService.relativeCwd(webConfig.outDir)}。`,
|
|
202
|
+
durationMs: webBuildDurationMs,
|
|
203
|
+
tags: ["build", "web"]
|
|
204
|
+
}]);
|
|
205
|
+
} catch (error) {
|
|
206
|
+
emitDashboardEvents(analyzeHandle, [{
|
|
207
|
+
kind: "diagnostic",
|
|
208
|
+
level: "error",
|
|
209
|
+
title: "web build failed",
|
|
210
|
+
detail: error instanceof Error ? error.message : String(error),
|
|
211
|
+
durationMs: Date.now() - webBuildStartedAt,
|
|
212
|
+
tags: ["build", "web"]
|
|
213
|
+
}]);
|
|
214
|
+
logger_default.error(error);
|
|
215
|
+
throw error;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (uploadTarget && uploadOptions) await executeUploadTarget(uploadTarget, uploadOptions, "upload");
|
|
219
|
+
if (miniBackend) logBuildAppFinish(configService, void 0, { skipWeb: !webBackend });
|
|
220
|
+
if (options.open && getBackendForCapability(targets, "miniprogram", "ide")) {
|
|
221
|
+
emitDashboardEvents(analyzeHandle, [{
|
|
222
|
+
kind: "command",
|
|
223
|
+
level: "info",
|
|
224
|
+
title: "opening ide",
|
|
225
|
+
detail: "构建完成后准备打开 IDE 项目。",
|
|
226
|
+
tags: ["ide", "open"]
|
|
227
|
+
}]);
|
|
228
|
+
const generatedProjectConfig = configService.multiPlatform.projectConfigs !== void 0;
|
|
229
|
+
await openIde(configService.platform, resolveIdeProjectPath(generatedProjectConfig ? configService.outDir : configService.mpDistRoot, generatedProjectConfig), {
|
|
230
|
+
openRecovery: options.openRecovery,
|
|
231
|
+
trustProject: options.trustProject,
|
|
232
|
+
openStrategy: options.ideOpenStrategy
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
if (analyzeHandle) await analyzeHandle.waitForExit();
|
|
236
|
+
buildCompleted = true;
|
|
237
|
+
} catch (error) {
|
|
238
|
+
buildFailed = true;
|
|
239
|
+
throw error;
|
|
240
|
+
} finally {
|
|
241
|
+
if (buildFailed) await session?.close().catch((error) => logger_default.error(error));
|
|
242
|
+
else await session?.close();
|
|
243
|
+
if (buildCompleted) scheduleCompletedProductionBuildExit(options, analyzeHandle);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
//#endregion
|
|
247
|
+
export { runBuildCommand };
|
|
@@ -1,67 +1,3 @@
|
|
|
1
|
-
//#region src/analyze/subpackages/artifacts/category.ts
|
|
2
|
-
function isRuntimeCategory(category) {
|
|
3
|
-
return category === "runtime" || category === "reactivity" || category === "host" || category === "helper";
|
|
4
|
-
}
|
|
5
|
-
//#endregion
|
|
6
|
-
//#region src/analyze/subpackages/budget.ts
|
|
7
|
-
const defaultBudgets = {
|
|
8
|
-
totalBytes: 20971520,
|
|
9
|
-
mainBytes: 2097152,
|
|
10
|
-
subPackageBytes: 2097152,
|
|
11
|
-
independentBytes: 2097152,
|
|
12
|
-
warningRatio: .85,
|
|
13
|
-
source: "default"
|
|
14
|
-
};
|
|
15
|
-
function createAnalyzeBudgetCheck(result) {
|
|
16
|
-
const budgets = result.metadata?.budgets ?? defaultBudgets;
|
|
17
|
-
const createItem = (options, unknown = false) => {
|
|
18
|
-
const ratio = options.limitBytes > 0 ? options.currentBytes / options.limitBytes : options.currentBytes > 0 ? 1 : 0;
|
|
19
|
-
return {
|
|
20
|
-
...options,
|
|
21
|
-
ratio,
|
|
22
|
-
status: unknown ? "unknown" : ratio >= 1 ? "exceeded" : ratio >= budgets.warningRatio ? "warning" : "ok"
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
const files = result.packages.flatMap((pkg) => pkg.files);
|
|
26
|
-
const unique = new Map(files.map((file) => [file.file, file]));
|
|
27
|
-
const sizeUnknown = (items) => items.some((file) => typeof file.size !== "number" || !Number.isFinite(file.size) || file.size < 0);
|
|
28
|
-
const items = [createItem({
|
|
29
|
-
id: "__total__",
|
|
30
|
-
label: "总包",
|
|
31
|
-
scope: "total",
|
|
32
|
-
currentBytes: [...unique.values()].reduce((sum, file) => sum + (file.size ?? 0), 0),
|
|
33
|
-
limitBytes: budgets.totalBytes,
|
|
34
|
-
measurement: "file-bytes",
|
|
35
|
-
files: [...unique.keys()].sort()
|
|
36
|
-
}, sizeUnknown(files))];
|
|
37
|
-
for (const pkg of result.packages) {
|
|
38
|
-
const limitBytes = budgets.packageBytes?.[pkg.id] ?? (pkg.type === "main" ? budgets.mainBytes : pkg.type === "subPackage" ? budgets.subPackageBytes : pkg.type === "independent" ? budgets.independentBytes : void 0);
|
|
39
|
-
if (limitBytes === void 0) continue;
|
|
40
|
-
items.push(createItem({
|
|
41
|
-
id: pkg.id,
|
|
42
|
-
label: pkg.label,
|
|
43
|
-
scope: pkg.type,
|
|
44
|
-
currentBytes: pkg.files.reduce((sum, file) => sum + (file.size ?? 0), 0),
|
|
45
|
-
limitBytes,
|
|
46
|
-
measurement: "file-bytes",
|
|
47
|
-
files: pkg.files.map((file) => file.file).sort()
|
|
48
|
-
}, sizeUnknown(pkg.files)));
|
|
49
|
-
}
|
|
50
|
-
if (budgets.runtimeBytes !== void 0) {
|
|
51
|
-
const artifacts = result.artifacts;
|
|
52
|
-
items.push(createItem({
|
|
53
|
-
id: "__runtime__",
|
|
54
|
-
label: "Runtime(含混合 chunk 的文件上界)",
|
|
55
|
-
scope: "runtime",
|
|
56
|
-
currentBytes: artifacts?.runtime.upperBoundBytes ?? 0,
|
|
57
|
-
limitBytes: budgets.runtimeBytes,
|
|
58
|
-
measurement: artifacts ? "upper-bound" : "unavailable",
|
|
59
|
-
files: artifacts?.files.filter((file) => artifacts.runtime.unknownFiles.includes(file.file) || file.modules.some((module) => isRuntimeCategory(module.category))).map((file) => file.file) ?? files.filter((file) => file.type === "chunk" || /\.[cm]?js$/i.test(file.file)).map((file) => file.file)
|
|
60
|
-
}, !artifacts || artifacts.runtime.unknownFiles.length > 0));
|
|
61
|
-
}
|
|
62
|
-
return items.sort((a, b) => b.ratio - a.ratio || a.label.localeCompare(b.label));
|
|
63
|
-
}
|
|
64
|
-
//#endregion
|
|
65
1
|
//#region src/dashboard/analyze/comparison.ts
|
|
66
2
|
function createModuleComparisonKey(source, sourceType) {
|
|
67
3
|
const origin = sourceType === "node_modules" || sourceType === "workspace" ? "dependency" : sourceType;
|
|
@@ -245,4 +181,4 @@ function createDuplicateModuleInsights(result) {
|
|
|
245
181
|
}).sort((a, b) => b.estimatedSavingBytes - a.estimatedSavingBytes || b.packageCount - a.packageCount || b.bytes - a.bytes || a.source.localeCompare(b.source) || a.id.localeCompare(b.id));
|
|
246
182
|
}
|
|
247
183
|
//#endregion
|
|
248
|
-
export {
|
|
184
|
+
export { createModuleByteMap as n, createAnalyzeComparison as r, createDuplicateModuleInsights as t };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import path from "pathe";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import { Buffer } from "node:buffer";
|
|
6
|
+
//#region src/dashboard/assets.ts
|
|
7
|
+
const ANALYZE_DASHBOARD_PACKAGE_NAME = "@weapp-vite/dashboard";
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
function parseDashboardManifest(source) {
|
|
10
|
+
const parsed = JSON.parse(source);
|
|
11
|
+
const metadata = parsed && typeof parsed === "object" && "weappViteDashboard" in parsed ? parsed.weappViteDashboard : void 0;
|
|
12
|
+
if (!metadata || typeof metadata !== "object") return;
|
|
13
|
+
return { weappViteDashboard: {
|
|
14
|
+
devConfigFile: "devConfigFile" in metadata && typeof metadata.devConfigFile === "string" ? metadata.devConfigFile : void 0,
|
|
15
|
+
devRoot: "devRoot" in metadata && typeof metadata.devRoot === "string" ? metadata.devRoot : void 0,
|
|
16
|
+
distDir: "distDir" in metadata && typeof metadata.distDir === "string" ? metadata.distDir : void 0
|
|
17
|
+
} };
|
|
18
|
+
}
|
|
19
|
+
function resolveDashboardPackage(cwd) {
|
|
20
|
+
const resolvePaths = cwd && cwd !== process.cwd() ? [cwd, process.cwd()] : cwd ? [cwd] : void 0;
|
|
21
|
+
try {
|
|
22
|
+
const packageJsonPath = require.resolve(`${ANALYZE_DASHBOARD_PACKAGE_NAME}/package.json`, { paths: resolvePaths });
|
|
23
|
+
let manifest;
|
|
24
|
+
try {
|
|
25
|
+
manifest = parseDashboardManifest(fs.readFileSync(packageJsonPath, "utf8"));
|
|
26
|
+
} catch {
|
|
27
|
+
manifest = void 0;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
root: path.dirname(packageJsonPath),
|
|
31
|
+
manifest,
|
|
32
|
+
packageJsonPath
|
|
33
|
+
};
|
|
34
|
+
} catch {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function resolveDashboardDistRoot(packageRoot, manifest) {
|
|
39
|
+
const root = path.resolve(packageRoot, manifest?.weappViteDashboard?.distDir ?? "dist");
|
|
40
|
+
return fs.existsSync(path.join(root, "index.html")) ? { root } : void 0;
|
|
41
|
+
}
|
|
42
|
+
function resolveDashboardDevRoot(packageRoot, manifest) {
|
|
43
|
+
const devRoot = manifest?.weappViteDashboard?.devRoot;
|
|
44
|
+
const devConfigFile = manifest?.weappViteDashboard?.devConfigFile;
|
|
45
|
+
if (!devRoot || !devConfigFile) return;
|
|
46
|
+
const root = path.resolve(packageRoot, devRoot);
|
|
47
|
+
const configFile = path.resolve(root, devConfigFile);
|
|
48
|
+
return fs.existsSync(root) && fs.existsSync(configFile) ? {
|
|
49
|
+
root,
|
|
50
|
+
configFile
|
|
51
|
+
} : void 0;
|
|
52
|
+
}
|
|
53
|
+
/** 同一次解析绑定 Dashboard 资源目录及其传输依赖的安装所有者。 */
|
|
54
|
+
function resolveDashboardInstallation(options) {
|
|
55
|
+
const resolved = resolveDashboardPackage(options.cwd);
|
|
56
|
+
if (!resolved) return;
|
|
57
|
+
const assets = options.watch ? resolveDashboardDevRoot(resolved.root, resolved.manifest) ?? resolveDashboardDistRoot(resolved.root, resolved.manifest) : resolveDashboardDistRoot(resolved.root, resolved.manifest) ?? resolveDashboardDevRoot(resolved.root, resolved.manifest);
|
|
58
|
+
return assets ? {
|
|
59
|
+
...assets,
|
|
60
|
+
packageJsonPath: resolved.packageJsonPath
|
|
61
|
+
} : void 0;
|
|
62
|
+
}
|
|
63
|
+
/** 定位可选仪表盘包的原生构建 SPA;未安装或尚未构建时返回 undefined。 */
|
|
64
|
+
function resolveDashboardClientAssets(cwd) {
|
|
65
|
+
const resolved = resolveDashboardPackage(cwd);
|
|
66
|
+
return resolved ? resolveDashboardDistRoot(resolved.root, resolved.manifest)?.root : void 0;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/dashboard/artifacts.ts
|
|
70
|
+
const MAX_DASHBOARD_FILE_CONTENT_BYTES = 2097152;
|
|
71
|
+
/** 保留同一次分析的产物内容,不读取或改写开发构建目录。 */
|
|
72
|
+
function createDashboardArtifactSnapshot() {
|
|
73
|
+
const files = /* @__PURE__ */ new Map();
|
|
74
|
+
let retainedBytes = 0;
|
|
75
|
+
return {
|
|
76
|
+
files,
|
|
77
|
+
capture(fileName, source) {
|
|
78
|
+
const key = fileName.replaceAll("\\", "/");
|
|
79
|
+
const previous = files.get(key);
|
|
80
|
+
if (previous?.content !== void 0) retainedBytes -= previous.size;
|
|
81
|
+
const size = typeof source === "string" ? Buffer.byteLength(source, "utf8") : source.byteLength;
|
|
82
|
+
if (size > 2097152) {
|
|
83
|
+
files.set(key, {
|
|
84
|
+
size,
|
|
85
|
+
error: `文件超过 ${MAX_DASHBOARD_FILE_CONTENT_BYTES} 字节,已拒绝读取。`
|
|
86
|
+
});
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (retainedBytes + size > 33554432) {
|
|
90
|
+
files.set(key, {
|
|
91
|
+
size,
|
|
92
|
+
error: "分析产物内容超过快照容量上限,已拒绝读取。"
|
|
93
|
+
});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const content = typeof source === "string" ? source : Buffer.from(source.buffer, source.byteOffset, source.byteLength).toString("utf8");
|
|
97
|
+
files.set(key, {
|
|
98
|
+
content,
|
|
99
|
+
size
|
|
100
|
+
});
|
|
101
|
+
retainedBytes += size;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
export { resolveDashboardInstallation as a, resolveDashboardClientAssets as i, createDashboardArtifactSnapshot as n, ANALYZE_DASHBOARD_PACKAGE_NAME as r, MAX_DASHBOARD_FILE_CONTENT_BYTES as t };
|