tailwindcss-patch 6.0.9 → 7.0.1

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.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// ../../node_modules/.pnpm/tsup@8.3.6_jiti@2.4.2_postcss@8.5.3_tsx@4.19.3_typescript@5.7.3_yaml@2.7.0/node_modules/tsup/assets/cjs_shims.js
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// ../../node_modules/.pnpm/tsup@8.4.0_jiti@2.4.2_postcss@8.5.3_tsx@4.19.3_typescript@5.8.2_yaml@2.7.0/node_modules/tsup/assets/cjs_shims.js
2
2
  var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
3
3
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
4
4
 
@@ -569,6 +569,33 @@ function monkeyPatchForExposingContextV2(twDir, opt) {
569
569
 
570
570
 
571
571
 
572
+
573
+ // src/utils.ts
574
+ function isObject(val) {
575
+ return val !== null && typeof val === "object" && Array.isArray(val) === false;
576
+ }
577
+ function spliceChangesIntoString(str, changes) {
578
+ if (!changes[0]) {
579
+ return str;
580
+ }
581
+ changes.sort((a, b) => {
582
+ return a.end - b.end || a.start - b.start;
583
+ });
584
+ let result = "";
585
+ let previous = changes[0];
586
+ result += str.slice(0, previous.start);
587
+ result += previous.replacement;
588
+ for (let i = 1; i < changes.length; ++i) {
589
+ const change = changes[i];
590
+ result += str.slice(previous.end, change.start);
591
+ result += change.replacement;
592
+ previous = change;
593
+ }
594
+ result += str.slice(previous.end);
595
+ return result;
596
+ }
597
+
598
+ // src/core/patches/supportCustomUnits/index.ts
572
599
  function findAstNode(content, options) {
573
600
  const { variableName, units } = options;
574
601
  const ast = _parser.parse.call(void 0, content);
@@ -579,14 +606,13 @@ function findAstNode(content, options) {
579
606
  if (path7.node.name === variableName && t3.isVariableDeclarator(path7.parent) && t3.isArrayExpression(path7.parent.init)) {
580
607
  arrayRef = path7.parent.init;
581
608
  const set = new Set(path7.parent.init.elements.map((x) => x.value));
582
- for (let i = 0; i < units.length; i++) {
583
- const unit = units[i];
609
+ for (const unit of units) {
584
610
  if (!set.has(unit)) {
585
611
  path7.parent.init.elements = path7.parent.init.elements.map((x) => {
586
612
  if (t3.isStringLiteral(x)) {
587
613
  return {
588
- type: _optionalChain([x, 'optionalAccess', _15 => _15.type]),
589
- value: _optionalChain([x, 'optionalAccess', _16 => _16.value])
614
+ type: x.type,
615
+ value: x.value
590
616
  };
591
617
  }
592
618
  return x;
@@ -606,7 +632,7 @@ function findAstNode(content, options) {
606
632
  changed
607
633
  };
608
634
  }
609
- function monkeyPatchForSupportingCustomUnit(rootDir, options) {
635
+ function monkeyPatchForSupportingCustomUnitV3(rootDir, options) {
610
636
  const opts = defuOverrideArray(options, {
611
637
  units: ["rpx"],
612
638
  lengthUnitsFilePath: "lib/util/dataTypes.js",
@@ -641,6 +667,72 @@ function monkeyPatchForSupportingCustomUnit(rootDir, options) {
641
667
  };
642
668
  }
643
669
  }
670
+ function monkeyPatchForSupportingCustomUnitV4(rootDir, options) {
671
+ const opts = defuOverrideArray(options, {
672
+ units: ["rpx"],
673
+ overwrite: true
674
+ });
675
+ const distPath = _pathe2.default.resolve(rootDir, "dist");
676
+ const list = _fsextra2.default.readdirSync(distPath);
677
+ const chunks = list.filter((x) => x.endsWith("js"));
678
+ const guessUnitStart = /\[\s*["']cm["'],\s*["']mm["'],[\w,"]+\]/;
679
+ const guessFiles = chunks.reduce((acc, chunkName) => {
680
+ const guessFile = _pathe2.default.join(distPath, chunkName);
681
+ const code = _fsextra2.default.readFileSync(guessFile, "utf8");
682
+ const matches = guessUnitStart.exec(code);
683
+ if (matches && code) {
684
+ acc.push({
685
+ code,
686
+ hasPatched: false,
687
+ file: guessFile,
688
+ matches
689
+ });
690
+ }
691
+ return acc;
692
+ }, []);
693
+ for (const item of guessFiles) {
694
+ const { matches, code, file } = item;
695
+ const match = matches[0];
696
+ const ast = _parser.parse.call(void 0, match, {
697
+ sourceType: "unambiguous"
698
+ });
699
+ traverse(ast, {
700
+ ArrayExpression(path7) {
701
+ for (const unit of opts.units) {
702
+ if (path7.node.elements.some((x) => t3.isStringLiteral(x) && x.value === unit)) {
703
+ item.hasPatched = true;
704
+ break;
705
+ }
706
+ path7.node.elements.push(t3.stringLiteral(unit));
707
+ }
708
+ }
709
+ });
710
+ if (item.hasPatched) {
711
+ continue;
712
+ }
713
+ const { code: replacement } = generate(ast, {
714
+ minified: true
715
+ });
716
+ item.code = spliceChangesIntoString(code, [
717
+ {
718
+ start: matches.index,
719
+ end: matches.index + match.length,
720
+ replacement: replacement.endsWith(";") ? replacement.slice(0, -1) : replacement
721
+ }
722
+ ]);
723
+ if (opts.overwrite && file) {
724
+ _fsextra2.default.writeFileSync(file, item.code, {
725
+ encoding: "utf8"
726
+ });
727
+ }
728
+ }
729
+ if (guessFiles.some((x) => !x.hasPatched)) {
730
+ logger_default.success("patch tailwindcss for custom length unit successfully!");
731
+ }
732
+ return {
733
+ files: guessFiles
734
+ };
735
+ }
644
736
 
645
737
  // src/core/runtime.ts
646
738
  var _module = require('module');
@@ -649,20 +741,37 @@ var _semver = require('semver');
649
741
  var require2 = _module.createRequire.call(void 0, importMetaUrl);
650
742
  function internalPatch(pkgJsonPath, options) {
651
743
  if (pkgJsonPath) {
652
- const pkgJson = require2(pkgJsonPath);
653
- const twDir = _pathe2.default.dirname(pkgJsonPath);
654
- options.version = pkgJson.version;
655
- if (_semver.gte.call(void 0, pkgJson.version, "3.0.0")) {
744
+ let pkgJson;
745
+ let twDir;
746
+ if (typeof pkgJsonPath === "string") {
747
+ pkgJson = require2(pkgJsonPath);
748
+ twDir = _pathe2.default.dirname(pkgJsonPath);
749
+ options.version = pkgJson.version;
750
+ } else if (typeof pkgJsonPath === "object") {
751
+ pkgJson = pkgJsonPath.packageJson;
752
+ twDir = pkgJsonPath.rootPath;
753
+ options.version = pkgJsonPath.version;
754
+ } else {
755
+ throw new TypeError("tailwindcss not found");
756
+ }
757
+ if (_semver.gte.call(void 0, pkgJson.version, "4.0.0")) {
758
+ try {
759
+ if (_optionalChain([options, 'access', _15 => _15.applyPatches, 'optionalAccess', _16 => _16.extendLengthUnits])) {
760
+ return monkeyPatchForSupportingCustomUnitV4(twDir, options);
761
+ }
762
+ } catch (e3) {
763
+ }
764
+ } else if (_semver.gte.call(void 0, pkgJson.version, "3.0.0")) {
656
765
  let result = {};
657
766
  if (_optionalChain([options, 'access', _17 => _17.applyPatches, 'optionalAccess', _18 => _18.exportContext])) {
658
767
  result = monkeyPatchForExposingContextV3(twDir, options);
659
768
  }
660
769
  if (_optionalChain([options, 'access', _19 => _19.applyPatches, 'optionalAccess', _20 => _20.extendLengthUnits])) {
661
770
  try {
662
- Object.assign(_nullishCoalesce(result, () => ( {})), monkeyPatchForSupportingCustomUnit(twDir, defu(options.applyPatches.extendLengthUnits === true ? void 0 : options.applyPatches.extendLengthUnits, {
771
+ Object.assign(_nullishCoalesce(result, () => ( {})), monkeyPatchForSupportingCustomUnitV3(twDir, defu(options.applyPatches.extendLengthUnits === true ? void 0 : options.applyPatches.extendLengthUnits, {
663
772
  overwrite: options.overwrite
664
773
  })));
665
- } catch (e3) {
774
+ } catch (e4) {
666
775
  }
667
776
  }
668
777
  return result;
@@ -681,11 +790,6 @@ function internalPatch(pkgJsonPath, options) {
681
790
  var _localpkg = require('local-pkg');
682
791
 
683
792
 
684
- // src/utils.ts
685
- function isObject(val) {
686
- return val !== null && typeof val === "object" && Array.isArray(val) === false;
687
- }
688
-
689
793
  // src/core/candidates.ts
690
794
 
691
795
  function importNode() {
@@ -805,12 +909,10 @@ var TailwindcssPatcher = (_class = class {
805
909
  }
806
910
  this.packageInfo = packageInfo;
807
911
  this.patch = () => {
808
- if (this.majorVersion === 3 || this.majorVersion === 2) {
809
- try {
810
- return internalPatch(_optionalChain([this, 'access', _32 => _32.packageInfo, 'optionalAccess', _33 => _33.packageJsonPath]), this.patchOptions);
811
- } catch (error) {
812
- logger_default.error(`patch tailwindcss failed: ${error.message}`);
813
- }
912
+ try {
913
+ return internalPatch(this.packageInfo, this.patchOptions);
914
+ } catch (error) {
915
+ logger_default.error(`Patch Tailwind CSS Failed: ${error.message}`);
814
916
  }
815
917
  };
816
918
  }
@@ -852,7 +954,7 @@ var TailwindcssPatcher = (_class = class {
852
954
  const { tailwindcss } = this.patchOptions;
853
955
  if (this.majorVersion === 4) {
854
956
  const { v4 } = _nullishCoalesce(tailwindcss, () => ( {}));
855
- if (Array.isArray(_optionalChain([v4, 'optionalAccess', _34 => _34.cssEntries]))) {
957
+ if (Array.isArray(_optionalChain([v4, 'optionalAccess', _32 => _32.cssEntries]))) {
856
958
  const results = (await Promise.all(
857
959
  v4.cssEntries.map(async (x) => {
858
960
  if (await _fsextra2.default.exists(x)) {
@@ -864,32 +966,32 @@ var TailwindcssPatcher = (_class = class {
864
966
  )).filter((x) => x);
865
967
  for (const css of results) {
866
968
  const candidates = await extractValidCandidates({
867
- base: _optionalChain([v4, 'optionalAccess', _35 => _35.base]),
969
+ base: _optionalChain([v4, 'optionalAccess', _33 => _33.base]),
868
970
  css,
869
- sources: _optionalChain([v4, 'optionalAccess', _36 => _36.sources, 'optionalAccess', _37 => _37.map, 'call', _38 => _38((x) => {
971
+ sources: _optionalChain([v4, 'optionalAccess', _34 => _34.sources, 'optionalAccess', _35 => _35.map, 'call', _36 => _36((x) => {
870
972
  return {
871
- base: _nullishCoalesce(_nullishCoalesce(x.base, () => ( _optionalChain([v4, 'optionalAccess', _39 => _39.base]))), () => ( _process2.default.cwd())),
973
+ base: _nullishCoalesce(_nullishCoalesce(x.base, () => ( _optionalChain([v4, 'optionalAccess', _37 => _37.base]))), () => ( _process2.default.cwd())),
872
974
  pattern: x.pattern
873
975
  };
874
976
  })])
875
977
  });
876
978
  for (const candidate of candidates) {
877
- _optionalChain([this, 'access', _40 => _40.filter, 'optionalCall', _41 => _41(candidate)]) && classSet.add(candidate);
979
+ _optionalChain([this, 'access', _38 => _38.filter, 'optionalCall', _39 => _39(candidate)]) && classSet.add(candidate);
878
980
  }
879
981
  }
880
982
  } else {
881
983
  const candidates = await extractValidCandidates({
882
- base: _optionalChain([v4, 'optionalAccess', _42 => _42.base]),
883
- css: _optionalChain([v4, 'optionalAccess', _43 => _43.css]),
884
- sources: _optionalChain([v4, 'optionalAccess', _44 => _44.sources, 'optionalAccess', _45 => _45.map, 'call', _46 => _46((x) => {
984
+ base: _optionalChain([v4, 'optionalAccess', _40 => _40.base]),
985
+ css: _optionalChain([v4, 'optionalAccess', _41 => _41.css]),
986
+ sources: _optionalChain([v4, 'optionalAccess', _42 => _42.sources, 'optionalAccess', _43 => _43.map, 'call', _44 => _44((x) => {
885
987
  return {
886
- base: _nullishCoalesce(_nullishCoalesce(x.base, () => ( _optionalChain([v4, 'optionalAccess', _47 => _47.base]))), () => ( _process2.default.cwd())),
988
+ base: _nullishCoalesce(_nullishCoalesce(x.base, () => ( _optionalChain([v4, 'optionalAccess', _45 => _45.base]))), () => ( _process2.default.cwd())),
887
989
  pattern: x.pattern
888
990
  };
889
991
  })])
890
992
  });
891
993
  for (const candidate of candidates) {
892
- _optionalChain([this, 'access', _48 => _48.filter, 'optionalCall', _49 => _49(candidate)]) && classSet.add(candidate);
994
+ _optionalChain([this, 'access', _46 => _46.filter, 'optionalCall', _47 => _47(candidate)]) && classSet.add(candidate);
893
995
  }
894
996
  }
895
997
  } else {
@@ -898,7 +1000,7 @@ var TailwindcssPatcher = (_class = class {
898
1000
  const keys = classCacheMap.keys();
899
1001
  for (const key of keys) {
900
1002
  const v = key.toString();
901
- _optionalChain([this, 'access', _50 => _50.filter, 'optionalCall', _51 => _51(v)]) && classSet.add(v);
1003
+ _optionalChain([this, 'access', _48 => _48.filter, 'optionalCall', _49 => _49(v)]) && classSet.add(v);
902
1004
  }
903
1005
  }
904
1006
  }
@@ -961,4 +1063,5 @@ var TailwindcssPatcher = (_class = class {
961
1063
 
962
1064
 
963
1065
 
964
- exports.importMetaUrl = importMetaUrl; exports.defuOverrideArray = defuOverrideArray; exports.logger_default = logger_default; exports.getCacheOptions = getCacheOptions; exports.CacheManager = CacheManager; exports.getPatchOptions = getPatchOptions; exports.monkeyPatchForExposingContextV3 = monkeyPatchForExposingContextV3; exports.monkeyPatchForExposingContextV2 = monkeyPatchForExposingContextV2; exports.monkeyPatchForSupportingCustomUnit = monkeyPatchForSupportingCustomUnit; exports.internalPatch = internalPatch; exports.TailwindcssPatcher = TailwindcssPatcher;
1066
+
1067
+ exports.importMetaUrl = importMetaUrl; exports.defuOverrideArray = defuOverrideArray; exports.logger_default = logger_default; exports.getCacheOptions = getCacheOptions; exports.CacheManager = CacheManager; exports.getPatchOptions = getPatchOptions; exports.monkeyPatchForExposingContextV3 = monkeyPatchForExposingContextV3; exports.monkeyPatchForExposingContextV2 = monkeyPatchForExposingContextV2; exports.monkeyPatchForSupportingCustomUnitV3 = monkeyPatchForSupportingCustomUnitV3; exports.monkeyPatchForSupportingCustomUnitV4 = monkeyPatchForSupportingCustomUnitV4; exports.internalPatch = internalPatch; exports.TailwindcssPatcher = TailwindcssPatcher;
@@ -565,6 +565,33 @@ function monkeyPatchForExposingContextV2(twDir, opt) {
565
565
  import * as t3 from "@babel/types";
566
566
  import fs3 from "fs-extra";
567
567
  import path3 from "pathe";
568
+
569
+ // src/utils.ts
570
+ function isObject(val) {
571
+ return val !== null && typeof val === "object" && Array.isArray(val) === false;
572
+ }
573
+ function spliceChangesIntoString(str, changes) {
574
+ if (!changes[0]) {
575
+ return str;
576
+ }
577
+ changes.sort((a, b) => {
578
+ return a.end - b.end || a.start - b.start;
579
+ });
580
+ let result = "";
581
+ let previous = changes[0];
582
+ result += str.slice(0, previous.start);
583
+ result += previous.replacement;
584
+ for (let i = 1; i < changes.length; ++i) {
585
+ const change = changes[i];
586
+ result += str.slice(previous.end, change.start);
587
+ result += change.replacement;
588
+ previous = change;
589
+ }
590
+ result += str.slice(previous.end);
591
+ return result;
592
+ }
593
+
594
+ // src/core/patches/supportCustomUnits/index.ts
568
595
  function findAstNode(content, options) {
569
596
  const { variableName, units } = options;
570
597
  const ast = parse(content);
@@ -575,14 +602,13 @@ function findAstNode(content, options) {
575
602
  if (path7.node.name === variableName && t3.isVariableDeclarator(path7.parent) && t3.isArrayExpression(path7.parent.init)) {
576
603
  arrayRef = path7.parent.init;
577
604
  const set = new Set(path7.parent.init.elements.map((x) => x.value));
578
- for (let i = 0; i < units.length; i++) {
579
- const unit = units[i];
605
+ for (const unit of units) {
580
606
  if (!set.has(unit)) {
581
607
  path7.parent.init.elements = path7.parent.init.elements.map((x) => {
582
608
  if (t3.isStringLiteral(x)) {
583
609
  return {
584
- type: x?.type,
585
- value: x?.value
610
+ type: x.type,
611
+ value: x.value
586
612
  };
587
613
  }
588
614
  return x;
@@ -602,7 +628,7 @@ function findAstNode(content, options) {
602
628
  changed
603
629
  };
604
630
  }
605
- function monkeyPatchForSupportingCustomUnit(rootDir, options) {
631
+ function monkeyPatchForSupportingCustomUnitV3(rootDir, options) {
606
632
  const opts = defuOverrideArray(options, {
607
633
  units: ["rpx"],
608
634
  lengthUnitsFilePath: "lib/util/dataTypes.js",
@@ -637,6 +663,72 @@ function monkeyPatchForSupportingCustomUnit(rootDir, options) {
637
663
  };
638
664
  }
639
665
  }
666
+ function monkeyPatchForSupportingCustomUnitV4(rootDir, options) {
667
+ const opts = defuOverrideArray(options, {
668
+ units: ["rpx"],
669
+ overwrite: true
670
+ });
671
+ const distPath = path3.resolve(rootDir, "dist");
672
+ const list = fs3.readdirSync(distPath);
673
+ const chunks = list.filter((x) => x.endsWith("js"));
674
+ const guessUnitStart = /\[\s*["']cm["'],\s*["']mm["'],[\w,"]+\]/;
675
+ const guessFiles = chunks.reduce((acc, chunkName) => {
676
+ const guessFile = path3.join(distPath, chunkName);
677
+ const code = fs3.readFileSync(guessFile, "utf8");
678
+ const matches = guessUnitStart.exec(code);
679
+ if (matches && code) {
680
+ acc.push({
681
+ code,
682
+ hasPatched: false,
683
+ file: guessFile,
684
+ matches
685
+ });
686
+ }
687
+ return acc;
688
+ }, []);
689
+ for (const item of guessFiles) {
690
+ const { matches, code, file } = item;
691
+ const match = matches[0];
692
+ const ast = parse(match, {
693
+ sourceType: "unambiguous"
694
+ });
695
+ traverse(ast, {
696
+ ArrayExpression(path7) {
697
+ for (const unit of opts.units) {
698
+ if (path7.node.elements.some((x) => t3.isStringLiteral(x) && x.value === unit)) {
699
+ item.hasPatched = true;
700
+ break;
701
+ }
702
+ path7.node.elements.push(t3.stringLiteral(unit));
703
+ }
704
+ }
705
+ });
706
+ if (item.hasPatched) {
707
+ continue;
708
+ }
709
+ const { code: replacement } = generate(ast, {
710
+ minified: true
711
+ });
712
+ item.code = spliceChangesIntoString(code, [
713
+ {
714
+ start: matches.index,
715
+ end: matches.index + match.length,
716
+ replacement: replacement.endsWith(";") ? replacement.slice(0, -1) : replacement
717
+ }
718
+ ]);
719
+ if (opts.overwrite && file) {
720
+ fs3.writeFileSync(file, item.code, {
721
+ encoding: "utf8"
722
+ });
723
+ }
724
+ }
725
+ if (guessFiles.some((x) => !x.hasPatched)) {
726
+ logger_default.success("patch tailwindcss for custom length unit successfully!");
727
+ }
728
+ return {
729
+ files: guessFiles
730
+ };
731
+ }
640
732
 
641
733
  // src/core/runtime.ts
642
734
  import { createRequire } from "node:module";
@@ -645,17 +737,34 @@ import { gte } from "semver";
645
737
  var require2 = createRequire(import.meta.url);
646
738
  function internalPatch(pkgJsonPath, options) {
647
739
  if (pkgJsonPath) {
648
- const pkgJson = require2(pkgJsonPath);
649
- const twDir = path4.dirname(pkgJsonPath);
650
- options.version = pkgJson.version;
651
- if (gte(pkgJson.version, "3.0.0")) {
740
+ let pkgJson;
741
+ let twDir;
742
+ if (typeof pkgJsonPath === "string") {
743
+ pkgJson = require2(pkgJsonPath);
744
+ twDir = path4.dirname(pkgJsonPath);
745
+ options.version = pkgJson.version;
746
+ } else if (typeof pkgJsonPath === "object") {
747
+ pkgJson = pkgJsonPath.packageJson;
748
+ twDir = pkgJsonPath.rootPath;
749
+ options.version = pkgJsonPath.version;
750
+ } else {
751
+ throw new TypeError("tailwindcss not found");
752
+ }
753
+ if (gte(pkgJson.version, "4.0.0")) {
754
+ try {
755
+ if (options.applyPatches?.extendLengthUnits) {
756
+ return monkeyPatchForSupportingCustomUnitV4(twDir, options);
757
+ }
758
+ } catch {
759
+ }
760
+ } else if (gte(pkgJson.version, "3.0.0")) {
652
761
  let result = {};
653
762
  if (options.applyPatches?.exportContext) {
654
763
  result = monkeyPatchForExposingContextV3(twDir, options);
655
764
  }
656
765
  if (options.applyPatches?.extendLengthUnits) {
657
766
  try {
658
- Object.assign(result ?? {}, monkeyPatchForSupportingCustomUnit(twDir, defu(options.applyPatches.extendLengthUnits === true ? void 0 : options.applyPatches.extendLengthUnits, {
767
+ Object.assign(result ?? {}, monkeyPatchForSupportingCustomUnitV3(twDir, defu(options.applyPatches.extendLengthUnits === true ? void 0 : options.applyPatches.extendLengthUnits, {
659
768
  overwrite: options.overwrite
660
769
  })));
661
770
  } catch {
@@ -677,11 +786,6 @@ import fs4 from "fs-extra";
677
786
  import { getPackageInfoSync } from "local-pkg";
678
787
  import path6 from "pathe";
679
788
 
680
- // src/utils.ts
681
- function isObject(val) {
682
- return val !== null && typeof val === "object" && Array.isArray(val) === false;
683
- }
684
-
685
789
  // src/core/candidates.ts
686
790
  import process3 from "node:process";
687
791
  function importNode() {
@@ -801,12 +905,10 @@ var TailwindcssPatcher = class {
801
905
  }
802
906
  this.packageInfo = packageInfo;
803
907
  this.patch = () => {
804
- if (this.majorVersion === 3 || this.majorVersion === 2) {
805
- try {
806
- return internalPatch(this.packageInfo?.packageJsonPath, this.patchOptions);
807
- } catch (error) {
808
- logger_default.error(`patch tailwindcss failed: ${error.message}`);
809
- }
908
+ try {
909
+ return internalPatch(this.packageInfo, this.patchOptions);
910
+ } catch (error) {
911
+ logger_default.error(`Patch Tailwind CSS Failed: ${error.message}`);
810
912
  }
811
913
  };
812
914
  }
@@ -953,7 +1055,8 @@ export {
953
1055
  getPatchOptions,
954
1056
  monkeyPatchForExposingContextV3,
955
1057
  monkeyPatchForExposingContextV2,
956
- monkeyPatchForSupportingCustomUnit,
1058
+ monkeyPatchForSupportingCustomUnitV3,
1059
+ monkeyPatchForSupportingCustomUnitV4,
957
1060
  internalPatch,
958
1061
  TailwindcssPatcher
959
1062
  };
package/dist/cli.js CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- var _chunkMMFOI5KYjs = require('./chunk-MMFOI5KY.js');
7
+ var _chunk6CLAFWMVjs = require('./chunk-6CLAFWMV.js');
8
8
 
9
9
  // src/cli.ts
10
10
  var _process = require('process'); var _process2 = _interopRequireDefault(_process);
@@ -16,29 +16,38 @@ function init() {
16
16
  }
17
17
  var cli = _cac2.default.call(void 0, );
18
18
  cli.command("install", "patch install").action(() => {
19
- const twPatcher = new (0, _chunkMMFOI5KYjs.TailwindcssPatcher)({
20
- patch: _chunkMMFOI5KYjs.getPatchOptions.call(void 0, )
19
+ const twPatcher = new (0, _chunk6CLAFWMVjs.TailwindcssPatcher)({
20
+ patch: _chunk6CLAFWMVjs.getPatchOptions.call(void 0, )
21
21
  });
22
22
  twPatcher.patch();
23
23
  });
24
24
  cli.command("init").action(async () => {
25
25
  await init();
26
- _chunkMMFOI5KYjs.logger_default.success(`\u2728 ${_config.CONFIG_NAME}.config.ts initialized!`);
26
+ _chunk6CLAFWMVjs.logger_default.success(`\u2728 ${_config.CONFIG_NAME}.config.ts initialized!`);
27
27
  });
28
- cli.command("extract").action(async () => {
28
+ cli.command("extract").option("--css [file]", "css file entries").action(async (options) => {
29
29
  const { config } = await _config.getConfig.call(void 0, );
30
+ const file = options.css;
30
31
  if (config) {
31
- const twPatcher = new (0, _chunkMMFOI5KYjs.TailwindcssPatcher)(
32
+ const twPatcher = new (0, _chunk6CLAFWMVjs.TailwindcssPatcher)(
32
33
  {
33
- patch: _chunkMMFOI5KYjs.defuOverrideArray.call(void 0, config.patch, {
34
- resolve: {
35
- paths: [_chunkMMFOI5KYjs.importMetaUrl]
34
+ patch: _chunk6CLAFWMVjs.defuOverrideArray.call(void 0,
35
+ config.patch,
36
+ {
37
+ resolve: {
38
+ paths: [_chunk6CLAFWMVjs.importMetaUrl]
39
+ },
40
+ tailwindcss: {
41
+ v4: {
42
+ cssEntries: file ? [file] : void 0
43
+ }
44
+ }
36
45
  }
37
- })
46
+ )
38
47
  }
39
48
  );
40
49
  const p = await twPatcher.extract();
41
- p && _chunkMMFOI5KYjs.logger_default.success(`\u2728 tailwindcss-patch extract success! file path: ${p.filename}, classList length: ${p.classList.length}`);
50
+ p && _chunk6CLAFWMVjs.logger_default.success(`\u2728 tailwindcss-patch extract success! file path: ${p.filename}, classList length: ${p.classList.length}`);
42
51
  }
43
52
  });
44
53
  cli.help();
package/dist/cli.mjs CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  defuOverrideArray,
4
4
  getPatchOptions,
5
5
  logger_default
6
- } from "./chunk-QPUWFRNR.mjs";
6
+ } from "./chunk-VHUTSBJN.mjs";
7
7
 
8
8
  // src/cli.ts
9
9
  import process from "node:process";
@@ -24,16 +24,25 @@ cli.command("init").action(async () => {
24
24
  await init();
25
25
  logger_default.success(`\u2728 ${CONFIG_NAME}.config.ts initialized!`);
26
26
  });
27
- cli.command("extract").action(async () => {
27
+ cli.command("extract").option("--css [file]", "css file entries").action(async (options) => {
28
28
  const { config } = await getConfig();
29
+ const file = options.css;
29
30
  if (config) {
30
31
  const twPatcher = new TailwindcssPatcher(
31
32
  {
32
- patch: defuOverrideArray(config.patch, {
33
- resolve: {
34
- paths: [import.meta.url]
33
+ patch: defuOverrideArray(
34
+ config.patch,
35
+ {
36
+ resolve: {
37
+ paths: [import.meta.url]
38
+ },
39
+ tailwindcss: {
40
+ v4: {
41
+ cssEntries: file ? [file] : void 0
42
+ }
43
+ }
35
44
  }
36
- })
45
+ )
37
46
  }
38
47
  );
39
48
  const p = await twPatcher.extract();
package/dist/index.d.mts CHANGED
@@ -1,20 +1,13 @@
1
1
  import { PatchUserConfig } from '@tailwindcss-mangle/config';
2
2
  export { TailwindcssUserConfig, defineConfig } from '@tailwindcss-mangle/config';
3
- import { PackageJson } from 'pkg-types';
4
3
  import { Node, Rule } from 'postcss';
5
4
  import { Config } from 'tailwindcss';
5
+ import { PackageInfo } from 'local-pkg';
6
6
  import { GlobEntry } from '@tailwindcss/oxide';
7
7
  import * as consola from 'consola';
8
8
 
9
9
  type CacheStrategy = 'merge' | 'overwrite';
10
10
 
11
- interface PackageInfo {
12
- name: string;
13
- version: string | undefined;
14
- rootPath: string;
15
- packageJsonPath: string;
16
- packageJson: PackageJson;
17
- }
18
11
  interface CacheOptions {
19
12
  dir?: string;
20
13
  cwd?: string;
@@ -144,12 +137,22 @@ declare class TailwindcssPatcher {
144
137
  declare function monkeyPatchForExposingContextV3(twDir: string, opt: InternalPatchOptions): Record<string, any> | undefined;
145
138
  declare function monkeyPatchForExposingContextV2(twDir: string, opt: InternalPatchOptions): Record<string, any>;
146
139
 
147
- declare function monkeyPatchForSupportingCustomUnit(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): {
140
+ declare function monkeyPatchForSupportingCustomUnitV3(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): {
148
141
  [x: string]: string;
149
142
  } | undefined;
143
+ interface V4GuessFile {
144
+ code: string;
145
+ hasPatched: boolean;
146
+ file: string;
147
+ matches: RegExpMatchArray;
148
+ }
149
+ declare function monkeyPatchForSupportingCustomUnitV4(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): {
150
+ files: V4GuessFile[];
151
+ };
150
152
 
151
- declare function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): Record<string, any> | undefined;
153
+ declare function internalPatch(pkgJsonPath: PackageInfo, options: InternalPatchOptions): any;
154
+ declare function internalPatch(pkgJsonPath: string, options: InternalPatchOptions): any;
152
155
 
153
156
  declare const logger: consola.ConsolaInstance;
154
157
 
155
- export { CacheManager, type CacheOptions, type CacheStrategy, type DeepRequired, type ILengthUnitsPatchOptions, type InternalCacheOptions, type InternalPatchOptions, type PackageInfo, type PatchOptions, type TailwindcssClassCache, TailwindcssPatcher, type TailwindcssPatcherOptions, type TailwindcssRuntimeContext, getCacheOptions, internalPatch, logger, monkeyPatchForExposingContextV2, monkeyPatchForExposingContextV3, monkeyPatchForSupportingCustomUnit };
158
+ export { CacheManager, type CacheOptions, type CacheStrategy, type DeepRequired, type ILengthUnitsPatchOptions, type InternalCacheOptions, type InternalPatchOptions, type PatchOptions, type TailwindcssClassCache, TailwindcssPatcher, type TailwindcssPatcherOptions, type TailwindcssRuntimeContext, getCacheOptions, internalPatch, logger, monkeyPatchForExposingContextV2, monkeyPatchForExposingContextV3, monkeyPatchForSupportingCustomUnitV3, monkeyPatchForSupportingCustomUnitV4 };
package/dist/index.d.ts CHANGED
@@ -1,20 +1,13 @@
1
1
  import { PatchUserConfig } from '@tailwindcss-mangle/config';
2
2
  export { TailwindcssUserConfig, defineConfig } from '@tailwindcss-mangle/config';
3
- import { PackageJson } from 'pkg-types';
4
3
  import { Node, Rule } from 'postcss';
5
4
  import { Config } from 'tailwindcss';
5
+ import { PackageInfo } from 'local-pkg';
6
6
  import { GlobEntry } from '@tailwindcss/oxide';
7
7
  import * as consola from 'consola';
8
8
 
9
9
  type CacheStrategy = 'merge' | 'overwrite';
10
10
 
11
- interface PackageInfo {
12
- name: string;
13
- version: string | undefined;
14
- rootPath: string;
15
- packageJsonPath: string;
16
- packageJson: PackageJson;
17
- }
18
11
  interface CacheOptions {
19
12
  dir?: string;
20
13
  cwd?: string;
@@ -144,12 +137,22 @@ declare class TailwindcssPatcher {
144
137
  declare function monkeyPatchForExposingContextV3(twDir: string, opt: InternalPatchOptions): Record<string, any> | undefined;
145
138
  declare function monkeyPatchForExposingContextV2(twDir: string, opt: InternalPatchOptions): Record<string, any>;
146
139
 
147
- declare function monkeyPatchForSupportingCustomUnit(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): {
140
+ declare function monkeyPatchForSupportingCustomUnitV3(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): {
148
141
  [x: string]: string;
149
142
  } | undefined;
143
+ interface V4GuessFile {
144
+ code: string;
145
+ hasPatched: boolean;
146
+ file: string;
147
+ matches: RegExpMatchArray;
148
+ }
149
+ declare function monkeyPatchForSupportingCustomUnitV4(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): {
150
+ files: V4GuessFile[];
151
+ };
150
152
 
151
- declare function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): Record<string, any> | undefined;
153
+ declare function internalPatch(pkgJsonPath: PackageInfo, options: InternalPatchOptions): any;
154
+ declare function internalPatch(pkgJsonPath: string, options: InternalPatchOptions): any;
152
155
 
153
156
  declare const logger: consola.ConsolaInstance;
154
157
 
155
- export { CacheManager, type CacheOptions, type CacheStrategy, type DeepRequired, type ILengthUnitsPatchOptions, type InternalCacheOptions, type InternalPatchOptions, type PackageInfo, type PatchOptions, type TailwindcssClassCache, TailwindcssPatcher, type TailwindcssPatcherOptions, type TailwindcssRuntimeContext, getCacheOptions, internalPatch, logger, monkeyPatchForExposingContextV2, monkeyPatchForExposingContextV3, monkeyPatchForSupportingCustomUnit };
158
+ export { CacheManager, type CacheOptions, type CacheStrategy, type DeepRequired, type ILengthUnitsPatchOptions, type InternalCacheOptions, type InternalPatchOptions, type PatchOptions, type TailwindcssClassCache, TailwindcssPatcher, type TailwindcssPatcherOptions, type TailwindcssRuntimeContext, getCacheOptions, internalPatch, logger, monkeyPatchForExposingContextV2, monkeyPatchForExposingContextV3, monkeyPatchForSupportingCustomUnitV3, monkeyPatchForSupportingCustomUnitV4 };
package/dist/index.js CHANGED
@@ -7,7 +7,8 @@
7
7
 
8
8
 
9
9
 
10
- var _chunkMMFOI5KYjs = require('./chunk-MMFOI5KY.js');
10
+
11
+ var _chunk6CLAFWMVjs = require('./chunk-6CLAFWMV.js');
11
12
 
12
13
  // src/index.ts
13
14
  var _config = require('@tailwindcss-mangle/config');
@@ -21,4 +22,5 @@ var _config = require('@tailwindcss-mangle/config');
21
22
 
22
23
 
23
24
 
24
- exports.CacheManager = _chunkMMFOI5KYjs.CacheManager; exports.TailwindcssPatcher = _chunkMMFOI5KYjs.TailwindcssPatcher; exports.defineConfig = _config.defineConfig; exports.getCacheOptions = _chunkMMFOI5KYjs.getCacheOptions; exports.internalPatch = _chunkMMFOI5KYjs.internalPatch; exports.logger = _chunkMMFOI5KYjs.logger_default; exports.monkeyPatchForExposingContextV2 = _chunkMMFOI5KYjs.monkeyPatchForExposingContextV2; exports.monkeyPatchForExposingContextV3 = _chunkMMFOI5KYjs.monkeyPatchForExposingContextV3; exports.monkeyPatchForSupportingCustomUnit = _chunkMMFOI5KYjs.monkeyPatchForSupportingCustomUnit;
25
+
26
+ exports.CacheManager = _chunk6CLAFWMVjs.CacheManager; exports.TailwindcssPatcher = _chunk6CLAFWMVjs.TailwindcssPatcher; exports.defineConfig = _config.defineConfig; exports.getCacheOptions = _chunk6CLAFWMVjs.getCacheOptions; exports.internalPatch = _chunk6CLAFWMVjs.internalPatch; exports.logger = _chunk6CLAFWMVjs.logger_default; exports.monkeyPatchForExposingContextV2 = _chunk6CLAFWMVjs.monkeyPatchForExposingContextV2; exports.monkeyPatchForExposingContextV3 = _chunk6CLAFWMVjs.monkeyPatchForExposingContextV3; exports.monkeyPatchForSupportingCustomUnitV3 = _chunk6CLAFWMVjs.monkeyPatchForSupportingCustomUnitV3; exports.monkeyPatchForSupportingCustomUnitV4 = _chunk6CLAFWMVjs.monkeyPatchForSupportingCustomUnitV4;
package/dist/index.mjs CHANGED
@@ -6,8 +6,9 @@ import {
6
6
  logger_default,
7
7
  monkeyPatchForExposingContextV2,
8
8
  monkeyPatchForExposingContextV3,
9
- monkeyPatchForSupportingCustomUnit
10
- } from "./chunk-QPUWFRNR.mjs";
9
+ monkeyPatchForSupportingCustomUnitV3,
10
+ monkeyPatchForSupportingCustomUnitV4
11
+ } from "./chunk-VHUTSBJN.mjs";
11
12
 
12
13
  // src/index.ts
13
14
  import { defineConfig } from "@tailwindcss-mangle/config";
@@ -20,5 +21,6 @@ export {
20
21
  logger_default as logger,
21
22
  monkeyPatchForExposingContextV2,
22
23
  monkeyPatchForExposingContextV3,
23
- monkeyPatchForSupportingCustomUnit
24
+ monkeyPatchForSupportingCustomUnitV3,
25
+ monkeyPatchForSupportingCustomUnitV4
24
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwindcss-patch",
3
- "version": "6.0.9",
3
+ "version": "7.0.1",
4
4
  "description": "patch tailwindcss for exposing context and extract classes",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
@@ -57,27 +57,29 @@
57
57
  "cac": "^6.7.14",
58
58
  "consola": "^3.4.0",
59
59
  "fs-extra": "^11.3.0",
60
- "local-pkg": "^1.0.0",
60
+ "local-pkg": "^1.1.0",
61
61
  "pathe": "^2.0.3",
62
62
  "postcss": "^8.5.3",
63
63
  "semver": "^7.7.1",
64
64
  "tailwindcss-config": "^1.0.0",
65
- "@tailwindcss-mangle/config": "^5.0.4"
65
+ "@tailwindcss-mangle/config": "^5.0.5"
66
66
  },
67
67
  "devDependencies": {
68
- "@tailwindcss/node": "^4.0.8",
69
- "@tailwindcss/oxide": "^4.0.8",
70
- "@tailwindcss/postcss": "^4.0.8",
71
- "@tailwindcss/vite": "^4.0.8",
72
- "tailwindcss": "^4.0.6",
68
+ "@tailwindcss/node": "^4.0.9",
69
+ "@tailwindcss/oxide": "^4.0.9",
70
+ "@tailwindcss/postcss": "^4.0.9",
71
+ "@tailwindcss/vite": "^4.0.9",
72
+ "tailwindcss": "^4.0.9",
73
73
  "tailwindcss-3": "npm:tailwindcss@^3",
74
- "tailwindcss-4": "npm:tailwindcss@^4.0.6"
74
+ "tailwindcss-4": "npm:tailwindcss@^4.0.9"
75
75
  },
76
76
  "scripts": {
77
77
  "dev": "tsup --watch --sourcemap",
78
78
  "build": "tsup",
79
79
  "test": "pnpm run patch && vitest run --coverage.enabled",
80
80
  "test:dev": "vitest",
81
- "patch": "tsx dev/bin.js install"
81
+ "patch": "tsx dev/bin.js install",
82
+ "r0": "tsx dev/bin.js extract",
83
+ "r1": "tsx dev/bin.js extract --css index.css"
82
84
  }
83
85
  }