ref0-git 0.26.0 → 0.29.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 (49) hide show
  1. package/app/apps/github/README.md +1 -5
  2. package/app/apps/github/package.json +0 -1
  3. package/app/apps/github/src/signin/auth.ts +17 -89
  4. package/app/apps/github/src/signin/credentials.ts +10 -14
  5. package/app/apps/github/src/signin/guarded-write.ts +19 -0
  6. package/app/apps/github/src/signin/owner-names.ts +11 -41
  7. package/app/apps/github/src/signin/unborn.ts +20 -30
  8. package/app/apps/github/tsconfig.json +0 -2
  9. package/app/pnpm-workspace.yaml +14 -34
  10. package/dist/cli/documents.mjs +39 -25
  11. package/dist/cli/keys.mjs +9 -3
  12. package/dist/cli/node.mjs +1 -2
  13. package/dist/cli/runtime.mjs +3 -4
  14. package/dist/cli/setup.mjs +216 -468
  15. package/dist/cli/tools-node.mjs +8 -7
  16. package/dist/cli/tools.mjs +3 -3
  17. package/dist/cli/vercel-stores.mjs +287 -0
  18. package/dist/init/app.mjs +4 -37
  19. package/dist/init/choices.mjs +62 -209
  20. package/dist/init/cloudflare.mjs +1 -2
  21. package/dist/init/detect.mjs +77 -167
  22. package/dist/init/files.mjs +2 -12
  23. package/dist/init/frameworks.mjs +50 -174
  24. package/dist/init/git-module.mjs +5 -1
  25. package/dist/init/metadata.mjs +4 -22
  26. package/dist/init/next.mjs +13 -66
  27. package/dist/init/output.mjs +3 -6
  28. package/dist/init/plan.mjs +1 -29
  29. package/dist/init/routes.mjs +1 -78
  30. package/dist/init/stores.mjs +6 -35
  31. package/dist/init/template.mjs +14 -49
  32. package/dist/init/templates.mjs +30 -115
  33. package/dist/init/vercel-regions.mjs +87 -0
  34. package/dist/init/vercel.mjs +313 -212
  35. package/dist/init/versions.mjs +3 -3
  36. package/package.json +5 -11
  37. package/app/apps/github/migrations/postgres/0001_auth.sql +0 -53
  38. package/app/apps/github/src/camo/lookup.ts +0 -23
  39. package/app/apps/github/src/camo/node.ts +0 -50
  40. package/app/apps/github/src/signin/person-lock.ts +0 -104
  41. package/dist/cli/sqlite.mjs +0 -28
  42. package/dist/init/astro.mjs +0 -49
  43. package/dist/init/create.mjs +0 -152
  44. package/dist/init/mounts.mjs +0 -104
  45. package/dist/init/node-app.mjs +0 -196
  46. package/dist/init/node.mjs +0 -446
  47. package/dist/init/nuxt.mjs +0 -240
  48. package/dist/init/react-router.mjs +0 -59
  49. package/dist/init/sveltekit.mjs +0 -141
@@ -1,15 +1,15 @@
1
1
  import { looseSays } from "./git-module.mjs";
2
+ import "./frameworks.mjs";
2
3
  import * as Effect from "effect/Effect";
3
4
  // src/init/choices.ts
4
5
  const valued = (flag) => (value) => [`--${flag}`, value];
5
6
  /** Each platform's name, as a headline says it. */
6
7
  const platformNames = {
7
8
  cloudflare: "Cloudflare",
8
- vercel: "Vercel",
9
- node: "Node"
9
+ vercel: "Vercel"
10
10
  };
11
11
  /** `value`, when it names a platform. */
12
- const platformNamed = (value) => value === "cloudflare" || value === "vercel" || value === "node" ? value : void 0;
12
+ const platformNamed = (value) => value === "cloudflare" || value === "vercel" ? value : void 0;
13
13
  /** The values `offered`, as a headline lists them. */
14
14
  const takes = (offered) => offered.map((offer) => offer.value).join(" or ");
15
15
  /** Refused unless `context` offers it, as `not_on_platform`. */
@@ -46,49 +46,45 @@ const serve = {
46
46
  ],
