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