@tc96/cli 0.0.0-stage → 0.27.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.
Files changed (200) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +213 -2
  3. package/cli.js +1395 -0
  4. package/package.json +35 -4
  5. package/registry/agent-builder.json +503 -0
  6. package/registry/aggregate.json +4 -0
  7. package/registry/app-shell-1.json +81 -0
  8. package/registry/app-shell-2.json +89 -0
  9. package/registry/app-shell-3.json +109 -0
  10. package/registry/app-shell-4.json +104 -0
  11. package/registry/app-shell-5.json +106 -0
  12. package/registry/bulk-import-1.json +151 -0
  13. package/registry/card-1.json +104 -0
  14. package/registry/card-2.json +97 -0
  15. package/registry/card-3.json +104 -0
  16. package/registry/card-4.json +98 -0
  17. package/registry/card-5.json +85 -0
  18. package/registry/card-6.json +98 -0
  19. package/registry/card-7.json +104 -0
  20. package/registry/card-8.json +106 -0
  21. package/registry/card-9.json +92 -0
  22. package/registry/charts.json +30 -0
  23. package/registry/chat-assistant.json +110 -0
  24. package/registry/chats-panel.json +97 -0
  25. package/registry/checklist.json +307 -0
  26. package/registry/collection-layouts.json +836 -0
  27. package/registry/collection-views.json +836 -0
  28. package/registry/collection.json +831 -0
  29. package/registry/dashboard-1.json +160 -0
  30. package/registry/dashboard-2.json +153 -0
  31. package/registry/dashboard-3.json +154 -0
  32. package/registry/dashboard-4.json +168 -0
  33. package/registry/detail-sheet.json +54 -0
  34. package/registry/editable.json +36 -0
  35. package/registry/empty-state-1.json +40 -0
  36. package/registry/empty-state-2.json +39 -0
  37. package/registry/empty-state-3.json +61 -0
  38. package/registry/empty-state-4.json +39 -0
  39. package/registry/empty-state-5.json +47 -0
  40. package/registry/empty-state-6.json +40 -0
  41. package/registry/flow-canvas.json +198 -0
  42. package/registry/flow-inspector.json +151 -0
  43. package/registry/flow-step-library.json +112 -0
  44. package/registry/forgot-password-1.json +73 -0
  45. package/registry/forgot-password-2.json +73 -0
  46. package/registry/icon-row.json +52 -0
  47. package/registry/impact-map.json +75 -0
  48. package/registry/list-1.json +129 -0
  49. package/registry/list-2.json +117 -0
  50. package/registry/list-3.json +129 -0
  51. package/registry/list-4.json +105 -0
  52. package/registry/list-5.json +98 -0
  53. package/registry/list-6.json +92 -0
  54. package/registry/list.json +52 -0
  55. package/registry/login-1.json +89 -0
  56. package/registry/login-10.json +88 -0
  57. package/registry/login-2.json +81 -0
  58. package/registry/login-3.json +90 -0
  59. package/registry/login-4.json +81 -0
  60. package/registry/login-5.json +82 -0
  61. package/registry/login-6.json +88 -0
  62. package/registry/login-7.json +83 -0
  63. package/registry/login-8.json +81 -0
  64. package/registry/login-9.json +88 -0
  65. package/registry/lookup-create-1.json +157 -0
  66. package/registry/magic-link-6.json +79 -0
  67. package/registry/navbar-1.json +66 -0
  68. package/registry/navbar-2.json +48 -0
  69. package/registry/navbar-3.json +50 -0
  70. package/registry/navbar-4.json +39 -0
  71. package/registry/navbar-5.json +50 -0
  72. package/registry/next-steps-1.json +147 -0
  73. package/registry/onboarding-1.json +114 -0
  74. package/registry/onboarding-2.json +78 -0
  75. package/registry/onboarding-3.json +71 -0
  76. package/registry/otp-1.json +73 -0
  77. package/registry/properties.json +523 -0
  78. package/registry/record-dialog.json +88 -0
  79. package/registry/record-group.json +190 -0
  80. package/registry/record-preview.json +70 -0
  81. package/registry/record-status-list.json +70 -0
  82. package/registry/reset-password-1.json +92 -0
  83. package/registry/reset-password-2.json +98 -0
  84. package/registry/reset-password-6.json +91 -0
  85. package/registry/rich-text-editor.json +93 -0
  86. package/registry/run-monitor.json +198 -0
  87. package/registry/settings-1.json +119 -0
  88. package/registry/settings-10.json +218 -0
  89. package/registry/settings-11.json +129 -0
  90. package/registry/settings-12.json +130 -0
  91. package/registry/settings-13.json +130 -0
  92. package/registry/settings-14.json +173 -0
  93. package/registry/settings-15.json +149 -0
  94. package/registry/settings-16.json +129 -0
  95. package/registry/settings-17.json +117 -0
  96. package/registry/settings-18.json +117 -0
  97. package/registry/settings-19.json +125 -0
  98. package/registry/settings-2.json +123 -0
  99. package/registry/settings-20.json +112 -0
  100. package/registry/settings-21.json +116 -0
  101. package/registry/settings-22.json +118 -0
  102. package/registry/settings-23.json +118 -0
  103. package/registry/settings-3.json +123 -0
  104. package/registry/settings-4.json +116 -0
  105. package/registry/settings-5.json +119 -0
  106. package/registry/settings-6.json +125 -0
  107. package/registry/settings-7.json +128 -0
  108. package/registry/settings-8.json +116 -0
  109. package/registry/settings-9.json +118 -0
  110. package/registry/settings-shell.json +60 -0
  111. package/registry/settings.json +82 -0
  112. package/registry/signup-1.json +100 -0
  113. package/registry/signup-2.json +93 -0
  114. package/registry/signup-3.json +83 -0
  115. package/registry/signup-6.json +99 -0
  116. package/registry/state-surface.json +58 -0
  117. package/registry/stats-1.json +116 -0
  118. package/registry/stats-2.json +115 -0
  119. package/registry/stats-3.json +97 -0
  120. package/registry/stats-4.json +92 -0
  121. package/registry/stats-5.json +103 -0
  122. package/registry/stats-6.json +105 -0
  123. package/registry/stats-7.json +103 -0
  124. package/registry/stats.json +64 -0
  125. package/registry/timeline-1.json +97 -0
  126. package/registry/timeline-2.json +102 -0
  127. package/registry/timeline-3.json +68 -0
  128. package/registry/timeline-4.json +86 -0
  129. package/registry/ui/accordion.json +15 -0
  130. package/registry/ui/alert-dialog.json +14 -0
  131. package/registry/ui/alert.json +50 -0
  132. package/registry/ui/autocomplete.json +18 -0
  133. package/registry/ui/avatar.json +14 -0
  134. package/registry/ui/badge.json +51 -0
  135. package/registry/ui/breadcrumb.json +15 -0
  136. package/registry/ui/button.json +25 -0
  137. package/registry/ui/calendar.json +15 -0
  138. package/registry/ui/card.json +14 -0
  139. package/registry/ui/chat.json +115 -0
  140. package/registry/ui/checkbox-group.json +14 -0
  141. package/registry/ui/checkbox.json +14 -0
  142. package/registry/ui/collapsible.json +14 -0
  143. package/registry/ui/combobox.json +18 -0
  144. package/registry/ui/command.json +17 -0
  145. package/registry/ui/composer-clipboard.json +14 -0
  146. package/registry/ui/composer-document.json +14 -0
  147. package/registry/ui/composer-editor.json +16 -0
  148. package/registry/ui/composer-query.json +12 -0
  149. package/registry/ui/composer.json +17 -0
  150. package/registry/ui/context-menu.json +23 -0
  151. package/registry/ui/dialog.json +18 -0
  152. package/registry/ui/drawer.json +18 -0
  153. package/registry/ui/empty.json +14 -0
  154. package/registry/ui/field.json +22 -0
  155. package/registry/ui/fieldset.json +14 -0
  156. package/registry/ui/form.json +14 -0
  157. package/registry/ui/frame.json +12 -0
  158. package/registry/ui/gauge.json +31 -0
  159. package/registry/ui/group.json +17 -0
  160. package/registry/ui/icon-frame.json +31 -0
  161. package/registry/ui/input-group.json +17 -0
  162. package/registry/ui/input.json +14 -0
  163. package/registry/ui/kbd.json +12 -0
  164. package/registry/ui/label.json +14 -0
  165. package/registry/ui/menu.json +39 -0
  166. package/registry/ui/meter.json +14 -0
  167. package/registry/ui/number-field.json +17 -0
  168. package/registry/ui/otp-field.json +31 -0
  169. package/registry/ui/pagination.json +17 -0
  170. package/registry/ui/popover.json +14 -0
  171. package/registry/ui/preview-card.json +14 -0
  172. package/registry/ui/progress.json +14 -0
  173. package/registry/ui/radio-group.json +14 -0
  174. package/registry/ui/render-anchor.json +12 -0
  175. package/registry/ui/scroll-area.json +14 -0
  176. package/registry/ui/segmented-control.json +14 -0
  177. package/registry/ui/select.json +16 -0
  178. package/registry/ui/separator.json +14 -0
  179. package/registry/ui/sheet.json +18 -0
  180. package/registry/ui/sidebar.json +25 -0
  181. package/registry/ui/skeleton.json +24 -0
  182. package/registry/ui/slider.json +14 -0
  183. package/registry/ui/spinner.json +14 -0
  184. package/registry/ui/switch.json +14 -0
  185. package/registry/ui/table.json +14 -0
  186. package/registry/ui/tabs.json +16 -0
  187. package/registry/ui/text.json +31 -0
  188. package/registry/ui/textarea.json +14 -0
  189. package/registry/ui/toast.json +89 -0
  190. package/registry/ui/toggle-group.json +18 -0
  191. package/registry/ui/toggle.json +15 -0
  192. package/registry/ui/toolbar.json +14 -0
  193. package/registry/ui/tooltip.json +14 -0
  194. package/registry/ui/use-composer-editor.json +17 -0
  195. package/registry/ui/use-copy-to-clipboard.json +12 -0
  196. package/registry/ui/use-media-query.json +12 -0
  197. package/registry/view.json +831 -0
  198. package/registry/widgets.json +319 -0
  199. package/registry/wizard.json +89 -0
  200. package/registry/workflow-editor.json +460 -0
