weapp-vite 5.3.0 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -1,10 +1,15 @@
1
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; }
2
2
 
3
+ var _chunkOWCDSB6Fcjs = require('./chunk-OWCDSB6F.cjs');
3
4
 
4
5
 
5
6
 
6
7
 
7
- var _chunkN2SUN4MXcjs = require('./chunk-N2SUN4MX.cjs');
8
+
9
+
10
+
11
+
12
+ var _chunk5GG5TEGRcjs = require('./chunk-5GG5TEGR.cjs');
8
13
 
9
14
 
10
15
  var _chunkOS76JPG2cjs = require('./chunk-OS76JPG2.cjs');
@@ -601,7 +606,7 @@ var CAC = class extends _events.EventEmitter {
601
606
  };
602
607
  var cac = (name = "") => new CAC(name);
603
608
 
604
- // ../../node_modules/.pnpm/package-manager-detector@1.4.0/node_modules/package-manager-detector/dist/commands.mjs
609
+ // ../../node_modules/.pnpm/package-manager-detector@1.5.0/node_modules/package-manager-detector/dist/commands.mjs
605
610
  _chunkOS76JPG2cjs.init_cjs_shims.call(void 0, );
606
611
  function dashDashArg(agent, agentCommand) {
607
612
  return (args) => {
@@ -626,6 +631,7 @@ var npm = {
626
631
  "add": ["npm", "i", 0],
627
632
  "upgrade": ["npm", "update", 0],
628
633
  "upgrade-interactive": null,
634
+ "dedupe": ["npm", "dedupe", 0],
629
635
  "execute": ["npx", 0],
630
636
  "execute-local": ["npx", 0],
631
637
  "uninstall": ["npm", "uninstall", 0],
@@ -640,6 +646,7 @@ var yarn = {
640
646
  "add": ["yarn", "add", 0],
641
647
  "upgrade": ["yarn", "upgrade", 0],
642
648
  "upgrade-interactive": ["yarn", "upgrade-interactive", 0],
649
+ "dedupe": null,
643
650
  "execute": ["npx", 0],
644
651
  "execute-local": dashDashArg("yarn", "exec"),
645
652
  "uninstall": ["yarn", "remove", 0],
@@ -650,6 +657,7 @@ var yarnBerry = {
650
657
  "frozen": ["yarn", "install", "--immutable", 0],
651
658
  "upgrade": ["yarn", "up", 0],
652
659
  "upgrade-interactive": ["yarn", "up", "-i", 0],
660
+ "dedupe": ["yarn", "dedupe", 0],
653
661
  "execute": ["yarn", "dlx", 0],
654
662
  "execute-local": ["yarn", "exec", 0],
655
663
  // Yarn 2+ removed 'global', see https://github.com/yarnpkg/berry/issues/821
@@ -665,6 +673,7 @@ var pnpm = {
665
673
  "add": ["pnpm", "add", 0],
666
674
  "upgrade": ["pnpm", "update", 0],
667
675
  "upgrade-interactive": ["pnpm", "update", "-i", 0],
676
+ "dedupe": ["pnpm", "dedupe", 0],
668
677
  "execute": ["pnpm", "dlx", 0],
669
678
  "execute-local": ["pnpm", "exec", 0],
670
679
  "uninstall": ["pnpm", "remove", 0],
@@ -678,7 +687,8 @@ var bun = {
678
687
  "global": ["bun", "add", "-g", 0],
679
688
  "add": ["bun", "add", 0],
680
689
  "upgrade": ["bun", "update", 0],
681
- "upgrade-interactive": ["bun", "update", 0],
690
+ "upgrade-interactive": ["bun", "update", "-i", 0],
691
+ "dedupe": null,
682
692
  "execute": ["bun", "x", 0],
683
693
  "execute-local": ["bun", "x", 0],
684
694
  "uninstall": ["bun", "remove", 0],
@@ -693,6 +703,7 @@ var deno = {
693
703
  "add": ["deno", "add", 0],
694
704
  "upgrade": ["deno", "outdated", "--update", 0],
695
705
  "upgrade-interactive": ["deno", "outdated", "--update", 0],
706
+ "dedupe": null,
696
707
  "execute": denoExecute(),
697
708
  "execute-local": ["deno", "task", "--eval", 0],
698
709
  "uninstall": ["deno", "remove", 0],
@@ -806,7 +817,7 @@ async function generate(options) {
806
817
  for (const { code, fileName: fileName2 } of files) {
807
818
  if (code !== void 0) {
808
819
  await _fsextra2.default.outputFile(_pathe2.default.resolve(basepath, fileName2), code, "utf8");
809
- _chunkN2SUN4MXcjs.logger_default.success(`${composePath(outDir, fileName2)} \u521B\u5EFA\u6210\u529F\uFF01`);
820
+ _chunk5GG5TEGRcjs.logger_default.success(`${composePath(outDir, fileName2)} \u521B\u5EFA\u6210\u529F\uFF01`);
810
821
  }
811
822
  }
812
823
  }
@@ -844,7 +855,7 @@ async function readTemplateFile(templatePath, context) {
844
855
  // src/cli.ts
845
856
  var cli = cac("weapp-vite");
846
857
  try {
847
- _chunkN2SUN4MXcjs.checkRuntime.call(void 0, {
858
+ _chunk5GG5TEGRcjs.checkRuntime.call(void 0, {
848
859
  bun: "0.0.0",
849
860
  deno: "0.0.0",
850
861
  node: "20.19.0"
@@ -862,7 +873,7 @@ async function loadConfig(configFile) {
862
873
  mode: "development"
863
874
  };
864
875
  const loaded = await _vite.loadConfigFromFile.call(void 0, configEnv, resolvedConfigFile, cwd);
865
- const weappConfigFilePath = await _chunkN2SUN4MXcjs.resolveWeappConfigFile.call(void 0, {
876
+ const weappConfigFilePath = await _chunk5GG5TEGRcjs.resolveWeappConfigFile.call(void 0, {
866
877
  root: cwd,
867
878
  specified: resolvedConfigFile
868
879
  });
@@ -900,22 +911,54 @@ async function loadConfig(configFile) {
900
911
  };
901
912
  }
902
913
  var logBuildAppFinishOnlyShowOnce = false;
903
- function logBuildAppFinish(configService) {
904
- if (!logBuildAppFinishOnlyShowOnce) {
905
- const { command, args } = _nullishCoalesce(resolveCommand(
906
- configService.packageManager.agent,
907
- "run",
908
- ["open"]
909
- ), () => ( {
910
- command: "npm",
911
- args: ["run", "open"]
912
- }));
913
- const devCommand = `${command} ${args.join(" ")}`;
914
- _chunkN2SUN4MXcjs.logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
915
- _chunkN2SUN4MXcjs.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`);
916
- _chunkN2SUN4MXcjs.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");
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
+ _chunk5GG5TEGRcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
925
+ for (const url of candidates) {
926
+ _chunk5GG5TEGRcjs.logger_default.info(` \u279C ${url}`);
927
+ }
928
+ } else {
929
+ _chunk5GG5TEGRcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
930
+ }
931
+ } else {
932
+ _chunk5GG5TEGRcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
933
+ }
917
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
+ _chunk5GG5TEGRcjs.logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
947
+ _chunk5GG5TEGRcjs.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
+ _chunk5GG5TEGRcjs.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
+ _chunk5GG5TEGRcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
954
+ for (const url of candidates) {
955
+ _chunk5GG5TEGRcjs.logger_default.info(` \u279C ${url}`);
956
+ }
957
+ } else {
958
+ _chunk5GG5TEGRcjs.logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
959
+ }
918
960
  }
961
+ logBuildAppFinishOnlyShowOnce = true;
919
962
  }
920
963
  function filterDuplicateOptions(options) {
921
964
  for (const [key, value] of Object.entries(options)) {
@@ -942,28 +985,104 @@ async function openIde() {
942
985
  try {
943
986
  await _weappidecli.parse.call(void 0, ["open", "-p"]);
944
987
  } catch (error) {
945
- _chunkN2SUN4MXcjs.logger_default.error(error);
988
+ _chunk5GG5TEGRcjs.logger_default.error(error);
989
+ }
990
+ }
991
+ function logRuntimeTarget(targets) {
992
+ _chunk5GG5TEGRcjs.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: _chunk5GG5TEGRcjs.DEFAULT_MP_PLATFORM,
1001
+ label: _chunk5GG5TEGRcjs.DEFAULT_MP_PLATFORM
1002
+ };
1003
+ }
1004
+ const normalized = _chunk5GG5TEGRcjs.normalizeMiniPlatform.call(void 0, rawPlatform);
1005
+ if (!normalized) {
1006
+ return {
1007
+ runMini: true,
1008
+ runWeb: false,
1009
+ mpPlatform: _chunk5GG5TEGRcjs.DEFAULT_MP_PLATFORM,
1010
+ label: _chunk5GG5TEGRcjs.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 = _chunk5GG5TEGRcjs.resolveMiniPlatform.call(void 0, normalized);
1022
+ if (mpPlatform) {
1023
+ return {
1024
+ runMini: true,
1025
+ runWeb: false,
1026
+ mpPlatform,
1027
+ label: mpPlatform
1028
+ };
1029
+ }
1030
+ _chunk5GG5TEGRcjs.logger_default.warn(`\u672A\u8BC6\u522B\u7684\u5E73\u53F0 "${rawPlatform}"\uFF0C\u5DF2\u56DE\u9000\u5230 ${_chunk5GG5TEGRcjs.DEFAULT_MP_PLATFORM}`);
1031
+ return {
1032
+ runMini: true,
1033
+ runWeb: false,
1034
+ mpPlatform: _chunk5GG5TEGRcjs.DEFAULT_MP_PLATFORM,
1035
+ label: _chunk5GG5TEGRcjs.DEFAULT_MP_PLATFORM
1036
+ };
1037
+ }
1038
+ function createInlineConfig(mpPlatform) {
1039
+ if (!mpPlatform) {
1040
+ return void 0;
946
1041
  }
1042
+ return {
1043
+ weapp: {
1044
+ platform: mpPlatform
1045
+ }
1046
+ };
947
1047
  }
948
1048
  cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {
949
1049
  type: [convertBase]
950
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`);
951
- cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).action(async (root, options) => {
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) => {
952
1052
  filterDuplicateOptions(options);
953
1053
  const configFile = resolveConfigFile(options);
954
- const { buildService, configService } = await _chunkN2SUN4MXcjs.createCompilerContext.call(void 0, {
1054
+ const targets = resolveRuntimeTargets(options);
1055
+ logRuntimeTarget(targets);
1056
+ const inlineConfig = createInlineConfig(targets.mpPlatform);
1057
+ const { buildService, configService, webService } = await _chunkOWCDSB6Fcjs.createCompilerContext.call(void 0, {
955
1058
  cwd: root,
956
1059
  mode: _nullishCoalesce(options.mode, () => ( "development")),
957
1060
  isDev: true,
958
- configFile
1061
+ configFile,
1062
+ inlineConfig
959
1063
  });
960
- await buildService.build(options);
961
- logBuildAppFinish(configService);
962
- if (options.open) {
1064
+ if (targets.runMini) {
1065
+ await buildService.build(options);
1066
+ }
1067
+ let webServer;
1068
+ if (targets.runWeb) {
1069
+ try {
1070
+ webServer = await _optionalChain([webService, 'optionalAccess', _15 => _15.startDevServer, 'call', _16 => _16()]);
1071
+ } catch (error) {
1072
+ _chunk5GG5TEGRcjs.logger_default.error(error);
1073
+ throw error;
1074
+ }
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) {
963
1082
  await openIde();
964
1083
  }
965
1084
  });
966
- cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option(
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(
967
1086
  "--sourcemap [output]",
968
1087
  `[boolean | "inline" | "hidden"] output source maps for build (default: false)`
969
1088
  ).option(
@@ -975,14 +1094,32 @@ cli.command("build [root]", "build for production").option("--target <target>",
975
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) => {
976
1095
  filterDuplicateOptions(options);
977
1096
  const configFile = resolveConfigFile(options);
978
- const { buildService, configService } = await _chunkN2SUN4MXcjs.createCompilerContext.call(void 0, {
1097
+ const targets = resolveRuntimeTargets(options);
1098
+ logRuntimeTarget(targets);
1099
+ const inlineConfig = createInlineConfig(targets.mpPlatform);
1100
+ const { buildService, configService, webService } = await _chunkOWCDSB6Fcjs.createCompilerContext.call(void 0, {
979
1101
  cwd: root,
980
1102
  mode: _nullishCoalesce(options.mode, () => ( "production")),
981
- configFile
1103
+ configFile,
1104
+ inlineConfig
982
1105
  });
983
- await buildService.build(options);
984
- logBuildAppFinish(configService);
985
- if (options.open) {
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])) {
1111
+ try {
1112
+ await _optionalChain([webService, 'optionalAccess', _18 => _18.build, 'call', _19 => _19()]);
1113
+ _chunk5GG5TEGRcjs.logger_default.success(`Web \u6784\u5EFA\u5B8C\u6210\uFF0C\u8F93\u51FA\u76EE\u5F55\uFF1A${configService.relativeCwd(webConfig.outDir)}`);
1114
+ } catch (error) {
1115
+ _chunk5GG5TEGRcjs.logger_default.error(error);
1116
+ throw error;
1117
+ }
1118
+ }
1119
+ if (targets.runMini) {
1120
+ logBuildAppFinish(configService, void 0, { skipWeb: !targets.runWeb });
1121
+ }
1122
+ if (options.open && targets.runMini) {
986
1123
  await openIde();
987
1124
  }
988
1125
  });
@@ -992,7 +1129,7 @@ cli.command("init").action(async () => {
992
1129
  command: "weapp-vite"
993
1130
  });
994
1131
  } catch (error) {
995
- _chunkN2SUN4MXcjs.logger_default.error(error);
1132
+ _chunk5GG5TEGRcjs.logger_default.error(error);
996
1133
  }
997
1134
  });
998
1135
  cli.command("open").action(async () => {
@@ -1002,7 +1139,7 @@ cli.command("npm").alias("build:npm").alias("build-npm").action(async () => {
1002
1139
  try {
1003
1140
  await _weappidecli.parse.call(void 0, ["build-npm", "-p"]);
1004
1141
  } catch (error) {
1005
- _chunkN2SUN4MXcjs.logger_default.error(error);
1142
+ _chunk5GG5TEGRcjs.logger_default.error(error);
1006
1143
  }
1007
1144
  });
1008
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) => {
@@ -1017,25 +1154,25 @@ cli.command("g [filepath]", "generate component").alias("generate").option("-a,
1017
1154
  fileName = "app";
1018
1155
  }
1019
1156
  if (filepath === void 0) {
1020
- _chunkN2SUN4MXcjs.logger_default.error("weapp-vite generate <outDir> \u547D\u4EE4\u5FC5\u987B\u4F20\u5165\u8DEF\u5F84\u53C2\u6570 outDir");
1157
+ _chunk5GG5TEGRcjs.logger_default.error("weapp-vite generate <outDir> \u547D\u4EE4\u5FC5\u987B\u4F20\u5165\u8DEF\u5F84\u53C2\u6570 outDir");
1021
1158
  return;
1022
1159
  }
1023
1160
  if (options.page) {
1024
1161
  type = "page";
1025
1162
  }
1026
- const generateOptions = _optionalChain([config, 'optionalAccess', _15 => _15.config, 'access', _16 => _16.weapp, 'optionalAccess', _17 => _17.generate]);
1027
- fileName = _nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _18 => _18.filenames, 'optionalAccess', _19 => _19[type]]), () => ( fileName));
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));
1028
1165
  await generate({
1029
- outDir: _pathe2.default.join(_nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _20 => _20.dirs, 'optionalAccess', _21 => _21[type]]), () => ( "")), filepath),
1166
+ outDir: _pathe2.default.join(_nullishCoalesce(_optionalChain([generateOptions, 'optionalAccess', _25 => _25.dirs, 'optionalAccess', _26 => _26[type]]), () => ( "")), filepath),
1030
1167
  type,
1031
1168
  fileName,
1032
- extensions: _optionalChain([generateOptions, 'optionalAccess', _22 => _22.extensions]),
1033
- templates: _optionalChain([generateOptions, 'optionalAccess', _23 => _23.templates])
1169
+ extensions: _optionalChain([generateOptions, 'optionalAccess', _27 => _27.extensions]),
1170
+ templates: _optionalChain([generateOptions, 'optionalAccess', _28 => _28.templates])
1034
1171
  });
1035
1172
  });
1036
1173
  cli.command("create [outDir]", "create project").option("-t, --template <type>", "template type").action(async (outDir, options) => {
1037
1174
  await _init.createProject.call(void 0, outDir, options.template);
1038
1175
  });
1039
1176
  cli.help();
1040
- cli.version(_chunkN2SUN4MXcjs.VERSION);
1177
+ cli.version(_chunk5GG5TEGRcjs.VERSION);
1041
1178
  cli.parse();
package/dist/cli.mjs CHANGED
@@ -1,10 +1,15 @@
1
1
  import {
2
+ createCompilerContext
3
+ } from "./chunk-QCLEMTCV.mjs";
4
+ import {
5
+ DEFAULT_MP_PLATFORM,
2
6
  VERSION,
3
7
  checkRuntime,
4
- createCompilerContext,
5
8
  logger_default,
9
+ normalizeMiniPlatform,
10
+ resolveMiniPlatform,
6
11
  resolveWeappConfigFile
7
- } from "./chunk-JGSE2EOU.mjs";
12
+ } from "./chunk-T4MUKDMP.mjs";
8
13
  import {
9
14
  init_esm_shims
10
15
  } from "./chunk-7MAZ2JUY.mjs";
@@ -601,7 +606,7 @@ var CAC = class extends EventEmitter {
601
606
  };
602
607
  var cac = (name = "") => new CAC(name);
603
608
 
604
- // ../../node_modules/.pnpm/package-manager-detector@1.4.0/node_modules/package-manager-detector/dist/commands.mjs
609
+ // ../../node_modules/.pnpm/package-manager-detector@1.5.0/node_modules/package-manager-detector/dist/commands.mjs
605
610
  init_esm_shims();
606
611
  function dashDashArg(agent, agentCommand) {
607
612
  return (args) => {
@@ -626,6 +631,7 @@ var npm = {
626
631
  "add": ["npm", "i", 0],
627
632
  "upgrade": ["npm", "update", 0],
628
633
  "upgrade-interactive": null,
634
+ "dedupe": ["npm", "dedupe", 0],
629
635
  "execute": ["npx", 0],
630
636
  "execute-local": ["npx", 0],
631
637
  "uninstall": ["npm", "uninstall", 0],
@@ -640,6 +646,7 @@ var yarn = {
640
646
  "add": ["yarn", "add", 0],
641
647
  "upgrade": ["yarn", "upgrade", 0],
642
648
  "upgrade-interactive": ["yarn", "upgrade-interactive", 0],
649
+ "dedupe": null,
643
650
  "execute": ["npx", 0],
644
651
  "execute-local": dashDashArg("yarn", "exec"),
645
652
  "uninstall": ["yarn", "remove", 0],
@@ -650,6 +657,7 @@ var yarnBerry = {
650
657
  "frozen": ["yarn", "install", "--immutable", 0],
651
658
  "upgrade": ["yarn", "up", 0],
652
659
  "upgrade-interactive": ["yarn", "up", "-i", 0],
660
+ "dedupe": ["yarn", "dedupe", 0],
653
661
  "execute": ["yarn", "dlx", 0],
654
662
  "execute-local": ["yarn", "exec", 0],
655
663
  // Yarn 2+ removed 'global', see https://github.com/yarnpkg/berry/issues/821
@@ -665,6 +673,7 @@ var pnpm = {
665
673
  "add": ["pnpm", "add", 0],
666
674
  "upgrade": ["pnpm", "update", 0],
667
675
  "upgrade-interactive": ["pnpm", "update", "-i", 0],
676
+ "dedupe": ["pnpm", "dedupe", 0],
668
677
  "execute": ["pnpm", "dlx", 0],
669
678
  "execute-local": ["pnpm", "exec", 0],
670
679
  "uninstall": ["pnpm", "remove", 0],
@@ -678,7 +687,8 @@ var bun = {
678
687
  "global": ["bun", "add", "-g", 0],
679
688
  "add": ["bun", "add", 0],
680
689
  "upgrade": ["bun", "update", 0],
681
- "upgrade-interactive": ["bun", "update", 0],
690
+ "upgrade-interactive": ["bun", "update", "-i", 0],
691
+ "dedupe": null,
682
692
  "execute": ["bun", "x", 0],
683
693
  "execute-local": ["bun", "x", 0],
684
694
  "uninstall": ["bun", "remove", 0],
@@ -693,6 +703,7 @@ var deno = {
693
703
  "add": ["deno", "add", 0],
694
704
  "upgrade": ["deno", "outdated", "--update", 0],
695
705
  "upgrade-interactive": ["deno", "outdated", "--update", 0],
706
+ "dedupe": null,
696
707
  "execute": denoExecute(),
697
708
  "execute-local": ["deno", "task", "--eval", 0],
698
709
  "uninstall": ["deno", "remove", 0],
@@ -900,22 +911,54 @@ async function loadConfig(configFile) {
900
911
  };
901
912
  }
902
913
  var logBuildAppFinishOnlyShowOnce = false;
903
- function logBuildAppFinish(configService) {
904
- if (!logBuildAppFinishOnlyShowOnce) {
905
- const { command, args } = resolveCommand(
906
- configService.packageManager.agent,
907
- "run",
908
- ["open"]
909
- ) ?? {
910
- command: "npm",
911
- args: ["run", "open"]
912
- };
913
- const devCommand = `${command} ${args.join(" ")}`;
914
- logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
915
- 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`);
916
- 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");
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 ? [...urls.local ?? [], ...urls.network ?? []] : [];
923
+ if (candidates.length > 0) {
924
+ logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
925
+ for (const url of candidates) {
926
+ logger_default.info(` \u279C ${url}`);
927
+ }
928
+ } else {
929
+ logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
930
+ }
931
+ } else {
932
+ logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
933
+ }
917
934
  logBuildAppFinishOnlyShowOnce = true;
935
+ return;
936
+ }
937
+ const { command, args } = 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
+ logger_default.success("\u5E94\u7528\u6784\u5EFA\u5B8C\u6210\uFF01\u9884\u89C8\u65B9\u5F0F ( `2` \u79CD\u9009\u5176\u4E00\u5373\u53EF)\uFF1A");
947
+ 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
+ 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 ? [...urls.local ?? [], ...urls.network ?? []] : [];
952
+ if (candidates.length > 0) {
953
+ logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8\uFF0C\u6D4F\u89C8\u5668\u8BBF\u95EE\uFF1A");
954
+ for (const url of candidates) {
955
+ logger_default.info(` \u279C ${url}`);
956
+ }
957
+ } else {
958
+ logger_default.success("Web \u8FD0\u884C\u65F6\u5DF2\u542F\u52A8");
959
+ }
918
960
  }
961
+ logBuildAppFinishOnlyShowOnce = true;
919
962
  }
920
963
  function filterDuplicateOptions(options) {
921
964
  for (const [key, value] of Object.entries(options)) {
@@ -945,25 +988,101 @@ async function openIde() {
945
988
  logger_default.error(error);
946
989
  }
947
990
  }
991
+ function logRuntimeTarget(targets) {
992
+ 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: DEFAULT_MP_PLATFORM,
1001
+ label: DEFAULT_MP_PLATFORM
1002
+ };
1003
+ }
1004
+ const normalized = normalizeMiniPlatform(rawPlatform);
1005
+ if (!normalized) {
1006
+ return {
1007
+ runMini: true,
1008
+ runWeb: false,
1009
+ mpPlatform: DEFAULT_MP_PLATFORM,
1010
+ label: 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 = resolveMiniPlatform(normalized);
1022
+ if (mpPlatform) {
1023
+ return {
1024
+ runMini: true,
1025
+ runWeb: false,
1026
+ mpPlatform,
1027
+ label: mpPlatform
1028
+ };
1029
+ }
1030
+ logger_default.warn(`\u672A\u8BC6\u522B\u7684\u5E73\u53F0 "${rawPlatform}"\uFF0C\u5DF2\u56DE\u9000\u5230 ${DEFAULT_MP_PLATFORM}`);
1031
+ return {
1032
+ runMini: true,
1033
+ runWeb: false,
1034
+ mpPlatform: DEFAULT_MP_PLATFORM,
1035
+ label: 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
+ }
948
1048
  cli.option("-c, --config <file>", `[string] use specified config file`).option("--base <path>", `[string] public base path (default: /)`, {
949
1049
  type: [convertBase]
950
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`);
951
- cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).action(async (root, options) => {
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) => {
952
1052
  filterDuplicateOptions(options);
953
1053
  const configFile = resolveConfigFile(options);
954
- const { buildService, configService } = await createCompilerContext({
1054
+ const targets = resolveRuntimeTargets(options);
1055
+ logRuntimeTarget(targets);
1056
+ const inlineConfig = createInlineConfig(targets.mpPlatform);
1057
+ const { buildService, configService, webService } = await createCompilerContext({
955
1058
  cwd: root,
956
1059
  mode: options.mode ?? "development",
957
1060
  isDev: true,
958
- configFile
1061
+ configFile,
1062
+ inlineConfig
959
1063
  });
960
- await buildService.build(options);
961
- logBuildAppFinish(configService);
962
- if (options.open) {
1064
+ if (targets.runMini) {
1065
+ await buildService.build(options);
1066
+ }
1067
+ let webServer;
1068
+ if (targets.runWeb) {
1069
+ try {
1070
+ webServer = await webService?.startDevServer();
1071
+ } catch (error) {
1072
+ logger_default.error(error);
1073
+ throw error;
1074
+ }
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) {
963
1082
  await openIde();
964
1083
  }
965
1084
  });
966
- cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option(
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(
967
1086
  "--sourcemap [output]",
968
1087
  `[boolean | "inline" | "hidden"] output source maps for build (default: false)`
969
1088
  ).option(
@@ -975,14 +1094,32 @@ cli.command("build [root]", "build for production").option("--target <target>",
975
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) => {
976
1095
  filterDuplicateOptions(options);
977
1096
  const configFile = resolveConfigFile(options);
978
- const { buildService, configService } = await createCompilerContext({
1097
+ const targets = resolveRuntimeTargets(options);
1098
+ logRuntimeTarget(targets);
1099
+ const inlineConfig = createInlineConfig(targets.mpPlatform);
1100
+ const { buildService, configService, webService } = await createCompilerContext({
979
1101
  cwd: root,
980
1102
  mode: options.mode ?? "production",
981
- configFile
1103
+ configFile,
1104
+ inlineConfig
982
1105
  });
983
- await buildService.build(options);
984
- logBuildAppFinish(configService);
985
- if (options.open) {
1106
+ if (targets.runMini) {
1107
+ await buildService.build(options);
1108
+ }
1109
+ const webConfig = configService.weappWebConfig;
1110
+ if (targets.runWeb && webConfig?.enabled) {
1111
+ try {
1112
+ await webService?.build();
1113
+ logger_default.success(`Web \u6784\u5EFA\u5B8C\u6210\uFF0C\u8F93\u51FA\u76EE\u5F55\uFF1A${configService.relativeCwd(webConfig.outDir)}`);
1114
+ } catch (error) {
1115
+ logger_default.error(error);
1116
+ throw error;
1117
+ }
1118
+ }
1119
+ if (targets.runMini) {
1120
+ logBuildAppFinish(configService, void 0, { skipWeb: !targets.runWeb });
1121
+ }
1122
+ if (options.open && targets.runMini) {
986
1123
  await openIde();
987
1124
  }
988
1125
  });