tailwindcss-patch 9.4.0 → 9.4.2

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.
@@ -0,0 +1,671 @@
1
+ const require_chunk = require("./chunk-8l464Juk.js");
2
+ const require_validate = require("./validate-5eUbRAzl.js");
3
+ let node_process = require("node:process");
4
+ node_process = require_chunk.__toESM(node_process);
5
+ let fs_extra = require("fs-extra");
6
+ fs_extra = require_chunk.__toESM(fs_extra);
7
+ let pathe = require("pathe");
8
+ pathe = require_chunk.__toESM(pathe);
9
+ let cac = require("cac");
10
+ cac = require_chunk.__toESM(cac);
11
+ //#region src/commands/token-output.ts
12
+ const TOKEN_FORMATS = [
13
+ "json",
14
+ "lines",
15
+ "grouped-json"
16
+ ];
17
+ const DEFAULT_TOKEN_REPORT = ".tw-patch/tw-token-report.json";
18
+ function formatTokenLine(entry) {
19
+ return `${entry.relativeFile}:${entry.line}:${entry.column} ${entry.rawCandidate} (${entry.start}-${entry.end})`;
20
+ }
21
+ function formatGroupedPreview(map, limit = 3) {
22
+ const files = Object.keys(map);
23
+ if (!files.length) return {
24
+ preview: "",
25
+ moreFiles: 0
26
+ };
27
+ return {
28
+ preview: files.slice(0, limit).map((file) => {
29
+ const tokens = map[file] ?? [];
30
+ const sample = tokens.slice(0, 3).map((token) => token.rawCandidate).join(", ");
31
+ const suffix = tokens.length > 3 ? ", …" : "";
32
+ return `${file}: ${tokens.length} tokens (${sample}${suffix})`;
33
+ }).join("\n"),
34
+ moreFiles: Math.max(0, files.length - limit)
35
+ };
36
+ }
37
+ //#endregion
38
+ //#region src/commands/command-definitions.ts
39
+ function createCwdOptionDefinition(description = "Working directory") {
40
+ return {
41
+ flags: "--cwd <dir>",
42
+ description,
43
+ config: { default: node_process.default.cwd() }
44
+ };
45
+ }
46
+ function buildDefaultCommandDefinitions() {
47
+ return {
48
+ install: {
49
+ description: "Apply Tailwind CSS runtime patches",
50
+ optionDefs: [createCwdOptionDefinition()]
51
+ },
52
+ extract: {
53
+ description: "Collect generated class names into a cache file",
54
+ optionDefs: [
55
+ createCwdOptionDefinition(),
56
+ {
57
+ flags: "--output <file>",
58
+ description: "Override output file path"
59
+ },
60
+ {
61
+ flags: "--format <format>",
62
+ description: "Output format (json|lines)"
63
+ },
64
+ {
65
+ flags: "--css <file>",
66
+ description: "Tailwind CSS entry CSS when using v4"
67
+ },
68
+ {
69
+ flags: "--no-write",
70
+ description: "Skip writing to disk"
71
+ }
72
+ ]
73
+ },
74
+ tokens: {
75
+ description: "Extract Tailwind tokens with file/position metadata",
76
+ optionDefs: [
77
+ createCwdOptionDefinition(),
78
+ {
79
+ flags: "--output <file>",
80
+ description: "Override output file path",
81
+ config: { default: DEFAULT_TOKEN_REPORT }
82
+ },
83
+ {
84
+ flags: "--format <format>",
85
+ description: "Output format (json|lines|grouped-json)",
86
+ config: { default: "json" }
87
+ },
88
+ {
89
+ flags: "--group-key <key>",
90
+ description: "Grouping key for grouped-json output (relative|absolute)",
91
+ config: { default: "relative" }
92
+ },
93
+ {
94
+ flags: "--no-write",
95
+ description: "Skip writing to disk"
96
+ }
97
+ ]
98
+ },
99
+ init: {
100
+ description: "Generate a tailwindcss-patch config file",
101
+ optionDefs: [createCwdOptionDefinition()]
102
+ },
103
+ migrate: {
104
+ description: "Migrate deprecated config fields to modern options",
105
+ optionDefs: [
106
+ createCwdOptionDefinition(),
107
+ {
108
+ flags: "--config <file>",
109
+ description: "Migrate a specific config file path"
110
+ },
111
+ {
112
+ flags: "--workspace",
113
+ description: "Scan workspace recursively for config files"
114
+ },
115
+ {
116
+ flags: "--max-depth <n>",
117
+ description: "Maximum recursion depth for --workspace",
118
+ config: { default: 6 }
119
+ },
120
+ {
121
+ flags: "--include <glob>",
122
+ description: "Only migrate files that match this glob (repeatable)"
123
+ },
124
+ {
125
+ flags: "--exclude <glob>",
126
+ description: "Skip files that match this glob (repeatable)"
127
+ },
128
+ {
129
+ flags: "--report-file <file>",
130
+ description: "Write migration report JSON to a file"
131
+ },
132
+ {
133
+ flags: "--backup-dir <dir>",
134
+ description: "Write pre-migration backups into this directory"
135
+ },
136
+ {
137
+ flags: "--check",
138
+ description: "Exit with an error when migration changes are required"
139
+ },
140
+ {
141
+ flags: "--json",
142
+ description: "Print the migration report as JSON"
143
+ },
144
+ {
145
+ flags: "--dry-run",
146
+ description: "Preview changes without writing files"
147
+ }
148
+ ]
149
+ },
150
+ restore: {
151
+ description: "Restore config files from a previous migration report backup snapshot",
152
+ optionDefs: [
153
+ createCwdOptionDefinition(),
154
+ {
155
+ flags: "--report-file <file>",
156
+ description: "Migration report file generated by migrate"
157
+ },
158
+ {
159
+ flags: "--dry-run",
160
+ description: "Preview restore targets without writing files"
161
+ },
162
+ {
163
+ flags: "--strict",
164
+ description: "Fail when any backup file is missing"
165
+ },
166
+ {
167
+ flags: "--json",
168
+ description: "Print the restore result as JSON"
169
+ }
170
+ ]
171
+ },
172
+ validate: {
173
+ description: "Validate migration report compatibility without modifying files",
174
+ optionDefs: [
175
+ createCwdOptionDefinition(),
176
+ {
177
+ flags: "--report-file <file>",
178
+ description: "Migration report file to validate"
179
+ },
180
+ {
181
+ flags: "--strict",
182
+ description: "Fail when any backup file is missing"
183
+ },
184
+ {
185
+ flags: "--json",
186
+ description: "Print validation result as JSON"
187
+ }
188
+ ]
189
+ },
190
+ status: {
191
+ description: "Check which Tailwind patches are applied",
192
+ optionDefs: [createCwdOptionDefinition(), {
193
+ flags: "--json",
194
+ description: "Print a JSON report of patch status"
195
+ }]
196
+ }
197
+ };
198
+ }
199
+ //#endregion
200
+ //#region src/commands/command-metadata.ts
201
+ function addPrefixIfMissing(value, prefix) {
202
+ if (!prefix || value.startsWith(prefix)) return value;
203
+ return `${prefix}${value}`;
204
+ }
205
+ function resolveCommandNames(command, mountOptions, prefix) {
206
+ const override = mountOptions.commandOptions?.[command];
207
+ return {
208
+ name: addPrefixIfMissing(override?.name ?? command, prefix),
209
+ aliases: (override?.aliases ?? []).map((alias) => addPrefixIfMissing(alias, prefix))
210
+ };
211
+ }
212
+ function resolveOptionDefinitions(defaults, override) {
213
+ if (!override) return defaults;
214
+ const appendDefaults = override.appendDefaultOptions ?? true;
215
+ const customDefs = override.optionDefs ?? [];
216
+ if (!appendDefaults) return customDefs;
217
+ if (customDefs.length === 0) return defaults;
218
+ return [...defaults, ...customDefs];
219
+ }
220
+ function resolveCommandMetadata(command, mountOptions, prefix, defaults) {
221
+ const names = resolveCommandNames(command, mountOptions, prefix);
222
+ const definition = defaults[command];
223
+ const override = mountOptions.commandOptions?.[command];
224
+ const description = override?.description ?? definition.description;
225
+ const optionDefs = resolveOptionDefinitions(definition.optionDefs, override);
226
+ return {
227
+ ...names,
228
+ description,
229
+ optionDefs
230
+ };
231
+ }
232
+ function applyCommandOptions(command, optionDefs) {
233
+ for (const option of optionDefs) command.option(option.flags, option.description ?? "", option.config);
234
+ }
235
+ //#endregion
236
+ //#region src/commands/command-context.ts
237
+ function resolveCommandCwd(rawCwd) {
238
+ if (!rawCwd) return node_process.default.cwd();
239
+ return pathe.default.resolve(rawCwd);
240
+ }
241
+ function createMemoizedPromiseRunner(factory) {
242
+ let promise;
243
+ return () => {
244
+ if (!promise) promise = factory();
245
+ return promise;
246
+ };
247
+ }
248
+ function createTailwindcssPatchCommandContext(cli, command, commandName, args, cwd) {
249
+ const loadCachedConfig = createMemoizedPromiseRunner(() => require_validate.loadWorkspaceConfigModule().then((mod) => mod.getConfig(cwd)));
250
+ const loadCachedPatchOptions = createMemoizedPromiseRunner(() => require_validate.loadPatchOptionsForWorkspace(cwd));
251
+ const createCachedPatcher = createMemoizedPromiseRunner(async () => {
252
+ return new require_validate.TailwindcssPatcher(await loadCachedPatchOptions());
253
+ });
254
+ const loadPatchOptionsForContext = (overrides) => {
255
+ if (overrides) return require_validate.loadPatchOptionsForWorkspace(cwd, overrides);
256
+ return loadCachedPatchOptions();
257
+ };
258
+ const createPatcherForContext = async (overrides) => {
259
+ if (overrides) return new require_validate.TailwindcssPatcher(await require_validate.loadPatchOptionsForWorkspace(cwd, overrides));
260
+ return createCachedPatcher();
261
+ };
262
+ return {
263
+ cli,
264
+ command,
265
+ commandName,
266
+ args,
267
+ cwd,
268
+ logger: require_validate.logger,
269
+ loadConfig: loadCachedConfig,
270
+ loadPatchOptions: loadPatchOptionsForContext,
271
+ createPatcher: createPatcherForContext
272
+ };
273
+ }
274
+ //#endregion
275
+ //#region src/commands/command-runtime.ts
276
+ function runWithCommandHandler(cli, command, commandName, args, handler, defaultHandler) {
277
+ const context = createTailwindcssPatchCommandContext(cli, command, commandName, args, resolveCommandCwd(args.cwd));
278
+ const runDefault = createMemoizedPromiseRunner(() => defaultHandler(context));
279
+ if (!handler) return runDefault();
280
+ return handler(context, runDefault);
281
+ }
282
+ //#endregion
283
+ //#region src/commands/basic-handlers.ts
284
+ const DEFAULT_CONFIG_NAME = "tailwindcss-mangle";
285
+ async function installCommandDefaultHandler(_ctx) {
286
+ await (await _ctx.createPatcher()).patch();
287
+ require_validate.logger.success("Tailwind CSS runtime patched successfully.");
288
+ }
289
+ async function extractCommandDefaultHandler(ctx) {
290
+ const { args } = ctx;
291
+ const overrides = {};
292
+ let hasOverrides = false;
293
+ if (args.output || args.format) {
294
+ overrides.extract = {
295
+ ...args.output === void 0 ? {} : { file: args.output },
296
+ ...args.format === void 0 ? {} : { format: args.format }
297
+ };
298
+ hasOverrides = true;
299
+ }
300
+ if (args.css) {
301
+ overrides.tailwindcss = { v4: { cssEntries: [args.css] } };
302
+ hasOverrides = true;
303
+ }
304
+ const patcher = await ctx.createPatcher(hasOverrides ? overrides : void 0);
305
+ const extractOptions = args.write === void 0 ? {} : { write: args.write };
306
+ const result = await patcher.extract(extractOptions);
307
+ if (result.filename) require_validate.logger.success(`Collected ${result.classList.length} classes → ${result.filename}`);
308
+ else require_validate.logger.success(`Collected ${result.classList.length} classes.`);
309
+ return result;
310
+ }
311
+ async function tokensCommandDefaultHandler(ctx) {
312
+ const { args } = ctx;
313
+ const report = await (await ctx.createPatcher()).collectContentTokens();
314
+ const shouldWrite = args.write ?? true;
315
+ let format = args.format ?? "json";
316
+ if (!TOKEN_FORMATS.includes(format)) format = "json";
317
+ const targetFile = args.output ?? ".tw-patch/tw-token-report.json";
318
+ const groupKey = args.groupKey === "absolute" ? "absolute" : "relative";
319
+ const buildGrouped = () => require_validate.groupTokensByFile(report, {
320
+ key: groupKey,
321
+ stripAbsolutePaths: groupKey !== "absolute"
322
+ });
323
+ const grouped = format === "grouped-json" ? buildGrouped() : null;
324
+ const resolveGrouped = () => grouped ?? buildGrouped();
325
+ if (shouldWrite) {
326
+ const target = pathe.default.resolve(targetFile);
327
+ await fs_extra.default.ensureDir(pathe.default.dirname(target));
328
+ if (format === "json") await fs_extra.default.writeJSON(target, report, { spaces: 2 });
329
+ else if (format === "grouped-json") await fs_extra.default.writeJSON(target, resolveGrouped(), { spaces: 2 });
330
+ else {
331
+ const lines = report.entries.map(formatTokenLine);
332
+ await fs_extra.default.writeFile(target, `${lines.join("\n")}\n`, "utf8");
333
+ }
334
+ require_validate.logger.success(`Collected ${report.entries.length} tokens (${format}) → ${target.replace(node_process.default.cwd(), ".")}`);
335
+ } else {
336
+ require_validate.logger.success(`Collected ${report.entries.length} tokens from ${report.filesScanned} files.`);
337
+ if (format === "lines") {
338
+ const preview = report.entries.slice(0, 5).map(formatTokenLine).join("\n");
339
+ if (preview) {
340
+ require_validate.logger.log("");
341
+ require_validate.logger.info(preview);
342
+ if (report.entries.length > 5) require_validate.logger.info(`…and ${report.entries.length - 5} more.`);
343
+ }
344
+ } else if (format === "grouped-json") {
345
+ const { preview, moreFiles } = formatGroupedPreview(resolveGrouped());
346
+ if (preview) {
347
+ require_validate.logger.log("");
348
+ require_validate.logger.info(preview);
349
+ if (moreFiles > 0) require_validate.logger.info(`…and ${moreFiles} more files.`);
350
+ }
351
+ } else {
352
+ const previewEntries = report.entries.slice(0, 3);
353
+ if (previewEntries.length) {
354
+ require_validate.logger.log("");
355
+ require_validate.logger.info(JSON.stringify(previewEntries, null, 2));
356
+ }
357
+ }
358
+ }
359
+ if (report.skippedFiles.length) {
360
+ require_validate.logger.warn("Skipped files:");
361
+ for (const skipped of report.skippedFiles) require_validate.logger.warn(` • ${skipped.file} (${skipped.reason})`);
362
+ }
363
+ return report;
364
+ }
365
+ async function initCommandDefaultHandler(ctx) {
366
+ const configModule = await require_validate.loadWorkspaceConfigModule();
367
+ await configModule.initConfig(ctx.cwd);
368
+ const configName = configModule.CONFIG_NAME || DEFAULT_CONFIG_NAME;
369
+ require_validate.logger.success(`✨ ${configName}.config.ts initialized!`);
370
+ }
371
+ //#endregion
372
+ //#region src/commands/migration-args.ts
373
+ function normalizePatternArgs(value) {
374
+ if (!value) return;
375
+ const values = (Array.isArray(value) ? value : [value]).flatMap((item) => item.split(",")).map((item) => item.trim()).filter(Boolean);
376
+ return values.length > 0 ? values : void 0;
377
+ }
378
+ function parseMaxDepth(value) {
379
+ if (value === void 0) return {
380
+ maxDepth: void 0,
381
+ hasInvalidMaxDepth: false
382
+ };
383
+ const parsed = Number(value);
384
+ if (!Number.isFinite(parsed) || parsed < 0) return {
385
+ maxDepth: void 0,
386
+ hasInvalidMaxDepth: true
387
+ };
388
+ return {
389
+ maxDepth: Math.floor(parsed),
390
+ hasInvalidMaxDepth: false
391
+ };
392
+ }
393
+ function resolveMigrateCommandArgs(args) {
394
+ const include = normalizePatternArgs(args.include);
395
+ const exclude = normalizePatternArgs(args.exclude);
396
+ const { maxDepth, hasInvalidMaxDepth } = parseMaxDepth(args.maxDepth);
397
+ const checkMode = args.check ?? false;
398
+ return {
399
+ include,
400
+ exclude,
401
+ maxDepth,
402
+ checkMode,
403
+ dryRun: args.dryRun ?? checkMode,
404
+ hasInvalidMaxDepth
405
+ };
406
+ }
407
+ function resolveRestoreCommandArgs(args) {
408
+ return {
409
+ reportFile: args.reportFile ?? ".tw-patch/migrate-report.json",
410
+ dryRun: args.dryRun ?? false,
411
+ strict: args.strict ?? false
412
+ };
413
+ }
414
+ function resolveValidateCommandArgs(args) {
415
+ return {
416
+ reportFile: args.reportFile ?? ".tw-patch/migrate-report.json",
417
+ strict: args.strict ?? false
418
+ };
419
+ }
420
+ //#endregion
421
+ //#region src/commands/migration-output.ts
422
+ function formatPathForLog(file) {
423
+ return file.replace(node_process.default.cwd(), ".");
424
+ }
425
+ function createMigrationCheckFailureError(changedFiles) {
426
+ return /* @__PURE__ */ new Error(`Migration check failed: ${changedFiles} file(s) still need migration.`);
427
+ }
428
+ async function writeMigrationReportFile(cwd, reportFile, report) {
429
+ const reportPath = pathe.default.resolve(cwd, reportFile);
430
+ await fs_extra.default.ensureDir(pathe.default.dirname(reportPath));
431
+ await fs_extra.default.writeJSON(reportPath, report, { spaces: 2 });
432
+ require_validate.logger.info(`Migration report written: ${formatPathForLog(reportPath)}`);
433
+ }
434
+ function logMigrationReportAsJson(report) {
435
+ require_validate.logger.log(JSON.stringify(report, null, 2));
436
+ }
437
+ function logNoMigrationConfigFilesWarning() {
438
+ require_validate.logger.warn("No config files found for migration.");
439
+ }
440
+ function logMigrationEntries(report, dryRun) {
441
+ for (const entry of report.entries) {
442
+ const fileLabel = formatPathForLog(entry.file);
443
+ if (!entry.changed) {
444
+ require_validate.logger.info(`No changes: ${fileLabel}`);
445
+ continue;
446
+ }
447
+ if (dryRun) require_validate.logger.info(`[dry-run] ${fileLabel}`);
448
+ else require_validate.logger.success(`Migrated: ${fileLabel}`);
449
+ for (const change of entry.changes) require_validate.logger.info(` - ${change}`);
450
+ if (entry.backupFile) require_validate.logger.info(` - backup: ${formatPathForLog(entry.backupFile)}`);
451
+ }
452
+ }
453
+ function logMigrationSummary(report) {
454
+ require_validate.logger.info(`Migration summary: scanned=${report.scannedFiles}, changed=${report.changedFiles}, written=${report.writtenFiles}, backups=${report.backupsWritten}, missing=${report.missingFiles}, unchanged=${report.unchangedFiles}`);
455
+ }
456
+ function logRestoreResultAsJson(result) {
457
+ require_validate.logger.log(JSON.stringify(result, null, 2));
458
+ }
459
+ function logRestoreSummary(result) {
460
+ require_validate.logger.info(`Restore summary: scanned=${result.scannedEntries}, restorable=${result.restorableEntries}, restored=${result.restoredFiles}, missingBackups=${result.missingBackups}, skipped=${result.skippedEntries}`);
461
+ if (result.restored.length > 0) {
462
+ const preview = result.restored.slice(0, 5);
463
+ for (const file of preview) require_validate.logger.info(` - ${formatPathForLog(file)}`);
464
+ if (result.restored.length > preview.length) require_validate.logger.info(` ...and ${result.restored.length - preview.length} more`);
465
+ }
466
+ }
467
+ function logValidateSuccessAsJson(result) {
468
+ const payload = {
469
+ ok: true,
470
+ ...result
471
+ };
472
+ require_validate.logger.log(JSON.stringify(payload, null, 2));
473
+ }
474
+ function logValidateSuccessSummary(result) {
475
+ require_validate.logger.success(`Migration report validated: scanned=${result.scannedEntries}, restorable=${result.restorableEntries}, missingBackups=${result.missingBackups}, skipped=${result.skippedEntries}`);
476
+ if (result.reportKind || result.reportSchemaVersion !== void 0) {
477
+ const kind = result.reportKind ?? "unknown";
478
+ const schema = result.reportSchemaVersion === void 0 ? "unknown" : String(result.reportSchemaVersion);
479
+ require_validate.logger.info(` metadata: kind=${kind}, schema=${schema}`);
480
+ }
481
+ }
482
+ function logValidateFailureAsJson(summary) {
483
+ const payload = {
484
+ ok: false,
485
+ reason: summary.reason,
486
+ exitCode: summary.exitCode,
487
+ message: summary.message
488
+ };
489
+ require_validate.logger.log(JSON.stringify(payload, null, 2));
490
+ }
491
+ function logValidateFailureSummary(summary) {
492
+ require_validate.logger.error(`Validation failed [${summary.reason}] (exit ${summary.exitCode}): ${summary.message}`);
493
+ }
494
+ //#endregion
495
+ //#region src/commands/migrate-handler.ts
496
+ async function migrateCommandDefaultHandler(ctx) {
497
+ const { args } = ctx;
498
+ const { include, exclude, maxDepth, checkMode, dryRun, hasInvalidMaxDepth } = resolveMigrateCommandArgs(args);
499
+ if (args.workspace && hasInvalidMaxDepth) require_validate.logger.warn(`Invalid --max-depth value "${String(args.maxDepth)}", fallback to default depth.`);
500
+ const report = await require_validate.migrateConfigFiles({
501
+ cwd: ctx.cwd,
502
+ dryRun,
503
+ ...args.config ? { files: [args.config] } : {},
504
+ ...args.workspace ? { workspace: true } : {},
505
+ ...args.workspace && maxDepth !== void 0 ? { maxDepth } : {},
506
+ ...args.backupDir ? { backupDir: args.backupDir } : {},
507
+ ...include ? { include } : {},
508
+ ...exclude ? { exclude } : {}
509
+ });
510
+ if (args.reportFile) await writeMigrationReportFile(ctx.cwd, args.reportFile, report);
511
+ if (args.json) {
512
+ logMigrationReportAsJson(report);
513
+ if (checkMode && report.changedFiles > 0) throw createMigrationCheckFailureError(report.changedFiles);
514
+ if (report.scannedFiles === 0) logNoMigrationConfigFilesWarning();
515
+ return report;
516
+ }
517
+ if (report.scannedFiles === 0) {
518
+ logNoMigrationConfigFilesWarning();
519
+ return report;
520
+ }
521
+ logMigrationEntries(report, dryRun);
522
+ logMigrationSummary(report);
523
+ if (checkMode && report.changedFiles > 0) throw createMigrationCheckFailureError(report.changedFiles);
524
+ return report;
525
+ }
526
+ //#endregion
527
+ //#region src/commands/restore-handler.ts
528
+ async function restoreCommandDefaultHandler(ctx) {
529
+ const { args } = ctx;
530
+ const restoreArgs = resolveRestoreCommandArgs(args);
531
+ const result = await require_validate.restoreConfigFiles({
532
+ cwd: ctx.cwd,
533
+ reportFile: restoreArgs.reportFile,
534
+ dryRun: restoreArgs.dryRun,
535
+ strict: restoreArgs.strict
536
+ });
537
+ if (args.json) {
538
+ logRestoreResultAsJson(result);
539
+ return result;
540
+ }
541
+ logRestoreSummary(result);
542
+ return result;
543
+ }
544
+ //#endregion
545
+ //#region src/commands/status-output.ts
546
+ function formatFilesHint(entry) {
547
+ if (!entry.files.length) return "";
548
+ return ` (${entry.files.join(", ")})`;
549
+ }
550
+ function formatPackageLabel(report) {
551
+ return `${report.package.name ?? "tailwindcss"}@${report.package.version ?? "unknown"}`;
552
+ }
553
+ function partitionStatusEntries(report) {
554
+ return {
555
+ applied: report.entries.filter((entry) => entry.status === "applied"),
556
+ pending: report.entries.filter((entry) => entry.status === "not-applied"),
557
+ skipped: report.entries.filter((entry) => entry.status === "skipped" || entry.status === "unsupported")
558
+ };
559
+ }
560
+ function logStatusReportAsJson(report) {
561
+ require_validate.logger.log(JSON.stringify(report, null, 2));
562
+ }
563
+ function logStatusReportSummary(report) {
564
+ const { applied, pending, skipped } = partitionStatusEntries(report);
565
+ require_validate.logger.info(`Patch status for ${formatPackageLabel(report)} (v${report.majorVersion})`);
566
+ if (applied.length) {
567
+ require_validate.logger.success("Applied:");
568
+ applied.forEach((entry) => require_validate.logger.success(` • ${entry.name}${formatFilesHint(entry)}`));
569
+ }
570
+ if (pending.length) {
571
+ require_validate.logger.warn("Needs attention:");
572
+ pending.forEach((entry) => {
573
+ const details = entry.reason ? ` - ${entry.reason}` : "";
574
+ require_validate.logger.warn(` • ${entry.name}${formatFilesHint(entry)}${details}`);
575
+ });
576
+ } else require_validate.logger.success("All applicable patches are applied.");
577
+ if (skipped.length) {
578
+ require_validate.logger.info("Skipped:");
579
+ skipped.forEach((entry) => {
580
+ const details = entry.reason ? ` - ${entry.reason}` : "";
581
+ require_validate.logger.info(` • ${entry.name}${details}`);
582
+ });
583
+ }
584
+ }
585
+ //#endregion
586
+ //#region src/commands/status-handler.ts
587
+ async function statusCommandDefaultHandler(ctx) {
588
+ const report = await (await ctx.createPatcher()).getPatchStatus();
589
+ if (ctx.args.json) {
590
+ logStatusReportAsJson(report);
591
+ return report;
592
+ }
593
+ logStatusReportSummary(report);
594
+ return report;
595
+ }
596
+ //#endregion
597
+ //#region src/commands/validate-handler.ts
598
+ async function validateCommandDefaultHandler(ctx) {
599
+ const { args } = ctx;
600
+ const validateArgs = resolveValidateCommandArgs(args);
601
+ try {
602
+ const result = await require_validate.restoreConfigFiles({
603
+ cwd: ctx.cwd,
604
+ reportFile: validateArgs.reportFile,
605
+ dryRun: true,
606
+ strict: validateArgs.strict
607
+ });
608
+ if (args.json) {
609
+ logValidateSuccessAsJson(result);
610
+ return result;
611
+ }
612
+ logValidateSuccessSummary(result);
613
+ return result;
614
+ } catch (error) {
615
+ const summary = require_validate.classifyValidateError(error);
616
+ if (args.json) logValidateFailureAsJson(summary);
617
+ else logValidateFailureSummary(summary);
618
+ throw new require_validate.ValidateCommandError(summary, { cause: error });
619
+ }
620
+ }
621
+ //#endregion
622
+ //#region src/commands/default-handler-map.ts
623
+ const defaultCommandHandlers = {
624
+ install: installCommandDefaultHandler,
625
+ extract: extractCommandDefaultHandler,
626
+ tokens: tokensCommandDefaultHandler,
627
+ init: initCommandDefaultHandler,
628
+ migrate: migrateCommandDefaultHandler,
629
+ restore: restoreCommandDefaultHandler,
630
+ validate: validateCommandDefaultHandler,
631
+ status: statusCommandDefaultHandler
632
+ };
633
+ //#endregion
634
+ //#region src/commands/command-registrar.ts
635
+ function registerTailwindcssPatchCommand(cli, commandName, options, prefix, defaultDefinitions) {
636
+ const metadata = resolveCommandMetadata(commandName, options, prefix, defaultDefinitions);
637
+ const command = cli.command(metadata.name, metadata.description);
638
+ applyCommandOptions(command, metadata.optionDefs);
639
+ command.action(async (args) => {
640
+ const defaultHandler = defaultCommandHandlers[commandName];
641
+ return runWithCommandHandler(cli, command, commandName, args, options.commandHandlers?.[commandName], defaultHandler);
642
+ });
643
+ metadata.aliases.forEach((alias) => command.alias(alias));
644
+ }
645
+ //#endregion
646
+ //#region src/commands/cli.ts
647
+ function mountTailwindcssPatchCommands(cli, options = {}) {
648
+ const prefix = options.commandPrefix ?? "";
649
+ const selectedCommands = options.commands ?? require_validate.tailwindcssPatchCommands;
650
+ const defaultDefinitions = buildDefaultCommandDefinitions();
651
+ for (const name of selectedCommands) registerTailwindcssPatchCommand(cli, name, options, prefix, defaultDefinitions);
652
+ return cli;
653
+ }
654
+ function createTailwindcssPatchCli(options = {}) {
655
+ const cli = (0, cac.default)(options.name ?? "tw-patch");
656
+ mountTailwindcssPatchCommands(cli, options.mountOptions);
657
+ return cli;
658
+ }
659
+ //#endregion
660
+ Object.defineProperty(exports, "createTailwindcssPatchCli", {
661
+ enumerable: true,
662
+ get: function() {
663
+ return createTailwindcssPatchCli;
664
+ }
665
+ });
666
+ Object.defineProperty(exports, "mountTailwindcssPatchCommands", {
667
+ enumerable: true,
668
+ get: function() {
669
+ return mountTailwindcssPatchCommands;
670
+ }
671
+ });
package/dist/cli.js CHANGED
@@ -1,11 +1,11 @@
1
1
  const require_chunk = require("./chunk-8l464Juk.js");
