weapp-vite 5.7.0 → 5.7.1

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/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createCompilerContext
3
- } from "./chunk-GU7U5762.mjs";
3
+ } from "./chunk-AXUA33LJ.mjs";
4
4
  import {
5
5
  DEFAULT_MP_PLATFORM,
6
6
  SHARED_CHUNK_VIRTUAL_PREFIX,
@@ -11,7 +11,7 @@ import {
11
11
  normalizeMiniPlatform,
12
12
  resolveMiniPlatform,
13
13
  resolveWeappConfigFile
14
- } from "./chunk-AKJEW44F.mjs";
14
+ } from "./chunk-O4FBXXL3.mjs";
15
15
  import {
16
16
  init_esm_shims
17
17
  } from "./chunk-SSQGJIB5.mjs";
@@ -607,8 +607,8 @@ var cac = (name = "") => new CAC(name);
607
607
 
608
608
  // src/cli/commands/analyze.ts
609
609
  init_esm_shims();
610
- import process2 from "process";
611
- import fs from "fs-extra";
610
+ import process3 from "process";
611
+ import fs2 from "fs-extra";
612
612
  import path2 from "pathe";
613
613
 
614
614
  // src/analyze/subpackages.ts
@@ -1007,6 +1007,125 @@ async function analyzeSubpackages(ctx) {
1007
1007
  };
1008
1008
  }
1009
1009
 
1010
+ // src/cli/analyze/dashboard.ts
1011
+ init_esm_shims();
1012
+ import { dirname, resolve } from "path";
1013
+ import process2 from "process";
1014
+ import { fileURLToPath } from "url";
1015
+ import fs from "fs-extra";
1016
+ import { createServer } from "vite";
1017
+ var __filename2 = fileURLToPath(import.meta.url);
1018
+ var __dirname2 = dirname(__filename2);
1019
+ var PACKAGE_ROOT = resolve(__dirname2, "../../..");
1020
+ var BUILD_DASHBOARD_ROOT = resolve(PACKAGE_ROOT, "modules/analyze-dashboard");
1021
+ var ANALYZE_GLOBAL_KEY = "__WEAPP_VITE_ANALYZE_RESULT__";
1022
+ function resolveDashboardRoot() {
1023
+ if (fs.existsSync(BUILD_DASHBOARD_ROOT)) {
1024
+ return {
1025
+ root: BUILD_DASHBOARD_ROOT
1026
+ };
1027
+ }
1028
+ throw new Error(
1029
+ "[weapp-vite analyze] \u672A\u627E\u5230\u4EEA\u8868\u76D8\u4EA7\u7269\uFF0C\u8BF7\u5148\u6267\u884C `pnpm --filter weapp-vite run build:dashboard` \u751F\u6210\u3002"
1030
+ );
1031
+ }
1032
+ function createAnalyzeHtmlPlugin(state, onServerInstance) {
1033
+ return {
1034
+ name: "weapp-vite-analyze-html",
1035
+ transformIndexHtml(html) {
1036
+ return {
1037
+ html,
1038
+ tags: [
1039
+ {
1040
+ tag: "script",
1041
+ children: `window.${ANALYZE_GLOBAL_KEY} = ${JSON.stringify(state.current)}`,
1042
+ injectTo: "head-prepend"
1043
+ }
1044
+ ]
1045
+ };
1046
+ },
1047
+ configureServer(server) {
1048
+ onServerInstance(server);
1049
+ }
1050
+ };
1051
+ }
1052
+ async function waitForServerExit(server) {
1053
+ let resolved = false;
1054
+ const cleanup = async () => {
1055
+ if (resolved) {
1056
+ return;
1057
+ }
1058
+ resolved = true;
1059
+ try {
1060
+ await server.close();
1061
+ } catch (error) {
1062
+ logger_default.error(error);
1063
+ }
1064
+ };
1065
+ const signals = ["SIGINT", "SIGTERM"];
1066
+ await new Promise((resolvePromise) => {
1067
+ const resolveOnce = async () => {
1068
+ await cleanup();
1069
+ signals.forEach((signal) => {
1070
+ process2.removeListener(signal, resolveOnce);
1071
+ });
1072
+ resolvePromise();
1073
+ };
1074
+ signals.forEach((signal) => {
1075
+ process2.once(signal, resolveOnce);
1076
+ });
1077
+ server.httpServer?.once("close", resolveOnce);
1078
+ });
1079
+ }
1080
+ async function startAnalyzeDashboard(result, options) {
1081
+ const { root } = resolveDashboardRoot();
1082
+ const state = { current: result };
1083
+ let serverRef;
1084
+ const plugins = [
1085
+ createAnalyzeHtmlPlugin(state, (server2) => {
1086
+ serverRef = server2;
1087
+ })
1088
+ ];
1089
+ const server = await createServer({
1090
+ root,
1091
+ clearScreen: false,
1092
+ appType: "spa",
1093
+ publicDir: false,
1094
+ plugins,
1095
+ server: {
1096
+ host: "127.0.0.1",
1097
+ port: 0
1098
+ },
1099
+ logLevel: "error"
1100
+ });
1101
+ await server.listen();
1102
+ serverRef ??= server;
1103
+ server.printUrls();
1104
+ logger_default.info("\u5206\u6790\u4EEA\u8868\u76D8\u5DF2\u542F\u52A8\uFF08\u4F7F\u7528\u9884\u6784\u5EFA\u8D44\u6E90\uFF09\uFF0C\u6309 Ctrl+C \u9000\u51FA\u3002");
1105
+ const waitPromise = waitForServerExit(server);
1106
+ const handle = {
1107
+ async update(nextResult) {
1108
+ state.current = nextResult;
1109
+ if (serverRef) {
1110
+ serverRef.ws.send({
1111
+ type: "custom",
1112
+ event: "weapp-analyze:update",
1113
+ data: nextResult
1114
+ });
1115
+ }
1116
+ },
1117
+ waitForExit: () => waitPromise,
1118
+ close: async () => {
1119
+ await server.close();
1120
+ }
1121
+ };
1122
+ if (options?.watch) {
1123
+ void waitPromise;
1124
+ return handle;
1125
+ }
1126
+ await waitPromise;
1127
+ }
1128
+
1010
1129
  // src/cli/options.ts
