tailwindcss-patch 8.7.4-alpha.0 → 9.0.0-alpha.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.
- package/README.md +45 -5
- package/dist/{chunk-6ZDYMYHE.mjs → chunk-SWLOK2S6.mjs} +231 -239
- package/dist/{chunk-ZXW4S356.js → chunk-Z6OMJZTU.js} +267 -275
- package/dist/cli.js +4 -4
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +12 -108
- package/dist/index.d.ts +12 -108
- package/dist/index.js +5 -3
- package/dist/index.mjs +4 -2
- package/package.json +2 -2
|
@@ -20,7 +20,7 @@ import path from "pathe";
|
|
|
20
20
|
// package.json
|
|
21
21
|
var package_default = {
|
|
22
22
|
name: "tailwindcss-patch",
|
|
23
|
-
version: "
|
|
23
|
+
version: "9.0.0-alpha.1",
|
|
24
24
|
description: "patch tailwindcss for exposing context and extract classes",
|
|
25
25
|
author: "ice breaker <1324318532@qq.com>",
|
|
26
26
|
license: "MIT",
|
|
@@ -41,17 +41,17 @@ var package_default = {
|
|
|
41
41
|
],
|
|
42
42
|
exports: {
|
|
43
43
|
".": {
|
|
44
|
-
types: "./
|
|
45
|
-
import: "./
|
|
46
|
-
require: "./
|
|
44
|
+
types: "./src/index.ts",
|
|
45
|
+
import: "./src/index.ts",
|
|
46
|
+
require: "./src/index.ts"
|
|
47
47
|
},
|
|
48
48
|
"./migration-report.schema.json": "./schema/migration-report.schema.json",
|
|
49
49
|
"./restore-result.schema.json": "./schema/restore-result.schema.json",
|
|
50
50
|
"./validate-result.schema.json": "./schema/validate-result.schema.json"
|
|
51
51
|
},
|
|
52
|
-
main: "./
|
|
53
|
-
module: "./
|
|
54
|
-
types: "./
|
|
52
|
+
main: "./src/index.ts",
|
|
53
|
+
module: "./src/index.ts",
|
|
54
|
+
types: "./src/index.ts",
|
|
55
55
|
bin: {
|
|
56
56
|
"tw-patch": "dev/bin.ts",
|
|
57
57
|
"tailwindcss-patch": "dev/bin.ts"
|
|
@@ -1516,14 +1516,6 @@ ${Date.now()}`, { flag: "wx" });
|
|
|
1516
1516
|
import process3 from "process";
|
|
1517
1517
|
import fs3 from "fs-extra";
|
|
1518
1518
|
import path2 from "pathe";
|
|
1519
|
-
var hasWarnedDeprecatedOptions = false;
|
|
1520
|
-
var deprecatedOptionMapping = {
|
|
1521
|
-
cwd: "projectRoot",
|
|
1522
|
-
overwrite: "apply.overwrite",
|
|
1523
|
-
tailwind: "tailwindcss",
|
|
1524
|
-
features: "apply",
|
|
1525
|
-
output: "extract"
|
|
1526
|
-
};
|
|
1527
1519
|
function resolveRealpathSafe(value) {
|
|
1528
1520
|
const resolved = path2.resolve(value);
|
|
1529
1521
|
try {
|
|
@@ -1668,66 +1660,32 @@ function normalizeTailwindOptions(tailwind, projectRoot) {
|
|
|
1668
1660
|
v4
|
|
1669
1661
|
};
|
|
1670
1662
|
}
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
const
|
|
1680
|
-
const pretty = options.extract?.pretty ?? options.output?.pretty;
|
|
1681
|
-
const removeUniversalSelector = options.extract?.removeUniversalSelector ?? options.output?.removeUniversalSelector;
|
|
1682
|
-
const extract = {
|
|
1683
|
-
...write === void 0 ? {} : { write },
|
|
1684
|
-
...file === void 0 ? {} : { file },
|
|
1685
|
-
...format === void 0 ? {} : { format },
|
|
1686
|
-
...pretty === void 0 ? {} : { pretty },
|
|
1687
|
-
...removeUniversalSelector === void 0 ? {} : { removeUniversalSelector }
|
|
1688
|
-
};
|
|
1689
|
-
return {
|
|
1690
|
-
...projectRoot === void 0 ? {} : { projectRoot },
|
|
1691
|
-
...overwrite === void 0 ? {} : { overwrite },
|
|
1692
|
-
...tailwind === void 0 ? {} : { tailwind },
|
|
1693
|
-
...Object.keys(extract).length === 0 ? {} : { extract },
|
|
1694
|
-
...exposeContext === void 0 ? {} : { exposeContext },
|
|
1695
|
-
...extendLengthUnits === void 0 ? {} : { extendLengthUnits }
|
|
1696
|
-
};
|
|
1697
|
-
}
|
|
1698
|
-
function findUsedDeprecatedOptions(options) {
|
|
1699
|
-
const result = [];
|
|
1700
|
-
for (const key of Object.keys(deprecatedOptionMapping)) {
|
|
1701
|
-
if (options[key] !== void 0) {
|
|
1702
|
-
result.push(key);
|
|
1703
|
-
}
|
|
1704
|
-
}
|
|
1705
|
-
return result;
|
|
1706
|
-
}
|
|
1707
|
-
function warnDeprecatedOptionsIfNeeded(options) {
|
|
1708
|
-
if (hasWarnedDeprecatedOptions) {
|
|
1709
|
-
return;
|
|
1710
|
-
}
|
|
1711
|
-
const used = findUsedDeprecatedOptions(options);
|
|
1663
|
+
var deprecatedOptionMapping = {
|
|
1664
|
+
cwd: "projectRoot",
|
|
1665
|
+
overwrite: "apply.overwrite",
|
|
1666
|
+
tailwind: "tailwindcss",
|
|
1667
|
+
features: "apply",
|
|
1668
|
+
output: "extract"
|
|
1669
|
+
};
|
|
1670
|
+
function assertNoDeprecatedOptions(options) {
|
|
1671
|
+
const used = Object.keys(deprecatedOptionMapping).filter((key) => Object.prototype.hasOwnProperty.call(options, key));
|
|
1712
1672
|
if (used.length === 0) {
|
|
1713
1673
|
return;
|
|
1714
1674
|
}
|
|
1715
|
-
hasWarnedDeprecatedOptions = true;
|
|
1716
1675
|
const mapping = used.map((key) => `${key} -> ${deprecatedOptionMapping[key]}`).join(", ");
|
|
1717
|
-
|
|
1718
|
-
`
|
|
1676
|
+
throw new Error(
|
|
1677
|
+
`Legacy TailwindcssPatcher options are no longer supported: ${used.join(", ")}. Use the modern fields instead: ${mapping}.`
|
|
1719
1678
|
);
|
|
1720
1679
|
}
|
|
1721
1680
|
function normalizeOptions(options = {}) {
|
|
1722
|
-
|
|
1723
|
-
const
|
|
1724
|
-
const
|
|
1725
|
-
const
|
|
1726
|
-
const output = normalizeOutputOptions(resolved.extract);
|
|
1681
|
+
assertNoDeprecatedOptions(options);
|
|
1682
|
+
const projectRoot = resolveRealpathSafe(options.projectRoot ? path2.resolve(options.projectRoot) : process3.cwd());
|
|
1683
|
+
const overwrite = options.apply?.overwrite ?? true;
|
|
1684
|
+
const output = normalizeOutputOptions(options.extract);
|
|
1727
1685
|
const cache = normalizeCacheOptions(options.cache, projectRoot);
|
|
1728
|
-
const tailwind = normalizeTailwindOptions(
|
|
1729
|
-
const exposeContext = normalizeExposeContextOptions(
|
|
1730
|
-
const extendLengthUnits = normalizeExtendLengthUnitsOptions(
|
|
1686
|
+
const tailwind = normalizeTailwindOptions(options.tailwindcss, projectRoot);
|
|
1687
|
+
const exposeContext = normalizeExposeContextOptions(options.apply?.exposeContext);
|
|
1688
|
+
const extendLengthUnits = normalizeExtendLengthUnitsOptions(options.apply?.extendLengthUnits);
|
|
1731
1689
|
const filter = (className) => {
|
|
1732
1690
|
if (output.removeUniversalSelector && className === "*") {
|
|
1733
1691
|
return false;
|
|
@@ -1752,122 +1710,70 @@ function normalizeOptions(options = {}) {
|
|
|
1752
1710
|
}
|
|
1753
1711
|
|
|
1754
1712
|
// src/options/legacy.ts
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1713
|
+
var deprecatedRegistryMapping = {
|
|
1714
|
+
output: "extract",
|
|
1715
|
+
tailwind: "tailwindcss"
|
|
1716
|
+
};
|
|
1717
|
+
var deprecatedTailwindMapping = {
|
|
1718
|
+
package: "packageName",
|
|
1719
|
+
legacy: "v2",
|
|
1720
|
+
classic: "v3",
|
|
1721
|
+
next: "v4"
|
|
1722
|
+
};
|
|
1723
|
+
function assertNoDeprecatedRegistryOptions(registry) {
|
|
1724
|
+
const usedRegistryKeys = Object.keys(deprecatedRegistryMapping).filter((key) => Object.prototype.hasOwnProperty.call(registry, key));
|
|
1725
|
+
if (usedRegistryKeys.length > 0) {
|
|
1726
|
+
const mapping = usedRegistryKeys.map((key) => `${key} -> ${deprecatedRegistryMapping[key]}`).join(", ");
|
|
1727
|
+
throw new Error(
|
|
1728
|
+
`Legacy registry fields are no longer supported: ${usedRegistryKeys.join(", ")}. Use the modern fields instead: ${mapping}.`
|
|
1729
|
+
);
|
|
1770
1730
|
}
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
}
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1731
|
+
const tailwind = registry.tailwindcss;
|
|
1732
|
+
if (!tailwind) {
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1735
|
+
const usedTailwindKeys = Object.keys(deprecatedTailwindMapping).filter((key) => Object.prototype.hasOwnProperty.call(tailwind, key));
|
|
1736
|
+
if (usedTailwindKeys.length > 0) {
|
|
1737
|
+
const mapping = usedTailwindKeys.map((key) => `${key} -> tailwindcss.${deprecatedTailwindMapping[key]}`).join(", ");
|
|
1738
|
+
throw new Error(
|
|
1739
|
+
`Legacy "registry.tailwindcss" fields are no longer supported: ${usedTailwindKeys.join(", ")}. Use the modern fields instead: ${mapping}.`
|
|
1740
|
+
);
|
|
1779
1741
|
}
|
|
1780
|
-
const patch = options.patch;
|
|
1781
|
-
const features = normalizeLegacyFeatures(patch);
|
|
1782
|
-
const output = patch?.output;
|
|
1783
|
-
const tailwindConfig = patch?.tailwindcss;
|
|
1784
|
-
const tailwindVersion = tailwindConfig?.version;
|
|
1785
|
-
const tailwindV2 = tailwindConfig?.v2;
|
|
1786
|
-
const tailwindV3 = tailwindConfig?.v3;
|
|
1787
|
-
const tailwindV4 = tailwindConfig?.v4;
|
|
1788
|
-
const tailwindConfigPath = tailwindV3?.config ?? tailwindV2?.config;
|
|
1789
|
-
const tailwindCwd = tailwindV3?.cwd ?? tailwindV2?.cwd ?? patch?.cwd;
|
|
1790
|
-
const normalizedExtract = output ? {
|
|
1791
|
-
...output.filename === void 0 ? {} : { file: output.filename },
|
|
1792
|
-
pretty: output.loose ? 2 : false,
|
|
1793
|
-
...output.removeUniversalSelector === void 0 ? {} : { removeUniversalSelector: output.removeUniversalSelector }
|
|
1794
|
-
} : void 0;
|
|
1795
|
-
const normalizedTailwindcss = {
|
|
1796
|
-
...patch?.packageName === void 0 ? {} : { packageName: patch.packageName },
|
|
1797
|
-
...tailwindVersion === void 0 ? {} : { version: tailwindVersion },
|
|
1798
|
-
...patch?.resolve === void 0 ? {} : { resolve: patch.resolve },
|
|
1799
|
-
...tailwindConfigPath === void 0 ? {} : { config: tailwindConfigPath },
|
|
1800
|
-
...tailwindCwd === void 0 ? {} : { cwd: tailwindCwd },
|
|
1801
|
-
...tailwindV2 === void 0 ? {} : { v2: tailwindV2 },
|
|
1802
|
-
...tailwindV3 === void 0 ? {} : { v3: tailwindV3 },
|
|
1803
|
-
...tailwindV4 === void 0 ? {} : { v4: tailwindV4 }
|
|
1804
|
-
};
|
|
1805
|
-
const normalizedCache = typeof options.cache === "boolean" ? options.cache : options.cache ? {
|
|
1806
|
-
...options.cache,
|
|
1807
|
-
enabled: options.cache.enabled ?? true
|
|
1808
|
-
} : void 0;
|
|
1809
|
-
const normalizedApply = {
|
|
1810
|
-
...patch?.overwrite === void 0 ? {} : { overwrite: patch.overwrite },
|
|
1811
|
-
exposeContext: features.exposeContext,
|
|
1812
|
-
extendLengthUnits: features.extendLengthUnits
|
|
1813
|
-
};
|
|
1814
|
-
return {
|
|
1815
|
-
...patch?.cwd === void 0 ? {} : { projectRoot: patch.cwd },
|
|
1816
|
-
...patch?.filter === void 0 ? {} : { filter: patch.filter },
|
|
1817
|
-
...normalizedCache === void 0 ? {} : { cache: normalizedCache },
|
|
1818
|
-
...normalizedExtract === void 0 ? {} : { extract: normalizedExtract },
|
|
1819
|
-
...Object.keys(normalizedTailwindcss).length === 0 ? {} : { tailwindcss: normalizedTailwindcss },
|
|
1820
|
-
apply: normalizedApply
|
|
1821
|
-
};
|
|
1822
1742
|
}
|
|
1823
1743
|
function fromUnifiedConfig(registry) {
|
|
1824
1744
|
if (!registry) {
|
|
1825
1745
|
return {};
|
|
1826
1746
|
}
|
|
1827
|
-
|
|
1828
|
-
const
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
}
|
|
1835
|
-
if (typeof value === "boolean") {
|
|
1836
|
-
return value ? 2 : false;
|
|
1837
|
-
}
|
|
1838
|
-
return value;
|
|
1839
|
-
})();
|
|
1840
|
-
const removeUniversalSelector = modernExtract?.removeUniversalSelector ?? legacyOutput?.stripUniversalSelector;
|
|
1841
|
-
const outputFile = modernExtract?.file ?? legacyOutput?.file;
|
|
1842
|
-
const normalizedExtract = modernExtract || legacyOutput ? {
|
|
1843
|
-
...modernExtract?.write === void 0 ? {} : { write: modernExtract.write },
|
|
1844
|
-
...outputFile === void 0 ? {} : { file: outputFile },
|
|
1845
|
-
...pretty === void 0 ? {} : { pretty },
|
|
1846
|
-
...removeUniversalSelector === void 0 ? {} : { removeUniversalSelector },
|
|
1847
|
-
...modernExtract?.format === void 0 ? {} : { format: modernExtract.format }
|
|
1747
|
+
assertNoDeprecatedRegistryOptions(registry);
|
|
1748
|
+
const extract = registry.extract ? {
|
|
1749
|
+
...registry.extract.write === void 0 ? {} : { write: registry.extract.write },
|
|
1750
|
+
...registry.extract.file === void 0 ? {} : { file: registry.extract.file },
|
|
1751
|
+
...registry.extract.format === void 0 ? {} : { format: registry.extract.format },
|
|
1752
|
+
...registry.extract.pretty === void 0 ? {} : { pretty: registry.extract.pretty },
|
|
1753
|
+
...registry.extract.removeUniversalSelector === void 0 ? {} : { removeUniversalSelector: registry.extract.removeUniversalSelector }
|
|
1848
1754
|
} : void 0;
|
|
1849
|
-
const
|
|
1850
|
-
...
|
|
1851
|
-
...
|
|
1852
|
-
...
|
|
1853
|
-
...
|
|
1854
|
-
...
|
|
1855
|
-
...
|
|
1856
|
-
...
|
|
1857
|
-
...
|
|
1755
|
+
const tailwindcss = registry.tailwindcss ? {
|
|
1756
|
+
...registry.tailwindcss.version === void 0 ? {} : { version: registry.tailwindcss.version },
|
|
1757
|
+
...registry.tailwindcss.packageName === void 0 ? {} : { packageName: registry.tailwindcss.packageName },
|
|
1758
|
+
...registry.tailwindcss.resolve === void 0 ? {} : { resolve: registry.tailwindcss.resolve },
|
|
1759
|
+
...registry.tailwindcss.config === void 0 ? {} : { config: registry.tailwindcss.config },
|
|
1760
|
+
...registry.tailwindcss.cwd === void 0 ? {} : { cwd: registry.tailwindcss.cwd },
|
|
1761
|
+
...registry.tailwindcss.v2 === void 0 ? {} : { v2: registry.tailwindcss.v2 },
|
|
1762
|
+
...registry.tailwindcss.v3 === void 0 ? {} : { v3: registry.tailwindcss.v3 },
|
|
1763
|
+
...registry.tailwindcss.v4 === void 0 ? {} : { v4: registry.tailwindcss.v4 }
|
|
1858
1764
|
} : void 0;
|
|
1859
|
-
const
|
|
1765
|
+
const apply = registry.apply ? {
|
|
1860
1766
|
...registry.apply.overwrite === void 0 ? {} : { overwrite: registry.apply.overwrite },
|
|
1861
1767
|
...registry.apply.exposeContext === void 0 ? {} : { exposeContext: registry.apply.exposeContext },
|
|
1862
1768
|
...registry.apply.extendLengthUnits === void 0 ? {} : { extendLengthUnits: registry.apply.extendLengthUnits }
|
|
1863
1769
|
} : void 0;
|
|
1864
1770
|
return {
|
|
1865
1771
|
...registry.projectRoot === void 0 ? {} : { projectRoot: registry.projectRoot },
|
|
1866
|
-
...
|
|
1772
|
+
...apply === void 0 ? {} : { apply },
|
|
1867
1773
|
...registry.cache === void 0 ? {} : { cache: registry.cache },
|
|
1868
1774
|
...registry.filter === void 0 ? {} : { filter: registry.filter },
|
|
1869
|
-
...
|
|
1870
|
-
...
|
|
1775
|
+
...extract === void 0 ? {} : { extract },
|
|
1776
|
+
...tailwindcss === void 0 ? {} : { tailwindcss }
|
|
1871
1777
|
};
|
|
1872
1778
|
}
|
|
1873
1779
|
|
|
@@ -1879,19 +1785,22 @@ var defuPromise;
|
|
|
1879
1785
|
function isNodeError(error) {
|
|
1880
1786
|
return !!error && typeof error === "object" && ("code" in error || "message" in error);
|
|
1881
1787
|
}
|
|
1882
|
-
function
|
|
1883
|
-
if (!isNodeError(error)
|
|
1788
|
+
function isMissingModuleError(error, pkgName2) {
|
|
1789
|
+
if (!isNodeError(error)) {
|
|
1884
1790
|
return false;
|
|
1885
1791
|
}
|
|
1886
|
-
const
|
|
1887
|
-
|
|
1888
|
-
}
|
|
1889
|
-
function isMissingSharedModuleError(error) {
|
|
1890
|
-
if (!isNodeError(error) || error.code !== "MODULE_NOT_FOUND") {
|
|
1792
|
+
const code = error.code;
|
|
1793
|
+
if (code !== "MODULE_NOT_FOUND" && code !== "ERR_MODULE_NOT_FOUND") {
|
|
1891
1794
|
return false;
|
|
1892
1795
|
}
|
|
1893
1796
|
const message = error.message ?? "";
|
|
1894
|
-
return message.includes(
|
|
1797
|
+
return message.includes(pkgName2) || message.includes(`${pkgName2}/dist/`);
|
|
1798
|
+
}
|
|
1799
|
+
function isMissingConfigModuleError(error) {
|
|
1800
|
+
return isMissingModuleError(error, "@tailwindcss-mangle/config");
|
|
1801
|
+
}
|
|
1802
|
+
function isMissingSharedModuleError(error) {
|
|
1803
|
+
return isMissingModuleError(error, "@tailwindcss-mangle/shared");
|
|
1895
1804
|
}
|
|
1896
1805
|
async function loadWorkspaceConfigModule() {
|
|
1897
1806
|
if (!configModulePromise) {
|
|
@@ -1922,8 +1831,10 @@ async function loadPatchOptionsForWorkspace(cwd, overrides) {
|
|
|
1922
1831
|
const merge = await loadWorkspaceDefu();
|
|
1923
1832
|
const configModule = await loadWorkspaceConfigModule();
|
|
1924
1833
|
const { config } = await configModule.getConfig(cwd);
|
|
1925
|
-
|
|
1926
|
-
|
|
1834
|
+
if (config && typeof config === "object" && "patch" in config && config.patch !== void 0) {
|
|
1835
|
+
throw new Error('Legacy workspace config field "patch" is no longer supported. Move patcher options under "registry".');
|
|
1836
|
+
}
|
|
1837
|
+
const base = config?.registry ? fromUnifiedConfig(config.registry) : {};
|
|
1927
1838
|
const merged = merge(overrides ?? {}, base);
|
|
1928
1839
|
return merged;
|
|
1929
1840
|
}
|
|
@@ -3257,25 +3168,7 @@ function applyTailwindPatches(context) {
|
|
|
3257
3168
|
return results;
|
|
3258
3169
|
}
|
|
3259
3170
|
|
|
3260
|
-
// src/
|
|
3261
|
-
function resolveMajorVersion(version, hint) {
|
|
3262
|
-
if (hint && [2, 3, 4].includes(hint)) {
|
|
3263
|
-
return hint;
|
|
3264
|
-
}
|
|
3265
|
-
if (version) {
|
|
3266
|
-
const coerced = coerce(version);
|
|
3267
|
-
if (coerced) {
|
|
3268
|
-
const major = coerced.major;
|
|
3269
|
-
if (major === 2 || major === 3 || major === 4) {
|
|
3270
|
-
return major;
|
|
3271
|
-
}
|
|
3272
|
-
if (major >= 4) {
|
|
3273
|
-
return 4;
|
|
3274
|
-
}
|
|
3275
|
-
}
|
|
3276
|
-
}
|
|
3277
|
-
return 3;
|
|
3278
|
-
}
|
|
3171
|
+
// src/runtime/collector.ts
|
|
3279
3172
|
function resolveTailwindExecutionOptions(normalized, majorVersion) {
|
|
3280
3173
|
const base = normalized.tailwind;
|
|
3281
3174
|
if (majorVersion === 2 && base.v2) {
|
|
@@ -3298,17 +3191,138 @@ function resolveTailwindExecutionOptions(normalized, majorVersion) {
|
|
|
3298
3191
|
postcssPlugin: base.postcssPlugin
|
|
3299
3192
|
};
|
|
3300
3193
|
}
|
|
3194
|
+
var BaseCollector = class {
|
|
3195
|
+
constructor(packageInfo, options, majorVersion) {
|
|
3196
|
+
this.packageInfo = packageInfo;
|
|
3197
|
+
this.options = options;
|
|
3198
|
+
this.majorVersion = majorVersion;
|
|
3199
|
+
}
|
|
3200
|
+
async patch() {
|
|
3201
|
+
return applyTailwindPatches({
|
|
3202
|
+
packageInfo: this.packageInfo,
|
|
3203
|
+
options: this.options,
|
|
3204
|
+
majorVersion: this.majorVersion
|
|
3205
|
+
});
|
|
3206
|
+
}
|
|
3207
|
+
async getPatchStatus() {
|
|
3208
|
+
return getPatchStatusReport({
|
|
3209
|
+
packageInfo: this.packageInfo,
|
|
3210
|
+
options: this.options,
|
|
3211
|
+
majorVersion: this.majorVersion
|
|
3212
|
+
});
|
|
3213
|
+
}
|
|
3214
|
+
getContexts() {
|
|
3215
|
+
return loadRuntimeContexts(
|
|
3216
|
+
this.packageInfo,
|
|
3217
|
+
this.majorVersion,
|
|
3218
|
+
this.options.features.exposeContext.refProperty
|
|
3219
|
+
);
|
|
3220
|
+
}
|
|
3221
|
+
};
|
|
3222
|
+
var RuntimeCollector = class extends BaseCollector {
|
|
3223
|
+
constructor(packageInfo, options, majorVersion, snapshotFactory) {
|
|
3224
|
+
super(packageInfo, options, majorVersion);
|
|
3225
|
+
this.snapshotFactory = snapshotFactory;
|
|
3226
|
+
}
|
|
3227
|
+
inFlightBuild;
|
|
3228
|
+
async collectClassSet() {
|
|
3229
|
+
const contexts = this.getContexts();
|
|
3230
|
+
return collectClassesFromContexts(contexts, this.options.filter);
|
|
3231
|
+
}
|
|
3232
|
+
getPatchSnapshot() {
|
|
3233
|
+
return this.snapshotFactory();
|
|
3234
|
+
}
|
|
3235
|
+
async runTailwindBuildIfNeeded() {
|
|
3236
|
+
if (this.inFlightBuild) {
|
|
3237
|
+
return this.inFlightBuild;
|
|
3238
|
+
}
|
|
3239
|
+
const executionOptions = resolveTailwindExecutionOptions(this.options, this.majorVersion);
|
|
3240
|
+
const buildOptions = {
|
|
3241
|
+
cwd: executionOptions.cwd,
|
|
3242
|
+
majorVersion: this.majorVersion,
|
|
3243
|
+
...executionOptions.config === void 0 ? {} : { config: executionOptions.config },
|
|
3244
|
+
...executionOptions.postcssPlugin === void 0 ? {} : { postcssPlugin: executionOptions.postcssPlugin }
|
|
3245
|
+
};
|
|
3246
|
+
this.inFlightBuild = runTailwindBuild(buildOptions).then(() => void 0);
|
|
3247
|
+
try {
|
|
3248
|
+
await this.inFlightBuild;
|
|
3249
|
+
} finally {
|
|
3250
|
+
this.inFlightBuild = void 0;
|
|
3251
|
+
}
|
|
3252
|
+
}
|
|
3253
|
+
};
|
|
3254
|
+
var TailwindV4Collector = class extends BaseCollector {
|
|
3255
|
+
constructor(packageInfo, options, snapshotFactory) {
|
|
3256
|
+
super(packageInfo, options, 4);
|
|
3257
|
+
this.snapshotFactory = snapshotFactory;
|
|
3258
|
+
}
|
|
3259
|
+
snapshotFactory;
|
|
3260
|
+
async collectClassSet() {
|
|
3261
|
+
return collectClassesFromTailwindV4(this.options);
|
|
3262
|
+
}
|
|
3263
|
+
getPatchSnapshot() {
|
|
3264
|
+
return this.snapshotFactory();
|
|
3265
|
+
}
|
|
3266
|
+
};
|
|
3267
|
+
|
|
3268
|
+
// src/api/tailwindcss-patcher.ts
|
|
3269
|
+
function resolveInstalledMajorVersion(version) {
|
|
3270
|
+
if (!version) {
|
|
3271
|
+
return void 0;
|
|
3272
|
+
}
|
|
3273
|
+
const coerced = coerce(version);
|
|
3274
|
+
if (!coerced) {
|
|
3275
|
+
return void 0;
|
|
3276
|
+
}
|
|
3277
|
+
const major = coerced.major;
|
|
3278
|
+
if (major === 2 || major === 3 || major === 4) {
|
|
3279
|
+
return major;
|
|
3280
|
+
}
|
|
3281
|
+
if (major >= 4) {
|
|
3282
|
+
return 4;
|
|
3283
|
+
}
|
|
3284
|
+
return void 0;
|
|
3285
|
+
}
|
|
3286
|
+
function validateInstalledVersion(packageVersion, expectedMajor, packageName) {
|
|
3287
|
+
const installedMajor = resolveInstalledMajorVersion(packageVersion);
|
|
3288
|
+
if (installedMajor === void 0) {
|
|
3289
|
+
return;
|
|
3290
|
+
}
|
|
3291
|
+
if (installedMajor !== expectedMajor) {
|
|
3292
|
+
throw new Error(
|
|
3293
|
+
`Configured tailwindcss.version=${expectedMajor}, but resolved package "${packageName}" is version ${packageVersion}. Update the configuration or resolve the correct package.`
|
|
3294
|
+
);
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
function resolveMajorVersionOrThrow(configuredMajor, packageVersion, packageName) {
|
|
3298
|
+
if (configuredMajor !== void 0) {
|
|
3299
|
+
validateInstalledVersion(packageVersion, configuredMajor, packageName);
|
|
3300
|
+
return configuredMajor;
|
|
3301
|
+
}
|
|
3302
|
+
const installedMajor = resolveInstalledMajorVersion(packageVersion);
|
|
3303
|
+
if (installedMajor !== void 0) {
|
|
3304
|
+
return installedMajor;
|
|
3305
|
+
}
|
|
3306
|
+
throw new Error(
|
|
3307
|
+
`Unable to infer Tailwind CSS major version from resolved package "${packageName}" (${packageVersion ?? "unknown"}). Set "tailwindcss.version" to 2, 3, or 4 explicitly.`
|
|
3308
|
+
);
|
|
3309
|
+
}
|
|
3310
|
+
function createCollector(packageInfo, options, majorVersion, snapshotFactory) {
|
|
3311
|
+
if (majorVersion === 4) {
|
|
3312
|
+
return new TailwindV4Collector(packageInfo, options, snapshotFactory);
|
|
3313
|
+
}
|
|
3314
|
+
return new RuntimeCollector(packageInfo, options, majorVersion, snapshotFactory);
|
|
3315
|
+
}
|
|
3301
3316
|
var TailwindcssPatcher = class {
|
|
3302
3317
|
options;
|
|
3303
3318
|
packageInfo;
|
|
3304
3319
|
majorVersion;
|
|
3305
3320
|
cacheContext;
|
|
3306
3321
|
cacheStore;
|
|
3322
|
+
collector;
|
|
3307
3323
|
patchMemo;
|
|
3308
|
-
inFlightBuild;
|
|
3309
3324
|
constructor(options = {}) {
|
|
3310
|
-
|
|
3311
|
-
this.options = normalizeOptions(resolvedOptions);
|
|
3325
|
+
this.options = normalizeOptions(options);
|
|
3312
3326
|
const packageInfo = getPackageInfoSync(
|
|
3313
3327
|
this.options.tailwind.packageName,
|
|
3314
3328
|
this.options.tailwind.resolve
|
|
@@ -3317,9 +3331,10 @@ var TailwindcssPatcher = class {
|
|
|
3317
3331
|
throw new Error(`Unable to locate Tailwind CSS package "${this.options.tailwind.packageName}".`);
|
|
3318
3332
|
}
|
|
3319
3333
|
this.packageInfo = packageInfo;
|
|
3320
|
-
this.majorVersion =
|
|
3334
|
+
this.majorVersion = resolveMajorVersionOrThrow(
|
|
3335
|
+
this.options.tailwind.versionHint,
|
|
3321
3336
|
this.packageInfo.version,
|
|
3322
|
-
this.options.tailwind.
|
|
3337
|
+
this.options.tailwind.packageName
|
|
3323
3338
|
);
|
|
3324
3339
|
this.cacheContext = createCacheContextDescriptor(
|
|
3325
3340
|
this.options,
|
|
@@ -3327,56 +3342,30 @@ var TailwindcssPatcher = class {
|
|
|
3327
3342
|
this.majorVersion
|
|
3328
3343
|
);
|
|
3329
3344
|
this.cacheStore = new CacheStore(this.options.cache, this.cacheContext);
|
|
3345
|
+
this.collector = createCollector(
|
|
3346
|
+
this.packageInfo,
|
|
3347
|
+
this.options,
|
|
3348
|
+
this.majorVersion,
|
|
3349
|
+
() => this.createPatchSnapshot()
|
|
3350
|
+
);
|
|
3330
3351
|
}
|
|
3331
3352
|
async patch() {
|
|
3332
|
-
const snapshot = this.
|
|
3353
|
+
const snapshot = this.collector.getPatchSnapshot();
|
|
3333
3354
|
if (this.patchMemo && this.patchMemo.snapshot === snapshot) {
|
|
3334
3355
|
return this.patchMemo.result;
|
|
3335
3356
|
}
|
|
3336
|
-
const result =
|
|
3337
|
-
packageInfo: this.packageInfo,
|
|
3338
|
-
options: this.options,
|
|
3339
|
-
majorVersion: this.majorVersion
|
|
3340
|
-
});
|
|
3357
|
+
const result = await this.collector.patch();
|
|
3341
3358
|
this.patchMemo = {
|
|
3342
3359
|
result,
|
|
3343
|
-
snapshot: this.
|
|
3360
|
+
snapshot: this.collector.getPatchSnapshot()
|
|
3344
3361
|
};
|
|
3345
3362
|
return result;
|
|
3346
3363
|
}
|
|
3347
3364
|
async getPatchStatus() {
|
|
3348
|
-
return
|
|
3349
|
-
packageInfo: this.packageInfo,
|
|
3350
|
-
options: this.options,
|
|
3351
|
-
majorVersion: this.majorVersion
|
|
3352
|
-
});
|
|
3365
|
+
return this.collector.getPatchStatus();
|
|
3353
3366
|
}
|
|
3354
3367
|
getContexts() {
|
|
3355
|
-
return
|
|
3356
|
-
this.packageInfo,
|
|
3357
|
-
this.majorVersion,
|
|
3358
|
-
this.options.features.exposeContext.refProperty
|
|
3359
|
-
);
|
|
3360
|
-
}
|
|
3361
|
-
async runTailwindBuildIfNeeded() {
|
|
3362
|
-
if (this.majorVersion === 2 || this.majorVersion === 3) {
|
|
3363
|
-
if (this.inFlightBuild) {
|
|
3364
|
-
return this.inFlightBuild;
|
|
3365
|
-
}
|
|
3366
|
-
const executionOptions = resolveTailwindExecutionOptions(this.options, this.majorVersion);
|
|
3367
|
-
const buildOptions = {
|
|
3368
|
-
cwd: executionOptions.cwd,
|
|
3369
|
-
majorVersion: this.majorVersion,
|
|
3370
|
-
...executionOptions.config === void 0 ? {} : { config: executionOptions.config },
|
|
3371
|
-
...executionOptions.postcssPlugin === void 0 ? {} : { postcssPlugin: executionOptions.postcssPlugin }
|
|
3372
|
-
};
|
|
3373
|
-
this.inFlightBuild = runTailwindBuild(buildOptions).then(() => void 0);
|
|
3374
|
-
try {
|
|
3375
|
-
await this.inFlightBuild;
|
|
3376
|
-
} finally {
|
|
3377
|
-
this.inFlightBuild = void 0;
|
|
3378
|
-
}
|
|
3379
|
-
}
|
|
3368
|
+
return this.collector.getContexts();
|
|
3380
3369
|
}
|
|
3381
3370
|
createPatchSnapshot() {
|
|
3382
3371
|
const entries = [];
|
|
@@ -3420,11 +3409,14 @@ var TailwindcssPatcher = class {
|
|
|
3420
3409
|
}
|
|
3421
3410
|
async collectClassSet() {
|
|
3422
3411
|
if (this.majorVersion === 4) {
|
|
3423
|
-
return
|
|
3412
|
+
return this.collector.collectClassSet();
|
|
3424
3413
|
}
|
|
3425
3414
|
const contexts = this.getContexts();
|
|
3426
3415
|
return collectClassesFromContexts(contexts, this.options.filter);
|
|
3427
3416
|
}
|
|
3417
|
+
async runTailwindBuildIfNeeded() {
|
|
3418
|
+
await this.collector.runTailwindBuildIfNeeded?.();
|
|
3419
|
+
}
|
|
3428
3420
|
debugCacheRead(meta) {
|
|
3429
3421
|
if (meta.hit) {
|
|
3430
3422
|
logger_default.debug(
|
|
@@ -4564,7 +4556,7 @@ import fs15 from "fs-extra";
|
|
|
4564
4556
|
import path16 from "pathe";
|
|
4565
4557
|
var DEFAULT_CONFIG_NAME = "tailwindcss-mangle";
|
|
4566
4558
|
async function installCommandDefaultHandler(_ctx) {
|
|
4567
|
-
const patcher =
|
|
4559
|
+
const patcher = await _ctx.createPatcher();
|
|
4568
4560
|
await patcher.patch();
|
|
4569
4561
|
logger_default.success("Tailwind CSS runtime patched successfully.");
|
|
4570
4562
|
}
|