2
- const require_validate = require("./validate-D9fDrE9I.js");
3
- const require_index_bundle = require("./index.bundle-CGaLDIgy.js");
2
+ const require_validate = require("./validate-5eUbRAzl.js");
3
+ const require_cli = require("./cli-DsXcyl2O.js");
4
4
  let node_process = require("node:process");
5
5
  node_process = require_chunk.__toESM(node_process);
6
- //#region src/cli.bundle.ts
6
+ //#region src/cli.ts
7
7
  async function main() {
8
- const cli = require_index_bundle.createTailwindcssPatchCli();
8
+ const cli = require_cli.createTailwindcssPatchCli();
9
9
  cli.help();
10
10
  cli.parse(node_process.default.argv, { run: false });
11
11
  await cli.runMatchedCommand();
package/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { F as logger, r as ValidateCommandError } from "./validate-Ci0W2Fuu.mjs";
2
- import { t as createTailwindcssPatchCli } from "./index.bundle-D6yHhQ-W.mjs";
1
+ import { it as logger, r as ValidateCommandError } from "./validate-CInDiiYy.mjs";
2
+ import { t as createTailwindcssPatchCli } from "./cli-D5D3Yj69.mjs";
3
3
  import process from "node:process";
4
- //#region src/cli.bundle.ts
4
+ //#region src/cli.ts
5
5
  async function main() {
6
6
  const cli = createTailwindcssPatchCli();
7
7
  cli.help();