1011
1130
  init_esm_shims();
1012
1131
  function filterDuplicateOptions(options) {
@@ -1196,10 +1315,10 @@ function registerAnalyzeCommand(cli2) {
1196
1315
  let writtenPath;
1197
1316
  if (outputOption) {
1198
1317
  const configService = ctx.configService;
1199
- const baseDir = configService?.cwd ?? process2.cwd();
1318
+ const baseDir = configService?.cwd ?? process3.cwd();
1200
1319
  const resolvedOutputPath = path2.isAbsolute(outputOption) ? outputOption : path2.resolve(baseDir, outputOption);
1201
- await fs.ensureDir(path2.dirname(resolvedOutputPath));
1202
- await fs.writeFile(resolvedOutputPath, `${JSON.stringify(result, null, 2)}
1320
+ await fs2.ensureDir(path2.dirname(resolvedOutputPath));
1321
+ await fs2.writeFile(resolvedOutputPath, `${JSON.stringify(result, null, 2)}
1203
1322
  `, "utf8");
1204
1323
  const relativeOutput = configService ? configService.relativeCwd(resolvedOutputPath) : resolvedOutputPath;
1205
1324
  logger_default.success(`\u5206\u6790\u7ED3\u679C\u5DF2\u5199\u5165 ${relativeOutput}`);
@@ -1207,15 +1326,16 @@ function registerAnalyzeCommand(cli2) {
1207
1326
  }
1208
1327
  if (outputJson) {
1209
1328
  if (!writtenPath) {
1210
- process2.stdout.write(`${JSON.stringify(result, null, 2)}
1329
+ process3.stdout.write(`${JSON.stringify(result, null, 2)}
1211
1330
  `);
1212
1331
  }
1213
1332
  } else {
1214
1333
  printAnalysisSummary(result);
1334
+ await startAnalyzeDashboard(result);
1215
1335
  }
1216
1336
  } catch (error) {
1217
1337
  logger_default.error(error);
1218
- process2.exitCode = 1;
1338
+ process3.exitCode = 1;
1219
1339
  }
1220
1340
  });
1221
1341
  }
