weapp-tailwindcss 5.0.0-next.3 → 5.0.0-next.5

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 (95) hide show
  1. package/README.md +4 -5
  2. package/bin/weapp-tailwindcss.js +1 -21
  3. package/dist/bundlers/shared/generator-css.d.ts +5 -2
  4. package/dist/bundlers/vite/generate-bundle.d.ts +1 -0
  5. package/dist/bundlers/vite/index.d.ts +1 -1
  6. package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
  7. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +0 -1
  8. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +1 -1
  9. package/dist/cli/context.d.ts +0 -3
  10. package/dist/cli/mount-options.d.ts +2 -0
  11. package/dist/cli.js +8 -2
  12. package/dist/cli.mjs +8 -2
  13. package/dist/constants.d.ts +1 -1
  14. package/dist/core.js +1 -1
  15. package/dist/core.mjs +1 -1
  16. package/dist/css-macro.d.ts +1 -0
  17. package/dist/defaults.js +5 -7
  18. package/dist/defaults.mjs +5 -7
  19. package/dist/generator/index.d.ts +1 -1
  20. package/dist/generator/options.d.ts +3 -4
  21. package/dist/{generator-mmhXzZnv.js → generator-9UEp8OoQ.js} +259 -21
  22. package/dist/{generator-Y-Ikv4Fu.mjs → generator-Dpp-5s8z.mjs} +260 -22
  23. package/dist/{generator-css-CRLrHW4F.js → generator-css-CGueCYbX.js} +173 -32
  24. package/dist/{generator-css-Bwy_Uz89.mjs → generator-css-MyjZhF0z.mjs} +173 -32
  25. package/dist/generator.js +1 -1
  26. package/dist/generator.mjs +1 -1
  27. package/dist/gulp.js +15 -11
  28. package/dist/gulp.mjs +15 -11
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +4 -4
  31. package/dist/index.mjs +4 -4
  32. package/dist/js/index.d.ts +1 -0
  33. package/dist/js/literal-transform.d.ts +2 -0
  34. package/dist/{logger-BoVx1Dbt.mjs → logger-1gx9UllH.mjs} +21 -51
  35. package/dist/{logger-BZ45DZJT.js → logger-D9clu_3f.js} +21 -51
  36. package/dist/patcher-options-DnqazL9E.js +34 -0
  37. package/dist/patcher-options-GuOwX0-k.mjs +17 -0
  38. package/dist/postcss.d.ts +2 -2
  39. package/dist/postcss.js +37 -28
  40. package/dist/postcss.mjs +37 -28
  41. package/dist/presets.js +1 -1
  42. package/dist/presets.mjs +1 -1
  43. package/dist/{recorder-XdFvVASS.mjs → recorder-BIW3Kuke.mjs} +5 -12
  44. package/dist/{recorder-GdTJ3QqX.js → recorder-D4BKt75Q.js} +5 -12
  45. package/dist/reset.d.ts +1 -0
  46. package/dist/{css-imports-BbrbluP9.js → run-tasks-Cq5A5nVD.js} +6 -55
  47. package/dist/{css-imports-CSdPq_Sc.mjs → run-tasks-DUVrDJGl.mjs} +5 -42
  48. package/dist/tailwindcss/miniprogram.d.ts +5 -1
  49. package/dist/tailwindcss/patcher-options.d.ts +3 -51
  50. package/dist/tailwindcss/patcher.d.ts +1 -2
  51. package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
  52. package/dist/tailwindcss/v4/patcher.d.ts +1 -0
  53. package/dist/tailwindcss/v4-engine/types.d.ts +1 -1
  54. package/dist/tailwindcss/version.d.ts +4 -0
  55. package/dist/typedoc.export.d.ts +0 -2
  56. package/dist/types/index.d.ts +1 -3
  57. package/dist/types/shared.d.ts +3 -0
  58. package/dist/types/user-defined-options/general.d.ts +0 -2
  59. package/dist/types/user-defined-options/important.d.ts +3 -3
  60. package/dist/utils/disabled.d.ts +2 -3
  61. package/dist/version-CWBxRFPB.js +56 -0
  62. package/dist/version-WNz3MwRv.mjs +49 -0
  63. package/dist/{vite-DgRh_GXn.js → vite-BkMGwDeH.js} +106 -39
  64. package/dist/{vite-BDywuCjn.mjs → vite-fDM-UQpR.mjs} +89 -22
  65. package/dist/vite.d.ts +1 -2
  66. package/dist/vite.js +3 -4
  67. package/dist/vite.mjs +2 -2
  68. package/dist/weapp-tw-css-import-rewrite-loader.js +1 -1
  69. package/dist/{webpack-CAJR4hhP.js → webpack-CICGEKT9.js} +225 -43
  70. package/dist/{webpack-CiHqVZTg.mjs → webpack-D2Wdk28V.mjs} +214 -27
  71. package/dist/webpack.js +1 -1
  72. package/dist/webpack.mjs +1 -1
  73. package/package.json +21 -30
  74. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
  75. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
  76. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
  77. package/dist/experimental/index.d.ts +0 -2
  78. package/dist/experimental/oxc/ast-utils.d.ts +0 -30
  79. package/dist/experimental/oxc/index.d.ts +0 -2
  80. package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
  81. package/dist/experimental/shared/cache.d.ts +0 -3
  82. package/dist/experimental/shared/transform.d.ts +0 -3
  83. package/dist/experimental/shared.d.ts +0 -8
  84. package/dist/experimental/swc/ast-utils.d.ts +0 -30
  85. package/dist/experimental/swc/index.d.ts +0 -2
  86. package/dist/experimental/swc/module-specifiers.d.ts +0 -2
  87. package/dist/loader-anchors-1MumTAtA.mjs +0 -205
  88. package/dist/loader-anchors-TrFvT6g1.js +0 -273
  89. package/dist/patcher-options-6gJN2EXy.js +0 -115
  90. package/dist/patcher-options-DQfR5xxT.mjs +0 -92
  91. package/dist/types/disabled-options.d.ts +0 -4
  92. package/dist/webpack4.d.ts +0 -4
  93. package/dist/webpack4.js +0 -387
  94. package/dist/webpack4.mjs +0 -379
  95. package/scripts/postinstall.mjs +0 -59