47
47
  named: valued("serve")
48
48
  };
49
- /** The platforms the app is written for: its pages and sign-in run there. */
50
- const appPlatforms = ["cloudflare", "node"];
51
- const appBuilt = (platform) => appPlatforms.some((each) => each === platform);
52
- /** `--app` on a platform it isn't written for: the flag the platform can't take, as any other's. */
53
- const appOffPlatform = {
54
- reason: "not_on_platform",
55
- headline: `The app runs on ${appPlatforms.map((each) => platformNames[each]).join(" and ")}: --platform takes ${appPlatforms.join(" or ")} with --app`
49
+ const platform = {
50
+ key: "platform",
51
+ flag: "platform",
52
+ row: "Platform",
53
+ question: "Where will it run?",
54
+ offers: ({ framework }) => [...framework === "Next.js" ? [] : [{
55
+ value: "cloudflare",
56
+ says: "Cloudflare",
57
+ why: "one Worker, its records in Durable Objects and its packs in R2"
58
+ }], {
59
+ value: "vercel",
60
+ says: "Vercel",
61
+ why: "Vercel's functions, records in Postgres and packs in Vercel Blob"
62
+ }],
63
+ refuse: (value, context) => context.framework === "Next.js" && value === "cloudflare" ? {
64
+ reason: "not_on_platform",
65
+ headline: "Next.js runs Git on Vercel alone: --platform takes vercel in a Next.js app"
66
+ } : onPlatform(platform, value, context),
67
+ named: valued("platform")
56
68
  };
57
69
  /**
58
70
  * The app's pages read GitHub's REST, and own `/` and their routes: only a new project's, and on
59
- * the platforms it's written for.
71
+ * Cloudflare, the one platform its sign-in runs on.
60
72
  */
61
73
  const app = {
62
74
  key: "app",
63
75
  flag: "app",
64
76
  row: "App",
65
77
  question: "Add the web app?",
66
- offers: ({ project, chosen, creating }) => {
67
- if (creating !== void 0) return [{
68
- value: "framework",
69
- says: `A new ${creating.says} app`,
70
- why: "its own create command, then Git in it"
71
- }, {
72
- value: "none",
73
- says: "No",
74
- why: "only the APIs"
75
- }];
76
- const ref0 = project === "new" && chosen.serve === "github" && appBuilt(chosen.platform) ? [{
77
- value: "ref0",
78
- says: "The ref0 app",
79
- why: "pages for code, pull requests and issues"
80
- }] : [];
81
- const none = [{
82
- value: "none",
83
- says: "No",
84
- why: project === "new" ? "only the APIs" : "the app starts a project of its own"
85
- }];
86
- return chosen.platform === "node" ? [...none, ...ref0] : [...ref0, ...none];
87
- },
88
- refuse: (value, { project, chosen, held, creating }) => value === "framework" !== (creating !== void 0) ? {
89
- reason: "app_choices_conflict",
90
- headline: "--app, --framework and --no-app are one choice: pass one of them"
91
- } : value === "framework" ? void 0 : value === "none" ? held?.app === "ref0" ? {
78
+ offers: ({ project, chosen }) => [...project === "new" && chosen.serve === "github" && chosen.platform === "cloudflare" ? [{
79
+ value: "ref0",
80
+ says: "The ref0 app",
81
+ why: "pages for code, pull requests and issues"
82
+ }] : [], {
83
+ value: "none",
84
+ says: "No",
85
+ why: project === "new" ? "only the APIs" : "the app starts a project of its own"
86
+ }],
87
+ refuse: (value, { project, chosen, held }) => value === "none" ? held?.app === "ref0" ? {
92
88
  reason: "app_held",
93
89
  headline: "This setup has the app, which init can't take out: its pages are yours. Set up Git without it in an empty folder"
94
90
  } : void 0 : project === "existing" ? {
@@ -97,98 +93,11 @@ const app = {
97
93
  } : chosen.serve !== "github" ? {
98
94
  reason: "app_needs_github",
99
95
  headline: "The web app reads GitHub's REST: it takes --serve github"
100
- } : appBuilt(chosen.platform) ? void 0 : appOffPlatform,
101
- named: (value) => [Object.entries(appFlags).find(([answer]) => answer === value)?.[1] ?? "--no-app"]
102
- };
103
- /** The flag that names each answer of the app's. */
104
- const appFlags = {
105
- ref0: "--app",
106
- framework: "--framework",
107
- none: "--no-app"
108
- };
109
- const platforms = [
110
- {
111
- value: "cloudflare",
112
- says: "Cloudflare",
113
- why: "Git, its records and its packs in one Worker"
114
- },
115
- {
116
- value: "vercel",
117
- says: "Vercel",
118
- why: "Git in Vercel's functions, its jobs woken by Vercel Queues"
119
- },
120
- {
121
- value: "node",
122
- says: "Node",
123
- why: "one process of your own, on a server or a VM"
124
- }
125
- ];
126
- /**
127
- * The platforms a folder on `folder` can move to: a Node project stays on Node, and a Worker or a
128
- * Vercel project moves between the two, each held store a conflict to settle.
129
- */
130
- const movesTo = {
131
- cloudflare: ["cloudflare", "vercel"],
132
- vercel: ["cloudflare", "vercel"],
133
- node: ["node"]
134
- };
135
- const platform = {
136
- key: "platform",
137
- flag: "platform",
138
- row: "Platform",
139
- question: "Where will it run?",
140
- offers: ({ folder, creating }) => creating === void 0 ? platforms.filter((each) => folder === void 0 || movesTo[folder].some((value) => value === each.value)) : creating.platforms.flatMap((each) => platforms.filter((offer) => offer.value === each)),
141
- refuse: (value, context) => {
142
- const offered = platform.offers(context);
143
- if (offered.some((offer) => offer.value === value)) return void 0;
144
- return {
145
- reason: "not_on_platform",
146
- headline: context.creating !== void 0 ? `A new ${context.creating.says} app runs on ${offered.map((offer) => offer.says).join(" or ")}: --platform takes ${takes(offered)}` : context.folder === void 0 ? `--platform takes ${takes(offered)}` : `This folder runs on ${platformNames[context.folder]}: --platform takes ${takes(offered)}`
147
- };
148
- },
149
- named: valued("platform")
150
- };
151
- /** The records stores each platform offers. */
152
- const recordsOffered = {
153
- cloudflare: [{
154
- value: "durable-objects",
155
- says: "Durable Objects",
156
- why: "the one store a Worker can wake"
157
- }],
158
- vercel: [{
159
- value: "postgres",
160
- says: "Postgres",
161
- why: "Vercel's Marketplace Postgres takes each commit in one transaction"
162
- }, {
163
- value: "turso",
164
- says: "Turso",
165
- why: "a database per repo, at the cost of a Platform API token"
166
- }],
167
- node: [
168
- {
169
- value: "sqlite",
170
- says: "SQLite",
171
- why: "one file, with no server, and one process owns the jobs"
172
- },
173
- {
174
- value: "postgres",
175
- says: "Postgres",
176
- why: "several replicas share the work"
177
- },
178
- {
179
- value: "turso",
180
- says: "Turso",
181
- why: "a database for each repo, in one Turso group"
182
- }
183
- ]
184
- };
185
- const records = {
186
- key: "records",
187
- flag: "records",
188
- row: "Records",
189
- question: "Where should it keep its records?",
190
- offers: ({ chosen }) => recordsOffered[platformNamed(chosen.platform) ?? "cloudflare"],
191
- named: valued("records")
96
+ } : chosen.platform !== "cloudflare" ? {
97
+ reason: "not_on_platform",
98
+ headline: "The app runs on Cloudflare: --platform takes cloudflare with --app"
99
+ } : void 0,
100
+ named: (value) => [value === "ref0" ? "--app" : "--no-app"]
192
101
  };
193
102
  const objects = {
194
103
  key: "objects",
@@ -214,42 +123,6 @@ const objects = {
214
123
  } : onPlatform(objects, value, context),
215
124
  named: valued("objects")
216
125
  };
217
- const bucket = {
218
- key: "bucket",
219
- flag: "bucket",
220
- row: "Bucket",
221
- question: "Where should it keep its packs?",
222
- offers: ({ chosen }) => chosen.objects === "loose" ? [{
223
- value: "none",
224
- says: "None",
225
- why: "loose objects keep no bucket"
226
- }] : chosen.platform === "node" ? [{
227
- value: "disk",
228
- says: "A folder",
229
- why: "beside the records, with no keys to keep"
230
- }, {
231
- value: "s3",
232
- says: "S3",
233
- why: "any S3-compatible bucket, which signs large pushes' parts and LFS's links"
234
- }] : chosen.platform === "vercel" ? [{
235
- value: "vercel-blob",
236
- says: "Vercel Blob",
237
- why: "it comes with the project, with no account elsewhere"
238
- }, {
239
- value: "s3",
240
- says: "S3",
241
- why: "any S3 bucket, and LFS files past 4.5 MB"
242
- }] : [{
243
- value: "r2",
244
- says: "R2",
245
- why: "bound to the Worker, with no keys to keep"
246
- }],
247
- refuse: (value, context) => context.chosen.objects !== "loose" ? onPlatform(bucket, value, context) : value === "none" ? void 0 : {
248
- reason: "loose_has_no_bucket",
249
- headline: "--bucket goes with --objects packs"
250
- },
251
- named: (value) => value === "none" ? [] : ["--bucket", value]
252
- };
253
126
  const queue = {
254
127
  key: "queue",
255
128
  flag: "queue",
@@ -298,31 +171,6 @@ const basePath = {
298
171
  } : void 0,
299
172
  named: valued("base-path")
300
173
  };
301
- const vercelPlan = {
302
- key: "vercelPlan",
303
- flag: "vercel-plan",
304
- row: "Vercel plan",
305
- question: "Which Vercel plan does the project's team have?",
306
- offers: ({ chosen }) => chosen.platform === "vercel" ? [{
307
- value: "hobby",
308
- says: "Hobby",
309
- why: "deploys on every plan; Pro sweeps each minute and lets a clone run 800 s"
310
- }, {
311
- value: "pro",
312
- says: "Pro",
313
- why: "the cron sweeps each minute, and a clone may run 800 s"
314
- }] : [{
315
- value: "none",
316
- says: "None",
317
- why: ""
318
- }],
319
- refuse: (value, context) => context.chosen.platform !== "vercel" && value !== "none" ? {
320
- reason: "not_on_platform",
321
- headline: "--vercel-plan goes with --platform vercel"
322
- } : onPlatform(vercelPlan, value, context),
323
- named: (value) => value === "none" ? [] : ["--vercel-plan", value],
324
- shown: ({ chosen }) => chosen.platform === "vercel"
325
- };
326
174
  /** Why `value` can't be `choice`'s answer here, if it can't. */
327
175
  const refusalOf = (choice, value, context) => choice.refuse === void 0 ? onPlatform(choice, value, context) : choice.refuse(value, context);
328
176
  /** Every choice, in the order `init` asks them. */
@@ -330,28 +178,38 @@ const choices = [
330
178
  serve,
331
179
  platform,
332
180
  app,
333
- records,
334
181
  objects,
335
- bucket,
336
182
  queue,
337
- basePath,
338
- vercelPlan
183
+ basePath
339
184
  ];
185
+ /** Each platform's records store and packs' bucket, as a move's line names them. */
186
+ const stores = {
187
+ cloudflare: {
188
+ records: "Durable Objects",
189
+ bucket: "R2"
190
+ },
191
+ vercel: {
192
+ records: "Postgres",
193
+ bucket: "Vercel Blob"
194
+ }
195
+ };
340
196
  /**
341
197
  * What each held answer a flag moved costs, as the receipt and `--dry-run` say it: a line for each
342
198
  * move that leaves stored data behind or stops URLs in use from answering, since `init` moves no
343
- * data. A move that does neither, as the Vercel plan's or the queue's, has none, and a platform's
344
- * data is named by the records and objects it moves.
199
+ * data. A move that does neither, as the queue's, has none.
345
200
  */
346
201
  const movesOf = (settled) => {
347
202
  const moves = [];
348
- const { serve, records, objects, bucket, basePath } = settled;
203
+ const { serve, platform, objects, basePath } = settled;
204
+ const was = stores[platformNamed(platform.moved ?? platform.value) ?? "cloudflare"];
205
+ const now = stores[platformNamed(platform.value) ?? "cloudflare"];
349
206
  if (serve.moved === "github" && serve.value !== "github") moves.push(`GitHub's APIs stop answering: \`gh\` and GitHub's clients pointed at this host stop working, and it serves ${serve.value === "api" ? "Git's REST" : "Git's protocol"} only`);
350
- if (records.moved !== void 0) moves.push(`Records move from ${records.moved} to ${records.value}; init moves no data, the existing records stay in ${records.moved}, and the new store starts empty`);
351
- if (objects.moved === "loose") moves.push(`Repos' loose objects stay in ${records.moved ?? records.value}; the new setup starts with none of them`);
352
- if (objects.moved === "packs") moves.push(`Repos' packs stay in ${bucket.moved ?? bucket.value}; the new setup starts with none of them`);
353
- if (bucket.moved === "none") moves.push(`Packs start in ${bucket.value}`);
354
- else if (bucket.moved !== void 0 && bucket.value !== "none") moves.push(`The bucket moves from ${bucket.moved} to ${bucket.value}; init moves no packs, the existing packs stay in ${bucket.moved}, and the new bucket starts empty`);
207
+ if (platform.moved !== void 0 && was !== now) {
208
+ moves.push(`Records move from ${was.records} to ${now.records}; init moves no data, the existing records stay in ${was.records}, and the new store starts empty`);
209
+ if (objects.moved === void 0 && objects.value === "packs") moves.push(`Repos' packs stay in ${was.bucket}; the new setup starts with none of them`);
210
+ }
211
+ if (objects.moved === "loose") moves.push(`Repos' loose objects stay in ${was.records}; the new setup starts with none of them, and its packs start in ${now.bucket}`);
212
+ if (objects.moved === "packs") moves.push(`Repos' packs stay in ${was.bucket}; the new setup starts with none of them`);
355
213
  if (basePath.moved !== void 0) moves.push(`Git's URLs move from \`${basePath.moved}\` to \`${basePath.value}\`; existing remotes need \`git remote set-url\``);
356
214
  return moves;
357
215
  };
@@ -373,20 +231,17 @@ const asChoices = (answers) => answers;
373
231
  * choice open, and the recommended answer stands in for it, so the later choices' offers still
374
232
  * follow. A refused flag fails at once.
375
233
  */
376
- const settle = /* @__PURE__ */ Effect.fnUntraced(function* (given, detected, project, yes, ask, creating, framework) {
234
+ const settle = /* @__PURE__ */ Effect.fnUntraced(function* (given, detected, project, yes, ask, framework) {
377
235
  const chosen = {};
378
236
  const settled = {};
379
237
  const open = [];
380
238
  const conflicts = [];
381
- const folder = platformOf(detected);
382
239
  const holds = Object.fromEntries(Object.entries(detected).map(([key, each]) => [key, each?.value]));
383
240
  for (const choice of choices) {
384
241
  const context = {
385
242
  project,
386
243
  chosen,
387
244
  held: holds,
388
- folder,
389
- creating,
390
245
  framework
391
246
  };
392
247
  const offers = choice.offers(context);
@@ -465,15 +320,13 @@ const recovered = (given, detected, project, conflicts) => {
465
320
  return value === void 0 ? [] : [[choice.key, value]];
466
321
  }))
467
322
  };
468
- const folder = platformOf(detected);
469
323
  const chosen = {};
470
324
  const named = {};
471
325
  for (const choice of choices) {
472
326
  const context = {
473
327
  project,
474
328
  chosen,
475
- held: holds,
476
- folder
329
+ held: holds
477
330
  };
478
331
  const flagged = wanted[choice.key];
479
332
  const held = holds[choice.key];
@@ -315,8 +315,7 @@ const entryOf = (choices, layout) => {
315
315
  text: startEntry,
316
316
  main: "src/server.ts"
317
317
  };
318
- case "manual":
319
- case "mount": return;
318
+ case "manual": return;
320
319
  }
321
320
  };
322
321
  /** Everything `init` writes for `choices` in `project`, with `secret` making each new secret. */