weapp-vite 5.6.3 → 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.cjs CHANGED
@@ -1,6 +1,6 @@
1
- "use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
1
+ "use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkWYNGNSLKcjs = require('./chunk-WYNGNSLK.cjs');
3
+ var _chunkGGLONZVQcjs = require('./chunk-GGLONZVQ.cjs');
4
4
 
5
5
 
6
6
 
@@ -9,16 +9,16 @@ var _chunkWYNGNSLKcjs = require('./chunk-WYNGNSLK.cjs');
9
9
 
10
10
 
11
11
 
12
- var _chunkOQYESMEYcjs = require('./chunk-OQYESMEY.cjs');
12
+
13
+
14
+ var _chunkT4OVF4GPcjs = require('./chunk-T4OVF4GP.cjs');
15
+
13
16
 
14
17
 
15
18
  var _chunkA5DD7GKXcjs = require('./chunk-A5DD7GKX.cjs');
16
19
 
17
20
  // src/cli.ts
18
21
  _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
19
- var _process = require('process'); var _process2 = _interopRequireDefault(_process);
20
- var _init = require('@weapp-core/init');
21
- var _shared = require('@weapp-core/shared');
22
22
 
23
23
  // ../../node_modules/.pnpm/cac@6.7.14/node_modules/cac/dist/index.mjs
24
24
  _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
