ref0-git 0.2.0 → 0.4.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 (210) hide show
  1. package/app/apps/github/.dev.vars.example +2 -1
  2. package/app/apps/github/generated/git-rest.ts +191 -25
  3. package/app/apps/github/generated/routeTree.gen.ts +21 -0
  4. package/app/apps/github/package.json +1 -1
  5. package/app/apps/github/src/branches/branch-list.tsx +8 -4
  6. package/app/apps/github/src/branches/branches.ts +10 -5
  7. package/app/apps/github/src/camo/addresses.ts +120 -0
  8. package/app/apps/github/src/camo/client.ts +125 -0
  9. package/app/apps/github/src/camo/fetch.ts +201 -0
  10. package/app/apps/github/src/camo/lookup.ts +23 -0
  11. package/app/apps/github/src/camo/node.ts +50 -0
  12. package/app/apps/github/src/camo/proxy.ts +116 -0
  13. package/app/apps/github/src/camo/sign-images.ts +307 -0
  14. package/app/apps/github/src/camo/signing.ts +80 -0
  15. package/app/apps/github/src/clients/allowed.ts +111 -18
  16. package/app/apps/github/src/clients/clients.ts +76 -61
  17. package/app/apps/github/src/clients/transport.ts +13 -0
  18. package/app/apps/github/src/code/code-tree.tsx +3 -1
  19. package/app/apps/github/src/code/file-view.tsx +15 -6
  20. package/app/apps/github/src/code/files.ts +26 -19
  21. package/app/apps/github/src/code/go-to-file.tsx +2 -1
  22. package/app/apps/github/src/code/load.ts +41 -23
  23. package/app/apps/github/src/code/markdown-files.ts +13 -2
  24. package/app/apps/github/src/code/ref-pages.ts +14 -5
  25. package/app/apps/github/src/code/ref-switcher.tsx +4 -3
  26. package/app/apps/github/src/code/refs.ts +42 -8
  27. package/app/apps/github/src/code/repo-home.tsx +6 -2
  28. package/app/apps/github/src/code/repo.ts +12 -6
  29. package/app/apps/github/src/code/saved.ts +5 -3
  30. package/app/apps/github/src/code/trees.ts +11 -9
  31. package/app/apps/github/src/components/markdown/markdown.css +6 -0
  32. package/app/apps/github/src/components/markdown/markdown.tsx +95 -10
  33. package/app/apps/github/src/components/owner-card.tsx +3 -1
  34. package/app/apps/github/src/components/repos/your-repos.tsx +3 -1
  35. package/app/apps/github/src/components/shell/owner-repos.tsx +7 -12
  36. package/app/apps/github/src/components/shell/repo-switcher.tsx +10 -16
  37. package/app/apps/github/src/components/signin/device-card.tsx +9 -2
  38. package/app/apps/github/src/components/user-avatar.tsx +2 -1
  39. package/app/apps/github/src/context/context.ts +13 -0
  40. package/app/apps/github/src/diffs/blobs.ts +37 -14
  41. package/app/apps/github/src/diffs/diff-job.ts +53 -0
  42. package/app/apps/github/src/diffs/diff-worker.ts +6 -0
  43. package/app/apps/github/src/diffs/diffing.ts +136 -0
  44. package/app/apps/github/src/diffs/files.ts +4 -3
  45. package/app/apps/github/src/diffs/hunks.tsx +101 -53
  46. package/app/apps/github/src/diffs/patch.ts +20 -11
  47. package/app/apps/github/src/history/commit-diff.ts +10 -5
  48. package/app/apps/github/src/history/commit-list.tsx +3 -1
  49. package/app/apps/github/src/history/commit-page.tsx +4 -2
  50. package/app/apps/github/src/history/history.ts +12 -10
  51. package/app/apps/github/src/hooks/allowed.ts +9 -9
  52. package/app/apps/github/src/hooks/avatars.ts +3 -3
  53. package/app/apps/github/src/hooks/open-counts.ts +5 -4
  54. package/app/apps/github/src/hooks/profiles.ts +26 -12
  55. package/app/apps/github/src/hooks/repos.ts +78 -25
  56. package/app/apps/github/src/inbox/count.ts +30 -29
  57. package/app/apps/github/src/inbox/inbox-item.tsx +3 -1
  58. package/app/apps/github/src/inbox/inbox-page.tsx +5 -2
  59. package/app/apps/github/src/inbox/marks.ts +26 -15
  60. package/app/apps/github/src/inbox/release-tags.ts +7 -6
  61. package/app/apps/github/src/inbox/subjects.ts +5 -4
  62. package/app/apps/github/src/inbox/subscription-controls.tsx +14 -5
  63. package/app/apps/github/src/inbox/subscriptions.ts +95 -35
  64. package/app/apps/github/src/inbox/threads.ts +6 -6
  65. package/app/apps/github/src/issues/changes.ts +40 -16
  66. package/app/apps/github/src/issues/counts.ts +8 -5
  67. package/app/apps/github/src/issues/issue-list.tsx +20 -6
  68. package/app/apps/github/src/issues/issue-page.tsx +30 -14
  69. package/app/apps/github/src/issues/issues.ts +195 -46
  70. package/app/apps/github/src/issues/label-dialog.tsx +8 -11
  71. package/app/apps/github/src/issues/labels-page.tsx +35 -3
  72. package/app/apps/github/src/issues/milestone-dialog.tsx +197 -0
  73. package/app/apps/github/src/issues/milestones-page.tsx +269 -0
  74. package/app/apps/github/src/issues/new-issue.tsx +3 -1
  75. package/app/apps/github/src/issues/sidebar.tsx +8 -6
  76. package/app/apps/github/src/markdown/README.md +22 -17
  77. package/app/apps/github/src/markdown/context.ts +83 -10
  78. package/app/apps/github/src/markdown/images.ts +3 -2
  79. package/app/apps/github/src/markdown/lookup.ts +17 -11
  80. package/app/apps/github/src/markdown/page-budget.ts +50 -0
  81. package/app/apps/github/src/markdown/patches.ts +74 -32
  82. package/app/apps/github/src/markdown/query.ts +7 -2
  83. package/app/apps/github/src/markdown/remote.ts +106 -0
  84. package/app/apps/github/src/markdown/render.ts +101 -24
  85. package/app/apps/github/src/markdown/texts.ts +43 -0
  86. package/app/apps/github/src/markdown/words-module.d.ts +5 -0
  87. package/app/apps/github/src/markdown/words-plugin.ts +135 -0
  88. package/app/apps/github/src/names/repos.ts +1 -1
  89. package/app/apps/github/src/palette/palette.tsx +28 -10
  90. package/app/apps/github/src/palette/rows.tsx +93 -40
  91. package/app/apps/github/src/palette/server.ts +10 -7
  92. package/app/apps/github/src/palette/targets.ts +1 -0
  93. package/app/apps/github/src/policy.ts +137 -61
  94. package/app/apps/github/src/private-repos.ts +5 -5
  95. package/app/apps/github/src/pulls/compare-page.tsx +6 -3
  96. package/app/apps/github/src/pulls/files-tab.tsx +480 -214
  97. package/app/apps/github/src/pulls/held-summary.ts +178 -0
  98. package/app/apps/github/src/pulls/live.ts +6 -4
  99. package/app/apps/github/src/pulls/merge-box.tsx +17 -10
  100. package/app/apps/github/src/pulls/pull-list.tsx +6 -3
  101. package/app/apps/github/src/pulls/pull-page.tsx +19 -10
  102. package/app/apps/github/src/pulls/pull.ts +68 -40
  103. package/app/apps/github/src/pulls/pulls.ts +39 -22
  104. package/app/apps/github/src/pulls/review-drafts.ts +131 -0
  105. package/app/apps/github/src/pulls/review.ts +374 -99
  106. package/app/apps/github/src/pulls/threads.tsx +152 -0
  107. package/app/apps/github/src/queue/queue-page.tsx +15 -8
  108. package/app/apps/github/src/queue/queue.ts +35 -20
  109. package/app/apps/github/src/releases/latest-release.tsx +3 -1
  110. package/app/apps/github/src/releases/overview.tsx +4 -2
  111. package/app/apps/github/src/releases/release-form.tsx +8 -5
  112. package/app/apps/github/src/releases/release-list.tsx +8 -5
  113. package/app/apps/github/src/releases/release-view.tsx +1 -0
  114. package/app/apps/github/src/releases/releases.ts +33 -23
  115. package/app/apps/github/src/releases/tag-list.tsx +3 -1
  116. package/app/apps/github/src/router.tsx +5 -2
  117. package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +7 -1
  118. package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +6 -1
  119. package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +2 -1
  120. package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +1 -1
  121. package/app/apps/github/src/routes/$owner/$repo/branches.tsx +5 -1
  122. package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +1 -1
  123. package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +6 -1
  124. package/app/apps/github/src/routes/$owner/$repo/index.tsx +1 -1
  125. package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +4 -2
  126. package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +2 -2
  127. package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +5 -2
  128. package/app/apps/github/src/routes/$owner/$repo/labels.tsx +2 -1
  129. package/app/apps/github/src/routes/$owner/$repo/milestones.tsx +36 -0
  130. package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +4 -2
  131. package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +2 -2
  132. package/app/apps/github/src/routes/$owner/$repo/queue.tsx +2 -1
  133. package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +5 -2
  134. package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +2 -1
  135. package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +4 -2
  136. package/app/apps/github/src/routes/$owner/$repo/route.tsx +9 -5
  137. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +3 -1
  138. package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +3 -1
  139. package/app/apps/github/src/routes/-nav.tsx +10 -2
  140. package/app/apps/github/src/routes/-root-testing.ts +29 -6
  141. package/app/apps/github/src/routes/__root.tsx +9 -4
  142. package/app/apps/github/src/routes/index.tsx +3 -1
  143. package/app/apps/github/src/routes/orgs/$owner/route.tsx +4 -1
  144. package/app/apps/github/src/routes/orgs/$owner/settings.tsx +4 -1
  145. package/app/apps/github/src/seed/acme.ts +1 -1
  146. package/app/apps/github/src/seed/seed.ts +199 -120
  147. package/app/apps/github/src/server.ts +24 -15
  148. package/app/apps/github/src/settings/account-avatar.tsx +4 -1
  149. package/app/apps/github/src/settings/general-settings.tsx +3 -1
  150. package/app/apps/github/src/settings/general.ts +4 -4
  151. package/app/apps/github/src/settings/hook-form.tsx +3 -1
  152. package/app/apps/github/src/settings/hook-list.tsx +5 -2
  153. package/app/apps/github/src/settings/hooks.ts +7 -7
  154. package/app/apps/github/src/settings/org-settings.tsx +3 -1
  155. package/app/apps/github/src/settings/orgs.ts +21 -11
  156. package/app/apps/github/src/settings/settings-layout.tsx +3 -1
  157. package/app/apps/github/src/signin/approval.ts +4 -3
  158. package/app/apps/github/src/signin/auth.ts +9 -2
  159. package/app/apps/github/src/signin/device-code.ts +8 -3
  160. package/app/apps/github/src/signin/device-prompt.ts +28 -3
  161. package/app/apps/github/src/signin/revoke.ts +36 -0
  162. package/app/apps/github/tsconfig.json +4 -1
  163. package/app/apps/github/vite.config.ts +8 -0
  164. package/app/pnpm-workspace.yaml +9 -5
  165. package/app/tsconfig.base.json +1 -0
  166. package/dist/cli/child.mjs +1 -1
  167. package/dist/cli/credentials.mjs +4 -4
  168. package/dist/cli/documents.mjs +32 -22
  169. package/dist/cli/events.mjs +1 -1
  170. package/dist/cli/failure.mjs +20 -7
  171. package/dist/cli/folders.mjs +2 -2
  172. package/dist/cli/git-remote-ref0.mjs +47 -22
  173. package/dist/cli/git.mjs +26 -5
  174. package/dist/cli/helpers.mjs +168 -35
  175. package/dist/cli/hosts.mjs +3 -3
  176. package/dist/cli/output.mjs +2 -2
  177. package/dist/cli/prompt.mjs +1 -1
  178. package/dist/cli/queue.mjs +7 -7
  179. package/dist/cli/ref0-git.mjs +2 -2
  180. package/dist/cli/repos.mjs +35 -18
  181. package/dist/cli/resources.mjs +5 -5
  182. package/dist/cli/retry-after.mjs +8 -0
  183. package/dist/cli/setup.mjs +172 -66
  184. package/dist/cli/sign-in.mjs +65 -23
  185. package/dist/cli/sign-ins.mjs +70 -13
  186. package/dist/cli/sqlite.mjs +2 -2
  187. package/dist/cli/tokens.mjs +3 -3
  188. package/dist/cli/vendor.mjs +1 -1
  189. package/dist/init/app.mjs +18 -20
  190. package/dist/init/choices.mjs +1 -1
  191. package/dist/init/cloudflare.mjs +15 -19
  192. package/dist/init/create.mjs +4 -3
  193. package/dist/init/detect.mjs +4 -4
  194. package/dist/init/files.mjs +121 -9
  195. package/dist/init/frameworks.mjs +16 -0
  196. package/dist/init/git-module.mjs +22 -7
  197. package/dist/init/jsonc.mjs +9 -7
  198. package/dist/init/metadata.mjs +9 -3
  199. package/dist/init/mounts.mjs +13 -10
  200. package/dist/init/next.mjs +3 -5
  201. package/dist/init/node-app.mjs +3 -3
  202. package/dist/init/node.mjs +41 -42
  203. package/dist/init/nuxt.mjs +153 -27
  204. package/dist/init/stores.mjs +14 -9
  205. package/dist/init/sveltekit.mjs +4 -2
  206. package/dist/init/template.mjs +9 -6
  207. package/dist/init/templates.mjs +64 -48
  208. package/dist/init/vercel.mjs +37 -36
  209. package/dist/init/versions.mjs +3 -3
  210. package/package.json +6 -5