@@ -1434,20 +1554,27 @@ function registerBuildCommand(cli2) {
1434
1554
  ).option(
1435
1555
  "--emptyOutDir",
1436
1556
  `[boolean] force empty outDir when it's outside of root`
1437
- ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).action(async (root, options) => {
1557
+ ).option("-w, --watch", `[boolean] rebuilds when modules have changed on disk`).option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).option("--analyze", `[boolean] \u8F93\u51FA\u5206\u5305\u5206\u6790\u4EEA\u8868\u76D8`, { default: false }).action(async (root, options) => {
1438
1558
  filterDuplicateOptions(options);
1439
1559
  const configFile = resolveConfigFile(options);
1440
1560
  const targets = resolveRuntimeTargets(options);
1441
1561
  logRuntimeTarget(targets);
1442
1562
  const inlineConfig = createInlineConfig(targets.mpPlatform);
1443
- const { buildService, configService, webService } = await createCompilerContext({
1563
+ const ctx = await createCompilerContext({
1444
1564
  cwd: root,
1445
1565
  mode: options.mode ?? "production",
1446
1566
  configFile,
1447
1567
  inlineConfig
1448
1568
  });
1569
+ const { buildService, configService, webService } = ctx;
1570
+ const enableAnalyze = Boolean(options.analyze && targets.runMini);
1571
+ let analyzeHandle;
1449
1572
  if (targets.runMini) {
1450
1573
  await buildService.build(options);
1574
+ if (enableAnalyze) {
1575
+ const analyzeResult = await analyzeSubpackages(ctx);
1576
+ analyzeHandle = await startAnalyzeDashboard(analyzeResult, { watch: true }) ?? void 0;
1577
+ }
1451
1578
  }
1452
1579
  const webConfig = configService.weappWebConfig;
1453
1580
  if (targets.runWeb && webConfig?.enabled) {
@@ -1465,6 +1592,9 @@ function registerBuildCommand(cli2) {
1465
1592
  if (options.open && targets.runMini) {
1466
1593
  await openIde();
1467
1594
  }
1595
+ if (analyzeHandle) {
1596
+ await analyzeHandle.waitForExit();
1597
+ }
1468
1598
  });
1469
1599
  }
1470
1600
 
@@ -1483,10 +1613,10 @@ import path5 from "pathe";
1483
1613
 
1484
1614
  // src/schematics.ts
1485
1615
  init_esm_shims();
1486
- import process3 from "process";
1616
+ import process4 from "process";
1487
1617
  import { generateJs, generateJson, generateWxml, generateWxss } from "@weapp-core/schematics";
1488
1618
  import { defu } from "@weapp-core/shared";
1489
- import fs2 from "fs-extra";
1619
+ import fs3 from "fs-extra";
1490
1620
  import path3 from "pathe";
1491
1621
  function composePath(outDir, filename) {
1492
1622
  return `${outDir}${outDir ? "/" : ""}${filename}`;
@@ -1502,7 +1632,7 @@ function resolveExtension(extension) {
1502
1632
  }
1503
1633
  async function readTemplateFile(templatePath, context) {
1504
1634
  const absolutePath = path3.isAbsolute(templatePath) ? templatePath : path3.resolve(context.cwd, templatePath);
1505
- return fs2.readFile(absolutePath, "utf8");
1635
+ return fs3.readFile(absolutePath, "utf8");
1506
1636
  }
1507
1637
  async function loadTemplate(template, context) {
1508
1638
  if (template === void 0) {
@@ -1536,7 +1666,7 @@ async function generate(options) {
1536
1666
  extensions: {
1537
1667
  ...defaultExtensions
1538
1668
  },
1539
- cwd: process3.cwd(),
1669
+ cwd: process4.cwd(),
1540
1670
  templates: void 0
1541
1671
  });
1542
1672
  if (fileName === void 0) {
@@ -1582,7 +1712,7 @@ async function generate(options) {
1582
1712
  }
1583
1713
  for (const { code, fileName: fileName2 } of files) {
1584
1714
  if (code !== void 0) {
1585
- await fs2.outputFile(path3.resolve(basepath, fileName2), code, "utf8");
1715
+ await fs3.outputFile(path3.resolve(basepath, fileName2), code, "utf8");
1586
1716
  logger_default.success(`${composePath(outDir, fileName2)} \u521B\u5EFA\u6210\u529F\uFF01`);
1587
1717
  }
1588
1718
  }
@@ -1590,12 +1720,12 @@ async function generate(options) {
1590
1720
 
1591
1721
  // src/cli/loadConfig.ts
1592
1722
  init_esm_shims();
1593
- import process4 from "process";
1723
+ import process5 from "process";
1594
1724
  import { defu as defu2 } from "@weapp-core/shared";
1595
1725
  import path4 from "pathe";
1596
1726
  import { loadConfigFromFile } from "vite";
1597
1727
  async function loadConfig(configFile) {
1598
- const cwd = process4.cwd();
1728
+ const cwd = process5.cwd();
1599
1729
  let resolvedConfigFile = configFile;
1600
1730
  if (resolvedConfigFile && !path4.isAbsolute(resolvedConfigFile)) {
1601
1731
  resolvedConfigFile = path4.resolve(cwd, resolvedConfigFile);
@@ -1715,21 +1845,50 @@ function registerOpenCommand(cli2) {
1715
1845
  // src/cli/commands/serve.ts
1716
1846
  init_esm_shims();
1717
1847
  function registerServeCommand(cli2) {
1718
- cli2.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).action(async (root, options) => {
1848
+ cli2.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).option("--analyze", `[boolean] \u542F\u52A8\u5206\u5305\u5206\u6790\u4EEA\u8868\u76D8 (\u5B9E\u9A8C\u7279\u6027)`, { default: false }).action(async (root, options) => {
1719
1849
  filterDuplicateOptions(options);
1720
1850
  const configFile = resolveConfigFile(options);
1721
1851
  const targets = resolveRuntimeTargets(options);
1722
1852
  logRuntimeTarget(targets);
1723
1853
  const inlineConfig = createInlineConfig(targets.mpPlatform);
1724
- const { buildService, configService, webService } = await createCompilerContext({
1854
+ const ctx = await createCompilerContext({
1725
1855
  cwd: root,
1726
1856
  mode: options.mode ?? "development",
1727
1857
  isDev: true,
1728
1858
  configFile,
1729
1859
  inlineConfig
1730
1860
  });
1861
+ const { buildService, configService, webService } = ctx;
1862
+ const enableAnalyze = Boolean(options.analyze && targets.runMini);
1863
+ let analyzeHandle;
1864
+ const triggerAnalyzeUpdate = async () => {
1865
+ if (!analyzeHandle) {
1866
+ return;
1867
+ }
1868
+ const next = await analyzeSubpackages(ctx);
1869
+ await analyzeHandle.update(next);
1870
+ };
1731
1871
  if (targets.runMini) {
1732
- await buildService.build(options);
1872
+ const buildResult = await buildService.build(options);
1873
+ if (enableAnalyze) {
1874
+ const initialResult = await analyzeSubpackages(ctx);
1875
+ analyzeHandle = await startAnalyzeDashboard(initialResult, { watch: true }) ?? void 0;
1876
+ if (analyzeHandle && buildResult && typeof buildResult.on === "function") {
1877
+ const watcher = buildResult;
1878
+ let updating = false;
1879
+ watcher.on("event", (event) => {
1880
+ if (event.code !== "END" || updating) {
1881
+ return;
1882
+ }
1883
+ updating = true;
1884
+ triggerAnalyzeUpdate().finally(() => {
1885
+ updating = false;
1886
+ });
1887
+ });
1888
+ } else if (analyzeHandle) {
1889
+ await triggerAnalyzeUpdate();
1890
+ }
1891
+ }
1733
1892
  }
1734
1893
  let webServer;
1735
1894
  if (targets.runWeb) {
@@ -1748,6 +1907,9 @@ function registerServeCommand(cli2) {
1748
1907
  if (options.open && targets.runMini) {
1749
1908
  await openIde();
1750
1909
  }
1910
+ if (analyzeHandle) {
1911
+ await analyzeHandle.waitForExit();
1912
+ }
1751
1913
  });
1752
1914
  }
1753
1915
 
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkVRKZFXIZcjs = require('./chunk-VRKZFXIZ.cjs');
4
- require('./chunk-FUJ4D6IR.cjs');
3
+ var _chunkGGLONZVQcjs = require('./chunk-GGLONZVQ.cjs');
4
+ require('./chunk-T4OVF4GP.cjs');
5
5
 
6
6
 
7
7
  var _chunkMQBCRXCDcjs = require('./chunk-MQBCRXCD.cjs');
@@ -27,4 +27,4 @@ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
27
27
 
28
28
 
29
29
 
30
- exports.createCompilerContext = _chunkVRKZFXIZcjs.createCompilerContext; exports.defineAppJson = _chunkG6EZVEVTcjs.defineAppJson; exports.defineComponentJson = _chunkG6EZVEVTcjs.defineComponentJson; exports.defineConfig = _chunkMQBCRXCDcjs.defineConfig; exports.definePageJson = _chunkG6EZVEVTcjs.definePageJson; exports.defineSitemapJson = _chunkG6EZVEVTcjs.defineSitemapJson; exports.defineThemeJson = _chunkG6EZVEVTcjs.defineThemeJson;
30
+ exports.createCompilerContext = _chunkGGLONZVQcjs.createCompilerContext; exports.defineAppJson = _chunkG6EZVEVTcjs.defineAppJson; exports.defineComponentJson = _chunkG6EZVEVTcjs.defineComponentJson; exports.defineConfig = _chunkMQBCRXCDcjs.defineConfig; exports.definePageJson = _chunkG6EZVEVTcjs.definePageJson; exports.defineSitemapJson = _chunkG6EZVEVTcjs.defineSitemapJson; exports.defineThemeJson = _chunkG6EZVEVTcjs.defineThemeJson;
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createCompilerContext
3
- } from "./chunk-GU7U5762.mjs";
4
- import "./chunk-AKJEW44F.mjs";
3
+ } from "./chunk-AXUA33LJ.mjs";
4
+ import "./chunk-O4FBXXL3.mjs";
5
5
  import {
6
6
  defineConfig
7
7
  } from "./chunk-N463WDOG.mjs";