weapp-vite 6.11.5 → 6.11.7
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
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as getCompilerContext } from "./createContext-
|
|
1
|
+
import { i as getCompilerContext } from "./createContext-DZgOqIMU.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,16 +1,17 @@
|
|
|
1
|
-
import { c as normalizeMiniPlatform, d as SHARED_CHUNK_VIRTUAL_PREFIX, f as resolveWeappConfigFile, g as
|
|
1
|
+
import { _ as isPathInside, c as normalizeMiniPlatform, d as SHARED_CHUNK_VIRTUAL_PREFIX, f as resolveWeappConfigFile, g as createCjsConfigLoadError, h as parseCommentJson, l as resolveMiniPlatform, m as getProjectConfigFileName, n as syncProjectSupportFiles, o as formatBytes, p as checkRuntime, r as syncManagedTsconfigBootstrapFiles, s as DEFAULT_MP_PLATFORM, t as createCompilerContext, u as createSharedBuildConfig } from "./createContext-DZgOqIMU.mjs";
|
|
2
2
|
import { r as logger_default, t as colors } from "./logger-gutcwWKE.mjs";
|
|
3
|
-
import { f as VERSION } from "./file-
|
|
3
|
+
import { f as VERSION } from "./file-rRQhPOL8.mjs";
|
|
4
4
|
import { resolveWeappMcpConfig, startWeappViteMcpServer } from "./mcp.mjs";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
5
6
|
import { defu } from "@weapp-core/shared";
|
|
6
7
|
import path, { posix } from "pathe";
|
|
7
8
|
import fs from "fs-extra";
|
|
8
9
|
import process from "node:process";
|
|
9
10
|
import { build, createServer, loadConfigFromFile } from "vite";
|
|
10
|
-
import { getPackageInfoSync } from "local-pkg";
|
|
11
11
|
import { execFile } from "node:child_process";
|
|
12
12
|
import { Buffer } from "node:buffer";
|
|
13
|
-
import fs$1 from "node:fs";
|
|
13
|
+
import fs$1 from "node:fs/promises";
|
|
14
|
+
import fs$2 from "node:fs";
|
|
14
15
|
import { cac } from "cac";
|
|
15
16
|
import { resolveCommand } from "package-manager-detector/commands";
|
|
16
17
|
import { promisify } from "node:util";
|
|
@@ -315,33 +316,131 @@ async function analyzeSubpackages(ctx) {
|
|
|
315
316
|
//#region src/cli/analyze/dashboard.ts
|
|
316
317
|
const ANALYZE_GLOBAL_KEY = "__WEAPP_VITE_ANALYZE_RESULT__";
|
|
317
318
|
const ANALYZE_DASHBOARD_PACKAGE_NAME = "@weapp-vite/dashboard";
|
|
319
|
+
const ANALYZE_SSE_PATH = "/__weapp_vite_analyze";
|
|
320
|
+
const require = createRequire(import.meta.url);
|
|
318
321
|
function createInstallCommand(agent) {
|
|
319
322
|
const resolved = resolveCommand(agent ?? "npm", "install", [ANALYZE_DASHBOARD_PACKAGE_NAME]);
|
|
320
323
|
if (!resolved) return `npm install ${ANALYZE_DASHBOARD_PACKAGE_NAME}`;
|
|
321
324
|
return `${resolved.command} ${resolved.args.join(" ")}`;
|
|
322
325
|
}
|
|
326
|
+
function readDashboardManifest(packageJsonPath) {
|
|
327
|
+
try {
|
|
328
|
+
return parseCommentJson(fs$2.readFileSync(packageJsonPath, "utf8"));
|
|
329
|
+
} catch {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function resolveDashboardSourceRoot(packageRoot, manifest) {
|
|
334
|
+
const devRoot = manifest?.weappViteDashboard?.devRoot ?? ".";
|
|
335
|
+
const devConfigFile = manifest?.weappViteDashboard?.devConfigFile ?? "vite.config.ts";
|
|
336
|
+
const resolvedRoot = path.resolve(packageRoot, devRoot);
|
|
337
|
+
const viteConfigPath = path.resolve(packageRoot, devConfigFile);
|
|
338
|
+
const srcRoot = path.join(resolvedRoot, "src");
|
|
339
|
+
if (!fs$2.existsSync(viteConfigPath) || !fs$2.existsSync(srcRoot)) return;
|
|
340
|
+
return {
|
|
341
|
+
root: resolvedRoot,
|
|
342
|
+
configFile: viteConfigPath
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
function resolveDashboardDistRoot(packageRoot, manifest) {
|
|
346
|
+
const distDir = manifest?.weappViteDashboard?.distDir ?? "dist";
|
|
347
|
+
const distRoot = path.resolve(packageRoot, distDir);
|
|
348
|
+
if (!fs$2.existsSync(distRoot)) return;
|
|
349
|
+
return { root: distRoot };
|
|
350
|
+
}
|
|
323
351
|
function resolveDashboardRoot(options) {
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
352
|
+
const resolvePaths = options?.cwd && options.cwd !== process.cwd() ? [options.cwd, process.cwd()] : options?.cwd ? [options.cwd] : void 0;
|
|
353
|
+
let dashboardPackageRoot;
|
|
354
|
+
let dashboardManifest;
|
|
355
|
+
try {
|
|
356
|
+
const dashboardPackageJsonPath = require.resolve(`${ANALYZE_DASHBOARD_PACKAGE_NAME}/package.json`, { paths: resolvePaths });
|
|
357
|
+
dashboardPackageRoot = path.dirname(dashboardPackageJsonPath);
|
|
358
|
+
dashboardManifest = readDashboardManifest(dashboardPackageJsonPath);
|
|
359
|
+
} catch {
|
|
360
|
+
dashboardPackageRoot = void 0;
|
|
361
|
+
dashboardManifest = void 0;
|
|
362
|
+
}
|
|
363
|
+
if (dashboardPackageRoot) {
|
|
364
|
+
if (options?.watch) {
|
|
365
|
+
const sourceResolved = resolveDashboardSourceRoot(dashboardPackageRoot, dashboardManifest);
|
|
366
|
+
if (sourceResolved) return sourceResolved;
|
|
367
|
+
}
|
|
368
|
+
const distResolved = resolveDashboardDistRoot(dashboardPackageRoot, dashboardManifest);
|
|
369
|
+
if (distResolved) return distResolved;
|
|
370
|
+
}
|
|
371
|
+
logger_default.warn(`[weapp-vite ui] 未安装可选仪表盘包 ${colors.bold(colors.green(ANALYZE_DASHBOARD_PACKAGE_NAME))},已自动降级关闭 dashboard 能力。`);
|
|
328
372
|
logger_default.info(`如需启用,请执行 ${colors.bold(colors.green(createInstallCommand(options?.packageManagerAgent)))}`);
|
|
329
373
|
}
|
|
330
|
-
function createAnalyzeHtmlPlugin(state, onServerInstance) {
|
|
374
|
+
function createAnalyzeHtmlPlugin(state, onServerInstance, onBroadcastReady) {
|
|
375
|
+
const sseClients = /* @__PURE__ */ new Set();
|
|
376
|
+
const hotBridgeScript = `
|
|
377
|
+
const applyAnalyzePayload = (payload) => {
|
|
378
|
+
window.${ANALYZE_GLOBAL_KEY} = payload
|
|
379
|
+
window.dispatchEvent(new CustomEvent('weapp-analyze:update', { detail: payload }))
|
|
380
|
+
}
|
|
381
|
+
const source = new EventSource('${ANALYZE_SSE_PATH}')
|
|
382
|
+
source.onmessage = (event) => {
|
|
383
|
+
try {
|
|
384
|
+
applyAnalyzePayload(JSON.parse(event.data))
|
|
385
|
+
}
|
|
386
|
+
catch {}
|
|
387
|
+
}
|
|
388
|
+
if (import.meta.hot) {
|
|
389
|
+
import.meta.hot.on('weapp-analyze:update', (payload) => {
|
|
390
|
+
applyAnalyzePayload(payload)
|
|
391
|
+
})
|
|
392
|
+
}
|
|
393
|
+
`.trim();
|
|
394
|
+
const broadcast = (payload) => {
|
|
395
|
+
const serialized = `data: ${JSON.stringify(payload)}\n\n`;
|
|
396
|
+
for (const client of sseClients) client.write(serialized);
|
|
397
|
+
};
|
|
398
|
+
onBroadcastReady(broadcast);
|
|
331
399
|
return {
|
|
332
400
|
name: "weapp-vite-analyze-html",
|
|
333
401
|
transformIndexHtml(html) {
|
|
334
402
|
return {
|
|
335
403
|
html,
|
|
336
|
-
tags: [
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
404
|
+
tags: [
|
|
405
|
+
{
|
|
406
|
+
tag: "script",
|
|
407
|
+
children: `window.${ANALYZE_GLOBAL_KEY} = ${JSON.stringify(state.current)}`,
|
|
408
|
+
injectTo: "head-prepend"
|
|
409
|
+
},
|
|
410
|
+
{
|
|
411
|
+
tag: "script",
|
|
412
|
+
attrs: {
|
|
413
|
+
type: "module",
|
|
414
|
+
src: "/@vite/client"
|
|
415
|
+
},
|
|
416
|
+
injectTo: "head"
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
tag: "script",
|
|
420
|
+
attrs: { type: "module" },
|
|
421
|
+
children: hotBridgeScript,
|
|
422
|
+
injectTo: "body"
|
|
423
|
+
}
|
|
424
|
+
]
|
|
341
425
|
};
|
|
342
426
|
},
|
|
343
427
|
configureServer(server) {
|
|
344
428
|
onServerInstance(server);
|
|
429
|
+
server.middlewares.use((req, res, next) => {
|
|
430
|
+
if (req.url !== ANALYZE_SSE_PATH) {
|
|
431
|
+
next();
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
res.statusCode = 200;
|
|
435
|
+
res.setHeader("Content-Type", "text/event-stream");
|
|
436
|
+
res.setHeader("Cache-Control", "no-cache, no-transform");
|
|
437
|
+
res.setHeader("Connection", "keep-alive");
|
|
438
|
+
res.write(`data: ${JSON.stringify(state.current)}\n\n`);
|
|
439
|
+
sseClients.add(res);
|
|
440
|
+
req.on("close", () => {
|
|
441
|
+
sseClients.delete(res);
|
|
442
|
+
});
|
|
443
|
+
});
|
|
345
444
|
}
|
|
346
445
|
};
|
|
347
446
|
}
|
|
@@ -374,24 +473,32 @@ async function waitForServerExit(server) {
|
|
|
374
473
|
async function startAnalyzeDashboard(result, options) {
|
|
375
474
|
const resolved = resolveDashboardRoot(options);
|
|
376
475
|
if (!resolved) return;
|
|
377
|
-
const { root } = resolved;
|
|
476
|
+
const { root, configFile } = resolved;
|
|
378
477
|
const state = { current: result };
|
|
379
478
|
let serverRef;
|
|
380
|
-
|
|
479
|
+
let broadcastAnalyzeResult;
|
|
480
|
+
const plugins = [createAnalyzeHtmlPlugin(state, (server) => {
|
|
481
|
+
serverRef = server;
|
|
482
|
+
}, (broadcast) => {
|
|
483
|
+
broadcastAnalyzeResult = broadcast;
|
|
484
|
+
})];
|
|
485
|
+
const serverOptions = {
|
|
381
486
|
root,
|
|
487
|
+
configFile: configFile ?? false,
|
|
382
488
|
clearScreen: false,
|
|
383
489
|
appType: "spa",
|
|
384
490
|
publicDir: false,
|
|
385
|
-
plugins
|
|
386
|
-
serverRef = server;
|
|
387
|
-
})],
|
|
491
|
+
plugins,
|
|
388
492
|
server: {
|
|
389
493
|
host: "127.0.0.1",
|
|
390
|
-
port: 0
|
|
494
|
+
port: 0,
|
|
495
|
+
watch: { ignored: ["**/*"] }
|
|
391
496
|
},
|
|
392
497
|
logLevel: "error"
|
|
393
|
-
}
|
|
394
|
-
await
|
|
498
|
+
};
|
|
499
|
+
const server = await createServer(serverOptions);
|
|
500
|
+
const requestedPort = typeof serverOptions.server?.port === "number" ? serverOptions.server.port : void 0;
|
|
501
|
+
await server.listen(requestedPort);
|
|
395
502
|
serverRef ??= server;
|
|
396
503
|
server.printUrls();
|
|
397
504
|
const urls = (() => {
|
|
@@ -405,6 +512,7 @@ async function startAnalyzeDashboard(result, options) {
|
|
|
405
512
|
event: "weapp-analyze:update",
|
|
406
513
|
data: state.current
|
|
407
514
|
});
|
|
515
|
+
broadcastAnalyzeResult?.(state.current);
|
|
408
516
|
const handle = {
|
|
409
517
|
async update(nextResult) {
|
|
410
518
|
state.current = nextResult;
|
|
@@ -413,6 +521,7 @@ async function startAnalyzeDashboard(result, options) {
|
|
|
413
521
|
event: "weapp-analyze:update",
|
|
414
522
|
data: nextResult
|
|
415
523
|
});
|
|
524
|
+
broadcastAnalyzeResult?.(nextResult);
|
|
416
525
|
},
|
|
417
526
|
waitForExit: () => waitPromise,
|
|
418
527
|
close: async () => {
|
|
@@ -421,12 +530,16 @@ async function startAnalyzeDashboard(result, options) {
|
|
|
421
530
|
urls
|
|
422
531
|
};
|
|
423
532
|
if (options?.watch) {
|
|
424
|
-
|
|
425
|
-
|
|
533
|
+
if (!options.silentStartupLog) {
|
|
534
|
+
logger_default.info("weapp-vite UI 已启动(分析视图,实时模式),按 Ctrl+C 退出。");
|
|
535
|
+
for (const url of handle.urls) logger_default.info(` ➜ ${colors.bold(colors.cyan(url))}`);
|
|
536
|
+
}
|
|
426
537
|
return handle;
|
|
427
538
|
}
|
|
428
|
-
|
|
429
|
-
|
|
539
|
+
if (!options?.silentStartupLog) {
|
|
540
|
+
logger_default.info("weapp-vite UI 已启动(分析视图,静态模式),按 Ctrl+C 退出。");
|
|
541
|
+
for (const url of handle.urls) logger_default.info(` ➜ ${colors.bold(colors.cyan(url))}`);
|
|
542
|
+
}
|
|
430
543
|
await waitPromise;
|
|
431
544
|
}
|
|
432
545
|
//#endregion
|
|
@@ -455,6 +568,9 @@ function coerceBooleanOption(value) {
|
|
|
455
568
|
if (typeof value === "number") return value !== 0;
|
|
456
569
|
return Boolean(value);
|
|
457
570
|
}
|
|
571
|
+
function isUiEnabled(options) {
|
|
572
|
+
return Boolean(options.ui || options.analyze);
|
|
573
|
+
}
|
|
458
574
|
//#endregion
|
|
459
575
|
//#region src/cli/runtime.ts
|
|
460
576
|
function logRuntimeTarget(targets, options = {}) {
|
|
@@ -480,6 +596,14 @@ function resolveRuntimeTargets(options) {
|
|
|
480
596
|
rawPlatform
|
|
481
597
|
};
|
|
482
598
|
const normalized = normalizeMiniPlatform(rawPlatform);
|
|
599
|
+
const lowerRawPlatform = rawPlatform.toLowerCase();
|
|
600
|
+
if (lowerRawPlatform === "all" || lowerRawPlatform === "both") return {
|
|
601
|
+
runMini: true,
|
|
602
|
+
runWeb: true,
|
|
603
|
+
mpPlatform: void 0,
|
|
604
|
+
label: "weapp + web",
|
|
605
|
+
rawPlatform
|
|
606
|
+
};
|
|
483
607
|
if (!normalized) return {
|
|
484
608
|
runMini: true,
|
|
485
609
|
runWeb: false,
|
|
@@ -676,18 +800,19 @@ function registerAnalyzeCommand(cli) {
|
|
|
676
800
|
//#endregion
|
|
677
801
|
//#region src/cli/logBuildAppFinish.ts
|
|
678
802
|
let logBuildAppFinishOnlyShowOnce = false;
|
|
803
|
+
function collectServerUrls(webServer) {
|
|
804
|
+
const urls = webServer?.resolvedUrls;
|
|
805
|
+
if (!urls) return [];
|
|
806
|
+
return [...urls.local ?? [], ...urls.network ?? []];
|
|
807
|
+
}
|
|
679
808
|
function logBuildAppFinish(configService, webServer, options = {}) {
|
|
680
809
|
if (logBuildAppFinishOnlyShowOnce) return;
|
|
681
|
-
const { skipMini = false, skipWeb = false } = options;
|
|
810
|
+
const { skipMini = false, skipWeb = false, uiUrls = [] } = options;
|
|
811
|
+
const webUrls = skipWeb ? [] : collectServerUrls(webServer);
|
|
682
812
|
if (skipMini) {
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
if (candidates.length > 0) {
|
|
687
|
-
logger_default.success("Web 运行时已启动,浏览器访问:");
|
|
688
|
-
for (const url of candidates) logger_default.info(` ➜ ${colors.cyan(url)}`);
|
|
689
|
-
} else logger_default.success("Web 运行时已启动");
|
|
690
|
-
} else logger_default.success("Web 运行时已启动");
|
|
813
|
+
logger_default.success("开发服务已就绪:");
|
|
814
|
+
if (webUrls.length > 0) logger_default.info(`Web:${colors.cyan(webUrls[0])}`);
|
|
815
|
+
else logger_default.info("Web:已启动");
|
|
691
816
|
logBuildAppFinishOnlyShowOnce = true;
|
|
692
817
|
return;
|
|
693
818
|
}
|
|
@@ -696,18 +821,13 @@ function logBuildAppFinish(configService, webServer, options = {}) {
|
|
|
696
821
|
args: ["run", "open"]
|
|
697
822
|
};
|
|
698
823
|
const devCommand = `${command} ${args.join(" ")}`;
|
|
699
|
-
logger_default.success("
|
|
700
|
-
logger_default.info(
|
|
824
|
+
logger_default.success("开发服务已就绪:");
|
|
825
|
+
logger_default.info(`小程序:执行 ${colors.bold(colors.green(devCommand))},或手动导入 ${colors.green(getProjectConfigFileName(configService.platform))}`);
|
|
826
|
+
if (uiUrls.length > 0) logger_default.info(`UI:${colors.cyan(uiUrls[0])}`);
|
|
827
|
+
else if (!skipMini) logger_default.info("UI:未启用");
|
|
828
|
+
if (webUrls.length > 0) logger_default.info(`Web:${colors.cyan(webUrls[0])}`);
|
|
701
829
|
const projectConfigFileName = getProjectConfigFileName(configService.platform);
|
|
702
|
-
logger_default.info(
|
|
703
|
-
if (!skipWeb && webServer) {
|
|
704
|
-
const urls = webServer.resolvedUrls;
|
|
705
|
-
const candidates = urls ? [...urls.local ?? [], ...urls.network ?? []] : [];
|
|
706
|
-
if (candidates.length > 0) {
|
|
707
|
-
logger_default.success("Web 运行时已启动,浏览器访问:");
|
|
708
|
-
for (const url of candidates) logger_default.info(` ➜ ${colors.cyan(url)}`);
|
|
709
|
-
} else logger_default.success("Web 运行时已启动");
|
|
710
|
-
}
|
|
830
|
+
if (!uiUrls.length && !webUrls.length) logger_default.info(`提示:手动打开对应平台开发者工具,导入根目录(${colors.green(projectConfigFileName)} 文件所在目录)`);
|
|
711
831
|
logBuildAppFinishOnlyShowOnce = true;
|
|
712
832
|
}
|
|
713
833
|
const WINDOWS_SEPARATOR_RE = /\\/g;
|
|
@@ -889,7 +1009,7 @@ function resolveIdeProjectRoot(mpDistRoot, cwd) {
|
|
|
889
1009
|
//#endregion
|
|
890
1010
|
//#region src/cli/commands/build.ts
|
|
891
1011
|
function registerBuildCommand(cli) {
|
|
892
|
-
cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).option("--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("--analyze", `[boolean] 输出分包分析仪表盘`, { default: false }).action(async (root, options) => {
|
|
1012
|
+
cli.command("build [root]", "build for production").option("--target <target>", `[string] transpile target (default: 'modules')`).option("--outDir <dir>", `[string] output directory (default: dist)`).option("-p, --platform <platform>", `[string] target platform (weapp | h5 | 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("--ui", `[boolean] 启动调试 UI(当前提供分析视图)`, { default: false }).option("--analyze", `[boolean] 输出分包分析仪表盘`, { default: false }).action(async (root, options) => {
|
|
893
1013
|
filterDuplicateOptions(options);
|
|
894
1014
|
const configFile = resolveConfigFile(options);
|
|
895
1015
|
const targets = resolveRuntimeTargets(options);
|
|
@@ -904,7 +1024,7 @@ function registerBuildCommand(cli) {
|
|
|
904
1024
|
});
|
|
905
1025
|
const { buildService, configService, webService } = ctx;
|
|
906
1026
|
logRuntimeTarget(targets, { resolvedConfigPlatform: configService.platform });
|
|
907
|
-
const enableAnalyze = Boolean(options
|
|
1027
|
+
const enableAnalyze = Boolean(isUiEnabled(options) && targets.runMini);
|
|
908
1028
|
let analyzeHandle;
|
|
909
1029
|
if (targets.runMini) {
|
|
910
1030
|
const output = await buildService.build(options);
|
|
@@ -1417,8 +1537,92 @@ function registerPrepareCommand(cli) {
|
|
|
1417
1537
|
}
|
|
1418
1538
|
//#endregion
|
|
1419
1539
|
//#region src/cli/commands/serve.ts
|
|
1540
|
+
function resolveWebHost(host) {
|
|
1541
|
+
if (host === void 0) return;
|
|
1542
|
+
if (typeof host === "boolean") return host;
|
|
1543
|
+
if (typeof host === "string") return host;
|
|
1544
|
+
return String(host);
|
|
1545
|
+
}
|
|
1546
|
+
const REG_DIST_PAGE_ENTRY = /pages\/.+\/index\.js$/;
|
|
1547
|
+
const REG_DIST_POSIX_SEP = /\\/g;
|
|
1548
|
+
function hasAnalyzeData(result) {
|
|
1549
|
+
return result.packages.length > 0 || result.modules.length > 0;
|
|
1550
|
+
}
|
|
1551
|
+
async function collectOutputFiles(root) {
|
|
1552
|
+
const entries = await fs$1.readdir(root, { withFileTypes: true });
|
|
1553
|
+
const files = [];
|
|
1554
|
+
for (const entry of entries) {
|
|
1555
|
+
const absolutePath = path.join(root, entry.name);
|
|
1556
|
+
if (entry.isDirectory()) {
|
|
1557
|
+
files.push(...await collectOutputFiles(absolutePath));
|
|
1558
|
+
continue;
|
|
1559
|
+
}
|
|
1560
|
+
if (entry.isFile()) files.push(absolutePath);
|
|
1561
|
+
}
|
|
1562
|
+
return files;
|
|
1563
|
+
}
|
|
1564
|
+
async function analyzeUiFallback(ctx) {
|
|
1565
|
+
const { configService, scanService } = ctx;
|
|
1566
|
+
await scanService.loadAppEntry();
|
|
1567
|
+
const subPackageMetas = scanService.loadSubPackages();
|
|
1568
|
+
const distRoot = configService.outDir;
|
|
1569
|
+
const absoluteFiles = await collectOutputFiles(distRoot);
|
|
1570
|
+
const packages = /* @__PURE__ */ new Map();
|
|
1571
|
+
const ensurePackage = (packageId, packageType) => {
|
|
1572
|
+
const existing = packages.get(packageId);
|
|
1573
|
+
if (existing) return existing;
|
|
1574
|
+
const created = {
|
|
1575
|
+
id: packageId,
|
|
1576
|
+
label: packageId === "__main__" ? "主包" : packageType === "independent" ? `独立分包 ${packageId}` : `分包 ${packageId}`,
|
|
1577
|
+
type: packageType,
|
|
1578
|
+
files: []
|
|
1579
|
+
};
|
|
1580
|
+
packages.set(packageId, created);
|
|
1581
|
+
return created;
|
|
1582
|
+
};
|
|
1583
|
+
const classifyPackage = (relativeFile) => {
|
|
1584
|
+
const normalized = relativeFile.replace(REG_DIST_POSIX_SEP, "/");
|
|
1585
|
+
for (const meta of subPackageMetas) {
|
|
1586
|
+
const root = meta.subPackage.root;
|
|
1587
|
+
if (root && normalized.startsWith(`${root}/`)) return {
|
|
1588
|
+
id: root,
|
|
1589
|
+
type: meta.subPackage.independent ? "independent" : "subPackage"
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
return {
|
|
1593
|
+
id: "__main__",
|
|
1594
|
+
type: "main"
|
|
1595
|
+
};
|
|
1596
|
+
};
|
|
1597
|
+
for (const absoluteFile of absoluteFiles) {
|
|
1598
|
+
const relativeFile = path.relative(distRoot, absoluteFile).replace(REG_DIST_POSIX_SEP, "/");
|
|
1599
|
+
const packageInfo = classifyPackage(relativeFile);
|
|
1600
|
+
const stat = await fs$1.stat(absoluteFile);
|
|
1601
|
+
ensurePackage(packageInfo.id, packageInfo.type).files.push({
|
|
1602
|
+
file: relativeFile,
|
|
1603
|
+
type: relativeFile.endsWith(".js") ? "chunk" : "asset",
|
|
1604
|
+
from: packageInfo.type === "independent" ? "independent" : "main",
|
|
1605
|
+
size: stat.size,
|
|
1606
|
+
isEntry: relativeFile === "app.js" || REG_DIST_PAGE_ENTRY.test(relativeFile),
|
|
1607
|
+
source: relativeFile.endsWith(".js") ? void 0 : relativeFile
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1610
|
+
return {
|
|
1611
|
+
packages: Array.from(packages.values()).sort((a, b) => {
|
|
1612
|
+
if (a.id === "__main__") return -1;
|
|
1613
|
+
if (b.id === "__main__") return 1;
|
|
1614
|
+
return a.id.localeCompare(b.id);
|
|
1615
|
+
}),
|
|
1616
|
+
modules: [],
|
|
1617
|
+
subPackages: subPackageMetas.map((meta) => ({
|
|
1618
|
+
root: meta.subPackage.root ?? "",
|
|
1619
|
+
independent: Boolean(meta.subPackage.independent),
|
|
1620
|
+
name: meta.subPackage.name
|
|
1621
|
+
})).filter((item) => item.root).sort((a, b) => a.root.localeCompare(b.root))
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1420
1624
|
function registerServeCommand(cli) {
|
|
1421
|
-
cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).option("-p, --platform <platform>", `[string] target platform (weapp | h5)`).option("--project-config <path>", `[string] project config path (miniprogram only)`).option("--host [host]", `[string] web dev server host`).option("--analyze", `[boolean] 启动分包分析仪表盘 (实验特性)`, { default: false }).action(async (root, options) => {
|
|
1625
|
+
cli.command("[root]", "start dev server").alias("serve").alias("dev").option("--skipNpm", `[boolean] if skip npm build`).option("-o, --open", `[boolean] open ide`).option("-p, --platform <platform>", `[string] target platform (weapp | h5 | all)`).option("--project-config <path>", `[string] project config path (miniprogram only)`).option("--host [host]", `[string] web dev server host`).option("--ui", `[boolean] 启动调试 UI(当前提供分析视图)`, { default: false }).option("--analyze", `[boolean] 启动分包分析仪表盘 (实验特性)`, { default: false }).action(async (root, options) => {
|
|
1422
1626
|
filterDuplicateOptions(options);
|
|
1423
1627
|
const configFile = resolveConfigFile(options);
|
|
1424
1628
|
const targets = resolveRuntimeTargets(options);
|
|
@@ -1432,6 +1636,34 @@ function registerServeCommand(cli) {
|
|
|
1432
1636
|
host
|
|
1433
1637
|
}
|
|
1434
1638
|
};
|
|
1639
|
+
if (targets.runMini) {
|
|
1640
|
+
const buildWatch = typeof inlineConfig?.build?.watch === "object" && inlineConfig.build.watch ? inlineConfig.build.watch : {};
|
|
1641
|
+
const buildChokidar = "chokidar" in buildWatch ? buildWatch.chokidar : void 0;
|
|
1642
|
+
const existingServer = inlineConfig?.server ?? {};
|
|
1643
|
+
inlineConfig = {
|
|
1644
|
+
...inlineConfig,
|
|
1645
|
+
build: {
|
|
1646
|
+
...inlineConfig?.build ?? {},
|
|
1647
|
+
watch: {
|
|
1648
|
+
...buildWatch,
|
|
1649
|
+
chokidar: {
|
|
1650
|
+
...buildChokidar ?? {},
|
|
1651
|
+
usePolling: true,
|
|
1652
|
+
interval: 100
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
},
|
|
1656
|
+
server: {
|
|
1657
|
+
...existingServer,
|
|
1658
|
+
...existingServer.port === void 0 ? { port: 0 } : {},
|
|
1659
|
+
watch: {
|
|
1660
|
+
...existingServer.watch ?? {},
|
|
1661
|
+
usePolling: true,
|
|
1662
|
+
interval: 100
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1435
1667
|
}
|
|
1436
1668
|
const ctx = await createCompilerContext({
|
|
1437
1669
|
cwd: root,
|
|
@@ -1444,32 +1676,56 @@ function registerServeCommand(cli) {
|
|
|
1444
1676
|
});
|
|
1445
1677
|
const { buildService, configService, webService } = ctx;
|
|
1446
1678
|
logRuntimeTarget(targets, { resolvedConfigPlatform: configService.platform });
|
|
1447
|
-
const enableAnalyze = Boolean(options
|
|
1679
|
+
const enableAnalyze = Boolean(isUiEnabled(options) && targets.runMini);
|
|
1448
1680
|
let analyzeHandle;
|
|
1681
|
+
let analyzeRunId = 0;
|
|
1682
|
+
const runAnalyze = async () => {
|
|
1683
|
+
try {
|
|
1684
|
+
const result = await analyzeSubpackages(await createCompilerContext({
|
|
1685
|
+
key: `serve-ui-analyze:${process.pid}:${++analyzeRunId}`,
|
|
1686
|
+
cwd: configService.cwd,
|
|
1687
|
+
mode: configService.mode,
|
|
1688
|
+
isDev: false,
|
|
1689
|
+
configFile,
|
|
1690
|
+
inlineConfig: createInlineConfig(targets.mpPlatform),
|
|
1691
|
+
cliPlatform: targets.rawPlatform,
|
|
1692
|
+
projectConfigPath: options.projectConfig,
|
|
1693
|
+
syncSupportFiles: false
|
|
1694
|
+
}));
|
|
1695
|
+
if (hasAnalyzeData(result)) return result;
|
|
1696
|
+
} catch (error) {
|
|
1697
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1698
|
+
logger_default.warn(`[ui] 完整分析失败,已回退到 dist 文件扫描:${message}`);
|
|
1699
|
+
}
|
|
1700
|
+
return analyzeUiFallback(ctx);
|
|
1701
|
+
};
|
|
1449
1702
|
const triggerAnalyzeUpdate = async () => {
|
|
1450
1703
|
if (!analyzeHandle) return;
|
|
1451
|
-
const next = await
|
|
1704
|
+
const next = await runAnalyze();
|
|
1452
1705
|
await analyzeHandle.update(next);
|
|
1453
1706
|
};
|
|
1454
1707
|
if (targets.runMini) {
|
|
1455
1708
|
const buildResult = await buildService.build(options);
|
|
1456
1709
|
if (enableAnalyze) {
|
|
1457
|
-
analyzeHandle = await startAnalyzeDashboard(await
|
|
1710
|
+
analyzeHandle = await startAnalyzeDashboard(await runAnalyze(), {
|
|
1458
1711
|
watch: true,
|
|
1459
1712
|
cwd: configService.cwd,
|
|
1460
|
-
packageManagerAgent: configService.packageManager.agent
|
|
1713
|
+
packageManagerAgent: configService.packageManager.agent,
|
|
1714
|
+
silentStartupLog: true
|
|
1461
1715
|
}) ?? void 0;
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
updating =
|
|
1468
|
-
triggerAnalyzeUpdate().finally(() => {
|
|
1469
|
-
updating = false;
|
|
1470
|
-
});
|
|
1716
|
+
let updating = false;
|
|
1717
|
+
if (analyzeHandle && buildResult && typeof buildResult.on === "function") buildResult.on("event", (event) => {
|
|
1718
|
+
if (event.code !== "END" || updating) return;
|
|
1719
|
+
updating = true;
|
|
1720
|
+
triggerAnalyzeUpdate().finally(() => {
|
|
1721
|
+
updating = false;
|
|
1471
1722
|
});
|
|
1472
|
-
}
|
|
1723
|
+
});
|
|
1724
|
+
if (analyzeHandle) {
|
|
1725
|
+
updating = true;
|
|
1726
|
+
await triggerAnalyzeUpdate();
|
|
1727
|
+
updating = false;
|
|
1728
|
+
}
|
|
1473
1729
|
}
|
|
1474
1730
|
}
|
|
1475
1731
|
let webServer;
|
|
@@ -1479,7 +1735,10 @@ function registerServeCommand(cli) {
|
|
|
1479
1735
|
logger_default.error(error);
|
|
1480
1736
|
throw error;
|
|
1481
1737
|
}
|
|
1482
|
-
if (targets.runMini) logBuildAppFinish(configService, webServer, {
|
|
1738
|
+
if (targets.runMini) logBuildAppFinish(configService, webServer, {
|
|
1739
|
+
skipWeb: !targets.runWeb,
|
|
1740
|
+
uiUrls: analyzeHandle?.urls
|
|
1741
|
+
});
|
|
1483
1742
|
else if (targets.runWeb) logBuildAppFinish(configService, webServer, { skipMini: true });
|
|
1484
1743
|
if (options.open && targets.runMini) {
|
|
1485
1744
|
if (!await maybeStartForwardConsole({
|
|
@@ -1492,12 +1751,6 @@ function registerServeCommand(cli) {
|
|
|
1492
1751
|
if (analyzeHandle) await analyzeHandle.waitForExit();
|
|
1493
1752
|
});
|
|
1494
1753
|
}
|
|
1495
|
-
function resolveWebHost(host) {
|
|
1496
|
-
if (host === void 0) return;
|
|
1497
|
-
if (typeof host === "boolean") return host;
|
|
1498
|
-
if (typeof host === "string") return host;
|
|
1499
|
-
return String(host);
|
|
1500
|
-
}
|
|
1501
1754
|
//#endregion
|
|
1502
1755
|
//#region src/cli/error.ts
|
|
1503
1756
|
const watchLimitErrorCodes = new Set(["EMFILE", "ENOSPC"]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-twds-ZHy.mjs";
|
|
2
2
|
import { n as applyWeappViteHostMeta } from "./pluginHost-SJdl15d3.mjs";
|
|
3
3
|
import { n as configureLogger, r as logger_default } from "./logger-gutcwWKE.mjs";
|
|
4
|
-
import { _ as vueExtensions, a as findJsEntry, c as findVueEntry, d as touch, g as templateExtensions, h as supportedCssLangs, i as findCssEntry, l as isJsOrTs, m as jsExtensions, n as extractConfigFromVue, o as findJsonEntry, p as configExtensions, s as findTemplateEntry, t as changeFileExtension, u as isTemplate } from "./file-
|
|
4
|
+
import { _ as vueExtensions, a as findJsEntry, c as findVueEntry, d as touch, g as templateExtensions, h as supportedCssLangs, i as findCssEntry, l as isJsOrTs, m as jsExtensions, n as extractConfigFromVue, o as findJsonEntry, p as configExtensions, s as findTemplateEntry, t as changeFileExtension, u as isTemplate } from "./file-rRQhPOL8.mjs";
|
|
5
5
|
import { createRequire, isBuiltin } from "node:module";
|
|
6
6
|
import { addExtension, defu, get, isEmptyObject, isObject, objectHash, removeExtension, removeExtensionDeep, set } from "@weapp-core/shared";
|
|
7
7
|
import { LRUCache } from "lru-cache";
|
|
@@ -7887,6 +7887,27 @@ function resolveTouchAppWxssEnabled(options) {
|
|
|
7887
7887
|
}
|
|
7888
7888
|
}
|
|
7889
7889
|
//#endregion
|
|
7890
|
+
//#region src/runtime/watch/options.ts
|
|
7891
|
+
function resolvePollingWatchConfig(configService) {
|
|
7892
|
+
const buildWatch = configService.inlineConfig?.build?.watch;
|
|
7893
|
+
const chokidar = buildWatch && typeof buildWatch === "object" && "chokidar" in buildWatch ? buildWatch.chokidar : void 0;
|
|
7894
|
+
const serverWatch = configService.inlineConfig?.server?.watch;
|
|
7895
|
+
return {
|
|
7896
|
+
usePolling: chokidar?.usePolling ?? serverWatch?.usePolling,
|
|
7897
|
+
interval: chokidar?.interval ?? serverWatch?.interval,
|
|
7898
|
+
binaryInterval: chokidar?.binaryInterval ?? serverWatch?.binaryInterval
|
|
7899
|
+
};
|
|
7900
|
+
}
|
|
7901
|
+
function createSidecarWatchOptions(configService, input) {
|
|
7902
|
+
const polling = resolvePollingWatchConfig(configService);
|
|
7903
|
+
return {
|
|
7904
|
+
...input,
|
|
7905
|
+
...polling.usePolling !== void 0 ? { usePolling: polling.usePolling } : {},
|
|
7906
|
+
...typeof polling.interval === "number" ? { interval: polling.interval } : {},
|
|
7907
|
+
...typeof polling.binaryInterval === "number" ? { binaryInterval: polling.binaryInterval } : {}
|
|
7908
|
+
};
|
|
7909
|
+
}
|
|
7910
|
+
//#endregion
|
|
7890
7911
|
//#region src/runtime/buildPlugin/workers.ts
|
|
7891
7912
|
function checkWorkersOptions(target, configService, scanService) {
|
|
7892
7913
|
if (target === "plugin") return {
|
|
@@ -7914,10 +7935,10 @@ async function buildWorkers(configService) {
|
|
|
7914
7935
|
}
|
|
7915
7936
|
function watchWorkers(configService, watcherService, workersDir) {
|
|
7916
7937
|
const absWorkerRoot = path.resolve(configService.absoluteSrcRoot, workersDir);
|
|
7917
|
-
const workerWatcher = chokidar.watch(absWorkerRoot, {
|
|
7938
|
+
const workerWatcher = chokidar.watch(absWorkerRoot, createSidecarWatchOptions(configService, {
|
|
7918
7939
|
persistent: true,
|
|
7919
7940
|
ignoreInitial: true
|
|
7920
|
-
});
|
|
7941
|
+
}));
|
|
7921
7942
|
const logWorkerEvent = (type, targetPath, level = "info") => {
|
|
7922
7943
|
if (!targetPath) return;
|
|
7923
7944
|
const message = `[workers:${type}] ${configService.relativeCwd(targetPath)}`;
|
|
@@ -7984,6 +8005,7 @@ function createBuildService(ctx) {
|
|
|
7984
8005
|
debug$2?.("dev build watcher end");
|
|
7985
8006
|
debug$2?.("dev watcher listen start");
|
|
7986
8007
|
let startTime;
|
|
8008
|
+
let firstBuildCompleted = false;
|
|
7987
8009
|
let resolveWatcher;
|
|
7988
8010
|
let rejectWatcher;
|
|
7989
8011
|
const promise = new Promise((res, rej) => {
|
|
@@ -7994,7 +8016,9 @@ function createBuildService(ctx) {
|
|
|
7994
8016
|
watcher.on("event", (e) => {
|
|
7995
8017
|
if (e.code === "START") startTime = performance.now();
|
|
7996
8018
|
else if (e.code === "END") {
|
|
7997
|
-
|
|
8019
|
+
const duration = (performance.now() - startTime).toFixed(2);
|
|
8020
|
+
if (firstBuildCompleted) logger_default.success(`小程序已重新构建(${duration} ms)`);
|
|
8021
|
+
else firstBuildCompleted = true;
|
|
7998
8022
|
if (appWxssPath && shouldTouchAppWxss()) touch(appWxssPath).catch(() => {});
|
|
7999
8023
|
resolveWatcher(e);
|
|
8000
8024
|
} else if (e.code === "ERROR") rejectWatcher(e);
|
|
@@ -8818,7 +8842,167 @@ function configureBuildAndPlugins(options) {
|
|
|
8818
8842
|
};
|
|
8819
8843
|
}
|
|
8820
8844
|
//#endregion
|
|
8845
|
+
//#region src/runtime/config/internal/tsconfigPaths.ts
|
|
8846
|
+
const PATHS_RE = /"paths"\s*:/;
|
|
8847
|
+
const BASE_URL_RE = /"baseUrl"\s*:/;
|
|
8848
|
+
function withJsonExtension(filePath) {
|
|
8849
|
+
return path.extname(filePath) ? filePath : `${filePath}.json`;
|
|
8850
|
+
}
|
|
8851
|
+
function resolveReferencePath(baseDir, referencePath) {
|
|
8852
|
+
const resolved = path.resolve(baseDir, referencePath);
|
|
8853
|
+
if (path.extname(resolved)) return resolved;
|
|
8854
|
+
return path.join(resolved, "tsconfig.json");
|
|
8855
|
+
}
|
|
8856
|
+
function resolveExtendsPath(baseDir, extendsPath) {
|
|
8857
|
+
if (!extendsPath) return;
|
|
8858
|
+
if (extendsPath.startsWith(".") || path.isAbsolute(extendsPath)) return withJsonExtension(path.isAbsolute(extendsPath) ? extendsPath : path.resolve(baseDir, extendsPath));
|
|
8859
|
+
}
|
|
8860
|
+
function normalizePathAliasKey(key) {
|
|
8861
|
+
if (!key || key.includes("*") && !key.endsWith("/*")) return;
|
|
8862
|
+
return key.endsWith("/*") ? key.slice(0, -2) : key;
|
|
8863
|
+
}
|
|
8864
|
+
function normalizePathAliasTarget(target) {
|
|
8865
|
+
if (!target || target.includes("*") && !target.endsWith("/*")) return;
|
|
8866
|
+
return target.endsWith("/*") ? target.slice(0, -2) : target;
|
|
8867
|
+
}
|
|
8868
|
+
function extractPathAliases(baseDir, compilerOptions) {
|
|
8869
|
+
const aliases = [];
|
|
8870
|
+
const paths = compilerOptions?.paths;
|
|
8871
|
+
if (!paths || typeof paths !== "object") return aliases;
|
|
8872
|
+
for (const [key, value] of Object.entries(paths)) {
|
|
8873
|
+
const find = normalizePathAliasKey(key);
|
|
8874
|
+
const target = Array.isArray(value) ? value.find((item) => typeof item === "string") : void 0;
|
|
8875
|
+
const normalizedTarget = typeof target === "string" ? normalizePathAliasTarget(target) : void 0;
|
|
8876
|
+
if (!find || !normalizedTarget) continue;
|
|
8877
|
+
aliases.push({
|
|
8878
|
+
find,
|
|
8879
|
+
replacement: path.resolve(baseDir, normalizedTarget)
|
|
8880
|
+
});
|
|
8881
|
+
}
|
|
8882
|
+
return aliases;
|
|
8883
|
+
}
|
|
8884
|
+
function mergeAliases(current, incoming) {
|
|
8885
|
+
const merged = [...current];
|
|
8886
|
+
for (const entry of incoming) {
|
|
8887
|
+
if (merged.some((existing) => existing.find === entry.find)) continue;
|
|
8888
|
+
merged.push(entry);
|
|
8889
|
+
}
|
|
8890
|
+
return merged;
|
|
8891
|
+
}
|
|
8892
|
+
async function inspectTsconfigPathsState(filePath, visited) {
|
|
8893
|
+
if (visited.has(filePath)) return {
|
|
8894
|
+
root: false,
|
|
8895
|
+
references: false,
|
|
8896
|
+
aliases: []
|
|
8897
|
+
};
|
|
8898
|
+
visited.add(filePath);
|
|
8899
|
+
if (!await fs.pathExists(filePath)) return {
|
|
8900
|
+
root: false,
|
|
8901
|
+
references: false,
|
|
8902
|
+
aliases: []
|
|
8903
|
+
};
|
|
8904
|
+
let content = "";
|
|
8905
|
+
try {
|
|
8906
|
+
content = await fs.readFile(filePath, "utf8");
|
|
8907
|
+
} catch {
|
|
8908
|
+
return {
|
|
8909
|
+
root: false,
|
|
8910
|
+
references: false,
|
|
8911
|
+
aliases: []
|
|
8912
|
+
};
|
|
8913
|
+
}
|
|
8914
|
+
let parsed;
|
|
8915
|
+
try {
|
|
8916
|
+
parsed = parse$1(content);
|
|
8917
|
+
} catch {
|
|
8918
|
+
return {
|
|
8919
|
+
root: false,
|
|
8920
|
+
references: false,
|
|
8921
|
+
aliases: []
|
|
8922
|
+
};
|
|
8923
|
+
}
|
|
8924
|
+
const compilerOptions = parsed?.compilerOptions;
|
|
8925
|
+
let aliases = extractPathAliases(path.dirname(filePath), compilerOptions);
|
|
8926
|
+
let root = Boolean(PATHS_RE.test(content) || BASE_URL_RE.test(content) || compilerOptions?.paths || compilerOptions?.baseUrl);
|
|
8927
|
+
const baseDir = path.dirname(filePath);
|
|
8928
|
+
const extendsPath = typeof parsed?.extends === "string" ? resolveExtendsPath(baseDir, parsed.extends) : void 0;
|
|
8929
|
+
if (extendsPath) {
|
|
8930
|
+
const extendsState = await inspectTsconfigPathsState(extendsPath, visited);
|
|
8931
|
+
root = root || extendsState.root;
|
|
8932
|
+
aliases = mergeAliases(aliases, extendsState.aliases);
|
|
8933
|
+
}
|
|
8934
|
+
let references = false;
|
|
8935
|
+
const refs = Array.isArray(parsed?.references) ? parsed.references : [];
|
|
8936
|
+
for (const ref of refs) {
|
|
8937
|
+
if (!ref || typeof ref !== "object" || typeof ref.path !== "string") continue;
|
|
8938
|
+
const referenceState = await inspectTsconfigPathsState(resolveReferencePath(baseDir, ref.path), visited);
|
|
8939
|
+
if (referenceState.root || referenceState.references) references = true;
|
|
8940
|
+
aliases = mergeAliases(aliases, referenceState.aliases);
|
|
8941
|
+
}
|
|
8942
|
+
return {
|
|
8943
|
+
root,
|
|
8944
|
+
references,
|
|
8945
|
+
aliases
|
|
8946
|
+
};
|
|
8947
|
+
}
|
|
8948
|
+
async function inspectTsconfigPathsUsage(cwd) {
|
|
8949
|
+
const candidates = [path.resolve(cwd, "tsconfig.json"), path.resolve(cwd, "jsconfig.json")];
|
|
8950
|
+
let root = false;
|
|
8951
|
+
let references = false;
|
|
8952
|
+
let referenceAliases = [];
|
|
8953
|
+
for (const filePath of candidates) {
|
|
8954
|
+
const state = await inspectTsconfigPathsState(filePath, /* @__PURE__ */ new Set());
|
|
8955
|
+
root = root || state.root;
|
|
8956
|
+
references = references || state.references;
|
|
8957
|
+
referenceAliases = mergeAliases(referenceAliases, state.aliases);
|
|
8958
|
+
}
|
|
8959
|
+
return {
|
|
8960
|
+
enabled: root || references,
|
|
8961
|
+
root,
|
|
8962
|
+
references,
|
|
8963
|
+
referenceAliases
|
|
8964
|
+
};
|
|
8965
|
+
}
|
|
8966
|
+
//#endregion
|
|
8821
8967
|
//#region src/runtime/config/internal/loadConfig.ts
|
|
8968
|
+
function injectDefaultSrcAlias(config, cwd, srcRoot) {
|
|
8969
|
+
if (!srcRoot) return;
|
|
8970
|
+
const resolve = config.resolve ?? (config.resolve = {});
|
|
8971
|
+
const currentAlias = resolve.alias;
|
|
8972
|
+
const aliasArray = Array.isArray(currentAlias) ? currentAlias.filter((entry) => {
|
|
8973
|
+
return Boolean(entry && typeof entry === "object" && "find" in entry && "replacement" in entry);
|
|
8974
|
+
}) : currentAlias ? Object.entries(currentAlias).map(([find, replacement]) => ({
|
|
8975
|
+
find,
|
|
8976
|
+
replacement
|
|
8977
|
+
})) : [];
|
|
8978
|
+
if (aliasArray.some((entry) => {
|
|
8979
|
+
return typeof entry.find === "string" && entry.find === "@";
|
|
8980
|
+
})) {
|
|
8981
|
+
resolve.alias = aliasArray;
|
|
8982
|
+
return;
|
|
8983
|
+
}
|
|
8984
|
+
aliasArray.unshift({
|
|
8985
|
+
find: "@",
|
|
8986
|
+
replacement: path.resolve(cwd, srcRoot)
|
|
8987
|
+
});
|
|
8988
|
+
resolve.alias = aliasArray;
|
|
8989
|
+
}
|
|
8990
|
+
function injectResolvedAliases(config, aliases) {
|
|
8991
|
+
if (aliases.length === 0) return;
|
|
8992
|
+
const resolve = config.resolve ?? (config.resolve = {});
|
|
8993
|
+
const currentAlias = resolve.alias;
|
|
8994
|
+
const aliasArray = Array.isArray(currentAlias) ? currentAlias.filter((entry) => {
|
|
8995
|
+
return Boolean(entry && typeof entry === "object" && "find" in entry && "replacement" in entry);
|
|
8996
|
+
}) : currentAlias ? Object.entries(currentAlias).map(([find, replacement]) => ({
|
|
8997
|
+
find,
|
|
8998
|
+
replacement
|
|
8999
|
+
})) : [];
|
|
9000
|
+
for (const entry of aliases) {
|
|
9001
|
+
if (aliasArray.some((existing) => typeof existing.find === "string" && existing.find === entry.find)) continue;
|
|
9002
|
+
aliasArray.unshift(entry);
|
|
9003
|
+
}
|
|
9004
|
+
resolve.alias = aliasArray;
|
|
9005
|
+
}
|
|
8822
9006
|
function createLoadConfig(options) {
|
|
8823
9007
|
const { injectBuiltinAliases, oxcRolldownPlugin, oxcVitePlugin } = options;
|
|
8824
9008
|
return async function loadConfig(opts) {
|
|
@@ -8918,6 +9102,12 @@ function createLoadConfig(options) {
|
|
|
8918
9102
|
srcRoot: rawLibConfig.root
|
|
8919
9103
|
};
|
|
8920
9104
|
const srcRoot = config.weapp?.srcRoot ?? "";
|
|
9105
|
+
const tsconfigPathsUsage = await inspectTsconfigPathsUsage(cwd);
|
|
9106
|
+
if (!tsconfigPathsUsage.enabled) injectDefaultSrcAlias(config, cwd, srcRoot);
|
|
9107
|
+
else if (tsconfigPathsUsage.references && !tsconfigPathsUsage.root) {
|
|
9108
|
+
injectResolvedAliases(config, tsconfigPathsUsage.referenceAliases);
|
|
9109
|
+
injectDefaultSrcAlias(config, cwd, srcRoot);
|
|
9110
|
+
}
|
|
8921
9111
|
const resolvedLibConfig = libEntryConfigured ? resolveWeappLibConfig({
|
|
8922
9112
|
cwd,
|
|
8923
9113
|
srcRoot,
|
|
@@ -9191,14 +9381,14 @@ function createAutoImportPlugin(state) {
|
|
|
9191
9381
|
if (fileWatcherStarted || !configService?.isDev || !globs?.length) return;
|
|
9192
9382
|
const watchTargets = registerAutoImportWatchTargets(state, globs, void 0, { includeSrcRoot: false });
|
|
9193
9383
|
if (!watchTargets?.size) return;
|
|
9194
|
-
const watcher = chokidar.watch([...watchTargets], {
|
|
9384
|
+
const watcher = chokidar.watch([...watchTargets], createSidecarWatchOptions(configService, {
|
|
9195
9385
|
ignoreInitial: true,
|
|
9196
9386
|
persistent: true,
|
|
9197
9387
|
awaitWriteFinish: {
|
|
9198
9388
|
stabilityThreshold: 80,
|
|
9199
9389
|
pollInterval: 20
|
|
9200
9390
|
}
|
|
9201
|
-
});
|
|
9391
|
+
}));
|
|
9202
9392
|
watcher.on("add", (filePath) => {
|
|
9203
9393
|
if (!matchesAutoImportGlobs(ctx, filePath)) return;
|
|
9204
9394
|
logger_default.info(`[auto-import:watch] 新增组件文件 ${configService.relativeCwd(filePath)}`);
|
|
@@ -9355,14 +9545,14 @@ function createAutoRoutesPlugin(ctx) {
|
|
|
9355
9545
|
const ext = path.extname(filePath);
|
|
9356
9546
|
return allowedExtensions.has(ext) && isPagesRelatedPath(filePath);
|
|
9357
9547
|
};
|
|
9358
|
-
const watcher = chokidar.watch([...watchDirs], {
|
|
9548
|
+
const watcher = chokidar.watch([...watchDirs], createSidecarWatchOptions(configService, {
|
|
9359
9549
|
ignoreInitial: true,
|
|
9360
9550
|
persistent: true,
|
|
9361
9551
|
awaitWriteFinish: {
|
|
9362
9552
|
stabilityThreshold: 80,
|
|
9363
9553
|
pollInterval: 20
|
|
9364
9554
|
}
|
|
9365
|
-
});
|
|
9555
|
+
}));
|
|
9366
9556
|
watcher.on("add", (filePath) => {
|
|
9367
9557
|
if (!isRouteVueFile(filePath)) return;
|
|
9368
9558
|
logger_default.info(`[auto-routes:watch] 新增路由文件 ${configService.relativeCwd(filePath)}`);
|
|
@@ -12728,7 +12918,7 @@ function ensureSidecarWatcher(ctx, rootDir) {
|
|
|
12728
12918
|
...templateExtensions.map((ext) => path.join(absRoot, `**/*.${ext}`))
|
|
12729
12919
|
];
|
|
12730
12920
|
const ignoredMatcher = createSidecarIgnoredMatcher(ctx, absRoot);
|
|
12731
|
-
const watcher = chokidar.watch(patterns, {
|
|
12921
|
+
const watcher = chokidar.watch(patterns, createSidecarWatchOptions(ctx.configService, {
|
|
12732
12922
|
ignoreInitial: false,
|
|
12733
12923
|
persistent: true,
|
|
12734
12924
|
awaitWriteFinish: {
|
|
@@ -12736,7 +12926,7 @@ function ensureSidecarWatcher(ctx, rootDir) {
|
|
|
12736
12926
|
pollInterval: 20
|
|
12737
12927
|
},
|
|
12738
12928
|
ignored: ignoredMatcher
|
|
12739
|
-
});
|
|
12929
|
+
}));
|
|
12740
12930
|
const forwardChange = (event, input, options) => {
|
|
12741
12931
|
if (!input) return;
|
|
12742
12932
|
const normalizedPath = path.normalize(input);
|
|
@@ -13363,11 +13553,15 @@ const VUE_LIKE_EXTENSIONS$2 = [
|
|
|
13363
13553
|
".tsx",
|
|
13364
13554
|
".jsx"
|
|
13365
13555
|
];
|
|
13556
|
+
const WINDOWS_ABSOLUTE_PATH_RE = /^[A-Z]:[\\/]/i;
|
|
13366
13557
|
let warnedMissingWevu = false;
|
|
13367
13558
|
let wevuInstallState = "unknown";
|
|
13368
13559
|
function isVueLikeFile$2(id) {
|
|
13369
13560
|
return VUE_LIKE_EXTENSIONS$2.some((ext) => id.endsWith(ext));
|
|
13370
13561
|
}
|
|
13562
|
+
function isExplicitFileRequest(id) {
|
|
13563
|
+
return id.startsWith(".") || id.startsWith("/") || WINDOWS_ABSOLUTE_PATH_RE.test(id);
|
|
13564
|
+
}
|
|
13371
13565
|
function hasWevuDependency(ctx) {
|
|
13372
13566
|
const packageJson = ctx.configService?.packageJson;
|
|
13373
13567
|
if (!packageJson) return false;
|
|
@@ -13412,11 +13606,13 @@ function createVueResolverPlugin(ctx) {
|
|
|
13412
13606
|
}
|
|
13413
13607
|
if (isVueLikeFile$2(id)) {
|
|
13414
13608
|
ensureWevuInstalled(ctx);
|
|
13609
|
+
if (!isExplicitFileRequest(id)) return null;
|
|
13415
13610
|
const absoluteId = toAbsoluteId(id, configService, importer, { base: "srcRoot" });
|
|
13416
13611
|
if (!absoluteId) return null;
|
|
13417
13612
|
return absoluteId;
|
|
13418
13613
|
}
|
|
13419
13614
|
if (id.startsWith(VUE_VIRTUAL_MODULE_PREFIX)) return id;
|
|
13615
|
+
if (!isExplicitFileRequest(id)) return null;
|
|
13420
13616
|
const absoluteId = toAbsoluteId(id, configService, importer, { base: "srcRoot" });
|
|
13421
13617
|
if (!absoluteId) return null;
|
|
13422
13618
|
for (const ext of VUE_LIKE_EXTENSIONS$2) {
|
|
@@ -15679,7 +15875,7 @@ function mergeMiniprogram(options, ...configs) {
|
|
|
15679
15875
|
applyWeappViteHostMeta(inlineConfig, "miniprogram");
|
|
15680
15876
|
stripRollupOptions(inlineConfig);
|
|
15681
15877
|
arrangePlugins(inlineConfig, ctx, subPackageMeta);
|
|
15682
|
-
inlineConfig.logLevel = "
|
|
15878
|
+
inlineConfig.logLevel = "warn";
|
|
15683
15879
|
injectBuiltinAliases(inlineConfig);
|
|
15684
15880
|
const currentRoot = subPackageMeta?.subPackage.root;
|
|
15685
15881
|
setOptions({ currentSubPackageRoot: currentRoot });
|
|
@@ -17498,7 +17694,7 @@ function createScanService(ctx) {
|
|
|
17498
17694
|
let vueAppPath;
|
|
17499
17695
|
if (!appEntryPath) vueAppPath = await findVueEntry(appBasename);
|
|
17500
17696
|
if (!appConfigFile && vueAppPath) {
|
|
17501
|
-
const { extractConfigFromVue } = await import("./file-
|
|
17697
|
+
const { extractConfigFromVue } = await import("./file-rRQhPOL8.mjs").then((n) => n.r);
|
|
17502
17698
|
configFromVue = await extractConfigFromVue(vueAppPath);
|
|
17503
17699
|
if (configFromVue) appConfigFile = vueAppPath;
|
|
17504
17700
|
}
|
|
@@ -17722,7 +17918,8 @@ function createWebService(ctx) {
|
|
|
17722
17918
|
const inlineConfig = configService.mergeWeb();
|
|
17723
17919
|
if (!inlineConfig) return;
|
|
17724
17920
|
const server = await createServer(inlineConfig);
|
|
17725
|
-
|
|
17921
|
+
const requestedPort = typeof inlineConfig.server?.port === "number" ? inlineConfig.server.port : void 0;
|
|
17922
|
+
await server.listen(requestedPort);
|
|
17726
17923
|
devServer = server;
|
|
17727
17924
|
return devServer;
|
|
17728
17925
|
}
|
|
@@ -18265,4 +18462,4 @@ async function createCompilerContext(options) {
|
|
|
18265
18462
|
return ctx;
|
|
18266
18463
|
}
|
|
18267
18464
|
//#endregion
|
|
18268
|
-
export { getInstance_exports as a, normalizeMiniPlatform as c, SHARED_CHUNK_VIRTUAL_PREFIX as d, resolveWeappConfigFile as f,
|
|
18465
|
+
export { isPathInside as _, getInstance_exports as a, normalizeMiniPlatform as c, SHARED_CHUNK_VIRTUAL_PREFIX as d, resolveWeappConfigFile as f, createCjsConfigLoadError as g, parseCommentJson as h, getCompilerContext as i, resolveMiniPlatform as l, getProjectConfigFileName as m, syncProjectSupportFiles as n, formatBytes as o, checkRuntime as p, syncManagedTsconfigBootstrapFiles as r, DEFAULT_MP_PLATFORM as s, createCompilerContext as t, createSharedBuildConfig as u };
|
|
@@ -78,7 +78,7 @@ function resolveAutoRoutesMacroImportPath() {
|
|
|
78
78
|
}
|
|
79
79
|
async function resolveAutoRoutesInlineSnapshot() {
|
|
80
80
|
try {
|
|
81
|
-
const { getCompilerContext } = await import("./createContext-
|
|
81
|
+
const { getCompilerContext } = await import("./createContext-DZgOqIMU.mjs").then((n) => n.a);
|
|
82
82
|
const compilerContext = getCompilerContext();
|
|
83
83
|
const service = compilerContext.autoRoutesService;
|
|
84
84
|
const reference = service?.getReference?.();
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineAppJson, defineComponentJson, definePageJson, defineSitemapJson, defineThemeJson } from "./json.mjs";
|
|
2
2
|
import { a as resolveWeappViteHostMeta, i as isWeappViteHost, n as applyWeappViteHostMeta, r as createWeappViteHostMeta, t as WEAPP_VITE_HOST_NAME } from "./pluginHost-SJdl15d3.mjs";
|
|
3
3
|
import { defineConfig } from "./config.mjs";
|
|
4
|
-
import { t as createCompilerContext } from "./createContext-
|
|
4
|
+
import { t as createCompilerContext } from "./createContext-DZgOqIMU.mjs";
|
|
5
5
|
import { defineEmits, defineProps } from "./runtime.mjs";
|
|
6
6
|
import { createWevuComponent, setPageLayout } from "wevu";
|
|
7
7
|
export { WEAPP_VITE_HOST_NAME, applyWeappViteHostMeta, createCompilerContext, createWeappViteHostMeta, createWevuComponent, defineAppJson, defineComponentJson, defineConfig, defineEmits, definePageJson, defineProps, defineSitemapJson, defineThemeJson, isWeappViteHost, resolveWeappViteHostMeta, setPageLayout };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weapp-vite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.11.
|
|
4
|
+
"version": "6.11.7",
|
|
5
5
|
"description": "weapp-vite 一个现代化的小程序打包工具",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -106,26 +106,26 @@
|
|
|
106
106
|
"picomatch": "^4.0.4",
|
|
107
107
|
"postcss": "^8.5.8",
|
|
108
108
|
"rolldown": "1.0.0-rc.11",
|
|
109
|
-
"rolldown-plugin-dts": "0.
|
|
109
|
+
"rolldown-plugin-dts": "0.23.0",
|
|
110
110
|
"semver": "^7.7.4",
|
|
111
111
|
"typescript": "^6.0.2",
|
|
112
|
-
"vite": "8.0.
|
|
112
|
+
"vite": "8.0.3",
|
|
113
113
|
"vite-tsconfig-paths": "^6.1.1",
|
|
114
|
-
"vue": "^3.5.
|
|
114
|
+
"vue": "^3.5.31",
|
|
115
115
|
"vue-tsc": "^3.2.6",
|
|
116
116
|
"@weapp-core/init": "6.0.5",
|
|
117
117
|
"@weapp-core/logger": "3.1.1",
|
|
118
118
|
"@weapp-core/schematics": "6.0.4",
|
|
119
119
|
"@weapp-core/shared": "3.0.2",
|
|
120
|
-
"@weapp-vite/ast": "6.11.
|
|
120
|
+
"@weapp-vite/ast": "6.11.7",
|
|
121
121
|
"@weapp-vite/mcp": "1.1.1",
|
|
122
122
|
"@weapp-vite/volar": "2.0.8",
|
|
123
|
-
"@weapp-vite/web": "1.3.
|
|
123
|
+
"@weapp-vite/web": "1.3.8",
|
|
124
124
|
"@wevu/api": "0.2.2",
|
|
125
|
-
"rolldown-require": "2.0.
|
|
125
|
+
"rolldown-require": "2.0.10",
|
|
126
126
|
"vite-plugin-performance": "2.0.1",
|
|
127
127
|
"weapp-ide-cli": "5.1.2",
|
|
128
|
-
"wevu": "6.11.
|
|
128
|
+
"wevu": "6.11.7"
|
|
129
129
|
},
|
|
130
130
|
"publishConfig": {
|
|
131
131
|
"access": "public",
|