weapp-vite 6.16.42 → 6.16.43

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.
@@ -1,4 +1,4 @@
1
- import { g as getRouteRuntimeGlobalKeys, n as getCompilerContext } from "./createContext-BjCo8Rn4.mjs";
1
+ import { g as getRouteRuntimeGlobalKeys, n as getCompilerContext } from "./createContext-CRpsNCP2.mjs";
2
2
  //#region src/auto-routes.ts
3
3
  const ROUTE_RUNTIME_OVERRIDE_KEY = Symbol.for("weapp-vite.route-runtime");
4
4
  function createGetter(resolver) {
package/dist/cli.mjs CHANGED
@@ -1,9 +1,10 @@
1
- import { C as createCjsConfigLoadError, E as isPathInside, S as parseCommentJson, T as shouldPassPlatformArgToIdeOpen, _ as createBuildScopeConfigFromCli, a as formatBytes, b as getProjectConfigFileName, d as syncProjectSupportFiles, f as syncManagedTsconfigBootstrapFiles, h as resolveHmrProfileJsonPath, m as SHARED_CHUNK_VIRTUAL_PREFIX, p as createSharedBuildConfig, t as createCompilerContext, u as resolveWeappViteTarget, v as resolveWeappConfigFile, w as getDefaultIdeProjectRoot, x as loadViteConfigFile, y as checkRuntime } from "./createContext-BjCo8Rn4.mjs";
1
+ import { C as createCjsConfigLoadError, E as isPathInside, S as parseCommentJson, T as shouldPassPlatformArgToIdeOpen, _ as createBuildScopeConfigFromCli, a as formatBytes, b as getProjectConfigFileName, d as syncProjectSupportFiles, f as syncManagedTsconfigBootstrapFiles, h as resolveHmrProfileJsonPath, m as SHARED_CHUNK_VIRTUAL_PREFIX, p as createSharedBuildConfig, t as createCompilerContext, u as resolveWeappViteTarget, v as resolveWeappConfigFile, w as getDefaultIdeProjectRoot, x as loadViteConfigFile, y as checkRuntime } from "./createContext-CRpsNCP2.mjs";
2
2
  import { r as logger_default, t as colors } from "./logger-mt4mSTqV.mjs";
3
- import { h as VERSION } from "./file-Cm-gX3xL.mjs";
3
+ import { h as VERSION } from "./file-Wkzc9gMS.mjs";
4
4
  import { o as resolveWeappMcpConfig, s as startWeappViteMcpServer } from "./mcp-qmDOTH07.mjs";
5
5
  import { createRequire } from "node:module";
6
6
  import path, { posix } from "pathe";
7
+ import path$1 from "node:path";
7
8
  import { defu } from "@weapp-core/shared";
8
9
  import { fs } from "@weapp-core/shared/fs";
9
10
  import fs$1 from "node:fs";
@@ -14,7 +15,7 @@ import os from "node:os";
14
15
  import { execFile, spawn } from "node:child_process";
15
16
  import { Buffer } from "node:buffer";
16
17
  import { cac } from "cac";
17
- import { RETRY_CANCEL_KEYS, RETRY_CONFIRM_KEYS, bootstrapWechatDevtoolsSettings, buildWechatIdeNpm, clearWechatIdeCache, clearWechatIdeCacheByAutomator, closeSharedMiniProgram, closeWechatIdeProject, compileWechatIdeByAutomator, connectOpenedAutomator, createSharedInputSession, createWechatIdeLoginRequiredExitError, dispatchWechatCliCommand, formatAutomatorLoginError, getConfig, getWechatIdeTestAccounts, getWechatIdeTicket, getWechatIdeToolInfo, isAutomatorLoginError, isWeappIdeTopLevelCommand, isWechatIdeEngineBuildEndpointMissingError, isWechatIdeLoginRequiredError, isWechatIdeLoginRequiredExitError, launchAutomator, openWechatIdeProjectByHttp, parse, promptRetryKeypress, promptWechatIdeLoginRetry, quitWechatIde, refreshWechatIdeTicket, resetWechatIdeFileUtilsByHttp, runRetryableCommand, runWechatIdeEngineBuild, runWithSuspendedSharedInput, setWechatIdeTicket, startForwardConsole, takeScreenshot } from "weapp-ide-cli";
18
+ import { RETRY_CANCEL_KEYS, RETRY_CONFIRM_KEYS, bootstrapWechatDevtoolsSettings, buildWechatIdeNpm, clearWechatIdeCache, clearWechatIdeCacheByAutomator, closeSharedMiniProgram, closeWechatIdeProject, compileWechatIdeByAutomator, connectOpenedAutomator, createSharedInputSession, createWechatIdeLoginRequiredExitError, dispatchWechatCliCommand, formatAutomatorLoginError, getConfig, getWechatIdeTestAccounts, getWechatIdeTicket, getWechatIdeToolInfo, isAutomatorLoginError, isWeappIdeTopLevelCommand, isWechatIdeEngineBuildEndpointMissingError, isWechatIdeLoginRequiredError, isWechatIdeLoginRequiredExitError, launchAutomator, openWechatIdeProjectByHttp, parse, promptRetryKeypress, promptWechatIdeLoginRetry, quitWechatIde, refreshWechatIdeTicket, resetWechatIdeFileUtilsByHttp, resolveProjectAutomatorPort, runRetryableCommand, runWechatIdeEngineBuild, runWithSuspendedSharedInput, setWechatIdeTicket, startForwardConsole, takeScreenshot } from "weapp-ide-cli";
18
19
  import { promisify } from "node:util";
19
20
  import { brotliCompressSync, gzipSync } from "node:zlib";
20
21
  import { resolveCommand } from "package-manager-detector/commands";
@@ -66,12 +67,15 @@ function readArgOption(argv, ...names) {
66
67
  if (typeof next === "string" && !next.startsWith("-")) return next;
67
68
  }
68
69
  }
