ref0-git 0.27.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.
- package/app/apps/github/README.md +1 -5
- package/app/apps/github/package.json +0 -1
- package/app/apps/github/src/signin/auth.ts +17 -89
- package/app/apps/github/src/signin/credentials.ts +10 -14
- package/app/apps/github/src/signin/guarded-write.ts +19 -0
- package/app/apps/github/src/signin/owner-names.ts +11 -41
- package/app/apps/github/src/signin/unborn.ts +20 -30
- package/app/apps/github/tsconfig.json +0 -2
- package/app/pnpm-workspace.yaml +14 -34
- package/dist/cli/documents.mjs +39 -25
- package/dist/cli/keys.mjs +9 -3
- package/dist/cli/node.mjs +1 -2
- package/dist/cli/runtime.mjs +3 -4
- package/dist/cli/setup.mjs +216 -468
- package/dist/cli/tools-node.mjs +8 -7
- package/dist/cli/tools.mjs +3 -3
- package/dist/cli/vercel-stores.mjs +287 -0
- package/dist/init/app.mjs +4 -37
- package/dist/init/choices.mjs +62 -209
- package/dist/init/cloudflare.mjs +1 -2
- package/dist/init/detect.mjs +77 -167
- package/dist/init/files.mjs +2 -12
- package/dist/init/frameworks.mjs +50 -174
- package/dist/init/git-module.mjs +5 -1
- package/dist/init/metadata.mjs +4 -22
- package/dist/init/next.mjs +13 -66
- package/dist/init/output.mjs +3 -6
- package/dist/init/plan.mjs +1 -29
- package/dist/init/routes.mjs +1 -78
- package/dist/init/stores.mjs +6 -35
- package/dist/init/template.mjs +14 -49
- package/dist/init/templates.mjs +30 -115
- package/dist/init/vercel-regions.mjs +87 -0
- package/dist/init/vercel.mjs +313 -212
- package/dist/init/versions.mjs +3 -3
- package/package.json +5 -11
- package/app/apps/github/migrations/postgres/0001_auth.sql +0 -53
- package/app/apps/github/src/camo/lookup.ts +0 -23
- package/app/apps/github/src/camo/node.ts +0 -50
- package/app/apps/github/src/signin/person-lock.ts +0 -104
- package/dist/cli/sqlite.mjs +0 -28
- package/dist/init/astro.mjs +0 -49
- package/dist/init/create.mjs +0 -152
- package/dist/init/mounts.mjs +0 -104
- package/dist/init/node-app.mjs +0 -196
- package/dist/init/node.mjs +0 -446
- package/dist/init/nuxt.mjs +0 -240
- package/dist/init/react-router.mjs +0 -59
- package/dist/init/sveltekit.mjs +0 -141
package/dist/init/detect.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { detectFrameworks } from "./frameworks.mjs";
|
|
1
|
+
import { detectFrameworks, isNextApp, notYetFramework } from "./frameworks.mjs";
|
|
2
2
|
import { itemsAt, nodeAt, parseJsonc, stringAt as stringAt$1 } from "./jsonc.mjs";
|
|
3
|
+
import { regionNamed } from "./vercel-regions.mjs";
|
|
3
4
|
// src/init/detect.ts
|
|
4
5
|
const managers = [
|
|
5
6
|
"npm",
|
|
@@ -8,20 +9,6 @@ const managers = [
|
|
|
8
9
|
"bun"
|
|
9
10
|
];
|
|
10
11
|
const newProjectFiles = /^(\.git|\.gitignore|README.*|LICENSE.*)$/i;
|
|
11
|
-
/**
|
|
12
|
-
* Why a folder with a `package.json` reads as Node: it has none of the files the other kinds do. A
|
|
13
|
-
* library or a monorepo's root reads as Node too, and the Folder row says so first.
|
|
14
|
-
*/
|
|
15
|
-
const nodeBecause = "no Worker, Vercel project or framework init knows";
|
|
16
|
-
/** The servers a Node project depends on that make it a Node server. */
|
|
17
|
-
const nodeServers = /* @__PURE__ */ new Set([
|
|
18
|
-
"express",
|
|
19
|
-
"hono",
|
|
20
|
-
"fastify",
|
|
21
|
-
"@hono/node-server"
|
|
22
|
-
]);
|
|
23
|
-
/** A framework's name with its article, as a Folder row reads it: `an Astro`, `a Hono`. */
|
|
24
|
-
const aFramework = (says) => `${/^[AEIOU]/.test(says) ? "an" : "a"} ${says}`;
|
|
25
12
|
const configFiles = [
|
|
26
13
|
"wrangler.jsonc",
|
|
27
14
|
"wrangler.json",
|
|
@@ -48,81 +35,24 @@ const dependencies = (text) => {
|
|
|
48
35
|
};
|
|
49
36
|
/** The choices a `src/git.ts` that `init` wrote holds, from its imports and calls. */
|
|
50
37
|
const readBack = (text) => {
|
|
51
|
-
const
|
|
52
|
-
const imports = (entry) => entries.has(entry);
|
|
38
|
+
const imports = (entry) => new RegExp(`^import (?:\\* as \\w+|\\{[^}]*\\}) from '@ref0\\/infra\\/${entry}';$`, "m").test(text);
|
|
53
39
|
const vercel = imports("vercel");
|
|
54
|
-
|
|
55
|
-
if (!vercel && !onNode && !imports("cloudflare")) return void 0;
|
|
56
|
-
const app = text.includes("from './signin/auth.ts'");
|
|
40
|
+
if (!vercel && !imports("cloudflare")) return void 0;
|
|
57
41
|
const loose = /\bObjects\.layerRecords\(\)/.test(text);
|
|
58
|
-
|
|
59
|
-
const shared = {
|
|
42
|
+
return {
|
|
60
43
|
serve: text.includes("from '@ref0/github'") ? "github" : /^ {2}Rest\.layer\(\),$/m.test(text) ? "api" : "git",
|
|
61
|
-
|
|
62
|
-
|
|
44
|
+
platform: vercel ? "vercel" : "cloudflare",
|
|
45
|
+
app: text.includes("from './signin/auth.ts'") ? "ref0" : "none",
|
|
46
|
+
objects: loose && !vercel ? "loose" : "packs",
|
|
47
|
+
queue: text.includes("MergeQueue.layer({ target: 'refs/heads/main', keys: ") ? "on" : "off",
|
|
63
48
|
basePath: /\bGit\.layer\(\{ basePath: '([^']*)'/.exec(text)?.[1] ?? "/"
|
|
64
49
|
};
|
|
65
|
-
if (vercel) return {
|
|
66
|
-
...shared,
|
|
67
|
-
platform: "vercel",
|
|
68
|
-
records: imports("turso") ? "turso" : "postgres",
|
|
69
|
-
objects: "packs",
|
|
70
|
-
bucket: imports("s3") ? "s3" : "vercel-blob",
|
|
71
|
-
vercelPlan: text.includes("maxDuration: '800 seconds'") ? "pro" : "hobby"
|
|
72
|
-
};
|
|
73
|
-
if (onNode) return {
|
|
74
|
-
...shared,
|
|
75
|
-
platform: "node",
|
|
76
|
-
records: imports("sqlite") ? "sqlite" : imports("postgres") ? "postgres" : "turso",
|
|
77
|
-
objects: loose ? "loose" : "packs",
|
|
78
|
-
bucket: loose ? "none" : imports("s3") ? "s3" : "disk",
|
|
79
|
-
vercelPlan: "none"
|
|
80
|
-
};
|
|
81
|
-
return {
|
|
82
|
-
...shared,
|
|
83
|
-
platform: "cloudflare",
|
|
84
|
-
records: "durable-objects",
|
|
85
|
-
objects: loose ? "loose" : "packs",
|
|
86
|
-
bucket: loose ? "none" : "r2",
|
|
87
|
-
vercelPlan: "none"
|
|
88
|
-
};
|
|
89
50
|
};
|
|
90
|
-
/** A cron schedule that runs more often than once a day: its minute or hour isn't one number. */
|
|
91
|
-
const subDaily = (schedule) => {
|
|
92
|
-
const [minute, hour] = schedule.trim().split(/\s+/);
|
|
93
|
-
return !/^\d+$/.test(minute ?? "") || !/^\d+$/.test(hour ?? "");
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* The Vercel plan a `vercel.json` needs: Pro when a cron runs more often than daily or a function
|
|
97
|
-
* may run past 300 s, which Hobby refuses to deploy; else Hobby, which deploys anywhere.
|
|
98
|
-
*/
|
|
99
|
-
const planOf = (text) => {
|
|
100
|
-
const tree = parseJsonc(text);
|
|
101
|
-
const functions = nodeAt(tree, ["functions"]);
|
|
102
|
-
const durations = functions?.kind === "object" ? functions.members.flatMap((member) => {
|
|
103
|
-
const found = nodeAt(member.value, ["maxDuration"]);
|
|
104
|
-
return found?.kind === "value" ? [Number(found.raw)] : [];
|
|
105
|
-
}) : [];
|
|
106
|
-
const schedules = itemsAt(tree, ["crons"]).flatMap((each) => stringAt$1(each, ["schedule"]) ?? []);
|
|
107
|
-
return durations.some((each) => each > 300) || schedules.some(subDaily) ? "pro" : "hobby";
|
|
108
|
-
};
|
|
109
|
-
/** Each platform's name, as a refusal says it. */
|
|
110
|
-
const platformSays = {
|
|
111
|
-
cloudflare: "Cloudflare",
|
|
112
|
-
vercel: "Vercel",
|
|
113
|
-
node: "Node"
|
|
114
|
-
};
|
|
115
|
-
/** OpenNext's Worker, which `next build` writes: Git wraps it as any Worker's `main`. */
|
|
116
|
-
const openNextMain = ".open-next/worker.js";
|
|
117
51
|
/** A file under `src/`'s path from the folder, from an import in `src/` such as `./index.ts`. */
|
|
118
52
|
const fromSrc = (specifier) => new URL(specifier, "file:///src/").pathname.slice(1);
|
|
119
53
|
/** Where Git goes in an existing Worker whose `main` is `main`. */
|
|
120
54
|
const workerLayout = (folder, main, held) => {
|
|
121
55
|
if (main === "src/worker.ts" && held) return { kind: "own" };
|
|
122
|
-
if (main === openNextMain) return {
|
|
123
|
-
kind: "wrapped",
|
|
124
|
-
main
|
|
125
|
-
};
|
|
126
56
|
if (main === "src/git-entry.ts") {
|
|
127
57
|
const wrapped = /^import worker from '([^']+)';$/m.exec(folder.read(main) ?? "")?.[1];
|
|
128
58
|
if (wrapped !== void 0) return {
|
|
@@ -140,23 +70,23 @@ const workerLayout = (folder, main, held) => {
|
|
|
140
70
|
why: "class"
|
|
141
71
|
};
|
|
142
72
|
};
|
|
143
|
-
/**
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const text = folder.read(path);
|
|
151
|
-
return text === void 0 ? void 0 : readBack(text);
|
|
152
|
-
};
|
|
153
|
-
const framework = frameworks.find((each) => each.name === named) ?? frameworks.find((each) => heldIn(each.serverModule) !== void 0) ?? frameworks[0];
|
|
154
|
-
const held = heldIn(framework?.serverModule ?? "src/git.ts");
|
|
155
|
-
const runsOn = (platform) => framework?.platforms.includes(platform) ?? true;
|
|
156
|
-
const toNode = runsOn("node") && !(runsOn("cloudflare") && runsOn("vercel")) && (wanted ?? held?.platform) === "node";
|
|
73
|
+
/** Why `init` can't set Git up in `folder`, which has files but no Worker or Vercel project. */
|
|
74
|
+
const noPlatform = (folder) => ({
|
|
75
|
+
reason: "no_platform",
|
|
76
|
+
headline: `${folder.name} has no wrangler.jsonc or vercel.json, and init sets Git up on Cloudflare or Vercel: run it in a Worker's or a Vercel project's folder, or in an empty one`
|
|
77
|
+
});
|
|
78
|
+
/** The folder's project, or why `init` can't set Git up in it. */
|
|
79
|
+
const detect = (folder) => {
|
|
157
80
|
const packageJson = folder.read("package.json");
|
|
158
81
|
const depends = dependencies(packageJson);
|
|
159
|
-
const
|
|
82
|
+
const vercelJson = folder.read("vercel.json");
|
|
83
|
+
const linked = vercelJson !== void 0 || folder.read(".vercel/project.json") !== void 0 || depends.some((each) => each.startsWith("@vercel/"));
|
|
84
|
+
const configFile = configFiles.find((file) => folder.read(file) !== void 0);
|
|
85
|
+
const alchemy = folder.entries.includes("alchemy.run.ts");
|
|
86
|
+
const vercel = configFile === void 0 && !alchemy && (linked || depends.includes("next") && isNextApp(folder));
|
|
87
|
+
const framework = detectFrameworks(folder, vercel)[0];
|
|
88
|
+
const gitModule = folder.read(framework?.serverModule ?? "src/git.ts");
|
|
89
|
+
const held = gitModule === void 0 ? void 0 : readBack(gitModule);
|
|
160
90
|
const config = configFile === void 0 ? void 0 : {
|
|
161
91
|
file: configFile,
|
|
162
92
|
text: folder.read(configFile) ?? ""
|
|
@@ -180,15 +110,13 @@ const detect = (folder, wanted, named) => {
|
|
|
180
110
|
});
|
|
181
111
|
const heldChoices = held === void 0 ? {} : {
|
|
182
112
|
serve: fromGit(held.serve),
|
|
113
|
+
platform: fromGit(held.platform),
|
|
183
114
|
app: fromGit(held.app),
|
|
184
|
-
records: fromGit(held.records),
|
|
185
115
|
objects: fromGit(held.objects),
|
|
186
|
-
bucket: fromGit(held.bucket),
|
|
187
116
|
queue: fromGit(held.queue),
|
|
188
|
-
basePath: fromGit(held.basePath)
|
|
189
|
-
vercelPlan: fromGit(held.vercelPlan)
|
|
117
|
+
basePath: fromGit(held.basePath)
|
|
190
118
|
};
|
|
191
|
-
const
|
|
119
|
+
const heldRegion = regionNamed(vercelJson === void 0 ? void 0 : stringAt$1(itemsAt(parseJsonc(vercelJson), ["regions"])[0], []));
|
|
192
120
|
const base = {
|
|
193
121
|
config,
|
|
194
122
|
vercelJson,
|
|
@@ -197,7 +125,11 @@ const detect = (folder, wanted, named) => {
|
|
|
197
125
|
packageJson,
|
|
198
126
|
packageManager,
|
|
199
127
|
framework,
|
|
200
|
-
|
|
128
|
+
region: heldRegion === void 0 ? void 0 : {
|
|
129
|
+
value: heldRegion,
|
|
130
|
+
from: "detected",
|
|
131
|
+
detectedFrom: "vercel.json"
|
|
132
|
+
}
|
|
201
133
|
};
|
|
202
134
|
if (isNew) return {
|
|
203
135
|
...base,
|
|
@@ -207,71 +139,8 @@ const detect = (folder, wanted, named) => {
|
|
|
207
139
|
detected: {}
|
|
208
140
|
};
|
|
209
141
|
const start = depends.includes("@tanstack/react-start");
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const onWorker = config !== void 0 || alchemy;
|
|
213
|
-
const platforms = framework?.platforms ?? (start ? ["cloudflare", "node"] : []);
|
|
214
|
-
if (onWorker ? framework !== void 0 && !runsOn("cloudflare") : vercel && platforms.length > 0 && !platforms.includes("vercel")) return {
|
|
215
|
-
reason: "not_on_platform",
|
|
216
|
-
headline: `${framework?.says ?? "TanStack Start"} runs Git on ${platforms.map((each) => platformSays[each]).join(" and ")} only: ${onWorker ? "its Cloudflare adapter" : "Vercel's build of it"} gives Git's jobs no function or class of their own. Run init with --platform node`
|
|
217
|
-
};
|
|
218
|
-
if (config === void 0 && !alchemy && vercel) {
|
|
219
|
-
const from = vercelJson !== void 0 ? "vercel.json" : packageJson === void 0 ? ".vercel/project.json" : "package.json";
|
|
220
|
-
const plan = held?.platform !== "vercel" && vercelJson !== void 0 ? { vercelPlan: {
|
|
221
|
-
value: planOf(vercelJson),
|
|
222
|
-
from: "detected",
|
|
223
|
-
detectedFrom: "vercel.json"
|
|
224
|
-
} } : {};
|
|
225
|
-
return {
|
|
226
|
-
...base,
|
|
227
|
-
project: held?.platform === "vercel" ? "new" : "existing",
|
|
228
|
-
says: held?.platform === "vercel" ? `${folder.name}, set up by init` : `${folder.name}, ${framework === void 0 ? "a Vercel project" : `${aFramework(framework.says)} project on Vercel`}: ${from}`,
|
|
229
|
-
layout: { kind: "own" },
|
|
230
|
-
detected: {
|
|
231
|
-
platform: {
|
|
232
|
-
value: "vercel",
|
|
233
|
-
from: "detected",
|
|
234
|
-
detectedFrom: from
|
|
235
|
-
},
|
|
236
|
-
...plan,
|
|
237
|
-
...heldChoices
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
if (config === void 0 && !alchemy) {
|
|
242
|
-
if (packageJson === void 0) return {
|
|
243
|
-
reason: "not_a_project",
|
|
244
|
-
headline: `${folder.name} has files but no package.json or wrangler.jsonc`
|
|
245
|
-
};
|
|
246
|
-
const ours = held?.platform === "node" && held.app === "ref0" || held?.platform === "node" && (folder.read("src/main.ts") ?? "").includes("from './git.ts'");
|
|
247
|
-
const server = depends.some((each) => nodeServers.has(each));
|
|
248
|
-
const because = framework === void 0 ? nodeBecause : `${framework.says} with no vercel.json or wrangler.jsonc, which run it elsewhere`;
|
|
249
|
-
return {
|
|
250
|
-
...base,
|
|
251
|
-
project: ours ? "new" : "existing",
|
|
252
|
-
says: ours ? `${folder.name}, set up by init` : framework === void 0 ? `${folder.name}, a Node ${server ? "server" : "project"}: package.json, with ${nodeBecause}` : `${folder.name}, ${aFramework(framework.says)} project: package.json`,
|
|
253
|
-
layout: ours ? { kind: "own" } : { kind: "mount" },
|
|
254
|
-
detected: {
|
|
255
|
-
platform: {
|
|
256
|
-
value: "node",
|
|
257
|
-
from: "detected",
|
|
258
|
-
...framework?.adapter?.name === "node" ? {
|
|
259
|
-
detectedFrom: framework.adapter.file,
|
|
260
|
-
because: "adapter-node"
|
|
261
|
-
} : {
|
|
262
|
-
detectedFrom: "package.json",
|
|
263
|
-
because
|
|
264
|
-
}
|
|
265
|
-
},
|
|
266
|
-
...heldChoices
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
const platform = {
|
|
271
|
-
value: "cloudflare",
|
|
272
|
-
from: "detected",
|
|
273
|
-
detectedFrom: alchemy ? "alchemy.run.ts" : config?.file ?? "wrangler.jsonc"
|
|
274
|
-
};
|
|
142
|
+
if (config === void 0 && !alchemy && vercel) return vercelProject(folder, base, heldChoices, start, linked);
|
|
143
|
+
if (config === void 0 && !alchemy) return noPlatform(folder);
|
|
275
144
|
const main = config?.file === "wrangler.toml" ? void 0 : stringAt(config?.text, ["main"]);
|
|
276
145
|
const ours = main === "src/server.ts" && (folder.read(main) ?? "").includes("from './git.ts'");
|
|
277
146
|
const layout = alchemy ? {
|
|
@@ -291,9 +160,50 @@ const detect = (folder, wanted, named) => {
|
|
|
291
160
|
says: layout.kind === "own" ? `${folder.name}, set up by init` : says,
|
|
292
161
|
layout,
|
|
293
162
|
detected: {
|
|
294
|
-
platform
|
|
163
|
+
platform: {
|
|
164
|
+
value: "cloudflare",
|
|
165
|
+
from: "detected",
|
|
166
|
+
detectedFrom: alchemy ? "alchemy.run.ts" : config?.file ?? "wrangler.jsonc"
|
|
167
|
+
},
|
|
168
|
+
...heldChoices
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* A Vercel project, from `vercel.json`, `.vercel/project.json` or a `@vercel/` dependency, or a
|
|
174
|
+
* Next.js app, linked or not, as Next.js runs Git on Vercel alone: Git in its functions, or in
|
|
175
|
+
* Next.js's route files. Another framework's is refused, as `init` writes Git
|
|
176
|
+
* for Vercel in plain functions or Next.js alone: one it sets Git up in on Cloudflare, such as
|
|
177
|
+
* Astro or Start, is sent there, and Nuxt, SvelteKit and React Router aren't set up anywhere yet.
|
|
178
|
+
*/
|
|
179
|
+
const vercelProject = (folder, base, heldChoices, start, linked) => {
|
|
180
|
+
const { framework, held, vercelJson, packageJson } = base;
|
|
181
|
+
const onCloudflare = framework === void 0 ? start ? "TanStack Start" : void 0 : framework.says;
|
|
182
|
+
if (onCloudflare !== void 0 && framework?.name !== "next") return {
|
|
183
|
+
reason: "not_on_platform",
|
|
184
|
+
headline: `${onCloudflare} runs Git on Cloudflare only: on Vercel, init sets Git up in Next.js or in plain functions. Run init in its Worker's folder`
|
|
185
|
+
};
|
|
186
|
+
const notYet = onCloudflare === void 0 ? notYetFramework(folder) : void 0;
|
|
187
|
+
if (notYet !== void 0) return {
|
|
188
|
+
reason: "not_on_platform",
|
|
189
|
+
headline: `init doesn't set Git up in ${notYet} yet: on Vercel, it sets Git up in Next.js or in plain functions`
|
|
190
|
+
};
|
|
191
|
+
const from = vercelJson !== void 0 ? "vercel.json" : packageJson === void 0 ? ".vercel/project.json" : "package.json";
|
|
192
|
+
const ours = held?.platform === "vercel";
|
|
193
|
+
const what = framework === void 0 ? "a Vercel project" : linked ? `a ${framework.says} project on Vercel` : `a ${framework.says} app, which runs Git on Vercel alone`;
|
|
194
|
+
return {
|
|
195
|
+
...base,
|
|
196
|
+
project: ours ? "new" : "existing",
|
|
197
|
+
says: ours ? `${folder.name}, set up by init` : `${folder.name}, ${what}: ${from}`,
|
|
198
|
+
layout: { kind: "own" },
|
|
199
|
+
detected: {
|
|
200
|
+
platform: {
|
|
201
|
+
value: "vercel",
|
|
202
|
+
from: "detected",
|
|
203
|
+
detectedFrom: from
|
|
204
|
+
},
|
|
295
205
|
...heldChoices
|
|
296
206
|
}
|
|
297
207
|
};
|
|
298
208
|
};
|
|
299
|
-
export { detect,
|
|
209
|
+
export { detect, readBack };
|
package/dist/init/files.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseJsonc, stringAt, withEntries, withValue } from "./jsonc.mjs";
|
|
2
|
-
import { appPackages
|
|
2
|
+
import { appPackages } from "./metadata.mjs";
|
|
3
3
|
import { initWrote, specOf } from "./versions.mjs";
|
|
4
4
|
import * as Predicate from "effect/Predicate";
|
|
5
5
|
// src/init/files.ts
|
|
@@ -179,14 +179,4 @@ const withPnpmOverrides = (current, vendor) => {
|
|
|
179
179
|
...all.slice(at + 1 + block.length)
|
|
180
180
|
].join(end);
|
|
181
181
|
};
|
|
182
|
-
|
|
183
|
-
* `package.json` with an `@types/node` older than `typesMajor` moved to the catalog's, where a
|
|
184
|
-
* create command wrote it in this run: `create-next-app` writes `^20`. One of the person's stays.
|
|
185
|
-
*/
|
|
186
|
-
const withCreatedTypes = (created) => (text) => {
|
|
187
|
-
const spec = stringAt(parseJsonc(text), ["devDependencies", "@types/node"]);
|
|
188
|
-
const major = Number(/^[\^~=v]*(\d+)/.exec(spec ?? "")?.[1] ?? 22);
|
|
189
|
-
if (created !== true || major >= 22) return text;
|
|
190
|
-
return withValue(text, ["devDependencies", "@types/node"], nodePackages["@types/node"]);
|
|
191
|
-
};
|
|
192
|
-
export { fitted, ignoring, importLine, lines, listed, pnpmEntries, pnpmManual, pnpmOverridesOf, served, withCli, withCreatedTypes, withDependencies, withLines, withPnpmOverrides, wroteOf };
|
|
182
|
+
export { fitted, ignoring, importLine, lines, listed, pnpmEntries, pnpmManual, pnpmOverridesOf, served, withCli, withDependencies, withLines, withPnpmOverrides, wroteOf };
|
package/dist/init/frameworks.mjs
CHANGED
|
@@ -1,86 +1,60 @@
|
|
|
1
1
|
import { nodeAt, parseJsonc, stringAt } from "./jsonc.mjs";
|
|
2
|
-
import { nuxtGitMiddleware, nuxtJobsPlugin } from "./nuxt.mjs";
|
|
3
2
|
import { rangeMajor } from "./range-major.mjs";
|
|
4
3
|
// src/init/frameworks.ts
|
|
4
|
+
/** Next.js's name, as a receipt and `Context.framework` give it: it runs Git on Vercel alone. */
|
|
5
|
+
const nextJs = "Next.js";
|
|
5
6
|
/** `init.md`'s Detection table, in its order: the first a project depends on wins. */
|
|
6
7
|
const rows = [
|
|
7
8
|
{
|
|
8
9
|
name: "next",
|
|
9
10
|
dependency: "next",
|
|
10
|
-
says:
|
|
11
|
+
says: nextJs,
|
|
11
12
|
majors: [16],
|
|
12
|
-
|
|
13
|
-
"cloudflare",
|
|
14
|
-
"vercel",
|
|
15
|
-
"node"
|
|
16
|
-
]
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
name: "sveltekit",
|
|
20
|
-
dependency: "@sveltejs/kit",
|
|
21
|
-
says: "SvelteKit",
|
|
22
|
-
majors: [3],
|
|
23
|
-
platforms: ["node"]
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: "nuxt",
|
|
27
|
-
dependency: "nuxt",
|
|
28
|
-
says: "Nuxt",
|
|
29
|
-
majors: [4],
|
|
30
|
-
platforms: ["node"]
|
|
13
|
+
vercelOnly: true
|
|
31
14
|
},
|
|
32
15
|
{
|
|
33
16
|
name: "astro",
|
|
34
17
|
dependency: "astro",
|
|
35
18
|
says: "Astro",
|
|
36
|
-
majors: [7]
|
|
37
|
-
platforms: ["cloudflare", "node"]
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: "react-router",
|
|
41
|
-
dependency: "@react-router/dev",
|
|
42
|
-
says: "React Router",
|
|
43
|
-
majors: [7, 8],
|
|
44
|
-
platforms: ["cloudflare", "node"]
|
|
19
|
+
majors: [7]
|
|
45
20
|
},
|
|
46
21
|
{
|
|
47
22
|
name: "hono",
|
|
48
23
|
dependency: "hono",
|
|
49
|
-
with: "@hono/node-server",
|
|
50
24
|
says: "Hono",
|
|
51
|
-
majors: [4]
|
|
52
|
-
platforms: ["cloudflare", "node"]
|
|
25
|
+
majors: [4]
|
|
53
26
|
},
|
|
54
27
|
{
|
|
55
28
|
name: "express",
|
|
56
29
|
dependency: "express",
|
|
57
30
|
says: "Express",
|
|
58
|
-
majors: [5]
|
|
59
|
-
platforms: ["cloudflare", "node"]
|
|
31
|
+
majors: [5]
|
|
60
32
|
},
|
|
61
33
|
{
|
|
62
34
|
name: "fastify",
|
|
63
35
|
dependency: "fastify",
|
|
64
36
|
says: "Fastify",
|
|
65
|
-
majors: [5]
|
|
66
|
-
platforms: ["cloudflare", "node"]
|
|
37
|
+
majors: [5]
|
|
67
38
|
}
|
|
68
39
|
];
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
40
|
+
/**
|
|
41
|
+
* The frameworks `init` sets Git up in nowhere yet, each by the dependency that names it. Their
|
|
42
|
+
* Vercel builds give Git's plain functions no place, so a Vercel project that depends on one is
|
|
43
|
+
* refused; elsewhere its folder is a Worker like any. Start isn't one: it runs Git on Cloudflare.
|
|
44
|
+
*/
|
|
45
|
+
const notYet = [
|
|
46
|
+
{
|
|
47
|
+
dependency: "nuxt",
|
|
48
|
+
says: "Nuxt"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
dependency: "@sveltejs/kit",
|
|
52
|
+
says: "SvelteKit"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
dependency: "@react-router/dev",
|
|
56
|
+
says: "React Router"
|
|
57
|
+
}
|
|
84
58
|
];
|
|
85
59
|
/** The config files Next.js 16 reads, in the order it looks for them. */
|
|
86
60
|
const nextConfigs = [
|
|
@@ -89,27 +63,6 @@ const nextConfigs = [
|
|
|
89
63
|
"next.config.ts",
|
|
90
64
|
"next.config.mts"
|
|
91
65
|
];
|
|
92
|
-
const astroConfigs = [
|
|
93
|
-
"astro.config.mjs",
|
|
94
|
-
"astro.config.ts",
|
|
95
|
-
"astro.config.mts",
|
|
96
|
-
"astro.config.js"
|
|
97
|
-
];
|
|
98
|
-
/** The config files Nuxt 4 reads, in the order c12 looks for them: the first it finds is the one. */
|
|
99
|
-
const nuxtConfigs = /* @__PURE__ */ [
|
|
100
|
-
"js",
|
|
101
|
-
"ts",
|
|
102
|
-
"mjs",
|
|
103
|
-
"cjs",
|
|
104
|
-
"mts",
|
|
105
|
-
"cts",
|
|
106
|
-
"json",
|
|
107
|
-
"jsonc",
|
|
108
|
-
"json5",
|
|
109
|
-
"yaml",
|
|
110
|
-
"yml",
|
|
111
|
-
"toml"
|
|
112
|
-
].map((extension) => `nuxt.config.${extension}`);
|
|
113
66
|
/** Each name a `package.json` depends on, with its version spec. */
|
|
114
67
|
const dependencies = (text) => {
|
|
115
68
|
const tree = text === void 0 ? void 0 : parseJsonc(text);
|
|
@@ -121,16 +74,16 @@ const dependencies = (text) => {
|
|
|
121
74
|
};
|
|
122
75
|
/** Next.js's App Router folder, as Next picks it: root `app/` over `src/app/`, else beside pages. */
|
|
123
76
|
const appDirOf = (folder) => folder.isFolder("app") ? "app" : folder.isFolder("src/app") || !folder.isFolder("pages") && folder.isFolder("src/pages") ? "src/app" : "app";
|
|
124
|
-
/**
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Whether `folder` holds a Next.js app of its own: a config Next reads, or a folder of its routes.
|
|
79
|
+
* A workspace root or a library that depends on `next` holds neither.
|
|
80
|
+
*/
|
|
81
|
+
const isNextApp = (folder) => nextConfigs.some((file) => folder.read(file) !== void 0) || [
|
|
82
|
+
"app",
|
|
83
|
+
"src/app",
|
|
84
|
+
"pages",
|
|
85
|
+
"src/pages"
|
|
86
|
+
].some((path) => folder.isFolder(path));
|
|
134
87
|
/** The first of `paths` the folder holds, with its text. */
|
|
135
88
|
const firstOf = (folder, paths) => paths.flatMap((path) => {
|
|
136
89
|
const text = folder.read(path);
|
|
@@ -139,21 +92,6 @@ const firstOf = (folder, paths) => paths.flatMap((path) => {
|
|
|
139
92
|
text
|
|
140
93
|
}];
|
|
141
94
|
})[0];
|
|
142
|
-
/**
|
|
143
|
-
* Astro's adapter, from the first `astro.config.*` whose `adapter:` calls an import: `node` for
|
|
144
|
-
* `@astrojs/node`, or the package's name for one outside `@astrojs/`, and the name it's imported as.
|
|
145
|
-
*/
|
|
146
|
-
const astroAdapterOf = (folder) => astroConfigs.flatMap((file) => {
|
|
147
|
-
const text = folder.read(file) ?? "";
|
|
148
|
-
const called = /\badapter\s*:\s*([A-Za-z_$][\w$]*)\s*\(/.exec(text)?.[1];
|
|
149
|
-
const from = called === void 0 ? void 0 : new RegExp(`^import\\s+${called.replaceAll("$", "\\$")}\\s+from\\s+['"]([^'"]+)['"]`, "m").exec(text)?.[1];
|
|
150
|
-
return from === void 0 ? [] : [{
|
|
151
|
-
name: from.replace(/^@astrojs\//, ""),
|
|
152
|
-
file,
|
|
153
|
-
text,
|
|
154
|
-
call: called
|
|
155
|
-
}];
|
|
156
|
-
})[0];
|
|
157
95
|
/** One row's framework in `folder`, whose `package.json` names it at `spec`. */
|
|
158
96
|
const frameworkOf = (row, spec, folder) => {
|
|
159
97
|
const major = rangeMajor(spec);
|
|
@@ -164,8 +102,7 @@ const frameworkOf = (row, spec, folder) => {
|
|
|
164
102
|
name: row.name,
|
|
165
103
|
says: row.says,
|
|
166
104
|
major,
|
|
167
|
-
known
|
|
168
|
-
platforms: row.platforms
|
|
105
|
+
known
|
|
169
106
|
};
|
|
170
107
|
if (row.name === "next") {
|
|
171
108
|
const appDir = appDirOf(folder);
|
|
@@ -174,91 +111,30 @@ const frameworkOf = (row, spec, folder) => {
|
|
|
174
111
|
serverModule: appDir === "src/app" ? "src/lib/git.ts" : "lib/git.ts",
|
|
175
112
|
appDir,
|
|
176
113
|
config: firstOf(folder, nextConfigs),
|
|
177
|
-
instrumentation: firstOf(folder, [
|
|
178
|
-
"instrumentation.ts",
|
|
179
|
-
"instrumentation.js",
|
|
180
|
-
"src/instrumentation.ts",
|
|
181
|
-
"src/instrumentation.js"
|
|
182
|
-
]),
|
|
183
|
-
platform: "node",
|
|
184
114
|
row: `${version}${unknown}, App Router in ${appDir}/, from package.json`
|
|
185
115
|
};
|
|
186
116
|
}
|
|
187
|
-
if (row.name === "sveltekit") {
|
|
188
|
-
const adapter = adapterOf(folder);
|
|
189
|
-
const where = adapter === void 0 ? ", no adapter" : `, adapter-${adapter.name} in ${adapter.file}`;
|
|
190
|
-
return {
|
|
191
|
-
...base,
|
|
192
|
-
serverModule: "src/lib/server/git.ts",
|
|
193
|
-
adapter,
|
|
194
|
-
hooks: {
|
|
195
|
-
server: firstOf(folder, ["src/hooks.server.ts", "src/hooks.server.js"]),
|
|
196
|
-
universal: firstOf(folder, ["src/hooks.ts", "src/hooks.js"])
|
|
197
|
-
},
|
|
198
|
-
platform: adapter?.name === "node" ? "node" : void 0,
|
|
199
|
-
row: `${version}${unknown}${where}, from package.json`
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
if (row.name === "astro") {
|
|
203
|
-
const adapter = astroAdapterOf(folder);
|
|
204
|
-
const where = adapter === void 0 ? ", no adapter" : `, ${adapter.name} adapter in ${adapter.file}`;
|
|
205
|
-
return {
|
|
206
|
-
...base,
|
|
207
|
-
serverModule: "src/lib/git.ts",
|
|
208
|
-
config: firstOf(folder, astroConfigs),
|
|
209
|
-
adapter,
|
|
210
|
-
platform: adapter?.name === "node" ? "node" : void 0,
|
|
211
|
-
row: `${version}${unknown}${where}, from package.json`
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
if (row.name === "nuxt") return {
|
|
215
|
-
...base,
|
|
216
|
-
serverModule: "server/git.ts",
|
|
217
|
-
config: firstOf(folder, nuxtConfigs),
|
|
218
|
-
nitro: {
|
|
219
|
-
plugin: firstOf(folder, [nuxtJobsPlugin]),
|
|
220
|
-
middleware: firstOf(folder, [nuxtGitMiddleware])
|
|
221
|
-
},
|
|
222
|
-
platform: "node",
|
|
223
|
-
row: `${version}${unknown}, from package.json`
|
|
224
|
-
};
|
|
225
|
-
const routesFile = row.name === "react-router" ? firstOf(folder, ["app/routes.ts"]) : void 0;
|
|
226
|
-
const flat = routesFile === void 0 ? {} : {
|
|
227
|
-
config: routesFile,
|
|
228
|
-
flatRoutes: /\bflatRoutes\(/.test(routesFile.text)
|
|
229
|
-
};
|
|
230
|
-
const routes = flat.flatRoutes === void 0 ? "" : flat.flatRoutes ? ", flatRoutes() in app/routes.ts" : ", routes listed in app/routes.ts";
|
|
231
117
|
return {
|
|
232
118
|
...base,
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
platform: "node",
|
|
236
|
-
row: `${version}${unknown}${routes}, from package.json`
|
|
119
|
+
serverModule: "src/git.ts",
|
|
120
|
+
row: `${version}${unknown}, from package.json`
|
|
237
121
|
};
|
|
238
122
|
};
|
|
239
|
-
/**
|
|
240
|
-
|
|
123
|
+
/**
|
|
124
|
+
* The frameworks `folder`'s `package.json` depends on, in the table's order: Next.js only when the
|
|
125
|
+
* folder is a Vercel project.
|
|
126
|
+
*/
|
|
127
|
+
const detectFrameworks = (folder, vercel) => {
|
|
241
128
|
const depends = dependencies(folder.read("package.json"));
|
|
242
129
|
return rows.flatMap((row) => {
|
|
243
130
|
const spec = depends.get(row.dependency);
|
|
244
|
-
if (row.
|
|
131
|
+
if (row.vercelOnly === true && !vercel) return [];
|
|
245
132
|
return spec === void 0 ? [] : [frameworkOf(row, spec, folder)];
|
|
246
133
|
});
|
|
247
134
|
};
|
|
248
|
-
/** The
|
|
249
|
-
const
|
|
250
|
-
const
|
|
251
|
-
return
|
|
252
|
-
};
|
|
253
|
-
/**
|
|
254
|
-
* The framework Git goes in: `named`, from `--framework`, among those found, or the first found;
|
|
255
|
-
* `undefined` for none. `--framework` in a folder with frameworks only picks one already there.
|
|
256
|
-
*/
|
|
257
|
-
const frameworkFor = (found, named) => {
|
|
258
|
-
if (named === void 0) return found[0];
|
|
259
|
-
return found.find((each) => each.name === named) ?? {
|
|
260
|
-
reason: "framework_differs",
|
|
261
|
-
headline: `This folder is a ${found.map((each) => each.says).join(" and ")} project, not ${named}: run init without --framework, or in an empty folder`
|
|
262
|
-
};
|
|
135
|
+
/** The first framework `init` doesn't set Git up in yet that `folder`'s `package.json` depends on. */
|
|
136
|
+
const notYetFramework = (folder) => {
|
|
137
|
+
const depends = dependencies(folder.read("package.json"));
|
|
138
|
+
return notYet.find((each) => depends.has(each.dependency))?.says;
|
|
263
139
|
};
|
|
264
|
-
export { detectFrameworks,
|
|
140
|
+
export { detectFrameworks, isNextApp, nextConfigs, nextJs, notYetFramework };
|
package/dist/init/git-module.mjs
CHANGED
|
@@ -145,5 +145,9 @@ const gitOptions = (choices, maxDuration) => {
|
|
|
145
145
|
* The admin's sign-in, then `export const runtime`: the whole host, Git with its features over the
|
|
146
146
|
* adapter, one runtime that every entry, object and job runner takes.
|
|
147
147
|
*/
|
|
148
|
-
const runtimeLines = (choices, parts) =>
|
|
148
|
+
const runtimeLines = (choices, parts) => {
|
|
149
|
+
const at = parts.over === void 0 ? "" : " ";
|
|
150
|
+
const body = lines(`${at}Git.runtime(`, parts.maxDuration !== void 0 && lines(`${at} // The functions' \`maxDuration\`, from \`vercel.json\`: a clone that would outrun it ends first,`, `${at} // with Git's own message.`), `${at} Git.layer(${gitOptions(choices, parts.maxDuration)}, ${choices.serve === "github" ? "github" : "features"}).pipe(`, `${at} Layer.provide(Policy.layer(policy)),`, parts.bootstrap === true ? `${at} Layer.provide(auth),` : `${at} Layer.provide(Auth.layer(auth)),`, choices.objects === "packs" ? parts.memory === void 0 ? `${at} Layer.provide(Objects.layer()),` : lines(`${at} // What packs() counts: an instance's memory, less the runtime's own.`, `${at} Layer.provide(Objects.layer({ memory: ${parts.memory} * 1024 * 1024 })),`) : `${at} // Each object a row in its push's commit: no bucket, ${looseSays}.\n${at} Layer.provide(Objects.layerRecords()),`, `${at} Layer.provideMerge(${parts.adapter}),`, `${at} ),`, `${at})`);
|
|
151
|
+
return lines(parts.bootstrap === true ? lines("/** The bootstrap's sign-in, while `ADMIN_TOKEN` holds one: a Bearer token, or Basic's password. */", "const auth =", ` ${parts.token} === undefined || ${parts.token} === ''`, " ? Layer.empty", ` : Auth.layer(Auth.bearer({ token: Redacted.make(${parts.token}), actor: bootstrap }));`) : lines("/** The admin's sign-in: `ADMIN_TOKEN`, as a Bearer token or as Basic's password. */", `const auth = Auth.bearer({ token: Redacted.make(${parts.token}), actor: admin });`), "", "/**", parts.over === void 0 ? " * The whole host, one runtime that every request and job shares: Git and its features over the" : " * The whole host over `store`, one runtime that a process's requests or jobs share: Git and its", parts.over === void 0 ? ` * adapter, deciding with \`policy\`, and the ${parts.bootstrap === true ? "bootstrap" : "admin"} signing in with \`auth\`.` : ` * features over the adapter, deciding with \`policy\`, and the admin signing in with \`auth\`.`, parts.jobs !== void 0 && ` * ${parts.jobs}`, " */", parts.over === void 0 ? `export const runtime = ${body};` : lines(`export const hostOver = (store: ${parts.over.type}) =>`, `${body};`, "", "/** The Functions' runtime: Git's URLs, over a store that runs no job. */", `export const runtime = hostOver(${parts.over.store});`), "");
|
|
152
|
+
};
|
|
149
153
|
export { adminLines, effectImports, featuresLines, gitDependencies, gitImports, gitPackages, header, lfsLines, looseSays, mergeLines, policyLines, queueLine, repoHint, runtimeLines, workerStoreLines, writtenCpu };
|