@codefast/cli 0.3.12 → 0.3.13-canary.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/README.md +206 -51
  2. package/dist/{bin.js → bin.mjs} +4 -1
  3. package/dist/commands/arrange.mjs +107 -0
  4. package/dist/commands/mirror.mjs +66 -0
  5. package/dist/commands/tag.mjs +58 -0
  6. package/dist/lib/arrange/application/analyze.mjs +92 -0
  7. package/dist/lib/arrange/application/group-file.mjs +113 -0
  8. package/dist/lib/arrange/application/run-target.mjs +65 -0
  9. package/dist/lib/arrange/domain/ast/ast-helpers.mjs +115 -0
  10. package/dist/lib/arrange/domain/ast/collectors-cn.mjs +61 -0
  11. package/dist/lib/arrange/domain/ast/collectors-jsx.mjs +20 -0
  12. package/dist/lib/arrange/domain/ast/collectors-tv.mjs +170 -0
  13. package/dist/lib/arrange/domain/ast/targets.mjs +106 -0
  14. package/dist/lib/arrange/domain/constants.mjs +169 -0
  15. package/dist/lib/arrange/domain/errors.mjs +19 -0
  16. package/dist/lib/arrange/domain/grouping.mjs +235 -0
  17. package/dist/lib/arrange/domain/imports.mjs +54 -0
  18. package/dist/lib/arrange/domain/tokenizer.mjs +216 -0
  19. package/dist/lib/arrange/index.mjs +15 -0
  20. package/dist/lib/arrange/infra/walk.mjs +33 -0
  21. package/dist/lib/arrange/presentation/formatters.mjs +52 -0
  22. package/dist/lib/arrange/presentation/report.mjs +24 -0
  23. package/dist/lib/config/domain/schema.mjs +25 -0
  24. package/dist/lib/config/index.mjs +3 -0
  25. package/dist/lib/config/infra/loader.mjs +78 -0
  26. package/dist/lib/infra/caught-unknown-message.mjs +20 -0
  27. package/dist/lib/infra/config-reporter.mjs +10 -0
  28. package/dist/lib/infra/node-io.mjs +30 -0
  29. package/dist/lib/infra/workspace/repo-root.mjs +22 -0
  30. package/dist/lib/mirror/application/engine.mjs +248 -0
  31. package/dist/lib/mirror/application/sync.mjs +162 -0
  32. package/dist/lib/mirror/domain/constants.mjs +12 -0
  33. package/dist/lib/mirror/domain/errors.mjs +15 -0
  34. package/dist/lib/mirror/domain/types.mjs +1 -0
  35. package/dist/lib/mirror/index.mjs +2 -0
  36. package/dist/lib/mirror/infra/dirent-list.mjs +14 -0
  37. package/dist/lib/mirror/infra/package-filter.mjs +26 -0
  38. package/dist/lib/mirror/infra/path-normalizer.mjs +7 -0
  39. package/dist/lib/mirror/infra/update-pkg.mjs +105 -0
  40. package/dist/lib/mirror/infra/workspace-packages.mjs +159 -0
  41. package/dist/lib/mirror/presentation/reporter.mjs +111 -0
  42. package/dist/lib/tag/application/engine.mjs +287 -0
  43. package/dist/lib/tag/domain/types.mjs +1 -0
  44. package/dist/lib/tag/index.mjs +4 -0
  45. package/dist/lib/tag/infra/target-resolver.mjs +170 -0
  46. package/dist/lib/tag/presentation/colors.mjs +12 -0
  47. package/dist/lib/tag/presentation/tag-presenter.mjs +63 -0
  48. package/dist/program.mjs +34 -0
  49. package/package.json +11 -11
  50. package/dist/bin.d.ts +0 -3
  51. package/dist/bin.d.ts.map +0 -1
  52. package/dist/commands/arrange.d.ts +0 -3
  53. package/dist/commands/arrange.d.ts.map +0 -1
  54. package/dist/commands/arrange.js +0 -114
  55. package/dist/commands/mirror.d.ts +0 -4
  56. package/dist/commands/mirror.d.ts.map +0 -1
  57. package/dist/commands/mirror.js +0 -63
  58. package/dist/lib/arrange/analyze.d.ts +0 -4
  59. package/dist/lib/arrange/analyze.d.ts.map +0 -1
  60. package/dist/lib/arrange/analyze.js +0 -105
  61. package/dist/lib/arrange/ast/collectors-cn.d.ts +0 -10
  62. package/dist/lib/arrange/ast/collectors-cn.d.ts.map +0 -1
  63. package/dist/lib/arrange/ast/collectors-cn.js +0 -84
  64. package/dist/lib/arrange/ast/collectors-jsx.d.ts +0 -4
  65. package/dist/lib/arrange/ast/collectors-jsx.d.ts.map +0 -1
  66. package/dist/lib/arrange/ast/collectors-jsx.js +0 -18
  67. package/dist/lib/arrange/ast/collectors-tv.d.ts +0 -13
  68. package/dist/lib/arrange/ast/collectors-tv.d.ts.map +0 -1
  69. package/dist/lib/arrange/ast/collectors-tv.js +0 -273
  70. package/dist/lib/arrange/ast/targets.d.ts +0 -8
  71. package/dist/lib/arrange/ast/targets.d.ts.map +0 -1
  72. package/dist/lib/arrange/ast/targets.js +0 -143
  73. package/dist/lib/arrange/ast/utils.d.ts +0 -36
  74. package/dist/lib/arrange/ast/utils.d.ts.map +0 -1
  75. package/dist/lib/arrange/ast/utils.js +0 -138
  76. package/dist/lib/arrange/constants.d.ts +0 -68
  77. package/dist/lib/arrange/constants.d.ts.map +0 -1
  78. package/dist/lib/arrange/constants.js +0 -179
  79. package/dist/lib/arrange/errors.d.ts +0 -14
  80. package/dist/lib/arrange/errors.d.ts.map +0 -1
  81. package/dist/lib/arrange/errors.js +0 -16
  82. package/dist/lib/arrange/formatters.d.ts +0 -16
  83. package/dist/lib/arrange/formatters.d.ts.map +0 -1
  84. package/dist/lib/arrange/formatters.js +0 -57
  85. package/dist/lib/arrange/group-file.d.ts +0 -4
  86. package/dist/lib/arrange/group-file.d.ts.map +0 -1
  87. package/dist/lib/arrange/group-file.js +0 -115
  88. package/dist/lib/arrange/grouping.d.ts +0 -41
  89. package/dist/lib/arrange/grouping.d.ts.map +0 -1
  90. package/dist/lib/arrange/grouping.js +0 -280
  91. package/dist/lib/arrange/imports.d.ts +0 -6
  92. package/dist/lib/arrange/imports.d.ts.map +0 -1
  93. package/dist/lib/arrange/imports.js +0 -74
  94. package/dist/lib/arrange/report.d.ts +0 -4
  95. package/dist/lib/arrange/report.d.ts.map +0 -1
  96. package/dist/lib/arrange/report.js +0 -37
  97. package/dist/lib/arrange/run-target.d.ts +0 -4
  98. package/dist/lib/arrange/run-target.d.ts.map +0 -1
  99. package/dist/lib/arrange/run-target.js +0 -28
  100. package/dist/lib/arrange/tokenizer.d.ts +0 -37
  101. package/dist/lib/arrange/tokenizer.d.ts.map +0 -1
  102. package/dist/lib/arrange/tokenizer.js +0 -390
  103. package/dist/lib/arrange/types.d.ts +0 -104
  104. package/dist/lib/arrange/types.d.ts.map +0 -1
  105. package/dist/lib/arrange/types.js +0 -7
  106. package/dist/lib/arrange/walk.d.ts +0 -4
  107. package/dist/lib/arrange/walk.d.ts.map +0 -1
  108. package/dist/lib/arrange/walk.js +0 -34
  109. package/dist/lib/arrange.d.ts +0 -41
  110. package/dist/lib/arrange.d.ts.map +0 -1
  111. package/dist/lib/arrange.js +0 -38
  112. package/dist/lib/infra/fs-contract.d.ts +0 -28
  113. package/dist/lib/infra/fs-contract.d.ts.map +0 -1
  114. package/dist/lib/infra/node-io.d.ts +0 -4
  115. package/dist/lib/infra/node-io.d.ts.map +0 -1
  116. package/dist/lib/infra/node-io.js +0 -27
  117. package/dist/lib/mirror/config.d.ts +0 -7
  118. package/dist/lib/mirror/config.d.ts.map +0 -1
  119. package/dist/lib/mirror/config.js +0 -146
  120. package/dist/lib/mirror/constants.d.ts +0 -10
  121. package/dist/lib/mirror/constants.d.ts.map +0 -1
  122. package/dist/lib/mirror/constants.js +0 -13
  123. package/dist/lib/mirror/engine.d.ts +0 -12
  124. package/dist/lib/mirror/engine.d.ts.map +0 -1
  125. package/dist/lib/mirror/engine.js +0 -248
  126. package/dist/lib/mirror/errors.d.ts +0 -10
  127. package/dist/lib/mirror/errors.d.ts.map +0 -1
  128. package/dist/lib/mirror/errors.js +0 -12
  129. package/dist/lib/mirror/package-filter.d.ts +0 -8
  130. package/dist/lib/mirror/package-filter.d.ts.map +0 -1
  131. package/dist/lib/mirror/package-filter.js +0 -33
  132. package/dist/lib/mirror/reporter.d.ts +0 -24
  133. package/dist/lib/mirror/reporter.d.ts.map +0 -1
  134. package/dist/lib/mirror/reporter.js +0 -126
  135. package/dist/lib/mirror/sync.d.ts +0 -4
  136. package/dist/lib/mirror/sync.d.ts.map +0 -1
  137. package/dist/lib/mirror/sync.js +0 -135
  138. package/dist/lib/mirror/types.d.ts +0 -81
  139. package/dist/lib/mirror/types.d.ts.map +0 -1
  140. package/dist/lib/mirror/update-pkg.d.ts +0 -13
  141. package/dist/lib/mirror/update-pkg.d.ts.map +0 -1
  142. package/dist/lib/mirror/update-pkg.js +0 -39
  143. package/dist/lib/mirror/workspace-packages.d.ts +0 -26
  144. package/dist/lib/mirror/workspace-packages.d.ts.map +0 -1
  145. package/dist/lib/mirror/workspace-packages.js +0 -160
  146. package/dist/lib/mirror.d.ts +0 -7
  147. package/dist/lib/mirror.d.ts.map +0 -1
  148. package/dist/lib/mirror.js +0 -5
  149. package/dist/lib/repo-root.d.ts +0 -7
  150. package/dist/lib/repo-root.d.ts.map +0 -1
  151. package/dist/lib/repo-root.js +0 -23
  152. package/dist/lib/shared/utils.d.ts +0 -9
  153. package/dist/lib/shared/utils.d.ts.map +0 -1
  154. package/dist/lib/shared/utils.js +0 -12
  155. package/dist/program.d.ts +0 -4
  156. package/dist/program.d.ts.map +0 -1
  157. package/dist/program.js +0 -38
  158. /package/dist/lib/{infra/fs-contract.js → arrange/domain/types.mjs} +0 -0
  159. /package/dist/lib/{mirror/types.js → infra/fs-contract.mjs} +0 -0
