ref0-git 0.0.0 → 0.3.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 (385) hide show
  1. package/app/apps/github/.dev.vars.example +6 -0
  2. package/app/apps/github/README.md +70 -0
  3. package/app/apps/github/THIRD_PARTY_NOTICES.md +214 -0
  4. package/app/apps/github/components.json +25 -0
  5. package/app/apps/github/generated/git-rest.ts +10444 -0
  6. package/app/apps/github/generated/routeTree.gen.ts +1242 -0
  7. package/app/apps/github/migrations/postgres/0001_auth.sql +46 -0
  8. package/app/apps/github/migrations/sql/0001_auth.sql +19 -0
  9. package/app/apps/github/migrations/sql/0002_passkeys.sql +9 -0
  10. package/app/apps/github/migrations/sql/0003_orgs.sql +22 -0
  11. package/app/apps/github/migrations/sql/0004_avatars.sql +6 -0
  12. package/app/apps/github/package.json +80 -0
  13. package/app/apps/github/src/branches/branch-list.tsx +385 -0
  14. package/app/apps/github/src/branches/branches.ts +55 -0
  15. package/app/apps/github/src/clients/allowed.ts +213 -0
  16. package/app/apps/github/src/clients/at-most.ts +17 -0
  17. package/app/apps/github/src/clients/avatars.ts +410 -0
  18. package/app/apps/github/src/clients/cached.ts +65 -0
  19. package/app/apps/github/src/clients/calls.ts +160 -0
  20. package/app/apps/github/src/clients/clients.ts +82 -0
  21. package/app/apps/github/src/clients/graphql.ts +50 -0
  22. package/app/apps/github/src/clients/host-answer.ts +28 -0
  23. package/app/apps/github/src/clients/host-calls.ts +382 -0
  24. package/app/apps/github/src/clients/icon-bytes.ts +203 -0
  25. package/app/apps/github/src/clients/proxy.ts +59 -0
  26. package/app/apps/github/src/clients/session-ended.ts +18 -0
  27. package/app/apps/github/src/clients/transfers.ts +212 -0
  28. package/app/apps/github/src/code/breadcrumbs.tsx +50 -0
  29. package/app/apps/github/src/code/code-page.tsx +147 -0
  30. package/app/apps/github/src/code/code-tree.tsx +338 -0
  31. package/app/apps/github/src/code/controls.tsx +230 -0
  32. package/app/apps/github/src/code/file-view.tsx +450 -0
  33. package/app/apps/github/src/code/files.ts +332 -0
  34. package/app/apps/github/src/code/folder-list.tsx +122 -0
  35. package/app/apps/github/src/code/go-to-file.tsx +131 -0
  36. package/app/apps/github/src/code/highlighted.tsx +58 -0
  37. package/app/apps/github/src/code/lines.ts +46 -0
  38. package/app/apps/github/src/code/load.ts +147 -0
  39. package/app/apps/github/src/code/markdown-files.ts +58 -0
  40. package/app/apps/github/src/code/places.ts +88 -0
  41. package/app/apps/github/src/code/ref-pages.ts +179 -0
  42. package/app/apps/github/src/code/ref-switcher.tsx +203 -0
  43. package/app/apps/github/src/code/refs.ts +142 -0
  44. package/app/apps/github/src/code/repo-home.tsx +240 -0
  45. package/app/apps/github/src/code/repo.ts +105 -0
  46. package/app/apps/github/src/code/saved-reads.ts +199 -0
  47. package/app/apps/github/src/code/saved.ts +110 -0
  48. package/app/apps/github/src/code/tree-fold.ts +186 -0
  49. package/app/apps/github/src/code/trees.ts +136 -0
  50. package/app/apps/github/src/components/avatar-picture.ts +53 -0
  51. package/app/apps/github/src/components/avatar-url.ts +16 -0
  52. package/app/apps/github/src/components/confirm-action.tsx +100 -0
  53. package/app/apps/github/src/components/count.tsx +24 -0
  54. package/app/apps/github/src/components/create-button.tsx +38 -0
  55. package/app/apps/github/src/components/file-icons/file-icons.css +225 -0
  56. package/app/apps/github/src/components/file-icons/file-icons.tsx +138 -0
  57. package/app/apps/github/src/components/filter.tsx +35 -0
  58. package/app/apps/github/src/components/hotkeys/hotkeys.tsx +255 -0
  59. package/app/apps/github/src/components/item-list.tsx +65 -0
  60. package/app/apps/github/src/components/language-dot.tsx +29 -0
  61. package/app/apps/github/src/components/list-toolbar.tsx +82 -0
  62. package/app/apps/github/src/components/markdown/editor.tsx +57 -0
  63. package/app/apps/github/src/components/markdown/markdown.css +177 -0
  64. package/app/apps/github/src/components/markdown/markdown.tsx +82 -0
  65. package/app/apps/github/src/components/owner-card.tsx +196 -0
  66. package/app/apps/github/src/components/pull-status.tsx +34 -0
  67. package/app/apps/github/src/components/recent.ts +41 -0
  68. package/app/apps/github/src/components/relative-time.tsx +78 -0
  69. package/app/apps/github/src/components/repos/icon-hashes.ts +91 -0
  70. package/app/apps/github/src/components/repos/new-repo-form.tsx +196 -0
  71. package/app/apps/github/src/components/repos/repo-icon.tsx +47 -0
  72. package/app/apps/github/src/components/repos/repo-list.tsx +528 -0
  73. package/app/apps/github/src/components/repos/your-repos.tsx +124 -0
  74. package/app/apps/github/src/components/review-state.tsx +75 -0
  75. package/app/apps/github/src/components/route-dialog.tsx +137 -0
  76. package/app/apps/github/src/components/save-button.tsx +58 -0
  77. package/app/apps/github/src/components/shell/app-shell.tsx +164 -0
  78. package/app/apps/github/src/components/shell/create-org-dialog.tsx +118 -0
  79. package/app/apps/github/src/components/shell/create-row.tsx +49 -0
  80. package/app/apps/github/src/components/shell/link-menu.tsx +94 -0
  81. package/app/apps/github/src/components/shell/nav-user.tsx +97 -0
  82. package/app/apps/github/src/components/shell/owner-repos.tsx +247 -0
  83. package/app/apps/github/src/components/shell/owner-switcher.tsx +104 -0
  84. package/app/apps/github/src/components/shell/repo-switcher.tsx +179 -0
  85. package/app/apps/github/src/components/shell/sections.ts +31 -0
  86. package/app/apps/github/src/components/shell/submenu-chevron.ts +147 -0
  87. package/app/apps/github/src/components/signin/device-card.tsx +139 -0
  88. package/app/apps/github/src/components/signin/login-form.tsx +88 -0
  89. package/app/apps/github/src/components/signin/signin-page.tsx +33 -0
  90. package/app/apps/github/src/components/signin/signup-form.tsx +106 -0
  91. package/app/apps/github/src/components/states/live-status.tsx +42 -0
  92. package/app/apps/github/src/components/states/states.tsx +126 -0
  93. package/app/apps/github/src/components/tab-indicator.tsx +143 -0
  94. package/app/apps/github/src/components/theme-choice.tsx +108 -0
  95. package/app/apps/github/src/components/theme-provider.tsx +126 -0
  96. package/app/apps/github/src/components/tones.ts +23 -0
  97. package/app/apps/github/src/components/ui/alert-dialog.tsx +187 -0
  98. package/app/apps/github/src/components/ui/alert.tsx +78 -0
  99. package/app/apps/github/src/components/ui/avatar.tsx +106 -0
  100. package/app/apps/github/src/components/ui/badge.tsx +51 -0
  101. package/app/apps/github/src/components/ui/breadcrumb.tsx +124 -0
  102. package/app/apps/github/src/components/ui/button-group.tsx +87 -0
  103. package/app/apps/github/src/components/ui/button.tsx +61 -0
  104. package/app/apps/github/src/components/ui/calendar.tsx +221 -0
  105. package/app/apps/github/src/components/ui/card.tsx +102 -0
  106. package/app/apps/github/src/components/ui/checkbox.tsx +26 -0
  107. package/app/apps/github/src/components/ui/collapsible.tsx +19 -0
  108. package/app/apps/github/src/components/ui/combobox.tsx +304 -0
  109. package/app/apps/github/src/components/ui/command.tsx +208 -0
  110. package/app/apps/github/src/components/ui/dialog.tsx +156 -0
  111. package/app/apps/github/src/components/ui/dropdown-menu.tsx +290 -0
  112. package/app/apps/github/src/components/ui/empty.tsx +100 -0
  113. package/app/apps/github/src/components/ui/field.tsx +236 -0
  114. package/app/apps/github/src/components/ui/hover-card.tsx +48 -0
  115. package/app/apps/github/src/components/ui/input-group.tsx +163 -0
  116. package/app/apps/github/src/components/ui/input.tsx +19 -0
  117. package/app/apps/github/src/components/ui/item.tsx +201 -0
  118. package/app/apps/github/src/components/ui/kbd.tsx +27 -0
  119. package/app/apps/github/src/components/ui/label.tsx +33 -0
  120. package/app/apps/github/src/components/ui/popover.tsx +87 -0
  121. package/app/apps/github/src/components/ui/radio-group.tsx +35 -0
  122. package/app/apps/github/src/components/ui/select.tsx +198 -0
  123. package/app/apps/github/src/components/ui/separator.tsx +22 -0
  124. package/app/apps/github/src/components/ui/sheet.tsx +138 -0
  125. package/app/apps/github/src/components/ui/sidebar.tsx +724 -0
  126. package/app/apps/github/src/components/ui/skeleton.tsx +13 -0
  127. package/app/apps/github/src/components/ui/sonner.tsx +47 -0
  128. package/app/apps/github/src/components/ui/styles.css +242 -0
  129. package/app/apps/github/src/components/ui/table.tsx +113 -0
  130. package/app/apps/github/src/components/ui/tabs.tsx +79 -0
  131. package/app/apps/github/src/components/ui/textarea.tsx +17 -0
  132. package/app/apps/github/src/components/ui/title.ts +6 -0
  133. package/app/apps/github/src/components/ui/toggle-group.tsx +89 -0
  134. package/app/apps/github/src/components/ui/toggle.tsx +42 -0
  135. package/app/apps/github/src/components/ui/tooltip.tsx +63 -0
  136. package/app/apps/github/src/components/user-avatar.tsx +145 -0
  137. package/app/apps/github/src/components/view-tabs.tsx +42 -0
  138. package/app/apps/github/src/context/context.ts +133 -0
  139. package/app/apps/github/src/diffs/blobs.ts +94 -0
  140. package/app/apps/github/src/diffs/diff-view.tsx +155 -0
  141. package/app/apps/github/src/diffs/files.ts +121 -0
  142. package/app/apps/github/src/diffs/hunks.tsx +454 -0
  143. package/app/apps/github/src/diffs/patch.ts +131 -0
  144. package/app/apps/github/src/diffs/rows.ts +137 -0
  145. package/app/apps/github/src/history/commit-diff.ts +54 -0
  146. package/app/apps/github/src/history/commit-list.tsx +207 -0
  147. package/app/apps/github/src/history/commit-page.tsx +147 -0
  148. package/app/apps/github/src/history/history.ts +129 -0
  149. package/app/apps/github/src/hooks/allowed.ts +31 -0
  150. package/app/apps/github/src/hooks/answers.ts +65 -0
  151. package/app/apps/github/src/hooks/avatars.ts +54 -0
  152. package/app/apps/github/src/hooks/draft.ts +38 -0
  153. package/app/apps/github/src/hooks/open-counts.ts +127 -0
  154. package/app/apps/github/src/hooks/profiles.ts +120 -0
  155. package/app/apps/github/src/hooks/repos.ts +440 -0
  156. package/app/apps/github/src/hooks/use-mobile.ts +19 -0
  157. package/app/apps/github/src/hooks/viewer.ts +39 -0
  158. package/app/apps/github/src/inbox/count.ts +70 -0
  159. package/app/apps/github/src/inbox/inbox-item.tsx +66 -0
  160. package/app/apps/github/src/inbox/inbox-page.tsx +572 -0
  161. package/app/apps/github/src/inbox/marks.ts +130 -0
  162. package/app/apps/github/src/inbox/release-tags.ts +65 -0
  163. package/app/apps/github/src/inbox/search.ts +97 -0
  164. package/app/apps/github/src/inbox/subjects.ts +184 -0
  165. package/app/apps/github/src/inbox/subscription-controls.tsx +184 -0
  166. package/app/apps/github/src/inbox/subscriptions.ts +189 -0
  167. package/app/apps/github/src/inbox/threads.ts +198 -0
  168. package/app/apps/github/src/issues/changes.ts +332 -0
  169. package/app/apps/github/src/issues/counts.ts +62 -0
  170. package/app/apps/github/src/issues/issue-list.tsx +682 -0
  171. package/app/apps/github/src/issues/issue-page.tsx +533 -0
  172. package/app/apps/github/src/issues/issues.ts +566 -0
  173. package/app/apps/github/src/issues/label-dialog.tsx +310 -0
  174. package/app/apps/github/src/issues/labels-page.tsx +119 -0
  175. package/app/apps/github/src/issues/new-issue.tsx +79 -0
  176. package/app/apps/github/src/issues/parts.tsx +71 -0
  177. package/app/apps/github/src/issues/picker.tsx +298 -0
  178. package/app/apps/github/src/issues/search.ts +238 -0
  179. package/app/apps/github/src/issues/sidebar.tsx +236 -0
  180. package/app/apps/github/src/lib/cn.ts +8 -0
  181. package/app/apps/github/src/lib/highlighting.ts +13 -0
  182. package/app/apps/github/src/live/follow.ts +129 -0
  183. package/app/apps/github/src/live/sse.ts +74 -0
  184. package/app/apps/github/src/live/use-follow.ts +37 -0
  185. package/app/apps/github/src/markdown/README.md +53 -0
  186. package/app/apps/github/src/markdown/allowed-html.ts +69 -0
  187. package/app/apps/github/src/markdown/context.ts +206 -0
  188. package/app/apps/github/src/markdown/images.ts +81 -0
  189. package/app/apps/github/src/markdown/lookup.ts +127 -0
  190. package/app/apps/github/src/markdown/patches.ts +299 -0
  191. package/app/apps/github/src/markdown/query.ts +25 -0
  192. package/app/apps/github/src/markdown/references.ts +158 -0
  193. package/app/apps/github/src/markdown/render.ts +103 -0
  194. package/app/apps/github/src/names/owners.ts +51 -0
  195. package/app/apps/github/src/names/repos.ts +24 -0
  196. package/app/apps/github/src/palette/palette.tsx +562 -0
  197. package/app/apps/github/src/palette/recent.ts +116 -0
  198. package/app/apps/github/src/palette/rows.tsx +487 -0
  199. package/app/apps/github/src/palette/server.ts +107 -0
  200. package/app/apps/github/src/palette/targets.ts +306 -0
  201. package/app/apps/github/src/policy.ts +606 -0
  202. package/app/apps/github/src/private-repos.ts +47 -0
  203. package/app/apps/github/src/pulls/compare-page.tsx +342 -0
  204. package/app/apps/github/src/pulls/files-tab.tsx +776 -0
  205. package/app/apps/github/src/pulls/live.ts +124 -0
  206. package/app/apps/github/src/pulls/merge-box.tsx +367 -0
  207. package/app/apps/github/src/pulls/merge-button.ts +86 -0
  208. package/app/apps/github/src/pulls/pull-list.tsx +235 -0
  209. package/app/apps/github/src/pulls/pull-page.tsx +474 -0
  210. package/app/apps/github/src/pulls/pull.ts +468 -0
  211. package/app/apps/github/src/pulls/pulls.ts +318 -0
  212. package/app/apps/github/src/pulls/review.ts +350 -0
  213. package/app/apps/github/src/pulls/search.ts +130 -0
  214. package/app/apps/github/src/queue/queue-page.tsx +405 -0
  215. package/app/apps/github/src/queue/queue.ts +231 -0
  216. package/app/apps/github/src/releases/latest-release.tsx +55 -0
  217. package/app/apps/github/src/releases/overview.tsx +30 -0
  218. package/app/apps/github/src/releases/release-form.tsx +353 -0
  219. package/app/apps/github/src/releases/release-list.tsx +173 -0
  220. package/app/apps/github/src/releases/release-view.tsx +183 -0
  221. package/app/apps/github/src/releases/releases.ts +308 -0
  222. package/app/apps/github/src/releases/tag-list.tsx +134 -0
  223. package/app/apps/github/src/router.tsx +46 -0
  224. package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +33 -0
  225. package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +28 -0
  226. package/app/apps/github/src/routes/$owner/$repo/_code.tsx +11 -0
  227. package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +19 -0
  228. package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +19 -0
  229. package/app/apps/github/src/routes/$owner/$repo/_releases.tsx +23 -0
  230. package/app/apps/github/src/routes/$owner/$repo/branches.tsx +39 -0
  231. package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +34 -0
  232. package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +42 -0
  233. package/app/apps/github/src/routes/$owner/$repo/compare/$.tsx +19 -0
  234. package/app/apps/github/src/routes/$owner/$repo/index.tsx +24 -0
  235. package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +50 -0
  236. package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +53 -0
  237. package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +43 -0
  238. package/app/apps/github/src/routes/$owner/$repo/labels.tsx +22 -0
  239. package/app/apps/github/src/routes/$owner/$repo/pull/$number/checks.tsx +15 -0
  240. package/app/apps/github/src/routes/$owner/$repo/pull/$number/commits.tsx +15 -0
  241. package/app/apps/github/src/routes/$owner/$repo/pull/$number/files.tsx +15 -0
  242. package/app/apps/github/src/routes/$owner/$repo/pull/$number/index.tsx +19 -0
  243. package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +52 -0
  244. package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +48 -0
  245. package/app/apps/github/src/routes/$owner/$repo/queue.tsx +22 -0
  246. package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +58 -0
  247. package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +40 -0
  248. package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +35 -0
  249. package/app/apps/github/src/routes/$owner/$repo/route.tsx +102 -0
  250. package/app/apps/github/src/routes/$owner/$repo/settings/access.tsx +9 -0
  251. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +16 -0
  252. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/new.tsx +25 -0
  253. package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +17 -0
  254. package/app/apps/github/src/routes/$owner/$repo/settings/route.tsx +28 -0
  255. package/app/apps/github/src/routes/$owner/$repo/settings/rules.tsx +12 -0
  256. package/app/apps/github/src/routes/$owner/$repo/tokens.tsx +16 -0
  257. package/app/apps/github/src/routes/$owner/index.tsx +45 -0
  258. package/app/apps/github/src/routes/-nav.tsx +293 -0
  259. package/app/apps/github/src/routes/-root-testing.ts +107 -0
  260. package/app/apps/github/src/routes/__root.tsx +225 -0
  261. package/app/apps/github/src/routes/api.auth.$.ts +18 -0
  262. package/app/apps/github/src/routes/downloads/$owner/$repo/$asset.tsx +10 -0
  263. package/app/apps/github/src/routes/file-icons[.]svg.ts +21 -0
  264. package/app/apps/github/src/routes/icons/$owner/$repo.tsx +14 -0
  265. package/app/apps/github/src/routes/icons/$owner/index.tsx +14 -0
  266. package/app/apps/github/src/routes/icons/index.tsx +12 -0
  267. package/app/apps/github/src/routes/index.tsx +48 -0
  268. package/app/apps/github/src/routes/login.tsx +24 -0
  269. package/app/apps/github/src/routes/login_.code.tsx +31 -0
  270. package/app/apps/github/src/routes/new.tsx +91 -0
  271. package/app/apps/github/src/routes/notifications.tsx +20 -0
  272. package/app/apps/github/src/routes/orgs/$owner/issues.tsx +8 -0
  273. package/app/apps/github/src/routes/orgs/$owner/pulls.tsx +8 -0
  274. package/app/apps/github/src/routes/orgs/$owner/releases.tsx +8 -0
  275. package/app/apps/github/src/routes/orgs/$owner/route.tsx +25 -0
  276. package/app/apps/github/src/routes/orgs/$owner/settings.tsx +30 -0
  277. package/app/apps/github/src/routes/orgs/$owner/tokens.tsx +15 -0
  278. package/app/apps/github/src/routes/settings.tsx +54 -0
  279. package/app/apps/github/src/routes/signup.tsx +24 -0
  280. package/app/apps/github/src/routes/uploads/$owner/$repo/$release.tsx +10 -0
  281. package/app/apps/github/src/seed/acme.ts +498 -0
  282. package/app/apps/github/src/seed/licenses.ts +114 -0
  283. package/app/apps/github/src/seed/seed.ts +528 -0
  284. package/app/apps/github/src/server.ts +97 -0
  285. package/app/apps/github/src/settings/account-avatar.tsx +43 -0
  286. package/app/apps/github/src/settings/avatar-section.tsx +140 -0
  287. package/app/apps/github/src/settings/avatar.ts +58 -0
  288. package/app/apps/github/src/settings/general-settings.tsx +439 -0
  289. package/app/apps/github/src/settings/general.ts +73 -0
  290. package/app/apps/github/src/settings/hook-form.tsx +195 -0
  291. package/app/apps/github/src/settings/hook-list.tsx +166 -0
  292. package/app/apps/github/src/settings/hooks.ts +87 -0
  293. package/app/apps/github/src/settings/org-settings.tsx +228 -0
  294. package/app/apps/github/src/settings/orgs.ts +116 -0
  295. package/app/apps/github/src/settings/rule-list.tsx +72 -0
  296. package/app/apps/github/src/settings/rules.ts +27 -0
  297. package/app/apps/github/src/settings/settings-layout.tsx +114 -0
  298. package/app/apps/github/src/signin/approval.ts +186 -0
  299. package/app/apps/github/src/signin/auth-client.ts +127 -0
  300. package/app/apps/github/src/signin/auth.ts +753 -0
  301. package/app/apps/github/src/signin/avatars.ts +126 -0
  302. package/app/apps/github/src/signin/client-ip.ts +39 -0
  303. package/app/apps/github/src/signin/credentials.ts +26 -0
  304. package/app/apps/github/src/signin/device-code.ts +95 -0
  305. package/app/apps/github/src/signin/device-prompt.ts +125 -0
  306. package/app/apps/github/src/signin/errors.ts +135 -0
  307. package/app/apps/github/src/signin/host-session.ts +68 -0
  308. package/app/apps/github/src/signin/orgs.ts +283 -0
  309. package/app/apps/github/src/signin/owner-names.ts +183 -0
  310. package/app/apps/github/src/signin/person-lock.ts +104 -0
  311. package/app/apps/github/src/signin/seal.ts +88 -0
  312. package/app/apps/github/src/signin/seed-people.ts +92 -0
  313. package/app/apps/github/src/signin/session.ts +48 -0
  314. package/app/apps/github/src/signin/unborn.ts +110 -0
  315. package/app/apps/github/src/signin/viewer-orgs.ts +47 -0
  316. package/app/apps/github/src/signin/viewer.ts +74 -0
  317. package/app/apps/github/src/signin/with-headers.ts +14 -0
  318. package/app/apps/github/src/tokens/tokens-page.tsx +529 -0
  319. package/app/apps/github/src/tokens/tokens.ts +54 -0
  320. package/app/apps/github/tsconfig.json +25 -0
  321. package/app/apps/github/tsconfig.worker.json +24 -0
  322. package/app/apps/github/vite.config.ts +21 -0
  323. package/app/pnpm-workspace.yaml +216 -0
  324. package/app/tsconfig.base.json +127 -0
  325. package/dist/LICENSE +202 -0
  326. package/dist/cli/child.mjs +42 -0
  327. package/dist/cli/commands.mjs +23 -0
  328. package/dist/cli/credentials.mjs +84 -0
  329. package/dist/cli/documents.mjs +214 -0
  330. package/dist/cli/events.mjs +55 -0
  331. package/dist/cli/failure.mjs +105 -0
  332. package/dist/cli/folders.mjs +32 -0
  333. package/dist/cli/git-remote-ref0.d.mts +1 -0
  334. package/dist/cli/git-remote-ref0.mjs +29 -0
  335. package/dist/cli/git.mjs +69 -0
  336. package/dist/cli/helpers.mjs +184 -0
  337. package/dist/cli/hosts.mjs +127 -0
  338. package/dist/cli/node.mjs +15 -0
  339. package/dist/cli/output.mjs +135 -0
  340. package/dist/cli/prompt.mjs +35 -0
  341. package/dist/cli/queue.mjs +215 -0
  342. package/dist/cli/ref0-git.d.mts +1 -0
  343. package/dist/cli/ref0-git.mjs +144 -0
  344. package/dist/cli/repos.mjs +162 -0
  345. package/dist/cli/resources.mjs +131 -0
  346. package/dist/cli/run-end.mjs +57 -0
  347. package/dist/cli/runtime.mjs +50 -0
  348. package/dist/cli/setup.mjs +1410 -0
  349. package/dist/cli/sign-in.mjs +162 -0
  350. package/dist/cli/sign-ins.mjs +136 -0
  351. package/dist/cli/sqlite.mjs +28 -0
  352. package/dist/cli/tokens.mjs +141 -0
  353. package/dist/cli/vendor.mjs +123 -0
  354. package/dist/init/app.mjs +231 -0
  355. package/dist/init/astro.mjs +49 -0
  356. package/dist/init/choices.mjs +497 -0
  357. package/dist/init/cloudflare.mjs +324 -0
  358. package/dist/init/create.mjs +151 -0
  359. package/dist/init/detect.mjs +297 -0
  360. package/dist/init/files.mjs +80 -0
  361. package/dist/init/frameworks.mjs +248 -0
  362. package/dist/init/git-module.mjs +49 -0
  363. package/dist/init/github-routes.mjs +66 -0
  364. package/dist/init/jsonc.mjs +143 -0
  365. package/dist/init/metadata.mjs +48 -0
  366. package/dist/init/mounts.mjs +109 -0
  367. package/dist/init/next.mjs +203 -0
  368. package/dist/init/node-app.mjs +189 -0
  369. package/dist/init/node.mjs +460 -0
  370. package/dist/init/nuxt.mjs +115 -0
  371. package/dist/init/output.mjs +21 -0
  372. package/dist/init/plan.mjs +82 -0
  373. package/dist/init/range-major.mjs +257 -0
  374. package/dist/init/react-router.mjs +59 -0
  375. package/dist/init/routes.mjs +148 -0
  376. package/dist/init/shell.mjs +4 -0
  377. package/dist/init/stores.mjs +51 -0
  378. package/dist/init/sveltekit.mjs +139 -0
  379. package/dist/init/template.mjs +142 -0
  380. package/dist/init/templates.mjs +343 -0
  381. package/dist/init/vercel.mjs +384 -0
  382. package/dist/init/versions.mjs +32 -0
  383. package/dist/init/workspace.mjs +20 -0
  384. package/package.json +48 -6
  385. package/README.md +0 -5
