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