weapp-tailwindcss 5.0.0-next.11 → 5.0.0-next.14

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 (77) hide show
  1. package/dist/{bundle-state-BrtFgX-A.mjs → bundle-state-BOBbxYzQ.mjs} +3 -2
  2. package/dist/{bundle-state-BRkhpjio.js → bundle-state-CxtGmT4t.js} +3 -2
  3. package/dist/bundlers/shared/css-cleanup.d.ts +6 -1
  4. package/dist/bundlers/shared/generator-css/source-files.d.ts +9 -6
  5. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +16 -2
  6. package/dist/bundlers/shared/generator-css.d.ts +4 -0
  7. package/dist/bundlers/shared/hmr-timing.d.ts +18 -1
  8. package/dist/bundlers/vite/bundle-state.d.ts +1 -0
  9. package/dist/bundlers/vite/css-finalizer.d.ts +2 -0
  10. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +5 -1
  11. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +1 -0
  12. package/dist/bundlers/vite/generate-bundle.d.ts +8 -1
  13. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +1 -0
  14. package/dist/bundlers/vite/runtime-class-set.d.ts +4 -1
  15. package/dist/bundlers/vite/source-candidates.d.ts +11 -0
  16. package/dist/bundlers/vite/source-scan.d.ts +18 -1
  17. package/dist/bundlers/vite/static-config-content.d.ts +5 -0
  18. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +5 -0
  19. package/dist/cli.js +486 -18
  20. package/dist/cli.mjs +484 -17
  21. package/dist/core.js +1 -1
  22. package/dist/core.mjs +1 -1
  23. package/dist/defaults-B1igPF_e.mjs +150 -0
  24. package/dist/defaults-IHhYxNeU.js +193 -0
  25. package/dist/defaults.js +6 -150
  26. package/dist/defaults.mjs +1 -143
  27. package/dist/generator-C9H44wEF.mjs +32 -0
  28. package/dist/generator-CRORPkpW.js +55 -0
  29. package/dist/generator.js +12 -11
  30. package/dist/generator.mjs +2 -1
  31. package/dist/gulp.js +49 -13
  32. package/dist/gulp.mjs +46 -10
  33. package/dist/{incremental-runtime-class-set-CBMefNHQ.js → incremental-runtime-class-set-B4EXHHii.js} +512 -103
  34. package/dist/{incremental-runtime-class-set-DaS2yw5c.mjs → incremental-runtime-class-set-DoKrMrEh.mjs} +491 -88
  35. package/dist/index.js +4 -4
  36. package/dist/index.mjs +4 -4
  37. package/dist/js/babel/cache-options.d.ts +3 -0
  38. package/dist/js/babel/parse.d.ts +7 -4
  39. package/dist/{postcss-xZDiTRII.mjs → postcss-BFxu5_cs.mjs} +19 -8
  40. package/dist/{postcss-Bs-RbNzK.js → postcss-CZE8k8oP.js} +59 -53
  41. package/dist/{postcss-BdcRlSpp.js → postcss-Vqn4IlO3.js} +30 -19
  42. package/dist/postcss.js +1 -1
  43. package/dist/postcss.mjs +1 -1
  44. package/dist/{precheck-D5eEdqeH.js → precheck-CZHcFX8k.js} +65 -25
  45. package/dist/{precheck-DtBGFS-n.mjs → precheck-DCresEiu.mjs} +57 -17
  46. package/dist/presets.js +4 -4
  47. package/dist/presets.mjs +2 -2
  48. package/dist/source-candidates-BvbvkIPP.js +274 -0
  49. package/dist/source-candidates-CK70jGo7.mjs +259 -0
  50. package/dist/tailwindcss/runtime/cache.d.ts +1 -0
  51. package/dist/tailwindcss/v3-engine/types.d.ts +3 -0
  52. package/dist/tailwindcss/v4-engine/types.d.ts +8 -0
  53. package/dist/{tailwindcss-DGM8lHUj.mjs → tailwindcss-7k0LFa12.mjs} +8 -3
  54. package/dist/{tailwindcss-B78nj6n7.js → tailwindcss-CN0K7G-l.js} +20 -15
  55. package/dist/types/index.d.ts +7 -1
  56. package/dist/types/user-defined-options/general.d.ts +2 -0
  57. package/dist/v3-engine-D61eilBl.mjs +3208 -0
  58. package/dist/v3-engine-DwV1E6rX.js +3461 -0
  59. package/dist/{vite-C8S1wfyQ.mjs → vite-DCmKrTo0.mjs} +378 -540
  60. package/dist/{vite-BEj9JOOA.js → vite-DJ0P9Hrp.js} +383 -548
  61. package/dist/vite.js +1 -1
  62. package/dist/vite.mjs +1 -1
  63. package/dist/weapp-tw-css-import-rewrite-loader.js +29 -9
  64. package/dist/weapp-tw-runtime-classset-loader.js +1 -1
  65. package/dist/{webpack-Dm1IXTIh.js → webpack-8y4NOMnT.js} +39 -22
  66. package/dist/{webpack-ZGIKKpFf.mjs → webpack-CbO4jjkH.mjs} +35 -18
  67. package/dist/webpack.js +1 -1
  68. package/dist/webpack.mjs +1 -1
  69. package/package.json +3 -3
  70. package/dist/cache-B_9E7FxF.js +0 -517
  71. package/dist/cache-DEDxBMIw.mjs +0 -443
  72. package/dist/generator-CahkD2vq.mjs +0 -1469
  73. package/dist/generator-Ck1Dd1V0.js +0 -1568
  74. package/dist/runtime-patch-CqB-A4zA.js +0 -85
  75. package/dist/runtime-patch-DGKsVkiG.mjs +0 -71
  76. package/dist/source-scan-CIVTa3Cj.js +0 -297
  77. package/dist/source-scan-CJ0y0XBj.mjs +0 -258
