weapp-vite 7.5.0 → 7.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/THIRD_PARTY_NOTICES.md +60 -0
- package/dist/action-B3YZMA-h.mjs +255 -0
- package/dist/action-BELcDNNv.mjs +139 -0
- package/dist/action-BOk3vGI7.mjs +1110 -0
- package/dist/action-DlC6JYpt.mjs +95 -0
- package/dist/action-zEDY7oh_.mjs +247 -0
- package/dist/{analyze-ZJUvEdaY.mjs → analyze-DN79YOAH.mjs} +1 -65
- package/dist/artifacts-BOyC9Fy-.mjs +106 -0
- package/dist/assets-C5_YYXNk.mjs +637 -0
- package/dist/auto-routes.mjs +2 -2
- package/dist/{budget-BD7VqLCl.d.mts → budget-CTLOHwgI.d.mts} +1 -2
- package/dist/budget-EOeEycc_.mjs +65 -0
- package/dist/builtProject-C29udgXY.mjs +541 -0
- package/dist/{chunkStrategy-DRA5WpB-.mjs → chunkStrategy-DY_LZIIe.mjs} +15 -3
- package/dist/{package-7swhyLmf.mjs → classifier-DBJY__kg.mjs} +4 -7
- package/dist/cli-acceptance.mjs +1 -1
- package/dist/cli.mjs +110 -4506
- package/dist/{config-V0L-IAJf.d.mts → config-Bf6DWhyb.d.mts} +136 -49
- package/dist/config.d.mts +2 -2
- package/dist/{createCompilerContextInstance-DJH_P_nZ.mjs → createCompilerContextInstance-aYwi8wQt.mjs} +15235 -9523
- package/dist/{createContext-BqYzHhY9.mjs → createContext-tApLtII-.mjs} +6 -3
- package/dist/dashboard/analyze.d.mts +1 -1
- package/dist/dashboard/analyze.mjs +3 -1
- package/dist/dashboard/vite.d.mts +1 -1
- package/dist/dashboard.d.mts +2 -2
- package/dist/dashboard.mjs +1749 -1
- package/dist/dashboardTransport-C_Y6jMp-.mjs +16 -0
- package/dist/{dashboardViteBridge-Dy3nAD4m.mjs → dashboardViteBridge-DCGR43aM.mjs} +8 -5
- package/dist/{dev-fR5GiJRO.mjs → dev-C2fgr_Xd.mjs} +5 -1
- package/dist/devProvider-D-hTfsEO.mjs +3027 -0
- package/dist/docs/README.md +8 -2
- package/dist/docs/mcp.md +10 -0
- package/dist/docs/troubleshooting.md +8 -0
- package/dist/docs/vue-sfc.md +25 -2
- package/dist/doctor-worker.mjs +3 -2
- package/dist/doctor.d.mts +2 -2
- package/dist/doctor.mjs +15 -13
- package/dist/engine-C66J0HLz.mjs +54 -0
- package/dist/{file-sC3jD7Fh.mjs → file-CcIOmqhC.mjs} +47 -19
- package/dist/file-DtcteQ4G.mjs +1 -0
- package/dist/forwardConsole-B0Reo8Lf.mjs +511 -0
- package/dist/getInstance-BAIaU2y9.mjs +1 -0
- package/dist/{getInstance-DiGSzBNI.mjs → getInstance-Dt9IQDKr.mjs} +1 -1
- package/dist/history-BIiRCzbq.mjs +784 -0
- package/dist/i18n.d.mts +1 -1
- package/dist/{index-C9HjUX5c.d.mts → index-D5rgBzYZ.d.mts} +1 -2
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/json.d.mts +1 -1
- package/dist/lib-DjccSI1B.mjs +143 -0
- package/dist/{lifecycle-BROTlwSL.mjs → lifecycle-C36WSbQS.mjs} +120 -27
- package/dist/{loadConfig-C3BQhz7F.mjs → loadConfig-BWIsDXR4.mjs} +1 -1
- package/dist/loadConfig-D-BpBgsk.mjs +1 -0
- package/dist/logBuildAppFinish-ChjwATMv.mjs +57 -0
- package/dist/mcp-CYgX9HpO.mjs +86 -0
- package/dist/mcp.d.mts +1 -1
- package/dist/mcpClient-DVLvFLZv.mjs +287 -0
- package/dist/{processCleanup-B6KA30Zc.mjs → metadata-hwF7QRcS.mjs} +1 -19
- package/dist/nodeEnv-BmH8UZPR.mjs +7 -0
- package/dist/openIde-CroqOgk5.mjs +648 -0
- package/dist/options-jqFwfD1G.mjs +34 -0
- package/dist/package-Cmakyy3J.mjs +4 -0
- package/dist/path-CYYIQGS7.mjs +44 -0
- package/dist/processCleanup-BQn2kTcK.mjs +19 -0
- package/dist/{protocol-vg8HGJ4n.mjs → protocol-Cg6Jdlvb.mjs} +42 -39
- package/dist/reader-sh_POQ9-.mjs +93 -0
- package/dist/realpathScope-Tf9mz-fh.mjs +23 -0
- package/dist/report-hyonPGbZ.mjs +107 -0
- package/dist/{path-doV773b7.mjs → resolvedId-CiDl7SC1.mjs} +3 -46
- package/dist/runtime-CLUhQsdA.mjs +43 -0
- package/dist/{runtime-Ee2HY6gR.d.mts → runtime-DpVf714f.d.mts} +1 -1
- package/dist/runtime.d.mts +1 -1
- package/dist/schematics-kO26eQRT.mjs +91 -0
- package/dist/{session-PskhD-nZ.mjs → session-D3zsdzIy.mjs} +71 -9
- package/dist/test.mjs +10 -8
- package/dist/{types-CgZn5X6j.d.mts → types-D-kfuyVa.d.mts} +1 -2
- package/dist/types-D0FFexRF.d.mts +39 -0
- package/dist/types.d.mts +2 -2
- package/dist/{upload-D4msblBf.mjs → upload-DozK8UdN.mjs} +109 -5
- package/dist/upload-worker.mjs +1 -1
- package/dist/{utils-CJSCgEj6.mjs → utils-Dy51PYAC.mjs} +56 -116
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +51 -12
- package/dist/wxs-BT8btflA.mjs +112 -0
- package/dist/wxs-Z4VQDeJ_.mjs +1 -0
- package/package.json +52 -46
- package/dist/dashboard-DvqF3Key.mjs +0 -1842
- package/dist/devProvider-BGBkw28J.mjs +0 -1050
- package/dist/file-DRb4eWqw.mjs +0 -1
- package/dist/getInstance-SiE6WZRh.mjs +0 -1
- package/dist/loadConfig-VGtBF4qm.mjs +0 -1
- package/dist/mcp-D3Yh24Cj.mjs +0 -529
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as normalizeFsResolvedId, t as isSkippableResolvedId } from "./resolvedId-CiDl7SC1.mjs";
|
|
2
|
+
import { i as normalizeRoot, s as toPosixPath } from "./path-CYYIQGS7.mjs";
|
|
2
3
|
import { S as shouldNormalizeUsingComponents, l as getProjectPlatformOptions, p as normalizePlatformNpmImportPath, v as shouldFillComponentGenericsDefault, x as shouldNormalizePlatformNpmImportPath } from "./platform-CnkySBKz.mjs";
|
|
3
|
-
import {
|
|
4
|
+
import { o as changeFileExtension } from "./file-CcIOmqhC.mjs";
|
|
4
5
|
import { i as scriptExtensions, s as vueExtensions } from "./constants-DEZdcsMn.mjs";
|
|
5
6
|
import "./logger-DGn5iEVN.mjs";
|
|
7
|
+
import { n as loadHostRolldownBuild } from "./engine-C66J0HLz.mjs";
|
|
6
8
|
import { createRequire } from "node:module";
|
|
7
9
|
import process from "node:process";
|
|
8
10
|
import path from "pathe";
|
|
9
11
|
import { existsSync, readFileSync } from "node:fs";
|
|
10
|
-
import { pathToFileURL } from "node:url";
|
|
11
12
|
import path$1 from "node:path";
|
|
12
13
|
import { defuOverrideArray, get, isObject, removeExtensionDeep, set } from "@weapp-core/shared";
|
|
13
14
|
import { parse, stringify } from "comment-json";
|
|
14
15
|
import { fs as fs$1 } from "@weapp-core/shared/fs";
|
|
15
16
|
import { parseJsLikeWithEngine } from "@weapp-vite/ast";
|
|
16
|
-
import { BABEL_TS_MODULE_PARSER_OPTIONS as BABEL_TS_MODULE_PARSER_OPTIONS$1, generate as generate$1, parse as parse$2, parseJsLike as parseJsLike$1, traverse as traverse$1 } from "@weapp-vite/ast/babel";
|
|
17
|
+
import { BABEL_TS_MODULE_PARSER_OPTIONS as BABEL_TS_MODULE_PARSER_OPTIONS$1, generate as generate$1, getVisitorKeys, parse as parse$2, parseJsLike as parseJsLike$1, traverse as traverse$1 } from "@weapp-vite/ast/babel";
|
|
17
18
|
import picomatch from "picomatch";
|
|
18
19
|
import { invalidateFileCache, pathExists, readFile as readFile$2 } from "wevu/compiler";
|
|
19
20
|
import fs$2, { readFile as readFile$1, readdir, realpath, unlink } from "node:fs/promises";
|
|
@@ -744,56 +745,6 @@ async function pruneOwnedAssetFiles(outDir, fileNames) {
|
|
|
744
745
|
}
|
|
745
746
|
}
|
|
746
747
|
//#endregion
|
|
747
|
-
//#region src/runtime/viteHost/engine.ts
|
|
748
|
-
function readIdentity(file) {
|
|
749
|
-
const value = JSON.parse(readFileSync(file, "utf8"));
|
|
750
|
-
if (!value || typeof value !== "object" || !("name" in value) || typeof value.name !== "string" || !("version" in value) || typeof value.version !== "string") throw new Error("[weapp-vite] Vite 宿主 package.json 缺少 name/version。");
|
|
751
|
-
return {
|
|
752
|
-
name: value.name,
|
|
753
|
-
version: value.version
|
|
754
|
-
};
|
|
755
|
-
}
|
|
756
|
-
/** 按宿主的真实导出解析引擎,不依赖扁平 node_modules 布局或版本号相等。 */
|
|
757
|
-
function resolveViteHost(importer = import.meta.url) {
|
|
758
|
-
const packagePath = createRequire(importer).resolve("vite/package.json");
|
|
759
|
-
const identity = readIdentity(packagePath);
|
|
760
|
-
const hostRequire = createRequire(packagePath);
|
|
761
|
-
if (identity.name === "@voidzero-dev/vite-plus-core") return {
|
|
762
|
-
kind: "vite-plus",
|
|
763
|
-
packagePath,
|
|
764
|
-
packageVersion: identity.version,
|
|
765
|
-
experimentalPath: hostRequire.resolve("@voidzero-dev/vite-plus-core/rolldown/experimental")
|
|
766
|
-
};
|
|
767
|
-
if (identity.name !== "vite") throw new Error(`[weapp-vite] 不支持的 Vite 宿主:${identity.name}@${identity.version}。`);
|
|
768
|
-
return {
|
|
769
|
-
kind: "vite",
|
|
770
|
-
packagePath,
|
|
771
|
-
packageVersion: identity.version,
|
|
772
|
-
experimentalPath: hostRequire.resolve("rolldown/experimental")
|
|
773
|
-
};
|
|
774
|
-
}
|
|
775
|
-
/** 加载与宿主绑定的引擎;缺失能力时保留原始错误,禁止回退到另一套引擎。 */
|
|
776
|
-
async function loadHostRolldown(importer) {
|
|
777
|
-
let identity;
|
|
778
|
-
try {
|
|
779
|
-
identity = resolveViteHost(importer);
|
|
780
|
-
const runtime = await import(pathToFileURL(identity.experimentalPath).href);
|
|
781
|
-
if (typeof runtime.dev !== "function" || typeof runtime.scan !== "function") throw new TypeError("Rolldown 缺少 dev/scan 能力");
|
|
782
|
-
return runtime;
|
|
783
|
-
} catch (cause) {
|
|
784
|
-
const host = identity ? `${identity.kind}@${identity.packageVersion}` : "vite";
|
|
785
|
-
throw new Error(`[weapp-vite] 无法加载 ${host} 配套的 Rolldown;请检查宿主依赖和 Vite+ alias 配置。`, { cause });
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
/** 原生输出写出也绑定宿主引擎,避免 Vite+ 额外加载包内另一套 Rolldown。 */
|
|
789
|
-
async function loadHostRolldownBuild(importer) {
|
|
790
|
-
const identity = resolveViteHost(importer);
|
|
791
|
-
const entry = createRequire(identity.packagePath).resolve(identity.kind === "vite-plus" ? "@voidzero-dev/vite-plus-core/rolldown" : "rolldown");
|
|
792
|
-
const runtime = await import(pathToFileURL(entry).href);
|
|
793
|
-
if (typeof runtime.rolldown !== "function") throw new TypeError(`[weapp-vite] ${identity.kind}@${identity.packageVersion} 缺少 Rolldown 原生写出能力。`);
|
|
794
|
-
return runtime;
|
|
795
|
-
}
|
|
796
|
-
//#endregion
|
|
797
748
|
//#region src/utils/projectConfigOutput.ts
|
|
798
749
|
/** 平台项目目录独立发布,禁止覆盖由主编译持有的小程序目录。 */
|
|
799
750
|
async function collectProjectConfigAssets(sourceDir, outputRoot, outDir, watch) {
|
|
@@ -854,13 +805,13 @@ async function publishProjectConfigAssets(outputRoot, assets, previous = /* @__P
|
|
|
854
805
|
}
|
|
855
806
|
//#endregion
|
|
856
807
|
//#region src/utils/projectConfig.ts
|
|
857
|
-
async function readProjectConfigFile(filePath, required) {
|
|
808
|
+
async function readProjectConfigFile(filePath, required, readFile) {
|
|
858
809
|
if (!await fs$1.pathExists(filePath)) {
|
|
859
810
|
if (required) throw new Error(`找不到项目配置文件:${filePath}`);
|
|
860
811
|
return {};
|
|
861
812
|
}
|
|
862
813
|
try {
|
|
863
|
-
return await fs$1.readJson(filePath) || {};
|
|
814
|
+
return readFile ? JSON.parse((await readFile(filePath)).replace(/^\uFEFF/, "")) || {} : await fs$1.readJson(filePath) || {};
|
|
864
815
|
} catch {
|
|
865
816
|
throw new Error(`解析 json 格式失败, ${filePath} 为非法的 json 格式`);
|
|
866
817
|
}
|
|
@@ -885,23 +836,12 @@ function resolveProjectConfigRoot(projectConfig, platform) {
|
|
|
885
836
|
async function getProjectConfig(root, options) {
|
|
886
837
|
const baseJsonPath = path.resolve(root, options?.basePath ?? "project.config.json");
|
|
887
838
|
const privateJsonPath = path.resolve(root, options?.privatePath ?? "project.private.config.json");
|
|
888
|
-
const baseJson = await readProjectConfigFile(baseJsonPath, true);
|
|
889
|
-
const privateJson = options?.ignorePrivate ? {} : await readProjectConfigFile(privateJsonPath, false);
|
|
839
|
+
const baseJson = await readProjectConfigFile(baseJsonPath, true, options?.readFile);
|
|
840
|
+
const privateJson = options?.ignorePrivate ? {} : await readProjectConfigFile(privateJsonPath, false, options?.readFile);
|
|
890
841
|
return defuOverrideArray(privateJson, baseJson);
|
|
891
842
|
}
|
|
892
843
|
async function getProjectPrivateConfig(root, options) {
|
|
893
|
-
return await readProjectConfigFile(path.resolve(root, options?.privatePath ?? "project.private.config.json"), false);
|
|
894
|
-
}
|
|
895
|
-
async function disableProjectPrivateConfigHotReload(filePath) {
|
|
896
|
-
const config = await readProjectConfigFile(filePath, true);
|
|
897
|
-
const setting = config.setting && typeof config.setting === "object" && !Array.isArray(config.setting) ? config.setting : {};
|
|
898
|
-
if (setting.compileHotReLoad === false) return false;
|
|
899
|
-
config.setting = {
|
|
900
|
-
...setting,
|
|
901
|
-
compileHotReLoad: false
|
|
902
|
-
};
|
|
903
|
-
await fs$1.writeFile(filePath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
904
|
-
return true;
|
|
844
|
+
return await readProjectConfigFile(path.resolve(root, options?.privatePath ?? "project.private.config.json"), false, options?.readFile);
|
|
905
845
|
}
|
|
906
846
|
function resolveProjectConfigSyncDirs(options) {
|
|
907
847
|
const outputRoot = path.dirname(options.outDir);
|
|
@@ -930,11 +870,9 @@ async function syncProjectConfigToOutput(options) {
|
|
|
930
870
|
}
|
|
931
871
|
//#endregion
|
|
932
872
|
//#region src/utils/reExport.ts
|
|
933
|
-
function
|
|
934
|
-
|
|
935
|
-
if (
|
|
936
|
-
if (exported.type === "Identifier") return exported.name;
|
|
937
|
-
if (exported.type === "StringLiteral") return exported.value;
|
|
873
|
+
function getSpecifierName(name) {
|
|
874
|
+
if (name?.type === "Identifier") return name.name;
|
|
875
|
+
if (name?.type === "StringLiteral" || name?.type === "Literal") return name.value;
|
|
938
876
|
}
|
|
939
877
|
function getSourceValue(node) {
|
|
940
878
|
const source = node?.source;
|
|
@@ -951,65 +889,67 @@ function parseModuleForReExport(code, astEngine) {
|
|
|
951
889
|
});
|
|
952
890
|
return parse$2(code, BABEL_TS_MODULE_PARSER_OPTIONS$1).program;
|
|
953
891
|
}
|
|
954
|
-
async function
|
|
955
|
-
if (depth <= 0) return;
|
|
956
|
-
if (visited.has(exporterFile)) return;
|
|
957
|
-
visited.add(exporterFile);
|
|
892
|
+
async function readReExportFacts(exporterFile, options) {
|
|
958
893
|
const cacheKey = getReExportCacheKey(exporterFile, options.astEngine);
|
|
959
|
-
let
|
|
960
|
-
if (!entry) {
|
|
961
|
-
entry = /* @__PURE__ */ new Map();
|
|
962
|
-
options.cache.set(cacheKey, entry);
|
|
963
|
-
}
|
|
964
|
-
if (entry.has(exportName)) return entry.get(exportName);
|
|
965
|
-
let code;
|
|
894
|
+
let source;
|
|
966
895
|
try {
|
|
967
|
-
|
|
896
|
+
source = await options.readFile(exporterFile);
|
|
968
897
|
} catch {
|
|
969
|
-
|
|
898
|
+
options.cache.delete(cacheKey);
|
|
970
899
|
return;
|
|
971
900
|
}
|
|
972
|
-
|
|
901
|
+
const cached = options.cache.get(cacheKey);
|
|
902
|
+
if (cached?.source === source) return cached;
|
|
903
|
+
const facts = {
|
|
904
|
+
source,
|
|
905
|
+
named: /* @__PURE__ */ new Map(),
|
|
906
|
+
exportAll: []
|
|
907
|
+
};
|
|
973
908
|
try {
|
|
974
|
-
ast = parseModuleForReExport(
|
|
975
|
-
|
|
976
|
-
entry.set(exportName, void 0);
|
|
977
|
-
return;
|
|
978
|
-
}
|
|
979
|
-
const exportAllSources = [];
|
|
980
|
-
for (const node of ast.body ?? []) {
|
|
981
|
-
if (node?.type === "ExportNamedDeclaration") {
|
|
909
|
+
const ast = parseModuleForReExport(source, options.astEngine);
|
|
910
|
+
for (const node of ast.body) {
|
|
982
911
|
const source = getSourceValue(node);
|
|
983
912
|
if (!source) continue;
|
|
984
|
-
for (const spec of node.specifiers ?? []) {
|
|
913
|
+
if (node?.type === "ExportNamedDeclaration") for (const spec of node.specifiers ?? []) {
|
|
985
914
|
if (spec?.type !== "ExportSpecifier") continue;
|
|
986
|
-
const
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
}
|
|
915
|
+
const name = getSpecifierName(spec.exported);
|
|
916
|
+
const imported = getSpecifierName(spec.local);
|
|
917
|
+
if (name && imported) facts.named.set(name, {
|
|
918
|
+
source,
|
|
919
|
+
imported
|
|
920
|
+
});
|
|
993
921
|
}
|
|
922
|
+
else if (node?.type === "ExportAllDeclaration") facts.exportAll.push(source);
|
|
994
923
|
}
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
924
|
+
} catch {}
|
|
925
|
+
options.cache.set(cacheKey, facts);
|
|
926
|
+
return facts;
|
|
927
|
+
}
|
|
928
|
+
async function resolveReExportedInternal(exporterFile, exportName, depth, visited, options) {
|
|
929
|
+
const key = `${exporterFile}\0${exportName}`;
|
|
930
|
+
if (depth <= 0 || (visited.get(key) ?? 0) >= depth) return;
|
|
931
|
+
visited.set(key, depth);
|
|
932
|
+
const facts = await readReExportFacts(exporterFile, options);
|
|
933
|
+
if (!facts) return;
|
|
934
|
+
const binding = facts.named.get(exportName);
|
|
935
|
+
if (binding) {
|
|
936
|
+
const resolved = await options.resolveId(binding.source, exporterFile);
|
|
937
|
+
if (!resolved) return;
|
|
938
|
+
if (binding.imported !== "default") return resolveReExportedInternal(resolved, binding.imported, depth - 1, visited, options);
|
|
939
|
+
if (/\.(?:[cm]?ts|[cm]?js)$/.test(resolved)) {
|
|
940
|
+
if ((await readReExportFacts(resolved, options))?.named.has("default")) return resolveReExportedInternal(resolved, "default", depth - 1, visited, options);
|
|
998
941
|
}
|
|
942
|
+
return resolved;
|
|
999
943
|
}
|
|
1000
|
-
for (const source of
|
|
944
|
+
for (const source of facts.exportAll) {
|
|
1001
945
|
const hopId = await options.resolveId(source, exporterFile);
|
|
1002
946
|
if (!hopId) continue;
|
|
1003
947
|
const nested = await resolveReExportedInternal(hopId, exportName, depth - 1, visited, options);
|
|
1004
|
-
if (nested)
|
|
1005
|
-
entry.set(exportName, nested);
|
|
1006
|
-
return nested;
|
|
1007
|
-
}
|
|
948
|
+
if (nested) return nested;
|
|
1008
949
|
}
|
|
1009
|
-
entry.set(exportName, void 0);
|
|
1010
950
|
}
|
|
1011
951
|
async function resolveReExportedName(exporterFile, exportName, options) {
|
|
1012
|
-
return resolveReExportedInternal(exporterFile, exportName, options.maxDepth ?? 4, /* @__PURE__ */ new
|
|
952
|
+
return resolveReExportedInternal(exporterFile, exportName, options.maxDepth ?? 4, /* @__PURE__ */ new Map(), options);
|
|
1013
953
|
}
|
|
1014
954
|
//#endregion
|
|
1015
955
|
//#region src/utils/toAbsoluteId.ts
|
|
@@ -1091,4 +1031,4 @@ async function resolveWeappConfigFile(options) {
|
|
|
1091
1031
|
return findWeappConfigInDirectory(root);
|
|
1092
1032
|
}
|
|
1093
1033
|
//#endregion
|
|
1094
|
-
export {
|
|
1034
|
+
export { resolveNpmDependencyId as $, createCjsConfigLoadError as A, WEAPP_SCOPED_SLOT_GENERIC_COMPONENT_PLACEHOLDER as B, loadViteConfigFile as C, invalidateFileCache as D, resolveEntryPath as E, getVisitorKeys as F, parseCommentJson as G, jsonFileRemoveJsExtension as H, parse$2 as I, toKebabCaseComponentName as J, resolveImportee as K, parseJsLike$1 as L, getReadFileCheckMtime as M, BABEL_TS_MODULE_PARSER_OPTIONS$1 as N, pathExists as O, generate$1 as P, parseNpmPackageSpecifier as Q, traverse$1 as R, TYPELESS_PACKAGE_JSON_WARNING_CODE as S, resolveEntryExtensions as T, matches as U, getAliasEntries as V, normalizeAppJson as W, normalizeNpmImportLookupPath as X, hasNpmDependencyPrefix as Y, normalizeNpmImportPathByPlatform as Z, applyPreloadRulesToAppJson as _, resolveReExportedName as a, resolvePreloadPackageIdentifier as b, getProjectConfigRootKeys as c, resolveProjectConfigRoot as d, resolveProjectConfigSyncDirs as f, pruneOwnedAssetFiles as g, publishProjectConfigAssets as h, toAbsoluteId as i, getPathExistsTtlMs as j, readFile$2 as k, getProjectPrivateConfig as l, collectProjectConfigAssets as m, shouldResolveUsingComponentFrom as n, getProjectConfig as o, syncProjectConfigToOutput as p, resolveJson as q, usingComponentFromResolvedFile as r, getProjectConfigFileName as s, resolveWeappConfigFile as t, getProjectPrivateConfigFileName as u, collectPreloadPages as v, createCachedEntryResolveOptions as w, suggestPreloadRules as x, findPreloadRuleKey as y, ALIPAY_GENERIC_COMPONENT_PLACEHOLDER as z };
|
package/dist/vite.d.mts
CHANGED
package/dist/vite.mjs
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
import { i as isWeappViteHost } from "./pluginHost--CaeyWpA.mjs";
|
|
2
|
-
import { t as bindHostLifecycle } from "./lifecycle-
|
|
2
|
+
import { i as takeHostLifecycle, n as setHostRestartData, r as takeHostConfigRestartData, t as bindHostLifecycle } from "./lifecycle-C36WSbQS.mjs";
|
|
3
3
|
import process from "node:process";
|
|
4
|
+
import { WEAPP_VITE_HMR_RUNTIME_SESSION_HANDOFF_KEY } from "@weapp-core/constants";
|
|
4
5
|
import path from "pathe";
|
|
6
|
+
//#region src/vite/classicFallback.ts
|
|
7
|
+
/** 停止失败的宿主时同时保留原始错误与清理错误。 */
|
|
8
|
+
async function rethrowAfterHostCleanup(error, cleanup) {
|
|
9
|
+
try {
|
|
10
|
+
await cleanup();
|
|
11
|
+
} catch (cleanupError) {
|
|
12
|
+
if (cleanupError === error) throw error;
|
|
13
|
+
throw new AggregateError([error, cleanupError], "Host operation and cleanup failed", { cause: error });
|
|
14
|
+
}
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
/** 通过公共宿主重启交接到 classic,当前构建只发布请求,不等待关闭自己。 */
|
|
18
|
+
function bindClassicFallback(server, runtime) {
|
|
19
|
+
return runtime.bindRequest(async () => {
|
|
20
|
+
try {
|
|
21
|
+
await server.restart();
|
|
22
|
+
} catch (error) {
|
|
23
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
24
|
+
server.config.logger.error("[weapp-vite] classic 回退失败,开发会话已停止。", { error: failure });
|
|
25
|
+
await rethrowAfterHostCleanup(failure, () => server.close());
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
5
30
|
//#region src/vite/environment.ts
|
|
6
31
|
/** 环境钩子捕获本轮会话,旧环境关闭不能清理重启后的新会话。 */
|
|
7
32
|
function createSessionEnvironmentPlugin(session, serve) {
|
|
@@ -53,7 +78,8 @@ function createSessionEnvironmentPlugin(session, serve) {
|
|
|
53
78
|
}
|
|
54
79
|
},
|
|
55
80
|
async closeWatcher() {
|
|
56
|
-
await session.close
|
|
81
|
+
if (serve) await session.closeHostGeneration("close");
|
|
82
|
+
else await session.close();
|
|
57
83
|
}
|
|
58
84
|
};
|
|
59
85
|
}
|
|
@@ -167,12 +193,14 @@ function createPluginSlots(apply) {
|
|
|
167
193
|
//#endregion
|
|
168
194
|
//#region src/vite/index.ts
|
|
169
195
|
const PLUGIN_NAME = "weapp-vite:host";
|
|
196
|
+
const hmrRuntimeSessionKey = Symbol.for(WEAPP_VITE_HMR_RUNTIME_SESSION_HANDOFF_KEY);
|
|
170
197
|
/** 通过顶层 weapp 配置激活标准 Vite 小程序编译。 */
|
|
171
198
|
function weapp() {
|
|
172
199
|
let session;
|
|
173
200
|
let initializing = false;
|
|
174
201
|
let inactive = false;
|
|
175
202
|
let serveRequested = false;
|
|
203
|
+
let inheritedLifecycle;
|
|
176
204
|
const apply = (config) => !isWeappViteHost(config);
|
|
177
205
|
const slots = createPluginSlots(apply);
|
|
178
206
|
const coordinator = {
|
|
@@ -185,6 +213,7 @@ function weapp() {
|
|
|
185
213
|
if (initializing || session && session.state !== "closed") throw new Error("[weapp-vite] 同一插件实例不能被多个活动宿主复用,请为每个宿主调用 weapp()。");
|
|
186
214
|
initializing = true;
|
|
187
215
|
try {
|
|
216
|
+
inheritedLifecycle = takeHostLifecycle(config);
|
|
188
217
|
session = void 0;
|
|
189
218
|
serveRequested = false;
|
|
190
219
|
slots.bind([]);
|
|
@@ -200,10 +229,17 @@ function weapp() {
|
|
|
200
229
|
...config,
|
|
201
230
|
plugins: serveRequested ? userPlugins : []
|
|
202
231
|
};
|
|
203
|
-
const { WeappBuildSession } = await import("./session-
|
|
204
|
-
session = new WeappBuildSession();
|
|
232
|
+
const { WeappBuildSession } = await import("./session-D3zsdzIy.mjs");
|
|
233
|
+
session = new WeappBuildSession(takeHostConfigRestartData(inheritedLifecycle, hmrRuntimeSessionKey));
|
|
205
234
|
try {
|
|
206
|
-
const
|
|
235
|
+
const fallbackBeforePrepare = session.hmrRuntimeSession.fallback;
|
|
236
|
+
let merged = await session.prepare(hostConfig, path.resolve(config.root ?? process.cwd()), env.mode, serveRequested);
|
|
237
|
+
if (session.hmrRuntimeSession.phase === "switching" && session.hmrRuntimeSession.fallback !== fallbackBeforePrepare) {
|
|
238
|
+
const runtime = session.hmrRuntimeSession;
|
|
239
|
+
await session.close("restart");
|
|
240
|
+
session = new WeappBuildSession(runtime);
|
|
241
|
+
merged = await session.prepare(hostConfig, path.resolve(config.root ?? process.cwd()), env.mode, serveRequested);
|
|
242
|
+
}
|
|
207
243
|
session.context.configService.options.sourceConfig = {
|
|
208
244
|
...hostConfig,
|
|
209
245
|
root: session.context.configService.cwd,
|
|
@@ -216,8 +252,8 @@ function weapp() {
|
|
|
216
252
|
return normalized;
|
|
217
253
|
}
|
|
218
254
|
if (serveRequested) {
|
|
219
|
-
const { prepareDevHostConfig } = await import("./dev-
|
|
220
|
-
if (!session.statefulController && config.experimental?.bundledDev) throw new Error("[weapp-vite] classic 开发模式暂不支持 experimental.bundledDev,请关闭此选项。");
|
|
255
|
+
const { prepareDevHostConfig } = await import("./dev-C2fgr_Xd.mjs");
|
|
256
|
+
if (!session.statefulController && config.experimental?.bundledDev && !session.hmrRuntimeSession.fallback) throw new Error("[weapp-vite] classic 开发模式暂不支持 experimental.bundledDev,请关闭此选项。");
|
|
221
257
|
const host = prepareDevHostConfig(session, merged, config);
|
|
222
258
|
slots.bind((await resolvePlugins(host.plugins)).filter((plugin) => !configuredPlugins.includes(plugin)));
|
|
223
259
|
return host.config;
|
|
@@ -228,8 +264,7 @@ function weapp() {
|
|
|
228
264
|
if (normalized.build) normalized.build.emptyOutDir = config.build?.emptyOutDir;
|
|
229
265
|
return normalized;
|
|
230
266
|
} catch (error) {
|
|
231
|
-
await
|
|
232
|
-
throw error;
|
|
267
|
+
return await rethrowAfterHostCleanup(error, () => session.close(inheritedLifecycle ? "restart" : "close"));
|
|
233
268
|
}
|
|
234
269
|
} finally {
|
|
235
270
|
initializing = false;
|
|
@@ -247,13 +282,17 @@ function weapp() {
|
|
|
247
282
|
return result;
|
|
248
283
|
};
|
|
249
284
|
}
|
|
250
|
-
bindHostLifecycle(server, () => active.
|
|
285
|
+
bindHostLifecycle(server, (reason) => active.closeHostGeneration(reason), inheritedLifecycle, () => active.hmrRuntimeSession.phase === "switching", () => active.releaseHostClassicIdeConfig());
|
|
286
|
+
inheritedLifecycle = void 0;
|
|
251
287
|
try {
|
|
288
|
+
await setHostRestartData(server, hmrRuntimeSessionKey, active.hmrRuntimeSession);
|
|
252
289
|
await active.startDev(server);
|
|
253
290
|
} catch (error) {
|
|
254
|
-
await
|
|
255
|
-
throw error;
|
|
291
|
+
return await rethrowAfterHostCleanup(error, () => server.close());
|
|
256
292
|
}
|
|
293
|
+
return () => {
|
|
294
|
+
if (!active.isClosing) active.onClose(bindClassicFallback(server, active.hmrRuntimeSession));
|
|
295
|
+
};
|
|
257
296
|
},
|
|
258
297
|
configResolved(config) {
|
|
259
298
|
if (inactive || !session) return;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { addExtension } from "@weapp-core/shared";
|
|
3
|
+
import * as t from "@weapp-vite/ast/babelTypes";
|
|
4
|
+
import * as babel from "@weapp-vite/ast/babelCore";
|
|
5
|
+
//#region src/wxs/utils.ts
|
|
6
|
+
function normalizeWxsFilename(value, extension = "wxs") {
|
|
7
|
+
const normalized = extension.startsWith(".") ? extension.slice(1) : extension;
|
|
8
|
+
let filename = value;
|
|
9
|
+
filename = filename.replace(/\.[jt]s$/i, "");
|
|
10
|
+
filename = filename.replace(/\.(wxs|sjs)$/i, "");
|
|
11
|
+
return addExtension(filename, `.${normalized}`);
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/wxs/index.ts
|
|
15
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
16
|
+
let babelPresets;
|
|
17
|
+
/** 首次转换才加载 presets,兼容 Babel 的 ESM default 与 CommonJS 导出。 */
|
|
18
|
+
function loadBabelPreset(name) {
|
|
19
|
+
const loaded = nodeRequire(name);
|
|
20
|
+
return loaded.default ?? loaded;
|
|
21
|
+
}
|
|
22
|
+
function getBabelPresets() {
|
|
23
|
+
return babelPresets ??= {
|
|
24
|
+
env: loadBabelPreset("@babel/preset-env"),
|
|
25
|
+
typescript: loadBabelPreset("@babel/preset-typescript")
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function transformWxsCode(code, options) {
|
|
29
|
+
const presets = getBabelPresets();
|
|
30
|
+
const filename = options?.filename ?? "script.ts";
|
|
31
|
+
const extension = options?.extension ?? "wxs";
|
|
32
|
+
const preserveEsmExports = extension.replace(/^\./, "") === "sjs";
|
|
33
|
+
const importees = [];
|
|
34
|
+
const maybePushImportee = (value) => {
|
|
35
|
+
if (typeof value !== "string" || !value) return;
|
|
36
|
+
importees.push({ source: value });
|
|
37
|
+
};
|
|
38
|
+
const tryCollectArgument = (path) => {
|
|
39
|
+
const node = path.node;
|
|
40
|
+
if (t.isStringLiteral(node)) {
|
|
41
|
+
maybePushImportee(node.value);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (t.isTemplateLiteral(node) && node.expressions.length === 0) {
|
|
45
|
+
const value = node.quasis.map((q) => q.value.cooked ?? q.value.raw ?? "").join("");
|
|
46
|
+
maybePushImportee(value);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const evaluated = path.evaluate();
|
|
51
|
+
if (evaluated.confident) maybePushImportee(evaluated.value);
|
|
52
|
+
} catch {}
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
result: babel.transformSync(code, {
|
|
56
|
+
babelrc: false,
|
|
57
|
+
configFile: false,
|
|
58
|
+
presets: [[presets.env, {
|
|
59
|
+
modules: preserveEsmExports ? false : "commonjs",
|
|
60
|
+
targets: { ie: "11" }
|
|
61
|
+
}], presets.typescript],
|
|
62
|
+
filename,
|
|
63
|
+
plugins: [{ visitor: {
|
|
64
|
+
Directive: { enter(p) {
|
|
65
|
+
p.remove();
|
|
66
|
+
} },
|
|
67
|
+
CallExpression: { enter(p) {
|
|
68
|
+
const node = p.node;
|
|
69
|
+
if (!t.isIdentifier(node.callee, { name: "require" })) return;
|
|
70
|
+
if (node.arguments.length !== 1) return;
|
|
71
|
+
const argPath = p.get("arguments.0");
|
|
72
|
+
tryCollectArgument(argPath);
|
|
73
|
+
const arg = node.arguments[0];
|
|
74
|
+
if (t.isStringLiteral(arg)) arg.value = normalizeWxsFilename(arg.value, extension);
|
|
75
|
+
} },
|
|
76
|
+
ExpressionStatement(p) {
|
|
77
|
+
const expression = p.node.expression;
|
|
78
|
+
if (expression.type === "CallExpression" && expression.callee.type === "MemberExpression" && t.isIdentifier(expression.callee.object) && expression.callee.object.name === "Object" && t.isIdentifier(expression.callee.property) && expression.callee.property.name === "defineProperty" && expression.arguments.length >= 2 && t.isIdentifier(expression.arguments[0]) && expression.arguments[0].name === "exports" && t.isStringLiteral(expression.arguments[1]) && expression.arguments[1].value === "__esModule") p.remove();
|
|
79
|
+
},
|
|
80
|
+
AssignmentExpression: { enter(p) {
|
|
81
|
+
if (!preserveEsmExports || p.node.operator !== "=") return;
|
|
82
|
+
const left = p.node.left;
|
|
83
|
+
if (!t.isMemberExpression(left) || left.computed || !t.isIdentifier(left.object, { name: "module" }) || !t.isIdentifier(left.property, { name: "exports" }) || !p.parentPath.isExpressionStatement()) return;
|
|
84
|
+
p.parentPath.replaceWith(t.exportDefaultDeclaration(p.node.right));
|
|
85
|
+
} },
|
|
86
|
+
NewExpression: { enter(p) {
|
|
87
|
+
const node = p.node;
|
|
88
|
+
if (t.isIdentifier(node.callee, { name: "RegExp" })) p.replaceWith(t.callExpression(t.identifier("getRegExp"), node.arguments));
|
|
89
|
+
else if (t.isIdentifier(node.callee, { name: "Date" })) p.replaceWith(t.callExpression(t.identifier("getDate"), node.arguments));
|
|
90
|
+
} },
|
|
91
|
+
RegExpLiteral: { enter(p) {
|
|
92
|
+
const args = [t.stringLiteral(p.node.pattern)];
|
|
93
|
+
if (p.node.flags) args.push(t.stringLiteral(p.node.flags));
|
|
94
|
+
p.replaceWith(t.callExpression(t.identifier("getRegExp"), args));
|
|
95
|
+
} },
|
|
96
|
+
MemberExpression: { enter(p) {
|
|
97
|
+
if (preserveEsmExports) return;
|
|
98
|
+
const node = p.node;
|
|
99
|
+
if (!t.isIdentifier(node.object, { name: "exports" })) return;
|
|
100
|
+
const moduleExports = t.memberExpression(t.identifier("module"), t.identifier("exports"));
|
|
101
|
+
p.replaceWith(t.memberExpression(moduleExports, node.property, node.computed));
|
|
102
|
+
} },
|
|
103
|
+
ImportDeclaration: { enter(p) {
|
|
104
|
+
maybePushImportee(p.node.source.value);
|
|
105
|
+
} }
|
|
106
|
+
} }]
|
|
107
|
+
}),
|
|
108
|
+
importees
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
export { normalizeWxsFilename as n, transformWxsCode as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as transformWxsCode } from "./wxs-BT8btflA.mjs";
|