@sdxc/kit 0.0.0-stage → 2026.10.16

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 (248) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +92 -2
  3. package/changelog.jsonl +1040 -0
  4. package/config.schema.json +89 -0
  5. package/dist/bin.d.ts +9 -0
  6. package/dist/bin.js +10 -0
  7. package/dist/cli.d.ts +33 -0
  8. package/dist/cli.js +58 -0
  9. package/dist/commands/create.d.ts +20 -0
  10. package/dist/commands/create.js +164 -0
  11. package/dist/commands/init.d.ts +16 -0
  12. package/dist/commands/init.js +27 -0
  13. package/dist/commands/make.d.ts +335 -0
  14. package/dist/commands/make.js +152 -0
  15. package/dist/commands/run.d.ts +23 -0
  16. package/dist/commands/run.js +51 -0
  17. package/dist/commands/ui/add.d.ts +23 -0
  18. package/dist/commands/ui/add.js +50 -0
  19. package/dist/commands/ui/diff.d.ts +20 -0
  20. package/dist/commands/ui/diff.js +28 -0
  21. package/dist/commands/ui/list.d.ts +24 -0
  22. package/dist/commands/ui/list.js +45 -0
  23. package/dist/commands/ui/remove.d.ts +22 -0
  24. package/dist/commands/ui/remove.js +48 -0
  25. package/dist/commands/ui/update.d.ts +23 -0
  26. package/dist/commands/ui/update.js +37 -0
  27. package/dist/commands/upgrade.d.ts +30 -0
  28. package/dist/commands/upgrade.js +184 -0
  29. package/dist/config.d.ts +81 -0
  30. package/dist/config.js +157 -0
  31. package/dist/contract.d.ts +161 -0
  32. package/dist/contract.js +308 -0
  33. package/dist/create/github.d.ts +63 -0
  34. package/dist/create/github.js +172 -0
  35. package/dist/create/target.d.ts +31 -0
  36. package/dist/create/target.js +56 -0
  37. package/dist/create/templates.d.ts +62 -0
  38. package/dist/create/templates.js +228 -0
  39. package/dist/dependencies.d.ts +34 -0
  40. package/dist/dependencies.js +76 -0
  41. package/dist/diff.d.ts +14 -0
  42. package/dist/diff.js +103 -0
  43. package/dist/format.d.ts +21 -0
  44. package/dist/format.js +40 -0
  45. package/dist/init.d.ts +38 -0
  46. package/dist/init.js +92 -0
  47. package/dist/lock.d.ts +74 -0
  48. package/dist/lock.js +214 -0
  49. package/dist/make/declare.d.ts +54 -0
  50. package/dist/make/declare.js +495 -0
  51. package/dist/make/generate.d.ts +62 -0
  52. package/dist/make/generate.js +154 -0
  53. package/dist/make/imports.d.ts +43 -0
  54. package/dist/make/imports.js +105 -0
  55. package/dist/make/index.d.ts +43 -0
  56. package/dist/make/index.js +136 -0
  57. package/dist/make/kinds.d.ts +39 -0
  58. package/dist/make/kinds.js +95 -0
  59. package/dist/make/migrations.d.ts +41 -0
  60. package/dist/make/migrations.js +116 -0
  61. package/dist/make/names.d.ts +31 -0
  62. package/dist/make/names.js +47 -0
  63. package/dist/make/stubs.d.ts +44 -0
  64. package/dist/make/stubs.js +89 -0
  65. package/dist/middleware.d.ts +44 -0
  66. package/dist/middleware.js +49 -0
  67. package/dist/package-manager.d.ts +41 -0
  68. package/dist/package-manager.js +80 -0
  69. package/dist/project.d.ts +19 -0
  70. package/dist/project.js +42 -0
  71. package/dist/releases.d.ts +40 -0
  72. package/dist/releases.js +110 -0
  73. package/dist/testing.d.ts +50 -0
  74. package/dist/testing.js +129 -0
  75. package/dist/ui/commands.d.ts +114 -0
  76. package/dist/ui/commands.js +432 -0
  77. package/dist/ui/imports.d.ts +46 -0
  78. package/dist/ui/imports.js +160 -0
  79. package/dist/ui/layout.d.ts +48 -0
  80. package/dist/ui/layout.js +138 -0
  81. package/dist/ui/registry.d.ts +58 -0
  82. package/dist/ui/registry.js +82 -0
  83. package/dist/upgrade/changelog.d.ts +50 -0
  84. package/dist/upgrade/changelog.js +69 -0
  85. package/dist/upgrade/project.d.ts +62 -0
  86. package/dist/upgrade/project.js +132 -0
  87. package/dist/upgrade/prompt.d.ts +51 -0
  88. package/dist/upgrade/prompt.js +227 -0
  89. package/dist/upgrade/registry.d.ts +33 -0
  90. package/dist/upgrade/registry.js +50 -0
  91. package/lock.schema.json +60 -0
  92. package/package.json +44 -5
  93. package/registry/ui/accordion.json +15 -0
  94. package/registry/ui/alert-dialog.json +20 -0
  95. package/registry/ui/alert.json +15 -0
  96. package/registry/ui/aspect-ratio.json +13 -0
  97. package/registry/ui/attachment.json +15 -0
  98. package/registry/ui/avatar.json +15 -0
  99. package/registry/ui/badge.json +13 -0
  100. package/registry/ui/breadcrumbs.json +15 -0
  101. package/registry/ui/bubble.json +13 -0
  102. package/registry/ui/button.json +16 -0
  103. package/registry/ui/calendar.json +16 -0
  104. package/registry/ui/card.json +18 -0
  105. package/registry/ui/carousel.json +15 -0
  106. package/registry/ui/chart.json +13 -0
  107. package/registry/ui/checkbox-group.json +13 -0
  108. package/registry/ui/checkbox.json +16 -0
  109. package/registry/ui/color-area.json +13 -0
  110. package/registry/ui/color-field.json +20 -0
  111. package/registry/ui/color-picker.json +17 -0
  112. package/registry/ui/color-slider.json +13 -0
  113. package/registry/ui/color-swatch-picker.json +15 -0
  114. package/registry/ui/color-swatch.json +13 -0
  115. package/registry/ui/color-wheel.json +13 -0
  116. package/registry/ui/combobox.json +15 -0
  117. package/registry/ui/command.json +13 -0
  118. package/registry/ui/confirm.json +19 -0
  119. package/registry/ui/context-menu.json +16 -0
  120. package/registry/ui/date-field.json +19 -0
  121. package/registry/ui/date-picker.json +15 -0
  122. package/registry/ui/date-range-picker.json +16 -0
  123. package/registry/ui/description.json +13 -0
  124. package/registry/ui/dialog.json +19 -0
  125. package/registry/ui/disclosure.json +18 -0
  126. package/registry/ui/drawer.json +18 -0
  127. package/registry/ui/drop-indicator.json +13 -0
  128. package/registry/ui/drop-zone.json +13 -0
  129. package/registry/ui/empty.json +15 -0
  130. package/registry/ui/field-error.json +13 -0
  131. package/registry/ui/file-trigger.json +13 -0
  132. package/registry/ui/form.json +21 -0
  133. package/registry/ui/grid-list.json +18 -0
  134. package/registry/ui/group.json +13 -0
  135. package/registry/ui/header.json +13 -0
  136. package/registry/ui/heading-scope.json +20 -0
  137. package/registry/ui/heading.json +15 -0
  138. package/registry/ui/highlight.json +16 -0
  139. package/registry/ui/hover-card.json +13 -0
  140. package/registry/ui/image-placeholder.json +16 -0
  141. package/registry/ui/input.json +13 -0
  142. package/registry/ui/item.json +13 -0
  143. package/registry/ui/keyboard.json +13 -0
  144. package/registry/ui/label.json +13 -0
  145. package/registry/ui/link-button.json +16 -0
  146. package/registry/ui/link.json +13 -0
  147. package/registry/ui/listbox.json +15 -0
  148. package/registry/ui/logo.json +15 -0
  149. package/registry/ui/marker.json +13 -0
  150. package/registry/ui/menu.json +19 -0
  151. package/registry/ui/menubar.json +13 -0
  152. package/registry/ui/message-scroller.json +16 -0
  153. package/registry/ui/message.json +13 -0
  154. package/registry/ui/meter.json +13 -0
  155. package/registry/ui/modal.json +15 -0
  156. package/registry/ui/nav-link.json +13 -0
  157. package/registry/ui/navigation-menu.json +15 -0
  158. package/registry/ui/number-field.json +15 -0
  159. package/registry/ui/otp-field.json +15 -0
  160. package/registry/ui/overlay-arrow.json +13 -0
  161. package/registry/ui/pagination.json +16 -0
  162. package/registry/ui/popover.json +13 -0
  163. package/registry/ui/progress-bar.json +13 -0
  164. package/registry/ui/radio-group.json +13 -0
  165. package/registry/ui/range-calendar.json +16 -0
  166. package/registry/ui/resizable.json +13 -0
  167. package/registry/ui/scroll-area.json +13 -0
  168. package/registry/ui/search-field.json +16 -0
  169. package/registry/ui/section.json +13 -0
  170. package/registry/ui/select.json +13 -0
  171. package/registry/ui/selection-indicator.json +13 -0
  172. package/registry/ui/sentinel-row.json +16 -0
  173. package/registry/ui/separator.json +13 -0
  174. package/registry/ui/shared-element.json +13 -0
  175. package/registry/ui/sheet.json +15 -0
  176. package/registry/ui/shortcut-list.json +18 -0
  177. package/registry/ui/sidebar.json +20 -0
  178. package/registry/ui/skeleton.json +13 -0
  179. package/registry/ui/slider.json +16 -0
  180. package/registry/ui/spinner.json +13 -0
  181. package/registry/ui/switch.json +16 -0
  182. package/registry/ui/table.json +16 -0
  183. package/registry/ui/tabs.json +17 -0
  184. package/registry/ui/tag-group.json +18 -0
  185. package/registry/ui/text-field.json +19 -0
  186. package/registry/ui/text.json +13 -0
  187. package/registry/ui/textarea.json +13 -0
  188. package/registry/ui/time-field.json +19 -0
  189. package/registry/ui/toast.json +16 -0
  190. package/registry/ui/toggle-button.json +17 -0
  191. package/registry/ui/toolbar.json +13 -0
  192. package/registry/ui/tooltip.json +16 -0
  193. package/registry/ui/tree.json +18 -0
  194. package/registry/ui/typeset.json +16 -0
  195. package/registry/ui/youtube-embed.json +16 -0
  196. package/stubs/command.stub +12 -0
  197. package/stubs/command.test.stub +18 -0
  198. package/stubs/controller.form.stub +33 -0
  199. package/stubs/controller.stub +17 -0
  200. package/stubs/controller.test.stub +15 -0
  201. package/stubs/email.stub +44 -0
  202. package/stubs/email.test.stub +16 -0
  203. package/stubs/factory.stub +10 -0
  204. package/stubs/initializer.stub +7 -0
  205. package/stubs/initializer.test.stub +13 -0
  206. package/stubs/job.cron.stub +12 -0
  207. package/stubs/job.stub +11 -0
  208. package/stubs/job.test.stub +15 -0
  209. package/stubs/mcp.resource.stub +12 -0
  210. package/stubs/mcp.stub +10 -0
  211. package/stubs/mcp.test.stub +15 -0
  212. package/stubs/middleware.stub +11 -0
  213. package/stubs/middleware.test.stub +13 -0
  214. package/stubs/migration.stub +1 -0
  215. package/stubs/model.stub +24 -0
  216. package/stubs/model.test.stub +15 -0
  217. package/stubs/policy.stub +13 -0
  218. package/stubs/policy.test.stub +17 -0
  219. package/stubs/service.stub +13 -0
  220. package/stubs/service.test.stub +14 -0
  221. package/stubs/validator.stub +14 -0
  222. package/stubs/validator.test.stub +22 -0
  223. package/templates/app/README.md +57 -0
  224. package/templates/app/app/commands/about.test.ts +29 -0
  225. package/templates/app/app/commands/about.ts +34 -0
  226. package/templates/app/app/commands/index.ts +15 -0
  227. package/templates/app/app/http/controllers/home.tsx +22 -0
  228. package/templates/app/app/http/controllers/not-found.tsx +25 -0
  229. package/templates/app/app/initializers/assets.ts +11 -0
  230. package/templates/app/app/initializers/cli.ts +35 -0
  231. package/templates/app/app/initializers/dispatcher.ts +18 -0
  232. package/templates/app/app/initializers/logger.ts +10 -0
  233. package/templates/app/app/initializers/mcp.ts +16 -0
  234. package/templates/app/app/initializers/router.tsx +65 -0
  235. package/templates/app/app/jobs/index.ts +10 -0
  236. package/templates/app/app/mcp/resources/index.ts +9 -0
  237. package/templates/app/app/mcp/tools/index.ts +10 -0
  238. package/templates/app/bootstrap/browser.ts +27 -0
  239. package/templates/app/bootstrap/cli.ts +9 -0
  240. package/templates/app/bootstrap/worker.ts +31 -0
  241. package/templates/app/cloudflare.config.ts +28 -0
  242. package/templates/app/config/router-context.d.ts +20 -0
  243. package/templates/app/gitignore +9 -0
  244. package/templates/app/package.json +38 -0
  245. package/templates/app/resources/layouts/document.tsx +58 -0
  246. package/templates/app/routes/web.ts +12 -0
  247. package/templates/app/tsconfig.json +40 -0
  248. package/templates/app/vite.config.ts +40 -0