@@ -1,17 +1,16 @@
1
1
  const require_chunk = require("./chunk-8l464Juk.js");
2
- const require_cache = require("./cache-B_9E7FxF.js");
3
- const require_runtime_patch = require("./runtime-patch-CqB-A4zA.js");
2
+ const require_v3_engine = require("./v3-engine-DwV1E6rX.js");
3
+ const require_defaults = require("./defaults-IHhYxNeU.js");
4
4
  require("./utils-4ODFyoqD.js");
5
- const require_defaults = require("./defaults.js");
6
- const require_tailwindcss = require("./tailwindcss-B78nj6n7.js");
5
+ const require_tailwindcss = require("./tailwindcss-CN0K7G-l.js");
7
6
  let node_path = require("node:path");
8
7
  node_path = require_chunk.__toESM(node_path);
9
8
  let node_process = require("node:process");
10
9
  node_process = require_chunk.__toESM(node_process);
11
10
  let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
11
+ let node_fs_promises = require("node:fs/promises");
12
12
  let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
13
13
  let node_buffer = require("node:buffer");
14
- let node_fs_promises = require("node:fs/promises");
15
14
  let lru_cache = require("lru-cache");
16
15
  let _weapp_tailwindcss_shared_node = require("@weapp-tailwindcss/shared/node");
17
16
  let _weapp_core_escape = require("@weapp-core/escape");
@@ -110,12 +109,12 @@ function initializeCache(cacheConfig) {
110
109
  }
111
110
  //#endregion
112
111
  //#region src/tailwindcss/runtime.ts
113
- const debug$1 = require_runtime_patch.createDebug("[tailwindcss:runtime] ");
112
+ const debug$1 = require_v3_engine.createDebug("[tailwindcss:runtime] ");
114
113
  const refreshTailwindcssPatcherSymbol = Symbol.for("weapp-tailwindcss.refreshTailwindcssPatcher");
115
114
  function createTailwindRuntimeReadyPromise(twPatcher) {
116
115
  return Promise.resolve().then(async () => {
117
- await require_runtime_patch.ensureTailwindcssRuntimePatch(twPatcher);
118
- require_cache.invalidateRuntimeClassSet(twPatcher);
116
+ await require_v3_engine.ensureTailwindcssRuntimePatch(twPatcher);
117
+ require_v3_engine.invalidateRuntimeClassSet(twPatcher);
119
118
  });
120
119
  }
121
120
  const runtimeClassSetStateCache = /* @__PURE__ */ new WeakMap();
@@ -155,7 +154,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
155
154
  });
156
155
  await state.readyPromise;
157
156
  const entry = getRuntimeClassSetStateEntry(state);
158
- const signature = require_cache.getRuntimeClassSetSignature(state.twPatcher);
157
+ const signature = await require_v3_engine.getRuntimeClassSetSignatureWithSources(state.twPatcher);
159
158
  const signatureChanged = entry.signature !== signature;
160
159
  const shouldForceCollect = forceCollect || forceRefresh || signatureChanged;
