tailwindcss-patch 6.0.9 → 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.
- package/dist/{chunk-QPUWFRNR.mjs → chunk-AWSP7JFU.mjs} +125 -22
- package/dist/{chunk-MMFOI5KY.js → chunk-UVLKU3DI.js} +138 -35
- package/dist/cli.js +20 -11
- package/dist/cli.mjs +15 -6
- package/dist/index.d.mts +9 -11
- package/dist/index.d.ts +9 -11
- package/dist/index.js +4 -2
- package/dist/index.mjs +5 -3
- package/package.json +12 -10
|
@@ -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 (
|
|
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
|
|
585
|
-
value: x
|
|
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
|
|
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
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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 ?? {},
|
|
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
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
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
|
-
|
|
1058
|
+
monkeyPatchForSupportingCustomUnitV3,
|
|
1059
|
+
monkeyPatchForSupportingCustomUnitV4,
|
|
957
1060
|
internalPatch,
|
|
958
1061
|
TailwindcssPatcher
|
|
959
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.
|
|
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 (
|
|
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:
|
|
589
|
-
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
|
|
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
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
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, () => ( {})),
|
|
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 (
|
|
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
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
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',
|
|
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',
|
|
969
|
+
base: _optionalChain([v4, 'optionalAccess', _33 => _33.base]),
|
|
868
970
|
css,
|
|
869
|
-
sources: _optionalChain([v4, 'optionalAccess',
|
|
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',
|
|
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',
|
|
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',
|
|
883
|
-
css: _optionalChain([v4, 'optionalAccess',
|
|
884
|
-
sources: _optionalChain([v4, 'optionalAccess',
|
|
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',
|
|
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',
|
|
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',
|
|
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
|
-
|
|
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
|
|
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,
|
|
20
|
-
patch:
|
|
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
|
-
|
|
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,
|
|
32
|
+
const twPatcher = new (0, _chunkUVLKU3DIjs.TailwindcssPatcher)(
|
|
32
33
|
{
|
|
33
|
-
patch:
|
|
34
|
-
|
|
35
|
-
|
|
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 &&
|
|
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-
|
|
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(
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
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:
|
|
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
|
|
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
|
|
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:
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
10
|
-
|
|
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
|
-
|
|
24
|
+
monkeyPatchForSupportingCustomUnitV3,
|
|
25
|
+
monkeyPatchForSupportingCustomUnitV4
|
|
24
26
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwindcss-patch",
|
|
3
|
-
"version": "
|
|
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.
|
|
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.
|
|
65
|
+
"@tailwindcss-mangle/config": "^5.0.5"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@tailwindcss/node": "^4.0.
|
|
69
|
-
"@tailwindcss/oxide": "^4.0.
|
|
70
|
-
"@tailwindcss/postcss": "^4.0.
|
|
71
|
-
"@tailwindcss/vite": "^4.0.
|
|
72
|
-
"tailwindcss": "^4.0.
|
|
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.
|
|
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
|
}
|