@@ -1,5 +1,5 @@
1
- import { a as resolveTailwindV4Source, c as resolveTailwindV4SourceOptionsFromPatcher, h as resolveTailwindV3SourceOptionsFromPatcher, i as normalizeWeappTailwindcssGeneratorOptions, m as resolveTailwindV3SourceFromPatcher, p as resolveTailwindV3Source, s as resolveTailwindV4SourceFromPatcher, t as createWeappTailwindcssGenerator, v as removeUnsupportedCascadeLayers } from "./generator-Y-Ikv4Fu.mjs";
2
- import { l as replaceWxml } from "./recorder-XdFvVASS.mjs";
1
+ import { a as resolveTailwindV4Source, c as resolveTailwindV4SourceOptionsFromPatcher, h as resolveTailwindV3SourceOptionsFromPatcher, i as normalizeWeappTailwindcssGeneratorOptions, m as resolveTailwindV3SourceFromPatcher, p as resolveTailwindV3Source, s as resolveTailwindV4SourceFromPatcher, t as createWeappTailwindcssGenerator, v as removeUnsupportedCascadeLayers } from "./generator-Dpp-5s8z.mjs";
2
+ import { l as replaceWxml } from "./recorder-BIW3Kuke.mjs";
3
3
  import postcss from "postcss";
4
4
  import path from "node:path";
5
5
  import process from "node:process";
@@ -162,7 +162,7 @@ function removeUnsupportedMiniProgramAtRules(css) {
162
162
  if (MINI_PROGRAM_UNSUPPORTED_AT_RULES.has(atRule.name)) atRule.remove();
163
163
  });
164
164
  root.walkAtRules((atRule) => {
165
- if (!atRule.nodes || atRule.nodes.length === 0) atRule.remove();
165
+ if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
166
166
  });
167
167
  return root.toString();
168
168
  } catch {
@@ -563,6 +563,10 @@ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
563
563
  }
564
564
  }
565
565
  function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
566
+ const tailwindV3StyleOptions = cssHandlerOptions.majorVersion === 3 ? {
567
+ cssPreflight: opts.cssPreflight,
568
+ cssPreflightRange: opts.cssPreflightRange
569
+ } : {};
566
570
  return {
567
571
  cssChildCombinatorReplaceValue: opts.cssChildCombinatorReplaceValue,
568
572
  cssSelectorReplacement: opts.cssSelectorReplacement,
@@ -579,6 +583,7 @@ function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOpt
579
583
  uniAppXCssTarget: opts.uniAppXCssTarget,
580
584
  uniAppXUnsupported: opts.uniAppXUnsupported,
581
585
  ...cssHandlerOptions,
586
+ ...tailwindV3StyleOptions,
582
587
  ...generatorStyleOptions
583
588
  };
584
589
  }