161
160
  if (!shouldForceCollect) {
@@ -184,7 +183,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
184
183
  try {
185
184
  const runtimeSet = await task;
186
185
  entry.value = runtimeSet;
187
- entry.signature = require_cache.getRuntimeClassSetSignature(state.twPatcher);
186
+ entry.signature = await require_v3_engine.getRuntimeClassSetSignatureWithSources(state.twPatcher);
188
187
  return runtimeSet;
189
188
  } finally {
190
189
  if (entry.promise === task) entry.promise = void 0;
@@ -209,6 +208,19 @@ function tryGetRuntimeClassSetSync(twPatcher) {
209
208
  return;
210
209
  }
211
210
  }
211
+ async function collectTailwindV4GeneratorClassSet(twPatcher) {
212
+ try {
213
+ const generated = await require_v3_engine.createTailwindV4Engine(await require_v3_engine.resolveTailwindV4SourceFromPatcher(twPatcher)).generate({
214
+ scanSources: true,
215
+ target: "tailwind"
216
+ });
217
+ debug$1("runtime class set resolved via tailwindcss v4 generator source scan, size=%d", generated.classSet.size);
218
+ return generated.classSet;
219
+ } catch (error) {
220
+ debug$1("tailwindcss v4 generator source scan failed, continuing fallback chain: %O", error);
221
+ return;
222
+ }
223
+ }
212
224
  async function collectRuntimeClassSet(twPatcher, options = {}) {
213
225
  let activePatcher = twPatcher;
214
226
  if (options.force && !options.skipRefresh) {
@@ -220,14 +232,14 @@ async function collectRuntimeClassSet(twPatcher, options = {}) {
220
232
  debug$1("refreshTailwindcssPatcher failed, continuing with existing patcher: %O", error);
221
233
  }
222
234
  }
223
- const entry = require_cache.getRuntimeClassSetCacheEntry(activePatcher);
224
- const signature = require_cache.getRuntimeClassSetSignature(activePatcher);
235
+ const entry = require_v3_engine.getRuntimeClassSetCacheEntry(activePatcher);
236
+ const signature = await require_v3_engine.getRuntimeClassSetSignatureWithSources(activePatcher);
225
237
  if (!options.force) {
226
238
  if (entry.value && entry.signature === signature) return entry.value;
227
239
  if (entry.promise) return entry.promise;
228
240
  } else entry.value = void 0;
229
241
  const task = (async () => {
230
- await require_runtime_patch.ensureTailwindcssRuntimePatch(activePatcher);
242
+ await require_v3_engine.ensureTailwindcssRuntimePatch(activePatcher);
231
243
  const preExtractSyncSet = options.force ? tryGetRuntimeClassSetSync(activePatcher) : void 0;
232
244
  if (preExtractSyncSet) debug$1("runtime class set snapshot via getClassSetSync() before extract(), size=%d", preExtractSyncSet.size);
233
245
  const preferExtract = options.force === true;
@@ -238,12 +250,20 @@ async function collectRuntimeClassSet(twPatcher, options = {}) {
238
250
  debug$1("runtime class set resolved via extract(), size=%d", result.classSet.size);
239
251
  return result.classSet;
240
252
  }
241
- if (preferExtract) debug$1("runtime class set from extract() is empty on force collect, fallback to sync/async class set");
253
+ if (preferExtract && activePatcher.majorVersion !== 4) {
254
+ debug$1("runtime class set resolved via empty extract() on force collect, size=0");
255
+ return result.classSet;
256
+ }
257
+ if (preferExtract) debug$1("runtime class set from extract() is empty on force collect, fallback to generator/sync/async class set");
242
258
  else debug$1("runtime class set from extract() is empty, fallback to sync/async class set");
243
259
  }
244
260
  } catch (error) {
245
261
  debug$1("extract() failed, fallback to getClassSet(): %O", error);
246
262
  }
263
+ if (activePatcher.majorVersion === 4) {
264
+ const generatorClassSet = await collectTailwindV4GeneratorClassSet(activePatcher);
265
+ if (generatorClassSet && generatorClassSet.size > 0) return generatorClassSet;
266
+ }
247
267
  if (preExtractSyncSet) {
248
268
  debug$1("runtime class set fallback to pre-extract sync snapshot, size=%d", preExtractSyncSet.size);
249
269
  return preExtractSyncSet;
@@ -610,20 +630,40 @@ function createNameMatcher(list, { exact = false } = {}) {
610
630
  }
611
631
  //#endregion
612
632
  //#region src/js/babel/parse.ts
613
- const parseCache = new lru_cache.LRUCache({ max: 1024 });
633
+ const parseCache = new lru_cache.LRUCache({ max: require_defaults.HARD_PARSE_CACHE_MAX_ENTRIES });
614
634
  function genCacheKey(source, options) {
615
- if (typeof options === "string") return source + options;
616
- return source + JSON.stringify(options, (_, val) => typeof val === "function" ? val.toString() : val);
635
+ if (typeof options === "string") return `${(0, _weapp_tailwindcss_shared_node.md5)(source)}:${options}`;
636
+ return `${(0, _weapp_tailwindcss_shared_node.md5)(source)}:${JSON.stringify(options, (_, val) => typeof val === "function" ? val.toString() : val)}`;
637
+ }
638
+ function normalizeCacheMaxEntries(value) {
639
+ if (typeof value !== "number" || !Number.isFinite(value)) return 128;
640
+ return Math.min(Math.max(Math.floor(value), 0), require_defaults.HARD_PARSE_CACHE_MAX_ENTRIES);
641
+ }
642
+ function normalizeCacheMaxSourceLength(value) {
643
+ if (typeof value !== "number" || !Number.isFinite(value)) return require_defaults.DEFAULT_PARSE_CACHE_MAX_SOURCE_LENGTH;
644
+ return Math.max(Math.floor(value), 0);
645
+ }
646
+ function trimParseCache(maxEntries) {
647
+ while (parseCache.size > maxEntries) parseCache.pop();
617
648
  }
618
649
  function babelParse(code, opts = {}) {
619
- const { cache, cacheKey, ...rest } = opts;
620
- const cacheKeyString = genCacheKey(code, cacheKey ?? rest);
650
+ const { cache, cacheKey, cacheMaxEntries, cacheMaxSourceLength, ...rest } = opts;
651
+ const maxEntries = normalizeCacheMaxEntries(cacheMaxEntries);
652
+ const maxSourceLength = normalizeCacheMaxSourceLength(cacheMaxSourceLength);
653
+ const shouldCache = cache === true && maxEntries > 0 && code.length <= maxSourceLength;
654
+ const cacheKeyString = shouldCache ? genCacheKey(code, cacheKey ?? rest) : void 0;
621
655
  let result;
622
- if (cache) result = parseCache.get(cacheKeyString);
656
+ if (shouldCache) {
657
+ trimParseCache(maxEntries);
658
+ result = parseCache.get(cacheKeyString);
659
+ }
623
660
  if (!result) {
624
- const { cache: _cache, cacheKey: _cacheKey, ...parseOptions } = opts;
661
+ const { cache: _cache, cacheKey: _cacheKey, cacheMaxEntries: _cacheMaxEntries, cacheMaxSourceLength: _cacheMaxSourceLength, ...parseOptions } = opts;
625
662
  result = (0, _babel_parser.parse)(code, parseOptions);
626
- if (cache) parseCache.set(cacheKeyString, result);
663
+ if (shouldCache) {
664
+ parseCache.set(cacheKeyString, result);
665
+ trimParseCache(maxEntries);
666
+ }
627
667
  }
628
668
  return result;
629
669
  }
@@ -637,7 +677,7 @@ function replaceWxml(original, options = {
637
677
  const { keepEOL, escapeMap, ignoreHead } = options;
638
678
  let res = original;
639
679
  if (!keepEOL) res = res.replaceAll(NEWLINE_RE, "");
640
- res = (0, _weapp_core_escape.escape)(res, require_cache.omitUndefined({
680
+ res = (0, _weapp_core_escape.escape)(res, require_v3_engine.omitUndefined({
641
681
  map: escapeMap,
642
682
  ignoreHead
643
683
  }));
@@ -837,7 +877,7 @@ function isClassContextLiteralPath(path) {
837
877
  }
838
878
  //#endregion
839
879
  //#region src/js/handlers.ts
840
- const debug = require_runtime_patch.createDebug("[js:handlers] ");
880
+ const debug = require_v3_engine.createDebug("[js:handlers] ");
841
881
  const replacementCacheByEscapeMap = /* @__PURE__ */ new WeakMap();
842
882
  const defaultReplacementCache = /* @__PURE__ */ new Map();
843
883
  const WEAPP_TW_IGNORE_MARKER = "weapp-tw";
@@ -2587,7 +2627,7 @@ function createInternalCompilerContext(opts) {
2587
2627
  const refreshTailwindcssPatcher = async (options) => {
2588
2628
  const previousPatcher = ctx.twPatcher;
2589
2629
  if (options?.clearCache !== false) await clearTailwindcssPatcherCache(previousPatcher);
2590
- require_cache.invalidateRuntimeClassSet(previousPatcher);
2630
+ require_v3_engine.invalidateRuntimeClassSet(previousPatcher);
2591
2631
  const nextPatcher = require_tailwindcss.createTailwindcssPatcherFromContext(ctx);
2592
2632
  Object.assign(previousPatcher, nextPatcher);
2593
2633
  ctx.twPatcher = previousPatcher;
@@ -1,14 +1,13 @@
1
- import { l as omitUndefined, n as getRuntimeClassSetSignature, r as invalidateRuntimeClassSet, t as getRuntimeClassSetCacheEntry } from "./cache-DEDxBMIw.mjs";
2
- import { n as createDebug, t as ensureTailwindcssRuntimePatch } from "./runtime-patch-DGKsVkiG.mjs";
1
+ import { B as omitUndefined, C as createTailwindV4Engine, F as createDebug, c as getRuntimeClassSetCacheEntry, d as invalidateRuntimeClassSet, s as ensureTailwindcssRuntimePatch, u as getRuntimeClassSetSignatureWithSources, x as resolveTailwindV4SourceFromPatcher } from "./v3-engine-D61eilBl.mjs";
2
+ import { a as resolveDefaultCssPreflight, i as getDefaultOptions, o as DEFAULT_PARSE_CACHE_MAX_SOURCE_LENGTH, s as HARD_PARSE_CACHE_MAX_ENTRIES } from "./defaults-B1igPF_e.mjs";
3
3
  import { i as isMap, n as defuOverrideArray } from "./utils-CGBVVNm6.mjs";
4
- import { getDefaultOptions, resolveDefaultCssPreflight } from "./defaults.mjs";
5
- import { a as applyV4CssCalcDefaults, i as resolveUniAppXOptions, o as warnMissingCssEntries, r as isUniAppXEnabled, t as createTailwindcssPatcherFromContext } from "./tailwindcss-DGM8lHUj.mjs";
4
+ import { a as applyV4CssCalcDefaults, i as resolveUniAppXOptions, o as warnMissingCssEntries, r as isUniAppXEnabled, t as createTailwindcssPatcherFromContext } from "./tailwindcss-7k0LFa12.mjs";
6
5
  import path from "node:path";
7
6
  import process from "node:process";
8
7
  import { logger, pc } from "@weapp-tailwindcss/logger";
8
+ import { rm } from "node:fs/promises";
9
9
  import { createStyleHandler } from "@weapp-tailwindcss/postcss";
10
10
  import { Buffer } from "node:buffer";
11
- import { rm } from "node:fs/promises";
12
11
  import { LRUCache } from "lru-cache";
13
12
  import { md5 as md5Hash } from "@weapp-tailwindcss/shared/node";
14
13
  import { MappingChars2String, escape } from "@weapp-core/escape";
@@ -148,7 +147,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
148
147
  });
149
148
  await state.readyPromise;
150
149
  const entry = getRuntimeClassSetStateEntry(state);
151
- const signature = getRuntimeClassSetSignature(state.twPatcher);
150
+ const signature = await getRuntimeClassSetSignatureWithSources(state.twPatcher);
152
151
  const signatureChanged = entry.signature !== signature;
153
152
  const shouldForceCollect = forceCollect || forceRefresh || signatureChanged;
154
153
  if (!shouldForceCollect) {
@@ -177,7 +176,7 @@ async function ensureRuntimeClassSet(state, options = {}) {
177
176
  try {
178
177
  const runtimeSet = await task;
179
178
  entry.value = runtimeSet;
180
- entry.signature = getRuntimeClassSetSignature(state.twPatcher);
179
+ entry.signature = await getRuntimeClassSetSignatureWithSources(state.twPatcher);
181
180
  return runtimeSet;
182
181
  } finally {
183
182
  if (entry.promise === task) entry.promise = void 0;
@@ -202,6 +201,19 @@ function tryGetRuntimeClassSetSync(twPatcher) {
202
201
  return;
203
202
  }
204
203
  }
204
+ async function collectTailwindV4GeneratorClassSet(twPatcher) {
205
+ try {
206
+ const generated = await createTailwindV4Engine(await resolveTailwindV4SourceFromPatcher(twPatcher)).generate({
207
+ scanSources: true,
208
+ target: "tailwind"
209
+ });
210
+ debug$1("runtime class set resolved via tailwindcss v4 generator source scan, size=%d", generated.classSet.size);
211
+ return generated.classSet;
212
+ } catch (error) {
213
+ debug$1("tailwindcss v4 generator source scan failed, continuing fallback chain: %O", error);
214
+ return;
215
+ }
216
+ }
205
217
  async function collectRuntimeClassSet(twPatcher, options = {}) {
206
218
  let activePatcher = twPatcher;
207
219
  if (options.force && !options.skipRefresh) {
@@ -214,7 +226,7 @@ async function collectRuntimeClassSet(twPatcher, options = {}) {
214
226
  }
215
227
  }
216
228
  const entry = getRuntimeClassSetCacheEntry(activePatcher);
217
- const signature = getRuntimeClassSetSignature(activePatcher);
229
+ const signature = await getRuntimeClassSetSignatureWithSources(activePatcher);
218
230
  if (!options.force) {
219
231
  if (entry.value && entry.signature === signature) return entry.value;
220
232
  if (entry.promise) return entry.promise;
@@ -231,12 +243,20 @@ async function collectRuntimeClassSet(twPatcher, options = {}) {
231
243
  debug$1("runtime class set resolved via extract(), size=%d", result.classSet.size);
232
244
  return result.classSet;
233
245
  }
234
- if (preferExtract) debug$1("runtime class set from extract() is empty on force collect, fallback to sync/async class set");
246
+ if (preferExtract && activePatcher.majorVersion !== 4) {
247
+ debug$1("runtime class set resolved via empty extract() on force collect, size=0");
248
+ return result.classSet;
249
+ }
250
+ if (preferExtract) debug$1("runtime class set from extract() is empty on force collect, fallback to generator/sync/async class set");
235
251
  else debug$1("runtime class set from extract() is empty, fallback to sync/async class set");
236
252
  }
237
253
  } catch (error) {
238
254
  debug$1("extract() failed, fallback to getClassSet(): %O", error);
239
255
  }
256
+ if (activePatcher.majorVersion === 4) {
257
+ const generatorClassSet = await collectTailwindV4GeneratorClassSet(activePatcher);
258
+ if (generatorClassSet && generatorClassSet.size > 0) return generatorClassSet;
259
+ }
240
260
  if (preExtractSyncSet) {
241
261
  debug$1("runtime class set fallback to pre-extract sync snapshot, size=%d", preExtractSyncSet.size);
242
262
  return preExtractSyncSet;
@@ -603,20 +623,40 @@ function createNameMatcher(list, { exact = false } = {}) {
603
623
  }
604
624
  //#endregion
605
625
  //#region src/js/babel/parse.ts
606
- const parseCache = new LRUCache({ max: 1024 });
626
+ const parseCache = new LRUCache({ max: HARD_PARSE_CACHE_MAX_ENTRIES });
607
627
  function genCacheKey(source, options) {
608
- if (typeof options === "string") return source + options;
609
- return source + JSON.stringify(options, (_, val) => typeof val === "function" ? val.toString() : val);
628
+ if (typeof options === "string") return `${md5Hash(source)}:${options}`;
629
+ return `${md5Hash(source)}:${JSON.stringify(options, (_, val) => typeof val === "function" ? val.toString() : val)}`;
630
+ }
631
+ function normalizeCacheMaxEntries(value) {
632
+ if (typeof value !== "number" || !Number.isFinite(value)) return 128;
633
+ return Math.min(Math.max(Math.floor(value), 0), HARD_PARSE_CACHE_MAX_ENTRIES);
634
+ }
635
+ function normalizeCacheMaxSourceLength(value) {
636
+ if (typeof value !== "number" || !Number.isFinite(value)) return DEFAULT_PARSE_CACHE_MAX_SOURCE_LENGTH;
637
+ return Math.max(Math.floor(value), 0);
638
+ }
639
+ function trimParseCache(maxEntries) {
640
+ while (parseCache.size > maxEntries) parseCache.pop();
610
641
  }
611
642
  function babelParse(code, opts = {}) {
612
- const { cache, cacheKey, ...rest } = opts;
613
- const cacheKeyString = genCacheKey(code, cacheKey ?? rest);
643
+ const { cache, cacheKey, cacheMaxEntries, cacheMaxSourceLength, ...rest } = opts;
644
+ const maxEntries = normalizeCacheMaxEntries(cacheMaxEntries);
645
+ const maxSourceLength = normalizeCacheMaxSourceLength(cacheMaxSourceLength);
646
+ const shouldCache = cache === true && maxEntries > 0 && code.length <= maxSourceLength;
647
+ const cacheKeyString = shouldCache ? genCacheKey(code, cacheKey ?? rest) : void 0;
614
648
  let result;
615
- if (cache) result = parseCache.get(cacheKeyString);
649
+ if (shouldCache) {
650
+ trimParseCache(maxEntries);
651
+ result = parseCache.get(cacheKeyString);
652
+ }
616
653
  if (!result) {
617
- const { cache: _cache, cacheKey: _cacheKey, ...parseOptions } = opts;
654
+ const { cache: _cache, cacheKey: _cacheKey, cacheMaxEntries: _cacheMaxEntries, cacheMaxSourceLength: _cacheMaxSourceLength, ...parseOptions } = opts;
618
655
  result = parse(code, parseOptions);
619
- if (cache) parseCache.set(cacheKeyString, result);
656
+ if (shouldCache) {
657
+ parseCache.set(cacheKeyString, result);
658
+ trimParseCache(maxEntries);
659
+ }
620
660
  }
621
661
  return result;
622
662
  }
package/dist/presets.js CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("./chunk-8l464Juk.js");
3
- const require_cache = require("./cache-B_9E7FxF.js");
3
+ const require_v3_engine = require("./v3-engine-DwV1E6rX.js");
4
4
  const require_utils = require("./utils-4ODFyoqD.js");
5
- const require_tailwindcss = require("./tailwindcss-B78nj6n7.js");
5
+ const require_tailwindcss = require("./tailwindcss-CN0K7G-l.js");
6
6
  require("./logger-EVNB9z7i.js");
7
7
  let node_process = require("node:process");
8
8
  node_process = require_chunk.__toESM(node_process);
@@ -22,7 +22,7 @@ function createBasePreset(options = {}) {
22
22
  const tailwindConfig = {
23
23
  v2: { cwd: baseDir },
24
24
  v3: { cwd: baseDir },
25
- v4: require_cache.omitUndefined({
25
+ v4: require_v3_engine.omitUndefined({
26
26
  base: baseDir,
27
27
  cssEntries: normalizedCssEntries
28
28
  })
@@ -109,7 +109,7 @@ function uniAppX(options) {
109
109
  cwd: options.base,
110
110
  resolve: resolvedResolve,
111
111
  v3: { cwd: options.base },
112
- v4: require_cache.omitUndefined({
112
+ v4: require_v3_engine.omitUndefined({
113
113
  base: options.base,
114
114
  cssEntries
115
115
  })
package/dist/presets.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { l as omitUndefined } from "./cache-DEDxBMIw.mjs";
1
+ import { B as omitUndefined } from "./v3-engine-D61eilBl.mjs";
2
2
  import { n as defuOverrideArray, o as resolveUniUtsPlatform } from "./utils-CGBVVNm6.mjs";
3
- import { i as resolveUniAppXOptions, n as resolveTailwindcssBasedir } from "./tailwindcss-DGM8lHUj.mjs";
3
+ import { i as resolveUniAppXOptions, n as resolveTailwindcssBasedir } from "./tailwindcss-7k0LFa12.mjs";
4
4
  import { t as logger } from "./logger-CZUxvJJD.mjs";
5
5
  import process from "node:process";
6
6
  import { getPackageInfoSync } from "local-pkg";
@@ -0,0 +1,274 @@
1
+ const require_chunk = require("./chunk-8l464Juk.js");
2
+ const require_v3_engine = require("./v3-engine-DwV1E6rX.js");
3
+ let node_path = require("node:path");
4
+ node_path = require_chunk.__toESM(node_path);
5
+ let tailwindcss_patch = require("tailwindcss-patch");
6
+ let node_fs_promises = require("node:fs/promises");
7
+ let fast_glob = require("fast-glob");
8
+ fast_glob = require_chunk.__toESM(fast_glob);
9
+ let micromatch = require("micromatch");
10
+ micromatch = require_chunk.__toESM(micromatch);
11
+ //#region src/bundlers/vite/source-candidates.ts
12
+ const CLEAN_URL_RE = /[?#].*$/;
13
+ const SOURCE_CANDIDATE_EXTENSIONS = [
14
+ "js",
15
+ "jsx",
16
+ "mjs",
17
+ "cjs",
18
+ "ts",
19
+ "tsx",
20
+ "mts",
21
+ "cts",
22
+ "vue",
23
+ "uvue",
24
+ "nvue",
25
+ "svelte",
26
+ "mpx",
27
+ "html",
28
+ "wxml",
29
+ "axml",
30
+ "jxml",
31
+ "ksml",
32
+ "ttml",
33
+ "qml",
34
+ "tyml",
35
+ "xhsml",
36
+ "swan",
37
+ "css",
38
+ "wxss",
39
+ "acss",
40
+ "jxss",
41
+ "ttss",
42
+ "qss",
43
+ "tyss",
44
+ "scss",
45
+ "sass",
46
+ "less",
47
+ "styl",
48
+ "stylus"
49
+ ];
50
+ const SOURCE_CANDIDATE_EXTENSION_RE = /\.(?:[cm]?[jt]sx?|vue|uvue|nvue|svelte|mpx|html|wxml|axml|jxml|ksml|ttml|qml|tyml|xhsml|swan|css|wxss|acss|jxss|ttss|qss|tyss|scss|sass|less|stylus?)$/;
51
+ const SOURCE_CANDIDATE_GLOB = `**/*.{${SOURCE_CANDIDATE_EXTENSIONS.join(",")}}`;
52
+ const DEFAULT_SCAN_IGNORE = ["**/node_modules/**", "**/.git/**"];
53
+ const sourceCandidateContentCache = /* @__PURE__ */ new Map();
54
+ function cleanUrl(id) {
55
+ return node_path.default.resolve(id.replace(CLEAN_URL_RE, ""));
56
+ }
57
+ function toPosixPath(value) {
58
+ return value.split(node_path.default.sep).join("/");
59
+ }
60
+ function resolveOutDirIgnorePattern(root, outDir) {
61
+ if (!outDir) return;
62
+ const relative = node_path.default.relative(root, node_path.default.resolve(root, outDir));
63
+ if (!relative || relative.startsWith("..") || node_path.default.isAbsolute(relative)) return;
64
+ return `${toPosixPath(relative)}/**`;
65
+ }
66
+ function resolveSourceCandidateExtension(id) {
67
+ const normalized = cleanUrl(id);
68
+ return /\.([^.\\/]+)$/.exec(normalized)?.[1] ?? "html";
69
+ }
70
+ function createSourceCandidateContentCacheKey(extension, source) {
71
+ return `${extension}\0${source}`;
72
+ }
73
+ function isSourceCandidateRequest(id) {
74
+ return SOURCE_CANDIDATE_EXTENSION_RE.test(cleanUrl(id));
75
+ }
76
+ function removeCandidateSet(candidateCount, candidates) {
77
+ for (const candidate of candidates) {
78
+ const count = candidateCount.get(candidate);
79
+ if (count == null) continue;
80
+ if (count <= 1) {
81
+ candidateCount.delete(candidate);
82
+ continue;
83
+ }
84
+ candidateCount.set(candidate, count - 1);
85
+ }
86
+ }
87
+ function addCandidateSet(candidateCount, candidates) {
88
+ for (const candidate of candidates) candidateCount.set(candidate, (candidateCount.get(candidate) ?? 0) + 1);
89
+ }
90
+ function isFileMatchedByEntries(file, entries) {
91
+ if (!entries?.length) return true;
92
+ const positiveEntries = entries.filter((entry) => !entry.negated);
93
+ const negativeEntries = entries.filter((entry) => entry.negated);
94
+ if (positiveEntries.length === 0) return false;
95
+ const resolvedFile = node_path.default.resolve(file);
96
+ if (!positiveEntries.some((entry) => {
97
+ const relative = toPosixPath(node_path.default.relative(node_path.default.resolve(entry.base), resolvedFile));
98
+ const pattern = node_path.default.isAbsolute(entry.pattern) ? toPosixPath(node_path.default.relative(node_path.default.resolve(entry.base), entry.pattern)) : entry.pattern;
99
+ return relative && !relative.startsWith("../") && !node_path.default.isAbsolute(relative) && micromatch.default.isMatch(relative, pattern);
100
+ })) return false;
101
+ return !negativeEntries.some((entry) => {
102
+ const relative = toPosixPath(node_path.default.relative(node_path.default.resolve(entry.base), resolvedFile));
103
+ const pattern = node_path.default.isAbsolute(entry.pattern) ? toPosixPath(node_path.default.relative(node_path.default.resolve(entry.base), entry.pattern)) : entry.pattern;
104
+ return relative && !relative.startsWith("../") && !node_path.default.isAbsolute(relative) && micromatch.default.isMatch(relative, pattern);
105
+ });
106
+ }
107
+ function createSourceCandidateCollector() {
108
+ const candidatesById = /* @__PURE__ */ new Map();
109
+ const scanCandidatesById = /* @__PURE__ */ new Map();
110
+ const transformCandidatesById = /* @__PURE__ */ new Map();
111
+ const candidateCount = /* @__PURE__ */ new Map();
112
+ let inlineIncludedCandidates = /* @__PURE__ */ new Set();
113
+ let inlineExcludedCandidates = /* @__PURE__ */ new Set();
114
+ async function sync(id, source) {
115
+ const normalizedId = cleanUrl(id);
116
+ const extension = resolveSourceCandidateExtension(normalizedId);
117
+ const contentCacheKey = createSourceCandidateContentCacheKey(extension, source);
118
+ const cachedCandidates = sourceCandidateContentCache.get(contentCacheKey);
119
+ if (cachedCandidates) {
120
+ replaceScanLayer(normalizedId, new Set(cachedCandidates));
121
+ return;
122
+ }
123
+ const nextCandidates = new Set(await (0, tailwindcss_patch.extractSourceCandidates)(source, extension));
124
+ sourceCandidateContentCache.set(contentCacheKey, [...nextCandidates]);
125
+ replaceScanLayer(normalizedId, nextCandidates);
126
+ }
127
+ async function merge(id, source) {
128
+ const normalizedId = cleanUrl(id);
129
+ const extension = resolveSourceCandidateExtension(normalizedId);
130
+ const contentCacheKey = createSourceCandidateContentCacheKey(extension, source);
131
+ const cachedCandidates = sourceCandidateContentCache.get(contentCacheKey);
132
+ const extractedCandidates = cachedCandidates ? new Set(cachedCandidates) : new Set(await (0, tailwindcss_patch.extractSourceCandidates)(source, extension));
133
+ if (!cachedCandidates) sourceCandidateContentCache.set(contentCacheKey, [...extractedCandidates]);
134
+ replaceTransformLayer(normalizedId, extractedCandidates);
135
+ }
136
+ async function syncFile(id) {
137
+ const normalizedId = cleanUrl(id);
138
+ await sync(normalizedId, await (0, node_fs_promises.readFile)(normalizedId, "utf8"));
139
+ }
140
+ async function scanRoot({ entries, root, outDir }) {
141
+ const resolvedRoot = node_path.default.resolve(root);
142
+ const outDirIgnore = resolveOutDirIgnorePattern(resolvedRoot, outDir);
143
+ const ignore = outDirIgnore ? [...DEFAULT_SCAN_IGNORE, outDirIgnore] : DEFAULT_SCAN_IGNORE;
144
+ const files = entries ? await require_v3_engine.expandTailwindSourceEntries(entries, { ignore }) : await (0, fast_glob.default)(SOURCE_CANDIDATE_GLOB, {
145
+ absolute: true,
146
+ cwd: resolvedRoot,
147
+ ignore,
148
+ onlyFiles: true,
149
+ unique: true
150
+ });
151
+ await Promise.all(files.map((file) => syncFile(file)));
152
+ }
153
+ function replaceFinal(id, nextCandidates) {
154
+ const normalizedId = cleanUrl(id);
155
+ const previousCandidates = candidatesById.get(normalizedId);
156
+ if (previousCandidates) {
157
+ removeCandidateSet(candidateCount, previousCandidates);
158
+ candidatesById.delete(normalizedId);
159
+ }
160
+ if (nextCandidates.size === 0) return;
161
+ candidatesById.set(normalizedId, nextCandidates);
162
+ addCandidateSet(candidateCount, nextCandidates);
163
+ }
164
+ function replaceScanLayer(id, nextCandidates) {
165
+ const normalizedId = cleanUrl(id);
166
+ if (nextCandidates.size === 0) scanCandidatesById.delete(normalizedId);
167
+ else scanCandidatesById.set(normalizedId, nextCandidates);
168
+ recompute(normalizedId);
169
+ }
170
+ function replaceTransformLayer(id, nextCandidates) {
171
+ const normalizedId = cleanUrl(id);
172
+ if (nextCandidates.size === 0) transformCandidatesById.delete(normalizedId);
173
+ else transformCandidatesById.set(normalizedId, nextCandidates);
174
+ recompute(normalizedId);
175
+ }
176
+ function recompute(id) {
177
+ const normalizedId = cleanUrl(id);
178
+ replaceFinal(normalizedId, new Set([...scanCandidatesById.get(normalizedId) ?? [], ...transformCandidatesById.get(normalizedId) ?? []]));
179
+ }
180
+ function syncInline(inlineCandidates) {
181
+ inlineIncludedCandidates = new Set(inlineCandidates?.included ?? []);
182
+ inlineExcludedCandidates = new Set(inlineCandidates?.excluded ?? []);
183
+ }
184
+ function remove(id) {
185
+ const normalizedId = cleanUrl(id);
186
+ scanCandidatesById.delete(normalizedId);
187
+ transformCandidatesById.delete(normalizedId);
188
+ const previousCandidates = candidatesById.get(normalizedId);
189
+ if (!previousCandidates) return;
190
+ removeCandidateSet(candidateCount, previousCandidates);
191
+ candidatesById.delete(normalizedId);
192
+ }
193
+ function values() {
194
+ const values = new Set([...candidateCount.keys(), ...inlineIncludedCandidates]);
195
+ for (const candidate of inlineExcludedCandidates) values.delete(candidate);
196
+ return values;
197
+ }
198
+ function valuesForEntries(entries) {
199
+ if (entries === void 0) return values();
200
+ const filtered = /* @__PURE__ */ new Set();
201
+ for (const [id, candidates] of candidatesById) {
202
+ if (!isFileMatchedByEntries(id, entries)) continue;
203
+ for (const candidate of candidates) filtered.add(candidate);
204
+ }
205
+ for (const candidate of inlineIncludedCandidates) filtered.add(candidate);
206
+ for (const candidate of inlineExcludedCandidates) filtered.delete(candidate);
207
+ return filtered;
208
+ }
209
+ function clear() {
210
+ candidatesById.clear();
211
+ scanCandidatesById.clear();
212
+ transformCandidatesById.clear();
213
+ candidateCount.clear();
214
+ inlineIncludedCandidates.clear();
215
+ inlineExcludedCandidates.clear();
216
+ }
217
+ function snapshot() {
218
+ return {
219
+ candidatesById: [...candidatesById.entries()].map(([id, candidates]) => [id, [...candidates]]),
220
+ scanCandidatesById: [...scanCandidatesById.entries()].map(([id, candidates]) => [id, [...candidates]]),
221
+ transformCandidatesById: [...transformCandidatesById.entries()].map(([id, candidates]) => [id, [...candidates]]),
222
+ inlineExcludedCandidates: [...inlineExcludedCandidates],
223
+ inlineIncludedCandidates: [...inlineIncludedCandidates]
224
+ };
225
+ }
226
+ function restore(snapshot) {
227
+ clear();
228
+ inlineExcludedCandidates = new Set(snapshot.inlineExcludedCandidates);
229
+ inlineIncludedCandidates = new Set(snapshot.inlineIncludedCandidates);
230
+ const scanEntries = snapshot.scanCandidatesById ?? snapshot.candidatesById;
231
+ for (const [id, candidates] of scanEntries) {
232
+ const candidateSet = new Set(candidates);
233
+ if (candidateSet.size === 0) continue;
234
+ scanCandidatesById.set(id, candidateSet);
235
+ }
236
+ for (const [id, candidates] of snapshot.transformCandidatesById ?? []) {
237
+ const candidateSet = new Set(candidates);
238
+ if (candidateSet.size === 0) continue;
239
+ transformCandidatesById.set(id, candidateSet);
240
+ }
241
+ for (const [id, candidates] of snapshot.candidatesById) {
242
+ const candidateSet = new Set(candidates);
243
+ if (candidateSet.size === 0) continue;
244
+ candidatesById.set(id, candidateSet);
245
+ addCandidateSet(candidateCount, candidateSet);
246
+ }
247
+ }
248
+ return {
249
+ sync,
250
+ merge,
251
+ syncFile,
252
+ scanRoot,
253
+ syncInline,
254
+ remove,
255
+ values,
256
+ valuesForEntries,
257
+ snapshot,
258
+ restore,
259
+ clear
260
+ };
261
+ }
262
+ //#endregion
263
+ Object.defineProperty(exports, "createSourceCandidateCollector", {
264
+ enumerable: true,
265
+ get: function() {
266
+ return createSourceCandidateCollector;
267
+ }
268
+ });
269
+ Object.defineProperty(exports, "isSourceCandidateRequest", {
270
+ enumerable: true,
271
+ get: function() {
272
+ return isSourceCandidateRequest;
273
+ }
274
+ });