@@ -1,7 +1,6 @@
1
1
  import { ignoring, lines, withCli, withCreatedTypes, withDependencies, withLines } from "./files.mjs";
2
- import { frameworkPackages, nodePackages } from "./metadata.mjs";
3
- import { adminLines, gitImports, gitPackages, handlerLines, header, mergeLines, serveExport, serverLines } from "./git-module.mjs";
4
- import { parseJsonc, stringAt, withEntries } from "./jsonc.mjs";
2
+ import { adminLines, gitDependencies, gitImports, gitPackages, handlerLines, header, mergeLines, serveExport, serverLines } from "./git-module.mjs";
3
+ import { manifestText, parseJsonc, stringAt, withEntries } from "./jsonc.mjs";
5
4
  import { astroRouteFiles, astroSteps } from "./astro.mjs";
6
5
  import { mountManual } from "./mounts.mjs";
7
6
  import { nextConfigOutput, nextRouteFiles } from "./next.mjs";
@@ -9,8 +8,9 @@ import { nuxtOutput } from "./nuxt.mjs";
9
8
  import { reactRouterRouteFiles, reactRouterSteps } from "./react-router.mjs";
10
9
  import { bodySizeLimit, onAdapterNode, svelteAdapterAnchor, svelteHooks, svelteInitLines, svelteNodeAdapter, svelteRerouteLines, svelteRouteFiles, svelteServerHooks, svelteStartStep, withSvelteStart } from "./sveltekit.mjs";
