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 CHANGED
@@ -59,6 +59,40 @@ cli.help()
59
59
  cli.parse()
60
60
  ```
61
61
 
62
+ #### Custom command hooks
63
+
64
+ Hosts can override per-command lifecycles by supplying `commandHandlers`. Each handler receives a context object (with the resolved `cwd`, parsed `args`, memoized `loadConfig`/`createPatcher` helpers, and the shared `logger`) plus a `next()` callback that runs the built-in action.
65
+
66
+ ```ts
67
+ mountTailwindcssPatchCommands(cli, {
68
+ commandHandlers: {
69
+ install: async (ctx) => {
70
+ const patcher = await ctx.createPatcher()
71
+ await clearTailwindcssPatcherCache(ctx.cwd)
72
+ await patcher.patch()
73
+ await saveCliPatchTargetRecord({ cwd: ctx.cwd })
74
+ },
75
+ extract: async (ctx, next) => {
76
+ const result = await next() // run the default extract implementation
77
+ ctx.logger.success(`[host] wrote ${result.classList.length} classes`)
78
+ return result
79
+ },
80
+ },
81
+ commandOptions: {
82
+ extract: {
83
+ description: 'Localised extract command',
84
+ appendDefaultOptions: false,
85
+ optionDefs: [
86
+ { flags: '--entry <file>', description: 'Tailwind CSS entry file' },
87
+ { flags: '--preview', description: 'Print a preview instead of writing' },
88
+ ],
89
+ },
90
+ },
91
+ })
92
+ ```
93
+
94
+ Skip `next()` to fully replace a command (e.g. custom `init` or cache clearing before `install`). Calling `next()` returns the default result—`ExtractResult`, `TailwindTokenReport`, etc.—so hosts can log metadata or feed it into their own telemetry without re-implementing the commands.
95
+
62
96
  ### Extract options
63
97
 
64
98
  | Flag | Description |
@@ -73,13 +107,13 @@ The CLI loads `tailwindcss-patch.config.ts` via `@tailwindcss-mangle/config`. Le
73
107
 
74
108
  ### Token report options
75
109
 
76
- | Flag | Description |
77
- | ------------------------ | --------------------------------------------------------------------------- |
78
- | `--cwd <dir>` | Use a different working directory when loading configuration. |
79
- | `--output <file>` | Override the token report target file (defaults to `.tw-patch/tw-token-report.json`). |
110
+ | Flag | Description |
111
+ | -------------------------------------- | ----------------------------------------------------------------------------------------- |
112
+ | `--cwd <dir>` | Use a different working directory when loading configuration. |
113
+ | `--output <file>` | Override the token report target file (defaults to `.tw-patch/tw-token-report.json`). |
80
114
  | `--format <json\|lines\|grouped-json>` | Choose between a JSON payload (default), newline summaries, or JSON grouped by file path. |
81
- | `--group-key <relative\|absolute>` | Control grouped-json keys (defaults to relative paths). |
82
- | `--no-write` | Skip writing to disk and only print a preview. |
115
+ | `--group-key <relative\|absolute>` | Control grouped-json keys (defaults to relative paths). |
116
+ | `--no-write` | Skip writing to disk and only print a preview. |
83
117
 
84
118
  ## Programmatic API
85
119
 
@@ -1660,156 +1660,143 @@ var acceptChars = [..."abcdefghijklmnopqrstuvwxyz"];
1660
1660
  var _cac = require('cac'); var _cac2 = _interopRequireDefault(_cac);
1661
1661
 
1662
1662
 
1663
- var tailwindcssPatchCommands = [
1664
- "install",
1665
- "extract",
1666
- "tokens",
1667
- "init"
1668
- ];
1669
- function createTailwindcssPatchCli(options = {}) {
1670
- const cli = _cac2.default.call(void 0, _nullishCoalesce(options.name, () => ( "tw-patch")));
1671
- mountTailwindcssPatchCommands(cli, options.mountOptions);
1672
- return cli;
1663
+ var tailwindcssPatchCommands = ["install", "extract", "tokens", "init"];
1664
+ var TOKEN_FORMATS = ["json", "lines", "grouped-json"];
1665
+ var DEFAULT_TOKEN_REPORT = ".tw-patch/tw-token-report.json";
1666
+ function formatTokenLine(entry) {
1667
+ return `${entry.relativeFile}:${entry.line}:${entry.column} ${entry.rawCandidate} (${entry.start}-${entry.end})`;
1673
1668
  }
1674
- function mountTailwindcssPatchCommands(cli, options = {}) {
1675
- const prefix = _nullishCoalesce(options.commandPrefix, () => ( ""));
1676
- const selectedCommands = _nullishCoalesce(options.commands, () => ( tailwindcssPatchCommands));
1677
- const TOKEN_FORMATS = ["json", "lines", "grouped-json"];
1678
- const registrars = {
1679
- install() {
1680
- const { name, aliases } = resolveCommandNames("install", options, prefix);
1681
- const command = cli.command(name, "Apply Tailwind CSS runtime patches").option("--cwd <dir>", "Working directory", { default: _process2.default.cwd() }).action(async (args) => {
1682
- const patchOptions = await loadPatchOptions(args.cwd);
1683
- const patcher = new TailwindcssPatcher(patchOptions);
1684
- await patcher.patch();
1685
- logger_default.success("Tailwind CSS runtime patched successfully.");
1686
- });
1687
- aliases.forEach((alias) => command.alias(alias));
1688
- },
1689
- extract() {
1690
- const { name, aliases } = resolveCommandNames("extract", options, prefix);
1691
- const command = cli.command(name, "Collect generated class names into a cache file").option("--cwd <dir>", "Working directory", { default: _process2.default.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) => {
1692
- const overrides = {};
1693
- if (args.output || args.format) {
1694
- overrides.output = {
1695
- file: args.output,
1696
- format: args.format
1697
- };
1698
- }
1699
- if (args.css) {
1700
- overrides.tailwind = {
1701
- v4: {
1702
- cssEntries: [args.css]
1703
- }
1704
- };
1705
- }
1706
- const patchOptions = await loadPatchOptions(args.cwd, overrides);
1707
- const patcher = new TailwindcssPatcher(patchOptions);
1708
- const result = await patcher.extract({ write: args.write });
1709
- if (result.filename) {
1710
- logger_default.success(`Collected ${result.classList.length} classes \u2192 ${result.filename}`);
1711
- } else {
1712
- logger_default.success(`Collected ${result.classList.length} classes.`);
1713
- }
1714
- });
1715
- aliases.forEach((alias) => command.alias(alias));
1716
- },
1717
- tokens() {
1718
- const { name, aliases } = resolveCommandNames("tokens", options, prefix);
1719
- const command = cli.command(name, "Extract Tailwind tokens with file/position metadata").option("--cwd <dir>", "Working directory", { default: _process2.default.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) => {
1720
- const patchOptions = await loadPatchOptions(args.cwd);
1721
- const patcher = new TailwindcssPatcher(patchOptions);
1722
- const report = await patcher.collectContentTokens();
1723
- const shouldWrite = _nullishCoalesce(args.write, () => ( true));
1724
- let format = _nullishCoalesce(args.format, () => ( "json"));
1725
- if (!TOKEN_FORMATS.includes(format)) {
1726
- format = "json";
1727
- }
1728
- const targetFile = _nullishCoalesce(args.output, () => ( ".tw-patch/tw-token-report.json"));
1729
- const groupKey = args.groupKey === "absolute" ? "absolute" : "relative";
1730
- const buildGrouped = () => groupTokensByFile(report, {
1731
- key: groupKey,
1732
- stripAbsolutePaths: groupKey !== "absolute"
1733
- });
1734
- const grouped = format === "grouped-json" ? buildGrouped() : null;
1735
- const resolveGrouped = () => _nullishCoalesce(grouped, () => ( buildGrouped()));
1736
- if (shouldWrite) {
1737
- const target = _pathe2.default.resolve(targetFile);
1738
- await _fsextra2.default.ensureDir(_pathe2.default.dirname(target));
1739
- if (format === "json") {
1740
- await _fsextra2.default.writeJSON(target, report, { spaces: 2 });
1741
- } else if (format === "grouped-json") {
1742
- await _fsextra2.default.writeJSON(target, resolveGrouped(), { spaces: 2 });
1743
- } else {
1744
- const lines = report.entries.map(formatTokenLine);
1745
- await _fsextra2.default.writeFile(target, `${lines.join("\n")}
1746
- `, "utf8");
1747
- }
1748
- logger_default.success(
1749
- `Collected ${report.entries.length} tokens (${format}) \u2192 ${target.replace(_process2.default.cwd(), ".")}`
1750
- );
1751
- } else {
1752
- logger_default.success(`Collected ${report.entries.length} tokens from ${report.filesScanned} files.`);
1753
- if (format === "lines") {
1754
- const preview = report.entries.slice(0, 5).map(formatTokenLine).join("\n");
1755
- if (preview) {
1756
- logger_default.log("");
1757
- logger_default.info(preview);
1758
- if (report.entries.length > 5) {
1759
- logger_default.info(`\u2026and ${report.entries.length - 5} more.`);
1760
- }
1761
- }
1762
- } else if (format === "grouped-json") {
1763
- const map = resolveGrouped();
1764
- const { preview, moreFiles } = formatGroupedPreview(map);
1765
- if (preview) {
1766
- logger_default.log("");
1767
- logger_default.info(preview);
1768
- if (moreFiles > 0) {
1769
- logger_default.info(`\u2026and ${moreFiles} more files.`);
1770
- }
1771
- }
1772
- } else {
1773
- const previewEntries = report.entries.slice(0, 3);
1774
- if (previewEntries.length) {
1775
- logger_default.log("");
1776
- logger_default.info(JSON.stringify(previewEntries, null, 2));
1777
- }
1778
- }
1779
- }
1780
- if (report.skippedFiles.length) {
1781
- logger_default.warn("Skipped files:");
1782
- for (const skipped of report.skippedFiles) {
1783
- logger_default.warn(` \u2022 ${skipped.file} (${skipped.reason})`);
1784
- }
1785
- }
1786
- });
1787
- aliases.forEach((alias) => command.alias(alias));
1788
- },
1789
- init() {
1790
- const { name, aliases } = resolveCommandNames("init", options, prefix);
1791
- const command = cli.command(name, "Generate a tailwindcss-patch config file").option("--cwd <dir>", "Working directory", { default: _process2.default.cwd() }).action(async (args) => {
1792
- await _config.initConfig.call(void 0, args.cwd);
1793
- logger_default.success(`\u2728 ${_config.CONFIG_NAME}.config.ts initialized!`);
1794
- });
1795
- aliases.forEach((alias) => command.alias(alias));
1796
- }
1669
+ function formatGroupedPreview(map, limit = 3) {
1670
+ const files = Object.keys(map);
1671
+ if (!files.length) {
1672
+ return { preview: "", moreFiles: 0 };
1673
+ }
1674
+ const lines = files.slice(0, limit).map((file) => {
1675
+ const tokens = map[file];
1676
+ const sample = tokens.slice(0, 3).map((token) => token.rawCandidate).join(", ");
1677
+ const suffix = tokens.length > 3 ? ", \u2026" : "";
1678
+ return `${file}: ${tokens.length} tokens (${sample}${suffix})`;
1679
+ });
1680
+ return {
1681
+ preview: lines.join("\n"),
1682
+ moreFiles: Math.max(0, files.length - limit)
1797
1683
  };
1798
- for (const name of selectedCommands) {
1799
- const register = registrars[name];
1800
- if (register) {
1801
- register();
1802
- }
1684
+ }
1685
+ function resolveCwd(rawCwd) {
1686
+ if (!rawCwd) {
1687
+ return _process2.default.cwd();
1803
1688
  }
1804
- return cli;
1689
+ return _pathe2.default.resolve(rawCwd);
1805
1690
  }
1806
- async function loadPatchOptions(cwd, overrides) {
1691
+ function createDefaultRunner(factory) {
1692
+ let promise;
1693
+ return () => {
1694
+ if (!promise) {
1695
+ promise = factory();
1696
+ }
1697
+ return promise;
1698
+ };
1699
+ }
1700
+ async function loadPatchOptionsForCwd(cwd, overrides) {
1807
1701
  const { config } = await _config.getConfig.call(void 0, cwd);
1808
1702
  const legacyConfig = config;
1809
1703
  const base = _optionalChain([config, 'optionalAccess', _79 => _79.registry]) ? fromUnifiedConfig(config.registry) : _optionalChain([legacyConfig, 'optionalAccess', _80 => _80.patch]) ? fromLegacyOptions({ patch: legacyConfig.patch }) : {};
1810
1704
  const merged = defu(_nullishCoalesce(overrides, () => ( {})), base);
1811
1705
  return merged;
1812
1706
  }
1707
+ function createCommandContext(cli, command, commandName, args, cwd) {
1708
+ let cachedOptions;
1709
+ let cachedPatcher;
1710
+ let cachedConfig;
1711
+ const loadPatchOptionsForContext = (overrides) => {
1712
+ if (overrides) {
1713
+ return loadPatchOptionsForCwd(cwd, overrides);
1714
+ }
1715
+ if (!cachedOptions) {
1716
+ cachedOptions = loadPatchOptionsForCwd(cwd);
1717
+ }
1718
+ return cachedOptions;
1719
+ };
1720
+ const createPatcherForContext = async (overrides) => {
1721
+ if (overrides) {
1722
+ const patchOptions = await loadPatchOptionsForCwd(cwd, overrides);
1723
+ return new TailwindcssPatcher(patchOptions);
1724
+ }
1725
+ if (!cachedPatcher) {
1726
+ cachedPatcher = loadPatchOptionsForContext().then((options) => new TailwindcssPatcher(options));
1727
+ }
1728
+ return cachedPatcher;
1729
+ };
1730
+ return {
1731
+ cli,
1732
+ command,
1733
+ commandName,
1734
+ args,
1735
+ cwd,
1736
+ logger: logger_default,
1737
+ loadConfig: () => {
1738
+ if (!cachedConfig) {
1739
+ cachedConfig = _config.getConfig.call(void 0, cwd);
1740
+ }
1741
+ return cachedConfig;
1742
+ },
1743
+ loadPatchOptions: loadPatchOptionsForContext,
1744
+ createPatcher: createPatcherForContext
1745
+ };
1746
+ }
1747
+ function createCwdOptionDefinition(description = "Working directory") {
1748
+ return {
1749
+ flags: "--cwd <dir>",
1750
+ description,
1751
+ config: { default: _process2.default.cwd() }
1752
+ };
1753
+ }
1754
+ function buildDefaultCommandDefinitions() {
1755
+ return {
1756
+ install: {
1757
+ description: "Apply Tailwind CSS runtime patches",
1758
+ optionDefs: [createCwdOptionDefinition()]
1759
+ },
1760
+ extract: {
1761
+ description: "Collect generated class names into a cache file",
1762
+ optionDefs: [
1763
+ createCwdOptionDefinition(),
1764
+ { flags: "--output <file>", description: "Override output file path" },
1765
+ { flags: "--format <format>", description: "Output format (json|lines)" },
1766
+ { flags: "--css <file>", description: "Tailwind CSS entry CSS when using v4" },
1767
+ { flags: "--no-write", description: "Skip writing to disk" }
1768
+ ]
1769
+ },
1770
+ tokens: {
1771
+ description: "Extract Tailwind tokens with file/position metadata",
1772
+ optionDefs: [
1773
+ createCwdOptionDefinition(),
1774
+ { flags: "--output <file>", description: "Override output file path", config: { default: DEFAULT_TOKEN_REPORT } },
1775
+ {
1776
+ flags: "--format <format>",
1777
+ description: "Output format (json|lines|grouped-json)",
1778
+ config: { default: "json" }
1779
+ },
1780
+ {
1781
+ flags: "--group-key <key>",
1782
+ description: "Grouping key for grouped-json output (relative|absolute)",
1783
+ config: { default: "relative" }
1784
+ },
1785
+ { flags: "--no-write", description: "Skip writing to disk" }
1786
+ ]
1787
+ },
1788
+ init: {
1789
+ description: "Generate a tailwindcss-patch config file",
1790
+ optionDefs: [createCwdOptionDefinition()]
1791
+ }
1792
+ };
1793
+ }
1794
+ function addPrefixIfMissing(value, prefix) {
1795
+ if (!prefix || value.startsWith(prefix)) {
1796
+ return value;
1797
+ }
1798
+ return `${prefix}${value}`;
1799
+ }
1813
1800
  function resolveCommandNames(command, mountOptions, prefix) {
1814
1801
  const override = _optionalChain([mountOptions, 'access', _81 => _81.commandOptions, 'optionalAccess', _82 => _82[command]]);
1815
1802
  const baseName = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _83 => _83.name]), () => ( command));
@@ -1817,30 +1804,228 @@ function resolveCommandNames(command, mountOptions, prefix) {
1817
1804
  const aliases = (_nullishCoalesce(_optionalChain([override, 'optionalAccess', _84 => _84.aliases]), () => ( []))).map((alias) => addPrefixIfMissing(alias, prefix));
1818
1805
  return { name, aliases };
1819
1806
  }
1820
- function addPrefixIfMissing(value, prefix) {
1821
- if (!prefix || value.startsWith(prefix)) {
1822
- return value;
1807
+ function resolveOptionDefinitions(defaults, override) {
1808
+ if (!override) {
1809
+ return defaults;
1823
1810
  }
1824
- return `${prefix}${value}`;
1811
+ const appendDefaults = _nullishCoalesce(override.appendDefaultOptions, () => ( true));
1812
+ const customDefs = _nullishCoalesce(override.optionDefs, () => ( []));
1813
+ if (!appendDefaults) {
1814
+ return customDefs;
1815
+ }
1816
+ if (customDefs.length === 0) {
1817
+ return defaults;
1818
+ }
1819
+ return [...defaults, ...customDefs];
1825
1820
  }
1826
- function formatTokenLine(entry) {
1827
- return `${entry.relativeFile}:${entry.line}:${entry.column} ${entry.rawCandidate} (${entry.start}-${entry.end})`;
1821
+ function applyCommandOptions(command, optionDefs) {
1822
+ for (const option of optionDefs) {
1823
+ command.option(option.flags, _nullishCoalesce(option.description, () => ( "")), option.config);
1824
+ }
1828
1825
  }
1829
- function formatGroupedPreview(map, limit = 3) {
1830
- const files = Object.keys(map);
1831
- if (!files.length) {
1832
- return { preview: "", moreFiles: 0 };
1826
+ function runWithCommandHandler(cli, command, commandName, args, handler, defaultHandler) {
1827
+ const cwd = resolveCwd(args.cwd);
1828
+ const context = createCommandContext(cli, command, commandName, args, cwd);
1829
+ const runDefault = createDefaultRunner(() => defaultHandler(context));
1830
+ if (!handler) {
1831
+ return runDefault();
1832
+ }
1833
+ return handler(context, runDefault);
1834
+ }
1835
+ function resolveCommandMetadata(command, mountOptions, prefix, defaults) {
1836
+ const names = resolveCommandNames(command, mountOptions, prefix);
1837
+ const definition = defaults[command];
1838
+ const override = _optionalChain([mountOptions, 'access', _85 => _85.commandOptions, 'optionalAccess', _86 => _86[command]]);
1839
+ const description = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _87 => _87.description]), () => ( definition.description));
1840
+ const optionDefs = resolveOptionDefinitions(definition.optionDefs, override);
1841
+ return { ...names, description, optionDefs };
1842
+ }
1843
+ async function installCommandDefaultHandler(ctx) {
1844
+ const patcher = await ctx.createPatcher();
1845
+ await patcher.patch();
1846
+ logger_default.success("Tailwind CSS runtime patched successfully.");
1847
+ }
1848
+ async function extractCommandDefaultHandler(ctx) {
1849
+ const { args } = ctx;
1850
+ const overrides = {};
1851
+ let hasOverrides = false;
1852
+ if (args.output || args.format) {
1853
+ overrides.output = {
1854
+ file: args.output,
1855
+ format: args.format
1856
+ };
1857
+ hasOverrides = true;
1833
1858
  }
1834
- const lines = files.slice(0, limit).map((file) => {
1835
- const tokens = map[file];
1836
- const sample = tokens.slice(0, 3).map((token) => token.rawCandidate).join(", ");
1837
- const suffix = tokens.length > 3 ? ", \u2026" : "";
1838
- return `${file}: ${tokens.length} tokens (${sample}${suffix})`;
1859
+ if (args.css) {
1860
+ overrides.tailwind = {
1861
+ v4: {
1862
+ cssEntries: [args.css]
1863
+ }
1864
+ };
1865
+ hasOverrides = true;
1866
+ }
1867
+ const patcher = await ctx.createPatcher(hasOverrides ? overrides : void 0);
1868
+ const result = await patcher.extract({ write: args.write });
1869
+ if (result.filename) {
1870
+ logger_default.success(`Collected ${result.classList.length} classes \u2192 ${result.filename}`);
1871
+ } else {
1872
+ logger_default.success(`Collected ${result.classList.length} classes.`);
1873
+ }
1874
+ return result;
1875
+ }
1876
+ async function tokensCommandDefaultHandler(ctx) {
1877
+ const { args } = ctx;
1878
+ const patcher = await ctx.createPatcher();
1879
+ const report = await patcher.collectContentTokens();
1880
+ const shouldWrite = _nullishCoalesce(args.write, () => ( true));
1881
+ let format = _nullishCoalesce(args.format, () => ( "json"));
1882
+ if (!TOKEN_FORMATS.includes(format)) {
1883
+ format = "json";
1884
+ }
1885
+ const targetFile = _nullishCoalesce(args.output, () => ( DEFAULT_TOKEN_REPORT));
1886
+ const groupKey = args.groupKey === "absolute" ? "absolute" : "relative";
1887
+ const buildGrouped = () => groupTokensByFile(report, {
1888
+ key: groupKey,
1889
+ stripAbsolutePaths: groupKey !== "absolute"
1839
1890
  });
1840
- return {
1841
- preview: lines.join("\n"),
1842
- moreFiles: Math.max(0, files.length - limit)
1891
+ const grouped = format === "grouped-json" ? buildGrouped() : null;
1892
+ const resolveGrouped = () => _nullishCoalesce(grouped, () => ( buildGrouped()));
1893
+ if (shouldWrite) {
1894
+ const target = _pathe2.default.resolve(targetFile);
1895
+ await _fsextra2.default.ensureDir(_pathe2.default.dirname(target));
1896
+ if (format === "json") {
1897
+ await _fsextra2.default.writeJSON(target, report, { spaces: 2 });
1898
+ } else if (format === "grouped-json") {
1899
+ await _fsextra2.default.writeJSON(target, resolveGrouped(), { spaces: 2 });
1900
+ } else {
1901
+ const lines = report.entries.map(formatTokenLine);
1902
+ await _fsextra2.default.writeFile(target, `${lines.join("\n")}
1903
+ `, "utf8");
1904
+ }
1905
+ logger_default.success(`Collected ${report.entries.length} tokens (${format}) \u2192 ${target.replace(_process2.default.cwd(), ".")}`);
1906
+ } else {
1907
+ logger_default.success(`Collected ${report.entries.length} tokens from ${report.filesScanned} files.`);
1908
+ if (format === "lines") {
1909
+ const preview = report.entries.slice(0, 5).map(formatTokenLine).join("\n");
1910
+ if (preview) {
1911
+ logger_default.log("");
1912
+ logger_default.info(preview);
1913
+ if (report.entries.length > 5) {
1914
+ logger_default.info(`\u2026and ${report.entries.length - 5} more.`);
1915
+ }
1916
+ }
1917
+ } else if (format === "grouped-json") {
1918
+ const map = resolveGrouped();
1919
+ const { preview, moreFiles } = formatGroupedPreview(map);
1920
+ if (preview) {
1921
+ logger_default.log("");
1922
+ logger_default.info(preview);
1923
+ if (moreFiles > 0) {
1924
+ logger_default.info(`\u2026and ${moreFiles} more files.`);
1925
+ }
1926
+ }
1927
+ } else {
1928
+ const previewEntries = report.entries.slice(0, 3);
1929
+ if (previewEntries.length) {
1930
+ logger_default.log("");
1931
+ logger_default.info(JSON.stringify(previewEntries, null, 2));
1932
+ }
1933
+ }
1934
+ }
1935
+ if (report.skippedFiles.length) {
1936
+ logger_default.warn("Skipped files:");
1937
+ for (const skipped of report.skippedFiles) {
1938
+ logger_default.warn(` \u2022 ${skipped.file} (${skipped.reason})`);
1939
+ }
1940
+ }
1941
+ return report;
1942
+ }
1943
+ async function initCommandDefaultHandler(ctx) {
1944
+ await _config.initConfig.call(void 0, ctx.cwd);
1945
+ logger_default.success(`\u2728 ${_config.CONFIG_NAME}.config.ts initialized!`);
1946
+ }
1947
+ function mountTailwindcssPatchCommands(cli, options = {}) {
1948
+ const prefix = _nullishCoalesce(options.commandPrefix, () => ( ""));
1949
+ const selectedCommands = _nullishCoalesce(options.commands, () => ( tailwindcssPatchCommands));
1950
+ const defaultDefinitions = buildDefaultCommandDefinitions();
1951
+ const registrars = {
1952
+ install: () => {
1953
+ const metadata = resolveCommandMetadata("install", options, prefix, defaultDefinitions);
1954
+ const command = cli.command(metadata.name, metadata.description);
1955
+ applyCommandOptions(command, metadata.optionDefs);
1956
+ command.action(async (args) => {
1957
+ return runWithCommandHandler(
1958
+ cli,
1959
+ command,
1960
+ "install",
1961
+ args,
1962
+ _optionalChain([options, 'access', _88 => _88.commandHandlers, 'optionalAccess', _89 => _89.install]),
1963
+ installCommandDefaultHandler
1964
+ );
1965
+ });
1966
+ metadata.aliases.forEach((alias) => command.alias(alias));
1967
+ },
1968
+ extract: () => {
1969
+ const metadata = resolveCommandMetadata("extract", options, prefix, defaultDefinitions);
1970
+ const command = cli.command(metadata.name, metadata.description);
1971
+ applyCommandOptions(command, metadata.optionDefs);
1972
+ command.action(async (args) => {
1973
+ return runWithCommandHandler(
1974
+ cli,
1975
+ command,
1976
+ "extract",
1977
+ args,
1978
+ _optionalChain([options, 'access', _90 => _90.commandHandlers, 'optionalAccess', _91 => _91.extract]),
1979
+ extractCommandDefaultHandler
1980
+ );
1981
+ });
1982
+ metadata.aliases.forEach((alias) => command.alias(alias));
1983
+ },
1984
+ tokens: () => {
1985
+ const metadata = resolveCommandMetadata("tokens", options, prefix, defaultDefinitions);
1986
+ const command = cli.command(metadata.name, metadata.description);
1987
+ applyCommandOptions(command, metadata.optionDefs);
1988
+ command.action(async (args) => {
1989
+ return runWithCommandHandler(
1990
+ cli,
1991
+ command,
1992
+ "tokens",
1993
+ args,
1994
+ _optionalChain([options, 'access', _92 => _92.commandHandlers, 'optionalAccess', _93 => _93.tokens]),
1995
+ tokensCommandDefaultHandler
1996
+ );
1997
+ });
1998
+ metadata.aliases.forEach((alias) => command.alias(alias));
1999
+ },
2000
+ init: () => {
2001
+ const metadata = resolveCommandMetadata("init", options, prefix, defaultDefinitions);
2002
+ const command = cli.command(metadata.name, metadata.description);
2003
+ applyCommandOptions(command, metadata.optionDefs);
2004
+ command.action(async (args) => {
2005
+ return runWithCommandHandler(
2006
+ cli,
2007
+ command,
2008
+ "init",
2009
+ args,
2010
+ _optionalChain([options, 'access', _94 => _94.commandHandlers, 'optionalAccess', _95 => _95.init]),
2011
+ initCommandDefaultHandler
2012
+ );
2013
+ });
2014
+ metadata.aliases.forEach((alias) => command.alias(alias));
2015
+ }
1843
2016
  };
2017
+ for (const name of selectedCommands) {
2018
+ const register = registrars[name];
2019
+ if (register) {
2020
+ register();
2021
+ }
2022
+ }
2023
+ return cli;
2024
+ }
2025
+ function createTailwindcssPatchCli(options = {}) {
2026
+ const cli = _cac2.default.call(void 0, _nullishCoalesce(options.name, () => ( "tw-patch")));
2027
+ mountTailwindcssPatchCommands(cli, options.mountOptions);
2028
+ return cli;
1844
2029
  }
1845
2030
 
1846
2031
 
@@ -1860,4 +2045,4 @@ function formatGroupedPreview(map, limit = 3) {
1860
2045
 
1861
2046
 
1862
2047
 
1863
- exports.logger_default = logger_default; exports.CacheStore = CacheStore; exports.extractRawCandidatesWithPositions = extractRawCandidatesWithPositions; exports.extractRawCandidates = extractRawCandidates; exports.extractValidCandidates = extractValidCandidates; exports.extractProjectCandidatesWithPositions = extractProjectCandidatesWithPositions; exports.groupTokensByFile = groupTokensByFile; exports.normalizeOptions = normalizeOptions; exports.collectClassesFromContexts = collectClassesFromContexts; exports.collectClassesFromTailwindV4 = collectClassesFromTailwindV4; exports.loadRuntimeContexts = loadRuntimeContexts; exports.runTailwindBuild = runTailwindBuild; exports.TailwindcssPatcher = TailwindcssPatcher; exports.tailwindcssPatchCommands = tailwindcssPatchCommands; exports.createTailwindcssPatchCli = createTailwindcssPatchCli; exports.mountTailwindcssPatchCommands = mountTailwindcssPatchCommands;
2048
+ exports.logger_default = logger_default; exports.CacheStore = CacheStore; exports.extractRawCandidatesWithPositions = extractRawCandidatesWithPositions; exports.extractRawCandidates = extractRawCandidates; exports.extractValidCandidates = extractValidCandidates; exports.extractProjectCandidatesWithPositions = extractProjectCandidatesWithPositions; exports.groupTokensByFile = groupTokensByFile; exports.normalizeOptions = normalizeOptions; exports.collectClassesFromContexts = collectClassesFromContexts; exports.collectClassesFromTailwindV4 = collectClassesFromTailwindV4; exports.loadRuntimeContexts = loadRuntimeContexts; exports.runTailwindBuild = runTailwindBuild; exports.TailwindcssPatcher = TailwindcssPatcher; exports.tailwindcssPatchCommands = tailwindcssPatchCommands; exports.mountTailwindcssPatchCommands = mountTailwindcssPatchCommands; exports.createTailwindcssPatchCli = createTailwindcssPatchCli;