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/cli/sign-in.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { TokenInput, logoutJson } from "./documents.mjs";
|
|
|
2
2
|
import { answered, failure, snakeCase, usageFailure } from "./failure.mjs";
|
|
3
3
|
import { chosenHost, hostFlag, hostName, hostOf, remoteOf } from "./hosts.mjs";
|
|
4
4
|
import { CliModes, answer, cliDocument, commandLine, document, printable, receipt, say, secrets, utcDay } from "./output.mjs";
|
|
5
|
+
import { retryAfterSeconds } from "./retry-after.mjs";
|
|
5
6
|
import { checkedHelpers, removeSignIn, storeSignIn } from "./sign-ins.mjs";
|
|
6
7
|
import * as Effect from "effect/Effect";
|
|
7
8
|
import * as Redacted from "effect/Redacted";
|
|
@@ -10,6 +11,7 @@ import * as Stdio from "effect/Stdio";
|
|
|
10
11
|
import * as FetchHttpClient from "effect/http/FetchHttpClient";
|
|
11
12
|
import * as Command from "effect/cli/Command";
|
|
12
13
|
import * as Schema from "effect/Schema";
|
|
14
|
+
import * as Duration from "effect/Duration";
|
|
13
15
|
import * as DateTime from "effect/DateTime";
|
|
14
16
|
import * as Flag from "effect/cli/Flag";
|
|
15
17
|
import { createRestClient } from "@ref0/git/rest";
|
|
@@ -18,7 +20,7 @@ import * as Clock from "effect/Clock";
|
|
|
18
20
|
import * as Result from "effect/Result";
|
|
19
21
|
import * as HttpClient from "effect/http/HttpClient";
|
|
20
22
|
import * as HttpClientRequest from "effect/http/HttpClientRequest";
|
|
21
|
-
import { deviceGrant, ghClientId, readAccessTokenAnswer, readDeviceCodeAnswer, signInPaths } from "@ref0/git/auth";
|
|
23
|
+
import { deviceGrant, ghClientId, ghWriteScope, readAccessTokenAnswer, readDeviceCodeAnswer, signInPaths } from "@ref0/git/auth";
|
|
22
24
|
// src/cli/sign-in.ts
|
|
23
25
|
/**
|
|
24
26
|
* `login`, `logout` and `whoami`. A token reaches Git's helpers through `git credential approve`
|
|
@@ -27,43 +29,83 @@ import { deviceGrant, ghClientId, readAccessTokenAnswer, readDeviceCodeAnswer, s
|
|
|
27
29
|
*/
|
|
28
30
|
/** How long a sign-in request may take, when the code's expiry doesn't come first. */
|
|
29
31
|
const requestMs = 3e4;
|
|
32
|
+
/** The longest a device code is waited on, whatever `expires_in` the host sends: GitHub's is 900. */
|
|
33
|
+
const codeLifeSeconds = 1800;
|
|
34
|
+
/** The least time between polls, whatever `interval` the host sends or `slow_down` asks for. */
|
|
35
|
+
const pollFloorSeconds = 1;
|
|
36
|
+
/**
|
|
37
|
+
* The most polls in a row the host may leave unanswered, by a 5xx, a 429 or by not being reached,
|
|
38
|
+
* before the sign-in fails: any answer it reads starts the count again.
|
|
39
|
+
*/
|
|
40
|
+
const pollMissesMost = 5;
|
|
41
|
+
/** The status a host sends when it limits how fast it's polled. */
|
|
42
|
+
const tooManyRequests = 429;
|
|
30
43
|
/**
|
|
31
44
|
* A form POST to the host's sign-in, at its origin's root whatever its base path, as GitHub's is,
|
|
32
|
-
* its JSON read by `read`, as `@ref0/git/auth` reads the server's answer, or
|
|
33
|
-
* `within` ms. It follows no redirect, which could send the device code, and
|
|
45
|
+
* with its status and its JSON read by `read`, as `@ref0/git/auth` reads the server's answer, or
|
|
46
|
+
* `undefined`, within `within` ms. It follows no redirect, which could send the device code, and
|
|
47
|
+
* the token, elsewhere.
|
|
34
48
|
*/
|
|
35
|
-
const signInPost = (host, path, fields, read, within = requestMs) => HttpClient.HttpClient.pipe(Effect.flatMap((client) => client.execute(HttpClientRequest.post(`${host.origin}${path}`).pipe(HttpClientRequest.acceptJson, HttpClientRequest.bodyUrlParams(fields)))), Effect.flatMap((response) =>
|
|
49
|
+
const signInPost = (host, path, fields, read, within = requestMs) => HttpClient.HttpClient.pipe(Effect.flatMap((client) => client.execute(HttpClientRequest.post(`${host.origin}${path}`).pipe(HttpClientRequest.acceptJson, HttpClientRequest.bodyUrlParams(fields)))), Effect.flatMap((response) => Effect.map(response.text, (text) => ({
|
|
50
|
+
status: response.status,
|
|
51
|
+
retryAfter: response.headers["retry-after"],
|
|
52
|
+
text
|
|
53
|
+
}))), Effect.timeout(Math.max(within, 1)), Effect.provideService(FetchHttpClient.RequestInit, { redirect: "error" }), Effect.mapError(() => failure("unreachable", `Couldn't reach ${hostName(host)}'s sign-in`, "Check the host, then sign in again")), Effect.map(({ status, retryAfter, text }) => ({
|
|
54
|
+
status,
|
|
55
|
+
retryAfter,
|
|
56
|
+
value: read(text)
|
|
57
|
+
})));
|
|
36
58
|
/** `HH:MM UTC`, when a wait ends. */
|
|
37
59
|
const utcTime = (at) => `${DateTime.formatIso(DateTime.makeUnsafe(at)).slice(11, 16)} UTC`;
|
|
38
|
-
const sleep = (
|
|
60
|
+
const sleep = (ms) => Effect.sleep(Duration.millis(ms));
|
|
39
61
|
/**
|
|
40
|
-
* GitHub's device flow, as `gh auth login` runs it with `gh`'s client ID
|
|
41
|
-
*
|
|
62
|
+
* GitHub's device flow, as `gh auth login` runs it with `gh`'s client ID, asking for
|
|
63
|
+
* `ghWriteScope`, the scope a host grants a push for: the code and link on stderr in every mode,
|
|
64
|
+
* then a poll at the host's interval until the person decides or it expires.
|
|
42
65
|
*/
|
|
43
|
-
const deviceToken = Effect.fnUntraced(function* (host) {
|
|
44
|
-
const started = yield* signInPost(host, signInPaths.deviceCode, {
|
|
66
|
+
const deviceToken = /* @__PURE__ */ Effect.fnUntraced(function* (host) {
|
|
67
|
+
const { value: started } = yield* signInPost(host, signInPaths.deviceCode, {
|
|
68
|
+
client_id: ghClientId,
|
|
69
|
+
scope: ghWriteScope
|
|
70
|
+
}, readDeviceCodeAnswer);
|
|
45
71
|
if (started === void 0) return yield* failure("sign_in_unavailable", `${hostName(host)} doesn't offer sign-in from a device`, "Sign in with a token instead: --with-token");
|
|
46
72
|
const link = URL.parse(started.verification_uri);
|
|
47
73
|
if (/[\s\p{Cc}\p{Cf}]/u.test(started.verification_uri) || link?.origin !== host.origin || link.username !== "" || link.password !== "") return yield* failure("sign_in_elsewhere", `${hostName(host)} sent a sign-in link to another host`, "Check the host, then sign in again");
|
|
48
|
-
const expiresIn = started.expires_in;
|
|
74
|
+
const expiresIn = Math.min(Math.max(started.expires_in, 0), codeLifeSeconds);
|
|
49
75
|
const deviceCode = started.device_code;
|
|
50
|
-
let interval = started.interval ?? 5;
|
|
51
|
-
const until = (yield* Clock.currentTimeMillis) + expiresIn * 1e3;
|
|
76
|
+
let interval = Math.max(started.interval ?? 5, pollFloorSeconds);
|
|
77
|
+
const until = (yield* Clock.currentTimeMillis) + Math.ceil(expiresIn * 1e3);
|
|
52
78
|
yield* say(`Signing in to ${hostName(host)} in your browser. Enter this code there:`, ` ${printable(started.user_code)}`, ` ${printable(started.verification_uri)}`, `Waiting until ${utcTime(until)}.`);
|
|
79
|
+
let misses = 0;
|
|
53
80
|
for (;;) {
|
|
54
|
-
yield*
|
|
81
|
+
const waits = until - (yield* Clock.currentTimeMillis);
|
|
82
|
+
yield* sleep(Math.min(Math.ceil(interval * 1e3), Math.max(waits, 0)));
|
|
55
83
|
const left = until - (yield* Clock.currentTimeMillis);
|
|
56
84
|
if (left <= 0) break;
|
|
57
|
-
const
|
|
85
|
+
const answered = yield* signInPost(host, signInPaths.accessToken, {
|
|
58
86
|
client_id: ghClientId,
|
|
59
87
|
device_code: deviceCode,
|
|
60
88
|
grant_type: deviceGrant
|
|
61
|
-
}, readAccessTokenAnswer, Math.min(left, requestMs)).pipe(Effect.
|
|
89
|
+
}, readAccessTokenAnswer, Math.min(left, requestMs)).pipe(Effect.map(({ status, retryAfter, value }) => {
|
|
90
|
+
if (status === tooManyRequests) interval = Math.max(retryAfterSeconds(retryAfter, codeLifeSeconds) ?? interval + 5, pollFloorSeconds);
|
|
91
|
+
return status >= 500 || status === tooManyRequests ? Result.fail(failure("sign_in_failed", `${hostName(host)}'s sign-in answered ${status}`, "Check the host, then sign in again")) : Result.succeed(value);
|
|
92
|
+
}), Effect.catch((unreached) => Effect.succeed(Result.fail(unreached))));
|
|
93
|
+
if (Result.isFailure(answered)) {
|
|
94
|
+
const now = yield* Clock.currentTimeMillis;
|
|
95
|
+
if (now >= until) continue;
|
|
96
|
+
const missed = answered.failure;
|
|
97
|
+
misses += 1;
|
|
98
|
+
if (misses >= pollMissesMost || now + Math.ceil(interval * 1e3) >= until) return yield* missed;
|
|
99
|
+
yield* say(`${missed.headline}; polling again`);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
misses = 0;
|
|
103
|
+
const polled = answered.success;
|
|
62
104
|
if (polled?.access_token !== void 0) return Redacted.make(polled.access_token);
|
|
63
105
|
const error = polled?.error;
|
|
64
106
|
if (error === "authorization_pending") continue;
|
|
65
107
|
if (error === "slow_down") {
|
|
66
|
-
interval = polled?.interval ?? interval + 5;
|
|
108
|
+
interval = Math.max(polled?.interval ?? interval + 5, pollFloorSeconds);
|
|
67
109
|
continue;
|
|
68
110
|
}
|
|
69
111
|
if (error === "access_denied") return yield* failure("access_denied", `The sign-in to ${hostName(host)} was denied`);
|
|
@@ -72,9 +114,9 @@ const deviceToken = Effect.fnUntraced(function* (host) {
|
|
|
72
114
|
}
|
|
73
115
|
return yield* failure("timeout", `The code expired at ${utcTime(until)} before it was approved`, "Sign in again for a new code");
|
|
74
116
|
});
|
|
75
|
-
const decodeToken = Schema.decodeUnknownResult(TokenInput);
|
|
117
|
+
const decodeToken = /* @__PURE__ */ Schema.decodeUnknownResult(TokenInput);
|
|
76
118
|
/** The token on stdin, as `TokenInput` reads it: never typed at a prompt. */
|
|
77
|
-
const tokenFromStdin = Effect.fnUntraced(function* (host) {
|
|
119
|
+
const tokenFromStdin = /* @__PURE__ */ Effect.fnUntraced(function* (host) {
|
|
78
120
|
if ((yield* CliModes).stdinTerminal) return yield* usageFailure("token_not_piped", "--with-token reads the token from stdin", `Pipe it in, as \`read -rs t; printf '%s\\n' "$t" | ${commandLine([
|
|
79
121
|
"login",
|
|
80
122
|
host,
|
|
@@ -96,8 +138,8 @@ const signInCommands = [
|
|
|
96
138
|
Command.make("login", {
|
|
97
139
|
host: Argument.String("HOST").pipe(Argument.withDescription("The host, as git.acme.dev, git.acme.dev/git where Git is under a path, or http://localhost:5173")),
|
|
98
140
|
withToken: Flag.Boolean("with-token").pipe(Flag.withDescription("Read a token from stdin instead of signing in in the browser"), Flag.withDefault(false)),
|
|
99
|
-
allowPlaintext: Flag.Boolean("allow-plaintext").pipe(Flag.withDescription("Store the token
|
|
100
|
-
}, Effect.fnUntraced(function* ({ host, withToken, allowPlaintext }) {
|
|
141
|
+
allowPlaintext: Flag.Boolean("allow-plaintext").pipe(Flag.withDescription("Store the token with a helper that may keep it as plain text, as Git's store does, or one ref0-git can't tell keeps it encrypted"), Flag.withDefault(false))
|
|
142
|
+
}, /* @__PURE__ */ Effect.fnUntraced(function* ({ host, withToken, allowPlaintext }) {
|
|
101
143
|
const named = yield* hostOf(host);
|
|
102
144
|
const helpers = yield* checkedHelpers(named, allowPlaintext);
|
|
103
145
|
const token = withToken ? yield* tokenFromStdin(hostName(named)) : yield* deviceToken(named);
|
|
@@ -126,8 +168,8 @@ const signInCommands = [
|
|
|
126
168
|
]]
|
|
127
169
|
}
|
|
128
170
|
});
|
|
129
|
-
})).pipe(Command.withDescription("Sign in, and store a token for Git and ref0-git (experimental)")),
|
|
130
|
-
Command.make("logout", { host: Argument.String("HOST").pipe(Argument.withDescription("The host to sign out of, if you are signed in to more than one"), Argument.optional) }, Effect.fnUntraced(function* ({ host }) {
|
|
171
|
+
})).pipe(Command.withDescription("Sign in, and store a token for Git and ref0-git in a Git credential helper, which must be set up (experimental)")),
|
|
172
|
+
Command.make("logout", { host: Argument.String("HOST").pipe(Argument.withDescription("The host to sign out of, if you are signed in to more than one"), Argument.optional) }, /* @__PURE__ */ Effect.fnUntraced(function* ({ host }) {
|
|
131
173
|
const chosen = yield* chosenHost(host, "Name the one to sign out of, as logout's HOST").pipe(Effect.catchIf((failed) => failed.reason === "no_host", () => Effect.succeed(void 0)));
|
|
132
174
|
const mode = yield* CliModes;
|
|
133
175
|
if (chosen === void 0) return yield* mode.json ? cliDocument(logoutJson, {
|
|
@@ -141,7 +183,7 @@ const signInCommands = [
|
|
|
141
183
|
});
|
|
142
184
|
yield* removed ? receipt({ done: `Signed out of ${hostName(chosen)}` }) : say(`Not signed in to ${hostName(chosen)}: nothing to remove`);
|
|
143
185
|
})).pipe(Command.withDescription("Remove the stored token (experimental)")),
|
|
144
|
-
Command.make("whoami", { host: hostFlag }, Effect.fnUntraced(function* ({ host }) {
|
|
186
|
+
Command.make("whoami", { host: hostFlag }, /* @__PURE__ */ Effect.fnUntraced(function* ({ host }) {
|
|
145
187
|
const remote = yield* remoteOf(yield* chosenHost(host));
|
|
146
188
|
const me = yield* answered(remote.host, (signal) => remote.client.me({ signal }));
|
|
147
189
|
if ((yield* CliModes).json) return yield* document(me);
|
package/dist/cli/sign-ins.mjs
CHANGED
|
@@ -40,7 +40,7 @@ const plaintextRefused = (plain) => {
|
|
|
40
40
|
* keep plain text and `allowPlaintext` isn't set, or when Git asks them by repo path, which a
|
|
41
41
|
* host's one sign-in can't answer.
|
|
42
42
|
*/
|
|
43
|
-
const checkedHelpers = Effect.fnUntraced(function* (host, allowPlaintext) {
|
|
43
|
+
const checkedHelpers = /* @__PURE__ */ Effect.fnUntraced(function* (host, allowPlaintext) {
|
|
44
44
|
const { origin } = host;
|
|
45
45
|
const helpers = yield* credentialHelpers(origin);
|
|
46
46
|
if (helpers.length === 0) return yield* failure("no_credential_helper", "Git has no credential helper to keep the token in", `Set one up: \`git config --global credential.helper ${suggestedHelper()}\`, then sign in again`);
|
|
@@ -78,7 +78,7 @@ const eraseCommand = (url, username) => {
|
|
|
78
78
|
* fills never ask at the terminal. Past `earlierSignIns`, one still kept fails as
|
|
79
79
|
* `credential_not_erased`, before anything is stored.
|
|
80
80
|
*/
|
|
81
|
-
const eraseEarlier = Effect.fnUntraced(function* (host, url, helpers) {
|
|
81
|
+
const eraseEarlier = /* @__PURE__ */ Effect.fnUntraced(function* (host, url, helpers) {
|
|
82
82
|
for (let erased = 0; erased < earlierSignIns; erased++) {
|
|
83
83
|
const kept = yield* fillCredential(url);
|
|
84
84
|
if (kept === void 0) return;
|
|
@@ -96,7 +96,7 @@ const recordsOf = (host) => Effect.map(signedInHosts, (hosts) => hosts.filter((o
|
|
|
96
96
|
* line break a host could use to store it for another host, and forgets a host it just recorded when the helpers don't give it
|
|
97
97
|
* back. Once it's kept, the origin's other records go: the token they named is this one now.
|
|
98
98
|
*/
|
|
99
|
-
const storeSignIn = Effect.fnUntraced(function* (host, credential, helpers) {
|
|
99
|
+
const storeSignIn = /* @__PURE__ */ Effect.fnUntraced(function* (host, credential, helpers) {
|
|
100
100
|
const { origin } = host;
|
|
101
101
|
if (breaksField(credential.username) || breaksField(Redacted.value(credential.password))) return yield* unsafeCredential(hostName(host));
|
|
102
102
|
const url = new URL(`${origin}/`);
|
|
@@ -122,7 +122,7 @@ const storeSignIn = Effect.fnUntraced(function* (host, credential, helpers) {
|
|
|
122
122
|
* origin's, then each record of the origin; while a helper still gives one back, it fails and
|
|
123
123
|
* keeps the records.
|
|
124
124
|
*/
|
|
125
|
-
const removeSignIn = Effect.fnUntraced(function* (host) {
|
|
125
|
+
const removeSignIn = /* @__PURE__ */ Effect.fnUntraced(function* (host) {
|
|
126
126
|
const { origin } = host;
|
|
127
127
|
const url = new URL(`${origin}/`);
|
|
128
128
|
const kept = yield* fillCredential(url);
|
package/dist/cli/sqlite.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { node } from "./node.mjs";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
2
3
|
import * as Effect from "effect/Effect";
|
|
3
4
|
import * as Data from "effect/Data";
|
|
4
5
|
import * as Layer from "effect/Layer";
|
|
5
|
-
import * as Context from "effect/Context";
|
|
6
6
|
// src/cli/sqlite.ts
|
|
7
7
|
/** A SQLite file that couldn't be opened or read, as one that isn't a database. */
|
|
8
8
|
var SqliteUnreadable = class extends Data.TaggedError("SqliteUnreadable") {};
|
|
9
9
|
/** The local SQLite `doctor` reads, read-only: Node's own, which has no Effect service (D12). */
|
|
10
|
-
var Sqlite = class extends Context.Service()("ref0-git/cli/Sqlite") {};
|
|
10
|
+
var Sqlite = class extends (/* @__PURE__ */ Context.Service()("ref0-git/cli/Sqlite")) {};
|
|
11
11
|
const migrated = (path) => Effect.try({
|
|
12
12
|
try: () => {
|
|
13
13
|
if (!node.fs.existsSync(path)) return /* @__PURE__ */ new Set();
|
package/dist/cli/tokens.mjs
CHANGED
|
@@ -35,7 +35,7 @@ const create = Command.make("create", {
|
|
|
35
35
|
scope: Flag.Literals("scope", tokenScopes).pipe(Flag.withDescription("What it may do: read, report a check, or write"), Flag.withDefault("read")),
|
|
36
36
|
expires: Flag.String("expires").pipe(Flag.withDescription("How long until it expires, as 12h or 90d"), Flag.withMetavar("DURATION"), Flag.withDefault("30d")),
|
|
37
37
|
showToken: Flag.Boolean("show-token").pipe(Flag.withDescription("Print the token on stdout, the only way to get it"), Flag.withDefault(false))
|
|
38
|
-
}, Effect.fnUntraced(function* (flags) {
|
|
38
|
+
}, /* @__PURE__ */ Effect.fnUntraced(function* (flags) {
|
|
39
39
|
const target = yield* targetOf(flags);
|
|
40
40
|
const lasts = yield* durationOf("expires", flags.expires);
|
|
41
41
|
if (!flags.showToken) {
|
|
@@ -98,7 +98,7 @@ const list = Command.make("list", {
|
|
|
98
98
|
host: hostFlag,
|
|
99
99
|
state: Flag.Literals("state", tokenStates).pipe(Flag.withDescription("Which tokens: active, the default, expired, revoked or all"), Flag.optional),
|
|
100
100
|
...pageFlags
|
|
101
|
-
}, Effect.fnUntraced(function* (flags) {
|
|
101
|
+
}, /* @__PURE__ */ Effect.fnUntraced(function* (flags) {
|
|
102
102
|
const target = yield* targetOf(flags);
|
|
103
103
|
const state = Option.getOrUndefined(flags.state);
|
|
104
104
|
const command = (host) => [
|
|
@@ -129,7 +129,7 @@ const list = Command.make("list", {
|
|
|
129
129
|
const revoke = Command.make("revoke", {
|
|
130
130
|
token: Argument.String("TOKEN").pipe(Argument.withDescription("The token's ID, as tokens list prints it")),
|
|
131
131
|
host: hostFlag
|
|
132
|
-
}, Effect.fnUntraced(function* (flags) {
|
|
132
|
+
}, /* @__PURE__ */ Effect.fnUntraced(function* (flags) {
|
|
133
133
|
const done = yield* called(flags.host, (client, signal) => client.tokens.revoke(flags.token, { signal }));
|
|
134
134
|
yield* changed({}, flags.token, { done: `Revoked token ${printable(flags.token)} on ${done.host}` });
|
|
135
135
|
})).pipe(Command.withDescription("Revoke a token, so it signs nothing in again"));
|
package/dist/cli/vendor.mjs
CHANGED
|
@@ -30,7 +30,7 @@ const freshTag = () => Buffer.from(crypto.getRandomValues(/* @__PURE__ */ new Ui
|
|
|
30
30
|
* but the disk, so no destination is left between its old tarball and its new one. The packed
|
|
31
31
|
* folder is `init`'s to remove, however the run ends.
|
|
32
32
|
*/
|
|
33
|
-
const vendored = Effect.fnUntraced(function* (packed, folder, tag = freshTag()) {
|
|
33
|
+
const vendored = /* @__PURE__ */ Effect.fnUntraced(function* (packed, folder, tag = freshTag()) {
|
|
34
34
|
const fs = yield* FileSystem.FileSystem;
|
|
35
35
|
const path = yield* Path.Path;
|
|
36
36
|
const own = `${folder}/vendor/.ref0-init-${tag}`;
|
package/dist/init/app.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { bucketLine, bucketName, devVars,
|
|
1
|
+
import { bucketLine, bucketName, devVars, looseAdapter, looseInfraImport, mergePackage, secretFiles } from "./cloudflare.mjs";
|
|
2
2
|
import { ignoring, lines, listed, withCli } from "./files.mjs";
|
|
3
3
|
import { bucketLines, firstImports, infraImports, partsOf, storeLines } from "./node.mjs";
|
|
4
4
|
import { specOf } from "./versions.mjs";
|
|
5
5
|
import { looseObjects } from "./git-module.mjs";
|
|
6
|
+
import { jsonString, manifestText } from "./jsonc.mjs";
|
|
6
7
|
import { filled, platforms, templates, unless } from "./template.mjs";
|
|
7
8
|
import { blockOf, catalogOf } from "./workspace.mjs";
|
|
8
9
|
import { appPackages } from "./metadata.mjs";
|
|
@@ -39,23 +40,19 @@ const overridesOf = (workspace, catalog) => Object.fromEntries(blockOf(workspace
|
|
|
39
40
|
const spec = entry[2] ?? "";
|
|
40
41
|
return [[entry[1] ?? "", spec === "catalog:" ? catalog.get(entry[1] ?? "") ?? spec : spec]];
|
|
41
42
|
}));
|
|
42
|
-
const Manifest = Schema.Record(Schema.String, Schema.Json);
|
|
43
|
-
const Specs = Schema.Record(Schema.String, Schema.String);
|
|
44
|
-
const ManifestText = Schema.fromJsonString(Manifest);
|
|
45
|
-
const decodeManifest = Schema.decodeUnknownSync(ManifestText);
|
|
46
|
-
const decodeSpecs = Schema.decodeUnknownSync(Specs);
|
|
47
|
-
const readManifest = Schema.decodeUnknownEffect(ManifestText);
|
|
48
|
-
const readSpecs = Schema.decodeUnknownEffect(Specs);
|
|
49
|
-
/** The app's `package.json` as `init` writes it: two-space JSON, as npm writes one. */
|
|
50
|
-
const encodeManifest = Schema.encodeSync(Schema.fromJsonString(Manifest, { space: 2 }));
|
|
51
|
-
/** A JSON string, quoted and escaped, for a value in JSONC text. */
|
|
52
|
-
const jsonString = Schema.encodeSync(Schema.fromJsonString(Schema.String));
|
|
43
|
+
const Manifest = /* @__PURE__ */ Schema.Record(Schema.String, Schema.Json);
|
|
44
|
+
const Specs = /* @__PURE__ */ Schema.Record(Schema.String, Schema.String);
|
|
45
|
+
const ManifestText = /* @__PURE__ */ Schema.fromJsonString(Manifest);
|
|
46
|
+
const decodeManifest = /* @__PURE__ */ Schema.decodeUnknownSync(ManifestText);
|
|
47
|
+
const decodeSpecs = /* @__PURE__ */ Schema.decodeUnknownSync(Specs);
|
|
48
|
+
const readManifest = /* @__PURE__ */ Schema.decodeUnknownEffect(ManifestText);
|
|
49
|
+
const readSpecs = /* @__PURE__ */ Schema.decodeUnknownEffect(Specs);
|
|
53
50
|
/**
|
|
54
51
|
* The app's `package.json` from a checkout, read as `appManifest` reads it: JSON, with its scripts
|
|
55
52
|
* and both dependency lists, where it has them, strings by name. The source's loading reads it with
|
|
56
53
|
* this first, so `appManifest`'s own decodes read only what passed.
|
|
57
54
|
*/
|
|
58
|
-
const checkedManifest = Effect.fnUntraced(function* (text) {
|
|
55
|
+
const checkedManifest = /* @__PURE__ */ Effect.fnUntraced(function* (text) {
|
|
59
56
|
const held = yield* readManifest(text);
|
|
60
57
|
for (const key of [
|
|
61
58
|
"scripts",
|
|
@@ -87,14 +84,16 @@ const appManifest = (source, name, vendor, platform = {}) => {
|
|
|
87
84
|
...nested
|
|
88
85
|
}
|
|
89
86
|
};
|
|
90
|
-
return withCli(`${
|
|
87
|
+
return withCli(`${manifestText(made)}\n`, vendor);
|
|
91
88
|
};
|
|
92
89
|
/** The `@ref0/git` import of the app's `src/git.ts`, naming what the store and the queue use. */
|
|
93
90
|
const gitServerImport = (choices) => `import { ${[
|
|
94
91
|
"createGitServer",
|
|
92
|
+
choices.objects === "packs" && "lfs",
|
|
95
93
|
choices.objects !== "packs" && "loose",
|
|
96
94
|
choices.queue === "on" && "mergeQueue",
|
|
97
|
-
choices.objects === "packs" && "packs"
|
|
95
|
+
choices.objects === "packs" && "packs",
|
|
96
|
+
"RepoRecords"
|
|
98
97
|
].filter(Predicate.isString).join(", ")} } from '@ref0/git';`;
|
|
99
98
|
/** The slots both platforms' `src/git.ts` fill alike: the queue's, and the store's past the head. */
|
|
100
99
|
const bodySlots = (choices, uploads) => {
|
|
@@ -103,6 +102,7 @@ const bodySlots = (choices, uploads) => {
|
|
|
103
102
|
queueMerge: unless(queue, ""),
|
|
104
103
|
queue: unless(queue, ""),
|
|
105
104
|
objects: unless(choices.objects === "packs", looseObjects),
|
|
105
|
+
lfs: unless(choices.objects === "packs", ""),
|
|
106
106
|
uploads: unless(uploads, "")
|
|
107
107
|
};
|
|
108
108
|
};
|
|
@@ -115,8 +115,7 @@ const cloudflareGit = (choices) => {
|
|
|
115
115
|
infraImport: unless(packs, looseInfraImport),
|
|
116
116
|
safety: unless(packs, "binds the objects, and D1"),
|
|
117
117
|
bucket: unless(packs, ""),
|
|
118
|
-
|
|
119
|
-
adapterBucket: unless(packs, looseAdapterEnd),
|
|
118
|
+
adapter: unless(packs, looseAdapter),
|
|
120
119
|
...bodySlots(choices, packs)
|
|
121
120
|
});
|
|
122
121
|
};
|
|
@@ -134,17 +133,17 @@ const dialectOn = {
|
|
|
134
133
|
sqlite: false,
|
|
135
134
|
"durable-objects": false
|
|
136
135
|
};
|
|
137
|
-
/** The app's `src/git.ts` on Node: its imports, the store, the bucket
|
|
136
|
+
/** The app's `src/git.ts` on Node: its imports, the store, the bucket and Better Auth's database. */
|
|
138
137
|
const nodeHead = (choices) => {
|
|
139
|
-
const packs = choices.objects === "packs";
|
|
140
138
|
const queue = choices.queue === "on";
|
|
141
139
|
const dialect = dialectOn[choices.records];
|
|
142
|
-
return lines(firstImports(choices, false), dialect !== false && `${dialect}\n`, gitServerImport(choices), queue && "import type { MergeInput, MergePlan } from '@ref0/git';", "import { tokens } from '@ref0/git/auth';", "import {
|
|
140
|
+
return lines(firstImports(choices, false), dialect !== false && `${dialect}\n`, gitServerImport(choices), queue && "import type { MergeInput, MergePlan } from '@ref0/git';", "import { tokens } from '@ref0/git/auth';", "import { createRestHandler } from '@ref0/git/rest';", "import { createGitHubHandler } from '@ref0/github';", infraImports(choices), "import { xdiff } from '@ref0/xdiff-wasm/node';", "", `import { env${partsOf(choices).length > 0 ? ", need" : ""} } from './env.ts';`, "import { admin, approvalPage, hostPolicy, hostRules, type Identify } from './policy.ts';", "import { privateReposOf } from './private-repos.ts';", "import { readyAdapter, readyAuth, starterAuth } from './signin/auth.ts';", "import { avatars } from './signin/avatars.ts';", "import { clientIpHeader } from './signin/client-ip.ts';", "import { appAuth } from './signin/host-session.ts';", "import { orgsOver } from './signin/orgs.ts';", "import { sealKey } from './signin/seal.ts';", "", "/** What the app reads from `.env`, as the server's entry reads it here. */", "export { env };", "", storeLines(choices), bucketLines(choices), "", peopleOn[choices.records], "");
|
|
143
141
|
};
|
|
144
142
|
/** The app's `src/git.ts` on Node: `apps/github`'s own past its head, Node's head and parts in Cloudflare's place. */
|
|
145
143
|
const nodeGit = (choices) => filled(templates.appGitNode, {
|
|
146
144
|
head: `${nodeHead(choices)}\n`,
|
|
147
|
-
|
|
145
|
+
adapter: ` adapter: ${choices.objects === "packs" ? "[store, bucket]" : "store"},`,
|
|
146
|
+
xdiff: " xdiff: await xdiff(),",
|
|
148
147
|
database: " database: people,",
|
|
149
148
|
ipHeader: lines(" // The server's own, which `src/server.ts` sets from the caller's address on every request.", " ipHeader: clientIpHeader,", ""),
|
|
150
149
|
classes: "",
|
package/dist/init/choices.mjs
CHANGED
|
@@ -373,7 +373,7 @@ const asChoices = (answers) => answers;
|
|
|
373
373
|
* choice open, and the recommended answer stands in for it, so the later choices' offers still
|
|
374
374
|
* follow. A refused flag fails at once.
|
|
375
375
|
*/
|
|
376
|
-
const settle = Effect.fnUntraced(function* (given, detected, project, yes, ask, creating, framework) {
|
|
376
|
+
const settle = /* @__PURE__ */ Effect.fnUntraced(function* (given, detected, project, yes, ask, creating, framework) {
|
|
377
377
|
const chosen = {};
|
|
378
378
|
const settled = {};
|
|
379
379
|
const open = [];
|
package/dist/init/cloudflare.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { fitted, ignoring, lines, withCli, withDependencies, withLines } from "./files.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { itemsAt, parseJsonc, stringAt, withEntries, withValue } from "./jsonc.mjs";
|
|
2
|
+
import { basePathLines, eventsLines, gitDependencies, gitImports, gitPackages, githubHandler, header, looseObjects, queueLine } from "./git-module.mjs";
|
|
3
|
+
import { itemsAt, jsonString, manifestText, parseJsonc, stringAt, withEntries, withValue } from "./jsonc.mjs";
|
|
5
4
|
import { filled, templates, unless } from "./template.mjs";
|
|
6
|
-
import {
|
|
5
|
+
import { catalog } from "./metadata.mjs";
|
|
7
6
|
import * as Redacted from "effect/Redacted";
|
|
8
7
|
// src/init/cloudflare.ts
|
|
9
8
|
/**
|
|
@@ -40,32 +39,29 @@ const gitClasses = [{
|
|
|
40
39
|
class_name: "Jobs"
|
|
41
40
|
}];
|
|
42
41
|
/** The infra import of a `src/git.ts` with no bucket. */
|
|
43
|
-
const looseInfraImport = "import {
|
|
44
|
-
/** The
|
|
45
|
-
const
|
|
42
|
+
const looseInfraImport = "import { layer, toJobObject, toRecordsObject } from '@ref0/infra/cloudflare';";
|
|
43
|
+
/** The adapter of a `src/git.ts` with no bucket: the records and jobs' Layer alone. */
|
|
44
|
+
const looseAdapter = " adapter: layer({ records: env.RECORDS, jobs: env.JOBS }),";
|
|
46
45
|
/** `src/git.ts`: `examples/git-worker`'s own, with what it serves, the store and the queue as chosen. */
|
|
47
46
|
const gitModule = (choices, envFile) => {
|
|
48
47
|
const packs = choices.objects === "packs";
|
|
49
48
|
const queue = choices.queue === "on";
|
|
50
49
|
const github = choices.serve === "github";
|
|
51
|
-
const xdiff = {
|
|
52
|
-
line: "import xdiff from '@ref0/git/xdiff.wasm';",
|
|
53
|
-
last: true
|
|
54
|
-
};
|
|
55
50
|
const basePath = basePathLines(choices);
|
|
56
51
|
return filled(templates.workerGit, {
|
|
57
52
|
header: `${header(choices, "Cloudflare")}\n`,
|
|
58
|
-
gitImports: `${gitImports(choices
|
|
53
|
+
gitImports: `${gitImports(choices)}\n`,
|
|
59
54
|
infraImport: unless(packs, looseInfraImport),
|
|
60
55
|
envFile: `'${envFile}'`,
|
|
61
56
|
safety: unless(packs, "binds the objects"),
|
|
62
57
|
bucket: unless(packs, ""),
|
|
63
|
-
|
|
58
|
+
adapter: unless(packs, looseAdapter),
|
|
64
59
|
merge: unless(queue, ""),
|
|
65
60
|
objects: unless(packs, looseObjects),
|
|
61
|
+
lfs: unless(packs, ""),
|
|
66
62
|
uploads: unless(packs, ""),
|
|
67
63
|
basePath: basePath === false ? void 0 : `${basePath}\n`,
|
|
68
|
-
queue:
|
|
64
|
+
queue: queue ? `${queueLine(github)}\n` : "",
|
|
69
65
|
events: github ? `${eventsLines}\n` : void 0,
|
|
70
66
|
github: github ? `${githubHandler}\n` : void 0,
|
|
71
67
|
rest: choices.serve === "git" ? "" : void 0
|
|
@@ -108,7 +104,7 @@ const wranglerConfig = (choices, name) => {
|
|
|
108
104
|
return filled(templates.workerWrangler, {
|
|
109
105
|
about: unless(packs, "Durable Object classes"),
|
|
110
106
|
signing: unless(packs, ""),
|
|
111
|
-
name: ` "name": ${
|
|
107
|
+
name: ` "name": ${jsonString(name)},`,
|
|
112
108
|
bucket: bucketLine(choices, name),
|
|
113
109
|
vars: packs ? ` "vars": { "PACKS_BUCKET": "${bucketName(name)}" },\n` : ""
|
|
114
110
|
});
|
|
@@ -173,8 +169,8 @@ const tools = {
|
|
|
173
169
|
};
|
|
174
170
|
/** `package.json` with Git's packages added where it doesn't name them. */
|
|
175
171
|
const mergePackage = (choices, name, own, vendor) => (current) => {
|
|
176
|
-
const git = Object.fromEntries(
|
|
177
|
-
if (current === void 0) return withCli(`${
|
|
172
|
+
const git = Object.fromEntries(gitDependencies(choices, vendor));
|
|
173
|
+
if (current === void 0) return withCli(`${manifestText({
|
|
178
174
|
name,
|
|
179
175
|
private: true,
|
|
180
176
|
type: "module",
|
|
@@ -184,7 +180,7 @@ const mergePackage = (choices, name, own, vendor) => (current) => {
|
|
|
184
180
|
},
|
|
185
181
|
dependencies: git,
|
|
186
182
|
devDependencies: tools
|
|
187
|
-
}
|
|
183
|
+
})}\n`, vendor);
|
|
188
184
|
const added = withCli(withDependencies(current, git), vendor);
|
|
189
185
|
return own ? withEntries(added, ["devDependencies"], tools) : added;
|
|
190
186
|
};
|
|
@@ -321,4 +317,4 @@ const cloudflareOutput = (choices, project, secret, vendor) => {
|
|
|
321
317
|
next: "Check it, then deploy it"
|
|
322
318
|
};
|
|
323
319
|
};
|
|
324
|
-
export { bucketLine, bucketName, cloudflareOutput, configParts, devVars, gitClasses, gitModule, gitSecrets,
|
|
320
|
+
export { bucketLine, bucketName, cloudflareOutput, configParts, devVars, gitClasses, gitModule, gitSecrets, looseAdapter, looseInfraImport, mergePackage, mergeWrangler, secretFiles };
|
package/dist/init/create.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { newFramework } from "./frameworks.mjs";
|
|
|
2
2
|
import { nodeAt, parseJsonc } from "./jsonc.mjs";
|
|
3
3
|
import { nextConfigAnchor } from "./next.mjs";
|
|
4
4
|
import { shellWord } from "./shell.mjs";
|
|
5
|
+
import { nuxtConfigAnchor } from "./nuxt.mjs";
|
|
5
6
|
import { svelteAdapterAnchor } from "./sveltekit.mjs";
|
|
6
7
|
import * as Schema from "effect/Schema";
|
|
7
8
|
// src/init/create.ts
|
|
@@ -26,10 +27,10 @@ const createPlatforms = {
|
|
|
26
27
|
const anchors = {
|
|
27
28
|
next: [["next.config.ts", nextConfigAnchor]],
|
|
28
29
|
sveltekit: [["vite.config.ts", `import adapter from ${svelteAdapterAnchor};\n`]],
|
|
29
|
-
nuxt: []
|
|
30
|
+
nuxt: [["nuxt.config.ts", nuxtConfigAnchor]]
|
|
30
31
|
};
|
|
31
32
|
/** The `package.json` a create command writes, as `creatorFolder` stands it in: two-space JSON. */
|
|
32
|
-
const creatorManifest = Schema.encodeSync(Schema.fromJsonString(Schema.Struct({
|
|
33
|
+
const creatorManifest = /* @__PURE__ */ Schema.encodeSync(Schema.fromJsonString(Schema.Struct({
|
|
33
34
|
name: Schema.String,
|
|
34
35
|
dependencies: Schema.Record(Schema.String, Schema.String)
|
|
35
36
|
}), { space: 2 }));
|
package/dist/init/detect.mjs
CHANGED
|
@@ -48,10 +48,10 @@ const dependencies = (text) => {
|
|
|
48
48
|
};
|
|
49
49
|
/** The choices a `src/git.ts` that `init` wrote holds, from its imports and calls. */
|
|
50
50
|
const readBack = (text) => {
|
|
51
|
-
const
|
|
52
|
-
const imports = (
|
|
53
|
-
const vercel = imports("
|
|
54
|
-
const onNode = !vercel && (imports("
|
|
51
|
+
const entries = new Set([...text.matchAll(/^import (?:\* as \w+|\{[^}]*\}) from '@ref0\/infra\/([a-z0-9]+)';$/gm)].map((found) => found[1]));
|
|
52
|
+
const imports = (entry) => entries.has(entry);
|
|
53
|
+
const vercel = imports("vercel");
|
|
54
|
+
const onNode = !vercel && (imports("node") || imports("sqlite"));
|
|
55
55
|
if (!vercel && !onNode && !imports("cloudflare")) return void 0;
|
|
56
56
|
const loose = /\bloose\(\)/.test(text);
|
|
57
57
|
const shared = {
|