@@ -588,6 +593,9 @@ function parseImportRequest(params) {
588
593
  function parseConfigRequest(params) {
589
594
  return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
590
595
  }
596
+ function isPackageJsonImportRequest(request) {
597
+ return typeof request === "string" && request.startsWith("#");
598
+ }
591
599
  function resolvePostcssFromOption(cssHandlerOptions) {
592
600
  const from = cssHandlerOptions.postcssOptions?.options?.from;
593
601
  return typeof from === "string" && from.length > 0 ? from : void 0;
@@ -605,11 +613,13 @@ function isTailwindImportAtRule(node) {
605
613
  function isTailwindSourceDirective(node) {
606
614
  if (node.type !== "atrule") return false;
607
615
  if (isTailwindImportAtRule(node)) return true;
616
+ if (node.name === "import" && isPackageJsonImportRequest(parseImportRequest(node.params))) return true;
608
617
  return TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES.has(node.name);
609
618
  }
610
619
  function isTailwindGenerationDirective(node) {
611
620
  if (node.type !== "atrule") return false;
612
- return isTailwindImportAtRule(node) || node.name === "layer" || node.name === "config";
621
+ const request = node.name === "import" ? parseImportRequest(node.params) : node.name === "config" || node.name === "plugin" || node.name === "reference" ? parseConfigRequest(node.params) : void 0;
622
+ return isTailwindImportAtRule(node) || isPackageJsonImportRequest(request) || node.name === "apply" || node.name === "layer" || node.name === "config" || node.name === "source";
613
623
  }
614
624
  function removeTailwindSourceDirectives(rawSource) {
615
625
  try {
@@ -657,7 +667,7 @@ function resolveCssEntrySource(rawSource, base, options = {}) {
657
667
  const configPath = parseConfigRequest(node.params);
658
668
  if (configPath && !config) {
659
669
  configRequest = configPath;
660
- config = path.isAbsolute(configPath) ? configPath : path.resolve(base, configPath);
670
+ config = isPackageJsonImportRequest(configPath) ? void 0 : path.isAbsolute(configPath) ? configPath : path.resolve(base, configPath);
661
671
  }
662
672
  if (removeConfig) {
663
673
  node.remove();
@@ -696,6 +706,20 @@ function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
696
706
  }
697
707
  return sourceOptions.config;
698
708
  }
709
+ function quoteCssString(value) {
710
+ return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
711
+ }
712
+ function toCssPath(value) {
713
+ return value.replaceAll("\\", "/");
714
+ }
715
+ function prependConfigDirective(css, config) {
716
+ if (!config || /@config\s+/.test(css)) return css;
717
+ return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
718
+ }
719
+ function normalizeConfigDirective(css, config) {
720
+ if (!config || !/@config\s+/.test(css)) return css;
721
+ return css.replace(/@config\s+(["'])(.+?)\1\s*;?/, `@config "${quoteCssString(toCssPath(config))}";`);
722
+ }
699
723
  function stripStyleExtension(file) {
700
724
  return file.replace(/[?#].*$/, "").replace(/\.(?:wx|ac|jx|tt|q|c|ty)?ss$/i, "");
701
725
  }
@@ -737,6 +761,11 @@ function createSourceStylePathCandidates(file, sourceOptions) {
737
761
  }
738
762
  return [...candidates];
739
763
  }
764
+ function canResolveSourceSideCssEntry(file, cssHandlerOptions) {
765
+ const from = resolvePostcssFromOption(cssHandlerOptions);
766
+ if (!from || !path.isAbsolute(from)) return path.isAbsolute(file);
767
+ return true;
768
+ }
740
769
  function extractStyleDirectiveSources(source) {
741
770
  const styleSources = [];
742
771
  SFC_STYLE_BLOCK_RE.lastIndex = 0;
@@ -766,6 +795,34 @@ function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {
766
795
  }
767
796
  }
768
797
  }
798
+ function normalizeCssSourceForCompare(css) {
799
+ return stripGeneratorPlaceholderMarkers(stripTailwindBanners(css)).trim();
800
+ }
801
+ function getOutputFileStem(file) {
802
+ const normalized = file.replace(/[?#].*$/, "");
803
+ return path.basename(normalized, path.extname(normalized));
804
+ }
805
+ function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
806
+ const cssEntries = sourceOptions.cssEntries;
807
+ if (!cssEntries?.length) return;
808
+ const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
809
+ const outputStem = getOutputFileStem(file);
810
+ const matchingEntry = cssEntries.find((cssEntry) => {
811
+ if (!existsSync(cssEntry)) return false;
812
+ try {
813
+ if (normalizeCssSourceForCompare(readFileSync(cssEntry, "utf8")) === normalizedRawSource) return true;
814
+ return outputStem.length > 0 && getOutputFileStem(cssEntry) === outputStem;
815
+ } catch {
816
+ return false;
817
+ }
818
+ });
819
+ if (!matchingEntry) return;
820
+ return resolveTailwindV4Source({
821
+ ...sourceOptions,
822
+ css: void 0,
823
+ cssEntries: [matchingEntry]
824
+ });
825
+ }
769
826
  function tryResolveTailwindV4SourceOptions(runtimeState) {
770
827
  try {
771
828
  return resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
@@ -773,16 +830,20 @@ function tryResolveTailwindV4SourceOptions(runtimeState) {
773
830
  return;
774
831
  }
775
832
  }
776
- async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions) {
833
+ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions) {
777
834
  const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), { removeConfig: majorVersion === 3 });
778
835
  if (majorVersion === 3) {
779
836
  const sourceOptions = resolveTailwindV3SourceOptionsFromPatcher(runtimeState.twPatcher);
780
- const sourceSideEntrySource = resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: true });
837
+ const mergedSourceOptions = {
838
+ ...sourceOptions,
839
+ config: generatorOptions?.config ?? sourceOptions.config
840
+ };
841
+ const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
781
842
  const resolvedEntrySource = cssEntrySource ?? sourceSideEntrySource;
782
- if (!resolvedEntrySource) return resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
783
- const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, sourceOptions);
843
+ if (!resolvedEntrySource) return generatorOptions?.config ? resolveTailwindV3Source(mergedSourceOptions) : resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
844
+ const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, mergedSourceOptions);
784
845
  return resolveTailwindV3Source({
785
- ...sourceOptions,
846
+ ...mergedSourceOptions,
786
847
  base: resolvedEntrySource.base,
787
848
  css: resolvedEntrySource.css,
788
849
  ...config ? { config } : {}
@@ -790,29 +851,46 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
790
851
  }
791
852
  const sourceOptions = tryResolveTailwindV4SourceOptions(runtimeState);
792
853
  const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder"));
793
- const resolvedEntrySource = (sourceOptions && shouldPreferSourceSideEntry ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0) ?? cssEntrySource;
794
- if (!resolvedEntrySource) return resolveTailwindV4SourceFromPatcher(runtimeState.twPatcher);
854
+ const sourceSideEntrySource = sourceOptions && shouldPreferSourceSideEntry ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0;
855
+ const matchedCssEntrySource = sourceOptions && cssEntrySource ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
856
+ if (matchedCssEntrySource) return generatorOptions?.config ? {
857
+ ...matchedCssEntrySource,
858
+ css: prependConfigDirective(matchedCssEntrySource.css, generatorOptions.config)
859
+ } : matchedCssEntrySource;
860
+ const resolvedEntrySource = sourceSideEntrySource ?? cssEntrySource;
861
+ if (!resolvedEntrySource) {
862
+ const source = await resolveTailwindV4SourceFromPatcher(runtimeState.twPatcher);
863
+ return generatorOptions?.config ? {
864
+ ...source,
865
+ css: prependConfigDirective(source.css, generatorOptions.config)
866
+ } : source;
867
+ }
868
+ const resolvedSourceOptions = sourceOptions ?? {};
869
+ const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, resolvedSourceOptions);
795
870
  return resolveTailwindV4Source({
796
- ...sourceOptions ?? {},
871
+ ...resolvedSourceOptions,
797
872
  base: resolvedEntrySource.base,
798
- css: resolvedEntrySource.css
873
+ css: normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config)
799
874
  });
800
875
  }
801
- async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions) {
876
+ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions) {
802
877
  const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), { removeConfig: majorVersion === 3 });
803
- if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions)];
878
+ if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions)];
804
879
  let sourceOptions;