@@ -123,7 +123,7 @@ var findAllBrackets = (v) => {
123
123
  const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
124
124
  const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
125
125
  const res = [];
126
- const parse2 = (match) => {
126
+ const parse3 = (match) => {
127
127
  let variadic = false;
128
128
  let value = match[1];
129
129
  if (value.startsWith("...")) {
@@ -138,11 +138,11 @@ var findAllBrackets = (v) => {
138
138
  };
139
139
  let angledMatch;
140
140
  while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) {
141
- res.push(parse2(angledMatch));
141
+ res.push(parse3(angledMatch));
142
142
  }
143
143
  let squareMatch;
144
144
  while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) {
145
- res.push(parse2(squareMatch));
145
+ res.push(parse3(squareMatch));
146
146
  }
147
147
  return res;
148
148
  };
@@ -606,6 +606,747 @@ var CAC = class extends _events.EventEmitter {
606
606
  };
607
607
  var cac = (name = "") => new CAC(name);
608
608
 
609
+ // src/cli/commands/analyze.ts
610
+ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
611
+ var _process = require('process'); var _process2 = _interopRequireDefault(_process);
612
+ var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
613
+ var _pathe = require('pathe'); var _pathe2 = _interopRequireDefault(_pathe);
614
+
615
+ // src/analyze/subpackages.ts
616
+ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
617
+ var _buffer = require('buffer');
618
+
619
+ var _vite = require('vite');
620
+ var VIRTUAL_MODULE_INDICATOR = "\0";
621
+ var VIRTUAL_PREFIX = `${_chunkT4OVF4GPcjs.SHARED_CHUNK_VIRTUAL_PREFIX}/`;
622
+ function isPathInside(parent, candidate) {
623
+ if (!parent) {
624
+ return false;
625
+ }
626
+ const relative = _pathe.posix.relative(parent, candidate);
627
+ return relative === "" || !relative.startsWith("..") && !_pathe.posix.isAbsolute(relative);
628
+ }
629
+ function ensurePackage(packages, classification) {
630
+ const existing = packages.get(classification.id);
631
+ if (existing) {
632
+ return existing;
633
+ }
634
+ const created = {
635
+ ...classification,
636
+ files: /* @__PURE__ */ new Map()
637
+ };
638
+ packages.set(classification.id, created);
639
+ return created;
640
+ }
641
+ function ensureModule(modules, id, source, sourceType) {
642
+ const existing = modules.get(id);
643
+ if (existing) {
644
+ return existing;
645
+ }
646
+ const created = {
647
+ id,
648
+ source,
649
+ sourceType,
650
+ packages: /* @__PURE__ */ new Map()
651
+ };
652
+ modules.set(id, created);
653
+ return created;
654
+ }
655
+ function registerModuleInPackage(modules, moduleId, source, sourceType, packageId, fileName) {
656
+ const moduleEntry = ensureModule(modules, moduleId, source, sourceType);
657
+ const files = _nullishCoalesce(moduleEntry.packages.get(packageId), () => ( /* @__PURE__ */ new Set()));
658
+ files.add(fileName);
659
+ moduleEntry.packages.set(packageId, files);
660
+ }
661
+ function classifyPackage(fileName, origin, context) {
662
+ if (fileName.startsWith(VIRTUAL_PREFIX)) {
663
+ const combination = fileName.slice(VIRTUAL_PREFIX.length).split("/")[0] || "shared";
664
+ return {
665
+ id: `virtual:${combination}`,
666
+ label: `\u5171\u4EAB\u865A\u62DF\u5305 ${combination}`,
667
+ type: "virtual"
668
+ };
669
+ }
670
+ const segments = fileName.split("/");
671
+ const rootCandidate = _nullishCoalesce(segments[0], () => ( ""));
672
+ if (rootCandidate && context.subPackageRoots.has(rootCandidate)) {
673
+ const isIndependent = context.independentRoots.has(rootCandidate);
674
+ return {
675
+ id: rootCandidate,
676
+ label: `${isIndependent ? "\u72EC\u7ACB\u5206\u5305" : "\u5206\u5305"} ${rootCandidate}`,
677
+ type: isIndependent || origin === "independent" ? "independent" : "subPackage"
678
+ };
679
+ }
680
+ return {
681
+ id: "__main__",
682
+ label: "\u4E3B\u5305",
683
+ type: "main"
684
+ };
685
+ }
686
+ function normalizeModuleId(id) {
687
+ if (!id || id.includes(VIRTUAL_MODULE_INDICATOR)) {
688
+ return void 0;
689
+ }
690
+ if (!_pathe.posix.isAbsolute(id)) {
691
+ return void 0;
692
+ }
693
+ return _pathe.posix.normalize(id);
694
+ }
695
+ function resolveModuleSourceType(absoluteId, ctx) {
696
+ const { configService } = ctx;
697
+ const isNodeModule = absoluteId.includes("/node_modules/") || absoluteId.includes("\\node_modules\\");
698
+ const pluginRoot = configService.absolutePluginRoot;
699
+ const srcRoot = configService.absoluteSrcRoot;
700
+ const inSrc = isPathInside(srcRoot, absoluteId);
701
+ const inPlugin = pluginRoot ? isPathInside(pluginRoot, absoluteId) : false;
702
+ let sourceType;
703
+ if (isNodeModule) {
704
+ sourceType = "node_modules";
705
+ } else if (inSrc) {
706
+ sourceType = "src";
707
+ } else if (inPlugin) {
708
+ sourceType = "plugin";
709
+ } else {
710
+ sourceType = "workspace";
711
+ }
712
+ return {
713
+ source: configService.relativeAbsoluteSrcRoot(absoluteId),
714
+ sourceType
715
+ };
716
+ }
717
+ function resolveAssetSource(fileName, ctx) {
718
+ const { configService } = ctx;
719
+ const normalized = _pathe.posix.normalize(fileName);
720
+ const srcCandidate = _pathe.posix.resolve(configService.absoluteSrcRoot, normalized);
721
+ if (isPathInside(configService.absoluteSrcRoot, srcCandidate)) {
722
+ return {
723
+ absolute: srcCandidate,
724
+ source: configService.relativeAbsoluteSrcRoot(srcCandidate),
725
+ sourceType: "src"
726
+ };
727
+ }
728
+ const pluginRoot = configService.absolutePluginRoot;
729
+ if (pluginRoot) {
730
+ const pluginBase = _pathe.posix.basename(pluginRoot);
731
+ if (normalized === pluginBase || normalized.startsWith(`${pluginBase}/`)) {
732
+ const relative = normalized === pluginBase ? "" : normalized.slice(pluginBase.length + 1);
733
+ const absolute = _pathe.posix.resolve(pluginRoot, relative);
734
+ if (isPathInside(pluginRoot, absolute)) {
735
+ return {
736
+ absolute,
737
+ source: configService.relativeAbsoluteSrcRoot(absolute),
738
+ sourceType: "plugin"
739
+ };
740
+ }
741
+ }
742
+ }
743
+ }
744
+ function toArray(value) {
745
+ return Array.from(value);
746
+ }
747
+ function getAssetSize(asset) {
748
+ if (typeof asset.source === "string") {
749
+ return _buffer.Buffer.byteLength(asset.source, "utf8");
750
+ }
751
+ if (asset.source instanceof Uint8Array) {
752
+ return asset.source.byteLength;
753
+ }
754
+ }
755
+ function processChunk(chunk, origin, ctx, classifierContext, packages, modules) {
756
+ const classification = classifyPackage(chunk.fileName, origin, classifierContext);
757
+ const packageEntry = ensurePackage(packages, classification);
758
+ const chunkEntry = {
759
+ file: chunk.fileName,
760
+ type: "chunk",
761
+ from: origin,
762
+ size: typeof chunk.code === "string" ? _buffer.Buffer.byteLength(chunk.code, "utf8") : void 0,
763
+ isEntry: chunk.isEntry,
764
+ modules: []
765
+ };
766
+ const moduleEntries = Object.entries(_nullishCoalesce(chunk.modules, () => ( {})));
767
+ for (const [rawModuleId, info] of moduleEntries) {
768
+ const absoluteId = normalizeModuleId(rawModuleId);
769
+ if (!absoluteId) {
770
+ continue;
771
+ }
772
+ const { source, sourceType } = resolveModuleSourceType(absoluteId, ctx);
773
+ const moduleEntry = {
774
+ id: absoluteId,
775
+ source,
776
+ sourceType,
777
+ bytes: _optionalChain([info, 'optionalAccess', _2 => _2.renderedLength])
778
+ };
779
+ if (typeof _optionalChain([info, 'optionalAccess', _3 => _3.code]) === "string") {
780
+ moduleEntry.originalBytes = _buffer.Buffer.byteLength(info.code, "utf8");
781
+ }
782
+ chunkEntry.modules.push(moduleEntry);
783
+ registerModuleInPackage(
784
+ modules,
785
+ absoluteId,
786
+ source,
787
+ sourceType,
788
+ classification.id,
789
+ chunk.fileName
790
+ );
791
+ }
792
+ if (chunkEntry.modules) {
793
+ chunkEntry.modules.sort((a, b) => a.source.localeCompare(b.source));
794
+ }
795
+ packageEntry.files.set(chunk.fileName, chunkEntry);
796
+ }
797
+ function processAsset(asset, origin, ctx, classifierContext, packages, modules) {
798
+ const classification = classifyPackage(asset.fileName, origin, classifierContext);
799
+ const packageEntry = ensurePackage(packages, classification);
800
+ const entry = {
801
+ file: asset.fileName,
802
+ type: "asset",
803
+ from: origin,
804
+ size: getAssetSize(asset)
805
+ };
806
+ const assetSource = resolveAssetSource(asset.fileName, ctx);
807
+ if (assetSource) {
808
+ entry.source = assetSource.source;
809
+ registerModuleInPackage(
810
+ modules,
811
+ assetSource.absolute,
812
+ assetSource.source,
813
+ assetSource.sourceType,
814
+ classification.id,
815
+ asset.fileName
816
+ );
817
+ }
818
+ packageEntry.files.set(asset.fileName, entry);
819
+ }
820
+ function processOutput(output, origin, ctx, classifierContext, packages, modules) {
821
+ if (!output) {
822
+ return;
823
+ }
824
+ for (const item of _nullishCoalesce(output.output, () => ( []))) {
825
+ if (item.type === "chunk") {
826
+ processChunk(item, origin, ctx, classifierContext, packages, modules);
827
+ } else if (item.type === "asset") {
828
+ processAsset(item, origin, ctx, classifierContext, packages, modules);
829
+ }
830
+ }
831
+ }
832
+ function summarizePackages(packages) {
833
+ const order = {
834
+ main: 0,
835
+ subPackage: 1,
836
+ independent: 2,
837
+ virtual: 3
838
+ };
839
+ const reports = toArray(packages.values()).map((pkg) => {
840
+ const files = toArray(pkg.files.values());
841
+ files.sort((a, b) => a.file.localeCompare(b.file));
842
+ return {
843
+ id: pkg.id,
844
+ label: pkg.label,
845
+ type: pkg.type,
846
+ files
847
+ };
848
+ });
849
+ reports.sort((a, b) => {
850
+ const delta = order[a.type] - order[b.type];
851
+ if (delta !== 0) {
852
+ return delta;
853
+ }
854
+ if (a.id === "__main__") {
855
+ return -1;
856
+ }
857
+ if (b.id === "__main__") {
858
+ return 1;
859
+ }
860
+ return a.id.localeCompare(b.id);
861
+ });
862
+ return reports;
863
+ }
864
+ function summarizeModules(modules) {
865
+ const usage = toArray(modules.values()).map((module) => {
866
+ const packages = toArray(module.packages.entries()).map(([packageId, files]) => {
867
+ const sortedFiles = toArray(files).sort((a, b) => a.localeCompare(b));
868
+ return {
869
+ packageId,
870
+ files: sortedFiles
871
+ };
872
+ }).sort((a, b) => {
873
+ if (a.packageId === b.packageId) {
874
+ return 0;
875
+ }
876
+ if (a.packageId === "__main__") {
877
+ return -1;
878
+ }
879
+ if (b.packageId === "__main__") {
880
+ return 1;
881
+ }
882
+ return a.packageId.localeCompare(b.packageId);
883
+ });
884
+ return {
885
+ id: module.id,
886
+ source: module.source,
887
+ sourceType: module.sourceType,
888
+ packages
889
+ };
890
+ });
891
+ usage.sort((a, b) => a.source.localeCompare(b.source));
892
+ return usage;
893
+ }
894
+ function expandVirtualModulePlacements(modules, packages, context) {
895
+ for (const moduleEntry of modules.values()) {
896
+ const virtualEntries = Array.from(moduleEntry.packages.entries()).filter(([packageId]) => packageId.startsWith("virtual:"));
897
+ if (!virtualEntries.length) {
898
+ continue;
899
+ }
900
+ const virtualFileBases = /* @__PURE__ */ new Map();
901
+ for (const [virtualPackageId, files] of virtualEntries) {
902
+ const combination = virtualPackageId.slice("virtual:".length);
903
+ if (!combination) {
904
+ continue;
905
+ }
906
+ const segments = combination.split(/[_+]/).map((segment) => segment.trim()).filter(Boolean);
907
+ if (!segments.length) {
908
+ continue;
909
+ }
910
+ let matchingBases = virtualFileBases.get(virtualPackageId);
911
+ if (!matchingBases) {
912
+ matchingBases = Array.from(files).map((file) => _pathe.posix.basename(file));
913
+ virtualFileBases.set(virtualPackageId, matchingBases);
914
+ }
915
+ for (const root of segments) {
916
+ if (!context.subPackageRoots.has(root)) {
917
+ continue;
918
+ }
919
+ const targetPackage = packages.get(root);
920
+ if (!targetPackage) {
921
+ continue;
922
+ }
923
+ const moduleFiles = _nullishCoalesce(moduleEntry.packages.get(root), () => ( /* @__PURE__ */ new Set()));
924
+ const targetFiles = Array.from(targetPackage.files.values()).filter((fileEntry) => {
925
+ if (!_optionalChain([matchingBases, 'optionalAccess', _4 => _4.length])) {
926
+ return true;
927
+ }
928
+ const base = _pathe.posix.basename(fileEntry.file);
929
+ return matchingBases.includes(base);
930
+ }).map((fileEntry) => fileEntry.file);
931
+ if (targetFiles.length === 0) {
932
+ const fallback = targetPackage.files.values().next().value;
933
+ if (fallback) {
934
+ moduleFiles.add(fallback.file);
935
+ }
936
+ } else {
937
+ for (const fileName of targetFiles) {
938
+ moduleFiles.add(fileName);
939
+ }
940
+ }
941
+ if (moduleFiles.size > 0) {
942
+ moduleEntry.packages.set(root, moduleFiles);
943
+ }
944
+ }
945
+ }
946
+ }
947
+ }
948
+ function summarizeSubPackages(metas) {
949
+ const descriptors = metas.map((meta) => {
950
+ const root = _nullishCoalesce(meta.subPackage.root, () => ( ""));
951
+ return {
952
+ root,
953
+ independent: Boolean(meta.subPackage.independent),
954
+ name: meta.subPackage.name
955
+ };
956
+ }).filter((descriptor) => descriptor.root);
957
+ descriptors.sort((a, b) => a.root.localeCompare(b.root));
958
+ return descriptors;
959
+ }
960
+ async function analyzeSubpackages(ctx) {
961
+ const { configService, scanService, buildService } = ctx;
962
+ if (!configService || !scanService || !buildService) {
963
+ throw new Error("analyzeSubpackages requires configService, scanService and buildService to be initialized");
964
+ }
965
+ await scanService.loadAppEntry();
966
+ const subPackageMetas = scanService.loadSubPackages();
967
+ const subPackageRoots = /* @__PURE__ */ new Set();
968
+ const independentRoots = /* @__PURE__ */ new Set();
969
+ for (const meta of subPackageMetas) {
970
+ const root = meta.subPackage.root;
971
+ if (root) {
972
+ subPackageRoots.add(root);
973
+ if (meta.subPackage.independent) {
974
+ independentRoots.add(root);
975
+ }
976
+ }
977
+ }
978
+ const classifierContext = {
979
+ subPackageRoots,
980
+ independentRoots
981
+ };
982
+ const analysisConfig = configService.merge(
983
+ void 0,
984
+ _chunkT4OVF4GPcjs.createSharedBuildConfig.call(void 0, configService, scanService),
985
+ {
986
+ build: {
987
+ write: false,
988
+ watch: null
989
+ }
990
+ }
991
+ );
992
+ const mainResult = await _vite.build.call(void 0, analysisConfig);
993
+ const mainOutputs = Array.isArray(mainResult) ? mainResult : [mainResult];
994
+ const packages = /* @__PURE__ */ new Map();
995
+ const modules = /* @__PURE__ */ new Map();
996
+ for (const output of mainOutputs) {
997
+ processOutput(output, "main", ctx, classifierContext, packages, modules);
998
+ }
999
+ for (const root of independentRoots) {
1000
+ const output = buildService.getIndependentOutput(root);
1001
+ processOutput(output, "independent", ctx, classifierContext, packages, modules);
1002
+ }
1003
+ expandVirtualModulePlacements(modules, packages, classifierContext);
1004
+ return {
1005
+ packages: summarizePackages(packages),
1006
+ modules: summarizeModules(modules),
1007
+ subPackages: summarizeSubPackages(subPackageMetas)
1008
+ };
1009
+ }
1010
+
1011
+ // src/cli/analyze/dashboard.ts
1012
+ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
1013
+ var _path = require('path');
1014
+
1015
+ var _url = require('url');
1016
+
1017
+
1018
+ var __filename = _url.fileURLToPath.call(void 0, _chunkA5DD7GKXcjs.importMetaUrl);
1019
+ var __dirname = _path.dirname.call(void 0, __filename);
1020
+ var PACKAGE_ROOT = _path.resolve.call(void 0, __dirname, "../../..");
1021
+ var BUILD_DASHBOARD_ROOT = _path.resolve.call(void 0, PACKAGE_ROOT, "modules/analyze-dashboard");
1022
+ var ANALYZE_GLOBAL_KEY = "__WEAPP_VITE_ANALYZE_RESULT__";
1023
+ function resolveDashboardRoot() {
1024
+ if (_fsextra2.default.existsSync(BUILD_DASHBOARD_ROOT)) {
1025
+ return {
1026
+ root: BUILD_DASHBOARD_ROOT
1027
+ };
1028
+ }
1029
+ throw new Error(
1030
+ "[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"
1031
+ );
1032
+ }
1033
+ function createAnalyzeHtmlPlugin(state, onServerInstance) {
1034
+ return {
1035
+ name: "weapp-vite-analyze-html",
1036
+ transformIndexHtml(html) {
1037
+ return {
1038
+ html,
1039
+ tags: [
1040
+ {
1041
+ tag: "script",
1042
+ children: `window.${ANALYZE_GLOBAL_KEY} = ${JSON.stringify(state.current)}`,
1043
+ injectTo: "head-prepend"
1044
+ }
1045
+ ]
1046
+ };
1047
+ },
1048
+ configureServer(server) {
1049
+ onServerInstance(server);
1050
+ }
1051
+ };
1052
+ }
1053
+ async function waitForServerExit(server) {
1054
+ let resolved = false;
1055
+ const cleanup = async () => {
1056
+ if (resolved) {
1057
+ return;
1058
+ }
1059
+ resolved = true;
1060
+ try {
1061
+ await server.close();
1062
+ } catch (error) {
1063
+ _chunkT4OVF4GPcjs.logger_default.error(error);
1064
+ }
1065
+ };
1066
+ const signals = ["SIGINT", "SIGTERM"];
1067
+ await new Promise((resolvePromise) => {
1068
+ const resolveOnce = async () => {
1069
+ await cleanup();
1070
+ signals.forEach((signal) => {
1071
+ _process2.default.removeListener(signal, resolveOnce);
1072
+ });
1073
+ resolvePromise();
1074
+ };
1075
+ signals.forEach((signal) => {
1076
+ _process2.default.once(signal, resolveOnce);
1077
+ });
1078
+ _optionalChain([server, 'access', _5 => _5.httpServer, 'optionalAccess', _6 => _6.once, 'call', _7 => _7("close", resolveOnce)]);
1079
+ });
1080
+ }
1081
+ async function startAnalyzeDashboard(result, options) {
1082
+ const { root } = resolveDashboardRoot();
1083
+ const state = { current: result };
1084
+ let serverRef;
1085
+ const plugins = [
1086
+ createAnalyzeHtmlPlugin(state, (server2) => {
1087
+ serverRef = server2;
1088
+ })
1089
+ ];
1090
+ const server = await _vite.createServer.call(void 0, {
1091
+ root,
1092
+ clearScreen: false,
1093
+ appType: "spa",
1094
+ publicDir: false,
1095
+ plugins,
1096
+ server: {
1097
+ host: "127.0.0.1",
1098
+ port: 0
1099
+ },
1100
+ logLevel: "error"
1101
+ });
1102
+ await server.listen();
1103
+ serverRef ??= server;
1104
+ server.printUrls();
1105
+ _chunkT4OVF4GPcjs.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");
1106
+ const waitPromise = waitForServerExit(server);
1107
+ const handle = {
1108
+ async update(nextResult) {
1109
+ state.current = nextResult;
1110
+ if (serverRef) {
1111
+ serverRef.ws.send({
1112
+ type: "custom",
1113
+ event: "weapp-analyze:update",
1114
+ data: nextResult
1115
+ });
1116
+ }
1117
+ },
1118
+ waitForExit: () => waitPromise,
1119
+ close: async () => {
1120
+ await server.close();
1121
+ }
1122
+ };
1123
+ if (_optionalChain([options, 'optionalAccess', _8 => _8.watch])) {
1124
+ void waitPromise;
1125
+ return handle;
1126
+ }
1127
+ await waitPromise;
1128
+ }
1129
+
1130
+ // src/cli/options.ts
1131
+ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
1132
+ function filterDuplicateOptions(options) {
1133
+ for (const [key, value] of Object.entries(options)) {
1134
+ if (Array.isArray(value)) {
1135
+ options[key] = value[value.length - 1];
1136
+ }
1137
+ }
1138
+ }
1139
+ function resolveConfigFile(options) {
1140
+ if (typeof options.config === "string") {
1141
+ return options.config;
1142
+ }
1143
+ if (typeof options.c === "string") {
1144
+ return options.c;
1145
+ }
1146
+ }
1147
+ function convertBase(value) {
1148
+ if (value === 0) {
1149
+ return "";
1150
+ }
1151
+ return value;
1152
+ }
1153
+ function coerceBooleanOption(value) {
1154
+ if (value === void 0) {
1155
+ return void 0;
1156
+ }
1157
+ if (typeof value === "boolean") {
1158
+ return value;
1159
+ }
1160
+ if (typeof value === "string") {
1161
+ const normalized = value.trim().toLowerCase();
1162
+ if (normalized === "") {
1163
+ return true;
1164
+ }
1165
+ if (normalized === "false" || normalized === "0" || normalized === "off" || normalized === "no") {
1166
+ return false;
1167
+ }
1168
+ if (normalized === "true" || normalized === "1" || normalized === "on" || normalized === "yes") {
1169
+ return true;
1170
+ }
1171
+ return true;
1172
+ }
1173
+ if (typeof value === "number") {
1174
+ return value !== 0;
1175
+ }
1176
+ return Boolean(value);
1177
+ }
1178
+
1179
+ // src/cli/runtime.ts
1180
+ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
1181
+ function logRuntimeTarget(targets) {
1182
+ _chunkT4OVF4GPcjs.logger_default.info(`\u76EE\u6807\u5E73\u53F0\uFF1A${targets.label}`);
1183
+ }
1184
+ function resolveRuntimeTargets(options) {
1185
+ const rawPlatform = typeof options.platform === "string" ? options.platform : typeof options.p === "string" ? options.p : void 0;
1186
+ if (!rawPlatform) {
1187
+ return {
1188
+ runMini: true,
1189
+ runWeb: false,
1190
+ mpPlatform: _chunkT4OVF4GPcjs.DEFAULT_MP_PLATFORM,
1191
+ label: _chunkT4OVF4GPcjs.DEFAULT_MP_PLATFORM
1192
+ };
1193
+ }
1194
+ const normalized = _chunkT4OVF4GPcjs.normalizeMiniPlatform.call(void 0, rawPlatform);
1195
+ if (!normalized) {
1196
+ return {
1197
+ runMini: true,
1198
+ runWeb: false,
1199
+ mpPlatform: _chunkT4OVF4GPcjs.DEFAULT_MP_PLATFORM,
1200
+ label: _chunkT4OVF4GPcjs.DEFAULT_MP_PLATFORM
1201
+ };
1202
+ }
1203
+ if (normalized === "h5" || normalized === "web") {
1204
+ return {
1205
+ runMini: false,
1206
+ runWeb: true,
1207
+ mpPlatform: void 0,
1208
+ label: normalized === "h5" ? "h5" : "web"
1209
+ };
1210
+ }
1211
+ const mpPlatform = _chunkT4OVF4GPcjs.resolveMiniPlatform.call(void 0, normalized);
1212
+ if (mpPlatform) {
1213
+ return {
1214
+ runMini: true,
1215
+ runWeb: false,
1216
+ mpPlatform,
1217
+ label: mpPlatform
1218
+ };
1219
+ }
1220
+ _chunkT4OVF4GPcjs.logger_default.warn(`\u672A\u8BC6\u522B\u7684\u5E73\u53F0 "${rawPlatform}"\uFF0C\u5DF2\u56DE\u9000\u5230 ${_chunkT4OVF4GPcjs.DEFAULT_MP_PLATFORM}`);
1221
+ return {
1222
+ runMini: true,
1223
+ runWeb: false,
1224
+ mpPlatform: _chunkT4OVF4GPcjs.DEFAULT_MP_PLATFORM,
1225
+ label: _chunkT4OVF4GPcjs.DEFAULT_MP_PLATFORM
1226
+ };
1227
+ }
1228
+ function createInlineConfig(mpPlatform) {
1229
+ if (!mpPlatform) {
1230
+ return void 0;
1231
+ }
1232
+ return {
1233
+ weapp: {
1234
+ platform: mpPlatform
1235
+ }
1236
+ };
1237
+ }
1238
+
1239
+ // src/cli/commands/analyze.ts
1240
+ function printAnalysisSummary(result) {
1241
+ const packageLabelMap = /* @__PURE__ */ new Map();
1242
+ const packageModuleSet = /* @__PURE__ */ new Map();
1243
+ for (const pkg of result.packages) {
1244
+ packageLabelMap.set(pkg.id, pkg.label);
1245
+ }
1246
+ for (const module of result.modules) {
1247
+ for (const pkgRef of module.packages) {
1248
+ const set = _nullishCoalesce(packageModuleSet.get(pkgRef.packageId), () => ( /* @__PURE__ */ new Set()));
1249
+ set.add(module.id);
1250
+ packageModuleSet.set(pkgRef.packageId, set);
1251
+ }
1252
+ }
1253
+ _chunkT4OVF4GPcjs.logger_default.success("\u5206\u5305\u5206\u6790\u5B8C\u6210");
1254
+ for (const pkg of result.packages) {
1255
+ const chunkCount = pkg.files.filter((file) => file.type === "chunk").length;
1256
+ const assetCount = pkg.files.length - chunkCount;
1257
+ const moduleCount = _nullishCoalesce(_optionalChain([packageModuleSet, 'access', _9 => _9.get, 'call', _10 => _10(pkg.id), 'optionalAccess', _11 => _11.size]), () => ( 0));
1258
+ _chunkT4OVF4GPcjs.logger_default.info(`- ${pkg.label}\uFF1A${chunkCount} \u4E2A\u6A21\u5757\u4EA7\u7269\uFF0C${assetCount} \u4E2A\u8D44\u6E90\uFF0C\u8986\u76D6 ${moduleCount} \u4E2A\u6E90\u7801\u6A21\u5757`);
1259
+ }
1260
+ if (result.subPackages.length > 0) {
1261
+ _chunkT4OVF4GPcjs.logger_default.info("\u5206\u5305\u914D\u7F6E\uFF1A");
1262
+ for (const descriptor of result.subPackages) {
1263
+ const segments = [descriptor.root];
1264
+ if (descriptor.name) {
1265
+ segments.push(`\u522B\u540D\uFF1A${descriptor.name}`);
1266
+ }
1267
+ if (descriptor.independent) {
1268
+ segments.push("\u72EC\u7ACB\u6784\u5EFA");
1269
+ }
1270
+ _chunkT4OVF4GPcjs.logger_default.info(`- ${segments.join("\uFF0C")}`);
1271
+ }
1272
+ }
1273
+ const duplicates = result.modules.filter((module) => module.packages.length > 1);
1274
+ if (duplicates.length === 0) {
1275
+ _chunkT4OVF4GPcjs.logger_default.info("\u672A\u68C0\u6D4B\u5230\u8DE8\u5305\u590D\u7528\u7684\u6E90\u7801\u6A21\u5757\u3002");
1276
+ return;
1277
+ }
1278
+ _chunkT4OVF4GPcjs.logger_default.info(`\u8DE8\u5305\u590D\u7528/\u590D\u5236\u6E90\u7801\u5171 ${duplicates.length} \u9879\uFF1A`);
1279
+ const limit = 10;
1280
+ const entries = duplicates.slice(0, limit);
1281
+ for (const module of entries) {
1282
+ const placements = module.packages.map((pkgRef) => {
1283
+ const label = _nullishCoalesce(packageLabelMap.get(pkgRef.packageId), () => ( pkgRef.packageId));
1284
+ return `${label} \u2192 ${pkgRef.files.join(", ")}`;
1285
+ }).join("\uFF1B");
1286
+ _chunkT4OVF4GPcjs.logger_default.info(`- ${module.source} (${module.sourceType})\uFF1A${placements}`);
1287
+ }
1288
+ if (duplicates.length > limit) {
1289
+ _chunkT4OVF4GPcjs.logger_default.info(`- \u2026\u5176\u4F59 ${duplicates.length - limit} \u9879\u8BF7\u4F7F\u7528 \`weapp-vite analyze --json\` \u67E5\u770B`);
1290
+ }
1291
+ }
1292
+ function registerAnalyzeCommand(cli2) {
1293
+ cli2.command("analyze [root]", "analyze \u4E24\u7AEF\u5305\u4F53\u4E0E\u6E90\u7801\u6620\u5C04").option("--json", `[boolean] \u8F93\u51FA JSON \u7ED3\u679C`).option("--output <file>", `[string] \u5C06\u5206\u6790\u7ED3\u679C\u5199\u5165\u6307\u5B9A\u6587\u4EF6\uFF08JSON\uFF09`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).action(async (root, options) => {
1294
+ filterDuplicateOptions(options);
1295
+ const configFile = resolveConfigFile(options);
1296
+ const targets = resolveRuntimeTargets(options);
1297
+ logRuntimeTarget(targets);
1298
+ if (!targets.runMini) {
1299
+ _chunkT4OVF4GPcjs.logger_default.warn("\u5F53\u524D\u547D\u4EE4\u4EC5\u652F\u6301\u5C0F\u7A0B\u5E8F\u5E73\u53F0\uFF0C\u8BF7\u901A\u8FC7 --platform weapp \u6307\u5B9A\u76EE\u6807\u3002");
1300
+ return;
1301
+ }
1302
+ if (targets.runWeb) {
1303
+ _chunkT4OVF4GPcjs.logger_default.warn("\u5206\u6790\u547D\u4EE4\u6682\u4E0D\u652F\u6301 Web \u5E73\u53F0\uFF0C\u5C06\u5FFD\u7565\u76F8\u5173\u914D\u7F6E\u3002");
1304
+ }
1305
+ const inlineConfig = createInlineConfig(targets.mpPlatform);
1306
+ try {
1307
+ const ctx = await _chunkGGLONZVQcjs.createCompilerContext.call(void 0, {
1308
+ cwd: root,
1309
+ mode: _nullishCoalesce(options.mode, () => ( "production")),
1310
+ configFile,
1311
+ inlineConfig
1312
+ });
1313
+ const result = await analyzeSubpackages(ctx);
1314
+ const outputJson = coerceBooleanOption(options.json);
1315
+ const outputOption = typeof options.output === "string" ? options.output.trim() : "";
1316
+ let writtenPath;
1317
+ if (outputOption) {
1318
+ const configService = ctx.configService;
1319
+ const baseDir = _nullishCoalesce(_optionalChain([configService, 'optionalAccess', _12 => _12.cwd]), () => ( _process2.default.cwd()));
1320
+ const resolvedOutputPath = _pathe2.default.isAbsolute(outputOption) ? outputOption : _pathe2.default.resolve(baseDir, outputOption);
1321
+ await _fsextra2.default.ensureDir(_pathe2.default.dirname(resolvedOutputPath));
1322
+ await _fsextra2.default.writeFile(resolvedOutputPath, `${JSON.stringify(result, null, 2)}
1323
+ `, "utf8");
1324
+ const relativeOutput = configService ? configService.relativeCwd(resolvedOutputPath) : resolvedOutputPath;
1325
+ _chunkT4OVF4GPcjs.logger_default.success(`\u5206\u6790\u7ED3\u679C\u5DF2\u5199\u5165 ${relativeOutput}`);
1326
+ writtenPath = resolvedOutputPath;
1327
+ }
1328
+ if (outputJson) {
1329
+ if (!writtenPath) {
1330
+ _process2.default.stdout.write(`${JSON.stringify(result, null, 2)}
1331
+ `);
1332
+ }
1333
+ } else {
1334
+ printAnalysisSummary(result);
1335
+ await startAnalyzeDashboard(result);
1336
+ }
1337
+ } catch (error) {
1338
+ _chunkT4OVF4GPcjs.logger_default.error(error);
1339
+ _process2.default.exitCode = 1;
1340
+ }
1341
+ });
1342
+ }
1343
+
1344
+ // src/cli/commands/build.ts
1345
+ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
1346
+
1347
+ // src/cli/logBuildAppFinish.ts
1348
+ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
1349
+
609
1350
  // ../../node_modules/.pnpm/package-manager-detector@1.5.0/node_modules/package-manager-detector/dist/commands.mjs
610
1351
  _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
611
1352
  function dashDashArg(agent, agentCommand) {
@@ -740,17 +1481,143 @@ function constructCommand(value, args) {
740
1481
  };
741
1482
  }
742
1483
 
743
- // src/cli.ts
744
- var _pathe = require('pathe'); var _pathe2 = _interopRequireDefault(_pathe);
745
- var _vite = require('vite');
1484
+ // src/cli/logBuildAppFinish.ts
1485
+ var logBuildAppFinishOnlyShowOnce = false;
1486
+ function logBuildAppFinish(configService, webServer, options = {}) {
1487
+ if (logBuildAppFinishOnlyShowOnce) {
1488
+ return;
1489
+ }
1490
+ const { skipMini = false, skipWeb = false } = options;
1491
+ if (skipMini) {
1492
+ if (webServer) {
1493
+ const urls = webServer.resolvedUrls;
1494
+ const candidates = urls ? [..._nullishCoalesce(urls.local, () => ( [])), ..._nullishCoalesce(urls.network, () => ( []))] : [];
1495
+ if (candidates.length > 0) {
1496
+ _chunkT4OVF4GPcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
1497
+ for (const url of candidates) {
1498
+ _chunkT4OVF4GPcjs.logger_default.info(` \u279C ${url}`);
1499
+ }
1500
+ } else {
1501
+ _chunkT4OVF4GPcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
1502
+ }
1503
+ } else {
1504
+ _chunkT4OVF4GPcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
1505
+ }
1506
+ logBuildAppFinishOnlyShowOnce = true;
1507
+ return;
1508
+ }
1509
+ const { command, args } = _nullishCoalesce(resolveCommand(
1510
+ configService.packageManager.agent,
1511
+ "run",
1512
+ ["open"]
1513
+ ), () => ( {
1514
+ command: "npm",
1515
+ args: ["run", "open"]
1516
+ }));
1517
+ const devCommand = `${command} ${args.join(" ")}`;
1518
+ _chunkT4OVF4GPcjs.logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
1519
+ _chunkT4OVF4GPcjs.logger_default.info(`\u6267\u884C \`${devCommand}\` \u53EF\u4EE5\u76F4\u63A5\u5728 \`\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\` \u91CC\u6253\u5F00\u5F53\u524D\u5E94\u7528`);
1520
+ _chunkT4OVF4GPcjs.logger_default.info("\u6216\u624B\u52A8\u6253\u5F00\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\uFF0C\u5BFC\u5165\u6839\u76EE\u5F55(`project.config.json` \u6587\u4EF6\u6240\u5728\u7684\u76EE\u5F55)\uFF0C\u5373\u53EF\u9884\u89C8\u6548\u679C");
1521
+ if (!skipWeb && webServer) {
1522
+ const urls = webServer.resolvedUrls;
1523
+ const candidates = urls ? [..._nullishCoalesce(urls.local, () => ( [])), ..._nullishCoalesce(urls.network, () => ( []))] : [];
1524
+ if (candidates.length > 0) {
1525
+ _chunkT4OVF4GPcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
1526
+ for (const url of candidates) {
1527
+ _chunkT4OVF4GPcjs.logger_default.info(` \u279C ${url}`);
1528
+ }
1529
+ } else {
1530
+ _chunkT4OVF4GPcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
1531
+ }
1532
+ }
1533
+ logBuildAppFinishOnlyShowOnce = true;
1534
+ }
1535
+
1536
+ // src/cli/openIde.ts
1537
+ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
746
1538
  var _weappidecli = require('weapp-ide-cli');
1539
+ async function openIde() {
1540
+ try {
1541
+ await _weappidecli.parse.call(void 0, ["open", "-p"]);
1542
+ } catch (error) {
1543
+ _chunkT4OVF4GPcjs.logger_default.error(error);
1544
+ }
1545
+ }
1546
+
1547
+ // src/cli/commands/build.ts
1548
+ function registerBuildCommand(cli2) {
1549
+ cli2.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).option(
1550
+ "--sourcemap [output]",
1551
+ `[boolean | "inline" | "hidden"] output source maps for build (default: false)`
1552
+ ).option(
1553
+ "--minify [minifier]",
1554
+ `[boolean | "terser" | "esbuild"] enable/disable minification, or specify minifier to use (default: esbuild)`
1555
+ ).option(
1556
+ "--emptyOutDir",
1557
+ `[boolean] force empty outDir when it's outside of root`
1558
+ ).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) => {
1559
+ filterDuplicateOptions(options);
1560
+ const configFile = resolveConfigFile(options);
1561
+ const targets = resolveRuntimeTargets(options);
1562
+ logRuntimeTarget(targets);
1563
+ const inlineConfig = createInlineConfig(targets.mpPlatform);
1564
+ const ctx = await _chunkGGLONZVQcjs.createCompilerContext.call(void 0, {
1565
+ cwd: root,
1566
+ mode: _nullishCoalesce(options.mode, () => ( "production")),
1567
+ configFile,
1568
+ inlineConfig
1569
+ });
1570
+ const { buildService, configService, webService } = ctx;
1571
+ const enableAnalyze = Boolean(options.analyze && targets.runMini);
1572
+ let analyzeHandle;
1573
+ if (targets.runMini) {
1574
+ await buildService.build(options);
1575
+ if (enableAnalyze) {
1576
+ const analyzeResult = await analyzeSubpackages(ctx);
1577
+ analyzeHandle = await _asyncNullishCoalesce(await startAnalyzeDashboard(analyzeResult, { watch: true }), async () => ( void 0));
1578
+ }
1579
+ }
1580
+ const webConfig = configService.weappWebConfig;
1581
+ if (targets.runWeb && _optionalChain([webConfig, 'optionalAccess', _13 => _13.enabled])) {
1582
+ try {
1583
+ await _optionalChain([webService, 'optionalAccess', _14 => _14.build, 'call', _15 => _15()]);
1584
+ _chunkT4OVF4GPcjs.logger_default.success(`Web \u6784\u5EFA\u5B8C\u6210\uFF0C\u8F93\u51FA\u76EE\u5F55\uFF1A${configService.relativeCwd(webConfig.outDir)}`);
1585
+ } catch (error) {
1586
+ _chunkT4OVF4GPcjs.logger_default.error(error);
1587
+ throw error;
1588
+ }
1589
+ }
1590
+ if (targets.runMini) {
1591
+ logBuildAppFinish(configService, void 0, { skipWeb: !targets.runWeb });
1592
+ }
1593
+ if (options.open && targets.runMini) {
1594
+ await openIde();
1595
+ }
1596
+ if (analyzeHandle) {
1597
+ await analyzeHandle.waitForExit();
1598
+ }
1599
+ });
1600
+ }
1601
+
1602
+ // src/cli/commands/create.ts
1603
+ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
1604
+ var _init = require('@weapp-core/init');
1605
+ function registerCreateCommand(cli2) {
1606
+ cli2.command("create [outDir]", "create project").option("-t, --template <type>", "template type").action(async (outDir, options) => {
1607
+ await _init.createProject.call(void 0, outDir, options.template);
1608
+ });
1609
+ }
1610
+
1611
+ // src/cli/commands/generate.ts
1612
+ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
1613
+
747
1614
 
