weapp-vite 6.13.0 → 6.13.2
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 +3 -0
- package/dist/auto-import-components/resolvers.d.mts +1 -1
- package/dist/auto-routes.d.mts +1 -1
- package/dist/auto-routes.mjs +1 -1
- package/dist/cli.mjs +2 -18
- package/dist/{config-B3HNOAZo.d.mts → config-CeCx5qMh.d.mts} +3 -2
- package/dist/config.d.mts +1 -1
- package/dist/{createContext-CZ7Kunvn.mjs → createContext-Dja7tL2g.mjs} +375 -156
- package/dist/docs/README.md +3 -0
- package/dist/{file-DwwblEq4.mjs → file-MiE605t6.mjs} +1 -1
- package/dist/index.d.mts +2 -3
- package/dist/index.mjs +2 -3
- package/dist/json.d.mts +1 -1
- package/dist/mcp.d.mts +1 -1
- package/dist/runtime-CpQutkhu.d.mts +39 -0
- package/dist/runtime-gyZnAGCZ.mjs +53 -0
- package/dist/runtime.d.mts +1 -30
- package/dist/runtime.mjs +1 -31
- package/dist/types.d.mts +3 -3
- package/package.json +7 -5
- /package/dist/{index-BQqQ_BLM.d.mts → index-B5wBsuYI.d.mts} +0 -0
- /package/dist/{routes-DUBjYF43.d.mts → routes-o20IHwXa.d.mts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-twds-ZHy.mjs";
|
|
2
2
|
import { n as applyWeappViteHostMeta } from "./pluginHost-SJdl15d3.mjs";
|
|
3
3
|
import { n as configureLogger, r as logger_default } from "./logger-gutcwWKE.mjs";
|
|
4
|
-
import { _ as templateExtensions, a as findJsEntry, c as findVueEntry, d as isTemplate, f as touch, g as supportedCssLangs, h as jsExtensions, i as findCssEntry, l as inlineAutoRoutesImports, m as configExtensions, n as extractConfigFromVue, o as findJsonEntry, s as findTemplateEntry, t as changeFileExtension, u as isJsOrTs, v as vueExtensions } from "./file-
|
|
4
|
+
import { _ as templateExtensions, a as findJsEntry, c as findVueEntry, d as isTemplate, f as touch, g as supportedCssLangs, h as jsExtensions, i as findCssEntry, l as inlineAutoRoutesImports, m as configExtensions, n as extractConfigFromVue, o as findJsonEntry, s as findTemplateEntry, t as changeFileExtension, u as isJsOrTs, v as vueExtensions } from "./file-MiE605t6.mjs";
|
|
5
5
|
import { createRequire, isBuiltin } from "node:module";
|
|
6
6
|
import { addExtension, defu, get, isEmptyObject, isObject, objectHash, removeExtension, removeExtensionDeep, set } from "@weapp-core/shared";
|
|
7
7
|
import { LRUCache } from "lru-cache";
|
|
@@ -1315,6 +1315,7 @@ function createScheduleHelpers(options) {
|
|
|
1315
1315
|
const configChanged = settings.enabled !== outputsState.lastHtmlCustomDataEnabled || settings.outputPath !== outputsState.lastHtmlCustomDataOutput;
|
|
1316
1316
|
if (!shouldWrite && !configChanged && !outputsState.lastHtmlCustomDataOutputPath) return;
|
|
1317
1317
|
outputsState.htmlCustomDataWriteRequested = true;
|
|
1318
|
+
outputsState.preparedSyncStatePromise = void 0;
|
|
1318
1319
|
if (outputsState.pendingHtmlCustomDataWrite) return;
|
|
1319
1320
|
outputsState.pendingHtmlCustomDataWrite = Promise.resolve().then(async () => {
|
|
1320
1321
|
while (outputsState.htmlCustomDataWriteRequested) {
|
|
@@ -1333,6 +1334,7 @@ function createScheduleHelpers(options) {
|
|
|
1333
1334
|
const configService = ctx.configService;
|
|
1334
1335
|
if (!getAutoImportConfig(configService)) return;
|
|
1335
1336
|
outputsState.writeRequested = true;
|
|
1337
|
+
outputsState.preparedSyncStatePromise = void 0;
|
|
1336
1338
|
if (outputsState.pendingWrite) return;
|
|
1337
1339
|
outputsState.pendingWrite = Promise.resolve().then(async () => {
|
|
1338
1340
|
while (outputsState.writeRequested) {
|
|
@@ -1355,6 +1357,7 @@ function createScheduleHelpers(options) {
|
|
|
1355
1357
|
const configChanged = settings.enabled !== outputsState.lastTypedComponentsEnabled || settings.outputPath !== outputsState.lastTypedComponentsOutput;
|
|
1356
1358
|
if (!shouldWrite && !configChanged && !outputsState.lastTypedDefinitionOutputPath) return;
|
|
1357
1359
|
outputsState.typedWriteRequested = true;
|
|
1360
|
+
outputsState.preparedSyncStatePromise = void 0;
|
|
1358
1361
|
if (outputsState.pendingTypedWrite) return;
|
|
1359
1362
|
outputsState.pendingTypedWrite = Promise.resolve().then(async () => {
|
|
1360
1363
|
while (outputsState.typedWriteRequested) {
|
|
@@ -1373,6 +1376,7 @@ function createScheduleHelpers(options) {
|
|
|
1373
1376
|
const configChanged = settings.enabled !== outputsState.lastVueComponentsEnabled || settings.outputPath !== outputsState.lastVueComponentsOutput;
|
|
1374
1377
|
if (!shouldWrite && !configChanged && !outputsState.lastVueComponentsOutputPath) return;
|
|
1375
1378
|
outputsState.vueComponentsWriteRequested = true;
|
|
1379
|
+
outputsState.preparedSyncStatePromise = void 0;
|
|
1376
1380
|
if (outputsState.pendingVueComponentsWrite) return;
|
|
1377
1381
|
outputsState.pendingVueComponentsWrite = Promise.resolve().then(async () => {
|
|
1378
1382
|
while (outputsState.vueComponentsWriteRequested) {
|
|
@@ -4256,6 +4260,19 @@ const VUE_LIKE_EXTENSIONS$2 = [
|
|
|
4256
4260
|
];
|
|
4257
4261
|
const CAMEL_TO_KEBAB_RE$2 = /([a-z0-9])([A-Z])/g;
|
|
4258
4262
|
const TRAILING_INDEX_SEGMENT_RE = /\/index$/;
|
|
4263
|
+
async function getPreparedSyncState(options) {
|
|
4264
|
+
const { outputsState } = options;
|
|
4265
|
+
if (!outputsState.preparedSyncStatePromise) outputsState.preparedSyncStatePromise = Promise.resolve().then(() => {
|
|
4266
|
+
options.syncResolverComponentProps();
|
|
4267
|
+
options.preloadResolverComponentMetadata();
|
|
4268
|
+
const componentNames = collectAllComponentNames(options);
|
|
4269
|
+
return {
|
|
4270
|
+
componentNames,
|
|
4271
|
+
componentMetadataMap: new Map(componentNames.map((name) => [name, options.getComponentMetadata(name)]))
|
|
4272
|
+
};
|
|
4273
|
+
});
|
|
4274
|
+
return await outputsState.preparedSyncStatePromise;
|
|
4275
|
+
}
|
|
4259
4276
|
function toRelativeImportSpecifier(outputPath, sourcePath) {
|
|
4260
4277
|
const relative = path.relative(path.dirname(outputPath), sourcePath).replaceAll("\\", "/");
|
|
4261
4278
|
if (!relative || relative === ".") return "./";
|
|
@@ -4360,9 +4377,11 @@ async function syncTypedComponentsDefinition(settings, options) {
|
|
|
4360
4377
|
outputsState.lastWrittenTypedDefinition = void 0;
|
|
4361
4378
|
return;
|
|
4362
4379
|
}
|
|
4363
|
-
options
|
|
4364
|
-
|
|
4365
|
-
|
|
4380
|
+
const prepared = await getPreparedSyncState(options);
|
|
4381
|
+
const nextDefinition = createTypedComponentsDefinition(prepared.componentNames, (name) => prepared.componentMetadataMap.get(name) ?? {
|
|
4382
|
+
types: /* @__PURE__ */ new Map(),
|
|
4383
|
+
docs: /* @__PURE__ */ new Map()
|
|
4384
|
+
});
|
|
4366
4385
|
if (nextDefinition === outputsState.lastWrittenTypedDefinition && settings.outputPath === outputsState.lastTypedDefinitionOutputPath) return;
|
|
4367
4386
|
try {
|
|
4368
4387
|
if (outputsState.lastTypedDefinitionOutputPath && outputsState.lastTypedDefinitionOutputPath !== settings.outputPath) try {
|
|
@@ -4392,15 +4411,16 @@ async function syncVueComponentsDefinition(settings, options) {
|
|
|
4392
4411
|
outputsState.lastWrittenLayoutTypesDefinition = void 0;
|
|
4393
4412
|
return;
|
|
4394
4413
|
}
|
|
4395
|
-
options
|
|
4396
|
-
options.preloadResolverComponentMetadata();
|
|
4414
|
+
const prepared = await getPreparedSyncState(options);
|
|
4397
4415
|
const outputPath = settings.outputPath;
|
|
4398
|
-
const componentNames = collectAllComponentNames(options);
|
|
4399
4416
|
const layoutNames = await collectLayoutNames(configService.absoluteSrcRoot);
|
|
4400
4417
|
const layoutPropsMap = await collectLayoutPropsMap(ctx);
|
|
4401
4418
|
const layoutTypesOutputPath = resolveLayoutTypesDefaultPath(configService);
|
|
4402
4419
|
const layoutTypesDefinition = createLayoutTypesDefinition(layoutNames, layoutPropsMap);
|
|
4403
|
-
const nextDefinition = createVueComponentsDefinition(componentNames,
|
|
4420
|
+
const nextDefinition = createVueComponentsDefinition(prepared.componentNames, (name) => prepared.componentMetadataMap.get(name) ?? {
|
|
4421
|
+
types: /* @__PURE__ */ new Map(),
|
|
4422
|
+
docs: /* @__PURE__ */ new Map()
|
|
4423
|
+
}, {
|
|
4404
4424
|
useTypedComponents: getTypedComponentsSettings({ configService }).enabled,
|
|
4405
4425
|
moduleName: settings.moduleName,
|
|
4406
4426
|
layoutNames,
|
|
@@ -4444,11 +4464,12 @@ async function syncHtmlCustomData(settings, options) {
|
|
|
4444
4464
|
outputsState.lastWrittenHtmlCustomData = void 0;
|
|
4445
4465
|
return;
|
|
4446
4466
|
}
|
|
4447
|
-
options
|
|
4448
|
-
options.preloadResolverComponentMetadata();
|
|
4449
|
-
const componentNames = collectAllComponentNames(options);
|
|
4467
|
+
const prepared = await getPreparedSyncState(options);
|
|
4450
4468
|
const builtinTags = loadWeappBuiltinHtmlTags();
|
|
4451
|
-
const nextDefinition = createHtmlCustomDataDefinition(componentNames,
|
|
4469
|
+
const nextDefinition = createHtmlCustomDataDefinition(prepared.componentNames, (name) => prepared.componentMetadataMap.get(name) ?? {
|
|
4470
|
+
types: /* @__PURE__ */ new Map(),
|
|
4471
|
+
docs: /* @__PURE__ */ new Map()
|
|
4472
|
+
}, builtinTags);
|
|
4452
4473
|
if (nextDefinition === outputsState.lastWrittenHtmlCustomData && settings.outputPath === outputsState.lastHtmlCustomDataOutputPath) return;
|
|
4453
4474
|
try {
|
|
4454
4475
|
if (outputsState.lastHtmlCustomDataOutputPath && outputsState.lastHtmlCustomDataOutputPath !== settings.outputPath) try {
|
|
@@ -5054,6 +5075,12 @@ async function resolveWeappConfigFile(options) {
|
|
|
5054
5075
|
//#region src/runtime/autoImport/service/registry.ts
|
|
5055
5076
|
const JSON_LIKE_FILE_RE = /\.(?:json|jsonc|json5)$/i;
|
|
5056
5077
|
function createRegistryHelpers(state) {
|
|
5078
|
+
function scheduleOutputs(shouldWrite, vueEnabled) {
|
|
5079
|
+
state.scheduleManifestWrite(shouldWrite);
|
|
5080
|
+
state.scheduleTypedComponentsWrite(shouldWrite);
|
|
5081
|
+
state.scheduleHtmlCustomDataWrite(shouldWrite);
|
|
5082
|
+
state.scheduleVueComponentsWrite(vueEnabled || shouldWrite);
|
|
5083
|
+
}
|
|
5057
5084
|
async function extractComponentPropsFromVue(vuePath) {
|
|
5058
5085
|
const source = await fs.readFile(vuePath, "utf8");
|
|
5059
5086
|
const astEngine = resolveAstEngine(state.ctx.configService?.weappViteConfig);
|
|
@@ -5087,12 +5114,13 @@ function createRegistryHelpers(state) {
|
|
|
5087
5114
|
async function registerLocalComponent(filePath) {
|
|
5088
5115
|
if (!state.ctx.configService || !state.ctx.jsonService) throw new Error("扫描组件前必须初始化 configService/jsonService。");
|
|
5089
5116
|
const baseName = removeExtensionDeep(filePath);
|
|
5090
|
-
const [{ path: jsEntry }, { path: jsonPath }, { path: templatePath }
|
|
5117
|
+
const [{ path: jsEntry }, { path: jsonPath }, { path: templatePath }] = await Promise.all([
|
|
5091
5118
|
findJsEntry(baseName),
|
|
5092
5119
|
findJsonEntry(baseName),
|
|
5093
|
-
findTemplateEntry(baseName)
|
|
5094
|
-
filePath.endsWith(".vue") ? Promise.resolve(filePath) : findVueEntry(baseName)
|
|
5120
|
+
findTemplateEntry(baseName)
|
|
5095
5121
|
]);
|
|
5122
|
+
let vueEntry = filePath.endsWith(".vue") ? filePath : void 0;
|
|
5123
|
+
if ((!jsEntry || !jsonPath || !templatePath) && !vueEntry) vueEntry = await findVueEntry(baseName);
|
|
5096
5124
|
const { removed, removedNames } = removeRegisteredComponent({
|
|
5097
5125
|
baseName,
|
|
5098
5126
|
templatePath,
|
|
@@ -5108,6 +5136,7 @@ function createRegistryHelpers(state) {
|
|
|
5108
5136
|
let resolvedJsonPath = jsonPath;
|
|
5109
5137
|
let resolvedTemplatePath = templatePath;
|
|
5110
5138
|
let json = jsonPath ? await state.ctx.jsonService.read(jsonPath) : void 0;
|
|
5139
|
+
const vueSettings = getVueComponentsSettings(state.ctx);
|
|
5111
5140
|
if ((!resolvedJsEntry || !resolvedJsonPath || !resolvedTemplatePath) && vueEntry) {
|
|
5112
5141
|
const vueConfig = await extractConfigFromVue(vueEntry);
|
|
5113
5142
|
const vueJson = vueConfig && typeof vueConfig === "object" && !Array.isArray(vueConfig) ? { ...vueConfig } : {};
|
|
@@ -5120,34 +5149,22 @@ function createRegistryHelpers(state) {
|
|
|
5120
5149
|
}
|
|
5121
5150
|
}
|
|
5122
5151
|
if (!resolvedJsEntry || !resolvedJsonPath || !resolvedTemplatePath) {
|
|
5123
|
-
|
|
5124
|
-
state.scheduleTypedComponentsWrite(removed || removedNames.length > 0);
|
|
5125
|
-
state.scheduleHtmlCustomDataWrite(removed || removedNames.length > 0);
|
|
5126
|
-
state.scheduleVueComponentsWrite(getVueComponentsSettings(state.ctx).enabled || removed || removedNames.length > 0);
|
|
5152
|
+
scheduleOutputs(removed || removedNames.length > 0, vueSettings.enabled);
|
|
5127
5153
|
return;
|
|
5128
5154
|
}
|
|
5129
5155
|
if (!json?.component) {
|
|
5130
|
-
|
|
5131
|
-
state.scheduleTypedComponentsWrite(removed || removedNames.length > 0);
|
|
5132
|
-
state.scheduleHtmlCustomDataWrite(removed || removedNames.length > 0);
|
|
5133
|
-
state.scheduleVueComponentsWrite(getVueComponentsSettings(state.ctx).enabled || removed || removedNames.length > 0);
|
|
5156
|
+
scheduleOutputs(removed || removedNames.length > 0, vueSettings.enabled);
|
|
5134
5157
|
return;
|
|
5135
5158
|
}
|
|
5136
5159
|
const { componentName, base } = resolvedComponentName(baseName);
|
|
5137
5160
|
if (!componentName) {
|
|
5138
|
-
|
|
5139
|
-
state.scheduleTypedComponentsWrite(removed || removedNames.length > 0);
|
|
5140
|
-
state.scheduleHtmlCustomDataWrite(removed || removedNames.length > 0);
|
|
5141
|
-
state.scheduleVueComponentsWrite(getVueComponentsSettings(state.ctx).enabled || removed || removedNames.length > 0);
|
|
5161
|
+
scheduleOutputs(removed || removedNames.length > 0, vueSettings.enabled);
|
|
5142
5162
|
return;
|
|
5143
5163
|
}
|
|
5144
5164
|
if (state.registry.has(componentName) && base !== "index") {
|
|
5145
5165
|
const message = `发现 \`${componentName}\` 组件重名! 跳过组件 \`${state.ctx.configService.relativeCwd(baseName)}\` 的自动引入`;
|
|
5146
5166
|
state.logWarnOnce(message);
|
|
5147
|
-
|
|
5148
|
-
state.scheduleTypedComponentsWrite(removed || removedNames.length > 0);
|
|
5149
|
-
state.scheduleHtmlCustomDataWrite(removed || removedNames.length > 0);
|
|
5150
|
-
state.scheduleVueComponentsWrite(getVueComponentsSettings(state.ctx).enabled || removed || removedNames.length > 0);
|
|
5167
|
+
scheduleOutputs(removed || removedNames.length > 0, vueSettings.enabled);
|
|
5151
5168
|
return;
|
|
5152
5169
|
}
|
|
5153
5170
|
const sourceWithoutExt = removeExtensionDeep(resolvedJsonPath);
|
|
@@ -5169,12 +5186,11 @@ function createRegistryHelpers(state) {
|
|
|
5169
5186
|
state.scheduleManifestWrite(true);
|
|
5170
5187
|
const typedSettings = getTypedComponentsSettings(state.ctx);
|
|
5171
5188
|
const htmlSettings = getHtmlCustomDataSettings(state.ctx);
|
|
5172
|
-
const vueSettings = getVueComponentsSettings(state.ctx);
|
|
5173
5189
|
if (typedSettings.enabled || htmlSettings.enabled) {
|
|
5174
5190
|
const astEngine = resolveAstEngine(state.ctx.configService.weappViteConfig);
|
|
5175
5191
|
let metadataSource = json;
|
|
5176
5192
|
try {
|
|
5177
|
-
if (JSON_LIKE_FILE_RE.test(resolvedJsonPath)) metadataSource = await fs.readJson(resolvedJsonPath);
|
|
5193
|
+
if (!metadataSource && JSON_LIKE_FILE_RE.test(resolvedJsonPath)) metadataSource = await fs.readJson(resolvedJsonPath);
|
|
5178
5194
|
} catch {}
|
|
5179
5195
|
const metadata = extractJsonPropMetadata(metadataSource);
|
|
5180
5196
|
const baseProps = metadata.props;
|
|
@@ -5231,6 +5247,10 @@ const TRAILING_SLASH_RE$1 = /\/+$/;
|
|
|
5231
5247
|
const SCRIPT_OR_DTS_EXTENSION_RE = /\.(?:[cm]?js|tsx?|jsx|d\.ts)$/;
|
|
5232
5248
|
function createResolverHelpers(state) {
|
|
5233
5249
|
const miniprogramDirCache = /* @__PURE__ */ new Map();
|
|
5250
|
+
const resolveCache = /* @__PURE__ */ new Map();
|
|
5251
|
+
function getResolveCacheKey(componentName, importerBaseName) {
|
|
5252
|
+
return `${importerBaseName ?? ""}\0${componentName}`;
|
|
5253
|
+
}
|
|
5234
5254
|
function resolveWithResolver(resolver, componentName, baseName) {
|
|
5235
5255
|
if (!resolver) return;
|
|
5236
5256
|
const candidates = [componentName];
|
|
@@ -5306,15 +5326,10 @@ function createResolverHelpers(state) {
|
|
|
5306
5326
|
} catch {}
|
|
5307
5327
|
}
|
|
5308
5328
|
function collectResolverComponents() {
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
const map = resolver?.components;
|
|
5314
|
-
if (!map) continue;
|
|
5315
|
-
for (const [name, from] of Object.entries(map)) entries.push([name, from]);
|
|
5316
|
-
}
|
|
5317
|
-
return Object.fromEntries(entries);
|
|
5329
|
+
return Object.fromEntries(state.resolvedResolverComponents);
|
|
5330
|
+
}
|
|
5331
|
+
function clearResolveCache() {
|
|
5332
|
+
resolveCache.clear();
|
|
5318
5333
|
}
|
|
5319
5334
|
function syncResolverComponentProps() {
|
|
5320
5335
|
const resolverEntries = collectResolverComponents();
|
|
@@ -5334,15 +5349,25 @@ function createResolverHelpers(state) {
|
|
|
5334
5349
|
}
|
|
5335
5350
|
}
|
|
5336
5351
|
function resolveWithResolvers(componentName, importerBaseName) {
|
|
5352
|
+
const cacheKey = getResolveCacheKey(componentName, importerBaseName);
|
|
5353
|
+
if (resolveCache.has(cacheKey)) return resolveCache.get(cacheKey) ?? void 0;
|
|
5337
5354
|
const resolvers = getAutoImportConfig(state.ctx.configService)?.resolvers;
|
|
5338
|
-
if (!Array.isArray(resolvers))
|
|
5355
|
+
if (!Array.isArray(resolvers)) {
|
|
5356
|
+
resolveCache.set(cacheKey, null);
|
|
5357
|
+
return;
|
|
5358
|
+
}
|
|
5339
5359
|
for (const resolver of resolvers) {
|
|
5340
5360
|
const value = resolveWithResolver(resolver, componentName, importerBaseName ?? "");
|
|
5341
|
-
if (value)
|
|
5361
|
+
if (value) {
|
|
5362
|
+
resolveCache.set(cacheKey, value);
|
|
5363
|
+
return value;
|
|
5364
|
+
}
|
|
5342
5365
|
}
|
|
5366
|
+
resolveCache.set(cacheKey, null);
|
|
5343
5367
|
}
|
|
5344
5368
|
return {
|
|
5345
5369
|
collectResolverComponents,
|
|
5370
|
+
clearResolveCache,
|
|
5346
5371
|
syncResolverComponentProps,
|
|
5347
5372
|
resolveWithResolvers,
|
|
5348
5373
|
resolveNavigationImport
|
|
@@ -5362,6 +5387,7 @@ function logWarnOnce(message) {
|
|
|
5362
5387
|
function createAutoImportService(ctx) {
|
|
5363
5388
|
const autoImportState = ctx.runtimeState.autoImport;
|
|
5364
5389
|
const registry = autoImportState.registry;
|
|
5390
|
+
const resolvedResolverComponents = autoImportState.resolvedResolverComponents;
|
|
5365
5391
|
const manifestFileName = DEFAULT_AUTO_IMPORT_MANIFEST_FILENAME;
|
|
5366
5392
|
const manifestCache = /* @__PURE__ */ new Map();
|
|
5367
5393
|
const componentMetadataMap = /* @__PURE__ */ new Map();
|
|
@@ -5388,11 +5414,13 @@ function createAutoImportService(ctx) {
|
|
|
5388
5414
|
lastTypedComponentsEnabled: false,
|
|
5389
5415
|
lastTypedComponentsOutput: void 0,
|
|
5390
5416
|
lastVueComponentsEnabled: false,
|
|
5391
|
-
lastVueComponentsOutput: void 0
|
|
5417
|
+
lastVueComponentsOutput: void 0,
|
|
5418
|
+
preparedSyncStatePromise: void 0
|
|
5392
5419
|
};
|
|
5393
5420
|
const resolverHelpers = createResolverHelpers({
|
|
5394
5421
|
ctx,
|
|
5395
5422
|
registry,
|
|
5423
|
+
resolvedResolverComponents,
|
|
5396
5424
|
componentMetadataMap,
|
|
5397
5425
|
resolverComponentNames,
|
|
5398
5426
|
resolverComponentsMapRef
|
|
@@ -5437,6 +5465,8 @@ function createAutoImportService(ctx) {
|
|
|
5437
5465
|
registry.clear();
|
|
5438
5466
|
autoImportState.matcher = void 0;
|
|
5439
5467
|
autoImportState.matcherKey = "";
|
|
5468
|
+
resolvedResolverComponents.clear();
|
|
5469
|
+
resolverHelpers.clearResolveCache();
|
|
5440
5470
|
outputsHelpers.scheduleManifestWrite(true);
|
|
5441
5471
|
componentMetadataMap.clear();
|
|
5442
5472
|
resolverComponentNames.clear();
|
|
@@ -5478,6 +5508,8 @@ function createAutoImportService(ctx) {
|
|
|
5478
5508
|
if (local) return local;
|
|
5479
5509
|
const resolvedValue = resolverHelpers.resolveWithResolvers(componentName, importerBaseName);
|
|
5480
5510
|
if (resolvedValue) {
|
|
5511
|
+
const resolverChanged = resolvedResolverComponents.get(resolvedValue.name) !== resolvedValue.from;
|
|
5512
|
+
resolvedResolverComponents.set(resolvedValue.name, resolvedValue.from);
|
|
5481
5513
|
const resolved = {
|
|
5482
5514
|
kind: "resolver",
|
|
5483
5515
|
value: resolvedValue
|
|
@@ -5486,14 +5518,16 @@ function createAutoImportService(ctx) {
|
|
|
5486
5518
|
const htmlSettings = getHtmlCustomDataSettings(ctx);
|
|
5487
5519
|
const vueSettings = getVueComponentsSettings(ctx);
|
|
5488
5520
|
if (typedSettings.enabled || htmlSettings.enabled) {
|
|
5489
|
-
|
|
5521
|
+
const metadataMissing = !componentMetadataMap.has(resolved.value.name);
|
|
5522
|
+
if (metadataMissing) componentMetadataMap.set(resolved.value.name, {
|
|
5490
5523
|
types: /* @__PURE__ */ new Map(),
|
|
5491
5524
|
docs: /* @__PURE__ */ new Map()
|
|
5492
5525
|
});
|
|
5493
|
-
if (typedSettings.enabled) outputsHelpers.scheduleTypedComponentsWrite(true);
|
|
5494
|
-
if (htmlSettings.enabled) outputsHelpers.scheduleHtmlCustomDataWrite(true);
|
|
5526
|
+
if (typedSettings.enabled && (resolverChanged || metadataMissing)) outputsHelpers.scheduleTypedComponentsWrite(true);
|
|
5527
|
+
if (htmlSettings.enabled && (resolverChanged || metadataMissing)) outputsHelpers.scheduleHtmlCustomDataWrite(true);
|
|
5495
5528
|
} else componentMetadataMap.delete(resolved.value.name);
|
|
5496
|
-
if (vueSettings.enabled) outputsHelpers.scheduleVueComponentsWrite(true);
|
|
5529
|
+
if (vueSettings.enabled && resolverChanged) outputsHelpers.scheduleVueComponentsWrite(true);
|
|
5530
|
+
if (resolverChanged) outputsHelpers.scheduleManifestWrite(true);
|
|
5497
5531
|
return resolved;
|
|
5498
5532
|
}
|
|
5499
5533
|
},
|
|
@@ -6211,9 +6245,14 @@ function ensureSubPackage(map, root) {
|
|
|
6211
6245
|
}
|
|
6212
6246
|
return set;
|
|
6213
6247
|
}
|
|
6214
|
-
function shouldIncludeScanCandidate(candidate, json) {
|
|
6248
|
+
function shouldIncludeScanCandidate(candidate, json, route) {
|
|
6215
6249
|
if (candidate.jsonPath && json === void 0) return false;
|
|
6216
6250
|
if (json && typeof json === "object" && json.component === true) return false;
|
|
6251
|
+
if (route?.root && !route.pagePath.startsWith("pages/") && candidate.hasScript && !candidate.hasTemplate && !candidate.jsonPath) {
|
|
6252
|
+
const hasVueEntry = [...candidate.files].some((file) => file.endsWith(".vue"));
|
|
6253
|
+
const isIndexEntry = path.basename(route.pagePath) === "index";
|
|
6254
|
+
if (!hasVueEntry && !isIndexEntry) return false;
|
|
6255
|
+
}
|
|
6217
6256
|
return candidate.hasScript || candidate.hasTemplate || Boolean(candidate.jsonPath);
|
|
6218
6257
|
}
|
|
6219
6258
|
async function scanRoutes(ctx, candidatesMap) {
|
|
@@ -6247,7 +6286,7 @@ async function scanRoutes(ctx, candidatesMap) {
|
|
|
6247
6286
|
const route = resolveRoute(normalizedBase, subPackageRoots);
|
|
6248
6287
|
if (!route) continue;
|
|
6249
6288
|
watchDirs.add(path.dirname(candidate.base));
|
|
6250
|
-
if (!shouldIncludeScanCandidate(candidate, jsonMap.get(candidate))) continue;
|
|
6289
|
+
if (!shouldIncludeScanCandidate(candidate, jsonMap.get(candidate), route)) continue;
|
|
6251
6290
|
entriesSet.add(route.entry);
|
|
6252
6291
|
if (route.root) ensureSubPackage(subPackages, route.root).add(route.pagePath);
|
|
6253
6292
|
else pagesSet.add(route.pagePath);
|
|
@@ -8195,6 +8234,13 @@ function normalizeSharedPathCandidate(absoluteId) {
|
|
|
8195
8234
|
stripLeadingNullByte: true
|
|
8196
8235
|
});
|
|
8197
8236
|
}
|
|
8237
|
+
function resolveNodeModulesSharedPath(cleanedAbsoluteId) {
|
|
8238
|
+
const normalized = cleanedAbsoluteId.replaceAll("\\", "/");
|
|
8239
|
+
const markerIndex = normalized.lastIndexOf("/node_modules/");
|
|
8240
|
+
if (markerIndex < 0) return;
|
|
8241
|
+
const packageRelativePath = normalizeNpmImportLookupPath(normalized.slice(markerIndex));
|
|
8242
|
+
return packageRelativePath ? normalizeRelativePath(packageRelativePath) : void 0;
|
|
8243
|
+
}
|
|
8198
8244
|
function createStringOrRegExpMatcher(pattern) {
|
|
8199
8245
|
if (typeof pattern === "string") {
|
|
8200
8246
|
const matcher = picomatch(pattern, { dot: true });
|
|
@@ -8237,7 +8283,7 @@ function createSharedPathResolver(configService, sharedPathRoot) {
|
|
|
8237
8283
|
return (absoluteId) => {
|
|
8238
8284
|
const cleaned = normalizeSharedPathCandidate(absoluteId);
|
|
8239
8285
|
if (!path.isAbsolute(cleaned)) return;
|
|
8240
|
-
if (!isPathInside(resolvedRoot, cleaned)) return;
|
|
8286
|
+
if (!isPathInside(resolvedRoot, cleaned)) return resolveNodeModulesSharedPath(cleaned);
|
|
8241
8287
|
return normalizeRelativePath(path.relative(resolvedRoot, cleaned));
|
|
8242
8288
|
};
|
|
8243
8289
|
}
|
|
@@ -8820,27 +8866,93 @@ function createOxcRuntimeSupport() {
|
|
|
8820
8866
|
}
|
|
8821
8867
|
//#endregion
|
|
8822
8868
|
//#region src/runtime/packageAliases.ts
|
|
8823
|
-
const
|
|
8824
|
-
|
|
8825
|
-
|
|
8826
|
-
|
|
8827
|
-
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
|
|
8869
|
+
const WEVU_WORKSPACE_PACKAGE_PATH = "packages-runtime/wevu";
|
|
8870
|
+
const PACKAGE_ALIASES = [
|
|
8871
|
+
{
|
|
8872
|
+
find: "class-variance-authority",
|
|
8873
|
+
packageName: "class-variance-authority",
|
|
8874
|
+
distEntry: "dist/index.js"
|
|
8875
|
+
},
|
|
8876
|
+
{
|
|
8877
|
+
find: "wevu",
|
|
8878
|
+
packageName: "wevu",
|
|
8879
|
+
distEntry: "dist/index.mjs",
|
|
8880
|
+
fallbackWorkspacePackagePath: WEVU_WORKSPACE_PACKAGE_PATH
|
|
8881
|
+
},
|
|
8882
|
+
{
|
|
8883
|
+
find: "wevu/compiler",
|
|
8884
|
+
packageName: "wevu",
|
|
8885
|
+
distEntry: "dist/compiler.mjs",
|
|
8886
|
+
fallbackWorkspacePackagePath: WEVU_WORKSPACE_PACKAGE_PATH
|
|
8887
|
+
},
|
|
8888
|
+
{
|
|
8889
|
+
find: "wevu/jsx-runtime",
|
|
8890
|
+
packageName: "wevu",
|
|
8891
|
+
distEntry: "dist/jsx-runtime.mjs",
|
|
8892
|
+
fallbackWorkspacePackagePath: WEVU_WORKSPACE_PACKAGE_PATH
|
|
8893
|
+
},
|
|
8894
|
+
{
|
|
8895
|
+
find: "wevu/store",
|
|
8896
|
+
packageName: "wevu",
|
|
8897
|
+
distEntry: "dist/store.mjs",
|
|
8898
|
+
fallbackWorkspacePackagePath: WEVU_WORKSPACE_PACKAGE_PATH
|
|
8899
|
+
},
|
|
8900
|
+
{
|
|
8901
|
+
find: "wevu/api",
|
|
8902
|
+
packageName: "wevu",
|
|
8903
|
+
distEntry: "dist/api.mjs",
|
|
8904
|
+
fallbackWorkspacePackagePath: WEVU_WORKSPACE_PACKAGE_PATH
|
|
8905
|
+
},
|
|
8906
|
+
{
|
|
8907
|
+
find: "wevu/fetch",
|
|
8908
|
+
packageName: "wevu",
|
|
8909
|
+
distEntry: "dist/fetch.mjs",
|
|
8910
|
+
fallbackWorkspacePackagePath: WEVU_WORKSPACE_PACKAGE_PATH
|
|
8911
|
+
},
|
|
8912
|
+
{
|
|
8913
|
+
find: "wevu/router",
|
|
8914
|
+
packageName: "wevu",
|
|
8915
|
+
distEntry: "dist/router.mjs",
|
|
8916
|
+
fallbackWorkspacePackagePath: WEVU_WORKSPACE_PACKAGE_PATH
|
|
8917
|
+
},
|
|
8918
|
+
{
|
|
8919
|
+
find: "vue-demi",
|
|
8920
|
+
packageName: "wevu",
|
|
8921
|
+
distEntry: "dist/vue-demi.mjs",
|
|
8922
|
+
fallbackWorkspacePackagePath: WEVU_WORKSPACE_PACKAGE_PATH
|
|
8923
|
+
}
|
|
8924
|
+
];
|
|
8925
|
+
function resolveRepoRoot(fromDir) {
|
|
8926
|
+
let currentDir = fromDir;
|
|
8927
|
+
while (true) {
|
|
8928
|
+
if (existsSync(path.join(currentDir, "pnpm-workspace.yaml"))) return currentDir;
|
|
8929
|
+
const parentDir = path.dirname(currentDir);
|
|
8930
|
+
if (parentDir === currentDir) return;
|
|
8931
|
+
currentDir = parentDir;
|
|
8932
|
+
}
|
|
8933
|
+
}
|
|
8934
|
+
function resolvePackageEntry(packageName, distEntry, fallbackWorkspacePackagePath) {
|
|
8935
|
+
const packageInfo = getPackageInfoSync(packageName);
|
|
8936
|
+
if (packageInfo) {
|
|
8937
|
+
const resolvedEntry = path.resolve(packageInfo.rootPath, distEntry);
|
|
8938
|
+
if (existsSync(resolvedEntry)) return resolvedEntry;
|
|
8939
|
+
}
|
|
8940
|
+
if (!fallbackWorkspacePackagePath) return;
|
|
8941
|
+
const repoRoot = resolveRepoRoot(path.dirname(fileURLToPath(import.meta.url)));
|
|
8942
|
+
if (!repoRoot) return;
|
|
8943
|
+
const fallbackEntry = path.resolve(repoRoot, fallbackWorkspacePackagePath, distEntry);
|
|
8944
|
+
if (existsSync(fallbackEntry)) return fallbackEntry;
|
|
8945
|
+
}
|
|
8831
8946
|
function resolveBuiltinPackageAliases() {
|
|
8832
8947
|
const aliases = [];
|
|
8833
|
-
for (const { packageName, distEntry } of
|
|
8834
|
-
const
|
|
8835
|
-
if (!
|
|
8836
|
-
const resolvedEntry = path.resolve(info.rootPath, distEntry);
|
|
8837
|
-
if (!existsSync(resolvedEntry)) continue;
|
|
8948
|
+
for (const { find, packageName, distEntry, fallbackWorkspacePackagePath } of PACKAGE_ALIASES) {
|
|
8949
|
+
const resolvedEntry = resolvePackageEntry(packageName, distEntry, fallbackWorkspacePackagePath);
|
|
8950
|
+
if (!resolvedEntry) continue;
|
|
8838
8951
|
aliases.push({
|
|
8839
|
-
find
|
|
8952
|
+
find,
|
|
8840
8953
|
replacement: resolvedEntry
|
|
8841
8954
|
});
|
|
8842
8955
|
}
|
|
8843
|
-
aliases.push(...SPECIFIER_ALIASES);
|
|
8844
8956
|
return aliases;
|
|
8845
8957
|
}
|
|
8846
8958
|
//#endregion
|
|
@@ -9806,8 +9918,12 @@ function asset(ctx) {
|
|
|
9806
9918
|
const LEADING_DOT_SLASH_RE$2 = /^\.\//;
|
|
9807
9919
|
const LEADING_SLASHES_RE$2 = /^\/+/;
|
|
9808
9920
|
const GLOB_WILDCARD_RE = /[*?[{]/;
|
|
9809
|
-
const TRAILING_SLASHES_RE$
|
|
9921
|
+
const TRAILING_SLASHES_RE$1 = /\/+$/;
|
|
9810
9922
|
const AUTO_IMPORT_WATCHER_KEY = "__auto-import-vue-watcher__";
|
|
9923
|
+
const AUTO_IMPORT_CONFIG_SUFFIXES = configExtensions.map((ext) => `.${ext}`);
|
|
9924
|
+
const AUTO_IMPORT_JS_SUFFIXES = new Set(jsExtensions.map((ext) => `.${ext}`));
|
|
9925
|
+
const AUTO_IMPORT_TEMPLATE_SUFFIXES = new Set(templateExtensions.map((ext) => `.${ext}`));
|
|
9926
|
+
const AUTO_IMPORT_VUE_SUFFIXES = new Set(vueExtensions.map((ext) => `.${ext}`));
|
|
9811
9927
|
function isEnabledOutputOption(option) {
|
|
9812
9928
|
if (option === true) return true;
|
|
9813
9929
|
if (typeof option === "string") return option.trim().length > 0;
|
|
@@ -9828,6 +9944,44 @@ function normalizeChangedPath(id) {
|
|
|
9828
9944
|
const [pathWithoutQuery] = id.split("?");
|
|
9829
9945
|
return pathWithoutQuery;
|
|
9830
9946
|
}
|
|
9947
|
+
function getAutoImportCandidateKind(filePath) {
|
|
9948
|
+
if (AUTO_IMPORT_VUE_SUFFIXES.has(path.extname(filePath))) return "vue";
|
|
9949
|
+
if (AUTO_IMPORT_TEMPLATE_SUFFIXES.has(path.extname(filePath))) return "template";
|
|
9950
|
+
if (AUTO_IMPORT_JS_SUFFIXES.has(path.extname(filePath))) return "script";
|
|
9951
|
+
if (AUTO_IMPORT_CONFIG_SUFFIXES.some((suffix) => filePath.endsWith(suffix))) return "config";
|
|
9952
|
+
}
|
|
9953
|
+
function getAutoImportCandidateBase(filePath, kind) {
|
|
9954
|
+
if (!kind) return;
|
|
9955
|
+
if (kind === "config") {
|
|
9956
|
+
const suffix = AUTO_IMPORT_CONFIG_SUFFIXES.find((item) => filePath.endsWith(item));
|
|
9957
|
+
return suffix ? filePath.slice(0, -suffix.length) : void 0;
|
|
9958
|
+
}
|
|
9959
|
+
return filePath.slice(0, -path.extname(filePath).length);
|
|
9960
|
+
}
|
|
9961
|
+
function rankAutoImportCandidate(kind) {
|
|
9962
|
+
switch (kind) {
|
|
9963
|
+
case "vue": return 4;
|
|
9964
|
+
case "template": return 3;
|
|
9965
|
+
case "script": return 2;
|
|
9966
|
+
case "config": return 1;
|
|
9967
|
+
default: return 0;
|
|
9968
|
+
}
|
|
9969
|
+
}
|
|
9970
|
+
function collectDistinctAutoImportCandidates(files) {
|
|
9971
|
+
const bestByBase = /* @__PURE__ */ new Map();
|
|
9972
|
+
for (const filePath of files) {
|
|
9973
|
+
const kind = getAutoImportCandidateKind(filePath);
|
|
9974
|
+
const base = getAutoImportCandidateBase(filePath, kind);
|
|
9975
|
+
if (!kind || !base) continue;
|
|
9976
|
+
const rank = rankAutoImportCandidate(kind);
|
|
9977
|
+
const existing = bestByBase.get(base);
|
|
9978
|
+
if (!existing || rank > existing.rank || rank === existing.rank && filePath < existing.filePath) bestByBase.set(base, {
|
|
9979
|
+
filePath,
|
|
9980
|
+
rank
|
|
9981
|
+
});
|
|
9982
|
+
}
|
|
9983
|
+
return Array.from(bestByBase.values(), (entry) => entry.filePath).sort((a, b) => a.localeCompare(b));
|
|
9984
|
+
}
|
|
9831
9985
|
function resolveAbsolutePath(ctx, candidate) {
|
|
9832
9986
|
const { configService } = ctx;
|
|
9833
9987
|
if (!configService) return;
|
|
@@ -9857,10 +10011,10 @@ async function findAutoImportCandidates(state, globs) {
|
|
|
9857
10011
|
const { configService } = ctx;
|
|
9858
10012
|
if (!resolvedConfig) return [];
|
|
9859
10013
|
const ignore = [...defaultExcluded, `${resolvedConfig.build.outDir}/**`];
|
|
9860
|
-
return await new fdir({
|
|
10014
|
+
return collectDistinctAutoImportCandidates(await new fdir({
|
|
9861
10015
|
includeDirs: false,
|
|
9862
10016
|
pathSeparator: "/"
|
|
9863
|
-
}).withFullPaths().globWithOptions(globs.map((pattern) => path.resolve(configService.absoluteSrcRoot, pattern)), { ignore }).crawl(configService.absoluteSrcRoot).withPromise();
|
|
10017
|
+
}).withFullPaths().globWithOptions(globs.map((pattern) => path.resolve(configService.absoluteSrcRoot, pattern)), { ignore }).crawl(configService.absoluteSrcRoot).withPromise());
|
|
9864
10018
|
}
|
|
9865
10019
|
function registerAutoImportWatchTargets(state, globs, registrar, options = {}) {
|
|
9866
10020
|
const { configService } = state.ctx;
|
|
@@ -9870,7 +10024,7 @@ function registerAutoImportWatchTargets(state, globs, registrar, options = {}) {
|
|
|
9870
10024
|
for (const pattern of globs ?? []) {
|
|
9871
10025
|
const normalizedPattern = toPosixPath(pattern).replace(LEADING_DOT_SLASH_RE$2, "").replace(LEADING_SLASHES_RE$2, "");
|
|
9872
10026
|
const wildcardIndex = normalizedPattern.search(GLOB_WILDCARD_RE);
|
|
9873
|
-
const cleanedBase = (wildcardIndex >= 0 ? normalizedPattern.slice(0, wildcardIndex) : normalizedPattern).replace(TRAILING_SLASHES_RE$
|
|
10027
|
+
const cleanedBase = (wildcardIndex >= 0 ? normalizedPattern.slice(0, wildcardIndex) : normalizedPattern).replace(TRAILING_SLASHES_RE$1, "");
|
|
9874
10028
|
if (!cleanedBase) continue;
|
|
9875
10029
|
watchTargets.add(path.resolve(configService.absoluteSrcRoot, cleanedBase));
|
|
9876
10030
|
}
|
|
@@ -9895,11 +10049,13 @@ function createAutoImportPlugin(state) {
|
|
|
9895
10049
|
}
|
|
9896
10050
|
}));
|
|
9897
10051
|
watcher.on("add", (filePath) => {
|
|
10052
|
+
if (!getAutoImportCandidateKind(filePath)) return;
|
|
9898
10053
|
if (!matchesAutoImportGlobs(ctx, filePath)) return;
|
|
9899
10054
|
logger_default.info(`[auto-import:watch] 新增组件文件 ${configService.relativeCwd(filePath)}`);
|
|
9900
10055
|
autoImportService.registerPotentialComponent(filePath);
|
|
9901
10056
|
});
|
|
9902
10057
|
watcher.on("unlink", (filePath) => {
|
|
10058
|
+
if (!getAutoImportCandidateKind(filePath)) return;
|
|
9903
10059
|
if (!matchesAutoImportGlobs(ctx, filePath)) return;
|
|
9904
10060
|
logger_default.info(`[auto-import:watch] 删除组件文件 ${configService.relativeCwd(filePath)}`);
|
|
9905
10061
|
autoImportService.removePotentialComponent(filePath);
|
|
@@ -9949,6 +10105,7 @@ function createAutoImportPlugin(state) {
|
|
|
9949
10105
|
const absolutePath = resolveAbsolutePath(ctx, filePath);
|
|
9950
10106
|
if (!absolutePath) return;
|
|
9951
10107
|
if (!matchesAutoImportGlobs(ctx, absolutePath)) return;
|
|
10108
|
+
if (!getAutoImportCandidateKind(absolutePath)) return;
|
|
9952
10109
|
if (change.event === "delete") {
|
|
9953
10110
|
autoImportService.removePotentialComponent(absolutePath);
|
|
9954
10111
|
return;
|
|
@@ -11823,8 +11980,6 @@ function createTemplateScanner(wxmlService, debug) {
|
|
|
11823
11980
|
}
|
|
11824
11981
|
//#endregion
|
|
11825
11982
|
//#region src/plugins/hooks/useLoadEntry/index.ts
|
|
11826
|
-
const LEADING_RELATIVE_SEGMENTS_RE = /^[./]+/;
|
|
11827
|
-
const TRAILING_SLASHES_RE$1 = /\/+$/;
|
|
11828
11983
|
function useLoadEntry(ctx, options) {
|
|
11829
11984
|
const debug = createDebugger("weapp-vite:load-entry");
|
|
11830
11985
|
const buildTarget = options?.buildTarget ?? "app";
|
|
@@ -11931,54 +12086,23 @@ function resolvePendingEntryIds(options) {
|
|
|
11931
12086
|
const pending = new Set(options.dirtyEntrySet);
|
|
11932
12087
|
if (options.mode === "full") return new Set(options.resolvedEntryMap.keys());
|
|
11933
12088
|
if (!options.isDev || options.mode === "off") return pending;
|
|
11934
|
-
let hasDependencyDrivenEntry = false;
|
|
11935
|
-
for (const entryId of options.dirtyEntrySet) if (options.dirtyEntryReasons.get(entryId) === "dependency") {
|
|
11936
|
-
hasDependencyDrivenEntry = true;
|
|
11937
|
-
break;
|
|
11938
|
-
}
|
|
11939
12089
|
if (!options.sharedChunkImporters?.size) return pending;
|
|
11940
|
-
if (!hasDependencyDrivenEntry && !hasCrossPackageDirectDirtyImporter(options)) return pending;
|
|
11941
12090
|
for (const importers of options.sharedChunkImporters.values()) {
|
|
11942
12091
|
if (importers.size <= 1) continue;
|
|
11943
12092
|
let hasDependencyDrivenImporter = false;
|
|
11944
|
-
|
|
11945
|
-
|
|
11946
|
-
|
|
11947
|
-
|
|
11948
|
-
|
|
11949
|
-
|
|
12093
|
+
let hasDirectDirtyImporter = false;
|
|
12094
|
+
for (const importer of importers) {
|
|
12095
|
+
if (options.dirtyEntrySet.has(importer) && options.dirtyEntryReasons.get(importer) === "dependency") {
|
|
12096
|
+
hasDependencyDrivenImporter = true;
|
|
12097
|
+
break;
|
|
12098
|
+
}
|
|
12099
|
+
if (options.dirtyEntrySet.has(importer) && options.dirtyEntryReasons.get(importer) === "direct") hasDirectDirtyImporter = true;
|
|
11950
12100
|
}
|
|
12101
|
+
if (!hasDependencyDrivenImporter && !hasDirectDirtyImporter) continue;
|
|
11951
12102
|
for (const importer of importers) pending.add(importer);
|
|
11952
12103
|
}
|
|
11953
12104
|
return pending;
|
|
11954
12105
|
}
|
|
11955
|
-
function shouldExpandDirectUpdateAcrossPackageScopes(importers, options) {
|
|
11956
|
-
let hasDirectDirtyImporter = false;
|
|
11957
|
-
const scopes = /* @__PURE__ */ new Set();
|
|
11958
|
-
for (const importer of importers) {
|
|
11959
|
-
if (options.dirtyEntrySet.has(importer) && options.dirtyEntryReasons.get(importer) === "direct") hasDirectDirtyImporter = true;
|
|
11960
|
-
const scope = resolveEntryPackageScope(importer, options.subPackageRoots, options.relativeAbsoluteSrcRoot);
|
|
11961
|
-
scopes.add(scope);
|
|
11962
|
-
if (scopes.size > 1 && hasDirectDirtyImporter) return true;
|
|
11963
|
-
}
|
|
11964
|
-
return false;
|
|
11965
|
-
}
|
|
11966
|
-
function hasCrossPackageDirectDirtyImporter(options) {
|
|
11967
|
-
for (const importers of options.sharedChunkImporters?.values() ?? []) {
|
|
11968
|
-
if (importers.size <= 1) continue;
|
|
11969
|
-
if (shouldExpandDirectUpdateAcrossPackageScopes(importers, options)) return true;
|
|
11970
|
-
}
|
|
11971
|
-
return false;
|
|
11972
|
-
}
|
|
11973
|
-
function resolveEntryPackageScope(entryId, subPackageRoots, relativeAbsoluteSrcRoot) {
|
|
11974
|
-
const normalized = (relativeAbsoluteSrcRoot?.(entryId) ?? entryId).replace(LEADING_RELATIVE_SEGMENTS_RE, "");
|
|
11975
|
-
for (const root of subPackageRoots ?? []) {
|
|
11976
|
-
const normalizedRoot = posix.normalize(root).replace(LEADING_RELATIVE_SEGMENTS_RE, "").replace(TRAILING_SLASHES_RE$1, "");
|
|
11977
|
-
if (!normalizedRoot) continue;
|
|
11978
|
-
if (normalized === normalizedRoot || normalized.startsWith(`${normalizedRoot}/`)) return normalizedRoot;
|
|
11979
|
-
}
|
|
11980
|
-
return "";
|
|
11981
|
-
}
|
|
11982
12106
|
//#endregion
|
|
11983
12107
|
//#region src/utils/wxmlScriptModule.ts
|
|
11984
12108
|
const IMPORT_SJS_TAG_RE = /<import-sjs([\s\S]*?)>/g;
|
|
@@ -12458,37 +12582,32 @@ function refreshModuleGraph(pluginCtx, state) {
|
|
|
12458
12582
|
if (importers.size) state.moduleImporters.set(normalizedId, importers);
|
|
12459
12583
|
}
|
|
12460
12584
|
}
|
|
12461
|
-
function refreshSharedChunkImporters(bundle, state) {
|
|
12462
|
-
state.hmrSharedChunkImporters.clear();
|
|
12463
|
-
appendSharedChunkImporters(bundle, state);
|
|
12464
|
-
}
|
|
12465
|
-
function refreshPartialSharedChunkImporters(bundle, state, entryIds) {
|
|
12466
|
-
if (!entryIds.size) return;
|
|
12467
|
-
for (const [chunkId, importers] of state.hmrSharedChunkImporters) {
|
|
12468
|
-
for (const entryId of entryIds) importers.delete(entryId);
|
|
12469
|
-
if (importers.size === 0) state.hmrSharedChunkImporters.delete(chunkId);
|
|
12470
|
-
}
|
|
12471
|
-
appendSharedChunkImporters(bundle, state, entryIds);
|
|
12472
|
-
}
|
|
12473
12585
|
function appendSharedChunkImporters(bundle, state, onlyEntryIds) {
|
|
12474
|
-
const
|
|
12475
|
-
|
|
12476
|
-
if (
|
|
12477
|
-
|
|
12478
|
-
|
|
12586
|
+
const getTrackedImporterIds = (chunk) => {
|
|
12587
|
+
const trackedImporterIds = /* @__PURE__ */ new Set();
|
|
12588
|
+
if (chunk.facadeModuleId) {
|
|
12589
|
+
const entryId = normalizeFsResolvedId(chunk.facadeModuleId);
|
|
12590
|
+
if (chunk.isEntry || state.resolvedEntryMap.has(entryId)) trackedImporterIds.add(entryId);
|
|
12591
|
+
}
|
|
12592
|
+
if (Array.isArray(chunk.moduleIds)) for (const moduleId of chunk.moduleIds) {
|
|
12593
|
+
const normalizedModuleId = normalizeFsResolvedId(moduleId);
|
|
12594
|
+
if (state.resolvedEntryMap.has(normalizedModuleId)) trackedImporterIds.add(normalizedModuleId);
|
|
12595
|
+
}
|
|
12596
|
+
return trackedImporterIds;
|
|
12479
12597
|
};
|
|
12480
12598
|
const entryChunks = [];
|
|
12481
12599
|
for (const output of Object.values(bundle)) {
|
|
12482
12600
|
if (output?.type !== "chunk") continue;
|
|
12483
12601
|
const chunk = output;
|
|
12484
|
-
|
|
12485
|
-
if (!
|
|
12486
|
-
const
|
|
12487
|
-
|
|
12488
|
-
|
|
12489
|
-
|
|
12490
|
-
|
|
12491
|
-
|
|
12602
|
+
const trackedImporterIds = getTrackedImporterIds(chunk);
|
|
12603
|
+
if (!trackedImporterIds.size) continue;
|
|
12604
|
+
for (const trackedImporterId of trackedImporterIds) {
|
|
12605
|
+
if (onlyEntryIds && !onlyEntryIds.has(trackedImporterId)) continue;
|
|
12606
|
+
entryChunks.push({
|
|
12607
|
+
entryId: trackedImporterId,
|
|
12608
|
+
chunk
|
|
12609
|
+
});
|
|
12610
|
+
}
|
|
12492
12611
|
}
|
|
12493
12612
|
if (!entryChunks.length) return;
|
|
12494
12613
|
for (const { chunk, entryId } of entryChunks) {
|
|
@@ -12499,13 +12618,25 @@ function appendSharedChunkImporters(bundle, state, onlyEntryIds) {
|
|
|
12499
12618
|
for (const imported of imports) {
|
|
12500
12619
|
const target = bundle[imported];
|
|
12501
12620
|
if (!target || target.type !== "chunk") continue;
|
|
12502
|
-
if (
|
|
12621
|
+
if (getTrackedImporterIds(target).size) continue;
|
|
12503
12622
|
const current = state.hmrSharedChunkImporters.get(imported);
|
|
12504
12623
|
if (current) current.add(entryId);
|
|
12505
12624
|
else state.hmrSharedChunkImporters.set(imported, new Set([entryId]));
|
|
12506
12625
|
}
|
|
12507
12626
|
}
|
|
12508
12627
|
}
|
|
12628
|
+
function refreshSharedChunkImporters(bundle, state) {
|
|
12629
|
+
state.hmrSharedChunkImporters.clear();
|
|
12630
|
+
appendSharedChunkImporters(bundle, state);
|
|
12631
|
+
}
|
|
12632
|
+
function refreshPartialSharedChunkImporters(bundle, state, entryIds) {
|
|
12633
|
+
if (!entryIds.size) return;
|
|
12634
|
+
for (const [chunkId, importers] of state.hmrSharedChunkImporters) {
|
|
12635
|
+
for (const entryId of entryIds) importers.delete(entryId);
|
|
12636
|
+
if (importers.size === 0) state.hmrSharedChunkImporters.delete(chunkId);
|
|
12637
|
+
}
|
|
12638
|
+
appendSharedChunkImporters(bundle, state, entryIds);
|
|
12639
|
+
}
|
|
12509
12640
|
//#endregion
|
|
12510
12641
|
//#region src/plugins/core/helpers/independent.ts
|
|
12511
12642
|
async function flushIndependentBuilds(state) {
|
|
@@ -12713,7 +12844,7 @@ const PRETTY_NODE_MODULES_RE = /node_modules\/(?:\.pnpm\/[^/]+\/node_modules\/)?
|
|
|
12713
12844
|
const REQUEST_GLOBAL_EXPORT_RE = /Object\.defineProperty\(exports,\s*(?:`([^`]+)`|'([^']+)'|"([^"]+)"),\s*\{[\s\S]*?get:function\(\)\{return ([A-Za-z_$][\w$]*)\}\}\)/g;
|
|
12714
12845
|
const REQUEST_GLOBAL_INSTALLER_RE = /function\s+([A-Za-z_$][\w$]*)\([^)]*=\{\}\)\{[\s\S]{0,200}?targets\?\?\[[\s\S]{0,80}?fetch[\s\S]{0,80}?Headers[\s\S]{0,80}?Request[\s\S]{0,80}?Response[\s\S]{0,80}?AbortController[\s\S]{0,80}?AbortSignal[\s\S]{0,80}?XMLHttpRequest[\s\S]{0,240}?return [^}]+\}/;
|
|
12715
12846
|
const REQUEST_GLOBAL_ENTRY_NAME_RE = /\.[^/.]+$/;
|
|
12716
|
-
const
|
|
12847
|
+
const REQUEST_GLOBAL_REQUIRE_DECLARATOR_RE = /([A-Za-z_$][\w$]*)\s*=\s*require\((`([^`]+)`|'([^']+)'|"([^"]+)")\)/g;
|
|
12717
12848
|
const REQUEST_GLOBAL_TARGET_SIGNATURES = [
|
|
12718
12849
|
"fetch",
|
|
12719
12850
|
"Headers",
|
|
@@ -12933,6 +13064,29 @@ function resolveRequestGlobalsBindingTargets(targets) {
|
|
|
12933
13064
|
if (targets.some((target) => target === "fetch" || target === "Request" || target === "Response" || target === "XMLHttpRequest")) bindingTargets.push("URL", "URLSearchParams", "Blob", "FormData");
|
|
12934
13065
|
return [...new Set(bindingTargets)].filter((target) => REQUEST_GLOBAL_FREE_BINDING_TARGETS.has(target));
|
|
12935
13066
|
}
|
|
13067
|
+
function createRequestGlobalsPassiveBindingsCode(bindingTargets) {
|
|
13068
|
+
return `${[
|
|
13069
|
+
"const __weappViteRequestGlobalsActuals__ = globalThis.__weappViteRequestGlobalsActuals__ || (globalThis.__weappViteRequestGlobalsActuals__ = Object.create(null))",
|
|
13070
|
+
"function __weappViteMarkRequestGlobalsPlaceholder__(value){try{Object.defineProperty(value,\"__weappViteRequestGlobalsPlaceholder__\",{value:true,configurable:true})}catch{value.__weappViteRequestGlobalsPlaceholder__=true}return value}",
|
|
13071
|
+
"function __weappViteCreateLazyRequestGlobalsFunction__(name){const placeholder=function(...args){const actual=__weappViteRequestGlobalsActuals__[name];if(typeof actual!==\"function\"){throw new Error(name+\" is not initialized\")}return actual.apply(this,args)};return __weappViteMarkRequestGlobalsPlaceholder__(placeholder)}",
|
|
13072
|
+
"function __weappViteCreateLazyRequestGlobalsConstructor__(name){const placeholder=function(...args){const actual=__weappViteRequestGlobalsActuals__[name];if(typeof actual!==\"function\"){throw new Error(name+\" is not initialized\")}return Reflect.construct(actual,args)};return __weappViteMarkRequestGlobalsPlaceholder__(placeholder)}",
|
|
13073
|
+
"function __weappViteHasUsableRequestGlobalsConstructor__(value,args){if(typeof value!==\"function\"||value?.__weappViteRequestGlobalsPlaceholder__===true){return false}try{return Reflect.construct(value,args),true}catch{return false}}"
|
|
13074
|
+
].join(";")};${bindingTargets.map((target) => {
|
|
13075
|
+
if (target === "fetch") return "var fetch = typeof __weappViteRequestGlobalsActuals__[\"fetch\"]===\"function\"&&__weappViteRequestGlobalsActuals__[\"fetch\"]?.__weappViteRequestGlobalsPlaceholder__!==true?__weappViteRequestGlobalsActuals__[\"fetch\"]:typeof globalThis.fetch===\"function\"&&globalThis.fetch?.__weappViteRequestGlobalsPlaceholder__!==true?globalThis.fetch:__weappViteCreateLazyRequestGlobalsFunction__(\"fetch\")";
|
|
13076
|
+
const placeholderFactory = `__weappViteCreateLazyRequestGlobalsConstructor__(${JSON.stringify(target)})`;
|
|
13077
|
+
const actualRef = `__weappViteRequestGlobalsActuals__[${JSON.stringify(target)}]`;
|
|
13078
|
+
if (target === "URL") return `var URL = __weappViteHasUsableRequestGlobalsConstructor__(${actualRef},["https://request-globals.invalid"])?${actualRef}:__weappViteHasUsableRequestGlobalsConstructor__(globalThis.URL,["https://request-globals.invalid"])?globalThis.URL:${placeholderFactory}`;
|
|
13079
|
+
if (target === "URLSearchParams") return `var URLSearchParams = __weappViteHasUsableRequestGlobalsConstructor__(${actualRef},["client=graphql-request"])?${actualRef}:__weappViteHasUsableRequestGlobalsConstructor__(globalThis.URLSearchParams,["client=graphql-request"])?globalThis.URLSearchParams:${placeholderFactory}`;
|
|
13080
|
+
if (target === "Blob") return `var Blob = __weappViteHasUsableRequestGlobalsConstructor__(${actualRef},[])?${actualRef}:__weappViteHasUsableRequestGlobalsConstructor__(globalThis.Blob,[])?globalThis.Blob:${placeholderFactory}`;
|
|
13081
|
+
if (target === "FormData") return `var FormData = __weappViteHasUsableRequestGlobalsConstructor__(${actualRef},[])?${actualRef}:__weappViteHasUsableRequestGlobalsConstructor__(globalThis.FormData,[])?globalThis.FormData:${placeholderFactory}`;
|
|
13082
|
+
if (target === "Headers") return `var Headers = __weappViteHasUsableRequestGlobalsConstructor__(${actualRef},[])?${actualRef}:__weappViteHasUsableRequestGlobalsConstructor__(globalThis.Headers,[])?globalThis.Headers:${placeholderFactory}`;
|
|
13083
|
+
if (target === "Request") return `var Request = __weappViteHasUsableRequestGlobalsConstructor__(${actualRef},["https://request-globals.invalid"])?${actualRef}:__weappViteHasUsableRequestGlobalsConstructor__(globalThis.Request,["https://request-globals.invalid"])?globalThis.Request:${placeholderFactory}`;
|
|
13084
|
+
if (target === "Response") return `var Response = __weappViteHasUsableRequestGlobalsConstructor__(${actualRef},[null])?${actualRef}:__weappViteHasUsableRequestGlobalsConstructor__(globalThis.Response,[null])?globalThis.Response:${placeholderFactory}`;
|
|
13085
|
+
if (target === "XMLHttpRequest") return `var XMLHttpRequest = __weappViteHasUsableRequestGlobalsConstructor__(${actualRef},[])?${actualRef}:__weappViteHasUsableRequestGlobalsConstructor__(globalThis.XMLHttpRequest,[])?globalThis.XMLHttpRequest:${placeholderFactory}`;
|
|
13086
|
+
if (target === "AbortController") return `var AbortController = __weappViteHasUsableRequestGlobalsConstructor__(${actualRef},[])?${actualRef}:__weappViteHasUsableRequestGlobalsConstructor__(globalThis.AbortController,[])?globalThis.AbortController:${placeholderFactory}`;
|
|
13087
|
+
return `var ${target} = typeof ${actualRef}==="function"&&${actualRef}?.__weappViteRequestGlobalsPlaceholder__!==true?${actualRef}:typeof globalThis.${target}==="function"&&globalThis.${target}?.__weappViteRequestGlobalsPlaceholder__!==true?globalThis.${target}:${placeholderFactory}`;
|
|
13088
|
+
}).join(";")};`;
|
|
13089
|
+
}
|
|
12936
13090
|
function injectRequestGlobalsBundleRuntime(bundle, targets) {
|
|
12937
13091
|
const installerChunks = /* @__PURE__ */ new Map();
|
|
12938
13092
|
if (targets.length === 0) return installerChunks;
|
|
@@ -12945,14 +13099,38 @@ function injectRequestGlobalsBundleRuntime(bundle, targets) {
|
|
|
12945
13099
|
const exportName = resolveRequestGlobalsExportName(chunk.code);
|
|
12946
13100
|
if (!installerName || !exportName) continue;
|
|
12947
13101
|
installerChunks.set(toPosixPath(chunk.fileName), exportName);
|
|
12948
|
-
const
|
|
12949
|
-
|
|
12950
|
-
|
|
12951
|
-
|
|
12952
|
-
|
|
13102
|
+
const passiveBindingsCode = createRequestGlobalsPassiveBindingsCode(bindingTargets);
|
|
13103
|
+
const runtimeBindingCode = [
|
|
13104
|
+
`const __weappViteRequestGlobalsBundleHost__ = ${installerName}({ targets: ${JSON.stringify(targets)} }) || globalThis`,
|
|
13105
|
+
...bindingTargets.map((target) => `__weappViteRequestGlobalsActuals__[${JSON.stringify(target)}] = __weappViteRequestGlobalsBundleHost__.${target}`),
|
|
13106
|
+
...bindingTargets.map((target) => `${target} = __weappViteRequestGlobalsBundleHost__.${target}`)
|
|
13107
|
+
].join(";");
|
|
13108
|
+
const bundlePrelude = `/* __weappViteRequestGlobalsBundleInstalled__ */ ${passiveBindingsCode}\n`;
|
|
13109
|
+
const firstRequireMatch = chunk.code.match(REQUEST_GLOBAL_REQUIRE_DECLARATOR_RE);
|
|
13110
|
+
if (firstRequireMatch?.[0]) {
|
|
13111
|
+
chunk.code = `${bundlePrelude}${chunk.code.replace(firstRequireMatch[0], (match) => `${match};${runtimeBindingCode}`)}\n`;
|
|
13112
|
+
continue;
|
|
13113
|
+
}
|
|
13114
|
+
chunk.code = `${bundlePrelude}${chunk.code}\n;${runtimeBindingCode};\n`;
|
|
12953
13115
|
}
|
|
12954
13116
|
return installerChunks;
|
|
12955
13117
|
}
|
|
13118
|
+
function injectRequestGlobalsPassiveBindings(bundle, installerChunks, targets, entriesMap) {
|
|
13119
|
+
if (installerChunks.size === 0 || targets.length === 0) return;
|
|
13120
|
+
const bindingTargets = resolveRequestGlobalsBindingTargets(targets);
|
|
13121
|
+
if (bindingTargets.length === 0) return;
|
|
13122
|
+
const passiveBindingsCode = createRequestGlobalsPassiveBindingsCode(bindingTargets);
|
|
13123
|
+
for (const output of Object.values(bundle)) {
|
|
13124
|
+
if (output?.type !== "chunk") continue;
|
|
13125
|
+
const chunk = output;
|
|
13126
|
+
if (installerChunks.has(toPosixPath(chunk.fileName))) continue;
|
|
13127
|
+
if (chunk.code.includes("__weappViteRequestGlobalsPassiveBindings__") || chunk.code.includes("__weappViteRequestGlobalsLocalBindings__") || chunk.code.includes("__weappViteRequestGlobalsBundleInstalled__")) continue;
|
|
13128
|
+
const entryName = chunk.fileName.replace(REQUEST_GLOBAL_ENTRY_NAME_RE, "");
|
|
13129
|
+
const entryType = entriesMap?.get(entryName)?.type;
|
|
13130
|
+
if (entryType === "page" || entryType === "component") continue;
|
|
13131
|
+
chunk.code = `/* __weappViteRequestGlobalsPassiveBindings__ */ ${passiveBindingsCode}\n${chunk.code}`;
|
|
13132
|
+
}
|
|
13133
|
+
}
|
|
12956
13134
|
function injectRequestGlobalsLocalBindings(bundle, installerChunks, targets, entriesMap) {
|
|
12957
13135
|
if (installerChunks.size === 0 || targets.length === 0) return;
|
|
12958
13136
|
const bindingTargets = resolveRequestGlobalsBindingTargets(targets);
|
|
@@ -12964,16 +13142,25 @@ function injectRequestGlobalsLocalBindings(bundle, installerChunks, targets, ent
|
|
|
12964
13142
|
const entryType = entriesMap?.get(entryName)?.type;
|
|
12965
13143
|
if (entryType !== "page" && entryType !== "component") continue;
|
|
12966
13144
|
if (chunk.code.includes("__weappViteRequestGlobalsLocalBindings__")) continue;
|
|
12967
|
-
|
|
12968
|
-
|
|
12969
|
-
const
|
|
12970
|
-
|
|
12971
|
-
|
|
12972
|
-
|
|
12973
|
-
|
|
12974
|
-
|
|
12975
|
-
|
|
12976
|
-
|
|
13145
|
+
let requireImportLiteral = null;
|
|
13146
|
+
let exportName;
|
|
13147
|
+
for (const requireMatch of chunk.code.matchAll(REQUEST_GLOBAL_REQUIRE_DECLARATOR_RE)) {
|
|
13148
|
+
const importee = requireMatch[3] ?? requireMatch[4] ?? requireMatch[5];
|
|
13149
|
+
if (!importee) continue;
|
|
13150
|
+
const installerChunkFileName = normalizeRelativeChunkImport(chunk.fileName, importee);
|
|
13151
|
+
exportName = installerChunks.get(installerChunkFileName);
|
|
13152
|
+
if (!exportName) continue;
|
|
13153
|
+
requireImportLiteral = requireMatch[2] ?? null;
|
|
13154
|
+
break;
|
|
13155
|
+
}
|
|
13156
|
+
if (!requireImportLiteral || !exportName) continue;
|
|
13157
|
+
chunk.code = `/* __weappViteRequestGlobalsLocalBindings__ */ ${[
|
|
13158
|
+
`const __weappViteChunkRequestGlobalsModule__ = require(${requireImportLiteral})`,
|
|
13159
|
+
`const __weappViteChunkRequestGlobalsHost__ = __weappViteChunkRequestGlobalsModule__[${JSON.stringify(exportName)}]({ targets: ${JSON.stringify(targets)} }) || globalThis`,
|
|
13160
|
+
"const __weappViteRequestGlobalsActuals__ = globalThis.__weappViteRequestGlobalsActuals__ || (globalThis.__weappViteRequestGlobalsActuals__ = Object.create(null))",
|
|
13161
|
+
...bindingTargets.map((target) => `__weappViteRequestGlobalsActuals__[${JSON.stringify(target)}] = __weappViteChunkRequestGlobalsHost__.${target}`),
|
|
13162
|
+
...bindingTargets.map((target) => `var ${target} = __weappViteChunkRequestGlobalsHost__.${target}`)
|
|
13163
|
+
].join(";")};\n${chunk.code}`;
|
|
12977
13164
|
}
|
|
12978
13165
|
}
|
|
12979
13166
|
function toRelativeRuntimeNpmImport(fileName, root, importee) {
|
|
@@ -13178,7 +13365,11 @@ function createGenerateBundleHook(state, isPluginBuild) {
|
|
|
13178
13365
|
}
|
|
13179
13366
|
const injectWeapiGlobalName = resolveInjectWeapiGlobalName(state);
|
|
13180
13367
|
if (injectWeapiGlobalName) rewriteBundlePlatformApi(rolldownBundle, injectWeapiGlobalName, { astEngine });
|
|
13181
|
-
if (injectRequestGlobalsOptions?.targets?.length)
|
|
13368
|
+
if (injectRequestGlobalsOptions?.targets?.length) {
|
|
13369
|
+
const installerChunks = injectRequestGlobalsBundleRuntime(rolldownBundle, injectRequestGlobalsOptions.targets);
|
|
13370
|
+
injectRequestGlobalsPassiveBindings(rolldownBundle, installerChunks, injectRequestGlobalsOptions.targets, state.entriesMap);
|
|
13371
|
+
injectRequestGlobalsLocalBindings(rolldownBundle, installerChunks, injectRequestGlobalsOptions.targets, state.entriesMap);
|
|
13372
|
+
}
|
|
13182
13373
|
refreshModuleGraph(this, state);
|
|
13183
13374
|
if (configService.weappViteConfig?.debug?.watchFiles) {
|
|
13184
13375
|
const watcherService = ctx.watcherService;
|
|
@@ -18977,6 +19168,7 @@ function createRuntimeState() {
|
|
|
18977
19168
|
},
|
|
18978
19169
|
autoImport: {
|
|
18979
19170
|
registry: /* @__PURE__ */ new Map(),
|
|
19171
|
+
resolvedResolverComponents: /* @__PURE__ */ new Map(),
|
|
18980
19172
|
matcherKey: ""
|
|
18981
19173
|
},
|
|
18982
19174
|
build: {
|
|
@@ -19380,7 +19572,7 @@ function createScanService(ctx) {
|
|
|
19380
19572
|
const vueAppPath = await findVueEntry(appBasename);
|
|
19381
19573
|
let configFromVue;
|
|
19382
19574
|
if (!appConfigFile && vueAppPath) {
|
|
19383
|
-
const { extractConfigFromVue } = await import("./file-
|
|
19575
|
+
const { extractConfigFromVue } = await import("./file-MiE605t6.mjs").then((n) => n.r);
|
|
19384
19576
|
configFromVue = await extractConfigFromVue(vueAppPath);
|
|
19385
19577
|
if (configFromVue) appConfigFile = vueAppPath;
|
|
19386
19578
|
}
|
|
@@ -20101,6 +20293,31 @@ async function hasManagedTsconfigChanges(ctx) {
|
|
|
20101
20293
|
for (const file of files) if (await readFile(file.path, "utf8").catch(() => void 0) !== file.content) return true;
|
|
20102
20294
|
return false;
|
|
20103
20295
|
}
|
|
20296
|
+
async function collectAutoImportTemplateTags(ctx) {
|
|
20297
|
+
const srcRoot = ctx.configService?.absoluteSrcRoot;
|
|
20298
|
+
if (!srcRoot) return [];
|
|
20299
|
+
const files = await new fdir({
|
|
20300
|
+
includeDirs: false,
|
|
20301
|
+
pathSeparator: "/"
|
|
20302
|
+
}).withFullPaths().filter((filePath) => filePath.endsWith(".vue") || filePath.endsWith(".wxml")).crawl(srcRoot).withPromise();
|
|
20303
|
+
const tags = /* @__PURE__ */ new Map();
|
|
20304
|
+
const platform = ctx.configService?.platform ?? "weapp";
|
|
20305
|
+
for (const filePath of files) {
|
|
20306
|
+
const source = await readFile(filePath, "utf8").catch(() => void 0);
|
|
20307
|
+
if (!source) continue;
|
|
20308
|
+
if (filePath.endsWith(".vue")) {
|
|
20309
|
+
const { descriptor, errors } = parse(source, { filename: filePath });
|
|
20310
|
+
if (errors.length > 0 || !descriptor.template?.content) continue;
|
|
20311
|
+
for (const tag of collectVueTemplateAutoImportTags(descriptor.template.content, filePath)) tags.set(tag, removeExtensionDeep(filePath));
|
|
20312
|
+
continue;
|
|
20313
|
+
}
|
|
20314
|
+
for (const tag of Object.keys(scanWxml(source, { platform }).components)) tags.set(tag, removeExtensionDeep(filePath));
|
|
20315
|
+
}
|
|
20316
|
+
return Array.from(tags.entries(), ([tag, importerBaseName]) => ({
|
|
20317
|
+
tag,
|
|
20318
|
+
importerBaseName
|
|
20319
|
+
}));
|
|
20320
|
+
}
|
|
20104
20321
|
async function syncProjectSupportFiles(ctx) {
|
|
20105
20322
|
const managedTsconfigChanged = await hasManagedTsconfigChanges(ctx);
|
|
20106
20323
|
await syncManagedTsconfigFiles(ctx);
|
|
@@ -20116,6 +20333,8 @@ async function syncProjectSupportFiles(ctx) {
|
|
|
20116
20333
|
}, globs);
|
|
20117
20334
|
await Promise.all(files.map((file) => ctx.autoImportService.registerPotentialComponent(file)));
|
|
20118
20335
|
} else if (!shouldBootstrapAutoImportWithoutGlobs(autoImportConfig)) {}
|
|
20336
|
+
const templateTags = await collectAutoImportTemplateTags(ctx);
|
|
20337
|
+
for (const { tag, importerBaseName } of templateTags) ctx.autoImportService.resolve(tag, importerBaseName);
|
|
20119
20338
|
await ctx.autoImportService.awaitManifestWrites();
|
|
20120
20339
|
}
|
|
20121
20340
|
return { managedTsconfigChanged };
|