tailwindcss-patch 9.0.0-alpha.1 → 9.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/dist/{chunk-Z6OMJZTU.js → chunk-77GHKSKG.js} +59 -732
- package/dist/{chunk-SWLOK2S6.mjs → chunk-D6ICWMM4.mjs} +63 -736
- package/dist/chunk-PMN7HS4Y.js +25 -0
- package/dist/chunk-YYBY7EM5.mjs +21 -0
- package/dist/cli.js +7 -5
- package/dist/cli.mjs +5 -3
- package/dist/commands/cli-runtime.d.mts +13 -0
- package/dist/commands/cli-runtime.d.ts +13 -0
- package/dist/commands/cli-runtime.js +1331 -0
- package/dist/commands/cli-runtime.mjs +1331 -0
- package/dist/index.d.mts +17 -677
- package/dist/index.d.ts +17 -677
- 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 +11 -3
- package/src/api/tailwindcss-patcher.ts +424 -0
- package/src/babel/index.ts +12 -0
- package/src/cache/context.ts +212 -0
- package/src/cache/store.ts +1440 -0
- package/src/cache/types.ts +71 -0
- package/src/cli.bundle.ts +20 -0
- package/src/cli.ts +20 -0
- package/src/commands/basic-handlers.ts +145 -0
- package/src/commands/cli.ts +56 -0
- package/src/commands/command-context.ts +77 -0
- package/src/commands/command-definitions.ts +102 -0
- package/src/commands/command-metadata.ts +68 -0
- package/src/commands/command-registrar.ts +39 -0
- package/src/commands/command-runtime.ts +33 -0
- package/src/commands/default-handler-map.ts +25 -0
- package/src/commands/migrate-config.ts +104 -0
- package/src/commands/migrate-handler.ts +67 -0
- package/src/commands/migration-aggregation.ts +100 -0
- package/src/commands/migration-args.ts +85 -0
- package/src/commands/migration-file-executor.ts +189 -0
- package/src/commands/migration-output.ts +115 -0
- package/src/commands/migration-report-loader.ts +26 -0
- package/src/commands/migration-report.ts +21 -0
- package/src/commands/migration-source.ts +318 -0
- package/src/commands/migration-target-files.ts +161 -0
- package/src/commands/migration-target-resolver.ts +34 -0
- package/src/commands/migration-types.ts +65 -0
- package/src/commands/restore-handler.ts +24 -0
- package/src/commands/status-handler.ts +17 -0
- package/src/commands/status-output.ts +60 -0
- package/src/commands/token-output.ts +30 -0
- package/src/commands/types.ts +137 -0
- package/src/commands/validate-handler.ts +42 -0
- package/src/commands/validate.ts +83 -0
- package/src/config/index.ts +25 -0
- package/src/config/workspace.ts +87 -0
- package/src/constants.ts +4 -0
- package/src/extraction/candidate-extractor.ts +354 -0
- package/src/index.bundle.ts +105 -0
- package/src/index.ts +57 -0
- package/src/install/class-collector.ts +1 -0
- package/src/install/context-registry.ts +1 -0
- package/src/install/index.ts +5 -0
- package/src/install/patch-runner.ts +1 -0
- package/src/install/process-tailwindcss.ts +1 -0
- package/src/install/status.ts +1 -0
- package/src/logger.ts +5 -0
- package/src/options/legacy.ts +93 -0
- package/src/options/normalize.ts +262 -0
- package/src/options/types.ts +217 -0
- package/src/patching/operations/export-context/index.ts +110 -0
- package/src/patching/operations/export-context/postcss-v2.ts +235 -0
- package/src/patching/operations/export-context/postcss-v3.ts +249 -0
- package/src/patching/operations/extend-length-units.ts +197 -0
- package/src/patching/patch-runner.ts +46 -0
- package/src/patching/status.ts +262 -0
- package/src/runtime/class-collector.ts +105 -0
- package/src/runtime/collector.ts +148 -0
- package/src/runtime/context-registry.ts +65 -0
- package/src/runtime/process-tailwindcss.ts +115 -0
- package/src/types.ts +159 -0
- package/src/utils.ts +52 -0
|
@@ -20,10 +20,13 @@ import path from "pathe";
|
|
|
20
20
|
// package.json
|
|
21
21
|
var package_default = {
|
|
22
22
|
name: "tailwindcss-patch",
|
|
23
|
-
version: "9.0.0-alpha.
|
|
23
|
+
version: "9.0.0-alpha.3",
|
|
24
24
|
description: "patch tailwindcss for exposing context and extract classes",
|
|
25
25
|
author: "ice breaker <1324318532@qq.com>",
|
|
26
26
|
license: "MIT",
|
|
27
|
+
engines: {
|
|
28
|
+
node: ">=18.0.0"
|
|
29
|
+
},
|
|
27
30
|
homepage: "https://mangle.icebreaker.top/",
|
|
28
31
|
repository: {
|
|
29
32
|
type: "git",
|
|
@@ -59,18 +62,23 @@ var package_default = {
|
|
|
59
62
|
files: [
|
|
60
63
|
"bin",
|
|
61
64
|
"dist",
|
|
62
|
-
"schema"
|
|
65
|
+
"schema",
|
|
66
|
+
"src"
|
|
63
67
|
],
|
|
64
68
|
scripts: {
|
|
65
69
|
dev: "tsup --watch --sourcemap",
|
|
66
70
|
build: "tsup",
|
|
67
71
|
test: "vitest run",
|
|
72
|
+
"test:types": "pnpm build && tsd --typings dist/index.d.mts --files test-d/**/*.test-d.ts",
|
|
68
73
|
"test:dev": "vitest",
|
|
69
74
|
"bench:cold-start": "node --import tsx bench/cold-start.ts",
|
|
70
75
|
patch: "tsx dev/bin.ts install",
|
|
71
76
|
r0: "tsx dev/bin.ts extract",
|
|
72
77
|
r1: "tsx dev/bin.ts extract --css index.css"
|
|
73
78
|
},
|
|
79
|
+
tsd: {
|
|
80
|
+
directory: "test-d"
|
|
81
|
+
},
|
|
74
82
|
publishConfig: {
|
|
75
83
|
access: "public",
|
|
76
84
|
registry: "https://registry.npmjs.org/",
|
|
@@ -2099,14 +2107,12 @@ function groupTokensByFile(report, options) {
|
|
|
2099
2107
|
const stripAbsolute = options?.stripAbsolutePaths ?? key !== "absolute";
|
|
2100
2108
|
return report.entries.reduce((acc, entry) => {
|
|
2101
2109
|
const bucketKey = key === "absolute" ? entry.file : entry.relativeFile;
|
|
2102
|
-
|
|
2103
|
-
acc[bucketKey] = [];
|
|
2104
|
-
}
|
|
2110
|
+
const bucket = acc[bucketKey] ?? (acc[bucketKey] = []);
|
|
2105
2111
|
const value = stripAbsolute ? {
|
|
2106
2112
|
...entry,
|
|
2107
2113
|
file: entry.relativeFile
|
|
2108
2114
|
} : entry;
|
|
2109
|
-
|
|
2115
|
+
bucket.push(value);
|
|
2110
2116
|
return acc;
|
|
2111
2117
|
}, {});
|
|
2112
2118
|
}
|
|
@@ -2121,18 +2127,22 @@ function isObject(val) {
|
|
|
2121
2127
|
return val !== null && typeof val === "object" && Array.isArray(val) === false;
|
|
2122
2128
|
}
|
|
2123
2129
|
function spliceChangesIntoString(str, changes) {
|
|
2124
|
-
|
|
2130
|
+
const firstChange = changes[0];
|
|
2131
|
+
if (!firstChange) {
|
|
2125
2132
|
return str;
|
|
2126
2133
|
}
|
|
2127
2134
|
changes.sort((a, b) => {
|
|
2128
2135
|
return a.end - b.end || a.start - b.start;
|
|
2129
2136
|
});
|
|
2130
2137
|
let result = "";
|
|
2131
|
-
let previous =
|
|
2138
|
+
let previous = firstChange;
|
|
2132
2139
|
result += str.slice(0, previous.start);
|
|
2133
2140
|
result += previous.replacement;
|
|
2134
2141
|
for (let i = 1; i < changes.length; ++i) {
|
|
2135
2142
|
const change = changes[i];
|
|
2143
|
+
if (!change) {
|
|
2144
|
+
continue;
|
|
2145
|
+
}
|
|
2136
2146
|
result += str.slice(previous.end, change.start);
|
|
2137
2147
|
result += change.replacement;
|
|
2138
2148
|
previous = change;
|
|
@@ -2398,8 +2408,8 @@ function transformProcessTailwindFeaturesReturnContextV2(content) {
|
|
|
2398
2408
|
});
|
|
2399
2409
|
let hasPatched = false;
|
|
2400
2410
|
traverse(ast, {
|
|
2401
|
-
FunctionDeclaration(
|
|
2402
|
-
const node =
|
|
2411
|
+
FunctionDeclaration(path15) {
|
|
2412
|
+
const node = path15.node;
|
|
2403
2413
|
if (node.id?.name !== "processTailwindFeatures" || node.body.body.length !== 1 || !t.isReturnStatement(node.body.body[0])) {
|
|
2404
2414
|
return;
|
|
2405
2415
|
}
|
|
@@ -2430,8 +2440,8 @@ function transformPostcssPluginV2(content, options) {
|
|
|
2430
2440
|
const ast = parse(content);
|
|
2431
2441
|
let hasPatched = false;
|
|
2432
2442
|
traverse(ast, {
|
|
2433
|
-
Program(
|
|
2434
|
-
const program =
|
|
2443
|
+
Program(path15) {
|
|
2444
|
+
const program = path15.node;
|
|
2435
2445
|
const index = program.body.findIndex((statement) => {
|
|
2436
2446
|
return t.isFunctionDeclaration(statement) && statement.id?.name === "_default";
|
|
2437
2447
|
});
|
|
@@ -2441,7 +2451,12 @@ function transformPostcssPluginV2(content, options) {
|
|
|
2441
2451
|
const previous = program.body[index - 1];
|
|
2442
2452
|
const beforePrevious = program.body[index - 2];
|
|
2443
2453
|
const alreadyHasVariable = Boolean(
|
|
2444
|
-
previous && t.isVariableDeclaration(previous) && previous.declarations.length === 1 &&
|
|
2454
|
+
previous && t.isVariableDeclaration(previous) && previous.declarations.length === 1 && (() => {
|
|
2455
|
+
const declaration = previous.declarations[0];
|
|
2456
|
+
return Boolean(
|
|
2457
|
+
declaration && t.isIdentifier(declaration.id) && declaration.id.name === refIdentifier.name
|
|
2458
|
+
);
|
|
2459
|
+
})()
|
|
2445
2460
|
);
|
|
2446
2461
|
const alreadyAssignsExports = Boolean(
|
|
2447
2462
|
beforePrevious && t.isExpressionStatement(beforePrevious) && t.isAssignmentExpression(beforePrevious.expression) && t.isMemberExpression(beforePrevious.expression.left) && t.isIdentifier(beforePrevious.expression.right) && beforePrevious.expression.right.name === refIdentifier.name && generate(beforePrevious.expression.left).code === generate(exportMember).code
|
|
@@ -2465,11 +2480,11 @@ function transformPostcssPluginV2(content, options) {
|
|
|
2465
2480
|
);
|
|
2466
2481
|
}
|
|
2467
2482
|
},
|
|
2468
|
-
FunctionDeclaration(
|
|
2483
|
+
FunctionDeclaration(path15) {
|
|
2469
2484
|
if (hasPatched) {
|
|
2470
2485
|
return;
|
|
2471
2486
|
}
|
|
2472
|
-
const fn =
|
|
2487
|
+
const fn = path15.node;
|
|
2473
2488
|
if (fn.id?.name !== "_default") {
|
|
2474
2489
|
return;
|
|
2475
2490
|
}
|
|
@@ -2558,8 +2573,8 @@ function transformProcessTailwindFeaturesReturnContext(content) {
|
|
|
2558
2573
|
const ast = parse(content);
|
|
2559
2574
|
let hasPatched = false;
|
|
2560
2575
|
traverse(ast, {
|
|
2561
|
-
FunctionDeclaration(
|
|
2562
|
-
const node =
|
|
2576
|
+
FunctionDeclaration(path15) {
|
|
2577
|
+
const node = path15.node;
|
|
2563
2578
|
if (node.id?.name !== "processTailwindFeatures" || node.body.body.length !== 1) {
|
|
2564
2579
|
return;
|
|
2565
2580
|
}
|
|
@@ -2591,8 +2606,8 @@ function transformPostcssPlugin(content, { refProperty }) {
|
|
|
2591
2606
|
const valueMember = t2.memberExpression(refIdentifier, t2.identifier("value"));
|
|
2592
2607
|
let hasPatched = false;
|
|
2593
2608
|
traverse(ast, {
|
|
2594
|
-
Program(
|
|
2595
|
-
const program =
|
|
2609
|
+
Program(path15) {
|
|
2610
|
+
const program = path15.node;
|
|
2596
2611
|
const index = program.body.findIndex((statement) => {
|
|
2597
2612
|
return t2.isExpressionStatement(statement) && t2.isAssignmentExpression(statement.expression) && t2.isMemberExpression(statement.expression.left) && t2.isFunctionExpression(statement.expression.right) && statement.expression.right.id?.name === "tailwindcss";
|
|
2598
2613
|
});
|
|
@@ -2602,7 +2617,12 @@ function transformPostcssPlugin(content, { refProperty }) {
|
|
|
2602
2617
|
const previousStatement = program.body[index - 1];
|
|
2603
2618
|
const lastStatement = program.body[program.body.length - 1];
|
|
2604
2619
|
const alreadyHasVariable = Boolean(
|
|
2605
|
-
previousStatement && t2.isVariableDeclaration(previousStatement) && previousStatement.declarations.length === 1 &&
|
|
2620
|
+
previousStatement && t2.isVariableDeclaration(previousStatement) && previousStatement.declarations.length === 1 && (() => {
|
|
2621
|
+
const declaration = previousStatement.declarations[0];
|
|
2622
|
+
return Boolean(
|
|
2623
|
+
declaration && t2.isIdentifier(declaration.id) && declaration.id.name === refIdentifier.name
|
|
2624
|
+
);
|
|
2625
|
+
})()
|
|
2606
2626
|
);
|
|
2607
2627
|
const alreadyAssignsModuleExports = Boolean(
|
|
2608
2628
|
t2.isExpressionStatement(lastStatement) && t2.isAssignmentExpression(lastStatement.expression) && t2.isMemberExpression(lastStatement.expression.left) && t2.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === refIdentifier.name && generate(lastStatement.expression.left).code === generate(moduleExportsMember).code
|
|
@@ -2630,11 +2650,11 @@ function transformPostcssPlugin(content, { refProperty }) {
|
|
|
2630
2650
|
);
|
|
2631
2651
|
}
|
|
2632
2652
|
},
|
|
2633
|
-
FunctionExpression(
|
|
2653
|
+
FunctionExpression(path15) {
|
|
2634
2654
|
if (hasPatched) {
|
|
2635
2655
|
return;
|
|
2636
2656
|
}
|
|
2637
|
-
const fn =
|
|
2657
|
+
const fn = path15.node;
|
|
2638
2658
|
if (fn.id?.name !== "tailwindcss" || fn.body.body.length !== 1) {
|
|
2639
2659
|
return;
|
|
2640
2660
|
}
|
|
@@ -2713,21 +2733,21 @@ function updateLengthUnitsArray(content, options) {
|
|
|
2713
2733
|
let arrayRef;
|
|
2714
2734
|
let changed = false;
|
|
2715
2735
|
traverse(ast, {
|
|
2716
|
-
Identifier(
|
|
2717
|
-
if (
|
|
2718
|
-
arrayRef =
|
|
2736
|
+
Identifier(path15) {
|
|
2737
|
+
if (path15.node.name === variableName && t3.isVariableDeclarator(path15.parent) && t3.isArrayExpression(path15.parent.init)) {
|
|
2738
|
+
arrayRef = path15.parent.init;
|
|
2719
2739
|
const existing = new Set(
|
|
2720
|
-
|
|
2740
|
+
path15.parent.init.elements.map((element) => t3.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
|
|
2721
2741
|
);
|
|
2722
2742
|
for (const unit of units) {
|
|
2723
2743
|
if (!existing.has(unit)) {
|
|
2724
|
-
|
|
2744
|
+
path15.parent.init.elements = path15.parent.init.elements.map((element) => {
|
|
2725
2745
|
if (t3.isStringLiteral(element)) {
|
|
2726
2746
|
return t3.stringLiteral(element.value);
|
|
2727
2747
|
}
|
|
2728
2748
|
return element;
|
|
2729
2749
|
});
|
|
2730
|
-
|
|
2750
|
+
path15.parent.init.elements.push(t3.stringLiteral(unit));
|
|
2731
2751
|
changed = true;
|
|
2732
2752
|
}
|
|
2733
2753
|
}
|
|
@@ -2808,13 +2828,13 @@ function applyExtendLengthUnitsPatchV4(rootDir, options) {
|
|
|
2808
2828
|
const { code, file, match } = item;
|
|
2809
2829
|
const ast = parse(match[0], { sourceType: "unambiguous" });
|
|
2810
2830
|
traverse(ast, {
|
|
2811
|
-
ArrayExpression(
|
|
2831
|
+
ArrayExpression(path15) {
|
|
2812
2832
|
for (const unit of opts.units) {
|
|
2813
|
-
if (
|
|
2833
|
+
if (path15.node.elements.some((element) => t3.isStringLiteral(element) && element.value === unit)) {
|
|
2814
2834
|
item.hasPatched = true;
|
|
2815
2835
|
return;
|
|
2816
2836
|
}
|
|
2817
|
-
|
|
2837
|
+
path15.node.elements.push(t3.stringLiteral(unit));
|
|
2818
2838
|
}
|
|
2819
2839
|
}
|
|
2820
2840
|
});
|
|
@@ -2850,14 +2870,14 @@ function inspectLengthUnitsArray(content, variableName, units) {
|
|
|
2850
2870
|
let found = false;
|
|
2851
2871
|
let missingUnits = [];
|
|
2852
2872
|
traverse(ast, {
|
|
2853
|
-
Identifier(
|
|
2854
|
-
if (
|
|
2873
|
+
Identifier(path15) {
|
|
2874
|
+
if (path15.node.name === variableName && t4.isVariableDeclarator(path15.parent) && t4.isArrayExpression(path15.parent.init)) {
|
|
2855
2875
|
found = true;
|
|
2856
2876
|
const existing = new Set(
|
|
2857
|
-
|
|
2877
|
+
path15.parent.init.elements.map((element) => t4.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
|
|
2858
2878
|
);
|
|
2859
2879
|
missingUnits = units.filter((unit) => !existing.has(unit));
|
|
2860
|
-
|
|
2880
|
+
path15.stop();
|
|
2861
2881
|
}
|
|
2862
2882
|
}
|
|
2863
2883
|
});
|
|
@@ -4261,6 +4281,9 @@ async function restoreConfigFiles(options) {
|
|
|
4261
4281
|
};
|
|
4262
4282
|
}
|
|
4263
4283
|
|
|
4284
|
+
// src/commands/types.ts
|
|
4285
|
+
var tailwindcssPatchCommands = ["install", "extract", "tokens", "init", "migrate", "restore", "validate", "status"];
|
|
4286
|
+
|
|
4264
4287
|
// src/commands/validate.ts
|
|
4265
4288
|
var VALIDATE_EXIT_CODES = {
|
|
4266
4289
|
OK: 0,
|
|
@@ -4319,707 +4342,12 @@ var ValidateCommandError = class extends Error {
|
|
|
4319
4342
|
}
|
|
4320
4343
|
};
|
|
4321
4344
|
|
|
4322
|
-
// src/commands/types.ts
|
|
4323
|
-
var tailwindcssPatchCommands = ["install", "extract", "tokens", "init", "migrate", "restore", "validate", "status"];
|
|
4324
|
-
|
|
4325
|
-
// src/commands/cli.ts
|
|
4326
|
-
import cac from "cac";
|
|
4327
|
-
|
|
4328
|
-
// src/commands/command-definitions.ts
|
|
4329
|
-
import process7 from "process";
|
|
4330
|
-
|
|
4331
|
-
// src/commands/token-output.ts
|
|
4332
|
-
var TOKEN_FORMATS = ["json", "lines", "grouped-json"];
|
|
4333
|
-
var DEFAULT_TOKEN_REPORT = ".tw-patch/tw-token-report.json";
|
|
4334
|
-
function formatTokenLine(entry) {
|
|
4335
|
-
return `${entry.relativeFile}:${entry.line}:${entry.column} ${entry.rawCandidate} (${entry.start}-${entry.end})`;
|
|
4336
|
-
}
|
|
4337
|
-
function formatGroupedPreview(map, limit = 3) {
|
|
4338
|
-
const files = Object.keys(map);
|
|
4339
|
-
if (!files.length) {
|
|
4340
|
-
return { preview: "", moreFiles: 0 };
|
|
4341
|
-
}
|
|
4342
|
-
const lines = files.slice(0, limit).map((file) => {
|
|
4343
|
-
const tokens = map[file] ?? [];
|
|
4344
|
-
const sample = tokens.slice(0, 3).map((token) => token.rawCandidate).join(", ");
|
|
4345
|
-
const suffix = tokens.length > 3 ? ", \u2026" : "";
|
|
4346
|
-
return `${file}: ${tokens.length} tokens (${sample}${suffix})`;
|
|
4347
|
-
});
|
|
4348
|
-
return {
|
|
4349
|
-
preview: lines.join("\n"),
|
|
4350
|
-
moreFiles: Math.max(0, files.length - limit)
|
|
4351
|
-
};
|
|
4352
|
-
}
|
|
4353
|
-
|
|
4354
|
-
// src/commands/command-definitions.ts
|
|
4355
|
-
function createCwdOptionDefinition(description = "Working directory") {
|
|
4356
|
-
return {
|
|
4357
|
-
flags: "--cwd <dir>",
|
|
4358
|
-
description,
|
|
4359
|
-
config: { default: process7.cwd() }
|
|
4360
|
-
};
|
|
4361
|
-
}
|
|
4362
|
-
function buildDefaultCommandDefinitions() {
|
|
4363
|
-
return {
|
|
4364
|
-
install: {
|
|
4365
|
-
description: "Apply Tailwind CSS runtime patches",
|
|
4366
|
-
optionDefs: [createCwdOptionDefinition()]
|
|
4367
|
-
},
|
|
4368
|
-
extract: {
|
|
4369
|
-
description: "Collect generated class names into a cache file",
|
|
4370
|
-
optionDefs: [
|
|
4371
|
-
createCwdOptionDefinition(),
|
|
4372
|
-
{ flags: "--output <file>", description: "Override output file path" },
|
|
4373
|
-
{ flags: "--format <format>", description: "Output format (json|lines)" },
|
|
4374
|
-
{ flags: "--css <file>", description: "Tailwind CSS entry CSS when using v4" },
|
|
4375
|
-
{ flags: "--no-write", description: "Skip writing to disk" }
|
|
4376
|
-
]
|
|
4377
|
-
},
|
|
4378
|
-
tokens: {
|
|
4379
|
-
description: "Extract Tailwind tokens with file/position metadata",
|
|
4380
|
-
optionDefs: [
|
|
4381
|
-
createCwdOptionDefinition(),
|
|
4382
|
-
{ flags: "--output <file>", description: "Override output file path", config: { default: DEFAULT_TOKEN_REPORT } },
|
|
4383
|
-
{
|
|
4384
|
-
flags: "--format <format>",
|
|
4385
|
-
description: "Output format (json|lines|grouped-json)",
|
|
4386
|
-
config: { default: "json" }
|
|
4387
|
-
},
|
|
4388
|
-
{
|
|
4389
|
-
flags: "--group-key <key>",
|
|
4390
|
-
description: "Grouping key for grouped-json output (relative|absolute)",
|
|
4391
|
-
config: { default: "relative" }
|
|
4392
|
-
},
|
|
4393
|
-
{ flags: "--no-write", description: "Skip writing to disk" }
|
|
4394
|
-
]
|
|
4395
|
-
},
|
|
4396
|
-
init: {
|
|
4397
|
-
description: "Generate a tailwindcss-patch config file",
|
|
4398
|
-
optionDefs: [createCwdOptionDefinition()]
|
|
4399
|
-
},
|
|
4400
|
-
migrate: {
|
|
4401
|
-
description: "Migrate deprecated config fields to modern options",
|
|
4402
|
-
optionDefs: [
|
|
4403
|
-
createCwdOptionDefinition(),
|
|
4404
|
-
{ flags: "--config <file>", description: "Migrate a specific config file path" },
|
|
4405
|
-
{ flags: "--workspace", description: "Scan workspace recursively for config files" },
|
|
4406
|
-
{ flags: "--max-depth <n>", description: "Maximum recursion depth for --workspace", config: { default: 6 } },
|
|
4407
|
-
{ flags: "--include <glob>", description: "Only migrate files that match this glob (repeatable)" },
|
|
4408
|
-
{ flags: "--exclude <glob>", description: "Skip files that match this glob (repeatable)" },
|
|
4409
|
-
{ flags: "--report-file <file>", description: "Write migration report JSON to a file" },
|
|
4410
|
-
{ flags: "--backup-dir <dir>", description: "Write pre-migration backups into this directory" },
|
|
4411
|
-
{ flags: "--check", description: "Exit with an error when migration changes are required" },
|
|
4412
|
-
{ flags: "--json", description: "Print the migration report as JSON" },
|
|
4413
|
-
{ flags: "--dry-run", description: "Preview changes without writing files" }
|
|
4414
|
-
]
|
|
4415
|
-
},
|
|
4416
|
-
restore: {
|
|
4417
|
-
description: "Restore config files from a previous migration report backup snapshot",
|
|
4418
|
-
optionDefs: [
|
|
4419
|
-
createCwdOptionDefinition(),
|
|
4420
|
-
{ flags: "--report-file <file>", description: "Migration report file generated by migrate" },
|
|
4421
|
-
{ flags: "--dry-run", description: "Preview restore targets without writing files" },
|
|
4422
|
-
{ flags: "--strict", description: "Fail when any backup file is missing" },
|
|
4423
|
-
{ flags: "--json", description: "Print the restore result as JSON" }
|
|
4424
|
-
]
|
|
4425
|
-
},
|
|
4426
|
-
validate: {
|
|
4427
|
-
description: "Validate migration report compatibility without modifying files",
|
|
4428
|
-
optionDefs: [
|
|
4429
|
-
createCwdOptionDefinition(),
|
|
4430
|
-
{ flags: "--report-file <file>", description: "Migration report file to validate" },
|
|
4431
|
-
{ flags: "--strict", description: "Fail when any backup file is missing" },
|
|
4432
|
-
{ flags: "--json", description: "Print validation result as JSON" }
|
|
4433
|
-
]
|
|
4434
|
-
},
|
|
4435
|
-
status: {
|
|
4436
|
-
description: "Check which Tailwind patches are applied",
|
|
4437
|
-
optionDefs: [
|
|
4438
|
-
createCwdOptionDefinition(),
|
|
4439
|
-
{ flags: "--json", description: "Print a JSON report of patch status" }
|
|
4440
|
-
]
|
|
4441
|
-
}
|
|
4442
|
-
};
|
|
4443
|
-
}
|
|
4444
|
-
|
|
4445
|
-
// src/commands/command-metadata.ts
|
|
4446
|
-
function addPrefixIfMissing(value, prefix) {
|
|
4447
|
-
if (!prefix || value.startsWith(prefix)) {
|
|
4448
|
-
return value;
|
|
4449
|
-
}
|
|
4450
|
-
return `${prefix}${value}`;
|
|
4451
|
-
}
|
|
4452
|
-
function resolveCommandNames(command, mountOptions, prefix) {
|
|
4453
|
-
const override = mountOptions.commandOptions?.[command];
|
|
4454
|
-
const baseName = override?.name ?? command;
|
|
4455
|
-
const name = addPrefixIfMissing(baseName, prefix);
|
|
4456
|
-
const aliases = (override?.aliases ?? []).map((alias) => addPrefixIfMissing(alias, prefix));
|
|
4457
|
-
return { name, aliases };
|
|
4458
|
-
}
|
|
4459
|
-
function resolveOptionDefinitions(defaults, override) {
|
|
4460
|
-
if (!override) {
|
|
4461
|
-
return defaults;
|
|
4462
|
-
}
|
|
4463
|
-
const appendDefaults = override.appendDefaultOptions ?? true;
|
|
4464
|
-
const customDefs = override.optionDefs ?? [];
|
|
4465
|
-
if (!appendDefaults) {
|
|
4466
|
-
return customDefs;
|
|
4467
|
-
}
|
|
4468
|
-
if (customDefs.length === 0) {
|
|
4469
|
-
return defaults;
|
|
4470
|
-
}
|
|
4471
|
-
return [...defaults, ...customDefs];
|
|
4472
|
-
}
|
|
4473
|
-
function resolveCommandMetadata(command, mountOptions, prefix, defaults) {
|
|
4474
|
-
const names = resolveCommandNames(command, mountOptions, prefix);
|
|
4475
|
-
const definition = defaults[command];
|
|
4476
|
-
const override = mountOptions.commandOptions?.[command];
|
|
4477
|
-
const description = override?.description ?? definition.description;
|
|
4478
|
-
const optionDefs = resolveOptionDefinitions(definition.optionDefs, override);
|
|
4479
|
-
return { ...names, description, optionDefs };
|
|
4480
|
-
}
|
|
4481
|
-
function applyCommandOptions(command, optionDefs) {
|
|
4482
|
-
for (const option of optionDefs) {
|
|
4483
|
-
command.option(option.flags, option.description ?? "", option.config);
|
|
4484
|
-
}
|
|
4485
|
-
}
|
|
4486
|
-
|
|
4487
|
-
// src/commands/command-context.ts
|
|
4488
|
-
import process8 from "process";
|
|
4489
|
-
import path15 from "pathe";
|
|
4490
|
-
function resolveCommandCwd(rawCwd) {
|
|
4491
|
-
if (!rawCwd) {
|
|
4492
|
-
return process8.cwd();
|
|
4493
|
-
}
|
|
4494
|
-
return path15.resolve(rawCwd);
|
|
4495
|
-
}
|
|
4496
|
-
function createMemoizedPromiseRunner(factory) {
|
|
4497
|
-
let promise;
|
|
4498
|
-
return () => {
|
|
4499
|
-
if (!promise) {
|
|
4500
|
-
promise = factory();
|
|
4501
|
-
}
|
|
4502
|
-
return promise;
|
|
4503
|
-
};
|
|
4504
|
-
}
|
|
4505
|
-
function createTailwindcssPatchCommandContext(cli, command, commandName, args, cwd) {
|
|
4506
|
-
const loadCachedConfig = createMemoizedPromiseRunner(
|
|
4507
|
-
() => loadWorkspaceConfigModule().then((mod) => mod.getConfig(cwd))
|
|
4508
|
-
);
|
|
4509
|
-
const loadCachedPatchOptions = createMemoizedPromiseRunner(
|
|
4510
|
-
() => loadPatchOptionsForWorkspace(cwd)
|
|
4511
|
-
);
|
|
4512
|
-
const createCachedPatcher = createMemoizedPromiseRunner(async () => {
|
|
4513
|
-
const patchOptions = await loadCachedPatchOptions();
|
|
4514
|
-
return new TailwindcssPatcher(patchOptions);
|
|
4515
|
-
});
|
|
4516
|
-
const loadPatchOptionsForContext = (overrides) => {
|
|
4517
|
-
if (overrides) {
|
|
4518
|
-
return loadPatchOptionsForWorkspace(cwd, overrides);
|
|
4519
|
-
}
|
|
4520
|
-
return loadCachedPatchOptions();
|
|
4521
|
-
};
|
|
4522
|
-
const createPatcherForContext = async (overrides) => {
|
|
4523
|
-
if (overrides) {
|
|
4524
|
-
const patchOptions = await loadPatchOptionsForWorkspace(cwd, overrides);
|
|
4525
|
-
return new TailwindcssPatcher(patchOptions);
|
|
4526
|
-
}
|
|
4527
|
-
return createCachedPatcher();
|
|
4528
|
-
};
|
|
4529
|
-
return {
|
|
4530
|
-
cli,
|
|
4531
|
-
command,
|
|
4532
|
-
commandName,
|
|
4533
|
-
args,
|
|
4534
|
-
cwd,
|
|
4535
|
-
logger: logger_default,
|
|
4536
|
-
loadConfig: loadCachedConfig,
|
|
4537
|
-
loadPatchOptions: loadPatchOptionsForContext,
|
|
4538
|
-
createPatcher: createPatcherForContext
|
|
4539
|
-
};
|
|
4540
|
-
}
|
|
4541
|
-
|
|
4542
|
-
// src/commands/command-runtime.ts
|
|
4543
|
-
function runWithCommandHandler(cli, command, commandName, args, handler, defaultHandler) {
|
|
4544
|
-
const cwd = resolveCommandCwd(args.cwd);
|
|
4545
|
-
const context = createTailwindcssPatchCommandContext(cli, command, commandName, args, cwd);
|
|
4546
|
-
const runDefault = createMemoizedPromiseRunner(() => defaultHandler(context));
|
|
4547
|
-
if (!handler) {
|
|
4548
|
-
return runDefault();
|
|
4549
|
-
}
|
|
4550
|
-
return handler(context, runDefault);
|
|
4551
|
-
}
|
|
4552
|
-
|
|
4553
|
-
// src/commands/basic-handlers.ts
|
|
4554
|
-
import process9 from "process";
|
|
4555
|
-
import fs15 from "fs-extra";
|
|
4556
|
-
import path16 from "pathe";
|
|
4557
|
-
var DEFAULT_CONFIG_NAME = "tailwindcss-mangle";
|
|
4558
|
-
async function installCommandDefaultHandler(_ctx) {
|
|
4559
|
-
const patcher = await _ctx.createPatcher();
|
|
4560
|
-
await patcher.patch();
|
|
4561
|
-
logger_default.success("Tailwind CSS runtime patched successfully.");
|
|
4562
|
-
}
|
|
4563
|
-
async function extractCommandDefaultHandler(ctx) {
|
|
4564
|
-
const { args } = ctx;
|
|
4565
|
-
const overrides = {};
|
|
4566
|
-
let hasOverrides = false;
|
|
4567
|
-
if (args.output || args.format) {
|
|
4568
|
-
overrides.extract = {
|
|
4569
|
-
...args.output === void 0 ? {} : { file: args.output },
|
|
4570
|
-
...args.format === void 0 ? {} : { format: args.format }
|
|
4571
|
-
};
|
|
4572
|
-
hasOverrides = true;
|
|
4573
|
-
}
|
|
4574
|
-
if (args.css) {
|
|
4575
|
-
overrides.tailwindcss = {
|
|
4576
|
-
v4: {
|
|
4577
|
-
cssEntries: [args.css]
|
|
4578
|
-
}
|
|
4579
|
-
};
|
|
4580
|
-
hasOverrides = true;
|
|
4581
|
-
}
|
|
4582
|
-
const patcher = await ctx.createPatcher(hasOverrides ? overrides : void 0);
|
|
4583
|
-
const extractOptions = args.write === void 0 ? {} : { write: args.write };
|
|
4584
|
-
const result = await patcher.extract(extractOptions);
|
|
4585
|
-
if (result.filename) {
|
|
4586
|
-
logger_default.success(`Collected ${result.classList.length} classes \u2192 ${result.filename}`);
|
|
4587
|
-
} else {
|
|
4588
|
-
logger_default.success(`Collected ${result.classList.length} classes.`);
|
|
4589
|
-
}
|
|
4590
|
-
return result;
|
|
4591
|
-
}
|
|
4592
|
-
async function tokensCommandDefaultHandler(ctx) {
|
|
4593
|
-
const { args } = ctx;
|
|
4594
|
-
const patcher = await ctx.createPatcher();
|
|
4595
|
-
const report = await patcher.collectContentTokens();
|
|
4596
|
-
const shouldWrite = args.write ?? true;
|
|
4597
|
-
let format = args.format ?? "json";
|
|
4598
|
-
if (!TOKEN_FORMATS.includes(format)) {
|
|
4599
|
-
format = "json";
|
|
4600
|
-
}
|
|
4601
|
-
const targetFile = args.output ?? DEFAULT_TOKEN_REPORT;
|
|
4602
|
-
const groupKey = args.groupKey === "absolute" ? "absolute" : "relative";
|
|
4603
|
-
const buildGrouped = () => groupTokensByFile(report, {
|
|
4604
|
-
key: groupKey,
|
|
4605
|
-
stripAbsolutePaths: groupKey !== "absolute"
|
|
4606
|
-
});
|
|
4607
|
-
const grouped = format === "grouped-json" ? buildGrouped() : null;
|
|
4608
|
-
const resolveGrouped = () => grouped ?? buildGrouped();
|
|
4609
|
-
if (shouldWrite) {
|
|
4610
|
-
const target = path16.resolve(targetFile);
|
|
4611
|
-
await fs15.ensureDir(path16.dirname(target));
|
|
4612
|
-
if (format === "json") {
|
|
4613
|
-
await fs15.writeJSON(target, report, { spaces: 2 });
|
|
4614
|
-
} else if (format === "grouped-json") {
|
|
4615
|
-
await fs15.writeJSON(target, resolveGrouped(), { spaces: 2 });
|
|
4616
|
-
} else {
|
|
4617
|
-
const lines = report.entries.map(formatTokenLine);
|
|
4618
|
-
await fs15.writeFile(target, `${lines.join("\n")}
|
|
4619
|
-
`, "utf8");
|
|
4620
|
-
}
|
|
4621
|
-
logger_default.success(`Collected ${report.entries.length} tokens (${format}) \u2192 ${target.replace(process9.cwd(), ".")}`);
|
|
4622
|
-
} else {
|
|
4623
|
-
logger_default.success(`Collected ${report.entries.length} tokens from ${report.filesScanned} files.`);
|
|
4624
|
-
if (format === "lines") {
|
|
4625
|
-
const preview = report.entries.slice(0, 5).map(formatTokenLine).join("\n");
|
|
4626
|
-
if (preview) {
|
|
4627
|
-
logger_default.log("");
|
|
4628
|
-
logger_default.info(preview);
|
|
4629
|
-
if (report.entries.length > 5) {
|
|
4630
|
-
logger_default.info(`\u2026and ${report.entries.length - 5} more.`);
|
|
4631
|
-
}
|
|
4632
|
-
}
|
|
4633
|
-
} else if (format === "grouped-json") {
|
|
4634
|
-
const map = resolveGrouped();
|
|
4635
|
-
const { preview, moreFiles } = formatGroupedPreview(map);
|
|
4636
|
-
if (preview) {
|
|
4637
|
-
logger_default.log("");
|
|
4638
|
-
logger_default.info(preview);
|
|
4639
|
-
if (moreFiles > 0) {
|
|
4640
|
-
logger_default.info(`\u2026and ${moreFiles} more files.`);
|
|
4641
|
-
}
|
|
4642
|
-
}
|
|
4643
|
-
} else {
|
|
4644
|
-
const previewEntries = report.entries.slice(0, 3);
|
|
4645
|
-
if (previewEntries.length) {
|
|
4646
|
-
logger_default.log("");
|
|
4647
|
-
logger_default.info(JSON.stringify(previewEntries, null, 2));
|
|
4648
|
-
}
|
|
4649
|
-
}
|
|
4650
|
-
}
|
|
4651
|
-
if (report.skippedFiles.length) {
|
|
4652
|
-
logger_default.warn("Skipped files:");
|
|
4653
|
-
for (const skipped of report.skippedFiles) {
|
|
4654
|
-
logger_default.warn(` \u2022 ${skipped.file} (${skipped.reason})`);
|
|
4655
|
-
}
|
|
4656
|
-
}
|
|
4657
|
-
return report;
|
|
4658
|
-
}
|
|
4659
|
-
async function initCommandDefaultHandler(ctx) {
|
|
4660
|
-
const configModule = await loadWorkspaceConfigModule();
|
|
4661
|
-
await configModule.initConfig(ctx.cwd);
|
|
4662
|
-
const configName = configModule.CONFIG_NAME || DEFAULT_CONFIG_NAME;
|
|
4663
|
-
logger_default.success(`\u2728 ${configName}.config.ts initialized!`);
|
|
4664
|
-
}
|
|
4665
|
-
|
|
4666
|
-
// src/commands/migration-args.ts
|
|
4667
|
-
function normalizePatternArgs(value) {
|
|
4668
|
-
if (!value) {
|
|
4669
|
-
return void 0;
|
|
4670
|
-
}
|
|
4671
|
-
const raw = Array.isArray(value) ? value : [value];
|
|
4672
|
-
const values = raw.flatMap((item) => item.split(",")).map((item) => item.trim()).filter(Boolean);
|
|
4673
|
-
return values.length > 0 ? values : void 0;
|
|
4674
|
-
}
|
|
4675
|
-
function parseMaxDepth(value) {
|
|
4676
|
-
if (value === void 0) {
|
|
4677
|
-
return {
|
|
4678
|
-
maxDepth: void 0,
|
|
4679
|
-
hasInvalidMaxDepth: false
|
|
4680
|
-
};
|
|
4681
|
-
}
|
|
4682
|
-
const parsed = Number(value);
|
|
4683
|
-
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
4684
|
-
return {
|
|
4685
|
-
maxDepth: void 0,
|
|
4686
|
-
hasInvalidMaxDepth: true
|
|
4687
|
-
};
|
|
4688
|
-
}
|
|
4689
|
-
return {
|
|
4690
|
-
maxDepth: Math.floor(parsed),
|
|
4691
|
-
hasInvalidMaxDepth: false
|
|
4692
|
-
};
|
|
4693
|
-
}
|
|
4694
|
-
function resolveMigrateCommandArgs(args) {
|
|
4695
|
-
const include = normalizePatternArgs(args.include);
|
|
4696
|
-
const exclude = normalizePatternArgs(args.exclude);
|
|
4697
|
-
const { maxDepth, hasInvalidMaxDepth } = parseMaxDepth(args.maxDepth);
|
|
4698
|
-
const checkMode = args.check ?? false;
|
|
4699
|
-
const dryRun = args.dryRun ?? checkMode;
|
|
4700
|
-
return {
|
|
4701
|
-
include,
|
|
4702
|
-
exclude,
|
|
4703
|
-
maxDepth,
|
|
4704
|
-
checkMode,
|
|
4705
|
-
dryRun,
|
|
4706
|
-
hasInvalidMaxDepth
|
|
4707
|
-
};
|
|
4708
|
-
}
|
|
4709
|
-
function resolveRestoreCommandArgs(args) {
|
|
4710
|
-
return {
|
|
4711
|
-
reportFile: args.reportFile ?? ".tw-patch/migrate-report.json",
|
|
4712
|
-
dryRun: args.dryRun ?? false,
|
|
4713
|
-
strict: args.strict ?? false
|
|
4714
|
-
};
|
|
4715
|
-
}
|
|
4716
|
-
function resolveValidateCommandArgs(args) {
|
|
4717
|
-
return {
|
|
4718
|
-
reportFile: args.reportFile ?? ".tw-patch/migrate-report.json",
|
|
4719
|
-
strict: args.strict ?? false
|
|
4720
|
-
};
|
|
4721
|
-
}
|
|
4722
|
-
|
|
4723
|
-
// src/commands/migration-output.ts
|
|
4724
|
-
import process10 from "process";
|
|
4725
|
-
import fs16 from "fs-extra";
|
|
4726
|
-
import path17 from "pathe";
|
|
4727
|
-
function formatPathForLog(file) {
|
|
4728
|
-
return file.replace(process10.cwd(), ".");
|
|
4729
|
-
}
|
|
4730
|
-
function createMigrationCheckFailureError(changedFiles) {
|
|
4731
|
-
return new Error(`Migration check failed: ${changedFiles} file(s) still need migration.`);
|
|
4732
|
-
}
|
|
4733
|
-
async function writeMigrationReportFile(cwd, reportFile, report) {
|
|
4734
|
-
const reportPath = path17.resolve(cwd, reportFile);
|
|
4735
|
-
await fs16.ensureDir(path17.dirname(reportPath));
|
|
4736
|
-
await fs16.writeJSON(reportPath, report, { spaces: 2 });
|
|
4737
|
-
logger_default.info(`Migration report written: ${formatPathForLog(reportPath)}`);
|
|
4738
|
-
}
|
|
4739
|
-
function logMigrationReportAsJson(report) {
|
|
4740
|
-
logger_default.log(JSON.stringify(report, null, 2));
|
|
4741
|
-
}
|
|
4742
|
-
function logNoMigrationConfigFilesWarning() {
|
|
4743
|
-
logger_default.warn("No config files found for migration.");
|
|
4744
|
-
}
|
|
4745
|
-
function logMigrationEntries(report, dryRun) {
|
|
4746
|
-
for (const entry of report.entries) {
|
|
4747
|
-
const fileLabel = formatPathForLog(entry.file);
|
|
4748
|
-
if (!entry.changed) {
|
|
4749
|
-
logger_default.info(`No changes: ${fileLabel}`);
|
|
4750
|
-
continue;
|
|
4751
|
-
}
|
|
4752
|
-
if (dryRun) {
|
|
4753
|
-
logger_default.info(`[dry-run] ${fileLabel}`);
|
|
4754
|
-
} else {
|
|
4755
|
-
logger_default.success(`Migrated: ${fileLabel}`);
|
|
4756
|
-
}
|
|
4757
|
-
for (const change of entry.changes) {
|
|
4758
|
-
logger_default.info(` - ${change}`);
|
|
4759
|
-
}
|
|
4760
|
-
if (entry.backupFile) {
|
|
4761
|
-
logger_default.info(` - backup: ${formatPathForLog(entry.backupFile)}`);
|
|
4762
|
-
}
|
|
4763
|
-
}
|
|
4764
|
-
}
|
|
4765
|
-
function logMigrationSummary(report) {
|
|
4766
|
-
logger_default.info(
|
|
4767
|
-
`Migration summary: scanned=${report.scannedFiles}, changed=${report.changedFiles}, written=${report.writtenFiles}, backups=${report.backupsWritten}, missing=${report.missingFiles}, unchanged=${report.unchangedFiles}`
|
|
4768
|
-
);
|
|
4769
|
-
}
|
|
4770
|
-
function logRestoreResultAsJson(result) {
|
|
4771
|
-
logger_default.log(JSON.stringify(result, null, 2));
|
|
4772
|
-
}
|
|
4773
|
-
function logRestoreSummary(result) {
|
|
4774
|
-
logger_default.info(
|
|
4775
|
-
`Restore summary: scanned=${result.scannedEntries}, restorable=${result.restorableEntries}, restored=${result.restoredFiles}, missingBackups=${result.missingBackups}, skipped=${result.skippedEntries}`
|
|
4776
|
-
);
|
|
4777
|
-
if (result.restored.length > 0) {
|
|
4778
|
-
const preview = result.restored.slice(0, 5);
|
|
4779
|
-
for (const file of preview) {
|
|
4780
|
-
logger_default.info(` - ${formatPathForLog(file)}`);
|
|
4781
|
-
}
|
|
4782
|
-
if (result.restored.length > preview.length) {
|
|
4783
|
-
logger_default.info(` ...and ${result.restored.length - preview.length} more`);
|
|
4784
|
-
}
|
|
4785
|
-
}
|
|
4786
|
-
}
|
|
4787
|
-
function logValidateSuccessAsJson(result) {
|
|
4788
|
-
const payload = {
|
|
4789
|
-
ok: true,
|
|
4790
|
-
...result
|
|
4791
|
-
};
|
|
4792
|
-
logger_default.log(JSON.stringify(payload, null, 2));
|
|
4793
|
-
}
|
|
4794
|
-
function logValidateSuccessSummary(result) {
|
|
4795
|
-
logger_default.success(
|
|
4796
|
-
`Migration report validated: scanned=${result.scannedEntries}, restorable=${result.restorableEntries}, missingBackups=${result.missingBackups}, skipped=${result.skippedEntries}`
|
|
4797
|
-
);
|
|
4798
|
-
if (result.reportKind || result.reportSchemaVersion !== void 0) {
|
|
4799
|
-
const kind = result.reportKind ?? "unknown";
|
|
4800
|
-
const schema = result.reportSchemaVersion === void 0 ? "unknown" : String(result.reportSchemaVersion);
|
|
4801
|
-
logger_default.info(` metadata: kind=${kind}, schema=${schema}`);
|
|
4802
|
-
}
|
|
4803
|
-
}
|
|
4804
|
-
function logValidateFailureAsJson(summary) {
|
|
4805
|
-
const payload = {
|
|
4806
|
-
ok: false,
|
|
4807
|
-
reason: summary.reason,
|
|
4808
|
-
exitCode: summary.exitCode,
|
|
4809
|
-
message: summary.message
|
|
4810
|
-
};
|
|
4811
|
-
logger_default.log(JSON.stringify(payload, null, 2));
|
|
4812
|
-
}
|
|
4813
|
-
function logValidateFailureSummary(summary) {
|
|
4814
|
-
logger_default.error(`Validation failed [${summary.reason}] (exit ${summary.exitCode}): ${summary.message}`);
|
|
4815
|
-
}
|
|
4816
|
-
|
|
4817
|
-
// src/commands/migrate-handler.ts
|
|
4818
|
-
async function migrateCommandDefaultHandler(ctx) {
|
|
4819
|
-
const { args } = ctx;
|
|
4820
|
-
const {
|
|
4821
|
-
include,
|
|
4822
|
-
exclude,
|
|
4823
|
-
maxDepth,
|
|
4824
|
-
checkMode,
|
|
4825
|
-
dryRun,
|
|
4826
|
-
hasInvalidMaxDepth
|
|
4827
|
-
} = resolveMigrateCommandArgs(args);
|
|
4828
|
-
if (args.workspace && hasInvalidMaxDepth) {
|
|
4829
|
-
logger_default.warn(`Invalid --max-depth value "${String(args.maxDepth)}", fallback to default depth.`);
|
|
4830
|
-
}
|
|
4831
|
-
const report = await migrateConfigFiles({
|
|
4832
|
-
cwd: ctx.cwd,
|
|
4833
|
-
dryRun,
|
|
4834
|
-
...args.config ? { files: [args.config] } : {},
|
|
4835
|
-
...args.workspace ? { workspace: true } : {},
|
|
4836
|
-
...args.workspace && maxDepth !== void 0 ? { maxDepth } : {},
|
|
4837
|
-
...args.backupDir ? { backupDir: args.backupDir } : {},
|
|
4838
|
-
...include ? { include } : {},
|
|
4839
|
-
...exclude ? { exclude } : {}
|
|
4840
|
-
});
|
|
4841
|
-
if (args.reportFile) {
|
|
4842
|
-
await writeMigrationReportFile(ctx.cwd, args.reportFile, report);
|
|
4843
|
-
}
|
|
4844
|
-
if (args.json) {
|
|
4845
|
-
logMigrationReportAsJson(report);
|
|
4846
|
-
if (checkMode && report.changedFiles > 0) {
|
|
4847
|
-
throw createMigrationCheckFailureError(report.changedFiles);
|
|
4848
|
-
}
|
|
4849
|
-
if (report.scannedFiles === 0) {
|
|
4850
|
-
logNoMigrationConfigFilesWarning();
|
|
4851
|
-
}
|
|
4852
|
-
return report;
|
|
4853
|
-
}
|
|
4854
|
-
if (report.scannedFiles === 0) {
|
|
4855
|
-
logNoMigrationConfigFilesWarning();
|
|
4856
|
-
return report;
|
|
4857
|
-
}
|
|
4858
|
-
logMigrationEntries(report, dryRun);
|
|
4859
|
-
logMigrationSummary(report);
|
|
4860
|
-
if (checkMode && report.changedFiles > 0) {
|
|
4861
|
-
throw createMigrationCheckFailureError(report.changedFiles);
|
|
4862
|
-
}
|
|
4863
|
-
return report;
|
|
4864
|
-
}
|
|
4865
|
-
|
|
4866
|
-
// src/commands/restore-handler.ts
|
|
4867
|
-
async function restoreCommandDefaultHandler(ctx) {
|
|
4868
|
-
const { args } = ctx;
|
|
4869
|
-
const restoreArgs = resolveRestoreCommandArgs(args);
|
|
4870
|
-
const result = await restoreConfigFiles({
|
|
4871
|
-
cwd: ctx.cwd,
|
|
4872
|
-
reportFile: restoreArgs.reportFile,
|
|
4873
|
-
dryRun: restoreArgs.dryRun,
|
|
4874
|
-
strict: restoreArgs.strict
|
|
4875
|
-
});
|
|
4876
|
-
if (args.json) {
|
|
4877
|
-
logRestoreResultAsJson(result);
|
|
4878
|
-
return result;
|
|
4879
|
-
}
|
|
4880
|
-
logRestoreSummary(result);
|
|
4881
|
-
return result;
|
|
4882
|
-
}
|
|
4883
|
-
|
|
4884
|
-
// src/commands/status-output.ts
|
|
4885
|
-
function formatFilesHint(entry) {
|
|
4886
|
-
if (!entry.files.length) {
|
|
4887
|
-
return "";
|
|
4888
|
-
}
|
|
4889
|
-
return ` (${entry.files.join(", ")})`;
|
|
4890
|
-
}
|
|
4891
|
-
function formatPackageLabel(report) {
|
|
4892
|
-
return `${report.package.name ?? "tailwindcss"}@${report.package.version ?? "unknown"}`;
|
|
4893
|
-
}
|
|
4894
|
-
function partitionStatusEntries(report) {
|
|
4895
|
-
return {
|
|
4896
|
-
applied: report.entries.filter((entry) => entry.status === "applied"),
|
|
4897
|
-
pending: report.entries.filter((entry) => entry.status === "not-applied"),
|
|
4898
|
-
skipped: report.entries.filter((entry) => entry.status === "skipped" || entry.status === "unsupported")
|
|
4899
|
-
};
|
|
4900
|
-
}
|
|
4901
|
-
function logStatusReportAsJson(report) {
|
|
4902
|
-
logger_default.log(JSON.stringify(report, null, 2));
|
|
4903
|
-
}
|
|
4904
|
-
function logStatusReportSummary(report) {
|
|
4905
|
-
const {
|
|
4906
|
-
applied,
|
|
4907
|
-
pending,
|
|
4908
|
-
skipped
|
|
4909
|
-
} = partitionStatusEntries(report);
|
|
4910
|
-
logger_default.info(`Patch status for ${formatPackageLabel(report)} (v${report.majorVersion})`);
|
|
4911
|
-
if (applied.length) {
|
|
4912
|
-
logger_default.success("Applied:");
|
|
4913
|
-
applied.forEach((entry) => logger_default.success(` \u2022 ${entry.name}${formatFilesHint(entry)}`));
|
|
4914
|
-
}
|
|
4915
|
-
if (pending.length) {
|
|
4916
|
-
logger_default.warn("Needs attention:");
|
|
4917
|
-
pending.forEach((entry) => {
|
|
4918
|
-
const details = entry.reason ? ` - ${entry.reason}` : "";
|
|
4919
|
-
logger_default.warn(` \u2022 ${entry.name}${formatFilesHint(entry)}${details}`);
|
|
4920
|
-
});
|
|
4921
|
-
} else {
|
|
4922
|
-
logger_default.success("All applicable patches are applied.");
|
|
4923
|
-
}
|
|
4924
|
-
if (skipped.length) {
|
|
4925
|
-
logger_default.info("Skipped:");
|
|
4926
|
-
skipped.forEach((entry) => {
|
|
4927
|
-
const details = entry.reason ? ` - ${entry.reason}` : "";
|
|
4928
|
-
logger_default.info(` \u2022 ${entry.name}${details}`);
|
|
4929
|
-
});
|
|
4930
|
-
}
|
|
4931
|
-
}
|
|
4932
|
-
|
|
4933
|
-
// src/commands/status-handler.ts
|
|
4934
|
-
async function statusCommandDefaultHandler(ctx) {
|
|
4935
|
-
const patcher = await ctx.createPatcher();
|
|
4936
|
-
const report = await patcher.getPatchStatus();
|
|
4937
|
-
if (ctx.args.json) {
|
|
4938
|
-
logStatusReportAsJson(report);
|
|
4939
|
-
return report;
|
|
4940
|
-
}
|
|
4941
|
-
logStatusReportSummary(report);
|
|
4942
|
-
return report;
|
|
4943
|
-
}
|
|
4944
|
-
|
|
4945
|
-
// src/commands/validate-handler.ts
|
|
4946
|
-
async function validateCommandDefaultHandler(ctx) {
|
|
4947
|
-
const { args } = ctx;
|
|
4948
|
-
const validateArgs = resolveValidateCommandArgs(args);
|
|
4949
|
-
try {
|
|
4950
|
-
const result = await restoreConfigFiles({
|
|
4951
|
-
cwd: ctx.cwd,
|
|
4952
|
-
reportFile: validateArgs.reportFile,
|
|
4953
|
-
dryRun: true,
|
|
4954
|
-
strict: validateArgs.strict
|
|
4955
|
-
});
|
|
4956
|
-
if (args.json) {
|
|
4957
|
-
logValidateSuccessAsJson(result);
|
|
4958
|
-
return result;
|
|
4959
|
-
}
|
|
4960
|
-
logValidateSuccessSummary(result);
|
|
4961
|
-
return result;
|
|
4962
|
-
} catch (error) {
|
|
4963
|
-
const summary = classifyValidateError(error);
|
|
4964
|
-
if (args.json) {
|
|
4965
|
-
logValidateFailureAsJson(summary);
|
|
4966
|
-
} else {
|
|
4967
|
-
logValidateFailureSummary(summary);
|
|
4968
|
-
}
|
|
4969
|
-
throw new ValidateCommandError(summary, { cause: error });
|
|
4970
|
-
}
|
|
4971
|
-
}
|
|
4972
|
-
|
|
4973
|
-
// src/commands/default-handler-map.ts
|
|
4974
|
-
var defaultCommandHandlers = {
|
|
4975
|
-
install: installCommandDefaultHandler,
|
|
4976
|
-
extract: extractCommandDefaultHandler,
|
|
4977
|
-
tokens: tokensCommandDefaultHandler,
|
|
4978
|
-
init: initCommandDefaultHandler,
|
|
4979
|
-
migrate: migrateCommandDefaultHandler,
|
|
4980
|
-
restore: restoreCommandDefaultHandler,
|
|
4981
|
-
validate: validateCommandDefaultHandler,
|
|
4982
|
-
status: statusCommandDefaultHandler
|
|
4983
|
-
};
|
|
4984
|
-
|
|
4985
|
-
// src/commands/command-registrar.ts
|
|
4986
|
-
function registerTailwindcssPatchCommand(cli, commandName, options, prefix, defaultDefinitions) {
|
|
4987
|
-
const metadata = resolveCommandMetadata(commandName, options, prefix, defaultDefinitions);
|
|
4988
|
-
const command = cli.command(metadata.name, metadata.description);
|
|
4989
|
-
applyCommandOptions(command, metadata.optionDefs);
|
|
4990
|
-
command.action(async (args) => {
|
|
4991
|
-
return runWithCommandHandler(
|
|
4992
|
-
cli,
|
|
4993
|
-
command,
|
|
4994
|
-
commandName,
|
|
4995
|
-
args,
|
|
4996
|
-
options.commandHandlers?.[commandName],
|
|
4997
|
-
defaultCommandHandlers[commandName]
|
|
4998
|
-
);
|
|
4999
|
-
});
|
|
5000
|
-
metadata.aliases.forEach((alias) => command.alias(alias));
|
|
5001
|
-
}
|
|
5002
|
-
|
|
5003
|
-
// src/commands/cli.ts
|
|
5004
|
-
function mountTailwindcssPatchCommands(cli, options = {}) {
|
|
5005
|
-
const prefix = options.commandPrefix ?? "";
|
|
5006
|
-
const selectedCommands = options.commands ?? tailwindcssPatchCommands;
|
|
5007
|
-
const defaultDefinitions = buildDefaultCommandDefinitions();
|
|
5008
|
-
for (const name of selectedCommands) {
|
|
5009
|
-
registerTailwindcssPatchCommand(cli, name, options, prefix, defaultDefinitions);
|
|
5010
|
-
}
|
|
5011
|
-
return cli;
|
|
5012
|
-
}
|
|
5013
|
-
function createTailwindcssPatchCli(options = {}) {
|
|
5014
|
-
const cli = cac(options.name ?? "tw-patch");
|
|
5015
|
-
mountTailwindcssPatchCommands(cli, options.mountOptions);
|
|
5016
|
-
return cli;
|
|
5017
|
-
}
|
|
5018
|
-
|
|
5019
4345
|
export {
|
|
5020
4346
|
logger_default,
|
|
5021
4347
|
CacheStore,
|
|
5022
4348
|
normalizeOptions,
|
|
4349
|
+
loadWorkspaceConfigModule,
|
|
4350
|
+
loadPatchOptionsForWorkspace,
|
|
5023
4351
|
extractRawCandidatesWithPositions,
|
|
5024
4352
|
extractRawCandidates,
|
|
5025
4353
|
extractValidCandidates,
|
|
@@ -5035,10 +4363,9 @@ export {
|
|
|
5035
4363
|
MIGRATION_REPORT_SCHEMA_VERSION,
|
|
5036
4364
|
migrateConfigFiles,
|
|
5037
4365
|
restoreConfigFiles,
|
|
4366
|
+
tailwindcssPatchCommands,
|
|
5038
4367
|
VALIDATE_EXIT_CODES,
|
|
5039
4368
|
VALIDATE_FAILURE_REASONS,
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
mountTailwindcssPatchCommands,
|
|
5043
|
-
createTailwindcssPatchCli
|
|
4369
|
+
classifyValidateError,
|
|
4370
|
+
ValidateCommandError
|
|
5044
4371
|
};
|