weapp-vite 5.7.0 → 5.7.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.
Files changed (36) hide show
  1. package/dist/auto-import-components/resolvers.cjs +5 -5
  2. package/dist/auto-import-components/resolvers.mjs +1 -1
  3. package/dist/auto-routes.cjs +8 -8
  4. package/dist/auto-routes.mjs +4 -4
  5. package/dist/{chunk-GU7U5762.mjs → chunk-3WGK7INY.mjs} +2 -2
  6. package/dist/{chunk-VRKZFXIZ.cjs → chunk-AUQJOLJS.cjs} +6 -6
  7. package/dist/{chunk-ZMX6CFVX.mjs → chunk-ED4S52HS.mjs} +1 -1
  8. package/dist/{chunk-AKJEW44F.mjs → chunk-FSDX3XLK.mjs} +454 -57
  9. package/dist/{chunk-FUJ4D6IR.cjs → chunk-HKSOVHNE.cjs} +799 -402
  10. package/dist/{chunk-MQBCRXCD.cjs → chunk-JKNSNXOE.cjs} +2 -2
  11. package/dist/chunk-O3YXI56P.cjs +6 -0
  12. package/dist/{chunk-A5DD7GKX.cjs → chunk-QKFYCWOC.cjs} +2 -2
  13. package/dist/{chunk-N463WDOG.mjs → chunk-RJVVY5EI.mjs} +1 -1
  14. package/dist/{chunk-G6EZVEVT.cjs → chunk-RMHCFT5Q.cjs} +2 -2
  15. package/dist/{chunk-2SUWUB42.mjs → chunk-SSYIWHY2.mjs} +1 -1
  16. package/dist/{chunk-SSQGJIB5.mjs → chunk-TZWATIK3.mjs} +2 -2
  17. package/dist/cli.cjs +298 -91
  18. package/dist/cli.mjs +228 -22
  19. package/dist/config.cjs +4 -4
  20. package/dist/config.mjs +3 -3
  21. package/dist/index.cjs +8 -8
  22. package/dist/index.mjs +6 -6
  23. package/dist/json.cjs +3 -3
  24. package/dist/json.mjs +2 -2
  25. package/dist/types.cjs +9 -9
  26. package/dist/types.mjs +2 -2
  27. package/dist/volar.cjs +2 -2
  28. package/dist/volar.mjs +1 -1
  29. package/modules/analyze-dashboard/assets/echarts.js +17 -0
  30. package/modules/analyze-dashboard/assets/index.css +2 -0
  31. package/modules/analyze-dashboard/assets/index.js +1 -0
  32. package/modules/analyze-dashboard/assets/rolldown-runtime.js +1 -0
  33. package/modules/analyze-dashboard/assets/vue.js +6 -0
  34. package/modules/analyze-dashboard/index.html +13 -0
  35. package/package.json +12 -5
  36. package/dist/chunk-FOWFAOSV.cjs +0 -6
@@ -3,7 +3,7 @@ import {
3
3
  __require,
4
4
  __toESM,
5
5
  init_esm_shims
6
- } from "./chunk-SSQGJIB5.mjs";
6
+ } from "./chunk-TZWATIK3.mjs";
7
7
 
8
8
  // ../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/internal/debug.js
