tailwindcss-patch 8.3.0 → 8.4.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/README.md +40 -6
- package/dist/{chunk-7ZWFVW77.js → chunk-PF5ZTTYM.js} +344 -159
- package/dist/{chunk-SN7IO2IS.mjs → chunk-SHYTHM5B.mjs} +345 -160
- package/dist/cli.js +2 -2
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +64 -6
- package/dist/index.d.ts +64 -6
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -1656,156 +1656,143 @@ var acceptChars = [..."abcdefghijklmnopqrstuvwxyz"];
|
|
|
1656
1656
|
import cac from "cac";
|
|
1657
1657
|
import fs8 from "fs-extra";
|
|
1658
1658
|
import path9 from "pathe";
|
|
1659
|
-
var tailwindcssPatchCommands = [
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
];
|
|
1665
|
-
function createTailwindcssPatchCli(options = {}) {
|
|
1666
|
-
const cli = cac(options.name ?? "tw-patch");
|
|
1667
|
-
mountTailwindcssPatchCommands(cli, options.mountOptions);
|
|
1668
|
-
return cli;
|
|
1659
|
+
var tailwindcssPatchCommands = ["install", "extract", "tokens", "init"];
|
|
1660
|
+
var TOKEN_FORMATS = ["json", "lines", "grouped-json"];
|
|
1661
|
+
var DEFAULT_TOKEN_REPORT = ".tw-patch/tw-token-report.json";
|
|
1662
|
+
function formatTokenLine(entry) {
|
|
1663
|
+
return `${entry.relativeFile}:${entry.line}:${entry.column} ${entry.rawCandidate} (${entry.start}-${entry.end})`;
|
|
1669
1664
|
}
|
|
1670
|
-
function
|
|
1671
|
-
const
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
},
|
|
1685
|
-
extract() {
|
|
1686
|
-
const { name, aliases } = resolveCommandNames("extract", options, prefix);
|
|
1687
|
-
const command = cli.command(name, "Collect generated class names into a cache file").option("--cwd <dir>", "Working directory", { default: process5.cwd() }).option("--output <file>", "Override output file path").option("--format <format>", "Output format (json|lines)").option("--css <file>", "Tailwind CSS entry CSS when using v4").option("--no-write", "Skip writing to disk").action(async (args) => {
|
|
1688
|
-
const overrides = {};
|
|
1689
|
-
if (args.output || args.format) {
|
|
1690
|
-
overrides.output = {
|
|
1691
|
-
file: args.output,
|
|
1692
|
-
format: args.format
|
|
1693
|
-
};
|
|
1694
|
-
}
|
|
1695
|
-
if (args.css) {
|
|
1696
|
-
overrides.tailwind = {
|
|
1697
|
-
v4: {
|
|
1698
|
-
cssEntries: [args.css]
|
|
1699
|
-
}
|
|
1700
|
-
};
|
|
1701
|
-
}
|
|
1702
|
-
const patchOptions = await loadPatchOptions(args.cwd, overrides);
|
|
1703
|
-
const patcher = new TailwindcssPatcher(patchOptions);
|
|
1704
|
-
const result = await patcher.extract({ write: args.write });
|
|
1705
|
-
if (result.filename) {
|
|
1706
|
-
logger_default.success(`Collected ${result.classList.length} classes \u2192 ${result.filename}`);
|
|
1707
|
-
} else {
|
|
1708
|
-
logger_default.success(`Collected ${result.classList.length} classes.`);
|
|
1709
|
-
}
|
|
1710
|
-
});
|
|
1711
|
-
aliases.forEach((alias) => command.alias(alias));
|
|
1712
|
-
},
|
|
1713
|
-
tokens() {
|
|
1714
|
-
const { name, aliases } = resolveCommandNames("tokens", options, prefix);
|
|
1715
|
-
const command = cli.command(name, "Extract Tailwind tokens with file/position metadata").option("--cwd <dir>", "Working directory", { default: process5.cwd() }).option("--output <file>", "Override output file path", { default: ".tw-patch/tw-token-report.json" }).option("--format <format>", "Output format (json|lines|grouped-json)", { default: "json" }).option("--group-key <key>", "Grouping key for grouped-json output (relative|absolute)", { default: "relative" }).option("--no-write", "Skip writing to disk").action(async (args) => {
|
|
1716
|
-
const patchOptions = await loadPatchOptions(args.cwd);
|
|
1717
|
-
const patcher = new TailwindcssPatcher(patchOptions);
|
|
1718
|
-
const report = await patcher.collectContentTokens();
|
|
1719
|
-
const shouldWrite = args.write ?? true;
|
|
1720
|
-
let format = args.format ?? "json";
|
|
1721
|
-
if (!TOKEN_FORMATS.includes(format)) {
|
|
1722
|
-
format = "json";
|
|
1723
|
-
}
|
|
1724
|
-
const targetFile = args.output ?? ".tw-patch/tw-token-report.json";
|
|
1725
|
-
const groupKey = args.groupKey === "absolute" ? "absolute" : "relative";
|
|
1726
|
-
const buildGrouped = () => groupTokensByFile(report, {
|
|
1727
|
-
key: groupKey,
|
|
1728
|
-
stripAbsolutePaths: groupKey !== "absolute"
|
|
1729
|
-
});
|
|
1730
|
-
const grouped = format === "grouped-json" ? buildGrouped() : null;
|
|
1731
|
-
const resolveGrouped = () => grouped ?? buildGrouped();
|
|
1732
|
-
if (shouldWrite) {
|
|
1733
|
-
const target = path9.resolve(targetFile);
|
|
1734
|
-
await fs8.ensureDir(path9.dirname(target));
|
|
1735
|
-
if (format === "json") {
|
|
1736
|
-
await fs8.writeJSON(target, report, { spaces: 2 });
|
|
1737
|
-
} else if (format === "grouped-json") {
|
|
1738
|
-
await fs8.writeJSON(target, resolveGrouped(), { spaces: 2 });
|
|
1739
|
-
} else {
|
|
1740
|
-
const lines = report.entries.map(formatTokenLine);
|
|
1741
|
-
await fs8.writeFile(target, `${lines.join("\n")}
|
|
1742
|
-
`, "utf8");
|
|
1743
|
-
}
|
|
1744
|
-
logger_default.success(
|
|
1745
|
-
`Collected ${report.entries.length} tokens (${format}) \u2192 ${target.replace(process5.cwd(), ".")}`
|
|
1746
|
-
);
|
|
1747
|
-
} else {
|
|
1748
|
-
logger_default.success(`Collected ${report.entries.length} tokens from ${report.filesScanned} files.`);
|
|
1749
|
-
if (format === "lines") {
|
|
1750
|
-
const preview = report.entries.slice(0, 5).map(formatTokenLine).join("\n");
|
|
1751
|
-
if (preview) {
|
|
1752
|
-
logger_default.log("");
|
|
1753
|
-
logger_default.info(preview);
|
|
1754
|
-
if (report.entries.length > 5) {
|
|
1755
|
-
logger_default.info(`\u2026and ${report.entries.length - 5} more.`);
|
|
1756
|
-
}
|
|
1757
|
-
}
|
|
1758
|
-
} else if (format === "grouped-json") {
|
|
1759
|
-
const map = resolveGrouped();
|
|
1760
|
-
const { preview, moreFiles } = formatGroupedPreview(map);
|
|
1761
|
-
if (preview) {
|
|
1762
|
-
logger_default.log("");
|
|
1763
|
-
logger_default.info(preview);
|
|
1764
|
-
if (moreFiles > 0) {
|
|
1765
|
-
logger_default.info(`\u2026and ${moreFiles} more files.`);
|
|
1766
|
-
}
|
|
1767
|
-
}
|
|
1768
|
-
} else {
|
|
1769
|
-
const previewEntries = report.entries.slice(0, 3);
|
|
1770
|
-
if (previewEntries.length) {
|
|
1771
|
-
logger_default.log("");
|
|
1772
|
-
logger_default.info(JSON.stringify(previewEntries, null, 2));
|
|
1773
|
-
}
|
|
1774
|
-
}
|
|
1775
|
-
}
|
|
1776
|
-
if (report.skippedFiles.length) {
|
|
1777
|
-
logger_default.warn("Skipped files:");
|
|
1778
|
-
for (const skipped of report.skippedFiles) {
|
|
1779
|
-
logger_default.warn(` \u2022 ${skipped.file} (${skipped.reason})`);
|
|
1780
|
-
}
|
|
1781
|
-
}
|
|
1782
|
-
});
|
|
1783
|
-
aliases.forEach((alias) => command.alias(alias));
|
|
1784
|
-
},
|
|
1785
|
-
init() {
|
|
1786
|
-
const { name, aliases } = resolveCommandNames("init", options, prefix);
|
|
1787
|
-
const command = cli.command(name, "Generate a tailwindcss-patch config file").option("--cwd <dir>", "Working directory", { default: process5.cwd() }).action(async (args) => {
|
|
1788
|
-
await initConfig(args.cwd);
|
|
1789
|
-
logger_default.success(`\u2728 ${CONFIG_NAME}.config.ts initialized!`);
|
|
1790
|
-
});
|
|
1791
|
-
aliases.forEach((alias) => command.alias(alias));
|
|
1792
|
-
}
|
|
1665
|
+
function formatGroupedPreview(map, limit = 3) {
|
|
1666
|
+
const files = Object.keys(map);
|
|
1667
|
+
if (!files.length) {
|
|
1668
|
+
return { preview: "", moreFiles: 0 };
|
|
1669
|
+
}
|
|
1670
|
+
const lines = files.slice(0, limit).map((file) => {
|
|
1671
|
+
const tokens = map[file];
|
|
1672
|
+
const sample = tokens.slice(0, 3).map((token) => token.rawCandidate).join(", ");
|
|
1673
|
+
const suffix = tokens.length > 3 ? ", \u2026" : "";
|
|
1674
|
+
return `${file}: ${tokens.length} tokens (${sample}${suffix})`;
|
|
1675
|
+
});
|
|
1676
|
+
return {
|
|
1677
|
+
preview: lines.join("\n"),
|
|
1678
|
+
moreFiles: Math.max(0, files.length - limit)
|
|
1793
1679
|
};
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
}
|
|
1680
|
+
}
|
|
1681
|
+
function resolveCwd(rawCwd) {
|
|
1682
|
+
if (!rawCwd) {
|
|
1683
|
+
return process5.cwd();
|
|
1799
1684
|
}
|
|
1800
|
-
return
|
|
1685
|
+
return path9.resolve(rawCwd);
|
|
1801
1686
|
}
|
|
1802
|
-
|
|
1687
|
+
function createDefaultRunner(factory) {
|
|
1688
|
+
let promise;
|
|
1689
|
+
return () => {
|
|
1690
|
+
if (!promise) {
|
|
1691
|
+
promise = factory();
|
|
1692
|
+
}
|
|
1693
|
+
return promise;
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
1696
|
+
async function loadPatchOptionsForCwd(cwd, overrides) {
|
|
1803
1697
|
const { config } = await getConfig(cwd);
|
|
1804
1698
|
const legacyConfig = config;
|
|
1805
1699
|
const base = config?.registry ? fromUnifiedConfig(config.registry) : legacyConfig?.patch ? fromLegacyOptions({ patch: legacyConfig.patch }) : {};
|
|
1806
1700
|
const merged = defu(overrides ?? {}, base);
|
|
1807
1701
|
return merged;
|
|
1808
1702
|
}
|
|
1703
|
+
function createCommandContext(cli, command, commandName, args, cwd) {
|
|
1704
|
+
let cachedOptions;
|
|
1705
|
+
let cachedPatcher;
|
|
1706
|
+
let cachedConfig;
|
|
1707
|
+
const loadPatchOptionsForContext = (overrides) => {
|
|
1708
|
+
if (overrides) {
|
|
1709
|
+
return loadPatchOptionsForCwd(cwd, overrides);
|
|
1710
|
+
}
|
|
1711
|
+
if (!cachedOptions) {
|
|
1712
|
+
cachedOptions = loadPatchOptionsForCwd(cwd);
|
|
1713
|
+
}
|
|
1714
|
+
return cachedOptions;
|
|
1715
|
+
};
|
|
1716
|
+
const createPatcherForContext = async (overrides) => {
|
|
1717
|
+
if (overrides) {
|
|
1718
|
+
const patchOptions = await loadPatchOptionsForCwd(cwd, overrides);
|
|
1719
|
+
return new TailwindcssPatcher(patchOptions);
|
|
1720
|
+
}
|
|
1721
|
+
if (!cachedPatcher) {
|
|
1722
|
+
cachedPatcher = loadPatchOptionsForContext().then((options) => new TailwindcssPatcher(options));
|
|
1723
|
+
}
|
|
1724
|
+
return cachedPatcher;
|
|
1725
|
+
};
|
|
1726
|
+
return {
|
|
1727
|
+
cli,
|
|
1728
|
+
command,
|
|
1729
|
+
commandName,
|
|
1730
|
+
args,
|
|
1731
|
+
cwd,
|
|
1732
|
+
logger: logger_default,
|
|
1733
|
+
loadConfig: () => {
|
|
1734
|
+
if (!cachedConfig) {
|
|
1735
|
+
cachedConfig = getConfig(cwd);
|
|
1736
|
+
}
|
|
1737
|
+
return cachedConfig;
|
|
1738
|
+
},
|
|
1739
|
+
loadPatchOptions: loadPatchOptionsForContext,
|
|
1740
|
+
createPatcher: createPatcherForContext
|
|
1741
|
+
};
|
|
1742
|
+
}
|
|
1743
|
+
function createCwdOptionDefinition(description = "Working directory") {
|
|
1744
|
+
return {
|
|
1745
|
+
flags: "--cwd <dir>",
|
|
1746
|
+
description,
|
|
1747
|
+
config: { default: process5.cwd() }
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
function buildDefaultCommandDefinitions() {
|
|
1751
|
+
return {
|
|
1752
|
+
install: {
|
|
1753
|
+
description: "Apply Tailwind CSS runtime patches",
|
|
1754
|
+
optionDefs: [createCwdOptionDefinition()]
|
|
1755
|
+
},
|
|
1756
|
+
extract: {
|
|
1757
|
+
description: "Collect generated class names into a cache file",
|
|
1758
|
+
optionDefs: [
|
|
1759
|
+
createCwdOptionDefinition(),
|
|
1760
|
+
{ flags: "--output <file>", description: "Override output file path" },
|
|
1761
|
+
{ flags: "--format <format>", description: "Output format (json|lines)" },
|
|
1762
|
+
{ flags: "--css <file>", description: "Tailwind CSS entry CSS when using v4" },
|
|
1763
|
+
{ flags: "--no-write", description: "Skip writing to disk" }
|
|
1764
|
+
]
|
|
1765
|
+
},
|
|
1766
|
+
tokens: {
|
|
1767
|
+
description: "Extract Tailwind tokens with file/position metadata",
|
|
1768
|
+
optionDefs: [
|
|
1769
|
+
createCwdOptionDefinition(),
|
|
1770
|
+
{ flags: "--output <file>", description: "Override output file path", config: { default: DEFAULT_TOKEN_REPORT } },
|
|
1771
|
+
{
|
|
1772
|
+
flags: "--format <format>",
|
|
1773
|
+
description: "Output format (json|lines|grouped-json)",
|
|
1774
|
+
config: { default: "json" }
|
|
1775
|
+
},
|
|
1776
|
+
{
|
|
1777
|
+
flags: "--group-key <key>",
|
|
1778
|
+
description: "Grouping key for grouped-json output (relative|absolute)",
|
|
1779
|
+
config: { default: "relative" }
|
|
1780
|
+
},
|
|
1781
|
+
{ flags: "--no-write", description: "Skip writing to disk" }
|
|
1782
|
+
]
|
|
1783
|
+
},
|
|
1784
|
+
init: {
|
|
1785
|
+
description: "Generate a tailwindcss-patch config file",
|
|
1786
|
+
optionDefs: [createCwdOptionDefinition()]
|
|
1787
|
+
}
|
|
1788
|
+
};
|
|
1789
|
+
}
|
|
1790
|
+
function addPrefixIfMissing(value, prefix) {
|
|
1791
|
+
if (!prefix || value.startsWith(prefix)) {
|
|
1792
|
+
return value;
|
|
1793
|
+
}
|
|
1794
|
+
return `${prefix}${value}`;
|
|
1795
|
+
}
|
|
1809
1796
|
function resolveCommandNames(command, mountOptions, prefix) {
|
|
1810
1797
|
const override = mountOptions.commandOptions?.[command];
|
|
1811
1798
|
const baseName = override?.name ?? command;
|
|
@@ -1813,30 +1800,228 @@ function resolveCommandNames(command, mountOptions, prefix) {
|
|
|
1813
1800
|
const aliases = (override?.aliases ?? []).map((alias) => addPrefixIfMissing(alias, prefix));
|
|
1814
1801
|
return { name, aliases };
|
|
1815
1802
|
}
|
|
1816
|
-
function
|
|
1817
|
-
if (!
|
|
1818
|
-
return
|
|
1803
|
+
function resolveOptionDefinitions(defaults, override) {
|
|
1804
|
+
if (!override) {
|
|
1805
|
+
return defaults;
|
|
1819
1806
|
}
|
|
1820
|
-
|
|
1807
|
+
const appendDefaults = override.appendDefaultOptions ?? true;
|
|
1808
|
+
const customDefs = override.optionDefs ?? [];
|
|
1809
|
+
if (!appendDefaults) {
|
|
1810
|
+
return customDefs;
|
|
1811
|
+
}
|
|
1812
|
+
if (customDefs.length === 0) {
|
|
1813
|
+
return defaults;
|
|
1814
|
+
}
|
|
1815
|
+
return [...defaults, ...customDefs];
|
|
1821
1816
|
}
|
|
1822
|
-
function
|
|
1823
|
-
|
|
1817
|
+
function applyCommandOptions(command, optionDefs) {
|
|
1818
|
+
for (const option of optionDefs) {
|
|
1819
|
+
command.option(option.flags, option.description ?? "", option.config);
|
|
1820
|
+
}
|
|
1824
1821
|
}
|
|
1825
|
-
function
|
|
1826
|
-
const
|
|
1827
|
-
|
|
1828
|
-
|
|
1822
|
+
function runWithCommandHandler(cli, command, commandName, args, handler, defaultHandler) {
|
|
1823
|
+
const cwd = resolveCwd(args.cwd);
|
|
1824
|
+
const context = createCommandContext(cli, command, commandName, args, cwd);
|
|
1825
|
+
const runDefault = createDefaultRunner(() => defaultHandler(context));
|
|
1826
|
+
if (!handler) {
|
|
1827
|
+
return runDefault();
|
|
1828
|
+
}
|
|
1829
|
+
return handler(context, runDefault);
|
|
1830
|
+
}
|
|
1831
|
+
function resolveCommandMetadata(command, mountOptions, prefix, defaults) {
|
|
1832
|
+
const names = resolveCommandNames(command, mountOptions, prefix);
|
|
1833
|
+
const definition = defaults[command];
|
|
1834
|
+
const override = mountOptions.commandOptions?.[command];
|
|
1835
|
+
const description = override?.description ?? definition.description;
|
|
1836
|
+
const optionDefs = resolveOptionDefinitions(definition.optionDefs, override);
|
|
1837
|
+
return { ...names, description, optionDefs };
|
|
1838
|
+
}
|
|
1839
|
+
async function installCommandDefaultHandler(ctx) {
|
|
1840
|
+
const patcher = await ctx.createPatcher();
|
|
1841
|
+
await patcher.patch();
|
|
1842
|
+
logger_default.success("Tailwind CSS runtime patched successfully.");
|
|
1843
|
+
}
|
|
1844
|
+
async function extractCommandDefaultHandler(ctx) {
|
|
1845
|
+
const { args } = ctx;
|
|
1846
|
+
const overrides = {};
|
|
1847
|
+
let hasOverrides = false;
|
|
1848
|
+
if (args.output || args.format) {
|
|
1849
|
+
overrides.output = {
|
|
1850
|
+
file: args.output,
|
|
1851
|
+
format: args.format
|
|
1852
|
+
};
|
|
1853
|
+
hasOverrides = true;
|
|
1829
1854
|
}
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1855
|
+
if (args.css) {
|
|
1856
|
+
overrides.tailwind = {
|
|
1857
|
+
v4: {
|
|
1858
|
+
cssEntries: [args.css]
|
|
1859
|
+
}
|
|
1860
|
+
};
|
|
1861
|
+
hasOverrides = true;
|
|
1862
|
+
}
|
|
1863
|
+
const patcher = await ctx.createPatcher(hasOverrides ? overrides : void 0);
|
|
1864
|
+
const result = await patcher.extract({ write: args.write });
|
|
1865
|
+
if (result.filename) {
|
|
1866
|
+
logger_default.success(`Collected ${result.classList.length} classes \u2192 ${result.filename}`);
|
|
1867
|
+
} else {
|
|
1868
|
+
logger_default.success(`Collected ${result.classList.length} classes.`);
|
|
1869
|
+
}
|
|
1870
|
+
return result;
|
|
1871
|
+
}
|
|
1872
|
+
async function tokensCommandDefaultHandler(ctx) {
|
|
1873
|
+
const { args } = ctx;
|
|
1874
|
+
const patcher = await ctx.createPatcher();
|
|
1875
|
+
const report = await patcher.collectContentTokens();
|
|
1876
|
+
const shouldWrite = args.write ?? true;
|
|
1877
|
+
let format = args.format ?? "json";
|
|
1878
|
+
if (!TOKEN_FORMATS.includes(format)) {
|
|
1879
|
+
format = "json";
|
|
1880
|
+
}
|
|
1881
|
+
const targetFile = args.output ?? DEFAULT_TOKEN_REPORT;
|
|
1882
|
+
const groupKey = args.groupKey === "absolute" ? "absolute" : "relative";
|
|
1883
|
+
const buildGrouped = () => groupTokensByFile(report, {
|
|
1884
|
+
key: groupKey,
|
|
1885
|
+
stripAbsolutePaths: groupKey !== "absolute"
|
|
1835
1886
|
});
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1887
|
+
const grouped = format === "grouped-json" ? buildGrouped() : null;
|
|
1888
|
+
const resolveGrouped = () => grouped ?? buildGrouped();
|
|
1889
|
+
if (shouldWrite) {
|
|
1890
|
+
const target = path9.resolve(targetFile);
|
|
1891
|
+
await fs8.ensureDir(path9.dirname(target));
|
|
1892
|
+
if (format === "json") {
|
|
1893
|
+
await fs8.writeJSON(target, report, { spaces: 2 });
|
|
1894
|
+
} else if (format === "grouped-json") {
|
|
1895
|
+
await fs8.writeJSON(target, resolveGrouped(), { spaces: 2 });
|
|
1896
|
+
} else {
|
|
1897
|
+
const lines = report.entries.map(formatTokenLine);
|
|
1898
|
+
await fs8.writeFile(target, `${lines.join("\n")}
|
|
1899
|
+
`, "utf8");
|
|
1900
|
+
}
|
|
1901
|
+
logger_default.success(`Collected ${report.entries.length} tokens (${format}) \u2192 ${target.replace(process5.cwd(), ".")}`);
|
|
1902
|
+
} else {
|
|
1903
|
+
logger_default.success(`Collected ${report.entries.length} tokens from ${report.filesScanned} files.`);
|
|
1904
|
+
if (format === "lines") {
|
|
1905
|
+
const preview = report.entries.slice(0, 5).map(formatTokenLine).join("\n");
|
|
1906
|
+
if (preview) {
|
|
1907
|
+
logger_default.log("");
|
|
1908
|
+
logger_default.info(preview);
|
|
1909
|
+
if (report.entries.length > 5) {
|
|
1910
|
+
logger_default.info(`\u2026and ${report.entries.length - 5} more.`);
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
} else if (format === "grouped-json") {
|
|
1914
|
+
const map = resolveGrouped();
|
|
1915
|
+
const { preview, moreFiles } = formatGroupedPreview(map);
|
|
1916
|
+
if (preview) {
|
|
1917
|
+
logger_default.log("");
|
|
1918
|
+
logger_default.info(preview);
|
|
1919
|
+
if (moreFiles > 0) {
|
|
1920
|
+
logger_default.info(`\u2026and ${moreFiles} more files.`);
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
} else {
|
|
1924
|
+
const previewEntries = report.entries.slice(0, 3);
|
|
1925
|
+
if (previewEntries.length) {
|
|
1926
|
+
logger_default.log("");
|
|
1927
|
+
logger_default.info(JSON.stringify(previewEntries, null, 2));
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
if (report.skippedFiles.length) {
|
|
1932
|
+
logger_default.warn("Skipped files:");
|
|
1933
|
+
for (const skipped of report.skippedFiles) {
|
|
1934
|
+
logger_default.warn(` \u2022 ${skipped.file} (${skipped.reason})`);
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
return report;
|
|
1938
|
+
}
|
|
1939
|
+
async function initCommandDefaultHandler(ctx) {
|
|
1940
|
+
await initConfig(ctx.cwd);
|
|
1941
|
+
logger_default.success(`\u2728 ${CONFIG_NAME}.config.ts initialized!`);
|
|
1942
|
+
}
|
|
1943
|
+
function mountTailwindcssPatchCommands(cli, options = {}) {
|
|
1944
|
+
const prefix = options.commandPrefix ?? "";
|
|
1945
|
+
const selectedCommands = options.commands ?? tailwindcssPatchCommands;
|
|
1946
|
+
const defaultDefinitions = buildDefaultCommandDefinitions();
|
|
1947
|
+
const registrars = {
|
|
1948
|
+
install: () => {
|
|
1949
|
+
const metadata = resolveCommandMetadata("install", options, prefix, defaultDefinitions);
|
|
1950
|
+
const command = cli.command(metadata.name, metadata.description);
|
|
1951
|
+
applyCommandOptions(command, metadata.optionDefs);
|
|
1952
|
+
command.action(async (args) => {
|
|
1953
|
+
return runWithCommandHandler(
|
|
1954
|
+
cli,
|
|
1955
|
+
command,
|
|
1956
|
+
"install",
|
|
1957
|
+
args,
|
|
1958
|
+
options.commandHandlers?.install,
|
|
1959
|
+
installCommandDefaultHandler
|
|
1960
|
+
);
|
|
1961
|
+
});
|
|
1962
|
+
metadata.aliases.forEach((alias) => command.alias(alias));
|
|
1963
|
+
},
|
|
1964
|
+
extract: () => {
|
|
1965
|
+
const metadata = resolveCommandMetadata("extract", options, prefix, defaultDefinitions);
|
|
1966
|
+
const command = cli.command(metadata.name, metadata.description);
|
|
1967
|
+
applyCommandOptions(command, metadata.optionDefs);
|
|
1968
|
+
command.action(async (args) => {
|
|
1969
|
+
return runWithCommandHandler(
|
|
1970
|
+
cli,
|
|
1971
|
+
command,
|
|
1972
|
+
"extract",
|
|
1973
|
+
args,
|
|
1974
|
+
options.commandHandlers?.extract,
|
|
1975
|
+
extractCommandDefaultHandler
|
|
1976
|
+
);
|
|
1977
|
+
});
|
|
1978
|
+
metadata.aliases.forEach((alias) => command.alias(alias));
|
|
1979
|
+
},
|
|
1980
|
+
tokens: () => {
|
|
1981
|
+
const metadata = resolveCommandMetadata("tokens", options, prefix, defaultDefinitions);
|
|
1982
|
+
const command = cli.command(metadata.name, metadata.description);
|
|
1983
|
+
applyCommandOptions(command, metadata.optionDefs);
|
|
1984
|
+
command.action(async (args) => {
|
|
1985
|
+
return runWithCommandHandler(
|
|
1986
|
+
cli,
|
|
1987
|
+
command,
|
|
1988
|
+
"tokens",
|
|
1989
|
+
args,
|
|
1990
|
+
options.commandHandlers?.tokens,
|
|
1991
|
+
tokensCommandDefaultHandler
|
|
1992
|
+
);
|
|
1993
|
+
});
|
|
1994
|
+
metadata.aliases.forEach((alias) => command.alias(alias));
|
|
1995
|
+
},
|
|
1996
|
+
init: () => {
|
|
1997
|
+
const metadata = resolveCommandMetadata("init", options, prefix, defaultDefinitions);
|
|
1998
|
+
const command = cli.command(metadata.name, metadata.description);
|
|
1999
|
+
applyCommandOptions(command, metadata.optionDefs);
|
|
2000
|
+
command.action(async (args) => {
|
|
2001
|
+
return runWithCommandHandler(
|
|
2002
|
+
cli,
|
|
2003
|
+
command,
|
|
2004
|
+
"init",
|
|
2005
|
+
args,
|
|
2006
|
+
options.commandHandlers?.init,
|
|
2007
|
+
initCommandDefaultHandler
|
|
2008
|
+
);
|
|
2009
|
+
});
|
|
2010
|
+
metadata.aliases.forEach((alias) => command.alias(alias));
|
|
2011
|
+
}
|
|
1839
2012
|
};
|
|
2013
|
+
for (const name of selectedCommands) {
|
|
2014
|
+
const register = registrars[name];
|
|
2015
|
+
if (register) {
|
|
2016
|
+
register();
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
return cli;
|
|
2020
|
+
}
|
|
2021
|
+
function createTailwindcssPatchCli(options = {}) {
|
|
2022
|
+
const cli = cac(options.name ?? "tw-patch");
|
|
2023
|
+
mountTailwindcssPatchCommands(cli, options.mountOptions);
|
|
2024
|
+
return cli;
|
|
1840
2025
|
}
|
|
1841
2026
|
|
|
1842
2027
|
export {
|
|
@@ -1854,6 +2039,6 @@ export {
|
|
|
1854
2039
|
runTailwindBuild,
|
|
1855
2040
|
TailwindcssPatcher,
|
|
1856
2041
|
tailwindcssPatchCommands,
|
|
1857
|
-
|
|
1858
|
-
|
|
2042
|
+
mountTailwindcssPatchCommands,
|
|
2043
|
+
createTailwindcssPatchCli
|
|
1859
2044
|
};
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkPF5ZTTYMjs = require('./chunk-PF5ZTTYM.js');
|
|
4
4
|
|
|
5
5
|
// src/cli.ts
|
|
6
|
-
var cli =
|
|
6
|
+
var cli = _chunkPF5ZTTYMjs.createTailwindcssPatchCli.call(void 0, );
|
|
7
7
|
cli.help();
|
|
8
8
|
cli.parse();
|
package/dist/cli.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -2,9 +2,9 @@ import { SourceEntry } from '@tailwindcss/oxide';
|
|
|
2
2
|
import postcss, { Node, Rule } from 'postcss';
|
|
3
3
|
import { Config } from 'tailwindcss';
|
|
4
4
|
import { PackageResolvingOptions, PackageInfo } from 'local-pkg';
|
|
5
|
-
import { TailwindLocatorOptions, TailwindNextOptions } from '@tailwindcss-mangle/config';
|
|
5
|
+
import { TailwindLocatorOptions, TailwindNextOptions, getConfig } from '@tailwindcss-mangle/config';
|
|
6
6
|
export { defineConfig } from '@tailwindcss-mangle/config';
|
|
7
|
-
import { CAC } from 'cac';
|
|
7
|
+
import { Command, CAC } from 'cac';
|
|
8
8
|
import * as consola from 'consola';
|
|
9
9
|
|
|
10
10
|
type CacheStrategy = 'merge' | 'overwrite';
|
|
@@ -423,25 +423,83 @@ declare class CacheStore {
|
|
|
423
423
|
readSync(): Set<string>;
|
|
424
424
|
}
|
|
425
425
|
|
|
426
|
+
declare const logger: consola.ConsolaInstance;
|
|
427
|
+
|
|
426
428
|
type TailwindcssPatchCommand = 'install' | 'extract' | 'tokens' | 'init';
|
|
427
429
|
declare const tailwindcssPatchCommands: TailwindcssPatchCommand[];
|
|
430
|
+
type TokenOutputFormat = 'json' | 'lines' | 'grouped-json';
|
|
431
|
+
type TokenGroupKey = 'relative' | 'absolute';
|
|
432
|
+
type CacOptionConfig = Parameters<Command['option']>[2];
|
|
433
|
+
interface TailwindcssPatchCommandOptionDefinition {
|
|
434
|
+
flags: string;
|
|
435
|
+
description?: string;
|
|
436
|
+
config?: CacOptionConfig;
|
|
437
|
+
}
|
|
428
438
|
interface TailwindcssPatchCommandOptions {
|
|
429
439
|
name?: string;
|
|
430
440
|
aliases?: string[];
|
|
441
|
+
description?: string;
|
|
442
|
+
optionDefs?: TailwindcssPatchCommandOptionDefinition[];
|
|
443
|
+
appendDefaultOptions?: boolean;
|
|
431
444
|
}
|
|
445
|
+
interface BaseCommandArgs {
|
|
446
|
+
cwd: string;
|
|
447
|
+
}
|
|
448
|
+
interface InstallCommandArgs extends BaseCommandArgs {
|
|
449
|
+
}
|
|
450
|
+
interface ExtractCommandArgs extends BaseCommandArgs {
|
|
451
|
+
output?: string;
|
|
452
|
+
format?: 'json' | 'lines';
|
|
453
|
+
css?: string;
|
|
454
|
+
write?: boolean;
|
|
455
|
+
}
|
|
456
|
+
interface TokensCommandArgs extends BaseCommandArgs {
|
|
457
|
+
output?: string;
|
|
458
|
+
format?: TokenOutputFormat;
|
|
459
|
+
groupKey?: TokenGroupKey;
|
|
460
|
+
write?: boolean;
|
|
461
|
+
}
|
|
462
|
+
interface InitCommandArgs extends BaseCommandArgs {
|
|
463
|
+
}
|
|
464
|
+
interface TailwindcssPatchCommandArgMap {
|
|
465
|
+
install: InstallCommandArgs;
|
|
466
|
+
extract: ExtractCommandArgs;
|
|
467
|
+
tokens: TokensCommandArgs;
|
|
468
|
+
init: InitCommandArgs;
|
|
469
|
+
}
|
|
470
|
+
interface TailwindcssPatchCommandResultMap {
|
|
471
|
+
install: void;
|
|
472
|
+
extract: ExtractResult;
|
|
473
|
+
tokens: TailwindTokenReport;
|
|
474
|
+
init: void;
|
|
475
|
+
}
|
|
476
|
+
interface TailwindcssPatchCommandContext<TCommand extends TailwindcssPatchCommand> {
|
|
477
|
+
cli: CAC;
|
|
478
|
+
command: Command;
|
|
479
|
+
commandName: TCommand;
|
|
480
|
+
args: TailwindcssPatchCommandArgMap[TCommand];
|
|
481
|
+
cwd: string;
|
|
482
|
+
logger: typeof logger;
|
|
483
|
+
loadConfig: () => ReturnType<typeof getConfig>;
|
|
484
|
+
loadPatchOptions: (overrides?: TailwindcssPatchOptions) => Promise<TailwindcssPatchOptions>;
|
|
485
|
+
createPatcher: (overrides?: TailwindcssPatchOptions) => Promise<TailwindcssPatcher>;
|
|
486
|
+
}
|
|
487
|
+
type TailwindcssPatchCommandHandler<TCommand extends TailwindcssPatchCommand> = (context: TailwindcssPatchCommandContext<TCommand>, next: () => Promise<TailwindcssPatchCommandResultMap[TCommand]>) => Promise<TailwindcssPatchCommandResultMap[TCommand]> | TailwindcssPatchCommandResultMap[TCommand];
|
|
488
|
+
type TailwindcssPatchCommandHandlerMap = Partial<{
|
|
489
|
+
[K in TailwindcssPatchCommand]: TailwindcssPatchCommandHandler<K>;
|
|
490
|
+
}>;
|
|
432
491
|
interface TailwindcssPatchCliMountOptions {
|
|
433
492
|
commandPrefix?: string;
|
|
434
493
|
commands?: TailwindcssPatchCommand[];
|
|
435
494
|
commandOptions?: Partial<Record<TailwindcssPatchCommand, TailwindcssPatchCommandOptions>>;
|
|
495
|
+
commandHandlers?: TailwindcssPatchCommandHandlerMap;
|
|
436
496
|
}
|
|
437
497
|
interface TailwindcssPatchCliOptions {
|
|
438
498
|
name?: string;
|
|
439
499
|
mountOptions?: TailwindcssPatchCliMountOptions;
|
|
440
500
|
}
|
|
441
|
-
declare function createTailwindcssPatchCli(options?: TailwindcssPatchCliOptions): CAC;
|
|
442
501
|
declare function mountTailwindcssPatchCommands(cli: CAC, options?: TailwindcssPatchCliMountOptions): CAC;
|
|
443
|
-
|
|
444
|
-
declare const logger: consola.ConsolaInstance;
|
|
502
|
+
declare function createTailwindcssPatchCli(options?: TailwindcssPatchCliOptions): CAC;
|
|
445
503
|
|
|
446
504
|
declare function normalizeOptions(options?: TailwindcssPatchOptions): NormalizedTailwindcssPatchOptions;
|
|
447
505
|
|
|
@@ -458,4 +516,4 @@ interface TailwindBuildOptions {
|
|
|
458
516
|
}
|
|
459
517
|
declare function runTailwindBuild(options: TailwindBuildOptions): Promise<postcss.Result<postcss.Root>>;
|
|
460
518
|
|
|
461
|
-
export { CacheStore, type CacheStrategy, type ExtractResult, type ILengthUnitsPatchOptions, type NormalizedTailwindcssPatchOptions, type TailwindPatchRuntime, type TailwindTokenByFileMap, type TailwindTokenFileKey, type TailwindTokenLocation, type TailwindTokenReport, type TailwindcssClassCache, type TailwindcssPatchCliMountOptions, type TailwindcssPatchCliOptions, type TailwindcssPatchCommand, type TailwindcssPatchCommandOptions, type TailwindcssPatchOptions, TailwindcssPatcher, type TailwindcssRuntimeContext, collectClassesFromContexts, collectClassesFromTailwindV4, createTailwindcssPatchCli, extractProjectCandidatesWithPositions, extractRawCandidates, extractRawCandidatesWithPositions, extractValidCandidates, groupTokensByFile, loadRuntimeContexts, logger, mountTailwindcssPatchCommands, normalizeOptions, runTailwindBuild, tailwindcssPatchCommands };
|
|
519
|
+
export { CacheStore, type CacheStrategy, type ExtractResult, type ILengthUnitsPatchOptions, type NormalizedTailwindcssPatchOptions, type TailwindPatchRuntime, type TailwindTokenByFileMap, type TailwindTokenFileKey, type TailwindTokenLocation, type TailwindTokenReport, type TailwindcssClassCache, type TailwindcssPatchCliMountOptions, type TailwindcssPatchCliOptions, type TailwindcssPatchCommand, type TailwindcssPatchCommandContext, type TailwindcssPatchCommandHandler, type TailwindcssPatchCommandHandlerMap, type TailwindcssPatchCommandOptionDefinition, type TailwindcssPatchCommandOptions, type TailwindcssPatchOptions, TailwindcssPatcher, type TailwindcssRuntimeContext, collectClassesFromContexts, collectClassesFromTailwindV4, createTailwindcssPatchCli, extractProjectCandidatesWithPositions, extractRawCandidates, extractRawCandidatesWithPositions, extractValidCandidates, groupTokensByFile, loadRuntimeContexts, logger, mountTailwindcssPatchCommands, normalizeOptions, runTailwindBuild, tailwindcssPatchCommands };
|