11
10
  import { envExample, needHelper, needsOf, recordsPart, s3Part } from "./stores.mjs";
12
- import { specOf } from "./versions.mjs";
11
+ import { frameworkPackages, nodePackages } from "./metadata.mjs";
13
12
  import * as Redacted from "effect/Redacted";
13
+ import * as Predicate from "effect/Predicate";
14
14
  // src/init/node.ts
15
15
  /**
16
16
  * What `init` writes for Git on Node, without the app: `src/git.ts`, which builds the store, the
@@ -35,30 +35,30 @@ const firstImports = (choices, loadsEnv) => {
35
35
  const first = lines(builtins !== "" && `${builtins}\n`, client !== "" && `${client}\n`);
36
36
  return first !== "" && first;
37
37
  };
38
- /** infra's import: one line from its promise entry, naming what the choices take. */
39
- const infraImports = (choices) => {
40
- return `import { ${[
41
- "createJobQueue",
42
- ...choices.bucket === "disk" ? ["disk"] : [],
43
- ...recordsOf(choices) === void 0 ? [] : ["poller"],
44
- ...choices.records === "sqlite" ? ["sqlite"] : [],
45
- ...partsOf(choices).flatMap((part) => part.infra)
46
- ].join(", ")} } from '@ref0/infra/promises';`;
47
- };
38
+ /**
39
+ * infra's imports: each platform entry the choices take, as a namespace, in the entries' order.
40
+ * Node's, for its poller, or for its job runner where the module starts its own jobs, `runs`.
41
+ */
42
+ const infraImports = (choices, runs = false) => lines(...[
43
+ choices.bucket === "disk" && "import * as Disk from '@ref0/infra/disk';",
44
+ (runs || recordsOf(choices) !== void 0) && "import * as Node from '@ref0/infra/node';",
45
+ choices.records === "sqlite" && "import * as Sqlite from '@ref0/infra/sqlite';",
46
+ ...partsOf(choices).map((part) => part.infra)
47
+ ].filter(Predicate.isString).toSorted());
48
48
  /** The store, as chosen: a shared one woken by a poller, or SQLite's file. */
49
49
  const storeLines = (choices) => {
50
50
  const records = recordsOf(choices);
51
- if (records !== void 0) return lines("// Every replica may run the queue: poller() looks for each one's due work once a second.", "const wake = poller();", "", records.code);
52
- return lines("mkdirSync('.data', { recursive: true });", "", "// One file, whose jobs this process alone runs.", "const database = new DatabaseSync('.data/records.db', { timeout: 5_000 });", "", "// WAL makes a commit about 4 times faster.", "database.exec('PRAGMA journal_mode = WAL; PRAGMA synchronous = NORMAL');", "", "const store = sqlite(database);");
51
+ if (records !== void 0) return lines("// Every replica may run the queue: the poller looks for each one's due work once a second.", "const wake = Node.layerPoller();", "", records.code);
52
+ return lines("mkdirSync('.data', { recursive: true });", "", "// One file, whose jobs this process alone runs.", "const database = new DatabaseSync('.data/records.db', { timeout: 5_000 });", "", "// WAL makes a commit about 4 times faster.", "database.exec('PRAGMA journal_mode = WAL; PRAGMA synchronous = NORMAL');", "", "const store = Sqlite.layer({ database });");
53
53
  };
