ref0-git 0.3.0 → 0.6.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/.dev.vars.example +2 -1
- package/app/apps/github/generated/git-rest.ts +191 -25
- package/app/apps/github/generated/routeTree.gen.ts +21 -0
- package/app/apps/github/package.json +1 -1
- package/app/apps/github/src/branches/branch-list.tsx +8 -4
- package/app/apps/github/src/branches/branches.ts +10 -5
- package/app/apps/github/src/camo/addresses.ts +120 -0
- package/app/apps/github/src/camo/client.ts +125 -0
- package/app/apps/github/src/camo/fetch.ts +201 -0
- package/app/apps/github/src/camo/lookup.ts +23 -0
- package/app/apps/github/src/camo/node.ts +50 -0
- package/app/apps/github/src/camo/proxy.ts +116 -0
- package/app/apps/github/src/camo/sign-images.ts +307 -0
- package/app/apps/github/src/camo/signing.ts +80 -0
- package/app/apps/github/src/clients/allowed.ts +111 -18
- package/app/apps/github/src/clients/clients.ts +76 -61
- package/app/apps/github/src/clients/transport.ts +13 -0
- package/app/apps/github/src/code/code-tree.tsx +3 -1
- package/app/apps/github/src/code/file-view.tsx +15 -6
- package/app/apps/github/src/code/files.ts +26 -19
- package/app/apps/github/src/code/go-to-file.tsx +2 -1
- package/app/apps/github/src/code/load.ts +41 -23
- package/app/apps/github/src/code/markdown-files.ts +13 -2
- package/app/apps/github/src/code/ref-pages.ts +14 -5
- package/app/apps/github/src/code/ref-switcher.tsx +4 -3
- package/app/apps/github/src/code/refs.ts +42 -8
- package/app/apps/github/src/code/repo-home.tsx +6 -2
- package/app/apps/github/src/code/repo.ts +12 -6
- package/app/apps/github/src/code/saved.ts +5 -3
- package/app/apps/github/src/code/trees.ts +11 -9
- package/app/apps/github/src/components/markdown/markdown.css +6 -0
- package/app/apps/github/src/components/markdown/markdown.tsx +95 -10
- package/app/apps/github/src/components/owner-card.tsx +3 -1
- package/app/apps/github/src/components/repos/your-repos.tsx +3 -1
- package/app/apps/github/src/components/shell/owner-repos.tsx +7 -12
- package/app/apps/github/src/components/shell/repo-switcher.tsx +10 -16
- package/app/apps/github/src/components/signin/device-card.tsx +9 -2
- package/app/apps/github/src/components/user-avatar.tsx +2 -1
- package/app/apps/github/src/context/context.ts +13 -0
- package/app/apps/github/src/diffs/blobs.ts +37 -14
- package/app/apps/github/src/diffs/diff-job.ts +53 -0
- package/app/apps/github/src/diffs/diff-worker.ts +6 -0
- package/app/apps/github/src/diffs/diffing.ts +136 -0
- package/app/apps/github/src/diffs/files.ts +4 -3
- package/app/apps/github/src/diffs/hunks.tsx +101 -53
- package/app/apps/github/src/diffs/patch.ts +20 -11
- package/app/apps/github/src/history/commit-diff.ts +10 -5
- package/app/apps/github/src/history/commit-list.tsx +3 -1
- package/app/apps/github/src/history/commit-page.tsx +4 -2
- package/app/apps/github/src/history/history.ts +12 -10
- package/app/apps/github/src/hooks/allowed.ts +9 -9
- package/app/apps/github/src/hooks/avatars.ts +3 -3
- package/app/apps/github/src/hooks/open-counts.ts +5 -4
- package/app/apps/github/src/hooks/profiles.ts +26 -12
- package/app/apps/github/src/hooks/repos.ts +78 -25
- package/app/apps/github/src/inbox/count.ts +30 -29
- package/app/apps/github/src/inbox/inbox-item.tsx +3 -1
- package/app/apps/github/src/inbox/inbox-page.tsx +5 -2
- package/app/apps/github/src/inbox/marks.ts +26 -15
- package/app/apps/github/src/inbox/release-tags.ts +7 -6
- package/app/apps/github/src/inbox/subjects.ts +5 -4
- package/app/apps/github/src/inbox/subscription-controls.tsx +14 -5
- package/app/apps/github/src/inbox/subscriptions.ts +95 -35
- package/app/apps/github/src/inbox/threads.ts +6 -6
- package/app/apps/github/src/issues/changes.ts +40 -16
- package/app/apps/github/src/issues/counts.ts +8 -5
- package/app/apps/github/src/issues/issue-list.tsx +20 -6
- package/app/apps/github/src/issues/issue-page.tsx +30 -14
- package/app/apps/github/src/issues/issues.ts +195 -46
- package/app/apps/github/src/issues/label-dialog.tsx +8 -11
- package/app/apps/github/src/issues/labels-page.tsx +35 -3
- package/app/apps/github/src/issues/milestone-dialog.tsx +197 -0
- package/app/apps/github/src/issues/milestones-page.tsx +269 -0
- package/app/apps/github/src/issues/new-issue.tsx +3 -1
- package/app/apps/github/src/issues/sidebar.tsx +8 -6
- package/app/apps/github/src/markdown/README.md +22 -17
- package/app/apps/github/src/markdown/context.ts +83 -10
- package/app/apps/github/src/markdown/images.ts +3 -2
- package/app/apps/github/src/markdown/lookup.ts +9 -8
- package/app/apps/github/src/markdown/page-budget.ts +50 -0
- package/app/apps/github/src/markdown/patches.ts +74 -32
- package/app/apps/github/src/markdown/query.ts +7 -2
- package/app/apps/github/src/markdown/remote.ts +106 -0
- package/app/apps/github/src/markdown/render.ts +101 -24
- package/app/apps/github/src/markdown/texts.ts +43 -0
- package/app/apps/github/src/markdown/words-module.d.ts +5 -0
- package/app/apps/github/src/markdown/words-plugin.ts +135 -0
- package/app/apps/github/src/names/repos.ts +1 -1
- package/app/apps/github/src/palette/palette.tsx +7 -4
- package/app/apps/github/src/palette/rows.tsx +54 -33
- package/app/apps/github/src/palette/server.ts +5 -5
- package/app/apps/github/src/palette/targets.ts +1 -0
- package/app/apps/github/src/policy.ts +165 -66
- package/app/apps/github/src/private-repos.ts +2 -2
- package/app/apps/github/src/pulls/compare-page.tsx +6 -3
- package/app/apps/github/src/pulls/files-tab.tsx +480 -214
- package/app/apps/github/src/pulls/held-summary.ts +178 -0
- package/app/apps/github/src/pulls/live.ts +6 -4
- package/app/apps/github/src/pulls/merge-box.tsx +17 -10
- package/app/apps/github/src/pulls/pull-list.tsx +6 -3
- package/app/apps/github/src/pulls/pull-page.tsx +19 -10
- package/app/apps/github/src/pulls/pull.ts +68 -40
- package/app/apps/github/src/pulls/pulls.ts +39 -22
- package/app/apps/github/src/pulls/review-drafts.ts +131 -0
- package/app/apps/github/src/pulls/review.ts +374 -99
- package/app/apps/github/src/pulls/threads.tsx +152 -0
- package/app/apps/github/src/queue/queue-page.tsx +15 -8
- package/app/apps/github/src/queue/queue.ts +35 -20
- package/app/apps/github/src/releases/latest-release.tsx +3 -1
- package/app/apps/github/src/releases/overview.tsx +4 -2
- package/app/apps/github/src/releases/release-form.tsx +8 -5
- package/app/apps/github/src/releases/release-list.tsx +8 -5
- package/app/apps/github/src/releases/release-view.tsx +1 -0
- package/app/apps/github/src/releases/releases.ts +33 -23
- package/app/apps/github/src/releases/tag-list.tsx +3 -1
- package/app/apps/github/src/router.tsx +5 -2
- package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +7 -1
- package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +6 -1
- package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +2 -1
- package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +1 -1
- package/app/apps/github/src/routes/$owner/$repo/branches.tsx +5 -1
- package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +1 -1
- package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +6 -1
- package/app/apps/github/src/routes/$owner/$repo/index.tsx +1 -1
- package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +4 -2
- package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +2 -2
- package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +5 -2
- package/app/apps/github/src/routes/$owner/$repo/labels.tsx +2 -1
- package/app/apps/github/src/routes/$owner/$repo/milestones.tsx +36 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +4 -2
- package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +2 -2
- package/app/apps/github/src/routes/$owner/$repo/queue.tsx +2 -1
- package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +5 -2
- package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +2 -1
- package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +4 -2
- package/app/apps/github/src/routes/$owner/$repo/route.tsx +9 -5
- package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +3 -1
- package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +3 -1
- package/app/apps/github/src/routes/-nav.tsx +10 -2
- package/app/apps/github/src/routes/-root-testing.ts +29 -6
- package/app/apps/github/src/routes/__root.tsx +9 -4
- package/app/apps/github/src/routes/index.tsx +3 -1
- package/app/apps/github/src/routes/orgs/$owner/route.tsx +4 -1
- package/app/apps/github/src/routes/orgs/$owner/settings.tsx +4 -1
- package/app/apps/github/src/seed/acme.ts +1 -1
- package/app/apps/github/src/seed/seed.ts +199 -110
- package/app/apps/github/src/server.ts +24 -15
- package/app/apps/github/src/settings/account-avatar.tsx +4 -1
- package/app/apps/github/src/settings/general-settings.tsx +3 -1
- package/app/apps/github/src/settings/general.ts +4 -4
- package/app/apps/github/src/settings/hook-form.tsx +3 -1
- package/app/apps/github/src/settings/hook-list.tsx +5 -2
- package/app/apps/github/src/settings/hooks.ts +7 -7
- package/app/apps/github/src/settings/org-settings.tsx +3 -1
- package/app/apps/github/src/settings/orgs.ts +21 -11
- package/app/apps/github/src/settings/settings-layout.tsx +3 -1
- package/app/apps/github/src/signin/approval.ts +4 -3
- package/app/apps/github/src/signin/auth.ts +9 -2
- package/app/apps/github/src/signin/device-code.ts +8 -3
- package/app/apps/github/src/signin/device-prompt.ts +28 -3
- package/app/apps/github/src/signin/revoke.ts +36 -0
- package/app/apps/github/tsconfig.json +4 -1
- package/app/apps/github/vite.config.ts +8 -0
- package/app/pnpm-workspace.yaml +12 -5
- package/app/tsconfig.base.json +1 -0
- package/dist/cli/child.mjs +1 -1
- package/dist/cli/credentials.mjs +4 -4
- package/dist/cli/documents.mjs +32 -22
- package/dist/cli/events.mjs +1 -1
- package/dist/cli/failure.mjs +20 -7
- package/dist/cli/folders.mjs +2 -2
- package/dist/cli/git-remote-ref0.mjs +47 -22
- package/dist/cli/git.mjs +1 -1
- package/dist/cli/helpers.mjs +2 -2
- package/dist/cli/hosts.mjs +3 -3
- package/dist/cli/output.mjs +2 -2
- package/dist/cli/prompt.mjs +1 -1
- package/dist/cli/queue.mjs +7 -7
- package/dist/cli/ref0-git.mjs +2 -2
- package/dist/cli/repos.mjs +35 -18
- package/dist/cli/resources.mjs +5 -5
- package/dist/cli/retry-after.mjs +8 -0
- package/dist/cli/setup.mjs +172 -66
- package/dist/cli/sign-in.mjs +65 -23
- package/dist/cli/sign-ins.mjs +4 -4
- package/dist/cli/sqlite.mjs +2 -2
- package/dist/cli/tokens.mjs +3 -3
- package/dist/cli/vendor.mjs +1 -1
- package/dist/init/app.mjs +20 -21
- package/dist/init/choices.mjs +1 -1
- package/dist/init/cloudflare.mjs +15 -19
- package/dist/init/create.mjs +3 -2
- package/dist/init/detect.mjs +4 -4
- package/dist/init/files.mjs +120 -13
- package/dist/init/frameworks.mjs +16 -0
- package/dist/init/git-module.mjs +22 -7
- package/dist/init/jsonc.mjs +9 -7
- package/dist/init/metadata.mjs +9 -3
- package/dist/init/mounts.mjs +13 -10
- package/dist/init/next.mjs +2 -2
- package/dist/init/node-app.mjs +3 -3
- package/dist/init/node.mjs +42 -45
- package/dist/init/nuxt.mjs +153 -27
- package/dist/init/stores.mjs +14 -9
- package/dist/init/sveltekit.mjs +4 -2
- package/dist/init/template.mjs +9 -6
- package/dist/init/templates.mjs +63 -47
- package/dist/init/vercel.mjs +37 -37
- package/dist/init/versions.mjs +3 -3
- package/package.json +6 -5
package/dist/init/files.mjs
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { parseJsonc, stringAt, withEntries, withValue } from "./jsonc.mjs";
|
|
2
|
-
import { nodePackages } from "./metadata.mjs";
|
|
2
|
+
import { appPackages, nodePackages } 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
|
|
6
6
|
/** The parts that are strings, one a line: a part that's `false` is left out. */
|
|
7
7
|
const lines = (...parts) => parts.filter(Predicate.isString).join("\n");
|
|
8
|
-
/** An import of `names` from `from`, on one line, or one name a line past the formatter's width. */
|
|
9
|
-
const importLine = (names, from) => {
|
|
10
|
-
const line = `import { ${names.join(", ")} } from '${from}';`;
|
|
11
|
-
return line.length <= 100 ? line : lines("import {", ...names.map((name) => ` ${name},`), `} from '${from}';`);
|
|
12
|
-
};
|
|
13
8
|
/** `names` as a sentence lists them: `a, b and c`. */
|
|
14
9
|
const listed = (names) => names.length < 2 ? names.join("") : `${names.slice(0, -1).join(", ")} and ${names[names.length - 1] ?? ""}`;
|
|
10
|
+
/**
|
|
11
|
+
* The receipt's words for the files `init` wrote, `wrote`: each by its path up to 8, and past that,
|
|
12
|
+
* when some are in folders, the top ones and the rest as the app's pages, with the app, or a count.
|
|
13
|
+
*/
|
|
14
|
+
const wroteOf = (wrote, app) => {
|
|
15
|
+
const top = wrote.filter((path) => !path.includes("/"));
|
|
16
|
+
if (wrote.length === 0) return "no files";
|
|
17
|
+
if (wrote.length <= 8 || top.length === wrote.length) return wrote.join(", ");
|
|
18
|
+
return `${wrote.length} files: ${top.join(", ")} and ${app ? "the app's pages" : `${wrote.length - top.length} more`}`;
|
|
19
|
+
};
|
|
15
20
|
/** `head` and `body` on one line when it fits the formatter's width, as it leaves them, else two. */
|
|
16
21
|
const fitted = (head, body) => head.length + body.length < 100 ? `${head} ${body}` : `${head}\n ${body}`;
|
|
17
22
|
/** The served parts' words, for the files' first lines. */
|
|
@@ -20,10 +25,10 @@ const served = {
|
|
|
20
25
|
api: "with its REST API",
|
|
21
26
|
git: "over Git's protocol only"
|
|
22
27
|
};
|
|
23
|
-
/** A file of lines with `lines` added at its end, on lines of their own
|
|
24
|
-
const appended = (current, lines) => {
|
|
28
|
+
/** A file of lines with `lines` added at its end, on lines of their own, each ending in `end`. */
|
|
29
|
+
const appended = (current, lines, end = "\n") => {
|
|
25
30
|
if (lines.length === 0) return current ?? "";
|
|
26
|
-
return `${current === void 0 || current === "" || current.endsWith(
|
|
31
|
+
return `${current === void 0 || current === "" || current.endsWith(end) ? current ?? "" : `${current}${end}`}${lines.join(end)}${end}`;
|
|
27
32
|
};
|
|
28
33
|
/** A file of lines with each of `wanted` that isn't there added at its end. */
|
|
29
34
|
const withLines = (current, wanted, key = (line) => line) => {
|
|
@@ -61,11 +66,113 @@ const withDependencies = (current, wanted) => {
|
|
|
61
66
|
* spec `init` wrote from the other source moves to this run's; any other spec is the person's.
|
|
62
67
|
*/
|
|
63
68
|
const withCli = (current, vendor) => {
|
|
69
|
+
const overridden = withOverrides(current, vendor);
|
|
64
70
|
const path = ["devDependencies", "ref0-git"];
|
|
65
|
-
const held = stringAt(parseJsonc(
|
|
71
|
+
const held = stringAt(parseJsonc(overridden), path);
|
|
66
72
|
const spec = specOf("ref0-git", vendor);
|
|
67
|
-
if (held !== void 0 && held !== spec && initWrote("ref0-git", held)) return withValue(
|
|
68
|
-
return vendor === void 0 || held !== void 0 ?
|
|
73
|
+
if (held !== void 0 && held !== spec && initWrote("ref0-git", held)) return withValue(overridden, path, spec);
|
|
74
|
+
return vendor === void 0 || held !== void 0 ? overridden : withEntries(overridden, ["devDependencies"], { "ref0-git": spec });
|
|
75
|
+
};
|
|
76
|
+
/** Git's packages, which `--from-checkout` packs and one another's manifests name at a version. */
|
|
77
|
+
const gitPackages = appPackages.map((each) => `@ref0/${each}`);
|
|
78
|
+
/**
|
|
79
|
+
* `package.json`'s `overrides`, npm's, so each of Git's packages that another's manifest names, as
|
|
80
|
+
* `ref0-git`'s names `@ref0/git`, is the checkout's, not npm's: `vendor/`'s tarball, or `$` and its
|
|
81
|
+
* name for one the manifest names itself, since npm takes only that dependency's own spec for it,
|
|
82
|
+
* and a person's own spec there stays theirs. One `init` wrote moves to this run's, a release's
|
|
83
|
+
* too; any other is the person's, and stays.
|
|
84
|
+
*/
|
|
85
|
+
const withOverrides = (current, vendor) => {
|
|
86
|
+
const manifest = parseJsonc(current);
|
|
87
|
+
const direct = (each) => stringAt(manifest, ["dependencies", each]) !== void 0 || stringAt(manifest, ["devDependencies", each]) !== void 0;
|
|
88
|
+
const wanted = (each) => direct(each) ? `$${each}` : specOf(each, vendor);
|
|
89
|
+
const moved = gitPackages.reduce((text, each) => {
|
|
90
|
+
const path = ["overrides", each];
|
|
91
|
+
const held = stringAt(parseJsonc(text), path);
|
|
92
|
+
const ours = held === `$${each}` || initWrote(each, held);
|
|
93
|
+
return held !== void 0 && held !== wanted(each) && ours ? withValue(text, path, wanted(each)) : text;
|
|
94
|
+
}, current);
|
|
95
|
+
return vendor === void 0 ? moved : withEntries(moved, ["overrides"], Object.fromEntries(gitPackages.map((each) => [each, wanted(each)])));
|
|
96
|
+
};
|
|
97
|
+
/** A key or a value of `pnpm-workspace.yaml`, in single quotes, so `@` and `:` read as text. */
|
|
98
|
+
const quoted = (text) => `'${text.replaceAll("'", "''")}'`;
|
|
99
|
+
/** `overrides:` at a line's start, its key quoted or not. */
|
|
100
|
+
const overridesKey = /^(['"]?)overrides\1\s*:/;
|
|
101
|
+
/**
|
|
102
|
+
* How `pnpm-workspace.yaml`'s lines write `overrides`: `none`, a `block` of entries below it,
|
|
103
|
+
* `empty` as `{}`, or `other`, such as a flow mapping with entries, which `init` leaves to the
|
|
104
|
+
* person. A comment after it is allowed.
|
|
105
|
+
*/
|
|
106
|
+
const pnpmOverridesOf = (all) => {
|
|
107
|
+
const at = all.findIndex((line) => overridesKey.test(line));
|
|
108
|
+
const rest = (all[at] ?? "").replace(overridesKey, "");
|
|
109
|
+
return {
|
|
110
|
+
at,
|
|
111
|
+
kind: at === -1 ? "none" : /^\s*(#.*)?$/.test(rest) ? "block" : /^\s*\{\s*\}\s*(#.*)?$/.test(rest) ? "empty" : "other"
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
/** A file's line end: `\r\n` when it has one, else `\n`. */
|
|
115
|
+
const lineEnd = (text) => text?.includes("\r\n") ? "\r\n" : "\n";
|
|
116
|
+
/** The entry `withPnpmOverrides` writes for one of Git's packages, at `indent`. */
|
|
117
|
+
const pnpmEntry = (each, vendor, indent = " ") => `${indent}${quoted(each)}: ${quoted(specOf(each, vendor))}`;
|
|
118
|
+
/** Each entry `withPnpmOverrides` writes, as a manual step lists them. */
|
|
119
|
+
const pnpmEntries = (vendor) => gitPackages.map((each) => pnpmEntry(each, vendor));
|
|
120
|
+
/** Whether `text` names one of Git's packages at a tarball `init` wrote, however it's written. */
|
|
121
|
+
const tarballIn = (text) => gitPackages.some((each) => {
|
|
122
|
+
const spec = new RegExp(`(['"]?)${each}\\1\\s*:\\s*(['"]?)([^'",}\\s]+)\\2`).exec(text)?.[3];
|
|
123
|
+
return spec !== specOf(each, void 0) && initWrote(each, spec);
|
|
124
|
+
});
|
|
125
|
+
/**
|
|
126
|
+
* The manual step for a `pnpm-workspace.yaml` whose `overrides` `withPnpmOverrides` leaves as it
|
|
127
|
+
* is, as `pnpmOverridesOf` says: Git's entries for a `--from-checkout` run, or the release's for
|
|
128
|
+
* a run without one while an entry still names a tarball. `init` doesn't install before it.
|
|
129
|
+
*/
|
|
130
|
+
const pnpmManual = (current, vendor) => {
|
|
131
|
+
if (!(pnpmOverridesOf((current ?? "").split(lineEnd(current))).kind === "other") || vendor === void 0 && !tarballIn(current ?? "")) return void 0;
|
|
132
|
+
return {
|
|
133
|
+
path: "pnpm-workspace.yaml",
|
|
134
|
+
why: "yours",
|
|
135
|
+
says: vendor === void 0 ? "Set Git's packages in `overrides` to the release before you install" : "Add Git's packages to `overrides` before you install",
|
|
136
|
+
lines: pnpmEntries(vendor)
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* `pnpm-workspace.yaml` with `overrides:` naming each of Git's packages at `vendor/`'s tarball,
|
|
141
|
+
* as `withOverrides` does for npm: pnpm reads overrides only from here, never `package.json`'s. An
|
|
142
|
+
* entry `init` wrote moves to this run's, a release's too, which adds none; any other entry is the
|
|
143
|
+
* person's, and stays, as do the rest and its line ends. `{}` becomes a block, and any other way
|
|
144
|
+
* of writing it that `pnpmOverridesOf` calls `other` stays as it is.
|
|
145
|
+
*/
|
|
146
|
+
const withPnpmOverrides = (current, vendor) => {
|
|
147
|
+
const end = lineEnd(current);
|
|
148
|
+
const all = (current ?? "").split(end);
|
|
149
|
+
const { at, kind } = pnpmOverridesOf(all);
|
|
150
|
+
if (kind === "other" || kind === "none" && vendor === void 0) return current ?? "";
|
|
151
|
+
const next = all.findIndex((line, index) => index > at && /^[^\s#]/.test(line));
|
|
152
|
+
const block = kind === "block" ? all.slice(at + 1, next === -1 ? void 0 : next) : [];
|
|
153
|
+
const keyOf = (line) => /^\s+(['"]?)(.+?)\1:\s/.exec(line)?.[2];
|
|
154
|
+
const valueOf = (line) => /:\s+(['"]?)(.*?)\1\s*$/.exec(line)?.[2];
|
|
155
|
+
const indent = /^\s+/.exec(block.find((line) => keyOf(line) !== void 0) ?? "")?.[0] ?? " ";
|
|
156
|
+
const kept = block.map((line) => {
|
|
157
|
+
const each = keyOf(line);
|
|
158
|
+
return each !== void 0 && gitPackages.includes(each) && initWrote(each, valueOf(line)) ? pnpmEntry(each, vendor, indent) : line;
|
|
159
|
+
});
|
|
160
|
+
const named = new Set(block.map(keyOf));
|
|
161
|
+
const added = gitPackages.filter((each) => vendor !== void 0 && !named.has(each)).map((each) => pnpmEntry(each, vendor, indent));
|
|
162
|
+
if (kind === "none") return appended(current, ["overrides:", ...added], end);
|
|
163
|
+
const last = kept.findLastIndex((line) => /^\s+\S/.test(line)) + 1;
|
|
164
|
+
const merged = [
|
|
165
|
+
...kept.slice(0, last),
|
|
166
|
+
...added,
|
|
167
|
+
...kept.slice(last)
|
|
168
|
+
];
|
|
169
|
+
const header = kind === "empty" ? "overrides:" : all[at] ?? "overrides:";
|
|
170
|
+
return [
|
|
171
|
+
...all.slice(0, at),
|
|
172
|
+
header,
|
|
173
|
+
...merged,
|
|
174
|
+
...all.slice(at + 1 + block.length)
|
|
175
|
+
].join(end);
|
|
69
176
|
};
|
|
70
177
|
/**
|
|
71
178
|
* `package.json` with an `@types/node` older than `typesMajor` moved to the catalog's, where a
|
|
@@ -77,4 +184,4 @@ const withCreatedTypes = (created) => (text) => {
|
|
|
77
184
|
if (created !== true || major >= 22) return text;
|
|
78
185
|
return withValue(text, ["devDependencies", "@types/node"], nodePackages["@types/node"]);
|
|
79
186
|
};
|
|
80
|
-
export { fitted, ignoring,
|
|
187
|
+
export { fitted, ignoring, lines, listed, pnpmEntries, pnpmManual, pnpmOverridesOf, served, withCli, withCreatedTypes, withDependencies, withLines, withPnpmOverrides, wroteOf };
|
package/dist/init/frameworks.mjs
CHANGED
|
@@ -95,6 +95,21 @@ const astroConfigs = [
|
|
|
95
95
|
"astro.config.mts",
|
|
96
96
|
"astro.config.js"
|
|
97
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}`);
|
|
98
113
|
/** Each name a `package.json` depends on, with its version spec. */
|
|
99
114
|
const dependencies = (text) => {
|
|
100
115
|
const tree = text === void 0 ? void 0 : parseJsonc(text);
|
|
@@ -199,6 +214,7 @@ const frameworkOf = (row, spec, folder) => {
|
|
|
199
214
|
if (row.name === "nuxt") return {
|
|
200
215
|
...base,
|
|
201
216
|
serverModule: "server/git.ts",
|
|
217
|
+
config: firstOf(folder, nuxtConfigs),
|
|
202
218
|
nitro: {
|
|
203
219
|
plugin: firstOf(folder, [nuxtJobsPlugin]),
|
|
204
220
|
middleware: firstOf(folder, [nuxtGitMiddleware])
|
package/dist/init/git-module.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { peerPackages } from "./metadata.mjs";
|
|
1
2
|
import { lines, served } from "./files.mjs";
|
|
3
|
+
import { specOf } from "./versions.mjs";
|
|
2
4
|
import { looseLimits } from "@ref0/git";
|
|
3
5
|
// src/init/git-module.ts
|
|
4
6
|
/**
|
|
@@ -9,18 +11,24 @@ import { looseLimits } from "@ref0/git";
|
|
|
9
11
|
const gitPackages = (choices) => [
|
|
10
12
|
"@ref0/git",
|
|
11
13
|
...choices.serve === "github" ? ["@ref0/github"] : [],
|
|
12
|
-
"@ref0/infra"
|
|
14
|
+
"@ref0/infra",
|
|
15
|
+
"@ref0/xdiff-wasm"
|
|
13
16
|
];
|
|
17
|
+
/**
|
|
18
|
+
* Git's packages as `package.json` names them, from the release or `vendor`, and the peers they
|
|
19
|
+
* take at the catalog's version: a project's own `effect` is the one Git's packages run on.
|
|
20
|
+
*/
|
|
21
|
+
const gitDependencies = (choices, vendor) => [...gitPackages(choices).map((each) => [each, specOf(each, vendor)]), ...Object.entries(peerPackages)];
|
|
14
22
|
/** `src/git.ts`'s first lines: what it serves, on `on`, and whose file it is. */
|
|
15
|
-
const header = (choices, on) => lines(`// Git on ${on}, ${served[choices.serve]}${choices.queue === "on" ? ", with a merge queue on `main`" : ""}. Written by`, "// `ref0-git init`, and yours to change: `init` rewrites it only while it reads as written, and", "// `ref0-git doctor` checks it.", choices.serve === "git" && "// Nothing here makes a repo over HTTP: make one from code, as `git.repos.create({
|
|
23
|
+
const header = (choices, on) => lines(`// Git on ${on}, ${served[choices.serve]}${choices.queue === "on" ? ", with a merge queue on `main`" : ""}. Written by`, "// `ref0-git init`, and yours to change: `init` rewrites it only while it reads as written, and", "// `ref0-git doctor` checks it.", choices.serve === "git" && "// Nothing here makes a repo over HTTP: make one from code, as `git.repos.create({ name: 'acme/app' })`.");
|
|
16
24
|
/** The `@ref0/git` import, naming what the choices use. */
|
|
17
25
|
const gitImport = (choices) => {
|
|
18
26
|
const packs = choices.objects === "packs";
|
|
19
27
|
const queue = choices.queue === "on";
|
|
20
|
-
return `import { accept, createGitServer, ${packs ? "" : "loose, "}${queue ? "mergeQueue, " : ""}${packs ? "packs, " : ""}reject } from '@ref0/git';`;
|
|
28
|
+
return `import { accept, createGitServer, ${packs ? "lfs, " : "loose, "}${queue ? "mergeQueue, " : ""}${packs ? "packs, " : ""}reject } from '@ref0/git';`;
|
|
21
29
|
};
|
|
22
|
-
/** Git's imports, from `@ref0/git` to the drop-in
|
|
23
|
-
const gitImports = (choices
|
|
30
|
+
/** Git's imports, from `@ref0/git` to the drop-in. */
|
|
31
|
+
const gitImports = (choices) => lines(gitImport(choices), choices.queue === "on" && "import type { MergeInput, MergePlan } from '@ref0/git';", "import { bearer, tokens } from '@ref0/git/auth';", choices.serve !== "git" && "import { createRestHandler } from '@ref0/git/rest';", choices.serve === "github" && "import { createGitHubHandler } from '@ref0/github';");
|
|
24
32
|
/** Who `ADMIN_TOKEN` signs in as. */
|
|
25
33
|
const adminLines = lines("/** Who `ADMIN_TOKEN` signs in as: it makes repos and tokens, and never pushes. */", "const admin = { id: '_admin' };", "");
|
|
26
34
|
/** How the queue writes an entry onto `main`, when there's a queue. */
|
|
@@ -29,16 +37,23 @@ const mergeLines = (choices) => choices.queue === "on" && lines("/** How the que
|
|
|
29
37
|
const uploads = " // A push past 64 MiB may upload its pack, once the bucket signs parts.\n pushes: { upload: { above: 64 * 1024 * 1024 } },";
|
|
30
38
|
/** What one push may carry into `loose()`, as `@ref0/git` holds it. */
|
|
31
39
|
const looseSays = `up to ${looseLimits.objects.toLocaleString("en-US")} objects and ${looseLimits.bytes / 1024 / 1024} MiB a push`;
|
|
40
|
+
/** `createGitServer`'s `lfs`, beside a bucket: LFS is on only when the host turns it on. */
|
|
41
|
+
const lfsLines = " // Git LFS, its objects in the bucket beside the packs.\n lfs: lfs(),";
|
|
32
42
|
/** `createGitServer`'s `objects` with no bucket: each object a row, and what `loose()` takes. */
|
|
33
43
|
const looseObjects = ` // Each object a row in its push's commit: no bucket, ${looseSays}.\n objects: loose(),`;
|
|
34
44
|
/** `createGitServer`'s `basePath`, when Git's URLs are under one. */
|
|
35
45
|
const basePathLines = (choices) => choices.basePath !== "/" && ` // Git's URLs, Smart HTTP, sign-in and REST, under this path.\n basePath: '${choices.basePath.replace(/\/$/, "")}',`;
|
|
36
46
|
/** `createGitServer`'s events, under `--serve github`. */
|
|
37
47
|
const eventsLines = " // Git's events go to the drop-in, which follows each push: a pull request's head, its queue.\n events: (input) => github.events(input),";
|
|
48
|
+
/**
|
|
49
|
+
* The queue's line: under the drop-in, a pull request's key merges once, so a push to it after its
|
|
50
|
+
* merge isn't queued again before the drop-in sees the merge.
|
|
51
|
+
*/
|
|
52
|
+
const queueLine = (github) => ` queue: mergeQueue({ target: 'refs/heads/main', keys: '${github ? "once" : "reusable"}', merge }),`;
|
|
38
53
|
/** The drop-in's handler, under `--serve github`. */
|
|
39
54
|
const githubHandler = "/** GitHub's REST, GraphQL, webhooks and Event Streams, so `gh` and Octokit work. */\nexport const github = createGitHubHandler(git);\n";
|
|
40
55
|
/** `export const git = createGitServer({ … });`, as chosen. */
|
|
41
|
-
const serverLines = (choices, parts) => lines("export const git = createGitServer({", parts.adapter, choices.objects === "packs" ? " objects: packs()," : looseObjects,
|
|
56
|
+
const serverLines = (choices, parts) => lines("export const git = createGitServer({", parts.adapter, choices.objects === "packs" ? " objects: packs()," : looseObjects, parts.xdiff, " tokens: tokens(),", choices.objects === "packs" && " // Git LFS, its objects in the bucket beside the packs.\n lfs: lfs(),", parts.uploads && " // A push past 64 MiB may upload its pack, once the bucket signs parts.\n pushes: { upload: { above: 64 * 1024 * 1024 } },", basePathLines(choices), ` auth: bearer({ token: ${parts.token}, actor: admin }),`, " authorize: ({ actor, operation }) => {", " if (actor.anonymous === true) return reject({ message: 'Sign in first' });", "", " if (actor.id === admin.id && operation.kind === 'push') {", " return reject({", " message: \"The admin token can't push\",", " hint: 'Make a write token for yourself: npx ref0-git tokens create --help',", " });", " }", "", " return accept();", " },", choices.queue === "on" && queueLine(choices.serve === "github"), choices.serve === "github" && " // Git's events go to the drop-in, which follows each push: a pull request's head, its queue.\n events: (input) => github.events(input),", "});", "");
|
|
42
57
|
/** The drop-in's and the REST's handlers, as served: none for Git's protocol alone. */
|
|
43
58
|
const handlerLines = (choices) => choices.serve !== "git" && lines(choices.serve === "github" && "/** GitHub's REST, GraphQL, webhooks and Event Streams, so `gh` and Octokit work. */\nexport const github = createGitHubHandler(git);\n", "/** Git's REST, whose `route` and `fetch` serve Git's protocol and sign-in too. */\nexport const rest = createRestHandler(git);\n");
|
|
44
59
|
/**
|
|
@@ -46,4 +61,4 @@ const handlerLines = (choices) => choices.serve !== "git" && lines(choices.serve
|
|
|
46
61
|
* under the base path first, then REST and Git's protocol.
|
|
47
62
|
*/
|
|
48
63
|
const serveExport = (choices) => choices.serve === "github" && lines(`/** What \`${choices.basePath.replace(/\/$/, "")}\` serves: the drop-in's links first, then REST and Git's protocol. */`, "export const serve = {", " fetch: async (request: Request) => (await github.route(request)) ?? rest.fetch(request),", "};", "");
|
|
49
|
-
export { adminLines, basePathLines, eventsLines, gitImports, gitPackages, githubHandler, handlerLines, header, looseObjects, looseSays, mergeLines, serveExport, serverLines, uploads };
|
|
64
|
+
export { adminLines, basePathLines, eventsLines, gitDependencies, gitImports, gitPackages, githubHandler, handlerLines, header, lfsLines, looseObjects, looseSays, mergeLines, queueLine, serveExport, serverLines, uploads };
|
package/dist/init/jsonc.mjs
CHANGED
|
@@ -2,11 +2,13 @@ import * as Option from "effect/Option";
|
|
|
2
2
|
import * as Predicate from "effect/Predicate";
|
|
3
3
|
import * as Schema from "effect/Schema";
|
|
4
4
|
// src/init/jsonc.ts
|
|
5
|
-
const decodeString = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.String));
|
|
5
|
+
const decodeString = /* @__PURE__ */ Schema.decodeUnknownOption(Schema.fromJsonString(Schema.String));
|
|
6
6
|
/** A key, or a string value, as JSON writes it, quoted and escaped. */
|
|
7
|
-
const
|
|
7
|
+
const jsonString = /* @__PURE__ */ Schema.encodeSync(Schema.fromJsonString(Schema.String));
|
|
8
|
+
/** A `package.json` as `init` writes it whole: two-space JSON, as npm writes one. */
|
|
9
|
+
const manifestText = /* @__PURE__ */ Schema.encodeSync(Schema.fromJsonString(Schema.Record(Schema.String, Schema.Json), { space: 2 }));
|
|
8
10
|
/** A value with no members, a string, number, boolean or null, as JSON writes it. */
|
|
9
|
-
const jsonLeaf = Schema.encodeSync(Schema.fromJsonString(Schema.Json));
|
|
11
|
+
const jsonLeaf = /* @__PURE__ */ Schema.encodeSync(Schema.fromJsonString(Schema.Json));
|
|
10
12
|
const literal = /-?\d[\d.eE+-]*|true|false|null/y;
|
|
11
13
|
/** `text`'s tree, or `undefined` when it isn't one JSONC value: comments and trailing commas pass. */
|
|
12
14
|
const parseJsonc = (text) => {
|
|
@@ -99,7 +101,7 @@ const itemsAt = (node, path) => {
|
|
|
99
101
|
return found?.kind === "array" ? found.items : [];
|
|
100
102
|
};
|
|
101
103
|
/** A value on one line, as the repo's configs write it: `{ "a": 1 }`, `[1, 2]`. */
|
|
102
|
-
const inline = (value) => Array.isArray(value) ? `[${value.map(inline).join(", ")}]` : Predicate.isObject(value) ? `{ ${Object.entries(value).map(([key, each]) => `${
|
|
104
|
+
const inline = (value) => Array.isArray(value) ? `[${value.map(inline).join(", ")}]` : Predicate.isObject(value) ? `{ ${Object.entries(value).map(([key, each]) => `${jsonString(key)}: ${inline(each)}`).join(", ")} }` : jsonLeaf(value);
|
|
103
105
|
/** The spaces a line starts with, for the line `at` is on. */
|
|
104
106
|
const indentAt = (text, at) => /^[ \t]*/.exec(text.slice(text.lastIndexOf("\n", at - 1) + 1))?.[0] ?? "";
|
|
105
107
|
/**
|
|
@@ -128,11 +130,11 @@ const withEntries = (text, path, wanted) => {
|
|
|
128
130
|
const nested = path.slice(found + 1).reduceRight((inner, key) => ({ [key]: inner }), wanted);
|
|
129
131
|
const parent = nodeAt(tree, path.slice(0, found));
|
|
130
132
|
const key = path[found];
|
|
131
|
-
return parent === void 0 || key === void 0 ? text : insertInto(text, parent, [`${
|
|
133
|
+
return parent === void 0 || key === void 0 ? text : insertInto(text, parent, [`${jsonString(key)}: ${inline(nested)}`]);
|
|
132
134
|
}
|
|
133
135
|
const container = nodeAt(tree, path);
|
|
134
136
|
if (container === void 0) return text;
|
|
135
|
-
const added = Array.isArray(wanted) ? wanted.map(inline) : Object.entries(wanted).filter(([key]) => nodeAt(container, [key]) === void 0).map(([key, value]) => `${
|
|
137
|
+
const added = Array.isArray(wanted) ? wanted.map(inline) : Object.entries(wanted).filter(([key]) => nodeAt(container, [key]) === void 0).map(([key, value]) => `${jsonString(key)}: ${inline(value)}`);
|
|
136
138
|
return insertInto(text, container, added);
|
|
137
139
|
};
|
|
138
140
|
/** `text` with the value at `path` written as `value`, when it's there. */
|
|
@@ -140,4 +142,4 @@ const withValue = (text, path, value) => {
|
|
|
140
142
|
const node = nodeAt(parseJsonc(text), path);
|
|
141
143
|
return node === void 0 ? text : `${text.slice(0, node.start)}${inline(value)}${text.slice(node.end)}`;
|
|
142
144
|
};
|
|
143
|
-
export { inline, insertInto, itemsAt, nodeAt, parseJsonc, stringAt, withEntries, withValue };
|
|
145
|
+
export { inline, insertInto, itemsAt, jsonString, manifestText, nodeAt, parseJsonc, stringAt, withEntries, withValue };
|
package/dist/init/metadata.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// src/init/metadata.ts
|
|
2
2
|
/** The version `ref0-git`, `create-ref0-git` and Git's packages release at, all at once (Q738). */
|
|
3
|
-
const release = "0.
|
|
3
|
+
const release = "0.6.0";
|
|
4
4
|
/** The packages the app depends on, by their folder in a checkout's `packages/`. */
|
|
5
5
|
const appPackages = [
|
|
6
6
|
"infra",
|
|
7
7
|
"git",
|
|
8
|
-
"github"
|
|
8
|
+
"github",
|
|
9
|
+
"xdiff-wasm"
|
|
9
10
|
];
|
|
10
11
|
/** What every platform's project builds and types with. At the root workspace's catalog. */
|
|
11
12
|
const catalog = {
|
|
@@ -40,9 +41,14 @@ const storePackages = {
|
|
|
40
41
|
pg: "8.23.1"
|
|
41
42
|
};
|
|
42
43
|
/**
|
|
44
|
+
* What Git's packages take as peers, which every project installs beside them (Q1086). At the root
|
|
45
|
+
* workspace's catalog.
|
|
46
|
+
*/
|
|
47
|
+
const peerPackages = { effect: "4.1.4" };
|
|
48
|
+
/**
|
|
43
49
|
* What a framework's Node server needs that its create command doesn't write: SvelteKit's
|
|
44
50
|
* adapter-node, in place of `sv create`'s adapter-auto. At the framework fixtures' own catalog,
|
|
45
51
|
* which differs from the root's.
|
|
46
52
|
*/
|
|
47
53
|
const frameworkPackages = { "@sveltejs/adapter-node": "6.0.5" };
|
|
48
|
-
export { appPackages, catalog, frameworkPackages, nodeAppPackages, nodePackages, release, storePackages, vercelPackages };
|
|
54
|
+
export { appPackages, catalog, frameworkPackages, nodeAppPackages, nodePackages, peerPackages, release, storePackages, vercelPackages };
|
package/dist/init/mounts.mjs
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { matcherCall, matcherImport, servedBy } from "./routes.mjs";
|
|
2
2
|
// src/init/mounts.ts
|
|
3
3
|
/**
|
|
4
|
-
* The server module's exports a mount imports: the jobs, and what serves
|
|
5
|
-
* Hono's, whose app imports `serve` from `@hono/node-server`.
|
|
4
|
+
* The server module's exports a mount imports: Git, whose runtime runs the jobs, and what serves
|
|
5
|
+
* Git's URLs, as `served` in Hono's, whose app imports `serve` from `@hono/node-server`.
|
|
6
6
|
*/
|
|
7
|
-
const importsOf = (choices,
|
|
7
|
+
const importsOf = (choices, asServed) => servedBy(choices) === "git" ? "git" : `git, ${servedBy(choices)}${asServed ? " as served" : ""}`;
|
|
8
|
+
/** What Hono's lines mount: Git itself, or what serves its URLs, imported `as served`. */
|
|
9
|
+
const honoServed = (choices) => servedBy(choices) === "git" ? "git" : "served";
|
|
8
10
|
/** Express's middleware, before any body parser, as printed source: the matcher's paths to Git. */
|
|
9
11
|
const expressLine = (choices) => `app.use(toNodeMiddleware(${servedBy(choices)}, (url) => ${matcherCall(choices)}))`;
|
|
10
12
|
/**
|
|
11
|
-
* The imports a mount's lines start with: `@ref0/git/node`'s `names`,
|
|
12
|
-
*
|
|
13
|
+
* The imports a mount's lines start with: `@ref0/git/node`'s `names`, Node's job runner, the
|
|
14
|
+
* matcher, and the module, what serves `as served` where `asServed`.
|
|
13
15
|
*/
|
|
14
|
-
const imports = (choices, names,
|
|
16
|
+
const imports = (choices, names, asServed = false) => [
|
|
15
17
|
`import { ${names} } from '@ref0/git/node';`,
|
|
16
18
|
matcherImport(choices),
|
|
17
|
-
|
|
19
|
+
"import * as Node from '@ref0/infra/node';",
|
|
20
|
+
`import { ${importsOf(choices, asServed)} } from './git.ts';`,
|
|
18
21
|
""
|
|
19
22
|
];
|
|
20
23
|
/** What Hono's lines take from Node and `@hono/node-server`: a server, and the app as a listener. */
|
|
@@ -24,7 +27,7 @@ const honoImports = ["import { createServer } from 'node:http';", "import { getR
|
|
|
24
27
|
* the listener runs once, then raises it again for Node, or the person's own listener, to exit.
|
|
25
28
|
*/
|
|
26
29
|
const startLines = [
|
|
27
|
-
"const stop =
|
|
30
|
+
"const stop = Node.toJobRunner(git.runtime);",
|
|
28
31
|
"",
|
|
29
32
|
"process.once('SIGTERM', () => void stop().finally(() => process.kill(process.pid, 'SIGTERM')));"
|
|
30
33
|
];
|
|
@@ -34,7 +37,7 @@ const mountLines = (server, choices) => {
|
|
|
34
37
|
if (server === "hono") return [
|
|
35
38
|
...startLines,
|
|
36
39
|
"",
|
|
37
|
-
`const mount = toNodeMiddleware(
|
|
40
|
+
`const mount = toNodeMiddleware(${honoServed(choices)}, (url) => ${matcherCall(choices)});`,
|
|
38
41
|
"",
|
|
39
42
|
"const listener = getRequestListener(app.fetch);",
|
|
40
43
|
"",
|
|
@@ -53,7 +56,7 @@ const mountLines = (server, choices) => {
|
|
|
53
56
|
`${expressLine(choices)};`
|
|
54
57
|
];
|
|
55
58
|
return [
|
|
56
|
-
"const stop =
|
|
59
|
+
"const stop = Node.toJobRunner(git.runtime);",
|
|
57
60
|
"",
|
|
58
61
|
"app.addHook('onClose', () => stop());",
|
|
59
62
|
"",
|
package/dist/init/next.mjs
CHANGED
|
@@ -46,11 +46,11 @@ const routeFile = (route, app, module, maxDuration) => {
|
|
|
46
46
|
text: lines(`// ${route.says} Written by \`ref0-git init\`.`, ...loaded, handlerLine(`(await import('${importOf(path, module)}')).${route.calls}.fetch(request);`), "", maxDuration !== void 0 && `export const maxDuration = ${maxDuration};\n`, `export { ${route.methods.map((method) => `git as ${method}`).join(", ")} };`, "")
|
|
47
47
|
};
|
|
48
48
|
};
|
|
49
|
-
/** A job route on Vercel: `jobs
|
|
49
|
+
/** A job route on Vercel: `jobs`, the queue's handler, for the queue's message or the cron's call. */
|
|
50
50
|
const jobFile = (path, method, says, module, maxDuration) => ({
|
|
51
51
|
path,
|
|
52
52
|
kind: "whole",
|
|
53
|
-
text: lines(...says, "// Written by `ref0-git init`.", `export const maxDuration = ${maxDuration};`, "", `export const ${method} = async (request: Request) => {`, ` const { jobs } = await import('${importOf(path, module)}');`, "", " return
|
|
53
|
+
text: lines(...says, "// Written by `ref0-git init`.", `export const maxDuration = ${maxDuration};`, "", `export const ${method} = async (request: Request) => {`, ` const { jobs } = await import('${importOf(path, module)}');`, "", " return jobs(request);", "};", "")
|
|
54
54
|
});
|
|
55
55
|
/** Next.js's route files for `choices`, over `framework`'s server module; on Vercel, at `maxDuration`. */
|
|
56
56
|
const nextRouteFiles = (choices, framework, maxDuration) => gitRoutes(choices).map((route) => routeFile(route, framework.appDir ?? "app", framework.serverModule, maxDuration));
|
package/dist/init/node-app.mjs
CHANGED
|
@@ -40,14 +40,14 @@ const readme = (choices) => lines("# The starter", "", "Git, a GitHub-compatible
|
|
|
40
40
|
/** The migrations `--records` reads: Postgres's own, else SQLite's, which libSQL speaks too. */
|
|
41
41
|
const migrationsOf = (records) => records === "postgres" ? "migrations/postgres/" : "migrations/sql/";
|
|
42
42
|
/** `src/env.ts` on Node: what the app reads from `.env`, each through `need()`. */
|
|
43
|
-
const envModule = lines("// What the app reads from `.env`: `npm start` passes it to Node, and `vite dev` reads it.", needHelper(".env").replace("const need =", "export const need ="), "", "/** The secrets `ref0-git init` made, where the app is served, and whether anyone may sign up. */", "export const env = {", " ADMIN_TOKEN: need('ADMIN_TOKEN'),", " SESSION_SECRET: need('SESSION_SECRET'),", " APP_ORIGIN: need('APP_ORIGIN'),", " SIGN_UP: process.env['SIGN_UP'],", " // The header the proxy in front sets with the caller's address, such as `x-real-ip`: set it", " // only when that proxy overwrites the header. Unset, the caller's address is the socket's.", " CLIENT_IP_HEADER: process.env['CLIENT_IP_HEADER'],", " /** In dev only, at least 15 characters: the password the seed signs Pip and Mo up with. */", " DEMO_PASSWORD: process.env['DEMO_PASSWORD'],", "};", "");
|
|
43
|
+
const envModule = lines("// What the app reads from `.env`: `npm start` passes it to Node, and `vite dev` reads it.", needHelper(".env").replace("const need =", "export const need ="), "", "/** The secrets `ref0-git init` made, where the app is served, and whether anyone may sign up. */", "export const env = {", " ADMIN_TOKEN: need('ADMIN_TOKEN'),", " SESSION_SECRET: need('SESSION_SECRET'),", " APP_ORIGIN: need('APP_ORIGIN'),", " SIGN_UP: process.env['SIGN_UP'],", " // `off` loads a text's remote images from their own origin, not through the image proxy.", " IMAGE_PROXY: process.env['IMAGE_PROXY'],", " // The header the proxy in front sets with the caller's address, such as `x-real-ip`: set it", " // only when that proxy overwrites the header. Unset, the caller's address is the socket's.", " CLIENT_IP_HEADER: process.env['CLIENT_IP_HEADER'],", " /** In dev only, at least 15 characters: the password the seed signs Pip and Mo up with. */", " DEMO_PASSWORD: process.env['DEMO_PASSWORD'],", "};", "");
|
|
44
44
|
/** `server/plugins/jobs.ts`: Git's jobs, started once a process, and stopped when Nitro closes. */
|
|
45
|
-
const jobsPlugin = lines("// Starts Git's jobs once this process, as Nitro loads its plugins, and stops them on close.", "import { definePlugin } from 'nitro';", "", "import {
|
|
45
|
+
const jobsPlugin = lines("// Starts Git's jobs once this process, as Nitro loads its plugins, and stops them on close.", "import { definePlugin } from 'nitro';", "", "import * as Node from '@ref0/infra/node';", "", "import { git } from '../../src/git.ts';", "", "export default definePlugin((nitro) => {", " const stop = Node.toJobRunner(git.runtime);", " nitro.hooks.hook('close', () => stop());", "});", "");
|
|
46
46
|
/** What `npm run migrate` opens, for each records store, and how it runs one file's SQL. */
|
|
47
47
|
const migrateParts = {
|
|
48
48
|
sqlite: lines("import { mkdirSync, readdirSync, readFileSync } from 'node:fs';", "import { DatabaseSync } from 'node:sqlite';", "", "mkdirSync('.data', { recursive: true });", "", "const database = new DatabaseSync('.data/auth.db');", "", "const run = async (sql: string) => {", " database.exec(sql);", "};", "", "/** The file and its record, bound, in one transaction, which a failure rolls back. */", "const apply = async (name: string, sql: string) => {", " database.exec('begin');", "", " try {", " database.exec(sql);", " database.prepare('insert into \"_migrations\" (\"name\") values (?)').run(name);", " database.exec('commit');", " } catch (cause) {", " if (database.isTransaction) database.exec('rollback');", "", " throw cause;", " }", "};", "", "const done = async () => {", " const rows = database.prepare('select \"name\" from \"_migrations\"').all();", "", " return new Set(rows.map((row) => String(row.name)));", "};"),
|
|
49
49
|
postgres: lines("import { readdirSync, readFileSync } from 'node:fs';", "import pg from 'pg';", "", "const client = new pg.Client({ connectionString: process.env['DATABASE_URL'] });", "", "await client.connect();", "", "const run = async (sql: string) => {", " await client.query(sql);", "};", "", "/** The file and its record, bound, in one transaction, which a failure rolls back. */", "const apply = async (name: string, sql: string) => {", " await client.query('begin');", "", " try {", " await client.query(sql);", " await client.query('insert into \"_migrations\" (\"name\") values ($1)', [name]);", " await client.query('commit');", " } catch (cause) {", " await client.query('rollback');", "", " throw cause;", " }", "};", "", "const done = async () => {", " const { rows } = await client.query<{ name: string }>('select \"name\" from \"_migrations\"');", "", " return new Set(rows.map((row) => row.name));", "};"),
|
|
50
|
-
turso: lines("import { createClient } from '@libsql/client';", "import
|
|
50
|
+
turso: lines("import { createClient } from '@libsql/client';", "import * as Turso from '@ref0/infra/turso';", "import { readdirSync, readFileSync } from 'node:fs';", "", "const need = (name: string) => process.env[name] ?? '';", "", "const databases = Turso.platform({", " organization: need('TURSO_ORGANIZATION'),", " group: need('TURSO_GROUP'),", " region: need('TURSO_REGION'),", " apiToken: need('TURSO_API_TOKEN'),", "});", "", "// `git-auth`, made in the group the first time: 409 says it's there already.", "await databases.create('git-auth').catch((error: { status?: number }) => {", " if (error.status !== 409) throw error;", "});", "", "const client = createClient({", " url: databases.url('git-auth'),", " authToken: need('TURSO_GROUP_TOKEN'),", "});", "", "const run = async (sql: string) => {", " await client.executeMultiple(sql);", "};", "", "/** The file and its record, bound, in one transaction, which a failure rolls back. */", "const apply = async (name: string, sql: string) => {", " const transaction = await client.transaction('write');", "", " try {", " await transaction.executeMultiple(sql);", " await transaction.execute({", " sql: 'insert into \"_migrations\" (\"name\") values (?)',", " args: [name],", " });", " await transaction.commit();", " } catch (cause) {", " await transaction.rollback();", "", " throw cause;", " } finally {", " transaction.close();", " }", "};", "", "const done = async () => {", " const { rows } = await client.execute('select \"name\" from \"_migrations\"');", "", " return new Set(rows.map((row) => String(row['name'])));", "};"),
|
|
51
51
|
"durable-objects": ""
|
|
52
52
|
};
|
|
53
53
|
/** How `npm run migrate` closes what it opened, for each records store. */
|