weapp-vite 6.17.1 → 6.17.3
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 +132 -25
- package/dist/{createContext-Dg_HER2J.mjs → createContext-Bm3wVI4b.mjs} +48 -3
- package/dist/file-BZkl3L_r.mjs +2 -0
- package/dist/{file-CtueODLX.mjs → file-kdAYpUO6.mjs} +1 -1
- package/dist/getInstance-CQ6SnI35.mjs +2 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +3 -3
- package/dist/runtime-CRoKWQZn.mjs +122 -0
- package/dist/{runtime-CDNs17Qq.d.mts → runtime-xQwLUxkz.d.mts} +32 -1
- package/dist/runtime.d.mts +2 -2
- package/dist/runtime.mjs +2 -2
- package/package.json +14 -14
- package/dist/file-C206GmuT.mjs +0 -2
- package/dist/getInstance-Dw7Y4EkD.mjs +0 -2
- package/dist/runtime-C3z9pDQB.mjs +0 -60
package/dist/auto-routes.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as getRouteRuntimeGlobalKeys, n as getCompilerContext } from "./createContext-
|
|
1
|
+
import { g as getRouteRuntimeGlobalKeys, n as getCompilerContext } from "./createContext-Bm3wVI4b.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,6 +1,6 @@
|
|
|
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-
|
|
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-Bm3wVI4b.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-kdAYpUO6.mjs";
|
|
4
4
|
import { c as startWeappViteMcpServer, l as detectAiDevelopmentEnvironment, s as resolveWeappMcpConfig } from "./mcp-BG6TliEg.mjs";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
6
|
import path, { posix } from "pathe";
|
|
@@ -23,7 +23,7 @@ import { generateJs, generateJson, generateWxml, generateWxss } from "@weapp-cor
|
|
|
23
23
|
import { determineAgent } from "@vercel/detect-agent";
|
|
24
24
|
import { initConfig } from "@weapp-core/init";
|
|
25
25
|
import { createInterface } from "node:readline/promises";
|
|
26
|
-
import { clearTimeout, setTimeout as setTimeout$1 } from "node:timers";
|
|
26
|
+
import { clearTimeout as clearTimeout$1, setTimeout as setTimeout$1 } from "node:timers";
|
|
27
27
|
import net from "node:net";
|
|
28
28
|
//#region src/cli/runtime.ts
|
|
29
29
|
function logRuntimeTarget(targets, options = {}) {
|
|
@@ -277,12 +277,28 @@ function logWechatIdeServicePortDisabledHint(projectPath) {
|
|
|
277
277
|
}
|
|
278
278
|
//#endregion
|
|
279
279
|
//#region src/cli/openIde/reuse.ts
|
|
280
|
+
const OPENED_PROJECT_HEALTH_CHECK_TIMEOUT = 3e3;
|
|
280
281
|
function formatReuseOpenedWechatIdePrompt() {
|
|
281
|
-
return `目标项目已在微信开发者工具中打开,已跳过重复打开。按 ${colors.bold(colors.green("
|
|
282
|
+
return `目标项目已在微信开发者工具中打开,已跳过重复打开。按 ${RETRY_CONFIRM_KEYS.map((key) => colors.bold(colors.green(key))).join(" / ")} 关闭当前窗口后重新打开。`;
|
|
282
283
|
}
|
|
283
284
|
function disconnectMiniProgram(miniProgram) {
|
|
284
285
|
miniProgram.disconnect();
|
|
285
286
|
}
|
|
287
|
+
function withTimeout(task, timeoutMs) {
|
|
288
|
+
let timer;
|
|
289
|
+
const timeout = new Promise((_, reject) => {
|
|
290
|
+
timer = setTimeout(() => {
|
|
291
|
+
reject(/* @__PURE__ */ new Error(`opened automator health check timed out after ${timeoutMs}ms`));
|
|
292
|
+
}, timeoutMs);
|
|
293
|
+
});
|
|
294
|
+
return Promise.race([task, timeout]).finally(() => {
|
|
295
|
+
if (timer) clearTimeout(timer);
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
async function verifyOpenedProjectHealth(miniProgram) {
|
|
299
|
+
if (typeof miniProgram.screenshot !== "function") return;
|
|
300
|
+
await withTimeout(miniProgram.screenshot({ timeout: OPENED_PROJECT_HEALTH_CHECK_TIMEOUT }), OPENED_PROJECT_HEALTH_CHECK_TIMEOUT);
|
|
301
|
+
}
|
|
286
302
|
async function openWechatIdeByAutomator(projectPath) {
|
|
287
303
|
disconnectMiniProgram(await launchAutomator({
|
|
288
304
|
persistAsDefaultSession: true,
|
|
@@ -293,13 +309,17 @@ async function openWechatIdeByAutomator(projectPath) {
|
|
|
293
309
|
}));
|
|
294
310
|
}
|
|
295
311
|
async function connectOpenedProject(projectPath) {
|
|
312
|
+
let miniProgram = null;
|
|
296
313
|
try {
|
|
297
|
-
|
|
314
|
+
miniProgram = await connectOpenedAutomator({
|
|
298
315
|
projectPath,
|
|
299
316
|
port: resolveProjectAutomatorPort(projectPath),
|
|
300
317
|
timeout: 3e3
|
|
301
318
|
});
|
|
319
|
+
await verifyOpenedProjectHealth(miniProgram);
|
|
320
|
+
return miniProgram;
|
|
302
321
|
} catch {
|
|
322
|
+
if (miniProgram) disconnectMiniProgram(miniProgram);
|
|
303
323
|
return null;
|
|
304
324
|
}
|
|
305
325
|
}
|
|
@@ -444,6 +464,32 @@ async function prepareOpenedWechatIdeAutomatorSession(projectPath, options) {
|
|
|
444
464
|
};
|
|
445
465
|
}
|
|
446
466
|
}
|
|
467
|
+
async function connectOpenedWechatIdeAutomatorSession(projectPath) {
|
|
468
|
+
try {
|
|
469
|
+
(await connectOpenedAutomator({
|
|
470
|
+
projectPath,
|
|
471
|
+
port: resolveProjectAutomatorPort(projectPath),
|
|
472
|
+
timeout: PREPARE_AUTOMATOR_SESSION_TIMEOUT
|
|
473
|
+
})).disconnect?.();
|
|
474
|
+
return { ok: true };
|
|
475
|
+
} catch (error) {
|
|
476
|
+
logger_default.warn("连接当前项目的微信开发者工具自动化会话失败,截图、MCP 或 IDE 联动命令首次运行时将重新连接。");
|
|
477
|
+
logWechatIdeRecoveryHint({
|
|
478
|
+
projectPath,
|
|
479
|
+
reason: "当前项目已完成打开流程,但尚未连接到可复用的自动化会话。"
|
|
480
|
+
});
|
|
481
|
+
if (shouldLogAutomatorFallbackError()) logger_default.error(error);
|
|
482
|
+
return {
|
|
483
|
+
ok: false,
|
|
484
|
+
reason: "automator-session-failed",
|
|
485
|
+
error
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
async function prepareWechatIdeAutomatorSession(projectPath, options) {
|
|
490
|
+
if (options.prepareAutomatorSession === "connect-opened") return await connectOpenedWechatIdeAutomatorSession(projectPath);
|
|
491
|
+
return await prepareOpenedWechatIdeAutomatorSession(projectPath, options);
|
|
492
|
+
}
|
|
447
493
|
async function stabilizeOpenedWechatIdeProject(projectPath, servicePortEnabled, options = {}) {
|
|
448
494
|
if (servicePortEnabled === false) return {
|
|
449
495
|
ok: false,
|
|
@@ -478,7 +524,7 @@ async function stabilizeOpenedWechatIdeProject(projectPath, servicePortEnabled,
|
|
|
478
524
|
if (!isWechatIdeEngineBuildEndpointMissingError(error)) throw error;
|
|
479
525
|
logger_default.warn("当前微信开发者工具不支持自动 engine build 刷新,已跳过该步骤;如模拟器显示旧状态,可在开发者工具内手动编译。");
|
|
480
526
|
}
|
|
481
|
-
if (options.useAutomatorOpen !== false) try {
|
|
527
|
+
if (options.useAutomatorOpen !== false && options.skipAutomatorCompile !== true) try {
|
|
482
528
|
await executeWechatIdeCliCommand(appendLoginRetryArgv(["compile"], options), {
|
|
483
529
|
automatorMode: "require",
|
|
484
530
|
httpMode: "skip",
|
|
@@ -572,7 +618,7 @@ async function openIde(platform, projectPath, options = {}) {
|
|
|
572
618
|
if (!await closeIde()) logger_default.warn("关闭当前微信开发者工具失败,仍继续尝试打开目标项目。");
|
|
573
619
|
}
|
|
574
620
|
await runWechatIdeOpenWithRetry(createIdeOpenArgv(platform, projectPath, normalizedOptions));
|
|
575
|
-
if (platform === "weapp" && projectPath && normalizedOptions.prepareAutomatorSession) await
|
|
621
|
+
if (platform === "weapp" && projectPath && normalizedOptions.prepareAutomatorSession) await prepareWechatIdeAutomatorSession(projectPath, normalizedOptions);
|
|
576
622
|
if (platform === "weapp" && projectPath && !normalizedOptions.skipPostOpenHealthCheck) await verifyAndRecoverOpenedWechatIdeProject(platform, projectPath, bootstrapResult?.servicePortEnabled, normalizedOptions);
|
|
577
623
|
}
|
|
578
624
|
/**
|
|
@@ -2861,6 +2907,7 @@ const DEFAULT_FORWARD_CONSOLE_LEVELS = [
|
|
|
2861
2907
|
"error"
|
|
2862
2908
|
];
|
|
2863
2909
|
let activeForwardConsoleSession;
|
|
2910
|
+
let activeForwardConsoleBridgeOptions;
|
|
2864
2911
|
const FORWARD_CONSOLE_RETRY_DELAY_MS = 1e3;
|
|
2865
2912
|
const FORWARD_CONSOLE_RETRY_TIMES = 5;
|
|
2866
2913
|
async function detectAgent() {
|
|
@@ -2975,6 +3022,31 @@ async function startForwardConsoleBridge(options) {
|
|
|
2975
3022
|
});
|
|
2976
3023
|
}
|
|
2977
3024
|
/**
|
|
3025
|
+
* @description 暂停当前 DevTools 日志桥,并返回恢复函数。
|
|
3026
|
+
*/
|
|
3027
|
+
async function pauseActiveForwardConsole() {
|
|
3028
|
+
const session = activeForwardConsoleSession;
|
|
3029
|
+
const bridgeOptions = activeForwardConsoleBridgeOptions;
|
|
3030
|
+
if (!session || !bridgeOptions) return;
|
|
3031
|
+
activeForwardConsoleSession = void 0;
|
|
3032
|
+
activeForwardConsoleBridgeOptions = void 0;
|
|
3033
|
+
await session.close();
|
|
3034
|
+
return async () => {
|
|
3035
|
+
if (activeForwardConsoleSession) return true;
|
|
3036
|
+
try {
|
|
3037
|
+
activeForwardConsoleSession = await startForwardConsoleBridge(bridgeOptions);
|
|
3038
|
+
activeForwardConsoleBridgeOptions = bridgeOptions;
|
|
3039
|
+
return true;
|
|
3040
|
+
} catch (error) {
|
|
3041
|
+
activeForwardConsoleSession = void 0;
|
|
3042
|
+
activeForwardConsoleBridgeOptions = void 0;
|
|
3043
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3044
|
+
logger_default.warn(`[forwardConsole] 恢复失败:${message}`);
|
|
3045
|
+
return false;
|
|
3046
|
+
}
|
|
3047
|
+
};
|
|
3048
|
+
}
|
|
3049
|
+
/**
|
|
2978
3050
|
* @description 在 weapp 开发态按需启动控制台转发。
|
|
2979
3051
|
*/
|
|
2980
3052
|
async function maybeStartForwardConsole(options) {
|
|
@@ -2996,10 +3068,12 @@ async function maybeStartForwardConsole(options) {
|
|
|
2996
3068
|
};
|
|
2997
3069
|
try {
|
|
2998
3070
|
activeForwardConsoleSession = await startForwardConsoleBridge(bridgeOptions);
|
|
3071
|
+
activeForwardConsoleBridgeOptions = bridgeOptions;
|
|
2999
3072
|
return true;
|
|
3000
3073
|
} catch (error) {
|
|
3001
3074
|
if (!isDevtoolsPortNotReadyError(error)) {
|
|
3002
3075
|
activeForwardConsoleSession = void 0;
|
|
3076
|
+
activeForwardConsoleBridgeOptions = void 0;
|
|
3003
3077
|
const message = error instanceof Error ? error.message : String(error);
|
|
3004
3078
|
logger_default.warn(`[forwardConsole] 启动失败,回退到普通 IDE 打开流程:${message}`);
|
|
3005
3079
|
return false;
|
|
@@ -3010,9 +3084,15 @@ async function maybeStartForwardConsole(options) {
|
|
|
3010
3084
|
openedOnly: true,
|
|
3011
3085
|
port: void 0
|
|
3012
3086
|
});
|
|
3087
|
+
activeForwardConsoleBridgeOptions = {
|
|
3088
|
+
...bridgeOptions,
|
|
3089
|
+
openedOnly: true,
|
|
3090
|
+
port: void 0
|
|
3091
|
+
};
|
|
3013
3092
|
return true;
|
|
3014
3093
|
} catch (fallbackError) {
|
|
3015
3094
|
activeForwardConsoleSession = void 0;
|
|
3095
|
+
activeForwardConsoleBridgeOptions = void 0;
|
|
3016
3096
|
const message = fallbackError instanceof Error ? fallbackError.message : String(fallbackError);
|
|
3017
3097
|
logger_default.warn(`[forwardConsole] 启动失败,回退到普通 IDE 打开流程:${message}`);
|
|
3018
3098
|
return false;
|
|
@@ -3365,7 +3445,7 @@ async function probeHttpEndpoint(url) {
|
|
|
3365
3445
|
} catch {
|
|
3366
3446
|
return false;
|
|
3367
3447
|
} finally {
|
|
3368
|
-
clearTimeout(timer);
|
|
3448
|
+
clearTimeout$1(timer);
|
|
3369
3449
|
controller.abort();
|
|
3370
3450
|
}
|
|
3371
3451
|
}
|
|
@@ -3876,7 +3956,7 @@ async function runOpenIdeAction(options) {
|
|
|
3876
3956
|
//#endregion
|
|
3877
3957
|
//#region src/cli/devHotkeys/screenshot.ts
|
|
3878
3958
|
const DEV_SCREENSHOT_DIR = ".weapp-vite/dev-screenshots";
|
|
3879
|
-
const DEFAULT_SCREENSHOT_TIMEOUT =
|
|
3959
|
+
const DEFAULT_SCREENSHOT_TIMEOUT = 12e4;
|
|
3880
3960
|
/**
|
|
3881
3961
|
* @description 生成开发态截图输出路径。
|
|
3882
3962
|
*/
|
|
@@ -3892,24 +3972,42 @@ function formatLogPath(cwd, targetPath) {
|
|
|
3892
3972
|
function formatResolvedScreenshotPath(cwd, fallbackPath, result) {
|
|
3893
3973
|
return formatLogPath(cwd, result.path ?? fallbackPath);
|
|
3894
3974
|
}
|
|
3975
|
+
async function resolveDefaultScreenshotPage(cwd) {
|
|
3976
|
+
try {
|
|
3977
|
+
const raw = await fs$2.readFile(path.join(cwd, "app.json"), "utf8");
|
|
3978
|
+
const appJson = JSON.parse(raw);
|
|
3979
|
+
const [firstPage] = Array.isArray(appJson.pages) ? appJson.pages : [];
|
|
3980
|
+
return typeof firstPage === "string" && firstPage.trim() ? firstPage : void 0;
|
|
3981
|
+
} catch {
|
|
3982
|
+
return;
|
|
3983
|
+
}
|
|
3984
|
+
}
|
|
3895
3985
|
/**
|
|
3896
3986
|
* @description 执行当前页面截图并输出结果日志。
|
|
3897
3987
|
*/
|
|
3898
3988
|
async function runScreenshotAction(options) {
|
|
3899
3989
|
const outputPath = resolveDevScreenshotOutputPath(options.cwd);
|
|
3900
3990
|
await fs$2.mkdir(path.dirname(outputPath), { recursive: true });
|
|
3991
|
+
const page = await resolveDefaultScreenshotPage(options.cwd);
|
|
3901
3992
|
logger_default.info(`[dev action] 正在截图当前页面,输出到 ${colors.cyan(formatLogPath(options.cwd, outputPath))}`);
|
|
3902
|
-
const
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3993
|
+
const resumeForwardConsole = await pauseActiveForwardConsole();
|
|
3994
|
+
try {
|
|
3995
|
+
const result = await takeScreenshot({
|
|
3996
|
+
projectPath: options.projectPath,
|
|
3997
|
+
fullPage: true,
|
|
3998
|
+
...page ? { page } : {},
|
|
3999
|
+
preserveProjectRoot: true,
|
|
4000
|
+
port: resolveProjectAutomatorPort(options.projectPath),
|
|
4001
|
+
retryWithFreshSession: false,
|
|
4002
|
+
outputPath,
|
|
4003
|
+
timeout: DEFAULT_SCREENSHOT_TIMEOUT
|
|
4004
|
+
});
|
|
4005
|
+
const resolvedPath = formatResolvedScreenshotPath(options.cwd, outputPath, result);
|
|
4006
|
+
logger_default.success(`[dev action] 当前页面截图完成:${colors.cyan(resolvedPath)}`);
|
|
4007
|
+
return resolvedPath;
|
|
4008
|
+
} finally {
|
|
4009
|
+
await resumeForwardConsole?.();
|
|
4010
|
+
}
|
|
3913
4011
|
}
|
|
3914
4012
|
//#endregion
|
|
3915
4013
|
//#region src/cli/devHotkeys/actions.ts
|
|
@@ -4024,7 +4122,7 @@ function resolveRunnableHotkeyDefinition(input) {
|
|
|
4024
4122
|
}
|
|
4025
4123
|
//#endregion
|
|
4026
4124
|
//#region package.json
|
|
4027
|
-
var version = "6.17.
|
|
4125
|
+
var version = "6.17.3";
|
|
4028
4126
|
//#endregion
|
|
4029
4127
|
//#region src/cli/devHotkeys/format.ts
|
|
4030
4128
|
const FULLWIDTH_ASCII_START = 65281;
|
|
@@ -4640,6 +4738,12 @@ function createAnalyzeController(options) {
|
|
|
4640
4738
|
}
|
|
4641
4739
|
//#endregion
|
|
4642
4740
|
//#region src/cli/commands/serve/shared.ts
|
|
4741
|
+
function startBackgroundForwardConsoleReuse(tryReuseForwardConsole) {
|
|
4742
|
+
if (!tryReuseForwardConsole) return;
|
|
4743
|
+
try {
|
|
4744
|
+
tryReuseForwardConsole().catch(() => {});
|
|
4745
|
+
} catch {}
|
|
4746
|
+
}
|
|
4643
4747
|
function resolveWebHost(host) {
|
|
4644
4748
|
if (host === void 0) return;
|
|
4645
4749
|
if (typeof host === "boolean") return host;
|
|
@@ -4656,7 +4760,7 @@ function createServeMiniProgramDevActions(options) {
|
|
|
4656
4760
|
openIde: async (openOptions = {}) => {
|
|
4657
4761
|
if (!openOptions.forceOpen && await options.tryReuseForwardConsole?.()) return "已通过控制台转发复用当前开发者工具会话";
|
|
4658
4762
|
await options.openIde(projectPath, openOptions);
|
|
4659
|
-
|
|
4763
|
+
startBackgroundForwardConsoleReuse(options.tryReuseForwardConsole);
|
|
4660
4764
|
return openOptions.forceReopen ? "已重新打开微信开发者工具项目" : "已打开或复用微信开发者工具项目";
|
|
4661
4765
|
},
|
|
4662
4766
|
rebuild: async () => {
|
|
@@ -4724,6 +4828,7 @@ function registerServeCommand(cli) {
|
|
|
4724
4828
|
configFile,
|
|
4725
4829
|
inlineConfig,
|
|
4726
4830
|
cliPlatform: targets.rawPlatform,
|
|
4831
|
+
preloadAppEntry: false,
|
|
4727
4832
|
projectConfigPath: options.projectConfig
|
|
4728
4833
|
});
|
|
4729
4834
|
const { buildService, configService, webService } = ctx;
|
|
@@ -4738,16 +4843,18 @@ function registerServeCommand(cli) {
|
|
|
4738
4843
|
},
|
|
4739
4844
|
fallbackProjectPath: configService.cwd,
|
|
4740
4845
|
openIde: async (projectPath, openOptions) => {
|
|
4846
|
+
const forceReopen = openOptions?.forceReopen === true;
|
|
4741
4847
|
await openIde(configService.platform, projectPath, {
|
|
4742
4848
|
loginRetry: options.loginRetry,
|
|
4743
4849
|
loginRetryTimeout: options.loginRetryTimeout,
|
|
4744
4850
|
nonInteractive: options.nonInteractive,
|
|
4745
4851
|
openRecovery: false,
|
|
4746
|
-
prepareAutomatorSession: true,
|
|
4747
|
-
reuseOpenedProject: !
|
|
4852
|
+
prepareAutomatorSession: forceReopen ? true : "connect-opened",
|
|
4853
|
+
reuseOpenedProject: !forceReopen,
|
|
4854
|
+
skipAutomatorCompile: !forceReopen,
|
|
4748
4855
|
skipPostOpenHealthCheck: true,
|
|
4749
4856
|
trustProject: options.trustProject,
|
|
4750
|
-
useAutomatorOpen:
|
|
4857
|
+
useAutomatorOpen: forceReopen
|
|
4751
4858
|
});
|
|
4752
4859
|
writePostOpenSeparator();
|
|
4753
4860
|
},
|
|
@@ -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-
|
|
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-kdAYpUO6.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";
|
|
@@ -10453,6 +10453,7 @@ function createAdvancedChunkNameResolver(options) {
|
|
|
10453
10453
|
const REG_NODE_MODULES_DIR = /[\\/]node_modules[\\/]/gi;
|
|
10454
10454
|
const REG_COMMONJS_HELPERS = /commonjsHelpers\.js$/;
|
|
10455
10455
|
const REG_REQUEST_GLOBAL_RUNTIME_VENDOR_ID = /(?:^|[/\\])(?:@wevu[/\\]web-apis|web-apis[/\\]dist[/\\]index\.(?:m?js|cjs)|weapp-vite[/\\](?:dist[/\\]web-apis\.mjs|src[/\\](?:webApis\.ts|runtime[/\\]webApis[/\\]index\.ts)))(?:$|[?#])/;
|
|
10456
|
+
const REG_WEAPP_VITE_RUNTIME_VENDOR_ID = /(?:^|[/\\])weapp-vite[/\\](?:dist[/\\]runtime\.mjs|src[/\\]plugins[/\\]vue[/\\]runtime\.ts)(?:$|[?#])/;
|
|
10456
10457
|
const REG_HASHED_DIST_CHUNK_ID = /(?:^|[/\\])dist[/\\](?:dev[/\\])?([^/\\-]+)-([\w-]{6,})\.(?:m?js|cjs)(?:$|[?#])/;
|
|
10457
10458
|
const STABLE_HASHED_DIST_CHUNK_PRIORITY = ["src"];
|
|
10458
10459
|
function resolveSharedPathRoot(configService, sharedPathRoot) {
|
|
@@ -10563,11 +10564,17 @@ function isRequestGlobalsRuntimeModuleId(id) {
|
|
|
10563
10564
|
if (REG_REQUEST_GLOBAL_RUNTIME_VENDOR_ID.test(cleanedAbsoluteId)) return true;
|
|
10564
10565
|
return resolveDistChunkPackageToken(cleanedAbsoluteId)?.endsWith("web-apis") === true;
|
|
10565
10566
|
}
|
|
10567
|
+
function isWeappViteRuntimeModuleId(id) {
|
|
10568
|
+
const cleanedAbsoluteId = normalizeSharedPathCandidate(id);
|
|
10569
|
+
REG_WEAPP_VITE_RUNTIME_VENDOR_ID.lastIndex = 0;
|
|
10570
|
+
return REG_WEAPP_VITE_RUNTIME_VENDOR_ID.test(cleanedAbsoluteId);
|
|
10571
|
+
}
|
|
10566
10572
|
function resolveStableHashedDistChunkFileName(chunk) {
|
|
10567
10573
|
const candidateIds = [chunk.facadeModuleId, ...chunk.moduleIds ?? []].filter((id) => typeof id === "string");
|
|
10568
10574
|
const matchedChunks = [];
|
|
10569
10575
|
let facadeMatchedChunk;
|
|
10570
10576
|
for (const id of candidateIds) {
|
|
10577
|
+
if (isWeappViteRuntimeModuleId(id)) return "weapp-vendors/weapp-vite-runtime.js";
|
|
10571
10578
|
const cleanedAbsoluteId = normalizeSharedPathCandidate(id);
|
|
10572
10579
|
if (!path.isAbsolute(cleanedAbsoluteId)) continue;
|
|
10573
10580
|
const matched = cleanedAbsoluteId.match(REG_HASHED_DIST_CHUNK_ID);
|
|
@@ -10616,6 +10623,7 @@ function createSharedBuildResolver(configService, getSubPackageRoots) {
|
|
|
10616
10623
|
});
|
|
10617
10624
|
const resolveSharedBuildChunkName = (id, ctx) => {
|
|
10618
10625
|
if (isRequestGlobalsRuntimeModuleId(id)) return REQUEST_GLOBAL_RUNTIME_CHUNK_FILE_BASENAME.replace(/\.js$/, "");
|
|
10626
|
+
if (isWeappViteRuntimeModuleId(id)) return "weapp-vendors/weapp-vite-runtime";
|
|
10619
10627
|
if (configService.isDev) {
|
|
10620
10628
|
const stableHashedDistChunkName = resolveStableHashedDistChunkName({ facadeModuleId: id });
|
|
10621
10629
|
if (stableHashedDistChunkName) return stableHashedDistChunkName;
|
|
@@ -19436,11 +19444,13 @@ function pruneUnchangedDevHmrOutputs(ctx, bundle, rewriteOptions) {
|
|
|
19436
19444
|
const cache = ctx.runtimeState?.build?.output?.emittedSource;
|
|
19437
19445
|
if (!ctx.configService?.isDev || !cache) return;
|
|
19438
19446
|
const isHmrBuild = ctx.runtimeState?.build?.hmr?.profile?.event !== void 0;
|
|
19447
|
+
const emittedChunkFileNames = ctx.runtimeState?.build?.hmr?.lastEmittedChunkFileNames;
|
|
19439
19448
|
rewriteWevuInternalRuntimeImports(bundle, rewriteOptions);
|
|
19440
19449
|
pruneUneventedDevHmrChunks(ctx, bundle);
|
|
19441
19450
|
for (const [fileName, output] of Object.entries(bundle)) {
|
|
19442
19451
|
const source = outputSourceToString(output);
|
|
19443
|
-
|
|
19452
|
+
const shouldForceEmitCurrentHmrChunk = isHmrBuild && output.type === "chunk" && (emittedChunkFileNames?.has(fileName) === true || emittedChunkFileNames?.has(output.fileName) === true);
|
|
19453
|
+
if (isHmrBuild && !shouldForceEmitCurrentHmrChunk && cache.get(fileName) === source) {
|
|
19444
19454
|
delete bundle[fileName];
|
|
19445
19455
|
continue;
|
|
19446
19456
|
}
|
|
@@ -20582,6 +20592,33 @@ function isAssetOnlyDevHmrBundle(bundle, state) {
|
|
|
20582
20592
|
function isStableHmrSharedChunk(fileName) {
|
|
20583
20593
|
return fileName.startsWith("weapp-vendors/") || !fileName.includes("/") && fileName !== "app.js";
|
|
20584
20594
|
}
|
|
20595
|
+
function isRuntimeVendorSharedChunk(fileName) {
|
|
20596
|
+
return fileName.startsWith("weapp-vendors/") && /(?:^|[-/])[\w-]*runtime[\w-]*(?:[-.]|$)/.test(fileName);
|
|
20597
|
+
}
|
|
20598
|
+
function resolveImportedChunkId(importerFileName, imported) {
|
|
20599
|
+
if (!imported.startsWith(".")) return imported;
|
|
20600
|
+
const importerSegments = importerFileName.split("/");
|
|
20601
|
+
importerSegments.pop();
|
|
20602
|
+
for (const segment of imported.split("/")) {
|
|
20603
|
+
if (!segment || segment === ".") continue;
|
|
20604
|
+
if (segment === "..") {
|
|
20605
|
+
importerSegments.pop();
|
|
20606
|
+
continue;
|
|
20607
|
+
}
|
|
20608
|
+
importerSegments.push(segment);
|
|
20609
|
+
}
|
|
20610
|
+
return importerSegments.join("/");
|
|
20611
|
+
}
|
|
20612
|
+
function isImportedByActiveHmrChunk(fileName, bundle, activeEntryIds) {
|
|
20613
|
+
if (!activeEntryIds?.size) return false;
|
|
20614
|
+
for (const output of Object.values(bundle)) {
|
|
20615
|
+
if (output?.type !== "chunk") continue;
|
|
20616
|
+
const chunk = output;
|
|
20617
|
+
if (!chunk.facadeModuleId || !activeEntryIds.has(chunk.facadeModuleId)) continue;
|
|
20618
|
+
if ([...Array.isArray(chunk.imports) ? chunk.imports : [], ...Array.isArray(chunk.dynamicImports) ? chunk.dynamicImports : []].some((imported) => resolveImportedChunkId(chunk.fileName, imported) === fileName)) return true;
|
|
20619
|
+
}
|
|
20620
|
+
return false;
|
|
20621
|
+
}
|
|
20585
20622
|
function prunePartialHmrStableSharedChunks(bundle, state) {
|
|
20586
20623
|
if (!state.ctx.configService.isDev || !state.hmrState.hasBuiltOnce || state.hmrState.didEmitAllEntries || state.hmrState.skipSharedChunkRefresh || !state.hmrState.lastEmittedEntryIds?.size) return;
|
|
20587
20624
|
for (const [fileName, output] of Object.entries(bundle)) {
|
|
@@ -20592,6 +20629,14 @@ function prunePartialHmrStableSharedChunks(bundle, state) {
|
|
|
20592
20629
|
continue;
|
|
20593
20630
|
}
|
|
20594
20631
|
const activeEntryIds = state.hmrState.lastHmrEntryIds?.size ? state.hmrState.lastHmrEntryIds : state.hmrState.lastEmittedEntryIds;
|
|
20632
|
+
if (isRuntimeVendorSharedChunk(fileName) && isImportedByActiveHmrChunk(fileName, bundle, activeEntryIds)) {
|
|
20633
|
+
const emittedChunkFileNames = state.ctx.runtimeState?.build?.hmr?.lastEmittedChunkFileNames;
|
|
20634
|
+
if (emittedChunkFileNames) {
|
|
20635
|
+
emittedChunkFileNames.add(fileName);
|
|
20636
|
+
if (output.fileName) emittedChunkFileNames.add(output.fileName);
|
|
20637
|
+
}
|
|
20638
|
+
continue;
|
|
20639
|
+
}
|
|
20595
20640
|
if (!Array.from(knownImporters).every((entryId) => activeEntryIds?.has(entryId))) {
|
|
20596
20641
|
delete bundle[fileName];
|
|
20597
20642
|
continue;
|
|
@@ -25935,7 +25980,7 @@ async function loadAppEntry(ctx, scanState) {
|
|
|
25935
25980
|
const vueAppPath = await findVueEntry(appBasename);
|
|
25936
25981
|
let configFromVue;
|
|
25937
25982
|
if (!appConfigFile && vueAppPath) {
|
|
25938
|
-
const { extractConfigFromVue } = await import("./file-
|
|
25983
|
+
const { extractConfigFromVue } = await import("./file-BZkl3L_r.mjs");
|
|
25939
25984
|
configFromVue = await extractConfigFromVue(vueAppPath);
|
|
25940
25985
|
if (configFromVue) appConfigFile = vueAppPath;
|
|
25941
25986
|
}
|
|
@@ -84,7 +84,7 @@ function resolveAutoRoutesMacroImportPath() {
|
|
|
84
84
|
}
|
|
85
85
|
async function resolveAutoRoutesInlineSnapshot() {
|
|
86
86
|
try {
|
|
87
|
-
const { getCompilerContext } = await import("./getInstance-
|
|
87
|
+
const { getCompilerContext } = await import("./getInstance-CQ6SnI35.mjs");
|
|
88
88
|
const compilerContext = getCompilerContext();
|
|
89
89
|
const service = compilerContext.autoRoutesService;
|
|
90
90
|
const reference = service?.getReference?.();
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { $n as WebPlatform, A as Ref, Bn as WeappViteHostMeta, C as LoadConfigOptions, D as MethodDefinitions, E as InlineConfig, F as RolldownPlugin, Gn as ResolveWeappViteTargetOptions, Hn as createWeappViteHostMeta, I as RolldownPluginOption, Jn as WeappVitePlatform, Kn as ResolvedWeappViteTarget, L as RolldownWatchOptions, M as RolldownBuild, N as RolldownOptions, O as Plugin, P as RolldownOutput, Qn as WeappViteTargetKind, R as RolldownWatcher, S as CompilerContext, T as ConfigEnv, Un as isWeappViteHost, Vn as applyWeappViteHostMeta, Wn as resolveWeappViteHostMeta, Xn as WeappViteTargetDescriptor, Yn as WeappViteRuntime, Zn as WeappViteTargetInput, _ as definePageJson, a as UserConfigFnNoEnvPlain, at as WeappViteConfig, c as UserConfigFnPromise, d as Component, er as getSupportedWeappVitePlatforms, f as Page, g as defineComponentJson, h as defineAppJson, i as UserConfigFnNoEnv, j as ResolvedConfig, k as PluginOption, l as defineConfig, m as Theme, n as UserConfigExport, nr as isWebPlatform, o as UserConfigFnObject, p as Sitemap, qn as WEB_PLATFORM_ALIASES, r as UserConfigFn, rr as resolveWeappViteTarget, s as UserConfigFnObjectPlain, t as UserConfig, tr as getSupportedWeappViteTargetDescriptors, u as App, v as defineSitemapJson, w as ComputedDefinitions, y as defineThemeJson, z as ViteDevServer, zn as WEAPP_VITE_HOST_NAME } from "./config-Cxi7xvCa.mjs";
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as LayoutHostContext, c as LayoutHostResolver, d as unregisterLayoutHosts, f as waitForLayoutHost, i as LayoutHostBridge, l as registerLayoutHosts, m as createWevuComponent, n as defineProps, o as LayoutHostEntry, p as WevuComponentOptions, r as setPageLayout, s as LayoutHostResolveOptions, t as defineEmits, u as resolveLayoutHost } from "./runtime-xQwLUxkz.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/createContext.d.ts
|
|
5
5
|
interface CreateCompilerContextOptions extends Partial<LoadConfigOptions> {
|
|
@@ -12,4 +12,4 @@ interface CreateCompilerContextOptions extends Partial<LoadConfigOptions> {
|
|
|
12
12
|
*/
|
|
13
13
|
declare function createCompilerContext(options?: CreateCompilerContextOptions): Promise<CompilerContext>;
|
|
14
14
|
//#endregion
|
|
15
|
-
export { type App, type Component, type ComputedDefinitions, type ConfigEnv, type InlineConfig, type MethodDefinitions, type Page, type Plugin, type PluginOption, type Ref, ResolveWeappViteTargetOptions, type ResolvedConfig, ResolvedWeappViteTarget, type RolldownBuild, type RolldownOptions, type RolldownOutput, type RolldownPlugin, type RolldownPluginOption, type RolldownWatchOptions, type RolldownWatcher, type Sitemap, type Theme, UserConfig, UserConfigExport, UserConfigFn, UserConfigFnNoEnv, UserConfigFnNoEnvPlain, UserConfigFnObject, UserConfigFnObjectPlain, UserConfigFnPromise, type ViteDevServer, WEAPP_VITE_HOST_NAME, WEB_PLATFORM_ALIASES, type WeappViteConfig, WeappViteHostMeta, WeappVitePlatform, WeappViteRuntime, WeappViteTargetDescriptor, WeappViteTargetInput, WeappViteTargetKind, WebPlatform, type WevuComponentOptions, applyWeappViteHostMeta, createCompilerContext, createWeappViteHostMeta, createWevuComponent, defineAppJson, defineComponentJson, defineConfig, defineEmits, definePageJson, defineProps, defineSitemapJson, defineThemeJson, getSupportedWeappVitePlatforms, getSupportedWeappViteTargetDescriptors, isWeappViteHost, isWebPlatform, resolveWeappViteHostMeta, resolveWeappViteTarget, setPageLayout };
|
|
15
|
+
export { type App, type Component, type ComputedDefinitions, type ConfigEnv, type InlineConfig, type LayoutHostBridge, type LayoutHostContext, type LayoutHostEntry, type LayoutHostResolveOptions, type LayoutHostResolver, type MethodDefinitions, type Page, type Plugin, type PluginOption, type Ref, ResolveWeappViteTargetOptions, type ResolvedConfig, ResolvedWeappViteTarget, type RolldownBuild, type RolldownOptions, type RolldownOutput, type RolldownPlugin, type RolldownPluginOption, type RolldownWatchOptions, type RolldownWatcher, type Sitemap, type Theme, UserConfig, UserConfigExport, UserConfigFn, UserConfigFnNoEnv, UserConfigFnNoEnvPlain, UserConfigFnObject, UserConfigFnObjectPlain, UserConfigFnPromise, type ViteDevServer, WEAPP_VITE_HOST_NAME, WEB_PLATFORM_ALIASES, type WeappViteConfig, WeappViteHostMeta, WeappVitePlatform, WeappViteRuntime, WeappViteTargetDescriptor, WeappViteTargetInput, WeappViteTargetKind, WebPlatform, type WevuComponentOptions, applyWeappViteHostMeta, createCompilerContext, createWeappViteHostMeta, createWevuComponent, defineAppJson, defineComponentJson, defineConfig, defineEmits, definePageJson, defineProps, defineSitemapJson, defineThemeJson, getSupportedWeappVitePlatforms, getSupportedWeappViteTargetDescriptors, isWeappViteHost, isWebPlatform, registerLayoutHosts, resolveLayoutHost, resolveWeappViteHostMeta, resolveWeappViteTarget, setPageLayout, unregisterLayoutHosts, waitForLayoutHost };
|
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-
|
|
5
|
-
import {
|
|
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 };
|
|
4
|
+
import { c as getSupportedWeappViteTargetDescriptors, l as isWebPlatform, o as WEB_PLATFORM_ALIASES, s as getSupportedWeappVitePlatforms, t as createCompilerContext, u as resolveWeappViteTarget } from "./createContext-Bm3wVI4b.mjs";
|
|
5
|
+
import { a as resolveLayoutHost, c as createWevuComponent, i as registerLayoutHosts, n as defineProps, o as unregisterLayoutHosts, r as setPageLayout, s as waitForLayoutHost, t as defineEmits } from "./runtime-CRoKWQZn.mjs";
|
|
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, registerLayoutHosts, resolveLayoutHost, resolveWeappViteHostMeta, resolveWeappViteTarget, setPageLayout, unregisterLayoutHosts, waitForLayoutHost };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { createMiniProgramLayoutHostRegistry, resolveMiniProgramPageKeys, resolveMiniProgramPlatform, supportsMiniProgramRuntimeCapability } from "@weapp-core/shared";
|
|
2
|
+
import { WEVU_PAGE_LAYOUT_SETTER_KEY } from "@weapp-core/constants";
|
|
3
|
+
import { defineComponent } from "wevu";
|
|
4
|
+
//#region src/plugins/vue/createWevuComponent.ts
|
|
5
|
+
/**
|
|
6
|
+
* 从 Vue SFC 的 options 创建 wevu 组件
|
|
7
|
+
* 同时支持 Vue 2 风格(Options API)与 Vue 3 风格(Composition API)
|
|
8
|
+
*
|
|
9
|
+
* 始终使用 defineComponent(其内部会调用小程序的 Component())。
|
|
10
|
+
* 在微信小程序中,Component() 可以同时定义页面与组件。
|
|
11
|
+
*/
|
|
12
|
+
function createWevuComponent(options) {
|
|
13
|
+
const { properties, ...restOptions } = options;
|
|
14
|
+
const mpOptions = {};
|
|
15
|
+
if (properties) mpOptions.properties = properties;
|
|
16
|
+
defineComponent({
|
|
17
|
+
...restOptions,
|
|
18
|
+
...mpOptions
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/plugins/vue/nativeLayoutHost.ts
|
|
23
|
+
const layoutHostRegistry = createMiniProgramLayoutHostRegistry();
|
|
24
|
+
function resolveCurrentPageInstance$1() {
|
|
25
|
+
if (!supportsMiniProgramRuntimeCapability(resolveMiniProgramPlatform(import.meta.env?.PLATFORM), "globalPageStack")) return;
|
|
26
|
+
const getCurrentPagesFn = globalThis.getCurrentPages;
|
|
27
|
+
if (typeof getCurrentPagesFn !== "function") return;
|
|
28
|
+
try {
|
|
29
|
+
const pages = getCurrentPagesFn();
|
|
30
|
+
return pages[pages.length - 1];
|
|
31
|
+
} catch {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function resolvePageKeys(page) {
|
|
36
|
+
return resolveMiniProgramPageKeys(page);
|
|
37
|
+
}
|
|
38
|
+
function resolvePageFromContext(context) {
|
|
39
|
+
return context ?? resolveCurrentPageInstance$1();
|
|
40
|
+
}
|
|
41
|
+
function resolveHostEntry(entry) {
|
|
42
|
+
return typeof entry === "function" ? entry() : entry;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 为当前原生 layout 注册宿主组件,页面可通过 resolveLayoutHost()/waitForLayoutHost() 访问。
|
|
46
|
+
*/
|
|
47
|
+
function registerLayoutHosts(hosts, context) {
|
|
48
|
+
const keys = Array.isArray(hosts) ? hosts : Object.keys(hosts);
|
|
49
|
+
if (!keys.length) return null;
|
|
50
|
+
const pageKeys = resolvePageKeys(resolvePageFromContext());
|
|
51
|
+
if (pageKeys.length === 0) return null;
|
|
52
|
+
const bridge = {
|
|
53
|
+
context,
|
|
54
|
+
keys,
|
|
55
|
+
resolveHost(key) {
|
|
56
|
+
if (!keys.includes(key)) return null;
|
|
57
|
+
if (!Array.isArray(hosts)) return resolveHostEntry(hosts[key]) ?? null;
|
|
58
|
+
return context?.selectComponent?.(key) ?? null;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
return layoutHostRegistry.register(keys, bridge, pageKeys) ? bridge : null;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 移除当前原生 layout 注册的宿主组件。
|
|
65
|
+
*/
|
|
66
|
+
function unregisterLayoutHosts(bridge) {
|
|
67
|
+
if (!bridge) return false;
|
|
68
|
+
return layoutHostRegistry.unregisterBridge(bridge);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 解析当前页面 layout 内暴露的宿主组件。
|
|
72
|
+
*/
|
|
73
|
+
function resolveLayoutHost(key, options = {}) {
|
|
74
|
+
const page = resolvePageFromContext(options.context);
|
|
75
|
+
return layoutHostRegistry.resolveHost(key, resolvePageKeys(page), (bridge, key) => bridge.resolveHost(key));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 等待当前页面 layout 宿主组件可用。
|
|
79
|
+
*/
|
|
80
|
+
function waitForLayoutHost(key, options = {}) {
|
|
81
|
+
return layoutHostRegistry.waitForHost(key, () => resolvePageKeys(resolvePageFromContext(options.context)), (bridge, key) => bridge.resolveHost(key), options);
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/plugins/vue/nativePageLayout.ts
|
|
85
|
+
function resolveCurrentPageInstance() {
|
|
86
|
+
if (!supportsMiniProgramRuntimeCapability(resolveMiniProgramPlatform(import.meta.env?.PLATFORM), "globalPageStack")) return;
|
|
87
|
+
const getCurrentPagesFn = globalThis.getCurrentPages;
|
|
88
|
+
if (typeof getCurrentPagesFn !== "function") return;
|
|
89
|
+
try {
|
|
90
|
+
const pages = getCurrentPagesFn();
|
|
91
|
+
return pages[pages.length - 1];
|
|
92
|
+
} catch {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 为原生 Page() 页面切换 layout。
|
|
98
|
+
*/
|
|
99
|
+
function setPageLayout(layout, props) {
|
|
100
|
+
const pageSetter = resolveCurrentPageInstance()?.[WEVU_PAGE_LAYOUT_SETTER_KEY];
|
|
101
|
+
if (typeof pageSetter === "function") {
|
|
102
|
+
pageSetter(layout, props);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
throw new Error("setPageLayout() 未找到当前页面实例。请在页面生命周期、事件回调或当前页面上下文中调用。");
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/plugins/vue/runtimeMacros.ts
|
|
109
|
+
/**
|
|
110
|
+
* 说明:Vue 3 风格的 props 声明(用于类型提示)
|
|
111
|
+
*/
|
|
112
|
+
function defineProps(props) {
|
|
113
|
+
return props;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 说明:Vue 3 风格的 emits 声明(用于类型提示)
|
|
117
|
+
*/
|
|
118
|
+
function defineEmits(emits) {
|
|
119
|
+
return emits;
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
export { resolveLayoutHost as a, createWevuComponent as c, registerLayoutHosts as i, defineProps as n, unregisterLayoutHosts as o, setPageLayout as r, waitForLayoutHost as s, defineEmits as t };
|
|
@@ -21,6 +21,37 @@ interface WevuComponentOptions<D extends object = Record<string, any>, C extends
|
|
|
21
21
|
*/
|
|
22
22
|
declare function createWevuComponent(options: WevuComponentOptions): void;
|
|
23
23
|
//#endregion
|
|
24
|
+
//#region src/plugins/vue/nativeLayoutHost.d.ts
|
|
25
|
+
type LayoutHostContext = Record<string, any>;
|
|
26
|
+
type LayoutHostResolver = (key: string) => unknown;
|
|
27
|
+
type LayoutHostEntry = unknown | (() => unknown);
|
|
28
|
+
interface LayoutHostBridge {
|
|
29
|
+
context?: LayoutHostContext;
|
|
30
|
+
keys: string[];
|
|
31
|
+
resolveHost: LayoutHostResolver;
|
|
32
|
+
}
|
|
33
|
+
interface LayoutHostResolveOptions {
|
|
34
|
+
context?: LayoutHostContext;
|
|
35
|
+
interval?: number;
|
|
36
|
+
retries?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 为当前原生 layout 注册宿主组件,页面可通过 resolveLayoutHost()/waitForLayoutHost() 访问。
|
|
40
|
+
*/
|
|
41
|
+
declare function registerLayoutHosts(hosts: Record<string, LayoutHostEntry> | string[], context?: LayoutHostContext): LayoutHostBridge | null;
|
|
42
|
+
/**
|
|
43
|
+
* 移除当前原生 layout 注册的宿主组件。
|
|
44
|
+
*/
|
|
45
|
+
declare function unregisterLayoutHosts(bridge: LayoutHostBridge | null | undefined): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* 解析当前页面 layout 内暴露的宿主组件。
|
|
48
|
+
*/
|
|
49
|
+
declare function resolveLayoutHost<T = any>(key: string, options?: LayoutHostResolveOptions): NonNullable<T> | null;
|
|
50
|
+
/**
|
|
51
|
+
* 等待当前页面 layout 宿主组件可用。
|
|
52
|
+
*/
|
|
53
|
+
declare function waitForLayoutHost<T = any>(key: string, options?: LayoutHostResolveOptions): Promise<T | null>;
|
|
54
|
+
//#endregion
|
|
24
55
|
//#region src/plugins/vue/nativePageLayout.d.ts
|
|
25
56
|
type ResolveTypedPageLayoutName = keyof WevuPageLayoutMap extends never ? string : Extract<keyof WevuPageLayoutMap, string>;
|
|
26
57
|
type ResolveTypedPageLayoutProps<Name extends string> = Name extends keyof WevuPageLayoutMap ? WevuPageLayoutMap[Name] : Record<string, any>;
|
|
@@ -37,4 +68,4 @@ declare function defineProps<T extends Record<string, any>>(props: T): T;
|
|
|
37
68
|
*/
|
|
38
69
|
declare function defineEmits<T extends Record<string, any> | string[]>(emits: T): T;
|
|
39
70
|
//#endregion
|
|
40
|
-
export {
|
|
71
|
+
export { LayoutHostContext as a, LayoutHostResolver as c, unregisterLayoutHosts as d, waitForLayoutHost as f, LayoutHostBridge as i, registerLayoutHosts as l, createWevuComponent as m, defineProps as n, LayoutHostEntry as o, WevuComponentOptions as p, setPageLayout as r, LayoutHostResolveOptions as s, defineEmits as t, resolveLayoutHost as u };
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { type WevuComponentOptions, createWevuComponent, defineEmits, defineProps, setPageLayout };
|
|
1
|
+
import { a as LayoutHostContext, c as LayoutHostResolver, d as unregisterLayoutHosts, f as waitForLayoutHost, i as LayoutHostBridge, l as registerLayoutHosts, m as createWevuComponent, n as defineProps, o as LayoutHostEntry, p as WevuComponentOptions, r as setPageLayout, s as LayoutHostResolveOptions, t as defineEmits, u as resolveLayoutHost } from "./runtime-xQwLUxkz.mjs";
|
|
2
|
+
export { type LayoutHostBridge, type LayoutHostContext, type LayoutHostEntry, type LayoutHostResolveOptions, type LayoutHostResolver, type WevuComponentOptions, createWevuComponent, defineEmits, defineProps, registerLayoutHosts, resolveLayoutHost, setPageLayout, unregisterLayoutHosts, waitForLayoutHost };
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { createWevuComponent, defineEmits, defineProps, setPageLayout };
|
|
1
|
+
import { a as resolveLayoutHost, c as createWevuComponent, i as registerLayoutHosts, n as defineProps, o as unregisterLayoutHosts, r as setPageLayout, s as waitForLayoutHost, t as defineEmits } from "./runtime-CRoKWQZn.mjs";
|
|
2
|
+
export { createWevuComponent, defineEmits, defineProps, registerLayoutHosts, resolveLayoutHost, setPageLayout, unregisterLayoutHosts, waitForLayoutHost };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weapp-vite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.17.
|
|
4
|
+
"version": "6.17.3",
|
|
5
5
|
"description": "weapp-vite 一个现代化的小程序打包工具",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -111,30 +111,30 @@
|
|
|
111
111
|
"pathe": "^2.0.3",
|
|
112
112
|
"picomatch": "^4.0.4",
|
|
113
113
|
"postcss": "^8.5.15",
|
|
114
|
-
"rolldown": "1.1.
|
|
114
|
+
"rolldown": "1.1.3",
|
|
115
115
|
"rolldown-plugin-dts": "0.26.0",
|
|
116
116
|
"semver": "^7.8.5",
|
|
117
117
|
"typescript": "^6.0.3",
|
|
118
|
-
"vite": "8.0
|
|
118
|
+
"vite": "8.1.0",
|
|
119
119
|
"vite-tsconfig-paths": "^6.1.1",
|
|
120
120
|
"vue": "^3.5.38",
|
|
121
121
|
"vue-tsc": "^3.3.5",
|
|
122
122
|
"@weapp-core/constants": "0.1.12",
|
|
123
|
-
"@weapp-core/init": "6.0.
|
|
124
|
-
"@weapp-core/schematics": "6.0.4",
|
|
125
|
-
"@weapp-core/shared": "3.0.4",
|
|
123
|
+
"@weapp-core/init": "6.0.11",
|
|
126
124
|
"@weapp-core/logger": "3.1.1",
|
|
127
|
-
"@weapp-
|
|
125
|
+
"@weapp-core/schematics": "6.0.4",
|
|
126
|
+
"@weapp-core/shared": "3.0.5",
|
|
127
|
+
"@weapp-vite/ast": "6.17.3",
|
|
128
128
|
"@weapp-vite/mcp": "1.4.6",
|
|
129
|
-
"@wevu/api": "0.2.10",
|
|
130
129
|
"@weapp-vite/miniprogram-automator": "1.2.5",
|
|
131
|
-
"@
|
|
130
|
+
"@weapp-vite/volar": "2.1.0",
|
|
131
|
+
"@weapp-vite/web": "1.3.33",
|
|
132
|
+
"@wevu/api": "0.2.11",
|
|
133
|
+
"@wevu/web-apis": "1.2.25",
|
|
132
134
|
"rolldown-require": "2.0.19",
|
|
133
135
|
"vite-plugin-performance": "2.0.1",
|
|
134
|
-
"weapp-ide-cli": "5.4.
|
|
135
|
-
"
|
|
136
|
-
"wevu": "6.17.1",
|
|
137
|
-
"@weapp-vite/web": "1.3.32"
|
|
136
|
+
"weapp-ide-cli": "5.4.10",
|
|
137
|
+
"wevu": "6.17.3"
|
|
138
138
|
},
|
|
139
139
|
"publishConfig": {
|
|
140
140
|
"access": "public",
|
|
@@ -159,7 +159,7 @@
|
|
|
159
159
|
"benchmark:auto-import:ci": "node --import tsx scripts/benchmark-auto-import-ci.ts",
|
|
160
160
|
"test:dev": "vitest",
|
|
161
161
|
"test": "vitest run",
|
|
162
|
-
"test:types": "cd test-d/auto-routes-define-app-json && tsd && cd ../config-define-config && tsd && cd ../internal-src-types && tsd",
|
|
162
|
+
"test:types": "cd test-d/auto-routes-define-app-json && tsd && cd ../config-define-config && tsd && cd ../internal-src-types && tsd && cd ../runtime-public-types && tsd",
|
|
163
163
|
"lint:src": "eslint src --ext .ts",
|
|
164
164
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
165
165
|
"sync": "cnpm sync weapp-vite"
|
package/dist/file-C206GmuT.mjs
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { resolveMiniProgramPlatform, supportsMiniProgramRuntimeCapability } from "@weapp-core/shared";
|
|
2
|
-
import { WEVU_PAGE_LAYOUT_SETTER_KEY } from "@weapp-core/constants";
|
|
3
|
-
import { defineComponent } from "wevu";
|
|
4
|
-
//#region src/plugins/vue/createWevuComponent.ts
|
|
5
|
-
/**
|
|
6
|
-
* 从 Vue SFC 的 options 创建 wevu 组件
|
|
7
|
-
* 同时支持 Vue 2 风格(Options API)与 Vue 3 风格(Composition API)
|
|
8
|
-
*
|
|
9
|
-
* 始终使用 defineComponent(其内部会调用小程序的 Component())。
|
|
10
|
-
* 在微信小程序中,Component() 可以同时定义页面与组件。
|
|
11
|
-
*/
|
|
12
|
-
function createWevuComponent(options) {
|
|
13
|
-
const { properties, ...restOptions } = options;
|
|
14
|
-
const mpOptions = {};
|
|
15
|
-
if (properties) mpOptions.properties = properties;
|
|
16
|
-
defineComponent({
|
|
17
|
-
...restOptions,
|
|
18
|
-
...mpOptions
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/plugins/vue/nativePageLayout.ts
|
|
23
|
-
function resolveCurrentPageInstance() {
|
|
24
|
-
if (!supportsMiniProgramRuntimeCapability(resolveMiniProgramPlatform(import.meta.env?.PLATFORM), "globalPageStack")) return;
|
|
25
|
-
const getCurrentPagesFn = globalThis.getCurrentPages;
|
|
26
|
-
if (typeof getCurrentPagesFn !== "function") return;
|
|
27
|
-
try {
|
|
28
|
-
const pages = getCurrentPagesFn();
|
|
29
|
-
return pages[pages.length - 1];
|
|
30
|
-
} catch {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* 为原生 Page() 页面切换 layout。
|
|
36
|
-
*/
|
|
37
|
-
function setPageLayout(layout, props) {
|
|
38
|
-
const pageSetter = resolveCurrentPageInstance()?.[WEVU_PAGE_LAYOUT_SETTER_KEY];
|
|
39
|
-
if (typeof pageSetter === "function") {
|
|
40
|
-
pageSetter(layout, props);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
throw new Error("setPageLayout() 未找到当前页面实例。请在页面生命周期、事件回调或当前页面上下文中调用。");
|
|
44
|
-
}
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/plugins/vue/runtimeMacros.ts
|
|
47
|
-
/**
|
|
48
|
-
* 说明:Vue 3 风格的 props 声明(用于类型提示)
|
|
49
|
-
*/
|
|
50
|
-
function defineProps(props) {
|
|
51
|
-
return props;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* 说明:Vue 3 风格的 emits 声明(用于类型提示)
|
|
55
|
-
*/
|
|
56
|
-
function defineEmits(emits) {
|
|
57
|
-
return emits;
|
|
58
|
-
}
|
|
59
|
-
//#endregion
|
|
60
|
-
export { createWevuComponent as i, defineProps as n, setPageLayout as r, defineEmits as t };
|