54
54
  /** The bucket, as chosen, after a blank line: none for loose objects. */
55
- const bucketLines = (choices) => choices.bucket === "s3" ? `\n${s3Part.code}` : choices.bucket === "disk" && "\nconst bucket = disk('.data/packs');";
56
- /** The jobs' comment in the server module, for what starts them. */
55
+ const bucketLines = (choices) => choices.bucket === "s3" ? `\n${s3Part.code}` : choices.bucket === "disk" && "\nconst bucket = Disk.layer('.data/packs');";
56
+ /** Git's comment in the server module, for what runs its jobs. */
57
57
  const jobsSays = {
58
- main: "/** Git's jobs, which `src/main.ts` runs in this process. */",
59
- server: "/** Git's jobs, which your server runs in its process. */",
60
- hook: "/** Git's jobs, which the framework's startup hook runs in each server process. */",
61
- "on-import": "/** Git's jobs, which this module starts on its first import. */"
58
+ main: "/** Git, whose jobs `src/main.ts` runs in this process. */",
59
+ server: "/** Git, whose jobs your server runs in its process. */",
60
+ hook: "/** Git, whose jobs the framework's startup hook runs in each server process. */",
61
+ "on-import": "/** Git, whose jobs this module starts on its first import. */"
62
62
  };
63
63
  /**
64
64
  * A framework's `.env`, loaded before any `need()`: a Vite dev server gives `process.env` none of
@@ -66,7 +66,7 @@ const jobsSays = {
66
66
  */
67
67
  const loadEnvLines = lines("// `.env` from the folder the server runs in, `process.cwd()`, as `node --env-file` reads it: a", "// host that runs it from another folder sets the environment itself. A variable already set", "// stays as it is.", "if (existsSync('.env')) process.loadEnvFile('.env');", "");
68
68
  /** The jobs' start on the module's first import, once a process: a dev reload imports it again. */
69
- const startedOnImport = lines("", "// Started once a process, on this module's first import: a dev reload imports it again.", "// SAFETY: only this module sets `gitJobs` on the global, to the stop `jobs.start()` returns.", "const started = globalThis as { gitJobs?: () => Promise<void> };", "", "started.gitJobs ??= jobs.start();");
69
+ const startedOnImport = lines("// Started once a process, on this module's first import, after the drop-in joins Git: the", "// runner starts Git's build, which refuses a join. A dev reload imports the module again.", "// SAFETY: only this module sets `gitJobs` on the global, to the stop `toJobRunner` returns.", "const started = globalThis as { gitJobs?: () => Promise<void> };", "", "started.gitJobs ??= Node.toJobRunner(git.runtime);", "");
70
70
  /**
71
71
  * The server module, `src/git.ts` or a framework's: the store, the bucket and the queue, then
72
72
  * Git, its REST and the drop-in, and, but for `src/main.ts`'s, the `serve` its routes call.
@@ -74,52 +74,49 @@ const startedOnImport = lines("", "// Started once a process, on this module's f
74
74
  const nodeModule = (choices, jobs) => {
75
75
  const packs = choices.objects === "packs";
76
76
  const framework = jobs === "hook" || jobs === "on-import";
77
- return lines(header(choices, "Node"), firstImports(choices, framework), gitImports(choices, {
78
- line: "import { xdiff } from '@ref0/git/node';",
79
- last: false
80
- }), infraImports(choices), "", framework && loadEnvLines, needHelper(".env"), "", adminLines, storeLines(choices), bucketLines(choices), "", jobsSays[jobs], "export const jobs = createJobQueue({ store });", jobs === "on-import" && startedOnImport, "", mergeLines(choices), serverLines(choices, {
81
- adapter: ` adapter: { store, ${packs ? "bucket, " : ""}jobs },`,
82
- engine: "engine({ xdiff: await xdiff() })",
77
+ return lines(header(choices, "Node"), firstImports(choices, framework), gitImports(choices), infraImports(choices, jobs === "on-import"), "import { xdiff } from '@ref0/xdiff-wasm/node';", "", framework && loadEnvLines, needHelper(".env"), "", adminLines, storeLines(choices), bucketLines(choices), "", mergeLines(choices), jobsSays[jobs], serverLines(choices, {
78
+ adapter: ` adapter: ${packs ? "[store, bucket]" : "store"},`,
79
+ xdiff: " xdiff: await xdiff(),",
83
80
  uploads: choices.bucket === "s3",
84
81
  token: "need('ADMIN_TOKEN')"
85
- }), handlerLines(choices), jobs !== "main" && serveExport(choices));
82
+ }), handlerLines(choices), jobs === "on-import" && startedOnImport, jobs !== "main" && serveExport(choices));
86
83
  };
87
84
  /** What the process serves, as `toNodeHandler` takes it. */
88
85
  const handled = {
89
86
  github: {
90
- names: "github, jobs, rest",
87
+ names: "git, github, rest",
91
88
  handler: "{\n fetch: async (request) => (await github.route(request)) ?? rest.fetch(request),\n}"
92
89
  },
93
90
  api: {
94
- names: "jobs, rest",
91
+ names: "git, rest",
95
92
  handler: "rest"
96
93
  },
97
94
  git: {
98
- names: "git, jobs",
95
+ names: "git",
99
96
  handler: "git"
100
97
  }
101
98
  };
102
99
  /** A stop waits this long for the responses still open, such as one a reader stopped reading. */
103
100
  const stopGrace = 1e4;
104
101
  /** The lines in `src/main.ts` that start the jobs and serve Git. */