package/cli.js ADDED
@@ -0,0 +1,1395 @@
1
+ #!/usr/bin/env node
2
+
3
+ // packages/registry/src/cli.ts
4
+ import { existsSync as existsSync7 } from "node:fs";
5
+ import { readFile as readFile5, realpath } from "node:fs/promises";
6
+ import { dirname as dirname5, join as join7, relative as relative5, resolve as resolve4 } from "node:path";
7
+ import { createInterface } from "node:readline/promises";
8
+ import { fileURLToPath } from "node:url";
9
+
10
+ // packages/registry/src/barrel.ts
11
+ import { existsSync } from "node:fs";
12
+ import { readFile, writeFile } from "node:fs/promises";
13
+ import ts from "typescript";
14
+ var barrelHeader = "// Generated by tc96 add from the installed patterns; rewritten on every add.";
15
+ function aggregateBarrel(source, installed) {
16
+ const ast = ts.createSourceFile("index.ts", source, ts.ScriptTarget.Latest);
17
+ const kept = ast.statements.filter((statement) => {
18
+ if (ts.isExpressionStatement(statement) && ts.isStringLiteral(statement.expression))
19
+ return true;
20
+ if (!ts.isExportDeclaration(statement) || !statement.moduleSpecifier || !ts.isStringLiteral(statement.moduleSpecifier))
21
+ throw new Error(
22
+ `The aggregate may only hold directives and re-exports: ${statement.getText(ast)}`
23
+ );
24
+ return installed(statement.moduleSpecifier.text);
25
+ });
26
+ return [barrelHeader, "", ...kept.map((node) => node.getText(ast)), ""].join(
27
+ "\n"
28
+ );
29
+ }
30
+ async function writeBarrel(path, content) {
31
+ if (existsSync(path)) {
32
+ const current = await readFile(path, "utf8");
33
+ if (!current.startsWith(barrelHeader)) return "preserved";
34
+ if (current === content) return "unchanged";
35
+ }
36
+ await writeFile(path, content);
37
+ return "written";
38
+ }
39
+
40
+ // packages/registry/src/check-compatibility.ts
41
+ import { dirname as dirname2, relative as relative2, resolve } from "node:path";
42
+ import ts2 from "typescript";
43
+
44
+ // packages/registry/src/dependencies.ts
45
+ import { spawnSync } from "node:child_process";
46
+ import { existsSync as existsSync2, readFileSync } from "node:fs";
47
+ import { dirname, join, relative } from "node:path";
48
+ function installedVersion(root, name) {
49
+ for (let directory = root; ; directory = dirname(directory)) {
50
+ const manifest = join(directory, "node_modules", name, "package.json");
51
+ if (existsSync2(manifest))
52
+ return JSON.parse(readFileSync(manifest, "utf8")).version;
53
+ if (dirname(directory) === directory) return void 0;
54
+ }
55
+ }
56
+ function compatibleVersion(installed, declared) {
57
+ const [major, minor] = installed.match(/\d+/g) ?? [];
58
+ const [wantedMajor, wantedMinor] = declared.match(/\d+/g) ?? [];
59
+ return major === wantedMajor && (major !== "0" || minor === wantedMinor);
60
+ }
61
+ function parseDependency(dependency) {
62
+ const separator = dependency.lastIndexOf("@");
63
+ return separator > 0 ? {
64
+ name: dependency.slice(0, separator),
65
+ declared: dependency.slice(separator + 1)
66
+ } : { name: dependency, declared: void 0 };
67
+ }
68
+ function declaredDependencies(root) {
69
+ const manifest = join(root, "package.json");
70
+ if (!existsSync2(manifest)) return /* @__PURE__ */ new Set();
71
+ const fields = JSON.parse(readFileSync(manifest, "utf8"));
72
+ return new Set(
73
+ [
74
+ "dependencies",
75
+ "devDependencies",
76
+ "peerDependencies",
77
+ "optionalDependencies"
78
+ ].flatMap((field) => Object.keys(fields[field] ?? {}))
79
+ );
80
+ }
81
+ function missingDependencies(root, dependencies, target) {
82
+ const wanted = /* @__PURE__ */ new Map();
83
+ for (const dependency of dependencies) {
84
+ const { name, declared } = parseDependency(dependency);
85
+ if (!wanted.has(name) || declared) wanted.set(name, declared);
86
+ }
87
+ const owner = target ? join(root, target.directory) : root;
88
+ const own = /* @__PURE__ */ new Set([
89
+ ...declaredDependencies(root),
90
+ ...declaredDependencies(owner)
91
+ ]);
92
+ return [...wanted].filter(([name, declared]) => {
93
+ const installed = own.has(name) && installedVersion(owner, name);
94
+ return !installed || declared && !compatibleVersion(installed, declared);
95
+ }).map(([name, declared]) => declared ? `${name}@${declared}` : name).sort();
96
+ }
97
+ function isWorkspaceRoot(root) {
98
+ const manifest = join(root, "package.json");
99
+ return existsSync2(join(root, "pnpm-workspace.yaml")) || existsSync2(manifest) && JSON.parse(readFileSync(manifest, "utf8")).workspaces !== void 0;
100
+ }
101
+ function dependencyTarget(root, directory) {
102
+ if (!isWorkspaceRoot(root)) return void 0;
103
+ for (let current = join(root, directory); current !== root && current !== dirname(current); current = dirname(current)) {
104
+ const manifest = join(current, "package.json");
105
+ if (existsSync2(manifest))
106
+ return {
107
+ directory: relative(root, current).replaceAll("\\", "/"),
108
+ name: String(JSON.parse(readFileSync(manifest, "utf8")).name ?? "")
109
+ };
110
+ }
111
+ return void 0;
112
+ }
113
+ function detectPackageManager(root) {
114
+ const manifest = join(root, "package.json");
115
+ const declared = existsSync2(manifest) ? String(
116
+ JSON.parse(readFileSync(manifest, "utf8")).packageManager ?? ""
117
+ ).split("@")[0] : "";
118
+ if (declared === "bun" || declared === "pnpm" || declared === "yarn")
119
+ return declared;
120
+ if (declared === "npm") return "npm";
121
+ if (["bun.lock", "bun.lockb"].some((file) => existsSync2(join(root, file))))
122
+ return "bun";
123
+ if (existsSync2(join(root, "pnpm-lock.yaml"))) return "pnpm";
124
+ if (existsSync2(join(root, "yarn.lock"))) return "yarn";
125
+ return "npm";
126
+ }
127
+ function installCommand(root, manager, dependencies, target) {
128
+ if (target) {
129
+ if (manager === "npm")
130
+ return ["npm", "install", "-w", target.directory, ...dependencies];
131
+ if (manager === "yarn" && target.name)
132
+ return ["yarn", "workspace", target.name, "add", ...dependencies];
133
+ if (manager === "pnpm")
134
+ return ["pnpm", "add", "--dir", target.directory, ...dependencies];
135
+ if (manager === "bun")
136
+ return ["bun", "add", "--cwd", target.directory, ...dependencies];
137
+ }
138
+ if (manager === "npm") return ["npm", "install", ...dependencies];
139
+ const workspaceRoot = manager === "pnpm" && existsSync2(join(root, "pnpm-workspace.yaml")) ? ["-w"] : [];
140
+ return [manager, "add", ...workspaceRoot, ...dependencies];
141
+ }
142
+ function installDependencies(root, dependencies, target) {
143
+ const command = installCommand(
144
+ root,
145
+ detectPackageManager(root),
146
+ dependencies,
147
+ target
148
+ );
149
+ console.log(`Installing dependencies: ${command.join(" ")}`);
150
+ const result = spawnSync(command[0], command.slice(1), {
151
+ cwd: root,
152
+ stdio: "inherit",
153
+ shell: process.platform === "win32"
154
+ });
155
+ if (result.status !== 0)
156
+ throw new Error(
157
+ `Installing dependencies failed (${result.status ?? result.error ?? result.signal}). The files were written; run it yourself: ${command.join(" ")}`
158
+ );
159
+ }
160
+
161
+ // packages/registry/src/check-compatibility.ts
162
+ function pendingDependencies(root, item) {
163
+ const pending = [];
164
+ for (const dependency of item.dependencies) {
165
+ const { name, declared } = parseDependency(dependency);
166
+ const installed = installedVersion(root, name);
167
+ if (!installed || declared && !compatibleVersion(installed, declared))
168
+ pending.push({ name, declared, installed });
169
+ }
170
+ return pending;
171
+ }
172
+ var unavailable = /* @__PURE__ */ new Set([2307, 2688, 2882, 6053, 7016]);
173
+ var duplicatedTypes = (diagnostic) => ts2.flattenDiagnosticMessageText(diagnostic.messageText, " ").includes("Two different types with this name exist");
174
+ var describe = (diagnostic) => {
175
+ const position = diagnostic.file && diagnostic.start !== void 0 ? diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start) : null;
176
+ return `${diagnostic.file?.fileName ?? "TypeScript"}${position ? `:${position.line + 1}` : ""} TS${diagnostic.code}: ${ts2.flattenDiagnosticMessageText(diagnostic.messageText, " ")}`;
177
+ };
178
+ function readCompilerOptions(root, directory = ".") {
179
+ const config = ts2.findConfigFile(resolve(root, directory), ts2.sys.fileExists);
180
+ if (!config || relative2(root, config).startsWith(".."))
181
+ return { failure: "No tsconfig.json was found." };
182
+ const read = ts2.readConfigFile(config, ts2.sys.readFile);
183
+ if (read.error) return { failure: `Cannot read ${relative2(root, config)}.` };
184
+ return {
185
+ options: ts2.parseJsonConfigFileContent(read.config, ts2.sys, dirname2(config)).options
186
+ };
187
+ }
188
+ function createConsumerProgram(root, options, roots, virtual, pending) {
189
+ const host = ts2.createCompilerHost(options);
190
+ const originalRead = host.readFile.bind(host);
191
+ const originalExists = host.fileExists.bind(host);
192
+ const originalDirectories = host.directoryExists?.bind(host);
193
+ host.readFile = (file) => virtual.get(resolve(file)) ?? originalRead(file);
194
+ host.fileExists = (file) => virtual.has(resolve(file)) || originalExists(file);
195
+ host.directoryExists = (directory) => [...virtual.keys()].some(
196
+ (file) => file.startsWith(`${resolve(directory)}/`)
197
+ ) || Boolean(originalDirectories?.(directory));
198
+ const blocked = (specifier) => pending.some(
199
+ ({ name }) => specifier === name || specifier.startsWith(`${name}/`)
200
+ );
201
+ const cache = ts2.createModuleResolutionCache(
202
+ root,
203
+ host.getCanonicalFileName,
204
+ options
205
+ );
206
+ host.resolveModuleNameLiterals = (literals, containingFile, redirectedReference, compilerOptions, containingSourceFile) => literals.map(
207
+ (literal) => blocked(literal.text) ? { resolvedModule: void 0 } : ts2.resolveModuleName(
208
+ literal.text,
209
+ containingFile,
210
+ compilerOptions,
211
+ host,
212
+ cache,
213
+ redirectedReference,
214
+ ts2.getModeForUsageLocation(
215
+ containingSourceFile,
216
+ literal,
217
+ compilerOptions
218
+ )
219
+ )
220
+ );
221
+ host.getSourceFile = (file, languageVersion) => {
222
+ const content = host.readFile(file);
223
+ return content === void 0 ? void 0 : ts2.createSourceFile(file, content, languageVersion, true);
224
+ };
225
+ return ts2.createProgram(roots, options, host);
226
+ }
227
+ function diagnoseDependents(root, dependents, project) {
228
+ const loaded = readCompilerOptions(root, project);
229
+ if ("failure" in loaded || !dependents.length) return /* @__PURE__ */ new Set();
230
+ const options = {
231
+ ...loaded.options,
232
+ noEmit: true,
233
+ skipLibCheck: true
234
+ };
235
+ const program = createConsumerProgram(
236
+ root,
237
+ options,
238
+ dependents.map((file) => resolve(file)),
239
+ /* @__PURE__ */ new Map(),
240
+ []
241
+ );
242
+ return new Set(ts2.getPreEmitDiagnostics(program).map(describe));
243
+ }
244
+ async function checkCompatibility(root, item, installed = false, {
245
+ dependents = [],
246
+ known = /* @__PURE__ */ new Set(),
247
+ project
248
+ } = {}) {
249
+ const loaded = readCompilerOptions(root, project);
250
+ if ("failure" in loaded)
251
+ return {
252
+ status: "inconclusive",
253
+ diagnostics: [loaded.failure],
254
+ pending: [],
255
+ deferred: [],
256
+ existingFiles: []
257
+ };
258
+ const pending = installed ? [] : pendingDependencies(root, item);
259
+ const options = {
260
+ ...loaded.options,
261
+ noEmit: true,
262
+ skipLibCheck: true,
263
+ // Before installing, anything unavailable becomes any; the implicit any
264
+ // that follows is not a consumer incompatibility.
265
+ ...installed ? {} : { noImplicitAny: false }
266
+ };
267
+ const virtual = /* @__PURE__ */ new Map();
268
+ const existingFiles = [];
269
+ for (const file of item.files) {
270
+ if (!file.target?.startsWith("~/"))
271
+ throw new Error(`Invalid target: ${file.target}`);
272
+ const path = resolve(root, file.target.slice(2));
273
+ if (ts2.sys.fileExists(path)) existingFiles.push(path);
274
+ if (/\.tsx?$/.test(path)) {
275
+ const existingUI = !/^(patterns|blocks)\//.test(file.path) && ts2.sys.fileExists(path);
276
+ if (!installed && !existingUI) virtual.set(path, file.content);
277
+ }
278
+ }
279
+ const targets = item.files.map((file) => file.target).filter(
280
+ (target) => Boolean(target && /\.tsx?$/.test(target))
281
+ ).map((target) => resolve(root, target.slice(2)));
282
+ const roots = [
283
+ ...targets,
284
+ ...dependents.map((file) => resolve(file)).filter((file) => /\.tsx?$/.test(file) && !targets.includes(file))
285
+ ];
286
+ const program = createConsumerProgram(root, options, roots, virtual, pending);
287
+ const diagnostics = ts2.getPreEmitDiagnostics(program).filter((diagnostic) => !known.has(describe(diagnostic)));
288
+ const incompatible = diagnostics.some(
289
+ (diagnostic) => !unavailable.has(diagnostic.code) && !duplicatedTypes(diagnostic)
290
+ );
291
+ const pendingLines = pending.map(
292
+ ({ name, declared, installed: found }) => `${declared ? `${name}@${declared}` : name} is not installed yet${found ? ` (found ${found})` : ""}; its types are checked after installation.`
293
+ );
294
+ return {
295
+ status: incompatible ? "incompatible" : diagnostics.length ? "inconclusive" : "compatible",
296
+ diagnostics: [...pendingLines, ...diagnostics.map(describe)],
297
+ pending: pendingLines,
298
+ deferred: diagnostics.filter(
299
+ (diagnostic) => unavailable.has(diagnostic.code) || duplicatedTypes(diagnostic)
300
+ ).map(describe),
301
+ existingFiles
302
+ };
303
+ }
304
+
305
+ // packages/registry/src/config.ts
306
+ import { existsSync as existsSync4 } from "node:fs";
307
+ import { readFile as readFile2 } from "node:fs/promises";
308
+ import { dirname as dirname3, isAbsolute as isAbsolute2, join as join3, relative as relative4, resolve as resolve2 } from "node:path";
309
+ import ts4 from "typescript";
310
+
311
+ // packages/registry/src/manifest.ts
312
+ import { isAbsolute, normalize } from "node:path";
313
+ import ts3 from "typescript";
314
+ var patternNames = [
315
+ "collection",
316
+ "properties",
317
+ "editable",
318
+ "checklist",
319
+ "record-dialog",
320
+ "record-preview",
321
+ "record-group",
322
+ "record-status-list",
323
+ "widgets",
324
+ "stats",
325
+ "rich-text-editor",
326
+ "state-surface",
327
+ "settings",
328
+ "chats-panel",
329
+ "wizard",
330
+ "flow-canvas",
331
+ "flow-step-library",
332
+ "flow-inspector",
333
+ "chat-assistant",
334
+ "list",
335
+ "charts"
336
+ ];
337
+ var blockNames = [
338
+ "app-shell-1",
339
+ "app-shell-2",
340
+ "app-shell-3",
341
+ "app-shell-4",
342
+ "login-1",
343
+ "login-2",
344
+ "otp-1",
345
+ "signup-1",
346
+ "signup-2",
347
+ "reset-password-1",
348
+ "reset-password-2",
349
+ "forgot-password-1",
350
+ "forgot-password-2",
351
+ "workflow-editor",
352
+ "agent-builder",
353
+ "settings-1",
354
+ "settings-2",
355
+ "settings-3",
356
+ "settings-4",
357
+ "settings-5",
358
+ "settings-6",
359
+ "settings-7",
360
+ "settings-8",
361
+ "settings-9",
362
+ "settings-10",
363
+ "settings-11",
364
+ "settings-12",
365
+ "settings-13",
366
+ "settings-14",
367
+ "settings-15",
368
+ "settings-16",
369
+ "settings-17",
370
+ "settings-18",
371
+ "settings-19",
372
+ "settings-20",
373
+ "settings-21",
374
+ "settings-22",
375
+ "settings-23",
376
+ "stats-1",
377
+ "stats-2",
378
+ "stats-3",
379
+ "stats-4",
380
+ "stats-5",
381
+ "stats-6",
382
+ "stats-7",
383
+ "card-1",
384
+ "card-2",
385
+ "card-3",
386
+ "card-4",
387
+ "card-5",
388
+ "card-6",
389
+ "card-7",
390
+ "card-8",
391
+ "card-9",
392
+ "list-1",
393
+ "list-2",
394
+ "list-3",
395
+ "list-4",
396
+ "list-5",
397
+ "list-6",
398
+ "empty-state-1",
399
+ "empty-state-2",
400
+ "empty-state-3",
401
+ "empty-state-4",
402
+ "empty-state-5",
403
+ "empty-state-6",
404
+ "timeline-1",
405
+ "timeline-2",
406
+ "timeline-3",
407
+ "timeline-4",
408
+ "navbar-1",
409
+ "navbar-2",
410
+ "navbar-3",
411
+ "navbar-4",
412
+ "navbar-5",
413
+ "onboarding-1",
414
+ "onboarding-2",
415
+ "onboarding-3",
416
+ "dashboard-1",
417
+ "dashboard-2",
418
+ "dashboard-3",
419
+ "dashboard-4",
420
+ "login-3",
421
+ "login-4",
422
+ "login-5",
423
+ "login-6",
424
+ "login-7",
425
+ "login-8",
426
+ "login-9",
427
+ "login-10",
428
+ "signup-3",
429
+ "signup-6",
430
+ "reset-password-6",
431
+ "magic-link-6",
432
+ "run-monitor",
433
+ "impact-map"
434
+ ];
435
+ function isBlock(name) {
436
+ return blockNames.includes(name);
437
+ }
438
+ var aliasNames = [
439
+ "ui",
440
+ "utils",
441
+ "hooks",
442
+ "lib",
443
+ "helpers",
444
+ "patterns",
445
+ "blocks"
446
+ ];
447
+ var pathNames = ["ui", "hooks", "lib", "helpers", "patterns"];
448
+ var distributedLayers = ["patterns", "helpers", "blocks"];
449
+ var isDistributedLayer = (value) => distributedLayers.includes(value);
450
+ function repoImportAlias(specifier) {
451
+ if (specifier === "@tc96/utils" || specifier.startsWith("@tc96/utils/"))
452
+ return { alias: "utils", rest: specifier.slice("@tc96/utils".length) };
453
+ const rest = specifier.match(/^@tc96\/ui(\/.*)$/)?.[1];
454
+ if (!rest) return void 0;
455
+ const [, layer = "", tail = ""] = rest.match(/^\/([^/]+)(\/.*)?$/) ?? [];
456
+ if (isDistributedLayer(layer) || layer === "hooks" || layer === "lib")
457
+ return { alias: layer, rest: tail };
458
+ return { alias: "ui", rest };
459
+ }
460
+ function selectItems(names) {
461
+ if (!names.length) throw new Error("Choose at least one pattern or block.");
462
+ return [
463
+ ...new Set(
464
+ names.map((name) => {
465
+ const resolved = name === "view" ? "collection" : name;
466
+ if (!patternNames.includes(resolved) && !isBlock(resolved))
467
+ throw new Error(`Unknown pattern or block: ${name}`);
468
+ return resolved;
469
+ })
470
+ )
471
+ ];
472
+ }
473
+ function validateConfig(value) {
474
+ for (const name of aliasNames) {
475
+ const alias = value.aliases?.[name];
476
+ if (typeof alias !== "string" || !/^[@#a-zA-Z]/.test(alias))
477
+ throw new Error(`Invalid ${name} alias.`);
478
+ }
479
+ for (const name of [...pathNames, "blocks"]) {
480
+ const destination = value.paths?.[name];
481
+ if (name === "blocks" && destination === void 0) continue;
482
+ if (typeof destination !== "string")
483
+ throw new Error(`Invalid ${name} path.`);
484
+ const path = normalize(destination).replaceAll("\\", "/");
485
+ if (isAbsolute(path) || path === "." || path.startsWith("../") || path.includes("/node_modules/")) {
486
+ throw new Error(`${name} path must be inside the consumer workspace.`);
487
+ }
488
+ }
489
+ return value;
490
+ }
491
+ function assertDistributable(item) {
492
+ for (const file of item.files) {
493
+ const [layer = ""] = file.path.split("/");
494
+ if (!isDistributedLayer(layer))
495
+ throw new Error(
496
+ `${item.name}: ${file.path} belongs to the consumer and is not distributed.`
497
+ );
498
+ const theme = file.content.match(/:root|\.dark\b|@theme|@utility/);
499
+ if (theme)
500
+ throw new Error(
501
+ `${item.name}: ${file.path} redefines the theme (${theme[0]}).`
502
+ );
503
+ }
504
+ }
505
+ function prepareItem(item, configuration) {
506
+ const config = validateConfig(configuration);
507
+ assertDistributable(item);
508
+ const destinations = {
509
+ patterns: config.paths.patterns,
510
+ helpers: config.paths.helpers,
511
+ blocks: config.paths.blocks
512
+ };
513
+ return {
514
+ ...item,
515
+ $schema: "https://ui.shadcn.com/schema/registry-item.json",
516
+ files: item.files.map((file) => {
517
+ const [layer = "", ...suffix] = file.path.split("/");
518
+ const destination = isDistributedLayer(layer) ? destinations[layer] : void 0;
519
+ if (!destination || !suffix.length || suffix.includes(".."))
520
+ throw new Error(`Invalid registry path: ${file.path}`);
521
+ const ast = ts3.createSourceFile(
522
+ file.path,
523
+ file.content,
524
+ ts3.ScriptTarget.Latest,
525
+ true
526
+ );
527
+ const edits = [];
528
+ function visit(node) {
529
+ if ((ts3.isImportDeclaration(node) || ts3.isExportDeclaration(node)) && node.moduleSpecifier && ts3.isStringLiteral(node.moduleSpecifier)) {
530
+ const match = repoImportAlias(node.moduleSpecifier.text);
531
+ if (match)
532
+ edits.push({
533
+ start: node.moduleSpecifier.getStart(ast) + 1,
534
+ end: node.moduleSpecifier.getEnd() - 1,
535
+ value: config.aliases[match.alias] + match.rest
536
+ });
537
+ }
538
+ ts3.forEachChild(node, visit);
539
+ }
540
+ visit(ast);
541
+ let content = file.content;
542
+ for (const edit of edits.sort((a, b) => b.start - a.start))
543
+ content = content.slice(0, edit.start) + edit.value + content.slice(edit.end);
544
+ return {
545
+ ...file,
546
+ content,
547
+ type: "registry:file",
548
+ target: `~/${destination}/${suffix.join("/")}`
549
+ };
550
+ })
551
+ };
552
+ }
553
+ function combineItems(items) {
554
+ const files = /* @__PURE__ */ new Map();
555
+ for (const item of items)
556
+ for (const file of item.files) {
557
+ const existing = files.get(file.path);
558
+ if (existing && existing.content !== file.content)
559
+ throw new Error(`Conflicting shared file: ${file.path}`);
560
+ files.set(file.path, file);
561
+ }
562
+ return {
563
+ name: "tc96-selected-patterns",
564
+ type: "registry:block",
565
+ files: [...files.values()].sort((a, b) => a.path.localeCompare(b.path)),
566
+ dependencies: [
567
+ ...new Set(items.flatMap((item) => item.dependencies))
568
+ ].sort(),
569
+ registryDependencies: [
570
+ ...new Set(items.flatMap((item) => item.registryDependencies ?? []))
571
+ ].sort()
572
+ };
573
+ }
574
+ function omitInstalled(item, installed) {
575
+ return {
576
+ ...item,
577
+ registryDependencies: (item.registryDependencies ?? []).filter(
578
+ (dependency) => {
579
+ const [, component] = dependency.match(/^@ui\/(.+)$/) ?? [];
580
+ return !component || !installed(component);
581
+ }
582
+ )
583
+ };
584
+ }
585
+
586
+ // packages/registry/src/workspace.ts
587
+ import { existsSync as existsSync3, readdirSync, readFileSync as readFileSync2, writeFileSync } from "node:fs";
588
+ import { join as join2, relative as relative3 } from "node:path";
589
+ function readJson(path) {
590
+ try {
591
+ return JSON.parse(readFileSync2(path, "utf8"));
592
+ } catch {
593
+ return void 0;
594
+ }
595
+ }
596
+ function workspaceGlobs(root) {
597
+ const workspaces = readJson(join2(root, "package.json"))?.workspaces;
598
+ const globs = Array.isArray(workspaces) ? workspaces : workspaces?.packages;
599
+ return Array.isArray(globs) ? globs.filter((glob) => typeof glob === "string") : [];
600
+ }
601
+ function expand(root, glob) {
602
+ const clean = glob.replace(/^\.\//, "").replace(/\/$/, "");
603
+ if (!clean.endsWith("/*")) return [clean];
604
+ const parent = clean.slice(0, -2);
605
+ if (!existsSync3(join2(root, parent))) return [];
606
+ return readdirSync(join2(root, parent), { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => `${parent}/${entry.name}`);
607
+ }
608
+ function workspacePackages(root) {
609
+ return workspaceGlobs(root).flatMap((glob) => expand(root, glob)).flatMap((directory) => {
610
+ const manifest = readJson(join2(root, directory, "package.json"));
611
+ return typeof manifest?.name === "string" ? [{ directory, name: manifest.name, exports: manifest.exports }] : [];
612
+ });
613
+ }
614
+ function exportTarget(value) {
615
+ if (typeof value === "string") return value;
616
+ if (!value || typeof value !== "object") return void 0;
617
+ const conditions = value;
618
+ for (const key of ["types", "import", "default"])
619
+ if (typeof conditions[key] === "string") return conditions[key];
620
+ return Object.values(conditions).map(exportTarget).find(Boolean);
621
+ }
622
+ function exportedAliasPath(root, alias) {
623
+ const owner = workspacePackages(root).filter(({ name }) => alias === name || alias.startsWith(`${name}/`)).sort((a, b) => b.name.length - a.name.length)[0];
624
+ if (!owner?.exports || typeof owner.exports !== "object") return void 0;
625
+ const subpath = `.${alias.slice(owner.name.length)}`;
626
+ const target = exportTarget(
627
+ owner.exports[`${subpath}/*`]
628
+ );
629
+ const prefix = target?.slice(0, target.indexOf("*"));
630
+ if (!prefix?.endsWith("/")) return void 0;
631
+ const path = relative3(root, join2(root, owner.directory, prefix));
632
+ return path.replaceAll("\\", "/");
633
+ }
634
+ function addFolderExports(root, alias, names) {
635
+ const directory = exportedAliasPath(root, alias);
636
+ const owner = workspacePackages(root).filter(({ name }) => alias === name || alias.startsWith(`${name}/`)).sort((a, b) => b.name.length - a.name.length)[0];
637
+ if (!directory || !owner) return [];
638
+ const manifestPath = join2(root, owner.directory, "package.json");
639
+ const manifest = JSON.parse(readFileSync2(manifestPath, "utf8"));
640
+ const exports = manifest.exports;
641
+ const subpath = `.${alias.slice(owner.name.length)}`;
642
+ const added = [];
643
+ for (const name of names) {
644
+ const key = `${subpath}/${name}`;
645
+ if (key in exports || !existsSync3(join2(root, directory, name, "index.ts")))
646
+ continue;
647
+ const target = relative3(
648
+ join2(root, owner.directory),
649
+ join2(root, directory, name, "index.ts")
650
+ );
651
+ exports[key] = `./${target.replaceAll("\\", "/")}`;
652
+ added.push(key);
653
+ }
654
+ if (added.length)
655
+ writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}
656
+ `);
657
+ return added;
658
+ }
659
+
660
+ // packages/registry/src/config.ts
661
+ var requiredAliasNames = ["ui", "utils"];
662
+ var rawAliases = (components) => components?.aliases ?? {};
663
+ var isAlias = (value) => typeof value === "string" && value !== "";
664
+ var deriveAlias = (ui, name) => ui.includes("/") ? `${ui.slice(0, ui.lastIndexOf("/"))}/${name}` : name;
665
+ function readAliases(components) {
666
+ const aliases = rawAliases(components);
667
+ const missing = requiredAliasNames.filter((name) => !isAlias(aliases[name]));
668
+ if (missing.length)
669
+ throw new Error(
670
+ `components.json is missing ${missing.map((name) => `aliases.${name}`).join(", ")}. tc96 needs the ui and utils aliases that shadcn init writes. shadcn init --force rewrites components.json; review the ui alias.`
671
+ );
672
+ const { ui, utils } = aliases;
673
+ const pick = (name) => {
674
+ const alias = aliases[name];
675
+ if (isAlias(alias)) return alias;
676
+ if (name === "blocks" && isAlias(aliases.templates))
677
+ return aliases.templates;
678
+ return deriveAlias(ui, name);
679
+ };
680
+ const child = (name) => {
681
+ const alias = aliases[name];
682
+ return isAlias(alias) ? alias : `${ui}/${name}`;
683
+ };
684
+ return {
685
+ ui,
686
+ utils,
687
+ hooks: child("hooks"),
688
+ lib: child("lib"),
689
+ helpers: pick("helpers"),
690
+ patterns: pick("patterns"),
691
+ blocks: pick("blocks")
692
+ };
693
+ }
694
+ function resolveAliasPath(root, alias, options, suggestion) {
695
+ const pattern = options.paths?.[`${alias}/*`]?.[0];
696
+ if (!pattern?.endsWith("/*")) {
697
+ const exported = exportedAliasPath(root, alias);
698
+ if (exported && !exported.startsWith("..")) return exported;
699
+ throw new Error(
700
+ `Cannot find where "${alias}" points. Export "${alias}/*" from the workspace package that owns it (tc96 init adds the tc96 exports), or add a tsconfig.json paths entry${suggestion ? `, e.g. "${alias}/*": ["${suggestion}/*"]` : ""}.`
701
+ );
702
+ }
703
+ const base = options.baseUrl ?? options.pathsBasePath ?? root;
704
+ const path = relative4(root, resolve2(base, pattern.slice(0, -2)));
705
+ if (!path || path.startsWith("..") || isAbsolute2(path))
706
+ throw new Error(`"${alias}/*" must resolve inside the consumer workspace.`);
707
+ return path.replaceAll("\\", "/");
708
+ }
709
+ function findAliasPath(root, alias, options) {
710
+ try {
711
+ return resolveAliasPath(root, alias, options);
712
+ } catch {
713
+ return void 0;
714
+ }
715
+ }
716
+ function findProjectRoot(start) {
717
+ let directory = resolve2(start);
718
+ while (!existsSync4(join3(directory, "components.json"))) {
719
+ const parent = dirname3(directory);
720
+ if (parent === directory) return resolve2(start);
721
+ directory = parent;
722
+ }
723
+ return directory;
724
+ }
725
+ async function readProject(root) {
726
+ const componentsPath = join3(root, "components.json");
727
+ if (!existsSync4(componentsPath))
728
+ throw new Error(
729
+ `No components.json found in ${root} or any parent directory. Run tc96 init at the monorepo root, or pass --cwd with the directory that holds it.`
730
+ );
731
+ const components = JSON.parse(await readFile2(componentsPath, "utf8"));
732
+ const aliases = readAliases(components);
733
+ const tsconfig = join3(root, "tsconfig.json");
734
+ if (!existsSync4(tsconfig)) return { components, aliases, options: {} };
735
+ const read = ts4.readConfigFile(tsconfig, ts4.sys.readFile);
736
+ if (read.error) throw new Error("Cannot read the consumer tsconfig.json.");
737
+ const { options } = ts4.parseJsonConfigFileContent(read.config, ts4.sys, root);
738
+ return { components, aliases, options };
739
+ }
740
+ function locateBlocks({ components, aliases, options }, root) {
741
+ const raw = rawAliases(components);
742
+ const path = findAliasPath(root, aliases.blocks, options);
743
+ const derived = !isAlias(raw.blocks) && !isAlias(raw.templates);
744
+ if (path !== void 0 || !derived) return { alias: aliases.blocks, path };
745
+ const templates = deriveAlias(aliases.ui, "templates");
746
+ const templatesPath = findAliasPath(root, templates, options);
747
+ if (options.paths?.[`${aliases.blocks}/*`] || templatesPath === void 0)
748
+ return { alias: aliases.blocks, path };
749
+ return {
750
+ alias: templates,
751
+ path: templatesPath,
752
+ legacy: { templates, blocks: aliases.blocks }
753
+ };
754
+ }
755
+ async function findBlocksPath(root) {
756
+ try {
757
+ return locateBlocks(await readProject(root), root).path;
758
+ } catch {
759
+ return void 0;
760
+ }
761
+ }
762
+ function legacyWarnings(root, { components, aliases, options }) {
763
+ const raw = rawAliases(components);
764
+ const warnings = [];
765
+ if (!isAlias(raw.blocks) && isAlias(raw.templates))
766
+ warnings.push(
767
+ "components.json aliases.templates is deprecated; rename it to aliases.blocks."
768
+ );
769
+ const elements = isAlias(raw.elements) ? raw.elements : deriveAlias(aliases.ui, "elements");
770
+ const elementsPath = findAliasPath(root, elements, options);
771
+ if (isAlias(raw.elements) || elementsPath !== void 0 && existsSync4(join3(root, elementsPath)))
772
+ warnings.push(
773
+ `tc96 no longer installs elements: Text and IconFrame come from your ui alias (${aliases.ui}/text, ${aliases.ui}/icon-frame). Files in ${elementsPath ?? elements} from earlier installs are no longer imported by tc96 patterns; remove them once your code stops importing them.`
774
+ );
775
+ return warnings;
776
+ }
777
+ async function readInstallConfig(root, { blocks = false } = {}) {
778
+ const project = await readProject(root);
779
+ const { aliases, options } = project;
780
+ const warnings = legacyWarnings(root, project);
781
+ const uiPath = resolveAliasPath(root, aliases.ui, options);
782
+ const uiSegments = uiPath.split("/");
783
+ const nested = aliases.ui.split("/").at(-1) === uiSegments.at(-1);
784
+ const suggestPath = (name) => nested ? [...uiSegments.slice(0, -1), name].join("/") : uiSegments.map((segment) => segment === "ui" ? name : segment).join("/");
785
+ const resolveSibling = (name) => resolveAliasPath(root, aliases[name], options, `./${suggestPath(name)}`);
786
+ const resolveChild = (name) => {
787
+ const path = findAliasPath(root, aliases[name], options);
788
+ if (path !== void 0) return path;
789
+ aliases[name] = `${aliases.ui}/${name}`;
790
+ return `${uiPath}/${name}`;
791
+ };
792
+ const paths = Object.fromEntries(
793
+ pathNames.map((name) => [
794
+ name,
795
+ name === "ui" ? uiPath : name === "hooks" || name === "lib" ? resolveChild(name) : resolveSibling(name)
796
+ ])
797
+ );
798
+ if (blocks) {
799
+ const location = locateBlocks(project, root);
800
+ if (location.legacy && location.path !== void 0) {
801
+ aliases.blocks = location.alias;
802
+ paths.blocks = location.path;
803
+ warnings.push(
804
+ `tsconfig.json paths has "${location.legacy.templates}/*" but no "${location.legacy.blocks}/*"; blocks are written to the templates path for now. Rename the entry to "${location.legacy.blocks}/*".`
805
+ );
806
+ } else paths.blocks = resolveSibling("blocks");
807
+ }
808
+ return { ...validateConfig({ aliases, paths }), warnings };
809
+ }
810
+ async function readStylesheet(root) {
811
+ const components = JSON.parse(
812
+ await readFile2(join3(root, "components.json"), "utf8")
813
+ );
814
+ const css = components?.tailwind?.css;
815
+ return typeof css === "string" && css ? css : void 0;
816
+ }
817
+
818
+ // packages/registry/src/coss.ts
819
+ import { readFile as readFile3 } from "node:fs/promises";
820
+ import { join as join4 } from "node:path";
821
+ function normalizeImports(content, aliases = { ui: "@tc96/ui", utils: "@tc96/utils" }) {
822
+ const hooks = aliases.hooks ?? `${aliases.ui}/hooks`;
823
+ const lib = aliases.lib ?? `${aliases.ui}/lib`;
824
+ return content.replace(
825
+ /(["'])@\/(?:registry\/default\/)?lib\/utils\1/g,
826
+ `$1${aliases.utils}$1`
827
+ ).replace(/(["'])@\/registry\/default\/hooks\//g, `$1${hooks}/`).replace(/(["'])@\/registry\/default\/lib\//g, `$1${lib}/`).replace(
828
+ /(["'])@\/registry\/default\/(?:ui\/)?([^"']+)\1/g,
829
+ `$1${aliases.ui}/$2$1`
830
+ ).replace(/(["'])@tc96\/utils\1/g, `$1${aliases.utils}$1`).replace(/(["'])@tc96\/ui\/hooks\//g, `$1${hooks}/`).replace(/(["'])@tc96\/ui\/lib\//g, `$1${lib}/`).replace(/(["'])@tc96\/ui\//g, `$1${aliases.ui}/`);
831
+ }
832
+ function cossInstalledPaths(name, directories = {
833
+ ui: ".",
834
+ hooks: "hooks"
835
+ }) {
836
+ return [
837
+ `${directories.ui}/${name}.tsx`,
838
+ `${directories.hooks}/${name}.ts`,
839
+ `${directories.ui}/${name}`
840
+ ].map((path) => path.replace(/^\.\//, ""));
841
+ }
842
+ function cossTarget(path, directories) {
843
+ const [, folder, rest] = path.match(/^(hooks|lib)\/(.+)$/) ?? [];
844
+ if (folder === "hooks" || folder === "lib")
845
+ return `${directories[folder]}/${rest}`;
846
+ return `${directories.ui}/${path}`;
847
+ }
848
+ function cossPath(item, path) {
849
+ const relative6 = path.match(/^registry\/default\/(?:ui\/)?(.+)$/)?.[1];
850
+ if (!relative6) throw new Error(`${item}: ${path} is outside registry/default`);
851
+ if (relative6 === "lib/utils.ts")
852
+ throw new Error(`${item}: lib/utils.ts is the consumer's own utils`);
853
+ return relative6;
854
+ }
855
+ async function loadUiItem(registryDirectory, name) {
856
+ try {
857
+ return JSON.parse(
858
+ await readFile3(join4(registryDirectory, "ui", `${name}.json`), "utf8")
859
+ );
860
+ } catch (error) {
861
+ if (error.code === "ENOENT")
862
+ throw new Error(`Unknown ui component: ${name}`);
863
+ throw error;
864
+ }
865
+ }
866
+ async function resolveItems(dependencies, load, installed) {
867
+ const queue = [...dependencies];
868
+ const items = /* @__PURE__ */ new Map();
869
+ while (queue.length) {
870
+ const dependency = queue.shift();
871
+ const [, name] = dependency.match(/^(?:@(?:coss|ui)\/)?([a-z0-9-]+)$/) ?? [];
872
+ if (!name)
873
+ throw new Error(`Unsupported ui registry dependency: ${dependency}`);
874
+ if (items.has(name) || installed(name)) continue;
875
+ const item = await load(name);
876
+ if (item.name !== name)
877
+ throw new Error(`ui item ${name} is published as ${item.name}`);
878
+ items.set(name, item);
879
+ queue.push(...item.registryDependencies ?? []);
880
+ }
881
+ return [...items.values()].sort((a, b) => a.name.localeCompare(b.name));
882
+ }
883
+ function componentFiles(item, aliases, directories) {
884
+ for (const key of ["envVars", "devDependencies", "tailwind"]) {
885
+ const value = item[key];
886
+ if (value && Object.keys(value).length)
887
+ throw new Error(`${item.name}: COSS items with ${key} are not supported`);
888
+ }
889
+ if (!item.files.length) throw new Error(`${item.name}: has no files`);
890
+ return item.files.map((file) => {
891
+ const path = cossPath(item.name, file.path);
892
+ const content = normalizeImports(file.content, aliases);
893
+ const unresolved = content.match(/(["'])(@\/[^"']*)\1/);
894
+ if (unresolved)
895
+ throw new Error(
896
+ `${item.name}: import ${unresolved[2]} in ${path} has no alias`
897
+ );
898
+ return {
899
+ path: `ui/${path}`,
900
+ type: "registry:ui",
901
+ content,
902
+ target: `~/${cossTarget(path, directories)}`
903
+ };
904
+ });
905
+ }
906
+ function cssRule(selector, body, indent = "") {
907
+ if (typeof body !== "object" || body === null)
908
+ return `${indent}${selector}: ${String(body)};`;
909
+ const inner = Object.entries(body).map(([key, value]) => cssRule(key, value, `${indent} `)).join("\n");
910
+ return `${indent}${selector} {
911
+ ${inner}
912
+ ${indent}}`;
913
+ }
914
+ function missingTheme(items, stylesheet2) {
915
+ const defined = (name) => stylesheet2?.includes(name) ?? false;
916
+ const result = [];
917
+ for (const item of items) {
918
+ const rules = [];
919
+ for (const [section, selector] of [
920
+ ["light", ":root"],
921
+ ["dark", ".dark"],
922
+ ["theme", "@theme"]
923
+ ]) {
924
+ const entries = Object.entries(item.cssVars?.[section] ?? {}).map(([name, value]) => [
925
+ name.startsWith("--") ? name : `--${name}`,
926
+ value
927
+ ]).filter(([name]) => !defined(`${name}:`));
928
+ if (entries.length)
929
+ rules.push(cssRule(selector, Object.fromEntries(entries)));
930
+ }
931
+ for (const [selector, body] of Object.entries(item.css ?? {}))
932
+ if (!defined(selector)) rules.push(cssRule(selector, body));
933
+ if (rules.length) result.push({ item: item.name, rules });
934
+ }
935
+ return result;
936
+ }
937
+
938
+ // packages/registry/src/files.ts
939
+ import { existsSync as existsSync5 } from "node:fs";
940
+ import { mkdir, readdir, readFile as readFile4, writeFile as writeFile2 } from "node:fs/promises";
941
+ import { dirname as dirname4, join as join5, resolve as resolve3 } from "node:path";
942
+ function targetPath(workspace, target) {
943
+ if (!target?.startsWith("~/"))
944
+ throw new Error(`Invalid registry target: ${target ?? "missing"}`);
945
+ return resolve3(workspace, target.slice(2));
946
+ }
947
+ async function planFiles(workspace, files) {
948
+ return Promise.all(
949
+ files.map(async (file) => {
950
+ const path = targetPath(workspace, file.target);
951
+ if (!existsSync5(path))
952
+ return { path, content: file.content, status: "create" };
953
+ const current = await readFile4(path, "utf8");
954
+ return {
955
+ path,
956
+ content: file.content,
957
+ current,
958
+ status: current === file.content ? "unchanged" : "conflict"
959
+ };
960
+ })
961
+ );
962
+ }
963
+ async function writeFiles(planned, confirm) {
964
+ const written = [];
965
+ const preserved = [];
966
+ for (const file of planned) {
967
+ if (file.status === "unchanged") continue;
968
+ if (file.status === "conflict" && !await confirm?.(file.path)) {
969
+ preserved.push(file.path);
970
+ continue;
971
+ }
972
+ await mkdir(dirname4(file.path), { recursive: true });
973
+ await writeFile2(file.path, file.content);
974
+ written.push(file.path);
975
+ }
976
+ return { written, preserved };
977
+ }
978
+ function diffLines(before, after, context = 2) {
979
+ const a = before.split("\n");
980
+ const b = after.split("\n");
981
+ const common = Array.from(
982
+ { length: a.length + 1 },
983
+ () => new Uint32Array(b.length + 1)
984
+ );
985
+ const at = (i2, j2) => common[i2]?.[j2] ?? 0;
986
+ for (let i2 = a.length - 1; i2 >= 0; i2--)
987
+ for (let j2 = b.length - 1; j2 >= 0; j2--)
988
+ common[i2][j2] = a[i2] === b[j2] ? at(i2 + 1, j2 + 1) + 1 : Math.max(at(i2 + 1, j2), at(i2, j2 + 1));
989
+ const lines = [];
990
+ let i = 0;
991
+ let j = 0;
992
+ while (i < a.length || j < b.length) {
993
+ if (i < a.length && j < b.length && a[i] === b[j]) {
994
+ lines.push(` ${a[i++]}`);
995
+ j++;
996
+ } else if (j >= b.length || i < a.length && at(i + 1, j) >= at(i, j + 1))
997
+ lines.push(`-${a[i++]}`);
998
+ else lines.push(`+${b[j++]}`);
999
+ }
1000
+ const changed = lines.map((line) => !line.startsWith(" "));
1001
+ const output = [];
1002
+ let skipped = false;
1003
+ lines.forEach((line, index) => {
1004
+ const near = changed.slice(Math.max(0, index - context), index + context + 1).some(Boolean);
1005
+ if (near) {
1006
+ if (skipped && output.length) output.push("@@");
1007
+ output.push(line);
1008
+ skipped = false;
1009
+ } else skipped = true;
1010
+ });
1011
+ return output.join("\n");
1012
+ }
1013
+ async function sourceFiles(directory) {
1014
+ if (!existsSync5(directory)) return [];
1015
+ const found = [];
1016
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
1017
+ const path = join5(directory, entry.name);
1018
+ if (entry.isDirectory()) {
1019
+ if (entry.name !== "node_modules")
1020
+ found.push(...await sourceFiles(path));
1021
+ } else if (/\.tsx?$/.test(entry.name)) found.push(path);
1022
+ }
1023
+ return found;
1024
+ }
1025
+
1026
+ // packages/registry/src/init.ts
1027
+ import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
1028
+ import { writeFile as writeFile3 } from "node:fs/promises";
1029
+ import { join as join6 } from "node:path";
1030
+ var uiPackage = "packages/ui";
1031
+ var utilsPackage = "packages/utils";
1032
+ var stylesheet = "packages/ui/src/styles/globals.css";
1033
+ var layerExports = {
1034
+ "./*": "./src/components/*.tsx",
1035
+ "./hooks/*": "./src/hooks/*.ts",
1036
+ "./lib/*": "./src/lib/*.ts",
1037
+ "./helpers/*": "./src/helpers/*.ts",
1038
+ "./patterns": "./src/patterns/index.ts",
1039
+ "./patterns/*/core": "./src/patterns/*/core.ts",
1040
+ "./patterns/*": "./src/patterns/*.tsx",
1041
+ "./blocks/*": "./src/blocks/*/index.ts"
1042
+ };
1043
+ function packageName(root, directory) {
1044
+ const path = join6(root, directory, "package.json");
1045
+ if (!existsSync6(path)) return void 0;
1046
+ const name = JSON.parse(readFileSync3(path, "utf8")).name;
1047
+ return typeof name === "string" ? name : void 0;
1048
+ }
1049
+ function defaultComponents(root, ui, utils) {
1050
+ return {
1051
+ $schema: "https://ui.shadcn.com/schema.json",
1052
+ style: "new-york",
1053
+ rsc: false,
1054
+ tsx: true,
1055
+ tailwind: {
1056
+ config: "",
1057
+ css: existsSync6(join6(root, stylesheet)) ? stylesheet : "",
1058
+ baseColor: "neutral",
1059
+ cssVariables: true
1060
+ },
1061
+ aliases: {
1062
+ components: ui,
1063
+ ui,
1064
+ utils,
1065
+ lib: `${ui}/lib`,
1066
+ hooks: `${ui}/hooks`,
1067
+ helpers: `${ui}/helpers`,
1068
+ patterns: `${ui}/patterns`,
1069
+ blocks: `${ui}/blocks`
1070
+ }
1071
+ };
1072
+ }
1073
+ async function init(root) {
1074
+ const ui = packageName(root, uiPackage);
1075
+ const utils = packageName(root, utilsPackage);
1076
+ const missing = [
1077
+ !ui && `${uiPackage}/package.json`,
1078
+ !utils && `${utilsPackage}/package.json`
1079
+ ].filter(Boolean);
1080
+ if (missing.length)
1081
+ throw new Error(
1082
+ `tc96 init expects the tc96-mono layout and cannot find ${missing.join(" and ")}. Create the ${uiPackage} package (@tc96/ui) and the ${utilsPackage} package (@tc96/utils, exporting cn), or write components.json yourself to install elsewhere.`
1083
+ );
1084
+ const warnings = [];
1085
+ const componentsPath = join6(root, "components.json");
1086
+ const created = !existsSync6(componentsPath);
1087
+ if (created)
1088
+ await writeFile3(
1089
+ componentsPath,
1090
+ `${JSON.stringify(defaultComponents(root, ui, utils), null, 2)}
1091
+ `
1092
+ );
1093
+ const configuredUi = JSON.parse(readFileSync3(componentsPath, "utf8"))?.aliases?.ui;
1094
+ const exportsAdded = [];
1095
+ if (configuredUi === ui) {
1096
+ const manifestPath = join6(root, uiPackage, "package.json");
1097
+ const manifest = JSON.parse(readFileSync3(manifestPath, "utf8"));
1098
+ const exports = manifest.exports && typeof manifest.exports === "object" ? manifest.exports : {};
1099
+ for (const [key, target] of Object.entries(layerExports))
1100
+ if (!(key in exports)) {
1101
+ exports[key] = target;
1102
+ exportsAdded.push(key);
1103
+ }
1104
+ if (exportsAdded.length)
1105
+ await writeFile3(
1106
+ manifestPath,
1107
+ `${JSON.stringify({ ...manifest, exports }, null, 2)}
1108
+ `
1109
+ );
1110
+ } else
1111
+ warnings.push(
1112
+ `components.json points ui to ${configuredUi}, not to ${uiPackage} (${ui}); its exports were left alone. Make each alias resolve through tsconfig paths or package exports.`
1113
+ );
1114
+ const listed = new Set(
1115
+ workspacePackages(root).map(({ directory }) => directory)
1116
+ );
1117
+ for (const directory of [uiPackage, utilsPackage])
1118
+ if (!listed.has(directory))
1119
+ warnings.push(
1120
+ `${directory} is not in the root package.json workspaces; add it so the aliases resolve.`
1121
+ );
1122
+ return {
1123
+ components: created ? "created" : "kept",
1124
+ exportsAdded,
1125
+ warnings
1126
+ };
1127
+ }
1128
+
1129
+ // packages/registry/src/cli.ts
1130
+ var help = `tc96 init [--cwd path]
1131
+ Writes components.json with the tc96-mono layout when it is missing: ui, hooks, lib, helpers, patterns and blocks in packages/ui (@tc96/ui), cn in packages/utils (@tc96/utils). Edit its aliases to install elsewhere. Adds the layer exports packages/ui/package.json lacks.
1132
+
1133
+ tc96 add <patterns or blocks...> [--cwd path] [--dry-run] [--diff] [--view] [--yes] [--force]
1134
+ Patterns: ${patternNames.join(" ")}
1135
+ Blocks: ${blockNames.join(" ")}
1136
+ Reads the aliases from the nearest components.json, searching from --cwd up to the filesystem root. Each alias resolves through tsconfig paths or, without them, through the exports of the workspace package that owns it. hooks and lib default to children of ui; helpers, patterns and blocks replace the last segment of the ui alias (@acme/ui/components gives @acme/ui/patterns) unless set; the blocks path is needed only to install a block.
1137
+ Installs only the ui components missing from the ui alias, from this package. Their theme tokens are listed, never written to your CSS.
1138
+ Stops before installing when the patterns do not type-check against your components, in a dry run too; --force installs anyway.
1139
+ Existing files that differ are preserved; in a terminal the CLI asks before overwriting each one, unless --yes.
1140
+ Installs the missing npm dependencies with the package manager of your lockfile, into the workspace package that holds the patterns path.
1141
+ --dry-run lists what would change, --view prints the new files and --diff the changes to existing ones; none of them writes.
1142
+ Writes index.ts at the patterns path, exporting every installed pattern.
1143
+ `;
1144
+ async function main() {
1145
+ const args = process.argv.slice(2);
1146
+ if (!args.length || args.includes("--help") || args.includes("-h")) {
1147
+ console.log(help);
1148
+ return;
1149
+ }
1150
+ const command = args.shift();
1151
+ if (command === "init") {
1152
+ const cwdIndex = args.indexOf("--cwd");
1153
+ const unknown = args.filter(
1154
+ (argument, index) => argument !== "--cwd" && !(cwdIndex !== -1 && index === cwdIndex + 1)
1155
+ );
1156
+ if (unknown.length) throw new Error(`Unsupported option: ${unknown[0]}`);
1157
+ const value = cwdIndex === -1 ? void 0 : args[cwdIndex + 1];
1158
+ if (cwdIndex !== -1 && (!value || value.startsWith("--")))
1159
+ throw new Error("Missing value for --cwd");
1160
+ const result2 = await init(resolve4(value ?? process.cwd()));
1161
+ for (const warning of result2.warnings) console.warn(warning);
1162
+ console.log(
1163
+ result2.components === "created" ? "Wrote components.json with the tc96-mono layout; edit its aliases to install elsewhere." : "Kept the existing components.json."
1164
+ );
1165
+ console.log(
1166
+ result2.exportsAdded.length ? `Added to packages/ui/package.json exports: ${result2.exportsAdded.join(", ")}.` : "packages/ui/package.json already exports every layer."
1167
+ );
1168
+ return;
1169
+ }
1170
+ if (command !== "add") throw new Error(help);
1171
+ let cwd = process.cwd();
1172
+ let registryDirectory = join7(
1173
+ dirname5(fileURLToPath(import.meta.url)),
1174
+ "registry"
1175
+ );
1176
+ const names = [];
1177
+ const flags = /* @__PURE__ */ new Set();
1178
+ let force = false;
1179
+ for (let i = 0; i < args.length; i++) {
1180
+ const argument = args[i];
1181
+ if (!argument) throw new Error("Missing argument");
1182
+ if (["--cwd", "--registry-dir"].includes(argument)) {
1183
+ const value = args[++i];
1184
+ if (!value || value.startsWith("--"))
1185
+ throw new Error(`Missing value for ${argument}`);
1186
+ if (argument === "--cwd") cwd = resolve4(value);
1187
+ else registryDirectory = resolve4(value);
1188
+ } else if (argument === "--force") force = true;
1189
+ else if ([
1190
+ "--dry-run",
1191
+ "--diff",
1192
+ "--view",
1193
+ "--yes",
1194
+ "--preserve-existing"
1195
+ ].includes(argument))
1196
+ flags.add(argument);
1197
+ else if (argument.startsWith("-"))
1198
+ throw new Error(`Unsupported option: ${argument}`);
1199
+ else names.push(argument);
1200
+ }
1201
+ cwd = findProjectRoot(cwd);
1202
+ const selected = selectItems(names);
1203
+ const configuration = await readInstallConfig(cwd, {
1204
+ blocks: selected.some(isBlock)
1205
+ });
1206
+ for (const warning of configuration.warnings) console.warn(warning);
1207
+ const stylesheetPath = await readStylesheet(cwd);
1208
+ const items = await Promise.all(
1209
+ selected.map(
1210
+ async (name) => JSON.parse(
1211
+ await readFile5(join7(registryDirectory, `${name}.json`), "utf8")
1212
+ )
1213
+ )
1214
+ );
1215
+ const workspace = await realpath(cwd);
1216
+ const show = (path) => relative5(workspace, path);
1217
+ const installed = (component) => component === "utils" || cossInstalledPaths(component, configuration.paths).some(
1218
+ (path) => existsSync7(join7(workspace, path))
1219
+ );
1220
+ const patterns = omitInstalled(
1221
+ prepareItem(combineItems(items), configuration),
1222
+ installed
1223
+ );
1224
+ const components = await resolveItems(
1225
+ patterns.registryDependencies ?? [],
1226
+ (name) => loadUiItem(registryDirectory, name),
1227
+ installed
1228
+ );
1229
+ const item = {
1230
+ ...patterns,
1231
+ files: [
1232
+ ...components.flatMap(
1233
+ (component) => componentFiles(component, configuration.aliases, configuration.paths)
1234
+ ),
1235
+ ...patterns.files
1236
+ ],
1237
+ dependencies: [
1238
+ ...patterns.dependencies,
1239
+ ...components.flatMap((component) => component.dependencies ?? [])
1240
+ ]
1241
+ };
1242
+ for (const file of item.files) {
1243
+ let ancestor = targetPath(workspace, file.target);
1244
+ while (!existsSync7(ancestor)) ancestor = dirname5(ancestor);
1245
+ const location = relative5(workspace, await realpath(ancestor));
1246
+ if (location.startsWith("..") || resolve4(workspace, location) === dirname5(workspace))
1247
+ throw new Error(`Target escapes the consumer workspace: ${file.target}`);
1248
+ }
1249
+ const barrelPath = join7(workspace, configuration.paths.patterns, "index.ts");
1250
+ const withPatterns = item.files.some(
1251
+ ({ path }) => path.startsWith("patterns/")
1252
+ );
1253
+ const targets = new Set(
1254
+ item.files.map((file) => targetPath(workspace, file.target))
1255
+ );
1256
+ const aggregate = JSON.parse(
1257
+ await readFile5(join7(registryDirectory, "aggregate.json"), "utf8")
1258
+ );
1259
+ const barrel = aggregateBarrel(
1260
+ aggregate.content,
1261
+ (specifier) => [".ts", ".tsx"].some((extension) => {
1262
+ const file = resolve4(dirname5(barrelPath), specifier + extension);
1263
+ return targets.has(file) || existsSync7(file);
1264
+ })
1265
+ );
1266
+ const preview = ["--dry-run", "--diff", "--view"].some(
1267
+ (flag) => flags.has(flag)
1268
+ );
1269
+ const blocksPath = withPatterns ? await findBlocksPath(workspace) : void 0;
1270
+ const dependents = blocksPath ? (await sourceFiles(join7(workspace, blocksPath))).filter(
1271
+ (file) => !targets.has(file)
1272
+ ) : [];
1273
+ const project = configuration.paths.patterns;
1274
+ const known = diagnoseDependents(workspace, dependents, project);
1275
+ if (dependents.length)
1276
+ console.log(
1277
+ `Checking ${dependents.length} installed block files against the updated patterns.`
1278
+ );
1279
+ const before = await checkCompatibility(workspace, item, false, {
1280
+ dependents,
1281
+ known,
1282
+ project
1283
+ });
1284
+ console.log(
1285
+ `Compatibility: ${before.status}. ${before.existingFiles.length} existing files; no automatic overwrite.`
1286
+ );
1287
+ const hidden = /* @__PURE__ */ new Set([...before.pending, ...before.deferred]);
1288
+ for (const diagnostic of before.diagnostics.filter((line) => !hidden.has(line)).slice(0, 12))
1289
+ console.log(diagnostic);
1290
+ if (before.pending.length)
1291
+ console.log(
1292
+ `${before.pending.length} dependencies are not installed yet, so ${before.deferred.length} diagnostics about them were hidden; their types are checked after installation:
1293
+ ${before.pending.map((line) => ` ${line.split(" ")[0]}`).join("\n")}`
1294
+ );
1295
+ else if (before.deferred.length)
1296
+ console.log(
1297
+ `${before.deferred.length} diagnostics about modules that are not installed yet were hidden; they are checked after installation.`
1298
+ );
1299
+ if (before.status === "incompatible") {
1300
+ if (!force)
1301
+ throw new Error(
1302
+ "The patterns do not type-check against your components, so nothing was installed. Fix the diagnostics above or pass --force to install anyway."
1303
+ );
1304
+ console.warn("Incompatible, installing anyway because of --force.");
1305
+ }
1306
+ console.log(
1307
+ components.length ? `Missing ui components, installed from this package: ${components.map((component) => component.name).join(", ")}.` : "Every ui component the patterns use is already installed; keeping yours."
1308
+ );
1309
+ const stylesheet2 = stylesheetPath && existsSync7(join7(workspace, stylesheetPath)) ? await readFile5(join7(workspace, stylesheetPath), "utf8") : void 0;
1310
+ const theme = missingTheme(components, stylesheet2);
1311
+ if (theme.length)
1312
+ console.warn(
1313
+ `${stylesheet2 ? `${stylesheetPath} does not define` : "components.json names no readable tailwind.css to check for"} theme tokens these ui components use. tc96 does not edit your CSS; add the ones you need:
1314
+ ${theme.map(({ item: item2, rules }) => `${item2}:
1315
+ ${rules.join("\n")}`).join("\n")}`
1316
+ );
1317
+ const planned = await planFiles(workspace, item.files);
1318
+ const target = dependencyTarget(workspace, configuration.paths.patterns);
1319
+ const dependencies = missingDependencies(workspace, item.dependencies, target);
1320
+ if (preview) {
1321
+ const labels = {
1322
+ create: "create",
1323
+ unchanged: "unchanged",
1324
+ conflict: "exists and differs, preserved unless you approve"
1325
+ };
1326
+ for (const file of planned)
1327
+ console.log(`${labels[file.status]}: ${show(file.path)}`);
1328
+ if (flags.has("--view"))
1329
+ for (const file of planned.filter(({ status }) => status !== "unchanged"))
1330
+ console.log(`--- ${show(file.path)}
1331
+ ${file.content}`);
1332
+ if (flags.has("--diff"))
1333
+ for (const file of planned.filter(({ status }) => status === "conflict"))
1334
+ console.log(
1335
+ `--- ${show(file.path)}
1336
+ ${diffLines(file.current ?? "", file.content)}`
1337
+ );
1338
+ console.log(
1339
+ dependencies.length ? `Dependencies to install: ${installCommand(workspace, detectPackageManager(workspace), dependencies, target).join(" ")}` : "Every npm dependency is already installed."
1340
+ );
1341
+ if (withPatterns)
1342
+ console.log(
1343
+ `${show(barrelPath)}, written after installation unless the consumer wrote that file:
1344
+ ${barrel}`
1345
+ );
1346
+ return;
1347
+ }
1348
+ const terminal = process.stdin.isTTY && !flags.has("--yes") && !flags.has("--preserve-existing") ? createInterface({ input: process.stdin, output: process.stdout }) : void 0;
1349
+ const result = await writeFiles(
1350
+ planned,
1351
+ terminal && (async (path) => /^y(es)?$/i.test(
1352
+ (await terminal.question(
1353
+ `${show(path)} differs from the registry. Overwrite it? (y/N) `
1354
+ )).trim()
1355
+ ))
1356
+ ).finally(() => terminal?.close());
1357
+ console.log(`Wrote ${result.written.length} files.`);
1358
+ if (result.preserved.length)
1359
+ console.log(
1360
+ `Preserved ${result.preserved.length} existing files that differ from the registry:
1361
+ ${result.preserved.map((path) => ` ${show(path)}`).join("\n")}`
1362
+ );
1363
+ const exported = addFolderExports(
1364
+ workspace,
1365
+ configuration.aliases.ui,
1366
+ components.map((component) => component.name)
1367
+ );
1368
+ if (exported.length)
1369
+ console.log(`Added to the ui package exports: ${exported.join(", ")}.`);
1370
+ if (dependencies.length) installDependencies(workspace, dependencies, target);
1371
+ const after = await checkCompatibility(workspace, item, true, {
1372
+ dependents,
1373
+ known,
1374
+ project
1375
+ });
1376
+ console.log(`Installed TypeScript compatibility: ${after.status}.`);
1377
+ if (after.status !== "compatible") {
1378
+ for (const diagnostic of after.diagnostics.slice(0, 20))
1379
+ console.error(diagnostic);
1380
+ throw new Error(
1381
+ "Installation requires consumer fixes; see diagnostics above. Preserved files were not overwritten automatically."
1382
+ );
1383
+ }
1384
+ if (withPatterns)
1385
+ console.log(
1386
+ await writeBarrel(barrelPath, barrel) === "preserved" ? `${show(barrelPath)} was not generated by tc96 and was preserved; export the installed patterns from it yourself.` : `${show(barrelPath)} exports the installed patterns.`
1387
+ );
1388
+ console.log(
1389
+ `Installed: ${selected.join(", ")}. Visual and behavioral compatibility still require consumer validation.`
1390
+ );
1391
+ }
1392
+ main().catch((error) => {
1393
+ console.error(error instanceof Error ? error.message : error);
1394
+ process.exitCode = 1;
1395
+ });