805
880
  try {
806
881
  sourceOptions = resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
807
882
  } catch {
808
- return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions)];
883
+ return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions)];
809
884
  }
810
- if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions)];
885
+ if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions)];
811
886
  return await Promise.all(sourceOptions.cssEntries.map((cssEntry) => resolveTailwindV4Source({
812
887
  ...sourceOptions,
813
888
  css: void 0,
814
889
  cssEntries: [cssEntry]
815
- })));
890
+ }).then((source) => generatorOptions?.config ? {
891
+ ...source,
892
+ css: prependConfigDirective(source.css, generatorOptions.config)
893
+ } : source)));
816
894
  }
817
895
  function isLocalImportRequest(request) {
818
896
  return request.length > 0 && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
@@ -833,8 +911,62 @@ function isPureLocalCssImportWrapper(css) {
833
911
  }
834
912
  return hasImport;
835
913
  }
914
+ function cleanLocalCssImportWrapperTailwindDirectives(css) {
915
+ let hasLocalImport = false;
916
+ let hasTailwindDirective = false;
917
+ try {
918
+ const root = postcss.parse(css);
919
+ for (const node of root.nodes) {
920
+ if (node.type === "comment") continue;
921
+ if (node.type === "atrule" && node.name === "import") {
922
+ const request = parseImportRequest(node.params);
923
+ if (!request || !isLocalImportRequest(request)) return;
924
+ hasLocalImport = true;
925
+ continue;
926
+ }
927
+ if (node.type === "atrule" && node.name === "source") {
928
+ hasTailwindDirective = true;
929
+ continue;
930
+ }
931
+ return;
932
+ }
933
+ } catch {
934
+ return;
935
+ }
936
+ return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(removeTailwindSourceDirectives(css)) : void 0;
937
+ }
938
+ function prefixLocalCssImportsWithWebpackIgnore(css) {
939
+ try {
940
+ const root = postcss.parse(css);
941
+ root.walkAtRules("import", (atRule) => {
942
+ const request = parseImportRequest(atRule.params);
943
+ if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
944
+ });
945
+ return root.toString();
946
+ } catch {
947
+ return css;
948
+ }
949
+ }
836
950
  function resolveLegacyCompatCssSource(rawSource) {
837
- return removeUnsupportedMiniProgramAtRules(removeTailwindSourceDirectives(stripTailwindBanners(rawSource)));
951
+ return removeUnsupportedMiniProgramAtRules(removeTailwindApplyRules(removeTailwindSourceDirectives(stripTailwindBanners(rawSource))));
952
+ }
953
+ function removeTailwindApplyRules(rawSource) {
954
+ try {
955
+ const root = postcss.parse(rawSource);
956
+ let removed = false;
957
+ root.walkAtRules("apply", (rule) => {
958
+ const parent = rule.parent;
959
+ if (parent?.type === "rule") parent.remove();
960
+ else rule.remove();
961
+ removed = true;
962
+ });
963
+ root.walkAtRules((rule) => {
964
+ if (rule.nodes && rule.nodes.length === 0) rule.remove();
965
+ });
966
+ return removed ? root.toString() : rawSource;
967
+ } catch {
968
+ return rawSource;
969
+ }
838
970
  }
