weapp-vite 6.16.41 → 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.
- package/dist/auto-routes.mjs +1 -1
- package/dist/cli.mjs +167 -34
- package/dist/{createContext-BVsIMQLE.mjs → createContext-CRpsNCP2.mjs} +14495 -14422
- package/dist/{file-bzejjf0g.mjs → file-Wkzc9gMS.mjs} +1 -1
- package/dist/file-iVST36Dh.mjs +2 -0
- package/dist/getInstance-QuyA4zlX.mjs +2 -0
- package/dist/index.mjs +1 -1
- package/package.json +9 -9
- package/dist/file-CHPrnwzT.mjs +0 -2
- package/dist/getInstance-cX_-OJXD.mjs +0 -2
package/dist/auto-routes.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as getRouteRuntimeGlobalKeys,
|
|
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,
|
|
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-
|
|
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({
|
|
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
|
|
355
|
+
if (await reopenOpenedWechatIde(projectPath, closeIde)) return "reopened";
|
|
344
356
|
}
|
|
345
|
-
const reuseResult = await tryReuseOpenedWechatIde(projectPath, closeIde);
|
|
346
|
-
if (reuseResult?.reused
|
|
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
|
|
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
|
-
|
|
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)
|
|
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,18 +2482,18 @@ 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
|
|
2490
|
+
cwd,
|
|
2446
2491
|
mode: options.mode ?? "production",
|
|
2447
2492
|
configFile,
|
|
2448
2493
|
inlineConfig,
|
|
2449
2494
|
cliPlatform: targets.rawPlatform,
|
|
2450
2495
|
projectConfigPath: options.projectConfig,
|
|
2451
2496
|
emitDefaultAutoImportOutputs: false,
|
|
2452
|
-
syncSupportFiles: false,
|
|
2453
2497
|
preloadAppEntry: false
|
|
2454
2498
|
});
|
|
2455
2499
|
const { buildService, configService, webService } = ctx;
|
|
@@ -3508,7 +3552,7 @@ function registerPrepareCommand(cli) {
|
|
|
3508
3552
|
filterDuplicateOptions(options);
|
|
3509
3553
|
const cwd = path.resolve(resolvePrepareRoot(input));
|
|
3510
3554
|
const cliPlatform = resolvePreparePlatform(options);
|
|
3511
|
-
await syncProjectSupportFiles(await createCompilerContext({
|
|
3555
|
+
const supportFiles = await syncProjectSupportFiles(await createCompilerContext({
|
|
3512
3556
|
cwd,
|
|
3513
3557
|
isDev: false,
|
|
3514
3558
|
mode: typeof options.mode === "string" ? options.mode : "development",
|
|
@@ -3518,6 +3562,7 @@ function registerPrepareCommand(cli) {
|
|
|
3518
3562
|
preloadAppEntry: false,
|
|
3519
3563
|
...cliPlatform ? { cliPlatform } : {}
|
|
3520
3564
|
}));
|
|
3565
|
+
for (const warning of supportFiles.managedTsconfigWarnings) logger_default.warn(warning);
|
|
3521
3566
|
logger_default.info("已生成 .weapp-vite 支持文件。");
|
|
3522
3567
|
} catch (error) {
|
|
3523
3568
|
logger_default.warn(`[prepare] ${formatPrepareSkipMessage$1(error)}`);
|
|
@@ -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.
|
|
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
|
-
|
|
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
|
|
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:
|
|
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
|
-
|
|
4492
|
-
|
|
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
|
}
|