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