839
971
  function hasContainerConfigToken(rawSource) {
840
972
  return rawSource.includes("@config") && /\bcontainer\b/.test(rawSource);
@@ -941,7 +1073,7 @@ function removeGeneratedSelectorCompatCss(css, generatedCss) {
941
1073
  }
942
1074
  });
943
1075
  root.walkAtRules((atRule) => {
944
- if (!atRule.nodes || atRule.nodes.length === 0) atRule.remove();
1076
+ if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
945
1077
  });
946
1078
  return removed ? root.toString() : css;
947
1079
  } catch {
@@ -1014,22 +1146,28 @@ async function generateCssByGenerator(options) {
1014
1146
  const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, styleHandler, debug } = options;
1015
1147
  const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
1016
1148
  const majorVersion = runtimeState.twPatcher.majorVersion;
1149
+ const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(rawSource);
1150
+ if (cleanedLocalImportWrapper !== void 0) return {
1151
+ css: generatorOptions.target === "weapp" ? removeUnsupportedMiniProgramAtRules(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
1152
+ target: generatorOptions.target,
1153
+ source: "generator",
1154
+ dependencies: []
1155
+ };
1017
1156
  if (isPureLocalCssImportWrapper(rawSource)) return;
1018
1157
  const hasGeneratedCss = hasTailwindGeneratedCss(rawSource);
1019
1158
  const hasSourceDirectives = hasTailwindSourceDirectives(rawSource);
1020
1159
  const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(rawSource);
1021
- const shouldForceGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
1022
- const shouldAutoGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives;
1023
- if (generatorOptions.mode === "off" || !SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || (generatorOptions.mode === "force" ? !shouldForceGenerateCurrentCss : !shouldAutoGenerateCurrentCss) || generatorOptions.mode === "force" && majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers || generatorOptions.mode !== "force" && majorVersion === 3) return;
1160
+ const shouldGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
1161
+ if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
1024
1162
  try {
1025
1163
  await runtimeState.patchPromise;
1026
- const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions);
1164
+ const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions);
1027
1165
  const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
1028
1166
  const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
1029
1167
  const generatedResults = await Promise.all(sources.map(async (source) => {
1030
1168
  return createWeappTailwindcssGenerator(source).generate({
1031
1169
  candidates: runtime,
1032
- scanSources: false,
1170
+ scanSources: majorVersion === 4,
1033
1171
  styleOptions: generatorStyleOptions,
1034
1172
  tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
1035
1173
  target: generatorOptions.target
@@ -1057,7 +1195,8 @@ async function generateCssByGenerator(options) {
1057
1195
  if (extraSource.trim().length === 0) return {
1058
1196
  css: finalizeMiniProgramGeneratorCss(css, generated.target),
1059
1197
  target: generated.target,
1060
- source: "generator"
1198
+ source: "generator",
1199
+ dependencies: generated.dependencies
1061
1200
  };
1062
1201
  if (generated.target === "weapp") {
1063
1202
  const { css: userCss } = await styleHandler(extraSource, {
@@ -1068,14 +1207,15 @@ async function generateCssByGenerator(options) {
1068
1207
  } else css = createCssAppend(css, extraSource);
1069
1208
  }
1070
1209
  }
1071
- if (generated.target === "weapp" && generatorOptions.mode === "force") {
1210
+ if (generated.target === "weapp") {
1072
1211
  css = await appendLegacyCompatCss(css, rawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1073
1212
  css = await appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1074
1213
  }
1075
1214
  return {
1076
1215
  css: finalizeMiniProgramGeneratorCss(css, generated.target),
1077
1216
  target: generated.target,
1078
- source: "generator"
1217
+ source: "generator",
1218
+ dependencies: generated.dependencies
1079
1219
  };
1080
1220
  }
1081
1221
  debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
@@ -1086,11 +1226,12 @@ async function generateCssByGenerator(options) {
1086
1226
  return {
1087
1227
  css: finalizeMiniProgramGeneratorCss(css, generated.target),
1088
1228
  target: generated.target,
1089
- source: generatorOptions.mode === "force" ? "generator-forced" : "generator"
1229
+ source: "generator",
1230
+ dependencies: generated.dependencies
1090
1231
  };
1091
1232
  } catch (error) {
1092
- if (generatorOptions.mode === "force") throw error;
1093
- debug("tailwind direct css generation failed, fallback to styleHandler: %s %O", file, error);
1233
+ debug("tailwind direct css generation failed: %s %O", file, error);
1234
+ throw error;
1094
1235
  }
1095
1236
  }
1096
1237
  //#endregion
package/dist/generator.js CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("./chunk-8l464Juk.js");
3
- const require_generator = require("./generator-mmhXzZnv.js");
3
+ const require_generator = require("./generator-9UEp8OoQ.js");
4
4
  let tailwindcss_patch = require("tailwindcss-patch");
5
5
  exports.createWeappTailwindcssGenerator = require_generator.createWeappTailwindcssGenerator;
6
6
  exports.createWeappTailwindcssGeneratorFromPatcher = require_generator.createWeappTailwindcssGeneratorFromPatcher;
@@ -1,2 +1,2 @@
1
- import { _ as transformTailwindV3CssToWeapp, a as resolveTailwindV4Source, c as resolveTailwindV4SourceOptionsFromPatcher, g as transformTailwindV3CssByTarget, h as resolveTailwindV3SourceOptionsFromPatcher, i as normalizeWeappTailwindcssGeneratorOptions, l as transformTailwindV4CssByTarget, m as resolveTailwindV3SourceFromPatcher, n as createWeappTailwindcssGeneratorFromPatcher, o as resolveTailwindV4SourceFromPatchOptions, p as resolveTailwindV3Source, r as resolveTailwindSourceFromPatcher, s as resolveTailwindV4SourceFromPatcher, t as createWeappTailwindcssGenerator, u as transformTailwindV4CssToWeapp } from "./generator-Y-Ikv4Fu.mjs";
1
+ import { _ as transformTailwindV3CssToWeapp, a as resolveTailwindV4Source, c as resolveTailwindV4SourceOptionsFromPatcher, g as transformTailwindV3CssByTarget, h as resolveTailwindV3SourceOptionsFromPatcher, i as normalizeWeappTailwindcssGeneratorOptions, l as transformTailwindV4CssByTarget, m as resolveTailwindV3SourceFromPatcher, n as createWeappTailwindcssGeneratorFromPatcher, o as resolveTailwindV4SourceFromPatchOptions, p as resolveTailwindV3Source, r as resolveTailwindSourceFromPatcher, s as resolveTailwindV4SourceFromPatcher, t as createWeappTailwindcssGenerator, u as transformTailwindV4CssToWeapp } from "./generator-Dpp-5s8z.mjs";
2
2
  export { createWeappTailwindcssGenerator, createWeappTailwindcssGeneratorFromPatcher, normalizeWeappTailwindcssGeneratorOptions, resolveTailwindSourceFromPatcher, resolveTailwindV3Source, resolveTailwindV3SourceFromPatcher, resolveTailwindV3SourceOptionsFromPatcher, resolveTailwindV4Source, resolveTailwindV4SourceFromPatchOptions, resolveTailwindV4SourceFromPatcher, resolveTailwindV4SourceOptionsFromPatcher, transformTailwindV3CssByTarget, transformTailwindV3CssToWeapp, transformTailwindV4CssByTarget, transformTailwindV4CssToWeapp };
package/dist/gulp.js CHANGED
@@ -1,7 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("./chunk-8l464Juk.js");
3
- const require_recorder = require("./recorder-GdTJ3QqX.js");
4
- const require_generator_css = require("./generator-css-CRLrHW4F.js");
3
+ const require_recorder = require("./recorder-D4BKt75Q.js");
4
+ const require_logger = require("./logger-D9clu_3f.js");
5
+ const require_generator_css = require("./generator-css-CGueCYbX.js");
5
6
  let node_path = require("node:path");
6
7
  node_path = require_chunk.__toESM(node_path);
7
8
  let node_process = require("node:process");
@@ -46,9 +47,6 @@ function createPlugins(options = {}) {
46
47
  ".jsx"
47
48
  ];
48
49
  let runtimeSetInitialized = false;
49
- async function refreshRuntimeState(force) {
50
- await require_recorder.refreshTailwindRuntimeState(runtimeState, force);
51
- }
52
50
  async function refreshRuntimeSet(force = false) {
53
51
  if (!force && runtimeSetInitialized) return runtimeSet;
54
52
  runtimeSet = await require_recorder.ensureRuntimeClassSet(runtimeState, {
@@ -60,6 +58,13 @@ function createPlugins(options = {}) {
60
58
  runtimeSetInitialized = true;
61
59
  return runtimeSet;
62
60
  }
61
+ function createRuntimeSetHash(rawSource, nextRuntimeSet) {
62
+ return cache.computeHash([
63
+ rawSource,
64
+ require_logger.getRuntimeClassSetSignature(runtimeState.twPatcher),
65
+ [...nextRuntimeSet].sort().join("\n")
66
+ ].join("\n\n"));
67
+ }
63
68
  function resolveWithExtensions(base) {
64
69
  for (const ext of MODULE_EXTENSIONS) {
65
70
  const candidate = `${base}${ext}`;
@@ -166,13 +171,12 @@ function createPlugins(options = {}) {
166
171
  }
167
172
  const transformWxss = (options = {}) => createVinylTransform(async (file) => {
168
173
  if (!file.contents) return;
169
- await refreshRuntimeState(true);
170
- await runtimeState.patchPromise;
171
174
  const rawSource = file.contents.toString();
175
+ const nextRuntimeSet = await refreshRuntimeSet(true);
172
176
  await require_generator_css.processCachedTask({
173
177
  cache,
174
178
  cacheKey: file.path,
175
- rawSource,
179
+ hash: createRuntimeSetHash(rawSource, nextRuntimeSet),
176
180
  applyResult(source) {
177
181
  file.contents = node_buffer.Buffer.from(source);
178
182
  },
@@ -185,7 +189,7 @@ function createPlugins(options = {}) {
185
189
  const css = (await require_generator_css.generateCssByGenerator({
186
190
  opts,
187
191
  runtimeState,
188
- runtime: await refreshRuntimeSet(false),
192
+ runtime: nextRuntimeSet,
189
193
  rawSource,
190
194
  file: file.path,
191
195
  cssHandlerOptions,
@@ -200,7 +204,7 @@ function createPlugins(options = {}) {
200
204
  });
201
205
  const transformJs = (options = {}) => createVinylTransform(async (file) => {
202
206
  if (!file.contents) return;
203
- await refreshRuntimeSet(false);
207
+ await refreshRuntimeSet(true);
204
208
  await runtimeState.patchPromise;
205
209
  const filename = node_path.default.resolve(file.path);
206
210
  const moduleGraph = resolveModuleGraphOptions(options.moduleGraph);
@@ -237,7 +241,7 @@ function createPlugins(options = {}) {
237
241
  });
238
242
  const transformWxml = (options = {}) => createVinylTransform(async (file) => {
239
243
  if (!file.contents) return;
240
- await refreshRuntimeSet(false);
244
+ await refreshRuntimeSet(true);
241
245
  await runtimeState.patchPromise;
242
246
  const rawSource = file.contents.toString();
243
247
  await require_generator_css.processCachedTask({
package/dist/gulp.mjs CHANGED
@@ -1,5 +1,6 @@
1
- import { _ as refreshTailwindRuntimeState, g as ensureRuntimeClassSet, n as shouldSkipJsTransform, r as getCompilerContext, t as setupPatchRecorder, v as createDebug } from "./recorder-XdFvVASS.mjs";
2
- import { i as processCachedTask, t as generateCssByGenerator } from "./generator-css-Bwy_Uz89.mjs";
1
+ import { g as ensureRuntimeClassSet, n as shouldSkipJsTransform, r as getCompilerContext, t as setupPatchRecorder, v as createDebug } from "./recorder-BIW3Kuke.mjs";
2
+ import { d as getRuntimeClassSetSignature } from "./logger-1gx9UllH.mjs";
3
+ import { i as processCachedTask, t as generateCssByGenerator } from "./generator-css-MyjZhF0z.mjs";
3
4
  import path from "node:path";
4
5
  import process from "node:process";
5
6
  import { Buffer } from "node:buffer";
@@ -40,9 +41,6 @@ function createPlugins(options = {}) {
40
41
  ".jsx"
41
42
  ];
42
43
  let runtimeSetInitialized = false;
43
- async function refreshRuntimeState(force) {
44
- await refreshTailwindRuntimeState(runtimeState, force);
45
- }
46
44
  async function refreshRuntimeSet(force = false) {
47
45
  if (!force && runtimeSetInitialized) return runtimeSet;
48
46
  runtimeSet = await ensureRuntimeClassSet(runtimeState, {
@@ -54,6 +52,13 @@ function createPlugins(options = {}) {
54
52
  runtimeSetInitialized = true;
55
53
  return runtimeSet;
56
54
  }
55
+ function createRuntimeSetHash(rawSource, nextRuntimeSet) {
56
+ return cache.computeHash([
57
+ rawSource,
58
+ getRuntimeClassSetSignature(runtimeState.twPatcher),
59
+ [...nextRuntimeSet].sort().join("\n")
60
+ ].join("\n\n"));
61
+ }
57
62
  function resolveWithExtensions(base) {
58
63
  for (const ext of MODULE_EXTENSIONS) {
59
64
  const candidate = `${base}${ext}`;
@@ -160,13 +165,12 @@ function createPlugins(options = {}) {
160
165
  }
161
166
  const transformWxss = (options = {}) => createVinylTransform(async (file) => {
162
167
  if (!file.contents) return;
163
- await refreshRuntimeState(true);
164
- await runtimeState.patchPromise;
165
168
  const rawSource = file.contents.toString();
169
+ const nextRuntimeSet = await refreshRuntimeSet(true);
166
170
  await processCachedTask({
167
171
  cache,
168
172
  cacheKey: file.path,
169
- rawSource,
173
+ hash: createRuntimeSetHash(rawSource, nextRuntimeSet),
170
174
  applyResult(source) {
171
175
  file.contents = Buffer.from(source);
172
176
  },
@@ -179,7 +183,7 @@ function createPlugins(options = {}) {
179
183
  const css = (await generateCssByGenerator({
180
184
  opts,
181
185
  runtimeState,
182
- runtime: await refreshRuntimeSet(false),
186
+ runtime: nextRuntimeSet,
183
187
  rawSource,
184
188
  file: file.path,
185
189
  cssHandlerOptions,
@@ -194,7 +198,7 @@ function createPlugins(options = {}) {
194
198
  });
195
199
  const transformJs = (options = {}) => createVinylTransform(async (file) => {
196
200
  if (!file.contents) return;
197
- await refreshRuntimeSet(false);
201
+ await refreshRuntimeSet(true);
198
202
  await runtimeState.patchPromise;
199
203
  const filename = path.resolve(file.path);
200
204
  const moduleGraph = resolveModuleGraphOptions(options.moduleGraph);
@@ -231,7 +235,7 @@ function createPlugins(options = {}) {
231
235
  });
232
236
  const transformWxml = (options = {}) => createVinylTransform(async (file) => {
233
237
  if (!file.contents) return;
234
- await refreshRuntimeSet(false);
238
+ await refreshRuntimeSet(true);
235
239
  await runtimeState.patchPromise;
236
240
  const rawSource = file.contents.toString();
237
241
  await processCachedTask({
package/dist/index.d.ts CHANGED
@@ -4,5 +4,5 @@ export { createPlugins } from './gulp';
4
4
  export { weappTailwindcssPostcssPlugin } from './postcss';
5
5
  export type { WeappTailwindcssPostcssPluginOptions } from './postcss';
6
6
  export type * from './types';
7
- export { UnifiedViteWeappTailwindcssPlugin } from './vite';
7
+ export { WeappTailwindcss } from './vite';
8
8
  export { UnifiedWebpackPluginV5, weappTailwindcssPackageDir } from './webpack';
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_generator = require("./generator-mmhXzZnv.js");
2
+ const require_generator = require("./generator-9UEp8OoQ.js");
3
3
  const require_gulp = require("./gulp.js");
4
4
  const require_postcss = require("./postcss.js");
5
- const require_vite = require("./vite-DgRh_GXn.js");
6
- const require_webpack = require("./webpack-CAJR4hhP.js");
7
- exports.UnifiedViteWeappTailwindcssPlugin = require_vite.UnifiedViteWeappTailwindcssPlugin;
5
+ const require_vite = require("./vite-BkMGwDeH.js");
6
+ const require_webpack = require("./webpack-CICGEKT9.js");
8
7
  exports.UnifiedWebpackPluginV5 = require_webpack.UnifiedWebpackPluginV5;
8
+ exports.WeappTailwindcss = require_vite.WeappTailwindcss;
9
9
  exports.createPlugins = require_gulp.createPlugins;
10
10
  exports.createWeappTailwindcssGenerator = require_generator.createWeappTailwindcssGenerator;
11
11
  exports.weappTailwindcssPackageDir = require_webpack.weappTailwindcssPackageDir;
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { t as createWeappTailwindcssGenerator } from "./generator-Y-Ikv4Fu.mjs";
1
+ import { t as createWeappTailwindcssGenerator } from "./generator-Dpp-5s8z.mjs";
2
2
  import { WeappTailwindcss as createPlugins } from "./gulp.mjs";
3
3
  import weappTailwindcssPostcssPlugin from "./postcss.mjs";
4
- import { t as UnifiedViteWeappTailwindcssPlugin } from "./vite-BDywuCjn.mjs";
5
- import { n as weappTailwindcssPackageDir, t as UnifiedWebpackPluginV5 } from "./webpack-CiHqVZTg.mjs";
6
- export { UnifiedViteWeappTailwindcssPlugin, UnifiedWebpackPluginV5, createPlugins, createWeappTailwindcssGenerator, weappTailwindcssPackageDir, weappTailwindcssPostcssPlugin };
4
+ import { t as WeappTailwindcss } from "./vite-fDM-UQpR.mjs";
5
+ import { n as weappTailwindcssPackageDir, t as UnifiedWebpackPluginV5 } from "./webpack-D2Wdk28V.mjs";
6
+ export { UnifiedWebpackPluginV5, WeappTailwindcss, createPlugins, createWeappTailwindcssGenerator, weappTailwindcssPackageDir, weappTailwindcssPostcssPlugin };
@@ -1,4 +1,5 @@
1
1
  import type { CreateJsHandlerOptions, JsHandler } from '../types';
2
2
  import { jsHandler } from './babel';
3
3
  export { jsHandler, };
4
+ export { transformLiteralText } from './literal-transform';
4
5
  export declare function createJsHandler(options: CreateJsHandlerOptions): JsHandler;
@@ -0,0 +1,2 @@
1
+ import type { IJsHandlerOptions } from '../types';
2
+ export declare function transformLiteralText(literal: string, options: IJsHandlerOptions): string | undefined;