tailwindcss-patch 8.3.0 → 8.4.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 +40 -6
- package/dist/{chunk-SN7IO2IS.mjs → chunk-C3YPPFE6.mjs} +355 -168
- package/dist/{chunk-7ZWFVW77.js → chunk-FKEOVCUS.js} +354 -167
- 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
|
@@ -9,6 +9,9 @@ var logger_default = logger;
|
|
|
9
9
|
|
|
10
10
|
// src/cache/store.ts
|
|
11
11
|
var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
|
|
12
|
+
function isErrnoException(error) {
|
|
13
|
+
return error instanceof Error && typeof error.code === "string";
|
|
14
|
+
}
|
|
12
15
|
var CacheStore = class {
|
|
13
16
|
constructor(options) {
|
|
14
17
|
this.options = options;
|
|
@@ -59,6 +62,9 @@ var CacheStore = class {
|
|
|
59
62
|
return new Set(data.filter((item) => typeof item === "string"));
|
|
60
63
|
}
|
|
61
64
|
} catch (error) {
|
|
65
|
+
if (isErrnoException(error) && error.code === "ENOENT") {
|
|
66
|
+
return /* @__PURE__ */ new Set();
|
|
67
|
+
}
|
|
62
68
|
logger_default.warn("Unable to read Tailwind class cache, removing invalid file.", error);
|
|
63
69
|
try {
|
|
64
70
|
await _fsextra2.default.remove(this.options.path);
|
|
@@ -82,6 +88,9 @@ var CacheStore = class {
|
|
|
82
88
|
return new Set(data.filter((item) => typeof item === "string"));
|
|
83
89
|
}
|
|
84
90
|
} catch (error) {
|
|
91
|
+
if (isErrnoException(error) && error.code === "ENOENT") {
|
|
92
|
+
return /* @__PURE__ */ new Set();
|
|
93
|
+
}
|
|
85
94
|
logger_default.warn("Unable to read Tailwind class cache, removing invalid file.", error);
|
|
86
95
|
try {
|
|
87
96
|
_fsextra2.default.removeSync(this.options.path);
|
|
@@ -391,7 +400,7 @@ function normalizeTailwindV4Options(v4, fallbackBase) {
|
|
|
391
400
|
const hasUserDefinedSources = Boolean(_optionalChain([userSources, 'optionalAccess', _17 => _17.length]));
|
|
392
401
|
const sources = hasUserDefinedSources ? userSources : [
|
|
393
402
|
{
|
|
394
|
-
base,
|
|
403
|
+
base: fallbackBase,
|
|
395
404
|
pattern: "**/*",
|
|
396
405
|
negated: false
|
|
397
406
|
}
|
|
@@ -520,13 +529,6 @@ async function collectClassesFromTailwindV4(options) {
|
|
|
520
529
|
if (!_optionalChain([v4Options, 'access', _28 => _28.sources, 'optionalAccess', _29 => _29.length])) {
|
|
521
530
|
return void 0;
|
|
522
531
|
}
|
|
523
|
-
if (!v4Options.hasUserDefinedSources && !resolvedConfiguredBase) {
|
|
524
|
-
return v4Options.sources.map((source) => ({
|
|
525
|
-
base,
|
|
526
|
-
pattern: source.pattern,
|
|
527
|
-
negated: source.negated
|
|
528
|
-
}));
|
|
529
|
-
}
|
|
530
532
|
return v4Options.sources.map((source) => ({
|
|
531
533
|
base: _nullishCoalesce(source.base, () => ( base)),
|
|
532
534
|
pattern: source.pattern,
|
|
@@ -1660,156 +1662,143 @@ var acceptChars = [..."abcdefghijklmnopqrstuvwxyz"];
|
|
|
1660
1662
|
var _cac = require('cac'); var _cac2 = _interopRequireDefault(_cac);
|
|
1661
1663
|
|
|
1662
1664
|
|
|
1663
|
-
var tailwindcssPatchCommands = [
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
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;
|
|
1665
|
+
var tailwindcssPatchCommands = ["install", "extract", "tokens", "init"];
|
|
1666
|
+
var TOKEN_FORMATS = ["json", "lines", "grouped-json"];
|
|
1667
|
+
var DEFAULT_TOKEN_REPORT = ".tw-patch/tw-token-report.json";
|
|
1668
|
+
function formatTokenLine(entry) {
|
|
1669
|
+
return `${entry.relativeFile}:${entry.line}:${entry.column} ${entry.rawCandidate} (${entry.start}-${entry.end})`;
|
|
1673
1670
|
}
|
|
1674
|
-
function
|
|
1675
|
-
const
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
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
|
-
}
|
|
1671
|
+
function formatGroupedPreview(map, limit = 3) {
|
|
1672
|
+
const files = Object.keys(map);
|
|
1673
|
+
if (!files.length) {
|
|
1674
|
+
return { preview: "", moreFiles: 0 };
|
|
1675
|
+
}
|
|
1676
|
+
const lines = files.slice(0, limit).map((file) => {
|
|
1677
|
+
const tokens = map[file];
|
|
1678
|
+
const sample = tokens.slice(0, 3).map((token) => token.rawCandidate).join(", ");
|
|
1679
|
+
const suffix = tokens.length > 3 ? ", \u2026" : "";
|
|
1680
|
+
return `${file}: ${tokens.length} tokens (${sample}${suffix})`;
|
|
1681
|
+
});
|
|
1682
|
+
return {
|
|
1683
|
+
preview: lines.join("\n"),
|
|
1684
|
+
moreFiles: Math.max(0, files.length - limit)
|
|
1797
1685
|
};
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
}
|
|
1686
|
+
}
|
|
1687
|
+
function resolveCwd(rawCwd) {
|
|
1688
|
+
if (!rawCwd) {
|
|
1689
|
+
return _process2.default.cwd();
|
|
1803
1690
|
}
|
|
1804
|
-
return
|
|
1691
|
+
return _pathe2.default.resolve(rawCwd);
|
|
1692
|
+
}
|
|
1693
|
+
function createDefaultRunner(factory) {
|
|
1694
|
+
let promise;
|
|
1695
|
+
return () => {
|
|
1696
|
+
if (!promise) {
|
|
1697
|
+
promise = factory();
|
|
1698
|
+
}
|
|
1699
|
+
return promise;
|
|
1700
|
+
};
|
|
1805
1701
|
}
|
|
1806
|
-
async function
|
|
1702
|
+
async function loadPatchOptionsForCwd(cwd, overrides) {
|
|
1807
1703
|
const { config } = await _config.getConfig.call(void 0, cwd);
|
|
1808
1704
|
const legacyConfig = config;
|
|
1809
1705
|
const base = _optionalChain([config, 'optionalAccess', _79 => _79.registry]) ? fromUnifiedConfig(config.registry) : _optionalChain([legacyConfig, 'optionalAccess', _80 => _80.patch]) ? fromLegacyOptions({ patch: legacyConfig.patch }) : {};
|
|
1810
1706
|
const merged = defu(_nullishCoalesce(overrides, () => ( {})), base);
|
|
1811
1707
|
return merged;
|
|
1812
1708
|
}
|
|
1709
|
+
function createCommandContext(cli, command, commandName, args, cwd) {
|
|
1710
|
+
let cachedOptions;
|
|
1711
|
+
let cachedPatcher;
|
|
1712
|
+
let cachedConfig;
|
|
1713
|
+
const loadPatchOptionsForContext = (overrides) => {
|
|
1714
|
+
if (overrides) {
|
|
1715
|
+
return loadPatchOptionsForCwd(cwd, overrides);
|
|
1716
|
+
}
|
|
1717
|
+
if (!cachedOptions) {
|
|
1718
|
+
cachedOptions = loadPatchOptionsForCwd(cwd);
|
|
1719
|
+
}
|
|
1720
|
+
return cachedOptions;
|
|
1721
|
+
};
|
|
1722
|
+
const createPatcherForContext = async (overrides) => {
|
|
1723
|
+
if (overrides) {
|
|
1724
|
+
const patchOptions = await loadPatchOptionsForCwd(cwd, overrides);
|
|
1725
|
+
return new TailwindcssPatcher(patchOptions);
|
|
1726
|
+
}
|
|
1727
|
+
if (!cachedPatcher) {
|
|
1728
|
+
cachedPatcher = loadPatchOptionsForContext().then((options) => new TailwindcssPatcher(options));
|
|
1729
|
+
}
|
|
1730
|
+
return cachedPatcher;
|
|
1731
|
+
};
|
|
1732
|
+
return {
|
|
1733
|
+
cli,
|
|
1734
|
+
command,
|
|
1735
|
+
commandName,
|
|
1736
|
+
args,
|
|
1737
|
+
cwd,
|
|
1738
|
+
logger: logger_default,
|
|
1739
|
+
loadConfig: () => {
|
|
1740
|
+
if (!cachedConfig) {
|
|
1741
|
+
cachedConfig = _config.getConfig.call(void 0, cwd);
|
|
1742
|
+
}
|
|
1743
|
+
return cachedConfig;
|
|
1744
|
+
},
|
|
1745
|
+
loadPatchOptions: loadPatchOptionsForContext,
|
|
1746
|
+
createPatcher: createPatcherForContext
|
|
1747
|
+
};
|
|
1748
|
+
}
|
|
1749
|
+
function createCwdOptionDefinition(description = "Working directory") {
|
|
1750
|
+
return {
|
|
1751
|
+
flags: "--cwd <dir>",
|
|
1752
|
+
description,
|
|
1753
|
+
config: { default: _process2.default.cwd() }
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
function buildDefaultCommandDefinitions() {
|
|
1757
|
+
return {
|
|
1758
|
+
install: {
|
|
1759
|
+
description: "Apply Tailwind CSS runtime patches",
|
|
1760
|
+
optionDefs: [createCwdOptionDefinition()]
|
|
1761
|
+
},
|
|
1762
|
+
extract: {
|
|
1763
|
+
description: "Collect generated class names into a cache file",
|
|
1764
|
+
optionDefs: [
|
|
1765
|
+
createCwdOptionDefinition(),
|
|
1766
|
+
{ flags: "--output <file>", description: "Override output file path" },
|
|
1767
|
+
{ flags: "--format <format>", description: "Output format (json|lines)" },
|
|
1768
|
+
{ flags: "--css <file>", description: "Tailwind CSS entry CSS when using v4" },
|
|
1769
|
+
{ flags: "--no-write", description: "Skip writing to disk" }
|
|
1770
|
+
]
|
|
1771
|
+
},
|
|
1772
|
+
tokens: {
|
|
1773
|
+
description: "Extract Tailwind tokens with file/position metadata",
|
|
1774
|
+
optionDefs: [
|
|
1775
|
+
createCwdOptionDefinition(),
|
|
1776
|
+
{ flags: "--output <file>", description: "Override output file path", config: { default: DEFAULT_TOKEN_REPORT } },
|
|
1777
|
+
{
|
|
1778
|
+
flags: "--format <format>",
|
|
1779
|
+
description: "Output format (json|lines|grouped-json)",
|
|
1780
|
+
config: { default: "json" }
|
|
1781
|
+
},
|
|
1782
|
+
{
|
|
1783
|
+
flags: "--group-key <key>",
|
|
1784
|
+
description: "Grouping key for grouped-json output (relative|absolute)",
|
|
1785
|
+
config: { default: "relative" }
|
|
1786
|
+
},
|
|
1787
|
+
{ flags: "--no-write", description: "Skip writing to disk" }
|
|
1788
|
+
]
|
|
1789
|
+
},
|
|
1790
|
+
init: {
|
|
1791
|
+
description: "Generate a tailwindcss-patch config file",
|
|
1792
|
+
optionDefs: [createCwdOptionDefinition()]
|
|
1793
|
+
}
|
|
1794
|
+
};
|
|
1795
|
+
}
|
|
1796
|
+
function addPrefixIfMissing(value, prefix) {
|
|
1797
|
+
if (!prefix || value.startsWith(prefix)) {
|
|
1798
|
+
return value;
|
|
1799
|
+
}
|
|
1800
|
+
return `${prefix}${value}`;
|
|
1801
|
+
}
|
|
1813
1802
|
function resolveCommandNames(command, mountOptions, prefix) {
|
|
1814
1803
|
const override = _optionalChain([mountOptions, 'access', _81 => _81.commandOptions, 'optionalAccess', _82 => _82[command]]);
|
|
1815
1804
|
const baseName = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _83 => _83.name]), () => ( command));
|
|
@@ -1817,30 +1806,228 @@ function resolveCommandNames(command, mountOptions, prefix) {
|
|
|
1817
1806
|
const aliases = (_nullishCoalesce(_optionalChain([override, 'optionalAccess', _84 => _84.aliases]), () => ( []))).map((alias) => addPrefixIfMissing(alias, prefix));
|
|
1818
1807
|
return { name, aliases };
|
|
1819
1808
|
}
|
|
1820
|
-
function
|
|
1821
|
-
if (!
|
|
1822
|
-
return
|
|
1809
|
+
function resolveOptionDefinitions(defaults, override) {
|
|
1810
|
+
if (!override) {
|
|
1811
|
+
return defaults;
|
|
1823
1812
|
}
|
|
1824
|
-
|
|
1813
|
+
const appendDefaults = _nullishCoalesce(override.appendDefaultOptions, () => ( true));
|
|
1814
|
+
const customDefs = _nullishCoalesce(override.optionDefs, () => ( []));
|
|
1815
|
+
if (!appendDefaults) {
|
|
1816
|
+
return customDefs;
|
|
1817
|
+
}
|
|
1818
|
+
if (customDefs.length === 0) {
|
|
1819
|
+
return defaults;
|
|
1820
|
+
}
|
|
1821
|
+
return [...defaults, ...customDefs];
|
|
1825
1822
|
}
|
|
1826
|
-
function
|
|
1827
|
-
|
|
1823
|
+
function applyCommandOptions(command, optionDefs) {
|
|
1824
|
+
for (const option of optionDefs) {
|
|
1825
|
+
command.option(option.flags, _nullishCoalesce(option.description, () => ( "")), option.config);
|
|
1826
|
+
}
|
|
1828
1827
|
}
|
|
1829
|
-
function
|
|
1830
|
-
const
|
|
1831
|
-
|
|
1832
|
-
|
|
1828
|
+
function runWithCommandHandler(cli, command, commandName, args, handler, defaultHandler) {
|
|
1829
|
+
const cwd = resolveCwd(args.cwd);
|
|
1830
|
+
const context = createCommandContext(cli, command, commandName, args, cwd);
|
|
1831
|
+
const runDefault = createDefaultRunner(() => defaultHandler(context));
|
|
1832
|
+
if (!handler) {
|
|
1833
|
+
return runDefault();
|
|
1834
|
+
}
|
|
1835
|
+
return handler(context, runDefault);
|
|
1836
|
+
}
|
|
1837
|
+
function resolveCommandMetadata(command, mountOptions, prefix, defaults) {
|
|
1838
|
+
const names = resolveCommandNames(command, mountOptions, prefix);
|
|
1839
|
+
const definition = defaults[command];
|
|
1840
|
+
const override = _optionalChain([mountOptions, 'access', _85 => _85.commandOptions, 'optionalAccess', _86 => _86[command]]);
|
|
1841
|
+
const description = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _87 => _87.description]), () => ( definition.description));
|
|
1842
|
+
const optionDefs = resolveOptionDefinitions(definition.optionDefs, override);
|
|
1843
|
+
return { ...names, description, optionDefs };
|
|
1844
|
+
}
|
|
1845
|
+
async function installCommandDefaultHandler(ctx) {
|
|
1846
|
+
const patcher = await ctx.createPatcher();
|
|
1847
|
+
await patcher.patch();
|
|
1848
|
+
logger_default.success("Tailwind CSS runtime patched successfully.");
|
|
1849
|
+
}
|
|
1850
|
+
async function extractCommandDefaultHandler(ctx) {
|
|
1851
|
+
const { args } = ctx;
|
|
1852
|
+
const overrides = {};
|
|
1853
|
+
let hasOverrides = false;
|
|
1854
|
+
if (args.output || args.format) {
|
|
1855
|
+
overrides.output = {
|
|
1856
|
+
file: args.output,
|
|
1857
|
+
format: args.format
|
|
1858
|
+
};
|
|
1859
|
+
hasOverrides = true;
|
|
1833
1860
|
}
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1861
|
+
if (args.css) {
|
|
1862
|
+
overrides.tailwind = {
|
|
1863
|
+
v4: {
|
|
1864
|
+
cssEntries: [args.css]
|
|
1865
|
+
}
|
|
1866
|
+
};
|
|
1867
|
+
hasOverrides = true;
|
|
1868
|
+
}
|
|
1869
|
+
const patcher = await ctx.createPatcher(hasOverrides ? overrides : void 0);
|
|
1870
|
+
const result = await patcher.extract({ write: args.write });
|
|
1871
|
+
if (result.filename) {
|
|
1872
|
+
logger_default.success(`Collected ${result.classList.length} classes \u2192 ${result.filename}`);
|
|
1873
|
+
} else {
|
|
1874
|
+
logger_default.success(`Collected ${result.classList.length} classes.`);
|
|
1875
|
+
}
|
|
1876
|
+
return result;
|
|
1877
|
+
}
|
|
1878
|
+
async function tokensCommandDefaultHandler(ctx) {
|
|
1879
|
+
const { args } = ctx;
|
|
1880
|
+
const patcher = await ctx.createPatcher();
|
|
1881
|
+
const report = await patcher.collectContentTokens();
|
|
1882
|
+
const shouldWrite = _nullishCoalesce(args.write, () => ( true));
|
|
1883
|
+
let format = _nullishCoalesce(args.format, () => ( "json"));
|
|
1884
|
+
if (!TOKEN_FORMATS.includes(format)) {
|
|
1885
|
+
format = "json";
|
|
1886
|
+
}
|
|
1887
|
+
const targetFile = _nullishCoalesce(args.output, () => ( DEFAULT_TOKEN_REPORT));
|
|
1888
|
+
const groupKey = args.groupKey === "absolute" ? "absolute" : "relative";
|
|
1889
|
+
const buildGrouped = () => groupTokensByFile(report, {
|
|
1890
|
+
key: groupKey,
|
|
1891
|
+
stripAbsolutePaths: groupKey !== "absolute"
|
|
1839
1892
|
});
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1893
|
+
const grouped = format === "grouped-json" ? buildGrouped() : null;
|
|
1894
|
+
const resolveGrouped = () => _nullishCoalesce(grouped, () => ( buildGrouped()));
|
|
1895
|
+
if (shouldWrite) {
|
|
1896
|
+
const target = _pathe2.default.resolve(targetFile);
|
|
1897
|
+
await _fsextra2.default.ensureDir(_pathe2.default.dirname(target));
|
|
1898
|
+
if (format === "json") {
|
|
1899
|
+
await _fsextra2.default.writeJSON(target, report, { spaces: 2 });
|
|
1900
|
+
} else if (format === "grouped-json") {
|
|
1901
|
+
await _fsextra2.default.writeJSON(target, resolveGrouped(), { spaces: 2 });
|
|
1902
|
+
} else {
|
|
1903
|
+
const lines = report.entries.map(formatTokenLine);
|
|
1904
|
+
await _fsextra2.default.writeFile(target, `${lines.join("\n")}
|
|
1905
|
+
`, "utf8");
|
|
1906
|
+
}
|
|
1907
|
+
logger_default.success(`Collected ${report.entries.length} tokens (${format}) \u2192 ${target.replace(_process2.default.cwd(), ".")}`);
|
|
1908
|
+
} else {
|
|
1909
|
+
logger_default.success(`Collected ${report.entries.length} tokens from ${report.filesScanned} files.`);
|
|
1910
|
+
if (format === "lines") {
|
|
1911
|
+
const preview = report.entries.slice(0, 5).map(formatTokenLine).join("\n");
|
|
1912
|
+
if (preview) {
|
|
1913
|
+
logger_default.log("");
|
|
1914
|
+
logger_default.info(preview);
|
|
1915
|
+
if (report.entries.length > 5) {
|
|
1916
|
+
logger_default.info(`\u2026and ${report.entries.length - 5} more.`);
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
} else if (format === "grouped-json") {
|
|
1920
|
+
const map = resolveGrouped();
|
|
1921
|
+
const { preview, moreFiles } = formatGroupedPreview(map);
|
|
1922
|
+
if (preview) {
|
|
1923
|
+
logger_default.log("");
|
|
1924
|
+
logger_default.info(preview);
|
|
1925
|
+
if (moreFiles > 0) {
|
|
1926
|
+
logger_default.info(`\u2026and ${moreFiles} more files.`);
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
} else {
|
|
1930
|
+
const previewEntries = report.entries.slice(0, 3);
|
|
1931
|
+
if (previewEntries.length) {
|
|
1932
|
+
logger_default.log("");
|
|
1933
|
+
logger_default.info(JSON.stringify(previewEntries, null, 2));
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
if (report.skippedFiles.length) {
|
|
1938
|
+
logger_default.warn("Skipped files:");
|
|
1939
|
+
for (const skipped of report.skippedFiles) {
|
|
1940
|
+
logger_default.warn(` \u2022 ${skipped.file} (${skipped.reason})`);
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
return report;
|
|
1944
|
+
}
|
|
1945
|
+
async function initCommandDefaultHandler(ctx) {
|
|
1946
|
+
await _config.initConfig.call(void 0, ctx.cwd);
|
|
1947
|
+
logger_default.success(`\u2728 ${_config.CONFIG_NAME}.config.ts initialized!`);
|
|
1948
|
+
}
|
|
1949
|
+
function mountTailwindcssPatchCommands(cli, options = {}) {
|
|
1950
|
+
const prefix = _nullishCoalesce(options.commandPrefix, () => ( ""));
|
|
1951
|
+
const selectedCommands = _nullishCoalesce(options.commands, () => ( tailwindcssPatchCommands));
|
|
1952
|
+
const defaultDefinitions = buildDefaultCommandDefinitions();
|
|
1953
|
+
const registrars = {
|
|
1954
|
+
install: () => {
|
|
1955
|
+
const metadata = resolveCommandMetadata("install", options, prefix, defaultDefinitions);
|
|
1956
|
+
const command = cli.command(metadata.name, metadata.description);
|
|
1957
|
+
applyCommandOptions(command, metadata.optionDefs);
|
|
1958
|
+
command.action(async (args) => {
|
|
1959
|
+
return runWithCommandHandler(
|
|
1960
|
+
cli,
|
|
1961
|
+
command,
|
|
1962
|
+
"install",
|
|
1963
|
+
args,
|
|
1964
|
+
_optionalChain([options, 'access', _88 => _88.commandHandlers, 'optionalAccess', _89 => _89.install]),
|
|
1965
|
+
installCommandDefaultHandler
|
|
1966
|
+
);
|
|
1967
|
+
});
|
|
1968
|
+
metadata.aliases.forEach((alias) => command.alias(alias));
|
|
1969
|
+
},
|
|
1970
|
+
extract: () => {
|
|
1971
|
+
const metadata = resolveCommandMetadata("extract", options, prefix, defaultDefinitions);
|
|
1972
|
+
const command = cli.command(metadata.name, metadata.description);
|
|
1973
|
+
applyCommandOptions(command, metadata.optionDefs);
|
|
1974
|
+
command.action(async (args) => {
|
|
1975
|
+
return runWithCommandHandler(
|
|
1976
|
+
cli,
|
|
1977
|
+
command,
|
|
1978
|
+
"extract",
|
|
1979
|
+
args,
|
|
1980
|
+
_optionalChain([options, 'access', _90 => _90.commandHandlers, 'optionalAccess', _91 => _91.extract]),
|
|
1981
|
+
extractCommandDefaultHandler
|
|
1982
|
+
);
|
|
1983
|
+
});
|
|
1984
|
+
metadata.aliases.forEach((alias) => command.alias(alias));
|
|
1985
|
+
},
|
|
1986
|
+
tokens: () => {
|
|
1987
|
+
const metadata = resolveCommandMetadata("tokens", options, prefix, defaultDefinitions);
|
|
1988
|
+
const command = cli.command(metadata.name, metadata.description);
|
|
1989
|
+
applyCommandOptions(command, metadata.optionDefs);
|
|
1990
|
+
command.action(async (args) => {
|
|
1991
|
+
return runWithCommandHandler(
|
|
1992
|
+
cli,
|
|
1993
|
+
command,
|
|
1994
|
+
"tokens",
|
|
1995
|
+
args,
|
|
1996
|
+
_optionalChain([options, 'access', _92 => _92.commandHandlers, 'optionalAccess', _93 => _93.tokens]),
|
|
1997
|
+
tokensCommandDefaultHandler
|
|
1998
|
+
);
|
|
1999
|
+
});
|
|
2000
|
+
metadata.aliases.forEach((alias) => command.alias(alias));
|
|
2001
|
+
},
|
|
2002
|
+
init: () => {
|
|
2003
|
+
const metadata = resolveCommandMetadata("init", options, prefix, defaultDefinitions);
|
|
2004
|
+
const command = cli.command(metadata.name, metadata.description);
|
|
2005
|
+
applyCommandOptions(command, metadata.optionDefs);
|
|
2006
|
+
command.action(async (args) => {
|
|
2007
|
+
return runWithCommandHandler(
|
|
2008
|
+
cli,
|
|
2009
|
+
command,
|
|
2010
|
+
"init",
|
|
2011
|
+
args,
|
|
2012
|
+
_optionalChain([options, 'access', _94 => _94.commandHandlers, 'optionalAccess', _95 => _95.init]),
|
|
2013
|
+
initCommandDefaultHandler
|
|
2014
|
+
);
|
|
2015
|
+
});
|
|
2016
|
+
metadata.aliases.forEach((alias) => command.alias(alias));
|
|
2017
|
+
}
|
|
1843
2018
|
};
|
|
2019
|
+
for (const name of selectedCommands) {
|
|
2020
|
+
const register = registrars[name];
|
|
2021
|
+
if (register) {
|
|
2022
|
+
register();
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
return cli;
|
|
2026
|
+
}
|
|
2027
|
+
function createTailwindcssPatchCli(options = {}) {
|
|
2028
|
+
const cli = _cac2.default.call(void 0, _nullishCoalesce(options.name, () => ( "tw-patch")));
|
|
2029
|
+
mountTailwindcssPatchCommands(cli, options.mountOptions);
|
|
2030
|
+
return cli;
|
|
1844
2031
|
}
|
|
1845
2032
|
|
|
1846
2033
|
|
|
@@ -1860,4 +2047,4 @@ function formatGroupedPreview(map, limit = 3) {
|
|
|
1860
2047
|
|
|
1861
2048
|
|
|
1862
2049
|
|
|
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.
|
|
2050
|
+
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;
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkFKEOVCUSjs = require('./chunk-FKEOVCUS.js');
|
|
4
4
|
|
|
5
5
|
// src/cli.ts
|
|
6
|
-
var cli =
|
|
6
|
+
var cli = _chunkFKEOVCUSjs.createTailwindcssPatchCli.call(void 0, );
|
|
7
7
|
cli.help();
|
|
8
8
|
cli.parse();
|