weapp-vite 5.9.0 → 5.9.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.
@@ -3,7 +3,7 @@ import {
3
3
  __require,
4
4
  __toESM,
5
5
  init_esm_shims
6
- } from "./chunk-TZWATIK3.mjs";
6
+ } from "./chunk-YNQOGMVA.mjs";
7
7
 
8
8
  // ../../node_modules/.pnpm/semver@7.7.3/node_modules/semver/internal/debug.js
9
9
  var require_debug = __commonJS({
@@ -2678,7 +2678,7 @@ function resolveBaseDir(configService) {
2678
2678
  return configService.cwd;
2679
2679
  }
2680
2680
  function cloneAutoImportComponents(config) {
2681
- if (!config || config === false) {
2681
+ if (config === false || !config) {
2682
2682
  return void 0;
2683
2683
  }
2684
2684
  const cloned = {};
@@ -2813,11 +2813,11 @@ function getAutoImportConfig(configService) {
2813
2813
  if (subPackageConfigs) {
2814
2814
  for (const root of Object.keys(subPackageConfigs)) {
2815
2815
  const scopedRaw = subPackageConfigs[root]?.autoImportComponents;
2816
- if (!scopedRaw || scopedRaw === false) {
2816
+ if (scopedRaw === false || !scopedRaw) {
2817
2817
  continue;
2818
2818
  }
2819
2819
  const scoped = cloneAutoImportComponents(scopedRaw);
2820
- if (scoped && scoped !== false) {
2820
+ if (scoped) {
2821
2821
  merged = mergeAutoImportComponents(merged, scoped, false);
2822
2822
  }
2823
2823
  }
@@ -21732,342 +21732,6 @@ function autoRoutes(ctx) {
21732
21732
  init_esm_shims();
21733
21733
  import { isEmptyObject as isEmptyObject2, isObject as isObject6, removeExtensionDeep as removeExtensionDeep5 } from "@weapp-core/shared";
21734
21734
  import fs16 from "fs-extra";
21735
- import path26 from "pathe";
21736
-
21737
- // src/plugins/css/shared/preprocessor.ts
21738
- init_esm_shims();
21739
- import { createHash } from "crypto";
21740
- import fs13 from "fs-extra";
21741
- import path21 from "pathe";
21742
- import { preprocessCSS } from "vite";
21743
-
21744
- // src/postcss/index.ts
21745
- init_esm_shims();
21746
- import postcss from "postcss";
21747
-
21748
- // src/postcss/constants.ts
21749
- init_esm_shims();
21750
- var cssAtRulePrefix = "wv";
21751
- var IFDEF = "#ifdef";
21752
- var IFNDEF = "#ifndef";
21753
- var ENDIF = "#endif";
21754
-
21755
- // src/postcss/post.ts
21756
- init_esm_shims();
21757
- function normalizeTargets(values) {
21758
- return values.map((value) => value.trim().toLowerCase()).filter(Boolean);
21759
- }
21760
- function parseDirective(text) {
21761
- const normalized = text.replace(/\*/g, "").trim();
21762
- if (!normalized) {
21763
- return void 0;
21764
- }
21765
- const [keyword, ...rest] = normalized.split(/\s+/);
21766
- if (!keyword) {
21767
- return void 0;
21768
- }
21769
- if (keyword === IFDEF) {
21770
- return {
21771
- type: "ifdef",
21772
- targets: normalizeTargets(rest)
21773
- };
21774
- }
21775
- if (keyword === IFNDEF) {
21776
- return {
21777
- type: "ifndef",
21778
- targets: normalizeTargets(rest)
21779
- };
21780
- }
21781
- if (keyword === ENDIF) {
21782
- return {
21783
- type: "endif",
21784
- targets: []
21785
- };
21786
- }
21787
- return void 0;
21788
- }
21789
- function removeConditionalBlock(start) {
21790
- let depth = 1;
21791
- let node = start.next();
21792
- while (node && depth > 0) {
21793
- if (node.type === "comment") {
21794
- const directive = parseDirective(node.text);
21795
- if (directive) {
21796
- if (directive.type === "endif") {
21797
- depth -= 1;
21798
- const comment = node;
21799
- node = comment.next();
21800
- comment.remove();
21801
- continue;
21802
- } else {
21803
- depth += 1;
21804
- const comment = node;
21805
- node = comment.next();
21806
- comment.remove();
21807
- continue;
21808
- }
21809
- }
21810
- }
21811
- const next = node.next();
21812
- node.remove();
21813
- node = next;
21814
- }
21815
- }
21816
- var postCreator = (options = { platform: "weapp" }) => {
21817
- const atRulePrefixRegExp = new RegExp(`^${cssAtRulePrefix}-`);
21818
- const platform = options.platform.toLowerCase();
21819
- return {
21820
- postcssPlugin: "postcss-weapp-vite-plugin-post",
21821
- prepare() {
21822
- return {
21823
- AtRule(atRule) {
21824
- if (!atRulePrefixRegExp.test(atRule.name)) {
21825
- return;
21826
- }
21827
- if (atRule.name === `${cssAtRulePrefix}-keep-import`) {
21828
- atRule.name = "import";
21829
- return;
21830
- }
21831
- if (atRule.name === `${cssAtRulePrefix}-if`) {
21832
- const matches2 = [...atRule.params.matchAll(/\(([^)]+)\)/g)];
21833
- const shouldKeep = matches2.some((match2) => {
21834
- return match2[1].trim() === platform;
21835
- });
21836
- if (!shouldKeep) {
21837
- atRule.remove();
21838
- } else {
21839
- atRule.replaceWith(atRule.nodes);
21840
- }
21841
- }
21842
- },
21843
- Comment(comment) {
21844
- const directive = parseDirective(comment.text);
21845
- if (!directive) {
21846
- comment.remove();
21847
- return;
21848
- }
21849
- if (directive.type === "endif") {
21850
- comment.remove();
21851
- return;
21852
- }
21853
- const targets = directive.targets;
21854
- const hasPlatform = targets.includes(platform);
21855
- const shouldKeep = directive.type === "ifdef" ? hasPlatform : !hasPlatform;
21856
- if (!shouldKeep) {
21857
- removeConditionalBlock(comment);
21858
- comment.remove();
21859
- return;
21860
- }
21861
- comment.remove();
21862
- }
21863
- };
21864
- }
21865
- };
21866
- };
21867
- postCreator.postcss = true;
21868
-
21869
- // src/postcss/index.ts
21870
- var NEEDS_PROCESS_RE = new RegExp(`@${cssAtRulePrefix}-|${IFDEF}|${IFNDEF}`);
21871
- async function cssPostProcess(code, options) {
21872
- if (!NEEDS_PROCESS_RE.test(code)) {
21873
- return code;
21874
- }
21875
- const result = await postcss([postCreator(options)]).process(code, { from: void 0 });
21876
- return result.css;
21877
- }
21878
-
21879
- // src/plugins/css/shared/preprocessor.ts
21880
- var cssCodeCache = new LRUCache({
21881
- max: 512
21882
- });
21883
- var sharedStyleCache = /* @__PURE__ */ new Map();
21884
- async function processCssWithCache(code, configService) {
21885
- const cacheKey = createHash("sha1").update(configService.platform).update("\0").update(code).digest("base64url");
21886
- let processed = cssCodeCache.get(cacheKey);
21887
- if (!processed) {
21888
- processed = await cssPostProcess(code, { platform: configService.platform });
21889
- cssCodeCache.set(cacheKey, processed);
21890
- }
21891
- return processed;
21892
- }
21893
- function dedupeAndNormalizeDependencies(base, dependencies) {
21894
- const seen = /* @__PURE__ */ new Set();
21895
- const baseDir = path21.dirname(base);
21896
- for (const dep of dependencies) {
21897
- if (!dep) {
21898
- continue;
21899
- }
21900
- const normalized = path21.isAbsolute(dep) ? dep : path21.resolve(baseDir, dep);
21901
- seen.add(normalized);
21902
- }
21903
- return Array.from(seen);
21904
- }
21905
- async function renderSharedStyleEntry(entry, _configService, resolvedConfig) {
21906
- const absolutePath = entry.absolutePath;
21907
- const cacheKey = `${absolutePath}:${resolvedConfig ? "resolved" : "raw"}`;
21908
- let stats;
21909
- try {
21910
- stats = await fs13.stat(absolutePath);
21911
- } catch (error) {
21912
- const reason = error instanceof Error ? error.message : String(error);
21913
- throw new Error(`[subpackages] \u7F16\u8BD1\u5171\u4EAB\u6837\u5F0F \`${entry.source}\` \u5931\u8D25\uFF1A${reason}`);
21914
- }
21915
- const cached = sharedStyleCache.get(cacheKey);
21916
- if (cached && cached.mtimeMs === stats.mtimeMs && cached.size === stats.size) {
21917
- return {
21918
- css: cached.result.css,
21919
- dependencies: [...cached.result.dependencies]
21920
- };
21921
- }
21922
- try {
21923
- const css2 = await fs13.readFile(absolutePath, "utf8");
21924
- if (!resolvedConfig) {
21925
- const result2 = {
21926
- css: css2,
21927
- dependencies: []
21928
- };
21929
- sharedStyleCache.set(cacheKey, {
21930
- mtimeMs: stats.mtimeMs,
21931
- size: stats.size,
21932
- result: result2
21933
- });
21934
- return {
21935
- css: result2.css,
21936
- dependencies: [...result2.dependencies]
21937
- };
21938
- }
21939
- const processed = await preprocessCSS(css2, absolutePath, resolvedConfig);
21940
- const dependencies = processed?.deps ? dedupeAndNormalizeDependencies(absolutePath, processed.deps) : [];
21941
- const result = {
21942
- css: processed.code,
21943
- dependencies
21944
- };
21945
- sharedStyleCache.set(cacheKey, {
21946
- mtimeMs: stats.mtimeMs,
21947
- size: stats.size,
21948
- result
21949
- });
21950
- return {
21951
- css: result.css,
21952
- dependencies: [...result.dependencies]
21953
- };
21954
- } catch (error) {
21955
- const reason = error instanceof Error ? error.message : String(error);
21956
- throw new Error(`[subpackages] \u7F16\u8BD1\u5171\u4EAB\u6837\u5F0F \`${entry.source}\` \u5931\u8D25\uFF1A${reason}`);
21957
- }
21958
- }
21959
- function invalidateSharedStyleCache() {
21960
- sharedStyleCache.clear();
21961
- cssCodeCache.clear();
21962
- try {
21963
- const candidates = [
21964
- // Tailwind v3 path
21965
- "tailwindcss/lib/lib/sharedState.js",
21966
- // Tailwind v4 moved files to top-level dist
21967
- "tailwindcss/dist/sharedState.js",
21968
- // Source path fallback (when running directly from repo)
21969
- "tailwindcss/src/lib/sharedState.js",
21970
- "tailwindcss/sharedState.js"
21971
- ];
21972
- for (const request of candidates) {
21973
- try {
21974
- const sharedState = __require(request);
21975
- if (sharedState) {
21976
- sharedState.contextMap?.clear?.();
21977
- sharedState.configContextMap?.clear?.();
21978
- sharedState.contextSourcesMap?.clear?.();
21979
- sharedState.sourceHashMap?.clear?.();
21980
- break;
21981
- }
21982
- } catch {
21983
- }
21984
- }
21985
- } catch {
21986
- }
21987
- }
21988
-
21989
- // src/plugins/hooks/useLoadEntry/index.ts
21990
- init_esm_shims();
21991
-
21992
- // src/plugins/hooks/useLoadEntry/autoImport.ts
21993
- init_esm_shims();
21994
- import { get as get2, isObject as isObject2, set as set2 } from "@weapp-core/shared";
21995
- function createAutoImportAugmenter(autoImportService, wxmlService) {
21996
- return function applyAutoImports(baseName, json) {
21997
- const hit = wxmlService.wxmlComponentsMap.get(baseName);
21998
- if (!hit) {
21999
- return;
22000
- }
22001
- const depComponentNames = Object.keys(hit);
22002
- for (const depComponentName of depComponentNames) {
22003
- const match2 = autoImportService.resolve(depComponentName, baseName);
22004
- if (!match2) {
22005
- continue;
22006
- }
22007
- const { value } = match2;
22008
- const usingComponents = get2(json, "usingComponents");
22009
- if (isObject2(usingComponents) && Reflect.has(usingComponents, value.name)) {
22010
- continue;
22011
- }
22012
- set2(json, `usingComponents.${value.name}`, value.from);
22013
- }
22014
- };
22015
- }
22016
-
22017
- // src/plugins/hooks/useLoadEntry/chunkEmitter.ts
22018
- init_esm_shims();
22019
- import { performance as performance2 } from "perf_hooks";
22020
- function createChunkEmitter(configService, loadedEntrySet, debug4) {
22021
- return function emitEntriesChunks(resolvedIds) {
22022
- return resolvedIds.map(async (resolvedId) => {
22023
- if (!resolvedId) {
22024
- return;
22025
- }
22026
- const start = performance2.now();
22027
- loadedEntrySet.add(resolvedId.id);
22028
- await this.load(resolvedId);
22029
- const fileName = configService.relativeAbsoluteSrcRoot(
22030
- changeFileExtension(resolvedId.id, ".js")
22031
- );
22032
- this.emitFile({
22033
- type: "chunk",
22034
- id: resolvedId.id,
22035
- fileName,
22036
- // @ts-ignore
22037
- preserveSignature: "exports-only"
22038
- });
22039
- debug4?.(`load ${fileName} \u8017\u65F6 ${(performance2.now() - start).toFixed(2)}ms`);
22040
- });
22041
- };
22042
- }
22043
-
22044
- // src/plugins/hooks/useLoadEntry/jsonEmit.ts
22045
- init_esm_shims();
22046
- function createJsonEmitManager(configService) {
22047
- const map = /* @__PURE__ */ new Map();
22048
- function register(entry) {
22049
- if (!entry.jsonPath) {
22050
- return;
22051
- }
22052
- const fileName = configService.relativeAbsoluteSrcRoot(
22053
- jsonFileRemoveJsExtension(entry.jsonPath)
22054
- );
22055
- map.set(fileName, {
22056
- fileName,
22057
- entry
22058
- });
22059
- }
22060
- return {
22061
- map,
22062
- register
22063
- };
22064
- }
22065
-
22066
- // src/plugins/hooks/useLoadEntry/loadEntry.ts
22067
- init_esm_shims();
22068
- import { performance as performance3 } from "perf_hooks";
22069
- import { removeExtensionDeep as removeExtensionDeep3 } from "@weapp-core/shared";
22070
- import fs14 from "fs-extra";
22071
21735
 
22072
21736
  // ../../node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs
22073
21737
  init_esm_shims();
@@ -22366,7 +22030,7 @@ function getRelativePath(from, to) {
22366
22030
  return fromParts.concat(toParts).join("/");
22367
22031
  }
22368
22032
  var toString2 = Object.prototype.toString;
22369
- function isObject3(thing) {
22033
+ function isObject2(thing) {
22370
22034
  return toString2.call(thing) === "[object Object]";
22371
22035
  }
22372
22036
  function getLocator(source) {
@@ -22624,7 +22288,7 @@ var MagicString = class _MagicString {
22624
22288
  }
22625
22289
  indent(indentStr, options) {
22626
22290
  const pattern = /^[^\r\n]/gm;
22627
- if (isObject3(indentStr)) {
22291
+ if (isObject2(indentStr)) {
22628
22292
  options = indentStr;
22629
22293
  indentStr = void 0;
22630
22294
  }
@@ -23080,73 +22744,409 @@ var MagicString = class _MagicString {
23080
22744
  }
23081
22745
  return matches2;
23082
22746
  }
23083
- if (searchValue.global) {
23084
- const matches2 = matchAll(searchValue, this.original);
23085
- matches2.forEach((match2) => {
23086
- if (match2.index != null) {
23087
- const replacement2 = getReplacement(match2, this.original);
23088
- if (replacement2 !== match2[0]) {
23089
- this.overwrite(match2.index, match2.index + match2[0].length, replacement2);
23090
- }
23091
- }
22747
+ if (searchValue.global) {
22748
+ const matches2 = matchAll(searchValue, this.original);
22749
+ matches2.forEach((match2) => {
22750
+ if (match2.index != null) {
22751
+ const replacement2 = getReplacement(match2, this.original);
22752
+ if (replacement2 !== match2[0]) {
22753
+ this.overwrite(match2.index, match2.index + match2[0].length, replacement2);
22754
+ }
22755
+ }
22756
+ });
22757
+ } else {
22758
+ const match2 = this.original.match(searchValue);
22759
+ if (match2 && match2.index != null) {
22760
+ const replacement2 = getReplacement(match2, this.original);
22761
+ if (replacement2 !== match2[0]) {
22762
+ this.overwrite(match2.index, match2.index + match2[0].length, replacement2);
22763
+ }
22764
+ }
22765
+ }
22766
+ return this;
22767
+ }
22768
+ _replaceString(string, replacement) {
22769
+ const { original } = this;
22770
+ const index = original.indexOf(string);
22771
+ if (index !== -1) {
22772
+ if (typeof replacement === "function") {
22773
+ replacement = replacement(string, index, original);
22774
+ }
22775
+ if (string !== replacement) {
22776
+ this.overwrite(index, index + string.length, replacement);
22777
+ }
22778
+ }
22779
+ return this;
22780
+ }
22781
+ replace(searchValue, replacement) {
22782
+ if (typeof searchValue === "string") {
22783
+ return this._replaceString(searchValue, replacement);
22784
+ }
22785
+ return this._replaceRegexp(searchValue, replacement);
22786
+ }
22787
+ _replaceAllString(string, replacement) {
22788
+ const { original } = this;
22789
+ const stringLength = string.length;
22790
+ for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
22791
+ const previous = original.slice(index, index + stringLength);
22792
+ let _replacement = replacement;
22793
+ if (typeof replacement === "function") {
22794
+ _replacement = replacement(previous, index, original);
22795
+ }
22796
+ if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
22797
+ }
22798
+ return this;
22799
+ }
22800
+ replaceAll(searchValue, replacement) {
22801
+ if (typeof searchValue === "string") {
22802
+ return this._replaceAllString(searchValue, replacement);
22803
+ }
22804
+ if (!searchValue.global) {
22805
+ throw new TypeError(
22806
+ "MagicString.prototype.replaceAll called with a non-global RegExp argument"
22807
+ );
22808
+ }
22809
+ return this._replaceRegexp(searchValue, replacement);
22810
+ }
22811
+ };
22812
+
22813
+ // src/plugins/core.ts
22814
+ import path26 from "pathe";
22815
+
22816
+ // src/plugins/css/shared/preprocessor.ts
22817
+ init_esm_shims();
22818
+ import { createHash } from "crypto";
22819
+ import fs13 from "fs-extra";
22820
+ import path21 from "pathe";
22821
+ import { preprocessCSS } from "vite";
22822
+
22823
+ // src/postcss/index.ts
22824
+ init_esm_shims();
22825
+ import postcss from "postcss";
22826
+
22827
+ // src/postcss/constants.ts
22828
+ init_esm_shims();
22829
+ var cssAtRulePrefix = "wv";
22830
+ var IFDEF = "#ifdef";
22831
+ var IFNDEF = "#ifndef";
22832
+ var ENDIF = "#endif";
22833
+
22834
+ // src/postcss/post.ts
22835
+ init_esm_shims();
22836
+ function normalizeTargets(values) {
22837
+ return values.map((value) => value.trim().toLowerCase()).filter(Boolean);
22838
+ }
22839
+ function parseDirective(text) {
22840
+ const normalized = text.replace(/\*/g, "").trim();
22841
+ if (!normalized) {
22842
+ return void 0;
22843
+ }
22844
+ const [keyword, ...rest] = normalized.split(/\s+/);
22845
+ if (!keyword) {
22846
+ return void 0;
22847
+ }
22848
+ if (keyword === IFDEF) {
22849
+ return {
22850
+ type: "ifdef",
22851
+ targets: normalizeTargets(rest)
22852
+ };
22853
+ }
22854
+ if (keyword === IFNDEF) {
22855
+ return {
22856
+ type: "ifndef",
22857
+ targets: normalizeTargets(rest)
22858
+ };
22859
+ }
22860
+ if (keyword === ENDIF) {
22861
+ return {
22862
+ type: "endif",
22863
+ targets: []
22864
+ };
22865
+ }
22866
+ return void 0;
22867
+ }
22868
+ function removeConditionalBlock(start) {
22869
+ let depth = 1;
22870
+ let node = start.next();
22871
+ while (node && depth > 0) {
22872
+ if (node.type === "comment") {
22873
+ const directive = parseDirective(node.text);
22874
+ if (directive) {
22875
+ if (directive.type === "endif") {
22876
+ depth -= 1;
22877
+ const comment = node;
22878
+ node = comment.next();
22879
+ comment.remove();
22880
+ continue;
22881
+ } else {
22882
+ depth += 1;
22883
+ const comment = node;
22884
+ node = comment.next();
22885
+ comment.remove();
22886
+ continue;
22887
+ }
22888
+ }
22889
+ }
22890
+ const next = node.next();
22891
+ node.remove();
22892
+ node = next;
22893
+ }
22894
+ }
22895
+ var postCreator = (options = { platform: "weapp" }) => {
22896
+ const atRulePrefixRegExp = new RegExp(`^${cssAtRulePrefix}-`);
22897
+ const platform = options.platform.toLowerCase();
22898
+ return {
22899
+ postcssPlugin: "postcss-weapp-vite-plugin-post",
22900
+ prepare() {
22901
+ return {
22902
+ AtRule(atRule) {
22903
+ if (!atRulePrefixRegExp.test(atRule.name)) {
22904
+ return;
22905
+ }
22906
+ if (atRule.name === `${cssAtRulePrefix}-keep-import`) {
22907
+ atRule.name = "import";
22908
+ return;
22909
+ }
22910
+ if (atRule.name === `${cssAtRulePrefix}-if`) {
22911
+ const matches2 = [...atRule.params.matchAll(/\(([^)]+)\)/g)];
22912
+ const shouldKeep = matches2.some((match2) => {
22913
+ return match2[1].trim() === platform;
22914
+ });
22915
+ if (!shouldKeep) {
22916
+ atRule.remove();
22917
+ } else {
22918
+ atRule.replaceWith(atRule.nodes);
22919
+ }
22920
+ }
22921
+ },
22922
+ Comment(comment) {
22923
+ const directive = parseDirective(comment.text);
22924
+ if (!directive) {
22925
+ comment.remove();
22926
+ return;
22927
+ }
22928
+ if (directive.type === "endif") {
22929
+ comment.remove();
22930
+ return;
22931
+ }
22932
+ const targets = directive.targets;
22933
+ const hasPlatform = targets.includes(platform);
22934
+ const shouldKeep = directive.type === "ifdef" ? hasPlatform : !hasPlatform;
22935
+ if (!shouldKeep) {
22936
+ removeConditionalBlock(comment);
22937
+ comment.remove();
22938
+ return;
22939
+ }
22940
+ comment.remove();
22941
+ }
22942
+ };
22943
+ }
22944
+ };
22945
+ };
22946
+ postCreator.postcss = true;
22947
+
22948
+ // src/postcss/index.ts
22949
+ var NEEDS_PROCESS_RE = new RegExp(`@${cssAtRulePrefix}-|${IFDEF}|${IFNDEF}`);
22950
+ async function cssPostProcess(code, options) {
22951
+ if (!NEEDS_PROCESS_RE.test(code)) {
22952
+ return code;
22953
+ }
22954
+ const result = await postcss([postCreator(options)]).process(code, { from: void 0 });
22955
+ return result.css;
22956
+ }
22957
+
22958
+ // src/plugins/css/shared/preprocessor.ts
22959
+ var cssCodeCache = new LRUCache({
22960
+ max: 512
22961
+ });
22962
+ var sharedStyleCache = /* @__PURE__ */ new Map();
22963
+ async function processCssWithCache(code, configService) {
22964
+ const cacheKey = createHash("sha1").update(configService.platform).update("\0").update(code).digest("base64url");
22965
+ let processed = cssCodeCache.get(cacheKey);
22966
+ if (!processed) {
22967
+ processed = await cssPostProcess(code, { platform: configService.platform });
22968
+ cssCodeCache.set(cacheKey, processed);
22969
+ }
22970
+ return processed;
22971
+ }
22972
+ function dedupeAndNormalizeDependencies(base, dependencies) {
22973
+ const seen = /* @__PURE__ */ new Set();
22974
+ const baseDir = path21.dirname(base);
22975
+ for (const dep of dependencies) {
22976
+ if (!dep) {
22977
+ continue;
22978
+ }
22979
+ const normalized = path21.isAbsolute(dep) ? dep : path21.resolve(baseDir, dep);
22980
+ seen.add(normalized);
22981
+ }
22982
+ return Array.from(seen);
22983
+ }
22984
+ async function renderSharedStyleEntry(entry, _configService, resolvedConfig) {
22985
+ const absolutePath = entry.absolutePath;
22986
+ const cacheKey = `${absolutePath}:${resolvedConfig ? "resolved" : "raw"}`;
22987
+ let stats;
22988
+ try {
22989
+ stats = await fs13.stat(absolutePath);
22990
+ } catch (error) {
22991
+ const reason = error instanceof Error ? error.message : String(error);
22992
+ throw new Error(`[subpackages] \u7F16\u8BD1\u5171\u4EAB\u6837\u5F0F \`${entry.source}\` \u5931\u8D25\uFF1A${reason}`);
22993
+ }
22994
+ const cached = sharedStyleCache.get(cacheKey);
22995
+ if (cached && cached.mtimeMs === stats.mtimeMs && cached.size === stats.size) {
22996
+ return {
22997
+ css: cached.result.css,
22998
+ dependencies: [...cached.result.dependencies]
22999
+ };
23000
+ }
23001
+ try {
23002
+ const css2 = await fs13.readFile(absolutePath, "utf8");
23003
+ if (!resolvedConfig) {
23004
+ const result2 = {
23005
+ css: css2,
23006
+ dependencies: []
23007
+ };
23008
+ sharedStyleCache.set(cacheKey, {
23009
+ mtimeMs: stats.mtimeMs,
23010
+ size: stats.size,
23011
+ result: result2
23092
23012
  });
23093
- } else {
23094
- const match2 = this.original.match(searchValue);
23095
- if (match2 && match2.index != null) {
23096
- const replacement2 = getReplacement(match2, this.original);
23097
- if (replacement2 !== match2[0]) {
23098
- this.overwrite(match2.index, match2.index + match2[0].length, replacement2);
23099
- }
23100
- }
23013
+ return {
23014
+ css: result2.css,
23015
+ dependencies: [...result2.dependencies]
23016
+ };
23101
23017
  }
23102
- return this;
23018
+ const processed = await preprocessCSS(css2, absolutePath, resolvedConfig);
23019
+ const dependencies = processed?.deps ? dedupeAndNormalizeDependencies(absolutePath, processed.deps) : [];
23020
+ const result = {
23021
+ css: processed.code,
23022
+ dependencies
23023
+ };
23024
+ sharedStyleCache.set(cacheKey, {
23025
+ mtimeMs: stats.mtimeMs,
23026
+ size: stats.size,
23027
+ result
23028
+ });
23029
+ return {
23030
+ css: result.css,
23031
+ dependencies: [...result.dependencies]
23032
+ };
23033
+ } catch (error) {
23034
+ const reason = error instanceof Error ? error.message : String(error);
23035
+ throw new Error(`[subpackages] \u7F16\u8BD1\u5171\u4EAB\u6837\u5F0F \`${entry.source}\` \u5931\u8D25\uFF1A${reason}`);
23103
23036
  }
23104
- _replaceString(string, replacement) {
23105
- const { original } = this;
23106
- const index = original.indexOf(string);
23107
- if (index !== -1) {
23108
- if (typeof replacement === "function") {
23109
- replacement = replacement(string, index, original);
23110
- }
23111
- if (string !== replacement) {
23112
- this.overwrite(index, index + string.length, replacement);
23037
+ }
23038
+ function invalidateSharedStyleCache() {
23039
+ sharedStyleCache.clear();
23040
+ cssCodeCache.clear();
23041
+ try {
23042
+ const candidates = [
23043
+ // Tailwind v3 path
23044
+ "tailwindcss/lib/lib/sharedState.js",
23045
+ // Tailwind v4 moved files to top-level dist
23046
+ "tailwindcss/dist/sharedState.js",
23047
+ // Source path fallback (when running directly from repo)
23048
+ "tailwindcss/src/lib/sharedState.js",
23049
+ "tailwindcss/sharedState.js"
23050
+ ];
23051
+ for (const request of candidates) {
23052
+ try {
23053
+ const sharedState = __require(request);
23054
+ if (sharedState) {
23055
+ sharedState.contextMap?.clear?.();
23056
+ sharedState.configContextMap?.clear?.();
23057
+ sharedState.contextSourcesMap?.clear?.();
23058
+ sharedState.sourceHashMap?.clear?.();
23059
+ break;
23060
+ }
23061
+ } catch {
23113
23062
  }
23114
23063
  }
23115
- return this;
23064
+ } catch {
23116
23065
  }
23117
- replace(searchValue, replacement) {
23118
- if (typeof searchValue === "string") {
23119
- return this._replaceString(searchValue, replacement);
23066
+ }
23067
+
23068
+ // src/plugins/hooks/useLoadEntry/index.ts
23069
+ init_esm_shims();
23070
+
23071
+ // src/plugins/hooks/useLoadEntry/autoImport.ts
23072
+ init_esm_shims();
23073
+ import { get as get2, isObject as isObject3, set as set2 } from "@weapp-core/shared";
23074
+ function createAutoImportAugmenter(autoImportService, wxmlService) {
23075
+ return function applyAutoImports(baseName, json) {
23076
+ const hit = wxmlService.wxmlComponentsMap.get(baseName);
23077
+ if (!hit) {
23078
+ return;
23120
23079
  }
23121
- return this._replaceRegexp(searchValue, replacement);
23122
- }
23123
- _replaceAllString(string, replacement) {
23124
- const { original } = this;
23125
- const stringLength = string.length;
23126
- for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
23127
- const previous = original.slice(index, index + stringLength);
23128
- let _replacement = replacement;
23129
- if (typeof replacement === "function") {
23130
- _replacement = replacement(previous, index, original);
23080
+ const depComponentNames = Object.keys(hit);
23081
+ for (const depComponentName of depComponentNames) {
23082
+ const match2 = autoImportService.resolve(depComponentName, baseName);
23083
+ if (!match2) {
23084
+ continue;
23131
23085
  }
23132
- if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
23133
- }
23134
- return this;
23135
- }
23136
- replaceAll(searchValue, replacement) {
23137
- if (typeof searchValue === "string") {
23138
- return this._replaceAllString(searchValue, replacement);
23086
+ const { value } = match2;
23087
+ const usingComponents = get2(json, "usingComponents");
23088
+ if (isObject3(usingComponents) && Reflect.has(usingComponents, value.name)) {
23089
+ continue;
23090
+ }
23091
+ set2(json, `usingComponents.${value.name}`, value.from);
23139
23092
  }
23140
- if (!searchValue.global) {
23141
- throw new TypeError(
23142
- "MagicString.prototype.replaceAll called with a non-global RegExp argument"
23093
+ };
23094
+ }
23095
+
23096
+ // src/plugins/hooks/useLoadEntry/chunkEmitter.ts
23097
+ init_esm_shims();
23098
+ import { performance as performance2 } from "perf_hooks";
23099
+ function createChunkEmitter(configService, loadedEntrySet, debug4) {
23100
+ return function emitEntriesChunks(resolvedIds) {
23101
+ return resolvedIds.map(async (resolvedId) => {
23102
+ if (!resolvedId) {
23103
+ return;
23104
+ }
23105
+ const start = performance2.now();
23106
+ loadedEntrySet.add(resolvedId.id);
23107
+ await this.load(resolvedId);
23108
+ const fileName = configService.relativeAbsoluteSrcRoot(
23109
+ changeFileExtension(resolvedId.id, ".js")
23143
23110
  );
23111
+ this.emitFile({
23112
+ type: "chunk",
23113
+ id: resolvedId.id,
23114
+ fileName,
23115
+ // @ts-ignore
23116
+ preserveSignature: "exports-only"
23117
+ });
23118
+ debug4?.(`load ${fileName} \u8017\u65F6 ${(performance2.now() - start).toFixed(2)}ms`);
23119
+ });
23120
+ };
23121
+ }
23122
+
23123
+ // src/plugins/hooks/useLoadEntry/jsonEmit.ts
23124
+ init_esm_shims();
23125
+ function createJsonEmitManager(configService) {
23126
+ const map = /* @__PURE__ */ new Map();
23127
+ function register(entry) {
23128
+ if (!entry.jsonPath) {
23129
+ return;
23144
23130
  }
23145
- return this._replaceRegexp(searchValue, replacement);
23131
+ const fileName = configService.relativeAbsoluteSrcRoot(
23132
+ jsonFileRemoveJsExtension(entry.jsonPath)
23133
+ );
23134
+ map.set(fileName, {
23135
+ fileName,
23136
+ entry
23137
+ });
23146
23138
  }
23147
- };
23139
+ return {
23140
+ map,
23141
+ register
23142
+ };
23143
+ }
23148
23144
 
23149
23145
  // src/plugins/hooks/useLoadEntry/loadEntry.ts
23146
+ init_esm_shims();
23147
+ import { performance as performance3 } from "perf_hooks";
23148
+ import { removeExtensionDeep as removeExtensionDeep3 } from "@weapp-core/shared";
23149
+ import fs14 from "fs-extra";
23150
23150
  import path23 from "pathe";
23151
23151
 
23152
23152
  // src/plugins/utils/analyze.ts
@@ -24246,12 +24246,13 @@ function emitJsonAsset(runtime, fileName, source) {
24246
24246
  // src/plugins/core.ts
24247
24247
  var debug2 = createDebugger("weapp-vite:core");
24248
24248
  function weappVite(ctx, subPackageMeta) {
24249
- const { loadEntry, loadedEntrySet, jsonEmitFilesMap } = useLoadEntry(ctx);
24249
+ const { loadEntry, loadedEntrySet, jsonEmitFilesMap, entriesMap } = useLoadEntry(ctx);
24250
24250
  const state = {
24251
24251
  ctx,
24252
24252
  subPackageMeta,
24253
24253
  loadEntry,
24254
24254
  loadedEntrySet,
24255
+ entriesMap,
24255
24256
  jsonEmitFilesMap,
24256
24257
  requireAsyncEmittedChunks: /* @__PURE__ */ new Set(),
24257
24258
  pendingIndependentBuilds: [],
@@ -24528,6 +24529,10 @@ function createCoreLifecyclePlugin(state) {
24528
24529
  logger_default.warn(`[subpackages] \u5206\u5305\u590D\u5236\u5171\u4EAB\u6A21\u5757\u4EA7\u751F\u5197\u4F59\u4F53\u79EF ${formatBytes(redundantBytesTotal)}\uFF0C\u5DF2\u8D85\u8FC7\u9608\u503C ${formatBytes(duplicateWarningBytes)}\uFF0C\u5EFA\u8BAE\u8C03\u6574\u5206\u5305\u5212\u5206\u6216\u8FD0\u884C weapp-vite analyze \u5B9A\u4F4D\u95EE\u9898\u3002`);
24529
24530
  }
24530
24531
  }
24532
+ removeImplicitPagePreloads(bundle, {
24533
+ configService,
24534
+ entriesMap: state.entriesMap
24535
+ });
24531
24536
  if (configService.weappViteConfig?.debug?.watchFiles) {
24532
24537
  const watcherService = ctx.watcherService;
24533
24538
  const watcherRoot = subPackageMeta?.subPackage.root ?? "/";
@@ -24637,6 +24642,99 @@ function emitJsonAssets(state) {
24637
24642
  }
24638
24643
  }
24639
24644
  }
24645
+ function removeImplicitPagePreloads(bundle, options) {
24646
+ const { configService, entriesMap } = options;
24647
+ if (!entriesMap || entriesMap.size === 0) {
24648
+ return;
24649
+ }
24650
+ const pageChunkFileNames = /* @__PURE__ */ new Set();
24651
+ for (const entry of entriesMap.values()) {
24652
+ if (!entry || entry.type !== "page") {
24653
+ continue;
24654
+ }
24655
+ const relative3 = configService.relativeAbsoluteSrcRoot(entry.path);
24656
+ const outputFile = changeFileExtension(relative3, ".js");
24657
+ pageChunkFileNames.add(outputFile);
24658
+ }
24659
+ if (pageChunkFileNames.size === 0) {
24660
+ return;
24661
+ }
24662
+ for (const chunk of Object.values(bundle)) {
24663
+ if (!chunk || chunk.type !== "chunk" || typeof chunk.code !== "string") {
24664
+ continue;
24665
+ }
24666
+ const targetSet = /* @__PURE__ */ new Set();
24667
+ if (Array.isArray(chunk.imports)) {
24668
+ for (const imported of chunk.imports) {
24669
+ if (pageChunkFileNames.has(imported)) {
24670
+ targetSet.add(imported);
24671
+ }
24672
+ }
24673
+ }
24674
+ const rawImplicit = chunk.implicitlyLoadedBefore;
24675
+ const implicitlyLoaded = Array.isArray(rawImplicit) ? rawImplicit : void 0;
24676
+ if (implicitlyLoaded) {
24677
+ for (const eager of implicitlyLoaded) {
24678
+ if (pageChunkFileNames.has(eager)) {
24679
+ targetSet.add(eager);
24680
+ }
24681
+ }
24682
+ }
24683
+ if (targetSet.size === 0) {
24684
+ continue;
24685
+ }
24686
+ const ranges = findImplicitRequireRemovalRanges(chunk, targetSet);
24687
+ if (!ranges.length) {
24688
+ continue;
24689
+ }
24690
+ const ms = new MagicString(chunk.code);
24691
+ for (const { start, end } of ranges) {
24692
+ ms.remove(start, end);
24693
+ }
24694
+ chunk.code = ms.toString();
24695
+ if (Array.isArray(chunk.imports) && chunk.imports.length) {
24696
+ chunk.imports = chunk.imports.filter((name) => !targetSet.has(name));
24697
+ }
24698
+ if (implicitlyLoaded && implicitlyLoaded.length) {
24699
+ chunk.implicitlyLoadedBefore = implicitlyLoaded.filter((name) => !targetSet.has(name));
24700
+ }
24701
+ }
24702
+ }
24703
+ function findImplicitRequireRemovalRanges(chunk, targetFileNames) {
24704
+ const code = chunk.code;
24705
+ const ranges = [];
24706
+ const requireRE = /\b(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*=\s*require\((`[^`]+`|'[^']+'|"[^"]+")\);?/g;
24707
+ for (const match2 of code.matchAll(requireRE)) {
24708
+ const specifier = stripQuotes(match2[1]);
24709
+ const resolved = resolveRelativeImport(chunk.fileName, specifier);
24710
+ if (!resolved || !targetFileNames.has(resolved)) {
24711
+ continue;
24712
+ }
24713
+ const start = match2.index;
24714
+ const end = start + match2[0].length;
24715
+ ranges.push({ start, end });
24716
+ }
24717
+ return ranges;
24718
+ }
24719
+ function stripQuotes(value) {
24720
+ if (!value) {
24721
+ return value;
24722
+ }
24723
+ const first = value[0];
24724
+ const last = value[value.length - 1];
24725
+ if (first === last && (first === '"' || first === "'") || first === "`" && last === "`") {
24726
+ return value.slice(1, -1);
24727
+ }
24728
+ return value;
24729
+ }
24730
+ function resolveRelativeImport(fromFile, specifier) {
24731
+ if (!specifier) {
24732
+ return "";
24733
+ }
24734
+ const dir = path26.posix.dirname(fromFile);
24735
+ const absolute = path26.posix.resolve("/", dir, specifier);
24736
+ return absolute.startsWith("/") ? absolute.slice(1) : absolute;
24737
+ }
24640
24738
  async function flushIndependentBuilds(state) {
24641
24739
  const { subPackageMeta, pendingIndependentBuilds } = state;
24642
24740
  if (subPackageMeta || pendingIndependentBuilds.length === 0) {