weapp-tailwindcss 4.9.8 → 4.9.9-beta.0

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.
@@ -12,20 +12,20 @@ import {
12
12
  } from "./chunk-RRHPTTCP.mjs";
13
13
  import {
14
14
  setupPatchRecorder
15
- } from "./chunk-W3JRVMJD.mjs";
15
+ } from "./chunk-NBS6RMNM.mjs";
16
16
  import {
17
17
  collectRuntimeClassSet,
18
18
  createAttributeMatcher,
19
19
  createDebug,
20
20
  generateCode,
21
21
  getCompilerContext,
22
+ getRuntimeClassSetSignature,
22
23
  refreshTailwindRuntimeState,
23
24
  replaceWxml,
24
25
  toCustomAttributesEntities,
25
26
  vitePluginName
26
- } from "./chunk-77PO4QLM.mjs";
27
+ } from "./chunk-YYE3U4L3.mjs";
27
28
  import {
28
- getGroupedEntries,
29
29
  resolveUniUtsPlatform
30
30
  } from "./chunk-OOHJLO5M.mjs";
31
31
 
@@ -352,6 +352,7 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
352
352
  return async () => {
353
353
  const {
354
354
  cache,
355
+ hashKey,
355
356
  createHandlerOptions,
356
357
  debug: debug2,
357
358
  jsHandler,
@@ -361,10 +362,13 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
361
362
  } = options;
362
363
  const absoluteFile = toAbsoluteOutputPath(file, outDir);
363
364
  const rawSource = originalSource.source.toString();
365
+ const rawHashSource = options.hashSalt ? `${rawSource}
366
+ /*${options.hashSalt}*/` : rawSource;
364
367
  await processCachedTask({
365
368
  cache,
366
369
  cacheKey: file,
367
- rawSource,
370
+ hashKey,
371
+ rawSource: rawHashSource,
368
372
  applyResult(source) {
369
373
  originalSource.source = source;
370
374
  },
@@ -465,8 +469,186 @@ function applyLinkedResults(linked, entries, onLinkedUpdate, onApplied) {
465
469
  }
466
470
  }
467
471
 
472
+ // src/bundlers/vite/js-precheck.ts
473
+ var FAST_JS_TRANSFORM_HINT_RE = /className\b|class\s*=|classList\.|\b(?:twMerge|clsx|classnames|cn|cva)\b|\[["'`]class["'`]\]|text-\[|bg-\[|\b(?:[whpm]|px|py|mx|my|rounded|flex|grid|gap)-/;
474
+ var DEPENDENCY_HINT_RE = /\bimport\s*[("'`{*]|\brequire\s*\(|\bexport\s+\*\s+from\s+["'`]|\bexport\s*\{[^}]*\}\s*from\s+["'`]/;
475
+ function shouldSkipViteJsTransform(rawSource, options) {
476
+ if (!rawSource) {
477
+ return true;
478
+ }
479
+ if (options?.alwaysEscape) {
480
+ return false;
481
+ }
482
+ if (options?.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) {
483
+ return false;
484
+ }
485
+ if (options?.wrapExpression) {
486
+ return false;
487
+ }
488
+ if (DEPENDENCY_HINT_RE.test(rawSource)) {
489
+ return false;
490
+ }
491
+ return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
492
+ }
493
+
468
494
  // src/bundlers/vite/generate-bundle.ts
495
+ function createEmptyMetric() {
496
+ return {
497
+ total: 0,
498
+ transformed: 0,
499
+ cacheHits: 0,
500
+ elapsed: 0
501
+ };
502
+ }
503
+ function createEmptyMetrics() {
504
+ return {
505
+ runtimeSet: 0,
506
+ html: createEmptyMetric(),
507
+ js: createEmptyMetric(),
508
+ css: createEmptyMetric()
509
+ };
510
+ }
511
+ function classifyEntry(file, opts) {
512
+ if (opts.cssMatcher(file)) {
513
+ return "css";
514
+ }
515
+ if (opts.htmlMatcher(file)) {
516
+ return "html";
517
+ }
518
+ if (opts.jsMatcher(file) || opts.wxsMatcher(file)) {
519
+ return "js";
520
+ }
521
+ return "other";
522
+ }
523
+ function readEntrySource(output) {
524
+ if (output.type === "chunk") {
525
+ return output.code;
526
+ }
527
+ return output.source.toString();
528
+ }
529
+ function toJsAbsoluteFilename(file, outDir) {
530
+ return toAbsoluteOutputPath(file, outDir);
531
+ }
532
+ function computeDirtyEntries(entries, opts, state) {
533
+ const nextSourceHashByFile = /* @__PURE__ */ new Map();
534
+ const changedByType = {
535
+ html: /* @__PURE__ */ new Set(),
536
+ js: /* @__PURE__ */ new Set(),
537
+ css: /* @__PURE__ */ new Set(),
538
+ other: /* @__PURE__ */ new Set()
539
+ };
540
+ for (const [file, output] of entries) {
541
+ const type = classifyEntry(file, opts);
542
+ const source = readEntrySource(output);
543
+ const hash = opts.cache.computeHash(source);
544
+ nextSourceHashByFile.set(file, hash);
545
+ const previousHash = state.previousSourceHashByFile.get(file);
546
+ if (previousHash == null || previousHash !== hash) {
547
+ changedByType[type].add(file);
548
+ }
549
+ }
550
+ return {
551
+ sourceHashByFile: nextSourceHashByFile,
552
+ changedByType
553
+ };
554
+ }
555
+ function buildProcessSets(entries, opts, changedByType, previousLinkedByEntry, forceAll = false) {
556
+ const processFiles = {
557
+ html: /* @__PURE__ */ new Set(),
558
+ js: /* @__PURE__ */ new Set(),
559
+ css: /* @__PURE__ */ new Set()
560
+ };
561
+ const linkedImpactsByEntry = /* @__PURE__ */ new Map();
562
+ if (forceAll) {
563
+ for (const [file] of entries) {
564
+ const type = classifyEntry(file, opts);
565
+ if (type === "html" || type === "js" || type === "css") {
566
+ processFiles[type].add(file);
567
+ }
568
+ }
569
+ return {
570
+ files: processFiles,
571
+ linkedImpactsByEntry
572
+ };
573
+ }
574
+ const firstRun = previousLinkedByEntry.size === 0;
575
+ if (firstRun) {
576
+ for (const [file] of entries) {
577
+ const type = classifyEntry(file, opts);
578
+ if (type === "html" || type === "js" || type === "css") {
579
+ processFiles[type].add(file);
580
+ }
581
+ }
582
+ return {
583
+ files: processFiles,
584
+ linkedImpactsByEntry
585
+ };
586
+ }
587
+ for (const file of changedByType.html) {
588
+ processFiles.html.add(file);
589
+ }
590
+ for (const file of changedByType.css) {
591
+ processFiles.css.add(file);
592
+ }
593
+ for (const file of changedByType.js) {
594
+ processFiles.js.add(file);
595
+ }
596
+ for (const changedFile of changedByType.js) {
597
+ for (const [entryFile, linkedFiles] of previousLinkedByEntry.entries()) {
598
+ if (linkedFiles.has(changedFile)) {
599
+ processFiles.js.add(entryFile);
600
+ let impacts = linkedImpactsByEntry.get(entryFile);
601
+ if (!impacts) {
602
+ impacts = /* @__PURE__ */ new Set();
603
+ linkedImpactsByEntry.set(entryFile, impacts);
604
+ }
605
+ impacts.add(changedFile);
606
+ }
607
+ }
608
+ }
609
+ return {
610
+ files: processFiles,
611
+ linkedImpactsByEntry
612
+ };
613
+ }
614
+ function measureElapsed(start) {
615
+ return performance.now() - start;
616
+ }
617
+ function formatCacheHitRate(metric) {
618
+ if (metric.total === 0) {
619
+ return "0.00%";
620
+ }
621
+ return `${(metric.cacheHits / metric.total * 100).toFixed(2)}%`;
622
+ }
623
+ function createLinkedImpactSignature(entry, linkedImpactsByEntry, sourceHashByFile) {
624
+ const changedLinkedFiles = linkedImpactsByEntry.get(entry);
625
+ if (!changedLinkedFiles || changedLinkedFiles.size === 0) {
626
+ return void 0;
627
+ }
628
+ const parts = [...changedLinkedFiles].sort().map((file) => {
629
+ const hash = sourceHashByFile.get(file) ?? "missing";
630
+ return `${file}:${hash}`;
631
+ });
632
+ return parts.join(",");
633
+ }
634
+ function createJsHashSalt(runtimeSignature, linkedImpactSignature) {
635
+ if (!linkedImpactSignature) {
636
+ return runtimeSignature;
637
+ }
638
+ return `${runtimeSignature}:linked:${linkedImpactSignature}`;
639
+ }
469
640
  function createGenerateBundleHook(context) {
641
+ const state = {
642
+ iteration: 0,
643
+ previousSourceHashByFile: /* @__PURE__ */ new Map(),
644
+ previousLinkedByEntry: /* @__PURE__ */ new Map(),
645
+ changedByType: {
646
+ html: /* @__PURE__ */ new Set(),
647
+ js: /* @__PURE__ */ new Set(),
648
+ css: /* @__PURE__ */ new Set(),
649
+ other: /* @__PURE__ */ new Set()
650
+ }
651
+ };
470
652
  return async function generateBundle(_opt, bundle) {
471
653
  const {
472
654
  opts,
@@ -490,7 +672,14 @@ function createGenerateBundleHook(context) {
490
672
  await runtimeState.patchPromise;
491
673
  debug2("start");
492
674
  onStart();
675
+ const metrics = createEmptyMetrics();
676
+ const forceRuntimeRefresh = process2.env.WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH === "1";
677
+ const disableDirtyOptimization = process2.env.WEAPP_TW_VITE_DISABLE_DIRTY === "1";
678
+ const disableJsPrecheck = process2.env.WEAPP_TW_VITE_DISABLE_JS_PRECHECK === "1";
493
679
  const entries = Object.entries(bundle);
680
+ const dirtyEntries = computeDirtyEntries(entries, opts, state);
681
+ const processSets = buildProcessSets(entries, opts, dirtyEntries.changedByType, state.previousLinkedByEntry, disableDirtyOptimization);
682
+ const processFiles = processSets.files;
494
683
  const resolvedConfig = getResolvedConfig();
495
684
  const rootDir = resolvedConfig?.root ? path2.resolve(resolvedConfig.root) : process2.cwd();
496
685
  const outDir = resolvedConfig?.build?.outDir ? path2.resolve(rootDir, resolvedConfig.build.outDir) : rootDir;
@@ -498,14 +687,16 @@ function createGenerateBundleHook(context) {
498
687
  for (const [fileName, output] of entries) {
499
688
  const entry = { fileName, output };
500
689
  if (isJavaScriptEntry(entry)) {
501
- const absolute = toAbsoluteOutputPath(fileName, outDir);
690
+ const absolute = toJsAbsoluteFilename(fileName, outDir);
502
691
  jsEntries.set(absolute, entry);
503
692
  }
504
693
  }
505
694
  const moduleGraphOptions = createBundleModuleGraphOptions(outDir, jsEntries);
506
- const groupedEntries = getGroupedEntries(entries, opts);
507
- const runtime = await ensureRuntimeClassSet(true);
695
+ const runtimeStart = performance.now();
696
+ const runtime = await ensureRuntimeClassSet(forceRuntimeRefresh);
697
+ metrics.runtimeSet = measureElapsed(runtimeStart);
508
698
  debug2("get runtimeSet, class count: %d", runtime.size);
699
+ const runtimeSignature = getRuntimeClassSetSignature(runtimeState.twPatcher) ?? "runtime:missing";
509
700
  const handleLinkedUpdate = (fileName, previous, next) => {
510
701
  onUpdate(fileName, previous, next);
511
702
  debug2("js linked handle: %s", fileName);
@@ -532,25 +723,37 @@ function createGenerateBundleHook(context) {
532
723
  sourceFilename: absoluteFilename
533
724
  }
534
725
  });
726
+ const linkedByEntry = /* @__PURE__ */ new Map();
535
727
  const tasks = [];
536
- if (Array.isArray(groupedEntries.html)) {
537
- for (const [file, originalSource] of groupedEntries.html) {
728
+ const jsTaskFactories = [];
729
+ for (const [file, originalSource] of entries) {
730
+ const type = classifyEntry(file, opts);
731
+ if (type === "html" && originalSource.type === "asset") {
732
+ metrics.html.total++;
733
+ if (!processFiles.html.has(file)) {
734
+ continue;
735
+ }
538
736
  const rawSource = originalSource.source.toString();
539
737
  tasks.push(
540
738
  processCachedTask({
541
739
  cache,
542
740
  cacheKey: file,
543
741
  rawSource,
742
+ hashKey: `${file}:html:${runtimeSignature}`,
544
743
  applyResult(source) {
545
744
  originalSource.source = source;
546
745
  },
547
746
  onCacheHit() {
747
+ metrics.html.cacheHits++;
548
748
  debug2("html cache hit: %s", file);
549
749
  },
550
750
  async transform() {
751
+ const start = performance.now();
551
752
  const transformed = await templateHandler(rawSource, {
552
753
  runtimeSet: runtime
553
754
  });
755
+ metrics.html.elapsed += measureElapsed(start);
756
+ metrics.html.transformed++;
554
757
  onUpdate(file, rawSource, transformed);
555
758
  debug2("html handle: %s", file);
556
759
  return {
@@ -559,73 +762,29 @@ function createGenerateBundleHook(context) {
559
762
  }
560
763
  })
561
764
  );
765
+ continue;
562
766
  }
563
- }
564
- const jsTaskFactories = [];
565
- if (Array.isArray(groupedEntries.js)) {
566
- for (const [file, originalSource] of groupedEntries.js) {
567
- if (originalSource.type === "chunk") {
568
- const absoluteFile = toAbsoluteOutputPath(file, outDir);
569
- const initialRawSource = originalSource.code;
570
- jsTaskFactories.push(async () => {
571
- await processCachedTask({
572
- cache,
573
- cacheKey: file,
574
- rawSource: initialRawSource,
575
- applyResult(source) {
576
- originalSource.code = source;
577
- },
578
- onCacheHit() {
579
- debug2("js cache hit: %s", file);
580
- },
581
- async transform() {
582
- const rawSource = originalSource.code;
583
- const { code, linked } = await jsHandler(rawSource, runtime, createHandlerOptions(absoluteFile));
584
- onUpdate(file, rawSource, code);
585
- debug2("js handle: %s", file);
586
- applyLinkedUpdates(linked);
587
- return {
588
- result: code
589
- };
590
- }
591
- });
592
- });
593
- } else if (uniAppX && originalSource.type === "asset") {
594
- jsTaskFactories.push(
595
- createUniAppXAssetTask(
596
- file,
597
- originalSource,
598
- outDir,
599
- {
600
- cache,
601
- createHandlerOptions,
602
- debug: debug2,
603
- jsHandler,
604
- onUpdate,
605
- runtimeSet: runtime,
606
- applyLinkedResults: applyLinkedUpdates,
607
- uniAppX
608
- }
609
- )
610
- );
767
+ if (type === "css" && originalSource.type === "asset") {
768
+ metrics.css.total++;
769
+ if (!processFiles.css.has(file)) {
770
+ continue;
611
771
  }
612
- }
613
- }
614
- if (Array.isArray(groupedEntries.css)) {
615
- for (const [file, originalSource] of groupedEntries.css) {
616
772
  const rawSource = originalSource.source.toString();
617
773
  tasks.push(
618
774
  processCachedTask({
619
775
  cache,
620
776
  cacheKey: file,
621
777
  rawSource,
778
+ hashKey: `${file}:css:${runtimeSignature}:${runtimeState.twPatcher.majorVersion ?? "unknown"}`,
622
779
  applyResult(source) {
623
780
  originalSource.source = source;
624
781
  },
625
782
  onCacheHit() {
783
+ metrics.css.cacheHits++;
626
784
  debug2("css cache hit: %s", file);
627
785
  },
628
786
  async transform() {
787
+ const start = performance.now();
629
788
  await runtimeState.patchPromise;
630
789
  const { css } = await styleHandler(rawSource, {
631
790
  isMainChunk: mainCssChunkMatcher(originalSource.fileName, appType),
@@ -636,6 +795,8 @@ function createGenerateBundleHook(context) {
636
795
  },
637
796
  majorVersion: runtimeState.twPatcher.majorVersion
638
797
  });
798
+ metrics.css.elapsed += measureElapsed(start);
799
+ metrics.css.transformed++;
639
800
  onUpdate(file, rawSource, css);
640
801
  debug2("css handle: %s", file);
641
802
  return {
@@ -644,6 +805,130 @@ function createGenerateBundleHook(context) {
644
805
  }
645
806
  })
646
807
  );
808
+ continue;
809
+ }
810
+ if (type !== "js") {
811
+ continue;
812
+ }
813
+ metrics.js.total++;
814
+ if (!processFiles.js.has(file)) {
815
+ continue;
816
+ }
817
+ if (originalSource.type === "chunk") {
818
+ const absoluteFile = toJsAbsoluteFilename(file, outDir);
819
+ const initialRawSource = originalSource.code;
820
+ const linkedSet = /* @__PURE__ */ new Set();
821
+ linkedByEntry.set(file, linkedSet);
822
+ jsTaskFactories.push(async () => {
823
+ const linkedImpactSignature = createLinkedImpactSignature(
824
+ file,
825
+ processSets.linkedImpactsByEntry,
826
+ dirtyEntries.sourceHashByFile
827
+ );
828
+ const hashSalt = createJsHashSalt(runtimeSignature, linkedImpactSignature);
829
+ await processCachedTask({
830
+ cache,
831
+ cacheKey: file,
832
+ hashKey: `${file}:js`,
833
+ rawSource: `${initialRawSource}
834
+ /*${hashSalt}*/`,
835
+ applyResult(source) {
836
+ originalSource.code = source;
837
+ },
838
+ onCacheHit() {
839
+ metrics.js.cacheHits++;
840
+ debug2("js cache hit: %s", file);
841
+ },
842
+ async transform() {
843
+ const start = performance.now();
844
+ const rawSource = originalSource.code;
845
+ const handlerOptions = createHandlerOptions(absoluteFile);
846
+ if (!disableJsPrecheck && shouldSkipViteJsTransform(rawSource, handlerOptions)) {
847
+ metrics.js.elapsed += measureElapsed(start);
848
+ metrics.js.transformed++;
849
+ return {
850
+ result: rawSource
851
+ };
852
+ }
853
+ const { code, linked } = await jsHandler(rawSource, runtime, handlerOptions);
854
+ metrics.js.elapsed += measureElapsed(start);
855
+ metrics.js.transformed++;
856
+ onUpdate(file, rawSource, code);
857
+ debug2("js handle: %s", file);
858
+ if (linked) {
859
+ for (const id of Object.keys(linked)) {
860
+ const linkedEntry = jsEntries.get(id);
861
+ if (linkedEntry) {
862
+ linkedSet.add(linkedEntry.fileName);
863
+ }
864
+ }
865
+ }
866
+ applyLinkedUpdates(linked);
867
+ return {
868
+ result: code
869
+ };
870
+ }
871
+ });
872
+ });
873
+ } else if (uniAppX && originalSource.type === "asset") {
874
+ const linkedSet = /* @__PURE__ */ new Set();
875
+ linkedByEntry.set(file, linkedSet);
876
+ const baseApplyLinkedUpdates = applyLinkedUpdates;
877
+ const wrappedApplyLinkedUpdates = (linked) => {
878
+ if (linked) {
879
+ for (const id of Object.keys(linked)) {
880
+ const linkedEntry = jsEntries.get(id);
881
+ if (linkedEntry) {
882
+ linkedSet.add(linkedEntry.fileName);
883
+ }
884
+ }
885
+ }
886
+ baseApplyLinkedUpdates(linked);
887
+ };
888
+ const factory = createUniAppXAssetTask(
889
+ file,
890
+ originalSource,
891
+ outDir,
892
+ {
893
+ cache,
894
+ hashKey: `${file}:js`,
895
+ hashSalt: createJsHashSalt(
896
+ runtimeSignature,
897
+ createLinkedImpactSignature(
898
+ file,
899
+ processSets.linkedImpactsByEntry,
900
+ dirtyEntries.sourceHashByFile
901
+ )
902
+ ),
903
+ createHandlerOptions,
904
+ debug: debug2,
905
+ jsHandler,
906
+ onUpdate,
907
+ runtimeSet: runtime,
908
+ applyLinkedResults: wrappedApplyLinkedUpdates,
909
+ uniAppX
910
+ }
911
+ );
912
+ jsTaskFactories.push(async () => {
913
+ const start = performance.now();
914
+ const currentSource = originalSource.source.toString();
915
+ const absoluteFile = toJsAbsoluteFilename(file, outDir);
916
+ const precheckOptions = createHandlerOptions(absoluteFile, {
917
+ uniAppX: uniAppX ?? true,
918
+ babelParserOptions: {
919
+ plugins: ["typescript"],
920
+ sourceType: "unambiguous"
921
+ }
922
+ });
923
+ if (!disableJsPrecheck && shouldSkipViteJsTransform(currentSource, precheckOptions)) {
924
+ metrics.js.elapsed += measureElapsed(start);
925
+ metrics.js.transformed++;
926
+ return;
927
+ }
928
+ await factory();
929
+ metrics.js.elapsed += measureElapsed(start);
930
+ metrics.js.transformed++;
931
+ });
647
932
  }
648
933
  }
649
934
  pushConcurrentTaskFactories(tasks, jsTaskFactories);
@@ -651,6 +936,44 @@ function createGenerateBundleHook(context) {
651
936
  for (const apply of pendingLinkedUpdates) {
652
937
  apply();
653
938
  }
939
+ state.iteration += 1;
940
+ const finalSourceHashByFile = /* @__PURE__ */ new Map();
941
+ for (const [fileName, output] of entries) {
942
+ finalSourceHashByFile.set(fileName, opts.cache.computeHash(readEntrySource(output)));
943
+ }
944
+ state.previousSourceHashByFile = finalSourceHashByFile;
945
+ state.changedByType = dirtyEntries.changedByType;
946
+ const nextLinkedByEntry = new Map(state.previousLinkedByEntry);
947
+ for (const [entryFile, linkedFiles] of linkedByEntry.entries()) {
948
+ nextLinkedByEntry.set(entryFile, linkedFiles);
949
+ }
950
+ for (const entryFile of [...nextLinkedByEntry.keys()]) {
951
+ const exists = entries.some(([fileName]) => fileName === entryFile);
952
+ if (!exists) {
953
+ nextLinkedByEntry.delete(entryFile);
954
+ }
955
+ }
956
+ state.previousLinkedByEntry = nextLinkedByEntry;
957
+ debug2(
958
+ "metrics iteration=%d runtime=%.2fms html(total=%d transform=%d hit=%d rate=%s elapsed=%.2fms) js(total=%d transform=%d hit=%d rate=%s elapsed=%.2fms) css(total=%d transform=%d hit=%d rate=%s elapsed=%.2fms)",
959
+ state.iteration,
960
+ metrics.runtimeSet,
961
+ metrics.html.total,
962
+ metrics.html.transformed,
963
+ metrics.html.cacheHits,
964
+ formatCacheHitRate(metrics.html),
965
+ metrics.html.elapsed,
966
+ metrics.js.total,
967
+ metrics.js.transformed,
968
+ metrics.js.cacheHits,
969
+ formatCacheHitRate(metrics.js),
970
+ metrics.js.elapsed,
971
+ metrics.css.total,
972
+ metrics.css.transformed,
973
+ metrics.css.cacheHits,
974
+ formatCacheHitRate(metrics.css),
975
+ metrics.css.elapsed
976
+ );
654
977
  onEnd();
655
978
  debug2("end");
656
979
  };
@@ -763,23 +1086,56 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
763
1086
  let runtimeSet;
764
1087
  let runtimeSetPromise;
765
1088
  let resolvedConfig;
1089
+ let runtimeRefreshSignature;
1090
+ let runtimeRefreshOptionsKey;
1091
+ function resolveRuntimeRefreshOptions() {
1092
+ const configPath = runtimeState.twPatcher.options?.tailwind?.config;
1093
+ const signature = getRuntimeClassSetSignature(runtimeState.twPatcher);
1094
+ const optionsKey = JSON.stringify({
1095
+ appType,
1096
+ uniAppX: Boolean(uniAppX),
1097
+ customAttributesEntities,
1098
+ disabledDefaultTemplateHandler,
1099
+ configPath,
1100
+ rewriteCssImports: shouldRewriteCssImports
1101
+ });
1102
+ const changed = signature !== runtimeRefreshSignature || optionsKey !== runtimeRefreshOptionsKey;
1103
+ runtimeRefreshSignature = signature;
1104
+ runtimeRefreshOptionsKey = optionsKey;
1105
+ return {
1106
+ changed,
1107
+ signature,
1108
+ optionsKey
1109
+ };
1110
+ }
766
1111
  async function refreshRuntimeState(force) {
767
- const refreshed = await refreshTailwindRuntimeState(runtimeState, force);
1112
+ const invalidation = resolveRuntimeRefreshOptions();
1113
+ const shouldRefresh = force || invalidation.changed;
1114
+ const refreshed = await refreshTailwindRuntimeState(runtimeState, {
1115
+ force: shouldRefresh,
1116
+ clearCache: force || invalidation.changed
1117
+ });
1118
+ if (invalidation.changed) {
1119
+ debug("runtime signature changed, refresh triggered. signature: %s", invalidation.signature);
1120
+ }
768
1121
  if (refreshed) {
769
1122
  runtimeSet = void 0;
770
1123
  runtimeSetPromise = void 0;
771
1124
  }
772
1125
  }
773
1126
  async function ensureRuntimeClassSet(force = false) {
1127
+ const forceRuntimeRefresh = force || process3.env.WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH === "1";
774
1128
  await refreshRuntimeState(force);
775
1129
  await runtimeState.patchPromise;
776
- if (!force && runtimeSet) {
1130
+ if (!forceRuntimeRefresh && runtimeSet) {
777
1131
  return runtimeSet;
778
1132
  }
779
- if (force || !runtimeSetPromise) {
1133
+ if (forceRuntimeRefresh || !runtimeSetPromise) {
1134
+ const invalidation = resolveRuntimeRefreshOptions();
780
1135
  const task2 = collectRuntimeClassSet(runtimeState.twPatcher, {
781
- force: force || !runtimeSet,
782
- skipRefresh: force
1136
+ force: forceRuntimeRefresh || invalidation.changed,
1137
+ skipRefresh: forceRuntimeRefresh,
1138
+ clearCache: forceRuntimeRefresh || invalidation.changed
783
1139
  });
784
1140
  runtimeSetPromise = task2;
785
1141
  }