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