weapp-vite 6.16.1 → 6.16.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/README.md +17 -3
- package/dist/auto-routes.mjs +1 -1
- package/dist/cli.mjs +976 -57
- package/dist/{config-BKXx-hW-.d.mts → config-Deromcuk.d.mts} +64 -4
- package/dist/config.d.mts +1 -1
- package/dist/{createContext-C-05IQc1.mjs → createContext-C775dw5P.mjs} +324 -95
- package/dist/docs/README.md +17 -3
- package/dist/docs/ai-workflows.md +19 -0
- package/dist/docs/mcp.md +23 -5
- package/dist/docs/volar.md +19 -1
- package/dist/docs/weapp-config.md +28 -0
- package/dist/{file-BC_RNbAI.mjs → file-CueQM5Yi.mjs} +1 -1
- package/dist/file-D7c-LQA5.mjs +2 -0
- package/dist/getInstance-BzywMrU-.mjs +2 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/json.d.mts +1 -1
- package/dist/{mcp-BzcrPiku.mjs → mcp-DV3K2AVD.mjs} +6 -4
- package/dist/mcp.d.mts +4 -3
- package/dist/mcp.mjs +2 -2
- package/dist/types.d.mts +2 -2
- package/package.json +7 -7
- package/dist/file-djYgQoCM.mjs +0 -2
- package/dist/getInstance-BzppVHkY.mjs +0 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as applyWeappViteHostMeta } from "./pluginHost-SJdl15d3.mjs";
|
|
2
2
|
import { n as configureLogger, r as logger_default } from "./logger-CgxdNjvb.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-CueQM5Yi.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";
|
|
@@ -8748,7 +8748,7 @@ const REQUEST_GLOBAL_EXPORT_RE = /Object\.defineProperty\(exports,\s*(?:`([^`]+)
|
|
|
8748
8748
|
const REQUEST_GLOBAL_INSTALLER_RE = /function\s+([A-Za-z_$][\w$]*)\([^)]*=\{\}\)\{[\s\S]{0,220}?targets\?\?\[[\s\S]{0,80}?fetch[\s\S]{0,80}?Headers[\s\S]{0,80}?Request[\s\S]{0,80}?Response[\s\S]{0,80}?AbortController[\s\S]{0,80}?AbortSignal[\s\S]{0,80}?XMLHttpRequest[\s\S]{0,80}?WebSocket[\s\S]{0,260}?return [^}]+\}/;
|
|
8749
8749
|
const REQUEST_GLOBAL_ENTRY_NAME_RE = /\.[^/.]+$/;
|
|
8750
8750
|
const REQUEST_GLOBAL_REQUIRE_DECLARATOR_RE = /([A-Za-z_$][\w$]*)\s*=\s*require\((`([^`]+)`|'([^']+)'|"([^"]+)")\)/g;
|
|
8751
|
-
const REQUEST_GLOBAL_RUNTIME_CHUNK_FILE_BASENAME = "request-globals-runtime.js";
|
|
8751
|
+
const REQUEST_GLOBAL_RUNTIME_CHUNK_FILE_BASENAME = "weapp-vendors/request-globals-runtime.js";
|
|
8752
8752
|
const DYNAMIC_GLOBAL_RESOLUTION_RE = /Function\(\s*(?:`return this`|'return this'|"return this")\s*\)\(\)/g;
|
|
8753
8753
|
const BROWSER_GLOBAL_HOST_TERNARY_RE = /typeof self<[`'"]u[`'"]\?self:typeof window<[`'"]u[`'"]\?window:globalThis/g;
|
|
8754
8754
|
const AXIOS_MODULE_ID_RE = /[/\\](?:\.pnpm[/\\][^/\\]+[/\\]node_modules[/\\])?axios[/\\]/u;
|
|
@@ -9891,6 +9891,12 @@ function resolveDistChunkPackageToken(cleanedAbsoluteId) {
|
|
|
9891
9891
|
if (!packageToken) return;
|
|
9892
9892
|
return sanitizePackageToken(packageToken);
|
|
9893
9893
|
}
|
|
9894
|
+
function isRequestGlobalsRuntimeModuleId(id) {
|
|
9895
|
+
const cleanedAbsoluteId = normalizeSharedPathCandidate(id);
|
|
9896
|
+
REG_REQUEST_GLOBAL_RUNTIME_VENDOR_ID.lastIndex = 0;
|
|
9897
|
+
if (REG_REQUEST_GLOBAL_RUNTIME_VENDOR_ID.test(cleanedAbsoluteId)) return true;
|
|
9898
|
+
return resolveDistChunkPackageToken(cleanedAbsoluteId)?.endsWith("web-apis") === true;
|
|
9899
|
+
}
|
|
9894
9900
|
function resolveStableHashedDistChunkFileName(chunk) {
|
|
9895
9901
|
const candidateIds = [chunk.facadeModuleId, ...chunk.moduleIds ?? []].filter((id) => typeof id === "string");
|
|
9896
9902
|
for (const id of candidateIds) {
|
|
@@ -9902,7 +9908,7 @@ function resolveStableHashedDistChunkFileName(chunk) {
|
|
|
9902
9908
|
const packageToken = resolveDistChunkPackageToken(cleanedAbsoluteId);
|
|
9903
9909
|
if (!baseName || !packageToken) continue;
|
|
9904
9910
|
REG_REQUEST_GLOBAL_RUNTIME_VENDOR_ID.lastIndex = 0;
|
|
9905
|
-
if (REG_REQUEST_GLOBAL_RUNTIME_VENDOR_ID.test(cleanedAbsoluteId) || packageToken.endsWith("web-apis")) return `request-globals-${packageToken}-${baseName}.js`;
|
|
9911
|
+
if (REG_REQUEST_GLOBAL_RUNTIME_VENDOR_ID.test(cleanedAbsoluteId) || packageToken.endsWith("web-apis")) return `weapp-vendors/request-globals-${packageToken}-${baseName}.js`;
|
|
9906
9912
|
return `weapp-vendors/${packageToken}-${baseName}.js`;
|
|
9907
9913
|
}
|
|
9908
9914
|
}
|
|
@@ -9913,7 +9919,7 @@ function createSharedBuildResolver(configService, getSubPackageRoots) {
|
|
|
9913
9919
|
const forceDuplicateTester = createForceDuplicateTester(forceDuplicatePatterns);
|
|
9914
9920
|
const resolveSharedMode = createSharedModeResolver(sharedMode, sharedOverrides);
|
|
9915
9921
|
const resolveSharedPath = createSharedPathResolver(configService, sharedPathRoot);
|
|
9916
|
-
|
|
9922
|
+
const resolveAdvancedChunkName = createAdvancedChunkNameResolver({
|
|
9917
9923
|
vendorsMatchers: [nodeModulesDeps, commonjsHelpersDeps],
|
|
9918
9924
|
relativeAbsoluteSrcRoot: configService.relativeAbsoluteSrcRoot,
|
|
9919
9925
|
getSubPackageRoots,
|
|
@@ -9922,12 +9928,18 @@ function createSharedBuildResolver(configService, getSubPackageRoots) {
|
|
|
9922
9928
|
sharedMode,
|
|
9923
9929
|
resolveSharedMode,
|
|
9924
9930
|
resolveSharedPath
|
|
9925
|
-
})
|
|
9931
|
+
});
|
|
9932
|
+
const resolveSharedBuildChunkName = (id, ctx) => {
|
|
9933
|
+
if (isRequestGlobalsRuntimeModuleId(id)) return REQUEST_GLOBAL_RUNTIME_CHUNK_FILE_BASENAME.replace(/\.js$/, "");
|
|
9934
|
+
return resolveAdvancedChunkName(id, ctx);
|
|
9935
|
+
};
|
|
9936
|
+
return { resolveAdvancedChunkName: resolveSharedBuildChunkName };
|
|
9926
9937
|
}
|
|
9927
9938
|
function createSharedBuildOutput(configService, getSubPackageRoots) {
|
|
9928
9939
|
const { resolveAdvancedChunkName } = createSharedBuildResolver(configService, getSubPackageRoots);
|
|
9929
9940
|
return {
|
|
9930
9941
|
codeSplitting: { groups: [{ name: (id, ctx) => resolveAdvancedChunkName(id, ctx) }] },
|
|
9942
|
+
minifyInternalExports: false,
|
|
9931
9943
|
chunkFileNames: (chunk) => {
|
|
9932
9944
|
if (isRequestGlobalsRuntimeChunk(chunk)) return REQUEST_GLOBAL_RUNTIME_CHUNK_FILE_BASENAME;
|
|
9933
9945
|
const stableHashedDistChunkFileName = resolveStableHashedDistChunkFileName(chunk);
|
|
@@ -11132,6 +11144,20 @@ function getWeappViteConfig() {
|
|
|
11132
11144
|
multiPlatform: false,
|
|
11133
11145
|
es5: false,
|
|
11134
11146
|
packageSizeWarningBytes: 2 * 1024 * 1024,
|
|
11147
|
+
analyze: {
|
|
11148
|
+
budgets: {
|
|
11149
|
+
totalBytes: 20 * 1024 * 1024,
|
|
11150
|
+
mainBytes: 2 * 1024 * 1024,
|
|
11151
|
+
subPackageBytes: 2 * 1024 * 1024,
|
|
11152
|
+
independentBytes: 2 * 1024 * 1024,
|
|
11153
|
+
warningRatio: .85
|
|
11154
|
+
},
|
|
11155
|
+
history: {
|
|
11156
|
+
enabled: true,
|
|
11157
|
+
dir: ".weapp-vite/analyze-history",
|
|
11158
|
+
limit: 20
|
|
11159
|
+
}
|
|
11160
|
+
},
|
|
11135
11161
|
jsFormat: "cjs",
|
|
11136
11162
|
isAdditionalWxml: () => {
|
|
11137
11163
|
return false;
|
|
@@ -11152,7 +11178,8 @@ function getWeappViteConfig() {
|
|
|
11152
11178
|
autoStart: false,
|
|
11153
11179
|
host: "127.0.0.1",
|
|
11154
11180
|
port: 3088,
|
|
11155
|
-
endpoint: "/mcp"
|
|
11181
|
+
endpoint: "/mcp",
|
|
11182
|
+
restEndpoint: "/api/weapp/devtools"
|
|
11156
11183
|
},
|
|
11157
11184
|
forwardConsole: {
|
|
11158
11185
|
enabled: "auto",
|
|
@@ -12646,14 +12673,29 @@ function createExtendedLibManager() {
|
|
|
12646
12673
|
}
|
|
12647
12674
|
//#endregion
|
|
12648
12675
|
//#region src/plugins/hooks/useLoadEntry/jsonEmit.ts
|
|
12676
|
+
function normalizeAppJson(json) {
|
|
12677
|
+
if (!json || typeof json !== "object" || Array.isArray(json)) return json;
|
|
12678
|
+
const subPackages = Array.isArray(json.subPackages) ? json.subPackages : Array.isArray(json.subpackages) ? json.subpackages : [];
|
|
12679
|
+
return {
|
|
12680
|
+
...json,
|
|
12681
|
+
subPackages: subPackages.map((subPackage) => ({
|
|
12682
|
+
...subPackage,
|
|
12683
|
+
pages: Array.isArray(subPackage?.pages) ? subPackage.pages : []
|
|
12684
|
+
}))
|
|
12685
|
+
};
|
|
12686
|
+
}
|
|
12649
12687
|
function createJsonEmitManager(configService) {
|
|
12650
12688
|
const map = /* @__PURE__ */ new Map();
|
|
12651
12689
|
function register(entry) {
|
|
12652
12690
|
if (!entry.jsonPath) return;
|
|
12653
12691
|
const fileName = resolveRelativeJsonOutputFileName(configService, entry.jsonPath);
|
|
12692
|
+
const normalizedEntry = entry.type === "app" && fileName === "app.json" ? {
|
|
12693
|
+
...entry,
|
|
12694
|
+
json: normalizeAppJson(entry.json)
|
|
12695
|
+
} : entry;
|
|
12654
12696
|
map.set(fileName, {
|
|
12655
12697
|
fileName,
|
|
12656
|
-
entry
|
|
12698
|
+
entry: normalizedEntry
|
|
12657
12699
|
});
|
|
12658
12700
|
}
|
|
12659
12701
|
return {
|
|
@@ -14468,6 +14510,7 @@ async function applyScriptSetupUsingComponents(options) {
|
|
|
14468
14510
|
}
|
|
14469
14511
|
//#endregion
|
|
14470
14512
|
//#region src/plugins/hooks/useLoadEntry/loadEntry/index.ts
|
|
14513
|
+
const VUE_LIKE_PAGE_ENTRY_RE = /\.(?:vue|jsx|tsx)$/;
|
|
14471
14514
|
function createStopwatch() {
|
|
14472
14515
|
const start = performance$1.now();
|
|
14473
14516
|
return () => `${(performance$1.now() - start).toFixed(2)}ms`;
|
|
@@ -14549,6 +14592,32 @@ function createEntryLoader(options) {
|
|
|
14549
14592
|
let shouldSkipAppEntries = false;
|
|
14550
14593
|
const nativeLayoutScriptEntries = /* @__PURE__ */ new Set();
|
|
14551
14594
|
const autoRoutesSignature = configService.isDev ? ctx.autoRoutesService?.getSignature?.() : void 0;
|
|
14595
|
+
const registerPageLayoutComponentEntries = async (layoutPlan, options) => {
|
|
14596
|
+
if (options?.trackLayoutDependencies) {
|
|
14597
|
+
const layoutDependencies = /* @__PURE__ */ new Set();
|
|
14598
|
+
for (const file of await expandResolvedPageLayoutFiles(layoutPlan.layouts)) layoutDependencies.add(normalizeFsResolvedId(file));
|
|
14599
|
+
replaceLayoutDependencies(normalizedId, layoutDependencies);
|
|
14600
|
+
}
|
|
14601
|
+
await addResolvedPageLayoutWatchFiles(this, layoutPlan.layouts);
|
|
14602
|
+
await registerResolvedPageLayoutEntries({
|
|
14603
|
+
layouts: layoutPlan.layouts,
|
|
14604
|
+
entries,
|
|
14605
|
+
explicitEntryTypes,
|
|
14606
|
+
nativeScriptEntries: nativeLayoutScriptEntries,
|
|
14607
|
+
normalizeEntry,
|
|
14608
|
+
jsonPath
|
|
14609
|
+
});
|
|
14610
|
+
for (const layout of layoutPlan.layouts) {
|
|
14611
|
+
if (layout.kind === "native") continue;
|
|
14612
|
+
if (!layout.file.endsWith(".vue")) continue;
|
|
14613
|
+
if (!await shouldEmitScriptlessVueLayoutJs$1(layout.file)) continue;
|
|
14614
|
+
const relativeLayoutBase = configService.relativeOutputPath(removeExtensionDeep(layout.file));
|
|
14615
|
+
if (!relativeLayoutBase || emittedScriptlessVueLayoutJs.has(relativeLayoutBase)) continue;
|
|
14616
|
+
emittedScriptlessVueLayoutJs.add(relativeLayoutBase);
|
|
14617
|
+
const { scriptExtension } = resolveCompilerOutputExtensions(configService.outputExtensions);
|
|
14618
|
+
emitScriptlessComponentAsset(this, resolveScriptlessComponentFileName(relativeLayoutBase, scriptExtension));
|
|
14619
|
+
}
|
|
14620
|
+
};
|
|
14552
14621
|
if (type === "app") {
|
|
14553
14622
|
appResult = await collectAppEntries({
|
|
14554
14623
|
pluginCtx: this,
|
|
@@ -14614,34 +14683,13 @@ function createEntryLoader(options) {
|
|
|
14614
14683
|
if (vueSource) {
|
|
14615
14684
|
const layoutPlan = await resolvePageLayoutPlan(vueSource, vueEntryPath, configService);
|
|
14616
14685
|
replaceLayoutDependencies(normalizedId, []);
|
|
14617
|
-
if (layoutPlan) {
|
|
14618
|
-
if (vueSource.includes("definePageMeta") || vueSource.includes("setPageLayout")) {
|
|
14619
|
-
const layoutDependencies = /* @__PURE__ */ new Set();
|
|
14620
|
-
for (const file of await expandResolvedPageLayoutFiles(layoutPlan.layouts)) layoutDependencies.add(normalizeFsResolvedId(file));
|
|
14621
|
-
replaceLayoutDependencies(normalizedId, layoutDependencies);
|
|
14622
|
-
}
|
|
14623
|
-
await addResolvedPageLayoutWatchFiles(this, layoutPlan.layouts);
|
|
14624
|
-
await registerResolvedPageLayoutEntries({
|
|
14625
|
-
layouts: layoutPlan.layouts,
|
|
14626
|
-
entries,
|
|
14627
|
-
explicitEntryTypes,
|
|
14628
|
-
nativeScriptEntries: nativeLayoutScriptEntries,
|
|
14629
|
-
normalizeEntry,
|
|
14630
|
-
jsonPath
|
|
14631
|
-
});
|
|
14632
|
-
for (const layout of layoutPlan.layouts) {
|
|
14633
|
-
if (layout.kind === "native") continue;
|
|
14634
|
-
if (!layout.file.endsWith(".vue")) continue;
|
|
14635
|
-
if (!await shouldEmitScriptlessVueLayoutJs$1(layout.file)) continue;
|
|
14636
|
-
const relativeLayoutBase = configService.relativeOutputPath(removeExtensionDeep(layout.file));
|
|
14637
|
-
if (!relativeLayoutBase || emittedScriptlessVueLayoutJs.has(relativeLayoutBase)) continue;
|
|
14638
|
-
emittedScriptlessVueLayoutJs.add(relativeLayoutBase);
|
|
14639
|
-
const { scriptExtension } = resolveCompilerOutputExtensions(configService.outputExtensions);
|
|
14640
|
-
emitScriptlessComponentAsset(this, resolveScriptlessComponentFileName(relativeLayoutBase, scriptExtension));
|
|
14641
|
-
}
|
|
14642
|
-
}
|
|
14686
|
+
if (layoutPlan) await registerPageLayoutComponentEntries(layoutPlan, { trackLayoutDependencies: vueSource.includes("definePageMeta") || vueSource.includes("setPageLayout") });
|
|
14643
14687
|
}
|
|
14644
14688
|
}
|
|
14689
|
+
} else if (type === "page" && templatePath && !VUE_LIKE_PAGE_ENTRY_RE.test(id)) {
|
|
14690
|
+
replaceLayoutDependencies(normalizedId, []);
|
|
14691
|
+
const layoutPlan = await resolvePageLayoutPlan(await fs.readFile(id, "utf-8"), id, configService);
|
|
14692
|
+
if (layoutPlan) await registerPageLayoutComponentEntries(layoutPlan, { trackLayoutDependencies: true });
|
|
14645
14693
|
}
|
|
14646
14694
|
if (configService.isDev && hasJsonEntry && vueEntryPath) {
|
|
14647
14695
|
const vueSource = await readVueSource();
|
|
@@ -14757,8 +14805,6 @@ function createTemplateScanner(wxmlService, debug) {
|
|
|
14757
14805
|
}
|
|
14758
14806
|
//#endregion
|
|
14759
14807
|
//#region src/plugins/hooks/useLoadEntry/index.ts
|
|
14760
|
-
const MAX_DIRECT_SOURCE_SHARED_CHUNK_IMPORTERS = 128;
|
|
14761
|
-
const MAX_FALLBACK_DIRECT_SOURCE_SHARED_CHUNK_IMPORTERS = 8;
|
|
14762
14808
|
function resolveUpstreamPendingReasonSummary(dirtyReasonSummary) {
|
|
14763
14809
|
if (!dirtyReasonSummary?.length) return [];
|
|
14764
14810
|
const pendingReasonSummary = [];
|
|
@@ -14770,12 +14816,6 @@ function resolveUpstreamPendingReasonSummary(dirtyReasonSummary) {
|
|
|
14770
14816
|
if (hasAutoRoutesTopology) pendingReasonSummary.push("auto-routes-topology");
|
|
14771
14817
|
return pendingReasonSummary;
|
|
14772
14818
|
}
|
|
14773
|
-
function isDirectSourceSharedChunkForEntry(options) {
|
|
14774
|
-
if (options.sourceSharedChunks?.has(options.chunkId) !== true) return false;
|
|
14775
|
-
const normalizedEntryId = normalizeFsResolvedId(options.entryId);
|
|
14776
|
-
if ((options.entryLayoutDependencies?.get(normalizedEntryId))?.size) return true;
|
|
14777
|
-
return options.importerCount <= MAX_FALLBACK_DIRECT_SOURCE_SHARED_CHUNK_IMPORTERS;
|
|
14778
|
-
}
|
|
14779
14819
|
function resolvePendingEntryIds(options) {
|
|
14780
14820
|
const pending = new Set(options.dirtyEntrySet);
|
|
14781
14821
|
const pendingReasonSummary = resolveUpstreamPendingReasonSummary(options.dirtyReasonSummary);
|
|
@@ -14817,17 +14857,9 @@ function resolvePendingEntryIds(options) {
|
|
|
14817
14857
|
hasDependencyDrivenImporter = true;
|
|
14818
14858
|
continue;
|
|
14819
14859
|
}
|
|
14820
|
-
if (options.dirtyEntrySet.has(importer) && options.dirtyEntryReasons.get(importer) === "direct")
|
|
14821
|
-
if (isDirectSourceSharedChunkForEntry({
|
|
14822
|
-
chunkId,
|
|
14823
|
-
entryId: importer,
|
|
14824
|
-
sourceSharedChunks: options.sourceSharedChunks,
|
|
14825
|
-
entryLayoutDependencies: options.entryLayoutDependencies,
|
|
14826
|
-
importerCount: importers.size
|
|
14827
|
-
})) hasDirectDirtyImporter = true;
|
|
14828
|
-
}
|
|
14860
|
+
if (options.dirtyEntrySet.has(importer) && options.dirtyEntryReasons.get(importer) === "direct") hasDirectDirtyImporter = true;
|
|
14829
14861
|
}
|
|
14830
|
-
if (!hasDependencyDrivenImporter && !
|
|
14862
|
+
if (!hasDependencyDrivenImporter && !hasDirectDirtyImporter) continue;
|
|
14831
14863
|
if (hasDependencyDrivenImporter && hasDirectDirtyImporter) expansionMode = "mixed";
|
|
14832
14864
|
else if (hasDirectDirtyImporter) expansionMode = expansionMode && expansionMode !== "direct" ? "mixed" : "direct";
|
|
14833
14865
|
else expansionMode = expansionMode && expansionMode !== "dependency" ? "mixed" : "dependency";
|
|
@@ -14907,7 +14939,6 @@ function useLoadEntry(ctx, options) {
|
|
|
14907
14939
|
const hmrSharedChunksMode = options?.hmr?.sharedChunks ?? "auto";
|
|
14908
14940
|
const hmrSharedChunkImporters = options?.hmr?.sharedChunkImporters;
|
|
14909
14941
|
const hmrSharedChunksByEntry = options?.hmr?.sharedChunksByEntry;
|
|
14910
|
-
const hmrSourceSharedChunks = options?.hmr?.sourceSharedChunks;
|
|
14911
14942
|
return {
|
|
14912
14943
|
loadEntry,
|
|
14913
14944
|
entriesMap,
|
|
@@ -14940,11 +14971,7 @@ function useLoadEntry(ctx, options) {
|
|
|
14940
14971
|
dirtyEntryReasons,
|
|
14941
14972
|
dirtyReasonSummary: ctx.runtimeState.build.hmr.profile.dirtyReasonSummary,
|
|
14942
14973
|
sharedChunkImporters: hmrSharedChunkImporters,
|
|
14943
|
-
sharedChunksByEntry: hmrSharedChunksByEntry
|
|
14944
|
-
sourceSharedChunks: hmrSourceSharedChunks,
|
|
14945
|
-
entryLayoutDependencies,
|
|
14946
|
-
subPackageRoots: new Set(ctx.scanService?.subPackageMap?.keys?.() ?? []),
|
|
14947
|
-
relativeAbsoluteSrcRoot: ctx.configService.relativeAbsoluteSrcRoot.bind(ctx.configService)
|
|
14974
|
+
sharedChunksByEntry: hmrSharedChunksByEntry
|
|
14948
14975
|
});
|
|
14949
14976
|
const pendingEntryIds = pendingResolution.pending;
|
|
14950
14977
|
const pending = [];
|
|
@@ -16186,9 +16213,26 @@ function rewriteJsonNpmImportsToLocalRoot(bundle, root, dependencyPatterns, depe
|
|
|
16186
16213
|
}
|
|
16187
16214
|
//#endregion
|
|
16188
16215
|
//#region src/plugins/core/lifecycle/emit/requestGlobals.ts
|
|
16216
|
+
const REQUEST_GLOBAL_REQUIRE_CALL_RE = /require\((`([^`]+)`|'([^']+)'|"([^"]+)")\)/g;
|
|
16217
|
+
const REQUEST_GLOBAL_APP_MODULE_KEY_PREFIX = "__weappViteRequestGlobalsModule:";
|
|
16189
16218
|
function resolveChunkRequestGlobalsTargets(code, targets, mode) {
|
|
16190
16219
|
return mode === "auto" ? resolveAutoRequestGlobalsTargets(code, targets) : targets;
|
|
16191
16220
|
}
|
|
16221
|
+
function collectTopLevelDeclaredIdentifiers(code) {
|
|
16222
|
+
const identifiers = /* @__PURE__ */ new Set();
|
|
16223
|
+
try {
|
|
16224
|
+
const body = parseJsLike(code)?.program?.body;
|
|
16225
|
+
if (!Array.isArray(body)) return identifiers;
|
|
16226
|
+
for (const statement of body) {
|
|
16227
|
+
if ((statement?.type === "FunctionDeclaration" || statement?.type === "ClassDeclaration") && statement.id?.type === "Identifier") identifiers.add(statement.id.name);
|
|
16228
|
+
if (statement?.type !== "VariableDeclaration") continue;
|
|
16229
|
+
for (const declaration of statement.declarations ?? []) if (declaration?.id?.type === "Identifier") identifiers.add(declaration.id.name);
|
|
16230
|
+
}
|
|
16231
|
+
} catch {
|
|
16232
|
+
return identifiers;
|
|
16233
|
+
}
|
|
16234
|
+
return identifiers;
|
|
16235
|
+
}
|
|
16192
16236
|
function resolveRequestGlobalsInstallerName(code) {
|
|
16193
16237
|
const installerMatch = code.match(REQUEST_GLOBAL_INSTALLER_RE);
|
|
16194
16238
|
if (installerMatch?.[1]) return installerMatch[1];
|
|
@@ -16267,14 +16311,15 @@ function injectRequestGlobalsBundleRuntime(bundle, targets, mode, networkDefault
|
|
|
16267
16311
|
if (chunkTargets.length === 0) continue;
|
|
16268
16312
|
const bindingTargets = resolveRequestGlobalsBindingTargets(chunkTargets);
|
|
16269
16313
|
if (bindingTargets.length === 0) continue;
|
|
16270
|
-
const
|
|
16314
|
+
const topLevelDeclaredIdentifiers = collectTopLevelDeclaredIdentifiers(chunk.code);
|
|
16315
|
+
const passiveBindingsCode = createRequestGlobalsPassiveBindingsCode(chunkTargets, bindingTargets.filter((target) => !topLevelDeclaredIdentifiers.has(target)));
|
|
16271
16316
|
const syntheticExportCode = exportName ? "" : `Object.defineProperty(exports,${JSON.stringify(REQUEST_GLOBAL_SYNTHETIC_EXPORT_NAME)},{enumerable:false,get:function(){return ${installerName}}});`;
|
|
16272
16317
|
const runtimeBindingCode = [
|
|
16273
16318
|
`const ${REQUEST_GLOBAL_BUNDLE_HOST_REF} = ${installerName}(${createRequestGlobalsInstallerOptionsCode(chunkTargets, networkDefaults)}) || globalThis`,
|
|
16274
16319
|
...bindingTargets.map((target) => `${REQUEST_GLOBAL_ACTUALS_KEY}[${JSON.stringify(target)}] = ${REQUEST_GLOBAL_BUNDLE_HOST_REF}.${target}`),
|
|
16275
16320
|
...bindingTargets.map((target) => `try{globalThis[${JSON.stringify(target)}]=${REQUEST_GLOBAL_BUNDLE_HOST_REF}.${target}}catch{}`)
|
|
16276
16321
|
].join(";");
|
|
16277
|
-
const bundlePrelude = `/* ${REQUEST_GLOBAL_BUNDLE_MARKER} */ ${passiveBindingsCode}\n`;
|
|
16322
|
+
const bundlePrelude = `/* ${REQUEST_GLOBAL_BUNDLE_MARKER} */ ${passiveBindingsCode ? `${passiveBindingsCode}\n` : ""}`;
|
|
16278
16323
|
const firstRequireMatch = chunk.code.match(REQUEST_GLOBAL_REQUIRE_DECLARATOR_RE);
|
|
16279
16324
|
if (firstRequireMatch?.[0]) {
|
|
16280
16325
|
chunk.code = `${bundlePrelude}${chunk.code.replace(firstRequireMatch[0], (match) => `${match};${syntheticExportCode}${runtimeBindingCode}`)}\n`;
|
|
@@ -16398,6 +16443,102 @@ function rewriteChunkRequireLiteral(chunk, fromFileName, toFileName) {
|
|
|
16398
16443
|
});
|
|
16399
16444
|
if (didRewrite) chunk.code = nextCode;
|
|
16400
16445
|
}
|
|
16446
|
+
function hasBareRequireRegistration(code, requirePath) {
|
|
16447
|
+
const escapedRequireLiteral = JSON.stringify(requirePath).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
16448
|
+
return new RegExp(`(?:^|[;\\n])\\s*require\\(${escapedRequireLiteral}\\);`).test(code);
|
|
16449
|
+
}
|
|
16450
|
+
function getRequireCallImportee(args) {
|
|
16451
|
+
return args[2] ?? args[3] ?? args[4];
|
|
16452
|
+
}
|
|
16453
|
+
function rewriteRequireCallLiterals(code, rewrite) {
|
|
16454
|
+
return code.replaceAll(REQUEST_GLOBAL_REQUIRE_CALL_RE, (...args) => {
|
|
16455
|
+
const match = args[0];
|
|
16456
|
+
const requireLiteral = args[1];
|
|
16457
|
+
const importee = getRequireCallImportee(args);
|
|
16458
|
+
if (typeof importee !== "string") return match;
|
|
16459
|
+
return rewrite(requireLiteral, importee) ?? match;
|
|
16460
|
+
});
|
|
16461
|
+
}
|
|
16462
|
+
function rewriteEmbeddedRequirePaths(code, fromFileName, toFileName) {
|
|
16463
|
+
return rewriteRequireCallLiterals(code, (_requireLiteral, importee) => {
|
|
16464
|
+
const resolvedImport = normalizeRelativeChunkImport(fromFileName, importee);
|
|
16465
|
+
return `require(${JSON.stringify(toRequireRequestPath(toFileName, resolvedImport))})`;
|
|
16466
|
+
});
|
|
16467
|
+
}
|
|
16468
|
+
function rewriteChunkRequireCallsToExpression(chunk, targetFileName, expression) {
|
|
16469
|
+
let didRewrite = false;
|
|
16470
|
+
const nextCode = rewriteRequireCallLiterals(chunk.code, (_requireLiteral, importee) => {
|
|
16471
|
+
if (normalizeRelativeChunkImport(chunk.fileName, importee) !== targetFileName) return;
|
|
16472
|
+
didRewrite = true;
|
|
16473
|
+
return expression;
|
|
16474
|
+
});
|
|
16475
|
+
if (didRewrite) chunk.code = nextCode;
|
|
16476
|
+
return didRewrite;
|
|
16477
|
+
}
|
|
16478
|
+
function createRequestGlobalsStaticImportReplacement(node, expression) {
|
|
16479
|
+
const declarations = [];
|
|
16480
|
+
const namedSpecifiers = [];
|
|
16481
|
+
for (const specifier of node.specifiers ?? []) {
|
|
16482
|
+
if (specifier?.type === "ImportNamespaceSpecifier" && specifier.local?.type === "Identifier") {
|
|
16483
|
+
declarations.push(`const ${specifier.local.name} = ${expression};`);
|
|
16484
|
+
continue;
|
|
16485
|
+
}
|
|
16486
|
+
if (specifier?.type === "ImportDefaultSpecifier" && specifier.local?.type === "Identifier") {
|
|
16487
|
+
declarations.push(`const ${specifier.local.name} = ${expression}.default;`);
|
|
16488
|
+
continue;
|
|
16489
|
+
}
|
|
16490
|
+
if (specifier?.type !== "ImportSpecifier" || specifier.local?.type !== "Identifier") continue;
|
|
16491
|
+
const importedName = specifier.imported?.type === "Identifier" ? specifier.imported.name : getStaticStringLiteral(specifier.imported);
|
|
16492
|
+
if (!importedName) continue;
|
|
16493
|
+
const propertyName = /^[_a-z]\w*$/i.test(importedName) ? importedName : JSON.stringify(importedName);
|
|
16494
|
+
namedSpecifiers.push(specifier.local.name === importedName && propertyName === importedName ? importedName : `${propertyName}: ${specifier.local.name}`);
|
|
16495
|
+
}
|
|
16496
|
+
if (namedSpecifiers.length > 0) declarations.unshift(`const { ${namedSpecifiers.join(", ")} } = ${expression};`);
|
|
16497
|
+
return declarations.length > 0 ? declarations.join("\n") : `${expression};`;
|
|
16498
|
+
}
|
|
16499
|
+
function rewriteChunkStaticImportsToExpression(chunk, targetFileName, expression) {
|
|
16500
|
+
try {
|
|
16501
|
+
const ast = parseJsLike(chunk.code);
|
|
16502
|
+
const replacements = [];
|
|
16503
|
+
traverse(ast, { ImportDeclaration(path) {
|
|
16504
|
+
const importee = getStaticStringLiteral(path.node?.source);
|
|
16505
|
+
if (!importee) return;
|
|
16506
|
+
if (normalizeRelativeChunkImport(chunk.fileName, importee) !== targetFileName) return;
|
|
16507
|
+
if (typeof path.node.start !== "number" || typeof path.node.end !== "number") return;
|
|
16508
|
+
replacements.push({
|
|
16509
|
+
end: path.node.end,
|
|
16510
|
+
start: path.node.start,
|
|
16511
|
+
value: createRequestGlobalsStaticImportReplacement(path.node, expression)
|
|
16512
|
+
});
|
|
16513
|
+
} });
|
|
16514
|
+
if (replacements.length === 0) return false;
|
|
16515
|
+
let nextCode = chunk.code;
|
|
16516
|
+
for (const replacement of replacements.sort((left, right) => right.start - left.start)) nextCode = `${nextCode.slice(0, replacement.start)}${replacement.value}${nextCode.slice(replacement.end)}`;
|
|
16517
|
+
chunk.code = nextCode;
|
|
16518
|
+
return true;
|
|
16519
|
+
} catch {
|
|
16520
|
+
return false;
|
|
16521
|
+
}
|
|
16522
|
+
}
|
|
16523
|
+
function hasAssetRequireCallToFile(source, fileName, targetFileName) {
|
|
16524
|
+
let hasRequireCall = false;
|
|
16525
|
+
rewriteRequireCallLiterals(source, (_requireLiteral, importee) => {
|
|
16526
|
+
if (normalizeRelativeChunkImport(fileName, importee) === targetFileName) hasRequireCall = true;
|
|
16527
|
+
});
|
|
16528
|
+
return hasRequireCall;
|
|
16529
|
+
}
|
|
16530
|
+
function shouldInlineRequestGlobalsAppRegisteredInstallerChunk(fileName) {
|
|
16531
|
+
return fileName !== "weapp-vendors/request-globals-runtime.js" && fileName.startsWith("weapp-vendors/request-globals-");
|
|
16532
|
+
}
|
|
16533
|
+
function toRequestGlobalsAppRegisteredModuleExpression(fileName) {
|
|
16534
|
+
return `globalThis[${JSON.stringify(`${REQUEST_GLOBAL_APP_MODULE_KEY_PREFIX}${fileName}`)}]`;
|
|
16535
|
+
}
|
|
16536
|
+
function toRequestGlobalsRequireModuleExpression(fromFileName, installerChunkFileName) {
|
|
16537
|
+
return `require(${JSON.stringify(toRequireRequestPath(fromFileName, installerChunkFileName))})`;
|
|
16538
|
+
}
|
|
16539
|
+
function toRequestGlobalsInstallerModuleExpression(fromFileName, installerChunkFileName, options = {}) {
|
|
16540
|
+
return options.appRegisteredModule !== false && shouldInlineRequestGlobalsAppRegisteredInstallerChunk(installerChunkFileName) ? toRequestGlobalsAppRegisteredModuleExpression(installerChunkFileName) : toRequestGlobalsRequireModuleExpression(fromFileName, installerChunkFileName);
|
|
16541
|
+
}
|
|
16401
16542
|
function collapseRequestGlobalsRuntimeSupportChunk(bundle) {
|
|
16402
16543
|
const runtimeChunk = bundle[REQUEST_GLOBAL_RUNTIME_CHUNK_FILE_BASENAME];
|
|
16403
16544
|
if (!runtimeChunk || runtimeChunk.type !== "chunk") return;
|
|
@@ -16410,7 +16551,7 @@ function collapseRequestGlobalsRuntimeSupportChunk(bundle) {
|
|
|
16410
16551
|
const resolvedImport = normalizeRelativeChunkImport(runtimeOutput.fileName, importee);
|
|
16411
16552
|
const supportChunk = bundle[resolvedImport];
|
|
16412
16553
|
if (!supportChunk || supportChunk.type !== "chunk") continue;
|
|
16413
|
-
if (resolvedImport === "request-globals-runtime.js" || !resolvedImport.startsWith("request-globals-") && !resolvedImport.endsWith("web-apis-shared.js")) continue;
|
|
16554
|
+
if (resolvedImport === "weapp-vendors/request-globals-runtime.js" || !resolvedImport.startsWith("request-globals-") && !resolvedImport.endsWith("web-apis-shared.js")) continue;
|
|
16414
16555
|
supportChunkFileName = resolvedImport;
|
|
16415
16556
|
runtimeRequireMatch = requireMatch;
|
|
16416
16557
|
break;
|
|
@@ -16444,6 +16585,65 @@ function collapseRequestGlobalsRuntimeSupportChunk(bundle) {
|
|
|
16444
16585
|
rewriteChunkRequireLiteral(chunk, supportChunkFileName, runtimeOutput.fileName);
|
|
16445
16586
|
}
|
|
16446
16587
|
}
|
|
16588
|
+
function injectRequestGlobalsAppRegistration(bundle, installerChunks) {
|
|
16589
|
+
if (installerChunks.size === 0) return;
|
|
16590
|
+
const appOutput = bundle["app.js"];
|
|
16591
|
+
if (!appOutput || appOutput.type !== "chunk") return;
|
|
16592
|
+
const appChunk = appOutput;
|
|
16593
|
+
const requireStatements = [];
|
|
16594
|
+
for (const installerChunkFileName of installerChunks.keys()) {
|
|
16595
|
+
const installerOutput = bundle[installerChunkFileName];
|
|
16596
|
+
if (!installerOutput || installerOutput.type !== "chunk") continue;
|
|
16597
|
+
const requirePath = toRequireRequestPath(appChunk.fileName, installerChunkFileName);
|
|
16598
|
+
if (hasBareRequireRegistration(appChunk.code, requirePath)) continue;
|
|
16599
|
+
requireStatements.push(`require(${JSON.stringify(requirePath)});`);
|
|
16600
|
+
}
|
|
16601
|
+
if (requireStatements.length === 0) return;
|
|
16602
|
+
appChunk.code = `${requireStatements.join("\n")}\n${appChunk.code}`;
|
|
16603
|
+
}
|
|
16604
|
+
function inlineRequestGlobalsAppRegisteredInstallerChunks(bundle, installerChunks, preservedInstallerChunks = /* @__PURE__ */ new Set()) {
|
|
16605
|
+
if (installerChunks.size === 0) return;
|
|
16606
|
+
const appOutput = bundle["app.js"];
|
|
16607
|
+
if (!appOutput || appOutput.type !== "chunk") return;
|
|
16608
|
+
const appChunk = appOutput;
|
|
16609
|
+
const inlinedModules = [];
|
|
16610
|
+
let inlinedIndex = 0;
|
|
16611
|
+
for (const installerChunkFileName of installerChunks.keys()) {
|
|
16612
|
+
if (!shouldInlineRequestGlobalsAppRegisteredInstallerChunk(installerChunkFileName)) continue;
|
|
16613
|
+
const installerOutput = bundle[installerChunkFileName];
|
|
16614
|
+
if (!installerOutput || installerOutput.type !== "chunk") continue;
|
|
16615
|
+
const moduleRef = `__wvRGA${inlinedIndex++}__`;
|
|
16616
|
+
const globalModuleExpression = toRequestGlobalsAppRegisteredModuleExpression(installerChunkFileName);
|
|
16617
|
+
const installerChunk = installerOutput;
|
|
16618
|
+
const embeddedCode = rewriteEmbeddedRequirePaths(installerChunk.code, installerChunk.fileName, appChunk.fileName);
|
|
16619
|
+
let hasPreservedAssetRequire = preservedInstallerChunks.has(installerChunkFileName);
|
|
16620
|
+
inlinedModules.push([
|
|
16621
|
+
`const ${moduleRef} = (() => {`,
|
|
16622
|
+
" const module = { exports: {} }",
|
|
16623
|
+
" const exports = module.exports",
|
|
16624
|
+
embeddedCode,
|
|
16625
|
+
" return module.exports",
|
|
16626
|
+
"})();",
|
|
16627
|
+
`try{${globalModuleExpression}=${moduleRef}}catch{}`
|
|
16628
|
+
].join("\n"));
|
|
16629
|
+
for (const output of Object.values(bundle)) {
|
|
16630
|
+
if (!output || output.type !== "chunk") continue;
|
|
16631
|
+
const chunk = output;
|
|
16632
|
+
const didRewriteRequire = rewriteChunkRequireCallsToExpression(chunk, installerChunkFileName, globalModuleExpression);
|
|
16633
|
+
const didRewriteImport = rewriteChunkStaticImportsToExpression(chunk, installerChunkFileName, globalModuleExpression);
|
|
16634
|
+
if ((didRewriteRequire || didRewriteImport) && Array.isArray(chunk.imports)) chunk.imports = chunk.imports.filter((importee) => importee !== installerChunkFileName);
|
|
16635
|
+
}
|
|
16636
|
+
for (const output of Object.values(bundle)) {
|
|
16637
|
+
if (!output || output.type !== "asset" || typeof output.fileName !== "string") continue;
|
|
16638
|
+
const source = typeof output.source === "string" ? output.source : output.source?.toString();
|
|
16639
|
+
if (!source) continue;
|
|
16640
|
+
if (hasAssetRequireCallToFile(source, output.fileName, installerChunkFileName)) hasPreservedAssetRequire = true;
|
|
16641
|
+
}
|
|
16642
|
+
if (!hasPreservedAssetRequire) delete bundle[installerChunkFileName];
|
|
16643
|
+
}
|
|
16644
|
+
if (inlinedModules.length === 0) return;
|
|
16645
|
+
appChunk.code = `${inlinedModules.join("\n")}\n${appChunk.code}`;
|
|
16646
|
+
}
|
|
16447
16647
|
function createRequestGlobalsPreludeCode(chunk, installerChunks, targets, mode, networkDefaults) {
|
|
16448
16648
|
const chunkTargets = resolveChunkRequestGlobalsTargets(chunk.code, targets, mode);
|
|
16449
16649
|
if (chunkTargets.length === 0 || chunk.code.includes(REQUEST_GLOBAL_PRELUDE_MARKER)) return;
|
|
@@ -16456,7 +16656,7 @@ function createRequestGlobalsPreludeCode(chunk, installerChunks, targets, mode,
|
|
|
16456
16656
|
else {
|
|
16457
16657
|
const installerImport = resolveRequestGlobalsInstallerImport(chunk, installerChunks);
|
|
16458
16658
|
if (!installerImport?.exportName || !installerImport.installerChunkFileName) return;
|
|
16459
|
-
installerHostCode =
|
|
16659
|
+
installerHostCode = `${toRequestGlobalsInstallerModuleExpression(chunk.fileName, installerImport.installerChunkFileName)}[${JSON.stringify(installerImport.exportName)}](${createRequestGlobalsInstallerOptionsCode(chunkTargets, networkDefaults)}) || globalThis`;
|
|
16460
16660
|
}
|
|
16461
16661
|
return [
|
|
16462
16662
|
`/* ${REQUEST_GLOBAL_PRELUDE_MARKER} */`,
|
|
@@ -16479,7 +16679,7 @@ function createRequestGlobalsPreludeAssetCode(preludeFileName, chunk, installerC
|
|
|
16479
16679
|
if (bindingTargets.length === 0) return;
|
|
16480
16680
|
const installerImport = resolveRequestGlobalsInstallerImport(chunk, installerChunks);
|
|
16481
16681
|
if (!installerImport?.installerChunkFileName || !installerImport.exportName) return;
|
|
16482
|
-
const installerHostCode =
|
|
16682
|
+
const installerHostCode = `${toRequestGlobalsInstallerModuleExpression(preludeFileName, installerImport.installerChunkFileName, { appRegisteredModule: false })}[${JSON.stringify(installerImport.exportName)}](${createRequestGlobalsInstallerOptionsCode(chunkTargets, networkDefaults)}) || globalThis`;
|
|
16483
16683
|
return [
|
|
16484
16684
|
`/* ${REQUEST_GLOBAL_PRELUDE_MARKER} */`,
|
|
16485
16685
|
`(() => {`,
|
|
@@ -16603,7 +16803,8 @@ function createAppPreludeRequireStatement(chunkFileName, preludeFileName) {
|
|
|
16603
16803
|
return `/* ${APP_PRELUDE_REQUIRE_MARKER} */require(${JSON.stringify(requestPath)})`;
|
|
16604
16804
|
}
|
|
16605
16805
|
function emitAppPreludeRequireAssets(bundle, appPreludeCode, state, requestGlobalsPreludeOptions, emitFile) {
|
|
16606
|
-
|
|
16806
|
+
const preservedRequestGlobalsInstallerChunks = /* @__PURE__ */ new Set();
|
|
16807
|
+
if (!appPreludeCode) return preservedRequestGlobalsInstallerChunks;
|
|
16607
16808
|
const preludeFileNames = /* @__PURE__ */ new Set();
|
|
16608
16809
|
if (state.subPackageMeta?.subPackage.root) preludeFileNames.add(`${state.subPackageMeta.subPackage.root}/${APP_PRELUDE_REQUIRE_FILE_BASENAME}`);
|
|
16609
16810
|
else {
|
|
@@ -16615,18 +16816,25 @@ function emitAppPreludeRequireAssets(bundle, appPreludeCode, state, requestGloba
|
|
|
16615
16816
|
const scopeChunks = Object.values(bundle).filter((output) => {
|
|
16616
16817
|
return output?.type === "chunk" && resolveAppPreludeRequireFileName(output.fileName, state) === fileName;
|
|
16617
16818
|
});
|
|
16618
|
-
const
|
|
16819
|
+
const requestGlobalsPreludeCode = requestGlobalsPreludeOptions.enabled ? scopeChunks.map((chunk) => createRequestGlobalsPreludeAssetCode(fileName, chunk, requestGlobalsPreludeOptions.installerChunks, requestGlobalsPreludeOptions.targets, requestGlobalsPreludeOptions.mode, requestGlobalsPreludeOptions.networkDefaults)).find(Boolean) : void 0;
|
|
16820
|
+
if (requestGlobalsPreludeCode) {
|
|
16821
|
+
const installerImport = scopeChunks.map((chunk) => resolveRequestGlobalsInstallerImport(chunk, requestGlobalsPreludeOptions.installerChunks)).find(Boolean);
|
|
16822
|
+
if (installerImport?.installerChunkFileName) preservedRequestGlobalsInstallerChunks.add(installerImport.installerChunkFileName);
|
|
16823
|
+
}
|
|
16824
|
+
const source = [requestGlobalsPreludeCode, appPreludeCode].filter(Boolean).join("\n");
|
|
16619
16825
|
emitFile?.({
|
|
16620
16826
|
type: "asset",
|
|
16621
16827
|
fileName,
|
|
16622
16828
|
source: `${source}\n`
|
|
16623
16829
|
});
|
|
16624
16830
|
}
|
|
16831
|
+
return preservedRequestGlobalsInstallerChunks;
|
|
16625
16832
|
}
|
|
16626
16833
|
function injectAppPreludeCode(bundle, appPreludeCode, options, state, requestGlobalsPreludeOptions, emitFile) {
|
|
16627
|
-
|
|
16834
|
+
let preservedRequestGlobalsInstallerChunks = /* @__PURE__ */ new Set();
|
|
16835
|
+
if (!options.enabled) return preservedRequestGlobalsInstallerChunks;
|
|
16628
16836
|
const entryChunkFileNames = options.mode === "entry" ? collectAppPreludeEntryChunkFileNames(state) : void 0;
|
|
16629
|
-
if (options.mode === "require" && appPreludeCode) emitAppPreludeRequireAssets(bundle, appPreludeCode, state, requestGlobalsPreludeOptions, emitFile);
|
|
16837
|
+
if (options.mode === "require" && appPreludeCode) preservedRequestGlobalsInstallerChunks = emitAppPreludeRequireAssets(bundle, appPreludeCode, state, requestGlobalsPreludeOptions, emitFile);
|
|
16630
16838
|
for (const output of Object.values(bundle)) {
|
|
16631
16839
|
if (output?.type !== "chunk") continue;
|
|
16632
16840
|
const chunk = output;
|
|
@@ -16637,6 +16845,7 @@ function injectAppPreludeCode(bundle, appPreludeCode, options, state, requestGlo
|
|
|
16637
16845
|
if (!injectedCode) continue;
|
|
16638
16846
|
chunk.code = prependChunkCodePreservingDirectives(chunk.code, injectedCode);
|
|
16639
16847
|
}
|
|
16848
|
+
return preservedRequestGlobalsInstallerChunks;
|
|
16640
16849
|
}
|
|
16641
16850
|
//#endregion
|
|
16642
16851
|
//#region src/plugins/core/lifecycle/emit/generate.ts
|
|
@@ -16807,10 +17016,11 @@ function createGenerateBundleHook(state, isPluginBuild) {
|
|
|
16807
17016
|
injectRequestGlobalsPassiveBindings(rolldownBundle, installerChunks, injectRequestGlobalsOptions.targets, injectRequestGlobalsOptions.mode, state.entriesMap);
|
|
16808
17017
|
injectRequestGlobalsLocalBindings(rolldownBundle, installerChunks, injectRequestGlobalsOptions.targets, injectRequestGlobalsOptions.mode, state.entriesMap, injectRequestGlobalsOptions.networkDefaults);
|
|
16809
17018
|
injectAxiosFetchAdapterEnv(rolldownBundle);
|
|
17019
|
+
injectRequestGlobalsAppRegistration(rolldownBundle, installerChunks);
|
|
16810
17020
|
collapseRequestGlobalsRuntimeSupportChunk(rolldownBundle);
|
|
16811
17021
|
}
|
|
16812
17022
|
const appPreludeOptions = resolveAppPreludeOptions(state);
|
|
16813
|
-
injectAppPreludeCode(rolldownBundle, await resolveAppPreludeCode(scanService.appEntry?.preludePath, {
|
|
17023
|
+
const preservedRequestGlobalsInstallerChunks = injectAppPreludeCode(rolldownBundle, await resolveAppPreludeCode(scanService.appEntry?.preludePath, {
|
|
16814
17024
|
importMetaDefineRegistry: configService.importMetaDefineRegistry,
|
|
16815
17025
|
relativePath: scanService.appEntry?.preludePath ? configService.relativeAbsoluteSrcRoot(scanService.appEntry.preludePath) : void 0
|
|
16816
17026
|
}), {
|
|
@@ -16823,6 +17033,7 @@ function createGenerateBundleHook(state, isPluginBuild) {
|
|
|
16823
17033
|
networkDefaults: injectRequestGlobalsOptions?.networkDefaults,
|
|
16824
17034
|
targets: injectRequestGlobalsOptions?.targets ?? []
|
|
16825
17035
|
}, (asset) => this.emitFile(asset));
|
|
17036
|
+
if (injectRequestGlobalsOptions?.targets?.length) inlineRequestGlobalsAppRegisteredInstallerChunks(rolldownBundle, installerChunks, preservedRequestGlobalsInstallerChunks);
|
|
16826
17037
|
syncChunkImportsFromRequireCalls(rolldownBundle);
|
|
16827
17038
|
refreshModuleGraph(this, state);
|
|
16828
17039
|
if (configService.weappViteConfig?.debug?.watchFiles) {
|
|
@@ -22133,6 +22344,17 @@ function createConfigServicePlugin(ctx) {
|
|
|
22133
22344
|
//#region src/runtime/jsonPlugin.ts
|
|
22134
22345
|
const APP_CONFIG_RE = /app\.json(?:\.[jt]s)?$/;
|
|
22135
22346
|
const SCRIPT_JSON_CONFIG_RE = /\.json\.[jt]s$/;
|
|
22347
|
+
function normalizeAppConfigJson(config) {
|
|
22348
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) return config;
|
|
22349
|
+
const subPackages = Array.isArray(config.subPackages) ? config.subPackages : Array.isArray(config.subpackages) ? config.subpackages : [];
|
|
22350
|
+
return {
|
|
22351
|
+
...config,
|
|
22352
|
+
subPackages: subPackages.map((subPackage) => ({
|
|
22353
|
+
...subPackage,
|
|
22354
|
+
pages: Array.isArray(subPackage?.pages) ? subPackage.pages : []
|
|
22355
|
+
}))
|
|
22356
|
+
};
|
|
22357
|
+
}
|
|
22136
22358
|
function createJsonService(ctx) {
|
|
22137
22359
|
const cache = ctx.runtimeState.json.cache;
|
|
22138
22360
|
async function read(filepath) {
|
|
@@ -22172,6 +22394,7 @@ function createJsonService(ctx) {
|
|
|
22172
22394
|
if (tempFilepath !== filepath) await fs.remove(tempFilepath);
|
|
22173
22395
|
}
|
|
22174
22396
|
} else resultJson = parseCommentJson(await fs.readFile(filepath, "utf8"));
|
|
22397
|
+
if (isAppConfig) resultJson = normalizeAppConfigJson(resultJson);
|
|
22175
22398
|
cache.set(filepath, resultJson);
|
|
22176
22399
|
return resultJson;
|
|
22177
22400
|
} catch (error) {
|
|
@@ -22521,6 +22744,13 @@ function mergeAutoRouteSubPackages(subPackages, routeSubPackages) {
|
|
|
22521
22744
|
if (!changed && anonymousEntries.length === 0) return existingEntries;
|
|
22522
22745
|
return [...merged.values(), ...anonymousEntries];
|
|
22523
22746
|
}
|
|
22747
|
+
function normalizeAppConfigSubPackages(config) {
|
|
22748
|
+
config.subPackages = (Array.isArray(config.subPackages) ? config.subPackages : Array.isArray(config.subpackages) ? config.subpackages : []).map((subPackage) => ({
|
|
22749
|
+
...subPackage,
|
|
22750
|
+
pages: Array.isArray(subPackage?.pages) ? subPackage.pages : []
|
|
22751
|
+
}));
|
|
22752
|
+
return config;
|
|
22753
|
+
}
|
|
22524
22754
|
async function applyAutoRoutesToAppConfigIfNeeded(ctx, config) {
|
|
22525
22755
|
const autoRoutesService = ctx.autoRoutesService;
|
|
22526
22756
|
if (!autoRoutesService?.isEnabled()) return config;
|
|
@@ -22541,7 +22771,7 @@ async function applyAutoRoutesToAppConfigIfNeeded(ctx, config) {
|
|
|
22541
22771
|
...subPackage,
|
|
22542
22772
|
pages: Array.isArray(subPackage.pages) ? subPackage.pages : []
|
|
22543
22773
|
}));
|
|
22544
|
-
return config;
|
|
22774
|
+
return normalizeAppConfigSubPackages(config);
|
|
22545
22775
|
}
|
|
22546
22776
|
async function loadAppEntry(ctx, scanState) {
|
|
22547
22777
|
if (!ctx.configService || !ctx.jsonService) throw new Error("扫描入口前必须初始化 configService/jsonService。");
|
|
@@ -22556,7 +22786,7 @@ async function loadAppEntry(ctx, scanState) {
|
|
|
22556
22786
|
const vueAppPath = await findVueEntry(appBasename);
|
|
22557
22787
|
let configFromVue;
|
|
22558
22788
|
if (!appConfigFile && vueAppPath) {
|
|
22559
|
-
const { extractConfigFromVue } = await import("./file-
|
|
22789
|
+
const { extractConfigFromVue } = await import("./file-D7c-LQA5.mjs");
|
|
22560
22790
|
configFromVue = await extractConfigFromVue(vueAppPath);
|
|
22561
22791
|
if (configFromVue) appConfigFile = vueAppPath;
|
|
22562
22792
|
}
|
|
@@ -22578,6 +22808,7 @@ async function loadAppEntry(ctx, scanState) {
|
|
|
22578
22808
|
else config = await ctx.jsonService.read(appConfigFile);
|
|
22579
22809
|
await applyAutoRoutesToAppConfigIfNeeded(ctx, config);
|
|
22580
22810
|
if (isObject(config)) {
|
|
22811
|
+
normalizeAppConfigSubPackages(config);
|
|
22581
22812
|
const resolvedAppEntry = {
|
|
22582
22813
|
path: appEntryPath || vueAppPath,
|
|
22583
22814
|
preludePath: appPreludePath,
|
|
@@ -23565,33 +23796,27 @@ function getAppPaths(ctx, legacyConfig) {
|
|
|
23565
23796
|
}
|
|
23566
23797
|
function createSharedTsconfig(ctx, legacyConfig) {
|
|
23567
23798
|
const userConfig = getManagedTypeScriptConfig(ctx);
|
|
23568
|
-
const config = { compilerOptions: {
|
|
23569
|
-
target: "ES2023",
|
|
23570
|
-
module: "ESNext",
|
|
23571
|
-
moduleResolution: "bundler",
|
|
23572
|
-
moduleDetection: "force",
|
|
23573
|
-
resolveJsonModule: true,
|
|
23574
|
-
allowImportingTsExtensions: true,
|
|
23575
|
-
strict: true,
|
|
23576
|
-
noFallthroughCasesInSwitch: true,
|
|
23577
|
-
noUnusedLocals: true,
|
|
23578
|
-
noUnusedParameters: true,
|
|
23579
|
-
noEmit: true,
|
|
23580
|
-
verbatimModuleSyntax: true,
|
|
23581
|
-
noUncheckedSideEffectImports: true,
|
|
23582
|
-
erasableSyntaxOnly: true,
|
|
23583
|
-
skipLibCheck: true,
|
|
23584
|
-
...omitDeprecatedCompilerOptions(legacyConfig?.shared?.compilerOptions) ?? {},
|
|
23585
|
-
...omitDeprecatedCompilerOptions(userConfig?.shared?.compilerOptions) ?? {}
|
|
23586
|
-
} };
|
|
23587
|
-
const exclude = unique([...legacyConfig?.shared?.exclude ?? [], ...userConfig?.shared?.exclude ?? []]);
|
|
23588
|
-
const files = unique([...legacyConfig?.shared?.files ?? [], ...userConfig?.shared?.files ?? []]);
|
|
23589
|
-
const include = unique([...legacyConfig?.shared?.include ?? [], ...userConfig?.shared?.include ?? []]);
|
|
23590
23799
|
return {
|
|
23591
|
-
|
|
23592
|
-
|
|
23593
|
-
|
|
23594
|
-
|
|
23800
|
+
compilerOptions: {
|
|
23801
|
+
target: "ES2023",
|
|
23802
|
+
module: "ESNext",
|
|
23803
|
+
moduleResolution: "bundler",
|
|
23804
|
+
moduleDetection: "force",
|
|
23805
|
+
resolveJsonModule: true,
|
|
23806
|
+
allowImportingTsExtensions: true,
|
|
23807
|
+
strict: true,
|
|
23808
|
+
noFallthroughCasesInSwitch: true,
|
|
23809
|
+
noUnusedLocals: true,
|
|
23810
|
+
noUnusedParameters: true,
|
|
23811
|
+
noEmit: true,
|
|
23812
|
+
verbatimModuleSyntax: true,
|
|
23813
|
+
noUncheckedSideEffectImports: true,
|
|
23814
|
+
erasableSyntaxOnly: true,
|
|
23815
|
+
skipLibCheck: true,
|
|
23816
|
+
...omitDeprecatedCompilerOptions(legacyConfig?.shared?.compilerOptions) ?? {},
|
|
23817
|
+
...omitDeprecatedCompilerOptions(userConfig?.shared?.compilerOptions) ?? {}
|
|
23818
|
+
},
|
|
23819
|
+
files: ["./tsconfig.shared.empty.d.ts"]
|
|
23595
23820
|
};
|
|
23596
23821
|
}
|
|
23597
23822
|
function createAppTsconfig(ctx, legacyConfig) {
|
|
@@ -23691,6 +23916,10 @@ async function createManagedTsconfigFiles(ctx) {
|
|
|
23691
23916
|
const nodePath = path.join(managedDir, "tsconfig.node.json");
|
|
23692
23917
|
const serverPath = path.join(managedDir, "tsconfig.server.json");
|
|
23693
23918
|
return [
|
|
23919
|
+
{
|
|
23920
|
+
path: path.join(managedDir, "tsconfig.shared.empty.d.ts"),
|
|
23921
|
+
content: "export {}\n"
|
|
23922
|
+
},
|
|
23694
23923
|
{
|
|
23695
23924
|
path: sharedPath,
|
|
23696
23925
|
content: toJson(createSharedTsconfig(ctx, legacyConfig))
|