@@ -0,0 +1,49 @@
1
+ import { lines, served } from "./files.mjs";
2
+ import { looseLimits } from "@ref0/git";
3
+ // src/init/git-module.ts
4
+ /**
5
+ * The lines Cloudflare's and Node's `src/git.ts` share, from its imports of Git to its handlers,
6
+ * so the two say one thing the same way.
7
+ */
8
+ /** Git's packages a setup depends on, at this release. */
9
+ const gitPackages = (choices) => [
10
+ "@ref0/git",
11
+ ...choices.serve === "github" ? ["@ref0/github"] : [],
12
+ "@ref0/infra"
13
+ ];
14
+ /** `src/git.ts`'s first lines: what it serves, on `on`, and whose file it is. */
15
+ const header = (choices, on) => lines(`// Git on ${on}, ${served[choices.serve]}${choices.queue === "on" ? ", with a merge queue on `main`" : ""}. Written by`, "// `ref0-git init`, and yours to change: `init` rewrites it only while it reads as written, and", "// `ref0-git doctor` checks it.", choices.serve === "git" && "// Nothing here makes a repo over HTTP: make one from code, as `git.repos.create({ id: 'acme/app' })`.");
16
+ /** The `@ref0/git` import, naming what the choices use. */
17
+ const gitImport = (choices) => {
18
+ const packs = choices.objects === "packs";
19
+ const queue = choices.queue === "on";
20
+ return `import { accept, createGitServer, ${packs ? "" : "loose, "}${queue ? "mergeQueue, " : ""}${packs ? "packs, " : ""}reject } from '@ref0/git';`;
21
+ };
22
+ /** Git's imports, from `@ref0/git` to the drop-in, with `xdiff`'s import where its module sorts. */
23
+ const gitImports = (choices, xdiff) => lines(gitImport(choices), choices.queue === "on" && "import type { MergeInput, MergePlan } from '@ref0/git';", "import { bearer, tokens } from '@ref0/git/auth';", "import { engine } from '@ref0/git/engine';", !xdiff.last && xdiff.line, choices.serve !== "git" && "import { createRestHandler } from '@ref0/git/rest';", xdiff.last && xdiff.line, choices.serve === "github" && "import { createGitHubHandler } from '@ref0/github';");
24
+ /** Who `ADMIN_TOKEN` signs in as. */
25
+ const adminLines = lines("/** Who `ADMIN_TOKEN` signs in as: it makes repos and tokens, and never pushes. */", "const admin = { id: '_admin' };", "");
26
+ /** How the queue writes an entry onto `main`, when there's a queue. */
27
+ const mergeLines = (choices) => choices.queue === "on" && lines("/** How the queue writes an entry onto `main`: a merge commit, by whoever added it. */", "const merge = ({ entry }: MergeInput): MergePlan => ({", " method: 'merge',", " message: `Merge ${entry.source.replace(/^refs\\/heads\\//, '')}\\n`,", " author: {", " name: entry.actor.id,", " email: `${entry.actor.id}@users.noreply.git`,", " at: Date.now(),", " offset: 0,", " },", "});", "");
28
+ /** `createGitServer`'s lines for a push's pack upload, once the bucket signs parts. */
29
+ const uploads = " // A push past 64 MiB may upload its pack, once the bucket signs parts.\n pushes: { upload: { above: 64 * 1024 * 1024 } },";
30
+ /** What one push may carry into `loose()`, as `@ref0/git` holds it. */
31
+ const looseSays = `up to ${looseLimits.objects.toLocaleString("en-US")} objects and ${looseLimits.bytes / 1024 / 1024} MiB a push`;
32
+ /** `createGitServer`'s `objects` with no bucket: each object a row, and what `loose()` takes. */
33
+ const looseObjects = ` // Each object a row in its push's commit: no bucket, ${looseSays}.\n objects: loose(),`;
34
+ /** `createGitServer`'s `basePath`, when Git's URLs are under one. */
35
+ const basePathLines = (choices) => choices.basePath !== "/" && ` // Git's URLs, Smart HTTP, sign-in and REST, under this path.\n basePath: '${choices.basePath.replace(/\/$/, "")}',`;
36
+ /** `createGitServer`'s events, under `--serve github`. */
37
+ const eventsLines = " // Git's events go to the drop-in, which follows each push: a pull request's head, its queue.\n events: (input) => github.events(input),";
38
+ /** The drop-in's handler, under `--serve github`. */
39
+ const githubHandler = "/** GitHub's REST, GraphQL, webhooks and Event Streams, so `gh` and Octokit work. */\nexport const github = createGitHubHandler(git);\n";
40
+ /** `export const git = createGitServer({ … });`, as chosen. */
41
+ const serverLines = (choices, parts) => lines("export const git = createGitServer({", parts.adapter, choices.objects === "packs" ? " objects: packs()," : looseObjects, ` engine: ${parts.engine},`, " tokens: tokens(),", parts.uploads && " // A push past 64 MiB may upload its pack, once the bucket signs parts.\n pushes: { upload: { above: 64 * 1024 * 1024 } },", basePathLines(choices), ` auth: bearer({ token: ${parts.token}, actor: admin }),`, " authorize: ({ actor, operation }) => {", " if (actor.anonymous === true) return reject({ message: 'Sign in first' });", "", " if (actor.id === admin.id && operation.kind === 'push') {", " return reject({", " message: \"The admin token can't push\",", " hint: 'Make a write token for yourself: npx ref0-git tokens create --help',", " });", " }", "", " return accept();", " },", choices.queue === "on" && " queue: mergeQueue({ target: 'refs/heads/main', merge }),", choices.serve === "github" && " // Git's events go to the drop-in, which follows each push: a pull request's head, its queue.\n events: (input) => github.events(input),", "});", "");
42
+ /** The drop-in's and the REST's handlers, as served: none for Git's protocol alone. */
43
+ const handlerLines = (choices) => choices.serve !== "git" && lines(choices.serve === "github" && "/** GitHub's REST, GraphQL, webhooks and Event Streams, so `gh` and Octokit work. */\nexport const github = createGitHubHandler(git);\n", "/** Git's REST, whose `route` and `fetch` serve Git's protocol and sign-in too. */\nexport const rest = createRestHandler(git);\n");
44
+ /**
45
+ * A framework's `serve` under `--serve github`, which its Git route calls: the drop-in's links
46
+ * under the base path first, then REST and Git's protocol.
47
+ */
48
+ const serveExport = (choices) => choices.serve === "github" && lines(`/** What \`${choices.basePath.replace(/\/$/, "")}\` serves: the drop-in's links first, then REST and Git's protocol. */`, "export const serve = {", " fetch: async (request: Request) => (await github.route(request)) ?? rest.fetch(request),", "};", "");
49
+ export { adminLines, basePathLines, eventsLines, gitImports, gitPackages, githubHandler, handlerLines, header, looseObjects, looseSays, mergeLines, serveExport, serverLines, uploads };
@@ -0,0 +1,66 @@
1
+ // src/init/github-routes.ts
2
+ /** Every URL the drop-in answers at the root, as `@ref0/github`'s `githubRoutes` lists them. */
3
+ const githubRoutes = [
4
+ {
5
+ path: "api/v3",
6
+ tail: "optional",
7
+ methods: [
8
+ "DELETE",
9
+ "GET",
10
+ "HEAD",
11
+ "PATCH",
12
+ "POST",
13
+ "PUT"
14
+ ]
15
+ },
16
+ {
17
+ path: "api/graphql",
18
+ tail: "none",
19
+ methods: ["POST"]
20
+ },
21
+ {
22
+ path: "api/uploads",
23
+ tail: "rest",
24
+ methods: [
25
+ "DELETE",
26
+ "GET",
27
+ "HEAD",
28
+ "PATCH",
29
+ "POST",
30
+ "PUT"
31
+ ]
32
+ },
33
+ {
34
+ path: "avatars/u",
35
+ tail: "segment",
36
+ methods: ["GET", "HEAD"]
37
+ },
38
+ {
39
+ path: ":owner/:repo.git/info/refs",
40
+ tail: "none",
41
+ methods: ["GET", "HEAD"]
42
+ },
43
+ {
44
+ path: ":owner/:repo.git/git-upload-pack",
45
+ tail: "none",
46
+ methods: ["POST"]
47
+ },
48
+ {
49
+ path: ":owner/:repo.git/git-receive-pack",
50
+ tail: "none",
51
+ methods: ["POST"]
52
+ },
53
+ {
54
+ path: ":owner/:repo.git/info/lfs",
55
+ tail: "rest",
56
+ methods: [
57
+ "DELETE",
58
+ "GET",
59
+ "HEAD",
60
+ "PATCH",
61
+ "POST",
62
+ "PUT"
63
+ ]
64
+ }
65
+ ];
66
+ export { githubRoutes };
@@ -0,0 +1,143 @@
1
+ import * as Option from "effect/Option";
2
+ import * as Predicate from "effect/Predicate";
3
+ import * as Schema from "effect/Schema";
4
+ // src/init/jsonc.ts
5
+ const decodeString = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.String));
6
+ /** A key, or a string value, as JSON writes it, quoted and escaped. */
7
+ const jsonKey = Schema.encodeSync(Schema.fromJsonString(Schema.String));
8
+ /** A value with no members, a string, number, boolean or null, as JSON writes it. */
9
+ const jsonLeaf = Schema.encodeSync(Schema.fromJsonString(Schema.Json));
10
+ const literal = /-?\d[\d.eE+-]*|true|false|null/y;
11
+ /** `text`'s tree, or `undefined` when it isn't one JSONC value: comments and trailing commas pass. */
12
+ const parseJsonc = (text) => {
13
+ let at = text.startsWith("") ? 1 : 0;
14
+ const skip = () => {
15
+ for (;;) {
16
+ while (/\s/.test(text[at] ?? "")) at += 1;
17
+ if (text.startsWith("/*", at) && !text.includes("*/", at + 2)) throw new SyntaxError("comment");
18
+ const end = text.startsWith("//", at) ? text.indexOf("\n", at) : text.startsWith("/*", at) ? text.indexOf("*/", at + 2) + 2 : at;
19
+ if (end === at) return text[at];
20
+ at = end <= at ? text.length : end;
21
+ }
22
+ };
23
+ const string = () => {
24
+ const start = at;
25
+ for (at += 1; at < text.length && text[at] !== "\""; at += text[at] === "\\" ? 2 : 1);
26
+ if (at >= text.length) throw new SyntaxError("string");
27
+ at += 1;
28
+ return {
29
+ kind: "value",
30
+ start,
31
+ end: at,
32
+ raw: text.slice(start, at)
33
+ };
34
+ };
35
+ const value = () => {
36
+ const next = skip();
37
+ const start = at;
38
+ if (next === "\"") return string();
39
+ if (next === "{" || next === "[") {
40
+ at += 1;
41
+ const members = [];
42
+ const items = [];
43
+ const close = next === "{" ? "}" : "]";
44
+ while (skip() !== close) {
45
+ if (next === "{") {
46
+ if (skip() !== "\"") throw new SyntaxError("key");
47
+ const key = Option.getOrUndefined(decodeString(string().raw));
48
+ if (skip() !== ":" || key === void 0) throw new SyntaxError("colon");
49
+ at += 1;
50
+ members.push({
51
+ key,
52
+ value: value()
53
+ });
54
+ } else items.push(value());
55
+ if (skip() === ",") at += 1;
56
+ else if (skip() !== close) throw new SyntaxError("comma");
57
+ }
58
+ at += 1;
59
+ return next === "{" ? {
60
+ kind: "object",
61
+ start,
62
+ end: at,
63
+ members
64
+ } : {
65
+ kind: "array",
66
+ start,
67
+ end: at,
68
+ items
69
+ };
70
+ }
71
+ literal.lastIndex = at;
72
+ const matched = literal.exec(text)?.[0];
73
+ if (matched === void 0) throw new SyntaxError("value");
74
+ at += matched.length;
75
+ return {
76
+ kind: "value",
77
+ start,
78
+ end: at,
79
+ raw: matched
80
+ };
81
+ };
82
+ try {
83
+ const tree = value();
84
+ return skip() === void 0 ? tree : void 0;
85
+ } catch {
86
+ return;
87
+ }
88
+ };
89
+ /** The node at `path` of object keys under `node`, if every key is there. */
90
+ const nodeAt = (node, path) => path.reduce((from, key) => from?.kind === "object" ? from.members.findLast((member) => member.key === key)?.value : void 0, node);
91
+ /** The string at `path` under `node`, if there's one there. */
92
+ const stringAt = (node, path) => {
93
+ const found = nodeAt(node, path);
94
+ return found?.kind === "value" ? Option.getOrUndefined(decodeString(found.raw)) : void 0;
95
+ };
96
+ /** The items of the array at `path` under `node`, none when there's no array. */
97
+ const itemsAt = (node, path) => {
98
+ const found = nodeAt(node, path);
99
+ return found?.kind === "array" ? found.items : [];
100
+ };
101
+ /** A value on one line, as the repo's configs write it: `{ "a": 1 }`, `[1, 2]`. */
102
+ const inline = (value) => Array.isArray(value) ? `[${value.map(inline).join(", ")}]` : Predicate.isObject(value) ? `{ ${Object.entries(value).map(([key, each]) => `${jsonKey(key)}: ${inline(each)}`).join(", ")} }` : jsonLeaf(value);
103
+ /** The spaces a line starts with, for the line `at` is on. */
104
+ const indentAt = (text, at) => /^[ \t]*/.exec(text.slice(text.lastIndexOf("\n", at - 1) + 1))?.[0] ?? "";
105
+ /**
106
+ * `text` with `entries` added at the end of `container`, an object's members or an array's items,
107
+ * each already written: on lines of their own in a container that spans lines, else on its line.
108
+ */
109
+ const insertInto = (text, container, entries) => {
110
+ if (container.kind === "value" || entries.length === 0) return text;
111
+ const last = container.kind === "object" ? container.members.at(-1)?.value : container.items.at(-1);
112
+ const spans = text.slice(container.start, container.end).includes("\n");
113
+ const indent = last === void 0 ? `${indentAt(text, container.start)} ` : indentAt(text, last.start);
114
+ const separator = spans ? `,\n${indent}` : ", ";
115
+ const pad = container.kind === "object" ? " " : "";
116
+ const added = last === void 0 ? spans ? `\n${indent}${entries.join(separator)}` : `${pad}${entries.join(separator)}${pad}` : `${separator}${entries.join(separator)}`;
117
+ const at = last === void 0 ? container.start + 1 : last.end;
118
+ return `${text.slice(0, at)}${added}${text.slice(at)}`;
119
+ };
120
+ /**
121
+ * `text` with what's missing of `wanted` at `path`: an array's new items at its end, an object's
122
+ * new keys after its last, and any object on the way made with the rest inside it.
123
+ */
124
+ const withEntries = (text, path, wanted) => {
125
+ const tree = parseJsonc(text);
126
+ const found = path.findIndex((_, depth) => nodeAt(tree, path.slice(0, depth + 1)) === void 0);
127
+ if (found !== -1) {
128
+ const nested = path.slice(found + 1).reduceRight((inner, key) => ({ [key]: inner }), wanted);
129
+ const parent = nodeAt(tree, path.slice(0, found));
130
+ const key = path[found];
131
+ return parent === void 0 || key === void 0 ? text : insertInto(text, parent, [`${jsonKey(key)}: ${inline(nested)}`]);
132
+ }
133
+ const container = nodeAt(tree, path);
134
+ if (container === void 0) return text;
135
+ const added = Array.isArray(wanted) ? wanted.map(inline) : Object.entries(wanted).filter(([key]) => nodeAt(container, [key]) === void 0).map(([key, value]) => `${jsonKey(key)}: ${inline(value)}`);
136
+ return insertInto(text, container, added);
137
+ };
138
+ /** `text` with the value at `path` written as `value`, when it's there. */
139
+ const withValue = (text, path, value) => {
140
+ const node = nodeAt(parseJsonc(text), path);
141
+ return node === void 0 ? text : `${text.slice(0, node.start)}${inline(value)}${text.slice(node.end)}`;
142
+ };
143
+ export { inline, insertInto, itemsAt, nodeAt, parseJsonc, stringAt, withEntries, withValue };
@@ -0,0 +1,48 @@
1
+ // src/init/metadata.ts
2
+ /** The version `ref0-git`, `create-ref0-git` and Git's packages release at, all at once (Q738). */
3
+ const release = "0.3.0";
4
+ /** The packages the app depends on, by their folder in a checkout's `packages/`. */
5
+ const appPackages = [
6
+ "infra",
7
+ "git",
8
+ "github"
9
+ ];
10
+ /** What every platform's project builds and types with. At the root workspace's catalog. */
11
+ const catalog = {
12
+ "@cloudflare/workers-types": "5.20261116.1",
13
+ typescript: "7.0.2",
14
+ wrangler: "4.163.0"
15
+ };
16
+ /** What Git on Vercel installs beside Git's packages. At the root workspace's catalog. */
17
+ const vercelPackages = {
18
+ "@types/node": "24.19.2",
19
+ "@vercel/blob": "2.9.0",
20
+ "@vercel/queue": "0.11.0",
21
+ typescript: "7.0.2"
22
+ };
23
+ /** What Git on Node type-checks with beside the store's client. At the root workspace's catalog. */
24
+ const nodePackages = { "@types/node": "24.19.2" };
25
+ /**
26
+ * What the app on Node builds and reads its people with, beside the store's client (Q-IN14). At the
27
+ * root workspace's catalog.
28
+ */
29
+ const nodeAppPackages = {
30
+ "@libsql/kysely-libsql": "0.4.1",
31
+ nitro: "3.0.261103-rc"
32
+ };
33
+ /**
34
+ * The clients of the stores more than one platform offers, as `init/stores.ts` names them. At the
35
+ * root workspace's catalog.
36
+ */
37
+ const storePackages = {
38
+ "@libsql/client": "0.18.0",
39
+ "@types/pg": "8.23.1",
40
+ pg: "8.23.1"
41
+ };
42
+ /**
43
+ * What a framework's Node server needs that its create command doesn't write: SvelteKit's
44
+ * adapter-node, in place of `sv create`'s adapter-auto. At the framework fixtures' own catalog,
45
+ * which differs from the root's.
46
+ */
47
+ const frameworkPackages = { "@sveltejs/adapter-node": "6.0.5" };
48
+ export { appPackages, catalog, frameworkPackages, nodeAppPackages, nodePackages, release, storePackages, vercelPackages };
@@ -0,0 +1,109 @@
1
+ import { matcherCall, matcherImport, servedBy } from "./routes.mjs";
2
+ // src/init/mounts.ts
3
+ /**
4
+ * The server module's exports a mount imports: the jobs, and what serves Git's URLs, as `git` in
5
+ * Hono's, whose app imports `serve` from `@hono/node-server`.
6
+ */
7
+ const importsOf = (choices, asGit) => servedBy(choices) === "git" ? "git, jobs" : `jobs, ${servedBy(choices)}${asGit ? " as git" : ""}`;
8
+ /** Express's middleware, before any body parser, as printed source: the matcher's paths to Git. */
9
+ const expressLine = (choices) => `app.use(toNodeMiddleware(${servedBy(choices)}, (url) => ${matcherCall(choices)}))`;
10
+ /**
11
+ * The imports a mount's lines start with: `@ref0/git/node`'s `names`, the matcher, and the module,
12
+ * its export `as git` where `asGit`.
13
+ */
14
+ const imports = (choices, names, asGit = false) => [
15
+ `import { ${names} } from '@ref0/git/node';`,
16
+ matcherImport(choices),
17
+ `import { ${importsOf(choices, asGit)} } from './git.ts';`,
18
+ ""
19
+ ];
20
+ /** What Hono's lines take from Node and `@hono/node-server`: a server, and the app as a listener. */
21
+ const honoImports = ["import { createServer } from 'node:http';", "import { getRequestListener } from '@hono/node-server';"];
22
+ /**
23
+ * Git's jobs, started, and stopped on `SIGTERM`. A listener takes away Node's own exit on it, so
24
+ * the listener runs once, then raises it again for Node, or the person's own listener, to exit.
25
+ */
26
+ const startLines = [
27
+ "const stop = jobs.start();",
28
+ "",
29
+ "process.once('SIGTERM', () => void stop().finally(() => process.kill(process.pid, 'SIGTERM')));"
30
+ ];
31
+ /** Each server's lines, after its imports. */
32
+ const mountLines = (server, choices) => {
33
+ const serve = servedBy(choices);
34
+ if (server === "hono") return [
35
+ ...startLines,
36
+ "",
37
+ `const mount = toNodeMiddleware(git, (url) => ${matcherCall(choices)});`,
38
+ "",
39
+ "const listener = getRequestListener(app.fetch);",
40
+ "",
41
+ "// In place of serve(), after the app's routes: Git answers its URLs in front of the app, as",
42
+ "// Express's middleware does, so Hono's middleware doesn't run on them; a guard for Git goes",
43
+ "// in git.ts's authorize. Every other request goes on to the app. Over HTTP/2, node:http2's",
44
+ "// createSecureServer takes it too.",
45
+ "createServer((incoming, outgoing) =>",
46
+ " mount(incoming, outgoing, () => void listener(incoming, outgoing)),",
47
+ ").listen(Number(process.env['PORT'] ?? 3000));"
48
+ ];
49
+ if (server === "express") return [
50
+ ...startLines,
51
+ "",
52
+ "// Before express.json() or any body parser, which would read the body Git streams.",
53
+ `${expressLine(choices)};`
54
+ ];
55
+ return [
56
+ "const stop = jobs.start();",
57
+ "",
58
+ "app.addHook('onClose', () => stop());",
59
+ "",
60
+ "// Git's URLs, answered before Fastify parses a body, so the body streams to Git and your routes",
61
+ "// keep their parsers and bodyLimit. The middleware calls its next before it returns, or never.",
62
+ `const mount = toNodeMiddleware(${serve}, (url) => ${matcherCall(choices)});`,
63
+ "",
64
+ "app.addHook('onRequest', (request, reply, done) => {",
65
+ " let passed = false;",
66
+ " mount(request.raw, reply.raw, () => (passed = true));",
67
+ "",
68
+ " if (!passed) reply.hijack();",
69
+ " done();",
70
+ "});"
71
+ ];
72
+ };
73
+ const mounting = (name) => name === "hono" || name === "express" || name === "fastify";
74
+ /** Each server's step, in a few words. */
75
+ const says = {
76
+ hono: "Start Git's jobs and serve it in front of your Hono app, in the file that makes it, in place of serve()",
77
+ express: "Start Git's jobs and serve it, in the file that makes your Express app, before any body parser",
78
+ fastify: "Start Git's jobs and serve it, in the file that makes your Fastify app, from an onRequest hook"
79
+ };
80
+ /**
81
+ * The printed step that mounts Git in the person's server: `framework`'s own words for Hono,
82
+ * Express and Fastify, whatever their major, and for any other `node:http`'s, where Git takes every
83
+ * path, and Express's, commented.
84
+ */
85
+ const mountManual = (choices, framework) => {
86
+ if (mounting(framework)) return {
87
+ path: "its server",
88
+ why: "yours",
89
+ says: says[framework],
90
+ lines: [
91
+ ...framework === "hono" ? honoImports : [],
92
+ ...imports(choices, "toNodeMiddleware", framework === "hono"),
93
+ ...mountLines(framework, choices)
94
+ ]
95
+ };
96
+ return {
97
+ path: "its server",
98
+ why: "yours",
99
+ says: "Start Git's jobs and serve it, before any body parser, which would read the body Git streams",
100
+ lines: [
101
+ ...imports(choices, "toNodeHandler, toNodeMiddleware"),
102
+ ...startLines,
103
+ "",
104
+ `// node:http: createServer(toNodeHandler(${servedBy(choices)})).`,
105
+ `// Express, before express.json(): ${expressLine(choices)}.`
106
+ ]
107
+ };
108
+ };
109
+ export { mountManual };
@@ -0,0 +1,203 @@
1
+ import { lines } from "./files.mjs";
2
+ import { nextConfigs } from "./frameworks.mjs";
3
+ import { gitRoutes, rootGitPattern } from "./routes.mjs";
4
+ // src/init/next.ts
5
+ /**
6
+ * What `init` writes in a Next.js project: a route file for Git's URLs under the base path, one
7
+ * for each of the drop-in's paths at the root, and on Vercel the two job routes `vercel.json`
8
+ * names. Each route loads the server module on its first request: `next build` loads every route
9
+ * to read its options, and one that imported the module at its top would open the database and
10
+ * want `ADMIN_TOKEN` at build time.
11
+ */
12
+ /** The job routes on Vercel: the queue's deliveries, which `vercel.json`'s trigger names, and the cron's. */
13
+ const nextJobRoutes = (framework) => {
14
+ const app = framework.appDir ?? "app";
15
+ return {
16
+ jobs: `${app}/api/git-jobs/route.ts`,
17
+ sweep: `${app}/api/git-jobs/sweep/route.ts`
18
+ };
19
+ };
20
+ /** The cron's path, which `app/api/git-jobs/sweep/route.ts` answers. */
21
+ const nextSweepPath = "/api/git-jobs/sweep";
22
+ /** `to`'s import specifier from the file at `from`, as Next.js takes it: relative, with no `.ts`. */
23
+ const importOf = (from, to) => {
24
+ const ups = from.split("/").length - 1;
25
+ return `${"../".repeat(ups)}${to.replace(/\.ts$/, "")}`;
26
+ };
27
+ const loaded = ["// Loaded on the first request, so `next build`, which loads each route to read its options, opens", "// no database and needs no secret."];
28
+ /** The route's handler over `call`, on one line where it fits, as the formatter breaks it. */
29
+ const handlerLine = (call) => {
30
+ const head = "const git = async (request: Request) =>";
31
+ return `${head} ${call}`.length > 100 ? `${head}\n ${call}` : `${head} ${call}`;
32
+ };
33
+ /** Next.js's folders for each parameter a route ends with. */
34
+ const nextTails = {
35
+ rest: "[...path]/",
36
+ optional: "[[...path]]/",
37
+ segment: "[id]/",
38
+ none: ""
39
+ };
40
+ /** One route file: the lazy handler over its export, and on Vercel the plan's `maxDuration`. */
41
+ const routeFile = (route, app, module, maxDuration) => {
42
+ const path = `${app}/${route.at}/${nextTails[route.tail]}route.ts`;
43
+ return {
44
+ path,
45
+ kind: "whole",
46
+ text: lines(`// ${route.says} Written by \`ref0-git init\`.`, ...loaded, handlerLine(`(await import('${importOf(path, module)}')).${route.calls}.fetch(request);`), "", maxDuration !== void 0 && `export const maxDuration = ${maxDuration};\n`, `export { ${route.methods.map((method) => `git as ${method}`).join(", ")} };`, "")
47
+ };
48
+ };
49
+ /** A job route on Vercel: `jobs.fetch` for the queue's message or the cron's call. */
50
+ const jobFile = (path, method, says, module, maxDuration) => ({
51
+ path,
52
+ kind: "whole",
53
+ text: lines(...says, "// Written by `ref0-git init`.", `export const maxDuration = ${maxDuration};`, "", `export const ${method} = async (request: Request) => {`, ` const { jobs } = await import('${importOf(path, module)}');`, "", " return (await jobs.fetch(request)) ?? new Response(null, { status: 404 });", "};", "")
54
+ });
55
+ /** Next.js's route files for `choices`, over `framework`'s server module; on Vercel, at `maxDuration`. */
56
+ const nextRouteFiles = (choices, framework, maxDuration) => gitRoutes(choices).map((route) => routeFile(route, framework.appDir ?? "app", framework.serverModule, maxDuration));
57
+ /** The two job routes on Vercel, at the plan's `maxDuration`. */
58
+ const nextJobFiles = (framework, maxDuration) => {
59
+ const { jobs, sweep } = nextJobRoutes(framework);
60
+ return [jobFile(jobs, "POST", ["// Vercel Queues' deliveries: `vercel.json` gives this route the trigger, which makes it private."], framework.serverModule, maxDuration), jobFile(sweep, "GET", ["// The cron's sweep, refused without `CRON_SECRET`: a message for each scope with work due."], framework.serverModule, maxDuration)];
61
+ };
62
+ /**
63
+ * `gh` builds a repo's Git URL from the host, `/<owner>/<repo>.git/…` at the root, whatever
64
+ * `clone_url` says, and git-lfs keeps it for every batch. This rewrite sends only those endings,
65
+ * in place, to Git's route under the base path, before the app's own routes: Next.js matches
66
+ * `:repo.git` as the param and a literal `.git`, and keeps the request's query.
67
+ */
68
+ const nextRewrite = (choices) => ({
69
+ source: `/:owner/:repo.git/:end(${rootGitPattern({
70
+ slash: "/",
71
+ more: ".*"
72
+ })})`,
73
+ destination: `${choices.basePath.replace(/\/$/, "")}/:owner/:repo.git/:end`
74
+ });
75
+ /** `rewrites()`, as a `next.config`'s member holds it, indented by two. */
76
+ const rewritesLines = (choices) => {
77
+ const { source, destination } = nextRewrite(choices);
78
+ return [
79
+ " // gh's Git URLs at the root, `/<owner>/<repo>.git/…`, to Git's route, before the app's own.",
80
+ " // Written by `ref0-git init`.",
81
+ " async rewrites() {",
82
+ " return {",
83
+ " beforeFiles: [",
84
+ " {",
85
+ ` source: '${source}',`,
86
+ ` destination: '${destination}',`,
87
+ " },",
88
+ " ],",
89
+ " };",
90
+ " },"
91
+ ];
92
+ };
93
+ /** `init`'s own `next.config.ts`, with the rewrite in it: what it writes where there's none. */
94
+ const nextConfigText = (choices) => lines("import type { NextConfig } from \"next\";", "", "const nextConfig: NextConfig = {", ...rewritesLines(choices), "};", "", "export default nextConfig;", "");
95
+ /**
96
+ * The line of `create-next-app`'s `next.config.ts` the rewrite goes after: `init` edits the file the
97
+ * create command actually wrote there, when the line is in it exactly once.
98
+ */
99
+ const nextConfigAnchor = "const nextConfig: NextConfig = {\n";
100
+ /**
101
+ * The rewrite after `path`'s one anchor line, as an edit of `text`, or `undefined` where the line
102
+ * isn't there exactly once.
103
+ */
104
+ const withRewrite = (path, text, choices) => {
105
+ const at = text.indexOf(nextConfigAnchor);
106
+ if (at === -1 || text.includes("const nextConfig: NextConfig = {\n", at + 1)) return void 0;
107
+ const after = at + 33;
108
+ const adds = rewritesLines(choices);
109
+ return {
110
+ path,
111
+ kind: "edit",
112
+ from: text,
113
+ text: `${text.slice(0, after)}${adds.join("\n")}\n${text.slice(after)}`,
114
+ edit: {
115
+ anchor: nextConfigAnchor.trimEnd(),
116
+ adds,
117
+ swaps: []
118
+ }
119
+ };
120
+ };
121
+ /** Whether a `next.config`'s text has the rewrite, as `init` writes it. */
122
+ const rewrites = (text, choices) => {
123
+ const { source, destination } = nextRewrite(choices);
124
+ return text.includes(source) && text.includes(destination);
125
+ };
126
+ /**
127
+ * The rewrite under `--serve github`: a `next.config.ts` where the project has none, or, in the one
128
+ * a create command wrote in this same run, after its anchor line; else, in the person's own
129
+ * `next.config`, or one whose anchor isn't there exactly once, a printed step.
130
+ */
131
+ const nextConfigOutput = (choices, framework, created) => {
132
+ const { config } = framework;
133
+ if (choices.serve !== "github" || config !== void 0 && rewrites(config.text, choices)) return {
134
+ files: [],
135
+ manual: []
136
+ };
137
+ if (config === void 0) return {
138
+ files: [{
139
+ path: "next.config.ts",
140
+ kind: "whole",
141
+ text: nextConfigText(choices)
142
+ }],
143
+ manual: []
144
+ };
145
+ const edited = created ? withRewrite(config.path, config.text, choices) : void 0;
146
+ if (edited !== void 0) return {
147
+ files: [edited],
148
+ manual: []
149
+ };
150
+ return {
151
+ files: [],
152
+ manual: [{
153
+ path: config.path,
154
+ says: "Rewrite gh's root Git URLs to Git's route, in nextConfig",
155
+ why: created ? "template_changed" : "yours",
156
+ lines: rewritesLines(choices)
157
+ }]
158
+ };
159
+ };
160
+ /** The files Next.js runs before every route it matches, newest name first, at the root or in `src/`. */
161
+ const proxyFiles = [
162
+ "proxy.ts",
163
+ "proxy.js",
164
+ "middleware.ts",
165
+ "middleware.js"
166
+ ].flatMap((file) => [file, `src/${file}`]);
167
+ /**
168
+ * Whether a proxy's `matcher` takes `/<base>/…`: none matches every path, as does a catch-all whose
169
+ * pattern doesn't name the base; one that starts with it takes it too.
170
+ */
171
+ const takesGit = (text, base) => {
172
+ const matchers = [...(/\bmatcher\s*:\s*(\[[^\]]*\]|'[^']*'|"[^"]*")/.exec(text)?.[1] ?? "").matchAll(/['"]([^'"]*)['"]/g)].map(([, pattern = ""]) => pattern);
173
+ if (matchers.length === 0) return true;
174
+ return matchers.some((pattern) => pattern.startsWith(`/${base}`) || /^\/(\(\.\*\)|:path\*|\(\(\?!)/.test(pattern) && !pattern.includes(base));
175
+ };
176
+ /** Whether `next.config` rewrites `gh`'s root Git URLs, which `gh repo clone` and `gh pr checkout` use. */
177
+ const rootUrls = (read, choices) => {
178
+ const config = nextConfigs.find((path) => read(path) !== void 0);
179
+ const ok = config !== void 0 && rewrites(read(config) ?? "", choices);
180
+ return {
181
+ check: "Root URLs",
182
+ ok,
183
+ says: ok ? `${config ?? ""} rewrites gh's /<owner>/<repo>.git/ URLs to ${choices.basePath}` : `${config ?? "No next.config"} rewrites no /<owner>/<repo>.git/ URL, so gh repo clone gets Next.js's 404: add the rewrite init printed`,
184
+ blocks: "gh repo clone and gh pr checkout"
185
+ };
186
+ };
187
+ /** `doctor`'s Next.js checks: a proxy that buffers Git's pushes, and the drop-in's `/api/v3/` 308. */
188
+ const nextFindings = (read, choices) => {
189
+ const base = choices.basePath.replace(/^\/|\/$/g, "");
190
+ const proxy = proxyFiles.find((file) => read(file) !== void 0);
191
+ const buffers = proxy !== void 0 && takesGit(read(proxy) ?? "", base);
192
+ return [{
193
+ check: "Proxy",
194
+ ok: !buffers,
195
+ says: proxy === void 0 ? "No proxy.ts or middleware.ts, so Next.js streams a push to Git as it arrives" : buffers ? `${proxy}'s matcher takes /${base}, so Next.js buffers a push's first 10 MB and refuses a larger one: leave /${base} out of its matcher` : `${proxy}'s matcher leaves /${base} out, so Next.js streams a push to Git as it arrives`,
196
+ blocks: "pushes over 10 MB"
197
+ }, ...choices.serve === "github" ? [rootUrls(read, choices), {
198
+ check: "API root",
199
+ ok: true,
200
+ says: "Next.js answers /api/v3/ with a 308 to /api/v3, which gh follows for a GET"
201
+ }] : []];
202
+ };
203
+ export { nextConfigAnchor, nextConfigOutput, nextFindings, nextJobFiles, nextJobRoutes, nextRewrite, nextRouteFiles, nextSweepPath };