105
- const serveLines = (choices) => lines("const stop = jobs.start();", "", `const handler = toNodeHandler(${handled[choices.serve].handler});`);
102
+ const serveLines = (choices) => lines("const stop = Node.toJobRunner(git.runtime);", "", `const handler = toNodeHandler(${handled[choices.serve].handler});`);
106
103
  /** Where `src/main.ts` serves Git when `PORT` is unset. */
107
104
  const mainOrigin = "http://localhost:8080";
108
105
  const mainPort = new URL(mainOrigin).port;
109
106
  /** `src/main.ts`: Git on `PORT`, its jobs in this process, stopped on `SIGTERM`. */
110
- const mainModule = (choices) => lines(`// Serves Git on PORT, ${mainPort} when unset, and runs its jobs in this process. Written by`, "// `ref0-git init`, and yours to change.", "import { createServer } from 'node:http';", "", "import { toNodeHandler } from '@ref0/git/node';", "", `import { ${handled[choices.serve].names} } from './git.ts';`, "", serveLines(choices), "", "const server = createServer(handler);", "", "// Node cuts a request off at 300 s, which a large push over a slow link outlasts: an hour.", "server.requestTimeout = 60 * 60 * 1000;", "", `server.listen(Number(process.env.PORT ?? '${mainPort}'));`, "", "process.on('SIGTERM', () => {", " server.close();", " void stop();", "", ` // A response still open after ${stopGrace / 1e3} s, such as to a reader that stopped reading, is cut off.`, ` setTimeout(() => server.closeAllConnections(), ${stopGrace / 1e3} * 1000).unref();`, "});", "");
107
+ const mainModule = (choices) => lines(`// Serves Git on PORT, ${mainPort} when unset, and runs its jobs in this process. Written by`, "// `ref0-git init`, and yours to change.", "import { createServer } from 'node:http';", "", "import { toNodeHandler } from '@ref0/git/node';", "import * as Node from '@ref0/infra/node';", "", `import { ${handled[choices.serve].names} } from './git.ts';`, "", serveLines(choices), "", "const server = createServer(handler);", "", "// Node cuts a request off at 300 s, which a large push over a slow link outlasts: an hour.", "server.requestTimeout = 60 * 60 * 1000;", "", `server.listen(Number(process.env.PORT ?? '${mainPort}'));`, "", "process.on('SIGTERM', () => {", " server.close();", " void stop();", "", ` // A response still open after ${stopGrace / 1e3} s, such as to a reader that stopped reading, is cut off.`, ` setTimeout(() => server.closeAllConnections(), ${stopGrace / 1e3} * 1000).unref();`, "});", "");
111
108
  /** The packages a Node setup runs with, beside Git's, and the tools it type-checks with. */
112
109
  const dependenciesOf = (choices, vendor) => {
113
110
  const parts = partsOf(choices);
114
111
  return {
115
- run: Object.fromEntries([...gitPackages(choices).map((each) => [each, specOf(each, vendor)]), ...parts.flatMap((part) => part.dependencies)]),
112
+ run: Object.fromEntries([...gitDependencies(choices, vendor), ...parts.flatMap((part) => part.dependencies)]),
116
113
  tools: Object.fromEntries([...Object.entries(nodePackages), ...parts.flatMap((part) => part.devDependencies)])
117
114
  };
118
115
  };
119
116
  /** `package.json` with Git's packages added where it doesn't name them, or names them as the other source does, and its tools with `tools`. */
120
117
  const mergePackage = (choices, name, tools, vendor) => (current) => {
121
118
  const { run, tools: types } = dependenciesOf(choices, vendor);
122
- if (current === void 0) return withCli(`${JSON.stringify({
119
+ if (current === void 0) return withCli(`${manifestText({
123
120
  name,
124
121
  private: true,
125
122
  type: "module",
@@ -129,7 +126,7 @@ const mergePackage = (choices, name, tools, vendor) => (current) => {
129
126
  },
130
127
  dependencies: run,
131
128
  devDependencies: types
132
- }, null, 2)}\n`, vendor);
129
+ })}\n`, vendor);
133
130
  const added = withCli(withDependencies(current, run), vendor);
134
131
  return tools ? withEntries(added, ["devDependencies"], types) : added;
135
132
  };