69
- async function tryExecuteWechatIdeCliCommandByAutomator(argv, projectPath) {
70
+ async function tryExecuteWechatIdeCliCommandByAutomator(argv, projectPath, options = {}) {
70
71
  if (!projectPath) return false;
71
72
  const command = argv[0];
72
73
  if (!command) return false;
73
74
  if (command === "compile") {
74
- await compileWechatIdeByAutomator({ projectPath });
75
+ await compileWechatIdeByAutomator({
76
+ preserveProjectRoot: options.preserveProjectRoot,
77
+ projectPath
78
+ });
75
79
  return true;
76
80
  }
77
81
  if (command === "cache") {
@@ -79,6 +83,7 @@ async function tryExecuteWechatIdeCliCommandByAutomator(argv, projectPath) {
79
83
  if (cleanType !== "compile" && cleanType !== "all") return false;
80
84
  await clearWechatIdeCacheByAutomator({
81
85
  clean: cleanType,
86
+ preserveProjectRoot: options.preserveProjectRoot,
82
87
  projectPath
83
88
  });
84
89
  return true;
@@ -132,15 +137,15 @@ async function tryExecuteWechatIdeCliCommandByHelper(argv) {
132
137
  * @description 统一执行 weapp-ide-cli 命令,并在登录失效时复用同一套重试交互。
133
138
  */
134
139
  async function executeWechatIdeCliCommand(argv, options = {}) {
135
- const { automatorMode = "prefer", cancelLevel = "warn", engineBuildFallbackToCli = false, httpMode = "prefer", promptOpenIdeLogin = true, onNonLoginError, onRetry, projectPath } = options;
140
+ const { automatorMode = "prefer", cancelLevel = "warn", engineBuildFallbackToCli = false, httpMode = "prefer", promptOpenIdeLogin = true, onNonLoginError, onRetry, projectPath, preserveProjectRoot } = options;
136
141
  await runWithSuspendedSharedInput(async () => {
137
142
  if (httpMode !== "skip") try {
138
143
  if (await tryExecuteWechatIdeCliCommandByHttp(argv, projectPath, engineBuildFallbackToCli)) return;
139
144
  } catch (error) {
140
145
  if (httpMode === "require" || isWechatIdeEngineBuildEndpointMissingError(error)) throw error;
141
146
  }
142
- try {
143
- if (await tryExecuteWechatIdeCliCommandByAutomator(argv, projectPath)) return;
147
+ if (automatorMode !== "skip") try {
148
+ if (await tryExecuteWechatIdeCliCommandByAutomator(argv, projectPath, { preserveProjectRoot })) return;
144
149
  } catch (error) {
145
150
  if (automatorMode === "require") throw error;
146
151
  }
@@ -272,10 +277,17 @@ async function connectOpenedProject(projectPath) {
272
277
  /**
273
278
  * @description 若当前项目已在微信开发者工具中打开且自动化可连通,则直接复用现有会话,避免重复拉起 IDE。
274
279
  */
275
- async function tryReuseOpenedWechatIde(projectPath, closeIde) {
280
+ async function tryReuseOpenedWechatIde(projectPath, closeIde, options = {}) {
276
281
  const miniProgram = await connectOpenedProject(projectPath);
277
282
  if (!miniProgram) return null;
278
283
  disconnectMiniProgram(miniProgram);
284
+ if (options.promptReopen === false) {
285
+ logger_default.info("目标项目已在微信开发者工具中打开,已跳过重复打开。");
286
+ return {
287
+ reopened: false,
288
+ reused: true
289
+ };
290
+ }
279
291
  logger_default.info(formatReuseOpenedWechatIdePrompt());
280
292
  if (await promptRetryKeypress({ logger: logger_default }) !== "retry") return {
281
293
  reopened: false,
@@ -340,12 +352,13 @@ async function closeIde() {
340
352
  }
341
353
  async function tryOpenWechatIdeByAutomator(projectPath, options) {
342
354
  if (options.reuseOpenedProject === false) {
343
- if (await reopenOpenedWechatIde(projectPath, closeIde)) return true;
355
+ if (await reopenOpenedWechatIde(projectPath, closeIde)) return "reopened";
344
356
  }
345
- const reuseResult = await tryReuseOpenedWechatIde(projectPath, closeIde);
346
- if (reuseResult?.reused || reuseResult?.reopened) return true;
357
+ const reuseResult = await tryReuseOpenedWechatIde(projectPath, closeIde, { promptReopen: options.reuseOpenedProject !== true });
358
+ if (reuseResult?.reused) return "reused";
359
+ if (reuseResult?.reopened) return "reopened";
347
360
  await openWechatIdeByAutomator(projectPath);
348
- return true;
361
+ return "opened";
349
362
  }
350
363
  /**
351
364
  * @description 打开后主动刷新微信开发者工具的项目索引,避免模拟器沿用过期 app 配置。
@@ -356,12 +369,29 @@ function appendLoginRetryArgv(argv, options) {
356
369
  if (options.loginRetryTimeout) argv.push("--login-retry-timeout", options.loginRetryTimeout);
357
370
  return argv;
358
371
  }
372
+ async function prepareOpenedWechatIdeAutomatorSession(projectPath, options) {
373
+ try {
374
+ (await launchAutomator({
375
+ persistAsDefaultSession: true,
376
+ preserveProjectRoot: true,
377
+ projectPath,
378
+ port: resolveProjectAutomatorPort(projectPath),
379
+ timeout: 3e4,
380
+ trustProject: options.trustProject !== false
381
+ })).disconnect?.();
382
+ } catch (error) {
383
+ logger_default.warn("准备当前项目的微信开发者工具自动化会话失败,截图、MCP 或 IDE 联动命令首次运行时将重新连接。");
384
+ if (shouldLogAutomatorFallbackError()) logger_default.error(error);
385
+ }
386
+ }
359
387
  async function stabilizeOpenedWechatIdeProject(projectPath, servicePortEnabled, options = {}) {
360
388
  if (servicePortEnabled === false) return;
361
389
  try {
362
390
  await executeWechatIdeCliCommand(appendLoginRetryArgv(["compile"], options), {
391
+ automatorMode: options.useAutomatorOpen === false ? "skip" : "prefer",
363
392
  httpMode: "prefer",
364
393
  onNonLoginError: (error) => logger_default.error(error),
394
+ preserveProjectRoot: options.useAutomatorOpen === false,
365
395
  projectPath
366
396
  });
367
397
  await executeWechatIdeCliCommand(appendLoginRetryArgv([
@@ -369,8 +399,10 @@ async function stabilizeOpenedWechatIdeProject(projectPath, servicePortEnabled,
369
399
  "-p",
370
400
  projectPath
371
401
  ], options), {
402
+ automatorMode: options.useAutomatorOpen === false ? "skip" : "prefer",
372
403
  httpMode: "prefer",
373
404
  onNonLoginError: (error) => logger_default.error(error),
405
+ preserveProjectRoot: options.useAutomatorOpen === false,
374
406
  projectPath
375
407
  });
376
408
  try {
@@ -379,18 +411,21 @@ async function stabilizeOpenedWechatIdeProject(projectPath, servicePortEnabled,
379
411
  "build",
380
412
  projectPath
381
413
  ], options), {
414
+ automatorMode: options.useAutomatorOpen === false ? "skip" : "prefer",
382
415
  httpMode: "prefer",
383
416
  onNonLoginError: (error) => logger_default.error(error),
417
+ preserveProjectRoot: options.useAutomatorOpen === false,
384
418
  projectPath
385
419
  });
386
420
  } catch (error) {
387
421
  if (!isWechatIdeEngineBuildEndpointMissingError(error)) throw error;
388
422
  logger_default.warn("当前微信开发者工具不支持自动 engine build 刷新,已跳过该步骤;如模拟器显示旧状态,可在开发者工具内手动编译。");
389
423
  }
390
- try {
424
+ if (options.useAutomatorOpen !== false) try {
391
425
  await executeWechatIdeCliCommand(appendLoginRetryArgv(["compile"], options), {
392
426
  automatorMode: "require",
393
427
  httpMode: "skip",
428
+ preserveProjectRoot: true,
394
429
  projectPath
395
430
  });
396
431
  } catch (error) {
@@ -414,6 +449,7 @@ function createIdeOpenArgv(platform, projectPath, options = {}) {
414
449
  }
415
450
  async function openIde(platform, projectPath, options = {}) {
416
451
  let bootstrapResult;
452
+ const useAutomatorOpen = options.useAutomatorOpen !== false;
417
453
  if (platform === "weapp" && projectPath) try {
418
454
  bootstrapResult = await bootstrapWechatDevtoolsSettings({
419
455
  projectPath,
@@ -424,8 +460,10 @@ async function openIde(platform, projectPath, options = {}) {
424
460
  logger_default.error(error);
425
461
  }
426
462
  if (platform === "weapp" && projectPath && bootstrapResult?.servicePortEnabled === false) logger_default.warn("检测到微信开发者工具服务端口当前处于关闭状态,已保留用户设置并回退到普通 open 流程。");
427
- if (platform === "weapp" && projectPath && options.trustProject !== false && bootstrapResult?.servicePortEnabled !== false) try {
428
- if (await tryOpenWechatIdeByAutomator(projectPath, options)) {
463
+ if (platform === "weapp" && projectPath && options.trustProject !== false && bootstrapResult?.servicePortEnabled !== false && useAutomatorOpen) try {
464
+ const openResult = await tryOpenWechatIdeByAutomator(projectPath, options);
465
+ if (openResult === "reused") return;
466
+ if (openResult) {
429
467
  await stabilizeOpenedWechatIdeProject(projectPath, bootstrapResult?.servicePortEnabled, options);
430
468
  return;
431
469
  }
@@ -437,8 +475,14 @@ async function openIde(platform, projectPath, options = {}) {
437
475
  logger_default.warn("通过 automator 启动微信开发者工具并自动信任项目失败,回退到普通 open 流程。");
438
476
  if (shouldLogAutomatorFallbackError()) logger_default.error(error);
439
477
  }
478
+ else if (platform === "weapp" && projectPath && options.reuseOpenedProject === false) {
479
+ if (!await closeIde()) logger_default.warn("关闭当前微信开发者工具失败,仍继续尝试打开目标项目。");
480
+ }
440
481
  await runWechatIdeOpenWithRetry(createIdeOpenArgv(platform, projectPath, options));
441
- if (platform === "weapp" && projectPath) await stabilizeOpenedWechatIdeProject(projectPath, bootstrapResult?.servicePortEnabled, options);
482
+ if (platform === "weapp" && projectPath) {
483
+ await stabilizeOpenedWechatIdeProject(projectPath, bootstrapResult?.servicePortEnabled, options);
484
+ if (options.useAutomatorOpen === false && bootstrapResult?.servicePortEnabled !== false) await prepareOpenedWechatIdeAutomatorSession(projectPath, options);
485
+ }
442
486
  }
443
487
  /**
444
488
  * @description 解析 IDE 相关命令所需的平台、项目目录与配置上下文。
@@ -2438,11 +2482,12 @@ function emitDashboardEvents$1(handle, events) {
2438
2482
  function registerBuildCommand(cli) {
2439
2483
  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 | web | all)`).option("--project-config <path>", `[string] project config path (miniprogram only)`).option("--sourcemap [output]", `[boolean | "inline" | "hidden"] output source maps for build (default: false)`).option("--minify [minifier]", "[boolean | \"terser\" | \"esbuild\"] enable/disable minification, or specify minifier to use (default: esbuild)").option("--emptyOutDir", `[boolean] force empty outDir when it's outside of root`).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("--trust-project", "[boolean] auto trust Wechat DevTools project on open", { default: true }).option("--ui", `[boolean] 启动调试 UI(当前提供分析视图)`, { default: false }).option("--analyze", `[boolean] 输出分包分析仪表盘`, { default: false }).option("--scope <scope>", `[string] 局部构建范围,例如 main,packages/order`).action(async (root, options) => {
2440
2484
  filterDuplicateOptions(options);
2485
+ const cwd = root ?? process.cwd();
2441
2486
  const configFile = resolveConfigFile(options);
2442
2487
  const targets = resolveRuntimeTargets(options);
2443
2488
  const inlineConfig = createInlineConfig(targets.platform, options.scope);
2444
2489
  const ctx = await createCompilerContext({
2445
- cwd: root,
2490
+ cwd,
2446
2491
  mode: options.mode ?? "production",
2447
2492
  configFile,
2448
2493
  inlineConfig,
@@ -3614,6 +3659,7 @@ async function runScreenshotAction(options) {
3614
3659
  const result = await takeScreenshot({
3615
3660
  fullPage: true,
3616
3661
  projectPath: options.projectPath,
3662
+ preserveProjectRoot: true,
3617
3663
  sharedSession: true,
3618
3664
  outputPath,
3619
3665
  timeout: DEFAULT_SCREENSHOT_TIMEOUT
@@ -3735,7 +3781,7 @@ function resolveRunnableHotkeyDefinition(input) {
3735
3781
  }
3736
3782
  //#endregion
3737
3783
  //#region package.json
3738
- var version = "6.16.42";
3784
+ var version = "6.16.43";
3739
3785
  //#endregion
3740
3786
  //#region src/cli/devHotkeys/format.ts
3741
3787
  const FULLWIDTH_ASCII_START = 65281;
@@ -3921,9 +3967,13 @@ function startDevHotkeys(options) {
3921
3967
  inputSession?.resume();
3922
3968
  printHint();
3923
3969
  };
3970
+ const suspendInput = () => {
3971
+ if (closed) return;
3972
+ inputSession?.suspend();
3973
+ };
3924
3974
  const suspend = () => {
3925
3975
  lastRenderedPanel = "";
3926
- inputSession?.suspend();
3976
+ suspendInput();
3927
3977
  forwardSigtstp();
3928
3978
  };
3929
3979
  const toggleMcp = createToggleMcpAction({
@@ -4025,9 +4075,76 @@ function startDevHotkeys(options) {
4025
4075
  });
4026
4076
  return {
4027
4077
  close,
4028
- restore
4078
+ restore,
4079
+ suspend: suspendInput
4080
+ };
4081
+ }
4082
+ //#endregion
4083
+ //#region src/cli/commands/serve/activeIdeProjects.ts
4084
+ const ACTIVE_IDE_PROJECTS_DIR = path$1.join(os.tmpdir(), "weapp-vite-active-dev-open-projects");
4085
+ function normalizeProjectPath(projectPath) {
4086
+ return path$1.resolve(projectPath);
4087
+ }
4088
+ function resolveRecordPath(projectPath) {
4089
+ return path$1.join(ACTIVE_IDE_PROJECTS_DIR, `${Buffer.from(normalizeProjectPath(projectPath)).toString("base64url")}.json`);
4090
+ }
4091
+ function isProcessAlive(pid) {
4092
+ try {
4093
+ process.kill(pid, 0);
4094
+ return true;
4095
+ } catch (error) {
4096
+ if (error && typeof error === "object" && "code" in error && error.code === "ESRCH") return false;
4097
+ return true;
4098
+ }
4099
+ }
4100
+ async function readRecord(filePath) {
4101
+ try {
4102
+ const raw = await fs$2.readFile(filePath, "utf8");
4103
+ const record = JSON.parse(raw);
4104
+ if (typeof record.pid !== "number" || typeof record.projectPath !== "string") return null;
4105
+ return record;
4106
+ } catch {
4107
+ return null;
4108
+ }
4109
+ }
4110
+ /**
4111
+ * @description 登记当前 dev:open 项目,供后续启动判断是否需要保留其它正在运行的 IDE 窗口。
4112
+ */
4113
+ async function registerActiveServeIdeProject(projectPath) {
4114
+ const filePath = resolveRecordPath(projectPath);
4115
+ await fs$2.mkdir(path$1.dirname(filePath), { recursive: true });
4116
+ await fs$2.writeFile(filePath, `${JSON.stringify({
4117
+ pid: process.pid,
4118
+ projectPath: normalizeProjectPath(projectPath),
4119
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
4120
+ }, null, 2)}\n`, "utf8");
4121
+ return async () => {
4122
+ await fs$2.rm(filePath, { force: true }).catch(() => {});
4029
4123
  };
4030
4124
  }
4125
+ /**
4126
+ * @description 检查是否存在其它仍在运行的 dev:open 项目。
4127
+ */
4128
+ async function hasOtherActiveServeIdeProject(projectPath) {
4129
+ const currentProjectPath = normalizeProjectPath(projectPath);
4130
+ let entries;
4131
+ try {
4132
+ entries = await fs$2.readdir(ACTIVE_IDE_PROJECTS_DIR);
4133
+ } catch {
4134
+ return false;
4135
+ }
4136
+ for (const entry of entries) {
4137
+ if (!entry.endsWith(".json")) continue;
4138
+ const filePath = path$1.join(ACTIVE_IDE_PROJECTS_DIR, entry);
4139
+ const record = await readRecord(filePath);
4140
+ if (!record || !isProcessAlive(record.pid)) {
4141
+ await fs$2.rm(filePath, { force: true }).catch(() => {});
4142
+ continue;
4143
+ }
4144
+ if (normalizeProjectPath(record.projectPath) !== currentProjectPath) return true;
4145
+ }
4146
+ return false;
4147
+ }
4031
4148
  //#endregion
4032
4149
  //#region src/cli/commands/serve/analyze.ts
4033
4150
  const REG_DIST_PAGE_ENTRY = /pages\/.+\/index\.js$/;
@@ -4310,10 +4427,10 @@ function createServeMiniProgramDevActions(options) {
4310
4427
  const projectPath = options.projectPath ?? options.fallbackProjectPath;
4311
4428
  return {
4312
4429
  projectPath,
4313
- openIde: async () => {
4314
- if (await options.tryReuseForwardConsole?.()) return "已通过控制台转发复用当前开发者工具会话";
4315
- await options.openIde(projectPath);
4316
- return "已重新打开微信开发者工具项目";
4430
+ openIde: async (openOptions = {}) => {
4431
+ if (!openOptions.forceOpen && await options.tryReuseForwardConsole?.()) return "已通过控制台转发复用当前开发者工具会话";
4432
+ await options.openIde(projectPath, openOptions);
4433
+ return openOptions.forceReopen ? "已重新打开微信开发者工具项目" : "已打开或复用微信开发者工具项目";
4317
4434
  },
4318
4435
  rebuild: async () => {
4319
4436
  await options.build();
@@ -4337,6 +4454,7 @@ function waitForServeShutdownSignal() {
4337
4454
  function registerServeCommand(cli) {
4338
4455
  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 | web | all)`).option("--project-config <path>", `[string] project config path (miniprogram only)`).option("--trust-project", "[boolean] auto trust Wechat DevTools project on open", { default: true }).option("--login-retry <mode>", "[string] login retry mode for Wechat DevTools (never | once | always)").option("--login-retry-timeout <ms>", "[number] login retry prompt timeout in milliseconds").option("--non-interactive", "[boolean] fail immediately when Wechat DevTools login has expired").option("--host [host]", `[string] web dev server host`).option("--ui", `[boolean] 启动调试 UI(当前提供分析视图)`, { default: false }).option("--analyze", `[boolean] 启动分包分析仪表盘 (实验特性)`, { default: false }).option("--scope <scope>", `[string] 局部构建范围,例如 main,packages/order`).action(async (root, options) => {
4339
4456
  filterDuplicateOptions(options);
4457
+ const cwd = root ?? process.cwd();
4340
4458
  const configFile = resolveConfigFile(options);
4341
4459
  const targets = resolveRuntimeTargets(options);
4342
4460
  let inlineConfig = createInlineConfig(targets.platform, options.scope);
@@ -4370,7 +4488,7 @@ function registerServeCommand(cli) {
4370
4488
  }
4371
4489
  }
4372
4490
  const ctx = await createCompilerContext({
4373
- cwd: root,
4491
+ cwd,
4374
4492
  mode: options.mode ?? "development",
4375
4493
  isDev: true,
4376
4494
  configFile,
@@ -4387,13 +4505,14 @@ function registerServeCommand(cli) {
4387
4505
  await buildService.build(options);
4388
4506
  },
4389
4507
  fallbackProjectPath: configService.cwd,
4390
- openIde: async (projectPath) => {
4508
+ openIde: async (projectPath, openOptions) => {
4391
4509
  await openIde(configService.platform, projectPath, {
4392
4510
  loginRetry: options.loginRetry,
4393
4511
  loginRetryTimeout: options.loginRetryTimeout,
4394
4512
  nonInteractive: options.nonInteractive,
4395
- reuseOpenedProject: false,
4396
- trustProject: options.trustProject
4513
+ reuseOpenedProject: !openOptions?.forceReopen,
4514
+ trustProject: options.trustProject,
4515
+ useAutomatorOpen: false
4397
4516
  });
4398
4517
  },
4399
4518
  projectPath: resolveIdeProjectRoot(configService.mpDistRoot, configService.cwd),
@@ -4409,13 +4528,17 @@ function registerServeCommand(cli) {
4409
4528
  const devHotkeysSession = targets.runMini ? startDevHotkeys({
4410
4529
  cwd: configService.cwd,
4411
4530
  mcpConfig: configService.weappViteConfig?.mcp,
4412
- openIde: miniProgramDevActions.openIde,
4531
+ openIde: async () => await miniProgramDevActions.openIde({
4532
+ forceOpen: true,
4533
+ forceReopen: true
4534
+ }),
4413
4535
  platform: configService.platform,
4414
4536
  projectPath: miniProgramDevActions.projectPath ?? configService.cwd,
4415
4537
  rebuild: miniProgramDevActions.rebuild,
4416
4538
  silentStartupHint: true,
4417
4539
  weappViteConfig: configService.weappViteConfig
4418
4540
  }) : void 0;
4541
+ let unregisterActiveIdeProject;
4419
4542
  try {
4420
4543
  const analyzeController = createAnalyzeController({
4421
4544
  configFile,
@@ -4488,12 +4611,22 @@ function registerServeCommand(cli) {
4488
4611
  detail: "开发服务已就绪,准备打开 IDE 项目。",
4489
4612
  tags: ["ide", "open"]
4490
4613
  }]);
4491
- await miniProgramDevActions.openIde();
4492
- devHotkeysSession?.restore();
4614
+ devHotkeysSession?.suspend();
4615
+ try {
4616
+ unregisterActiveIdeProject = miniProgramDevActions.projectPath ? await registerActiveServeIdeProject(miniProgramDevActions.projectPath) : void 0;
4617
+ const shouldForceReopen = miniProgramDevActions.projectPath ? !await hasOtherActiveServeIdeProject(miniProgramDevActions.projectPath) : true;
4618
+ await miniProgramDevActions.openIde({
4619
+ forceOpen: true,
4620
+ forceReopen: shouldForceReopen
4621
+ });
4622
+ } finally {
4623
+ devHotkeysSession?.restore();
4624
+ }
4493
4625
  }
4494
4626
  if (analyzeHandle) await analyzeController.waitForExit();
4495
4627
  else if (targets.runMini || targets.runWeb) await waitForServeShutdownSignal();
4496
4628
  } finally {
4629
+ await unregisterActiveIdeProject?.();
4497
4630
  devHotkeysSession?.close();
4498
4631
  ctx.watcherService?.closeAll();
4499
4632
  }
@@ -1,6 +1,6 @@
1
1
  import { n as applyWeappViteHostMeta } from "./pluginHost--CaeyWpA.mjs";
2
2
  import { n as configureLogger, r as logger_default } from "./logger-mt4mSTqV.mjs";
3
- import { _ as jsExtensions, a as findJsonEntry, b as vueExtensions, c as isJsOrTs, d as touch, g as configExtensions, i as findJsEntry, l as isTemplate, n as changeFileExtension, o as findTemplateEntry, p as inlineAutoRoutesImports, r as findCssEntry, s as findVueEntry, t as extractConfigFromVue, v as supportedCssLangs, y as templateExtensions } from "./file-Cm-gX3xL.mjs";
3
+ import { _ as jsExtensions, a as findJsonEntry, b as vueExtensions, c as isJsOrTs, d as touch, g as configExtensions, i as findJsEntry, l as isTemplate, n as changeFileExtension, o as findTemplateEntry, p as inlineAutoRoutesImports, r as findCssEntry, s as findVueEntry, t as extractConfigFromVue, v as supportedCssLangs, y as templateExtensions } from "./file-Wkzc9gMS.mjs";
4
4
  import { createRequire, isBuiltin } from "node:module";
5
5
  import path, { posix } from "pathe";
6
6
  import path$1, { normalize, relative, win32 } from "node:path";
@@ -14864,6 +14864,25 @@ function isKnownWevuComponentCallee(callee) {
14864
14864
  function mayNeedInjectSetDataPickInJs(source) {
14865
14865
  return source.includes("createWevuComponent") || source.includes("defineComponent") || source.includes("__wevu_isPage") || source.includes(".so(");
14866
14866
  }
14867
+ /**
14868
+ * 判断脚本 setup 阶段是否会读取编译期 slot 名元数据。
14869
+ */
14870
+ function mayNeedScopedSlotHostPropertiesForSetupSlotsInJs(source) {
14871
+ if (!source.includes("useSlots")) return false;
14872
+ const ast = parseJsLike(source);
14873
+ const useSlotsLocals = /* @__PURE__ */ new Set();
14874
+ traverse(ast, { ImportDeclaration(path) {
14875
+ const sourceValue = path.node.source.value;
14876
+ if (sourceValue !== "wevu" && sourceValue !== "vue" && sourceValue !== "wevu/internal-runtime") return;
14877
+ for (const specifier of path.node.specifiers) if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name === "useSlots" && specifier.local.type === "Identifier") useSlotsLocals.add(specifier.local.name);
14878
+ } });
14879
+ if (!useSlotsLocals.size) return false;
14880
+ let hasSetupSlotsCall = false;
14881
+ traverse(ast, { CallExpression(path) {
14882
+ if (path.node.callee.type === "Identifier" && useSlotsLocals.has(path.node.callee.name)) hasSetupSlotsCall = true;
14883
+ } });
14884
+ return hasSetupSlotsCall;
14885
+ }
14867
14886
  function getObjectPropertyByKey$1(objectExpression, key) {
14868
14887
  for (const member of objectExpression.properties) {
14869
14888
  if (member.type !== "ObjectProperty") continue;
@@ -23140,7 +23159,8 @@ async function finalizeTransformEntryScript(options) {
23140
23159
  }
23141
23160
  }
23142
23161
  const hasScopedSlotHostGenerics = Boolean(result.componentGenerics && Object.keys(result.componentGenerics).length > 0);
23143
- if (!isPage && !isApp && result.script && (hasScopedSlotHostGenerics || result.template?.includes(WEVU_SLOT_OWNER_ID_PROP) || result.template?.includes("vueSlots"))) {
23162
+ const needsSetupSlotHostProperties = result.script && mayNeedScopedSlotHostPropertiesForSetupSlotsInJs(result.script);
23163
+ if (!isPage && !isApp && result.script && (hasScopedSlotHostGenerics || result.template?.includes(WEVU_SLOT_OWNER_ID_PROP) || result.template?.includes("vueSlots") || needsSetupSlotHostProperties)) {
23144
23164
  const injectedProps = injectScopedSlotHostPropertiesInJs(result.script);
23145
23165
  if (injectedProps.transformed) {
23146
23166
  result.script = injectedProps.code;
@@ -23330,7 +23350,8 @@ async function finalizeCompiledVueLikeResult(options) {
23330
23350
  if (injectedPick.transformed) result.script = injectedPick.code;
23331
23351
  }
23332
23352
  const hasScopedSlotHostGenerics = Boolean(result.componentGenerics && Object.keys(result.componentGenerics).length > 0);
23333
- if (!isPage && !isApp && result.script && (hasScopedSlotHostGenerics || result.template?.includes(WEVU_SLOT_OWNER_ID_PROP) || result.template?.includes("vueSlots"))) {
23353
+ const needsSetupSlotHostProperties = result.script && mayNeedScopedSlotHostPropertiesForSetupSlotsInJs(result.script);
23354
+ if (!isPage && !isApp && result.script && (hasScopedSlotHostGenerics || result.template?.includes(WEVU_SLOT_OWNER_ID_PROP) || result.template?.includes("vueSlots") || needsSetupSlotHostProperties)) {
23334
23355
  const injectedProps = injectScopedSlotHostPropertiesInJs(result.script);
23335
23356
  if (injectedProps.transformed) result.script = injectedProps.code;
23336
23357
  }
@@ -25398,7 +25419,7 @@ async function loadAppEntry(ctx, scanState) {
25398
25419
  const vueAppPath = await findVueEntry(appBasename);
25399
25420
  let configFromVue;
25400
25421
  if (!appConfigFile && vueAppPath) {
25401
- const { extractConfigFromVue } = await import("./file-C00jTD86.mjs");
25422
+ const { extractConfigFromVue } = await import("./file-iVST36Dh.mjs");
25402
25423
  configFromVue = await extractConfigFromVue(vueAppPath);
25403
25424
  if (configFromVue) appConfigFile = vueAppPath;
25404
25425
  }
@@ -84,7 +84,7 @@ function resolveAutoRoutesMacroImportPath() {
84
84
  }
85
85
  async function resolveAutoRoutesInlineSnapshot() {
86
86
  try {
87
- const { getCompilerContext } = await import("./getInstance-BuRfAoqK.mjs");
87
+ const { getCompilerContext } = await import("./getInstance-QuyA4zlX.mjs");
88
88
  const compilerContext = getCompilerContext();
89
89
  const service = compilerContext.autoRoutesService;
90
90
  const reference = service?.getReference?.();
@@ -0,0 +1,2 @@
1
+ import { t as extractConfigFromVue } from "./file-Wkzc9gMS.mjs";
2
+ export { extractConfigFromVue };
@@ -0,0 +1,2 @@
1
+ import { n as getCompilerContext } from "./createContext-CRpsNCP2.mjs";
2
+ export { getCompilerContext };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { a as defineThemeJson, i as defineSitemapJson, n as defineComponentJson, r as definePageJson, t as defineAppJson } from "./json-BL8Dhhk6.mjs";
2
2
  import { a as resolveWeappViteHostMeta, i as isWeappViteHost, n as applyWeappViteHostMeta, r as createWeappViteHostMeta, t as WEAPP_VITE_HOST_NAME } from "./pluginHost--CaeyWpA.mjs";
3
3
  import { t as defineConfig } from "./config-DRGcCi3h.mjs";
4
- import { c as getSupportedWeappViteTargetDescriptors, l as isWebPlatform, o as WEB_PLATFORM_ALIASES, s as getSupportedWeappVitePlatforms, t as createCompilerContext, u as resolveWeappViteTarget } from "./createContext-BjCo8Rn4.mjs";
4
+ import { c as getSupportedWeappViteTargetDescriptors, l as isWebPlatform, o as WEB_PLATFORM_ALIASES, s as getSupportedWeappVitePlatforms, t as createCompilerContext, u as resolveWeappViteTarget } from "./createContext-CRpsNCP2.mjs";
5
5
  import { i as createWevuComponent, n as defineProps, r as setPageLayout, t as defineEmits } from "./runtime-C3z9pDQB.mjs";
6
6
  export { WEAPP_VITE_HOST_NAME, WEB_PLATFORM_ALIASES, applyWeappViteHostMeta, createCompilerContext, createWeappViteHostMeta, createWevuComponent, defineAppJson, defineComponentJson, defineConfig, defineEmits, definePageJson, defineProps, defineSitemapJson, defineThemeJson, getSupportedWeappVitePlatforms, getSupportedWeappViteTargetDescriptors, isWeappViteHost, isWebPlatform, resolveWeappViteHostMeta, resolveWeappViteTarget, setPageLayout };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "weapp-vite",
3
3
  "type": "module",
4
- "version": "6.16.42",
4
+ "version": "6.16.43",
5
5
  "description": "weapp-vite 一个现代化的小程序打包工具",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -93,7 +93,7 @@
93
93
  "@jridgewell/remapping": "^2.3.5",
94
94
  "@vercel/detect-agent": "^1.2.3",
95
95
  "@volar/typescript": "^2.4.28",
96
- "@vue/language-core": "^3.3.3",
96
+ "@vue/language-core": "^3.3.4",
97
97
  "cac": "^7.0.0",
98
98
  "chokidar": "^5.0.0",
99
99
  "comment-json": "^5.0.0",
@@ -111,19 +111,19 @@
111
111
  "postcss": "^8.5.15",
112
112
  "rolldown": "1.1.0",
113
113
  "rolldown-plugin-dts": "0.25.2",
114
- "semver": "^7.8.2",
114
+ "semver": "^7.8.3",
115
115
  "typescript": "^6.0.3",
116
116
  "vite": "8.0.16",
117
117
  "vite-tsconfig-paths": "^6.1.1",
118
118
  "vue": "^3.5.35",
119
- "vue-tsc": "^3.3.3",
119
+ "vue-tsc": "^3.3.4",
120
120
  "@weapp-core/constants": "0.1.12",
121
121
  "@weapp-core/init": "6.0.10",
122
122
  "@weapp-core/logger": "3.1.1",
123
123
  "@weapp-core/schematics": "6.0.4",
124
124
  "@weapp-core/shared": "3.0.4",
125
- "@weapp-vite/ast": "6.16.42",
126
- "@weapp-vite/mcp": "1.4.2",
125
+ "@weapp-vite/ast": "6.16.43",
126
+ "@weapp-vite/mcp": "1.4.3",
127
127
  "@weapp-vite/miniprogram-automator": "1.2.2",
128
128
  "@weapp-vite/volar": "2.1.0",
129
129
  "@weapp-vite/web": "1.3.30",
@@ -131,15 +131,15 @@
131
131
  "@wevu/web-apis": "1.2.20",
132
132
  "rolldown-require": "2.0.18",
133
133
  "vite-plugin-performance": "2.0.1",
134
- "weapp-ide-cli": "5.4.3",
135
- "wevu": "6.16.42"
134
+ "weapp-ide-cli": "5.4.4",
135
+ "wevu": "6.16.43"
136
136
  },
137
137
  "publishConfig": {
138
138
  "access": "public",
139
139
  "registry": "https://registry.npmjs.org"
140
140
  },
141
141
  "devDependencies": {
142
- "oxc-parser": "^0.134.0",
142
+ "oxc-parser": "^0.135.0",
143
143
  "oxc-walker": "^1.0.0",
144
144
  "tailwindcss": "^4.3.0",
145
145
  "ts-morph": "^28.0.0"
@@ -1,2 +0,0 @@
1
- import { t as extractConfigFromVue } from "./file-Cm-gX3xL.mjs";
2
- export { extractConfigFromVue };
@@ -1,2 +0,0 @@
1
- import { n as getCompilerContext } from "./createContext-BjCo8Rn4.mjs";
2
- export { getCompilerContext };