ref0-git 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +17 -11
- 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 +28 -10
- package/app/apps/github/src/palette/rows.tsx +93 -40
- package/app/apps/github/src/palette/server.ts +10 -7
- package/app/apps/github/src/palette/targets.ts +1 -0
- package/app/apps/github/src/policy.ts +137 -61
- package/app/apps/github/src/private-repos.ts +5 -5
- 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 -120
- 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 +9 -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 +26 -5
- package/dist/cli/helpers.mjs +168 -35
- 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 +70 -13
- 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 +18 -20
- package/dist/init/choices.mjs +1 -1
- package/dist/init/cloudflare.mjs +15 -19
- package/dist/init/create.mjs +4 -3
- package/dist/init/detect.mjs +4 -4
- package/dist/init/files.mjs +121 -9
- 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 +3 -5
- package/dist/init/node-app.mjs +3 -3
- package/dist/init/node.mjs +41 -42
- 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 +64 -48
- package/dist/init/vercel.mjs +37 -36
- package/dist/init/versions.mjs +3 -3
- package/package.json +6 -5
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import { init } from '@pierre/words';
|
|
1
2
|
import { createHtmlRenderer, escapeHtml, type MermaidPlugin } from '@pierre/words/html';
|
|
2
3
|
import * as pele from 'pele';
|
|
4
|
+
import wordsModule from 'virtual:words-module';
|
|
5
|
+
|
|
6
|
+
import { budgetOf, htmlAsWritten, htmlMost, htmlWithinLimits } from '@ref0/github/markdown';
|
|
3
7
|
|
|
4
8
|
import {
|
|
5
9
|
fragmentTargets,
|
|
10
|
+
hasFound,
|
|
11
|
+
linkPrefixOf,
|
|
6
12
|
linkerOf,
|
|
7
13
|
recorder,
|
|
8
14
|
type Found,
|
|
@@ -58,46 +64,117 @@ const fragments = (html: string) => {
|
|
|
58
64
|
);
|
|
59
65
|
};
|
|
60
66
|
|
|
67
|
+
/** What words starts each id the text gives with, so none meets the app's own. */
|
|
68
|
+
const idPrefix = 'user-content-';
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Words' renderer, from its module under the drop-in's most on its memory (#1098). A call that
|
|
72
|
+
* would grow that memory past the most traps, and the next text starts on a fresh renderer, whose
|
|
73
|
+
* memory is back to its first size: words' memory never shrinks, so the trapped one is let go.
|
|
74
|
+
* Rendering is synchronous, hooks and all, so no other text is mid-render when it's swapped.
|
|
75
|
+
*/
|
|
76
|
+
let words = init(wordsModule);
|
|
77
|
+
|
|
78
|
+
/** The bytes words' renderer holds now, which a trap's fresh renderer returns to its first size. */
|
|
79
|
+
export const wordsMemory = () => words.memory.buffer.byteLength;
|
|
80
|
+
|
|
61
81
|
/**
|
|
62
82
|
* Words, with `patches`: every patch, for the app, or all but one, for a test showing words still
|
|
63
|
-
* needs it. `draw` off leaves diagrams as code, for a pass that only reads references.
|
|
83
|
+
* needs it. `draw` off leaves diagrams as code, for a pass that only reads references. It renders
|
|
84
|
+
* a whole text in one call, with a renderer of its own, since a renderer renders a later text as
|
|
85
|
+
* an edit of its last, and a Mermaid plugin of its own, so no two of a text's diagrams' ids meet.
|
|
64
86
|
*/
|
|
87
|
+
const wordsFor = (context: MarkdownContext, patches: readonly Patch[], draw: boolean) => {
|
|
88
|
+
const { allowedHtml, components, urlTransform, after } = compose(context, patches);
|
|
89
|
+
|
|
90
|
+
return (text: string) => {
|
|
91
|
+
const renderer = createHtmlRenderer({
|
|
92
|
+
math: true,
|
|
93
|
+
allowedHtml,
|
|
94
|
+
components,
|
|
95
|
+
plugins: draw ? { mermaid: mermaid() } : {},
|
|
96
|
+
controls: false,
|
|
97
|
+
lineNumbers: false,
|
|
98
|
+
urlTransform,
|
|
99
|
+
idPrefix,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
return after(renderer.render(text, false).html);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (error instanceof WebAssembly.RuntimeError) words = init(wordsModule);
|
|
106
|
+
|
|
107
|
+
throw error;
|
|
108
|
+
} finally {
|
|
109
|
+
renderer.dispose();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** `text` through words in one call, with no bound: for a test of what words writes. */
|
|
65
115
|
export const rendered = (
|
|
66
116
|
text: string,
|
|
67
117
|
context: MarkdownContext,
|
|
68
118
|
patches: readonly Patch[],
|
|
69
119
|
draw: boolean,
|
|
70
|
-
) =>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
120
|
+
) => wordsFor(context, patches, draw)(text);
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* `text` through words within the drop-in's limits on its HTML (#1098): at most 16 characters a
|
|
124
|
+
* character, and `most`, in one call under words' most on its memory, or as written past them.
|
|
125
|
+
*/
|
|
126
|
+
const bounded = (
|
|
127
|
+
text: string,
|
|
128
|
+
context: MarkdownContext,
|
|
129
|
+
patches: readonly Patch[],
|
|
130
|
+
draw: boolean,
|
|
131
|
+
most = htmlMost,
|
|
132
|
+
) =>
|
|
133
|
+
htmlWithinLimits(text, wordsFor(context, patches, draw), {
|
|
134
|
+
most,
|
|
135
|
+
linkPrefix: linkPrefixOf(context),
|
|
81
136
|
});
|
|
82
137
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
renderer.dispose();
|
|
87
|
-
}
|
|
88
|
-
};
|
|
138
|
+
/** The line above a text past its limits, which shows below it as written. */
|
|
139
|
+
export const tooLarge =
|
|
140
|
+
'<p class="markdown-too-large">This text is too large to render, so it\'s shown as written.</p>\n';
|
|
89
141
|
|
|
90
142
|
/**
|
|
91
143
|
* `text` as sanitized HTML, the same in a preview and on the server: its references linked only
|
|
92
|
-
* where `found` says they exist.
|
|
144
|
+
* where `found` says they exist, and, past its limits, as written under a line saying so. `most`
|
|
145
|
+
* is the most HTML it may write, such as what's left of its page's.
|
|
93
146
|
*/
|
|
94
|
-
export const renderMarkdown = (
|
|
95
|
-
|
|
147
|
+
export const renderMarkdown = (
|
|
148
|
+
text: string,
|
|
149
|
+
context: MarkdownContext,
|
|
150
|
+
found: Found,
|
|
151
|
+
most = htmlMost,
|
|
152
|
+
): string => {
|
|
153
|
+
const all = patchesFor(context, linkerOf(found));
|
|
154
|
+
const patches = hasFound(found)
|
|
155
|
+
? Object.values(all)
|
|
156
|
+
: Object.entries(all).flatMap(([name, patch]) => (name === 'references' ? [] : [patch]));
|
|
157
|
+
const { html, rendered } = bounded(text, context, patches, true, most);
|
|
158
|
+
if (!rendered) return `${tooLarge}${html}`;
|
|
159
|
+
|
|
160
|
+
// Fragment links resolve after the bound, and may lengthen it: the text's budget holds them too.
|
|
161
|
+
const shown = fragments(html);
|
|
162
|
+
|
|
163
|
+
return shown.length <= budgetOf(text, most) ? shown : `${tooLarge}${htmlAsWritten(text)}`;
|
|
164
|
+
};
|
|
96
165
|
|
|
97
|
-
/**
|
|
166
|
+
/**
|
|
167
|
+
* The issues, pulls, people and commits `text` names in `context`, for a lookup before rendering:
|
|
168
|
+
* none for a text past the bound, which shows as written.
|
|
169
|
+
*/
|
|
98
170
|
export const referencesIn = (text: string, context: MarkdownContext): References => {
|
|
99
171
|
const { linker, references } = recorder();
|
|
100
|
-
rendered
|
|
172
|
+
const { rendered: whole } = bounded(
|
|
173
|
+
text,
|
|
174
|
+
context,
|
|
175
|
+
Object.values(patchesFor(context, linker)),
|
|
176
|
+
false,
|
|
177
|
+
);
|
|
101
178
|
|
|
102
|
-
return references();
|
|
179
|
+
return whole ? references() : { issues: [], users: [], commits: [] };
|
|
103
180
|
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as Schema from 'effect/Schema';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A repo's name, as `owner/name` writes it: GitHub's names, one slash between them, neither `.` nor
|
|
5
|
+
* `..`, so the call it names can't climb out of the repo's route.
|
|
6
|
+
*/
|
|
7
|
+
const RepoName = Schema.String.check(
|
|
8
|
+
Schema.isPattern(/^(?!\.\.?\/)[\w.-]{1,100}\/(?!\.\.?$)[\w.-]{1,100}$/),
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A file's path in its repo: segments joined by `/`, none empty, `.` or `..`, a line break in a
|
|
13
|
+
* segment too, as `s` lets `.` read one.
|
|
14
|
+
*/
|
|
15
|
+
const FilePath = Schema.String.check(
|
|
16
|
+
Schema.isMaxLength(4096),
|
|
17
|
+
Schema.isPattern(/^(?!(?:.*\/)?\.\.?(?:\/|$))[^/]+(?:\/[^/]+)*$/s),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
/** An issue's or a pull request's number, or a comment's, a review's or a release's ID. */
|
|
21
|
+
const Id = Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }));
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Where a text the app draws is kept in the drop-in (Q860): an issue's or a pull request's own
|
|
25
|
+
* text, a comment on one, a review, a comment on a pull request's lines, a release's notes, or a
|
|
26
|
+
* file at a ref. The image proxy's signer reads the text from there as the viewer, and signs only
|
|
27
|
+
* the remote images it holds.
|
|
28
|
+
*/
|
|
29
|
+
export const TextAddress = Schema.Union([
|
|
30
|
+
Schema.Struct({ kind: Schema.Literal('issue'), repo: RepoName, number: Id }),
|
|
31
|
+
Schema.Struct({ kind: Schema.Literal('issue-comment'), repo: RepoName, id: Id }),
|
|
32
|
+
Schema.Struct({ kind: Schema.Literal('review'), repo: RepoName, number: Id, id: Id }),
|
|
33
|
+
Schema.Struct({ kind: Schema.Literal('review-comment'), repo: RepoName, id: Id }),
|
|
34
|
+
Schema.Struct({ kind: Schema.Literal('release'), repo: RepoName, id: Id }),
|
|
35
|
+
Schema.Struct({
|
|
36
|
+
kind: Schema.Literal('file'),
|
|
37
|
+
repo: RepoName,
|
|
38
|
+
ref: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(1024)),
|
|
39
|
+
path: FilePath,
|
|
40
|
+
}),
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
export type TextAddress = typeof TextAddress.Type;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Words under the drop-in's limit on its memory (#1098, Q868): a Vite plugin that gives the app
|
|
3
|
+
* `virtual:words-module`, words' WebAssembly module with its memory's most set to
|
|
4
|
+
* `wordsMemoryPagesMost`. Words writes a text's whole HTML into that memory before any hook can stop
|
|
5
|
+
* it, and the memory never shrinks, so the app renders through this module, and starts a fresh
|
|
6
|
+
* renderer from it after a call traps at the most.
|
|
7
|
+
*
|
|
8
|
+
* On workerd, which compiles no WebAssembly at run time, the module is a file written once under
|
|
9
|
+
* Vite's cache, and words' own `./words.wasm` import reads it too, so words starts under the most.
|
|
10
|
+
* Elsewhere, in a browser or Node, the module is compiled at load from words' own bytes, edited.
|
|
11
|
+
*/
|
|
12
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
14
|
+
import { createRequire } from 'node:module';
|
|
15
|
+
import { dirname, isAbsolute, join } from 'node:path';
|
|
16
|
+
|
|
17
|
+
import type { Plugin } from 'vite-plus';
|
|
18
|
+
|
|
19
|
+
import { withMemoryMax, wordsMemoryPagesMost } from '@ref0/github/markdown';
|
|
20
|
+
|
|
21
|
+
/** The module the app imports for words' WebAssembly, under the most. */
|
|
22
|
+
export const wordsModuleId = 'virtual:words-module';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The module's id once resolved, holding where words and the drop-in's Markdown entry are, so a
|
|
26
|
+
* load needs nothing from its resolve: Vitest resolves an id it has met before as it is.
|
|
27
|
+
*/
|
|
28
|
+
const resolvedPrefix = `\0${wordsModuleId}?`;
|
|
29
|
+
|
|
30
|
+
/** Words' own import of its module, from its workerd entry. */
|
|
31
|
+
const wordsImporter = /[\\/]@pierre[\\/]words[\\/]dist[\\/]workerd\.js$/;
|
|
32
|
+
|
|
33
|
+
/** A path as Vite may give it, without a query. */
|
|
34
|
+
const pathOf = (id: string) => id.replace(/[?#].*$/, '');
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Words' entry as a file. A Node server build keeps words external, and resolves it to its bare
|
|
38
|
+
* name, which has no folder: the file is then where Node finds it from the importer.
|
|
39
|
+
*/
|
|
40
|
+
const wordsEntryFile = (resolved: string, importer: string) =>
|
|
41
|
+
isAbsolute(resolved) ? resolved : createRequire(importer).resolve('@pierre/words');
|
|
42
|
+
|
|
43
|
+
export const wordsMemoryMax = (pages = wordsMemoryPagesMost): Plugin => {
|
|
44
|
+
let cacheDir = '';
|
|
45
|
+
let root = '';
|
|
46
|
+
const written = new Map<string, string>();
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* `dist`'s `words.wasm` with its most, under Vite's cache: its path. A file there is kept only
|
|
50
|
+
* when it holds these bytes, since a run killed mid-write leaves an empty or short one, which
|
|
51
|
+
* workerd fails to compile. A write goes to a file of its own beside it and is renamed into place,
|
|
52
|
+
* so no reader, in this build or another at once, sees it part-written.
|
|
53
|
+
*/
|
|
54
|
+
const withMost = (dist: string) => {
|
|
55
|
+
const known = written.get(dist);
|
|
56
|
+
if (known !== undefined) return known;
|
|
57
|
+
|
|
58
|
+
const bytes = withMemoryMax(readFileSync(join(dist, 'words.wasm')), pages);
|
|
59
|
+
const hash = createHash('sha256').update(bytes).digest('hex').slice(0, 16);
|
|
60
|
+
const file = join(cacheDir, 'ref0-words', `words-${hash}.wasm`);
|
|
61
|
+
|
|
62
|
+
if (!existsSync(file) || !Buffer.from(bytes).equals(readFileSync(file))) {
|
|
63
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
64
|
+
const staged = `${file}.${process.pid}-${randomUUID()}.tmp`;
|
|
65
|
+
writeFileSync(staged, bytes);
|
|
66
|
+
renameSync(staged, file);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
written.set(dist, file);
|
|
70
|
+
|
|
71
|
+
return file;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
name: 'ref0-words-memory-max',
|
|
76
|
+
enforce: 'pre',
|
|
77
|
+
// The dev server's optimizer would bundle words into its cache, where no `words.wasm` sits
|
|
78
|
+
// beside it and this plugin no longer knows its import (#1334): words stays as installed.
|
|
79
|
+
configEnvironment: () => ({ optimizeDeps: { exclude: ['@pierre/words'] } }),
|
|
80
|
+
configResolved: (config) => {
|
|
81
|
+
cacheDir = config.cacheDir;
|
|
82
|
+
root = config.root;
|
|
83
|
+
},
|
|
84
|
+
async resolveId(source, importer, options) {
|
|
85
|
+
if (source.startsWith(resolvedPrefix)) return source;
|
|
86
|
+
|
|
87
|
+
if (source === wordsModuleId) {
|
|
88
|
+
const entry = await this.resolve('@pierre/words', importer, { ...options, skipSelf: true });
|
|
89
|
+
const markdown = await this.resolve('@ref0/github/markdown', importer, {
|
|
90
|
+
...options,
|
|
91
|
+
skipSelf: true,
|
|
92
|
+
});
|
|
93
|
+
if (entry === null || markdown === null)
|
|
94
|
+
throw new Error(
|
|
95
|
+
`${wordsModuleId} needs @pierre/words and @ref0/github beside its importer`,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const where = new URLSearchParams({
|
|
99
|
+
dist: dirname(wordsEntryFile(pathOf(entry.id), importer ?? join(root, 'vite.config.ts'))),
|
|
100
|
+
markdown: pathOf(markdown.id),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
return `${resolvedPrefix}${where.toString()}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (
|
|
107
|
+
source === './words.wasm' &&
|
|
108
|
+
importer !== undefined &&
|
|
109
|
+
wordsImporter.test(pathOf(importer))
|
|
110
|
+
)
|
|
111
|
+
return withMost(dirname(pathOf(importer)));
|
|
112
|
+
|
|
113
|
+
return null;
|
|
114
|
+
},
|
|
115
|
+
load(id) {
|
|
116
|
+
if (!id.startsWith(resolvedPrefix)) return null;
|
|
117
|
+
|
|
118
|
+
// Words' `dist` folder and the drop-in's Markdown entry, as the app resolved them.
|
|
119
|
+
const where = new URLSearchParams(id.slice(resolvedPrefix.length));
|
|
120
|
+
const dist = where.get('dist');
|
|
121
|
+
const markdown = where.get('markdown');
|
|
122
|
+
if (dist === null || markdown === null) throw new Error(`${id} names no words to load`);
|
|
123
|
+
|
|
124
|
+
if (this.environment.config.resolve.conditions.includes('workerd'))
|
|
125
|
+
return `import module from ${JSON.stringify(withMost(dist))};\nexport default module;\n`;
|
|
126
|
+
|
|
127
|
+
return [
|
|
128
|
+
`import bytes from ${JSON.stringify(join(dist, 'words.wasm.mjs'))};`,
|
|
129
|
+
`import { withMemoryMax } from ${JSON.stringify(markdown)};`,
|
|
130
|
+
`export default new WebAssembly.Module(withMemoryMax(bytes, ${pages}));`,
|
|
131
|
+
'',
|
|
132
|
+
].join('\n');
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
};
|
|
@@ -7,7 +7,7 @@ export const reservedRepos: ReadonlySet<string> = new Set(['login', 'new', 'sett
|
|
|
7
7
|
/**
|
|
8
8
|
* Why `name` can't name a repository, or `undefined` when it can. The drop-in turns each character
|
|
9
9
|
* outside these into `-`, and refuses a name starting with `.` or `-` or ending in `.git` or
|
|
10
|
-
* `.lock`, as Git's repo
|
|
10
|
+
* `.lock`, as Git's repo names do; the form says so before it sends one.
|
|
11
11
|
*/
|
|
12
12
|
export const repoProblem = (name: string): string | undefined => {
|
|
13
13
|
if (name === '') return 'Name the repository';
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
import { type KeyboardEvent, type ReactNode, useEffect, useRef, useState } from 'react';
|
|
16
16
|
import { toast } from 'sonner';
|
|
17
17
|
|
|
18
|
+
import { useClients } from '../clients/clients.ts';
|
|
18
19
|
import { copyText } from '../code/controls.tsx';
|
|
19
20
|
import { commitHref } from '../code/places.ts';
|
|
20
21
|
import { hotkeys, Keys, onMac } from '../components/hotkeys/hotkeys.tsx';
|
|
@@ -45,6 +46,7 @@ import {
|
|
|
45
46
|
useAllowedAt,
|
|
46
47
|
useGroups,
|
|
47
48
|
} from './rows.tsx';
|
|
49
|
+
import { paletteReads } from './server.ts';
|
|
48
50
|
import { type ModeSymbol, symbols, type Typed, typedInto } from './targets.ts';
|
|
49
51
|
|
|
50
52
|
export type { PaletteAt } from './rows.tsx';
|
|
@@ -208,21 +210,28 @@ function PaletteBody({
|
|
|
208
210
|
readonly shown: boolean;
|
|
209
211
|
readonly close: () => void;
|
|
210
212
|
}) {
|
|
213
|
+
const clients = useClients();
|
|
211
214
|
const router = useRouter();
|
|
212
215
|
const [typed, setTyped] = useState<Typed>({ symbol: undefined, text: '' });
|
|
213
216
|
const commands = useCommands(at);
|
|
214
|
-
const groups = useGroups(at, typed, commands, setTyped);
|
|
217
|
+
const groups = useGroups(at, typed, commands, setTyped, shown);
|
|
215
218
|
const rows = groups.flatMap((group) => group.rows);
|
|
216
219
|
const mode = typed.symbol ?? 'none';
|
|
217
|
-
// Closed once the dialog starts closing, before its exit animation unmounts the body.
|
|
220
|
+
// Closed once the dialog starts closing, before its exit animation unmounts the body. Closing
|
|
221
|
+
// aborts a commit jump's lookup, as another jump taking its place does, and the palette's own
|
|
222
|
+
// reads still out, such as a `#` search.
|
|
223
|
+
const client = useQueryClient();
|
|
218
224
|
const open = useRef(true);
|
|
225
|
+
const jump = useRef<AbortController | undefined>(undefined);
|
|
219
226
|
useEffect(() => {
|
|
220
227
|
open.current = shown;
|
|
221
228
|
|
|
222
229
|
return () => {
|
|
223
230
|
open.current = false;
|
|
231
|
+
jump.current?.abort();
|
|
232
|
+
void client.cancelQueries({ queryKey: paletteReads });
|
|
224
233
|
};
|
|
225
|
-
}, [shown]);
|
|
234
|
+
}, [client, shown]);
|
|
226
235
|
|
|
227
236
|
const go = (href: string, newTab: boolean) => {
|
|
228
237
|
if (newTab) {
|
|
@@ -261,16 +270,24 @@ function PaletteBody({
|
|
|
261
270
|
};
|
|
262
271
|
|
|
263
272
|
// A SHA names a commit only once the drop-in finds one it starts, as a comment's SHA does. A
|
|
264
|
-
// palette closed before the answer comes
|
|
273
|
+
// palette closed, or another jump picked, before the answer comes stops its read and goes
|
|
274
|
+
// nowhere, and a lookup that fails says so.
|
|
265
275
|
const jumpToCommit = async (
|
|
266
276
|
commit: { readonly owner: string; readonly repo: string; readonly sha: string },
|
|
267
277
|
newTab: boolean,
|
|
268
278
|
) => {
|
|
269
|
-
|
|
270
|
-
.commit({ repo: `${commit.owner}/${commit.repo}`, sha: commit.sha })
|
|
271
|
-
.catch(() => null);
|
|
279
|
+
// A closing palette's input still takes keys until its exit animation ends: it starts none.
|
|
272
280
|
if (!open.current) return;
|
|
273
281
|
|
|
282
|
+
jump.current?.abort();
|
|
283
|
+
const lookup = new AbortController();
|
|
284
|
+
jump.current = lookup;
|
|
285
|
+
|
|
286
|
+
const sha = await githubLookups(clients)
|
|
287
|
+
.commit({ repo: `${commit.owner}/${commit.repo}`, sha: commit.sha }, lookup.signal)
|
|
288
|
+
.catch(() => null);
|
|
289
|
+
if (lookup.signal.aborted || !open.current) return;
|
|
290
|
+
|
|
274
291
|
if (sha === null) {
|
|
275
292
|
toast.error(`Couldn't look up ${commit.sha} in ${commit.owner}/${commit.repo}`);
|
|
276
293
|
|
|
@@ -495,6 +512,7 @@ export interface PaletteParts {
|
|
|
495
512
|
* lists it finds are read ahead once the page is idle.
|
|
496
513
|
*/
|
|
497
514
|
export const usePalette = (at: PaletteAt | undefined, path: string): PaletteParts | undefined => {
|
|
515
|
+
const clients = useClients();
|
|
498
516
|
const client = useQueryClient();
|
|
499
517
|
const [open, setOpen] = useState(false);
|
|
500
518
|
const owner = at?.here.owner;
|
|
@@ -511,7 +529,7 @@ export const usePalette = (at: PaletteAt | undefined, path: string): PalettePart
|
|
|
511
529
|
useEffect(() => {
|
|
512
530
|
if (at === undefined) return;
|
|
513
531
|
|
|
514
|
-
const readAhead = () => prefetchLists(client, at);
|
|
532
|
+
const readAhead = () => prefetchLists(clients, client, at);
|
|
515
533
|
|
|
516
534
|
if ('requestIdleCallback' in window) {
|
|
517
535
|
const idle = requestIdleCallback(readAhead, { timeout: 2_000 });
|
|
@@ -522,11 +540,11 @@ export const usePalette = (at: PaletteAt | undefined, path: string): PalettePart
|
|
|
522
540
|
const next = setTimeout(readAhead, 0);
|
|
523
541
|
|
|
524
542
|
return () => clearTimeout(next);
|
|
525
|
-
}, [client, at === undefined, owner, repo]);
|
|
543
|
+
}, [clients, client, at === undefined, owner, repo]);
|
|
526
544
|
|
|
527
545
|
if (at === undefined) return undefined;
|
|
528
546
|
|
|
529
|
-
const readAhead = () => prefetchLists(client, at);
|
|
547
|
+
const readAhead = () => prefetchLists(clients, client, at);
|
|
530
548
|
const show = () => setOpen(true);
|
|
531
549
|
|
|
532
550
|
return {
|