@@ -170,8 +167,10 @@ const instrumentationOf = (framework) => `${framework.appDir === "src/app" ? "sr
170
167
  const registerLines = [
171
168
  "export async function register() {",
172
169
  " if (process.env.NEXT_RUNTIME === 'nodejs') {",
173
- " const { jobs } = await import('./lib/git');",
174
- " jobs.start();",
170
+ " const { git } = await import('./lib/git');",
171
+ " const Node = await import('@ref0/infra/node');",
172
+ "",
173
+ " Node.toJobRunner(git.runtime);",
175
174
  " }",
176
175
  "}"
177
176
  ];
@@ -287,7 +286,7 @@ const svelteNodeOutput = (choices, project, framework, secret, vendor) => {
287
286
  ...localFiles(choices, secret, [bodySizeLimit])
288
287
  ],
289
288
  manual: [
290
- ...theirs === void 0 || /\bjobs\.start\(/.test(theirs.text) ? [] : [{
289
+ ...theirs === void 0 || /\btoJobRunner\(/.test(theirs.text) ? [] : [{
291
290
  path: theirs.path,
292
291
  why: "yours",
293
292
  says: "Start Git's jobs in the init hook, once in each server process: merge these imports with yours",
@@ -320,7 +319,7 @@ const svelteNodeOutput = (choices, project, framework, secret, vendor) => {
320
319
  * drop-in's. Nitro's server loads no `.env`, so the module loads it, and Nitro sets no body limit.
321
320
  */
322
321
  const nuxtNodeOutput = (choices, project, framework, secret, vendor) => {
323
- const nuxt = nuxtOutput(choices, framework);
322
+ const nuxt = nuxtOutput(choices, framework, project.created === true);
324
323
  const needs = nodeNeeds(choices);
325
324
  return {
326
325
  files: [
@@ -21,9 +21,10 @@ const nuxtJobsPlugin = "server/plugins/git-jobs.ts";
21
21
  /** The plugin's lines, which a step in the person's own file at that path names too. */
22
22
  const pluginLines = (framework) => [
23
23
  "export default defineNitroPlugin(async (nitroApp) => {",
24
- ` const { jobs } = await import('${importOf(nuxtJobsPlugin, framework.serverModule)}');`,
24
+ ` const { git } = await import('${importOf(nuxtJobsPlugin, framework.serverModule)}');`,
25
+ " const Node = await import('@ref0/infra/node');",
25
26
  "",
26
- " const stop = jobs.start();",
27
+ " const stop = Node.toJobRunner(git.runtime);",
27
28
  " nitroApp.hooks.hook('close', () => void stop());",
28
29
  "});"
29
30
  ];
@@ -61,6 +62,122 @@ const middlewareLines = (choices, framework) => {
61
62
  "});"
62
63
  ];
63
64
  };
65
+ /**
66
+ * Nitro's build target, as a `nuxt.config`'s member holds it, indented by two. Nitro 2 builds the
67
+ * server for es2019, which refuses `server/git.ts`'s top-level `await xdiff()`.
68
+ */
69
+ const nitroTargetLines = [
70
+ " // Nitro builds the server for es2019 otherwise, which refuses server/git.ts's top-level await.",
71
+ " // Written by `ref0-git init`.",
72
+ " nitro: { esbuild: { options: { target: 'es2022' } } },"
73
+ ];
74
+ /**
75
+ * Nitro's target as a data `nuxt.config` holds it, by its extension: c12 parses these as JSON, YAML
76
+ * or TOML, with no `defineNuxtConfig` and no JavaScript.
77
+ */
78
+ const dataTargetLines = {
79
+ json: [" \"nitro\": { \"esbuild\": { \"options\": { \"target\": \"es2022\" } } }"],
80
+ yaml: [
81
+ "nitro:",
82
+ " esbuild:",
83
+ " options:",
84
+ " target: es2022"
85
+ ],
86
+ toml: ["[nitro.esbuild.options]", "target = \"es2022\""]
87
+ };
88
+ /** The data format a `nuxt.config`'s extension names, or `undefined` for JavaScript and TypeScript. */
89
+ const dataFormatOf = (path) => {
90
+ const extension = path.slice(path.lastIndexOf(".") + 1);
91
+ if (extension.startsWith("json")) return "json";
92
+ if (extension === "yaml" || extension === "yml") return "yaml";
93
+ if (extension === "toml") return "toml";
94
+ };
95
+ /** A `nuxt.config`'s tokens: strings, names, comments and the punctuation an object's shape is. */
96
+ const configTokens = /(["'`])(?:\\.|(?!\1)[^\\])*\1|[A-Za-z_$][\w$]*|\/\/[^\n]*|\/\*[\s\S]*?\*\/|[{}:,]/g;
97
+ /** A target with top-level `await`: es2022 or later, or esnext, quoted. */
98
+ const modernTarget = /^["'`](?:es202[2-9]|es20[3-9]\d|esnext)["'`]$/;
99
+ /**
100
+ * Whether a `nuxt.config`'s text sets Nitro's own target, `nitro.esbuild.options.target`, to one
101
+ * with top-level `await`, read by the keys around each `target`, so siblings in any order, nested
102
+ * or not, read the same. Nitro spreads only those options over its es2019, so Vite's
103
+ * `build.target` or `esbuild.target` sets nothing for it. A target from a variable reads as unset.
104
+ */
105
+ const targetsTopLevelAwait = (text) => {
106
+ const tokens = (text.match(configTokens) ?? []).filter((token) => !token.startsWith("/"));
107
+ const keys = [];
108
+ let key;
109
+ for (let at = 0; at < tokens.length; at += 1) {
110
+ const token = tokens[at] ?? "";
111
+ if (token === "{") keys.push(key ?? "");
112
+ if (token === "{" || token === "}" || token === ",") key = void 0;
113
+ if (token === "}") keys.pop();
114
+ if (tokens[at + 1] !== ":" || /^[{}:,]$/.test(token)) continue;
115
+ key = token.replace(/^["'`]|["'`]$/g, "");
116
+ at += 1;
117
+ const inOptions = keys.slice(-3).join(".") === "nitro.esbuild.options";
118
+ if (key === "target" && inOptions && modernTarget.test(tokens[at + 1] ?? "")) return true;
119
+ }
120
+ return false;
121
+ };
122
+ /** `init`'s own `nuxt.config.ts`, with the target in it: what it writes where there's none. */
123
+ const nuxtConfigText = lines("export default defineNuxtConfig({", ...nitroTargetLines, "});", "");
124
+ /**
125
+ * The line of `create-nuxt`'s `nuxt.config.ts` the target goes after: `init` edits the file the
126
+ * create command actually wrote there, when the line is in it exactly once.
127
+ */
128
+ const nuxtConfigAnchor = "export default defineNuxtConfig({\n";
129
+ /** The target after `path`'s one anchor line, as an edit of `text`, or `undefined` where it isn't once. */
130
+ const withTarget = (path, text) => {
131
+ const at = text.indexOf(nuxtConfigAnchor);
132
+ if (at === -1 || text.includes("export default defineNuxtConfig({\n", at + 1)) return void 0;
133
+ const after = at + 34;
134
+ return {
135
+ path,
136
+ kind: "edit",
137
+ from: text,
138
+ text: `${text.slice(0, after)}${nitroTargetLines.join("\n")}\n${text.slice(after)}`,
139
+ edit: {
140
+ anchor: nuxtConfigAnchor.trimEnd(),
141
+ adds: nitroTargetLines,
142
+ swaps: []
143
+ }
144
+ };
145
+ };
146
+ /**
147
+ * Nitro's target: a `nuxt.config.ts` where the project has none, or, in the one a create command
148
+ * wrote in this same run, after its anchor line; else, in the person's own `nuxt.config`, or one
149
+ * whose anchor isn't there exactly once, a printed step.
150
+ */
151
+ const nuxtConfigOutput = (framework, created) => {
152
+ const { config } = framework;
153
+ if (config !== void 0 && targetsTopLevelAwait(config.text)) return {
154
+ files: [],
155
+ manual: []
156
+ };
157
+ if (config === void 0) return {
158
+ files: [{
159
+ path: "nuxt.config.ts",
160
+ kind: "whole",
161
+ text: nuxtConfigText
162
+ }],
163
+ manual: []
164
+ };
165
+ const edited = created ? withTarget(config.path, config.text) : void 0;
166
+ if (edited !== void 0) return {
167
+ files: [edited],
168
+ manual: []
169
+ };
170
+ const format = dataFormatOf(config.path);
171
+ return {
172
+ files: [],
173
+ manual: [{
174
+ path: config.path,
175
+ says: format === void 0 ? "Build Nitro's server for es2022, which has top-level await, in defineNuxtConfig" : "Build Nitro's server for es2022, which has top-level await: set nitro.esbuild.options.target",
176
+ why: created ? "template_changed" : "yours",
177
+ lines: format === void 0 ? nitroTargetLines : dataTargetLines[format]
178
+ }]
179
+ };
180
+ };
64
181
  /** The first line of the middleware `init` writes, which marks the file as init's to rewrite. */
65
182
  const middlewareHeader = "// Git's URLs to Git, in front of the app's own. Written by `ref0-git init`.";
66
183
  /** Whether a file at the middleware's path answers Git: `init`'s, or one with its lines. */
@@ -81,35 +198,44 @@ const nuxtFindings = (framework) => {
81
198
  }];
82
199
  };
83
200
  /**
84
- * Nuxt's files and steps beside the server module: the jobs plugin and Git's middleware. The
85
- * middleware is init's to rewrite where it answers Git, so a rerun at a new base path moves it;
86
- * a person's own file at its path gets a step.
201
+ * Nuxt's files and steps beside the server module: the jobs plugin, Git's middleware and Nitro's
202
+ * target in `nuxt.config`. The middleware is init's to rewrite where it answers Git, so a rerun at
203
+ * a new base path moves it; a person's own file at its path gets a step.
87
204
  */
88
- const nuxtOutput = (choices, framework) => {
205
+ const nuxtOutput = (choices, framework, created) => {
206
+ const config = nuxtConfigOutput(framework, created);
89
207
  const plugin = framework.nitro?.plugin;
90
208
  const middleware = framework.nitro?.middleware;
91
209
  const ours = middleware === void 0 || middleware.text.startsWith(middlewareHeader);
92
210
  return {
93
- files: [...plugin === void 0 ? [{
94
- path: nuxtJobsPlugin,
95
- kind: "whole",
96
- text: lines("// Starts Git's jobs once in each Nitro server process, and stops them as it closes.", "// Written by `ref0-git init`.", ...pluginLines(framework), "")
97
- }] : [], ...ours ? [{
98
- path: nuxtGitMiddleware,
99
- kind: "whole",
100
- text: lines(middlewareHeader, ...middlewareLines(choices, framework), "")
101
- }] : []],
102
- manual: [...plugin === void 0 || /\bjobs\.start\(/.test(plugin.text) ? [] : [{
103
- path: plugin.path,
104
- why: "yours",
105
- says: "Start Git's jobs in a Nitro plugin, once in each server process",
106
- lines: pluginLines(framework)
107
- }], ...middleware === void 0 || answersGit(middleware.text) ? [] : [{
108
- path: middleware.path,
109
- why: "yours",
110
- says: "Answer Git's URLs with Git, and let every other path through",
111
- lines: middlewareLines(choices, framework)
112
- }]]
211
+ files: [
212
+ ...plugin === void 0 ? [{
213
+ path: nuxtJobsPlugin,
214
+ kind: "whole",
215
+ text: lines("// Starts Git's jobs once in each Nitro server process, and stops them as it closes.", "// Written by `ref0-git init`.", ...pluginLines(framework), "")
216
+ }] : [],
217
+ ...ours ? [{
218
+ path: nuxtGitMiddleware,
219
+ kind: "whole",
220
+ text: lines(middlewareHeader, ...middlewareLines(choices, framework), "")
221
+ }] : [],
222
+ ...config.files
223
+ ],
224
+ manual: [
225
+ ...config.manual,
226
+ ...plugin === void 0 || /\btoJobRunner\(/.test(plugin.text) ? [] : [{
227
+ path: plugin.path,
228
+ why: "yours",
229
+ says: "Start Git's jobs in a Nitro plugin, once in each server process",
230
+ lines: pluginLines(framework)
231
+ }],
232
+ ...middleware === void 0 || answersGit(middleware.text) ? [] : [{
233
+ path: middleware.path,
234
+ why: "yours",
235
+ says: "Answer Git's URLs with Git, and let every other path through",
236
+ lines: middlewareLines(choices, framework)
237
+ }]
238
+ ]
113
239
  };
114
240
  };
115
- export { nuxtFindings, nuxtGitMiddleware, nuxtJobsPlugin, nuxtOutput };
241
+ export { nuxtConfigAnchor, nuxtFindings, nuxtGitMiddleware, nuxtJobsPlugin, nuxtOutput };
@@ -1,18 +1,18 @@
1
1
  import { fitted, lines } from "./files.mjs";
2
2
  import { storePackages } from "./metadata.mjs";
3
3
  // src/init/stores.ts
4
- /** The records store, woken by the wake the platform's file declares as `wake`. */
4
+ /** The records store's Layer, woken by the wake's Layer the platform's file declares as `wake`. */
5
5
  const recordsPart = (records) => records === "postgres" ? {
6
6
  external: ["import pg from 'pg';"],
7
- infra: ["postgres"],
8
- code: `const store = postgres(new pg.Pool({ connectionString: need('DATABASE_URL') }), { wake });`,
7
+ infra: "import * as Postgres from '@ref0/infra/postgres';",
8
+ code: lines("const store = Postgres.layer({", " pool: new pg.Pool({ connectionString: need('DATABASE_URL') }),", " wake,", "});"),
9
9
  variables: ["DATABASE_URL"],
10
10
  dependencies: [["pg", storePackages.pg]],
11
11
  devDependencies: [["@types/pg", storePackages["@types/pg"]]]
12
12
  } : {
13
13
  external: ["import { createClient } from '@libsql/client';"],
14
- infra: ["turso", "tursoPlatform"],
15
- code: lines("// A database per repo in one Turso group, made at its first write over Turso's Platform API.", "const group = need('TURSO_GROUP');", "", "const databases = tursoPlatform({", " organization: need('TURSO_ORGANIZATION'),", " group,", " region: need('TURSO_REGION'),", " apiToken: need('TURSO_API_TOKEN'),", "});", "", "const store = turso({", " group,", " databases,", " groupToken: need('TURSO_GROUP_TOKEN'),", " createClient,", " wake,", "});"),
14
+ infra: "import * as Turso from '@ref0/infra/turso';",
15
+ code: lines("// A database per repo in one Turso group, made at its first write over Turso's Platform API.", "const group = need('TURSO_GROUP');", "", "const databases = Turso.platform({", " organization: need('TURSO_ORGANIZATION'),", " group,", " region: need('TURSO_REGION'),", " apiToken: need('TURSO_API_TOKEN'),", "});", "", "const store = Turso.layer({", " group,", " databases,", " groupToken: need('TURSO_GROUP_TOKEN'),", " createClient,", " wake,", "});"),
16
16
  variables: [
17
17
  "TURSO_ORGANIZATION",
18
18
  "TURSO_GROUP",
@@ -23,11 +23,11 @@ const recordsPart = (records) => records === "postgres" ? {
23
23
  dependencies: [["@libsql/client", storePackages["@libsql/client"]]],
24
24
  devDependencies: []
25
25
  };
26
- /** An S3 bucket, whose keys `s3()` reads from the environment itself. */
26
+ /** An S3 bucket, whose keys `S3.layer()` reads from the environment itself. */
27
27
  const s3Part = {
28
28
  external: [],
29
- infra: ["s3"],
30
- code: lines("// s3() reads AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY itself.", "const bucket = s3({", " endpoint: need('S3_ENDPOINT'),", " region: need('S3_REGION'),", " bucket: need('S3_BUCKET'),", "});"),
29
+ infra: "import * as S3 from '@ref0/infra/s3';",
30
+ code: lines("// S3.layer() reads AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY itself.", "const bucket = S3.layer({", " endpoint: need('S3_ENDPOINT'),", " region: need('S3_REGION'),", " bucket: need('S3_BUCKET'),", "});"),
31
31
  variables: [
32
32
  "S3_ENDPOINT",
33
33
  "S3_REGION",
@@ -44,8 +44,13 @@ const s3Part = {
44
44
  * platform's file picks, never a flag's or a file's text.
45
45
  */
46
46
  const needHelper = (where) => lines(`/** A variable the project sets, in ${where}. */`, "const need = (name: string) => {", " const value = process.env[name];", fitted(" if (value === undefined || value === '')", `throw new Error(\`Set \${name} in ${where}\`);`), "", " return value;", "};");
47
+ /**
48
+ * What `.env.example` says above a variable, if anything: Postgres's URL with `sslmode=verify-full`,
49
+ * since `pg` then checks the server's certificate and name, which `require` will stop doing in `pg` 9.
50
+ */
51
+ const noteOf = (name) => name === "DATABASE_URL" && "# Postgres's URL. Over a network, end it ?sslmode=verify-full, so pg checks the server's certificate";
47
52
  /** `.env.example`: `header`'s comment lines, then each of `variables` with an empty value. */
48
- const envExample = (header, variables) => lines(...header.map((line) => `# ${line}`), ...variables.map((name) => `${name}=`), "");
53
+ const envExample = (header, variables) => lines(...header.map((line) => `# ${line}`), ...variables.flatMap((name) => [noteOf(name), `${name}=`]), "");
49
54
  /** The variables `parts` read, in order, which the person sets: an Output's `needs`. */
50
55
  const needsOf = (parts) => parts.flatMap((part) => part.variables);
51
56
  export { envExample, needHelper, needsOf, recordsPart, s3Part };
@@ -36,8 +36,10 @@ const initLines = (framework) => [
36
36
  "export const init: ServerInit = async () => {",
37
37
  " if (building) return;",
38
38
  "",
39
- ` const { jobs } = await import('${importOf("src/hooks.server.ts", framework.serverModule)}');`,
40
- " jobs.start();",
39
+ ` const { git } = await import('${importOf("src/hooks.server.ts", framework.serverModule)}');`,
40
+ " const Node = await import('@ref0/infra/node');",
41
+ "",
42
+ " Node.toJobRunner(git.runtime);",
41
43
  "};"
42
44
  ];
43
45
  /** `src/hooks.server.ts`, where the project has none. */
@@ -14,10 +14,10 @@ const appGitSlots = [
14
14
  "infraImport",
15
15
  "safety",
16
16
  "bucket",
17
- "adapterAbout",
18
- "adapterBucket",
19
17
  "queueMerge",
18
+ "adapter",
20
19
  "objects",
20
+ "lfs",
21
21
  "uploads",
22
22
  "queue"
23
23
  ];
@@ -25,10 +25,12 @@ const appGitSlots = [
25
25
  const appGitNodeSlots = [
26
26
  "head",
27
27
  "queueMerge",
28
+ "adapter",
28
29
  "objects",
30
+ "lfs",
29
31
  "uploads",
30
32
  "queue",
31
- "engine",
33
+ "xdiff",
32
34
  "database",
33
35
  "ipHeader",
34
36
  "classes"
@@ -56,9 +58,10 @@ const workerGitSlots = [
56
58
  "envFile",
57
59
  "safety",
58
60
  "bucket",
59
- "adapterBucket",
60
61
  "merge",
62
+ "adapter",
61
63
  "objects",
64
+ "lfs",
62
65
  "uploads",
63
66
  "basePath",
64
67
  "queue",
@@ -82,9 +85,9 @@ const workerWranglerSlots = [
82
85
  "bucket",
83
86
  "vars"
84
87
  ];
85
- const Names = Schema.Array(Schema.String);
88
+ const Names = /* @__PURE__ */ Schema.Array(Schema.String);
86
89
  /** What the app needs on each platform, as `apps/github/src/platform.ts` says: `doctor` checks it. */
87
- const Platforms = Schema.Struct({
90
+ const Platforms = /* @__PURE__ */ Schema.Struct({
88
91
  cloudflare: Schema.Struct({
89
92
  secrets: Names,
90
93
  bound: Names,