weapp-vite 6.19.4 → 6.20.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/dist/auto-routes.mjs +1 -1
- package/dist/cli.mjs +37 -12
- package/dist/{config-DWY8nWj0.d.mts → config-Dd_PqIy2.d.mts} +13 -2
- package/dist/config.d.mts +1 -1
- package/dist/{createContext-r2rcHex1.mjs → createContext-DutRdQ_I.mjs} +708 -94
- package/dist/file-BG-q88IF.mjs +2 -0
- package/dist/{file-C-T36DmG.mjs → file-Bwxu2veP.mjs} +10 -4
- package/dist/getInstance-D8SEyLSD.mjs +2 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/json.d.mts +1 -1
- package/dist/mcp.d.mts +1 -1
- package/dist/test.mjs +1 -1
- package/dist/types.d.mts +2 -2
- package/package.json +12 -9
- package/dist/file-CV6ZWiTX.mjs +0 -2
- package/dist/getInstance-HvLRUAtA.mjs +0 -2
|
@@ -1,24 +1,24 @@
|
|
|
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
|
|
3
|
+
import { _ as jsExtensions, a as findJsonEntry, b as templateExtensions, 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 scriptExtensions, x as vueExtensions, y as supportedCssLangs } from "./file-Bwxu2veP.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_BUNDLE_MARKER as REQUEST_GLOBAL_BUNDLE_MARKER$1, 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_LOCAL_BINDINGS_MARKER as REQUEST_GLOBAL_LOCAL_BINDINGS_MARKER$1, 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";
|
|
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_BUNDLE_MARKER as REQUEST_GLOBAL_BUNDLE_MARKER$1, 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_LOCAL_BINDINGS_MARKER as REQUEST_GLOBAL_LOCAL_BINDINGS_MARKER$1, 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_REACT_EVENT_METHOD_NAME, 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, generate, mayContainPlatformApiIdentifierByText, mayContainStaticRequireLiteral, parseJsLikeWithEngine, platformApiIdentifiers } from "@weapp-vite/ast";
|
|
13
|
+
import { BABEL_TS_MODULE_PARSER_OPTIONS, analyzeScript, analyzeScripts, collectComponentPropsFromCode, collectRequireTokens, collectScriptSetupImportsFromCode, generate, mayContainPlatformApiIdentifierByText, mayContainStaticRequireLiteral, parse, 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
|
-
import { compileScript, parse } from "vue/compiler-sfc";
|
|
17
|
-
import { BABEL_TS_MODULE_PARSER_OPTIONS, generate as generate$1, getVisitorKeys, parse as parse$
|
|
16
|
+
import { compileScript, parse as parse$1 } from "vue/compiler-sfc";
|
|
17
|
+
import { BABEL_TS_MODULE_PARSER_OPTIONS as BABEL_TS_MODULE_PARSER_OPTIONS$1, generate as generate$1, getVisitorKeys, parse as parse$3, parseJsLike, traverse } from "@weapp-vite/ast/babel";
|
|
18
18
|
import pm from "picomatch";
|
|
19
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
|
-
import { parse as parse$
|
|
21
|
+
import { parse as parse$2, stringify } from "comment-json";
|
|
22
22
|
import fs$2, { appendFile, copyFile, mkdir, readFile, readdir, rm } from "node:fs/promises";
|
|
23
23
|
import { build, createLogger, createServer, loadConfigFromFile, preprocessCSS, transformWithOxc } from "vite";
|
|
24
24
|
import { createHash, randomBytes } from "node:crypto";
|
|
@@ -36,10 +36,10 @@ import { spawn } from "node:child_process";
|
|
|
36
36
|
import PQueue from "p-queue";
|
|
37
37
|
import { Buffer } from "node:buffer";
|
|
38
38
|
import MagicString from "magic-string";
|
|
39
|
+
import * as t from "@weapp-vite/ast/babelTypes";
|
|
39
40
|
import babelPresetEnv from "@babel/preset-env";
|
|
40
41
|
import babelPresetTypescript from "@babel/preset-typescript";
|
|
41
42
|
import * as babel from "@weapp-vite/ast/babelCore";
|
|
42
|
-
import * as t from "@weapp-vite/ast/babelTypes";
|
|
43
43
|
import { Parser } from "htmlparser2";
|
|
44
44
|
import { detect } from "package-manager-detector/detect";
|
|
45
45
|
import tsconfigPaths from "vite-tsconfig-paths";
|
|
@@ -116,6 +116,7 @@ function parseSidecarModuleId(id) {
|
|
|
116
116
|
const [kind, ownerId, sourceId, ...rest] = request.slice(0, -10).split(":");
|
|
117
117
|
if (rest.length || !kind || !ownerId || !sourceId || ![
|
|
118
118
|
"json",
|
|
119
|
+
"jsx",
|
|
119
120
|
"layout",
|
|
120
121
|
"script",
|
|
121
122
|
"style",
|
|
@@ -142,6 +143,7 @@ function parseSidecarSourceRequest(id) {
|
|
|
142
143
|
const ownerId = query.get(WEAPP_VITE_SIDECAR_OWNER_QUERY_MARKER);
|
|
143
144
|
if (!kind || ![
|
|
144
145
|
"json",
|
|
146
|
+
"jsx",
|
|
145
147
|
"layout",
|
|
146
148
|
"script",
|
|
147
149
|
"style",
|
|
@@ -313,6 +315,10 @@ function createModuleGraphService() {
|
|
|
313
315
|
const collectAffectedEntries = (rawFile) => {
|
|
314
316
|
const file = normalizeSourceId(rawFile);
|
|
315
317
|
const affected = /* @__PURE__ */ new Set();
|
|
318
|
+
for (const [ownerId, dependenciesByKind] of entryDependencies) for (const sourceIds of dependenciesByKind.values()) if (sourceIds.has(file)) {
|
|
319
|
+
affected.add(ownerId);
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
316
322
|
if (devServer) collectFromDevGraph(file, affected);
|
|
317
323
|
else collectFromBuildGraph(file, affected);
|
|
318
324
|
return affected;
|
|
@@ -572,7 +578,7 @@ function createDefaultAutoImportComponents(configService) {
|
|
|
572
578
|
addDefaultComponentGlobs(globs, configService, "wxml");
|
|
573
579
|
return globs.size ? { globs: [...globs] } : void 0;
|
|
574
580
|
}
|
|
575
|
-
function hasWevuDependency$
|
|
581
|
+
function hasWevuDependency$2(configService) {
|
|
576
582
|
const packageJson = configService.packageJson ?? {};
|
|
577
583
|
return Boolean(packageJson.dependencies?.wevu || packageJson.devDependencies?.wevu || packageJson.peerDependencies?.wevu);
|
|
578
584
|
}
|
|
@@ -580,7 +586,7 @@ function createEnabledAutoImportComponents(configService) {
|
|
|
580
586
|
const defaults = createDefaultAutoImportComponents(configService);
|
|
581
587
|
if (!defaults) return;
|
|
582
588
|
const globs = new Set(defaults.globs ?? []);
|
|
583
|
-
if (hasWevuDependency$
|
|
589
|
+
if (hasWevuDependency$2(configService)) addDefaultComponentGlobs(globs, configService, "vue");
|
|
584
590
|
return {
|
|
585
591
|
...defaults,
|
|
586
592
|
globs: [...globs],
|
|
@@ -588,7 +594,7 @@ function createEnabledAutoImportComponents(configService) {
|
|
|
588
594
|
typedComponents: true,
|
|
589
595
|
htmlCustomData: true,
|
|
590
596
|
vueComponents: true,
|
|
591
|
-
vueComponentsModule: hasWevuDependency$
|
|
597
|
+
vueComponentsModule: hasWevuDependency$2(configService) ? "wevu" : void 0
|
|
592
598
|
};
|
|
593
599
|
}
|
|
594
600
|
function getAutoImportConfig(configService) {
|
|
@@ -1321,8 +1327,8 @@ function extractFromPropsInterfaceMembers(node) {
|
|
|
1321
1327
|
}
|
|
1322
1328
|
function extractComponentPropsFromDts(code) {
|
|
1323
1329
|
let props = /* @__PURE__ */ new Map();
|
|
1324
|
-
const ast = parse$
|
|
1325
|
-
...BABEL_TS_MODULE_PARSER_OPTIONS,
|
|
1330
|
+
const ast = parse$3(code, {
|
|
1331
|
+
...BABEL_TS_MODULE_PARSER_OPTIONS$1,
|
|
1326
1332
|
errorRecovery: true
|
|
1327
1333
|
});
|
|
1328
1334
|
traverse(ast, {
|
|
@@ -1368,12 +1374,12 @@ function extractComponentPropsFromDts(code) {
|
|
|
1368
1374
|
}
|
|
1369
1375
|
function extractInlinePropsTypeFromCode(code) {
|
|
1370
1376
|
const source = code.includes("<script") ? (() => {
|
|
1371
|
-
const parsed = parse(code, { filename: "layout.vue" });
|
|
1377
|
+
const parsed = parse$1(code, { filename: "layout.vue" });
|
|
1372
1378
|
return parsed.descriptor.scriptSetup?.content ?? parsed.descriptor.script?.content ?? code;
|
|
1373
1379
|
})() : code;
|
|
1374
1380
|
const props = /* @__PURE__ */ new Map();
|
|
1375
|
-
const ast = parse$
|
|
1376
|
-
...BABEL_TS_MODULE_PARSER_OPTIONS,
|
|
1381
|
+
const ast = parse$3(source, {
|
|
1382
|
+
...BABEL_TS_MODULE_PARSER_OPTIONS$1,
|
|
1377
1383
|
errorRecovery: true
|
|
1378
1384
|
});
|
|
1379
1385
|
const typeAliases = /* @__PURE__ */ new Map();
|
|
@@ -2210,7 +2216,7 @@ function createVueComponentsDefinition(componentNames, getMetadata, options = {}
|
|
|
2210
2216
|
function extractVueComponentProps(source, filename, options = {}) {
|
|
2211
2217
|
const inlineProps = extractInlinePropsTypeFromCode(source);
|
|
2212
2218
|
if (inlineProps.size > 0) return inlineProps;
|
|
2213
|
-
const { descriptor, errors } = parse(source, { filename });
|
|
2219
|
+
const { descriptor, errors } = parse$1(source, { filename });
|
|
2214
2220
|
if (errors.length || !descriptor.script && !descriptor.scriptSetup) return /* @__PURE__ */ new Map();
|
|
2215
2221
|
const compiled = compileScript(descriptor, {
|
|
2216
2222
|
id: filename,
|
|
@@ -5079,7 +5085,7 @@ function buildCandidates(base, extensions) {
|
|
|
5079
5085
|
return extensions.map((ext) => changeFileExtension(base, ext));
|
|
5080
5086
|
}
|
|
5081
5087
|
function resolveEntryExtensions(kind, isDir) {
|
|
5082
|
-
return kind === "named" || isDir ? [...
|
|
5088
|
+
return kind === "named" || isDir ? [...scriptExtensions, ...vueExtensions] : [...vueExtensions, ...scriptExtensions];
|
|
5083
5089
|
}
|
|
5084
5090
|
function createCachedEntryResolveOptions(configService, options) {
|
|
5085
5091
|
return {
|
|
@@ -5125,7 +5131,7 @@ const COMPONENT_NAME_MULTI_UPPER_RE = /([A-Z]+)([A-Z][a-z])/g;
|
|
|
5125
5131
|
const COMPONENT_NAME_HAS_UPPER_RE = /[A-Z]/;
|
|
5126
5132
|
const SCOPED_SLOT_GENERIC_KEY_RE$1 = /^scoped-slots-/;
|
|
5127
5133
|
function parseCommentJson(json) {
|
|
5128
|
-
return parse$
|
|
5134
|
+
return parse$2(json, void 0, true);
|
|
5129
5135
|
}
|
|
5130
5136
|
function jsonFileRemoveJsExtension(fileName) {
|
|
5131
5137
|
return fileName.replace(JSON_FILE_JS_EXTENSION_RE, "");
|
|
@@ -5387,7 +5393,7 @@ function parseModuleForReExport(code, astEngine) {
|
|
|
5387
5393
|
engine: "oxc",
|
|
5388
5394
|
filename: "inline.ts"
|
|
5389
5395
|
});
|
|
5390
|
-
return parse$
|
|
5396
|
+
return parse$3(code, BABEL_TS_MODULE_PARSER_OPTIONS$1).program;
|
|
5391
5397
|
}
|
|
5392
5398
|
async function resolveReExportedInternal(exporterFile, exportName, depth, visited, options) {
|
|
5393
5399
|
if (depth <= 0) return;
|
|
@@ -5983,6 +5989,7 @@ function createAutoImportScheduling(options) {
|
|
|
5983
5989
|
html: void 0,
|
|
5984
5990
|
vue: void 0
|
|
5985
5991
|
};
|
|
5992
|
+
let outputWritesSuppressed = 0;
|
|
5986
5993
|
let outputSettingsSnapshot;
|
|
5987
5994
|
function getOutputSettingsSnapshot() {
|
|
5988
5995
|
if (!outputSettingsSnapshot) outputSettingsSnapshot = {
|
|
@@ -5993,6 +6000,7 @@ function createAutoImportScheduling(options) {
|
|
|
5993
6000
|
return outputSettingsSnapshot;
|
|
5994
6001
|
}
|
|
5995
6002
|
function deferOrSchedule(kind, shouldWrite) {
|
|
6003
|
+
if (outputWritesSuppressed > 0) return;
|
|
5996
6004
|
if (batchedWrites.depth > 0) {
|
|
5997
6005
|
const previous = batchedWrites[kind];
|
|
5998
6006
|
batchedWrites[kind] = previous === void 0 ? shouldWrite : previous || shouldWrite;
|
|
@@ -6035,10 +6043,19 @@ function createAutoImportScheduling(options) {
|
|
|
6035
6043
|
if (batchedWrites.depth === 0) flushBatchedWrites();
|
|
6036
6044
|
}
|
|
6037
6045
|
}
|
|
6046
|
+
async function runWithoutOutputWrites(task) {
|
|
6047
|
+
outputWritesSuppressed += 1;
|
|
6048
|
+
try {
|
|
6049
|
+
return await task();
|
|
6050
|
+
} finally {
|
|
6051
|
+
outputWritesSuppressed -= 1;
|
|
6052
|
+
}
|
|
6053
|
+
}
|
|
6038
6054
|
return {
|
|
6039
6055
|
getOutputSettingsSnapshot,
|
|
6040
6056
|
deferOrSchedule,
|
|
6041
|
-
runInBatch
|
|
6057
|
+
runInBatch,
|
|
6058
|
+
runWithoutOutputWrites
|
|
6042
6059
|
};
|
|
6043
6060
|
}
|
|
6044
6061
|
//#endregion
|
|
@@ -6159,6 +6176,9 @@ function createAutoImportService(ctx) {
|
|
|
6159
6176
|
},
|
|
6160
6177
|
async runInBatch(task) {
|
|
6161
6178
|
return await scheduling.runInBatch(task);
|
|
6179
|
+
},
|
|
6180
|
+
async runWithoutOutputWrites(task) {
|
|
6181
|
+
return await scheduling.runWithoutOutputWrites(task);
|
|
6162
6182
|
}
|
|
6163
6183
|
};
|
|
6164
6184
|
}
|
|
@@ -6413,7 +6433,7 @@ async function resolveDefaultSearchRoots(absoluteSrcRoot, subPackageRoots) {
|
|
|
6413
6433
|
}
|
|
6414
6434
|
//#endregion
|
|
6415
6435
|
//#region src/runtime/autoRoutesPlugin/candidates.ts
|
|
6416
|
-
const SCRIPT_EXTENSIONS = new Set(
|
|
6436
|
+
const SCRIPT_EXTENSIONS = new Set(scriptExtensions.map((ext) => `.${ext}`));
|
|
6417
6437
|
const TEMPLATE_EXTENSIONS = new Set(templateExtensions.map((ext) => `.${ext}`));
|
|
6418
6438
|
const VUE_EXTENSIONS = new Set(vueExtensions.map((ext) => `.${ext}`));
|
|
6419
6439
|
const STYLE_EXTENSIONS = new Set(supportedCssLangs.map((ext) => `.${ext}`));
|
|
@@ -6784,11 +6804,6 @@ function applyBuildScopeToAutoRoutes(routes, scope) {
|
|
|
6784
6804
|
subPackages
|
|
6785
6805
|
};
|
|
6786
6806
|
}
|
|
6787
|
-
function applyBuildScopeToSubPackageRoots(roots, scope) {
|
|
6788
|
-
if (!scope?.enabled) return roots;
|
|
6789
|
-
const scopedRoots = new Set(scope.subPackageRoots);
|
|
6790
|
-
return roots.map((root) => normalizeRoot(root)).filter((root) => scopedRoots.has(root));
|
|
6791
|
-
}
|
|
6792
6807
|
//#endregion
|
|
6793
6808
|
//#region src/utils/miniProgramGlobals.ts
|
|
6794
6809
|
function getMiniProgramGlobalKeys() {
|
|
@@ -6934,7 +6949,7 @@ function getAutoRoutesSubPackageRoots(ctx) {
|
|
|
6934
6949
|
const npmSubPackageRoots = Object.keys(ctx.configService?.weappViteConfig?.npm?.subPackages ?? {});
|
|
6935
6950
|
for (const root of npmSubPackageRoots) roots.add(root);
|
|
6936
6951
|
for (const root of collectAppJsonSubPackageRoots(ctx)) roots.add(root);
|
|
6937
|
-
return
|
|
6952
|
+
return [...roots];
|
|
6938
6953
|
}
|
|
6939
6954
|
//#endregion
|
|
6940
6955
|
//#region src/runtime/autoRoutesPlugin/shared.ts
|
|
@@ -7648,7 +7663,7 @@ function collectResolverPlugins(config) {
|
|
|
7648
7663
|
return (Array.isArray(config.plugins) ? config.plugins : config.plugins ? [config.plugins] : []).filter((plugin) => !isInternalPlugin(plugin));
|
|
7649
7664
|
}
|
|
7650
7665
|
async function transformVueSource(code, id) {
|
|
7651
|
-
const { descriptor, errors } = parse(code, { filename: id });
|
|
7666
|
+
const { descriptor, errors } = parse$1(code, { filename: id });
|
|
7652
7667
|
if (errors.length) throw errors[0];
|
|
7653
7668
|
const blocks = [descriptor.script, descriptor.scriptSetup].filter((block) => block?.content);
|
|
7654
7669
|
const source = blocks.map((block) => block.content).join("\n") || "export default {}";
|
|
@@ -11142,6 +11157,512 @@ function isStatefulHmrRuntimeCompatibilityError(error) {
|
|
|
11142
11157
|
return error instanceof StatefulHmrRuntimeCompatibilityError || typeof error === "object" && error !== null && Reflect.get(error, "code") === "WEAPP_VITE_STATEFUL_HMR_RUNTIME_INCOMPATIBLE";
|
|
11143
11158
|
}
|
|
11144
11159
|
//#endregion
|
|
11160
|
+
//#region src/plugins/react/baseTemplate.ts
|
|
11161
|
+
const MAX_TEMPLATE_DEPTH = 4;
|
|
11162
|
+
function renderHostAttributes(tag) {
|
|
11163
|
+
const common = "id=\"{{i.p.id}}\" class=\"{{i.cl}}\" style=\"{{i.st}}\" data-sid=\"{{i.sid}}\"";
|
|
11164
|
+
if (tag === "button") return `${common} disabled="{{i.p.disabled}}" bindtap="${WEAPP_REACT_EVENT_METHOD_NAME}"`;
|
|
11165
|
+
if (tag === "input") return `${common} value="{{i.p.value}}" type="{{i.p.type}}" checked="{{i.p.checked}}" disabled="{{i.p.disabled}}" placeholder="{{i.p.placeholder}}" bindinput="${WEAPP_REACT_EVENT_METHOD_NAME}" bindchange="${WEAPP_REACT_EVENT_METHOD_NAME}"`;
|
|
11166
|
+
return `${common} hidden="{{i.p.hidden}}" bindtap="${WEAPP_REACT_EVENT_METHOD_NAME}"`;
|
|
11167
|
+
}
|
|
11168
|
+
function renderHost(tag, depth) {
|
|
11169
|
+
const attributes = renderHostAttributes(tag);
|
|
11170
|
+
if (tag === "input" || depth === MAX_TEMPLATE_DEPTH) return ` <${tag} wx:elif="{{i.nn === '${tag}'}}" ${attributes} />`;
|
|
11171
|
+
return [
|
|
11172
|
+
` <${tag} wx:elif="{{i.nn === '${tag}'}}" ${attributes}>`,
|
|
11173
|
+
" <block wx:for=\"{{i.cn}}\" wx:key=\"sid\" wx:for-item=\"child\">",
|
|
11174
|
+
` <template is="react_node_${depth + 1}" data="{{i:child}}" />`,
|
|
11175
|
+
" </block>",
|
|
11176
|
+
` </${tag}>`
|
|
11177
|
+
].join("\n");
|
|
11178
|
+
}
|
|
11179
|
+
function renderNodeTemplate(depth) {
|
|
11180
|
+
return [
|
|
11181
|
+
`<template name="react_node_${depth}">`,
|
|
11182
|
+
" <block wx:if=\"{{i.nn === '#text'}}\">{{i.v}}</block>",
|
|
11183
|
+
renderHost("view", depth),
|
|
11184
|
+
renderHost("text", depth),
|
|
11185
|
+
renderHost("button", depth),
|
|
11186
|
+
renderHost("input", depth),
|
|
11187
|
+
"</template>"
|
|
11188
|
+
].join("\n");
|
|
11189
|
+
}
|
|
11190
|
+
const baseTemplate = [
|
|
11191
|
+
"<template name=\"react_root\">",
|
|
11192
|
+
" <block wx:for=\"{{root.cn}}\" wx:key=\"sid\" wx:for-item=\"child\">",
|
|
11193
|
+
" <template is=\"react_node_0\" data=\"{{i:child}}\" />",
|
|
11194
|
+
" </block>",
|
|
11195
|
+
"</template>",
|
|
11196
|
+
"",
|
|
11197
|
+
...Array.from({ length: 5 }, (_, depth) => renderNodeTemplate(depth)),
|
|
11198
|
+
""
|
|
11199
|
+
].join("\n");
|
|
11200
|
+
//#endregion
|
|
11201
|
+
//#region src/plugins/react/staticTemplate/style.ts
|
|
11202
|
+
const UNITLESS_STYLE_PROPERTIES = /* @__PURE__ */ new Set([
|
|
11203
|
+
"flex",
|
|
11204
|
+
"flexGrow",
|
|
11205
|
+
"flexShrink",
|
|
11206
|
+
"fontWeight",
|
|
11207
|
+
"lineHeight",
|
|
11208
|
+
"opacity",
|
|
11209
|
+
"order",
|
|
11210
|
+
"zIndex"
|
|
11211
|
+
]);
|
|
11212
|
+
function toKebabCase$2(value) {
|
|
11213
|
+
return value.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);
|
|
11214
|
+
}
|
|
11215
|
+
function readPropertyName(node) {
|
|
11216
|
+
if (t.isIdentifier(node)) return node.name;
|
|
11217
|
+
if (t.isStringLiteral(node)) return node.value;
|
|
11218
|
+
}
|
|
11219
|
+
function readPropertyValue(node) {
|
|
11220
|
+
if (t.isStringLiteral(node) || t.isNumericLiteral(node)) return node.value;
|
|
11221
|
+
}
|
|
11222
|
+
function compileStaticStyle(expression) {
|
|
11223
|
+
const declarations = [];
|
|
11224
|
+
for (const property of expression.properties) {
|
|
11225
|
+
if (!t.isObjectProperty(property) || property.computed) return;
|
|
11226
|
+
const name = readPropertyName(property.key);
|
|
11227
|
+
const value = readPropertyValue(property.value);
|
|
11228
|
+
if (!name || value === void 0) return;
|
|
11229
|
+
const normalized = typeof value === "number" && !UNITLESS_STYLE_PROPERTIES.has(name) ? `${value}px` : String(value);
|
|
11230
|
+
declarations.push(`${toKebabCase$2(name)}:${normalized}`);
|
|
11231
|
+
}
|
|
11232
|
+
return declarations.join(";");
|
|
11233
|
+
}
|
|
11234
|
+
//#endregion
|
|
11235
|
+
//#region src/plugins/react/staticTemplate/render.ts
|
|
11236
|
+
const HOST_TAGS = {
|
|
11237
|
+
Button: "button",
|
|
11238
|
+
Input: "input",
|
|
11239
|
+
Text: "text",
|
|
11240
|
+
View: "view",
|
|
11241
|
+
button: "button",
|
|
11242
|
+
input: "input",
|
|
11243
|
+
text: "text",
|
|
11244
|
+
view: "view"
|
|
11245
|
+
};
|
|
11246
|
+
const EVENT_NAMES = {
|
|
11247
|
+
onChange: "bindchange",
|
|
11248
|
+
onInput: "bindinput",
|
|
11249
|
+
onTap: "bindtap",
|
|
11250
|
+
onTapCapture: "capture-bind:tap"
|
|
11251
|
+
};
|
|
11252
|
+
const EVENT_PROP_RE = /^on[A-Z]/;
|
|
11253
|
+
const IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
|
|
11254
|
+
function escapeAttribute(value) {
|
|
11255
|
+
return value.replaceAll("&", "&").replaceAll("\"", """).replaceAll("<", "<");
|
|
11256
|
+
}
|
|
11257
|
+
function escapeText(value) {
|
|
11258
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
11259
|
+
}
|
|
11260
|
+
function normalizeJsxText(value) {
|
|
11261
|
+
return value.split(/\r?\n/).map((line) => line.trim()).filter(Boolean).join(" ");
|
|
11262
|
+
}
|
|
11263
|
+
function readTagName(node, context) {
|
|
11264
|
+
if (!t.isJSXIdentifier(node)) throw new Error("static template 暂不支持 member/namespaced JSX tag");
|
|
11265
|
+
const tag = HOST_TAGS[node.name];
|
|
11266
|
+
if (tag) return {
|
|
11267
|
+
kind: "host",
|
|
11268
|
+
tag
|
|
11269
|
+
};
|
|
11270
|
+
if (context.slotComponentNames.has(node.name) || node.name === "slot") return {
|
|
11271
|
+
kind: "slot",
|
|
11272
|
+
tag: "slot"
|
|
11273
|
+
};
|
|
11274
|
+
const nativeTag = context.nativeComponentTags.get(node.name);
|
|
11275
|
+
if (nativeTag) {
|
|
11276
|
+
context.usedNativeComponents.add(nativeTag);
|
|
11277
|
+
return {
|
|
11278
|
+
kind: "native",
|
|
11279
|
+
tag: nativeTag
|
|
11280
|
+
};
|
|
11281
|
+
}
|
|
11282
|
+
throw new Error(`static template 暂不支持动态组件 <${node.name}>`);
|
|
11283
|
+
}
|
|
11284
|
+
function readAttributeExpression(attribute) {
|
|
11285
|
+
if (!attribute.value) return t.booleanLiteral(true);
|
|
11286
|
+
if (t.isStringLiteral(attribute.value)) return attribute.value;
|
|
11287
|
+
if (!t.isJSXExpressionContainer(attribute.value) || t.isJSXEmptyExpression(attribute.value.expression)) return;
|
|
11288
|
+
return attribute.value.expression;
|
|
11289
|
+
}
|
|
11290
|
+
function readStaticPrimitive(expression) {
|
|
11291
|
+
if (t.isStringLiteral(expression) || t.isNumericLiteral(expression) || t.isBooleanLiteral(expression)) return expression.value;
|
|
11292
|
+
if (t.isTemplateLiteral(expression) && expression.expressions.length === 0) return expression.quasis[0]?.value.cooked ?? "";
|
|
11293
|
+
}
|
|
11294
|
+
function appendInternalAttribute(element, name, value) {
|
|
11295
|
+
element.openingElement.attributes.push(t.jsxAttribute(t.jsxIdentifier(name), t.stringLiteral(value)));
|
|
11296
|
+
}
|
|
11297
|
+
function toKebabCase$1(value) {
|
|
11298
|
+
return value.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
11299
|
+
}
|
|
11300
|
+
function resolveNativeEvent(name) {
|
|
11301
|
+
if (!EVENT_PROP_RE.test(name)) return;
|
|
11302
|
+
const capture = name.endsWith("Capture");
|
|
11303
|
+
const eventName = name.slice(2, capture ? -7 : void 0);
|
|
11304
|
+
if (!eventName) return;
|
|
11305
|
+
return `${capture ? "capture-bind" : "bind"}:${toKebabCase$1(eventName)}`;
|
|
11306
|
+
}
|
|
11307
|
+
function renderBindingExpression(slot, name) {
|
|
11308
|
+
return IDENTIFIER_RE.test(name) ? `slots.${slot}.${name}` : `slots.${slot}['${name}']`;
|
|
11309
|
+
}
|
|
11310
|
+
function compileAttributes(element, slot, bindingFields, tagKind) {
|
|
11311
|
+
const output = [];
|
|
11312
|
+
let hasEvent = false;
|
|
11313
|
+
for (const attribute of element.openingElement.attributes) {
|
|
11314
|
+
if (!t.isJSXAttribute(attribute) || !t.isJSXIdentifier(attribute.name)) throw new Error("static template 暂不支持 JSX spread 或动态属性名");
|
|
11315
|
+
const name = attribute.name.name;
|
|
11316
|
+
if (name === "key") continue;
|
|
11317
|
+
const eventName = tagKind === "native" ? resolveNativeEvent(name) : EVENT_NAMES[name];
|
|
11318
|
+
if (eventName) {
|
|
11319
|
+
hasEvent = true;
|
|
11320
|
+
output.push(`${eventName}="${WEAPP_REACT_EVENT_METHOD_NAME}"`);
|
|
11321
|
+
continue;
|
|
11322
|
+
}
|
|
11323
|
+
if (EVENT_PROP_RE.test(name)) throw new Error(`static template 暂不支持事件 ${name}`);
|
|
11324
|
+
const expression = readAttributeExpression(attribute);
|
|
11325
|
+
if (!expression) continue;
|
|
11326
|
+
const outputName = name === "className" ? "class" : name;
|
|
11327
|
+
if (name === "style" && t.isObjectExpression(expression)) {
|
|
11328
|
+
const style = compileStaticStyle(expression);
|
|
11329
|
+
if (style !== void 0) {
|
|
11330
|
+
output.push(`style="${escapeAttribute(style)}"`);
|
|
11331
|
+
continue;
|
|
11332
|
+
}
|
|
11333
|
+
}
|
|
11334
|
+
const staticValue = readStaticPrimitive(expression);
|
|
11335
|
+
if (staticValue !== void 0) {
|
|
11336
|
+
output.push(`${outputName}="${escapeAttribute(String(staticValue))}"`);
|
|
11337
|
+
continue;
|
|
11338
|
+
}
|
|
11339
|
+
bindingFields.add(name);
|
|
11340
|
+
output.push(`${outputName}="{{${renderBindingExpression(slot, name)}}}"`);
|
|
11341
|
+
}
|
|
11342
|
+
if (hasEvent) output.push(`data-sid="${slot}"`);
|
|
11343
|
+
return output;
|
|
11344
|
+
}
|
|
11345
|
+
function isDynamicTextExpression(node) {
|
|
11346
|
+
return !t.isJSXEmptyExpression(node.expression) && readStaticPrimitive(node.expression) === void 0;
|
|
11347
|
+
}
|
|
11348
|
+
function compileStaticChildren(children, context) {
|
|
11349
|
+
return children.map((child) => {
|
|
11350
|
+
if (t.isJSXText(child)) return escapeText(normalizeJsxText(child.value));
|
|
11351
|
+
if (t.isJSXElement(child)) return compileStaticElement(child, context);
|
|
11352
|
+
if (t.isJSXFragment(child)) return compileStaticFragment(child, context);
|
|
11353
|
+
if (t.isJSXExpressionContainer(child)) {
|
|
11354
|
+
if (t.isJSXEmptyExpression(child.expression)) return "";
|
|
11355
|
+
const value = readStaticPrimitive(child.expression);
|
|
11356
|
+
if (value !== void 0) return escapeText(String(value));
|
|
11357
|
+
throw new Error("static template 的容器节点暂不支持动态结构表达式");
|
|
11358
|
+
}
|
|
11359
|
+
return "";
|
|
11360
|
+
}).join("");
|
|
11361
|
+
}
|
|
11362
|
+
function compileStaticFragment(fragment, context) {
|
|
11363
|
+
return compileStaticChildren(fragment.children, context);
|
|
11364
|
+
}
|
|
11365
|
+
function compileStaticElement(element, context) {
|
|
11366
|
+
const resolvedTag = readTagName(element.openingElement.name, context);
|
|
11367
|
+
const { tag } = resolvedTag;
|
|
11368
|
+
const slot = `s${context.slotSeed++}`;
|
|
11369
|
+
const bindingFields = /* @__PURE__ */ new Set();
|
|
11370
|
+
const slotRecord = {
|
|
11371
|
+
bindings: [],
|
|
11372
|
+
id: slot,
|
|
11373
|
+
tag
|
|
11374
|
+
};
|
|
11375
|
+
context.slots.push(slotRecord);
|
|
11376
|
+
const attributes = compileAttributes(element, slot, bindingFields, resolvedTag.kind);
|
|
11377
|
+
const children = element.children;
|
|
11378
|
+
const hasDynamicText = (tag === "text" || tag === "button") && children.some((child) => t.isJSXExpressionContainer(child) && isDynamicTextExpression(child));
|
|
11379
|
+
let content;
|
|
11380
|
+
if (hasDynamicText) {
|
|
11381
|
+
if (children.some((child) => t.isJSXElement(child) || t.isJSXFragment(child))) throw new Error(`static template 的 <${tag}> 不支持动态文本与元素子节点混用`);
|
|
11382
|
+
bindingFields.add("text");
|
|
11383
|
+
content = `{{slots.${slot}.text}}`;
|
|
11384
|
+
} else content = compileStaticChildren(children, context);
|
|
11385
|
+
appendInternalAttribute(element, "__slot", slot);
|
|
11386
|
+
if (bindingFields.size > 0) appendInternalAttribute(element, "__bindingFields", [...bindingFields].join(","));
|
|
11387
|
+
slotRecord.bindings = [...bindingFields];
|
|
11388
|
+
const attributeSegment = attributes.length > 0 ? ` ${attributes.join(" ")}` : "";
|
|
11389
|
+
if (resolvedTag.kind === "slot" && children.length > 0) throw new Error("static template 的 <Slot> 不支持子节点");
|
|
11390
|
+
if (element.openingElement.selfClosing) return `<${tag}${attributeSegment} />`;
|
|
11391
|
+
return `<${tag}${attributeSegment}>${content}</${tag}>`;
|
|
11392
|
+
}
|
|
11393
|
+
function renderStaticTemplate(root, context) {
|
|
11394
|
+
return t.isJSXElement(root) ? compileStaticElement(root, context) : compileStaticFragment(root, context);
|
|
11395
|
+
}
|
|
11396
|
+
//#endregion
|
|
11397
|
+
//#region src/plugins/react/staticTemplate/index.ts
|
|
11398
|
+
const REACT_RUNTIME_MODULE_ID = "@weapp-vite/react";
|
|
11399
|
+
var ReactNativeBridgeStaticError = class extends Error {
|
|
11400
|
+
constructor(filename, cause) {
|
|
11401
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
11402
|
+
super(`[react] ${filename} 使用了原生组件 bridge,组件结构必须可静态分析:${message}`, { cause });
|
|
11403
|
+
this.name = "ReactNativeBridgeStaticError";
|
|
11404
|
+
}
|
|
11405
|
+
};
|
|
11406
|
+
function collectRuntimeImportNames(ast, importedName) {
|
|
11407
|
+
const names = /* @__PURE__ */ new Set();
|
|
11408
|
+
for (const statement of ast.program.body) {
|
|
11409
|
+
if (!t.isImportDeclaration(statement) || statement.source.value !== REACT_RUNTIME_MODULE_ID) continue;
|
|
11410
|
+
for (const specifier of statement.specifiers) if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported, { name: importedName })) names.add(specifier.local.name);
|
|
11411
|
+
}
|
|
11412
|
+
return names;
|
|
11413
|
+
}
|
|
11414
|
+
function collectNativeComponentTags(ast, factoryNames) {
|
|
11415
|
+
const tags = /* @__PURE__ */ new Map();
|
|
11416
|
+
for (const statement of ast.program.body) {
|
|
11417
|
+
const declaration = t.isVariableDeclaration(statement) ? statement : t.isExportNamedDeclaration(statement) && t.isVariableDeclaration(statement.declaration) ? statement.declaration : void 0;
|
|
11418
|
+
if (!declaration) continue;
|
|
11419
|
+
for (const item of declaration.declarations) {
|
|
11420
|
+
if (!t.isIdentifier(item.id) || !t.isCallExpression(item.init) || !t.isIdentifier(item.init.callee) || !factoryNames.has(item.init.callee.name)) continue;
|
|
11421
|
+
const [tagArgument] = item.init.arguments;
|
|
11422
|
+
if (!t.isStringLiteral(tagArgument) || !tagArgument.value) throw new Error("createNativeComponent 的 tagName 必须是非空字符串字面量");
|
|
11423
|
+
tags.set(item.id.name, tagArgument.value);
|
|
11424
|
+
}
|
|
11425
|
+
}
|
|
11426
|
+
return tags;
|
|
11427
|
+
}
|
|
11428
|
+
function collectNativeBridgeContext(ast) {
|
|
11429
|
+
return {
|
|
11430
|
+
nativeComponentTags: collectNativeComponentTags(ast, collectRuntimeImportNames(ast, "createNativeComponent")),
|
|
11431
|
+
slotComponentNames: collectRuntimeImportNames(ast, "Slot")
|
|
11432
|
+
};
|
|
11433
|
+
}
|
|
11434
|
+
function hasNativeComponentBridge(source) {
|
|
11435
|
+
return collectNativeBridgeContext(parse(source, BABEL_TS_MODULE_PARSER_OPTIONS)).nativeComponentTags.size > 0;
|
|
11436
|
+
}
|
|
11437
|
+
function findFunctionDeclaration(ast, componentName) {
|
|
11438
|
+
for (const statement of ast.program.body) {
|
|
11439
|
+
if (t.isFunctionDeclaration(statement) && statement.id?.name === componentName) return statement;
|
|
11440
|
+
if (t.isExportNamedDeclaration(statement) && t.isFunctionDeclaration(statement.declaration) && statement.declaration.id?.name === componentName) return statement.declaration;
|
|
11441
|
+
}
|
|
11442
|
+
}
|
|
11443
|
+
function findReturnedTemplate(component) {
|
|
11444
|
+
for (const statement of component.body.body) {
|
|
11445
|
+
if (!t.isReturnStatement(statement) || !statement.argument) continue;
|
|
11446
|
+
if (t.isJSXElement(statement.argument) || t.isJSXFragment(statement.argument)) return statement.argument;
|
|
11447
|
+
}
|
|
11448
|
+
}
|
|
11449
|
+
function findFirstFunctionDeclaration(ast) {
|
|
11450
|
+
for (const statement of ast.program.body) {
|
|
11451
|
+
const candidate = t.isFunctionDeclaration(statement) ? statement : t.isExportNamedDeclaration(statement) && t.isFunctionDeclaration(statement.declaration) ? statement.declaration : void 0;
|
|
11452
|
+
if (candidate?.id && findReturnedTemplate(candidate)) return candidate;
|
|
11453
|
+
}
|
|
11454
|
+
}
|
|
11455
|
+
function compileStaticReactPage(source, filename, componentName) {
|
|
11456
|
+
const ast = parse(source, BABEL_TS_MODULE_PARSER_OPTIONS);
|
|
11457
|
+
const bridgeContext = collectNativeBridgeContext(ast);
|
|
11458
|
+
try {
|
|
11459
|
+
const component = componentName ? findFunctionDeclaration(ast, componentName) : findFirstFunctionDeclaration(ast);
|
|
11460
|
+
if (!component) throw new Error(`未找到直接 return JSX 的 static template 组件${componentName ? ` ${componentName}` : ""}`);
|
|
11461
|
+
const root = findReturnedTemplate(component);
|
|
11462
|
+
if (!root) throw new Error(`static template 组件 ${componentName ?? component.id?.name ?? ""} 必须直接 return JSX`);
|
|
11463
|
+
const context = {
|
|
11464
|
+
...bridgeContext,
|
|
11465
|
+
slots: [],
|
|
11466
|
+
slotSeed: 0,
|
|
11467
|
+
usedNativeComponents: /* @__PURE__ */ new Set()
|
|
11468
|
+
};
|
|
11469
|
+
const template = renderStaticTemplate(root, context);
|
|
11470
|
+
return {
|
|
11471
|
+
code: generate(ast, {
|
|
11472
|
+
sourceFileName: filename,
|
|
11473
|
+
sourceMaps: true
|
|
11474
|
+
}, source).code,
|
|
11475
|
+
nativeComponents: [...context.usedNativeComponents].sort(),
|
|
11476
|
+
slots: context.slots,
|
|
11477
|
+
template
|
|
11478
|
+
};
|
|
11479
|
+
} catch (error) {
|
|
11480
|
+
if (bridgeContext.nativeComponentTags.size > 0 && !(error instanceof ReactNativeBridgeStaticError)) throw new ReactNativeBridgeStaticError(filename, error);
|
|
11481
|
+
throw error;
|
|
11482
|
+
}
|
|
11483
|
+
}
|
|
11484
|
+
//#endregion
|
|
11485
|
+
//#region src/plugins/react/index.ts
|
|
11486
|
+
const REACT_PLUGIN_NAME = "weapp-vite:react";
|
|
11487
|
+
const REACT_FILE_RE = /\.(?:jsx|tsx)(?:\?.*)?$/;
|
|
11488
|
+
function resolveStaticTemplateFileName(cwd, id) {
|
|
11489
|
+
const cleanId = id.split("?", 1)[0] ?? id;
|
|
11490
|
+
let fileName = path$1.relative(cwd, cleanId).replaceAll("\\", "/").replace(/\.(?:jsx|tsx)$/, ".wxml").replace(/^src\//, "");
|
|
11491
|
+
if (fileName.endsWith("/view.wxml")) fileName = fileName.replace(/\/view\.wxml$/, "/index.wxml");
|
|
11492
|
+
return fileName;
|
|
11493
|
+
}
|
|
11494
|
+
function createDynamicTemplate(fileName) {
|
|
11495
|
+
const relative = path$1.posix.relative(path$1.posix.dirname(fileName), "runtime/base.wxml");
|
|
11496
|
+
return `<import src="${relative.startsWith(".") ? relative : `./${relative}`}" />\n<template is="react_root" data="{{root:root}}" />`;
|
|
11497
|
+
}
|
|
11498
|
+
function resolveReactConfig(value) {
|
|
11499
|
+
if (!value) return;
|
|
11500
|
+
return value === true ? {} : value;
|
|
11501
|
+
}
|
|
11502
|
+
function isReactEnabled(ctx) {
|
|
11503
|
+
return Boolean(resolveReactConfig(ctx.configService?.weappViteConfig?.react));
|
|
11504
|
+
}
|
|
11505
|
+
function resolveReactConfigValue(value) {
|
|
11506
|
+
const config = resolveReactConfig(value);
|
|
11507
|
+
if (!config) return;
|
|
11508
|
+
return {
|
|
11509
|
+
compiler: config.compiler ?? false,
|
|
11510
|
+
renderMode: config.renderMode ?? "auto",
|
|
11511
|
+
devWarnings: config.devWarnings ?? true
|
|
11512
|
+
};
|
|
11513
|
+
}
|
|
11514
|
+
function isReactStaticTemplateSource(value, id) {
|
|
11515
|
+
const config = resolveReactConfigValue(value);
|
|
11516
|
+
return Boolean(config && config.renderMode !== "dynamic" && REACT_FILE_RE.test(id) && !id.includes("/node_modules/"));
|
|
11517
|
+
}
|
|
11518
|
+
async function transformWithSwc$1(source, id, compilationMode) {
|
|
11519
|
+
try {
|
|
11520
|
+
const { transform } = await import("@swc/core");
|
|
11521
|
+
const result = await transform(source, {
|
|
11522
|
+
filename: id,
|
|
11523
|
+
jsc: {
|
|
11524
|
+
parser: {
|
|
11525
|
+
syntax: "typescript",
|
|
11526
|
+
tsx: true
|
|
11527
|
+
},
|
|
11528
|
+
target: "es2020",
|
|
11529
|
+
transform: {
|
|
11530
|
+
react: {
|
|
11531
|
+
importSource: "react",
|
|
11532
|
+
runtime: "automatic"
|
|
11533
|
+
},
|
|
11534
|
+
reactCompiler: { compilationMode }
|
|
11535
|
+
}
|
|
11536
|
+
},
|
|
11537
|
+
module: { type: "es6" },
|
|
11538
|
+
sourceMaps: true
|
|
11539
|
+
});
|
|
11540
|
+
return {
|
|
11541
|
+
code: result.code,
|
|
11542
|
+
map: result.map
|
|
11543
|
+
};
|
|
11544
|
+
} catch (error) {
|
|
11545
|
+
return {
|
|
11546
|
+
fallback: true,
|
|
11547
|
+
warning: `[react] React Compiler transform failed for ${id}; falling back to Oxc: ${error instanceof Error ? error.message : String(error)}`
|
|
11548
|
+
};
|
|
11549
|
+
}
|
|
11550
|
+
}
|
|
11551
|
+
function createReactPlugin(ctx) {
|
|
11552
|
+
const resolved = resolveReactConfigValue(ctx.configService?.weappViteConfig?.react);
|
|
11553
|
+
if (!resolved) return [];
|
|
11554
|
+
const reactConfig = resolved;
|
|
11555
|
+
let config;
|
|
11556
|
+
const templates = /* @__PURE__ */ new Map();
|
|
11557
|
+
async function refreshStaticTemplate(id, event, warn) {
|
|
11558
|
+
if (!isReactStaticTemplateSource(reactConfig, id)) return;
|
|
11559
|
+
const cleanId = id.split("?", 1)[0] ?? id;
|
|
11560
|
+
const fileName = resolveStaticTemplateFileName(ctx.configService?.cwd ?? process.cwd(), cleanId);
|
|
11561
|
+
if (event === "delete") {
|
|
11562
|
+
templates.delete(fileName);
|
|
11563
|
+
return;
|
|
11564
|
+
}
|
|
11565
|
+
try {
|
|
11566
|
+
const compiled = compileStaticReactPage(await readFile(cleanId, "utf8"), cleanId);
|
|
11567
|
+
templates.set(fileName, {
|
|
11568
|
+
nativeComponents: compiled.nativeComponents,
|
|
11569
|
+
source: compiled.template
|
|
11570
|
+
});
|
|
11571
|
+
} catch (error) {
|
|
11572
|
+
if (error instanceof ReactNativeBridgeStaticError) throw error;
|
|
11573
|
+
if (reactConfig.renderMode === "static") throw error;
|
|
11574
|
+
templates.set(fileName, {
|
|
11575
|
+
nativeComponents: [],
|
|
11576
|
+
source: createDynamicTemplate(fileName)
|
|
11577
|
+
});
|
|
11578
|
+
if (reactConfig.devWarnings && error instanceof Error) warn(`[react] dynamic island fallback for ${cleanId}: ${error.message}`);
|
|
11579
|
+
}
|
|
11580
|
+
}
|
|
11581
|
+
return [{
|
|
11582
|
+
name: REACT_PLUGIN_NAME,
|
|
11583
|
+
enforce: "pre",
|
|
11584
|
+
configResolved(next) {
|
|
11585
|
+
config = next;
|
|
11586
|
+
},
|
|
11587
|
+
async watchChange(id, change) {
|
|
11588
|
+
await refreshStaticTemplate(id, change.event, (message) => this.warn(message));
|
|
11589
|
+
},
|
|
11590
|
+
async handleHotUpdate(context) {
|
|
11591
|
+
await refreshStaticTemplate(context.file, "update", (message) => this.warn(message));
|
|
11592
|
+
},
|
|
11593
|
+
transform: async function transformReact(source, id) {
|
|
11594
|
+
if (!REACT_FILE_RE.test(id) || id.includes("/node_modules/")) return null;
|
|
11595
|
+
let transformedSource = source;
|
|
11596
|
+
const fileName = resolveStaticTemplateFileName(ctx.configService?.cwd ?? process.cwd(), id);
|
|
11597
|
+
if (resolved.renderMode === "dynamic" && hasNativeComponentBridge(source)) throw new Error(`[react] ${id} 使用了原生组件 bridge,renderMode: 'dynamic' 不支持自定义组件`);
|
|
11598
|
+
if (resolved.renderMode !== "dynamic") try {
|
|
11599
|
+
const compiled = compileStaticReactPage(source, id);
|
|
11600
|
+
templates.set(fileName, {
|
|
11601
|
+
nativeComponents: compiled.nativeComponents,
|
|
11602
|
+
source: compiled.template
|
|
11603
|
+
});
|
|
11604
|
+
transformedSource = compiled.code;
|
|
11605
|
+
} catch (error) {
|
|
11606
|
+
if (resolved.renderMode === "static" || error instanceof ReactNativeBridgeStaticError) throw error;
|
|
11607
|
+
templates.set(fileName, {
|
|
11608
|
+
nativeComponents: [],
|
|
11609
|
+
source: createDynamicTemplate(fileName)
|
|
11610
|
+
});
|
|
11611
|
+
if (resolved.devWarnings && error instanceof Error) this.warn(`[react] dynamic island fallback for ${id}: ${error.message}`);
|
|
11612
|
+
}
|
|
11613
|
+
else templates.set(fileName, {
|
|
11614
|
+
nativeComponents: [],
|
|
11615
|
+
source: createDynamicTemplate(fileName)
|
|
11616
|
+
});
|
|
11617
|
+
if (resolved.compiler !== false) {
|
|
11618
|
+
const compilerConfig = typeof resolved.compiler === "object" ? resolved.compiler : {};
|
|
11619
|
+
const result = await transformWithSwc$1(transformedSource, id, compilerConfig.compilationMode ?? "infer");
|
|
11620
|
+
if (!result.fallback) return result;
|
|
11621
|
+
if (resolved.devWarnings !== false) this.warn(result.warning);
|
|
11622
|
+
}
|
|
11623
|
+
return await transformWithOxc(transformedSource, id, {
|
|
11624
|
+
jsx: {
|
|
11625
|
+
importSource: "react",
|
|
11626
|
+
runtime: "automatic"
|
|
11627
|
+
},
|
|
11628
|
+
lang: "tsx",
|
|
11629
|
+
sourcemap: Boolean(config?.command === "serve")
|
|
11630
|
+
});
|
|
11631
|
+
},
|
|
11632
|
+
generateBundle(_options, bundle) {
|
|
11633
|
+
for (const [fileName, template] of templates) {
|
|
11634
|
+
if (template.nativeComponents.length > 0) {
|
|
11635
|
+
const jsonFileName = fileName.replace(/\.wxml$/, ".json");
|
|
11636
|
+
const jsonAsset = bundle[jsonFileName];
|
|
11637
|
+
if (jsonAsset?.type !== "asset") throw new Error(`[react] ${fileName} 使用了原生组件 bridge,但缺少对应配置 ${jsonFileName}`);
|
|
11638
|
+
let json;
|
|
11639
|
+
try {
|
|
11640
|
+
json = JSON.parse(String(jsonAsset.source));
|
|
11641
|
+
} catch (error) {
|
|
11642
|
+
throw new Error(`[react] 无法解析原生组件配置 ${jsonFileName}`, { cause: error });
|
|
11643
|
+
}
|
|
11644
|
+
const usingComponents = json.usingComponents;
|
|
11645
|
+
const registered = usingComponents && typeof usingComponents === "object" && !Array.isArray(usingComponents) ? usingComponents : {};
|
|
11646
|
+
const missing = template.nativeComponents.filter((tag) => typeof registered[tag] !== "string");
|
|
11647
|
+
if (missing.length > 0) throw new Error(`[react] ${fileName} 的原生组件 bridge 未在 ${jsonFileName} 的 usingComponents 注册:${missing.join(", ")}`);
|
|
11648
|
+
}
|
|
11649
|
+
const existing = bundle[fileName];
|
|
11650
|
+
if (existing?.type === "asset") existing.source = template.source;
|
|
11651
|
+
else this.emitFile({
|
|
11652
|
+
type: "asset",
|
|
11653
|
+
fileName,
|
|
11654
|
+
source: template.source
|
|
11655
|
+
});
|
|
11656
|
+
}
|
|
11657
|
+
if (resolved.renderMode !== "static" && !bundle["runtime/base.wxml"]) this.emitFile({
|
|
11658
|
+
type: "asset",
|
|
11659
|
+
fileName: "runtime/base.wxml",
|
|
11660
|
+
source: baseTemplate
|
|
11661
|
+
});
|
|
11662
|
+
}
|
|
11663
|
+
}];
|
|
11664
|
+
}
|
|
11665
|
+
//#endregion
|
|
11145
11666
|
//#region src/runtime/statefulHmr/outputWriter.ts
|
|
11146
11667
|
/**
|
|
11147
11668
|
* @description 通过独立的 Vite write 阶段持久化 DevEngine 已生成的文件,不重新解析业务源码。
|
|
@@ -11804,7 +12325,11 @@ async function runStatefulHmrDev(ctx, buildOptions, restart, snapshots) {
|
|
|
11804
12325
|
server: {
|
|
11805
12326
|
...buildOptions.server ?? {},
|
|
11806
12327
|
host: "127.0.0.1",
|
|
11807
|
-
port: 0
|
|
12328
|
+
port: 0,
|
|
12329
|
+
watch: {
|
|
12330
|
+
...buildOptions.server?.watch ?? {},
|
|
12331
|
+
ignored: createStatefulHmrWatchIgnored(buildOptions.root ?? configService.cwd, configService.outDir, buildOptions.server?.watch?.ignored)
|
|
12332
|
+
}
|
|
11808
12333
|
},
|
|
11809
12334
|
build: {
|
|
11810
12335
|
...buildOptions.build ?? {},
|
|
@@ -11823,6 +12348,14 @@ async function runStatefulHmrDev(ctx, buildOptions, restart, snapshots) {
|
|
|
11823
12348
|
throw error;
|
|
11824
12349
|
}
|
|
11825
12350
|
}
|
|
12351
|
+
function createStatefulHmrWatchIgnored(root, outDir, ignored) {
|
|
12352
|
+
const normalizedRoot = normalizeFsResolvedId(root);
|
|
12353
|
+
const normalizedOutDir = normalizeFsResolvedId(path.isAbsolute(outDir) ? outDir : path.resolve(root, outDir));
|
|
12354
|
+
return [...ignored === void 0 ? [] : Array.isArray(ignored) ? ignored : [ignored], (id) => {
|
|
12355
|
+
const normalizedId = normalizeFsResolvedId(path.isAbsolute(id) ? id : path.resolve(normalizedRoot, id));
|
|
12356
|
+
return isPathInside(normalizedOutDir, normalizedId);
|
|
12357
|
+
}];
|
|
12358
|
+
}
|
|
11826
12359
|
var StatefulHmrSession = class {
|
|
11827
12360
|
ctx;
|
|
11828
12361
|
server;
|
|
@@ -11891,7 +12424,7 @@ var StatefulHmrSession = class {
|
|
|
11891
12424
|
const normalizedFile = normalizeFsResolvedId(path.isAbsolute(file) ? file : path.resolve(this.server.config.root, file));
|
|
11892
12425
|
const normalizedOutDir = normalizeFsResolvedId(this.ctx.configService.outDir).replace(/\/$/, "");
|
|
11893
12426
|
if (normalizedFile === normalizedOutDir || normalizedFile.startsWith(`${normalizedOutDir}/`)) return;
|
|
11894
|
-
if (shouldRestartStatefulHmrServer([normalizedFile], this.ctx.configService?.configFileDependencies)) {
|
|
12427
|
+
if (shouldRestartStatefulHmrServer([normalizedFile], this.ctx.configService?.configFileDependencies, this.ctx.configService?.weappViteConfig?.react)) {
|
|
11895
12428
|
this.requestServerRestart();
|
|
11896
12429
|
return;
|
|
11897
12430
|
}
|
|
@@ -11930,7 +12463,7 @@ var StatefulHmrSession = class {
|
|
|
11930
12463
|
if (output.type === "Noop") return false;
|
|
11931
12464
|
if (!isSafeJavaScriptPatch(files, output, this.ctx.runtimeState.build.hmr.profile.dirtyReasonSummary, this.ctx.runtimeState.build.hmr.resolvedEntryMap.keys(), this.server.config.root)) {
|
|
11932
12465
|
if (shouldRestartStatefulHmrServer(files, this.ctx.configService?.configFileDependencies)) this.requestServerRestart();
|
|
11933
|
-
else if (files.length > 0 && files.every(isStatefulHmrAssetFile) || shouldUseStatefulHmrSnapshotOnly(this.ctx.runtimeState.build.hmr.profile.dirtyReasonSummary ?? [])) {
|
|
12466
|
+
else if (this.snapshotScheduler.isPending() || files.length > 0 && files.every(isStatefulHmrAssetFile) || shouldUseStatefulHmrSnapshotOnly(this.ctx.runtimeState.build.hmr.profile.dirtyReasonSummary ?? [])) {
|
|
11934
12467
|
if (!this.snapshotScheduler.isPending()) this.requestSnapshotRefresh(files);
|
|
11935
12468
|
} else this.requestFullBuild(files);
|
|
11936
12469
|
return false;
|
|
@@ -11998,9 +12531,9 @@ var StatefulHmrSession = class {
|
|
|
11998
12531
|
await this.outputChain;
|
|
11999
12532
|
}
|
|
12000
12533
|
};
|
|
12001
|
-
function shouldRestartStatefulHmrServer(files, configFileDependencies = []) {
|
|
12534
|
+
function shouldRestartStatefulHmrServer(files, configFileDependencies = [], react) {
|
|
12002
12535
|
const normalizedConfigDependencies = new Set(Array.from(configFileDependencies, (dependency) => normalizeFsResolvedId(dependency)));
|
|
12003
|
-
return Array.from(files).some((file) => normalizedConfigDependencies.has(normalizeFsResolvedId(file)));
|
|
12536
|
+
return Array.from(files).some((file) => normalizedConfigDependencies.has(normalizeFsResolvedId(file)) || isReactStaticTemplateSource(react, file));
|
|
12004
12537
|
}
|
|
12005
12538
|
function mergeStatefulHmrSnapshotAssets(output, snapshotAssets) {
|
|
12006
12539
|
for (const asset of snapshotAssets) {
|
|
@@ -12067,13 +12600,13 @@ function isSafeJavaScriptPatch(files, output, dirtyReasonSummary = [], entryIds,
|
|
|
12067
12600
|
})) && !output.changedIds?.some(isNonJavaScriptSidecarId) && !dirtyReasonSummary.some(isUnsafeStatefulHmrReason);
|
|
12068
12601
|
}
|
|
12069
12602
|
function requiresStatefulHmrSnapshot(file, dirtyReasonSummary = []) {
|
|
12070
|
-
return !/\.(?:[cm]?[jt]sx?|vue)$/.test(file) || dirtyReasonSummary.some(isUnsafeStatefulHmrReason);
|
|
12603
|
+
return /\.(?:jsx|tsx)$/.test(file) || !/\.(?:[cm]?[jt]sx?|vue)$/.test(file) || dirtyReasonSummary.some(isUnsafeStatefulHmrReason);
|
|
12071
12604
|
}
|
|
12072
12605
|
function isStatefulHmrAssetFile(file) {
|
|
12073
12606
|
return !/\.(?:[cm]?[jt]sx?|vue)$/.test(file);
|
|
12074
12607
|
}
|
|
12075
12608
|
function isUnsafeStatefulHmrReason(reason) {
|
|
12076
|
-
return /^(?:entry-json-only|entry-local-asset|entry-style-only|tailwind-content):/.test(reason);
|
|
12609
|
+
return /^(?:entry-json-only|entry-local-asset|entry-style-only|react-template|tailwind-content):/.test(reason);
|
|
12077
12610
|
}
|
|
12078
12611
|
function shouldUseStatefulHmrSnapshotOnly(dirtyReasonSummary) {
|
|
12079
12612
|
return dirtyReasonSummary.some((reason) => /^(?:entry-json-only|entry-local-asset|entry-style-only):/.test(reason)) && dirtyReasonSummary.every((reason) => /^(?:entry-json-only|entry-local-asset|entry-style-only|tailwind-content):/.test(reason));
|
|
@@ -12154,7 +12687,7 @@ const GLOB_WILDCARD_RE$1 = /[*?[{]/;
|
|
|
12154
12687
|
const TRAILING_SLASHES_RE$2 = /\/+$/;
|
|
12155
12688
|
const AUTO_IMPORT_WATCHER_KEY = "__auto-import-vue-watcher__";
|
|
12156
12689
|
const AUTO_IMPORT_CONFIG_SUFFIXES = configExtensions.map((ext) => `.${ext}`);
|
|
12157
|
-
const AUTO_IMPORT_JS_SUFFIXES = new Set(
|
|
12690
|
+
const AUTO_IMPORT_JS_SUFFIXES = new Set(scriptExtensions.map((ext) => `.${ext}`));
|
|
12158
12691
|
const AUTO_IMPORT_TEMPLATE_SUFFIXES = new Set(templateExtensions.map((ext) => `.${ext}`));
|
|
12159
12692
|
const AUTO_IMPORT_VUE_SUFFIXES = new Set(vueExtensions.map((ext) => `.${ext}`));
|
|
12160
12693
|
function hasOwn$4(source, key) {
|
|
@@ -13240,6 +13773,7 @@ function shouldNormalizeTemplateImportSource(value) {
|
|
|
13240
13773
|
}
|
|
13241
13774
|
//#endregion
|
|
13242
13775
|
//#region src/wxml/scan/parser.ts
|
|
13776
|
+
const wxsScriptExtensions = /* @__PURE__ */ new Set(["js", "ts"]);
|
|
13243
13777
|
const TAG_NAME_LOWER_TO_UPPER_RE = /([a-z0-9])([A-Z])/g;
|
|
13244
13778
|
const TAG_NAME_MULTI_UPPER_RE = /([A-Z]+)([A-Z][a-z])/g;
|
|
13245
13779
|
const TAG_NAME_HAS_UPPER_RE = /[A-Z]/;
|
|
@@ -13351,7 +13885,7 @@ function parseWxml(options) {
|
|
|
13351
13885
|
});
|
|
13352
13886
|
}
|
|
13353
13887
|
}
|
|
13354
|
-
if (currentTagName && isScriptModuleTagName(currentTagName) && name === "lang" &&
|
|
13888
|
+
if (currentTagName && isScriptModuleTagName(currentTagName) && name === "lang" && wxsScriptExtensions.has(value)) removeWxsLangAttrTokens.push({
|
|
13355
13889
|
start: parser.startIndex,
|
|
13356
13890
|
end: parser.endIndex,
|
|
13357
13891
|
value
|
|
@@ -13399,7 +13933,7 @@ function parseWxml(options) {
|
|
|
13399
13933
|
tagStartIndex = 0;
|
|
13400
13934
|
},
|
|
13401
13935
|
ontext(data) {
|
|
13402
|
-
if (currentTagName && isScriptModuleTagName(currentTagName) &&
|
|
13936
|
+
if (currentTagName && isScriptModuleTagName(currentTagName) && wxsScriptExtensions.has(attrs.lang)) inlineWxsTokens.push({
|
|
13403
13937
|
start: parser.startIndex,
|
|
13404
13938
|
end: parser.endIndex,
|
|
13405
13939
|
value: data
|
|
@@ -13529,7 +14063,7 @@ function getManagedTypeScriptConfig(ctx) {
|
|
|
13529
14063
|
async function readLegacyManagedTsconfigFile(filePath) {
|
|
13530
14064
|
try {
|
|
13531
14065
|
const content = await fs$1.readFile(filePath, "utf8");
|
|
13532
|
-
const parsed = parse$
|
|
14066
|
+
const parsed = parse$2(content, void 0, true);
|
|
13533
14067
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return;
|
|
13534
14068
|
return parsed;
|
|
13535
14069
|
} catch {
|
|
@@ -13769,7 +14303,7 @@ async function readTsconfigData(filePath) {
|
|
|
13769
14303
|
const content = await fs$1.readFile(filePath, "utf8").catch(() => void 0);
|
|
13770
14304
|
if (!content) return;
|
|
13771
14305
|
try {
|
|
13772
|
-
const parsed = parse$
|
|
14306
|
+
const parsed = parse$2(content, void 0, true);
|
|
13773
14307
|
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : void 0;
|
|
13774
14308
|
} catch {
|
|
13775
14309
|
return;
|
|
@@ -13854,7 +14388,7 @@ async function syncManagedTsconfigBootstrapFiles(cwd) {
|
|
|
13854
14388
|
function parseJsonObject(content) {
|
|
13855
14389
|
if (!content) return;
|
|
13856
14390
|
try {
|
|
13857
|
-
const parsed = parse$
|
|
14391
|
+
const parsed = parse$2(content, void 0, true);
|
|
13858
14392
|
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : void 0;
|
|
13859
14393
|
} catch {
|
|
13860
14394
|
return;
|
|
@@ -13922,7 +14456,7 @@ async function collectAutoImportTemplateTags(ctx) {
|
|
|
13922
14456
|
const source = await readFile(filePath, "utf8").catch(() => void 0);
|
|
13923
14457
|
if (!source) return;
|
|
13924
14458
|
if (filePath.endsWith(".vue")) {
|
|
13925
|
-
const { descriptor, errors } = parse(source, { filename: filePath });
|
|
14459
|
+
const { descriptor, errors } = parse$1(source, { filename: filePath });
|
|
13926
14460
|
if (errors.length > 0 || !descriptor.template?.content) return;
|
|
13927
14461
|
for (const tag of collectVueTemplateAutoImportTags(descriptor.template.content, filePath)) tags.set(tag, removeExtensionDeep(filePath));
|
|
13928
14462
|
return;
|
|
@@ -14186,14 +14720,38 @@ function createIndependentBuilder(configService, buildState) {
|
|
|
14186
14720
|
const task = (async () => {
|
|
14187
14721
|
try {
|
|
14188
14722
|
const chunkRoot = meta.subPackage.root ?? root;
|
|
14189
|
-
const
|
|
14723
|
+
const isolatedCtx = createCompilerContextInstance();
|
|
14724
|
+
await isolatedCtx.configService.load({
|
|
14725
|
+
cwd: configService.cwd,
|
|
14726
|
+
isDev: configService.isDev,
|
|
14727
|
+
mode: configService.mode,
|
|
14728
|
+
configFile: configService.configFilePath,
|
|
14729
|
+
cliPlatform: configService.platform,
|
|
14730
|
+
projectConfigPath: configService.projectConfigPath
|
|
14731
|
+
});
|
|
14732
|
+
const isolatedConfigService = isolatedCtx.configService;
|
|
14733
|
+
isolatedConfigService.options = {
|
|
14734
|
+
...isolatedConfigService.options,
|
|
14735
|
+
currentSubPackageRoot: chunkRoot
|
|
14736
|
+
};
|
|
14737
|
+
const inlineConfig = isolatedConfigService.merge(meta, meta.subPackage.inlineConfig, { build: {
|
|
14190
14738
|
write: false,
|
|
14191
14739
|
watch: null,
|
|
14192
14740
|
rolldownOptions: { output: { chunkFileNames() {
|
|
14193
14741
|
return `${chunkRoot}/[name].js`;
|
|
14194
14742
|
} } }
|
|
14195
14743
|
} });
|
|
14196
|
-
const
|
|
14744
|
+
const autoImportGlobs = getAutoImportConfig(isolatedConfigService)?.globs;
|
|
14745
|
+
if (autoImportGlobs?.length) {
|
|
14746
|
+
const candidates = await findAutoImportCandidates({
|
|
14747
|
+
ctx: isolatedCtx,
|
|
14748
|
+
resolvedConfig: { build: { outDir: isolatedConfigService.outDir } }
|
|
14749
|
+
}, autoImportGlobs);
|
|
14750
|
+
await isolatedCtx.autoImportService.runWithoutOutputWrites(async () => {
|
|
14751
|
+
await Promise.all(candidates.map((candidate) => isolatedCtx.autoImportService.registerPotentialComponent(candidate)));
|
|
14752
|
+
});
|
|
14753
|
+
}
|
|
14754
|
+
const restoreDefineEnv = syncImportMetaEnvDefineOverride(isolatedConfigService, inlineConfig.define);
|
|
14197
14755
|
let result;
|
|
14198
14756
|
try {
|
|
14199
14757
|
result = await build(inlineConfig);
|
|
@@ -16516,7 +17074,7 @@ async function inspectTsconfigPathsState(filePath, visited) {
|
|
|
16516
17074
|
}
|
|
16517
17075
|
let parsed;
|
|
16518
17076
|
try {
|
|
16519
|
-
parsed = parse$
|
|
17077
|
+
parsed = parse$2(content);
|
|
16520
17078
|
} catch {
|
|
16521
17079
|
return {
|
|
16522
17080
|
root: false,
|
|
@@ -19790,7 +20348,7 @@ function buildTailwindContentPayload(descriptor, filename) {
|
|
|
19790
20348
|
};
|
|
19791
20349
|
}
|
|
19792
20350
|
function buildVueSfcSignaturePayloadWithTs(source, filename) {
|
|
19793
|
-
const { descriptor, errors } = parse(source, { filename });
|
|
20351
|
+
const { descriptor, errors } = parse$1(source, { filename });
|
|
19794
20352
|
if (errors.length) return;
|
|
19795
20353
|
return {
|
|
19796
20354
|
nonJson: buildNonJsonDescriptorPayload(descriptor, filename),
|
|
@@ -20041,7 +20599,7 @@ function stripTypeSyntaxFromAst(ast) {
|
|
|
20041
20599
|
});
|
|
20042
20600
|
}
|
|
20043
20601
|
function parseExpressionAst(expression) {
|
|
20044
|
-
const file = parse$
|
|
20602
|
+
const file = parse$3(`const __wv_layout_expr__ = ${expression}`, BABEL_TS_MODULE_PARSER_OPTIONS$1);
|
|
20045
20603
|
stripTypeSyntaxFromAst(file);
|
|
20046
20604
|
const stmt = file.program.body[0];
|
|
20047
20605
|
if (!stmt || !t.isVariableDeclaration(stmt)) return null;
|
|
@@ -20102,7 +20660,7 @@ function injectLayoutBindingComputed(script, props) {
|
|
|
20102
20660
|
if (!script || !props) return script;
|
|
20103
20661
|
const runtimeEntries = Object.entries(props).filter((entry) => typeof entry[1] === "object" && entry[1] !== null && "kind" in entry[1] && entry[1].kind === "expression");
|
|
20104
20662
|
if (runtimeEntries.length === 0) return script;
|
|
20105
|
-
const ast = parse$
|
|
20663
|
+
const ast = parse$3(script, BABEL_TS_MODULE_PARSER_OPTIONS$1);
|
|
20106
20664
|
const optionsObject = findWevuOptionsObject(ast);
|
|
20107
20665
|
if (!optionsObject) return script;
|
|
20108
20666
|
const computedEntries = runtimeEntries.map(([key, value]) => {
|
|
@@ -20171,7 +20729,7 @@ function injectNativePageLayoutState(pageOptions, currentLayout) {
|
|
|
20171
20729
|
}
|
|
20172
20730
|
function injectNativePageLayoutRuntime(script, filename, plan) {
|
|
20173
20731
|
if (!script) return script;
|
|
20174
|
-
const ast = parse$
|
|
20732
|
+
const ast = parse$3(script, BABEL_TS_MODULE_PARSER_OPTIONS$1);
|
|
20175
20733
|
stripTypeSyntaxFromAst(ast);
|
|
20176
20734
|
const strippedMeta = stripDefinePageMetaCalls(ast);
|
|
20177
20735
|
const shouldInjectSetter = Boolean(plan?.dynamicSwitch);
|
|
@@ -20354,10 +20912,10 @@ function collectSetPageLayoutPropKeysFromProgram(ast) {
|
|
|
20354
20912
|
return [...keys];
|
|
20355
20913
|
}
|
|
20356
20914
|
function parseScriptAst(content) {
|
|
20357
|
-
return parse$
|
|
20915
|
+
return parse$3(content, BABEL_TS_MODULE_PARSER_OPTIONS$1);
|
|
20358
20916
|
}
|
|
20359
20917
|
function analyzeVueScriptBlocks(source, filename) {
|
|
20360
|
-
const { descriptor } = parse(source, { filename });
|
|
20918
|
+
const { descriptor } = parse$1(source, { filename });
|
|
20361
20919
|
return {
|
|
20362
20920
|
descriptor,
|
|
20363
20921
|
scriptAst: descriptor.script?.content ? parseScriptAst(descriptor.script.content) : void 0,
|
|
@@ -20674,7 +21232,7 @@ function hasWevuTemplateRuntimeBindings(template) {
|
|
|
20674
21232
|
return typeof template === "string" && WEVU_TEMPLATE_RUNTIME_BINDING_ATTR_RE.test(template);
|
|
20675
21233
|
}
|
|
20676
21234
|
function isDefineComponentJsonOnlyScript(content) {
|
|
20677
|
-
const ast = parse$
|
|
21235
|
+
const ast = parse$3(content, BABEL_TS_MODULE_PARSER_OPTIONS$1);
|
|
20678
21236
|
let hasDefineComponentJson = false;
|
|
20679
21237
|
for (const statement of ast.program.body) {
|
|
20680
21238
|
if (t.isEmptyStatement(statement)) continue;
|
|
@@ -20686,7 +21244,7 @@ function isDefineComponentJsonOnlyScript(content) {
|
|
|
20686
21244
|
return hasDefineComponentJson;
|
|
20687
21245
|
}
|
|
20688
21246
|
function shouldEmitScriptlessVueLayoutJs(source, filename) {
|
|
20689
|
-
const { descriptor } = parse(source, { filename });
|
|
21247
|
+
const { descriptor } = parse$1(source, { filename });
|
|
20690
21248
|
if (hasWevuTemplateRuntimeBindings(descriptor.template?.content)) return false;
|
|
20691
21249
|
const blocks = [descriptor.script?.content, descriptor.scriptSetup?.content].filter((content) => typeof content === "string" && content.trim().length > 0);
|
|
20692
21250
|
if (blocks.length === 0) return true;
|
|
@@ -21534,7 +22092,10 @@ async function emitEntryOutput(options) {
|
|
|
21534
22092
|
continue;
|
|
21535
22093
|
}
|
|
21536
22094
|
const normalizedResolvedId = normalizeFsResolvedId(resolvedId.id);
|
|
21537
|
-
if (normalizedResolvedId && !isSkippableResolvedId(normalizedResolvedId))
|
|
22095
|
+
if (normalizedResolvedId && !isSkippableResolvedId(normalizedResolvedId)) {
|
|
22096
|
+
resolvedEntryMap.set(normalizedResolvedId, resolvedId);
|
|
22097
|
+
if (/\.(?:jsx|tsx)$/.test(normalizedResolvedId)) addNormalizedWatchFile(pluginCtx, normalizedResolvedId);
|
|
22098
|
+
}
|
|
21538
22099
|
const isForcedEntry = forceEmitEntrySet?.has(entry) === true || forceEmitEntrySet?.has(normalizedResolvedId) === true;
|
|
21539
22100
|
const isForcedReloadEntry = forceReloadEntrySet?.has(entry) === true || forceReloadEntrySet?.has(normalizedResolvedId) === true;
|
|
21540
22101
|
const isDirtyEntry = dirtyEntrySet.has(normalizedResolvedId);
|
|
@@ -23278,24 +23839,27 @@ function resolveWevuExportAliasMap(wevuChunk) {
|
|
|
23278
23839
|
const exportMatch = new RegExp(`\\b([A-Za-z_$][\\w$]*)\\s+as\\s+${exportName}\\b`).exec(code);
|
|
23279
23840
|
if (exportMatch?.[1]) aliases.set(exportName, exportMatch[1]);
|
|
23280
23841
|
}
|
|
23281
|
-
const propertyExports = Array.from(code.matchAll(/Object\.defineProperty\(exports,\s*["']([^"']+)[
|
|
23842
|
+
const propertyExports = Array.from(code.matchAll(/Object\.defineProperty\(exports,\s*(["'`])([^"'`]+)\1,\s*\{[^{}]*\bget\s*:\s*function\s*\(\)\s*\{([^{}]*)\}\s*\}\s*\)/g)).flatMap((match) => {
|
|
23843
|
+
const getterReturn = /^return\s+([A-Za-z_$][\w$]*);?$/.exec((match[3] ?? "").trim());
|
|
23844
|
+
return getterReturn?.[1] ? [[match[2], getterReturn[1]]] : [];
|
|
23845
|
+
});
|
|
23282
23846
|
for (const [exportName] of WEVU_EXPORT_ALIASES) {
|
|
23283
23847
|
if (aliases.has(exportName)) continue;
|
|
23284
|
-
const semanticExport = propertyExports.find((match) => match[
|
|
23285
|
-
if (semanticExport?.[
|
|
23286
|
-
aliases.set(exportName, semanticExport[
|
|
23848
|
+
const semanticExport = propertyExports.find((match) => match[0] === exportName);
|
|
23849
|
+
if (semanticExport?.[1]) {
|
|
23850
|
+
aliases.set(exportName, semanticExport[1]);
|
|
23287
23851
|
continue;
|
|
23288
23852
|
}
|
|
23289
|
-
const stableExport = propertyExports.find((match) => match[
|
|
23290
|
-
if (stableExport?.[
|
|
23291
|
-
aliases.set(exportName, stableExport[
|
|
23853
|
+
const stableExport = propertyExports.find((match) => match[0] === `__wevu${exportName[0].toUpperCase()}${exportName.slice(1)}`);
|
|
23854
|
+
if (stableExport?.[1]) {
|
|
23855
|
+
aliases.set(exportName, stableExport[1]);
|
|
23292
23856
|
continue;
|
|
23293
23857
|
}
|
|
23294
23858
|
}
|
|
23295
|
-
if (!aliases.has("defineComponent") && localIdentifiers.has("eo")) aliases.set("defineComponent", "eo");
|
|
23296
|
-
if (!aliases.has("createWevuComponent") && localIdentifiers.has("to")) aliases.set("createWevuComponent", "to");
|
|
23859
|
+
if (WEVU_SRC_CHUNK_RE.test(wevuChunk.fileName) && !aliases.has("defineComponent") && localIdentifiers.has("eo")) aliases.set("defineComponent", "eo");
|
|
23860
|
+
if (WEVU_SRC_CHUNK_RE.test(wevuChunk.fileName) && !aliases.has("createWevuComponent") && localIdentifiers.has("to")) aliases.set("createWevuComponent", "to");
|
|
23297
23861
|
if (!aliases.has("defineComponent")) {
|
|
23298
|
-
const createWevuComponentLocal = (propertyExports.find((match) => match[
|
|
23862
|
+
const createWevuComponentLocal = (propertyExports.find((match) => match[0] === "createWevuComponent") ?? propertyExports.find((match) => match[0] === "__wevuCreateWevuComponent"))?.[1];
|
|
23299
23863
|
if (createWevuComponentLocal) {
|
|
23300
23864
|
const functionMatch = new RegExp(`function\\s+${createWevuComponentLocal}\\s*\\([^)]*\\)\\s*\\{[\\s\\S]{0,500}?\\b([A-Za-z_$][\\w$]*)\\s*\\(`).exec(code);
|
|
23301
23865
|
if (functionMatch?.[1]) aliases.set("defineComponent", functionMatch[1]);
|
|
@@ -23356,7 +23920,7 @@ function appendWevuRuntimeExports(chunk, aliases, importedMembers) {
|
|
|
23356
23920
|
const localIdentifiers = collectLocalRuntimeIdentifiers(chunk.code);
|
|
23357
23921
|
for (const [exportName, stableName] of WEVU_EXPORT_ALIASES) {
|
|
23358
23922
|
const localName = aliases.get(exportName);
|
|
23359
|
-
if (!localName || existingExports.has(stableName)) continue;
|
|
23923
|
+
if (!localName || !localIdentifiers.has(localName) || existingExports.has(stableName)) continue;
|
|
23360
23924
|
lines.push(`Object.defineProperty(exports, ${JSON.stringify(stableName)}, { enumerable: false, get: function() { return ${localName}; } });`);
|
|
23361
23925
|
existingExports.add(stableName);
|
|
23362
23926
|
}
|
|
@@ -24024,7 +24588,7 @@ function mayContainRequestGlobalsUsageByText(code, allowedTargets) {
|
|
|
24024
24588
|
}
|
|
24025
24589
|
function extractRequestGlobalsUsageSource(code) {
|
|
24026
24590
|
if (!code.includes("<script")) return code;
|
|
24027
|
-
const { descriptor, errors } = parse(code, {
|
|
24591
|
+
const { descriptor, errors } = parse$1(code, {
|
|
24028
24592
|
filename: "request-globals-usage.vue",
|
|
24029
24593
|
ignoreEmpty: false
|
|
24030
24594
|
});
|
|
@@ -24175,7 +24739,7 @@ function injectCodeIntoSfcBlock(source, startOffset, injection) {
|
|
|
24175
24739
|
*/
|
|
24176
24740
|
function injectRequestGlobalsIntoSfc(source, targets, options) {
|
|
24177
24741
|
if (targets.length === 0) return source;
|
|
24178
|
-
const { descriptor, errors } = parse(source, {
|
|
24742
|
+
const { descriptor, errors } = parse$1(source, {
|
|
24179
24743
|
filename: "request-globals.vue",
|
|
24180
24744
|
ignoreEmpty: false
|
|
24181
24745
|
});
|
|
@@ -25299,7 +25863,7 @@ function replaceImportMetaAccess(code, options) {
|
|
|
25299
25863
|
}
|
|
25300
25864
|
function replaceImportMetaAccessInSfc(source, options) {
|
|
25301
25865
|
if (!source.includes("import.meta")) return source;
|
|
25302
|
-
const { descriptor, errors } = parse(source, {
|
|
25866
|
+
const { descriptor, errors } = parse$1(source, {
|
|
25303
25867
|
filename: "import-meta.vue",
|
|
25304
25868
|
ignoreEmpty: false
|
|
25305
25869
|
});
|
|
@@ -25591,10 +26155,7 @@ function rewriteBundlePlatformApi(bundle, globalName, options) {
|
|
|
25591
26155
|
cache: options?.analysisCache
|
|
25592
26156
|
});
|
|
25593
26157
|
if (analysis && !analysis.hasPlatformApiAccess) continue;
|
|
25594
|
-
const magicString = createMiniProgramPlatformApiRewrite(chunk.code, globalName
|
|
25595
|
-
...options,
|
|
25596
|
-
analysis
|
|
25597
|
-
});
|
|
26158
|
+
const magicString = createMiniProgramPlatformApiRewrite(chunk.code, globalName);
|
|
25598
26159
|
if (!magicString) continue;
|
|
25599
26160
|
applyMagicStringChunkRewrite(chunk, magicString);
|
|
25600
26161
|
}
|
|
@@ -27185,7 +27746,34 @@ function resolveRootEntryBasename(state) {
|
|
|
27185
27746
|
}
|
|
27186
27747
|
//#endregion
|
|
27187
27748
|
//#region src/plugins/core/lifecycle/load/options.ts
|
|
27188
|
-
|
|
27749
|
+
const LOCAL_IMPORT_RE = /\bimport\s+(?:[\s\S]*?\s+from\s+)?(['"])([^'"\n]+)\1/g;
|
|
27750
|
+
async function collectImportedVueComponents(state, candidates) {
|
|
27751
|
+
const { absoluteSrcRoot } = state.ctx.configService;
|
|
27752
|
+
const importedComponents = /* @__PURE__ */ new Set();
|
|
27753
|
+
for (const candidate of candidates) {
|
|
27754
|
+
if (candidate.type !== "page" || candidate.entry.includes(":")) continue;
|
|
27755
|
+
const pageBase = path.resolve(absoluteSrcRoot, candidate.entry);
|
|
27756
|
+
const pageSource = (await findJsEntry(pageBase)).path ?? await findVueEntry(pageBase);
|
|
27757
|
+
if (!pageSource || !await fs$1.pathExists(pageSource)) continue;
|
|
27758
|
+
let source;
|
|
27759
|
+
try {
|
|
27760
|
+
source = await fs$1.readFile(pageSource, "utf8");
|
|
27761
|
+
} catch {
|
|
27762
|
+
continue;
|
|
27763
|
+
}
|
|
27764
|
+
for (const match of source.matchAll(LOCAL_IMPORT_RE)) {
|
|
27765
|
+
const importSource = match[2];
|
|
27766
|
+
if (!importSource.startsWith(".") && !importSource.startsWith("/")) continue;
|
|
27767
|
+
const importedBase = path.resolve(path.dirname(pageSource), importSource);
|
|
27768
|
+
const importedVue = importedBase.endsWith(".vue") ? importedBase : await findVueEntry(importedBase);
|
|
27769
|
+
if (!importedVue || !await fs$1.pathExists(importedVue)) continue;
|
|
27770
|
+
const relativeEntry = path.relative(absoluteSrcRoot, removeExtensionDeep(importedVue)).replaceAll("\\", "/");
|
|
27771
|
+
if (relativeEntry && !relativeEntry.startsWith("../")) importedComponents.add(relativeEntry);
|
|
27772
|
+
}
|
|
27773
|
+
}
|
|
27774
|
+
return [...importedComponents];
|
|
27775
|
+
}
|
|
27776
|
+
async function collectMainLogicalInputs(state, appEntry) {
|
|
27189
27777
|
const { absoluteSrcRoot } = state.ctx.configService;
|
|
27190
27778
|
const appJson = normalizeAppJson(appEntry.json ?? {});
|
|
27191
27779
|
const inputs = { app: {
|
|
@@ -27216,6 +27804,10 @@ function collectMainLogicalInputs(state, appEntry) {
|
|
|
27216
27804
|
entry: "app-bar/index",
|
|
27217
27805
|
type: "component"
|
|
27218
27806
|
});
|
|
27807
|
+
for (const entry of await collectImportedVueComponents(state, candidates)) candidates.push({
|
|
27808
|
+
entry,
|
|
27809
|
+
type: "component"
|
|
27810
|
+
});
|
|
27219
27811
|
for (const { entry: rawEntry, type } of candidates) {
|
|
27220
27812
|
if (!rawEntry || rawEntry.includes(":")) continue;
|
|
27221
27813
|
const name = removeExtensionDeep(rawEntry).replace(/^[/\\]+/, "");
|
|
@@ -27313,8 +27905,7 @@ function createOptionsHook(state) {
|
|
|
27313
27905
|
scanService.loadSubPackages();
|
|
27314
27906
|
const dirtyIndependentRoots = scanService.drainIndependentDirtyRoots();
|
|
27315
27907
|
const pendingIndependentBuilds = [];
|
|
27316
|
-
const
|
|
27317
|
-
const previousSubPackageRoot = shouldSerializeIndependentBuilds ? configService.currentSubPackageRoot : void 0;
|
|
27908
|
+
const previousSubPackageRoot = configService.currentSubPackageRoot;
|
|
27318
27909
|
for (const root of dirtyIndependentRoots) {
|
|
27319
27910
|
const meta = scanService.independentSubPackageMap.get(root);
|
|
27320
27911
|
if (!meta) continue;
|
|
@@ -27326,16 +27917,16 @@ function createOptionsHook(state) {
|
|
|
27326
27917
|
});
|
|
27327
27918
|
buildTask.catch(() => {});
|
|
27328
27919
|
pendingIndependentBuilds.push(buildTask);
|
|
27329
|
-
|
|
27920
|
+
try {
|
|
27330
27921
|
await buildTask;
|
|
27331
27922
|
} catch {}
|
|
27332
27923
|
}
|
|
27333
|
-
if (
|
|
27924
|
+
if (configService.currentSubPackageRoot !== previousSubPackageRoot) configService.options = {
|
|
27334
27925
|
...configService.options,
|
|
27335
27926
|
currentSubPackageRoot: previousSubPackageRoot
|
|
27336
27927
|
};
|
|
27337
27928
|
state.pendingIndependentBuilds = pendingIndependentBuilds;
|
|
27338
|
-
scannedInput = collectMainLogicalInputs(state, appEntry);
|
|
27929
|
+
scannedInput = await collectMainLogicalInputs(state, appEntry);
|
|
27339
27930
|
}
|
|
27340
27931
|
}
|
|
27341
27932
|
const logicalInput = {};
|
|
@@ -27589,6 +28180,7 @@ async function collectLogicalEntryDependencies(state, ownerId) {
|
|
|
27589
28180
|
dependencies.push(...await collectUsingComponentDependencies(state, ownerId, entry?.json));
|
|
27590
28181
|
for (const kind of [
|
|
27591
28182
|
"json",
|
|
28183
|
+
"jsx",
|
|
27592
28184
|
"layout",
|
|
27593
28185
|
"script",
|
|
27594
28186
|
"style",
|
|
@@ -28004,7 +28596,8 @@ async function processChangedFile(state, id, event) {
|
|
|
28004
28596
|
const dirtyReasonStats = /* @__PURE__ */ new Map();
|
|
28005
28597
|
const markEntryDirtyWithCause = (entryId, reason, cause) => {
|
|
28006
28598
|
state.markEntryDirty(entryId, reason);
|
|
28007
|
-
|
|
28599
|
+
const isJsxTemplateDependency = reason === "dependency" && /\.(?:jsx|tsx)$/.test(normalizedId);
|
|
28600
|
+
if (/\.(?:vue|jsx|tsx)$/.test(entryId) && (reason !== "dependency" || isJsxTemplateDependency)) {
|
|
28008
28601
|
const hmr = ctx.runtimeState.build.hmr;
|
|
28009
28602
|
hmr.dirtyVueEntryIds ??= /* @__PURE__ */ new Set();
|
|
28010
28603
|
hmr.dirtyVueEntryIds.add(entryId);
|
|
@@ -28015,6 +28608,7 @@ async function processChangedFile(state, id, event) {
|
|
|
28015
28608
|
const isDeletedMissingSelf = event === "delete" && !await fs$1.pathExists(normalizedId);
|
|
28016
28609
|
const isAutoRouteFile = Boolean(ctx.autoRoutesService?.isRouteFile(normalizedId));
|
|
28017
28610
|
const pathKind = resolveWatchPathKind(normalizedId);
|
|
28611
|
+
const isReactStaticTemplateUpdate = event === "update" && isReactStaticTemplateSource(configService.weappViteConfig?.react, normalizedId);
|
|
28018
28612
|
const isScriptModuleSidecar = pathKind.isScriptModuleSidecar;
|
|
28019
28613
|
const concreteChangedEntryId = isAppVueFile(normalizedId) && scanService.appEntry?.path ? normalizeFsResolvedId(scanService.appEntry.path) : normalizedId;
|
|
28020
28614
|
const vueEntryUpdateInspector = normalizedId.endsWith(".vue") ? createVueEntryUpdateInspector(state, normalizedId) : void 0;
|
|
@@ -28142,8 +28736,9 @@ async function processChangedFile(state, id, event) {
|
|
|
28142
28736
|
const isAutoRoutesStaleAppEntry = isJsonOnlyVueEntryUpdate && isAppEntryAutoRoutesSignatureStale(state, normalizedId);
|
|
28143
28737
|
const isLocalAssetOnlyVueEntryUpdate = !isJsonOnlyVueEntryUpdate && !isAppShellTopologyChanged && event === "update" && (vueEntryUpdateInspector ? await vueEntryUpdateInspector.isLocalAssetOnlyUpdate() : false);
|
|
28144
28738
|
const isStyleOnlyVueEntryUpdate = isLocalAssetOnlyVueEntryUpdate && (vueEntryUpdateInspector ? await vueEntryUpdateInspector.isStyleOnlyUpdate() : false);
|
|
28145
|
-
markChangedEntryDirty(sidecarDirtyCause ? "metadata" : isJsonOnlyVueEntryUpdate && !isAutoRoutesStaleAppEntry || isLocalAssetOnlyVueEntryUpdate ? "metadata" : "direct", sidecarDirtyCause ?? (isJsonOnlyVueEntryUpdate ? isAutoRoutesStaleAppEntry ? "entry-auto-routes" : "entry-json-only" : isAppShellTopologyChanged ? "entry-direct" : isLocalAssetOnlyVueEntryUpdate ? isStyleOnlyVueEntryUpdate ? "entry-style-only" : "entry-local-asset" : "entry-direct"));
|
|
28146
|
-
} else if (!handledSidecarMetadataUpdate && importerGraphAffectedEntryIds.size) for (const entryId of importerGraphAffectedEntryIds) markEntryDirtyWithCause(entryId, "dependency", "importer-graph");
|
|
28739
|
+
markChangedEntryDirty(sidecarDirtyCause ? "metadata" : isJsonOnlyVueEntryUpdate && !isAutoRoutesStaleAppEntry || isLocalAssetOnlyVueEntryUpdate ? "metadata" : "direct", sidecarDirtyCause ?? (isReactStaticTemplateUpdate ? "react-template" : isJsonOnlyVueEntryUpdate ? isAutoRoutesStaleAppEntry ? "entry-auto-routes" : "entry-json-only" : isAppShellTopologyChanged ? "entry-direct" : isLocalAssetOnlyVueEntryUpdate ? isStyleOnlyVueEntryUpdate ? "entry-style-only" : "entry-local-asset" : "entry-direct"));
|
|
28740
|
+
} else if (!handledSidecarMetadataUpdate && importerGraphAffectedEntryIds.size) for (const entryId of importerGraphAffectedEntryIds) markEntryDirtyWithCause(entryId, "dependency", isReactStaticTemplateUpdate ? "react-template" : "importer-graph");
|
|
28741
|
+
else if (!handledSidecarMetadataUpdate && event === "update" && /\.(?:vue|jsx|tsx)$/.test(normalizedId) && resolvedEntryMap.has(normalizedId)) markChangedEntryDirty("direct", "entry-direct");
|
|
28147
28742
|
await markAppEntryForTailwindContent();
|
|
28148
28743
|
const relativeCwd = configService.relativeCwd(normalizedId);
|
|
28149
28744
|
let handledByIndependentWatcher = false;
|
|
@@ -28636,7 +29231,7 @@ let wevuInstallState = "unknown";
|
|
|
28636
29231
|
function isExplicitFileRequest$1(id) {
|
|
28637
29232
|
return id.startsWith(".") || id.startsWith("/") || WINDOWS_ABSOLUTE_PATH_RE$1.test(id);
|
|
28638
29233
|
}
|
|
28639
|
-
function hasWevuDependency(ctx) {
|
|
29234
|
+
function hasWevuDependency$1(ctx) {
|
|
28640
29235
|
const packageJson = ctx.configService?.packageJson;
|
|
28641
29236
|
if (!packageJson) return false;
|
|
28642
29237
|
return Boolean(packageJson.dependencies?.wevu || packageJson.devDependencies?.wevu);
|
|
@@ -28645,7 +29240,7 @@ function ensureWevuInstalled(ctx) {
|
|
|
28645
29240
|
if (wevuInstallState === "present") return;
|
|
28646
29241
|
if (wevuInstallState === "missing") return;
|
|
28647
29242
|
if (warnedMissingWevu) return;
|
|
28648
|
-
if (hasWevuDependency(ctx)) {
|
|
29243
|
+
if (hasWevuDependency$1(ctx)) {
|
|
28649
29244
|
wevuInstallState = "present";
|
|
28650
29245
|
return;
|
|
28651
29246
|
}
|
|
@@ -28660,7 +29255,7 @@ function ensureWevuInstalled(ctx) {
|
|
|
28660
29255
|
logger_default.warn("[vue] 检测到项目中有 .vue 文件,但未安装 wevu,请安装 wevu 后重试。");
|
|
28661
29256
|
}
|
|
28662
29257
|
}
|
|
28663
|
-
function createVueResolverPlugin(ctx) {
|
|
29258
|
+
function createVueResolverPlugin(ctx, options = {}) {
|
|
28664
29259
|
const isWeappVueStyleVirtualId = (id) => {
|
|
28665
29260
|
return id.startsWith("\0weapp-vite:vue-style:") || id.startsWith(LEGACY_WEAPP_VUE_STYLE_VIRTUAL_PREFIX);
|
|
28666
29261
|
};
|
|
@@ -28679,6 +29274,7 @@ function createVueResolverPlugin(ctx) {
|
|
|
28679
29274
|
return query ? `${absoluteId}?${query}` : absoluteId;
|
|
28680
29275
|
}
|
|
28681
29276
|
if (isVueLikeFile(id)) {
|
|
29277
|
+
if (options.react && /\.(?:jsx|tsx)(?:\?.*)?$/.test(id)) return null;
|
|
28682
29278
|
ensureWevuInstalled(ctx);
|
|
28683
29279
|
if (!isExplicitFileRequest$1(id)) return null;
|
|
28684
29280
|
const absoluteId = toAbsoluteId(id, configService, importer, { base: "srcRoot" });
|
|
@@ -29912,6 +30508,9 @@ async function finalizeTransformCompiledResult(options) {
|
|
|
29912
30508
|
if (isApp) setAppShell?.(hasAppShellTemplate(result) ? resolveAppShellLayout(configService) : void 0);
|
|
29913
30509
|
if (!isApp) registerVueTemplateToken(ctx, filename, result.template);
|
|
29914
30510
|
if (Array.isArray(result.meta?.sfcSrcDeps)) ctx.moduleGraphService.replaceEntryDependencies(filename, "style", result.meta.sfcSrcDeps);
|
|
30511
|
+
const jsxDependencies = result.meta?.jsxDependencies ?? [];
|
|
30512
|
+
addNormalizedWatchFiles(pluginCtx, jsxDependencies);
|
|
30513
|
+
ctx.moduleGraphService.replaceEntryDependencies(filename, "jsx", jsxDependencies);
|
|
29915
30514
|
await finalizeTransformEntryScript({
|
|
29916
30515
|
result: transformResult,
|
|
29917
30516
|
filename,
|
|
@@ -30861,6 +31460,9 @@ async function finalizeVueTransform(options) {
|
|
|
30861
31460
|
}
|
|
30862
31461
|
const sfcStyleDependencies = syncVueSfcStyleDependencies(ctx, filename, currentStyleBlocks);
|
|
30863
31462
|
ctx.moduleGraphService.replaceEntryDependencies(filename, "style", sfcStyleDependencies);
|
|
31463
|
+
const jsxDependencies = result.meta?.jsxDependencies ?? [];
|
|
31464
|
+
addNormalizedWatchFiles(pluginCtx, jsxDependencies);
|
|
31465
|
+
ctx.moduleGraphService.replaceEntryDependencies(filename, "jsx", jsxDependencies);
|
|
30864
31466
|
registerScopedSlotHostGenerics(ctx, result.scopedSlotComponents, parseUsingComponents(result.config));
|
|
30865
31467
|
await measureVueHmrStage("finalizeCompiledResult", "vueFinalizeCompiledMs", async () => {
|
|
30866
31468
|
await finalizeTransformCompiledResult({
|
|
@@ -30909,9 +31511,9 @@ async function tryRefreshJsonOnlyVueCompilation(options) {
|
|
|
30909
31511
|
//#endregion
|
|
30910
31512
|
//#region src/plugins/vue/transform/plugin/transformFile/reuse.ts
|
|
30911
31513
|
async function tryReuseVueCompilation(options) {
|
|
30912
|
-
const { ctx, pluginCtx, filename, source, cachedCompilation, previousStyleSignature, autoRoutesSignature, dirtyEntryId, dirtyVueEntryIds, isCssImporterDirty, canAttemptStyleOnlyReuse, sourceMap, isApp, styleBlocksCache, styleRefreshTokens, readAndParseSfc, createReadAndParseSfcOptions, measureStage, measureVueHmrStage, reportTiming } = options;
|
|
31514
|
+
const { ctx, pluginCtx, filename, source, cachedCompilation, previousStyleSignature, autoRoutesSignature, dirtyEntryId, dirtyVueEntryIds, isCssImporterDirty, canAttemptStyleOnlyReuse, isJsxTemplateDependencyDirty, sourceMap, isApp, styleBlocksCache, styleRefreshTokens, readAndParseSfc, createReadAndParseSfcOptions, measureStage, measureVueHmrStage, reportTiming } = options;
|
|
30913
31515
|
const configService = ctx.configService;
|
|
30914
|
-
if (configService.isDev && cachedCompilation && !ctx.runtimeState.scan.isDirty && cachedCompilation.source === source && cachedCompilation.autoRoutesSignature === autoRoutesSignature) {
|
|
31516
|
+
if (configService.isDev && cachedCompilation && !isJsxTemplateDependencyDirty && (filename.endsWith(".vue") || (cachedCompilation.refreshToken ?? 0) === 0) && !ctx.runtimeState.scan.isDirty && cachedCompilation.source === source && cachedCompilation.autoRoutesSignature === autoRoutesSignature) {
|
|
30915
31517
|
cachedCompilation.refreshToken = 0;
|
|
30916
31518
|
const cachedResult = normalizeVueTransformResult(cachedCompilation.result);
|
|
30917
31519
|
let cachedStyleBlocks = cachedResult.meta?.styleBlocks ?? styleBlocksCache.get(filename);
|
|
@@ -31053,6 +31655,7 @@ async function transformVueLikeFile(options) {
|
|
|
31053
31655
|
}
|
|
31054
31656
|
const dirtyVueEntryIds = ctx.runtimeState?.build?.hmr?.dirtyVueEntryIds;
|
|
31055
31657
|
const dirtyEntryId = resolveDirtyVueEntryId(dirtyVueEntryIds, filename);
|
|
31658
|
+
const isJsxTemplateDependencyDirty = Boolean(dirtyEntryId && /\.(?:jsx|tsx)$/.test(ctx.runtimeState?.build?.hmr?.profile?.file ?? ""));
|
|
31056
31659
|
const isCssImporterDirty = isVueCssImporterDirtyReasonSummary(ctx.runtimeState?.build?.hmr?.profile?.dirtyReasonSummary);
|
|
31057
31660
|
const canAttemptStyleOnlyReuse = isVueStyleOnlyDirtyReasonSummary(ctx.runtimeState?.build?.hmr?.profile?.dirtyReasonSummary);
|
|
31058
31661
|
const reuseResult = await tryReuseVueCompilation({
|
|
@@ -31067,6 +31670,7 @@ async function transformVueLikeFile(options) {
|
|
|
31067
31670
|
dirtyVueEntryIds,
|
|
31068
31671
|
isCssImporterDirty,
|
|
31069
31672
|
canAttemptStyleOnlyReuse,
|
|
31673
|
+
isJsxTemplateDependencyDirty,
|
|
31070
31674
|
sourceMap,
|
|
31071
31675
|
isApp,
|
|
31072
31676
|
styleBlocksCache,
|
|
@@ -31197,7 +31801,7 @@ function invalidateComponentMetaCache(componentMetaCache, id) {
|
|
|
31197
31801
|
componentMetaCache.delete(id);
|
|
31198
31802
|
componentMetaCache.delete(normalizeFsResolvedId(id));
|
|
31199
31803
|
}
|
|
31200
|
-
function createVueTransformPlugin(ctx) {
|
|
31804
|
+
function createVueTransformPlugin(ctx, options = {}) {
|
|
31201
31805
|
const compilationCache = /* @__PURE__ */ new Map();
|
|
31202
31806
|
let appShell;
|
|
31203
31807
|
let pageMatcher = null;
|
|
@@ -31259,6 +31863,7 @@ function createVueTransformPlugin(ctx) {
|
|
|
31259
31863
|
});
|
|
31260
31864
|
},
|
|
31261
31865
|
async transform(code, id) {
|
|
31866
|
+
if (options.react && /\.(?:jsx|tsx)(?:\?.*)?$/.test(id)) return null;
|
|
31262
31867
|
if (parseSidecarSourceRequest(id) || !VUE_TRANSFORM_FILTER_RE.test(id) || !isVueLikeId(id)) return null;
|
|
31263
31868
|
const startedAt = performance.now();
|
|
31264
31869
|
try {
|
|
@@ -31376,8 +31981,8 @@ const VUE_PLUGIN_NAME = "weapp-vite:vue";
|
|
|
31376
31981
|
function vuePlugin(ctx, options) {
|
|
31377
31982
|
if (options?.enable === false) return [];
|
|
31378
31983
|
return [
|
|
31379
|
-
createVueResolverPlugin(ctx),
|
|
31380
|
-
createVueTransformPlugin(ctx),
|
|
31984
|
+
createVueResolverPlugin(ctx, options),
|
|
31985
|
+
createVueTransformPlugin(ctx, options),
|
|
31381
31986
|
createVueWatchPlugin(ctx)
|
|
31382
31987
|
];
|
|
31383
31988
|
}
|
|
@@ -31576,17 +32181,26 @@ function flatten(groups) {
|
|
|
31576
32181
|
return acc;
|
|
31577
32182
|
}, []);
|
|
31578
32183
|
}
|
|
32184
|
+
function hasWevuDependency(ctx) {
|
|
32185
|
+
const packageJson = ctx.configService?.packageJson;
|
|
32186
|
+
return Boolean(packageJson?.dependencies?.wevu || packageJson?.devDependencies?.wevu);
|
|
32187
|
+
}
|
|
31579
32188
|
function vitePluginWeapp(ctx, subPackageMeta) {
|
|
31580
32189
|
const libModeEnabled = ctx.configService?.weappLibConfig?.enabled;
|
|
31581
32190
|
const vueEnabled = ctx.configService?.weappViteConfig?.vue?.enable !== false;
|
|
31582
|
-
const
|
|
32191
|
+
const reactEnabled = isReactEnabled(ctx);
|
|
32192
|
+
const runtimeProvider = resolveRuntimeProvider("miniprogram", vueEnabled && (!reactEnabled || hasWevuDependency(ctx)) ? "vue" : "native");
|
|
31583
32193
|
const groups = [
|
|
31584
32194
|
[createContextPlugin(ctx), createSelectedRuntimeProviderPlugin(runtimeProvider, ctx.configService.isDev)],
|
|
31585
32195
|
preflight(ctx),
|
|
31586
32196
|
uniAppCompatibility(ctx),
|
|
31587
|
-
|
|
32197
|
+
createReactPlugin(ctx),
|
|
32198
|
+
vue(ctx, {
|
|
32199
|
+
enable: vueEnabled,
|
|
32200
|
+
react: reactEnabled
|
|
32201
|
+
})
|
|
31588
32202
|
];
|
|
31589
|
-
if (vueEnabled && !libModeEnabled) groups.push(wevu(ctx));
|
|
32203
|
+
if (vueEnabled && !libModeEnabled && !reactEnabled) groups.push(wevu(ctx));
|
|
31590
32204
|
const autoRoutesEnabled = resolveWeappAutoRoutesConfig(ctx.configService?.weappViteConfig?.autoRoutes).enabled;
|
|
31591
32205
|
if (!subPackageMeta) {
|
|
31592
32206
|
groups.push(asset(ctx));
|
|
@@ -31664,7 +32278,7 @@ function createAbsolutePathPattern(value) {
|
|
|
31664
32278
|
function hasTsconfigReference(tsconfig, target) {
|
|
31665
32279
|
if (!existsSync(tsconfig)) return false;
|
|
31666
32280
|
try {
|
|
31667
|
-
const parsed = parse$
|
|
32281
|
+
const parsed = parse$2(readFileSync(tsconfig, "utf8"), void 0, true);
|
|
31668
32282
|
const references = Array.isArray(parsed.references) ? parsed.references : [];
|
|
31669
32283
|
const tsconfigDir = path.dirname(tsconfig);
|
|
31670
32284
|
return references.some((reference) => {
|
|
@@ -32612,7 +33226,7 @@ async function loadAppEntry(ctx, scanState) {
|
|
|
32612
33226
|
const { path: appEntryPath } = appEntry;
|
|
32613
33227
|
let configFromVue;
|
|
32614
33228
|
if (!appConfigFile && vueAppPath) {
|
|
32615
|
-
const { extractConfigFromVue } = await import("./file-
|
|
33229
|
+
const { extractConfigFromVue } = await import("./file-BG-q88IF.mjs");
|
|
32616
33230
|
configFromVue = await extractConfigFromVue(vueAppPath);
|
|
32617
33231
|
if (configFromVue) appConfigFile = vueAppPath;
|
|
32618
33232
|
}
|