@@ -0,0 +1,110 @@
1
+ /**
2
+ * The kit's one notion of a release: `@sdxc/*` versions are UTC dates and a daily release
3
+ * republishes only what changed, so a package at release D is its newest version on or before D,
4
+ * read from the npm registry. `create`, `make` and `upgrade` all pin through here.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import * as s from "@sdxc/json-schema";
10
+ import { failure, isFailure, success, wrap } from "@sdxc/result";
11
+ import { compare } from "@sdxc/semver";
12
+ /** Where npm serves a package's registry document, `<REGISTRY>/<name>`. */
13
+ export const REGISTRY = "https://registry.npmjs.org";
14
+ /** The scope every package the kit pins is published under. */
15
+ export const SCOPE = "@sdxc/";
16
+ /** A dated release version, `2026.10.14`; the bootstrap placeholder and prereleases are not one. */
17
+ const DATED_VERSION = /^\d{4}\.\d{1,2}\.\d{1,2}$/;
18
+ /** An exact pin as a manifest may spell it, with an optional range operator before a dated version. */
19
+ const DATED_PIN = /^[\^~=]?v?(\d{4}\.\d{1,2}\.\d{1,2})$/;
20
+ /** The fields of a registry document the kit reads. */
21
+ const PACKUMENT_SCHEMA = s.object({
22
+ "dist-tags": s.optional(s.record(s.string(), s.string())),
23
+ versions: s.optional(s.record(s.string(), s.object({ peerDependencies: s.optional(s.record(s.string(), s.string())) }))),
24
+ });
25
+ /**
26
+ * The registry document for `name`. A package npm does not have is a failure naming it, as is
27
+ * an unreachable registry or a document without versions.
28
+ */
29
+ export async function fetchPackument(name, signal) {
30
+ let url = `${REGISTRY}/${name.replaceAll("/", "%2f")}`;
31
+ let response = await wrap(() => fetch(url, { headers: { accept: "application/json" }, signal }));
32
+ if (isFailure(response)) {
33
+ return failure(new Error(`Could not reach the npm registry: ${response.error.message}`));
34
+ }
35
+ if (response.data.status === 404)
36
+ return failure(new Error(`${name} is not published on npm`));
37
+ if (!response.data.ok) {
38
+ return failure(new Error(`The npm registry answered ${response.data.status} for ${url}`));
39
+ }
40
+ let body = await wrap(() => response.data.json());
41
+ if (isFailure(body))
42
+ return failure(new Error(`The npm registry sent invalid JSON for ${url}`));
43
+ let checked = s.parseSafe(PACKUMENT_SCHEMA, body.data);
44
+ if (!checked.success)
45
+ return failure(new Error(`The npm registry sent no versions for ${url}`));
46
+ let versions = new Map();
47
+ for (let [version, manifest] of Object.entries(checked.value.versions ?? {})) {
48
+ versions.set(version, manifest.peerDependencies ?? {});
49
+ }
50
+ return success({ name, latest: checked.value["dist-tags"]?.latest ?? null, versions });
51
+ }
52
+ /** The newest dated version of `packument` on or before the release `release`, or `null`. */
53
+ export function versionAtRelease(packument, release) {
54
+ let found = null;
55
+ for (let version of packument.versions.keys()) {
56
+ if (!DATED_VERSION.test(version) || compare(version, release) > 0)
57
+ continue;
58
+ if (found === null || compare(version, found) > 0)
59
+ found = version;
60
+ }
61
+ return found;
62
+ }
63
+ /**
64
+ * The exact version of each of `names` at `release`, or at its `latest` dist-tag when `release`
65
+ * is `null`. A package with no version at that release is a failure naming both.
66
+ */
67
+ export async function resolveRelease(names, release, signal) {
68
+ let sorted = [...new Set(names)].sort();
69
+ let fetched = await Promise.all(sorted.map((name) => fetchPackument(name, signal)));
70
+ let versions = new Map();
71
+ for (let packument of fetched) {
72
+ if (isFailure(packument))
73
+ return packument;
74
+ let { name } = packument.data;
75
+ let version = release === null ? packument.data.latest : versionAtRelease(packument.data, release);
76
+ if (version === null) {
77
+ return failure(new Error(release === null
78
+ ? `${name} has no latest version on npm`
79
+ : `${name} has no release on or before ${release}`));
80
+ }
81
+ versions.set(name, version);
82
+ }
83
+ return success(versions);
84
+ }
85
+ /**
86
+ * The release a project is on: the newest date among the exact `@sdxc/*` pins its dependency
87
+ * sections list, or `null` when it pins none to a dated version.
88
+ */
89
+ export function projectRelease(sections) {
90
+ let newest = null;
91
+ for (let section of sections) {
92
+ for (let [name, range] of Object.entries(section ?? {})) {
93
+ if (!name.startsWith(SCOPE))
94
+ continue;
95
+ let version = DATED_PIN.exec(range.trim())?.[1];
96
+ if (version === undefined)
97
+ continue;
98
+ if (newest === null || compare(version, newest) > 0)
99
+ newest = version;
100
+ }
101
+ }
102
+ return newest;
103
+ }
104
+ /** The npm package a module specifier comes from, `@sdxc/auth/issuer` from `@sdxc/auth`, or `null`. */
105
+ export function scopedPackageOf(specifier) {
106
+ if (!specifier.startsWith(SCOPE))
107
+ return null;
108
+ let name = specifier.split("/").slice(0, 2).join("/");
109
+ return name.length > SCOPE.length ? name : null;
110
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Builds a project from a built-in template the way a consumer's install would see it, for the
3
+ * tests that type check templates and generated code: dependencies are linked from this
4
+ * workspace instead of installed, and the Worker's types are generated as `cf:typegen` does.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { Result } from "@sdxc/result";
10
+ /** What a spawned command printed and how it exited. */
11
+ export interface Spawned {
12
+ code: number | null;
13
+ output: string;
14
+ }
15
+ /**
16
+ * Creates `template` as the project `name` inside a fresh temporary directory and links every
17
+ * dependency its `package.json` lists: an `@sdxc/*` package to its workspace directory, anything
18
+ * else to the copy this workspace installed. `sdxc create` reads the npm registry, so the caller
19
+ * answers it, as {@link registryDocument} does. Answers the project directory; the caller removes
20
+ * its parent.
21
+ */
22
+ export declare function materialize(template: string, name?: string): Promise<Result<string, Error>>;
23
+ /**
24
+ * Links every dependency the project's `package.json` lists and `node_modules` lacks: an
25
+ * `@sdxc/*` package to its workspace directory, anything else to the copy this workspace
26
+ * installed, so a package `sdxc make` added resolves as an install would make it.
27
+ */
28
+ export declare function linkDependencies(project: string): Promise<Result<void, Error>>;
29
+ /**
30
+ * The npm registry document a test answers for `name` (`/@sdxc%2fjobs`, say): `versions` each
31
+ * published with `remix` 3.0.0 as a peer, and `latest` the newest of them.
32
+ *
33
+ * @example http.get(`${REGISTRY}/*`, ({ request }) => HttpResponse.json(registryDocument(new URL(request.url).pathname.slice(1))))
34
+ */
35
+ export declare function registryDocument(name: string, versions?: readonly string[]): Record<string, unknown>;
36
+ /**
37
+ * Links what `package.json` gained since, generates the Worker's types with the project's own
38
+ * `cf`, then type checks the project with the workspace's TypeScript, answering what it printed.
39
+ */
40
+ export declare function typecheck(project: string): Promise<Spawned>;
41
+ /**
42
+ * Runs the project's own command line, `bootstrap/cli.ts`, under Bun with `argv`, as
43
+ * `bun run cli` and `sdxc run` start it, answering both output streams together.
44
+ */
45
+ export declare function runCommandLine(project: string, argv: string[]): Promise<Spawned>;
46
+ /**
47
+ * Runs the project's own tests with its own Vite+, as `vp test run` inside it does, with
48
+ * `--no-color` so the summary reads as plain text on CI too, where Vite+ colors it otherwise.
49
+ */
50
+ export declare function testProject(project: string): Promise<Spawned>;
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Builds a project from a built-in template the way a consumer's install would see it, for the
3
+ * tests that type check templates and generated code: dependencies are linked from this
4
+ * workspace instead of installed, and the Worker's types are generated as `cf:typegen` does.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { spawn } from "node:child_process";
10
+ import { access, lstat, mkdir, mkdtemp, readFile, symlink } from "node:fs/promises";
11
+ import { tmpdir } from "node:os";
12
+ import { dirname, join } from "node:path";
13
+ import { invoke } from "@sdxc/cli/test";
14
+ import { failure, isFailure, isSuccess, success, wrap } from "@sdxc/result";
15
+ import { createSDXC } from "./cli.js";
16
+ import { defaultPackageRoot } from "./create/templates.js";
17
+ /**
18
+ * Creates `template` as the project `name` inside a fresh temporary directory and links every
19
+ * dependency its `package.json` lists: an `@sdxc/*` package to its workspace directory, anything
20
+ * else to the copy this workspace installed. `sdxc create` reads the npm registry, so the caller
21
+ * answers it, as {@link registryDocument} does. Answers the project directory; the caller removes
22
+ * its parent.
23
+ */
24
+ export async function materialize(template, name = "app") {
25
+ let parent = await mkdtemp(join(tmpdir(), "sdxc-template-"));
26
+ let created = await invoke(createSDXC(), ["create", name, "--template", template, "--no-git"], {
27
+ cwd: parent,
28
+ interactive: false,
29
+ });
30
+ if (created.code !== 0) {
31
+ return failure(new Error(`sdxc create exited with ${created.code}: ${created.stderr}`));
32
+ }
33
+ let project = join(parent, name);
34
+ let linked = await linkDependencies(project);
35
+ if (isFailure(linked))
36
+ return linked;
37
+ return success(project);
38
+ }
39
+ /**
40
+ * Links every dependency the project's `package.json` lists and `node_modules` lacks: an
41
+ * `@sdxc/*` package to its workspace directory, anything else to the copy this workspace
42
+ * installed, so a package `sdxc make` added resolves as an install would make it.
43
+ */
44
+ export async function linkDependencies(project) {
45
+ let packageRoot = defaultPackageRoot();
46
+ let manifest = JSON.parse(await readFile(join(project, "package.json"), "utf8"));
47
+ let names = Object.keys({ ...manifest.dependencies, ...manifest.devDependencies });
48
+ for (let dependency of names) {
49
+ let link = join(project, "node_modules", dependency);
50
+ if (isSuccess(await wrap(() => lstat(link))))
51
+ continue;
52
+ let source = dependency.startsWith("@sdxc/")
53
+ ? success(join(packageRoot, "..", dependency.slice("@sdxc/".length)))
54
+ : await installed(packageRoot, dependency);
55
+ if (isFailure(source))
56
+ return source;
57
+ await mkdir(dirname(link), { recursive: true });
58
+ await symlink(source.data, link, "dir");
59
+ }
60
+ return success(undefined);
61
+ }
62
+ /**
63
+ * The npm registry document a test answers for `name` (`/@sdxc%2fjobs`, say): `versions` each
64
+ * published with `remix` 3.0.0 as a peer, and `latest` the newest of them.
65
+ *
66
+ * @example http.get(`${REGISTRY}/*`, ({ request }) => HttpResponse.json(registryDocument(new URL(request.url).pathname.slice(1))))
67
+ */
68
+ export function registryDocument(name, versions = ["0.0.1"]) {
69
+ return {
70
+ name: decodeURIComponent(name),
71
+ "dist-tags": { latest: versions.at(-1) },
72
+ versions: Object.fromEntries(versions.map((version) => [version, { version, peerDependencies: { remix: "3.0.0" } }])),
73
+ };
74
+ }
75
+ /**
76
+ * Links what `package.json` gained since, generates the Worker's types with the project's own
77
+ * `cf`, then type checks the project with the workspace's TypeScript, answering what it printed.
78
+ */
79
+ export async function typecheck(project) {
80
+ let linked = await linkDependencies(project);
81
+ if (isFailure(linked))
82
+ return { code: null, output: linked.error.message };
83
+ let types = await run([join(project, "node_modules/cf/bin/cf"), "workers", "types"], project);
84
+ if (types.code !== 0)
85
+ return types;
86
+ return run([join(project, "node_modules/typescript/bin/tsc"), "--noEmit", "-p", project], project);
87
+ }
88
+ /**
89
+ * Runs the project's own command line, `bootstrap/cli.ts`, under Bun with `argv`, as
90
+ * `bun run cli` and `sdxc run` start it, answering both output streams together.
91
+ */
92
+ export function runCommandLine(project, argv) {
93
+ return run(["bootstrap/cli.ts", ...argv], project, "bun");
94
+ }
95
+ /**
96
+ * Runs the project's own tests with its own Vite+, as `vp test run` inside it does, with
97
+ * `--no-color` so the summary reads as plain text on CI too, where Vite+ colors it otherwise.
98
+ */
99
+ export function testProject(project) {
100
+ return run([join(project, "node_modules/vite-plus/bin/vp"), "test", "run", "--no-color"], project);
101
+ }
102
+ /** The directory `dependency` is installed at for this package or, failing that, the workspace. */
103
+ async function installed(packageRoot, dependency) {
104
+ let candidates = [
105
+ join(packageRoot, "node_modules", dependency),
106
+ join(packageRoot, "../../node_modules", dependency),
107
+ ];
108
+ for (let candidate of candidates) {
109
+ if (isSuccess(await wrap(() => access(join(candidate, "package.json"))))) {
110
+ return success(candidate);
111
+ }
112
+ }
113
+ return failure(new Error(`${dependency} is not installed in this workspace; add it to @sdxc/kit's devDependencies`));
114
+ }
115
+ /** Runs a script with `args` in `cwd` under `runtime`, Node by default, collecting both output streams. */
116
+ function run(args, cwd, runtime = process.execPath) {
117
+ return new Promise((settle) => {
118
+ let output = "";
119
+ let child = spawn(runtime, args, { cwd, shell: false });
120
+ child.stdout.on("data", (chunk) => {
121
+ output += chunk.toString();
122
+ });
123
+ child.stderr.on("data", (chunk) => {
124
+ output += chunk.toString();
125
+ });
126
+ child.once("error", (error) => settle({ code: null, output: error.message }));
127
+ child.once("close", (code) => settle({ code, output }));
128
+ });
129
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * What each `sdxc ui` command does, as plans over the project: `add`, `update` and `remove`
3
+ * answer every file they would write, edit or delete and the lock entries they would record,
4
+ * so `--dry-run` prints exactly what applying the same plan writes.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { AnyCommandContext } from "@sdxc/cli";
10
+ import type { Result } from "@sdxc/result";
11
+ import type { Config } from "../config.js";
12
+ import type { Lock } from "../lock.js";
13
+ import type { CopyLayout } from "./layout.js";
14
+ import type { Registry } from "./registry.js";
15
+ /** Everything a `ui` command reads before it plans. */
16
+ export interface UIContext {
17
+ root: string;
18
+ config: Config;
19
+ registry: Registry;
20
+ lock: Lock;
21
+ layout: CopyLayout;
22
+ }
23
+ /** One file a plan touches, relative to the project root; `after: null` deletes it. */
24
+ export interface FileChange {
25
+ before: string | null;
26
+ after: string | null;
27
+ }
28
+ /** A lock entry to record once its files are written. */
29
+ export interface PendingEntry {
30
+ name: string;
31
+ release: string;
32
+ /** Each file relative to `ui.directory`: a hash to keep, or `null` to hash once written. */
33
+ files: Record<string, string | null>;
34
+ }
35
+ /** What `add`, `update` or `remove` would change. */
36
+ export interface Plan {
37
+ files: Map<string, FileChange>;
38
+ record: PendingEntry[];
39
+ forget: string[];
40
+ /** Lines for the user: what the command did, and what it left for them to do. */
41
+ report: string[];
42
+ }
43
+ /** One row of `sdxc ui list`. */
44
+ export interface ListRow {
45
+ name: string;
46
+ /** The release whose commits last touched it, or `null` for a copy the registry lacks. */
47
+ changedIn: string | null;
48
+ copy: {
49
+ release: string;
50
+ edited: boolean;
51
+ behind: boolean;
52
+ } | null;
53
+ }
54
+ /** What a `ui` command's handler runs with: its context, and its prompts, tasks and processes. */
55
+ export type UICommandContext = Pick<AnyCommandContext, "exec" | "task" | "stdout" | "stderr">;
56
+ /**
57
+ * Reads the installed registry, the lock file and the copies' layout of the project at `root`.
58
+ *
59
+ * @param packageRoot - The `@sdxc/kit` package holding the registry.
60
+ */
61
+ export declare function loadContext(project: {
62
+ root: string;
63
+ config: Config;
64
+ }, packageRoot: string): Promise<Result<UIContext, Error>>;
65
+ /** The hash a lock entry records for a file's content: SHA-256, base64, `sha256-` prefixed. */
66
+ export declare function hashContent(content: string): string;
67
+ /**
68
+ * Every component in the registry, and every copy the registry no longer holds, sorted by
69
+ * name. A copy is edited when a file it recorded is missing or hashes differently, and behind
70
+ * when the component changed in a release after the one it came from.
71
+ */
72
+ export declare function listComponents(context: UIContext): Promise<ListRow[]>;
73
+ /**
74
+ * Copies `names` (and, with `withDeps`, every component they reach) into `ui.directory`, with
75
+ * their tests under `ui.tests`, and points every project file's imports of them at the copies.
76
+ * A component already copied is reported and left alone; a file in the way stops the plan.
77
+ */
78
+ export declare function planAdd(context: UIContext, names: readonly string[], options: {
79
+ withDeps: boolean;
80
+ }): Promise<Result<Plan, Error>>;
81
+ /**
82
+ * The difference between the copy of `name` and the installed version, as a unified diff from
83
+ * the installed file to the local one, or an empty string when they match.
84
+ */
85
+ export declare function diffComponent(context: UIContext, name: string): Promise<Result<string, Error>>;
86
+ /**
87
+ * Replaces each file of each copy whose hash still matches the lock with the installed version.
88
+ * An edited file is replaced only when `overwrite` answers yes for it, and otherwise left alone
89
+ * and reported; the entry moves to the installed release only when every file was replaced.
90
+ */
91
+ export declare function planUpdate(context: UIContext, names: readonly string[], options: {
92
+ overwrite: (path: string) => Promise<Result<boolean, Error>>;
93
+ }): Promise<Result<Plan, Error>>;
94
+ /**
95
+ * Deletes the copies of `names`, drops their lock entries and points every project file's
96
+ * imports of them back at `@sdxc/ui/<name>`, folded into an existing `@sdxc/ui` import.
97
+ */
98
+ export declare function planRemove(context: UIContext, names: readonly string[]): Promise<Result<Plan, Error>>;
99
+ /**
100
+ * Writes and deletes the plan's files as a task counting each one, runs `format` over what it
101
+ * wrote, then records the lock entries with each new file hashed as it ended up. A failed
102
+ * `format` is reported, and the hashes are then of the files as written.
103
+ */
104
+ export declare function applyPlan(ctx: UICommandContext, context: UIContext, plan: Plan): Promise<Result<string[], Error>>;
105
+ /**
106
+ * Lists the `@sdxc/*` packages the plan's files import in `package.json`, then prints the plan's
107
+ * diff on stdout and its report on stderr under `--dry-run`, or applies it and prints its report.
108
+ */
109
+ export declare function finishPlan(ctx: UICommandContext, context: UIContext, plan: Plan, dryRun: boolean): Promise<Result<void, Error>>;
110
+ /**
111
+ * The diff of every file the plan touches and of the lock file, which is what applying it
112
+ * writes before `format` runs; the lock's hashes are of the files as the CLI writes them.
113
+ */
114
+ export declare function renderPlan(context: UIContext, plan: Plan): Promise<Result<string, Error>>;