tailwindcss-patch 9.0.0-alpha.2 → 9.0.0-alpha.3
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/{chunk-TOAZIPHJ.js → chunk-77GHKSKG.js} +33 -724
- package/dist/{chunk-VDWTCQ74.mjs → chunk-D6ICWMM4.mjs} +37 -728
- package/dist/chunk-PMN7HS4Y.js +25 -0
- package/dist/chunk-YYBY7EM5.mjs +21 -0
- package/dist/cli.js +7 -5
- package/dist/cli.mjs +5 -3
- package/dist/commands/cli-runtime.d.mts +13 -0
- package/dist/commands/cli-runtime.d.ts +13 -0
- package/dist/commands/cli-runtime.js +1331 -0
- package/dist/commands/cli-runtime.mjs +1331 -0
- package/dist/index.d.mts +11 -679
- package/dist/index.d.ts +11 -679
- package/dist/index.js +5 -7
- package/dist/index.mjs +6 -8
- package/dist/validate-nbmOI2w8.d.mts +677 -0
- package/dist/validate-nbmOI2w8.d.ts +677 -0
- package/package.json +4 -1
- package/src/cli.bundle.ts +20 -0
- package/src/index.bundle.ts +105 -0
|
@@ -0,0 +1,1331 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TailwindcssPatcher,
|
|
3
|
+
VALIDATE_EXIT_CODES,
|
|
4
|
+
VALIDATE_FAILURE_REASONS,
|
|
5
|
+
ValidateCommandError,
|
|
6
|
+
classifyValidateError,
|
|
7
|
+
groupTokensByFile,
|
|
8
|
+
loadPatchOptionsForWorkspace,
|
|
9
|
+
loadWorkspaceConfigModule,
|
|
10
|
+
logger_default,
|
|
11
|
+
migrateConfigFiles,
|
|
12
|
+
restoreConfigFiles,
|
|
13
|
+
tailwindcssPatchCommands
|
|
14
|
+
} from "../chunk-D6ICWMM4.mjs";
|
|
15
|
+
import "../chunk-A67ABH3M.mjs";
|
|
16
|
+
|
|
17
|
+
// ../../node_modules/.pnpm/cac@7.0.0/node_modules/cac/dist/index.js
|
|
18
|
+
function toArr(any) {
|
|
19
|
+
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
20
|
+
}
|
|
21
|
+
function toVal(out, key, val, opts) {
|
|
22
|
+
var x, old = out[key], nxt = !!~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : !!~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
|
|
23
|
+
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
|
24
|
+
}
|
|
25
|
+
function lib_default(args, opts) {
|
|
26
|
+
args = args || [];
|
|
27
|
+
opts = opts || {};
|
|
28
|
+
var k, arr, arg, name, val, out = { _: [] };
|
|
29
|
+
var i = 0, j = 0, idx = 0, len = args.length;
|
|
30
|
+
const alibi = opts.alias !== void 0;
|
|
31
|
+
const strict = opts.unknown !== void 0;
|
|
32
|
+
const defaults = opts.default !== void 0;
|
|
33
|
+
opts.alias = opts.alias || {};
|
|
34
|
+
opts.string = toArr(opts.string);
|
|
35
|
+
opts.boolean = toArr(opts.boolean);
|
|
36
|
+
if (alibi) for (k in opts.alias) {
|
|
37
|
+
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
38
|
+
for (i = 0; i < arr.length; i++) (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
39
|
+
}
|
|
40
|
+
for (i = opts.boolean.length; i-- > 0; ) {
|
|
41
|
+
arr = opts.alias[opts.boolean[i]] || [];
|
|
42
|
+
for (j = arr.length; j-- > 0; ) opts.boolean.push(arr[j]);
|
|
43
|
+
}
|
|
44
|
+
for (i = opts.string.length; i-- > 0; ) {
|
|
45
|
+
arr = opts.alias[opts.string[i]] || [];
|
|
46
|
+
for (j = arr.length; j-- > 0; ) opts.string.push(arr[j]);
|
|
47
|
+
}
|
|
48
|
+
if (defaults) for (k in opts.default) {
|
|
49
|
+
name = typeof opts.default[k];
|
|
50
|
+
arr = opts.alias[k] = opts.alias[k] || [];
|
|
51
|
+
if (opts[name] !== void 0) {
|
|
52
|
+
opts[name].push(k);
|
|
53
|
+
for (i = 0; i < arr.length; i++) opts[name].push(arr[i]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const keys = strict ? Object.keys(opts.alias) : [];
|
|
57
|
+
for (i = 0; i < len; i++) {
|
|
58
|
+
arg = args[i];
|
|
59
|
+
if (arg === "--") {
|
|
60
|
+
out._ = out._.concat(args.slice(++i));
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
for (j = 0; j < arg.length; j++) if (arg.charCodeAt(j) !== 45) break;
|
|
64
|
+
if (j === 0) out._.push(arg);
|
|
65
|
+
else if (arg.substring(j, j + 3) === "no-") {
|
|
66
|
+
name = arg.substring(j + 3);
|
|
67
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
|
|
68
|
+
out[name] = false;
|
|
69
|
+
} else {
|
|
70
|
+
for (idx = j + 1; idx < arg.length; idx++) if (arg.charCodeAt(idx) === 61) break;
|
|
71
|
+
name = arg.substring(j, idx);
|
|
72
|
+
val = arg.substring(++idx) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
|
|
73
|
+
arr = j === 2 ? [name] : name;
|
|
74
|
+
for (idx = 0; idx < arr.length; idx++) {
|
|
75
|
+
name = arr[idx];
|
|
76
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
|
|
77
|
+
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (defaults) {
|
|
82
|
+
for (k in opts.default) if (out[k] === void 0) out[k] = opts.default[k];
|
|
83
|
+
}
|
|
84
|
+
if (alibi) for (k in out) {
|
|
85
|
+
arr = opts.alias[k] || [];
|
|
86
|
+
while (arr.length > 0) out[arr.shift()] = out[k];
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
function removeBrackets(v) {
|
|
91
|
+
return v.replace(/[<[].+/, "").trim();
|
|
92
|
+
}
|
|
93
|
+
function findAllBrackets(v) {
|
|
94
|
+
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
95
|
+
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
96
|
+
const res = [];
|
|
97
|
+
const parse = (match) => {
|
|
98
|
+
let variadic = false;
|
|
99
|
+
let value = match[1];
|
|
100
|
+
if (value.startsWith("...")) {
|
|
101
|
+
value = value.slice(3);
|
|
102
|
+
variadic = true;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
required: match[0].startsWith("<"),
|
|
106
|
+
value,
|
|
107
|
+
variadic
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
let angledMatch;
|
|
111
|
+
while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(angledMatch));
|
|
112
|
+
let squareMatch;
|
|
113
|
+
while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(squareMatch));
|
|
114
|
+
return res;
|
|
115
|
+
}
|
|
116
|
+
function getMriOptions(options) {
|
|
117
|
+
const result = {
|
|
118
|
+
alias: {},
|
|
119
|
+
boolean: []
|
|
120
|
+
};
|
|
121
|
+
for (const [index, option] of options.entries()) {
|
|
122
|
+
if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
|
|
123
|
+
if (option.isBoolean) if (option.negated) {
|
|
124
|
+
if (!options.some((o, i) => {
|
|
125
|
+
return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
|
|
126
|
+
})) result.boolean.push(option.names[0]);
|
|
127
|
+
} else result.boolean.push(option.names[0]);
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
function findLongest(arr) {
|
|
132
|
+
return arr.sort((a, b) => {
|
|
133
|
+
return a.length > b.length ? -1 : 1;
|
|
134
|
+
})[0];
|
|
135
|
+
}
|
|
136
|
+
function padRight(str, length) {
|
|
137
|
+
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
138
|
+
}
|
|
139
|
+
function camelcase(input) {
|
|
140
|
+
return input.replaceAll(/([a-z])-([a-z])/g, (_, p1, p2) => {
|
|
141
|
+
return p1 + p2.toUpperCase();
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function setDotProp(obj, keys, val) {
|
|
145
|
+
let current = obj;
|
|
146
|
+
for (let i = 0; i < keys.length; i++) {
|
|
147
|
+
const key = keys[i];
|
|
148
|
+
if (i === keys.length - 1) {
|
|
149
|
+
current[key] = val;
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (current[key] == null) {
|
|
153
|
+
const nextKeyIsArrayIndex = +keys[i + 1] > -1;
|
|
154
|
+
current[key] = nextKeyIsArrayIndex ? [] : {};
|
|
155
|
+
}
|
|
156
|
+
current = current[key];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function setByType(obj, transforms) {
|
|
160
|
+
for (const key of Object.keys(transforms)) {
|
|
161
|
+
const transform = transforms[key];
|
|
162
|
+
if (transform.shouldTransform) {
|
|
163
|
+
obj[key] = [obj[key]].flat();
|
|
164
|
+
if (typeof transform.transformFunction === "function") obj[key] = obj[key].map(transform.transformFunction);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function getFileName(input) {
|
|
169
|
+
const m = /([^\\/]+)$/.exec(input);
|
|
170
|
+
return m ? m[1] : "";
|
|
171
|
+
}
|
|
172
|
+
function camelcaseOptionName(name) {
|
|
173
|
+
return name.split(".").map((v, i) => {
|
|
174
|
+
return i === 0 ? camelcase(v) : v;
|
|
175
|
+
}).join(".");
|
|
176
|
+
}
|
|
177
|
+
var CACError = class extends Error {
|
|
178
|
+
constructor(message) {
|
|
179
|
+
super(message);
|
|
180
|
+
this.name = "CACError";
|
|
181
|
+
if (typeof Error.captureStackTrace !== "function") this.stack = new Error(message).stack;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
var Option = class {
|
|
185
|
+
rawName;
|
|
186
|
+
description;
|
|
187
|
+
/** Option name */
|
|
188
|
+
name;
|
|
189
|
+
/** Option name and aliases */
|
|
190
|
+
names;
|
|
191
|
+
isBoolean;
|
|
192
|
+
required;
|
|
193
|
+
config;
|
|
194
|
+
negated;
|
|
195
|
+
constructor(rawName, description, config) {
|
|
196
|
+
this.rawName = rawName;
|
|
197
|
+
this.description = description;
|
|
198
|
+
this.config = Object.assign({}, config);
|
|
199
|
+
rawName = rawName.replaceAll(".*", "");
|
|
200
|
+
this.negated = false;
|
|
201
|
+
this.names = removeBrackets(rawName).split(",").map((v) => {
|
|
202
|
+
let name = v.trim().replace(/^-{1,2}/, "");
|
|
203
|
+
if (name.startsWith("no-")) {
|
|
204
|
+
this.negated = true;
|
|
205
|
+
name = name.replace(/^no-/, "");
|
|
206
|
+
}
|
|
207
|
+
return camelcaseOptionName(name);
|
|
208
|
+
}).sort((a, b) => a.length > b.length ? 1 : -1);
|
|
209
|
+
this.name = this.names.at(-1);
|
|
210
|
+
if (this.negated && this.config.default == null) this.config.default = true;
|
|
211
|
+
if (rawName.includes("<")) this.required = true;
|
|
212
|
+
else if (rawName.includes("[")) this.required = false;
|
|
213
|
+
else this.isBoolean = true;
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
var runtimeProcessArgs;
|
|
217
|
+
var runtimeInfo;
|
|
218
|
+
if (typeof process !== "undefined") {
|
|
219
|
+
let runtimeName;
|
|
220
|
+
if (typeof Deno !== "undefined" && typeof Deno.version?.deno === "string") runtimeName = "deno";
|
|
221
|
+
else if (typeof Bun !== "undefined" && typeof Bun.version === "string") runtimeName = "bun";
|
|
222
|
+
else runtimeName = "node";
|
|
223
|
+
runtimeInfo = `${process.platform}-${process.arch} ${runtimeName}-${process.version}`;
|
|
224
|
+
runtimeProcessArgs = process.argv;
|
|
225
|
+
} else if (typeof navigator === "undefined") runtimeInfo = `unknown`;
|
|
226
|
+
else runtimeInfo = `${navigator.platform} ${navigator.userAgent}`;
|
|
227
|
+
var Command = class {
|
|
228
|
+
rawName;
|
|
229
|
+
description;
|
|
230
|
+
config;
|
|
231
|
+
cli;
|
|
232
|
+
options;
|
|
233
|
+
aliasNames;
|
|
234
|
+
name;
|
|
235
|
+
args;
|
|
236
|
+
commandAction;
|
|
237
|
+
usageText;
|
|
238
|
+
versionNumber;
|
|
239
|
+
examples;
|
|
240
|
+
helpCallback;
|
|
241
|
+
globalCommand;
|
|
242
|
+
constructor(rawName, description, config = {}, cli) {
|
|
243
|
+
this.rawName = rawName;
|
|
244
|
+
this.description = description;
|
|
245
|
+
this.config = config;
|
|
246
|
+
this.cli = cli;
|
|
247
|
+
this.options = [];
|
|
248
|
+
this.aliasNames = [];
|
|
249
|
+
this.name = removeBrackets(rawName);
|
|
250
|
+
this.args = findAllBrackets(rawName);
|
|
251
|
+
this.examples = [];
|
|
252
|
+
}
|
|
253
|
+
usage(text) {
|
|
254
|
+
this.usageText = text;
|
|
255
|
+
return this;
|
|
256
|
+
}
|
|
257
|
+
allowUnknownOptions() {
|
|
258
|
+
this.config.allowUnknownOptions = true;
|
|
259
|
+
return this;
|
|
260
|
+
}
|
|
261
|
+
ignoreOptionDefaultValue() {
|
|
262
|
+
this.config.ignoreOptionDefaultValue = true;
|
|
263
|
+
return this;
|
|
264
|
+
}
|
|
265
|
+
version(version, customFlags = "-v, --version") {
|
|
266
|
+
this.versionNumber = version;
|
|
267
|
+
this.option(customFlags, "Display version number");
|
|
268
|
+
return this;
|
|
269
|
+
}
|
|
270
|
+
example(example) {
|
|
271
|
+
this.examples.push(example);
|
|
272
|
+
return this;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Add a option for this command
|
|
276
|
+
* @param rawName Raw option name(s)
|
|
277
|
+
* @param description Option description
|
|
278
|
+
* @param config Option config
|
|
279
|
+
*/
|
|
280
|
+
option(rawName, description, config) {
|
|
281
|
+
const option = new Option(rawName, description, config);
|
|
282
|
+
this.options.push(option);
|
|
283
|
+
return this;
|
|
284
|
+
}
|
|
285
|
+
alias(name) {
|
|
286
|
+
this.aliasNames.push(name);
|
|
287
|
+
return this;
|
|
288
|
+
}
|
|
289
|
+
action(callback) {
|
|
290
|
+
this.commandAction = callback;
|
|
291
|
+
return this;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Check if a command name is matched by this command
|
|
295
|
+
* @param name Command name
|
|
296
|
+
*/
|
|
297
|
+
isMatched(name) {
|
|
298
|
+
return this.name === name || this.aliasNames.includes(name);
|
|
299
|
+
}
|
|
300
|
+
get isDefaultCommand() {
|
|
301
|
+
return this.name === "" || this.aliasNames.includes("!");
|
|
302
|
+
}
|
|
303
|
+
get isGlobalCommand() {
|
|
304
|
+
return this instanceof GlobalCommand;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Check if an option is registered in this command
|
|
308
|
+
* @param name Option name
|
|
309
|
+
*/
|
|
310
|
+
hasOption(name) {
|
|
311
|
+
name = name.split(".")[0];
|
|
312
|
+
return this.options.find((option) => {
|
|
313
|
+
return option.names.includes(name);
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
outputHelp() {
|
|
317
|
+
const { name, commands } = this.cli;
|
|
318
|
+
const { versionNumber, options: globalOptions, helpCallback } = this.cli.globalCommand;
|
|
319
|
+
let sections = [{ body: `${name}${versionNumber ? `/${versionNumber}` : ""}` }];
|
|
320
|
+
sections.push({
|
|
321
|
+
title: "Usage",
|
|
322
|
+
body: ` $ ${name} ${this.usageText || this.rawName}`
|
|
323
|
+
});
|
|
324
|
+
if ((this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0) {
|
|
325
|
+
const longestCommandName = findLongest(commands.map((command) => command.rawName));
|
|
326
|
+
sections.push({
|
|
327
|
+
title: "Commands",
|
|
328
|
+
body: commands.map((command) => {
|
|
329
|
+
return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
|
|
330
|
+
}).join("\n")
|
|
331
|
+
}, {
|
|
332
|
+
title: `For more info, run any command with the \`--help\` flag`,
|
|
333
|
+
body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
|
|
337
|
+
if (!this.isGlobalCommand && !this.isDefaultCommand) options = options.filter((option) => option.name !== "version");
|
|
338
|
+
if (options.length > 0) {
|
|
339
|
+
const longestOptionName = findLongest(options.map((option) => option.rawName));
|
|
340
|
+
sections.push({
|
|
341
|
+
title: "Options",
|
|
342
|
+
body: options.map((option) => {
|
|
343
|
+
return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
|
|
344
|
+
}).join("\n")
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
if (this.examples.length > 0) sections.push({
|
|
348
|
+
title: "Examples",
|
|
349
|
+
body: this.examples.map((example) => {
|
|
350
|
+
if (typeof example === "function") return example(name);
|
|
351
|
+
return example;
|
|
352
|
+
}).join("\n")
|
|
353
|
+
});
|
|
354
|
+
if (helpCallback) sections = helpCallback(sections) || sections;
|
|
355
|
+
console.info(sections.map((section) => {
|
|
356
|
+
return section.title ? `${section.title}:
|
|
357
|
+
${section.body}` : section.body;
|
|
358
|
+
}).join("\n\n"));
|
|
359
|
+
}
|
|
360
|
+
outputVersion() {
|
|
361
|
+
const { name } = this.cli;
|
|
362
|
+
const { versionNumber } = this.cli.globalCommand;
|
|
363
|
+
if (versionNumber) console.info(`${name}/${versionNumber} ${runtimeInfo}`);
|
|
364
|
+
}
|
|
365
|
+
checkRequiredArgs() {
|
|
366
|
+
const minimalArgsCount = this.args.filter((arg) => arg.required).length;
|
|
367
|
+
if (this.cli.args.length < minimalArgsCount) throw new CACError(`missing required args for command \`${this.rawName}\``);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Check if the parsed options contain any unknown options
|
|
371
|
+
*
|
|
372
|
+
* Exit and output error when true
|
|
373
|
+
*/
|
|
374
|
+
checkUnknownOptions() {
|
|
375
|
+
const { options, globalCommand } = this.cli;
|
|
376
|
+
if (!this.config.allowUnknownOptions) {
|
|
377
|
+
for (const name of Object.keys(options)) if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Check if the required string-type options exist
|
|
382
|
+
*/
|
|
383
|
+
checkOptionValue() {
|
|
384
|
+
const { options: parsedOptions, globalCommand } = this.cli;
|
|
385
|
+
const options = [...globalCommand.options, ...this.options];
|
|
386
|
+
for (const option of options) {
|
|
387
|
+
const value = parsedOptions[option.name.split(".")[0]];
|
|
388
|
+
if (option.required) {
|
|
389
|
+
const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
|
|
390
|
+
if (value === true || value === false && !hasNegated) throw new CACError(`option \`${option.rawName}\` value is missing`);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Check if the number of args is more than expected
|
|
396
|
+
*/
|
|
397
|
+
checkUnusedArgs() {
|
|
398
|
+
const maximumArgsCount = this.args.some((arg) => arg.variadic) ? Infinity : this.args.length;
|
|
399
|
+
if (maximumArgsCount < this.cli.args.length) throw new CACError(`Unused args: ${this.cli.args.slice(maximumArgsCount).map((arg) => `\`${arg}\``).join(", ")}`);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
var GlobalCommand = class extends Command {
|
|
403
|
+
constructor(cli) {
|
|
404
|
+
super("@@global@@", "", {}, cli);
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
var CAC = class extends EventTarget {
|
|
408
|
+
/** The program name to display in help and version message */
|
|
409
|
+
name;
|
|
410
|
+
commands;
|
|
411
|
+
globalCommand;
|
|
412
|
+
matchedCommand;
|
|
413
|
+
matchedCommandName;
|
|
414
|
+
/**
|
|
415
|
+
* Raw CLI arguments
|
|
416
|
+
*/
|
|
417
|
+
rawArgs;
|
|
418
|
+
/**
|
|
419
|
+
* Parsed CLI arguments
|
|
420
|
+
*/
|
|
421
|
+
args;
|
|
422
|
+
/**
|
|
423
|
+
* Parsed CLI options, camelCased
|
|
424
|
+
*/
|
|
425
|
+
options;
|
|
426
|
+
showHelpOnExit;
|
|
427
|
+
showVersionOnExit;
|
|
428
|
+
/**
|
|
429
|
+
* @param name The program name to display in help and version message
|
|
430
|
+
*/
|
|
431
|
+
constructor(name = "") {
|
|
432
|
+
super();
|
|
433
|
+
this.name = name;
|
|
434
|
+
this.commands = [];
|
|
435
|
+
this.rawArgs = [];
|
|
436
|
+
this.args = [];
|
|
437
|
+
this.options = {};
|
|
438
|
+
this.globalCommand = new GlobalCommand(this);
|
|
439
|
+
this.globalCommand.usage("<command> [options]");
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Add a global usage text.
|
|
443
|
+
*
|
|
444
|
+
* This is not used by sub-commands.
|
|
445
|
+
*/
|
|
446
|
+
usage(text) {
|
|
447
|
+
this.globalCommand.usage(text);
|
|
448
|
+
return this;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Add a sub-command
|
|
452
|
+
*/
|
|
453
|
+
command(rawName, description, config) {
|
|
454
|
+
const command = new Command(rawName, description || "", config, this);
|
|
455
|
+
command.globalCommand = this.globalCommand;
|
|
456
|
+
this.commands.push(command);
|
|
457
|
+
return command;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Add a global CLI option.
|
|
461
|
+
*
|
|
462
|
+
* Which is also applied to sub-commands.
|
|
463
|
+
*/
|
|
464
|
+
option(rawName, description, config) {
|
|
465
|
+
this.globalCommand.option(rawName, description, config);
|
|
466
|
+
return this;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Show help message when `-h, --help` flags appear.
|
|
470
|
+
*
|
|
471
|
+
*/
|
|
472
|
+
help(callback) {
|
|
473
|
+
this.globalCommand.option("-h, --help", "Display this message");
|
|
474
|
+
this.globalCommand.helpCallback = callback;
|
|
475
|
+
this.showHelpOnExit = true;
|
|
476
|
+
return this;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Show version number when `-v, --version` flags appear.
|
|
480
|
+
*
|
|
481
|
+
*/
|
|
482
|
+
version(version, customFlags = "-v, --version") {
|
|
483
|
+
this.globalCommand.version(version, customFlags);
|
|
484
|
+
this.showVersionOnExit = true;
|
|
485
|
+
return this;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Add a global example.
|
|
489
|
+
*
|
|
490
|
+
* This example added here will not be used by sub-commands.
|
|
491
|
+
*/
|
|
492
|
+
example(example) {
|
|
493
|
+
this.globalCommand.example(example);
|
|
494
|
+
return this;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Output the corresponding help message
|
|
498
|
+
* When a sub-command is matched, output the help message for the command
|
|
499
|
+
* Otherwise output the global one.
|
|
500
|
+
*
|
|
501
|
+
*/
|
|
502
|
+
outputHelp() {
|
|
503
|
+
if (this.matchedCommand) this.matchedCommand.outputHelp();
|
|
504
|
+
else this.globalCommand.outputHelp();
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Output the version number.
|
|
508
|
+
*
|
|
509
|
+
*/
|
|
510
|
+
outputVersion() {
|
|
511
|
+
this.globalCommand.outputVersion();
|
|
512
|
+
}
|
|
513
|
+
setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
|
|
514
|
+
this.args = args;
|
|
515
|
+
this.options = options;
|
|
516
|
+
if (matchedCommand) this.matchedCommand = matchedCommand;
|
|
517
|
+
if (matchedCommandName) this.matchedCommandName = matchedCommandName;
|
|
518
|
+
return this;
|
|
519
|
+
}
|
|
520
|
+
unsetMatchedCommand() {
|
|
521
|
+
this.matchedCommand = void 0;
|
|
522
|
+
this.matchedCommandName = void 0;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Parse argv
|
|
526
|
+
*/
|
|
527
|
+
parse(argv, { run = true } = {}) {
|
|
528
|
+
if (!argv) {
|
|
529
|
+
if (!runtimeProcessArgs) throw new Error("No argv provided and runtime process argv is not available.");
|
|
530
|
+
argv = runtimeProcessArgs;
|
|
531
|
+
}
|
|
532
|
+
this.rawArgs = argv;
|
|
533
|
+
if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
|
|
534
|
+
let shouldParse = true;
|
|
535
|
+
for (const command of this.commands) {
|
|
536
|
+
const parsed = this.mri(argv.slice(2), command);
|
|
537
|
+
const commandName = parsed.args[0];
|
|
538
|
+
if (command.isMatched(commandName)) {
|
|
539
|
+
shouldParse = false;
|
|
540
|
+
const parsedInfo = {
|
|
541
|
+
...parsed,
|
|
542
|
+
args: parsed.args.slice(1)
|
|
543
|
+
};
|
|
544
|
+
this.setParsedInfo(parsedInfo, command, commandName);
|
|
545
|
+
this.dispatchEvent(new CustomEvent(`command:${commandName}`, { detail: command }));
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
if (shouldParse) {
|
|
549
|
+
for (const command of this.commands) if (command.isDefaultCommand) {
|
|
550
|
+
shouldParse = false;
|
|
551
|
+
const parsed = this.mri(argv.slice(2), command);
|
|
552
|
+
this.setParsedInfo(parsed, command);
|
|
553
|
+
this.dispatchEvent(new CustomEvent("command:!", { detail: command }));
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
if (shouldParse) {
|
|
557
|
+
const parsed = this.mri(argv.slice(2));
|
|
558
|
+
this.setParsedInfo(parsed);
|
|
559
|
+
}
|
|
560
|
+
if (this.options.help && this.showHelpOnExit) {
|
|
561
|
+
this.outputHelp();
|
|
562
|
+
run = false;
|
|
563
|
+
this.unsetMatchedCommand();
|
|
564
|
+
}
|
|
565
|
+
if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
|
|
566
|
+
this.outputVersion();
|
|
567
|
+
run = false;
|
|
568
|
+
this.unsetMatchedCommand();
|
|
569
|
+
}
|
|
570
|
+
const parsedArgv = {
|
|
571
|
+
args: this.args,
|
|
572
|
+
options: this.options
|
|
573
|
+
};
|
|
574
|
+
if (run) this.runMatchedCommand();
|
|
575
|
+
if (!this.matchedCommand && this.args[0]) this.dispatchEvent(new CustomEvent("command:*", { detail: this.args[0] }));
|
|
576
|
+
return parsedArgv;
|
|
577
|
+
}
|
|
578
|
+
mri(argv, command) {
|
|
579
|
+
const cliOptions = [...this.globalCommand.options, ...command ? command.options : []];
|
|
580
|
+
const mriOptions = getMriOptions(cliOptions);
|
|
581
|
+
let argsAfterDoubleDashes = [];
|
|
582
|
+
const doubleDashesIndex = argv.indexOf("--");
|
|
583
|
+
if (doubleDashesIndex !== -1) {
|
|
584
|
+
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
|
585
|
+
argv = argv.slice(0, doubleDashesIndex);
|
|
586
|
+
}
|
|
587
|
+
let parsed = lib_default(argv, mriOptions);
|
|
588
|
+
parsed = Object.keys(parsed).reduce((res, name) => {
|
|
589
|
+
return {
|
|
590
|
+
...res,
|
|
591
|
+
[camelcaseOptionName(name)]: parsed[name]
|
|
592
|
+
};
|
|
593
|
+
}, { _: [] });
|
|
594
|
+
const args = parsed._;
|
|
595
|
+
const options = { "--": argsAfterDoubleDashes };
|
|
596
|
+
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
|
597
|
+
const transforms = /* @__PURE__ */ Object.create(null);
|
|
598
|
+
for (const cliOption of cliOptions) {
|
|
599
|
+
if (!ignoreDefault && cliOption.config.default !== void 0) for (const name of cliOption.names) options[name] = cliOption.config.default;
|
|
600
|
+
if (Array.isArray(cliOption.config.type) && transforms[cliOption.name] === void 0) {
|
|
601
|
+
transforms[cliOption.name] = /* @__PURE__ */ Object.create(null);
|
|
602
|
+
transforms[cliOption.name].shouldTransform = true;
|
|
603
|
+
transforms[cliOption.name].transformFunction = cliOption.config.type[0];
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
for (const key of Object.keys(parsed)) if (key !== "_") {
|
|
607
|
+
setDotProp(options, key.split("."), parsed[key]);
|
|
608
|
+
setByType(options, transforms);
|
|
609
|
+
}
|
|
610
|
+
return {
|
|
611
|
+
args,
|
|
612
|
+
options
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
runMatchedCommand() {
|
|
616
|
+
const { args, options, matchedCommand: command } = this;
|
|
617
|
+
if (!command || !command.commandAction) return;
|
|
618
|
+
command.checkUnknownOptions();
|
|
619
|
+
command.checkOptionValue();
|
|
620
|
+
command.checkRequiredArgs();
|
|
621
|
+
command.checkUnusedArgs();
|
|
622
|
+
const actionArgs = [];
|
|
623
|
+
command.args.forEach((arg, index) => {
|
|
624
|
+
if (arg.variadic) actionArgs.push(args.slice(index));
|
|
625
|
+
else actionArgs.push(args[index]);
|
|
626
|
+
});
|
|
627
|
+
actionArgs.push(options);
|
|
628
|
+
return command.commandAction.apply(this, actionArgs);
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
var cac = (name = "") => new CAC(name);
|
|
632
|
+
|
|
633
|
+
// src/commands/command-definitions.ts
|
|
634
|
+
import process2 from "process";
|
|
635
|
+
|
|
636
|
+
// src/commands/token-output.ts
|
|
637
|
+
var TOKEN_FORMATS = ["json", "lines", "grouped-json"];
|
|
638
|
+
var DEFAULT_TOKEN_REPORT = ".tw-patch/tw-token-report.json";
|
|
639
|
+
function formatTokenLine(entry) {
|
|
640
|
+
return `${entry.relativeFile}:${entry.line}:${entry.column} ${entry.rawCandidate} (${entry.start}-${entry.end})`;
|
|
641
|
+
}
|
|
642
|
+
function formatGroupedPreview(map, limit = 3) {
|
|
643
|
+
const files = Object.keys(map);
|
|
644
|
+
if (!files.length) {
|
|
645
|
+
return { preview: "", moreFiles: 0 };
|
|
646
|
+
}
|
|
647
|
+
const lines = files.slice(0, limit).map((file) => {
|
|
648
|
+
const tokens = map[file] ?? [];
|
|
649
|
+
const sample = tokens.slice(0, 3).map((token) => token.rawCandidate).join(", ");
|
|
650
|
+
const suffix = tokens.length > 3 ? ", \u2026" : "";
|
|
651
|
+
return `${file}: ${tokens.length} tokens (${sample}${suffix})`;
|
|
652
|
+
});
|
|
653
|
+
return {
|
|
654
|
+
preview: lines.join("\n"),
|
|
655
|
+
moreFiles: Math.max(0, files.length - limit)
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// src/commands/command-definitions.ts
|
|
660
|
+
function createCwdOptionDefinition(description = "Working directory") {
|
|
661
|
+
return {
|
|
662
|
+
flags: "--cwd <dir>",
|
|
663
|
+
description,
|
|
664
|
+
config: { default: process2.cwd() }
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
function buildDefaultCommandDefinitions() {
|
|
668
|
+
return {
|
|
669
|
+
install: {
|
|
670
|
+
description: "Apply Tailwind CSS runtime patches",
|
|
671
|
+
optionDefs: [createCwdOptionDefinition()]
|
|
672
|
+
},
|
|
673
|
+
extract: {
|
|
674
|
+
description: "Collect generated class names into a cache file",
|
|
675
|
+
optionDefs: [
|
|
676
|
+
createCwdOptionDefinition(),
|
|
677
|
+
{ flags: "--output <file>", description: "Override output file path" },
|
|
678
|
+
{ flags: "--format <format>", description: "Output format (json|lines)" },
|
|
679
|
+
{ flags: "--css <file>", description: "Tailwind CSS entry CSS when using v4" },
|
|
680
|
+
{ flags: "--no-write", description: "Skip writing to disk" }
|
|
681
|
+
]
|
|
682
|
+
},
|
|
683
|
+
tokens: {
|
|
684
|
+
description: "Extract Tailwind tokens with file/position metadata",
|
|
685
|
+
optionDefs: [
|
|
686
|
+
createCwdOptionDefinition(),
|
|
687
|
+
{ flags: "--output <file>", description: "Override output file path", config: { default: DEFAULT_TOKEN_REPORT } },
|
|
688
|
+
{
|
|
689
|
+
flags: "--format <format>",
|
|
690
|
+
description: "Output format (json|lines|grouped-json)",
|
|
691
|
+
config: { default: "json" }
|
|
692
|
+
},
|
|
693
|
+
{
|
|
694
|
+
flags: "--group-key <key>",
|
|
695
|
+
description: "Grouping key for grouped-json output (relative|absolute)",
|
|
696
|
+
config: { default: "relative" }
|
|
697
|
+
},
|
|
698
|
+
{ flags: "--no-write", description: "Skip writing to disk" }
|
|
699
|
+
]
|
|
700
|
+
},
|
|
701
|
+
init: {
|
|
702
|
+
description: "Generate a tailwindcss-patch config file",
|
|
703
|
+
optionDefs: [createCwdOptionDefinition()]
|
|
704
|
+
},
|
|
705
|
+
migrate: {
|
|
706
|
+
description: "Migrate deprecated config fields to modern options",
|
|
707
|
+
optionDefs: [
|
|
708
|
+
createCwdOptionDefinition(),
|
|
709
|
+
{ flags: "--config <file>", description: "Migrate a specific config file path" },
|
|
710
|
+
{ flags: "--workspace", description: "Scan workspace recursively for config files" },
|
|
711
|
+
{ flags: "--max-depth <n>", description: "Maximum recursion depth for --workspace", config: { default: 6 } },
|
|
712
|
+
{ flags: "--include <glob>", description: "Only migrate files that match this glob (repeatable)" },
|
|
713
|
+
{ flags: "--exclude <glob>", description: "Skip files that match this glob (repeatable)" },
|
|
714
|
+
{ flags: "--report-file <file>", description: "Write migration report JSON to a file" },
|
|
715
|
+
{ flags: "--backup-dir <dir>", description: "Write pre-migration backups into this directory" },
|
|
716
|
+
{ flags: "--check", description: "Exit with an error when migration changes are required" },
|
|
717
|
+
{ flags: "--json", description: "Print the migration report as JSON" },
|
|
718
|
+
{ flags: "--dry-run", description: "Preview changes without writing files" }
|
|
719
|
+
]
|
|
720
|
+
},
|
|
721
|
+
restore: {
|
|
722
|
+
description: "Restore config files from a previous migration report backup snapshot",
|
|
723
|
+
optionDefs: [
|
|
724
|
+
createCwdOptionDefinition(),
|
|
725
|
+
{ flags: "--report-file <file>", description: "Migration report file generated by migrate" },
|
|
726
|
+
{ flags: "--dry-run", description: "Preview restore targets without writing files" },
|
|
727
|
+
{ flags: "--strict", description: "Fail when any backup file is missing" },
|
|
728
|
+
{ flags: "--json", description: "Print the restore result as JSON" }
|
|
729
|
+
]
|
|
730
|
+
},
|
|
731
|
+
validate: {
|
|
732
|
+
description: "Validate migration report compatibility without modifying files",
|
|
733
|
+
optionDefs: [
|
|
734
|
+
createCwdOptionDefinition(),
|
|
735
|
+
{ flags: "--report-file <file>", description: "Migration report file to validate" },
|
|
736
|
+
{ flags: "--strict", description: "Fail when any backup file is missing" },
|
|
737
|
+
{ flags: "--json", description: "Print validation result as JSON" }
|
|
738
|
+
]
|
|
739
|
+
},
|
|
740
|
+
status: {
|
|
741
|
+
description: "Check which Tailwind patches are applied",
|
|
742
|
+
optionDefs: [
|
|
743
|
+
createCwdOptionDefinition(),
|
|
744
|
+
{ flags: "--json", description: "Print a JSON report of patch status" }
|
|
745
|
+
]
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// src/commands/command-metadata.ts
|
|
751
|
+
function addPrefixIfMissing(value, prefix) {
|
|
752
|
+
if (!prefix || value.startsWith(prefix)) {
|
|
753
|
+
return value;
|
|
754
|
+
}
|
|
755
|
+
return `${prefix}${value}`;
|
|
756
|
+
}
|
|
757
|
+
function resolveCommandNames(command, mountOptions, prefix) {
|
|
758
|
+
const override = mountOptions.commandOptions?.[command];
|
|
759
|
+
const baseName = override?.name ?? command;
|
|
760
|
+
const name = addPrefixIfMissing(baseName, prefix);
|
|
761
|
+
const aliases = (override?.aliases ?? []).map((alias) => addPrefixIfMissing(alias, prefix));
|
|
762
|
+
return { name, aliases };
|
|
763
|
+
}
|
|
764
|
+
function resolveOptionDefinitions(defaults, override) {
|
|
765
|
+
if (!override) {
|
|
766
|
+
return defaults;
|
|
767
|
+
}
|
|
768
|
+
const appendDefaults = override.appendDefaultOptions ?? true;
|
|
769
|
+
const customDefs = override.optionDefs ?? [];
|
|
770
|
+
if (!appendDefaults) {
|
|
771
|
+
return customDefs;
|
|
772
|
+
}
|
|
773
|
+
if (customDefs.length === 0) {
|
|
774
|
+
return defaults;
|
|
775
|
+
}
|
|
776
|
+
return [...defaults, ...customDefs];
|
|
777
|
+
}
|
|
778
|
+
function resolveCommandMetadata(command, mountOptions, prefix, defaults) {
|
|
779
|
+
const names = resolveCommandNames(command, mountOptions, prefix);
|
|
780
|
+
const definition = defaults[command];
|
|
781
|
+
const override = mountOptions.commandOptions?.[command];
|
|
782
|
+
const description = override?.description ?? definition.description;
|
|
783
|
+
const optionDefs = resolveOptionDefinitions(definition.optionDefs, override);
|
|
784
|
+
return { ...names, description, optionDefs };
|
|
785
|
+
}
|
|
786
|
+
function applyCommandOptions(command, optionDefs) {
|
|
787
|
+
for (const option of optionDefs) {
|
|
788
|
+
command.option(option.flags, option.description ?? "", option.config);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// src/commands/command-context.ts
|
|
793
|
+
import process3 from "process";
|
|
794
|
+
import path from "pathe";
|
|
795
|
+
function resolveCommandCwd(rawCwd) {
|
|
796
|
+
if (!rawCwd) {
|
|
797
|
+
return process3.cwd();
|
|
798
|
+
}
|
|
799
|
+
return path.resolve(rawCwd);
|
|
800
|
+
}
|
|
801
|
+
function createMemoizedPromiseRunner(factory) {
|
|
802
|
+
let promise;
|
|
803
|
+
return () => {
|
|
804
|
+
if (!promise) {
|
|
805
|
+
promise = factory();
|
|
806
|
+
}
|
|
807
|
+
return promise;
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
function createTailwindcssPatchCommandContext(cli, command, commandName, args, cwd) {
|
|
811
|
+
const loadCachedConfig = createMemoizedPromiseRunner(
|
|
812
|
+
() => loadWorkspaceConfigModule().then((mod) => mod.getConfig(cwd))
|
|
813
|
+
);
|
|
814
|
+
const loadCachedPatchOptions = createMemoizedPromiseRunner(
|
|
815
|
+
() => loadPatchOptionsForWorkspace(cwd)
|
|
816
|
+
);
|
|
817
|
+
const createCachedPatcher = createMemoizedPromiseRunner(async () => {
|
|
818
|
+
const patchOptions = await loadCachedPatchOptions();
|
|
819
|
+
return new TailwindcssPatcher(patchOptions);
|
|
820
|
+
});
|
|
821
|
+
const loadPatchOptionsForContext = (overrides) => {
|
|
822
|
+
if (overrides) {
|
|
823
|
+
return loadPatchOptionsForWorkspace(cwd, overrides);
|
|
824
|
+
}
|
|
825
|
+
return loadCachedPatchOptions();
|
|
826
|
+
};
|
|
827
|
+
const createPatcherForContext = async (overrides) => {
|
|
828
|
+
if (overrides) {
|
|
829
|
+
const patchOptions = await loadPatchOptionsForWorkspace(cwd, overrides);
|
|
830
|
+
return new TailwindcssPatcher(patchOptions);
|
|
831
|
+
}
|
|
832
|
+
return createCachedPatcher();
|
|
833
|
+
};
|
|
834
|
+
return {
|
|
835
|
+
cli,
|
|
836
|
+
command,
|
|
837
|
+
commandName,
|
|
838
|
+
args,
|
|
839
|
+
cwd,
|
|
840
|
+
logger: logger_default,
|
|
841
|
+
loadConfig: loadCachedConfig,
|
|
842
|
+
loadPatchOptions: loadPatchOptionsForContext,
|
|
843
|
+
createPatcher: createPatcherForContext
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// src/commands/command-runtime.ts
|
|
848
|
+
function runWithCommandHandler(cli, command, commandName, args, handler, defaultHandler) {
|
|
849
|
+
const cwd = resolveCommandCwd(args.cwd);
|
|
850
|
+
const context = createTailwindcssPatchCommandContext(cli, command, commandName, args, cwd);
|
|
851
|
+
const runDefault = createMemoizedPromiseRunner(() => defaultHandler(context));
|
|
852
|
+
if (!handler) {
|
|
853
|
+
return runDefault();
|
|
854
|
+
}
|
|
855
|
+
return handler(context, runDefault);
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// src/commands/basic-handlers.ts
|
|
859
|
+
import process4 from "process";
|
|
860
|
+
import fs from "fs-extra";
|
|
861
|
+
import path2 from "pathe";
|
|
862
|
+
var DEFAULT_CONFIG_NAME = "tailwindcss-mangle";
|
|
863
|
+
async function installCommandDefaultHandler(_ctx) {
|
|
864
|
+
const patcher = await _ctx.createPatcher();
|
|
865
|
+
await patcher.patch();
|
|
866
|
+
logger_default.success("Tailwind CSS runtime patched successfully.");
|
|
867
|
+
}
|
|
868
|
+
async function extractCommandDefaultHandler(ctx) {
|
|
869
|
+
const { args } = ctx;
|
|
870
|
+
const overrides = {};
|
|
871
|
+
let hasOverrides = false;
|
|
872
|
+
if (args.output || args.format) {
|
|
873
|
+
overrides.extract = {
|
|
874
|
+
...args.output === void 0 ? {} : { file: args.output },
|
|
875
|
+
...args.format === void 0 ? {} : { format: args.format }
|
|
876
|
+
};
|
|
877
|
+
hasOverrides = true;
|
|
878
|
+
}
|
|
879
|
+
if (args.css) {
|
|
880
|
+
overrides.tailwindcss = {
|
|
881
|
+
v4: {
|
|
882
|
+
cssEntries: [args.css]
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
hasOverrides = true;
|
|
886
|
+
}
|
|
887
|
+
const patcher = await ctx.createPatcher(hasOverrides ? overrides : void 0);
|
|
888
|
+
const extractOptions = args.write === void 0 ? {} : { write: args.write };
|
|
889
|
+
const result = await patcher.extract(extractOptions);
|
|
890
|
+
if (result.filename) {
|
|
891
|
+
logger_default.success(`Collected ${result.classList.length} classes \u2192 ${result.filename}`);
|
|
892
|
+
} else {
|
|
893
|
+
logger_default.success(`Collected ${result.classList.length} classes.`);
|
|
894
|
+
}
|
|
895
|
+
return result;
|
|
896
|
+
}
|
|
897
|
+
async function tokensCommandDefaultHandler(ctx) {
|
|
898
|
+
const { args } = ctx;
|
|
899
|
+
const patcher = await ctx.createPatcher();
|
|
900
|
+
const report = await patcher.collectContentTokens();
|
|
901
|
+
const shouldWrite = args.write ?? true;
|
|
902
|
+
let format = args.format ?? "json";
|
|
903
|
+
if (!TOKEN_FORMATS.includes(format)) {
|
|
904
|
+
format = "json";
|
|
905
|
+
}
|
|
906
|
+
const targetFile = args.output ?? DEFAULT_TOKEN_REPORT;
|
|
907
|
+
const groupKey = args.groupKey === "absolute" ? "absolute" : "relative";
|
|
908
|
+
const buildGrouped = () => groupTokensByFile(report, {
|
|
909
|
+
key: groupKey,
|
|
910
|
+
stripAbsolutePaths: groupKey !== "absolute"
|
|
911
|
+
});
|
|
912
|
+
const grouped = format === "grouped-json" ? buildGrouped() : null;
|
|
913
|
+
const resolveGrouped = () => grouped ?? buildGrouped();
|
|
914
|
+
if (shouldWrite) {
|
|
915
|
+
const target = path2.resolve(targetFile);
|
|
916
|
+
await fs.ensureDir(path2.dirname(target));
|
|
917
|
+
if (format === "json") {
|
|
918
|
+
await fs.writeJSON(target, report, { spaces: 2 });
|
|
919
|
+
} else if (format === "grouped-json") {
|
|
920
|
+
await fs.writeJSON(target, resolveGrouped(), { spaces: 2 });
|
|
921
|
+
} else {
|
|
922
|
+
const lines = report.entries.map(formatTokenLine);
|
|
923
|
+
await fs.writeFile(target, `${lines.join("\n")}
|
|
924
|
+
`, "utf8");
|
|
925
|
+
}
|
|
926
|
+
logger_default.success(`Collected ${report.entries.length} tokens (${format}) \u2192 ${target.replace(process4.cwd(), ".")}`);
|
|
927
|
+
} else {
|
|
928
|
+
logger_default.success(`Collected ${report.entries.length} tokens from ${report.filesScanned} files.`);
|
|
929
|
+
if (format === "lines") {
|
|
930
|
+
const preview = report.entries.slice(0, 5).map(formatTokenLine).join("\n");
|
|
931
|
+
if (preview) {
|
|
932
|
+
logger_default.log("");
|
|
933
|
+
logger_default.info(preview);
|
|
934
|
+
if (report.entries.length > 5) {
|
|
935
|
+
logger_default.info(`\u2026and ${report.entries.length - 5} more.`);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
} else if (format === "grouped-json") {
|
|
939
|
+
const map = resolveGrouped();
|
|
940
|
+
const { preview, moreFiles } = formatGroupedPreview(map);
|
|
941
|
+
if (preview) {
|
|
942
|
+
logger_default.log("");
|
|
943
|
+
logger_default.info(preview);
|
|
944
|
+
if (moreFiles > 0) {
|
|
945
|
+
logger_default.info(`\u2026and ${moreFiles} more files.`);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
} else {
|
|
949
|
+
const previewEntries = report.entries.slice(0, 3);
|
|
950
|
+
if (previewEntries.length) {
|
|
951
|
+
logger_default.log("");
|
|
952
|
+
logger_default.info(JSON.stringify(previewEntries, null, 2));
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
if (report.skippedFiles.length) {
|
|
957
|
+
logger_default.warn("Skipped files:");
|
|
958
|
+
for (const skipped of report.skippedFiles) {
|
|
959
|
+
logger_default.warn(` \u2022 ${skipped.file} (${skipped.reason})`);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
return report;
|
|
963
|
+
}
|
|
964
|
+
async function initCommandDefaultHandler(ctx) {
|
|
965
|
+
const configModule = await loadWorkspaceConfigModule();
|
|
966
|
+
await configModule.initConfig(ctx.cwd);
|
|
967
|
+
const configName = configModule.CONFIG_NAME || DEFAULT_CONFIG_NAME;
|
|
968
|
+
logger_default.success(`\u2728 ${configName}.config.ts initialized!`);
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
// src/commands/migration-args.ts
|
|
972
|
+
function normalizePatternArgs(value) {
|
|
973
|
+
if (!value) {
|
|
974
|
+
return void 0;
|
|
975
|
+
}
|
|
976
|
+
const raw = Array.isArray(value) ? value : [value];
|
|
977
|
+
const values = raw.flatMap((item) => item.split(",")).map((item) => item.trim()).filter(Boolean);
|
|
978
|
+
return values.length > 0 ? values : void 0;
|
|
979
|
+
}
|
|
980
|
+
function parseMaxDepth(value) {
|
|
981
|
+
if (value === void 0) {
|
|
982
|
+
return {
|
|
983
|
+
maxDepth: void 0,
|
|
984
|
+
hasInvalidMaxDepth: false
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
const parsed = Number(value);
|
|
988
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
989
|
+
return {
|
|
990
|
+
maxDepth: void 0,
|
|
991
|
+
hasInvalidMaxDepth: true
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
return {
|
|
995
|
+
maxDepth: Math.floor(parsed),
|
|
996
|
+
hasInvalidMaxDepth: false
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
function resolveMigrateCommandArgs(args) {
|
|
1000
|
+
const include = normalizePatternArgs(args.include);
|
|
1001
|
+
const exclude = normalizePatternArgs(args.exclude);
|
|
1002
|
+
const { maxDepth, hasInvalidMaxDepth } = parseMaxDepth(args.maxDepth);
|
|
1003
|
+
const checkMode = args.check ?? false;
|
|
1004
|
+
const dryRun = args.dryRun ?? checkMode;
|
|
1005
|
+
return {
|
|
1006
|
+
include,
|
|
1007
|
+
exclude,
|
|
1008
|
+
maxDepth,
|
|
1009
|
+
checkMode,
|
|
1010
|
+
dryRun,
|
|
1011
|
+
hasInvalidMaxDepth
|
|
1012
|
+
};
|
|
1013
|
+
}
|
|
1014
|
+
function resolveRestoreCommandArgs(args) {
|
|
1015
|
+
return {
|
|
1016
|
+
reportFile: args.reportFile ?? ".tw-patch/migrate-report.json",
|
|
1017
|
+
dryRun: args.dryRun ?? false,
|
|
1018
|
+
strict: args.strict ?? false
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
function resolveValidateCommandArgs(args) {
|
|
1022
|
+
return {
|
|
1023
|
+
reportFile: args.reportFile ?? ".tw-patch/migrate-report.json",
|
|
1024
|
+
strict: args.strict ?? false
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
// src/commands/migration-output.ts
|
|
1029
|
+
import process5 from "process";
|
|
1030
|
+
import fs2 from "fs-extra";
|
|
1031
|
+
import path3 from "pathe";
|
|
1032
|
+
function formatPathForLog(file) {
|
|
1033
|
+
return file.replace(process5.cwd(), ".");
|
|
1034
|
+
}
|
|
1035
|
+
function createMigrationCheckFailureError(changedFiles) {
|
|
1036
|
+
return new Error(`Migration check failed: ${changedFiles} file(s) still need migration.`);
|
|
1037
|
+
}
|
|
1038
|
+
async function writeMigrationReportFile(cwd, reportFile, report) {
|
|
1039
|
+
const reportPath = path3.resolve(cwd, reportFile);
|
|
1040
|
+
await fs2.ensureDir(path3.dirname(reportPath));
|
|
1041
|
+
await fs2.writeJSON(reportPath, report, { spaces: 2 });
|
|
1042
|
+
logger_default.info(`Migration report written: ${formatPathForLog(reportPath)}`);
|
|
1043
|
+
}
|
|
1044
|
+
function logMigrationReportAsJson(report) {
|
|
1045
|
+
logger_default.log(JSON.stringify(report, null, 2));
|
|
1046
|
+
}
|
|
1047
|
+
function logNoMigrationConfigFilesWarning() {
|
|
1048
|
+
logger_default.warn("No config files found for migration.");
|
|
1049
|
+
}
|
|
1050
|
+
function logMigrationEntries(report, dryRun) {
|
|
1051
|
+
for (const entry of report.entries) {
|
|
1052
|
+
const fileLabel = formatPathForLog(entry.file);
|
|
1053
|
+
if (!entry.changed) {
|
|
1054
|
+
logger_default.info(`No changes: ${fileLabel}`);
|
|
1055
|
+
continue;
|
|
1056
|
+
}
|
|
1057
|
+
if (dryRun) {
|
|
1058
|
+
logger_default.info(`[dry-run] ${fileLabel}`);
|
|
1059
|
+
} else {
|
|
1060
|
+
logger_default.success(`Migrated: ${fileLabel}`);
|
|
1061
|
+
}
|
|
1062
|
+
for (const change of entry.changes) {
|
|
1063
|
+
logger_default.info(` - ${change}`);
|
|
1064
|
+
}
|
|
1065
|
+
if (entry.backupFile) {
|
|
1066
|
+
logger_default.info(` - backup: ${formatPathForLog(entry.backupFile)}`);
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
function logMigrationSummary(report) {
|
|
1071
|
+
logger_default.info(
|
|
1072
|
+
`Migration summary: scanned=${report.scannedFiles}, changed=${report.changedFiles}, written=${report.writtenFiles}, backups=${report.backupsWritten}, missing=${report.missingFiles}, unchanged=${report.unchangedFiles}`
|
|
1073
|
+
);
|
|
1074
|
+
}
|
|
1075
|
+
function logRestoreResultAsJson(result) {
|
|
1076
|
+
logger_default.log(JSON.stringify(result, null, 2));
|
|
1077
|
+
}
|
|
1078
|
+
function logRestoreSummary(result) {
|
|
1079
|
+
logger_default.info(
|
|
1080
|
+
`Restore summary: scanned=${result.scannedEntries}, restorable=${result.restorableEntries}, restored=${result.restoredFiles}, missingBackups=${result.missingBackups}, skipped=${result.skippedEntries}`
|
|
1081
|
+
);
|
|
1082
|
+
if (result.restored.length > 0) {
|
|
1083
|
+
const preview = result.restored.slice(0, 5);
|
|
1084
|
+
for (const file of preview) {
|
|
1085
|
+
logger_default.info(` - ${formatPathForLog(file)}`);
|
|
1086
|
+
}
|
|
1087
|
+
if (result.restored.length > preview.length) {
|
|
1088
|
+
logger_default.info(` ...and ${result.restored.length - preview.length} more`);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
function logValidateSuccessAsJson(result) {
|
|
1093
|
+
const payload = {
|
|
1094
|
+
ok: true,
|
|
1095
|
+
...result
|
|
1096
|
+
};
|
|
1097
|
+
logger_default.log(JSON.stringify(payload, null, 2));
|
|
1098
|
+
}
|
|
1099
|
+
function logValidateSuccessSummary(result) {
|
|
1100
|
+
logger_default.success(
|
|
1101
|
+
`Migration report validated: scanned=${result.scannedEntries}, restorable=${result.restorableEntries}, missingBackups=${result.missingBackups}, skipped=${result.skippedEntries}`
|
|
1102
|
+
);
|
|
1103
|
+
if (result.reportKind || result.reportSchemaVersion !== void 0) {
|
|
1104
|
+
const kind = result.reportKind ?? "unknown";
|
|
1105
|
+
const schema = result.reportSchemaVersion === void 0 ? "unknown" : String(result.reportSchemaVersion);
|
|
1106
|
+
logger_default.info(` metadata: kind=${kind}, schema=${schema}`);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
function logValidateFailureAsJson(summary) {
|
|
1110
|
+
const payload = {
|
|
1111
|
+
ok: false,
|
|
1112
|
+
reason: summary.reason,
|
|
1113
|
+
exitCode: summary.exitCode,
|
|
1114
|
+
message: summary.message
|
|
1115
|
+
};
|
|
1116
|
+
logger_default.log(JSON.stringify(payload, null, 2));
|
|
1117
|
+
}
|
|
1118
|
+
function logValidateFailureSummary(summary) {
|
|
1119
|
+
logger_default.error(`Validation failed [${summary.reason}] (exit ${summary.exitCode}): ${summary.message}`);
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
// src/commands/migrate-handler.ts
|
|
1123
|
+
async function migrateCommandDefaultHandler(ctx) {
|
|
1124
|
+
const { args } = ctx;
|
|
1125
|
+
const {
|
|
1126
|
+
include,
|
|
1127
|
+
exclude,
|
|
1128
|
+
maxDepth,
|
|
1129
|
+
checkMode,
|
|
1130
|
+
dryRun,
|
|
1131
|
+
hasInvalidMaxDepth
|
|
1132
|
+
} = resolveMigrateCommandArgs(args);
|
|
1133
|
+
if (args.workspace && hasInvalidMaxDepth) {
|
|
1134
|
+
logger_default.warn(`Invalid --max-depth value "${String(args.maxDepth)}", fallback to default depth.`);
|
|
1135
|
+
}
|
|
1136
|
+
const report = await migrateConfigFiles({
|
|
1137
|
+
cwd: ctx.cwd,
|
|
1138
|
+
dryRun,
|
|
1139
|
+
...args.config ? { files: [args.config] } : {},
|
|
1140
|
+
...args.workspace ? { workspace: true } : {},
|
|
1141
|
+
...args.workspace && maxDepth !== void 0 ? { maxDepth } : {},
|
|
1142
|
+
...args.backupDir ? { backupDir: args.backupDir } : {},
|
|
1143
|
+
...include ? { include } : {},
|
|
1144
|
+
...exclude ? { exclude } : {}
|
|
1145
|
+
});
|
|
1146
|
+
if (args.reportFile) {
|
|
1147
|
+
await writeMigrationReportFile(ctx.cwd, args.reportFile, report);
|
|
1148
|
+
}
|
|
1149
|
+
if (args.json) {
|
|
1150
|
+
logMigrationReportAsJson(report);
|
|
1151
|
+
if (checkMode && report.changedFiles > 0) {
|
|
1152
|
+
throw createMigrationCheckFailureError(report.changedFiles);
|
|
1153
|
+
}
|
|
1154
|
+
if (report.scannedFiles === 0) {
|
|
1155
|
+
logNoMigrationConfigFilesWarning();
|
|
1156
|
+
}
|
|
1157
|
+
return report;
|
|
1158
|
+
}
|
|
1159
|
+
if (report.scannedFiles === 0) {
|
|
1160
|
+
logNoMigrationConfigFilesWarning();
|
|
1161
|
+
return report;
|
|
1162
|
+
}
|
|
1163
|
+
logMigrationEntries(report, dryRun);
|
|
1164
|
+
logMigrationSummary(report);
|
|
1165
|
+
if (checkMode && report.changedFiles > 0) {
|
|
1166
|
+
throw createMigrationCheckFailureError(report.changedFiles);
|
|
1167
|
+
}
|
|
1168
|
+
return report;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
// src/commands/restore-handler.ts
|
|
1172
|
+
async function restoreCommandDefaultHandler(ctx) {
|
|
1173
|
+
const { args } = ctx;
|
|
1174
|
+
const restoreArgs = resolveRestoreCommandArgs(args);
|
|
1175
|
+
const result = await restoreConfigFiles({
|
|
1176
|
+
cwd: ctx.cwd,
|
|
1177
|
+
reportFile: restoreArgs.reportFile,
|
|
1178
|
+
dryRun: restoreArgs.dryRun,
|
|
1179
|
+
strict: restoreArgs.strict
|
|
1180
|
+
});
|
|
1181
|
+
if (args.json) {
|
|
1182
|
+
logRestoreResultAsJson(result);
|
|
1183
|
+
return result;
|
|
1184
|
+
}
|
|
1185
|
+
logRestoreSummary(result);
|
|
1186
|
+
return result;
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
// src/commands/status-output.ts
|
|
1190
|
+
function formatFilesHint(entry) {
|
|
1191
|
+
if (!entry.files.length) {
|
|
1192
|
+
return "";
|
|
1193
|
+
}
|
|
1194
|
+
return ` (${entry.files.join(", ")})`;
|
|
1195
|
+
}
|
|
1196
|
+
function formatPackageLabel(report) {
|
|
1197
|
+
return `${report.package.name ?? "tailwindcss"}@${report.package.version ?? "unknown"}`;
|
|
1198
|
+
}
|
|
1199
|
+
function partitionStatusEntries(report) {
|
|
1200
|
+
return {
|
|
1201
|
+
applied: report.entries.filter((entry) => entry.status === "applied"),
|
|
1202
|
+
pending: report.entries.filter((entry) => entry.status === "not-applied"),
|
|
1203
|
+
skipped: report.entries.filter((entry) => entry.status === "skipped" || entry.status === "unsupported")
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
function logStatusReportAsJson(report) {
|
|
1207
|
+
logger_default.log(JSON.stringify(report, null, 2));
|
|
1208
|
+
}
|
|
1209
|
+
function logStatusReportSummary(report) {
|
|
1210
|
+
const {
|
|
1211
|
+
applied,
|
|
1212
|
+
pending,
|
|
1213
|
+
skipped
|
|
1214
|
+
} = partitionStatusEntries(report);
|
|
1215
|
+
logger_default.info(`Patch status for ${formatPackageLabel(report)} (v${report.majorVersion})`);
|
|
1216
|
+
if (applied.length) {
|
|
1217
|
+
logger_default.success("Applied:");
|
|
1218
|
+
applied.forEach((entry) => logger_default.success(` \u2022 ${entry.name}${formatFilesHint(entry)}`));
|
|
1219
|
+
}
|
|
1220
|
+
if (pending.length) {
|
|
1221
|
+
logger_default.warn("Needs attention:");
|
|
1222
|
+
pending.forEach((entry) => {
|
|
1223
|
+
const details = entry.reason ? ` - ${entry.reason}` : "";
|
|
1224
|
+
logger_default.warn(` \u2022 ${entry.name}${formatFilesHint(entry)}${details}`);
|
|
1225
|
+
});
|
|
1226
|
+
} else {
|
|
1227
|
+
logger_default.success("All applicable patches are applied.");
|
|
1228
|
+
}
|
|
1229
|
+
if (skipped.length) {
|
|
1230
|
+
logger_default.info("Skipped:");
|
|
1231
|
+
skipped.forEach((entry) => {
|
|
1232
|
+
const details = entry.reason ? ` - ${entry.reason}` : "";
|
|
1233
|
+
logger_default.info(` \u2022 ${entry.name}${details}`);
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
// src/commands/status-handler.ts
|
|
1239
|
+
async function statusCommandDefaultHandler(ctx) {
|
|
1240
|
+
const patcher = await ctx.createPatcher();
|
|
1241
|
+
const report = await patcher.getPatchStatus();
|
|
1242
|
+
if (ctx.args.json) {
|
|
1243
|
+
logStatusReportAsJson(report);
|
|
1244
|
+
return report;
|
|
1245
|
+
}
|
|
1246
|
+
logStatusReportSummary(report);
|
|
1247
|
+
return report;
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
// src/commands/validate-handler.ts
|
|
1251
|
+
async function validateCommandDefaultHandler(ctx) {
|
|
1252
|
+
const { args } = ctx;
|
|
1253
|
+
const validateArgs = resolveValidateCommandArgs(args);
|
|
1254
|
+
try {
|
|
1255
|
+
const result = await restoreConfigFiles({
|
|
1256
|
+
cwd: ctx.cwd,
|
|
1257
|
+
reportFile: validateArgs.reportFile,
|
|
1258
|
+
dryRun: true,
|
|
1259
|
+
strict: validateArgs.strict
|
|
1260
|
+
});
|
|
1261
|
+
if (args.json) {
|
|
1262
|
+
logValidateSuccessAsJson(result);
|
|
1263
|
+
return result;
|
|
1264
|
+
}
|
|
1265
|
+
logValidateSuccessSummary(result);
|
|
1266
|
+
return result;
|
|
1267
|
+
} catch (error) {
|
|
1268
|
+
const summary = classifyValidateError(error);
|
|
1269
|
+
if (args.json) {
|
|
1270
|
+
logValidateFailureAsJson(summary);
|
|
1271
|
+
} else {
|
|
1272
|
+
logValidateFailureSummary(summary);
|
|
1273
|
+
}
|
|
1274
|
+
throw new ValidateCommandError(summary, { cause: error });
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
// src/commands/default-handler-map.ts
|
|
1279
|
+
var defaultCommandHandlers = {
|
|
1280
|
+
install: installCommandDefaultHandler,
|
|
1281
|
+
extract: extractCommandDefaultHandler,
|
|
1282
|
+
tokens: tokensCommandDefaultHandler,
|
|
1283
|
+
init: initCommandDefaultHandler,
|
|
1284
|
+
migrate: migrateCommandDefaultHandler,
|
|
1285
|
+
restore: restoreCommandDefaultHandler,
|
|
1286
|
+
validate: validateCommandDefaultHandler,
|
|
1287
|
+
status: statusCommandDefaultHandler
|
|
1288
|
+
};
|
|
1289
|
+
|
|
1290
|
+
// src/commands/command-registrar.ts
|
|
1291
|
+
function registerTailwindcssPatchCommand(cli, commandName, options, prefix, defaultDefinitions) {
|
|
1292
|
+
const metadata = resolveCommandMetadata(commandName, options, prefix, defaultDefinitions);
|
|
1293
|
+
const command = cli.command(metadata.name, metadata.description);
|
|
1294
|
+
applyCommandOptions(command, metadata.optionDefs);
|
|
1295
|
+
command.action(async (args) => {
|
|
1296
|
+
const defaultHandler = defaultCommandHandlers[commandName];
|
|
1297
|
+
return runWithCommandHandler(
|
|
1298
|
+
cli,
|
|
1299
|
+
command,
|
|
1300
|
+
commandName,
|
|
1301
|
+
args,
|
|
1302
|
+
options.commandHandlers?.[commandName],
|
|
1303
|
+
defaultHandler
|
|
1304
|
+
);
|
|
1305
|
+
});
|
|
1306
|
+
metadata.aliases.forEach((alias) => command.alias(alias));
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
// src/commands/cli.ts
|
|
1310
|
+
function mountTailwindcssPatchCommands(cli, options = {}) {
|
|
1311
|
+
const prefix = options.commandPrefix ?? "";
|
|
1312
|
+
const selectedCommands = options.commands ?? tailwindcssPatchCommands;
|
|
1313
|
+
const defaultDefinitions = buildDefaultCommandDefinitions();
|
|
1314
|
+
for (const name of selectedCommands) {
|
|
1315
|
+
registerTailwindcssPatchCommand(cli, name, options, prefix, defaultDefinitions);
|
|
1316
|
+
}
|
|
1317
|
+
return cli;
|
|
1318
|
+
}
|
|
1319
|
+
function createTailwindcssPatchCli(options = {}) {
|
|
1320
|
+
const cli = cac(options.name ?? "tw-patch");
|
|
1321
|
+
mountTailwindcssPatchCommands(cli, options.mountOptions);
|
|
1322
|
+
return cli;
|
|
1323
|
+
}
|
|
1324
|
+
export {
|
|
1325
|
+
VALIDATE_EXIT_CODES,
|
|
1326
|
+
VALIDATE_FAILURE_REASONS,
|
|
1327
|
+
ValidateCommandError,
|
|
1328
|
+
createTailwindcssPatchCli,
|
|
1329
|
+
mountTailwindcssPatchCommands,
|
|
1330
|
+
tailwindcssPatchCommands
|
|
1331
|
+
};
|