748
1615
  // src/schematics.ts
749
1616
  _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
750
1617
 
751
1618
  var _schematics = require('@weapp-core/schematics');
1619
+ var _shared = require('@weapp-core/shared');
752
1620
 
753
- var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
754
1621
 
755
1622
  function composePath(outDir, filename) {
756
1623
  return `${outDir}${outDir ? "/" : ""}${filename}`;
@@ -788,11 +1655,11 @@ async function loadTemplate(template, context) {
788
1655
  return void 0;
789
1656
  }
790
1657
  function resolveTemplate(templates, type, fileType) {
791
- const scoped = _optionalChain([templates, 'optionalAccess', _2 => _2[type], 'optionalAccess', _3 => _3[fileType]]);
1658
+ const scoped = _optionalChain([templates, 'optionalAccess', _16 => _16[type], 'optionalAccess', _17 => _17[fileType]]);
792
1659
  if (scoped !== void 0) {
793
1660
  return scoped;
794
1661
  }
795
- return _optionalChain([templates, 'optionalAccess', _4 => _4.shared, 'optionalAccess', _5 => _5[fileType]]);
1662
+ return _optionalChain([templates, 'optionalAccess', _18 => _18.shared, 'optionalAccess', _19 => _19[fileType]]);
796
1663
  }
797
1664
  async function generate(options) {
798
1665
  let { fileName, outDir, extensions, type, cwd, templates } = _shared.defu.call(void 0, options, {
@@ -847,21 +1714,17 @@ async function generate(options) {
847
1714
  for (const { code, fileName: fileName2 } of files) {
848
1715
  if (code !== void 0) {
849
1716
  await _fsextra2.default.outputFile(_pathe2.default.resolve(basepath, fileName2), code, "utf8");
850
- _chunkOQYESMEYcjs.logger_default.success(`${composePath(outDir, fileName2)} \u521B\u5EFA\u6210\u529F\uFF01`);
1717
+ _chunkT4OVF4GPcjs.logger_default.success(`${composePath(outDir, fileName2)} \u521B\u5EFA\u6210\u529F\uFF01`);
851
1718
  }
852
1719
  }
853
1720
  }
854
1721
 
855
- // src/cli.ts
856
- var cli = cac("weapp-vite");
857
- try {
858
- _chunkOQYESMEYcjs.checkRuntime.call(void 0, {
859
- bun: "0.0.0",
860
- deno: "0.0.0",
861
- node: "20.19.0"
862
- });
863
- } catch (e) {
864
- }
1722
+ // src/cli/loadConfig.ts
1723
+ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
1724
+
1725
+
1726
+
1727
+
865
1728
  async function loadConfig(configFile) {
866
1729
  const cwd = _process2.default.cwd();
867
1730
  let resolvedConfigFile = configFile;
@@ -873,14 +1736,14 @@ async function loadConfig(configFile) {
873
1736
  mode: "development"
874
1737
  };
875
1738
  const loaded = await _vite.loadConfigFromFile.call(void 0, configEnv, resolvedConfigFile, cwd);
876
- const weappConfigFilePath = await _chunkOQYESMEYcjs.resolveWeappConfigFile.call(void 0, {
1739
+ const weappConfigFilePath = await _chunkT4OVF4GPcjs.resolveWeappConfigFile.call(void 0, {
877
1740
  root: cwd,
878
1741
  specified: resolvedConfigFile
879
1742
  });
880
1743
  let weappLoaded;
881
1744
  if (weappConfigFilePath) {
882
1745
  const normalizedWeappPath = _pathe2.default.resolve(weappConfigFilePath);
883
- const normalizedLoadedPath = _optionalChain([loaded, 'optionalAccess', _6 => _6.path]) ? _pathe2.default.resolve(loaded.path) : void 0;
1746
+ const normalizedLoadedPath = _optionalChain([loaded, 'optionalAccess', _20 => _20.path]) ? _pathe2.default.resolve(loaded.path) : void 0;
884
1747
  if (normalizedLoadedPath && normalizedLoadedPath === normalizedWeappPath) {
885
1748
  weappLoaded = loaded;
886
1749
  } else {
@@ -890,289 +1753,188 @@ async function loadConfig(configFile) {
890
1753
  if (!loaded && !weappLoaded) {
891
1754
  return void 0;
892
1755
  }
893
- const config = _nullishCoalesce(_optionalChain([loaded, 'optionalAccess', _7 => _7.config]), () => ( (_nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess', _8 => _8.config]), () => ( {})))));
894
- if (_optionalChain([weappLoaded, 'optionalAccess', _9 => _9.config, 'optionalAccess', _10 => _10.weapp])) {
1756
+ const config = _nullishCoalesce(_optionalChain([loaded, 'optionalAccess', _21 => _21.config]), () => ( (_nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess', _22 => _22.config]), () => ( {})))));
1757
+ if (_optionalChain([weappLoaded, 'optionalAccess', _23 => _23.config, 'optionalAccess', _24 => _24.weapp])) {
895
1758
  config.weapp = _shared.defu.call(void 0,
896
1759
  weappLoaded.config.weapp,
897
1760
  _nullishCoalesce(config.weapp, () => ( {}))
898
1761
  );
899
1762
  }
900
1763
  const dependencySet = /* @__PURE__ */ new Set();
901
- for (const dependency of _nullishCoalesce(_optionalChain([loaded, 'optionalAccess', _11 => _11.dependencies]), () => ( []))) {
1764
+ for (const dependency of _nullishCoalesce(_optionalChain([loaded, 'optionalAccess', _25 => _25.dependencies]), () => ( []))) {
902
1765
  dependencySet.add(dependency);
903
1766
  }
904
- for (const dependency of _nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess', _12 => _12.dependencies]), () => ( []))) {
1767
+ for (const dependency of _nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess', _26 => _26.dependencies]), () => ( []))) {
905
1768
  dependencySet.add(dependency);
906
1769
  }
907
1770
  return {
908
1771
  config,
909
- path: _nullishCoalesce(_nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess', _13 => _13.path]), () => ( _optionalChain([loaded, 'optionalAccess', _14 => _14.path]))), () => ( resolvedConfigFile)),
1772
+ path: _nullishCoalesce(_nullishCoalesce(_optionalChain([weappLoaded, 'optionalAccess', _27 => _27.path]), () => ( _optionalChain([loaded, 'optionalAccess', _28 => _28.path]))), () => ( resolvedConfigFile)),
910
1773
  dependencies: Array.from(dependencySet)
911
1774
  };
912
1775
  }
913
- var logBuildAppFinishOnlyShowOnce = false;
914
- function logBuildAppFinish(configService, webServer, options = {}) {
915
- if (logBuildAppFinishOnlyShowOnce) {
916
- return;
917
- }
918
- const { skipMini = false, skipWeb = false } = options;
919
- if (skipMini) {
920
- if (webServer) {
921
- const urls = webServer.resolvedUrls;
922
- const candidates = urls ? [..._nullishCoalesce(urls.local, () => ( [])), ..._nullishCoalesce(urls.network, () => ( []))] : [];
923
- if (candidates.length > 0) {
924
- _chunkOQYESMEYcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
925
- for (const url of candidates) {
926
- _chunkOQYESMEYcjs.logger_default.info(` \u279C ${url}`);
927
- }
928
- } else {
929
- _chunkOQYESMEYcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
1776
+
1777
+ // src/cli/commands/generate.ts
1778
+ function registerGenerateCommand(cli2) {
1779
+ cli2.command("g [filepath]", "generate component").alias("generate").option("-a, --app", "type app").option("-p, --page", "type app").option("-n, --name <name>", "filename").action(async (filepath, options) => {
1780
+ filterDuplicateOptions(options);
1781
+ const config = await loadConfig(resolveConfigFile(options));
1782
+ let type = "component";
1783
+ let fileName = options.name;
1784
+ if (options.app) {
1785
+ type = "app";
1786
+ if (filepath === void 0) {
1787
+ filepath = "";
930
1788
  }
931
- } else {
932
- _chunkOQYESMEYcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
1789
+ fileName = "app";
933
1790
  }
934
- logBuildAppFinishOnlyShowOnce = true;
935
- return;
936
- }
937
- const { command, args } = _nullishCoalesce(resolveCommand(
938
- configService.packageManager.agent,
939
- "run",
940
- ["open"]
941
- ), () => ( {
942
- command: "npm",
943
- args: ["run", "open"]
944
- }));
945
- const devCommand = `${command} ${args.join(" ")}`;
946
- _chunkOQYESMEYcjs.logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
947
- _chunkOQYESMEYcjs.logger_default.info(`\u6267\u884C \`${devCommand}\` \u53EF\u4EE5\u76F4\u63A5\u5728 \`\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\` \u91CC\u6253\u5F00\u5F53\u524D\u5E94\u7528`);
948
- _chunkOQYESMEYcjs.logger_default.info("\u6216\u624B\u52A8\u6253\u5F00\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\uFF0C\u5BFC\u5165\u6839\u76EE\u5F55(`project.config.json` \u6587\u4EF6\u6240\u5728\u7684\u76EE\u5F55)\uFF0C\u5373\u53EF\u9884\u89C8\u6548\u679C");
949
- if (!skipWeb && webServer) {
950
- const urls = webServer.resolvedUrls;
951
- const candidates = urls ? [..._nullishCoalesce(urls.local, () => ( [])), ..._nullishCoalesce(urls.network, () => ( []))] : [];
952
- if (candidates.length > 0) {
953
- _chunkOQYESMEYcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
954
- for (const url of candidates) {
955
- _chunkOQYESMEYcjs.logger_default.info(` \u279C ${url}`);
956
- }
957
- } else {
958
- _chunkOQYESMEYcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
1791
+ if (filepath === void 0) {
1792
+ _chunkT4OVF4GPcjs.logger_default.error("weapp-vite generate <outDir> \u547D\u4EE4\u5FC5\u987B\u4F20\u5165\u8DEF\u5F84\u53C2\u6570 outDir");
1793
+ return;
959
1794
  }
960
- }
961
- logBuildAppFinishOnlyShowOnce = true;
962
- }
963
- function filterDuplicateOptions(options) {
964
- for (const [key, value] of Object.entries(options)) {
965
- if (Array.isArray(value)) {
966
- options[key] = value[value.length - 1];
1795
+ if (options.page) {
1796
+ type = "page";
967
1797
  }
968
- }
969
- }
970
- function resolveConfigFile(options) {
971
- if (typeof options.config === "string") {
972
- return options.config;
973
- }
974
- if (typeof options.c === "string") {
975
- return options.c;
976
- }
977
- }
978
- function convertBase(v) {
979
- if (v === 0) {
980
- return "";
981
- }
982
- return v;
983
- }
984
- async function openIde() {
985
- try {
986
- await _weappidecli.parse.call(void 0, ["open", "-p"]);
987
- } catch (error) {
988
- _chunkOQYESMEYcjs.logger_default.error(error);
989
- }
990
- }
991
- function logRuntimeTarget(targets) {
992
- _chunkOQYESMEYcjs.logger_default.info(`\u76EE\u6807\u5E73\u53F0\uFF1A${targets.label}`);
993
- }
994
- function resolveRuntimeTargets(options) {
995
- const rawPlatform = typeof options.platform === "string" ? options.platform : typeof options.p === "string" ? options.p : void 0;
996
- if (!rawPlatform) {
997
- return {
998
- runMini: true,
999
- runWeb: false,
1000
- mpPlatform: _chunkOQYESMEYcjs.DEFAULT_MP_PLATFORM,
1001
- label: _chunkOQYESMEYcjs.DEFAULT_MP_PLATFORM
1002
- };
1003
- }
1004
- const normalized = _chunkOQYESMEYcjs.normalizeMiniPlatform.call(void 0, rawPlatform);
1005
- if (!normalized) {
1006
- return {
1007
- runMini: true,
1008
- runWeb: false,
1009
- mpPlatform: _chunkOQYESMEYcjs.DEFAULT_MP_PLATFORM,
1010
- label: _chunkOQYESMEYcjs.DEFAULT_MP_PLATFORM
1011
- };
1012
- }
1013
- if (normalized === "h5" || normalized === "web") {
1014
- return {
1015
- runMini: false,
1016
- runWeb: true,
1017
- mpPlatform: void 0,
1018
- label: normalized === "h5" ? "h5" : "web"
1019
- };
1020
- }
1021
- const mpPlatform = _chunkOQYESMEYcjs.resolveMiniPlatform.call(void 0, normalized);
1022
- if (mpPlatform) {
1023
- return {
1024
- runMini: true,
1025
- runWeb: false,
1026
- mpPlatform,
1027
- label: mpPlatform
1028
- };
1029
- }
1030
- _chunkOQYESMEYcjs.logger_default.warn(`\u672A\u8BC6\u522B\u7684\u5E73\u53F0 "${rawPlatform}"\uFF0C\u5DF2\u56DE\u9000\u5230 ${_chunkOQYESMEYcjs.DEFAULT_MP_PLATFORM}`);
1031
- return {
1032
- runMini: true,
1033
- runWeb: false,
1034
- mpPlatform: _chunkOQYESMEYcjs.DEFAULT_MP_PLATFORM,
1035
- label: _chunkOQYESMEYcjs.DEFAULT_MP_PLATFORM
1036
- };
1037
- }
1038
- function createInlineConfig(mpPlatform) {
1039
- if (!mpPlatform) {
1040
- return void 0;
1041
- }
1042
- return {
1043
- weapp: {
1044
- platform: mpPlatform
1045
- }
1046
- };
1047
- }
1048
- cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {
1049
- type: [convertBase]
1050
- }).option("-l, --logLevel <level>", `[string] info | warn | error | silent`).option("--clearScreen", `[boolean] allow/disable clear screen when logging`).option("-d, --debug [feat]", `[string | boolean] show debug logs`).option("-f, --filter <filter>", `[string] filter debug logs`).option("-m, --mode <mode>", `[string] set env mode`);
1051
- cli.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) => {
1052
- filterDuplicateOptions(options);
1053
- const configFile = resolveConfigFile(options);
1054
- const targets = resolveRuntimeTargets(options);
1055
- logRuntimeTarget(targets);
1056
- const inlineConfig = createInlineConfig(targets.mpPlatform);
1057
- const { buildService, configService, webService } = await _chunkWYNGNSLKcjs.createCompilerContext.call(void 0, {
1058
- cwd: root,
1059
- mode: _nullishCoalesce(options.mode, () => ( "development")),
1060
- isDev: true,
1061
- configFile,
1062
- inlineConfig
1798
+ const generateOptions = _optionalChain([config, 'optionalAccess', _29 => _29.config, 'access', _30 => _30.weapp, 'optionalAccess', _31 => _31.generate]);
1799
+ fileName = _nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _32 => _32.filenames, 'optionalAccess', _33 => _33[type]]), () => ( fileName));
1800
+ await generate({
1801
+ outDir: _pathe2.default.join(_nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _34 => _34.dirs, 'optionalAccess', _35 => _35[type]]), () => ( "")), filepath),
1802
+ type,
1803
+ fileName,
1804
+ extensions: _optionalChain([generateOptions, 'optionalAccess', _36 => _36.extensions]),
1805
+ templates: _optionalChain([generateOptions, 'optionalAccess', _37 => _37.templates])
1806
+ });
1063
1807
  });
1064
- if (targets.runMini) {
1065
- await buildService.build(options);
1066
- }
1067
- let webServer;
1068
- if (targets.runWeb) {
1808
+ }
1809
+
1810
+ // src/cli/commands/init.ts
1811
+ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
1812
+
1813
+ function registerInitCommand(cli2) {
1814
+ cli2.command("init").action(async () => {
1069
1815
  try {
1070
- webServer = await _optionalChain([webService, 'optionalAccess', _15 => _15.startDevServer, 'call', _16 => _16()]);
1816
+ await _init.initConfig.call(void 0, {
1817
+ command: "weapp-vite"
1818
+ });
1071
1819
  } catch (error) {
1072
- _chunkOQYESMEYcjs.logger_default.error(error);
1073
- throw error;
1820
+ _chunkT4OVF4GPcjs.logger_default.error(error);
1074
1821
  }
1075
- }
1076
- if (targets.runMini) {
1077
- logBuildAppFinish(configService, webServer, { skipWeb: !targets.runWeb });
1078
- } else if (targets.runWeb) {
1079
- logBuildAppFinish(configService, webServer, { skipMini: true });
1080
- }
1081
- if (options.open && targets.runMini) {
1082
- await openIde();
1083
- }
1084
- });
1085
- cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).option(
1086
- "--sourcemap [output]",
1087
- `[boolean | "inline" | "hidden"] output source maps for build (default: false)`
1088
- ).option(
1089
- "--minify [minifier]",
1090
- `[boolean | "terser" | "esbuild"] enable/disable minification, or specify minifier to use (default: esbuild)`
1091
- ).option(
1092
- "--emptyOutDir",
1093
- `[boolean] force empty outDir when it's outside of root`
1094
- ).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) => {
1095
- filterDuplicateOptions(options);
1096
- const configFile = resolveConfigFile(options);
1097
- const targets = resolveRuntimeTargets(options);
1098
- logRuntimeTarget(targets);
1099
- const inlineConfig = createInlineConfig(targets.mpPlatform);
1100
- const { buildService, configService, webService } = await _chunkWYNGNSLKcjs.createCompilerContext.call(void 0, {
1101
- cwd: root,
1102
- mode: _nullishCoalesce(options.mode, () => ( "production")),
1103
- configFile,
1104
- inlineConfig
1105
1822
  });
1106
- if (targets.runMini) {
1107
- await buildService.build(options);
1108
- }
1109
- const webConfig = configService.weappWebConfig;
1110
- if (targets.runWeb && _optionalChain([webConfig, 'optionalAccess', _17 => _17.enabled])) {
1823
+ }
1824
+
1825
+ // src/cli/commands/npm.ts
1826
+ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
1827
+
1828
+ function registerNpmCommand(cli2) {
1829
+ cli2.command("npm").alias("build:npm").alias("build-npm").action(async () => {
1111
1830
  try {
1112
- await _optionalChain([webService, 'optionalAccess', _18 => _18.build, 'call', _19 => _19()]);
1113
- _chunkOQYESMEYcjs.logger_default.success(`Web \u6784\u5EFA\u5B8C\u6210\uFF0C\u8F93\u51FA\u76EE\u5F55\uFF1A${configService.relativeCwd(webConfig.outDir)}`);
1831
+ await _weappidecli.parse.call(void 0, ["build-npm", "-p"]);
1114
1832
  } catch (error) {
1115
- _chunkOQYESMEYcjs.logger_default.error(error);
1116
- throw error;
1833
+ _chunkT4OVF4GPcjs.logger_default.error(error);
1117
1834
  }
1118
- }
1119
- if (targets.runMini) {
1120
- logBuildAppFinish(configService, void 0, { skipWeb: !targets.runWeb });
1121
- }
1122
- if (options.open && targets.runMini) {
1835
+ });
1836
+ }
1837
+
1838
+ // src/cli/commands/open.ts
1839
+ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
1840
+ function registerOpenCommand(cli2) {
1841
+ cli2.command("open").action(async () => {
1123
1842
  await openIde();
1124
- }
1125
- });
1126
- cli.command("init").action(async () => {
1127
- try {
1128
- await _init.initConfig.call(void 0, {
1129
- command: "weapp-vite"
1843
+ });
1844
+ }
1845
+
1846
+ // src/cli/commands/serve.ts
1847
+ _chunkA5DD7GKXcjs.init_cjs_shims.call(void 0, );
1848
+ function registerServeCommand(cli2) {
1849
+ 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) => {
1850
+ filterDuplicateOptions(options);
1851
+ const configFile = resolveConfigFile(options);
1852
+ const targets = resolveRuntimeTargets(options);
1853
+ logRuntimeTarget(targets);
1854
+ const inlineConfig = createInlineConfig(targets.mpPlatform);
1855
+ const ctx = await _chunkGGLONZVQcjs.createCompilerContext.call(void 0, {
1856
+ cwd: root,
1857
+ mode: _nullishCoalesce(options.mode, () => ( "development")),
1858
+ isDev: true,
1859
+ configFile,
1860
+ inlineConfig
1130
1861
  });
1131
- } catch (error) {
1132
- _chunkOQYESMEYcjs.logger_default.error(error);
1133
- }
1134
- });
1135
- cli.command("open").action(async () => {
1136
- await openIde();
1137
- });
1138
- cli.command("npm").alias("build:npm").alias("build-npm").action(async () => {
1139
- try {
1140
- await _weappidecli.parse.call(void 0, ["build-npm", "-p"]);
1141
- } catch (error) {
1142
- _chunkOQYESMEYcjs.logger_default.error(error);
1143
- }
1144
- });
1145
- cli.command("g [filepath]", "generate component").alias("generate").option("-a, --app", "type app").option("-p, --page", "type app").option("-n, --name <name>", "filename").action(async (filepath, options) => {
1146
- const config = await loadConfig(resolveConfigFile(options));
1147
- let type = "component";
1148
- let fileName = options.name;
1149
- if (options.app) {
1150
- type = "app";
1151
- if (filepath === void 0) {
1152
- filepath = "";
1862
+ const { buildService, configService, webService } = ctx;
1863
+ const enableAnalyze = Boolean(options.analyze && targets.runMini);
1864
+ let analyzeHandle;
1865
+ const triggerAnalyzeUpdate = async () => {
1866
+ if (!analyzeHandle) {
1867
+ return;
1868
+ }
1869
+ const next = await analyzeSubpackages(ctx);
1870
+ await analyzeHandle.update(next);
1871
+ };
1872
+ if (targets.runMini) {
1873
+ const buildResult = await buildService.build(options);
1874
+ if (enableAnalyze) {
1875
+ const initialResult = await analyzeSubpackages(ctx);
1876
+ analyzeHandle = await _asyncNullishCoalesce(await startAnalyzeDashboard(initialResult, { watch: true }), async () => ( void 0));
1877
+ if (analyzeHandle && buildResult && typeof buildResult.on === "function") {
1878
+ const watcher = buildResult;
1879
+ let updating = false;
1880
+ watcher.on("event", (event) => {
1881
+ if (event.code !== "END" || updating) {
1882
+ return;
1883
+ }
1884
+ updating = true;
1885
+ triggerAnalyzeUpdate().finally(() => {
1886
+ updating = false;
1887
+ });
1888
+ });
1889
+ } else if (analyzeHandle) {
1890
+ await triggerAnalyzeUpdate();
1891
+ }
1892
+ }
1153
1893
  }
1154
- fileName = "app";
1155
- }
1156
- if (filepath === void 0) {
1157
- _chunkOQYESMEYcjs.logger_default.error("weapp-vite generate <outDir> \u547D\u4EE4\u5FC5\u987B\u4F20\u5165\u8DEF\u5F84\u53C2\u6570 outDir");
1158
- return;
1159
- }
1160
- if (options.page) {
1161
- type = "page";
1162
- }
1163
- const generateOptions = _optionalChain([config, 'optionalAccess', _20 => _20.config, 'access', _21 => _21.weapp, 'optionalAccess', _22 => _22.generate]);
1164
- fileName = _nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _23 => _23.filenames, 'optionalAccess', _24 => _24[type]]), () => ( fileName));
1165
- await generate({
1166
- outDir: _pathe2.default.join(_nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _25 => _25.dirs, 'optionalAccess', _26 => _26[type]]), () => ( "")), filepath),
1167
- type,
1168
- fileName,
1169
- extensions: _optionalChain([generateOptions, 'optionalAccess', _27 => _27.extensions]),
1170
- templates: _optionalChain([generateOptions, 'optionalAccess', _28 => _28.templates])
1894
+ let webServer;
1895
+ if (targets.runWeb) {
1896
+ try {
1897
+ webServer = await _optionalChain([webService, 'optionalAccess', _38 => _38.startDevServer, 'call', _39 => _39()]);
1898
+ } catch (error) {
1899
+ _chunkT4OVF4GPcjs.logger_default.error(error);
1900
+ throw error;
1901
+ }
1902
+ }
1903
+ if (targets.runMini) {
1904
+ logBuildAppFinish(configService, webServer, { skipWeb: !targets.runWeb });
1905
+ } else if (targets.runWeb) {
1906
+ logBuildAppFinish(configService, webServer, { skipMini: true });
1907
+ }
1908
+ if (options.open && targets.runMini) {
1909
+ await openIde();
1910
+ }
1911
+ if (analyzeHandle) {
1912
+ await analyzeHandle.waitForExit();
1913
+ }
1914
+ });
1915
+ }
1916
+
1917
+ // src/cli.ts
1918
+ var cli = cac("weapp-vite");
1919
+ try {
1920
+ _chunkT4OVF4GPcjs.checkRuntime.call(void 0, {
1921
+ bun: "0.0.0",
1922
+ deno: "0.0.0",
1923
+ node: "20.19.0"
1171
1924
  });
1172
- });
1173
- cli.command("create [outDir]", "create project").option("-t, --template <type>", "template type").action(async (outDir, options) => {
1174
- await _init.createProject.call(void 0, outDir, options.template);
1175
- });
1925
+ } catch (e) {
1926
+ }
1927
+ cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {
1928
+ type: [convertBase]
1929
+ }).option("-l, --logLevel <level>", `[string] info | warn | error | silent`).option("--clearScreen", `[boolean] allow/disable clear screen when logging`).option("-d, --debug [feat]", `[string | boolean] show debug logs`).option("-f, --filter <filter>", `[string] filter debug logs`).option("-m, --mode <mode>", `[string] set env mode`);
1930
+ registerServeCommand(cli);
1931
+ registerBuildCommand(cli);
1932
+ registerAnalyzeCommand(cli);
1933
+ registerInitCommand(cli);
1934
+ registerOpenCommand(cli);
1935
+ registerNpmCommand(cli);
1936
+ registerGenerateCommand(cli);
1937
+ registerCreateCommand(cli);
1176
1938
  cli.help();
1177
- cli.version(_chunkOQYESMEYcjs.VERSION);
1939
+ cli.version(_chunkT4OVF4GPcjs.VERSION);
1178
1940
  cli.parse();