9
9
  var require_debug = __commonJS({
@@ -11922,8 +11922,39 @@ import { Buffer as Buffer2 } from "buffer";
11922
11922
  import { posix as path10 } from "pathe";
11923
11923
  var SHARED_CHUNK_VIRTUAL_PREFIX = "weapp_shared_virtual";
11924
11924
  var SUB_PACKAGE_SHARED_DIR = "weapp-shared";
11925
- var DEFAULT_SHARED_CHUNK_STRATEGY = "duplicate";
11925
+ var DEFAULT_SHARED_CHUNK_STRATEGY = "hoist";
11926
+ function markTakeModuleImporter(moduleId, importerId) {
11927
+ if (!moduleId || !importerId) {
11928
+ return;
11929
+ }
11930
+ const importers = takeImportersMap.get(moduleId);
11931
+ if (importers) {
11932
+ importers.add(importerId);
11933
+ } else {
11934
+ takeImportersMap.set(moduleId, /* @__PURE__ */ new Set([importerId]));
11935
+ }
11936
+ }
11937
+ function resetTakeImportRegistry() {
11938
+ takeImportersMap.clear();
11939
+ forceDuplicateSharedChunks.clear();
11940
+ sharedChunkDiagnostics.clear();
11941
+ }
11942
+ function getTakeImporters(moduleId) {
11943
+ return takeImportersMap.get(moduleId);
11944
+ }
11945
+ function markForceDuplicateSharedChunk(sharedName) {
11946
+ if (!sharedName) {
11947
+ return;
11948
+ }
11949
+ forceDuplicateSharedChunks.add(sharedName);
11950
+ forceDuplicateSharedChunks.add(`${sharedName}.js`);
11951
+ }
11952
+ function isForceDuplicateSharedChunk(fileName) {
11953
+ return forceDuplicateSharedChunks.has(fileName);
11954
+ }
11926
11955
  var sharedChunkDiagnostics = /* @__PURE__ */ new Map();
11956
+ var takeImportersMap = /* @__PURE__ */ new Map();
11957
+ var forceDuplicateSharedChunks = /* @__PURE__ */ new Set();
11927
11958
  function resolveSharedChunkName(options) {
11928
11959
  const {
11929
11960
  id,
@@ -11933,7 +11964,42 @@ function resolveSharedChunkName(options) {
11933
11964
  strategy,
11934
11965
  forceDuplicateTester
11935
11966
  } = options;
11967
+ const subPackageRootList = Array.from(subPackageRoots);
11936
11968
  const moduleInfo = ctx.getModuleInfo(id);
11969
+ const takeImporters = getTakeImporters(id);
11970
+ if (takeImporters?.size) {
11971
+ const takeSharedName = resolveTakeSharedChunkName({
11972
+ id,
11973
+ ctx,
11974
+ relativeAbsoluteSrcRoot,
11975
+ subPackageRoots: subPackageRootList,
11976
+ importers: Array.from(takeImporters)
11977
+ });
11978
+ if (takeSharedName) {
11979
+ return takeSharedName;
11980
+ }
11981
+ }
11982
+ if (strategy === "hoist") {
11983
+ const relativeId = relativeAbsoluteSrcRoot(id);
11984
+ const moduleRoot = resolveSubPackagePrefix(relativeId, subPackageRootList);
11985
+ if (moduleRoot) {
11986
+ assertModuleScopedToRoot({
11987
+ moduleInfo,
11988
+ moduleRoot,
11989
+ relativeAbsoluteSrcRoot,
11990
+ subPackageRoots: subPackageRootList,
11991
+ moduleId: id
11992
+ });
11993
+ if (!moduleInfo?.importers || moduleInfo.importers.length <= 1) {
11994
+ return void 0;
11995
+ }
11996
+ return path10.join(moduleRoot, "common");
11997
+ }
11998
+ if (!moduleInfo?.importers || moduleInfo.importers.length <= 1) {
11999
+ return void 0;
12000
+ }
12001
+ return "common";
12002
+ }
11937
12003
  if (!moduleInfo?.importers || moduleInfo.importers.length <= 1) {
11938
12004
  return void 0;
11939
12005
  }
@@ -11941,7 +12007,7 @@ function resolveSharedChunkName(options) {
11941
12007
  ctx,
11942
12008
  importers: moduleInfo.importers,
11943
12009
  relativeAbsoluteSrcRoot,
11944
- subPackageRoots: Array.from(subPackageRoots),
12010
+ subPackageRoots: subPackageRootList,
11945
12011
  forceDuplicateTester
11946
12012
  });
11947
12013
  const keys = Object.keys(summary);
@@ -11954,9 +12020,7 @@ function resolveSharedChunkName(options) {
11954
12020
  }
11955
12021
  const hasMainImporter = keys.includes("");
11956
12022
  if (strategy === "duplicate" && !hasMainImporter) {
11957
- const combination = keys.filter(Boolean).sort().join("+");
11958
- const combinationSegment = combination ? `${combination}/` : "";
11959
- const sharedName = `${SHARED_CHUNK_VIRTUAL_PREFIX}/${combinationSegment}common`;
12023
+ const sharedName = createSharedChunkNameFromKeys(keys);
11960
12024
  if (ignoredMainImporters.length) {
11961
12025
  sharedChunkDiagnostics.set(sharedName, {
11962
12026
  ignoredMainImporters: Array.from(new Set(ignoredMainImporters))
@@ -12107,8 +12171,60 @@ function resolveSubPackagePrefix(fileName, subPackageRoots) {
12107
12171
  }
12108
12172
  return "";
12109
12173
  }
12174
+ function resolveTakeSharedChunkName(options) {
12175
+ const {
12176
+ ctx,
12177
+ relativeAbsoluteSrcRoot,
12178
+ subPackageRoots,
12179
+ importers
12180
+ } = options;
12181
+ if (!importers.length) {
12182
+ return void 0;
12183
+ }
12184
+ const { summary } = summarizeImportPrefixes({
12185
+ ctx,
12186
+ importers,
12187
+ relativeAbsoluteSrcRoot,
12188
+ subPackageRoots
12189
+ });
12190
+ const keys = Object.keys(summary).filter(Boolean);
12191
+ if (!keys.length) {
12192
+ return void 0;
12193
+ }
12194
+ const sharedName = createSharedChunkNameFromKeys(keys);
12195
+ markForceDuplicateSharedChunk(sharedName);
12196
+ return sharedName;
12197
+ }
12198
+ function createSharedChunkNameFromKeys(keys) {
12199
+ const sanitize = (value) => value.replace(/[\\/]+/g, "_");
12200
+ const combination = keys.filter(Boolean).map(sanitize).sort().join("+");
12201
+ const combinationSegment = combination ? `${combination}/` : "";
12202
+ return `${SHARED_CHUNK_VIRTUAL_PREFIX}/${combinationSegment}common`;
12203
+ }
12204
+ function assertModuleScopedToRoot(options) {
12205
+ const {
12206
+ moduleInfo,
12207
+ moduleRoot,
12208
+ relativeAbsoluteSrcRoot,
12209
+ subPackageRoots,
12210
+ moduleId
12211
+ } = options;
12212
+ if (!moduleRoot || !moduleInfo?.importers?.length) {
12213
+ return;
12214
+ }
12215
+ for (const importer of moduleInfo.importers) {
12216
+ const importerRoot = resolveSubPackagePrefix(relativeAbsoluteSrcRoot(importer), subPackageRoots);
12217
+ if (importerRoot !== moduleRoot) {
12218
+ const moduleLabel = relativeAbsoluteSrcRoot(moduleId);
12219
+ const importerLabel = relativeAbsoluteSrcRoot(importer);
12220
+ throw new Error(
12221
+ `[subpackages] \u6A21\u5757 "${moduleLabel}" \u4F4D\u4E8E\u5206\u5305 "${moduleRoot}"\uFF0C\u4F46\u88AB "${importerLabel}" \u5F15\u7528\uFF0C\u8BF7\u5C06\u8BE5\u6A21\u5757\u79FB\u52A8\u5230\u4E3B\u5305\u6216\u516C\u5171\u76EE\u5F55\u4EE5\u8FDB\u884C\u8DE8\u5206\u5305\u5171\u4EAB\u3002`
12222
+ );
12223
+ }
12224
+ }
12225
+ }
12110
12226
  function applySharedChunkStrategy(bundle, options) {
12111
- if (options.strategy !== "duplicate") {
12227
+ if (options.strategy !== "duplicate" && forceDuplicateSharedChunks.size === 0) {
12112
12228
  return;
12113
12229
  }
12114
12230
  if (!this) {
@@ -12128,13 +12244,17 @@ function applySharedChunkStrategy(bundle, options) {
12128
12244
  if (importers.length === 0) {
12129
12245
  continue;
12130
12246
  }
12247
+ const sourceMapKeys = collectSourceMapKeys(fileName, chunk);
12248
+ const sourceMapAssetInfo = findSourceMapAsset(bundle, sourceMapKeys);
12249
+ const resolvedSourceMap = resolveSourceMapSource(originalMap, sourceMapAssetInfo?.asset.source);
12131
12250
  const importerMap = /* @__PURE__ */ new Map();
12132
12251
  let hasMainImporter = false;
12252
+ const shouldForceDuplicate = isForceDuplicateSharedChunk(originalSharedFileName);
12133
12253
  for (const importerFile of importers) {
12134
12254
  const root = resolveSubPackagePrefix(importerFile, subPackageRoots);
12135
12255
  if (!root) {
12136
12256
  hasMainImporter = true;
12137
- break;
12257
+ continue;
12138
12258
  }
12139
12259
  const duplicateBaseName = path10.basename(fileName);
12140
12260
  const intendedFileName = path10.join(root, SUB_PACKAGE_SHARED_DIR, duplicateBaseName);
@@ -12149,12 +12269,28 @@ function applySharedChunkStrategy(bundle, options) {
12149
12269
  });
12150
12270
  }
12151
12271
  }
12152
- if (hasMainImporter || importerMap.size === 0) {
12153
- consumeSharedChunkDiagnostics(originalSharedFileName);
12272
+ const importerToChunk = /* @__PURE__ */ new Map();
12273
+ const duplicates = [];
12274
+ const diagnostics = consumeSharedChunkDiagnostics(originalSharedFileName);
12275
+ const shouldRetainOriginalChunk = shouldForceDuplicate && hasMainImporter;
12276
+ if ((hasMainImporter || importerMap.size === 0) && (!shouldForceDuplicate || importerMap.size === 0)) {
12154
12277
  let finalFileName = chunk.fileName;
12155
12278
  if (fileName.startsWith(`${SHARED_CHUNK_VIRTUAL_PREFIX}/`)) {
12156
12279
  const newFileName = fileName.slice(SHARED_CHUNK_VIRTUAL_PREFIX.length + 1);
12157
12280
  chunk.fileName = newFileName;
12281
+ if (typeof chunk.sourcemapFileName === "string" && chunk.sourcemapFileName) {
12282
+ chunk.sourcemapFileName = `${newFileName}.map`;
12283
+ }
12284
+ const targetKey = `${newFileName}.map`;
12285
+ emitSourceMapAsset(this, targetKey, sourceMapAssetInfo, resolvedSourceMap);
12286
+ for (const mapKey of sourceMapKeys) {
12287
+ if (!mapKey || mapKey === targetKey) {
12288
+ continue;
12289
+ }
12290
+ if (bundle[mapKey]) {
12291
+ delete bundle[mapKey];
12292
+ }
12293
+ }
12158
12294
  finalFileName = newFileName;
12159
12295
  }
12160
12296
  options.onFallback?.({
@@ -12165,20 +12301,40 @@ function applySharedChunkStrategy(bundle, options) {
12165
12301
  });
12166
12302
  continue;
12167
12303
  }
12168
- const importerToChunk = /* @__PURE__ */ new Map();
12169
- const duplicates = [];
12170
- const diagnostics = consumeSharedChunkDiagnostics(originalSharedFileName);
12304
+ if (shouldRetainOriginalChunk && fileName.startsWith(`${SHARED_CHUNK_VIRTUAL_PREFIX}/`)) {
12305
+ const newFileName = fileName.slice(SHARED_CHUNK_VIRTUAL_PREFIX.length + 1);
12306
+ chunk.fileName = newFileName;
12307
+ if (typeof chunk.sourcemapFileName === "string" && chunk.sourcemapFileName) {
12308
+ chunk.sourcemapFileName = `${newFileName}.map`;
12309
+ }
12310
+ const targetKey = `${newFileName}.map`;
12311
+ emitSourceMapAsset(this, targetKey, sourceMapAssetInfo, resolvedSourceMap);
12312
+ for (const mapKey of sourceMapKeys) {
12313
+ if (!mapKey || mapKey === targetKey) {
12314
+ continue;
12315
+ }
12316
+ if (bundle[mapKey]) {
12317
+ delete bundle[mapKey];
12318
+ }
12319
+ }
12320
+ options.onFallback?.({
12321
+ sharedFileName: originalSharedFileName,
12322
+ finalFileName: newFileName,
12323
+ reason: "main-package",
12324
+ importers: [...importers]
12325
+ });
12326
+ }
12171
12327
  for (const { newFileName, importers: importerFiles } of importerMap.values()) {
12172
12328
  this.emitFile({
12173
12329
  type: "asset",
12174
12330
  fileName: newFileName,
12175
12331
  source: originalCode
12176
12332
  });
12177
- if (originalMap) {
12333
+ if (resolvedSourceMap) {
12178
12334
  this.emitFile({
12179
12335
  type: "asset",
12180
12336
  fileName: `${newFileName}.map`,
12181
- source: typeof originalMap === "string" ? originalMap : JSON.stringify(originalMap)
12337
+ source: cloneSourceLike(resolvedSourceMap)
12182
12338
  });
12183
12339
  }
12184
12340
  for (const importerFile of importerFiles) {
@@ -12190,10 +12346,13 @@ function applySharedChunkStrategy(bundle, options) {
12190
12346
  });
12191
12347
  }
12192
12348
  updateImporters(bundle, importerToChunk, fileName);
12193
- delete bundle[fileName];
12194
- const mapKey = `${fileName}.map`;
12195
- if (bundle[mapKey]) {
12196
- delete bundle[mapKey];
12349
+ if (!shouldRetainOriginalChunk) {
12350
+ delete bundle[fileName];
12351
+ for (const mapKey of sourceMapKeys) {
12352
+ if (mapKey && bundle[mapKey]) {
12353
+ delete bundle[mapKey];
12354
+ }
12355
+ }
12197
12356
  }
12198
12357
  const chunkBytes = typeof originalCode === "string" ? Buffer2.byteLength(originalCode, "utf8") : void 0;
12199
12358
  const redundantBytes = typeof chunkBytes === "number" ? chunkBytes * Math.max(duplicates.length - 1, 0) : void 0;
@@ -12202,7 +12361,8 @@ function applySharedChunkStrategy(bundle, options) {
12202
12361
  duplicates,
12203
12362
  ignoredMainImporters: diagnostics?.ignoredMainImporters,
12204
12363
  chunkBytes,
12205
- redundantBytes
12364
+ redundantBytes,
12365
+ retainedInMain: shouldRetainOriginalChunk
12206
12366
  });
12207
12367
  }
12208
12368
  }
@@ -12220,6 +12380,27 @@ function consumeSharedChunkDiagnostics(fileName) {
12220
12380
  }
12221
12381
  return void 0;
12222
12382
  }
12383
+ function emitSourceMapAsset(ctx, targetFileName, sourceMapAssetInfo, fallbackSource) {
12384
+ if (!targetFileName) {
12385
+ return;
12386
+ }
12387
+ if (sourceMapAssetInfo?.asset && isSourceLike(sourceMapAssetInfo.asset.source)) {
12388
+ ctx.emitFile({
12389
+ type: "asset",
12390
+ fileName: targetFileName,
12391
+ source: cloneSourceLike(sourceMapAssetInfo.asset.source),
12392
+ name: sourceMapAssetInfo.asset.name
12393
+ });
12394
+ return;
12395
+ }
12396
+ if (fallbackSource) {
12397
+ ctx.emitFile({
12398
+ type: "asset",
12399
+ fileName: targetFileName,
12400
+ source: cloneSourceLike(fallbackSource)
12401
+ });
12402
+ }
12403
+ }
12223
12404
  function isSharedVirtualChunk(fileName, output) {
12224
12405
  return output?.type === "chunk" && fileName.startsWith(`${SHARED_CHUNK_VIRTUAL_PREFIX}/`);
12225
12406
  }
@@ -12232,6 +12413,24 @@ function findChunkImporters(bundle, target) {
12232
12413
  const chunk = output;
12233
12414
  if (chunk.imports.includes(target) || chunk.dynamicImports.includes(target)) {
12234
12415
  importers.add(fileName);
12416
+ continue;
12417
+ }
12418
+ const metadata = chunk.viteMetadata;
12419
+ if (metadata) {
12420
+ const importedChunks = metadata.importedChunks;
12421
+ if (hasInCollection(importedChunks, target)) {
12422
+ importers.add(fileName);
12423
+ continue;
12424
+ }
12425
+ const importedScripts = metadata.importedScripts ?? metadata.importedScriptsByUrl;
12426
+ if (hasInCollection(importedScripts, target)) {
12427
+ importers.add(fileName);
12428
+ continue;
12429
+ }
12430
+ }
12431
+ const potentialImport = createRelativeImport(fileName, target);
12432
+ if (potentialImport && containsImportSpecifier(chunk.code ?? "", potentialImport)) {
12433
+ importers.add(fileName);
12235
12434
  }
12236
12435
  }
12237
12436
  return Array.from(importers);
@@ -12259,11 +12458,35 @@ function updateImporters(bundle, importerToChunk, originalFileName) {
12259
12458
  const importerChunk = importer;
12260
12459
  const originalImportPath = createRelativeImport(importerFile, originalFileName);
12261
12460
  const newImportPath = createRelativeImport(importerFile, newChunkFile);
12461
+ let codeUpdated = false;
12262
12462
  if (originalImportPath !== newImportPath) {
12263
- importerChunk.code = replaceAll(importerChunk.code, originalImportPath, newImportPath);
12463
+ const updated = replaceAll(importerChunk.code, originalImportPath, newImportPath);
12464
+ if (updated !== importerChunk.code) {
12465
+ importerChunk.code = updated;
12466
+ codeUpdated = true;
12467
+ }
12468
+ }
12469
+ importerChunk.imports = replaceInArray(importerChunk.imports, originalFileName, newChunkFile, codeUpdated);
12470
+ importerChunk.dynamicImports = replaceInArray(importerChunk.dynamicImports, originalFileName, newChunkFile, codeUpdated);
12471
+ const implicitlyLoadedBefore = importerChunk.implicitlyLoadedBefore;
12472
+ if (Array.isArray(implicitlyLoadedBefore)) {
12473
+ importerChunk.implicitlyLoadedBefore = replaceInArray(
12474
+ implicitlyLoadedBefore,
12475
+ originalFileName,
12476
+ newChunkFile,
12477
+ codeUpdated
12478
+ );
12264
12479
  }
12265
- importerChunk.imports = replaceInArray(importerChunk.imports, originalFileName, newChunkFile);
12266
- importerChunk.dynamicImports = replaceInArray(importerChunk.dynamicImports, originalFileName, newChunkFile);
12480
+ const referencedFiles = importerChunk.referencedFiles;
12481
+ if (Array.isArray(referencedFiles)) {
12482
+ importerChunk.referencedFiles = replaceInArray(
12483
+ referencedFiles,
12484
+ originalFileName,
12485
+ newChunkFile,
12486
+ codeUpdated
12487
+ );
12488
+ }
12489
+ updateViteMetadata(importerChunk, originalFileName, newChunkFile, codeUpdated);
12267
12490
  }
12268
12491
  }
12269
12492
  function replaceAll(source, searchValue, replaceValue) {
@@ -12282,10 +12505,74 @@ function replaceAll(source, searchValue, replaceValue) {
12282
12505
  }
12283
12506
  return source;
12284
12507
  }
12285
- function replaceInArray(list, searchValue, replaceValue) {
12286
- return list.map((value) => {
12287
- return value === searchValue ? replaceValue : value;
12288
- });
12508
+ function containsImportSpecifier(source, specifier) {
12509
+ if (!specifier) {
12510
+ return false;
12511
+ }
12512
+ if (source.includes(specifier)) {
12513
+ return true;
12514
+ }
12515
+ if (specifier.startsWith("./")) {
12516
+ const trimmed = specifier.slice(2);
12517
+ if (trimmed && source.includes(trimmed)) {
12518
+ return true;
12519
+ }
12520
+ }
12521
+ return false;
12522
+ }
12523
+ function hasInCollection(collection, value) {
12524
+ if (!collection || !value) {
12525
+ return false;
12526
+ }
12527
+ if (collection instanceof Set) {
12528
+ return collection.has(value);
12529
+ }
12530
+ if (Array.isArray(collection)) {
12531
+ return collection.includes(value);
12532
+ }
12533
+ if (collection instanceof Map) {
12534
+ return collection.has(value);
12535
+ }
12536
+ return false;
12537
+ }
12538
+ function replaceInArray(list, searchValue, replaceValue, shouldInsert) {
12539
+ const values = Array.isArray(list) ? [...list] : [];
12540
+ let replaced = false;
12541
+ for (let index = 0; index < values.length; index++) {
12542
+ const current2 = values[index];
12543
+ if (current2 === searchValue) {
12544
+ values[index] = replaceValue;
12545
+ replaced = true;
12546
+ }
12547
+ }
12548
+ if ((replaced || shouldInsert) && replaceValue && !values.includes(replaceValue)) {
12549
+ values.push(replaceValue);
12550
+ }
12551
+ return values;
12552
+ }
12553
+ function updateViteMetadata(importerChunk, originalFileName, newChunkFile, shouldInsert) {
12554
+ const metadata = importerChunk.viteMetadata;
12555
+ if (!metadata || typeof metadata !== "object") {
12556
+ return;
12557
+ }
12558
+ const candidateKeys = ["importedChunks", "importedScripts"];
12559
+ for (const key of candidateKeys) {
12560
+ const collection = metadata[key];
12561
+ if (collection instanceof Set) {
12562
+ const hadOriginal = collection.delete(originalFileName);
12563
+ if (hadOriginal || shouldInsert) {
12564
+ collection.add(newChunkFile);
12565
+ }
12566
+ } else if (Array.isArray(collection)) {
12567
+ metadata[key] = replaceInArray(collection, originalFileName, newChunkFile, shouldInsert);
12568
+ } else if (collection instanceof Map) {
12569
+ if (collection.has(originalFileName)) {
12570
+ const originalValue = collection.get(originalFileName);
12571
+ collection.delete(originalFileName);
12572
+ collection.set(newChunkFile, originalValue);
12573
+ }
12574
+ }
12575
+ }
12289
12576
  }
12290
12577
  function createRelativeImport(fromFile, toFile) {
12291
12578
  const relative3 = path10.relative(path10.dirname(fromFile), toFile);
@@ -12294,6 +12581,55 @@ function createRelativeImport(fromFile, toFile) {
12294
12581
  }
12295
12582
  return `./${relative3}`;
12296
12583
  }
12584
+ function collectSourceMapKeys(fileName, chunk) {
12585
+ const keys = /* @__PURE__ */ new Set();
12586
+ if (fileName) {
12587
+ keys.add(`${fileName}.map`);
12588
+ }
12589
+ if (typeof chunk.sourcemapFileName === "string" && chunk.sourcemapFileName) {
12590
+ keys.add(chunk.sourcemapFileName);
12591
+ }
12592
+ return keys;
12593
+ }
12594
+ function findSourceMapAsset(bundle, candidateKeys) {
12595
+ for (const key of candidateKeys) {
12596
+ if (!key) {
12597
+ continue;
12598
+ }
12599
+ const entry = bundle[key];
12600
+ if (entry?.type === "asset") {
12601
+ return {
12602
+ asset: entry,
12603
+ key
12604
+ };
12605
+ }
12606
+ }
12607
+ return void 0;
12608
+ }
12609
+ function resolveSourceMapSource(originalMap, assetSource) {
12610
+ if (originalMap) {
12611
+ if (typeof originalMap === "string") {
12612
+ return originalMap;
12613
+ }
12614
+ if (originalMap instanceof Uint8Array || Buffer2.isBuffer(originalMap)) {
12615
+ return Buffer2.from(originalMap);
12616
+ }
12617
+ return JSON.stringify(originalMap);
12618
+ }
12619
+ if (isSourceLike(assetSource)) {
12620
+ return cloneSourceLike(assetSource);
12621
+ }
12622
+ return void 0;
12623
+ }
12624
+ function isSourceLike(source) {
12625
+ return typeof source === "string" || source instanceof Uint8Array || Buffer2.isBuffer(source);
12626
+ }
12627
+ function cloneSourceLike(source) {
12628
+ if (typeof source === "string") {
12629
+ return source;
12630
+ }
12631
+ return Buffer2.from(source);
12632
+ }
12297
12633
 
12298
12634
  // src/runtime/advancedChunks.ts
12299
12635
  function testByReg2DExpList(reg2DExpList) {
@@ -12334,6 +12670,35 @@ function createAdvancedChunkNameResolver(options) {
12334
12670
  // src/runtime/sharedBuildConfig.ts
12335
12671
  var REG_NODE_MODULES_DIR = /[\\/]node_modules[\\/]/gi;
12336
12672
  var REG_COMMONJS_HELPERS = /commonjsHelpers\.js$/;
12673
+ function createForceDuplicateTester(patterns) {
12674
+ if (!patterns || patterns.length === 0) {
12675
+ return void 0;
12676
+ }
12677
+ const matchers = patterns.map((pattern) => {
12678
+ if (typeof pattern === "string") {
12679
+ const matcher = picomatch(pattern, { dot: true });
12680
+ return (value) => matcher(value);
12681
+ }
12682
+ if (isRegexp(pattern)) {
12683
+ return (value) => {
12684
+ pattern.lastIndex = 0;
12685
+ return pattern.test(value);
12686
+ };
12687
+ }
12688
+ return void 0;
12689
+ }).filter((matcher) => typeof matcher === "function");
12690
+ if (!matchers.length) {
12691
+ return void 0;
12692
+ }
12693
+ return (relativeId, absoluteId) => {
12694
+ for (const matcher of matchers) {
12695
+ if (matcher(relativeId) || matcher(absoluteId)) {
12696
+ return true;
12697
+ }
12698
+ }
12699
+ return false;
12700
+ };
12701
+ }
12337
12702
  function createSharedBuildConfig(configService, scanService) {
12338
12703
  const nodeModulesDeps = [REG_NODE_MODULES_DIR];
12339
12704
  const commonjsHelpersDeps = [REG_COMMONJS_HELPERS];
@@ -12364,35 +12729,6 @@ function createSharedBuildConfig(configService, scanService) {
12364
12729
  }
12365
12730
  };
12366
12731
  }
12367
- function createForceDuplicateTester(patterns) {
12368
- if (!patterns || patterns.length === 0) {
12369
- return void 0;
12370
- }
12371
- const matchers = patterns.map((pattern) => {
12372
- if (typeof pattern === "string") {
12373
- const matcher = picomatch(pattern, { dot: true });
12374
- return (value) => matcher(value);
12375
- }
12376
- if (isRegexp(pattern)) {
12377
- return (value) => {
12378
- pattern.lastIndex = 0;
12379
- return pattern.test(value);
12380
- };
12381
- }
12382
- return void 0;
12383
- }).filter((matcher) => typeof matcher === "function");
12384
- if (!matchers.length) {
12385
- return void 0;
12386
- }
12387
- return (relativeId, absoluteId) => {
12388
- for (const matcher of matchers) {
12389
- if (matcher(relativeId) || matcher(absoluteId)) {
12390
- return true;
12391
- }
12392
- }
12393
- return false;
12394
- };
12395
- }
12396
12732
 
12397
12733
  // src/runtime/buildPlugin.ts
12398
12734
  function createBuildService(ctx) {
@@ -23779,11 +24115,69 @@ function weappVite(ctx, subPackageMeta) {
23779
24115
  watchFilesSnapshot: []
23780
24116
  };
23781
24117
  return [
24118
+ createTakeQueryPlugin(state),
23782
24119
  createWxssResolverPlugin(state),
23783
24120
  createCoreLifecyclePlugin(state),
23784
24121
  createRequireAnalysisPlugin(state)
23785
24122
  ];
23786
24123
  }
24124
+ var TAKE_DIRECTIVE_PREFIX = "take:";
24125
+ function normalizeTakeRequest(source) {
24126
+ if (!source) {
24127
+ return null;
24128
+ }
24129
+ if (source.startsWith(TAKE_DIRECTIVE_PREFIX)) {
24130
+ const id = source.slice(TAKE_DIRECTIVE_PREFIX.length);
24131
+ if (!id) {
24132
+ return null;
24133
+ }
24134
+ return {
24135
+ id,
24136
+ legacy: false
24137
+ };
24138
+ }
24139
+ if (!source.includes("?")) {
24140
+ return null;
24141
+ }
24142
+ const [filename, rawQuery] = source.split("?", 2);
24143
+ if (!rawQuery) {
24144
+ return null;
24145
+ }
24146
+ const params = new URLSearchParams(rawQuery);
24147
+ if (!params.has("take")) {
24148
+ return null;
24149
+ }
24150
+ return {
24151
+ id: filename,
24152
+ legacy: true
24153
+ };
24154
+ }
24155
+ function createTakeQueryPlugin(_state) {
24156
+ return {
24157
+ name: "weapp-vite:pre:take-query",
24158
+ enforce: "pre",
24159
+ buildStart() {
24160
+ resetTakeImportRegistry();
24161
+ },
24162
+ async resolveId(source, importer) {
24163
+ const takeRequest = normalizeTakeRequest(source);
24164
+ if (!takeRequest) {
24165
+ return null;
24166
+ }
24167
+ const resolved = await this.resolve(takeRequest.id, importer, { skipSelf: true });
24168
+ if (resolved?.id) {
24169
+ markTakeModuleImporter(resolved.id, importer);
24170
+ if (takeRequest.legacy) {
24171
+ logger_default.warn(
24172
+ `"${source}" detected: the ?take query is deprecated, please migrate to the "take:" prefix (e.g. "take:${takeRequest.id}")`
24173
+ );
24174
+ }
24175
+ return resolved;
24176
+ }
24177
+ return null;
24178
+ }
24179
+ };
24180
+ }
23787
24181
  function createWxssResolverPlugin(_state) {
23788
24182
  return {
23789
24183
  name: "weapp-vite:pre:wxss",
@@ -23933,7 +24327,7 @@ function createCoreLifecyclePlugin(state) {
23933
24327
  const duplicateWarningBytes = Number(configService.weappViteConfig?.chunks?.duplicateWarningBytes ?? 0);
23934
24328
  const shouldWarnOnDuplicate = Number.isFinite(duplicateWarningBytes) && duplicateWarningBytes > 0;
23935
24329
  let redundantBytesTotal = 0;
23936
- const handleDuplicate = shouldLogChunks || shouldWarnOnDuplicate ? ({ duplicates, ignoredMainImporters, chunkBytes, redundantBytes }) => {
24330
+ const handleDuplicate = shouldLogChunks || shouldWarnOnDuplicate ? ({ duplicates, ignoredMainImporters, chunkBytes, redundantBytes, retainedInMain, sharedFileName }) => {
23937
24331
  if (shouldWarnOnDuplicate) {
23938
24332
  const duplicateCount = duplicates.length;
23939
24333
  const computedRedundant = typeof redundantBytes === "number" ? redundantBytes : typeof chunkBytes === "number" ? chunkBytes * Math.max(duplicateCount - 1, 0) : 0;
@@ -23952,6 +24346,9 @@ function createCoreLifecyclePlugin(state) {
23952
24346
  const subPackageList = Array.from(subPackageSet).join("\u3001") || "\u76F8\u5173\u5206\u5305";
23953
24347
  const ignoredHint = ignoredMainImporters?.length ? `\uFF0C\u5FFD\u7565\u4E3B\u5305\u5F15\u7528\uFF1A${ignoredMainImporters.join("\u3001")}` : "";
23954
24348
  logger_default.info(`[subpackages] \u5206\u5305 ${subPackageList} \u5171\u4EAB\u6A21\u5757\u5DF2\u590D\u5236\u5230\u5404\u81EA weapp-shared/common.js\uFF08${totalReferences} \u5904\u5F15\u7528${ignoredHint}\uFF09`);
24349
+ if (retainedInMain) {
24350
+ logger_default.warn(`[subpackages] \u6A21\u5757 ${sharedFileName} \u540C\u65F6\u88AB\u4E3B\u5305\u5F15\u7528\uFF0C\u56E0\u6B64\u4ECD\u4FDD\u7559\u5728\u4E3B\u5305 common.js\uFF0C\u5E76\u590D\u5236\u5230 ${subPackageList}\uFF0C\u8BF7\u786E\u8BA4\u662F\u5426\u9700\u8981\u5C06\u6E90\u4EE3\u7801\u79FB\u52A8\u5230\u4E3B\u5305\u6216\u516C\u5171\u76EE\u5F55\u3002`);
24351
+ }
23955
24352
  }
23956
24353
  } : void 0;
23957
24354
  applySharedChunkStrategy.call(this, bundle, {