tailwindcss-patch 6.0.8 → 7.0.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.
@@ -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.startsWith("chunk-"));
674
+ const guessUnitStart = /\[\s*["']cm["'],\s*["']mm["'],[\w,"]+\]/;
675
+ let code;
676
+ let matches = null;
677
+ let guessFile;
678
+ for (const chunkName of chunks) {
679
+ guessFile = path3.join(distPath, chunkName);
680
+ code = fs3.readFileSync(guessFile, "utf8");
681
+ const res = guessUnitStart.exec(code);
682
+ if (res) {
683
+ matches = res;
684
+ break;
685
+ }
686
+ }
687
+ let hasPatched = false;
688
+ if (matches && code) {
689
+ const match = matches[0];
690
+ const ast = parse(match, {
691
+ sourceType: "unambiguous"
692
+ });
693
+ traverse(ast, {
694
+ ArrayExpression(path7) {
695
+ for (const unit of opts.units) {
696
+ if (path7.node.elements.some((x) => t3.isStringLiteral(x) && x.value === unit)) {
697
+ hasPatched = true;
698
+ break;
699
+ }
700
+ path7.node.elements.push(t3.stringLiteral(unit));
701
+ }
702
+ }
703
+ });
704
+ if (hasPatched) {
705
+ return {
706
+ code,
707
+ hasPatched
708
+ };
709
+ }
710
+ const { code: replacement } = generate(ast, {
711
+ minified: true
712
+ });
713
+ code = spliceChangesIntoString(code, [
714
+ {
715
+ start: matches.index,
716
+ end: matches.index + match.length,
717
+ replacement: replacement.endsWith(";") ? replacement.slice(0, -1) : replacement
718
+ }
719
+ ]);
720
+ if (opts.overwrite && guessFile) {
721
+ fs3.writeFileSync(guessFile, code, {
722
+ encoding: "utf8"
723
+ });
724
+ logger_default.success("patch tailwindcss for custom length unit successfully!");
725
+ }
726
+ }
727
+ return {
728
+ code,
729
+ hasPatched
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() {
@@ -802,9 +906,9 @@ var TailwindcssPatcher = class {
802
906
  this.packageInfo = packageInfo;
803
907
  this.patch = () => {
804
908
  try {
805
- return internalPatch(this.packageInfo?.packageJsonPath, this.patchOptions);
909
+ return internalPatch(this.packageInfo, this.patchOptions);
806
910
  } catch (error) {
807
- logger_default.error(`patch tailwindcss failed: ${error.message}`);
911
+ logger_default.error(`Patch Tailwind CSS Failed: ${error.message}`);
808
912
  }
809
913
  };
810
914
  }
@@ -843,7 +947,7 @@ var TailwindcssPatcher = class {
843
947
  }
844
948
  async getClassCacheSet() {
845
949
  const classSet = /* @__PURE__ */ new Set();
846
- const { output, tailwindcss } = this.patchOptions;
950
+ const { tailwindcss } = this.patchOptions;
847
951
  if (this.majorVersion === 4) {
848
952
  const { v4 } = tailwindcss ?? {};
849
953
  if (Array.isArray(v4?.cssEntries)) {
@@ -951,7 +1055,8 @@ export {
951
1055
  getPatchOptions,
952
1056
  monkeyPatchForExposingContextV3,
953
1057
  monkeyPatchForExposingContextV2,
954
- monkeyPatchForSupportingCustomUnit,
1058
+ monkeyPatchForSupportingCustomUnitV3,
1059
+ monkeyPatchForSupportingCustomUnitV4,
955
1060
  internalPatch,
956
1061
  TailwindcssPatcher
957
1062
  };
@@ -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.2_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.startsWith("chunk-"));
678
+ const guessUnitStart = /\[\s*["']cm["'],\s*["']mm["'],[\w,"]+\]/;
679
+ let code;
680
+ let matches = null;
681
+ let guessFile;
682
+ for (const chunkName of chunks) {
683
+ guessFile = _pathe2.default.join(distPath, chunkName);
684
+ code = _fsextra2.default.readFileSync(guessFile, "utf8");
685
+ const res = guessUnitStart.exec(code);
686
+ if (res) {
687
+ matches = res;
688
+ break;
689
+ }
690
+ }
691
+ let hasPatched = false;
692
+ if (matches && code) {
693
+ const match = matches[0];
694
+ const ast = _parser.parse.call(void 0, match, {
695
+ sourceType: "unambiguous"
696
+ });
697
+ traverse(ast, {
698
+ ArrayExpression(path7) {
699
+ for (const unit of opts.units) {
700
+ if (path7.node.elements.some((x) => t3.isStringLiteral(x) && x.value === unit)) {
701
+ hasPatched = true;
702
+ break;
703
+ }
704
+ path7.node.elements.push(t3.stringLiteral(unit));
705
+ }
706
+ }
707
+ });
708
+ if (hasPatched) {
709
+ return {
710
+ code,
711
+ hasPatched
712
+ };
713
+ }
714
+ const { code: replacement } = generate(ast, {
715
+ minified: true
716
+ });
717
+ code = spliceChangesIntoString(code, [
718
+ {
719
+ start: matches.index,
720
+ end: matches.index + match.length,
721
+ replacement: replacement.endsWith(";") ? replacement.slice(0, -1) : replacement
722
+ }
723
+ ]);
724
+ if (opts.overwrite && guessFile) {
725
+ _fsextra2.default.writeFileSync(guessFile, code, {
726
+ encoding: "utf8"
727
+ });
728
+ logger_default.success("patch tailwindcss for custom length unit successfully!");
729
+ }
730
+ }
731
+ return {
732
+ code,
733
+ hasPatched
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() {
@@ -806,9 +910,9 @@ var TailwindcssPatcher = (_class = class {
806
910
  this.packageInfo = packageInfo;
807
911
  this.patch = () => {
808
912
  try {
809
- return internalPatch(_optionalChain([this, 'access', _32 => _32.packageInfo, 'optionalAccess', _33 => _33.packageJsonPath]), this.patchOptions);
913
+ return internalPatch(this.packageInfo, this.patchOptions);
810
914
  } catch (error) {
811
- logger_default.error(`patch tailwindcss failed: ${error.message}`);
915
+ logger_default.error(`Patch Tailwind CSS Failed: ${error.message}`);
812
916
  }
813
917
  };
814
918
  }
@@ -847,10 +951,10 @@ var TailwindcssPatcher = (_class = class {
847
951
  }
848
952
  async getClassCacheSet() {
849
953
  const classSet = /* @__PURE__ */ new Set();
850
- const { output, tailwindcss } = this.patchOptions;
954
+ const { tailwindcss } = this.patchOptions;
851
955
  if (this.majorVersion === 4) {
852
956
  const { v4 } = _nullishCoalesce(tailwindcss, () => ( {}));
853
- if (Array.isArray(_optionalChain([v4, 'optionalAccess', _34 => _34.cssEntries]))) {
957
+ if (Array.isArray(_optionalChain([v4, 'optionalAccess', _32 => _32.cssEntries]))) {
854
958
  const results = (await Promise.all(
855
959
  v4.cssEntries.map(async (x) => {
856
960
  if (await _fsextra2.default.exists(x)) {
@@ -862,32 +966,32 @@ var TailwindcssPatcher = (_class = class {
862
966
  )).filter((x) => x);
863
967
  for (const css of results) {
864
968
  const candidates = await extractValidCandidates({
865
- base: _optionalChain([v4, 'optionalAccess', _35 => _35.base]),
969
+ base: _optionalChain([v4, 'optionalAccess', _33 => _33.base]),
866
970
  css,
867
- 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) => {
868
972
  return {
869
- 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())),
870
974
  pattern: x.pattern
871
975
  };
872
976
  })])
873
977
  });
874
978
  for (const candidate of candidates) {
875
- _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);
876
980
  }
877
981
  }
878
982
  } else {
879
983
  const candidates = await extractValidCandidates({
880
- base: _optionalChain([v4, 'optionalAccess', _42 => _42.base]),
881
- css: _optionalChain([v4, 'optionalAccess', _43 => _43.css]),
882
- 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) => {
883
987
  return {
884
- 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())),
885
989
  pattern: x.pattern
886
990
  };
887
991
  })])
888
992
  });
889
993
  for (const candidate of candidates) {
890
- _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);
891
995
  }
892
996
  }
893
997
  } else {
@@ -896,7 +1000,7 @@ var TailwindcssPatcher = (_class = class {
896
1000
  const keys = classCacheMap.keys();
897
1001
  for (const key of keys) {
898
1002
  const v = key.toString();
899
- _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);
900
1004
  }
901
1005
  }
902
1006
  }
@@ -959,4 +1063,5 @@ var TailwindcssPatcher = (_class = class {
959
1063
 
960
1064
 
961
1065
 
962
- 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;
package/dist/cli.js CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- var _chunk436LRPDXjs = require('./chunk-436LRPDX.js');
7
+ var _chunkUVLKU3DIjs = require('./chunk-UVLKU3DI.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, _chunk436LRPDXjs.TailwindcssPatcher)({
20
- patch: _chunk436LRPDXjs.getPatchOptions.call(void 0, )
19
+ const twPatcher = new (0, _chunkUVLKU3DIjs.TailwindcssPatcher)({
20
+ patch: _chunkUVLKU3DIjs.getPatchOptions.call(void 0, )
21
21
  });
22
22
  twPatcher.patch();
23
23
  });
24
24
  cli.command("init").action(async () => {
25
25
  await init();
26
- _chunk436LRPDXjs.logger_default.success(`\u2728 ${_config.CONFIG_NAME}.config.ts initialized!`);
26
+ _chunkUVLKU3DIjs.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, _chunk436LRPDXjs.TailwindcssPatcher)(
32
+ const twPatcher = new (0, _chunkUVLKU3DIjs.TailwindcssPatcher)(
32
33
  {
33
- patch: _chunk436LRPDXjs.defuOverrideArray.call(void 0, config.patch, {
34
- resolve: {
35
- paths: [_chunk436LRPDXjs.importMetaUrl]
34
+ patch: _chunkUVLKU3DIjs.defuOverrideArray.call(void 0,
35
+ config.patch,
36
+ {
37
+ resolve: {
38
+ paths: [_chunkUVLKU3DIjs.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 && _chunk436LRPDXjs.logger_default.success(`\u2728 tailwindcss-patch extract success! file path: ${p.filename}, classList length: ${p.classList.length}`);
50
+ p && _chunkUVLKU3DIjs.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-I3NEK7LN.mjs";
6
+ } from "./chunk-AWSP7JFU.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,17 @@ 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
+ declare function monkeyPatchForSupportingCustomUnitV4(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): {
144
+ code: string | undefined;
145
+ hasPatched: boolean;
146
+ };
150
147
 
151
- declare function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): Record<string, any> | undefined;
148
+ declare function internalPatch(pkgJsonPath: PackageInfo, options: InternalPatchOptions): any;
149
+ declare function internalPatch(pkgJsonPath: string, options: InternalPatchOptions): any;
152
150
 
153
151
  declare const logger: consola.ConsolaInstance;
154
152
 
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 };
153
+ 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,17 @@ 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
+ declare function monkeyPatchForSupportingCustomUnitV4(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): {
144
+ code: string | undefined;
145
+ hasPatched: boolean;
146
+ };
150
147
 
151
- declare function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): Record<string, any> | undefined;
148
+ declare function internalPatch(pkgJsonPath: PackageInfo, options: InternalPatchOptions): any;
149
+ declare function internalPatch(pkgJsonPath: string, options: InternalPatchOptions): any;
152
150
 
153
151
  declare const logger: consola.ConsolaInstance;
154
152
 
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 };
153
+ 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 _chunk436LRPDXjs = require('./chunk-436LRPDX.js');
10
+
11
+ var _chunkUVLKU3DIjs = require('./chunk-UVLKU3DI.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 = _chunk436LRPDXjs.CacheManager; exports.TailwindcssPatcher = _chunk436LRPDXjs.TailwindcssPatcher; exports.defineConfig = _config.defineConfig; exports.getCacheOptions = _chunk436LRPDXjs.getCacheOptions; exports.internalPatch = _chunk436LRPDXjs.internalPatch; exports.logger = _chunk436LRPDXjs.logger_default; exports.monkeyPatchForExposingContextV2 = _chunk436LRPDXjs.monkeyPatchForExposingContextV2; exports.monkeyPatchForExposingContextV3 = _chunk436LRPDXjs.monkeyPatchForExposingContextV3; exports.monkeyPatchForSupportingCustomUnit = _chunk436LRPDXjs.monkeyPatchForSupportingCustomUnit;
25
+
26
+ exports.CacheManager = _chunkUVLKU3DIjs.CacheManager; exports.TailwindcssPatcher = _chunkUVLKU3DIjs.TailwindcssPatcher; exports.defineConfig = _config.defineConfig; exports.getCacheOptions = _chunkUVLKU3DIjs.getCacheOptions; exports.internalPatch = _chunkUVLKU3DIjs.internalPatch; exports.logger = _chunkUVLKU3DIjs.logger_default; exports.monkeyPatchForExposingContextV2 = _chunkUVLKU3DIjs.monkeyPatchForExposingContextV2; exports.monkeyPatchForExposingContextV3 = _chunkUVLKU3DIjs.monkeyPatchForExposingContextV3; exports.monkeyPatchForSupportingCustomUnitV3 = _chunkUVLKU3DIjs.monkeyPatchForSupportingCustomUnitV3; exports.monkeyPatchForSupportingCustomUnitV4 = _chunkUVLKU3DIjs.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-I3NEK7LN.mjs";
9
+ monkeyPatchForSupportingCustomUnitV3,
10
+ monkeyPatchForSupportingCustomUnitV4
11
+ } from "./chunk-AWSP7JFU.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.8",
3
+ "version": "7.0.0",
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
- "postcss": "^8.5.2",
62
+ "postcss": "^8.5.3",
63
63
  "semver": "^7.7.1",
64
64
  "tailwindcss-config": "^1.0.0",
65
- "@tailwindcss-mangle/config": "^5.0.3"
65
+ "@tailwindcss-mangle/config": "^5.0.5"
66
66
  },
67
67
  "devDependencies": {
68
- "@tailwindcss/node": "^4.0.7",
69
- "@tailwindcss/oxide": "^4.0.7",
70
- "@tailwindcss/postcss": "^4.0.7",
71
- "@tailwindcss/vite": "^4.0.7",
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
  }