weapp-vite 6.18.7 → 6.19.1
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 +28 -0
- package/dist/auto-import-components/resolvers.d.mts +2 -2
- package/dist/auto-import-components/resolvers.mjs +2 -334
- package/dist/auto-routes.mjs +1 -1
- package/dist/cli.mjs +52 -17
- package/dist/{config-DEdY6_Qn.d.mts → config-CKToDk5V.d.mts} +22 -4
- package/dist/config.d.mts +1 -1
- package/dist/{createContext-C3XuGjnq.mjs → createContext-DrwOUlDX.mjs} +914 -364
- package/dist/docs/README.md +28 -0
- package/dist/docs/getting-started.md +13 -0
- package/dist/docs/index.md +7 -3
- package/dist/docs/testing.md +38 -0
- package/dist/docs/uni-app-component-libraries.md +213 -0
- package/dist/docs/weapp-config.md +29 -0
- package/dist/{file-DjQkG6ce.mjs → file-CdNDPmkx.mjs} +1 -1
- package/dist/file-TBExd8Jd.mjs +2 -0
- package/dist/getInstance-wujsDq8Q.mjs +2 -0
- package/dist/{index-Bmclyjw8.d.mts → index-CaXAtb9e.d.mts} +24 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +2 -2
- package/dist/json.d.mts +1 -1
- package/dist/mcp.d.mts +1 -1
- package/dist/resolvers-w4g7O94W.mjs +684 -0
- package/dist/resolvers.d.mts +2 -0
- package/dist/resolvers.mjs +2 -0
- package/dist/{runtime-kc5RVjrC.mjs → runtime-D6VCNhNY.mjs} +4 -2
- package/dist/runtime.mjs +1 -1
- package/dist/test.d.mts +33 -0
- package/dist/test.mjs +82 -0
- package/dist/types.d.mts +3 -3
- package/package.json +32 -24
- package/dist/file-CWBCL2N8.mjs +0 -2
- package/dist/getInstance-DrwD5CVt.mjs +0 -2
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { n as applyWeappViteHostMeta } from "./pluginHost--CaeyWpA.mjs";
|
|
2
2
|
import { n as configureLogger, r as logger_default } from "./logger-mt4mSTqV.mjs";
|
|
3
|
-
import { _ as jsExtensions, a as findJsonEntry, b as vueExtensions, c as isJsOrTs, d as touch, g as configExtensions, i as findJsEntry, l as isTemplate, n as changeFileExtension, o as findTemplateEntry, p as inlineAutoRoutesImports, r as findCssEntry, s as findVueEntry, t as extractConfigFromVue, v as supportedCssLangs, y as templateExtensions } from "./file-
|
|
3
|
+
import { _ as jsExtensions, a as findJsonEntry, b as vueExtensions, c as isJsOrTs, d as touch, g as configExtensions, i as findJsEntry, l as isTemplate, n as changeFileExtension, o as findTemplateEntry, p as inlineAutoRoutesImports, r as findCssEntry, s as findVueEntry, t as extractConfigFromVue, v as supportedCssLangs, y as templateExtensions } from "./file-CdNDPmkx.mjs";
|
|
4
4
|
import { createRequire, isBuiltin } from "node:module";
|
|
5
5
|
import { createDebug } from "obug";
|
|
6
6
|
import fs, { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
7
|
-
import { APP_PRELUDE_CHUNK_MARKER, APP_PRELUDE_GUARD_KEY, APP_PRELUDE_REQUIRE_MARKER, REQUEST_GLOBAL_ACTUALS_KEY, REQUEST_GLOBAL_BUNDLE_HOST_REF, REQUEST_GLOBAL_BUNDLE_MARKER, REQUEST_GLOBAL_CHUNK_HOST_REF, REQUEST_GLOBAL_CHUNK_MODULE_REF, REQUEST_GLOBAL_EXPOSE_HELPER, REQUEST_GLOBAL_INSTALLER_HOST_REF, REQUEST_GLOBAL_LAZY_CONSTRUCTOR_HELPER, REQUEST_GLOBAL_LAZY_FUNCTION_HELPER, REQUEST_GLOBAL_LOCAL_BINDINGS_MARKER, REQUEST_GLOBAL_MARK_PLACEHOLDER_HELPER, REQUEST_GLOBAL_PASSIVE_BINDINGS_MARKER, REQUEST_GLOBAL_PASSIVE_BINDINGS_MARKER as REQUEST_GLOBAL_PASSIVE_BINDINGS_MARKER$1, REQUEST_GLOBAL_PLACEHOLDER_KEY, REQUEST_GLOBAL_PRELUDE_GUARD_KEY, REQUEST_GLOBAL_PRELUDE_MARKER, REQUEST_GLOBAL_SYNTHETIC_EXPORT_NAME, REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER, WEAPP_VITE_IMPORT_META_ENV_KEY, WEAPP_VITE_INJECTED_API_IDENTIFIER, WEAPP_VITE_LOGICAL_ENTRY_RESOLVED_PREFIX, WEAPP_VITE_LOGICAL_ENTRY_VIRTUAL_PREFIX, WEAPP_VITE_RUNTIME_CONTRACT_VERSION, WEAPP_VITE_RUNTIME_REACTIVITY_VIRTUAL_ID, WEAPP_VITE_RUNTIME_TEMPLATE_VIRTUAL_ID, WEAPP_VITE_RUNTIME_VIRTUAL_ID, WEAPP_VITE_RUNTIME_VIRTUAL_IDS, WEAPP_VITE_SIDECAR_OWNER_QUERY_MARKER, WEAPP_VITE_SIDECAR_QUERY_MARKER, WEAPP_VITE_SIDECAR_RESOLVED_PREFIX, WEAPP_VITE_SIDECAR_VIRTUAL_PREFIX, WEAPP_VITE_STATEFUL_HMR_BRIDGE_KEY, WEAPP_VITE_STATEFUL_HMR_CLIENT_KEY, WEAPP_VITE_STATEFUL_HMR_CONTROL_FILE, WEAPP_VITE_STATEFUL_HMR_CONTROL_KEY, WEAPP_VITE_STATEFUL_HMR_PRELOAD_FILE, WEAPP_VITE_STATEFUL_HMR_UPDATE_FILE, WEVU_APP_SHELL_COMPONENT_BASE, WEVU_APP_SHELL_TAG_NAME, WEVU_EXPRESSION_ERROR_IDENTIFIER, WEVU_INTERNAL_KEY_IDENTIFIER, WEVU_LAYOUT_BIND_PREFIX, WEVU_PAGE_LAYOUT_CURRENT_NAME_IDENTIFIER, WEVU_PAGE_LAYOUT_CURRENT_PROPS_IDENTIFIER, WEVU_PAGE_LAYOUT_NAME_KEY, WEVU_PAGE_LAYOUT_NEXT_NAME_IDENTIFIER, WEVU_PAGE_LAYOUT_NEXT_PROPS_IDENTIFIER, WEVU_PAGE_LAYOUT_NONE, WEVU_PAGE_LAYOUT_PROPS_KEY, WEVU_PAGE_LAYOUT_SETTER_KEY, WEVU_SCOPED_SLOT_CREATOR_KEY, WEVU_SLOT_FALLBACK_VIRTUAL_HOST_BASE, WEVU_SLOT_FALLBACK_VIRTUAL_HOST_GLOBAL_PATH, WEVU_SLOT_FALLBACK_VIRTUAL_HOST_TAG_NAME, WEVU_SLOT_NAMES_PROP, WEVU_SLOT_OWNER_ID_ATTR, WEVU_SLOT_OWNER_ID_KEY, WEVU_SLOT_OWNER_ID_PROP, WEVU_SLOT_PROPS_ATTR, WEVU_SLOT_SCOPE_ATTR, WEVU_SLOT_SCOPE_KEY } from "@weapp-core/constants";
|
|
7
|
+
import { APP_PRELUDE_CHUNK_MARKER, APP_PRELUDE_GUARD_KEY, APP_PRELUDE_REQUIRE_MARKER, REQUEST_GLOBAL_ACTUALS_KEY, REQUEST_GLOBAL_BUNDLE_HOST_REF, REQUEST_GLOBAL_BUNDLE_MARKER, REQUEST_GLOBAL_CHUNK_HOST_REF, REQUEST_GLOBAL_CHUNK_MODULE_REF, REQUEST_GLOBAL_EXPOSE_HELPER, REQUEST_GLOBAL_INSTALLER_HOST_REF, REQUEST_GLOBAL_LAZY_CONSTRUCTOR_HELPER, REQUEST_GLOBAL_LAZY_FUNCTION_HELPER, REQUEST_GLOBAL_LOCAL_BINDINGS_MARKER, REQUEST_GLOBAL_MARK_PLACEHOLDER_HELPER, REQUEST_GLOBAL_PASSIVE_BINDINGS_MARKER, REQUEST_GLOBAL_PASSIVE_BINDINGS_MARKER as REQUEST_GLOBAL_PASSIVE_BINDINGS_MARKER$1, REQUEST_GLOBAL_PLACEHOLDER_KEY, REQUEST_GLOBAL_PRELUDE_GUARD_KEY, REQUEST_GLOBAL_PRELUDE_MARKER, REQUEST_GLOBAL_SYNTHETIC_EXPORT_NAME, REQUEST_GLOBAL_USABLE_CONSTRUCTOR_HELPER, WEAPP_VITE_EXTERNAL_OUTPUT_DIRECTORY, WEAPP_VITE_IMPORT_META_ENV_KEY, WEAPP_VITE_INJECTED_API_IDENTIFIER, WEAPP_VITE_LOGICAL_ENTRY_RESOLVED_PREFIX, WEAPP_VITE_LOGICAL_ENTRY_VIRTUAL_PREFIX, WEAPP_VITE_RUNTIME_CONTRACT_VERSION, WEAPP_VITE_RUNTIME_REACTIVITY_VIRTUAL_ID, WEAPP_VITE_RUNTIME_TEMPLATE_VIRTUAL_ID, WEAPP_VITE_RUNTIME_VIRTUAL_ID, WEAPP_VITE_RUNTIME_VIRTUAL_IDS, WEAPP_VITE_SIDECAR_OWNER_QUERY_MARKER, WEAPP_VITE_SIDECAR_QUERY_MARKER, WEAPP_VITE_SIDECAR_RESOLVED_PREFIX, WEAPP_VITE_SIDECAR_VIRTUAL_PREFIX, WEAPP_VITE_STATEFUL_HMR_BRIDGE_KEY, WEAPP_VITE_STATEFUL_HMR_CLIENT_KEY, WEAPP_VITE_STATEFUL_HMR_CONTROL_FILE, WEAPP_VITE_STATEFUL_HMR_CONTROL_KEY, WEAPP_VITE_STATEFUL_HMR_PRELOAD_FILE, WEAPP_VITE_STATEFUL_HMR_UPDATE_FILE, WEVU_APP_SHELL_COMPONENT_BASE, WEVU_APP_SHELL_TAG_NAME, WEVU_EXPRESSION_ERROR_IDENTIFIER, WEVU_INTERNAL_KEY_IDENTIFIER, WEVU_LAYOUT_BIND_PREFIX, WEVU_PAGE_LAYOUT_CURRENT_NAME_IDENTIFIER, WEVU_PAGE_LAYOUT_CURRENT_PROPS_IDENTIFIER, WEVU_PAGE_LAYOUT_NAME_KEY, WEVU_PAGE_LAYOUT_NEXT_NAME_IDENTIFIER, WEVU_PAGE_LAYOUT_NEXT_PROPS_IDENTIFIER, WEVU_PAGE_LAYOUT_NONE, WEVU_PAGE_LAYOUT_PROPS_KEY, WEVU_PAGE_LAYOUT_SETTER_KEY, WEVU_SCOPED_SLOT_CREATOR_KEY, WEVU_SLOT_FALLBACK_VIRTUAL_HOST_BASE, WEVU_SLOT_FALLBACK_VIRTUAL_HOST_GLOBAL_PATH, WEVU_SLOT_FALLBACK_VIRTUAL_HOST_TAG_NAME, WEVU_SLOT_NAMES_PROP, WEVU_SLOT_OWNER_ID_ATTR, WEVU_SLOT_OWNER_ID_KEY, WEVU_SLOT_OWNER_ID_PROP, WEVU_SLOT_PROPS_ATTR, WEVU_SLOT_SCOPE_ATTR, WEVU_SLOT_SCOPE_KEY } from "@weapp-core/constants";
|
|
8
8
|
import path, { posix } from "pathe";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
import path$1, { normalize, relative, win32 } from "node:path";
|
|
11
11
|
import { MINI_PROGRAM_PLATFORM_ALIASES, MINI_PROGRAM_PLATFORM_DESCRIPTORS, MINI_PROGRAM_PLATFORM_DESCRIPTORS as MINI_PROGRAM_PLATFORM_ADAPTERS, addExtension, defu, escapeStringRegexp, get, getDefaultMiniProgramPlatform, getMiniProgramAppTypesPackage, getMiniProgramDefaultBuildTarget, getMiniProgramDirectivePrefix, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getSupportedMiniProgramDirectivePrefixes, getSupportedMiniProgramPlatforms, isEmptyObject, isObject, normalizeMiniProgramPlatform, removeExtension, removeExtensionDeep, resolveMiniProgramPlatform, set, supportsMiniProgramAutoTouchAppStyle } from "@weapp-core/shared";
|
|
12
12
|
import { fs as fs$1 } from "@weapp-core/shared/fs";
|
|
13
|
-
import { analyzeScript, analyzeScripts, collectComponentPropsFromCode, collectRequireTokens, collectScriptSetupImportsFromCode, mayContainPlatformApiAccess, mayContainPlatformApiIdentifierByText, mayContainStaticRequireLiteral, parseJsLikeWithEngine, platformApiIdentifiers } from "@weapp-vite/ast";
|
|
13
|
+
import { analyzeScript, analyzeScripts, collectComponentPropsFromCode, collectRequireTokens, collectScriptSetupImportsFromCode, generate, mayContainPlatformApiAccess, mayContainPlatformApiIdentifierByText, mayContainStaticRequireLiteral, parseJsLikeWithEngine, platformApiIdentifiers } from "@weapp-vite/ast";
|
|
14
14
|
import { collectOnPageScrollPerformanceWarnings } from "@weapp-vite/ast/operations/onPageScroll";
|
|
15
15
|
import { collectSetDataPickKeysFromTemplateCode } from "@weapp-vite/ast/operations/setDataPick";
|
|
16
16
|
import { compileScript, parse } from "vue/compiler-sfc";
|
|
17
|
-
import { BABEL_TS_MODULE_PARSER_OPTIONS, generate, getVisitorKeys, parse as parse$2, parseJsLike, traverse } from "@weapp-vite/ast/babel";
|
|
17
|
+
import { BABEL_TS_MODULE_PARSER_OPTIONS, generate as generate$1, getVisitorKeys, parse as parse$2, parseJsLike, traverse } from "@weapp-vite/ast/babel";
|
|
18
18
|
import pm from "picomatch";
|
|
19
|
-
import { VUE_COMPONENT_TAG_RE, WE_VU_COMPILER_REACTIVITY_MODULE_ID, WE_VU_COMPILER_RUNTIME_MODULE_ID, WE_VU_COMPILER_TEMPLATE_MODULE_ID, WE_VU_RUNTIME_APIS, buildClassStyleComputedCode, collectVueTemplateTags, compileJsxFile, compileVueFile, compileVueStyleToWxss, createJsonMerger, createPageEntryMatcher, createPageEntryMatcher as createPageEntryMatcher$1, generateScopedId, getClassStyleWxsSource, getMiniProgramTemplatePlatform, getSfcCheckMtime, injectWevuPageFeaturesInJsWithResolver, invalidateFileCache, isAutoImportCandidateTag, isBuiltinComponent, pathExists, readAndParseSfc, readFile as readFile$1, refreshVueFileJsonConfig, resolveClassStyleWxsLocation, stripJsonMacroCallsFromCode } from "wevu/compiler";
|
|
19
|
+
import { VUE_COMPONENT_TAG_RE, WE_VU_COMPILER_REACTIVITY_MODULE_ID, WE_VU_COMPILER_RUNTIME_MODULE_ID, WE_VU_COMPILER_TEMPLATE_MODULE_ID, WE_VU_RUNTIME_APIS, buildClassStyleComputedCode, collectVueTemplateTags, compileJsxFile, compileVueFile, compileVueStyleToWxss, createJsonMerger, createPageEntryMatcher, createPageEntryMatcher as createPageEntryMatcher$1, generateScopedId, getClassStyleWxsSource, getMiniProgramTemplatePlatform, getSfcCheckMtime, injectWevuPageFeaturesInJsWithResolver, invalidateFileCache, isAutoImportCandidateTag, isBuiltinComponent, isUniAppCompatibilityFile, pathExists, readAndParseSfc, readFile as readFile$1, refreshVueFileJsonConfig, resolveClassStyleWxsLocation, stripJsonMacroCallsFromCode, transformNestedWxssVars, transformUniAppSource, transformVueDeepSelectors } from "wevu/compiler";
|
|
20
20
|
import process from "node:process";
|
|
21
21
|
import { parse as parse$1, stringify } from "comment-json";
|
|
22
22
|
import fs$2, { appendFile, copyFile, mkdir, readFile, readdir, rm } from "node:fs/promises";
|
|
@@ -480,7 +480,8 @@ function normalizeRelativePath$1(value) {
|
|
|
480
480
|
}
|
|
481
481
|
function normalizeWatchPath(value) {
|
|
482
482
|
if (!value) return value;
|
|
483
|
-
|
|
483
|
+
const posix = toPosixPath(stripWindowsDevicePath(value));
|
|
484
|
+
return toPosixPath(normalize(posix));
|
|
484
485
|
}
|
|
485
486
|
function stripLeadingSlashes(value) {
|
|
486
487
|
return value.replace(LEADING_SLASH_RE$3, "");
|
|
@@ -1216,7 +1217,7 @@ function mapConstructorName(name) {
|
|
|
1216
1217
|
//#endregion
|
|
1217
1218
|
//#region src/runtime/autoImport/dtsProps.ts
|
|
1218
1219
|
function getNodeText(node) {
|
|
1219
|
-
return generate(node, {
|
|
1220
|
+
return generate$1(node, {
|
|
1220
1221
|
comments: false,
|
|
1221
1222
|
concise: true
|
|
1222
1223
|
}).code.trim();
|
|
@@ -1320,10 +1321,11 @@ function extractFromPropsInterfaceMembers(node) {
|
|
|
1320
1321
|
}
|
|
1321
1322
|
function extractComponentPropsFromDts(code) {
|
|
1322
1323
|
let props = /* @__PURE__ */ new Map();
|
|
1323
|
-
|
|
1324
|
+
const ast = parse$2(code, {
|
|
1324
1325
|
...BABEL_TS_MODULE_PARSER_OPTIONS,
|
|
1325
1326
|
errorRecovery: true
|
|
1326
|
-
})
|
|
1327
|
+
});
|
|
1328
|
+
traverse(ast, {
|
|
1327
1329
|
TSInterfaceDeclaration(path) {
|
|
1328
1330
|
if (props.size > 0) {
|
|
1329
1331
|
path.stop();
|
|
@@ -4895,7 +4897,7 @@ async function syncTypedComponentsDefinition(settings, options) {
|
|
|
4895
4897
|
}
|
|
4896
4898
|
}
|
|
4897
4899
|
async function syncVueComponentsDefinition(settings, options) {
|
|
4898
|
-
const { outputsState, ctx, resolverComponentsMapRef,
|
|
4900
|
+
const { outputsState, ctx, resolverComponentsMapRef, resolveComponentTypeImport } = options;
|
|
4899
4901
|
const configService = requireConfigService(ctx, "写入 components.d.ts 前必须初始化 configService。");
|
|
4900
4902
|
if (!settings.enabled || !settings.outputPath) {
|
|
4901
4903
|
if (outputsState.lastVueComponentsOutputPath) try {
|
|
@@ -4931,7 +4933,7 @@ async function syncVueComponentsDefinition(settings, options) {
|
|
|
4931
4933
|
}
|
|
4932
4934
|
const from = resolverComponentsMapRef.value[name];
|
|
4933
4935
|
if (!from) return;
|
|
4934
|
-
return
|
|
4936
|
+
return resolveComponentTypeImport(name, from);
|
|
4935
4937
|
}
|
|
4936
4938
|
});
|
|
4937
4939
|
const vueUnchanged = nextDefinition === outputsState.lastWrittenVueComponentsDefinition && outputPath === outputsState.lastVueComponentsOutputPath;
|
|
@@ -4984,7 +4986,7 @@ async function syncHtmlCustomData(settings, options) {
|
|
|
4984
4986
|
//#endregion
|
|
4985
4987
|
//#region src/runtime/autoImport/service/outputs/index.ts
|
|
4986
4988
|
function createOutputsHelpers(options) {
|
|
4987
|
-
const { ctx, registry, manifestFileName, manifestCache, componentMetadataMap, outputsState, getPreparedStateVersion, resolverComponentsMapRef, collectResolverComponents, collectManifestResolverComponents, syncResolverComponentProps, preloadResolverComponentMetadata, getComponentMetadata,
|
|
4989
|
+
const { ctx, registry, manifestFileName, manifestCache, componentMetadataMap, outputsState, getPreparedStateVersion, resolverComponentsMapRef, collectResolverComponents, collectManifestResolverComponents, syncResolverComponentProps, preloadResolverComponentMetadata, getComponentMetadata, resolveComponentTypeImport } = options;
|
|
4988
4990
|
const commonSyncOptions = {
|
|
4989
4991
|
ctx,
|
|
4990
4992
|
outputsState,
|
|
@@ -5015,7 +5017,7 @@ function createOutputsHelpers(options) {
|
|
|
5015
5017
|
syncVueComponents: async (settings) => syncVueComponentsDefinition(settings, {
|
|
5016
5018
|
...commonSyncOptions,
|
|
5017
5019
|
resolverComponentsMapRef,
|
|
5018
|
-
|
|
5020
|
+
resolveComponentTypeImport
|
|
5019
5021
|
})
|
|
5020
5022
|
});
|
|
5021
5023
|
return {
|
|
@@ -5951,6 +5953,11 @@ function createResolverHelpers(state) {
|
|
|
5951
5953
|
}
|
|
5952
5954
|
resolveCache.set(cacheKey, null);
|
|
5953
5955
|
}
|
|
5956
|
+
function resolveComponentTypeImport(componentName, from) {
|
|
5957
|
+
const resolved = resolveWithResolvers(componentName);
|
|
5958
|
+
if (resolved?.from === from && resolved.typeImport === false) return;
|
|
5959
|
+
return resolveNavigationImport(from);
|
|
5960
|
+
}
|
|
5954
5961
|
return {
|
|
5955
5962
|
collectResolverComponents,
|
|
5956
5963
|
collectRuntimeResolverComponents,
|
|
@@ -5961,7 +5968,8 @@ function createResolverHelpers(state) {
|
|
|
5961
5968
|
clearSupportFileResolverComponents,
|
|
5962
5969
|
collectStaticResolverComponentsForSupportFiles,
|
|
5963
5970
|
resolveWithResolvers,
|
|
5964
|
-
resolveNavigationImport
|
|
5971
|
+
resolveNavigationImport,
|
|
5972
|
+
resolveComponentTypeImport
|
|
5965
5973
|
};
|
|
5966
5974
|
}
|
|
5967
5975
|
//#endregion
|
|
@@ -6036,7 +6044,7 @@ function createAutoImportScheduling(options) {
|
|
|
6036
6044
|
//#region src/runtime/autoImport/service/shared.ts
|
|
6037
6045
|
const logWarnCache = new LRUCache({
|
|
6038
6046
|
max: 512,
|
|
6039
|
-
ttl:
|
|
6047
|
+
ttl: 36e5
|
|
6040
6048
|
});
|
|
6041
6049
|
function logWarnOnce(message) {
|
|
6042
6050
|
if (logWarnCache.get(message)) return;
|
|
@@ -6114,7 +6122,7 @@ function createAutoImportService(ctx) {
|
|
|
6114
6122
|
syncResolverComponentProps: resolverHelpers.syncResolverComponentProps,
|
|
6115
6123
|
preloadResolverComponentMetadata: metadataHelpers.preloadResolverComponentMetadata,
|
|
6116
6124
|
getComponentMetadata: metadataHelpers.getComponentMetadata,
|
|
6117
|
-
|
|
6125
|
+
resolveComponentTypeImport: resolverHelpers.resolveComponentTypeImport
|
|
6118
6126
|
})
|
|
6119
6127
|
});
|
|
6120
6128
|
return {
|
|
@@ -7602,7 +7610,15 @@ function resolveNpmStrategyMode(ctx) {
|
|
|
7602
7610
|
//#region src/moduleGraph/logicalEntry.ts
|
|
7603
7611
|
function createLogicalEntryModuleCode(entry, dependencies) {
|
|
7604
7612
|
const source = JSON.stringify(entry.sourceId);
|
|
7605
|
-
const
|
|
7613
|
+
const isVueLikeEntry = /\.(?:vue|jsx|tsx)$/.test(entry.sourceId);
|
|
7614
|
+
const delegatesComponentRegistration = entry.type === "component" && isVueLikeEntry;
|
|
7615
|
+
const forwardsDefault = entry.type !== "app" && isVueLikeEntry;
|
|
7616
|
+
const imports = delegatesComponentRegistration ? [
|
|
7617
|
+
`import { createWevuComponent as __weappViteCreateWevuComponent } from "wevu";`,
|
|
7618
|
+
`import __weappViteComponentOptions from ${source};`,
|
|
7619
|
+
`__weappViteCreateWevuComponent(__weappViteComponentOptions);`,
|
|
7620
|
+
`export default __weappViteComponentOptions;`
|
|
7621
|
+
] : [forwardsDefault ? `export { default } from ${source};` : `import ${source};`];
|
|
7606
7622
|
const seen = /* @__PURE__ */ new Set();
|
|
7607
7623
|
for (const dependency of dependencies) {
|
|
7608
7624
|
const dependencyId = createSidecarModuleId(entry.sourceId, dependency.sourceId, dependency.kind);
|
|
@@ -7632,8 +7648,10 @@ async function transformVueSource(code, id) {
|
|
|
7632
7648
|
const { descriptor, errors } = parse(code, { filename: id });
|
|
7633
7649
|
if (errors.length) throw errors[0];
|
|
7634
7650
|
const blocks = [descriptor.script, descriptor.scriptSetup].filter((block) => block?.content);
|
|
7635
|
-
|
|
7636
|
-
|
|
7651
|
+
const source = blocks.map((block) => block.content).join("\n") || "export default {}";
|
|
7652
|
+
const lang = blocks.some((block) => block?.lang === "tsx") ? "tsx" : blocks.some((block) => block?.lang === "ts") ? "ts" : "js";
|
|
7653
|
+
return await transformWithOxc(source, id, {
|
|
7654
|
+
lang,
|
|
7637
7655
|
sourcemap: false,
|
|
7638
7656
|
target: "esnext"
|
|
7639
7657
|
});
|
|
@@ -8207,9 +8225,7 @@ function ensureModuleResolution(ts, compilerOptions) {
|
|
|
8207
8225
|
case ts.ModuleKind.NodeNext:
|
|
8208
8226
|
moduleResolution = ts.ModuleResolutionKind.NodeNext;
|
|
8209
8227
|
break;
|
|
8210
|
-
default:
|
|
8211
|
-
moduleResolution = ts.version.startsWith("5") ? ts.ModuleResolutionKind.Bundler : ts.ModuleResolutionKind.Classic;
|
|
8212
|
-
break;
|
|
8228
|
+
default: moduleResolution = ts.version.startsWith("5") ? ts.ModuleResolutionKind.Bundler : ts.ModuleResolutionKind.Classic;
|
|
8213
8229
|
}
|
|
8214
8230
|
compilerOptions.moduleResolution = moduleResolution;
|
|
8215
8231
|
}
|
|
@@ -8590,13 +8606,13 @@ function getWeappViteConfig() {
|
|
|
8590
8606
|
platform: DEFAULT_MP_PLATFORM,
|
|
8591
8607
|
multiPlatform: false,
|
|
8592
8608
|
es5: false,
|
|
8593
|
-
packageSizeWarningBytes:
|
|
8609
|
+
packageSizeWarningBytes: 2097152,
|
|
8594
8610
|
analyze: {
|
|
8595
8611
|
budgets: {
|
|
8596
|
-
totalBytes:
|
|
8597
|
-
mainBytes:
|
|
8598
|
-
subPackageBytes:
|
|
8599
|
-
independentBytes:
|
|
8612
|
+
totalBytes: 20971520,
|
|
8613
|
+
mainBytes: 2097152,
|
|
8614
|
+
subPackageBytes: 2097152,
|
|
8615
|
+
independentBytes: 2097152,
|
|
8600
8616
|
warningRatio: .85
|
|
8601
8617
|
},
|
|
8602
8618
|
history: {
|
|
@@ -8649,7 +8665,7 @@ function getWeappViteConfig() {
|
|
|
8649
8665
|
dynamicImports: "preserve",
|
|
8650
8666
|
logOptimization: true,
|
|
8651
8667
|
forceDuplicatePatterns: [],
|
|
8652
|
-
duplicateWarningBytes:
|
|
8668
|
+
duplicateWarningBytes: 524288
|
|
8653
8669
|
}
|
|
8654
8670
|
};
|
|
8655
8671
|
}
|
|
@@ -10047,7 +10063,8 @@ function resolveTakeSharedChunkName(options) {
|
|
|
10047
10063
|
function createSharedChunkNameFromKeys(keys) {
|
|
10048
10064
|
const sanitize = (value) => value.replace(/[\\/]+/g, "_");
|
|
10049
10065
|
const combination = keys.filter(Boolean).map(sanitize).sort().join("+");
|
|
10050
|
-
|
|
10066
|
+
const combinationSegment = combination ? `${combination}/` : "";
|
|
10067
|
+
return `${SHARED_CHUNK_VIRTUAL_PREFIX}/${combinationSegment}common`;
|
|
10051
10068
|
}
|
|
10052
10069
|
function resolveSharedChunkName(options) {
|
|
10053
10070
|
const { id, ctx, relativeAbsoluteSrcRoot, subPackageRoots, strategy, sharedMode, resolveSharedMode, resolveSharedPath, forceDuplicateTester } = options;
|
|
@@ -10194,6 +10211,103 @@ function createAdvancedChunkNameResolver(options) {
|
|
|
10194
10211
|
};
|
|
10195
10212
|
}
|
|
10196
10213
|
//#endregion
|
|
10214
|
+
//#region src/runtime/wevuModules.ts
|
|
10215
|
+
const WEVU_RUNTIME_MODULE_IDS = [
|
|
10216
|
+
"wevu",
|
|
10217
|
+
"wevu/router",
|
|
10218
|
+
"wevu/store",
|
|
10219
|
+
"wevu/api",
|
|
10220
|
+
"wevu/fetch",
|
|
10221
|
+
"wevu/web-apis",
|
|
10222
|
+
"wevu/internal-runtime",
|
|
10223
|
+
"wevu/internal-reactivity",
|
|
10224
|
+
"wevu/internal-template"
|
|
10225
|
+
];
|
|
10226
|
+
const WEVU_ENTRY_MODULE_IDS = {
|
|
10227
|
+
"api": "wevu/api",
|
|
10228
|
+
"fetch": "wevu/fetch",
|
|
10229
|
+
"index": "wevu",
|
|
10230
|
+
"internal-reactivity": "wevu/internal-reactivity",
|
|
10231
|
+
"internal-runtime": "wevu/internal-runtime",
|
|
10232
|
+
"internal-template": "wevu/internal-template",
|
|
10233
|
+
"router": "wevu/router",
|
|
10234
|
+
"store": "wevu/store",
|
|
10235
|
+
"web-apis": "wevu/web-apis"
|
|
10236
|
+
};
|
|
10237
|
+
const WEVU_STABLE_VENDOR_FILE_RE = /^weapp-vendors\/wevu-[^/]+\.js$/;
|
|
10238
|
+
const HASHED_MODULE_BASENAME_RE = /-[\w-]{8}$/;
|
|
10239
|
+
const WEVU_RUNTIME_MODULE_ID_BY_FAMILY = {
|
|
10240
|
+
"api": "wevu/api",
|
|
10241
|
+
"fetch": "wevu/fetch",
|
|
10242
|
+
"reactivity": "wevu/internal-reactivity",
|
|
10243
|
+
"router": "wevu/router",
|
|
10244
|
+
"runtime": "wevu/internal-runtime",
|
|
10245
|
+
"store": "wevu/store",
|
|
10246
|
+
"template": "wevu/internal-template",
|
|
10247
|
+
"web-apis": "wevu/web-apis"
|
|
10248
|
+
};
|
|
10249
|
+
function isWevuEntryModulePath(value) {
|
|
10250
|
+
return Object.prototype.hasOwnProperty.call(WEVU_ENTRY_MODULE_IDS, value);
|
|
10251
|
+
}
|
|
10252
|
+
function normalizeModuleId(id) {
|
|
10253
|
+
return normalizeViteId(id, {
|
|
10254
|
+
stripQuery: true,
|
|
10255
|
+
fileProtocolToPath: true,
|
|
10256
|
+
stripAtFsPrefix: true,
|
|
10257
|
+
stripLeadingNullByte: true
|
|
10258
|
+
}).replaceAll("\\", "/");
|
|
10259
|
+
}
|
|
10260
|
+
function resolveWevuPreservedModulePath(id) {
|
|
10261
|
+
const normalized = normalizeModuleId(id);
|
|
10262
|
+
const sourceMarker = "/packages-runtime/wevu/src/";
|
|
10263
|
+
const distMarker = "/wevu/dist/";
|
|
10264
|
+
const sourceIndex = normalized.lastIndexOf(sourceMarker);
|
|
10265
|
+
if (sourceIndex >= 0) return normalized.slice(sourceIndex + 27).replace(/\.[cm]?[jt]s$/, "");
|
|
10266
|
+
const distIndex = normalized.lastIndexOf(distMarker);
|
|
10267
|
+
if (distIndex < 0) return;
|
|
10268
|
+
const modulePath = normalized.slice(distIndex + 11).replace(/^dev\//, "").replace(/\.[cm]?[jt]s$/, "");
|
|
10269
|
+
if (!isWevuEntryModulePath(modulePath) && HASHED_MODULE_BASENAME_RE.test(modulePath)) return;
|
|
10270
|
+
return modulePath;
|
|
10271
|
+
}
|
|
10272
|
+
function resolveWevuRuntimeModuleId(id) {
|
|
10273
|
+
if (WEVU_RUNTIME_MODULE_IDS.includes(id)) return id;
|
|
10274
|
+
const modulePath = resolveWevuPreservedModulePath(id);
|
|
10275
|
+
if (!modulePath || modulePath.includes("/")) return;
|
|
10276
|
+
return WEVU_ENTRY_MODULE_IDS[modulePath];
|
|
10277
|
+
}
|
|
10278
|
+
function resolveWevuRuntimeModuleFamily(id) {
|
|
10279
|
+
const bareModuleId = resolveWevuRuntimeModuleId(id);
|
|
10280
|
+
if (bareModuleId) {
|
|
10281
|
+
if (bareModuleId === "wevu/internal-reactivity") return "reactivity";
|
|
10282
|
+
if (bareModuleId === "wevu/internal-template") return "template";
|
|
10283
|
+
if (bareModuleId === "wevu/internal-runtime" || bareModuleId === "wevu") return "runtime";
|
|
10284
|
+
return bareModuleId.slice(5);
|
|
10285
|
+
}
|
|
10286
|
+
const modulePath = resolveWevuPreservedModulePath(id);
|
|
10287
|
+
if (!modulePath) return;
|
|
10288
|
+
if (modulePath.startsWith("reactivity/") || modulePath === "scheduler") return "reactivity";
|
|
10289
|
+
if (modulePath === "runtime/template") return "template";
|
|
10290
|
+
if (modulePath.startsWith("router/") || modulePath.startsWith("routerInternal/")) return "router";
|
|
10291
|
+
if (modulePath.startsWith("store/")) return "store";
|
|
10292
|
+
if (modulePath.startsWith("compiler/")) return "compiler";
|
|
10293
|
+
if (modulePath === "jsx-runtime" || modulePath === "vue-demi") return modulePath;
|
|
10294
|
+
if (modulePath === "api" || modulePath === "fetch" || modulePath === "web-apis") return modulePath;
|
|
10295
|
+
return "runtime";
|
|
10296
|
+
}
|
|
10297
|
+
function resolveWevuStableVendorFileName(id) {
|
|
10298
|
+
const family = resolveWevuRuntimeModuleFamily(id);
|
|
10299
|
+
return family ? `weapp-vendors/wevu-${family}.js` : void 0;
|
|
10300
|
+
}
|
|
10301
|
+
function isWevuStableVendorFileName(fileName) {
|
|
10302
|
+
return WEVU_STABLE_VENDOR_FILE_RE.test(fileName.replaceAll("\\", "/"));
|
|
10303
|
+
}
|
|
10304
|
+
function resolveWevuRuntimeModuleIdFromStableVendorFileName(fileName) {
|
|
10305
|
+
const normalized = fileName.replaceAll("\\", "/");
|
|
10306
|
+
if (!isWevuStableVendorFileName(normalized)) return;
|
|
10307
|
+
const family = normalized.slice(19, -3);
|
|
10308
|
+
return WEVU_RUNTIME_MODULE_ID_BY_FAMILY[family];
|
|
10309
|
+
}
|
|
10310
|
+
//#endregion
|
|
10197
10311
|
//#region src/runtime/sharedBuildConfig.ts
|
|
10198
10312
|
const REG_NODE_MODULES_DIR = /[\\/]node_modules[\\/]/gi;
|
|
10199
10313
|
const REG_COMMONJS_HELPERS = /commonjsHelpers\.js$/;
|
|
@@ -10331,6 +10445,10 @@ function resolveStableHashedDistChunkFileName(chunk) {
|
|
|
10331
10445
|
const candidateIds = [chunk.facadeModuleId, ...chunk.moduleIds ?? []].filter((id) => typeof id === "string");
|
|
10332
10446
|
const matchedChunks = [];
|
|
10333
10447
|
let facadeMatchedChunk;
|
|
10448
|
+
for (const id of candidateIds) {
|
|
10449
|
+
const fileName = resolveWevuStableVendorFileName(id);
|
|
10450
|
+
if (fileName) return fileName;
|
|
10451
|
+
}
|
|
10334
10452
|
for (const id of candidateIds) {
|
|
10335
10453
|
if (isWeappViteRuntimeModuleId(id)) return "weapp-vendors/weapp-vite-runtime.js";
|
|
10336
10454
|
const cleanedAbsoluteId = normalizeSharedPathCandidate(id);
|
|
@@ -10403,7 +10521,7 @@ function createSharedBuildResolver(configService, getSubPackageRoots) {
|
|
|
10403
10521
|
};
|
|
10404
10522
|
return { resolveAdvancedChunkName: resolveSharedBuildChunkName };
|
|
10405
10523
|
}
|
|
10406
|
-
function createSharedBuildOutput(configService, getSubPackageRoots) {
|
|
10524
|
+
function createSharedBuildOutput(configService, getSubPackageRoots, options = {}) {
|
|
10407
10525
|
const { resolveAdvancedChunkName } = createSharedBuildResolver(configService, getSubPackageRoots);
|
|
10408
10526
|
return {
|
|
10409
10527
|
codeSplitting: { groups: [...configService.isDev ? [{
|
|
@@ -10416,8 +10534,12 @@ function createSharedBuildOutput(configService, getSubPackageRoots) {
|
|
|
10416
10534
|
minifyInternalExports: false,
|
|
10417
10535
|
chunkFileNames: (chunk) => {
|
|
10418
10536
|
if (isRequestGlobalsRuntimeChunk(chunk)) return REQUEST_GLOBAL_RUNTIME_CHUNK_FILE_BASENAME;
|
|
10419
|
-
|
|
10420
|
-
|
|
10537
|
+
if (options.runtime !== "web") {
|
|
10538
|
+
const namedStableVendorFileName = `${chunk.name}.js`;
|
|
10539
|
+
if (isWevuStableVendorFileName(namedStableVendorFileName)) return namedStableVendorFileName;
|
|
10540
|
+
const stableHashedDistChunkFileName = resolveStableHashedDistChunkFileName(chunk);
|
|
10541
|
+
if (stableHashedDistChunkFileName) return stableHashedDistChunkFileName;
|
|
10542
|
+
}
|
|
10421
10543
|
return "[name].js";
|
|
10422
10544
|
}
|
|
10423
10545
|
};
|
|
@@ -10553,6 +10675,8 @@ const bridgeKey = ${JSON.stringify(WEAPP_VITE_STATEFUL_HMR_BRIDGE_KEY)};
|
|
|
10553
10675
|
const definitions = new Map();
|
|
10554
10676
|
const registered = new Set();
|
|
10555
10677
|
const instances = new Map();
|
|
10678
|
+
const instanceSnapshots = new WeakMap();
|
|
10679
|
+
const moduleSnapshots = new Map();
|
|
10556
10680
|
const pendingNativeDefinitions = new Map();
|
|
10557
10681
|
const wevuRefreshes = new Map();
|
|
10558
10682
|
const wevuRefreshGenerations = new Map();
|
|
@@ -10564,6 +10688,74 @@ function getInstances(moduleId) {
|
|
|
10564
10688
|
if (!values) instances.set(moduleId, values = new Set());
|
|
10565
10689
|
return values;
|
|
10566
10690
|
}
|
|
10691
|
+
function cloneInstanceData(value) {
|
|
10692
|
+
if (Array.isArray(value)) return value.map(cloneInstanceData);
|
|
10693
|
+
if (!value || typeof value !== 'object') return value;
|
|
10694
|
+
const result = {};
|
|
10695
|
+
for (const [key, child] of Object.entries(value)) result[key] = cloneInstanceData(child);
|
|
10696
|
+
return result;
|
|
10697
|
+
}
|
|
10698
|
+
function countChangedDataKeys(data, initialData) {
|
|
10699
|
+
let changed = 0;
|
|
10700
|
+
for (const [key, value] of Object.entries(data)) {
|
|
10701
|
+
if (!Object.prototype.hasOwnProperty.call(initialData, key)) {
|
|
10702
|
+
changed++;
|
|
10703
|
+
continue;
|
|
10704
|
+
}
|
|
10705
|
+
try {
|
|
10706
|
+
if (JSON.stringify(value) !== JSON.stringify(initialData[key])) changed++;
|
|
10707
|
+
} catch {
|
|
10708
|
+
if (value !== initialData[key]) changed++;
|
|
10709
|
+
}
|
|
10710
|
+
}
|
|
10711
|
+
return changed;
|
|
10712
|
+
}
|
|
10713
|
+
function rememberInstanceState(instance, moduleId) {
|
|
10714
|
+
if (!instance?.data || typeof instance.data !== 'object') return;
|
|
10715
|
+
const data = cloneInstanceData(instance.data);
|
|
10716
|
+
const definitionData = definitions.get(moduleId)?.data;
|
|
10717
|
+
const initialData = definitionData && typeof definitionData === 'object' ? definitionData : {};
|
|
10718
|
+
const changedKeys = countChangedDataKeys(data, initialData);
|
|
10719
|
+
const previous = instanceSnapshots.get(instance) || moduleSnapshots.get(moduleId);
|
|
10720
|
+
if (!previous || changedKeys >= previous.changedKeys) {
|
|
10721
|
+
const snapshot = { changedKeys, data, moduleId };
|
|
10722
|
+
instanceSnapshots.set(instance, snapshot);
|
|
10723
|
+
moduleSnapshots.set(moduleId, snapshot);
|
|
10724
|
+
}
|
|
10725
|
+
}
|
|
10726
|
+
function trackInstance(instance, moduleId) {
|
|
10727
|
+
getInstances(moduleId).add(instance);
|
|
10728
|
+
if (instanceSnapshots.has(instance)) return;
|
|
10729
|
+
const snapshot = moduleSnapshots.get(moduleId);
|
|
10730
|
+
if (snapshot) {
|
|
10731
|
+
instanceSnapshots.set(instance, snapshot);
|
|
10732
|
+
restoreInstanceState(instance, moduleId);
|
|
10733
|
+
} else {
|
|
10734
|
+
rememberInstanceState(instance, moduleId);
|
|
10735
|
+
}
|
|
10736
|
+
}
|
|
10737
|
+
function forgetInstance(instance, moduleId) {
|
|
10738
|
+
getInstances(moduleId).delete(instance);
|
|
10739
|
+
instanceSnapshots.delete(instance);
|
|
10740
|
+
if (!suppressLifecycles) moduleSnapshots.delete(moduleId);
|
|
10741
|
+
}
|
|
10742
|
+
function restoreInstanceState(instance, moduleId) {
|
|
10743
|
+
const snapshot = instanceSnapshots.get(instance);
|
|
10744
|
+
if (!snapshot || snapshot.moduleId !== moduleId) return;
|
|
10745
|
+
const data = cloneInstanceData(snapshot.data);
|
|
10746
|
+
if (instance.data && typeof instance.data === 'object') Object.assign(instance.data, data);
|
|
10747
|
+
if (typeof instance.setData === 'function') instance.setData(data);
|
|
10748
|
+
}
|
|
10749
|
+
function rememberTrackedInstances() {
|
|
10750
|
+
for (const [moduleId, values] of instances) {
|
|
10751
|
+
for (const instance of values) rememberInstanceState(instance, moduleId);
|
|
10752
|
+
}
|
|
10753
|
+
}
|
|
10754
|
+
function restoreTrackedInstances() {
|
|
10755
|
+
for (const [moduleId, values] of instances) {
|
|
10756
|
+
for (const instance of values) restoreInstanceState(instance, moduleId);
|
|
10757
|
+
}
|
|
10758
|
+
}
|
|
10567
10759
|
function refreshWevuInstance(instance, moduleId) {
|
|
10568
10760
|
if (!instance || (typeof instance !== 'object' && typeof instance !== 'function')) return;
|
|
10569
10761
|
const generation = wevuRefreshGenerations.get(moduleId) || 0;
|
|
@@ -10572,7 +10764,10 @@ function refreshWevuInstance(instance, moduleId) {
|
|
|
10572
10764
|
if (generations?.get(moduleId) === generation) return;
|
|
10573
10765
|
const refresh = wevuRefreshes.get(moduleId);
|
|
10574
10766
|
if (typeof refresh !== 'function') return;
|
|
10575
|
-
|
|
10767
|
+
restoreInstanceState(instance, moduleId);
|
|
10768
|
+
const snapshot = instanceSnapshots.get(instance) || moduleSnapshots.get(moduleId);
|
|
10769
|
+
refresh(instance, cloneInstanceData(snapshot?.data));
|
|
10770
|
+
rememberInstanceState(instance, moduleId);
|
|
10576
10771
|
if (!generations) wevuInstanceGenerations.set(instance, generations = new Map());
|
|
10577
10772
|
generations.set(moduleId, generation);
|
|
10578
10773
|
}
|
|
@@ -10583,10 +10778,15 @@ function proxyFunction(moduleId, path, fallback) {
|
|
|
10583
10778
|
const segments = path.split('.');
|
|
10584
10779
|
let value = definition;
|
|
10585
10780
|
for (const segment of segments) value = value && value[segment];
|
|
10586
|
-
|
|
10781
|
+
trackInstance(this, moduleId);
|
|
10782
|
+
try {
|
|
10783
|
+
return (typeof value === 'function' ? value : fallback)?.apply(this, args);
|
|
10784
|
+
} finally {
|
|
10785
|
+
rememberInstanceState(this, moduleId);
|
|
10786
|
+
}
|
|
10587
10787
|
};
|
|
10588
10788
|
}
|
|
10589
|
-
function decorateObject(value, moduleId, prefix = '') {
|
|
10789
|
+
function decorateObject(value, moduleId, prefix = '', trackLifecycle = false) {
|
|
10590
10790
|
if (!value || typeof value !== 'object' || Array.isArray(value)) return value;
|
|
10591
10791
|
const result = { ...value };
|
|
10592
10792
|
for (const [key, child] of Object.entries(value)) {
|
|
@@ -10599,24 +10799,28 @@ function decorateObject(value, moduleId, prefix = '') {
|
|
|
10599
10799
|
if (!prefix && typeof value.onLoad === 'function') {
|
|
10600
10800
|
const onLoad = result.onLoad;
|
|
10601
10801
|
result.onLoad = function (...args) {
|
|
10602
|
-
|
|
10802
|
+
trackInstance(this, moduleId);
|
|
10603
10803
|
return onLoad.apply(this, args);
|
|
10604
10804
|
};
|
|
10605
10805
|
}
|
|
10606
|
-
if (!prefix && result.lifetimes && typeof result.lifetimes === 'object') {
|
|
10607
|
-
const
|
|
10608
|
-
const
|
|
10609
|
-
|
|
10610
|
-
|
|
10806
|
+
if (!prefix && (trackLifecycle || (result.lifetimes && typeof result.lifetimes === 'object'))) {
|
|
10807
|
+
const lifetimes = { ...(result.lifetimes || {}) };
|
|
10808
|
+
const attached = lifetimes.attached;
|
|
10809
|
+
const detached = lifetimes.detached;
|
|
10810
|
+
result.lifetimes = lifetimes;
|
|
10811
|
+
if (trackLifecycle || typeof attached === 'function') {
|
|
10611
10812
|
result.lifetimes.attached = function (...args) {
|
|
10612
|
-
|
|
10613
|
-
return attached
|
|
10813
|
+
trackInstance(this, moduleId);
|
|
10814
|
+
return attached?.apply(this, args);
|
|
10614
10815
|
};
|
|
10615
10816
|
}
|
|
10616
|
-
if (typeof detached === 'function') {
|
|
10817
|
+
if (trackLifecycle || typeof detached === 'function') {
|
|
10617
10818
|
result.lifetimes.detached = function (...args) {
|
|
10618
|
-
|
|
10619
|
-
|
|
10819
|
+
try {
|
|
10820
|
+
return detached?.apply(this, args);
|
|
10821
|
+
} finally {
|
|
10822
|
+
forgetInstance(this, moduleId);
|
|
10823
|
+
}
|
|
10620
10824
|
};
|
|
10621
10825
|
}
|
|
10622
10826
|
}
|
|
@@ -10628,9 +10832,13 @@ function decorateWevuComponent(definition, moduleId) {
|
|
|
10628
10832
|
for (const [name, method] of Object.entries(methods)) {
|
|
10629
10833
|
if (typeof method !== 'function') continue;
|
|
10630
10834
|
methods[name] = function (...args) {
|
|
10631
|
-
|
|
10835
|
+
trackInstance(this, moduleId);
|
|
10632
10836
|
refreshWevuInstance(this, moduleId);
|
|
10633
|
-
|
|
10837
|
+
try {
|
|
10838
|
+
return method.apply(this, args);
|
|
10839
|
+
} finally {
|
|
10840
|
+
rememberInstanceState(this, moduleId);
|
|
10841
|
+
}
|
|
10634
10842
|
};
|
|
10635
10843
|
}
|
|
10636
10844
|
result.methods = methods;
|
|
@@ -10638,26 +10846,38 @@ function decorateWevuComponent(definition, moduleId) {
|
|
|
10638
10846
|
const onUnload = definition.onUnload;
|
|
10639
10847
|
if (typeof onLoad === 'function') {
|
|
10640
10848
|
result.onLoad = function (...args) {
|
|
10641
|
-
|
|
10849
|
+
trackInstance(this, moduleId);
|
|
10850
|
+
refreshWevuInstance(this, moduleId);
|
|
10851
|
+
if (suppressLifecycles) return;
|
|
10642
10852
|
return onLoad.apply(this, args);
|
|
10643
10853
|
};
|
|
10644
10854
|
}
|
|
10645
10855
|
if (typeof onUnload === 'function') {
|
|
10646
10856
|
result.onUnload = function (...args) {
|
|
10647
|
-
|
|
10648
|
-
|
|
10857
|
+
if (suppressLifecycles) return;
|
|
10858
|
+
try {
|
|
10859
|
+
return onUnload.apply(this, args);
|
|
10860
|
+
} finally {
|
|
10861
|
+
forgetInstance(this, moduleId);
|
|
10862
|
+
}
|
|
10649
10863
|
};
|
|
10650
10864
|
}
|
|
10651
10865
|
const lifetimes = { ...(definition.lifetimes || {}) };
|
|
10652
10866
|
const attached = lifetimes.attached;
|
|
10653
10867
|
const detached = lifetimes.detached;
|
|
10654
10868
|
lifetimes.attached = function (...args) {
|
|
10655
|
-
|
|
10869
|
+
trackInstance(this, moduleId);
|
|
10870
|
+
refreshWevuInstance(this, moduleId);
|
|
10871
|
+
if (suppressLifecycles) return;
|
|
10656
10872
|
return attached?.apply(this, args);
|
|
10657
10873
|
};
|
|
10658
10874
|
lifetimes.detached = function (...args) {
|
|
10659
|
-
|
|
10660
|
-
|
|
10875
|
+
if (suppressLifecycles) return;
|
|
10876
|
+
try {
|
|
10877
|
+
return detached?.apply(this, args);
|
|
10878
|
+
} finally {
|
|
10879
|
+
forgetInstance(this, moduleId);
|
|
10880
|
+
}
|
|
10661
10881
|
};
|
|
10662
10882
|
return { ...result, lifetimes };
|
|
10663
10883
|
}
|
|
@@ -10671,7 +10891,7 @@ function registerDefinition(name, definition, nativeRegistration) {
|
|
|
10671
10891
|
if (name === 'Component') {
|
|
10672
10892
|
let pending = pendingNativeDefinitions.get(name);
|
|
10673
10893
|
if (!pending) pendingNativeDefinitions.set(name, pending = []);
|
|
10674
|
-
pending.push(decorateObject(definition, moduleId));
|
|
10894
|
+
pending.push(decorateObject(definition, moduleId, '', true));
|
|
10675
10895
|
registered.add(moduleId);
|
|
10676
10896
|
return;
|
|
10677
10897
|
}
|
|
@@ -10695,15 +10915,14 @@ globalThis[bridgeKey] = {
|
|
|
10695
10915
|
isApplying() { return runtime.applyingPatch; },
|
|
10696
10916
|
trackWevuComponent(definition, refresh) {
|
|
10697
10917
|
const moduleId = runtime.registrationModuleId || runtime.currentModuleId || 'Component';
|
|
10698
|
-
if (!runtime.applyingPatch && runtime.patchedModules.has(moduleId))
|
|
10918
|
+
if (!runtime.applyingPatch && runtime.patchedModules.has(moduleId)) {
|
|
10919
|
+
return decorateWevuComponent(definition, moduleId);
|
|
10920
|
+
}
|
|
10699
10921
|
definitions.set(moduleId, definition);
|
|
10700
10922
|
if (typeof refresh === 'function') wevuRefreshes.set(moduleId, refresh);
|
|
10701
10923
|
if (runtime.applyingPatch) {
|
|
10702
10924
|
wevuRefreshGenerations.set(moduleId, (wevuRefreshGenerations.get(moduleId) || 0) + 1);
|
|
10703
|
-
const
|
|
10704
|
-
if (typeof currentRefresh === 'function') {
|
|
10705
|
-
for (const instance of [...getInstances(moduleId)]) currentRefresh(instance);
|
|
10706
|
-
}
|
|
10925
|
+
for (const instance of [...getInstances(moduleId)]) refreshWevuInstance(instance, moduleId);
|
|
10707
10926
|
return definition;
|
|
10708
10927
|
}
|
|
10709
10928
|
return decorateWevuComponent(definition, moduleId);
|
|
@@ -10711,10 +10930,12 @@ globalThis[bridgeKey] = {
|
|
|
10711
10930
|
ready: true,
|
|
10712
10931
|
beginUpdate() {
|
|
10713
10932
|
suppressLifecycles = true;
|
|
10933
|
+
rememberTrackedInstances();
|
|
10714
10934
|
runtime.beginPatch();
|
|
10715
10935
|
},
|
|
10716
10936
|
endUpdate() {
|
|
10717
10937
|
runtime.endPatch();
|
|
10938
|
+
restoreTrackedInstances();
|
|
10718
10939
|
setTimeout(() => { suppressLifecycles = false; });
|
|
10719
10940
|
}
|
|
10720
10941
|
};
|
|
@@ -11124,7 +11345,7 @@ async function readBody(request) {
|
|
|
11124
11345
|
for await (const chunk of request) {
|
|
11125
11346
|
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
11126
11347
|
size += buffer.length;
|
|
11127
|
-
if (size >
|
|
11348
|
+
if (size > 65536) throw new Error("stateful HMR request body is too large");
|
|
11128
11349
|
chunks.push(buffer);
|
|
11129
11350
|
}
|
|
11130
11351
|
return Buffer.concat(chunks).toString("utf8");
|
|
@@ -11279,7 +11500,7 @@ function toStableModuleId(id, root) {
|
|
|
11279
11500
|
//#endregion
|
|
11280
11501
|
//#region src/runtime/statefulHmr/session.ts
|
|
11281
11502
|
const maxRetainedDeltaCount = 1e3;
|
|
11282
|
-
const maxRetainedDeltaBytes =
|
|
11503
|
+
const maxRetainedDeltaBytes = 16777216;
|
|
11283
11504
|
async function runStatefulHmrDev(ctx, buildOptions, restart) {
|
|
11284
11505
|
const configService = ctx.configService;
|
|
11285
11506
|
if (configService.platform !== "weapp") throw new Error("weapp.hmr.runtime=\"stateful-experimental\" 目前仅支持微信小程序平台。");
|
|
@@ -11980,12 +12201,37 @@ const TEMPLATE_COMPONENT_TAG_HINT_RE = /<\s*(?:[A-Z_$]|[a-z][\w$]*-)/;
|
|
|
11980
12201
|
function hasTemplateComponentTagHint(source) {
|
|
11981
12202
|
return TEMPLATE_COMPONENT_TAG_HINT_RE.test(source);
|
|
11982
12203
|
}
|
|
11983
|
-
function
|
|
11984
|
-
return
|
|
12204
|
+
function kebabToCamel(name) {
|
|
12205
|
+
return name.replace(/-([a-z0-9])/g, (_, character) => character.toUpperCase());
|
|
12206
|
+
}
|
|
12207
|
+
function capitalize(name) {
|
|
12208
|
+
return name ? `${name.charAt(0).toUpperCase()}${name.slice(1)}` : name;
|
|
12209
|
+
}
|
|
12210
|
+
function collectVueTemplateComponentTagInfo(template, filename) {
|
|
12211
|
+
const templateTags = collectVueTemplateTags(template, {
|
|
11985
12212
|
filename,
|
|
11986
12213
|
warnLabel: "自动 usingComponents",
|
|
11987
|
-
shouldCollect: (tag) => VUE_COMPONENT_TAG_RE.test(tag)
|
|
12214
|
+
shouldCollect: (tag) => VUE_COMPONENT_TAG_RE.test(tag) || isAutoImportCandidateTag(tag)
|
|
11988
12215
|
});
|
|
12216
|
+
const componentNames = /* @__PURE__ */ new Set();
|
|
12217
|
+
const tagsByComponentName = /* @__PURE__ */ new Map();
|
|
12218
|
+
for (const tag of templateTags) {
|
|
12219
|
+
const camelName = kebabToCamel(tag);
|
|
12220
|
+
for (const componentName of [
|
|
12221
|
+
tag,
|
|
12222
|
+
camelName,
|
|
12223
|
+
capitalize(camelName)
|
|
12224
|
+
]) {
|
|
12225
|
+
componentNames.add(componentName);
|
|
12226
|
+
const matchedTags = tagsByComponentName.get(componentName) ?? /* @__PURE__ */ new Set();
|
|
12227
|
+
matchedTags.add(tag);
|
|
12228
|
+
tagsByComponentName.set(componentName, matchedTags);
|
|
12229
|
+
}
|
|
12230
|
+
}
|
|
12231
|
+
return {
|
|
12232
|
+
componentNames,
|
|
12233
|
+
tagsByComponentName
|
|
12234
|
+
};
|
|
11989
12235
|
}
|
|
11990
12236
|
function collectVueTemplateAutoImportTags(template, filename) {
|
|
11991
12237
|
return collectVueTemplateTags(template, {
|
|
@@ -12016,7 +12262,8 @@ async function applyScriptSetupUsingComponents(options) {
|
|
|
12016
12262
|
}
|
|
12017
12263
|
}
|
|
12018
12264
|
if (!errors?.length && descriptor?.scriptSetup && descriptor?.template) {
|
|
12019
|
-
const
|
|
12265
|
+
const templateComponentTagInfo = collectVueTemplateComponentTagInfo(descriptor.template.content, vueEntryPath);
|
|
12266
|
+
const templateComponentNames = templateComponentTagInfo.componentNames;
|
|
12020
12267
|
if (templateComponentNames.size) {
|
|
12021
12268
|
const astEngine = resolveAstEngine(configService.weappViteConfig);
|
|
12022
12269
|
const imports = collectScriptSetupImports(descriptor.scriptSetup.content, templateComponentNames, { astEngine });
|
|
@@ -12033,15 +12280,18 @@ async function applyScriptSetupUsingComponents(options) {
|
|
|
12033
12280
|
localName,
|
|
12034
12281
|
importSource,
|
|
12035
12282
|
resolvedId,
|
|
12036
|
-
from: resolvedFrom
|
|
12283
|
+
from: resolvedFrom,
|
|
12284
|
+
templateTags: [...templateComponentTagInfo.tagsByComponentName.get(localName) ?? [localName]]
|
|
12037
12285
|
};
|
|
12038
12286
|
}));
|
|
12039
|
-
for (const {
|
|
12287
|
+
for (const { importSource, resolvedId, from: resolvedFrom, templateTags } of resolvedImports) {
|
|
12040
12288
|
let from = resolvedFrom;
|
|
12041
12289
|
if (!from && importSource.startsWith("/")) from = removeExtensionDeep(importSource);
|
|
12042
12290
|
if (!from) continue;
|
|
12043
|
-
|
|
12044
|
-
|
|
12291
|
+
for (const tag of templateTags) {
|
|
12292
|
+
if (Reflect.has(usingComponents, tag) && usingComponents[tag] !== from) logger_default.warn(`[自动 usingComponents] 冲突:${vueEntryPath} 中 usingComponents['${tag}']='${usingComponents[tag]}' 将被 <script setup> 导入覆盖为 '${from}'`);
|
|
12293
|
+
usingComponents[tag] = from;
|
|
12294
|
+
}
|
|
12045
12295
|
if (resolvedId) externalComponentEntryMap?.set(removeExtensionDeep(from).replace(/^\/+/, ""), resolvedId);
|
|
12046
12296
|
}
|
|
12047
12297
|
json.usingComponents = usingComponents;
|
|
@@ -12892,7 +13142,8 @@ function getManagedTypeScriptConfig(ctx) {
|
|
|
12892
13142
|
}
|
|
12893
13143
|
async function readLegacyManagedTsconfigFile(filePath) {
|
|
12894
13144
|
try {
|
|
12895
|
-
const
|
|
13145
|
+
const content = await fs$1.readFile(filePath, "utf8");
|
|
13146
|
+
const parsed = parse$1(content, void 0, true);
|
|
12896
13147
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return;
|
|
12897
13148
|
return parsed;
|
|
12898
13149
|
} catch {
|
|
@@ -13070,11 +13321,18 @@ async function createManagedTsconfigFiles(ctx) {
|
|
|
13070
13321
|
const appPath = path.join(managedDir, "tsconfig.app.json");
|
|
13071
13322
|
const nodePath = path.join(managedDir, "tsconfig.node.json");
|
|
13072
13323
|
const serverPath = path.join(managedDir, "tsconfig.server.json");
|
|
13324
|
+
const sharedEmptyPath = path.join(managedDir, "tsconfig.shared.empty.d.ts");
|
|
13325
|
+
const uniAppTypesPath = path.join(managedDir, "uni-app.d.ts");
|
|
13326
|
+
const uniAppEnabled = Boolean(ctx.configService?.weappViteConfig.uniApp);
|
|
13073
13327
|
return [
|
|
13074
13328
|
{
|
|
13075
|
-
path:
|
|
13329
|
+
path: sharedEmptyPath,
|
|
13076
13330
|
content: "export {}\n"
|
|
13077
13331
|
},
|
|
13332
|
+
{
|
|
13333
|
+
path: uniAppTypesPath,
|
|
13334
|
+
content: uniAppEnabled ? "export {}\n\ndeclare global {\n const uni: typeof wx\n}\n" : "export {}\n"
|
|
13335
|
+
},
|
|
13078
13336
|
{
|
|
13079
13337
|
path: sharedPath,
|
|
13080
13338
|
content: toJson(createSharedTsconfig(ctx, legacyConfig))
|
|
@@ -14396,13 +14654,14 @@ function createBuildService(ctx) {
|
|
|
14396
14654
|
write: true
|
|
14397
14655
|
};
|
|
14398
14656
|
if (target === "app" && configService.weappViteConfig.hmr?.runtime === "stateful-experimental") {
|
|
14399
|
-
|
|
14657
|
+
const snapshotBuildOptions = {
|
|
14400
14658
|
...buildOptions,
|
|
14401
14659
|
build: {
|
|
14402
14660
|
...buildOptions.build ?? {},
|
|
14403
14661
|
watch: void 0
|
|
14404
14662
|
}
|
|
14405
|
-
}
|
|
14663
|
+
};
|
|
14664
|
+
await build(snapshotBuildOptions);
|
|
14406
14665
|
resetRuntimeStateForFreshBuild(ctx.runtimeState);
|
|
14407
14666
|
await scanService.loadAppEntry();
|
|
14408
14667
|
scanService.loadSubPackages();
|
|
@@ -14963,7 +15222,15 @@ function createOxcRuntimeSupport() {
|
|
|
14963
15222
|
//#endregion
|
|
14964
15223
|
//#region src/runtime/packageAliases.ts
|
|
14965
15224
|
const WEVU_WORKSPACE_PACKAGE_PATH = "packages-runtime/wevu";
|
|
15225
|
+
const SHARED_WORKSPACE_PACKAGE_PATH = "@weapp-core/shared";
|
|
15226
|
+
const PACKAGE_ALIAS_MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
14966
15227
|
const PACKAGE_ALIASES = [
|
|
15228
|
+
{
|
|
15229
|
+
find: "@weapp-core/shared/platforms",
|
|
15230
|
+
packageName: "@weapp-core/shared",
|
|
15231
|
+
distEntry: "dist/platforms/index.js",
|
|
15232
|
+
fallbackWorkspacePackagePath: SHARED_WORKSPACE_PACKAGE_PATH
|
|
15233
|
+
},
|
|
14967
15234
|
{
|
|
14968
15235
|
find: "class-variance-authority",
|
|
14969
15236
|
packageName: "class-variance-authority",
|
|
@@ -14988,7 +15255,6 @@ const PACKAGE_ALIASES = [
|
|
|
14988
15255
|
packageName: "wevu",
|
|
14989
15256
|
distEntry: "dist/internal-runtime.mjs",
|
|
14990
15257
|
devDistEntry: "dist/dev/internal-runtime.mjs",
|
|
14991
|
-
devWorkspaceEntry: "src/internal-runtime.ts",
|
|
14992
15258
|
fallbackWorkspacePackagePath: WEVU_WORKSPACE_PACKAGE_PATH
|
|
14993
15259
|
},
|
|
14994
15260
|
{
|
|
@@ -14996,7 +15262,6 @@ const PACKAGE_ALIASES = [
|
|
|
14996
15262
|
packageName: "wevu",
|
|
14997
15263
|
distEntry: "dist/internal-reactivity.mjs",
|
|
14998
15264
|
devDistEntry: "dist/dev/internal-reactivity.mjs",
|
|
14999
|
-
devWorkspaceEntry: "src/internal-reactivity.ts",
|
|
15000
15265
|
fallbackWorkspacePackagePath: WEVU_WORKSPACE_PACKAGE_PATH
|
|
15001
15266
|
},
|
|
15002
15267
|
{
|
|
@@ -15004,7 +15269,6 @@ const PACKAGE_ALIASES = [
|
|
|
15004
15269
|
packageName: "wevu",
|
|
15005
15270
|
distEntry: "dist/internal-template.mjs",
|
|
15006
15271
|
devDistEntry: "dist/dev/internal-template.mjs",
|
|
15007
|
-
devWorkspaceEntry: "src/internal-template.ts",
|
|
15008
15272
|
fallbackWorkspacePackagePath: WEVU_WORKSPACE_PACKAGE_PATH
|
|
15009
15273
|
},
|
|
15010
15274
|
{
|
|
@@ -15060,7 +15324,7 @@ const PACKAGE_ALIASES = [
|
|
|
15060
15324
|
function resolveWevuRuntimeDistEntries(target, options) {
|
|
15061
15325
|
if (!target.devDistEntry || target.packageName !== "wevu") return [target.distEntry];
|
|
15062
15326
|
const mode = options.wevuRuntime ?? "auto";
|
|
15063
|
-
if (mode === "dev" || mode === "auto" && options.isDev) return [target.
|
|
15327
|
+
if (mode === "dev" || mode === "auto" && options.isDev) return [target.devDistEntry];
|
|
15064
15328
|
return [target.distEntry];
|
|
15065
15329
|
}
|
|
15066
15330
|
function resolveRepoRoot(fromDir) {
|
|
@@ -15072,25 +15336,28 @@ function resolveRepoRoot(fromDir) {
|
|
|
15072
15336
|
currentDir = parentDir;
|
|
15073
15337
|
}
|
|
15074
15338
|
}
|
|
15075
|
-
function resolvePackageEntry(packageName, distEntries, fallbackWorkspacePackagePath) {
|
|
15076
|
-
const packageInfo = safeGetPackageInfoSync(packageName);
|
|
15339
|
+
function resolvePackageEntry(packageName, distEntries, fallbackWorkspacePackagePath, cwd) {
|
|
15340
|
+
const packageInfo = safeGetPackageInfoSync(packageName, cwd ? { paths: [cwd] } : void 0);
|
|
15077
15341
|
if (packageInfo) for (const distEntry of distEntries) {
|
|
15078
15342
|
const resolvedEntry = path.resolve(packageInfo.rootPath, distEntry);
|
|
15079
15343
|
if (existsSync(resolvedEntry)) return resolvedEntry;
|
|
15080
15344
|
}
|
|
15081
15345
|
if (!fallbackWorkspacePackagePath) return;
|
|
15082
|
-
const
|
|
15083
|
-
|
|
15084
|
-
|
|
15085
|
-
|
|
15086
|
-
|
|
15346
|
+
const fallbackRoots = new Set([cwd, PACKAGE_ALIAS_MODULE_DIR].filter((value) => Boolean(value)));
|
|
15347
|
+
for (const fromDir of fallbackRoots) {
|
|
15348
|
+
const repoRoot = resolveRepoRoot(fromDir);
|
|
15349
|
+
if (!repoRoot) continue;
|
|
15350
|
+
for (const distEntry of distEntries) {
|
|
15351
|
+
const fallbackEntry = path.resolve(repoRoot, fallbackWorkspacePackagePath, distEntry);
|
|
15352
|
+
if (existsSync(fallbackEntry)) return fallbackEntry;
|
|
15353
|
+
}
|
|
15087
15354
|
}
|
|
15088
15355
|
}
|
|
15089
15356
|
function resolveBuiltinPackageAliases(options = {}) {
|
|
15090
15357
|
const aliases = [];
|
|
15091
15358
|
for (const target of PACKAGE_ALIASES) {
|
|
15092
15359
|
const { find, packageName, fallbackWorkspacePackagePath } = target;
|
|
15093
|
-
const resolvedEntry = resolvePackageEntry(packageName, resolveWevuRuntimeDistEntries(target, options), fallbackWorkspacePackagePath);
|
|
15360
|
+
const resolvedEntry = resolvePackageEntry(packageName, resolveWevuRuntimeDistEntries(target, options), fallbackWorkspacePackagePath, options.cwd);
|
|
15094
15361
|
if (!resolvedEntry) continue;
|
|
15095
15362
|
aliases.push({
|
|
15096
15363
|
find,
|
|
@@ -15171,7 +15438,8 @@ function normalizeOutDir(root, config) {
|
|
|
15171
15438
|
return path.resolve(root, config.outDir);
|
|
15172
15439
|
}
|
|
15173
15440
|
function resolveWeappWebConfig(options) {
|
|
15174
|
-
const { cwd, srcRoot,
|
|
15441
|
+
const { cwd, srcRoot, enableByCli } = options;
|
|
15442
|
+
const config = options.config ?? (enableByCli ? {} : void 0);
|
|
15175
15443
|
if (!config) return;
|
|
15176
15444
|
if (!(config.enable !== false)) return;
|
|
15177
15445
|
const root = config.root ? path.resolve(cwd, config.root) : cwd;
|
|
@@ -15300,7 +15568,7 @@ var PlatformBackendRegistry = class {
|
|
|
15300
15568
|
label: "config",
|
|
15301
15569
|
raw
|
|
15302
15570
|
});
|
|
15303
|
-
const targetKey = normalized
|
|
15571
|
+
const targetKey = normalized;
|
|
15304
15572
|
if (RESERVED_COMBINED_TARGETS.has(targetKey)) return createExecution(this.backends.map((backend) => ({
|
|
15305
15573
|
descriptor: backend.descriptor,
|
|
15306
15574
|
driver: backend.driver,
|
|
@@ -15655,6 +15923,7 @@ function configureBuildAndPlugins(options) {
|
|
|
15655
15923
|
if (config.oxc !== false) {
|
|
15656
15924
|
const oxcOptions = config.oxc ?? {};
|
|
15657
15925
|
if (!Object.prototype.hasOwnProperty.call(oxcOptions, "tsconfig")) oxcOptions.tsconfig = false;
|
|
15926
|
+
if (config.esbuild !== false && config.esbuild?.jsx === "preserve" && !Object.prototype.hasOwnProperty.call(oxcOptions, "jsx")) oxcOptions.jsx = "preserve";
|
|
15658
15927
|
config.oxc = oxcOptions;
|
|
15659
15928
|
}
|
|
15660
15929
|
const rdTransform = rdOptions.transform ?? {};
|
|
@@ -15693,14 +15962,14 @@ function configureBuildAndPlugins(options) {
|
|
|
15693
15962
|
const arr = raw == null ? [] : Array.isArray(raw) ? [...raw] : [raw];
|
|
15694
15963
|
rd.plugins = arr.includes(oxcRolldownPlugin) ? arr : [oxcRolldownPlugin, ...arr];
|
|
15695
15964
|
}
|
|
15696
|
-
|
|
15965
|
+
const { normalizedCliPlatform, isWebRuntime } = resolveCliPlatformRuntime(cliPlatform);
|
|
15966
|
+
injectBuiltinAliases(config, isWebRuntime ? "build" : void 0);
|
|
15697
15967
|
if (oxcVitePlugin) {
|
|
15698
15968
|
config.plugins ??= [];
|
|
15699
15969
|
config.plugins.unshift(oxcVitePlugin);
|
|
15700
15970
|
}
|
|
15701
15971
|
const platform = config.weapp?.platform ?? DEFAULT_MP_PLATFORM;
|
|
15702
15972
|
const multiPlatform = resolveMultiPlatformConfig(config.weapp?.multiPlatform);
|
|
15703
|
-
const { normalizedCliPlatform, isWebRuntime } = resolveCliPlatformRuntime(cliPlatform);
|
|
15704
15973
|
if (multiPlatform.enabled && !isWebRuntime && !normalizedCliPlatform) throw new Error("已开启 weapp.multiPlatform,请通过 --platform 指定目标小程序平台,例如:weapp-vite dev -p weapp");
|
|
15705
15974
|
if (multiPlatform.enabled && !isWebRuntime && !supportsMultiPlatformTarget(multiPlatform, platform)) throw new Error(`当前平台 "${platform}" 不在 weapp.multiPlatform.targets 配置中,可选平台:${multiPlatform.targets.join(", ")}`);
|
|
15706
15975
|
if (multiPlatform.enabled && !isWebRuntime && projectConfigPath) {
|
|
@@ -15958,7 +16227,7 @@ async function loadConfigFileWithFallback(configEnv, configFile, cwd, configLoad
|
|
|
15958
16227
|
function createLoadConfig(options) {
|
|
15959
16228
|
const { injectBuiltinAliases, oxcRolldownPlugin, oxcVitePlugin } = options;
|
|
15960
16229
|
return async function loadConfig(opts) {
|
|
15961
|
-
const { cwd, isDev, mode, pluginOnly = false, inlineConfig, configFile, configLoader = "runner", cliPlatform, projectConfigPath } = opts;
|
|
16230
|
+
const { cwd, isDev, mode, outputRoot, pluginOnly = false, inlineConfig, configFile, configLoader = "runner", cliPlatform, projectConfigPath } = opts;
|
|
15962
16231
|
const { packageJson, packageJsonPath } = await loadPackageJson(cwd);
|
|
15963
16232
|
const resolvedConfigFile = resolveConfigFilePath(cwd, configFile);
|
|
15964
16233
|
const weappConfigFilePath = await resolveWeappConfigFile({
|
|
@@ -16069,7 +16338,8 @@ function createLoadConfig(options) {
|
|
|
16069
16338
|
const resolvedWebConfig = resolveWeappWebConfig({
|
|
16070
16339
|
cwd,
|
|
16071
16340
|
srcRoot,
|
|
16072
|
-
config: config.weapp?.web
|
|
16341
|
+
config: config.weapp?.web,
|
|
16342
|
+
enableByCli: resolveCliPlatformRuntime(cliPlatform).isWebRuntime
|
|
16073
16343
|
});
|
|
16074
16344
|
const { buildConfig, platform, multiPlatform, isWebRuntime } = configureBuildAndPlugins({
|
|
16075
16345
|
config,
|
|
@@ -16108,7 +16378,10 @@ function createLoadConfig(options) {
|
|
|
16108
16378
|
const normalizedDistRoot = normalizeRelativeDistRoot(mpDistRoot);
|
|
16109
16379
|
if (normalizedDistRoot === "dist") mpDistRoot = path.join("dist", platform, normalizedDistRoot);
|
|
16110
16380
|
}
|
|
16111
|
-
|
|
16381
|
+
if (outputRoot) {
|
|
16382
|
+
mpDistRoot = outputRoot;
|
|
16383
|
+
buildConfig.outDir = outputRoot;
|
|
16384
|
+
} else buildConfig.outDir ??= mpDistRoot;
|
|
16112
16385
|
projectConfigPathResolved = path.resolve(cwd, basePath ?? getProjectConfigFileName(platform));
|
|
16113
16386
|
projectPrivateConfigPathResolved = path.resolve(cwd, privatePath ?? getProjectPrivateConfigFileName(platform));
|
|
16114
16387
|
} else if (isLibMode) {
|
|
@@ -16401,7 +16674,7 @@ async function transformJsModuleToCjs(source, options) {
|
|
|
16401
16674
|
}
|
|
16402
16675
|
if (!transformed) return source;
|
|
16403
16676
|
if (options?.markEsModule && hasConvertedExport) ast.program.body.unshift(createEsModuleMarker());
|
|
16404
|
-
return generate(ast).code;
|
|
16677
|
+
return generate$1(ast).code;
|
|
16405
16678
|
} catch {
|
|
16406
16679
|
return source;
|
|
16407
16680
|
}
|
|
@@ -16764,8 +17037,9 @@ function createDependenciesCache(ctx) {
|
|
|
16764
17037
|
return resolveMainPackageDependencyScope(ctx);
|
|
16765
17038
|
}
|
|
16766
17039
|
function dependenciesCacheHash(root) {
|
|
17040
|
+
const configService = requireConfigService(ctx, "读取依赖缓存哈希前必须初始化 configService。");
|
|
16767
17041
|
return objectHash({
|
|
16768
|
-
dependencies:
|
|
17042
|
+
dependencies: configService.packageJson.dependencies ?? {},
|
|
16769
17043
|
scope: serializeDependencyScope(resolveDependencyScope(root))
|
|
16770
17044
|
});
|
|
16771
17045
|
}
|
|
@@ -17109,10 +17383,20 @@ const webRuntimeProvider = {
|
|
|
17109
17383
|
backend: "web",
|
|
17110
17384
|
compilation: "web",
|
|
17111
17385
|
injection: "virtual-module",
|
|
17112
|
-
entries: Object.freeze({
|
|
17113
|
-
|
|
17114
|
-
|
|
17115
|
-
|
|
17386
|
+
entries: Object.freeze({
|
|
17387
|
+
runtime: Object.freeze({
|
|
17388
|
+
development: "@weapp-vite/web/runtime",
|
|
17389
|
+
production: "@weapp-vite/web/runtime"
|
|
17390
|
+
}),
|
|
17391
|
+
reactivity: Object.freeze({
|
|
17392
|
+
development: "wevu/internal-reactivity",
|
|
17393
|
+
production: "wevu/internal-reactivity"
|
|
17394
|
+
}),
|
|
17395
|
+
template: Object.freeze({
|
|
17396
|
+
development: "wevu/internal-template",
|
|
17397
|
+
production: "wevu/internal-template"
|
|
17398
|
+
})
|
|
17399
|
+
}),
|
|
17116
17400
|
capabilities: Object.freeze({
|
|
17117
17401
|
framework: false,
|
|
17118
17402
|
hmr: true,
|
|
@@ -17126,12 +17410,14 @@ const webRuntimeProvider = {
|
|
|
17126
17410
|
contractVersion: WEAPP_VITE_RUNTIME_CONTRACT_VERSION
|
|
17127
17411
|
},
|
|
17128
17412
|
resolveModuleId(entry) {
|
|
17413
|
+
if (entry.kind !== "runtime") return entry.moduleId;
|
|
17129
17414
|
return fileURLToPath(import.meta.resolve(entry.moduleId));
|
|
17130
17415
|
}
|
|
17131
17416
|
};
|
|
17132
17417
|
//#endregion
|
|
17133
17418
|
//#region src/runtimeProviders/plugin.ts
|
|
17134
17419
|
const runtimeKindByVirtualId = new Map(Object.entries(WEAPP_VITE_RUNTIME_VIRTUAL_IDS).map(([kind, id]) => [id, kind]));
|
|
17420
|
+
const WEB_RUNTIME_COMPAT_ENTRY = "weapp-vite/runtime";
|
|
17135
17421
|
function resolveRuntimeProviderEntry(provider, kind, variant) {
|
|
17136
17422
|
const { descriptor } = provider;
|
|
17137
17423
|
if (descriptor.contractVersion !== WEAPP_VITE_RUNTIME_CONTRACT_VERSION) throw new Error(`运行时 provider "${descriptor.id}" 的 contract version 为 ${descriptor.contractVersion},当前编译器要求 ${WEAPP_VITE_RUNTIME_CONTRACT_VERSION}。`);
|
|
@@ -17154,7 +17440,7 @@ function createRuntimeProviderPlugin(provider, variant) {
|
|
|
17154
17440
|
name: `weapp-vite:runtime-provider:${provider.descriptor.id}`,
|
|
17155
17441
|
enforce: "pre",
|
|
17156
17442
|
async resolveId(id, importer) {
|
|
17157
|
-
const kind = runtimeKindByVirtualId.get(id);
|
|
17443
|
+
const kind = runtimeKindByVirtualId.get(id) ?? (provider.descriptor.backend === "web" && id === WEB_RUNTIME_COMPAT_ENTRY ? "runtime" : void 0);
|
|
17158
17444
|
if (!kind) return null;
|
|
17159
17445
|
const entry = resolveRuntimeProviderEntry(provider, kind, variant);
|
|
17160
17446
|
let moduleId = entry.moduleId;
|
|
@@ -17781,7 +18067,7 @@ function isKnownWevuComponentCallee(callee) {
|
|
|
17781
18067
|
* 通过轻量字符串特征快速判断脚本是否可能需要注入 setData.pick。
|
|
17782
18068
|
*/
|
|
17783
18069
|
function mayNeedInjectSetDataPickInJs(source) {
|
|
17784
|
-
return source.includes("createWevuComponent") || source.includes("defineComponent") || source.includes("__wevu_isPage") || source.includes(".so(");
|
|
18070
|
+
return source.includes("createWevuComponent") || source.includes("defineComponent") || source.includes("__wevu_isPage") || source.includes(".so(") || source.includes("export default");
|
|
17785
18071
|
}
|
|
17786
18072
|
/**
|
|
17787
18073
|
* 判断脚本 setup 阶段是否会读取编译期 slot 名元数据。
|
|
@@ -18056,12 +18342,20 @@ function transformTargetWevuOptionsInJs(source, transformOptions, options) {
|
|
|
18056
18342
|
};
|
|
18057
18343
|
const ast = parseJsLike(source);
|
|
18058
18344
|
const candidateOptions = /* @__PURE__ */ new Set();
|
|
18059
|
-
traverse(ast, {
|
|
18060
|
-
|
|
18061
|
-
|
|
18062
|
-
|
|
18063
|
-
|
|
18064
|
-
|
|
18345
|
+
traverse(ast, {
|
|
18346
|
+
CallExpression(path) {
|
|
18347
|
+
const firstArg = path.node.arguments[0];
|
|
18348
|
+
if (!firstArg || firstArg.type === "SpreadElement") return;
|
|
18349
|
+
const resolvedOptions = t.isExpression(firstArg) ? resolveOptionsObjectExpression(firstArg, path.scope) : null;
|
|
18350
|
+
if (resolvedOptions && (isKnownWevuComponentCallee(path.node.callee) || hasCompiledWevuOptionsMarker(resolvedOptions))) candidateOptions.add(resolvedOptions);
|
|
18351
|
+
},
|
|
18352
|
+
ExportDefaultDeclaration(path) {
|
|
18353
|
+
const declaration = path.node.declaration;
|
|
18354
|
+
if (!t.isExpression(declaration)) return;
|
|
18355
|
+
const resolvedOptions = resolveOptionsObjectExpression(declaration, path.scope);
|
|
18356
|
+
if (resolvedOptions) candidateOptions.add(resolvedOptions);
|
|
18357
|
+
}
|
|
18358
|
+
});
|
|
18065
18359
|
if (!candidateOptions.size) return {
|
|
18066
18360
|
code: source,
|
|
18067
18361
|
transformed: false
|
|
@@ -18073,7 +18367,7 @@ function transformTargetWevuOptionsInJs(source, transformOptions, options) {
|
|
|
18073
18367
|
transformed: false
|
|
18074
18368
|
};
|
|
18075
18369
|
const sourceMap = options?.sourceMap !== false;
|
|
18076
|
-
const generated = generate(ast, {
|
|
18370
|
+
const generated = generate$1(ast, {
|
|
18077
18371
|
retainLines: true,
|
|
18078
18372
|
sourceMaps: sourceMap,
|
|
18079
18373
|
sourceFileName: "inline.js"
|
|
@@ -19365,7 +19659,7 @@ function injectLayoutBindingComputed(script, props) {
|
|
|
19365
19659
|
else if (t.isObjectExpression(computedProp.value)) computedProp.value.properties.push(...computedEntries);
|
|
19366
19660
|
else if (t.isIdentifier(computedProp.value) || t.isMemberExpression(computedProp.value)) computedProp.value = t.objectExpression([...computedEntries, t.spreadElement(t.cloneNode(computedProp.value, true))]);
|
|
19367
19661
|
else return script;
|
|
19368
|
-
return generate(ast, { retainLines: true }).code;
|
|
19662
|
+
return generate$1(ast, { retainLines: true }).code;
|
|
19369
19663
|
}
|
|
19370
19664
|
//#endregion
|
|
19371
19665
|
//#region src/plugins/vue/transform/pageLayout/apply/native.ts
|
|
@@ -19427,12 +19721,12 @@ function injectNativePageLayoutRuntime(script, filename, plan) {
|
|
|
19427
19721
|
const strippedMeta = stripDefinePageMetaCalls(ast);
|
|
19428
19722
|
const shouldInjectSetter = Boolean(plan?.dynamicSwitch);
|
|
19429
19723
|
if (!shouldInjectSetter && !strippedMeta) return script;
|
|
19430
|
-
if (!shouldInjectSetter) return generate(ast, { retainLines: true }).code;
|
|
19724
|
+
if (!shouldInjectSetter) return generate$1(ast, { retainLines: true }).code;
|
|
19431
19725
|
const pageOptions = findNativePageOptionsObject(ast);
|
|
19432
19726
|
if (!pageOptions) throw new Error(`${filename} 中未找到可注入 layout 运行时的 Page({}) 定义。`);
|
|
19433
19727
|
injectNativePageLayoutState(pageOptions, plan?.currentLayout);
|
|
19434
19728
|
injectNativePageLayoutSetter(pageOptions);
|
|
19435
|
-
return generate(ast, { retainLines: true }).code;
|
|
19729
|
+
return generate$1(ast, { retainLines: true }).code;
|
|
19436
19730
|
}
|
|
19437
19731
|
//#endregion
|
|
19438
19732
|
//#region src/plugins/vue/transform/pageLayout/apply/index.ts
|
|
@@ -19492,7 +19786,7 @@ function extractStaticLayoutPropValue(node, filename, keyName) {
|
|
|
19492
19786
|
if (t.isNumericLiteral(normalized)) return normalized.value;
|
|
19493
19787
|
if (t.isBooleanLiteral(normalized)) return normalized.value;
|
|
19494
19788
|
if (t.isNullLiteral(normalized)) return null;
|
|
19495
|
-
const expression = generate(normalized, { compact: true }).code;
|
|
19789
|
+
const expression = generate$1(normalized, { compact: true }).code;
|
|
19496
19790
|
if (!expression) throw new Error(`${filename} 中 definePageMeta().layout.props.${keyName} 无法解析为表达式。`);
|
|
19497
19791
|
return {
|
|
19498
19792
|
kind: "expression",
|
|
@@ -20977,6 +21271,28 @@ function createEntryLoader(options) {
|
|
|
20977
21271
|
const templateEntryPathCache = /* @__PURE__ */ new Map();
|
|
20978
21272
|
const styleImportsCache = /* @__PURE__ */ new Map();
|
|
20979
21273
|
let resolveCacheVersion = 0;
|
|
21274
|
+
async function materializeVueAutoImportEntries(pluginCtx, importer, json, injectedEntries) {
|
|
21275
|
+
const usingComponents = get(json, "usingComponents");
|
|
21276
|
+
if (!isObject(usingComponents) || !injectedEntries.length) {
|
|
21277
|
+
if (!isObject(usingComponents) || !configService.weappViteConfig?.uniApp) return injectedEntries;
|
|
21278
|
+
}
|
|
21279
|
+
const candidateEntries = Array.from(/* @__PURE__ */ new Set([...injectedEntries, ...Object.values(usingComponents).filter((entry) => typeof entry === "string" && entry.endsWith(".vue"))]));
|
|
21280
|
+
const rewritten = /* @__PURE__ */ new Map();
|
|
21281
|
+
for (const entry of candidateEntries) {
|
|
21282
|
+
const resolved = await pluginCtx.resolve(entry, importer);
|
|
21283
|
+
const resolvedId = resolved?.id ? normalizeFsResolvedId(resolved.id) : void 0;
|
|
21284
|
+
if (!resolvedId?.endsWith(".vue")) {
|
|
21285
|
+
if (configService.weappViteConfig?.uniApp && entry.endsWith(".vue")) throw new Error(`[uni-app] 无法解析外部 Vue 组件: importer=${importer} request=${entry}`);
|
|
21286
|
+
continue;
|
|
21287
|
+
}
|
|
21288
|
+
const outputPath = usingComponentFromResolvedFile(resolvedId, configService);
|
|
21289
|
+
if (!outputPath) throw new Error(`[uni-app] 无法生成外部 Vue 组件输出路径: importer=${importer} resolvedId=${resolvedId}`);
|
|
21290
|
+
for (const [name, value] of Object.entries(usingComponents)) if (value === entry) usingComponents[name] = outputPath;
|
|
21291
|
+
ctx.runtimeState.build.hmr.externalComponentEntryMap.set(removeExtensionDeep(outputPath).replace(/^\/+/, ""), resolvedId);
|
|
21292
|
+
rewritten.set(entry, outputPath);
|
|
21293
|
+
}
|
|
21294
|
+
return Array.from(/* @__PURE__ */ new Set([...injectedEntries.map((entry) => rewritten.get(entry) ?? entry), ...candidateEntries.map((entry) => rewritten.get(entry) ?? entry)]));
|
|
21295
|
+
}
|
|
20980
21296
|
const shouldEmitScriptlessVueLayoutJs$1 = async (layoutFile) => {
|
|
20981
21297
|
const cached = scriptlessVueLayoutDecisionCache.get(layoutFile);
|
|
20982
21298
|
if (cached) return await cached;
|
|
@@ -21287,7 +21603,8 @@ function createEntryLoader(options) {
|
|
|
21287
21603
|
const autoImportStartedAt = performance$1.now();
|
|
21288
21604
|
try {
|
|
21289
21605
|
if (ctx.autoImportService?.hasPendingRegistrations?.() !== false) await ctx.autoImportService?.awaitPendingRegistrations?.();
|
|
21290
|
-
const
|
|
21606
|
+
const rawInjectedAutoImportEntries = await applyAutoImports(baseName, json) ?? [];
|
|
21607
|
+
const injectedAutoImportEntries = await materializeVueAutoImportEntries(this, vueEntryPath ?? id, json, rawInjectedAutoImportEntries);
|
|
21291
21608
|
const componentEntries = analyzeCommonJson(json);
|
|
21292
21609
|
const pendingAutoImportMap = ctx.runtimeState?.autoImport?.pendingEntriesByImporter;
|
|
21293
21610
|
const vueBaseName = vueEntryPath ? removeExtensionDeep(vueEntryPath) : void 0;
|
|
@@ -22031,19 +22348,6 @@ const WEVU_INTERNAL_RUNTIME_EXPORTS = [
|
|
|
22031
22348
|
"version",
|
|
22032
22349
|
"waitForLayoutHost"
|
|
22033
22350
|
];
|
|
22034
|
-
const WEVU_RUNTIME_MODULE_IDS = [
|
|
22035
|
-
"wevu",
|
|
22036
|
-
"wevu/router",
|
|
22037
|
-
"wevu/store",
|
|
22038
|
-
"wevu/api",
|
|
22039
|
-
"wevu/fetch",
|
|
22040
|
-
"wevu/web-apis",
|
|
22041
|
-
...[
|
|
22042
|
-
"wevu/internal-runtime",
|
|
22043
|
-
"wevu/internal-reactivity",
|
|
22044
|
-
"wevu/internal-template"
|
|
22045
|
-
]
|
|
22046
|
-
];
|
|
22047
22351
|
const WEVU_RUNTIME_MODULE_ID_PATTERN = ["wevu(?:\\/(?:router|store|api|fetch|web-apis|internal-(?:runtime|reactivity|template)))?", ...Object.values(WEAPP_VITE_RUNTIME_VIRTUAL_IDS).map((id) => id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))].join("|");
|
|
22048
22352
|
const WEVU_RUNTIME_NAMED_IMPORT_RE = new RegExp(`\\bimport\\s*\\{([^}]*)\\}\\s*from\\s*["'](${WEVU_RUNTIME_MODULE_ID_PATTERN})["'];?`, "g");
|
|
22049
22353
|
const WEVU_RUNTIME_REQUIRE_RE = new RegExp(`\\brequire\\(\\s*(\`(?:${WEVU_RUNTIME_MODULE_ID_PATTERN})\`|'(?:${WEVU_RUNTIME_MODULE_ID_PATTERN})'|"(?:${WEVU_RUNTIME_MODULE_ID_PATTERN})")\\s*\\)`, "g");
|
|
@@ -22198,7 +22502,8 @@ function removeImplicitPagePreloads(bundle, options, snapshot = createBundleChun
|
|
|
22198
22502
|
const pageChunkFileNames = /* @__PURE__ */ new Set();
|
|
22199
22503
|
for (const entry of entriesMap.values()) {
|
|
22200
22504
|
if (!entry || entry.type !== "page") continue;
|
|
22201
|
-
const
|
|
22505
|
+
const relative = configService.relativeAbsoluteSrcRoot(entry.path);
|
|
22506
|
+
const outputFile = changeFileExtension(relative, ".js");
|
|
22202
22507
|
pageChunkFileNames.add(outputFile);
|
|
22203
22508
|
}
|
|
22204
22509
|
if (pageChunkFileNames.size === 0) return;
|
|
@@ -22262,14 +22567,11 @@ function collectExistingExportNames(code) {
|
|
|
22262
22567
|
function collectChunkExportNames(chunk) {
|
|
22263
22568
|
return collectExistingExportNames(chunk.code);
|
|
22264
22569
|
}
|
|
22265
|
-
function isWevuRuntimeModuleId(value) {
|
|
22266
|
-
return WEVU_RUNTIME_MODULE_IDS.includes(value);
|
|
22267
|
-
}
|
|
22268
22570
|
function normalizeWevuRuntimeModuleId(value) {
|
|
22269
22571
|
if (value === WEAPP_VITE_RUNTIME_VIRTUAL_ID) return "wevu/internal-runtime";
|
|
22270
22572
|
if (value === WEAPP_VITE_RUNTIME_REACTIVITY_VIRTUAL_ID) return "wevu/internal-reactivity";
|
|
22271
22573
|
if (value === WEAPP_VITE_RUNTIME_TEMPLATE_VIRTUAL_ID) return "wevu/internal-template";
|
|
22272
|
-
return
|
|
22574
|
+
return resolveWevuRuntimeModuleId(value);
|
|
22273
22575
|
}
|
|
22274
22576
|
function resolveWevuInternalChunk(bundleOrSnapshot, importNames) {
|
|
22275
22577
|
const requiredNames = new Set(importNames);
|
|
@@ -22288,6 +22590,10 @@ function createWevuRuntimeChunkIndex(bundle, snapshot = createBundleChunkSnapsho
|
|
|
22288
22590
|
if (typeof chunk.code !== "string") continue;
|
|
22289
22591
|
vendorChunks.push(chunk);
|
|
22290
22592
|
const normalizedFileName = chunk.fileName.replace(/\\/g, "/");
|
|
22593
|
+
const resolvedModuleIds = [chunk.facadeModuleId, ...chunk.moduleIds ?? []].filter((id) => typeof id === "string").map((id) => resolveWevuRuntimeModuleId(id)).filter((id) => Boolean(id));
|
|
22594
|
+
for (const moduleId of resolvedModuleIds) if (!chunksByModuleId.has(moduleId)) chunksByModuleId.set(moduleId, chunk);
|
|
22595
|
+
const stableModuleId = resolveWevuRuntimeModuleIdFromStableVendorFileName(normalizedFileName);
|
|
22596
|
+
if (stableModuleId && !chunksByModuleId.has(stableModuleId)) chunksByModuleId.set(stableModuleId, chunk);
|
|
22291
22597
|
for (const moduleId of WEVU_RUNTIME_MODULE_IDS) {
|
|
22292
22598
|
const chunkFileName = moduleId.replace(/\//g, "-");
|
|
22293
22599
|
if ((moduleId === "wevu" ? normalizedFileName.endsWith(`${chunkFileName}.js`) : normalizedFileName.endsWith(`${chunkFileName}.js`) || normalizedFileName.includes(`/${chunkFileName}-`)) && !chunksByModuleId.has(moduleId)) chunksByModuleId.set(moduleId, chunk);
|
|
@@ -22362,12 +22668,20 @@ function resolveRootWevuInternalModuleId(importedName) {
|
|
|
22362
22668
|
if (WEVU_INTERNAL_RUNTIME_EXPORT_SET.has(importedName)) return "wevu/internal-runtime";
|
|
22363
22669
|
}
|
|
22364
22670
|
function resolveWevuRuntimeChunkForModuleId(index, moduleId, importedNames) {
|
|
22365
|
-
|
|
22671
|
+
const names = [...importedNames];
|
|
22672
|
+
const exactChunk = index.chunksByModuleId.get(moduleId);
|
|
22673
|
+
if (exactChunk) {
|
|
22674
|
+
const exports = getWevuRuntimeChunkExportNames(index, exactChunk);
|
|
22675
|
+
if (names.every((name) => exports.has(name))) return exactChunk;
|
|
22676
|
+
}
|
|
22677
|
+
return resolveIndexedWevuInternalChunk(index, names);
|
|
22366
22678
|
}
|
|
22367
22679
|
function resolveRememberedWevuRuntimeFileName(moduleId, importedNames, options) {
|
|
22368
22680
|
const names = [...importedNames];
|
|
22369
22681
|
const canUseLegacyRuntimeFileName = moduleId === "wevu/internal-runtime" && names.every((importedName) => WEVU_INTERNAL_RUNTIME_EXPORT_SET.has(importedName));
|
|
22370
|
-
|
|
22682
|
+
const rememberedFileName = options.runtimeFileNames?.get(moduleId) ?? (canUseLegacyRuntimeFileName ? options.runtimeFileName : void 0);
|
|
22683
|
+
if (rememberedFileName && options.isRuntimeFileNameAvailable && !options.isRuntimeFileNameAvailable(rememberedFileName)) return;
|
|
22684
|
+
return rememberedFileName;
|
|
22371
22685
|
}
|
|
22372
22686
|
function formatWevuRuntimeRequire(fileName, runtimeFileName, bindings) {
|
|
22373
22687
|
const specifier = normalizeRelativeRequireSpecifier(fileName, runtimeFileName);
|
|
@@ -23304,7 +23618,8 @@ function analyzeRequestGlobalsUsage(code, allowedTargets) {
|
|
|
23304
23618
|
if (typeof specifier === "string" && specifier.length > 0) matchedSpecifiers.add(specifier);
|
|
23305
23619
|
};
|
|
23306
23620
|
try {
|
|
23307
|
-
|
|
23621
|
+
const ast = parseJsLike(usageSource);
|
|
23622
|
+
traverse(ast, {
|
|
23308
23623
|
ImportDeclaration(path) {
|
|
23309
23624
|
addSpecifier(path.node?.source?.value);
|
|
23310
23625
|
},
|
|
@@ -23429,6 +23744,38 @@ const IFDEF = "#ifdef";
|
|
|
23429
23744
|
const IFNDEF = "#ifndef";
|
|
23430
23745
|
//#endregion
|
|
23431
23746
|
//#region src/postcss/post.ts
|
|
23747
|
+
const UNI_APP_PLATFORM_DEFINES = {
|
|
23748
|
+
weapp: [
|
|
23749
|
+
"mp",
|
|
23750
|
+
"mp-weixin",
|
|
23751
|
+
"vue3"
|
|
23752
|
+
],
|
|
23753
|
+
alipay: [
|
|
23754
|
+
"mp",
|
|
23755
|
+
"mp-alipay",
|
|
23756
|
+
"vue3"
|
|
23757
|
+
],
|
|
23758
|
+
tt: [
|
|
23759
|
+
"mp",
|
|
23760
|
+
"mp-toutiao",
|
|
23761
|
+
"vue3"
|
|
23762
|
+
],
|
|
23763
|
+
swan: [
|
|
23764
|
+
"mp",
|
|
23765
|
+
"mp-baidu",
|
|
23766
|
+
"vue3"
|
|
23767
|
+
],
|
|
23768
|
+
jd: [
|
|
23769
|
+
"mp",
|
|
23770
|
+
"mp-jd",
|
|
23771
|
+
"vue3"
|
|
23772
|
+
],
|
|
23773
|
+
xhs: [
|
|
23774
|
+
"mp",
|
|
23775
|
+
"mp-xhs",
|
|
23776
|
+
"vue3"
|
|
23777
|
+
]
|
|
23778
|
+
};
|
|
23432
23779
|
function normalizeTargets(values) {
|
|
23433
23780
|
return values.map((value) => value.trim().toLowerCase()).filter(Boolean);
|
|
23434
23781
|
}
|
|
@@ -23478,6 +23825,7 @@ function removeConditionalBlock(start) {
|
|
|
23478
23825
|
const postCreator = (options = { platform: "weapp" }) => {
|
|
23479
23826
|
const atRulePrefixRegExp = new RegExp(`^wv-`);
|
|
23480
23827
|
const platform = options.platform.toLowerCase();
|
|
23828
|
+
const activeTargets = /* @__PURE__ */ new Set([platform, ...UNI_APP_PLATFORM_DEFINES[options.platform]]);
|
|
23481
23829
|
return {
|
|
23482
23830
|
postcssPlugin: "postcss-weapp-vite-plugin-post",
|
|
23483
23831
|
prepare() {
|
|
@@ -23503,7 +23851,7 @@ const postCreator = (options = { platform: "weapp" }) => {
|
|
|
23503
23851
|
comment.remove();
|
|
23504
23852
|
return;
|
|
23505
23853
|
}
|
|
23506
|
-
const hasPlatform = directive.targets.
|
|
23854
|
+
const hasPlatform = directive.targets.some((target) => activeTargets.has(target));
|
|
23507
23855
|
if (!(directive.type === "ifdef" ? hasPlatform : !hasPlatform)) {
|
|
23508
23856
|
removeConditionalBlock(comment);
|
|
23509
23857
|
comment.remove();
|
|
@@ -23518,10 +23866,11 @@ const postCreator = (options = { platform: "weapp" }) => {
|
|
|
23518
23866
|
postCreator.postcss = true;
|
|
23519
23867
|
//#endregion
|
|
23520
23868
|
//#region src/postcss/index.ts
|
|
23521
|
-
const
|
|
23869
|
+
const NEEDS_CONDITIONAL_PROCESS_RE = new RegExp(`@wv-|${IFDEF}|${IFNDEF}`);
|
|
23522
23870
|
async function cssPostProcess(code, options) {
|
|
23523
|
-
|
|
23524
|
-
|
|
23871
|
+
let processed = code;
|
|
23872
|
+
if (NEEDS_CONDITIONAL_PROCESS_RE.test(processed)) processed = (await postcss([postCreator(options)]).process(processed, { from: void 0 })).css;
|
|
23873
|
+
return options.platform === "weapp" ? transformNestedWxssVars(transformVueDeepSelectors(processed)) : processed;
|
|
23525
23874
|
}
|
|
23526
23875
|
//#endregion
|
|
23527
23876
|
//#region src/plugins/css/shared/preprocessor.ts
|
|
@@ -24302,6 +24651,9 @@ function createOutputFinalizerPlugin(ctx) {
|
|
|
24302
24651
|
get runtimeFileNames() {
|
|
24303
24652
|
return ctx.runtimeState?.build?.output?.wevuInternalRuntimeFileNames;
|
|
24304
24653
|
},
|
|
24654
|
+
isRuntimeFileNameAvailable(fileName) {
|
|
24655
|
+
return ctx.runtimeState?.build?.output?.emittedSource.has(fileName) === true;
|
|
24656
|
+
},
|
|
24305
24657
|
onRuntimeFileName(fileName) {
|
|
24306
24658
|
const outputState = ctx.runtimeState?.build?.output;
|
|
24307
24659
|
if (outputState) outputState.wevuInternalRuntimeFileName = fileName;
|
|
@@ -24602,7 +24954,7 @@ function rewriteMiniProgramPlatformApiAccess(code, globalName, _options) {
|
|
|
24602
24954
|
OptionalMemberExpression: rewritePath
|
|
24603
24955
|
});
|
|
24604
24956
|
if (!mutated) return code;
|
|
24605
|
-
const transformedCode = generate(ast).code;
|
|
24957
|
+
const transformedCode = generate$1(ast).code;
|
|
24606
24958
|
return `${`var ${injectedApiIdentifier} = ${createWeapiAccessExpression(globalName)};`}\n${transformedCode}`;
|
|
24607
24959
|
} catch {
|
|
24608
24960
|
return code;
|
|
@@ -24692,7 +25044,7 @@ function rewriteChunkNpmImportsByPlatform(platform, code, dependencies, mode, op
|
|
|
24692
25044
|
mutated = true;
|
|
24693
25045
|
} });
|
|
24694
25046
|
if (!mutated) return code;
|
|
24695
|
-
return generate(ast).code;
|
|
25047
|
+
return generate$1(ast).code;
|
|
24696
25048
|
} catch {
|
|
24697
25049
|
return code;
|
|
24698
25050
|
}
|
|
@@ -24766,6 +25118,43 @@ function matchesSubPackageDependency(dependencies, importee, fallbackDependencie
|
|
|
24766
25118
|
return hasNpmDependencyPrefix(fallbackDependencies, normalized);
|
|
24767
25119
|
}
|
|
24768
25120
|
//#endregion
|
|
25121
|
+
//#region src/utils/sourcemap.ts
|
|
25122
|
+
function isEncodedSourceMapLike(value) {
|
|
25123
|
+
return Boolean(value && typeof value === "object" && "version" in value && typeof value.version === "number" && "mappings" in value && "names" in value && "sources" in value);
|
|
25124
|
+
}
|
|
25125
|
+
function normalizeEncodedSourceMapLike(value) {
|
|
25126
|
+
if (!value || typeof value !== "object") return null;
|
|
25127
|
+
const sourceMap = value;
|
|
25128
|
+
const numericVersion = typeof sourceMap.version === "number" ? sourceMap.version : typeof sourceMap.version === "string" ? Number(sourceMap.version) : NaN;
|
|
25129
|
+
if (!Number.isFinite(numericVersion)) return null;
|
|
25130
|
+
const normalized = {
|
|
25131
|
+
...sourceMap,
|
|
25132
|
+
version: numericVersion
|
|
25133
|
+
};
|
|
25134
|
+
return isEncodedSourceMapLike(normalized) ? normalized : null;
|
|
25135
|
+
}
|
|
25136
|
+
function composeSourceMaps(transformedMap, originalMap) {
|
|
25137
|
+
if (isEncodedSourceMapLike(transformedMap) && isEncodedSourceMapLike(originalMap)) return remapping([transformedMap, originalMap], () => null);
|
|
25138
|
+
if (isEncodedSourceMapLike(transformedMap)) return transformedMap;
|
|
25139
|
+
if (isEncodedSourceMapLike(originalMap)) return originalMap;
|
|
25140
|
+
return null;
|
|
25141
|
+
}
|
|
25142
|
+
//#endregion
|
|
25143
|
+
//#region src/plugins/core/lifecycle/emit/rewrite/sourcemap.ts
|
|
25144
|
+
function applyMagicStringChunkRewrite(chunk, magicString) {
|
|
25145
|
+
const previousCode = chunk.code;
|
|
25146
|
+
const nextCode = magicString.toString();
|
|
25147
|
+
if (nextCode === previousCode) return false;
|
|
25148
|
+
const previousMap = normalizeEncodedSourceMapLike(chunk.map);
|
|
25149
|
+
chunk.code = nextCode;
|
|
25150
|
+
if (previousMap) chunk.map = composeSourceMaps(magicString.generateMap({
|
|
25151
|
+
hires: "boundary",
|
|
25152
|
+
includeContent: true,
|
|
25153
|
+
source: chunk.fileName
|
|
25154
|
+
}), previousMap);
|
|
25155
|
+
return true;
|
|
25156
|
+
}
|
|
25157
|
+
//#endregion
|
|
24769
25158
|
//#region src/plugins/core/lifecycle/emit/rewrite/localRoot.ts
|
|
24770
25159
|
function isRelativeMiniprogramNpmImport(importee) {
|
|
24771
25160
|
return importee === "miniprogram_npm" || importee.startsWith("./miniprogram_npm/") || importee.startsWith("../miniprogram_npm/") || importee.includes("/miniprogram_npm/");
|
|
@@ -24779,6 +25168,17 @@ function isToEsmCall(node) {
|
|
|
24779
25168
|
function isNumericOneLiteral(node) {
|
|
24780
25169
|
return (node?.type === "NumericLiteral" || node?.type === "Literal") && node.value === 1;
|
|
24781
25170
|
}
|
|
25171
|
+
function hasNodeRange(node) {
|
|
25172
|
+
return Number.isInteger(node?.start) && Number.isInteger(node?.end) && node.start >= 0 && node.end >= node.start;
|
|
25173
|
+
}
|
|
25174
|
+
function findPreviousCommaIndex(code, start) {
|
|
25175
|
+
for (let index = start - 1; index >= 0; index--) {
|
|
25176
|
+
const char = code[index];
|
|
25177
|
+
if (char === ",") return index;
|
|
25178
|
+
if (!/\s/.test(char)) return start;
|
|
25179
|
+
}
|
|
25180
|
+
return start;
|
|
25181
|
+
}
|
|
24782
25182
|
function getLocalizedBindingNameFromExpression(node, localizedRequireBindings) {
|
|
24783
25183
|
if (!node) return;
|
|
24784
25184
|
if (node.type === "Identifier" && localizedRequireBindings.has(node.name)) return node.name;
|
|
@@ -24801,6 +25201,7 @@ function rewriteChunkNpmImportsToLocalRoot(chunk, root, dependencyPatterns, depe
|
|
|
24801
25201
|
if (!analysis.hasStaticRequireLiteral) return;
|
|
24802
25202
|
try {
|
|
24803
25203
|
const ast = parseJsLike(chunk.code);
|
|
25204
|
+
const magicString = new MagicString(chunk.code);
|
|
24804
25205
|
let mutated = false;
|
|
24805
25206
|
const localizedRequireBindings = /* @__PURE__ */ new Set();
|
|
24806
25207
|
traverse(ast, {
|
|
@@ -24831,7 +25232,8 @@ function rewriteChunkNpmImportsToLocalRoot(chunk, root, dependencyPatterns, depe
|
|
|
24831
25232
|
if (typeof currentValue !== "string" || !matchesSubPackageDependency(dependencyPatterns, currentValue, dependencies)) return;
|
|
24832
25233
|
const nextValue = toRelativeRuntimeNpmImport(chunk.fileName, root, currentValue, options?.basedir);
|
|
24833
25234
|
if (nextValue === currentValue) return;
|
|
24834
|
-
|
|
25235
|
+
if (!hasNodeRange(firstArg)) return;
|
|
25236
|
+
magicString.update(firstArg.start, firstArg.end, JSON.stringify(nextValue));
|
|
24835
25237
|
if (isRelativeMiniprogramNpmImport(nextValue) && path.parentPath?.node?.type === "VariableDeclarator" && path.parentPath.node.id?.type === "Identifier") localizedRequireBindings.add(path.parentPath.node.id.name);
|
|
24836
25238
|
if (isRelativeMiniprogramNpmImport(nextValue) && path.parentPath?.node?.type === "AssignmentExpression" && path.parentPath.node.left?.type === "Identifier") localizedRequireBindings.add(path.parentPath.node.left.name);
|
|
24837
25239
|
mutated = true;
|
|
@@ -24842,12 +25244,14 @@ function rewriteChunkNpmImportsToLocalRoot(chunk, root, dependencyPatterns, depe
|
|
|
24842
25244
|
if (!Array.isArray(args) || args.length < 2 || !isNumericOneLiteral(args[1])) return;
|
|
24843
25245
|
const firstArg = args[0];
|
|
24844
25246
|
if (!Boolean(getLocalizedBindingNameFromExpression(firstArg, localizedRequireBindings))) return;
|
|
24845
|
-
|
|
25247
|
+
const secondArg = args[1];
|
|
25248
|
+
if (!hasNodeRange(firstArg) || !hasNodeRange(secondArg)) return;
|
|
25249
|
+
magicString.remove(findPreviousCommaIndex(chunk.code, secondArg.start), secondArg.end);
|
|
24846
25250
|
mutated = true;
|
|
24847
25251
|
}
|
|
24848
25252
|
});
|
|
24849
25253
|
if (mutated) {
|
|
24850
|
-
chunk
|
|
25254
|
+
applyMagicStringChunkRewrite(chunk, magicString);
|
|
24851
25255
|
rememberChunkScriptAnalysis(chunk, analysis, { cache: options?.analysisCache });
|
|
24852
25256
|
}
|
|
24853
25257
|
} catch {}
|
|
@@ -24956,19 +25360,20 @@ function resolveRequestGlobalsInstallerName(code) {
|
|
|
24956
25360
|
let installerName = null;
|
|
24957
25361
|
const isInstallerFunctionNode = (node) => {
|
|
24958
25362
|
if (!node) return false;
|
|
24959
|
-
|
|
25363
|
+
if (Array.isArray(node.params) && node.params.length > 1) return false;
|
|
25364
|
+
const functionCode = generate$1(node).code;
|
|
24960
25365
|
return FULL_REQUEST_GLOBAL_TARGETS.every((target) => functionCode.includes(target));
|
|
24961
25366
|
};
|
|
24962
25367
|
traverse(ast, {
|
|
24963
25368
|
FunctionDeclaration(path) {
|
|
24964
25369
|
if (installerName || !path.node?.id?.name) return;
|
|
24965
|
-
if (isInstallerFunctionNode(path.node
|
|
25370
|
+
if (isInstallerFunctionNode(path.node)) installerName = path.node.id.name;
|
|
24966
25371
|
},
|
|
24967
25372
|
VariableDeclarator(path) {
|
|
24968
25373
|
if (installerName || path.node?.id?.type !== "Identifier") return;
|
|
24969
25374
|
const init = path.node.init;
|
|
24970
25375
|
if (!init || init.type !== "FunctionExpression" && init.type !== "ArrowFunctionExpression") return;
|
|
24971
|
-
if (isInstallerFunctionNode(init
|
|
25376
|
+
if (isInstallerFunctionNode(init)) installerName = path.node.id.name;
|
|
24972
25377
|
}
|
|
24973
25378
|
});
|
|
24974
25379
|
return installerName;
|
|
@@ -25029,18 +25434,13 @@ function injectRequestGlobalsBundleRuntime(bundle, targets, mode, networkDefault
|
|
|
25029
25434
|
const topLevelDeclaredIdentifiers = collectTopLevelDeclaredIdentifiers(chunk.code);
|
|
25030
25435
|
const passiveBindingsCode = createRequestGlobalsPassiveBindingsCode(chunkTargets, bindingTargets.filter((target) => !topLevelDeclaredIdentifiers.has(target)));
|
|
25031
25436
|
const syntheticExportCode = exportName ? "" : `Object.defineProperty(exports,${JSON.stringify(REQUEST_GLOBAL_SYNTHETIC_EXPORT_NAME)},{enumerable:false,get:function(){return ${installerName}}});`;
|
|
25437
|
+
const installerOptionsCode = createRequestGlobalsInstallerOptionsCode(chunkTargets, networkDefaults);
|
|
25032
25438
|
const runtimeBindingCode = [
|
|
25033
|
-
`const ${REQUEST_GLOBAL_BUNDLE_HOST_REF} = ${installerName}(${
|
|
25439
|
+
`const ${REQUEST_GLOBAL_BUNDLE_HOST_REF} = ${installerName}(${installerOptionsCode}) || globalThis`,
|
|
25034
25440
|
...bindingTargets.map((target) => `${REQUEST_GLOBAL_ACTUALS_KEY}[${JSON.stringify(target)}] = ${REQUEST_GLOBAL_BUNDLE_HOST_REF}.${target}`),
|
|
25035
25441
|
...bindingTargets.map((target) => `try{globalThis[${JSON.stringify(target)}]=${REQUEST_GLOBAL_BUNDLE_HOST_REF}.${target}}catch{}`)
|
|
25036
25442
|
].join(";");
|
|
25037
|
-
|
|
25038
|
-
const firstRequireMatch = chunk.code.match(REQUEST_GLOBAL_REQUIRE_DECLARATOR_RE);
|
|
25039
|
-
if (firstRequireMatch?.[0]) {
|
|
25040
|
-
chunk.code = `${bundlePrelude}${chunk.code.replace(firstRequireMatch[0], (match) => `${match};${syntheticExportCode}${runtimeBindingCode}`)}\n`;
|
|
25041
|
-
continue;
|
|
25042
|
-
}
|
|
25043
|
-
chunk.code = `${bundlePrelude}${syntheticExportCode}${chunk.code}\n;${runtimeBindingCode};\n`;
|
|
25443
|
+
chunk.code = `${`/* ${REQUEST_GLOBAL_BUNDLE_MARKER} */ ${passiveBindingsCode ? `${passiveBindingsCode}\n` : ""}`}${syntheticExportCode}${chunk.code}\n;${runtimeBindingCode};\n`;
|
|
25044
25444
|
}
|
|
25045
25445
|
return installerChunks;
|
|
25046
25446
|
}
|
|
@@ -25585,7 +25985,7 @@ function isStableHmrSharedChunk(fileName) {
|
|
|
25585
25985
|
return fileName.startsWith("weapp-vendors/") || !fileName.includes("/") && fileName !== "app.js";
|
|
25586
25986
|
}
|
|
25587
25987
|
function isRuntimeVendorSharedChunk(fileName) {
|
|
25588
|
-
return fileName.startsWith("weapp-vendors/") && /(?:^|[-/])[\w-]*runtime[\w-]*(?:[-.]|$)/.test(fileName);
|
|
25988
|
+
return !isWevuStableVendorFileName(fileName) && fileName.startsWith("weapp-vendors/") && /(?:^|[-/])[\w-]*runtime[\w-]*(?:[-.]|$)/.test(fileName);
|
|
25589
25989
|
}
|
|
25590
25990
|
function addEmittedChunkFileName(emittedChunkFileNames, fileName, chunk) {
|
|
25591
25991
|
if (!emittedChunkFileNames) return;
|
|
@@ -25993,6 +26393,9 @@ function createGenerateBundleHook(state, isPluginBuild) {
|
|
|
25993
26393
|
rewriteWevuInternalRuntimeImports(runtimeRewriteBundle, {
|
|
25994
26394
|
runtimeFileName: state.ctx.runtimeState?.build?.output?.wevuInternalRuntimeFileName,
|
|
25995
26395
|
runtimeFileNames: state.ctx.runtimeState?.build?.output?.wevuInternalRuntimeFileNames,
|
|
26396
|
+
isRuntimeFileNameAvailable(fileName) {
|
|
26397
|
+
return state.ctx.runtimeState?.build?.output?.emittedSource.has(fileName) === true;
|
|
26398
|
+
},
|
|
25996
26399
|
onRuntimeFileName(fileName) {
|
|
25997
26400
|
const outputState = state.ctx.runtimeState?.build?.output;
|
|
25998
26401
|
if (outputState) outputState.wevuInternalRuntimeFileName = fileName;
|
|
@@ -27022,7 +27425,8 @@ async function normalizeWatchEvent(id, event, options) {
|
|
|
27022
27425
|
if (event === "create" && await fs$1.pathExists(id)) {
|
|
27023
27426
|
const ext = path.extname(id);
|
|
27024
27427
|
if (ext) {
|
|
27025
|
-
const
|
|
27428
|
+
const basePath = id.slice(0, -ext.length);
|
|
27429
|
+
const primaryScript = await findJsEntry(basePath);
|
|
27026
27430
|
const primaryScriptId = primaryScript.path ? normalizeFsResolvedId(primaryScript.path) : "";
|
|
27027
27431
|
if (primaryScriptId && options.resolvedEntryMap.has(primaryScriptId)) return "update";
|
|
27028
27432
|
}
|
|
@@ -27354,23 +27758,120 @@ function createCoreLifecyclePlugin(state) {
|
|
|
27354
27758
|
//#endregion
|
|
27355
27759
|
//#region src/plugins/core/requireAnalysis.ts
|
|
27356
27760
|
const REQUIRE_ANALYSIS_FILTER_RE = /\.[jt]s$/;
|
|
27761
|
+
const URL_SUFFIX_RE = /[?#].*$/;
|
|
27762
|
+
function cleanModuleId(id) {
|
|
27763
|
+
return id.replace(URL_SUFFIX_RE, "");
|
|
27764
|
+
}
|
|
27765
|
+
function createRelativeModuleSpecifier(importerFileName, targetFileName) {
|
|
27766
|
+
const relativePath = path.relative(path.dirname(importerFileName), targetFileName);
|
|
27767
|
+
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
27768
|
+
}
|
|
27769
|
+
function resolveModulePackageRoot(id, relativeAbsoluteSrcRoot, subPackageRoots) {
|
|
27770
|
+
return resolveSubPackagePrefix(relativeAbsoluteSrcRoot(cleanModuleId(id)), subPackageRoots);
|
|
27771
|
+
}
|
|
27772
|
+
/**
|
|
27773
|
+
* 判断静态导入是否能安全交给微信普通分包的原生异步加载器。
|
|
27774
|
+
*/
|
|
27775
|
+
function isNativeSubPackageImport(options) {
|
|
27776
|
+
return options.dynamicImports === "native" && options.platform === "weapp" && options.request.startsWith(".") && Boolean(options.targetPackageRoot) && options.targetPackageRoot !== options.importerPackageRoot && !options.independentTarget;
|
|
27777
|
+
}
|
|
27778
|
+
function rewriteAsyncDependencies(code, options) {
|
|
27779
|
+
const { dependencyRewrites = [], nativeImportTokens = [], requireCallbackTokens = [] } = options;
|
|
27780
|
+
if (dependencyRewrites.length === 0 && nativeImportTokens.length === 0 && requireCallbackTokens.length === 0) return null;
|
|
27781
|
+
const source = new MagicString(code);
|
|
27782
|
+
for (const token of requireCallbackTokens) {
|
|
27783
|
+
source.overwrite(token.callStart, token.start, "void require.async(");
|
|
27784
|
+
source.overwrite(token.end, token.successCallbackStart, ").then(");
|
|
27785
|
+
}
|
|
27786
|
+
for (const token of nativeImportTokens) source.overwrite(token.callStart, token.start, "require.async(");
|
|
27787
|
+
for (const rewrite of dependencyRewrites) source.overwrite(rewrite.start, rewrite.end, JSON.stringify(rewrite.value));
|
|
27788
|
+
return {
|
|
27789
|
+
code: source.toString(),
|
|
27790
|
+
map: source.generateMap({ hires: "boundary" })
|
|
27791
|
+
};
|
|
27792
|
+
}
|
|
27357
27793
|
function createRequireAnalysisPlugin(state) {
|
|
27358
27794
|
const { ctx, requireAsyncEmittedChunks } = state;
|
|
27359
|
-
const { configService } = ctx;
|
|
27795
|
+
const { configService, scanService } = ctx;
|
|
27796
|
+
const resolveDynamicImports = () => configService.weappViteConfig?.chunks?.dynamicImports ?? "preserve";
|
|
27797
|
+
let warnedInlineFallback = false;
|
|
27360
27798
|
return {
|
|
27361
27799
|
name: "weapp-vite:post",
|
|
27362
27800
|
enforce: "post",
|
|
27801
|
+
buildStart() {
|
|
27802
|
+
if (resolveDynamicImports() === "inline" && state.buildTarget === "app" && !warnedInlineFallback) {
|
|
27803
|
+
warnedInlineFallback = true;
|
|
27804
|
+
logger_default.warn("`weapp.chunks.dynamicImports: \"inline\"` 已废弃,当前会回退为 `preserve`;请改用 `preserve`,或在微信分包场景使用 `native`。");
|
|
27805
|
+
}
|
|
27806
|
+
},
|
|
27363
27807
|
transform: {
|
|
27364
27808
|
filter: { id: REQUIRE_ANALYSIS_FILTER_RE },
|
|
27365
|
-
handler(code) {
|
|
27809
|
+
async handler(code, id) {
|
|
27366
27810
|
try {
|
|
27811
|
+
const dynamicImports = resolveDynamicImports();
|
|
27367
27812
|
const ast = this.parse(code);
|
|
27368
|
-
const { requireTokens } = collectRequireTokens(ast);
|
|
27813
|
+
const { dynamicImportTokens, requireCallbackTokens, requireTokens } = collectRequireTokens(ast);
|
|
27814
|
+
const dependencyRewrites = [];
|
|
27815
|
+
const nativeImportTokens = [];
|
|
27816
|
+
const resolvedDependencies = [];
|
|
27817
|
+
const importerFileName = resolveRelativeOutputFileNameWithExtension(configService, cleanModuleId(id), ".js");
|
|
27818
|
+
const subPackageRoots = [...scanService.subPackageMap.keys()].filter(Boolean).sort((left, right) => right.length - left.length);
|
|
27819
|
+
const importerPackageRoot = resolveModulePackageRoot(id, configService.relativeAbsoluteSrcRoot, subPackageRoots);
|
|
27820
|
+
const resolveDependency = async (token) => {
|
|
27821
|
+
if (!token.value.startsWith(".")) return null;
|
|
27822
|
+
const absoluteRequest = path.resolve(path.dirname(cleanModuleId(id)), token.value);
|
|
27823
|
+
const resolved = await this.resolve(absoluteRequest, id);
|
|
27824
|
+
if (!resolved || resolved.external) return null;
|
|
27825
|
+
const resolvedId = cleanModuleId(resolved.id);
|
|
27826
|
+
const fileName = resolveRelativeOutputFileNameWithExtension(configService, resolvedId, ".js");
|
|
27827
|
+
return {
|
|
27828
|
+
dependency: {
|
|
27829
|
+
fileName,
|
|
27830
|
+
id: resolvedId
|
|
27831
|
+
},
|
|
27832
|
+
specifier: createRelativeModuleSpecifier(importerFileName, fileName)
|
|
27833
|
+
};
|
|
27834
|
+
};
|
|
27835
|
+
for (const token of requireTokens) {
|
|
27836
|
+
const resolved = await resolveDependency(token);
|
|
27837
|
+
if (!resolved) continue;
|
|
27838
|
+
dependencyRewrites.push({
|
|
27839
|
+
end: token.end,
|
|
27840
|
+
start: token.start,
|
|
27841
|
+
value: resolved.specifier
|
|
27842
|
+
});
|
|
27843
|
+
resolvedDependencies.push(resolved.dependency);
|
|
27844
|
+
}
|
|
27845
|
+
if (dynamicImports === "native" && configService.platform === "weapp") for (const token of dynamicImportTokens) {
|
|
27846
|
+
const resolved = await resolveDependency(token);
|
|
27847
|
+
if (!resolved) continue;
|
|
27848
|
+
const targetPackageRoot = resolveModulePackageRoot(resolved.dependency.id, configService.relativeAbsoluteSrcRoot, subPackageRoots);
|
|
27849
|
+
if (!isNativeSubPackageImport({
|
|
27850
|
+
dynamicImports,
|
|
27851
|
+
importerPackageRoot,
|
|
27852
|
+
independentTarget: scanService.independentSubPackageMap.has(targetPackageRoot),
|
|
27853
|
+
platform: configService.platform,
|
|
27854
|
+
request: token.value,
|
|
27855
|
+
targetPackageRoot
|
|
27856
|
+
})) continue;
|
|
27857
|
+
dependencyRewrites.push({
|
|
27858
|
+
end: token.end,
|
|
27859
|
+
start: token.start,
|
|
27860
|
+
value: resolved.specifier
|
|
27861
|
+
});
|
|
27862
|
+
nativeImportTokens.push(token);
|
|
27863
|
+
resolvedDependencies.push(resolved.dependency);
|
|
27864
|
+
}
|
|
27865
|
+
const rewritten = rewriteAsyncDependencies(code, {
|
|
27866
|
+
dependencyRewrites,
|
|
27867
|
+
nativeImportTokens,
|
|
27868
|
+
requireCallbackTokens
|
|
27869
|
+
});
|
|
27369
27870
|
return {
|
|
27370
|
-
code,
|
|
27371
|
-
ast,
|
|
27372
|
-
map: null,
|
|
27373
|
-
meta: {
|
|
27871
|
+
code: rewritten?.code ?? code,
|
|
27872
|
+
...rewritten ? {} : { ast },
|
|
27873
|
+
map: rewritten?.map ?? null,
|
|
27874
|
+
meta: { requireAsyncDependencies: resolvedDependencies }
|
|
27374
27875
|
};
|
|
27375
27876
|
} catch (error) {
|
|
27376
27877
|
logger_default.error(error);
|
|
@@ -27378,19 +27879,16 @@ function createRequireAnalysisPlugin(state) {
|
|
|
27378
27879
|
}
|
|
27379
27880
|
},
|
|
27380
27881
|
async moduleParsed(moduleInfo) {
|
|
27381
|
-
const
|
|
27382
|
-
if (!Array.isArray(
|
|
27383
|
-
for (const
|
|
27384
|
-
|
|
27385
|
-
|
|
27386
|
-
|
|
27387
|
-
await this.load(resolved);
|
|
27388
|
-
if (requireAsyncEmittedChunks.has(resolved.id)) continue;
|
|
27389
|
-
requireAsyncEmittedChunks.add(resolved.id);
|
|
27882
|
+
const dependencies = moduleInfo.meta.requireAsyncDependencies;
|
|
27883
|
+
if (!Array.isArray(dependencies)) return;
|
|
27884
|
+
for (const dependency of dependencies) {
|
|
27885
|
+
await this.load({ id: dependency.id });
|
|
27886
|
+
if (requireAsyncEmittedChunks.has(dependency.id)) continue;
|
|
27887
|
+
requireAsyncEmittedChunks.add(dependency.id);
|
|
27390
27888
|
this.emitFile({
|
|
27391
27889
|
type: "chunk",
|
|
27392
|
-
id:
|
|
27393
|
-
fileName:
|
|
27890
|
+
id: dependency.id,
|
|
27891
|
+
fileName: dependency.fileName,
|
|
27394
27892
|
preserveSignature: "exports-only"
|
|
27395
27893
|
});
|
|
27396
27894
|
}
|
|
@@ -27525,6 +28023,49 @@ function preflight(ctx) {
|
|
|
27525
28023
|
return [createPluginPruner(), createEnvSynchronizer(ctx)];
|
|
27526
28024
|
}
|
|
27527
28025
|
//#endregion
|
|
28026
|
+
//#region src/plugins/uniApp.ts
|
|
28027
|
+
const SUPPORTED_SOURCE_RE = /(?:\.vue|\.[cm]?[jt]sx?|\.(?:css|less|sass|scss|styl|stylus))(?:\?.*)?$/i;
|
|
28028
|
+
function resolveVirtualBlockType(id) {
|
|
28029
|
+
const queryIndex = id.indexOf("?");
|
|
28030
|
+
if (queryIndex < 0) return;
|
|
28031
|
+
const query = new URLSearchParams(id.slice(queryIndex + 1));
|
|
28032
|
+
const block = query.get("weapp-vite-sidecar") ?? (query.has("weapp-vite-vue") ? query.get("type") : void 0);
|
|
28033
|
+
return block === "script" || block === "template" || block === "style" ? block : block ? null : void 0;
|
|
28034
|
+
}
|
|
28035
|
+
function resolveIncludedPackage(id, include) {
|
|
28036
|
+
const normalized = id.replace(/\\/g, "/");
|
|
28037
|
+
return include.find((packageName) => normalized.includes(`/node_modules/${packageName}/`));
|
|
28038
|
+
}
|
|
28039
|
+
function uniAppCompatibility(ctx) {
|
|
28040
|
+
const configService = ctx.configService;
|
|
28041
|
+
const config = configService.weappViteConfig?.uniApp;
|
|
28042
|
+
if (!config || configService.platform !== "weapp") return [];
|
|
28043
|
+
return [{
|
|
28044
|
+
name: "weapp-vite:uni-app-compatibility",
|
|
28045
|
+
enforce: "pre",
|
|
28046
|
+
transform(code, id) {
|
|
28047
|
+
const blockType = resolveVirtualBlockType(id);
|
|
28048
|
+
if (id.startsWith("\0") || parseSidecarSourceRequest(id) || !SUPPORTED_SOURCE_RE.test(id) || blockType === null || !isUniAppCompatibilityFile(id, configService.absoluteSrcRoot, config.include)) return null;
|
|
28049
|
+
try {
|
|
28050
|
+
const result = transformUniAppSource(code, {
|
|
28051
|
+
blockType: blockType ?? void 0,
|
|
28052
|
+
filename: id,
|
|
28053
|
+
target: "mp-weixin"
|
|
28054
|
+
});
|
|
28055
|
+
return result.changed ? {
|
|
28056
|
+
code: result.code,
|
|
28057
|
+
map: null
|
|
28058
|
+
} : null;
|
|
28059
|
+
} catch (error) {
|
|
28060
|
+
const packageName = resolveIncludedPackage(id, config.include) ?? "<project-source>";
|
|
28061
|
+
const filename = id.split("?", 1)[0];
|
|
28062
|
+
const section = blockType ?? (filename.endsWith(".vue") ? "sfc" : "source");
|
|
28063
|
+
throw new Error(`[uni-app] package=${packageName} file=${filename} block=${section}: ${error instanceof Error ? error.message : String(error)}`);
|
|
28064
|
+
}
|
|
28065
|
+
}
|
|
28066
|
+
}];
|
|
28067
|
+
}
|
|
28068
|
+
//#endregion
|
|
27528
28069
|
//#region src/plugins/vue/transform/styleRequest.ts
|
|
27529
28070
|
const WEAPP_VUE_STYLE_VIRTUAL_PREFIX = "\0weapp-vite:vue-style:";
|
|
27530
28071
|
const WEAPP_VUE_STYLE_VIRTUAL_PREFIX_PLAIN = "weapp-vite:vue-style:";
|
|
@@ -27673,132 +28214,6 @@ function getSourceFromVirtualId(id) {
|
|
|
27673
28214
|
return id;
|
|
27674
28215
|
}
|
|
27675
28216
|
//#endregion
|
|
27676
|
-
//#region src/plugins/vue/transform/bundle/outputExtensions.ts
|
|
27677
|
-
function resolveBundleOutputExtensions(outputExtensions) {
|
|
27678
|
-
return resolveOutputExtensions(outputExtensions);
|
|
27679
|
-
}
|
|
27680
|
-
//#endregion
|
|
27681
|
-
//#region src/plugins/vue/transform/slotFallbackWrapper.ts
|
|
27682
|
-
const slotFallbackWrapperUsageByBundle = /* @__PURE__ */ new WeakMap();
|
|
27683
|
-
const slotFallbackWrapperScriptByBundle = /* @__PURE__ */ new WeakMap();
|
|
27684
|
-
function parseJsonSafely$1(source) {
|
|
27685
|
-
if (!source) return {};
|
|
27686
|
-
try {
|
|
27687
|
-
const parsed = JSON.parse(source);
|
|
27688
|
-
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
27689
|
-
} catch {
|
|
27690
|
-
return {};
|
|
27691
|
-
}
|
|
27692
|
-
}
|
|
27693
|
-
function stringifyJson(json) {
|
|
27694
|
-
return JSON.stringify(json, null, 2);
|
|
27695
|
-
}
|
|
27696
|
-
function isAsset(value) {
|
|
27697
|
-
return value?.type === "asset";
|
|
27698
|
-
}
|
|
27699
|
-
function getAssetSource(asset) {
|
|
27700
|
-
return asset?.source?.toString?.() ?? "";
|
|
27701
|
-
}
|
|
27702
|
-
function upsertSlotFallbackWrapperUsingComponent(json) {
|
|
27703
|
-
const usingComponents = json.usingComponents && typeof json.usingComponents === "object" && !Array.isArray(json.usingComponents) ? { ...json.usingComponents } : {};
|
|
27704
|
-
usingComponents[WEVU_SLOT_FALLBACK_VIRTUAL_HOST_TAG_NAME] = WEVU_SLOT_FALLBACK_VIRTUAL_HOST_GLOBAL_PATH;
|
|
27705
|
-
json.usingComponents = usingComponents;
|
|
27706
|
-
return json;
|
|
27707
|
-
}
|
|
27708
|
-
function normalizeJsonConfigForPlatform$1(json, compilerCtx) {
|
|
27709
|
-
const jsonPlatformOptions = resolveVueTransformJsonPlatformOptions(compilerCtx?.configService);
|
|
27710
|
-
if (!jsonPlatformOptions.normalizeUsingComponents) return json;
|
|
27711
|
-
try {
|
|
27712
|
-
const source = resolveJson({ json }, void 0, jsonPlatformOptions.platform, {
|
|
27713
|
-
dependencies: jsonPlatformOptions.dependencies,
|
|
27714
|
-
alipayNpmMode: jsonPlatformOptions.alipayNpmMode
|
|
27715
|
-
});
|
|
27716
|
-
return source ? JSON.parse(source) : json;
|
|
27717
|
-
} catch {
|
|
27718
|
-
return json;
|
|
27719
|
-
}
|
|
27720
|
-
}
|
|
27721
|
-
function getSlotFallbackWrapperUsage(bundle) {
|
|
27722
|
-
let usage = slotFallbackWrapperUsageByBundle.get(bundle);
|
|
27723
|
-
if (!usage) {
|
|
27724
|
-
usage = /* @__PURE__ */ new Set();
|
|
27725
|
-
slotFallbackWrapperUsageByBundle.set(bundle, usage);
|
|
27726
|
-
}
|
|
27727
|
-
return usage;
|
|
27728
|
-
}
|
|
27729
|
-
function markSlotFallbackWrapperUsage(bundle, relativeBase) {
|
|
27730
|
-
getSlotFallbackWrapperUsage(bundle).add(relativeBase);
|
|
27731
|
-
}
|
|
27732
|
-
function getSlotFallbackWrapperScriptCache(bundle) {
|
|
27733
|
-
let cache = slotFallbackWrapperScriptByBundle.get(bundle);
|
|
27734
|
-
if (!cache) {
|
|
27735
|
-
cache = /* @__PURE__ */ new Map();
|
|
27736
|
-
slotFallbackWrapperScriptByBundle.set(bundle, cache);
|
|
27737
|
-
}
|
|
27738
|
-
return cache;
|
|
27739
|
-
}
|
|
27740
|
-
function injectSlotFallbackWrapperIntoJsonAsset(bundle, jsonFileName, compilerCtx) {
|
|
27741
|
-
const output = bundle[jsonFileName];
|
|
27742
|
-
if (!isAsset(output)) return false;
|
|
27743
|
-
output.source = stringifyJson(normalizeJsonConfigForPlatform$1(upsertSlotFallbackWrapperUsingComponent(parseJsonSafely$1(getAssetSource(output))), compilerCtx));
|
|
27744
|
-
return true;
|
|
27745
|
-
}
|
|
27746
|
-
function injectGlobalSlotFallbackWrapperUsingComponent(bundle, compilerCtx, outputExtensions) {
|
|
27747
|
-
const { jsonExtension } = resolveBundleOutputExtensions(outputExtensions);
|
|
27748
|
-
const usage = slotFallbackWrapperUsageByBundle.get(bundle);
|
|
27749
|
-
if (!usage?.size) return false;
|
|
27750
|
-
if (injectSlotFallbackWrapperIntoJsonAsset(bundle, `app.${jsonExtension}`, compilerCtx)) return true;
|
|
27751
|
-
for (const relativeBase of usage) injectSlotFallbackWrapperIntoJsonAsset(bundle, `${relativeBase}.${jsonExtension}`, compilerCtx);
|
|
27752
|
-
return false;
|
|
27753
|
-
}
|
|
27754
|
-
function hasGlobalSlotFallbackWrapperUsingComponentAsset(bundle, outputExtensions) {
|
|
27755
|
-
const { jsonExtension } = resolveBundleOutputExtensions(outputExtensions);
|
|
27756
|
-
return isAsset(bundle[`app.${jsonExtension}`]);
|
|
27757
|
-
}
|
|
27758
|
-
function injectLocalSlotFallbackWrapperUsingComponentIfNeeded(options) {
|
|
27759
|
-
if (!options.result.slotFallbackWrapperComponent || hasGlobalSlotFallbackWrapperUsingComponentAsset(options.bundle, options.outputExtensions)) return false;
|
|
27760
|
-
const config = upsertSlotFallbackWrapperUsingComponent(parseJsonSafely$1(options.result.config));
|
|
27761
|
-
options.result.config = stringifyJson(normalizeJsonConfigForPlatform$1(config, options.compilerCtx));
|
|
27762
|
-
return true;
|
|
27763
|
-
}
|
|
27764
|
-
function emitSlotFallbackWrapperScriptIfMissing(ctx, bundle, fileName, script) {
|
|
27765
|
-
const existing = bundle[fileName];
|
|
27766
|
-
if (existing && existing.type === "asset") {
|
|
27767
|
-
if ((existing.source?.toString?.() ?? "") !== script) existing.source = script;
|
|
27768
|
-
return;
|
|
27769
|
-
}
|
|
27770
|
-
const cache = getSlotFallbackWrapperScriptCache(bundle);
|
|
27771
|
-
if (cache.get(fileName) === script) return;
|
|
27772
|
-
if (!existing) {
|
|
27773
|
-
ctx.emitFile({
|
|
27774
|
-
type: "asset",
|
|
27775
|
-
fileName,
|
|
27776
|
-
source: script
|
|
27777
|
-
});
|
|
27778
|
-
cache.set(fileName, script);
|
|
27779
|
-
}
|
|
27780
|
-
}
|
|
27781
|
-
function emitSlotFallbackWrapperComponentAsset(options) {
|
|
27782
|
-
const component = options.result.slotFallbackWrapperComponent;
|
|
27783
|
-
if (!component) return;
|
|
27784
|
-
const { templateExtension, jsonExtension, scriptExtension } = resolveBundleOutputExtensions(options.outputExtensions);
|
|
27785
|
-
const componentBase = WEVU_SLOT_FALLBACK_VIRTUAL_HOST_BASE;
|
|
27786
|
-
markSlotFallbackWrapperUsage(options.bundle, options.relativeBase);
|
|
27787
|
-
emitSfcTemplateIfMissing(options.ctx, options.bundle, componentBase, component.template, templateExtension);
|
|
27788
|
-
const jsonFileName = `${componentBase}.${jsonExtension}`;
|
|
27789
|
-
const mergeJson = createJsonMerger(options.jsonOptions?.mergeStrategy, {
|
|
27790
|
-
filename: jsonFileName,
|
|
27791
|
-
kind: "component"
|
|
27792
|
-
});
|
|
27793
|
-
let config = component.config;
|
|
27794
|
-
if (options.jsonOptions?.defaults && Object.keys(options.jsonOptions.defaults).length > 0) config = mergeJson(config, options.jsonOptions.defaults, "defaults");
|
|
27795
|
-
emitSfcJsonAsset(options.ctx, options.bundle, componentBase, { config: JSON.stringify(normalizeJsonConfigForPlatform$1(config, options.compilerCtx), null, 2) }, {
|
|
27796
|
-
kind: "component",
|
|
27797
|
-
extension: jsonExtension
|
|
27798
|
-
});
|
|
27799
|
-
emitSlotFallbackWrapperScriptIfMissing(options.ctx, options.bundle, `${componentBase}.${scriptExtension}`, component.script);
|
|
27800
|
-
}
|
|
27801
|
-
//#endregion
|
|
27802
28217
|
//#region src/plugins/vue/transform/classStyle.ts
|
|
27803
28218
|
function resolveClassStylePackageRoot(ctx, relativeBase, configService) {
|
|
27804
28219
|
const currentRoot = normalizeRoot(configService.currentSubPackageRoot ?? "");
|
|
@@ -27814,21 +28229,27 @@ function resolveClassStylePackageRoot(ctx, relativeBase, configService) {
|
|
|
27814
28229
|
return "";
|
|
27815
28230
|
}
|
|
27816
28231
|
function resolveClassStyleWxsLocationForBase(ctx, relativeBase, extension, configService) {
|
|
28232
|
+
const packageRoot = configService.weappViteConfig?.vue?.template?.classStyleWxsShared ?? true ? resolveClassStylePackageRoot(ctx, relativeBase, configService) : (() => {
|
|
28233
|
+
const dir = path.posix.dirname(toPosixPath(relativeBase));
|
|
28234
|
+
return dir === "." ? "" : dir;
|
|
28235
|
+
})();
|
|
27817
28236
|
return resolveClassStyleWxsLocation({
|
|
27818
28237
|
relativeBase,
|
|
27819
28238
|
extension,
|
|
27820
|
-
packageRoot
|
|
27821
|
-
const dir = path.posix.dirname(toPosixPath(relativeBase));
|
|
27822
|
-
return dir === "." ? "" : dir;
|
|
27823
|
-
})()
|
|
28239
|
+
packageRoot
|
|
27824
28240
|
});
|
|
27825
28241
|
}
|
|
27826
28242
|
//#endregion
|
|
28243
|
+
//#region src/plugins/vue/transform/bundle/outputExtensions.ts
|
|
28244
|
+
function resolveBundleOutputExtensions(outputExtensions) {
|
|
28245
|
+
return resolveOutputExtensions(outputExtensions);
|
|
28246
|
+
}
|
|
28247
|
+
//#endregion
|
|
27827
28248
|
//#region src/plugins/vue/transform/scopedSlot/assets.ts
|
|
27828
28249
|
function hasOwn(source, key) {
|
|
27829
28250
|
return Object.prototype.hasOwnProperty.call(source, key);
|
|
27830
28251
|
}
|
|
27831
|
-
function parseJsonSafely(source) {
|
|
28252
|
+
function parseJsonSafely$1(source) {
|
|
27832
28253
|
if (!source) return;
|
|
27833
28254
|
try {
|
|
27834
28255
|
return JSON.parse(source);
|
|
@@ -27836,7 +28257,11 @@ function parseJsonSafely(source) {
|
|
|
27836
28257
|
return;
|
|
27837
28258
|
}
|
|
27838
28259
|
}
|
|
27839
|
-
function
|
|
28260
|
+
function resolveScopedSlotOwnerStyleImport(relativeBase, styleExtension) {
|
|
28261
|
+
const normalizedBase = toPosixPath(relativeBase);
|
|
28262
|
+
return `@import './${normalizedBase.slice(normalizedBase.lastIndexOf("/") + 1)}.${styleExtension}';\n`;
|
|
28263
|
+
}
|
|
28264
|
+
function normalizeJsonConfigForPlatform$1(json, compilerCtx) {
|
|
27840
28265
|
const jsonPlatformOptions = resolveVueTransformJsonPlatformOptions(compilerCtx?.configService);
|
|
27841
28266
|
if (!jsonPlatformOptions.normalizeUsingComponents) return json;
|
|
27842
28267
|
try {
|
|
@@ -27909,8 +28334,10 @@ function registerScopedSlotHostGenerics(ctx, scopedSlots, baseUsingComponents) {
|
|
|
27909
28334
|
function emitScopedSlotAssets(ctx, bundle, relativeBase, result, compilerCtx, classStyleWxs, outputExtensions, jsonOptions) {
|
|
27910
28335
|
const scopedSlots = result.scopedSlotComponents;
|
|
27911
28336
|
if (!scopedSlots?.length) return;
|
|
27912
|
-
const { templateExtension, jsonExtension } = resolveBundleOutputExtensions(outputExtensions);
|
|
27913
|
-
const
|
|
28337
|
+
const { templateExtension, styleExtension, jsonExtension } = resolveBundleOutputExtensions(outputExtensions);
|
|
28338
|
+
const hasOwnerStyle = typeof result.style === "string" && result.style.trim().length > 0;
|
|
28339
|
+
if (hasOwnerStyle) emitSfcStyleIfMissing(ctx, bundle, relativeBase, "", styleExtension, { updateExisting: false });
|
|
28340
|
+
const configObj = parseJsonSafely$1(result.config) ?? {};
|
|
27914
28341
|
const baseUsingComponents = configObj.usingComponents && typeof configObj.usingComponents === "object" && !Array.isArray(configObj.usingComponents) ? { ...configObj.usingComponents } : {};
|
|
27915
28342
|
const usingComponents = { ...baseUsingComponents };
|
|
27916
28343
|
registerScopedSlotHostGenerics(compilerCtx, scopedSlots, baseUsingComponents);
|
|
@@ -27919,6 +28346,7 @@ function emitScopedSlotAssets(ctx, bundle, relativeBase, result, compilerCtx, cl
|
|
|
27919
28346
|
const componentPath = `/${toPosixPath(componentBase)}`;
|
|
27920
28347
|
usingComponents[scopedSlot.componentName] = componentPath;
|
|
27921
28348
|
const wxmlFile = `${componentBase}.${templateExtension}`;
|
|
28349
|
+
const styleFile = `${componentBase}.${styleExtension}`;
|
|
27922
28350
|
const jsonFile = `${componentBase}.${jsonExtension}`;
|
|
27923
28351
|
const scopedUsingComponents = resolveScopedSlotAutoImports(compilerCtx, baseUsingComponents, componentBase, scopedSlot.template);
|
|
27924
28352
|
Object.assign(scopedUsingComponents, resolveNestedScopedSlotUsingComponents(scopedSlots, scopedSlot.componentName, relativeBase, scopedSlot.template));
|
|
@@ -27927,6 +28355,11 @@ function emitScopedSlotAssets(ctx, bundle, relativeBase, result, compilerCtx, cl
|
|
|
27927
28355
|
fileName: wxmlFile,
|
|
27928
28356
|
source: scopedSlot.template
|
|
27929
28357
|
});
|
|
28358
|
+
if (hasOwnerStyle && !bundle[styleFile]) ctx.emitFile({
|
|
28359
|
+
type: "asset",
|
|
28360
|
+
fileName: styleFile,
|
|
28361
|
+
source: resolveScopedSlotOwnerStyleImport(relativeBase, styleExtension)
|
|
28362
|
+
});
|
|
27930
28363
|
if (!bundle[jsonFile]) {
|
|
27931
28364
|
const mergeJson = createJsonMerger(jsonOptions?.mergeStrategy, {
|
|
27932
28365
|
filename: jsonFile,
|
|
@@ -27941,7 +28374,7 @@ function emitScopedSlotAssets(ctx, bundle, relativeBase, result, compilerCtx, cl
|
|
|
27941
28374
|
};
|
|
27942
28375
|
json = mergeJson(defaultConfig, json, "emit");
|
|
27943
28376
|
if (hasOwn(defaultConfig, "component")) json.component = true;
|
|
27944
|
-
const normalizedJson = normalizeJsonConfigForPlatform(json, compilerCtx);
|
|
28377
|
+
const normalizedJson = normalizeJsonConfigForPlatform$1(json, compilerCtx);
|
|
27945
28378
|
ctx.emitFile({
|
|
27946
28379
|
type: "asset",
|
|
27947
28380
|
fileName: jsonFile,
|
|
@@ -27951,7 +28384,7 @@ function emitScopedSlotAssets(ctx, bundle, relativeBase, result, compilerCtx, cl
|
|
|
27951
28384
|
if (scopedSlot.classStyleWxs && classStyleWxs) emitClassStyleWxsAssetIfMissing(ctx, bundle, classStyleWxs.fileName, classStyleWxs.source);
|
|
27952
28385
|
}
|
|
27953
28386
|
configObj.usingComponents = usingComponents;
|
|
27954
|
-
result.config = JSON.stringify(normalizeJsonConfigForPlatform(configObj, compilerCtx), null, 2);
|
|
28387
|
+
result.config = JSON.stringify(normalizeJsonConfigForPlatform$1(configObj, compilerCtx), null, 2);
|
|
27955
28388
|
}
|
|
27956
28389
|
//#endregion
|
|
27957
28390
|
//#region src/plugins/vue/transform/scopedSlot/module.ts
|
|
@@ -27963,20 +28396,31 @@ function buildInlineExpressionMapCode(inlineExpressions) {
|
|
|
27963
28396
|
return `${JSON.stringify(entry.id)}:{keys:${keys},fn:(ctx,scope,$event)=>${entry.expression}}`;
|
|
27964
28397
|
}).join(",")}}`;
|
|
27965
28398
|
}
|
|
28399
|
+
function buildTemplateRefsCode(templateRefs) {
|
|
28400
|
+
if (!templateRefs?.length) return null;
|
|
28401
|
+
return `[${templateRefs.map((binding) => {
|
|
28402
|
+
const fields = [`selector:${JSON.stringify(binding.selector)}`, `inFor:${binding.inFor}`];
|
|
28403
|
+
if (binding.name) fields.push(`name:${JSON.stringify(binding.name)}`);
|
|
28404
|
+
if (binding.expAst) fields.push(`get:function(){return ${generate(binding.expAst, { compact: true }).code}}`);
|
|
28405
|
+
if (binding.kind) fields.push(`kind:${JSON.stringify(binding.kind)}`);
|
|
28406
|
+
return `{${fields.join(",")}}`;
|
|
28407
|
+
}).join(",")}]`;
|
|
28408
|
+
}
|
|
27966
28409
|
function buildScopedSlotComponentModule(options) {
|
|
27967
28410
|
const computedCode = options?.computedCode;
|
|
27968
28411
|
const inlineMapCode = options?.inlineMapCode;
|
|
28412
|
+
const templateRefsCode = options?.templateRefsCode;
|
|
27969
28413
|
const lines = [`import { ${WE_VU_RUNTIME_APIS.createWevuScopedSlotComponent} as _createWevuScopedSlotComponent } from '${WE_VU_COMPILER_RUNTIME_MODULE_ID}';`];
|
|
27970
|
-
if (computedCode) {
|
|
27971
|
-
|
|
27972
|
-
lines.push(`import { unref as __wevuUnref } from '${WE_VU_COMPILER_REACTIVITY_MODULE_ID}';`);
|
|
27973
|
-
}
|
|
28414
|
+
if (computedCode) lines.push(`import { normalizeClass as __wevuNormalizeClass, normalizeStyle as __wevuNormalizeStyle } from '${WE_VU_COMPILER_TEMPLATE_MODULE_ID}';`);
|
|
28415
|
+
if (computedCode || templateRefsCode) lines.push(`import { unref as __wevuUnref } from '${WE_VU_COMPILER_REACTIVITY_MODULE_ID}';`);
|
|
27974
28416
|
lines.push("const globalObject = typeof globalThis !== 'undefined' ? globalThis : undefined;", `const createWevuScopedSlotComponent = globalObject?.${WEVU_SCOPED_SLOT_CREATOR_KEY}`, " ?? _createWevuScopedSlotComponent;");
|
|
27975
28417
|
if (computedCode) lines.push(`const __wevuComputed = ${computedCode};`);
|
|
27976
28418
|
if (inlineMapCode) lines.push(`const __wevuInlineMap = ${inlineMapCode};`);
|
|
28419
|
+
if (templateRefsCode) lines.push(`const __wevuTemplateRefs = ${templateRefsCode};`);
|
|
27977
28420
|
const overrideParts = [];
|
|
27978
28421
|
if (computedCode) overrideParts.push("computed: __wevuComputed");
|
|
27979
28422
|
if (inlineMapCode) overrideParts.push("inlineMap: __wevuInlineMap");
|
|
28423
|
+
if (templateRefsCode) overrideParts.push("templateRefs: __wevuTemplateRefs");
|
|
27980
28424
|
const overrideArg = overrideParts.length ? `{ ${overrideParts.join(", ")} }` : "";
|
|
27981
28425
|
lines.push("if (typeof createWevuScopedSlotComponent === 'function') {");
|
|
27982
28426
|
if (overrideArg) lines.push(` createWevuScopedSlotComponent(${overrideArg});`);
|
|
@@ -28004,9 +28448,11 @@ function emitScopedSlotChunks(ctx, relativeBase, result, scopedSlotModules, emit
|
|
|
28004
28448
|
unrefName: "__wevuUnref"
|
|
28005
28449
|
}) : null;
|
|
28006
28450
|
const inlineMapCode = buildInlineExpressionMapCode(scopedSlot.inlineExpressions);
|
|
28007
|
-
|
|
28451
|
+
const templateRefsCode = buildTemplateRefsCode(scopedSlot.templateRefs);
|
|
28452
|
+
scopedSlotModules.set(virtualId, buildScopedSlotComponentModule(computedCode || inlineMapCode || templateRefsCode ? {
|
|
28008
28453
|
computedCode: computedCode ?? void 0,
|
|
28009
|
-
inlineMapCode: inlineMapCode ?? void 0
|
|
28454
|
+
inlineMapCode: inlineMapCode ?? void 0,
|
|
28455
|
+
templateRefsCode: templateRefsCode ?? void 0
|
|
28010
28456
|
} : void 0));
|
|
28011
28457
|
}
|
|
28012
28458
|
ctx.emitFile({
|
|
@@ -28032,6 +28478,90 @@ function loadScopedSlotModule(id, scopedSlotModules) {
|
|
|
28032
28478
|
};
|
|
28033
28479
|
}
|
|
28034
28480
|
//#endregion
|
|
28481
|
+
//#region src/plugins/vue/transform/slotFallbackWrapper.ts
|
|
28482
|
+
const slotFallbackWrapperScriptByBundle = /* @__PURE__ */ new WeakMap();
|
|
28483
|
+
function parseJsonSafely(source) {
|
|
28484
|
+
if (!source) return {};
|
|
28485
|
+
try {
|
|
28486
|
+
const parsed = JSON.parse(source);
|
|
28487
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
28488
|
+
} catch {
|
|
28489
|
+
return {};
|
|
28490
|
+
}
|
|
28491
|
+
}
|
|
28492
|
+
function stringifyJson(json) {
|
|
28493
|
+
return JSON.stringify(json, null, 2);
|
|
28494
|
+
}
|
|
28495
|
+
function upsertSlotFallbackWrapperUsingComponent(json) {
|
|
28496
|
+
const usingComponents = json.usingComponents && typeof json.usingComponents === "object" && !Array.isArray(json.usingComponents) ? { ...json.usingComponents } : {};
|
|
28497
|
+
usingComponents[WEVU_SLOT_FALLBACK_VIRTUAL_HOST_TAG_NAME] = WEVU_SLOT_FALLBACK_VIRTUAL_HOST_GLOBAL_PATH;
|
|
28498
|
+
json.usingComponents = usingComponents;
|
|
28499
|
+
return json;
|
|
28500
|
+
}
|
|
28501
|
+
function normalizeJsonConfigForPlatform(json, compilerCtx) {
|
|
28502
|
+
const jsonPlatformOptions = resolveVueTransformJsonPlatformOptions(compilerCtx?.configService);
|
|
28503
|
+
if (!jsonPlatformOptions.normalizeUsingComponents) return json;
|
|
28504
|
+
try {
|
|
28505
|
+
const source = resolveJson({ json }, void 0, jsonPlatformOptions.platform, {
|
|
28506
|
+
dependencies: jsonPlatformOptions.dependencies,
|
|
28507
|
+
alipayNpmMode: jsonPlatformOptions.alipayNpmMode
|
|
28508
|
+
});
|
|
28509
|
+
return source ? JSON.parse(source) : json;
|
|
28510
|
+
} catch {
|
|
28511
|
+
return json;
|
|
28512
|
+
}
|
|
28513
|
+
}
|
|
28514
|
+
function getSlotFallbackWrapperScriptCache(bundle) {
|
|
28515
|
+
let cache = slotFallbackWrapperScriptByBundle.get(bundle);
|
|
28516
|
+
if (!cache) {
|
|
28517
|
+
cache = /* @__PURE__ */ new Map();
|
|
28518
|
+
slotFallbackWrapperScriptByBundle.set(bundle, cache);
|
|
28519
|
+
}
|
|
28520
|
+
return cache;
|
|
28521
|
+
}
|
|
28522
|
+
function injectLocalSlotFallbackWrapperUsingComponentIfNeeded(options) {
|
|
28523
|
+
if (!options.result.slotFallbackWrapperComponent) return false;
|
|
28524
|
+
const config = upsertSlotFallbackWrapperUsingComponent(parseJsonSafely(options.result.config));
|
|
28525
|
+
options.result.config = stringifyJson(normalizeJsonConfigForPlatform(config, options.compilerCtx));
|
|
28526
|
+
return true;
|
|
28527
|
+
}
|
|
28528
|
+
function emitSlotFallbackWrapperScriptIfMissing(ctx, bundle, fileName, script) {
|
|
28529
|
+
const existing = bundle[fileName];
|
|
28530
|
+
if (existing && existing.type === "asset") {
|
|
28531
|
+
if ((existing.source?.toString?.() ?? "") !== script) existing.source = script;
|
|
28532
|
+
return;
|
|
28533
|
+
}
|
|
28534
|
+
const cache = getSlotFallbackWrapperScriptCache(bundle);
|
|
28535
|
+
if (cache.get(fileName) === script) return;
|
|
28536
|
+
if (!existing) {
|
|
28537
|
+
ctx.emitFile({
|
|
28538
|
+
type: "asset",
|
|
28539
|
+
fileName,
|
|
28540
|
+
source: script
|
|
28541
|
+
});
|
|
28542
|
+
cache.set(fileName, script);
|
|
28543
|
+
}
|
|
28544
|
+
}
|
|
28545
|
+
function emitSlotFallbackWrapperComponentAsset(options) {
|
|
28546
|
+
const component = options.result.slotFallbackWrapperComponent;
|
|
28547
|
+
if (!component) return;
|
|
28548
|
+
const { templateExtension, jsonExtension, scriptExtension } = resolveBundleOutputExtensions(options.outputExtensions);
|
|
28549
|
+
const componentBase = WEVU_SLOT_FALLBACK_VIRTUAL_HOST_BASE;
|
|
28550
|
+
emitSfcTemplateIfMissing(options.ctx, options.bundle, componentBase, component.template, templateExtension);
|
|
28551
|
+
const jsonFileName = `${componentBase}.${jsonExtension}`;
|
|
28552
|
+
const mergeJson = createJsonMerger(options.jsonOptions?.mergeStrategy, {
|
|
28553
|
+
filename: jsonFileName,
|
|
28554
|
+
kind: "component"
|
|
28555
|
+
});
|
|
28556
|
+
let config = component.config;
|
|
28557
|
+
if (options.jsonOptions?.defaults && Object.keys(options.jsonOptions.defaults).length > 0) config = mergeJson(config, options.jsonOptions.defaults, "defaults");
|
|
28558
|
+
emitSfcJsonAsset(options.ctx, options.bundle, componentBase, { config: JSON.stringify(normalizeJsonConfigForPlatform(config, options.compilerCtx), null, 2) }, {
|
|
28559
|
+
kind: "component",
|
|
28560
|
+
extension: jsonExtension
|
|
28561
|
+
});
|
|
28562
|
+
emitSlotFallbackWrapperScriptIfMissing(options.ctx, options.bundle, `${componentBase}.${scriptExtension}`, component.script);
|
|
28563
|
+
}
|
|
28564
|
+
//#endregion
|
|
28035
28565
|
//#region src/plugins/vue/transform/bundle/shared/assets.ts
|
|
28036
28566
|
const APP_VUE_LIKE_FILE_RE$1 = /[\\/]app\.(?:vue|jsx|tsx)$/;
|
|
28037
28567
|
async function processVueResultStyle(style, configService) {
|
|
@@ -28215,8 +28745,11 @@ async function emitCompiledEntryBundleAssets(options) {
|
|
|
28215
28745
|
function hasVueExtension(id) {
|
|
28216
28746
|
return Boolean(id?.endsWith(".vue"));
|
|
28217
28747
|
}
|
|
28218
|
-
function getCompileVueFileOptionsCacheKey(vuePath, isPage, isApp) {
|
|
28219
|
-
return `${vuePath}::${isPage ? "page" : "component"}::${isApp ? "app" : "entry"}`;
|
|
28748
|
+
function getCompileVueFileOptionsCacheKey(vuePath, isPage, isApp, delegatesComponentRegistration = false) {
|
|
28749
|
+
return `${vuePath}::${isPage ? "page" : "component"}::${isApp ? "app" : "entry"}::${delegatesComponentRegistration ? "logical-registration" : "module-registration"}`;
|
|
28750
|
+
}
|
|
28751
|
+
function shouldDelegateComponentRegistration(ctx, vuePath, isPage, isApp, configService) {
|
|
28752
|
+
return !isPage && !isApp && !configService.weappLibConfig?.enabled && !ctx.moduleGraphService?.isLogicalLayoutEntry?.(vuePath);
|
|
28220
28753
|
}
|
|
28221
28754
|
function isVueTransformSourceMapEnabled(configService) {
|
|
28222
28755
|
return Boolean(configService.inlineConfig?.build?.sourcemap);
|
|
@@ -28240,7 +28773,7 @@ function resolveVueTemplatePlatformOptions(options) {
|
|
|
28240
28773
|
classStyleRuntime
|
|
28241
28774
|
};
|
|
28242
28775
|
}
|
|
28243
|
-
function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, configService, state) {
|
|
28776
|
+
function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, configService, state, delegatesComponentRegistration) {
|
|
28244
28777
|
const importerBaseName = removeExtensionDeep(vuePath);
|
|
28245
28778
|
const autoImportResolveCache = /* @__PURE__ */ new Map();
|
|
28246
28779
|
const scopedSlotsCompiler = configService.weappViteConfig?.vue?.template?.scopedSlotsCompiler ?? "auto";
|
|
@@ -28333,6 +28866,7 @@ function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, conf
|
|
|
28333
28866
|
return {
|
|
28334
28867
|
isPage,
|
|
28335
28868
|
isApp,
|
|
28869
|
+
skipComponentTransform: delegatesComponentRegistration,
|
|
28336
28870
|
warn: (message) => logger_default.warn(message),
|
|
28337
28871
|
autoUsingComponents: {
|
|
28338
28872
|
enabled: true,
|
|
@@ -28354,9 +28888,12 @@ function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, conf
|
|
|
28354
28888
|
});
|
|
28355
28889
|
if (!match?.value) return;
|
|
28356
28890
|
const sourceInfo = await resolveAutoImportComponentSourceType(match);
|
|
28891
|
+
const stableFrom = sourceInfo.sourceType === "wevu-sfc" ? usingComponentFromResolvedFile(sourceInfo.resolvedId, configService) : void 0;
|
|
28892
|
+
if (stableFrom && sourceInfo.resolvedId) ctx.runtimeState?.build?.hmr?.externalComponentEntryMap?.set(removeExtensionDeep(stableFrom).replace(/^\/+/, ""), sourceInfo.resolvedId);
|
|
28357
28893
|
return {
|
|
28358
28894
|
...match.value,
|
|
28359
|
-
...sourceInfo
|
|
28895
|
+
...sourceInfo,
|
|
28896
|
+
...stableFrom ? { from: stableFrom } : {}
|
|
28360
28897
|
};
|
|
28361
28898
|
}
|
|
28362
28899
|
},
|
|
@@ -28391,36 +28928,15 @@ function buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, conf
|
|
|
28391
28928
|
};
|
|
28392
28929
|
}
|
|
28393
28930
|
function createCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, configService, state) {
|
|
28394
|
-
const
|
|
28931
|
+
const delegatesComponentRegistration = shouldDelegateComponentRegistration(ctx, vuePath, isPage, isApp, configService);
|
|
28932
|
+
const cacheKey = getCompileVueFileOptionsCacheKey(vuePath, isPage, isApp, delegatesComponentRegistration);
|
|
28395
28933
|
const cached = state.compileOptionsCache?.get(cacheKey);
|
|
28396
28934
|
if (cached) return cached;
|
|
28397
|
-
const created = buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, configService, state);
|
|
28935
|
+
const created = buildCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, configService, state, delegatesComponentRegistration);
|
|
28398
28936
|
state.compileOptionsCache?.set(cacheKey, created);
|
|
28399
28937
|
return created;
|
|
28400
28938
|
}
|
|
28401
28939
|
//#endregion
|
|
28402
|
-
//#region src/utils/sourcemap.ts
|
|
28403
|
-
function isEncodedSourceMapLike(value) {
|
|
28404
|
-
return Boolean(value && typeof value === "object" && "version" in value && typeof value.version === "number" && "mappings" in value && "names" in value && "sources" in value);
|
|
28405
|
-
}
|
|
28406
|
-
function normalizeEncodedSourceMapLike(value) {
|
|
28407
|
-
if (!value || typeof value !== "object") return null;
|
|
28408
|
-
const sourceMap = value;
|
|
28409
|
-
const numericVersion = typeof sourceMap.version === "number" ? sourceMap.version : typeof sourceMap.version === "string" ? Number(sourceMap.version) : NaN;
|
|
28410
|
-
if (!Number.isFinite(numericVersion)) return null;
|
|
28411
|
-
const normalized = {
|
|
28412
|
-
...sourceMap,
|
|
28413
|
-
version: numericVersion
|
|
28414
|
-
};
|
|
28415
|
-
return isEncodedSourceMapLike(normalized) ? normalized : null;
|
|
28416
|
-
}
|
|
28417
|
-
function composeSourceMaps(transformedMap, originalMap) {
|
|
28418
|
-
if (isEncodedSourceMapLike(transformedMap) && isEncodedSourceMapLike(originalMap)) return remapping([transformedMap, originalMap], () => null);
|
|
28419
|
-
if (isEncodedSourceMapLike(transformedMap)) return transformedMap;
|
|
28420
|
-
if (isEncodedSourceMapLike(originalMap)) return originalMap;
|
|
28421
|
-
return null;
|
|
28422
|
-
}
|
|
28423
|
-
//#endregion
|
|
28424
28940
|
//#region src/plugins/utils/viteResolverAdapter.ts
|
|
28425
28941
|
const WINDOWS_ABSOLUTE_PATH_RE = /^[A-Z]:[\\/]/i;
|
|
28426
28942
|
function isExplicitFileRequest(id) {
|
|
@@ -28841,7 +29357,8 @@ async function finalizeTransformEntryScript(options) {
|
|
|
28841
29357
|
}
|
|
28842
29358
|
function finalizeTransformEntryCode(options) {
|
|
28843
29359
|
const { result, filename, styleBlocks, isPage, isApp, isDev, sourceMap = true, hmrStyleToken } = options;
|
|
28844
|
-
const
|
|
29360
|
+
const script = result.script ?? "";
|
|
29361
|
+
const returned = new MagicString(script);
|
|
28845
29362
|
let hasMutation = false;
|
|
28846
29363
|
if (styleBlocks?.length) {
|
|
28847
29364
|
const styleImports = buildWeappVueStyleRequests(filename, styleBlocks, { hmrToken: hmrStyleToken }).map((request) => `import ${JSON.stringify(request)};\n`).join("");
|
|
@@ -29310,7 +29827,11 @@ async function emitBundlePageLayoutsIfNeeded(options) {
|
|
|
29310
29827
|
emitVueLayout: layoutEmitters.emitVueLayout
|
|
29311
29828
|
});
|
|
29312
29829
|
}
|
|
29313
|
-
function
|
|
29830
|
+
function resolveAppShellUsingComponents(template, usingComponents) {
|
|
29831
|
+
const templateComponents = scanWxml(template, { excludeComponent: () => false }).autoImportComponents ?? {};
|
|
29832
|
+
return Object.fromEntries(Object.entries(usingComponents).filter(([name]) => Reflect.has(templateComponents, name)));
|
|
29833
|
+
}
|
|
29834
|
+
function resolveAppShellComponentConfig(config, template) {
|
|
29314
29835
|
const shellConfig = { styleIsolation: "apply-shared" };
|
|
29315
29836
|
if (!config) return JSON.stringify(shellConfig, null, 2);
|
|
29316
29837
|
try {
|
|
@@ -29318,7 +29839,10 @@ function resolveAppShellComponentConfig(config) {
|
|
|
29318
29839
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return JSON.stringify(shellConfig, null, 2);
|
|
29319
29840
|
for (const key of ["usingComponents", "componentGenerics"]) {
|
|
29320
29841
|
const value = parsed[key];
|
|
29321
|
-
if (value && typeof value === "object" && !Array.isArray(value))
|
|
29842
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
29843
|
+
const normalizedValue = key === "usingComponents" ? resolveAppShellUsingComponents(template, value) : value;
|
|
29844
|
+
if (Object.keys(normalizedValue).length > 0) shellConfig[key] = normalizedValue;
|
|
29845
|
+
}
|
|
29322
29846
|
}
|
|
29323
29847
|
return Object.keys(shellConfig).length ? JSON.stringify(shellConfig, null, 2) : void 0;
|
|
29324
29848
|
} catch {
|
|
@@ -29350,7 +29874,7 @@ function emitAppShellAssetsIfNeeded(options) {
|
|
|
29350
29874
|
bundle: options.bundle,
|
|
29351
29875
|
pluginCtx: options.pluginCtx,
|
|
29352
29876
|
relativeBase,
|
|
29353
|
-
config: resolveAppShellComponentConfig(result.config),
|
|
29877
|
+
config: resolveAppShellComponentConfig(result.config, result.template),
|
|
29354
29878
|
outputExtensions: options.outputExtensions,
|
|
29355
29879
|
platformAssetOptions: options.platformAssetOptions,
|
|
29356
29880
|
jsonOptions: {
|
|
@@ -29377,7 +29901,8 @@ function hasUnresolvedModuleImportDeclaration(script) {
|
|
|
29377
29901
|
if (!script?.includes("import")) return false;
|
|
29378
29902
|
try {
|
|
29379
29903
|
let hasUnresolvedImport = false;
|
|
29380
|
-
|
|
29904
|
+
const ast = parseJsLike(script);
|
|
29905
|
+
traverse(ast, { ImportDeclaration(path) {
|
|
29381
29906
|
const source = path.node.source.value;
|
|
29382
29907
|
if (typeof source === "string" && !(source === "wevu" || source === "wevu/router" || source === "wevu/store" || source === "wevu/api" || source === "wevu/fetch" || source === "wevu/web-apis" || source === "wevu/internal-runtime" || source === "wevu/internal-reactivity" || source === "wevu/internal-template" || Object.values(WEAPP_VITE_RUNTIME_VIRTUAL_IDS).includes(source))) {
|
|
29383
29908
|
hasUnresolvedImport = true;
|
|
@@ -29684,7 +30209,6 @@ async function emitVueBundleAssets(bundle, state) {
|
|
|
29684
30209
|
if (!emitState) return;
|
|
29685
30210
|
await emitCompiledBundleEntries(bundle, state, emitState.compilationEntries);
|
|
29686
30211
|
await emitFallbackPageAssets(bundle, state, { emittedEntryIds: emitState.emittedEntryIds });
|
|
29687
|
-
injectGlobalSlotFallbackWrapperUsingComponent(bundle, state.ctx, state.ctx.configService.outputExtensions);
|
|
29688
30212
|
}
|
|
29689
30213
|
//#endregion
|
|
29690
30214
|
//#region src/plugins/wevu.ts
|
|
@@ -30440,7 +30964,7 @@ async function transformWxsFile(state, wxsPath) {
|
|
|
30440
30964
|
const dirname = path.dirname(wxsPath);
|
|
30441
30965
|
const importeePaths = importees.map(({ source }) => path.resolve(dirname, source));
|
|
30442
30966
|
await Promise.all(importeePaths.map((importeePath) => transformWxsFile.call(this, state, importeePath)));
|
|
30443
|
-
if (code
|
|
30967
|
+
if (code == null) return;
|
|
30444
30968
|
const emittedFile = {
|
|
30445
30969
|
type: "asset",
|
|
30446
30970
|
fileName: resolveWxsOutputFileName(ctx, wxsPath, scriptModuleExtension),
|
|
@@ -30554,6 +31078,7 @@ function vitePluginWeapp(ctx, subPackageMeta) {
|
|
|
30554
31078
|
const groups = [
|
|
30555
31079
|
[createContextPlugin(ctx), createSelectedRuntimeProviderPlugin(runtimeProvider, ctx.configService.isDev)],
|
|
30556
31080
|
preflight(ctx),
|
|
31081
|
+
uniAppCompatibility(ctx),
|
|
30557
31082
|
vue(ctx, { enable: vueEnabled })
|
|
30558
31083
|
];
|
|
30559
31084
|
if (vueEnabled && !libModeEnabled) groups.push(wevu(ctx));
|
|
@@ -30705,6 +31230,7 @@ function mergeMiniprogram(options, ...configs) {
|
|
|
30705
31230
|
const npmBuildCandidates = packageJson ? resolveNpmBuildCandidateDependenciesSync(ctx, packageJson) : [];
|
|
30706
31231
|
if (npmBuildCandidates.length > 0) {
|
|
30707
31232
|
const builtinAliases = resolveBuiltinPackageAliases({
|
|
31233
|
+
cwd,
|
|
30708
31234
|
isDev,
|
|
30709
31235
|
wevuRuntime: config.weapp?.wevu?.runtime
|
|
30710
31236
|
});
|
|
@@ -30836,11 +31362,13 @@ function mergeWeb(options, ...configs) {
|
|
|
30836
31362
|
stripRollupOptions(inline);
|
|
30837
31363
|
inline.root = web.root;
|
|
30838
31364
|
inline.configFile = false;
|
|
30839
|
-
inline.mode = inline.mode ?? mode;
|
|
30840
31365
|
const runtimeProvider = resolveRuntimeProvider("web", "web");
|
|
30841
31366
|
const runtimeProviderPlugin = createSelectedRuntimeProviderPlugin(runtimeProvider, isDev);
|
|
30842
31367
|
const webPlugin = weappWebPlugin({
|
|
30843
31368
|
...web.pluginOptions,
|
|
31369
|
+
__uniApp: options.uniApp || void 0,
|
|
31370
|
+
__autoImportResolvers: options.autoImportResolvers,
|
|
31371
|
+
__resolveAppConfig: options.resolveAppConfig,
|
|
30844
31372
|
__runtimeProvider: {
|
|
30845
31373
|
moduleId: WEAPP_VITE_RUNTIME_VIRTUAL_ID,
|
|
30846
31374
|
hmrAcceptCode: resolveRuntimeProviderHmrFooter(runtimeProvider)
|
|
@@ -30851,8 +31379,19 @@ function mergeWeb(options, ...configs) {
|
|
|
30851
31379
|
inline.build.outDir = web.outDir;
|
|
30852
31380
|
inline.build.emptyOutDir ??= !isDev;
|
|
30853
31381
|
applyWeappViteHostMeta(inline, "web", "web");
|
|
30854
|
-
inline.define = defu(inline.define
|
|
30855
|
-
injectBuiltinAliases(inline);
|
|
31382
|
+
inline.define = defu(inline.define, getDefineImportMetaEnv());
|
|
31383
|
+
injectBuiltinAliases(inline, "build");
|
|
31384
|
+
const runtimeAlias = {
|
|
31385
|
+
find: "weapp-vite/runtime",
|
|
31386
|
+
replacement: WEAPP_VITE_RUNTIME_VIRTUAL_ID
|
|
31387
|
+
};
|
|
31388
|
+
inline.resolve ??= {};
|
|
31389
|
+
const aliases = inline.resolve.alias;
|
|
31390
|
+
if (Array.isArray(aliases)) inline.resolve.alias = [runtimeAlias, ...aliases.filter((alias) => !(typeof alias === "object" && alias !== null && "find" in alias && alias.find === runtimeAlias.find))];
|
|
31391
|
+
else inline.resolve.alias = [runtimeAlias, ...Object.entries(aliases ?? {}).filter(([find]) => find !== runtimeAlias.find).map(([find, replacement]) => ({
|
|
31392
|
+
find,
|
|
31393
|
+
replacement
|
|
31394
|
+
}))];
|
|
30856
31395
|
return inline;
|
|
30857
31396
|
}
|
|
30858
31397
|
//#endregion
|
|
@@ -30902,7 +31441,7 @@ function createMergeFactories(options) {
|
|
|
30902
31441
|
ensureConfigService(ctx);
|
|
30903
31442
|
const currentOptions = getOptions();
|
|
30904
31443
|
const configService = ctx.configService;
|
|
30905
|
-
const subPackageRoots = Object.keys(configService.weappViteConfig
|
|
31444
|
+
const subPackageRoots = Object.keys(configService.weappViteConfig.subPackages ?? {});
|
|
30906
31445
|
const sharedOutput = configService.options.chunksConfigured ? createSharedBuildOutput(configService, () => subPackageRoots) : void 0;
|
|
30907
31446
|
return mergeWorkers({
|
|
30908
31447
|
ctx,
|
|
@@ -30946,7 +31485,7 @@ function createMergeFactories(options) {
|
|
|
30946
31485
|
const currentOptions = getOptions();
|
|
30947
31486
|
const configService = ctx.configService;
|
|
30948
31487
|
const subPackageRoots = Object.keys(configService.weappViteConfig?.subPackages ?? {});
|
|
30949
|
-
const sharedOutput = configService.options.chunksConfigured ? createSharedBuildOutput(configService, () => subPackageRoots) : void 0;
|
|
31488
|
+
const sharedOutput = configService.options.chunksConfigured ? createSharedBuildOutput(configService, () => subPackageRoots, { runtime: "web" }) : void 0;
|
|
30950
31489
|
return backend.driver.mergeConfig({ merge: (...backendConfigs) => mergeWeb({
|
|
30951
31490
|
config: currentOptions.config,
|
|
30952
31491
|
web: currentOptions.weappWeb,
|
|
@@ -30954,7 +31493,10 @@ function createMergeFactories(options) {
|
|
|
30954
31493
|
isDev: currentOptions.isDev,
|
|
30955
31494
|
applyRuntimePlatform,
|
|
30956
31495
|
injectBuiltinAliases,
|
|
30957
|
-
getDefineImportMetaEnv
|
|
31496
|
+
getDefineImportMetaEnv,
|
|
31497
|
+
uniApp: configService.weappViteConfig.uniApp,
|
|
31498
|
+
autoImportResolvers: typeof configService.weappViteConfig.autoImportComponents === "object" ? configService.weappViteConfig.autoImportComponents.resolvers : void 0,
|
|
31499
|
+
resolveAppConfig: async () => (await ctx.scanService.loadAppEntry()).json
|
|
30958
31500
|
}, sharedOutput ? { build: { rolldownOptions: { output: sharedOutput } } } : {}, ...backendConfigs) }, ...configs);
|
|
30959
31501
|
}
|
|
30960
31502
|
function mergeInlineFactory(...configs) {
|
|
@@ -30977,11 +31519,12 @@ function createConfigService(ctx) {
|
|
|
30977
31519
|
let options = configState.options;
|
|
30978
31520
|
let loadingOptions;
|
|
30979
31521
|
const oxcRuntimeSupport = createOxcRuntimeSupport();
|
|
30980
|
-
const aliasManager = createAliasManager(oxcRuntimeSupport.alias, resolveBuiltinPackageAliases());
|
|
30981
|
-
function injectBuiltinAliases(config) {
|
|
31522
|
+
const aliasManager = createAliasManager(oxcRuntimeSupport.alias, resolveBuiltinPackageAliases({ cwd: options.cwd }));
|
|
31523
|
+
function injectBuiltinAliases(config, wevuRuntime) {
|
|
30982
31524
|
aliasManager.injectBuiltinAliases(config, resolveBuiltinPackageAliases({
|
|
31525
|
+
cwd: loadingOptions?.cwd ?? options.cwd,
|
|
30983
31526
|
isDev: loadingOptions?.isDev ?? options.isDev,
|
|
30984
|
-
wevuRuntime: config.weapp?.wevu?.runtime
|
|
31527
|
+
wevuRuntime: wevuRuntime ?? config.weapp?.wevu?.runtime
|
|
30985
31528
|
}));
|
|
30986
31529
|
}
|
|
30987
31530
|
const normalizeComparablePath = (input) => {
|
|
@@ -31049,9 +31592,14 @@ function createConfigService(ctx) {
|
|
|
31049
31592
|
};
|
|
31050
31593
|
const resolveExternalOutputPath = (filePath) => {
|
|
31051
31594
|
const normalizedPath = normalizeComparablePath(filePath);
|
|
31595
|
+
const nodeModulesIndex = normalizedPath.lastIndexOf("/node_modules/");
|
|
31596
|
+
if (nodeModulesIndex >= 0) {
|
|
31597
|
+
const packageRelative = normalizedPath.slice(nodeModulesIndex + 14);
|
|
31598
|
+
return normalizeRelativePath$1(path.join(WEAPP_VITE_EXTERNAL_OUTPUT_DIRECTORY, packageRelative));
|
|
31599
|
+
}
|
|
31052
31600
|
const normalizedDir = path.dirname(normalizedPath);
|
|
31053
31601
|
const dirHash = createHash("sha256").update(normalizedDir).digest("hex").slice(0, 10);
|
|
31054
|
-
return normalizeRelativePath$1(path.join(
|
|
31602
|
+
return normalizeRelativePath$1(path.join(WEAPP_VITE_EXTERNAL_OUTPUT_DIRECTORY, dirHash, path.basename(normalizedPath)));
|
|
31055
31603
|
};
|
|
31056
31604
|
function setOptions(value) {
|
|
31057
31605
|
options = value;
|
|
@@ -31446,7 +31994,8 @@ function resolveScanAppPreludeBasename(absoluteSrcRoot) {
|
|
|
31446
31994
|
return path.resolve(absoluteSrcRoot, "app.prelude");
|
|
31447
31995
|
}
|
|
31448
31996
|
async function resolveScanAppPreludePath(absoluteSrcRoot) {
|
|
31449
|
-
|
|
31997
|
+
const basename = resolveScanAppPreludeBasename(absoluteSrcRoot);
|
|
31998
|
+
return (await findJsEntry(basename)).path;
|
|
31450
31999
|
}
|
|
31451
32000
|
function resolveScanPluginBasename(absolutePluginRoot) {
|
|
31452
32001
|
return absolutePluginRoot ? path.resolve(absolutePluginRoot, "plugin") : void 0;
|
|
@@ -31546,14 +32095,15 @@ async function loadAppEntry(ctx, scanState) {
|
|
|
31546
32095
|
const { path: appEntryPath } = appEntry;
|
|
31547
32096
|
let configFromVue;
|
|
31548
32097
|
if (!appConfigFile && vueAppPath) {
|
|
31549
|
-
const { extractConfigFromVue } = await import("./file-
|
|
32098
|
+
const { extractConfigFromVue } = await import("./file-TBExd8Jd.mjs");
|
|
31550
32099
|
configFromVue = await extractConfigFromVue(vueAppPath);
|
|
31551
32100
|
if (configFromVue) appConfigFile = vueAppPath;
|
|
31552
32101
|
}
|
|
31553
32102
|
if (appEntryPath && vueAppPath) warnOnce(`[app] 检测到 ${path.basename(appEntryPath)} 与 ${path.basename(vueAppPath)} 同时存在,当前将优先使用 ${path.basename(appEntryPath)} 作为应用入口,${path.basename(vueAppPath)} 将被忽略。`);
|
|
31554
32103
|
if (discoveredAppConfigFile && vueAppPath) warnOnce(`[app] 检测到 ${path.basename(discoveredAppConfigFile)} 与 ${path.basename(vueAppPath)} 同时存在,当前将优先使用 ${path.basename(discoveredAppConfigFile)} 作为应用配置来源,${path.basename(vueAppPath)} 中的 app 配置不会生效。`);
|
|
31555
32104
|
if (ctx.configService.absolutePluginRoot) {
|
|
31556
|
-
const
|
|
32105
|
+
const pluginBasename = resolveScanPluginBasename(ctx.configService.absolutePluginRoot);
|
|
32106
|
+
const { path: pluginConfigFile } = await findJsonEntry(pluginBasename);
|
|
31557
32107
|
if (pluginConfigFile) {
|
|
31558
32108
|
scanState.pluginJson = await ctx.jsonService.read(pluginConfigFile);
|
|
31559
32109
|
scanState.pluginJsonPath = pluginConfigFile;
|