@@ -1,41 +0,0 @@
1
- /**
2
- * True when `staticLiteralTexts` carries the **same partition** of Tailwind tokens as
3
- * `suggestedGroups` from {@link suggestCnGroups}, ignoring order of arguments and
4
- * order of tokens within each chunk.
5
- */
6
- export declare function areCnTailwindPartitionsEquivalent(staticLiteralTexts: string[], suggestedGroups: string[]): boolean;
7
- /**
8
- * Merge singleton groups (< MIN_GROUP_TOKENS tokens) into their nearest
9
- * neighbour. Prefers merging toward a bucket-compatible neighbor.
10
- *
11
- * Loop termination: each iteration either splices one element (shrinking the
12
- * array, guaranteeing progress) or finds no singleton that can merge and exits
13
- * via `changed = false`. Two mutually-incompatible singletons both hit
14
- * `continue` and `changed` stays false, so the loop exits without spinning.
15
- */
16
- export declare function mergeSingletons(groups: string[]): string[];
17
- /**
18
- * Merge adjacent groups until total count ≤ maxGroups.
19
- * Only merges pairs allowed by {@link bucketsMergeCompatible} — never glues incompatible
20
- * buckets (which previously defaulted to penalty 0 and merged layout+state when over cap).
21
- *
22
- * Complexity: O(n²) in the number of groups — each merge pass scans all remaining adjacent
23
- * pairs. In practice `n` is bounded by {@link MAX_GROUPS_CAP} (24) and typical class strings
24
- * are well below that, so this is not a concern for the current usage pattern. If this ever
25
- * runs in a high-throughput batch mode, consider a priority-queue approach.
26
- */
27
- export declare function capGroups(groups: string[], maxGroups: number): string[];
28
- /**
29
- * If a chunk is **only** bare `ease-*` timing (Motion), buffer it and prepend to the **first**
30
- * **later** chunk that is predominantly `state` **and** contains some `animate-*` utility —
31
- * skipping intermediate `state` chunks (`sm:…`, `group-data-[…]:…`, etc.) that sit between
32
- * `ease-ui` and `data-open:animate-*`. If no such chunk exists, the ease chunk is left as-is.
33
- */
34
- export declare function mergeEaseTimingIntoFollowingAnimatedState(groups: string[]): string[];
35
- export declare function suggestCnGroups(classString: string): string[];
36
- /**
37
- * One label per suggested group: a single bucket name, or `mixed:a+b` when that chunk
38
- * spans multiple Tailwind buckets (matches `codefast arrange group` stdout).
39
- */
40
- export declare function summarizeGroupBucketLabels(groups: string[]): string[];
41
- //# sourceMappingURL=grouping.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"grouping.d.ts","sourceRoot":"","sources":["../../../src/lib/arrange/grouping.ts"],"names":[],"mappings":"AAsBA;;;;GAIG;AACH,wBAAgB,iCAAiC,CAC/C,kBAAkB,EAAE,MAAM,EAAE,EAC5B,eAAe,EAAE,MAAM,EAAE,GACxB,OAAO,CAiBT;AA+BD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAyC1D;AASD;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAmCvE;AAED;;;;;GAKG;AACH,wBAAgB,yCAAyC,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAwBpF;AAQD,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,CA8E7D;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAKrE"}
@@ -1,280 +0,0 @@
1
- import { BUCKET_ORDER, MAX_GROUPS_BASE, MAX_GROUPS_CAP, MAX_GROUPS_HEADROOM, MIN_GROUP_TOKENS, } from "#lib/arrange/constants";
2
- import { bucketsCompatible, bucketsMergeCompatible, classifyToken, compositeSecondaryOrder, stateKey, stripVariants, tokenizeClassString, } from "#lib/arrange/tokenizer";
3
- function isVariantKeyedBucket(bucket) {
4
- return bucket === "state" || bucket === "starting";
5
- }
6
- /**
7
- * True when `staticLiteralTexts` carries the **same partition** of Tailwind tokens as
8
- * `suggestedGroups` from {@link suggestCnGroups}, ignoring order of arguments and
9
- * order of tokens within each chunk.
10
- */
11
- export function areCnTailwindPartitionsEquivalent(staticLiteralTexts, suggestedGroups) {
12
- const partitionSignatures = (chunks) => chunks
13
- .map((chunk) => {
14
- const toks = tokenizeClassString(chunk);
15
- return toks.length === 0 ? "" : [...toks].sort().join(" ");
16
- })
17
- .filter((s) => s.length > 0)
18
- .sort((a, b) => a.localeCompare(b));
19
- const staticPartitionSigs = partitionSignatures(staticLiteralTexts);
20
- const suggestedPartitionSigs = partitionSignatures(suggestedGroups);
21
- if (staticPartitionSigs.length !== suggestedPartitionSigs.length)
22
- return false;
23
- for (let i = 0; i < staticPartitionSigs.length; i++) {
24
- if (staticPartitionSigs[i] !== suggestedPartitionSigs[i])
25
- return false;
26
- }
27
- return true;
28
- }
29
- /** Dominant bucket of a whitespace-delimited class group (for merge heuristics). */
30
- function dominantBucketOfGroup(groupStr) {
31
- const counts = new Map();
32
- for (const tok of tokenizeClassString(groupStr)) {
33
- const tokenBucket = classifyToken(tok);
34
- counts.set(tokenBucket, (counts.get(tokenBucket) ?? 0) + 1);
35
- }
36
- let best = "other";
37
- let bestN = 0;
38
- for (const [bucket, count] of counts) {
39
- if (count > bestN) {
40
- best = bucket;
41
- bestN = count;
42
- continue;
43
- }
44
- // Deterministic tie-break: prefer earlier render-pipeline bucket.
45
- if (count === bestN && BUCKET_ORDER[bucket] < BUCKET_ORDER[best]) {
46
- best = bucket;
47
- }
48
- }
49
- return best;
50
- }
51
- /** Dynamic cap: more tokens → allow more groups, within [BASE, CAP]. */
52
- function dynamicMaxGroups(tokenCount) {
53
- const byTokens = Math.ceil(tokenCount / 2) + MAX_GROUPS_HEADROOM;
54
- return Math.max(MAX_GROUPS_BASE, Math.min(MAX_GROUPS_CAP, byTokens));
55
- }
56
- /**
57
- * Merge singleton groups (< MIN_GROUP_TOKENS tokens) into their nearest
58
- * neighbour. Prefers merging toward a bucket-compatible neighbor.
59
- *
60
- * Loop termination: each iteration either splices one element (shrinking the
61
- * array, guaranteeing progress) or finds no singleton that can merge and exits
62
- * via `changed = false`. Two mutually-incompatible singletons both hit
63
- * `continue` and `changed` stays false, so the loop exits without spinning.
64
- */
65
- export function mergeSingletons(groups) {
66
- if (groups.length <= 1)
67
- return groups;
68
- const result = [...groups];
69
- let changed = true;
70
- while (changed) {
71
- changed = false;
72
- for (let i = 0; i < result.length; i++) {
73
- if (tokenizeClassString(result[i]).length < MIN_GROUP_TOKENS) {
74
- if (result.length === 1)
75
- break;
76
- const myBucket = dominantBucketOfGroup(result[i]);
77
- const prevCompat = i > 0 && bucketsMergeCompatible(myBucket, dominantBucketOfGroup(result[i - 1]));
78
- const nextCompat = i < result.length - 1 &&
79
- bucketsMergeCompatible(myBucket, dominantBucketOfGroup(result[i + 1]));
80
- let mergeDir;
81
- if (nextCompat && !prevCompat) {
82
- mergeDir = "forward";
83
- }
84
- else if (prevCompat && !nextCompat) {
85
- mergeDir = "backward";
86
- }
87
- else if (prevCompat && nextCompat) {
88
- mergeDir = i < result.length - 1 ? "forward" : "backward";
89
- }
90
- else {
91
- continue;
92
- }
93
- if (mergeDir === "forward") {
94
- result[i + 1] = result[i] + " " + result[i + 1];
95
- }
96
- else {
97
- result[i - 1] = result[i - 1] + " " + result[i];
98
- }
99
- result.splice(i, 1);
100
- changed = true;
101
- break;
102
- }
103
- }
104
- }
105
- return result;
106
- }
107
- /** Tie-break when two merge candidates are both {@link bucketsMergeCompatible} (same bucket or COMPATIBLE_BUCKET_SETS). */
108
- function capMergePenalty(leftBucket, rightBucket) {
109
- if (leftBucket === rightBucket)
110
- return 0;
111
- if (bucketsCompatible(leftBucket, rightBucket))
112
- return 0;
113
- return 500;
114
- }
115
- /**
116
- * Merge adjacent groups until total count ≤ maxGroups.
117
- * Only merges pairs allowed by {@link bucketsMergeCompatible} — never glues incompatible
118
- * buckets (which previously defaulted to penalty 0 and merged layout+state when over cap).
119
- *
120
- * Complexity: O(n²) in the number of groups — each merge pass scans all remaining adjacent
121
- * pairs. In practice `n` is bounded by {@link MAX_GROUPS_CAP} (24) and typical class strings
122
- * are well below that, so this is not a concern for the current usage pattern. If this ever
123
- * runs in a high-throughput batch mode, consider a priority-queue approach.
124
- */
125
- export function capGroups(groups, maxGroups) {
126
- const result = [...groups];
127
- const lengths = result.map((groupStr) => tokenizeClassString(groupStr).length);
128
- while (result.length > maxGroups) {
129
- const cands = [];
130
- for (let i = 0; i < result.length - 1; i++) {
131
- const dominantLeft = dominantBucketOfGroup(result[i]);
132
- const dominantRight = dominantBucketOfGroup(result[i + 1]);
133
- if (!bucketsMergeCompatible(dominantLeft, dominantRight))
134
- continue;
135
- cands.push({
136
- i,
137
- size: lengths[i] + lengths[i + 1],
138
- penalty: capMergePenalty(dominantLeft, dominantRight),
139
- });
140
- }
141
- if (cands.length === 0)
142
- break;
143
- let best = cands[0];
144
- for (const candidate of cands) {
145
- if (candidate.penalty < best.penalty ||
146
- (candidate.penalty === best.penalty && candidate.size < best.size)) {
147
- best = candidate;
148
- }
149
- }
150
- const bestIdx = best.i;
151
- result[bestIdx] = result[bestIdx] + " " + result[bestIdx + 1];
152
- lengths[bestIdx] = lengths[bestIdx] + lengths[bestIdx + 1];
153
- result.splice(bestIdx + 1, 1);
154
- lengths.splice(bestIdx + 1, 1);
155
- }
156
- return result;
157
- }
158
- /**
159
- * If a chunk is **only** bare `ease-*` timing (Motion), buffer it and prepend to the **first**
160
- * **later** chunk that is predominantly `state` **and** contains some `animate-*` utility —
161
- * skipping intermediate `state` chunks (`sm:…`, `group-data-[…]:…`, etc.) that sit between
162
- * `ease-ui` and `data-open:animate-*`. If no such chunk exists, the ease chunk is left as-is.
163
- */
164
- export function mergeEaseTimingIntoFollowingAnimatedState(groups) {
165
- const result = [...groups];
166
- let changed = true;
167
- while (changed) {
168
- changed = false;
169
- for (let i = 0; i < result.length; i++) {
170
- if (!chunkIsOnlyEaseTimingMotion(result[i]))
171
- continue;
172
- const easeStr = result[i];
173
- let target = -1;
174
- for (let j = i + 1; j < result.length; j++) {
175
- if (dominantBucketOfGroup(result[j]) !== "state")
176
- continue;
177
- const toks = tokenizeClassString(result[j]);
178
- if (!toks.some((t) => /^animate/.test(stripVariants(t))))
179
- continue;
180
- target = j;
181
- break;
182
- }
183
- if (target === -1)
184
- continue;
185
- result[target] = `${easeStr} ${result[target]}`.trim();
186
- result.splice(i, 1);
187
- changed = true;
188
- break;
189
- }
190
- }
191
- return result;
192
- }
193
- function chunkIsOnlyEaseTimingMotion(groupStr) {
194
- const toks = tokenizeClassString(groupStr);
195
- if (toks.length === 0)
196
- return false;
197
- return toks.every((t) => classifyToken(t) === "motion" && /^ease-/.test(stripVariants(t)));
198
- }
199
- export function suggestCnGroups(classString) {
200
- const tokens = tokenizeClassString(classString);
201
- if (tokens.length === 0)
202
- return [];
203
- const classified = tokens.map((tok, index) => ({ tok, bucket: classifyToken(tok), index }));
204
- classified.sort((left, right) => {
205
- const bucketOrderDiff = BUCKET_ORDER[left.bucket] - BUCKET_ORDER[right.bucket];
206
- if (bucketOrderDiff !== 0)
207
- return bucketOrderDiff;
208
- if (left.bucket === "composite" && right.bucket === "composite") {
209
- const c = compositeSecondaryOrder(stripVariants(left.tok)) -
210
- compositeSecondaryOrder(stripVariants(right.tok));
211
- if (c !== 0)
212
- return c;
213
- }
214
- return left.index - right.index;
215
- });
216
- const rawGroups = [];
217
- /** Bucket of the last token already placed in the current run (pairwise compat with `COMPATIBLE_BUCKET_SETS`). */
218
- let lastBucketInRun = null;
219
- let currentStateKey = null;
220
- let currentTokens = [];
221
- const flush = () => {
222
- if (currentTokens.length > 0) {
223
- rawGroups.push(currentTokens.join(" "));
224
- currentTokens = [];
225
- }
226
- lastBucketInRun = null;
227
- currentStateKey = null;
228
- };
229
- for (const { tok, bucket: tokenBucket } of classified) {
230
- if (lastBucketInRun === null) {
231
- lastBucketInRun = tokenBucket;
232
- currentStateKey = isVariantKeyedBucket(tokenBucket) ? stateKey(tok) : null;
233
- currentTokens.push(tok);
234
- continue;
235
- }
236
- if (isVariantKeyedBucket(tokenBucket)) {
237
- const key = stateKey(tok);
238
- if (currentStateKey !== null && key !== currentStateKey) {
239
- flush();
240
- lastBucketInRun = tokenBucket;
241
- currentStateKey = key;
242
- currentTokens.push(tok);
243
- continue;
244
- }
245
- }
246
- if (!bucketsCompatible(tokenBucket, lastBucketInRun)) {
247
- flush();
248
- lastBucketInRun = tokenBucket;
249
- currentStateKey = isVariantKeyedBucket(tokenBucket) ? stateKey(tok) : null;
250
- currentTokens.push(tok);
251
- continue;
252
- }
253
- if (isVariantKeyedBucket(tokenBucket)) {
254
- currentStateKey = stateKey(tok);
255
- }
256
- else if (currentStateKey !== null) {
257
- // Defensive reset: keeps state-key logic explicit if bucket rules evolve.
258
- currentStateKey = null;
259
- }
260
- lastBucketInRun = tokenBucket;
261
- currentTokens.push(tok);
262
- }
263
- flush();
264
- const merged = mergeSingletons(rawGroups);
265
- const withEaseMerged = mergeEaseTimingIntoFollowingAnimatedState(merged);
266
- // Never cap-merge below the semantic chunk count from the tokenizer (fixes layout+state glued
267
- // when `preferred` compat list was empty and unrelated pairs used penalty 0).
268
- const maxAllowed = Math.max(dynamicMaxGroups(tokens.length), withEaseMerged.length);
269
- return capGroups(withEaseMerged, maxAllowed);
270
- }
271
- /**
272
- * One label per suggested group: a single bucket name, or `mixed:a+b` when that chunk
273
- * spans multiple Tailwind buckets (matches `codefast arrange group` stdout).
274
- */
275
- export function summarizeGroupBucketLabels(groups) {
276
- return groups.map((g) => {
277
- const uniq = new Set(tokenizeClassString(g).map(classifyToken));
278
- return uniq.size === 1 ? [...uniq][0] : `mixed:${[...uniq].sort().join("+")}`;
279
- });
280
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * Resolve the module specifier used when injecting a `cn` import into a file.
3
- */
4
- export declare function cnModuleSpecifierForFile(filePath: string, override?: string): string;
5
- export declare function ensureCnImport(sourceText: string, filePath: string, cnImportOverride?: string): string;
6
- //# sourceMappingURL=imports.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../../../src/lib/arrange/imports.ts"],"names":[],"mappings":"AAgBA;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAIpF;AAgBD,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,gBAAgB,CAAC,EAAE,MAAM,GACxB,MAAM,CA+CR"}
@@ -1,74 +0,0 @@
1
- import ts from "typescript";
2
- function sourceFileImportsCn(sf) {
3
- for (const st of sf.statements) {
4
- if (!ts.isImportDeclaration(st) || !st.importClause)
5
- continue;
6
- const clause = st.importClause;
7
- if (clause.name?.text === "cn")
8
- return true;
9
- if (clause.namedBindings && ts.isNamedImports(clause.namedBindings)) {
10
- for (const el of clause.namedBindings.elements) {
11
- if (el.name.text === "cn")
12
- return true;
13
- }
14
- }
15
- }
16
- return false;
17
- }
18
- /**
19
- * Resolve the module specifier used when injecting a `cn` import into a file.
20
- */
21
- export function cnModuleSpecifierForFile(filePath, override) {
22
- void filePath;
23
- if (override)
24
- return override;
25
- return "@codefast/tailwind-variants";
26
- }
27
- function findImportDeclarationFromModule(sf, moduleSpecifier) {
28
- for (const st of sf.statements) {
29
- if (!ts.isImportDeclaration(st))
30
- continue;
31
- const spec = st.moduleSpecifier;
32
- if (ts.isStringLiteral(spec) && spec.text === moduleSpecifier) {
33
- return st;
34
- }
35
- }
36
- return undefined;
37
- }
38
- export function ensureCnImport(sourceText, filePath, cnImportOverride) {
39
- const sf = ts.createSourceFile(filePath, sourceText, ts.ScriptTarget.Latest, true, filePath.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
40
- if (sourceFileImportsCn(sf))
41
- return sourceText;
42
- const moduleSpecifier = cnModuleSpecifierForFile(filePath, cnImportOverride);
43
- const decl = findImportDeclarationFromModule(sf, moduleSpecifier);
44
- if (decl?.importClause &&
45
- !decl.importClause.isTypeOnly &&
46
- decl.importClause.namedBindings &&
47
- ts.isNamedImports(decl.importClause.namedBindings)) {
48
- const elements = decl.importClause.namedBindings.elements;
49
- if (elements.length > 0) {
50
- const pos = elements[0].getStart(sf);
51
- return `${sourceText.slice(0, pos)}cn, ${sourceText.slice(pos)}`;
52
- }
53
- }
54
- const importLine = `import { cn } from "${moduleSpecifier}";`;
55
- let firstImport = -1;
56
- for (const st of sf.statements) {
57
- if (ts.isImportDeclaration(st)) {
58
- firstImport = st.getStart(sf);
59
- break;
60
- }
61
- }
62
- const useClient = /^["']use client["'];?\s*\r?\n/.exec(sourceText);
63
- let insertAt;
64
- if (useClient) {
65
- insertAt = useClient[0].length;
66
- }
67
- else if (firstImport !== -1) {
68
- insertAt = firstImport;
69
- }
70
- else {
71
- insertAt = 0;
72
- }
73
- return `${sourceText.slice(0, insertAt)}${importLine}\n${sourceText.slice(insertAt)}`;
74
- }
@@ -1,4 +0,0 @@
1
- import type { CliLogger } from "#lib/infra/fs-contract";
2
- import type { AnalyzeReport } from "#lib/arrange/types";
3
- export declare function printAnalyzeReport(dir: string, r: AnalyzeReport, logger: CliLogger): void;
4
- //# sourceMappingURL=report.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../src/lib/arrange/report.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,GAAG,IAAI,CA0CzF"}
@@ -1,37 +0,0 @@
1
- import path from "node:path";
2
- import { LONG_STRING_TOKEN_THRESHOLD, MAX_REPORT_LINES } from "#lib/arrange/constants";
3
- export function printAnalyzeReport(dir, r, logger) {
4
- const { out } = logger;
5
- out(`Path: ${path.resolve(dir)}`);
6
- out(`.ts/.tsx files: ${r.files}`);
7
- out(`cn(...) call sites: ${r.cnCallExpressions}`);
8
- out(`tv(...) call sites: ${r.tvCallExpressions}`);
9
- out(`\nLong cn(...) string literals (≥${LONG_STRING_TOKEN_THRESHOLD} tokens — consider splitting arguments): ${r.longCnStringLiterals.length}`);
10
- for (const x of r.longCnStringLiterals.slice(0, MAX_REPORT_LINES)) {
11
- out(` ${x.file}:${x.line} (${x.tokenCount} tokens) ${x.preview}`);
12
- }
13
- if (r.longCnStringLiterals.length > MAX_REPORT_LINES) {
14
- out(` … and ${r.longCnStringLiterals.length - MAX_REPORT_LINES} more`);
15
- }
16
- out(`\nLong tv({...}) string literals in base/variants/… (≥${LONG_STRING_TOKEN_THRESHOLD} tokens): ${r.longTvStringLiterals.length}`);
17
- for (const x of r.longTvStringLiterals.slice(0, MAX_REPORT_LINES)) {
18
- out(` ${x.file}:${x.line} (${x.tokenCount} tokens) ${x.preview}`);
19
- }
20
- if (r.longTvStringLiterals.length > MAX_REPORT_LINES) {
21
- out(` … and ${r.longTvStringLiterals.length - MAX_REPORT_LINES} more`);
22
- }
23
- out(`\nJSX className="..." or className={'...'} (static strings, ≥${LONG_STRING_TOKEN_THRESHOLD} tokens): ${r.longJsxClassNameLiterals.length}`);
24
- for (const x of r.longJsxClassNameLiterals.slice(0, MAX_REPORT_LINES)) {
25
- out(` ${x.file}:${x.line} (${x.tokenCount} tokens) ${x.preview}`);
26
- }
27
- if (r.longJsxClassNameLiterals.length > MAX_REPORT_LINES) {
28
- out(` … and ${r.longJsxClassNameLiterals.length - MAX_REPORT_LINES} more`);
29
- }
30
- out(`\ncn(...) nested inside tv({...}) (prefer a string or array — preview/apply can rewrite): ${r.cnInsideTvCalls.length}`);
31
- for (const x of r.cnInsideTvCalls.slice(0, MAX_REPORT_LINES)) {
32
- out(` ${x.file}:${x.line} (${x.argCount} args) ${x.preview}`);
33
- }
34
- if (r.cnInsideTvCalls.length > MAX_REPORT_LINES) {
35
- out(` … and ${r.cnInsideTvCalls.length - MAX_REPORT_LINES} more`);
36
- }
37
- }
@@ -1,4 +0,0 @@
1
- import type { CliFs, CliLogger } from "#lib/infra/fs-contract";
2
- import type { ArrangeRunOnTargetOptions } from "#lib/arrange/types";
3
- export declare function runOnTarget(target: string, options: ArrangeRunOnTargetOptions, fs: CliFs, logger: CliLogger): void;
4
- //# sourceMappingURL=run-target.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"run-target.d.ts","sourceRoot":"","sources":["../../../src/lib/arrange/run-target.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAE/D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAIpE,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,yBAAyB,EAClC,EAAE,EAAE,KAAK,EACT,MAAM,EAAE,SAAS,GAChB,IAAI,CAkCN"}
@@ -1,28 +0,0 @@
1
- import { ArrangeError, ArrangeErrorCode } from "#lib/arrange/errors";
2
- import { groupFile } from "#lib/arrange/group-file";
3
- import { walkTsxFiles } from "#lib/arrange/walk";
4
- export function runOnTarget(target, options, fs, logger) {
5
- const { out } = logger;
6
- if (!fs.existsSync(target)) {
7
- throw new ArrangeError(ArrangeErrorCode.TARGET_NOT_FOUND, `Not found: ${target}`);
8
- }
9
- const filePaths = fs.statSync(target).isDirectory() ? walkTsxFiles(target, fs) : [target];
10
- let totalFound = 0;
11
- let totalChanged = 0;
12
- for (const fp of filePaths) {
13
- const result = groupFile(fp, options, fs, logger);
14
- totalFound += result.totalFound;
15
- totalChanged += result.changed;
16
- }
17
- out(`\nTotal: ${filePaths.length} file(s), ${totalFound} site(s) (cn/tv/JSX className) to review.`);
18
- if (options.write) {
19
- out(`Applied: ${totalChanged} site(s) updated.`);
20
- }
21
- else {
22
- out(`(Run "apply" to write changes, or "pnpm cli:arrange-apply" / "pnpm exec codefast arrange apply")`);
23
- }
24
- const showCascadeHint = options.write ? totalChanged > 0 : totalFound > 0;
25
- if (showCascadeHint) {
26
- out("Note: class order may change across concern groups — smoke-test the UI if you rely on cascade order.");
27
- }
28
- }
@@ -1,37 +0,0 @@
1
- import type { Bucket } from "#lib/arrange/types";
2
- export declare function tokenizeClassString(classString: string): string[];
3
- /**
4
- * Index of the first `:` that separates a Tailwind variant segment from the rest.
5
- * Colons inside `[...]` (at positive bracket depth) are ignored so selectors like
6
- * `[&_a:hover]:text-red-500` split as `[&_a:hover]:` + `text-red-500`.
7
- */
8
- export declare function indexOfFirstVariantColon(text: string): number;
9
- export declare function stripVariants(token: string): string;
10
- /**
11
- * Secondary sort inside the **composite** bucket: opacity / blend / isolation →
12
- * 3D context → 3D transforms → 2D transforms → filters → will-change.
13
- */
14
- export declare function compositeSecondaryOrder(bareUtility: string): number;
15
- /** Classify a **bare** utility (no `hover:` / `md:` / … prefixes). */
16
- export declare function classifyBareUtility(bareUtility: string): Bucket;
17
- /**
18
- * Arbitrary **parent** selectors (`[&…]`, `[&>a]:…`, slot forms with `&` inside the bracket)
19
- * scope utilities like variants — bucket as `state` so they chunk apart from base layout/typography.
20
- * Pure arbitrary **properties** (`[--x]:`, `[color:red]`) have no `&` in the leading `[…]` segment.
21
- */
22
- export declare function isArbitraryParentSelectorStateToken(token: string): boolean;
23
- export declare function classifyToken(token: string): Bucket;
24
- /**
25
- * Stable key for splitting adjacent `state` / `starting` tokens in {@link suggestCnGroups}.
26
- * Uses the **full variant stack** (every `:` segment outside `[…]`), not only the
27
- * outermost prefix, so `@md/foo:[&>*]:w-auto` and `@md/foo:has-[…]:mt-px` stay in
28
- * separate groups while `hover:opacity` still keys as `hover` + `opacity`…
29
- *
30
- * `data-[…]` / `aria-[…]` normalize the first segment via {@link dataAttributeStem} /
31
- * {@link ariaAttributeStem} (full token required for bracket capture).
32
- */
33
- export declare function stateKey(token: string): string;
34
- export declare function bucketsCompatible(a: Bucket, b: Bucket): boolean;
35
- /** Like {@link bucketsCompatible}, but never merge two distinct state / starting variant blobs. */
36
- export declare function bucketsMergeCompatible(a: Bucket, b: Bucket): boolean;
37
- //# sourceMappingURL=tokenizer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tokenizer.d.ts","sourceRoot":"","sources":["../../../src/lib/arrange/tokenizer.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAgCjD,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,CAEjE;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAa7D;AAMD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CASnD;AAwCD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAiDnE;AAED,sEAAsE;AACtE,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAiK/D;AAED;;;;GAIG;AACH,wBAAgB,mCAAmC,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAa1E;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgCnD;AAwBD;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAoB9C;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAG/D;AAED,mGAAmG;AACnG,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAKpE"}