ref0-git 0.0.0-stage → 0.2.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 +6 -0
- package/app/apps/github/README.md +70 -0
- package/app/apps/github/THIRD_PARTY_NOTICES.md +214 -0
- package/app/apps/github/components.json +25 -0
- package/app/apps/github/generated/git-rest.ts +10444 -0
- package/app/apps/github/generated/routeTree.gen.ts +1242 -0
- package/app/apps/github/migrations/postgres/0001_auth.sql +46 -0
- package/app/apps/github/migrations/sql/0001_auth.sql +19 -0
- package/app/apps/github/migrations/sql/0002_passkeys.sql +9 -0
- package/app/apps/github/migrations/sql/0003_orgs.sql +22 -0
- package/app/apps/github/migrations/sql/0004_avatars.sql +6 -0
- package/app/apps/github/package.json +80 -0
- package/app/apps/github/src/branches/branch-list.tsx +385 -0
- package/app/apps/github/src/branches/branches.ts +55 -0
- package/app/apps/github/src/clients/allowed.ts +213 -0
- package/app/apps/github/src/clients/at-most.ts +17 -0
- package/app/apps/github/src/clients/avatars.ts +410 -0
- package/app/apps/github/src/clients/cached.ts +65 -0
- package/app/apps/github/src/clients/calls.ts +160 -0
- package/app/apps/github/src/clients/clients.ts +82 -0
- package/app/apps/github/src/clients/graphql.ts +50 -0
- package/app/apps/github/src/clients/host-answer.ts +28 -0
- package/app/apps/github/src/clients/host-calls.ts +382 -0
- package/app/apps/github/src/clients/icon-bytes.ts +203 -0
- package/app/apps/github/src/clients/proxy.ts +59 -0
- package/app/apps/github/src/clients/session-ended.ts +18 -0
- package/app/apps/github/src/clients/transfers.ts +212 -0
- package/app/apps/github/src/code/breadcrumbs.tsx +50 -0
- package/app/apps/github/src/code/code-page.tsx +147 -0
- package/app/apps/github/src/code/code-tree.tsx +338 -0
- package/app/apps/github/src/code/controls.tsx +230 -0
- package/app/apps/github/src/code/file-view.tsx +450 -0
- package/app/apps/github/src/code/files.ts +332 -0
- package/app/apps/github/src/code/folder-list.tsx +122 -0
- package/app/apps/github/src/code/go-to-file.tsx +131 -0
- package/app/apps/github/src/code/highlighted.tsx +58 -0
- package/app/apps/github/src/code/lines.ts +46 -0
- package/app/apps/github/src/code/load.ts +147 -0
- package/app/apps/github/src/code/markdown-files.ts +58 -0
- package/app/apps/github/src/code/places.ts +88 -0
- package/app/apps/github/src/code/ref-pages.ts +179 -0
- package/app/apps/github/src/code/ref-switcher.tsx +203 -0
- package/app/apps/github/src/code/refs.ts +142 -0
- package/app/apps/github/src/code/repo-home.tsx +240 -0
- package/app/apps/github/src/code/repo.ts +105 -0
- package/app/apps/github/src/code/saved-reads.ts +199 -0
- package/app/apps/github/src/code/saved.ts +110 -0
- package/app/apps/github/src/code/tree-fold.ts +186 -0
- package/app/apps/github/src/code/trees.ts +136 -0
- package/app/apps/github/src/components/avatar-picture.ts +53 -0
- package/app/apps/github/src/components/avatar-url.ts +16 -0
- package/app/apps/github/src/components/confirm-action.tsx +100 -0
- package/app/apps/github/src/components/count.tsx +24 -0
- package/app/apps/github/src/components/create-button.tsx +38 -0
- package/app/apps/github/src/components/file-icons/file-icons.css +225 -0
- package/app/apps/github/src/components/file-icons/file-icons.tsx +138 -0
- package/app/apps/github/src/components/filter.tsx +35 -0
- package/app/apps/github/src/components/hotkeys/hotkeys.tsx +255 -0
- package/app/apps/github/src/components/item-list.tsx +65 -0
- package/app/apps/github/src/components/language-dot.tsx +29 -0
- package/app/apps/github/src/components/list-toolbar.tsx +82 -0
- package/app/apps/github/src/components/markdown/editor.tsx +57 -0
- package/app/apps/github/src/components/markdown/markdown.css +177 -0
- package/app/apps/github/src/components/markdown/markdown.tsx +82 -0
- package/app/apps/github/src/components/owner-card.tsx +196 -0
- package/app/apps/github/src/components/pull-status.tsx +34 -0
- package/app/apps/github/src/components/recent.ts +41 -0
- package/app/apps/github/src/components/relative-time.tsx +78 -0
- package/app/apps/github/src/components/repos/icon-hashes.ts +91 -0
- package/app/apps/github/src/components/repos/new-repo-form.tsx +196 -0
- package/app/apps/github/src/components/repos/repo-icon.tsx +47 -0
- package/app/apps/github/src/components/repos/repo-list.tsx +528 -0
- package/app/apps/github/src/components/repos/your-repos.tsx +124 -0
- package/app/apps/github/src/components/review-state.tsx +75 -0
- package/app/apps/github/src/components/route-dialog.tsx +137 -0
- package/app/apps/github/src/components/save-button.tsx +58 -0
- package/app/apps/github/src/components/shell/app-shell.tsx +164 -0
- package/app/apps/github/src/components/shell/create-org-dialog.tsx +118 -0
- package/app/apps/github/src/components/shell/create-row.tsx +49 -0
- package/app/apps/github/src/components/shell/link-menu.tsx +94 -0
- package/app/apps/github/src/components/shell/nav-user.tsx +97 -0
- package/app/apps/github/src/components/shell/owner-repos.tsx +247 -0
- package/app/apps/github/src/components/shell/owner-switcher.tsx +104 -0
- package/app/apps/github/src/components/shell/repo-switcher.tsx +179 -0
- package/app/apps/github/src/components/shell/sections.ts +31 -0
- package/app/apps/github/src/components/shell/submenu-chevron.ts +147 -0
- package/app/apps/github/src/components/signin/device-card.tsx +139 -0
- package/app/apps/github/src/components/signin/login-form.tsx +88 -0
- package/app/apps/github/src/components/signin/signin-page.tsx +33 -0
- package/app/apps/github/src/components/signin/signup-form.tsx +106 -0
- package/app/apps/github/src/components/states/live-status.tsx +42 -0
- package/app/apps/github/src/components/states/states.tsx +126 -0
- package/app/apps/github/src/components/tab-indicator.tsx +143 -0
- package/app/apps/github/src/components/theme-choice.tsx +108 -0
- package/app/apps/github/src/components/theme-provider.tsx +126 -0
- package/app/apps/github/src/components/tones.ts +23 -0
- package/app/apps/github/src/components/ui/alert-dialog.tsx +187 -0
- package/app/apps/github/src/components/ui/alert.tsx +78 -0
- package/app/apps/github/src/components/ui/avatar.tsx +106 -0
- package/app/apps/github/src/components/ui/badge.tsx +51 -0
- package/app/apps/github/src/components/ui/breadcrumb.tsx +124 -0
- package/app/apps/github/src/components/ui/button-group.tsx +87 -0
- package/app/apps/github/src/components/ui/button.tsx +61 -0
- package/app/apps/github/src/components/ui/calendar.tsx +221 -0
- package/app/apps/github/src/components/ui/card.tsx +102 -0
- package/app/apps/github/src/components/ui/checkbox.tsx +26 -0
- package/app/apps/github/src/components/ui/collapsible.tsx +19 -0
- package/app/apps/github/src/components/ui/combobox.tsx +304 -0
- package/app/apps/github/src/components/ui/command.tsx +208 -0
- package/app/apps/github/src/components/ui/dialog.tsx +156 -0
- package/app/apps/github/src/components/ui/dropdown-menu.tsx +290 -0
- package/app/apps/github/src/components/ui/empty.tsx +100 -0
- package/app/apps/github/src/components/ui/field.tsx +236 -0
- package/app/apps/github/src/components/ui/hover-card.tsx +48 -0
- package/app/apps/github/src/components/ui/input-group.tsx +163 -0
- package/app/apps/github/src/components/ui/input.tsx +19 -0
- package/app/apps/github/src/components/ui/item.tsx +201 -0
- package/app/apps/github/src/components/ui/kbd.tsx +27 -0
- package/app/apps/github/src/components/ui/label.tsx +33 -0
- package/app/apps/github/src/components/ui/popover.tsx +87 -0
- package/app/apps/github/src/components/ui/radio-group.tsx +35 -0
- package/app/apps/github/src/components/ui/select.tsx +198 -0
- package/app/apps/github/src/components/ui/separator.tsx +22 -0
- package/app/apps/github/src/components/ui/sheet.tsx +138 -0
- package/app/apps/github/src/components/ui/sidebar.tsx +724 -0
- package/app/apps/github/src/components/ui/skeleton.tsx +13 -0
- package/app/apps/github/src/components/ui/sonner.tsx +47 -0
- package/app/apps/github/src/components/ui/styles.css +242 -0
- package/app/apps/github/src/components/ui/table.tsx +113 -0
- package/app/apps/github/src/components/ui/tabs.tsx +79 -0
- package/app/apps/github/src/components/ui/textarea.tsx +17 -0
- package/app/apps/github/src/components/ui/title.ts +6 -0
- package/app/apps/github/src/components/ui/toggle-group.tsx +89 -0
- package/app/apps/github/src/components/ui/toggle.tsx +42 -0
- package/app/apps/github/src/components/ui/tooltip.tsx +63 -0
- package/app/apps/github/src/components/user-avatar.tsx +145 -0
- package/app/apps/github/src/components/view-tabs.tsx +42 -0
- package/app/apps/github/src/context/context.ts +133 -0
- package/app/apps/github/src/diffs/blobs.ts +94 -0
- package/app/apps/github/src/diffs/diff-view.tsx +155 -0
- package/app/apps/github/src/diffs/files.ts +121 -0
- package/app/apps/github/src/diffs/hunks.tsx +454 -0
- package/app/apps/github/src/diffs/patch.ts +131 -0
- package/app/apps/github/src/diffs/rows.ts +137 -0
- package/app/apps/github/src/history/commit-diff.ts +54 -0
- package/app/apps/github/src/history/commit-list.tsx +207 -0
- package/app/apps/github/src/history/commit-page.tsx +147 -0
- package/app/apps/github/src/history/history.ts +129 -0
- package/app/apps/github/src/hooks/allowed.ts +31 -0
- package/app/apps/github/src/hooks/answers.ts +65 -0
- package/app/apps/github/src/hooks/avatars.ts +54 -0
- package/app/apps/github/src/hooks/draft.ts +38 -0
- package/app/apps/github/src/hooks/open-counts.ts +127 -0
- package/app/apps/github/src/hooks/profiles.ts +120 -0
- package/app/apps/github/src/hooks/repos.ts +440 -0
- package/app/apps/github/src/hooks/use-mobile.ts +19 -0
- package/app/apps/github/src/hooks/viewer.ts +39 -0
- package/app/apps/github/src/inbox/count.ts +70 -0
- package/app/apps/github/src/inbox/inbox-item.tsx +66 -0
- package/app/apps/github/src/inbox/inbox-page.tsx +572 -0
- package/app/apps/github/src/inbox/marks.ts +130 -0
- package/app/apps/github/src/inbox/release-tags.ts +65 -0
- package/app/apps/github/src/inbox/search.ts +97 -0
- package/app/apps/github/src/inbox/subjects.ts +184 -0
- package/app/apps/github/src/inbox/subscription-controls.tsx +184 -0
- package/app/apps/github/src/inbox/subscriptions.ts +189 -0
- package/app/apps/github/src/inbox/threads.ts +198 -0
- package/app/apps/github/src/issues/changes.ts +332 -0
- package/app/apps/github/src/issues/counts.ts +62 -0
- package/app/apps/github/src/issues/issue-list.tsx +682 -0
- package/app/apps/github/src/issues/issue-page.tsx +533 -0
- package/app/apps/github/src/issues/issues.ts +566 -0
- package/app/apps/github/src/issues/label-dialog.tsx +310 -0
- package/app/apps/github/src/issues/labels-page.tsx +119 -0
- package/app/apps/github/src/issues/new-issue.tsx +79 -0
- package/app/apps/github/src/issues/parts.tsx +71 -0
- package/app/apps/github/src/issues/picker.tsx +298 -0
- package/app/apps/github/src/issues/search.ts +238 -0
- package/app/apps/github/src/issues/sidebar.tsx +236 -0
- package/app/apps/github/src/lib/cn.ts +8 -0
- package/app/apps/github/src/lib/highlighting.ts +13 -0
- package/app/apps/github/src/live/follow.ts +129 -0
- package/app/apps/github/src/live/sse.ts +74 -0
- package/app/apps/github/src/live/use-follow.ts +37 -0
- package/app/apps/github/src/markdown/README.md +53 -0
- package/app/apps/github/src/markdown/allowed-html.ts +69 -0
- package/app/apps/github/src/markdown/context.ts +206 -0
- package/app/apps/github/src/markdown/images.ts +81 -0
- package/app/apps/github/src/markdown/lookup.ts +122 -0
- package/app/apps/github/src/markdown/patches.ts +299 -0
- package/app/apps/github/src/markdown/query.ts +25 -0
- package/app/apps/github/src/markdown/references.ts +158 -0
- package/app/apps/github/src/markdown/render.ts +103 -0
- package/app/apps/github/src/names/owners.ts +51 -0
- package/app/apps/github/src/names/repos.ts +24 -0
- package/app/apps/github/src/palette/palette.tsx +547 -0
- package/app/apps/github/src/palette/recent.ts +116 -0
- package/app/apps/github/src/palette/rows.tsx +455 -0
- package/app/apps/github/src/palette/server.ts +104 -0
- package/app/apps/github/src/palette/targets.ts +306 -0
- package/app/apps/github/src/policy.ts +600 -0
- package/app/apps/github/src/private-repos.ts +47 -0
- package/app/apps/github/src/pulls/compare-page.tsx +342 -0
- package/app/apps/github/src/pulls/files-tab.tsx +776 -0
- package/app/apps/github/src/pulls/live.ts +124 -0
- package/app/apps/github/src/pulls/merge-box.tsx +367 -0
- package/app/apps/github/src/pulls/merge-button.ts +86 -0
- package/app/apps/github/src/pulls/pull-list.tsx +235 -0
- package/app/apps/github/src/pulls/pull-page.tsx +474 -0
- package/app/apps/github/src/pulls/pull.ts +468 -0
- package/app/apps/github/src/pulls/pulls.ts +318 -0
- package/app/apps/github/src/pulls/review.ts +350 -0
- package/app/apps/github/src/pulls/search.ts +130 -0
- package/app/apps/github/src/queue/queue-page.tsx +405 -0
- package/app/apps/github/src/queue/queue.ts +231 -0
- package/app/apps/github/src/releases/latest-release.tsx +55 -0
- package/app/apps/github/src/releases/overview.tsx +30 -0
- package/app/apps/github/src/releases/release-form.tsx +353 -0
- package/app/apps/github/src/releases/release-list.tsx +173 -0
- package/app/apps/github/src/releases/release-view.tsx +183 -0
- package/app/apps/github/src/releases/releases.ts +308 -0
- package/app/apps/github/src/releases/tag-list.tsx +134 -0
- package/app/apps/github/src/router.tsx +46 -0
- package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +33 -0
- package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +28 -0
- package/app/apps/github/src/routes/$owner/$repo/_code.tsx +11 -0
- package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +19 -0
- package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +19 -0
- package/app/apps/github/src/routes/$owner/$repo/_releases.tsx +23 -0
- package/app/apps/github/src/routes/$owner/$repo/branches.tsx +39 -0
- package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +34 -0
- package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +42 -0
- package/app/apps/github/src/routes/$owner/$repo/compare/$.tsx +19 -0
- package/app/apps/github/src/routes/$owner/$repo/index.tsx +24 -0
- package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +50 -0
- package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +53 -0
- package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +43 -0
- package/app/apps/github/src/routes/$owner/$repo/labels.tsx +22 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/checks.tsx +15 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/commits.tsx +15 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/files.tsx +15 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/index.tsx +19 -0
- package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +52 -0
- package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +48 -0
- package/app/apps/github/src/routes/$owner/$repo/queue.tsx +22 -0
- package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +58 -0
- package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +40 -0
- package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +35 -0
- package/app/apps/github/src/routes/$owner/$repo/route.tsx +102 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/access.tsx +9 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +16 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/hooks/new.tsx +25 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +17 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/route.tsx +28 -0
- package/app/apps/github/src/routes/$owner/$repo/settings/rules.tsx +12 -0
- package/app/apps/github/src/routes/$owner/$repo/tokens.tsx +16 -0
- package/app/apps/github/src/routes/$owner/index.tsx +45 -0
- package/app/apps/github/src/routes/-nav.tsx +293 -0
- package/app/apps/github/src/routes/-root-testing.ts +107 -0
- package/app/apps/github/src/routes/__root.tsx +225 -0
- package/app/apps/github/src/routes/api.auth.$.ts +18 -0
- package/app/apps/github/src/routes/downloads/$owner/$repo/$asset.tsx +10 -0
- package/app/apps/github/src/routes/file-icons[.]svg.ts +21 -0
- package/app/apps/github/src/routes/icons/$owner/$repo.tsx +14 -0
- package/app/apps/github/src/routes/icons/$owner/index.tsx +14 -0
- package/app/apps/github/src/routes/icons/index.tsx +12 -0
- package/app/apps/github/src/routes/index.tsx +48 -0
- package/app/apps/github/src/routes/login.tsx +24 -0
- package/app/apps/github/src/routes/login_.code.tsx +31 -0
- package/app/apps/github/src/routes/new.tsx +91 -0
- package/app/apps/github/src/routes/notifications.tsx +20 -0
- package/app/apps/github/src/routes/orgs/$owner/issues.tsx +8 -0
- package/app/apps/github/src/routes/orgs/$owner/pulls.tsx +8 -0
- package/app/apps/github/src/routes/orgs/$owner/releases.tsx +8 -0
- package/app/apps/github/src/routes/orgs/$owner/route.tsx +25 -0
- package/app/apps/github/src/routes/orgs/$owner/settings.tsx +30 -0
- package/app/apps/github/src/routes/orgs/$owner/tokens.tsx +15 -0
- package/app/apps/github/src/routes/settings.tsx +54 -0
- package/app/apps/github/src/routes/signup.tsx +24 -0
- package/app/apps/github/src/routes/uploads/$owner/$repo/$release.tsx +10 -0
- package/app/apps/github/src/seed/acme.ts +498 -0
- package/app/apps/github/src/seed/licenses.ts +114 -0
- package/app/apps/github/src/seed/seed.ts +538 -0
- package/app/apps/github/src/server.ts +97 -0
- package/app/apps/github/src/settings/account-avatar.tsx +43 -0
- package/app/apps/github/src/settings/avatar-section.tsx +140 -0
- package/app/apps/github/src/settings/avatar.ts +58 -0
- package/app/apps/github/src/settings/general-settings.tsx +439 -0
- package/app/apps/github/src/settings/general.ts +73 -0
- package/app/apps/github/src/settings/hook-form.tsx +195 -0
- package/app/apps/github/src/settings/hook-list.tsx +166 -0
- package/app/apps/github/src/settings/hooks.ts +87 -0
- package/app/apps/github/src/settings/org-settings.tsx +228 -0
- package/app/apps/github/src/settings/orgs.ts +116 -0
- package/app/apps/github/src/settings/rule-list.tsx +72 -0
- package/app/apps/github/src/settings/rules.ts +27 -0
- package/app/apps/github/src/settings/settings-layout.tsx +114 -0
- package/app/apps/github/src/signin/approval.ts +186 -0
- package/app/apps/github/src/signin/auth-client.ts +127 -0
- package/app/apps/github/src/signin/auth.ts +753 -0
- package/app/apps/github/src/signin/avatars.ts +126 -0
- package/app/apps/github/src/signin/client-ip.ts +39 -0
- package/app/apps/github/src/signin/credentials.ts +26 -0
- package/app/apps/github/src/signin/device-code.ts +95 -0
- package/app/apps/github/src/signin/device-prompt.ts +125 -0
- package/app/apps/github/src/signin/errors.ts +135 -0
- package/app/apps/github/src/signin/host-session.ts +68 -0
- package/app/apps/github/src/signin/orgs.ts +283 -0
- package/app/apps/github/src/signin/owner-names.ts +183 -0
- package/app/apps/github/src/signin/person-lock.ts +104 -0
- package/app/apps/github/src/signin/seal.ts +88 -0
- package/app/apps/github/src/signin/seed-people.ts +92 -0
- package/app/apps/github/src/signin/session.ts +48 -0
- package/app/apps/github/src/signin/unborn.ts +110 -0
- package/app/apps/github/src/signin/viewer-orgs.ts +47 -0
- package/app/apps/github/src/signin/viewer.ts +74 -0
- package/app/apps/github/src/signin/with-headers.ts +14 -0
- package/app/apps/github/src/tokens/tokens-page.tsx +529 -0
- package/app/apps/github/src/tokens/tokens.ts +54 -0
- package/app/apps/github/tsconfig.json +25 -0
- package/app/apps/github/tsconfig.worker.json +24 -0
- package/app/apps/github/vite.config.ts +21 -0
- package/app/pnpm-workspace.yaml +216 -0
- package/app/tsconfig.base.json +127 -0
- package/dist/LICENSE +202 -0
- package/dist/cli/child.mjs +42 -0
- package/dist/cli/commands.mjs +23 -0
- package/dist/cli/credentials.mjs +84 -0
- package/dist/cli/documents.mjs +214 -0
- package/dist/cli/events.mjs +55 -0
- package/dist/cli/failure.mjs +105 -0
- package/dist/cli/folders.mjs +32 -0
- package/dist/cli/git-remote-ref0.d.mts +1 -0
- package/dist/cli/git-remote-ref0.mjs +29 -0
- package/dist/cli/git.mjs +48 -0
- package/dist/cli/helpers.mjs +51 -0
- package/dist/cli/hosts.mjs +127 -0
- package/dist/cli/node.mjs +15 -0
- package/dist/cli/output.mjs +135 -0
- package/dist/cli/prompt.mjs +35 -0
- package/dist/cli/queue.mjs +215 -0
- package/dist/cli/ref0-git.d.mts +1 -0
- package/dist/cli/ref0-git.mjs +144 -0
- package/dist/cli/repos.mjs +162 -0
- package/dist/cli/resources.mjs +131 -0
- package/dist/cli/run-end.mjs +57 -0
- package/dist/cli/runtime.mjs +50 -0
- package/dist/cli/setup.mjs +1410 -0
- package/dist/cli/sign-in.mjs +162 -0
- package/dist/cli/sign-ins.mjs +79 -0
- package/dist/cli/sqlite.mjs +28 -0
- package/dist/cli/tokens.mjs +141 -0
- package/dist/cli/vendor.mjs +123 -0
- package/dist/init/app.mjs +231 -0
- package/dist/init/astro.mjs +49 -0
- package/dist/init/choices.mjs +497 -0
- package/dist/init/cloudflare.mjs +324 -0
- package/dist/init/create.mjs +151 -0
- package/dist/init/detect.mjs +297 -0
- package/dist/init/files.mjs +75 -0
- package/dist/init/frameworks.mjs +248 -0
- package/dist/init/git-module.mjs +49 -0
- package/dist/init/github-routes.mjs +66 -0
- package/dist/init/jsonc.mjs +143 -0
- package/dist/init/metadata.mjs +48 -0
- package/dist/init/mounts.mjs +109 -0
- package/dist/init/next.mjs +205 -0
- package/dist/init/node-app.mjs +189 -0
- package/dist/init/node.mjs +458 -0
- package/dist/init/nuxt.mjs +115 -0
- package/dist/init/output.mjs +21 -0
- package/dist/init/plan.mjs +82 -0
- package/dist/init/range-major.mjs +257 -0
- package/dist/init/react-router.mjs +59 -0
- package/dist/init/routes.mjs +148 -0
- package/dist/init/shell.mjs +4 -0
- package/dist/init/stores.mjs +51 -0
- package/dist/init/sveltekit.mjs +139 -0
- package/dist/init/template.mjs +142 -0
- package/dist/init/templates.mjs +343 -0
- package/dist/init/vercel.mjs +383 -0
- package/dist/init/versions.mjs +32 -0
- package/dist/init/workspace.mjs +20 -0
- package/package.json +52 -3
- package/README.md +0 -3
|
@@ -0,0 +1,1410 @@
|
|
|
1
|
+
import { choices, movesOf, platformOf, recovered, saysOf, settle, withDefaults } from "../init/choices.mjs";
|
|
2
|
+
import { appOutput, checkedManifest, copied, entered } from "../init/app.mjs";
|
|
3
|
+
import { nodeAppOutput, startOrigin } from "../init/node-app.mjs";
|
|
4
|
+
import { configParts, gitClasses, gitSecrets } from "../init/cloudflare.mjs";
|
|
5
|
+
import { platforms } from "../init/template.mjs";
|
|
6
|
+
import { keepsData, mainOrigin, nodeNeeds, routed, routedFindings } from "../init/node.mjs";
|
|
7
|
+
import { detect } from "../init/detect.mjs";
|
|
8
|
+
import { outputOf as outputOf$1, secretFilesOf } from "../init/output.mjs";
|
|
9
|
+
import { detectFrameworks, frameworkFor, newFramework, othersRow } from "../init/frameworks.mjs";
|
|
10
|
+
import { creatable, createCommand, createFailed, createPlatforms, created, creatorFolder, creators } from "../init/create.mjs";
|
|
11
|
+
import { nuxtFindings, nuxtJobsPlugin } from "../init/nuxt.mjs";
|
|
12
|
+
import { nextFindings, nextJobRoutes } from "../init/next.mjs";
|
|
13
|
+
import { svelteBodyLimit, svelteStart } from "../init/sveltekit.mjs";
|
|
14
|
+
import { variablesOf, vercelProblems } from "../init/vercel.mjs";
|
|
15
|
+
import { addedTo, plan } from "../init/plan.mjs";
|
|
16
|
+
import { dropInPrefixes } from "../init/routes.mjs";
|
|
17
|
+
import { appPackages, release } from "../init/metadata.mjs";
|
|
18
|
+
import { doctorJson, initJson, verifyJson } from "./documents.mjs";
|
|
19
|
+
import { CliFailure, answered, cancelled, diskFailed, failure, leftBehind, usageFailure } from "./failure.mjs";
|
|
20
|
+
import { chosenHost, hostFlag, remoteOf } from "./hosts.mjs";
|
|
21
|
+
import { runChild, stopMs } from "./child.mjs";
|
|
22
|
+
import { vendored } from "./vendor.mjs";
|
|
23
|
+
import { Folders } from "./folders.mjs";
|
|
24
|
+
import { gitRun } from "./git.mjs";
|
|
25
|
+
import { node } from "./node.mjs";
|
|
26
|
+
import { Sqlite } from "./sqlite.mjs";
|
|
27
|
+
import { CliModes, answer, cliDocument, field, nextDocument, printable, receipt, say, secrets, stderrText } from "./output.mjs";
|
|
28
|
+
import { select } from "./prompt.mjs";
|
|
29
|
+
import * as Effect from "effect/Effect";
|
|
30
|
+
import * as Redacted from "effect/Redacted";
|
|
31
|
+
import * as Stream from "effect/Stream";
|
|
32
|
+
import * as ChildProcess from "effect/process/ChildProcess";
|
|
33
|
+
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
|
|
34
|
+
import * as Exit from "effect/Exit";
|
|
35
|
+
import * as Option from "effect/Option";
|
|
36
|
+
import * as Command from "effect/cli/Command";
|
|
37
|
+
import * as Schema from "effect/Schema";
|
|
38
|
+
import * as Flag from "effect/cli/Flag";
|
|
39
|
+
import * as Argument from "effect/cli/Argument";
|
|
40
|
+
import { paginate, shortTarget } from "@ref0/git";
|
|
41
|
+
import * as Clock from "effect/Clock";
|
|
42
|
+
import * as FileSystem from "effect/FileSystem";
|
|
43
|
+
import * as Path from "effect/Path";
|
|
44
|
+
import * as Random from "effect/Random";
|
|
45
|
+
import { joinedBytes } from "@ref0/git/protocol";
|
|
46
|
+
// src/cli/setup.ts
|
|
47
|
+
/**
|
|
48
|
+
* `init` and `doctor`, in a project's folder: `init` plans Git's files from the choices, the flags
|
|
49
|
+
* and the folder, then writes and installs them; `doctor` reads the same detection and plan, and
|
|
50
|
+
* only reads, but for `--verify`'s scratch repo and hour-long token.
|
|
51
|
+
*/
|
|
52
|
+
const { process } = node;
|
|
53
|
+
/**
|
|
54
|
+
* Whether `path` under `folder` goes through a link, at any part of it: `init` reads and writes
|
|
55
|
+
* only the folder's own files, so a supplied repo can't point one at a file outside it.
|
|
56
|
+
*/
|
|
57
|
+
const linked = Effect.fnUntraced(function* (folder, path) {
|
|
58
|
+
const fs = yield* FileSystem.FileSystem;
|
|
59
|
+
const parts = path.split("/");
|
|
60
|
+
for (const at of parts.keys()) {
|
|
61
|
+
const each = `${folder}/${parts.slice(0, at + 1).join("/")}`;
|
|
62
|
+
const entry = yield* fs.lstat(each).pipe(Effect.option);
|
|
63
|
+
if (Option.isSome(entry) && entry.value.type === "SymbolicLink") return true;
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* The files of `paths`, those that hold secrets, that Git's index holds in `folder`: an ignore rule
|
|
69
|
+
* doesn't cover a tracked file, so a secret written to one is in the next commit. None outside a
|
|
70
|
+
* repo, or without Git.
|
|
71
|
+
*/
|
|
72
|
+
const trackedSecrets = (folder, paths) => Effect.map(gitRun([
|
|
73
|
+
"ls-files",
|
|
74
|
+
"-z",
|
|
75
|
+
"--",
|
|
76
|
+
...paths
|
|
77
|
+
], { cwd: folder }), (listed) => listed.status === 0 ? listed.stdout.split("\0").filter((path) => path !== "") : []);
|
|
78
|
+
/** `folder`, as detection reads it from the disk, through `Folders`: a file through a link reads as missing. */
|
|
79
|
+
const viewOf = Effect.fnUntraced(function* (folder) {
|
|
80
|
+
return (yield* Folders).view(folder, process.env["npm_config_user_agent"]);
|
|
81
|
+
});
|
|
82
|
+
/** The folder a command names, from the current one, and the argv that names it again. */
|
|
83
|
+
const folderOf = Effect.fnUntraced(function* (dir) {
|
|
84
|
+
const path = yield* Path.Path;
|
|
85
|
+
const given = Option.getOrUndefined(dir);
|
|
86
|
+
return {
|
|
87
|
+
path: given === void 0 ? process.cwd() : path.resolve(given),
|
|
88
|
+
argv: given === void 0 ? [] : [given]
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
/** The project in `folder`, or the failure that says why Git can't go there. */
|
|
92
|
+
const projectIn = (view, platform, framework) => {
|
|
93
|
+
const found = detect(view, platform, framework);
|
|
94
|
+
if (!("reason" in found)) return Effect.succeed(found);
|
|
95
|
+
return Effect.fail(found.reason === "not_on_platform" ? usageFailure(found.reason, found.headline) : failure(found.reason, found.headline));
|
|
96
|
+
};
|
|
97
|
+
/** 32 random bytes, as hex: a secret only the folder holds, which nothing printed may show. */
|
|
98
|
+
const madeSecret = () => {
|
|
99
|
+
const made = Array.from(crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
100
|
+
secrets.hide(made);
|
|
101
|
+
return Redacted.make(made);
|
|
102
|
+
};
|
|
103
|
+
/** Everything `init` writes for `choices` in `project`. */
|
|
104
|
+
const outputOf = (choices, project, source, vendor) => choices.app === "ref0" && source.app !== void 0 ? (choices.platform === "node" ? nodeAppOutput : appOutput)(choices, project.name, source.app, madeSecret, vendor) : outputOf$1(choices, project, madeSecret, vendor);
|
|
105
|
+
/** Each file under `folder`, by its path from it, that `keep` keeps, in the folders `init` enters. */
|
|
106
|
+
const filesUnder = Effect.fnUntraced(function* (folder, keep, under = "") {
|
|
107
|
+
const fs = yield* FileSystem.FileSystem;
|
|
108
|
+
const found = [];
|
|
109
|
+
for (const entry of yield* fs.readDirectory(`${folder}/${under}`)) {
|
|
110
|
+
const path = `${under}${entry}`;
|
|
111
|
+
if ((yield* fs.stat(`${folder}/${path}`)).type === "Directory") {
|
|
112
|
+
if (entered(path)) found.push(...yield* filesUnder(folder, keep, `${path}/`));
|
|
113
|
+
} else if (keep(path)) found.push(path);
|
|
114
|
+
}
|
|
115
|
+
return found;
|
|
116
|
+
});
|
|
117
|
+
/**
|
|
118
|
+
* Each package `--from-checkout` packs, by its folder in the checkout's `packages/`, and where in
|
|
119
|
+
* the project it goes: Git's in `vendor/`, and `ref0-git` in `vendor/cli/`, since `@ref0/git`'s
|
|
120
|
+
* tarball has its name.
|
|
121
|
+
*/
|
|
122
|
+
const vendorPacks = [...appPackages.map((each) => ({
|
|
123
|
+
folder: each,
|
|
124
|
+
name: `@ref0/${each}`,
|
|
125
|
+
into: "vendor"
|
|
126
|
+
})), {
|
|
127
|
+
folder: "cli",
|
|
128
|
+
name: "ref0-git",
|
|
129
|
+
into: "vendor/cli"
|
|
130
|
+
}];
|
|
131
|
+
/** What a checkout, or the copy `ref0-git` carries, must hold for `init` to take the app from it. */
|
|
132
|
+
const checkoutHolds = [
|
|
133
|
+
"pnpm-workspace.yaml",
|
|
134
|
+
"tsconfig.base.json",
|
|
135
|
+
"apps/github/package.json",
|
|
136
|
+
...vendorPacks.map((each) => `packages/${each.folder}/package.json`)
|
|
137
|
+
];
|
|
138
|
+
/** The files a checkout at `root` lacks, of what `init` takes from it. */
|
|
139
|
+
const lacking = Effect.fnUntraced(function* (root, packed) {
|
|
140
|
+
const fs = yield* FileSystem.FileSystem;
|
|
141
|
+
const missing = [];
|
|
142
|
+
for (const path of checkoutHolds.filter((each) => !packed || !each.startsWith("packages/"))) if (!(yield* fs.exists(`${root}/${path}`).pipe(Effect.orElseSucceed(() => false)))) missing.push(path);
|
|
143
|
+
return missing;
|
|
144
|
+
});
|
|
145
|
+
/** The app's files from a checkout at `root`, or from the copy `ref0-git`'s pack carries there. */
|
|
146
|
+
const appSourceIn = Effect.fnUntraced(function* (root) {
|
|
147
|
+
const fs = yield* FileSystem.FileSystem;
|
|
148
|
+
const app = `${root}/apps/github`;
|
|
149
|
+
const files = [];
|
|
150
|
+
for (const path of yield* filesUnder(app, copied)) files.push({
|
|
151
|
+
path,
|
|
152
|
+
text: yield* fs.readFileString(`${app}/${path}`)
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
files,
|
|
156
|
+
manifest: yield* fs.readFileString(`${app}/package.json`),
|
|
157
|
+
workspace: yield* fs.readFileString(`${root}/pnpm-workspace.yaml`),
|
|
158
|
+
base: yield* fs.readFileString(`${root}/tsconfig.base.json`)
|
|
159
|
+
};
|
|
160
|
+
}, (reading, root) => Effect.mapError(reading, diskFailed(`read the app's files in ${printable(root)}`)));
|
|
161
|
+
/**
|
|
162
|
+
* The app's files from `root`, once its `package.json` reads as `appManifest` reads it, or a
|
|
163
|
+
* usage failure naming the file and what's wrong with it: a checkout `--from-checkout` names is
|
|
164
|
+
* the person's to fix.
|
|
165
|
+
*/
|
|
166
|
+
const checkedApp = Effect.fnUntraced(function* (root) {
|
|
167
|
+
const app = yield* appSourceIn(root);
|
|
168
|
+
return yield* checkedManifest(app.manifest).pipe(Effect.as(app), Effect.mapError((error) => usageFailure("invalid_manifest", `${printable(`${root}/apps/github/package.json`)} isn't a package.json init can read: ${printable(error.message)}`, "Fix it, then run init again")));
|
|
169
|
+
});
|
|
170
|
+
/**
|
|
171
|
+
* The source `init` takes the app from: `--from-checkout`'s folder, or this checkout, or the copy
|
|
172
|
+
* of it in `app/` that `ref0-git`'s pack carries, whose packages are on npm.
|
|
173
|
+
*/
|
|
174
|
+
const sourceOf = Effect.fnUntraced(function* (fromCheckout, appChosen) {
|
|
175
|
+
if (fromCheckout !== void 0) {
|
|
176
|
+
const root = (yield* Path.Path).resolve(fromCheckout);
|
|
177
|
+
const missing = yield* lacking(root, false);
|
|
178
|
+
if (missing.length > 0) return yield* Effect.fail(usageFailure("not_a_checkout", `${printable(root)} isn't a ref-0/git checkout: it has no ${missing.join(", ")}`));
|
|
179
|
+
return {
|
|
180
|
+
app: appChosen ? yield* checkedApp(root) : void 0,
|
|
181
|
+
checkout: root
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
if (!appChosen) return {
|
|
185
|
+
app: void 0,
|
|
186
|
+
checkout: void 0
|
|
187
|
+
};
|
|
188
|
+
const path = yield* Path.Path;
|
|
189
|
+
const here = yield* path.fromFileUrl(new URL("../../../..", import.meta.url)).pipe(Effect.orDie);
|
|
190
|
+
const carried = yield* path.fromFileUrl(new URL("../../app", import.meta.url)).pipe(Effect.orDie);
|
|
191
|
+
const root = (yield* lacking(here, false)).length === 0 ? here : carried;
|
|
192
|
+
if ((yield* lacking(root, true)).length > 0) return yield* failure("internal", `ref0-git carries no copy of the app at ${printable(root)}`);
|
|
193
|
+
return {
|
|
194
|
+
app: yield* checkedApp(root),
|
|
195
|
+
checkout: void 0
|
|
196
|
+
};
|
|
197
|
+
});
|
|
198
|
+
/**
|
|
199
|
+
* A version npm publishes: semver 2.0.0's own, `MAJOR.MINOR.PATCH` with an optional prerelease and
|
|
200
|
+
* build, no leading `v` or `=` and no space, as `semver.valid` takes one without `loose`.
|
|
201
|
+
*/
|
|
202
|
+
const published = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?$/u;
|
|
203
|
+
/** The tarball `pnpm pack --json` says it made: its package's name and version, and its file. */
|
|
204
|
+
const readPacked = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Struct({
|
|
205
|
+
name: Schema.String,
|
|
206
|
+
version: Schema.String,
|
|
207
|
+
filename: Schema.String
|
|
208
|
+
})));
|
|
209
|
+
/**
|
|
210
|
+
* The JSON object `pnpm pack --json` prints last, after any lifecycle output its build prints: the
|
|
211
|
+
* last line that opens an object at its first column, to the end.
|
|
212
|
+
*/
|
|
213
|
+
const lastObject = (printed) => {
|
|
214
|
+
const at = printed.lastIndexOf("\n{");
|
|
215
|
+
return at === -1 ? printed.slice(Math.max(0, printed.indexOf("{"))) : printed.slice(at + 1);
|
|
216
|
+
};
|
|
217
|
+
/** A package's manifest, as far as a dry run reads it: its version. */
|
|
218
|
+
const readVersion = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Struct({ version: Schema.String })));
|
|
219
|
+
/**
|
|
220
|
+
* The tarballs a pack of `checkout` would make, from its own manifests' versions, named as `pnpm
|
|
221
|
+
* pack` names them: what a dry run, which packs nothing, says `init` would write.
|
|
222
|
+
*/
|
|
223
|
+
const plannedVendor = Effect.fnUntraced(function* (checkout) {
|
|
224
|
+
const fs = yield* FileSystem.FileSystem;
|
|
225
|
+
const vendor = /* @__PURE__ */ new Map();
|
|
226
|
+
for (const each of vendorPacks) {
|
|
227
|
+
const at = `${checkout}/packages/${each.folder}/package.json`;
|
|
228
|
+
const { version } = yield* readVersion(yield* fs.readFileString(at)).pipe(Effect.mapError(() => usageFailure("invalid_manifest", `${printable(at)} has no version init can read`)));
|
|
229
|
+
vendor.set(each.name, `${each.into}/${each.name.replace("@", "").replace("/", "-")}-${version}.tgz`);
|
|
230
|
+
}
|
|
231
|
+
return vendor;
|
|
232
|
+
}, (reading, checkout) => Effect.catchTag(reading, "PlatformError", (error) => Effect.fail(diskFailed(`read the package manifests in ${printable(checkout)}`)(error))));
|
|
233
|
+
/**
|
|
234
|
+
* Packs each of Git's packages, and `ref0-git`, in `checkout` into a folder of their own, before
|
|
235
|
+
* `init` plans anything, so the specs it writes name what `pnpm pack` made: each tarball by the
|
|
236
|
+
* name, version and file `pnpm pack --json` says, from the checkout's own manifest. A pack that
|
|
237
|
+
* fails, or names another package, is why it failed.
|
|
238
|
+
*/
|
|
239
|
+
const packedFrom = Effect.fnUntraced(function* (checkout) {
|
|
240
|
+
const fs = yield* FileSystem.FileSystem;
|
|
241
|
+
const folder = yield* fs.makeTempDirectory({ prefix: "ref0-git-vendor-" }).pipe(Effect.mapError(diskFailed("make a folder for the packs")));
|
|
242
|
+
return yield* packedInto(checkout, folder).pipe(Effect.onExit((exit) => Exit.isSuccess(exit) && exit.value.kind === "packed" ? Effect.void : fs.remove(folder, {
|
|
243
|
+
recursive: true,
|
|
244
|
+
force: true
|
|
245
|
+
}).pipe(Effect.catch((error) => leftBehind(folder, error)))));
|
|
246
|
+
});
|
|
247
|
+
/**
|
|
248
|
+
* `pnpm pack` of `from` into `destination`, its output kept, not shown: its build prints each file
|
|
249
|
+
* it writes. Interrupted, it gets SIGINT, then SIGKILL past `stopMs`, as `runChild` stops its child.
|
|
250
|
+
*/
|
|
251
|
+
const packOnce = Effect.fnUntraced(function* (from, destination) {
|
|
252
|
+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
253
|
+
const printed = [];
|
|
254
|
+
const out = [];
|
|
255
|
+
const started = ChildProcess.make("pnpm", [
|
|
256
|
+
"pack",
|
|
257
|
+
"--pack-destination",
|
|
258
|
+
destination,
|
|
259
|
+
"--json"
|
|
260
|
+
], {
|
|
261
|
+
cwd: from,
|
|
262
|
+
stdin: "ignore",
|
|
263
|
+
stdout: "pipe",
|
|
264
|
+
stderr: "pipe",
|
|
265
|
+
killSignal: "SIGINT",
|
|
266
|
+
forceKillAfter: stopMs
|
|
267
|
+
});
|
|
268
|
+
const ran = Effect.gen(function* () {
|
|
269
|
+
const child = yield* spawner.spawn(started);
|
|
270
|
+
yield* Effect.all([Stream.runForEach(child.stdout, (chunk) => Effect.sync(() => {
|
|
271
|
+
printed.push(chunk);
|
|
272
|
+
out.push(chunk);
|
|
273
|
+
})), Stream.runForEach(child.stderr, (chunk) => Effect.sync(() => printed.push(chunk)))], { concurrency: "unbounded" });
|
|
274
|
+
return yield* child.exitCode;
|
|
275
|
+
});
|
|
276
|
+
return {
|
|
277
|
+
status: yield* Effect.scoped(ran).pipe(Effect.orElseSucceed(() => null)),
|
|
278
|
+
printed,
|
|
279
|
+
out
|
|
280
|
+
};
|
|
281
|
+
});
|
|
282
|
+
/**
|
|
283
|
+
* `packedFrom`'s packs, each into `folder`, a folder of their own. They run side by side: each
|
|
284
|
+
* package's `prepack` builds and writes only in its own folder, and reads the others' source, as
|
|
285
|
+
* their `exports` name it, never their `dist/`. Their lines print first, in `vendorPacks`' order,
|
|
286
|
+
* and the packs are read in that order once all have ended, so the first that failed is named.
|
|
287
|
+
*/
|
|
288
|
+
const packedInto = Effect.fnUntraced(function* (checkout, folder) {
|
|
289
|
+
const fs = yield* FileSystem.FileSystem;
|
|
290
|
+
const path = yield* Path.Path;
|
|
291
|
+
const vendor = /* @__PURE__ */ new Map();
|
|
292
|
+
yield* say(...vendorPacks.map((each) => ` Packing ${each.name} into ${each.into}/...`));
|
|
293
|
+
const packs = yield* Effect.forEach(vendorPacks, Effect.fnUntraced(function* (each) {
|
|
294
|
+
const destination = `${folder}/${each.into}`;
|
|
295
|
+
yield* fs.makeDirectory(destination, { recursive: true }).pipe(Effect.mapError(diskFailed(`make ${printable(destination)}`)));
|
|
296
|
+
return {
|
|
297
|
+
each,
|
|
298
|
+
destination,
|
|
299
|
+
ran: yield* packOnce(`${checkout}/packages/${each.folder}`, destination)
|
|
300
|
+
};
|
|
301
|
+
}), { concurrency: vendorPacks.length });
|
|
302
|
+
for (const { each, destination, ran } of packs) {
|
|
303
|
+
const where = printable(`${checkout}/packages/${each.folder}`);
|
|
304
|
+
if (ran.status !== 0) {
|
|
305
|
+
yield* stderrText(new TextDecoder().decode(joinedBytes(ran.printed)));
|
|
306
|
+
return {
|
|
307
|
+
kind: "failed",
|
|
308
|
+
why: `pnpm pack failed in ${where}`
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
const made = yield* readPacked(lastObject(new TextDecoder().decode(joinedBytes(ran.out)))).pipe(Effect.option);
|
|
312
|
+
const file = Option.isSome(made) ? path.basename(path.resolve(destination, made.value.filename)) : void 0;
|
|
313
|
+
if (Option.isNone(made) || made.value.name !== each.name || file === void 0 || file === "") return {
|
|
314
|
+
kind: "failed",
|
|
315
|
+
why: `pnpm pack in ${where} didn't say it made ${each.name}`
|
|
316
|
+
};
|
|
317
|
+
if (!published.test(made.value.version)) return {
|
|
318
|
+
kind: "failed",
|
|
319
|
+
why: `pnpm pack in ${where} made ${file} at version ${made.value.version}, which isn't a version npm publishes: npm takes semver's MAJOR.MINOR.PATCH, with no leading v or =`
|
|
320
|
+
};
|
|
321
|
+
vendor.set(each.name, `${each.into}/${file}`);
|
|
322
|
+
}
|
|
323
|
+
return {
|
|
324
|
+
kind: "packed",
|
|
325
|
+
packed: {
|
|
326
|
+
folder,
|
|
327
|
+
vendor
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
});
|
|
331
|
+
/** `<manager> install` in `cwd`, as `runChild` runs it: its exit status, `null` if it never ran. */
|
|
332
|
+
const install = (manager, cwd) => runChild([manager, "install"], cwd).pipe(Effect.map((ended) => ended.exit));
|
|
333
|
+
const literals = (name, values, says) => Flag.Literals(name, values).pipe(Flag.withDescription(says), Flag.optional);
|
|
334
|
+
const toggle = (name, says) => Flag.Boolean(name).pipe(Flag.withDescription(says), Flag.optional);
|
|
335
|
+
const dirArgument = (says) => Argument.String("DIR").pipe(Argument.withDescription(says), Argument.optional);
|
|
336
|
+
/** A command's argv after `ref0-git`, as it was run, for a next step that runs it again. */
|
|
337
|
+
const asRun = () => process.argv.slice(2);
|
|
338
|
+
/** `init`'s flags that take a value as the next argument. */
|
|
339
|
+
const valueFlags = new Set([
|
|
340
|
+
"serve",
|
|
341
|
+
"platform",
|
|
342
|
+
"records",
|
|
343
|
+
"objects",
|
|
344
|
+
"bucket",
|
|
345
|
+
"base-path",
|
|
346
|
+
"name",
|
|
347
|
+
"package-manager",
|
|
348
|
+
"from-checkout",
|
|
349
|
+
"vercel-plan"
|
|
350
|
+
].map((flag) => `--${flag}`));
|
|
351
|
+
/**
|
|
352
|
+
* `args` without each of `flags`, and the value of one that takes a value, as the next argument
|
|
353
|
+
* or after `=`.
|
|
354
|
+
*/
|
|
355
|
+
const without = (args, flags) => args.filter((arg, at) => !flags.some((flag) => arg === flag || arg.startsWith(`${flag}=`)) && !(flags.includes(args[at - 1] ?? "") && valueFlags.has(args[at - 1] ?? "")));
|
|
356
|
+
/** Every spelling of each choice's flag, as `init` takes it. */
|
|
357
|
+
const choiceFlags = choices.flatMap((choice) => [`--${choice.flag}`, `--no-${choice.flag}`]);
|
|
358
|
+
/** The flags whose answers follow the platform's, which a move back to Cloudflare could refuse. */
|
|
359
|
+
const platformFlags = [
|
|
360
|
+
"--records",
|
|
361
|
+
"--bucket",
|
|
362
|
+
"--vercel-plan"
|
|
363
|
+
];
|
|
364
|
+
/**
|
|
365
|
+
* The ways out of `app_held`, as commands: this one serving GitHub on Cloudflare, which keeps the app, or the
|
|
366
|
+
* same flags for a new folder beside this one, for Git without it.
|
|
367
|
+
*/
|
|
368
|
+
const keepOrMove = (folder) => {
|
|
369
|
+
const [command = "init", ...rest] = asRun();
|
|
370
|
+
const at = rest.findIndex((arg, index) => folder.argv.includes(arg) && !valueFlags.has(rest[index - 1] ?? ""));
|
|
371
|
+
const flags = rest.filter((_, index) => index !== at);
|
|
372
|
+
const serving = without(flags.filter((arg) => arg !== "--no-app"), [
|
|
373
|
+
"--serve",
|
|
374
|
+
"--platform",
|
|
375
|
+
...platformFlags
|
|
376
|
+
]);
|
|
377
|
+
return {
|
|
378
|
+
says: "Keep the app, serving GitHub, or set up Git without it in a new folder",
|
|
379
|
+
run: [[
|
|
380
|
+
command,
|
|
381
|
+
...folder.argv,
|
|
382
|
+
...serving,
|
|
383
|
+
"--serve",
|
|
384
|
+
"github"
|
|
385
|
+
], [
|
|
386
|
+
command,
|
|
387
|
+
`${folder.path}-git`,
|
|
388
|
+
...flags
|
|
389
|
+
]]
|
|
390
|
+
};
|
|
391
|
+
};
|
|
392
|
+
/** The receipt's row for a settled choice: its words, and why or where from. */
|
|
393
|
+
const rowOf = (choice, settled, context) => {
|
|
394
|
+
const offer = saysOf(choice, settled.value, context);
|
|
395
|
+
const why = settled.from === "flag" ? `, from ${choice.named(settled.value)[0] ?? `--${choice.flag}`}` : settled.from === "detected" ? `, from ${settled.detectedFrom ?? "the folder"}` : offer.why === "" ? "" : `: ${offer.why}`;
|
|
396
|
+
return field([choice.row, `${offer.says}${why}`]);
|
|
397
|
+
};
|
|
398
|
+
/**
|
|
399
|
+
* Writes each step that changes a file, making its folders, and answers the paths written. A
|
|
400
|
+
* cancel waits until it ends, since it's uninterruptible: every file lands, or a failure names the
|
|
401
|
+
* one that stopped it and those written before.
|
|
402
|
+
*/
|
|
403
|
+
const written = Effect.fnUntraced(function* (folder, steps) {
|
|
404
|
+
const fs = yield* FileSystem.FileSystem;
|
|
405
|
+
const wrote = [];
|
|
406
|
+
for (const step of steps) {
|
|
407
|
+
const { text } = step;
|
|
408
|
+
if (text === void 0 || step.action === "unchanged" || step.action === "differs") continue;
|
|
409
|
+
const file = `${folder}/${step.path}`;
|
|
410
|
+
yield* Effect.gen(function* () {
|
|
411
|
+
yield* fs.makeDirectory(file.slice(0, file.lastIndexOf("/")), { recursive: true });
|
|
412
|
+
if (step.secrets !== void 0 && (yield* fs.exists(file))) yield* fs.chmod(file, 384);
|
|
413
|
+
yield* fs.writeFileString(file, text, step.secrets === void 0 ? {} : { mode: 384 });
|
|
414
|
+
}).pipe(Effect.mapError((error) => diskFailed(`write ${step.path}${wrote.length === 0 ? "" : `, after ${wrote.join(", ")}`}`)(error)));
|
|
415
|
+
wrote.push(step.path);
|
|
416
|
+
}
|
|
417
|
+
return wrote;
|
|
418
|
+
}, Effect.uninterruptible);
|
|
419
|
+
/**
|
|
420
|
+
* The plan carried out: printed under `--dry-run`; refused whole when a file differs, so nothing
|
|
421
|
+
* changes; else written, installed, and said, with the next step `doctor`.
|
|
422
|
+
*/
|
|
423
|
+
const finish = Effect.fnUntraced(function* (flags, folder, project, settled, output, steps, packed, create) {
|
|
424
|
+
const mode = yield* CliModes;
|
|
425
|
+
const manager = Option.getOrElse(flags.packageManager, () => project.packageManager.value);
|
|
426
|
+
const doctorStep = {
|
|
427
|
+
says: output.next,
|
|
428
|
+
run: [["doctor", ...folder.argv]]
|
|
429
|
+
};
|
|
430
|
+
const differs = steps.filter((step) => step.action === "differs");
|
|
431
|
+
const changes = steps.filter((step) => step.text !== void 0 && step.action !== "unchanged");
|
|
432
|
+
const installed = yield* (yield* FileSystem.FileSystem).exists(`${folder.path}/node_modules/@ref0/git`).pipe(Effect.orElseSucceed(() => false));
|
|
433
|
+
const installing = flags.install && !flags.dryRun && (changes.some((step) => step.path === "package.json") || !installed);
|
|
434
|
+
const documentOf = (ran) => ({
|
|
435
|
+
folder: folder.path,
|
|
436
|
+
project: project.project,
|
|
437
|
+
dryRun: flags.dryRun,
|
|
438
|
+
moves: movesOf(settled),
|
|
439
|
+
choices: {
|
|
440
|
+
...Object.fromEntries(Object.entries(settled).filter(([key, each]) => key !== "vercelPlan" || each.value !== "none")),
|
|
441
|
+
framework: project.framework === void 0 ? null : create === void 0 ? {
|
|
442
|
+
value: project.framework.name,
|
|
443
|
+
from: "detected",
|
|
444
|
+
detectedFrom: "package.json"
|
|
445
|
+
} : {
|
|
446
|
+
value: project.framework.name,
|
|
447
|
+
from: "flag"
|
|
448
|
+
},
|
|
449
|
+
name: {
|
|
450
|
+
value: project.name,
|
|
451
|
+
from: "detected"
|
|
452
|
+
},
|
|
453
|
+
packageManager: Option.isSome(flags.packageManager) ? {
|
|
454
|
+
value: manager,
|
|
455
|
+
from: "flag"
|
|
456
|
+
} : project.packageManager
|
|
457
|
+
},
|
|
458
|
+
files: steps.map((step) => {
|
|
459
|
+
const added = flags.dryRun && create !== void 0 && step.action === "merge" && step.path === "package.json" && step.from !== void 0 && step.text !== void 0 ? addedTo(step.from, step.text) : void 0;
|
|
460
|
+
return {
|
|
461
|
+
path: step.path,
|
|
462
|
+
action: step.action,
|
|
463
|
+
secrets: step.secrets,
|
|
464
|
+
content: flags.dryRun && step.secrets === void 0 && step.action === "create" ? step.text : void 0,
|
|
465
|
+
patch: added === void 0 && (flags.dryRun || step.action === "differs") ? step.patch : void 0,
|
|
466
|
+
adds: added,
|
|
467
|
+
edit: step.edit
|
|
468
|
+
};
|
|
469
|
+
}),
|
|
470
|
+
manual: output.manual,
|
|
471
|
+
needs: output.needs,
|
|
472
|
+
create: create === void 0 ? void 0 : {
|
|
473
|
+
command: {
|
|
474
|
+
line: create.command.line,
|
|
475
|
+
argv: create.command.argv
|
|
476
|
+
},
|
|
477
|
+
exit: create.exit
|
|
478
|
+
},
|
|
479
|
+
install: {
|
|
480
|
+
manager,
|
|
481
|
+
packages: output.packages.map((each) => `${each}@${release}`),
|
|
482
|
+
ran
|
|
483
|
+
},
|
|
484
|
+
nextStep: nextDocument(doctorStep)
|
|
485
|
+
});
|
|
486
|
+
const manualLines = output.manual.flatMap((step) => [
|
|
487
|
+
"",
|
|
488
|
+
` ${step.says}, in ${step.path}:`,
|
|
489
|
+
...step.lines
|
|
490
|
+
]);
|
|
491
|
+
const editLines = steps.flatMap(({ path, edit }) => edit === void 0 ? [] : [
|
|
492
|
+
"",
|
|
493
|
+
...edit.adds.length > 0 ? [` Adds after \`${edit.anchor}\`, in ${path}:`, ...edit.adds] : [],
|
|
494
|
+
...edit.swaps.map((swap) => ` Swaps ${swap.from} for ${swap.to}, in ${path}`)
|
|
495
|
+
]);
|
|
496
|
+
if (flags.dryRun) {
|
|
497
|
+
if (mode.json) return yield* cliDocument(initJson, documentOf(false));
|
|
498
|
+
if (manualLines.length > 0) yield* say(...manualLines);
|
|
499
|
+
if (editLines.length > 0) yield* say(...editLines);
|
|
500
|
+
return yield* answer([...create === void 0 ? [] : [`run\t${create.command.line}`], ...steps.map((step) => `${step.action}\t${step.path}`)].join("\n"));
|
|
501
|
+
}
|
|
502
|
+
if (differs.length > 0) {
|
|
503
|
+
if (!mode.json) yield* say(...differs.flatMap((step) => ["", ...(step.patch ?? "").trimEnd().split("\n")]));
|
|
504
|
+
return yield* Effect.fail(new CliFailure({
|
|
505
|
+
class: "failed",
|
|
506
|
+
reason: "file_differs",
|
|
507
|
+
headline: `${differs.map((step) => step.path).join(", ")} changed since init wrote ${differs.length === 1 ? "it" : "them"}, so init changed nothing`,
|
|
508
|
+
next: {
|
|
509
|
+
says: "Apply the change by hand, or move the file aside and run init again",
|
|
510
|
+
run: [asRun()]
|
|
511
|
+
},
|
|
512
|
+
data: { files: differs.map((step) => ({
|
|
513
|
+
path: step.path,
|
|
514
|
+
patch: step.patch
|
|
515
|
+
})) }
|
|
516
|
+
}));
|
|
517
|
+
}
|
|
518
|
+
const placed = packed === void 0 ? void 0 : yield* vendored(packed, folder.path);
|
|
519
|
+
if (placed?.kind === "refused") return yield* failure("install_failed", `The packed tarballs didn't go into ${printable(folder.path)}/vendor: ${placed.why}, so init wrote nothing`, {
|
|
520
|
+
says: "Make vendor/ a folder init can write into, then run init again",
|
|
521
|
+
run: [asRun()]
|
|
522
|
+
});
|
|
523
|
+
if (placed?.kind === "stranded") return yield* failure("install_failed", `The packed tarballs didn't go into ${printable(folder.path)}/vendor: ${placed.why}, and init couldn't put back what it moved, each named above`, {
|
|
524
|
+
says: "Put each back by hand, then run init again",
|
|
525
|
+
run: [asRun()]
|
|
526
|
+
});
|
|
527
|
+
const wrote = yield* written(folder.path, steps);
|
|
528
|
+
const kept = wrote.length === 0 ? "no files" : wrote.length <= 8 ? wrote.join(", ") : `${wrote.length} files: ${wrote.filter((path) => !path.includes("/")).join(", ")} and the app's pages`;
|
|
529
|
+
const installStep = {
|
|
530
|
+
says: `Run \`${manager} install\` in ${printable(folder.path)}, then check it`,
|
|
531
|
+
run: [["doctor", ...folder.argv]]
|
|
532
|
+
};
|
|
533
|
+
if (installing) {
|
|
534
|
+
cancelled.left = new CliFailure({
|
|
535
|
+
class: "cancelled",
|
|
536
|
+
reason: "canceled",
|
|
537
|
+
headline: `Canceled during the install, having written ${kept}`,
|
|
538
|
+
next: installStep
|
|
539
|
+
});
|
|
540
|
+
yield* say(` Installing ${output.packages.length} packages with ${manager}...`);
|
|
541
|
+
const status = yield* install(manager, folder.path);
|
|
542
|
+
delete cancelled.left;
|
|
543
|
+
if (status !== 0) return yield* failure("install_failed", `${manager} install failed, after init wrote ${kept}`, installStep);
|
|
544
|
+
}
|
|
545
|
+
if (output.manual.length > 0) {
|
|
546
|
+
if (!mode.json) yield* say(...manualLines);
|
|
547
|
+
return yield* Effect.fail(new CliFailure({
|
|
548
|
+
class: "failed",
|
|
549
|
+
reason: "manual_step",
|
|
550
|
+
headline: `Git's files are written, and ${output.manual.map((step) => step.path).join(" and ")} need${output.manual.length === 1 ? "s" : ""} the lines above`,
|
|
551
|
+
next: {
|
|
552
|
+
says: "Add them, then check it",
|
|
553
|
+
run: [["doctor", ...folder.argv]]
|
|
554
|
+
},
|
|
555
|
+
data: documentOf(installing)
|
|
556
|
+
}));
|
|
557
|
+
}
|
|
558
|
+
if (mode.json) return yield* cliDocument(initJson, documentOf(installing));
|
|
559
|
+
if (!mode.stdoutTerminal || !mode.interactive) yield* answer(folder.path);
|
|
560
|
+
if (changes.length === 0) return yield* receipt({
|
|
561
|
+
done: `Nothing to change: ${printable(folder.path)} is set up as init writes it`,
|
|
562
|
+
next: doctorStep
|
|
563
|
+
});
|
|
564
|
+
const secret = changes.some((step) => step.secrets !== void 0);
|
|
565
|
+
yield* receipt({
|
|
566
|
+
done: `${project.project === "new" ? "Set up" : "Added"} Git hosting in ${printable(folder.path)}`,
|
|
567
|
+
fields: [
|
|
568
|
+
["Wrote", kept],
|
|
569
|
+
...secret ? [["Secret", output.secret]] : [],
|
|
570
|
+
...output.needs.length > 0 ? [["Still needed", output.needs.join(", ")]] : []
|
|
571
|
+
],
|
|
572
|
+
next: doctorStep
|
|
573
|
+
});
|
|
574
|
+
});
|
|
575
|
+
/**
|
|
576
|
+
* `--framework` read against the folder, before anything else is: in a project with frameworks,
|
|
577
|
+
* one of them, which detection then takes; in a folder holding at most `.git`, the new app to
|
|
578
|
+
* make; anywhere else, refused.
|
|
579
|
+
*/
|
|
580
|
+
const framed = Effect.fnUntraced(function* (named, app, view) {
|
|
581
|
+
if (named === void 0) return void 0;
|
|
582
|
+
if (Option.isSome(app)) return yield* usageFailure("app_choices_conflict", `--framework ${named} and ${app.value ? "--app" : "--no-app"} are one choice: pass one of them`);
|
|
583
|
+
const found = detectFrameworks(view);
|
|
584
|
+
if (found.length > 0) {
|
|
585
|
+
const picked = frameworkFor(found, named);
|
|
586
|
+
if (picked !== void 0 && "reason" in picked) return yield* usageFailure(picked.reason, picked.headline);
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
yield* holdsAtMostGit(named, view.entries);
|
|
590
|
+
return {
|
|
591
|
+
name: named,
|
|
592
|
+
says: newFramework(named).says
|
|
593
|
+
};
|
|
594
|
+
});
|
|
595
|
+
/**
|
|
596
|
+
* A create command runs in place, where a file it writes, or one beside it, would stop it, and
|
|
597
|
+
* create-nuxt's `--force` would write over it: the folder may hold `.git` alone.
|
|
598
|
+
*/
|
|
599
|
+
const holdsAtMostGit = (named, entries) => {
|
|
600
|
+
const present = entries.filter((entry) => entry !== ".git");
|
|
601
|
+
return present.length === 0 ? Effect.void : failure("framework_needs_new_project", `--framework ${named} runs its create command in a folder holding at most .git, and this one holds ${present.join(", ")}`, {
|
|
602
|
+
says: `Move ${present.length === 1 ? "it" : "them"} aside, or run init in an empty folder`,
|
|
603
|
+
run: [asRun()]
|
|
604
|
+
});
|
|
605
|
+
};
|
|
606
|
+
/**
|
|
607
|
+
* `named`'s create command run in `folder`, first: with stdin closed and its output on stderr. A
|
|
608
|
+
* failed one, or one that left no `package.json` naming the framework, is `create_failed`, and
|
|
609
|
+
* what it left stays. Answers the folder as it left it.
|
|
610
|
+
*/
|
|
611
|
+
const createIn = Effect.fnUntraced(function* (folder, named, command) {
|
|
612
|
+
const [program = "npx", ...args] = command.argv;
|
|
613
|
+
yield* (yield* FileSystem.FileSystem).makeDirectory(folder, { recursive: true }).pipe(Effect.mapError(diskFailed(`make ${printable(folder)}`)));
|
|
614
|
+
yield* holdsAtMostGit(named, (yield* viewOf(folder)).entries);
|
|
615
|
+
cancelled.left = new CliFailure({
|
|
616
|
+
class: "cancelled",
|
|
617
|
+
reason: "canceled",
|
|
618
|
+
headline: `Canceled during ${creators[named]}, before init wrote anything`,
|
|
619
|
+
next: void 0
|
|
620
|
+
});
|
|
621
|
+
yield* say(` Running ${command.line}...`);
|
|
622
|
+
const ended = yield* runChild([program, ...args], folder);
|
|
623
|
+
delete cancelled.left;
|
|
624
|
+
const view = yield* viewOf(folder);
|
|
625
|
+
if (ended.exit !== 0 || !created(named, view.read("package.json"))) {
|
|
626
|
+
const left = view.entries.filter((entry) => entry !== ".git");
|
|
627
|
+
const refused = createFailed(named, command, ended, left);
|
|
628
|
+
return yield* new CliFailure({
|
|
629
|
+
class: "failed",
|
|
630
|
+
reason: refused.reason,
|
|
631
|
+
headline: refused.headline,
|
|
632
|
+
next: {
|
|
633
|
+
says: left.length === 0 ? "Run init again" : `Remove ${left.join(", ")}, which it left, then run init again`,
|
|
634
|
+
run: [asRun()]
|
|
635
|
+
},
|
|
636
|
+
data: refused.data
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
return {
|
|
640
|
+
view,
|
|
641
|
+
created: {
|
|
642
|
+
command,
|
|
643
|
+
exit: ended.exit
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
});
|
|
647
|
+
/**
|
|
648
|
+
* The folder Git goes in, and its project: as found, or, for `--framework`, as its create command
|
|
649
|
+
* leaves it, run first, or under `--dry-run` as its template would.
|
|
650
|
+
*/
|
|
651
|
+
const madeFor = Effect.fnUntraced(function* (creating, flags, folder, view, project, chosen) {
|
|
652
|
+
if (creating === void 0) return {
|
|
653
|
+
view,
|
|
654
|
+
project,
|
|
655
|
+
created: void 0
|
|
656
|
+
};
|
|
657
|
+
const manager = Option.getOrElse(flags.packageManager, () => project.packageManager.value);
|
|
658
|
+
const command = createCommand(creating.name, ".", manager, chosen.platform);
|
|
659
|
+
const left = flags.dryRun ? {
|
|
660
|
+
view: creatorFolder(creating.name, view, project.name),
|
|
661
|
+
created: {
|
|
662
|
+
command,
|
|
663
|
+
exit: null
|
|
664
|
+
}
|
|
665
|
+
} : yield* createIn(folder, creating.name, command);
|
|
666
|
+
const after = yield* projectIn(left.view, chosen.platform);
|
|
667
|
+
return {
|
|
668
|
+
view: left.view,
|
|
669
|
+
project: {
|
|
670
|
+
...after,
|
|
671
|
+
name: project.name,
|
|
672
|
+
project: project.project,
|
|
673
|
+
created: true
|
|
674
|
+
},
|
|
675
|
+
created: left.created
|
|
676
|
+
};
|
|
677
|
+
});
|
|
678
|
+
const init = Command.make("init", {
|
|
679
|
+
dir: dirArgument("The folder to set up, made when it doesn't exist: the current one when left out"),
|
|
680
|
+
serve: literals("serve", [
|
|
681
|
+
"github",
|
|
682
|
+
"api",
|
|
683
|
+
"git"
|
|
684
|
+
], "What to serve: GitHub's APIs, Git's REST, or Git's protocol only"),
|
|
685
|
+
app: toggle("app", "Add the web app, or --no-app for only the APIs"),
|
|
686
|
+
framework: literals("framework", creatable, "Make a new app with the framework's own create command, in an empty folder, then add Git to it"),
|
|
687
|
+
platform: literals("platform", [
|
|
688
|
+
"cloudflare",
|
|
689
|
+
"vercel",
|
|
690
|
+
"node"
|
|
691
|
+
], "Where it runs"),
|
|
692
|
+
records: literals("records", [
|
|
693
|
+
"durable-objects",
|
|
694
|
+
"postgres",
|
|
695
|
+
"turso",
|
|
696
|
+
"sqlite"
|
|
697
|
+
], "Where Git keeps its records"),
|
|
698
|
+
objects: literals("objects", ["packs", "loose"], "Packs in a bucket, or loose objects in the records"),
|
|
699
|
+
bucket: literals("bucket", [
|
|
700
|
+
"r2",
|
|
701
|
+
"vercel-blob",
|
|
702
|
+
"s3",
|
|
703
|
+
"disk"
|
|
704
|
+
], "The packs' bucket"),
|
|
705
|
+
queue: toggle("queue", "Run a merge queue on main, or --no-queue"),
|
|
706
|
+
vercelPlan: literals("vercel-plan", ["hobby", "pro"], "The Vercel team's plan, which sets the cron's schedule and a function's longest run"),
|
|
707
|
+
basePath: Flag.String("base-path").pipe(Flag.withDescription("The path Git's URLs are under, such as /git"), Flag.withMetavar("PATH"), Flag.optional),
|
|
708
|
+
name: Flag.String("name").pipe(Flag.withDescription("The Worker's name"), Flag.withMetavar("NAME"), Flag.optional),
|
|
709
|
+
packageManager: literals("package-manager", [
|
|
710
|
+
"npm",
|
|
711
|
+
"pnpm",
|
|
712
|
+
"yarn",
|
|
713
|
+
"bun"
|
|
714
|
+
], "The package manager that installs it"),
|
|
715
|
+
install: Flag.Boolean("install").pipe(Flag.withDescription("Install the packages once the files are written, or --no-install"), Flag.withDefault(true)),
|
|
716
|
+
yes: Flag.Boolean("yes").pipe(Flag.withDescription("Take the recommended answer for each choice the flags and the folder leave open"), Flag.withDefault(false)),
|
|
717
|
+
fromCheckout: Flag.String("from-checkout").pipe(Flag.withDescription("Take the app, Git's packages and ref0-git from a ref-0/git checkout, packed into vendor/, until they're on npm"), Flag.withMetavar("DIR"), Flag.optional),
|
|
718
|
+
dryRun: Flag.Boolean("dry-run").pipe(Flag.withDescription("Print the plan, each file and its action, and change nothing"), Flag.withDefault(false))
|
|
719
|
+
}, Effect.fnUntraced(function* (flags) {
|
|
720
|
+
const mode = yield* CliModes;
|
|
721
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
722
|
+
const folder = yield* folderOf(flags.dir);
|
|
723
|
+
const view = yield* viewOf(folder.path);
|
|
724
|
+
const creating = yield* framed(Option.getOrUndefined(flags.framework), flags.app, view);
|
|
725
|
+
const project = yield* projectIn(view, Option.getOrUndefined(flags.platform), Option.getOrUndefined(flags.framework));
|
|
726
|
+
const newApp = creating && {
|
|
727
|
+
says: creating.says,
|
|
728
|
+
platforms: createPlatforms[creating.name]
|
|
729
|
+
};
|
|
730
|
+
const named = Option.getOrUndefined(flags.name);
|
|
731
|
+
const placed = named === void 0 ? project : {
|
|
732
|
+
...project,
|
|
733
|
+
name: named
|
|
734
|
+
};
|
|
735
|
+
const flagged = {
|
|
736
|
+
serve: Option.getOrUndefined(flags.serve),
|
|
737
|
+
app: creating === void 0 ? Option.getOrUndefined(Option.map(flags.app, (on) => on ? "ref0" : "none")) : "framework",
|
|
738
|
+
platform: Option.getOrUndefined(flags.platform),
|
|
739
|
+
records: Option.getOrUndefined(flags.records),
|
|
740
|
+
objects: Option.getOrUndefined(flags.objects),
|
|
741
|
+
bucket: Option.getOrUndefined(flags.bucket),
|
|
742
|
+
queue: Option.getOrUndefined(Option.map(flags.queue, (on) => on ? "on" : "off")),
|
|
743
|
+
basePath: Option.getOrUndefined(flags.basePath),
|
|
744
|
+
vercelPlan: Option.getOrUndefined(flags.vercelPlan)
|
|
745
|
+
};
|
|
746
|
+
const given = Object.fromEntries(Object.entries(flagged).filter(([, value]) => value !== void 0));
|
|
747
|
+
cancelled.left = new CliFailure({
|
|
748
|
+
class: "cancelled",
|
|
749
|
+
reason: "canceled",
|
|
750
|
+
headline: "Canceled. Nothing was changed",
|
|
751
|
+
next: void 0
|
|
752
|
+
});
|
|
753
|
+
if (!mode.json) yield* say(field(["Folder", printable(project.says)]));
|
|
754
|
+
const others = othersRow(project.frameworks, project.framework);
|
|
755
|
+
if (!mode.json && project.framework !== void 0) yield* say(field(["Framework", printable(project.framework.row)]), ...others === void 0 ? [] : [field(["", printable(others)])]);
|
|
756
|
+
const { settled, chosen, open, conflicts } = yield* settle(given, project.detected, project.project, flags.yes, (choice, offers) => mode.interactive ? select(choice.row, choice.question, offers.map((offer, at) => ({
|
|
757
|
+
value: offer.value,
|
|
758
|
+
label: `${offer.says}${at === 0 ? " (recommended)" : ""}: ${offer.why}`
|
|
759
|
+
}))) : Effect.succeed(void 0), newApp, project.framework?.says ?? newApp?.says).pipe(Effect.mapError((refused) => usageFailure(refused.reason, refused.headline, refused.reason === "app_held" ? keepOrMove(folder) : void 0)));
|
|
760
|
+
const openChoices = choices.filter((choice) => open.includes(choice.key));
|
|
761
|
+
const settling = conflicts.filter((each) => each.change[0] === each.by[0]);
|
|
762
|
+
const shown = settling.length > 0 ? settling : conflicts;
|
|
763
|
+
const settles = recovered(given, project.detected, project.project, conflicts);
|
|
764
|
+
if (shown.length > 0) return yield* Effect.fail(new CliFailure({
|
|
765
|
+
class: "usage",
|
|
766
|
+
reason: "choices_open",
|
|
767
|
+
headline: shown.map((each) => `This setup has ${each.held.length > 0 ? each.held.join(" ") : `no ${each.key}`}, which ${each.by.length > 0 ? each.by.join(" ") : "the answers before it"} ${each.by.length > 2 ? "refuse" : "refuses"} (${each.refusal.headline}). Pass ${each.change.join(" ")} to ${each.change[0] === each.by[0] ? "settle" : "move"} it`).join("; "),
|
|
768
|
+
next: {
|
|
769
|
+
says: "Move each held answer with its flag",
|
|
770
|
+
run: [[...without(asRun(), choiceFlags), ...choices.flatMap((choice) => {
|
|
771
|
+
const value = settles[choice.key];
|
|
772
|
+
return value === void 0 ? [] : choice.named(value);
|
|
773
|
+
})]]
|
|
774
|
+
},
|
|
775
|
+
data: {
|
|
776
|
+
open,
|
|
777
|
+
conflicts: shown.map(({ key, held, by, change }) => ({
|
|
778
|
+
key,
|
|
779
|
+
held,
|
|
780
|
+
by,
|
|
781
|
+
change
|
|
782
|
+
}))
|
|
783
|
+
}
|
|
784
|
+
}));
|
|
785
|
+
if (open.length > 0) return yield* Effect.fail(new CliFailure({
|
|
786
|
+
class: "usage",
|
|
787
|
+
reason: "choices_open",
|
|
788
|
+
headline: `init can't ask here, and ${open.length} ${open.length === 1 ? "choice is" : "choices are"} open: ${openChoices.map((choice) => `--${choice.flag}`).join(", ")}`,
|
|
789
|
+
next: {
|
|
790
|
+
says: "Take the recommended answers, or name each one",
|
|
791
|
+
run: [[...asRun(), "--yes"], [...asRun(), ...openChoices.flatMap((choice) => choice.named(chosen[choice.key]))]]
|
|
792
|
+
},
|
|
793
|
+
data: {
|
|
794
|
+
open,
|
|
795
|
+
recommended: Object.fromEntries(open.map((key) => [key, chosen[key]]))
|
|
796
|
+
}
|
|
797
|
+
}));
|
|
798
|
+
const context = {
|
|
799
|
+
project: project.project,
|
|
800
|
+
chosen,
|
|
801
|
+
folder: platformOf(project.detected),
|
|
802
|
+
creating: newApp,
|
|
803
|
+
framework: project.framework?.says ?? newApp?.says
|
|
804
|
+
};
|
|
805
|
+
const rows = mode.json ? [] : choices.filter((each) => settled[each.key].from !== "prompt" && (each.shown?.(context) ?? true));
|
|
806
|
+
for (const choice of rows) yield* say(rowOf(choice, settled[choice.key], context));
|
|
807
|
+
if (!mode.json) yield* say(...movesOf(settled).map((move) => ` ${move}`));
|
|
808
|
+
const source = yield* sourceOf(Option.getOrUndefined(flags.fromCheckout), chosen.app === "ref0" || project.held?.app === "ref0");
|
|
809
|
+
const packing = source.checkout === void 0 || flags.dryRun ? void 0 : yield* packedFrom(source.checkout);
|
|
810
|
+
if (packing?.kind === "failed") return yield* failure("install_failed", `${packing.why}, so init wrote nothing`, {
|
|
811
|
+
says: "Fix the checkout so its packages pack, then run init again",
|
|
812
|
+
run: [asRun()]
|
|
813
|
+
});
|
|
814
|
+
const packed = packing?.packed;
|
|
815
|
+
return yield* Effect.ensuring(Effect.gen(function* () {
|
|
816
|
+
const made = yield* madeFor(creating, flags, folder.path, view, placed, chosen);
|
|
817
|
+
const vendor = source.checkout === void 0 ? void 0 : packed?.vendor ?? (yield* plannedVendor(source.checkout));
|
|
818
|
+
const output = outputOf(chosen, made.project, source, vendor);
|
|
819
|
+
const held = project.held === void 0 ? void 0 : outputOf({
|
|
820
|
+
...chosen,
|
|
821
|
+
...project.held
|
|
822
|
+
}, made.project, source, vendor);
|
|
823
|
+
const steps = plan(output.files, held?.files, made.view.read);
|
|
824
|
+
const links = [];
|
|
825
|
+
for (const step of steps) if (yield* linked(folder.path, step.path)) links.push(step.path);
|
|
826
|
+
if (links.length > 0) return yield* failure("file_is_link", `${links.join(", ")} ${links.length === 1 ? "is a link" : "are links"}, and init reads and writes only the folder's own files`, {
|
|
827
|
+
says: "Replace each with the file itself, then run init again",
|
|
828
|
+
run: [asRun()]
|
|
829
|
+
});
|
|
830
|
+
const tracked = yield* trackedSecrets(folder.path, secretFilesOf(chosen));
|
|
831
|
+
if (tracked.length > 0) return yield* failure("secrets_tracked", `${tracked.join(", ")} ${tracked.length === 1 ? "is" : "are"} tracked by Git, so the secrets init writes there would be in the next commit`, {
|
|
832
|
+
says: "Take it out of Git's index, keeping the file, then run init again",
|
|
833
|
+
run: [asRun()]
|
|
834
|
+
});
|
|
835
|
+
return yield* finish(flags, folder, made.project, settled, output, steps, packed, made.created);
|
|
836
|
+
}), packed === void 0 ? Effect.void : fileSystem.remove(packed.folder, {
|
|
837
|
+
recursive: true,
|
|
838
|
+
force: true
|
|
839
|
+
}).pipe(Effect.catch((error) => leftBehind(packed.folder, error))));
|
|
840
|
+
})).pipe(Command.withDescription("Set up Git hosting in a folder: a new Worker, or Git added to an existing one (experimental)"));
|
|
841
|
+
/** The prefix every scratch repo of `--verify`'s is under, so a run that died leaves findable ones. */
|
|
842
|
+
const scratchPrefix = "ref0-git-verify/";
|
|
843
|
+
/** The scratch repos a host still has. */
|
|
844
|
+
const leftovers = (host, client) => Effect.tryPromise({
|
|
845
|
+
try: async () => {
|
|
846
|
+
const found = [];
|
|
847
|
+
for await (const repo of paginate(client.repos.list, { prefix: scratchPrefix })) found.push(printable(repo));
|
|
848
|
+
return found;
|
|
849
|
+
},
|
|
850
|
+
catch: () => failure("unreachable", `${host} didn't list its scratch repos`)
|
|
851
|
+
});
|
|
852
|
+
/** How long each of `--verify`'s calls to the host may take, so a host that stops can't hold it. */
|
|
853
|
+
const callMs = 3e4;
|
|
854
|
+
/** `call`, given up after `callMs` as well as on the run's cancel. */
|
|
855
|
+
const bounded = (call) => (signal) => call(AbortSignal.any([signal, AbortSignal.timeout(callMs)]));
|
|
856
|
+
/** A create's failures that don't say the host made nothing: no answer, or its own failure. */
|
|
857
|
+
const unsettled = /^(unreachable|unavailable|deadline_exceeded|internal|data_loss)$/;
|
|
858
|
+
/**
|
|
859
|
+
* Creates a scratch repo, pushes a commit to it with a token of its own, reads it back and clones
|
|
860
|
+
* it, then, in a `finally`, revokes the token, deletes the repo by its name and lists what's left.
|
|
861
|
+
* A create the host may still finish can't be undone, so a repo whose create didn't succeed, a
|
|
862
|
+
* token whose ID never came and a failed clean-up call are named as maybe left.
|
|
863
|
+
*/
|
|
864
|
+
const verify = Effect.fnUntraced(function* (hostOption) {
|
|
865
|
+
const { host, client, origin, endpoint } = yield* remoteOf(yield* chosenHost(hostOption));
|
|
866
|
+
const now = yield* Clock.currentTimeMillis;
|
|
867
|
+
const repo = `${scratchPrefix}${now.toString(36)}${(yield* Random.nextIntBetween(0, 1679616)).toString(36).padStart(4, "0")}`;
|
|
868
|
+
const fs = yield* FileSystem.FileSystem;
|
|
869
|
+
const folder = yield* fs.makeTempDirectory({ prefix: "ref0-git-verify-" }).pipe(Effect.mapError(diskFailed("make a folder for the scratch repo")));
|
|
870
|
+
const steps = [];
|
|
871
|
+
/** What clean-up removes: the repo once its create was sent, and the token once it's known. */
|
|
872
|
+
const made = {
|
|
873
|
+
repo: false,
|
|
874
|
+
created: false,
|
|
875
|
+
token: "",
|
|
876
|
+
tokenSent: false
|
|
877
|
+
};
|
|
878
|
+
const left = [];
|
|
879
|
+
const run = (args, env = {}) => Effect.flatMap(gitRun(args, {
|
|
880
|
+
cwd: folder,
|
|
881
|
+
env
|
|
882
|
+
}), (ran) => ran.status === 0 ? Effect.succeed(ran.stdout) : Effect.fail(failure("verify_git", `git ${args[0] ?? ""} failed against ${host}`)));
|
|
883
|
+
const work = Effect.gen(function* () {
|
|
884
|
+
made.repo = true;
|
|
885
|
+
const created = yield* answered(host, bounded((signal) => client.repos.create({
|
|
886
|
+
id: repo,
|
|
887
|
+
signal
|
|
888
|
+
}))).pipe(Effect.tapError((failed) => Effect.sync(() => made.repo = unsettled.test(failed.reason))));
|
|
889
|
+
made.created = true;
|
|
890
|
+
steps.push("Created");
|
|
891
|
+
made.tokenSent = true;
|
|
892
|
+
const token = yield* answered(host, bounded((signal) => client.tokens.create(repo, {
|
|
893
|
+
scope: "write",
|
|
894
|
+
subject: { id: "ref0-git-verify" },
|
|
895
|
+
expiresAt: now + 36e5,
|
|
896
|
+
signal
|
|
897
|
+
}))).pipe(Effect.tapError((failed) => Effect.sync(() => made.tokenSent = unsettled.test(failed.reason))));
|
|
898
|
+
made.token = token.id;
|
|
899
|
+
secrets.hide(token.secret);
|
|
900
|
+
const identity = {
|
|
901
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
902
|
+
GIT_CONFIG_COUNT: "2",
|
|
903
|
+
GIT_CONFIG_KEY_0: "core.hooksPath",
|
|
904
|
+
GIT_CONFIG_VALUE_0: "/dev/null",
|
|
905
|
+
GIT_CONFIG_KEY_1: "commit.gpgsign",
|
|
906
|
+
GIT_CONFIG_VALUE_1: "false",
|
|
907
|
+
GIT_AUTHOR_NAME: "ref0-git doctor",
|
|
908
|
+
GIT_AUTHOR_EMAIL: "doctor@ref0.invalid",
|
|
909
|
+
GIT_COMMITTER_NAME: "ref0-git doctor",
|
|
910
|
+
GIT_COMMITTER_EMAIL: "doctor@ref0.invalid"
|
|
911
|
+
};
|
|
912
|
+
const signedIn = {
|
|
913
|
+
...identity,
|
|
914
|
+
REF0_GIT_VERIFY_TOKEN: token.secret,
|
|
915
|
+
GIT_CONFIG_COUNT: "4",
|
|
916
|
+
GIT_CONFIG_KEY_2: "credential.helper",
|
|
917
|
+
GIT_CONFIG_VALUE_2: "",
|
|
918
|
+
GIT_CONFIG_KEY_3: `credential.${origin}/.helper`,
|
|
919
|
+
GIT_CONFIG_VALUE_3: `!f() { test "$1" = get && printf 'username=ref0-git-verify\\npassword=%s\\n' "$REF0_GIT_VERIFY_TOKEN"; }; f`
|
|
920
|
+
};
|
|
921
|
+
const url = `${endpoint}/${repo}.git`;
|
|
922
|
+
const target = created.defaultBranch;
|
|
923
|
+
if (target === void 0) return yield* failure("verify_branch", `${host} made the repo with no default branch shown`);
|
|
924
|
+
if (!target.startsWith("refs/heads/") || printable(target) !== target) return yield* failure("verify_branch", `${host} made the repo with ${printable(target)}, not a branch`);
|
|
925
|
+
yield* run([
|
|
926
|
+
"init",
|
|
927
|
+
"-q",
|
|
928
|
+
"-b",
|
|
929
|
+
shortTarget(target),
|
|
930
|
+
"pushed"
|
|
931
|
+
]);
|
|
932
|
+
yield* run([
|
|
933
|
+
"-C",
|
|
934
|
+
"pushed",
|
|
935
|
+
"commit",
|
|
936
|
+
"-q",
|
|
937
|
+
"--allow-empty",
|
|
938
|
+
"-m",
|
|
939
|
+
"Check the host"
|
|
940
|
+
], identity);
|
|
941
|
+
yield* run([
|
|
942
|
+
"-C",
|
|
943
|
+
"pushed",
|
|
944
|
+
"push",
|
|
945
|
+
"-q",
|
|
946
|
+
url,
|
|
947
|
+
`HEAD:${target}`
|
|
948
|
+
], signedIn);
|
|
949
|
+
steps.push("pushed");
|
|
950
|
+
const head = (yield* run([
|
|
951
|
+
"-C",
|
|
952
|
+
"pushed",
|
|
953
|
+
"rev-parse",
|
|
954
|
+
"HEAD"
|
|
955
|
+
])).trim();
|
|
956
|
+
const read = yield* answered(host, (signal) => client.refs.get(repo, {
|
|
957
|
+
ref: target,
|
|
958
|
+
signal
|
|
959
|
+
}));
|
|
960
|
+
if (read.oid !== head) return yield* failure("verify_read", `${host} read back ${printable(read.oid)}, not the pushed ${head}`);
|
|
961
|
+
steps.push("read");
|
|
962
|
+
yield* run([
|
|
963
|
+
"clone",
|
|
964
|
+
"-q",
|
|
965
|
+
url,
|
|
966
|
+
"cloned"
|
|
967
|
+
], signedIn);
|
|
968
|
+
const cloned = (yield* run([
|
|
969
|
+
"-C",
|
|
970
|
+
"cloned",
|
|
971
|
+
"rev-parse",
|
|
972
|
+
"HEAD"
|
|
973
|
+
])).trim();
|
|
974
|
+
if (cloned !== head) return yield* failure("verify_clone", `The clone of ${repo} has ${cloned}, not ${head}`);
|
|
975
|
+
steps.push("cloned");
|
|
976
|
+
});
|
|
977
|
+
/** Whether `call` removed `what` in time, or found it gone where `gone` says that's settled. */
|
|
978
|
+
const removed = (what, call, gone = true) => Effect.tryPromise(bounded(call)).pipe(Effect.map((done) => done.kind === "success" || gone && done.error.code === "NOT_FOUND"), Effect.orElseSucceed(() => false), Effect.tap((done) => done ? Effect.void : Effect.sync(() => left.push(what))));
|
|
979
|
+
const cleanUpFailed = (headline) => failure("cleanup_failed", `${headline}, and may have left ${left.join(" and ")}`, {
|
|
980
|
+
says: `Check ${host} for it: a later \`doctor --verify\` lists scratch repos under Leftovers`,
|
|
981
|
+
run: []
|
|
982
|
+
});
|
|
983
|
+
const cleanUp = Effect.gen(function* () {
|
|
984
|
+
const token = made.token;
|
|
985
|
+
if (token !== "") yield* removed(`token ${token}`, (signal) => client.tokens.revoke(token, { signal }));
|
|
986
|
+
else if (made.tokenSent) left.push(`the token on ${repo}, which ends within the hour`);
|
|
987
|
+
const deleted = (signal) => client.repos.delete(repo, { signal });
|
|
988
|
+
if (made.repo && (yield* removed(repo, deleted, made.created))) steps.push("deleted");
|
|
989
|
+
yield* fs.remove(folder, {
|
|
990
|
+
recursive: true,
|
|
991
|
+
force: true
|
|
992
|
+
}).pipe(Effect.catch((error) => leftBehind(folder, error)));
|
|
993
|
+
if (left.length > 0) cancelled.left = cleanUpFailed("Canceled");
|
|
994
|
+
});
|
|
995
|
+
yield* work.pipe(Effect.ensuring(cleanUp), Effect.mapError((failed) => left.length === 0 ? failed : cleanUpFailed(failed.headline)));
|
|
996
|
+
if (left.length > 0) return yield* cleanUpFailed(`${host} works end to end`);
|
|
997
|
+
const found = yield* leftovers(host, client);
|
|
998
|
+
if ((yield* CliModes).json) return yield* cliDocument(verifyJson, {
|
|
999
|
+
host,
|
|
1000
|
+
repo,
|
|
1001
|
+
steps,
|
|
1002
|
+
leftovers: found
|
|
1003
|
+
});
|
|
1004
|
+
yield* receipt({
|
|
1005
|
+
done: `${host} works end to end`,
|
|
1006
|
+
fields: [["Scratch repo", `${repo}: ${steps.join(", ")}`], ["Leftovers", found.length === 0 ? "None" : found.join(", ")]]
|
|
1007
|
+
});
|
|
1008
|
+
});
|
|
1009
|
+
/**
|
|
1010
|
+
* The names `files` set, as `wrangler dev` reads `.dev.vars` and `vercel dev` its `.env` files: a
|
|
1011
|
+
* name counts only with a value after its `=`, which is matched and never read, as it's a secret.
|
|
1012
|
+
*/
|
|
1013
|
+
const devVars = (view, files = [".dev.vars"]) => new Set(files.flatMap((file) => [...(view.read(file) ?? "").matchAll(/^[ \t]*([A-Za-z_][\w.-]*)[ \t]*=[ \t]*\S/gm)].map((line) => line[1] ?? "")));
|
|
1014
|
+
/**
|
|
1015
|
+
* Whether a Start app's route file `name`, as `api.v3.$.ts`, takes one of the drop-in's root
|
|
1016
|
+
* prefixes: its name, `.` read as `/`, is the prefix or under it, as Start reads a flat route.
|
|
1017
|
+
*/
|
|
1018
|
+
const takesDropIn = (name) => {
|
|
1019
|
+
const path = name.replaceAll(".", "/");
|
|
1020
|
+
return dropInPrefixes.some((route) => path === route.path || path.startsWith(`${route.path}/`));
|
|
1021
|
+
};
|
|
1022
|
+
/** The secrets a host's Worker takes for `choices`: the app's, as its descriptor lists them, or Git's. */
|
|
1023
|
+
const secretsOf = (choices) => choices.app === "ref0" ? platforms.cloudflare.secrets : gitSecrets;
|
|
1024
|
+
/** Whether `doctor` finds `src/git.ts` and the files `init` wrote beside it as it wrote them. */
|
|
1025
|
+
const filesFinding = (view, project, chosen, source) => {
|
|
1026
|
+
const steps = plan(outputOf(chosen, project, source).files, void 0, view.read);
|
|
1027
|
+
const missing = steps.filter((step) => step.action === "create").map((step) => step.path);
|
|
1028
|
+
const edited = steps.filter((step) => step.action === "differs").map((step) => step.path);
|
|
1029
|
+
return {
|
|
1030
|
+
check: "Files",
|
|
1031
|
+
ok: project.held !== void 0 && missing.length === 0,
|
|
1032
|
+
says: project.held === void 0 ? "Git is not set up here: no src/git.ts that init wrote" : missing.length > 0 ? `${missing.join(", ")} ${missing.length === 1 ? "is" : "are"} missing` : edited.length > 0 ? `As init wrote them, but ${edited.join(", ")}, edited` : "As init wrote them",
|
|
1033
|
+
blocks: "deploying: run init to write them"
|
|
1034
|
+
};
|
|
1035
|
+
};
|
|
1036
|
+
/** Whether Git's packages are installed in `folder`. */
|
|
1037
|
+
const installedFinding = (project, disk) => ({
|
|
1038
|
+
check: "Installed",
|
|
1039
|
+
ok: disk.installed,
|
|
1040
|
+
says: disk.installed ? "Git's packages, in node_modules" : `Git's packages aren't installed: run \`${project.packageManager.value} install\``,
|
|
1041
|
+
blocks: "running it"
|
|
1042
|
+
});
|
|
1043
|
+
/** `folder`'s `Disk`, for `chosen`: the app's local SQLite is read only where it keeps its records. */
|
|
1044
|
+
const diskOf = Effect.fnUntraced(function* (folder, project, chosen) {
|
|
1045
|
+
const fs = yield* FileSystem.FileSystem;
|
|
1046
|
+
const sqlite = yield* Sqlite;
|
|
1047
|
+
const { database } = platforms.node;
|
|
1048
|
+
const listed = (at) => Effect.flatMap(fs.exists(at), (there) => there ? fs.readDirectory(at) : Effect.succeed([]));
|
|
1049
|
+
const data = `${folder}/.data`;
|
|
1050
|
+
const dataWritable = yield* fs.exists(data).pipe(Effect.flatMap((there) => fs.access(there ? data : folder, { writable: true })), Effect.as(true), Effect.orElseSucceed(() => false));
|
|
1051
|
+
const local = chosen.platform === "node" && project.held?.app === "ref0" && chosen.records === "sqlite";
|
|
1052
|
+
const file = `${folder}/${database.file}`;
|
|
1053
|
+
const migrated = local ? yield* sqlite.migrated(file).pipe(Effect.mapError((unreadable) => failure("database_unreadable", `${printable(database.file)} isn't a SQLite database doctor can read: ${printable(String(unreadable.cause))}`, "Check the file, then run `npm run migrate` again"))) : /* @__PURE__ */ new Set();
|
|
1054
|
+
return {
|
|
1055
|
+
installed: yield* fs.exists(`${folder}/node_modules/@ref0/git`),
|
|
1056
|
+
dataWritable,
|
|
1057
|
+
sources: yield* listed(`${folder}/src`),
|
|
1058
|
+
routes: yield* listed(`${folder}/src/routes`),
|
|
1059
|
+
migrations: (yield* listed(`${folder}/${database.migrations}`)).filter((each) => each.endsWith(".sql")),
|
|
1060
|
+
migrated
|
|
1061
|
+
};
|
|
1062
|
+
}, (reading, folder) => Effect.catchTag(reading, "PlatformError", (error) => Effect.fail(diskFailed(`read ${printable(folder)}`)(error))));
|
|
1063
|
+
const starters = {
|
|
1064
|
+
next: (framework) => ({
|
|
1065
|
+
file: framework.instrumentation,
|
|
1066
|
+
path: "instrumentation.ts",
|
|
1067
|
+
lines: "register()",
|
|
1068
|
+
server: "next start",
|
|
1069
|
+
start: (manager) => `\`${manager} start\`, which loads .env`
|
|
1070
|
+
}),
|
|
1071
|
+
sveltekit: (framework) => ({
|
|
1072
|
+
file: framework.hooks?.server,
|
|
1073
|
+
path: "src/hooks.server.ts",
|
|
1074
|
+
lines: "init hook",
|
|
1075
|
+
server: "adapter-node's server",
|
|
1076
|
+
start: (manager) => `\`${manager} start\`, which loads .env`
|
|
1077
|
+
}),
|
|
1078
|
+
nuxt: (framework) => ({
|
|
1079
|
+
file: framework.nitro?.plugin,
|
|
1080
|
+
path: nuxtJobsPlugin,
|
|
1081
|
+
lines: "Nitro plugin",
|
|
1082
|
+
server: "Nitro's Node server",
|
|
1083
|
+
start: () => "`node .output/server/index.mjs`"
|
|
1084
|
+
}),
|
|
1085
|
+
astro: () => void 0,
|
|
1086
|
+
"react-router": () => void 0,
|
|
1087
|
+
hono: () => void 0,
|
|
1088
|
+
express: () => void 0,
|
|
1089
|
+
fastify: () => void 0
|
|
1090
|
+
};
|
|
1091
|
+
const startersOf = (framework) => starters[framework.name](framework);
|
|
1092
|
+
/**
|
|
1093
|
+
* How a person starts a routed framework's build, whose server module loads `.env` itself:
|
|
1094
|
+
* Astro's template has no start script, so `@astrojs/node`'s standalone server, and React Router's
|
|
1095
|
+
* template's `start` runs `react-router-serve`.
|
|
1096
|
+
*/
|
|
1097
|
+
const routedStart = (framework, manager) => framework?.name === "astro" ? "`node ./dist/server/entry.mjs`" : `\`${manager} start\``;
|
|
1098
|
+
/** `doctor`'s SvelteKit checks: adapter-node's body limit, and `hooks.ts`'s reroute of `gh`'s root URLs. */
|
|
1099
|
+
const svelteFindings = (view, framework, chosen) => {
|
|
1100
|
+
const lifted = svelteBodyLimit((path) => view.read(path), process.env);
|
|
1101
|
+
const universal = framework.hooks?.universal;
|
|
1102
|
+
const rerouted = universal !== void 0 && universal.text.includes("gitRoot");
|
|
1103
|
+
const { adapter } = framework;
|
|
1104
|
+
return [
|
|
1105
|
+
{
|
|
1106
|
+
check: "Adapter",
|
|
1107
|
+
ok: adapter?.name === "node",
|
|
1108
|
+
says: adapter?.name === "node" ? `${adapter.file} builds with adapter-node, whose server runs Git's jobs between requests` : `${adapter?.file ?? "vite.config.ts"} builds with ${adapter === void 0 ? "no adapter" : `adapter-${adapter.name}`}: build with adapter-node, as init printed, so node build serves Git and runs its jobs`,
|
|
1109
|
+
blocks: "node build, and Git's jobs"
|
|
1110
|
+
},
|
|
1111
|
+
{
|
|
1112
|
+
check: "Body limit",
|
|
1113
|
+
ok: lifted !== void 0,
|
|
1114
|
+
says: lifted !== void 0 ? `${lifted} sets BODY_SIZE_LIMIT=Infinity for node build, which lifts adapter-node's 512 KB for every route: set it where the server runs too` : `node build keeps a body limit, adapter-node's 512 KB unless BODY_SIZE_LIMIT says another: start it with ${svelteStart}, and set BODY_SIZE_LIMIT=Infinity in .env and where the server runs`,
|
|
1115
|
+
blocks: "pushes over 512 KB"
|
|
1116
|
+
},
|
|
1117
|
+
...chosen.serve === "github" ? [{
|
|
1118
|
+
check: "Root URLs",
|
|
1119
|
+
ok: rerouted,
|
|
1120
|
+
says: rerouted ? `${universal.path} reroutes gh's /<owner>/<repo>.git/ URLs to ${chosen.basePath}` : `${universal?.path ?? "No src/hooks.ts"} reroutes no /<owner>/<repo>.git/ URL, so gh repo clone gets SvelteKit's 404: add the reroute init printed`,
|
|
1121
|
+
blocks: "gh repo clone and gh pr checkout"
|
|
1122
|
+
}] : []
|
|
1123
|
+
];
|
|
1124
|
+
};
|
|
1125
|
+
/** The Node checks every server shares: `.data` writable, the packages installed and `.env` set. */
|
|
1126
|
+
const localFindings = (project, chosen, disk, view) => {
|
|
1127
|
+
const variables = [...gitSecrets, ...nodeNeeds(chosen)];
|
|
1128
|
+
const set = devVars(view, [".env"]);
|
|
1129
|
+
const unset = variables.filter((name) => !set.has(name));
|
|
1130
|
+
const canWrite = disk.dataWritable;
|
|
1131
|
+
return [
|
|
1132
|
+
...keepsData(chosen) ? [{
|
|
1133
|
+
check: "Data",
|
|
1134
|
+
ok: canWrite,
|
|
1135
|
+
says: canWrite ? ".data, writable" : "This process can't write .data",
|
|
1136
|
+
blocks: "starting it: Git keeps its records and packs there"
|
|
1137
|
+
}] : [],
|
|
1138
|
+
installedFinding(project, disk),
|
|
1139
|
+
{
|
|
1140
|
+
check: "Variables",
|
|
1141
|
+
ok: unset.length === 0,
|
|
1142
|
+
says: unset.length === 0 ? `${variables.join(", ")}, set in .env` : `${unset.join(", ")} ${unset.length === 1 ? "is" : "are"} not set in .env`,
|
|
1143
|
+
blocks: "starting it: src/git.ts stops without them"
|
|
1144
|
+
}
|
|
1145
|
+
];
|
|
1146
|
+
};
|
|
1147
|
+
/**
|
|
1148
|
+
* What `doctor` finds in a Node project `init` set up: its files, a server that serves Git and
|
|
1149
|
+
* runs its jobs, a data folder it can write, the dependencies installed, and `.env`'s variables.
|
|
1150
|
+
*/
|
|
1151
|
+
const nodeFindings = (view, project, chosen, disk, source) => {
|
|
1152
|
+
if (project.held?.app === "ref0") return nodeAppFindings(view, project, chosen, disk, source);
|
|
1153
|
+
const { sources } = disk;
|
|
1154
|
+
const entry = sources.find((file) => {
|
|
1155
|
+
const text = file === "git.ts" ? "" : view.read(`src/${file}`) ?? "";
|
|
1156
|
+
return /from ['"]\.\/git\.ts['"]/.test(text) && /\b(?:toNode(?:Handler|Middleware)|(?:serve|rest|git)\.fetch)\(/.test(text) && /\bjobs\.start\(/.test(text);
|
|
1157
|
+
});
|
|
1158
|
+
const framework = project.framework;
|
|
1159
|
+
const starter = framework === void 0 ? void 0 : startersOf(framework);
|
|
1160
|
+
const starts = starter?.file;
|
|
1161
|
+
const started = starts !== void 0 && /\bjobs\.start\(/.test(starts.text);
|
|
1162
|
+
if (routed(project.framework)) return [
|
|
1163
|
+
filesFinding(view, project, chosen, source),
|
|
1164
|
+
...routedFindings(chosen, project, project.framework),
|
|
1165
|
+
...localFindings(project, chosen, disk, view)
|
|
1166
|
+
];
|
|
1167
|
+
return [
|
|
1168
|
+
filesFinding(view, project, chosen, source),
|
|
1169
|
+
starter === void 0 ? {
|
|
1170
|
+
check: "Entry",
|
|
1171
|
+
ok: entry !== void 0,
|
|
1172
|
+
says: entry === void 0 ? "No file in src/ serves src/git.ts and starts its jobs: add the lines init printed" : `src/${entry} serves Git and runs its jobs`,
|
|
1173
|
+
blocks: "serving Git: nothing answers its URLs or runs its jobs"
|
|
1174
|
+
} : {
|
|
1175
|
+
check: "Jobs",
|
|
1176
|
+
ok: started,
|
|
1177
|
+
says: started ? `${starts.path} starts Git's jobs in each server process` : `${starts?.path ?? `No ${starter.path}`} starts no Git jobs: add the ${starter.lines} lines init printed`,
|
|
1178
|
+
blocks: "Git's jobs: pushes land, but nothing packs, merges or sends events"
|
|
1179
|
+
},
|
|
1180
|
+
...framework?.name === "next" ? nextFindings(view.read, chosen) : [],
|
|
1181
|
+
...framework?.name === "sveltekit" ? svelteFindings(view, framework, chosen) : [],
|
|
1182
|
+
...framework?.name === "nuxt" ? nuxtFindings(framework) : [],
|
|
1183
|
+
...starter === void 0 ? [] : [{
|
|
1184
|
+
check: "Push timeout",
|
|
1185
|
+
ok: true,
|
|
1186
|
+
says: `${starter.server} keeps Node's 300 s requestTimeout, so a push that takes longer to upload is cut off: serve Git from your own node:http server to lift it`
|
|
1187
|
+
}],
|
|
1188
|
+
...starter === void 0 && project.layout.kind !== "own" ? [{
|
|
1189
|
+
check: "Push timeout",
|
|
1190
|
+
ok: true,
|
|
1191
|
+
says: "Your server keeps Node's 300 s requestTimeout unless it sets one, so a push that takes longer to upload is cut off: set its requestTimeout, as src/main.ts does"
|
|
1192
|
+
}] : [],
|
|
1193
|
+
...localFindings(project, chosen, disk, view)
|
|
1194
|
+
];
|
|
1195
|
+
};
|
|
1196
|
+
/**
|
|
1197
|
+
* What `doctor` finds in the app on Node: its files, the jobs' plugin and the server's entry, its
|
|
1198
|
+
* tables, the packages installed, and the variables it reads from `.env`, by name only.
|
|
1199
|
+
*/
|
|
1200
|
+
const nodeAppFindings = (view, project, chosen, disk, source) => {
|
|
1201
|
+
const { database, entry: entryPath, jobs } = platforms.node;
|
|
1202
|
+
const plugin = view.read(jobs) ?? "";
|
|
1203
|
+
const entry = view.read(entryPath) ?? "";
|
|
1204
|
+
const runs = /\bjobs\.start\(/.test(plugin) && /from ['"]\.\/git\.ts['"]/.test(entry);
|
|
1205
|
+
const files = disk.migrations;
|
|
1206
|
+
const local = chosen.records === "sqlite";
|
|
1207
|
+
const { migrated } = disk;
|
|
1208
|
+
const missing = files.filter((each) => !migrated.has(each));
|
|
1209
|
+
const variables = [...platforms.node.required, ...nodeNeeds(chosen)];
|
|
1210
|
+
const set = devVars(view, [platforms.node.secretFile]);
|
|
1211
|
+
const unset = variables.filter((name) => !set.has(name));
|
|
1212
|
+
const data = keepsData(chosen);
|
|
1213
|
+
const canWrite = disk.dataWritable;
|
|
1214
|
+
return [
|
|
1215
|
+
filesFinding(view, project, chosen, source),
|
|
1216
|
+
{
|
|
1217
|
+
check: "Entry",
|
|
1218
|
+
ok: runs,
|
|
1219
|
+
says: runs ? `${entryPath} serves the app and Git, and ${jobs} runs Git's jobs` : `${jobs} doesn't start Git's jobs, or ${entryPath} doesn't serve src/git.ts: run init again`,
|
|
1220
|
+
blocks: "serving Git: nothing answers its URLs or runs its jobs"
|
|
1221
|
+
},
|
|
1222
|
+
local ? {
|
|
1223
|
+
check: "Migrations",
|
|
1224
|
+
ok: missing.length === 0,
|
|
1225
|
+
says: missing.length === 0 ? `${database.file} holds ${files.join(", ")}` : `${database.file} lacks ${missing.join(", ")}: run \`npm run migrate\``,
|
|
1226
|
+
blocks: "signing in: the app keeps its people there"
|
|
1227
|
+
} : {
|
|
1228
|
+
check: "Migrations",
|
|
1229
|
+
ok: true,
|
|
1230
|
+
says: `Run \`npm run migrate\` once ${chosen.records === "postgres" ? "DATABASE_URL is" : "Turso's variables are"} set: it makes the app's tables, and skips those it has`
|
|
1231
|
+
},
|
|
1232
|
+
...data ? [{
|
|
1233
|
+
check: "Data",
|
|
1234
|
+
ok: canWrite,
|
|
1235
|
+
says: canWrite ? ".data, writable" : "This process can't write .data",
|
|
1236
|
+
blocks: "starting it: the app keeps its records there"
|
|
1237
|
+
}] : [],
|
|
1238
|
+
installedFinding(project, disk),
|
|
1239
|
+
{
|
|
1240
|
+
check: "Variables",
|
|
1241
|
+
ok: unset.length === 0,
|
|
1242
|
+
says: unset.length === 0 ? `${variables.join(", ")}, set in .env` : `${unset.join(", ")} ${unset.length === 1 ? "is" : "are"} not set in .env`,
|
|
1243
|
+
blocks: "starting it: src/git.ts and src/env.ts stop without them"
|
|
1244
|
+
}
|
|
1245
|
+
];
|
|
1246
|
+
};
|
|
1247
|
+
/**
|
|
1248
|
+
* What `doctor` finds in a project `init` set up: its files as the plan has them, the Worker's
|
|
1249
|
+
* bindings, migrations and exports, the dependencies installed, and its local secrets.
|
|
1250
|
+
*/
|
|
1251
|
+
/**
|
|
1252
|
+
* What `doctor` finds in a Vercel project `init` set up: its files, `vercel.json`'s rewrite,
|
|
1253
|
+
* limits, trigger and cron against the plan, the packages installed, and which variables are set
|
|
1254
|
+
* locally, by name only: the project's own are on Vercel, which `doctor` doesn't reach.
|
|
1255
|
+
*/
|
|
1256
|
+
const vercelFindingsOf = (view, project, disk, chosen, source) => {
|
|
1257
|
+
const next = project.framework?.name === "next" ? project.framework : void 0;
|
|
1258
|
+
const problems = vercelProblems(view.read("vercel.json"), chosen, next);
|
|
1259
|
+
const set = devVars(view, [".env", ".env.local"]);
|
|
1260
|
+
const unset = variablesOf(chosen).filter((name) => !set.has(name) && process.env[name] === void 0);
|
|
1261
|
+
return [
|
|
1262
|
+
filesFinding(view, project, chosen, source),
|
|
1263
|
+
{
|
|
1264
|
+
check: "Config",
|
|
1265
|
+
ok: problems.length === 0,
|
|
1266
|
+
says: problems.length === 0 ? next === void 0 ? "vercel.json sends Git's URLs to api/git.ts, wakes api/jobs.ts and sweeps on its cron" : `vercel.json wakes ${nextJobRoutes(next).jobs} and sweeps on its cron` : `vercel.json: ${problems.join("; ")}`,
|
|
1267
|
+
blocks: "deploying: Git's URLs, jobs or sweep would miss their functions"
|
|
1268
|
+
},
|
|
1269
|
+
...next === void 0 ? [] : nextFindings(view.read, chosen),
|
|
1270
|
+
installedFinding(project, disk),
|
|
1271
|
+
{
|
|
1272
|
+
check: "Variables",
|
|
1273
|
+
ok: true,
|
|
1274
|
+
says: unset.length === 0 ? "Each variable .env.example lists is set in .env or .env.local: `vercel env pull` fills .env.local from Development, so see Production's with `vercel env ls production`" : `${unset.join(", ")} ${unset.length === 1 ? "isn't" : "aren't"} set in .env or .env.local, which \`vercel env pull\` fills from Development: set each for Production and Development, then pull again`
|
|
1275
|
+
},
|
|
1276
|
+
{
|
|
1277
|
+
check: "Vercel plan",
|
|
1278
|
+
ok: true,
|
|
1279
|
+
says: chosen.vercelPlan === "pro" ? "Pro: the cron sweeps each minute, and a clone may run 800 s" : "Hobby: a lost queue message can wait up to a day for the daily sweep: --vercel-plan pro sweeps each minute"
|
|
1280
|
+
}
|
|
1281
|
+
];
|
|
1282
|
+
};
|
|
1283
|
+
/** The choices `doctor` checks a project against: what it holds, on its platform, else the defaults. */
|
|
1284
|
+
const chosenOf = (project) => {
|
|
1285
|
+
const platform = platformOf(project.detected);
|
|
1286
|
+
const held = project.held ?? {};
|
|
1287
|
+
return withDefaults(platform === void 0 ? held : {
|
|
1288
|
+
platform,
|
|
1289
|
+
...held
|
|
1290
|
+
}, project.project);
|
|
1291
|
+
};
|
|
1292
|
+
const findingsOf = (view, project, chosen, disk, source) => {
|
|
1293
|
+
if (chosen.platform === "vercel") return vercelFindingsOf(view, project, disk, chosen, source);
|
|
1294
|
+
if (chosen.platform === "node") return nodeFindings(view, project, chosen, disk, source);
|
|
1295
|
+
const { main, bindings, classes: made, buckets, databases } = configParts(project.config?.file ?? "wrangler.jsonc", project.config?.text ?? "");
|
|
1296
|
+
const classesBound = gitClasses.every((each) => bindings.includes(each.name) && made.includes(each.class_name));
|
|
1297
|
+
const entry = main === void 0 ? "" : view.read(main) ?? "";
|
|
1298
|
+
const exported = gitClasses.every(({ class_name: name }) => new RegExp(`export\\s+(const|class|\\{[^}]*)\\s*\\b${name}\\b`).test(entry));
|
|
1299
|
+
const routed = /from ['"]\.\/git\.ts['"]/.test(entry) && /\b(github|rest|git)\.(route|fetch)\b/.test(entry);
|
|
1300
|
+
const packs = chosen.objects === "packs";
|
|
1301
|
+
const bucketBound = buckets.includes("PACKS");
|
|
1302
|
+
const vars = devVars(view);
|
|
1303
|
+
const secrets = secretsOf(chosen);
|
|
1304
|
+
const unset = secrets.filter((name) => !vars.has(name));
|
|
1305
|
+
const people = platforms.cloudflare.database;
|
|
1306
|
+
const signs = platforms.cloudflare.signing.every((name) => vars.has(name));
|
|
1307
|
+
const { routes } = disk;
|
|
1308
|
+
const taken = chosen.serve === "github" ? routes.filter(takesDropIn) : [];
|
|
1309
|
+
return [
|
|
1310
|
+
filesFinding(view, project, chosen, source),
|
|
1311
|
+
{
|
|
1312
|
+
check: "Classes",
|
|
1313
|
+
ok: classesBound && exported,
|
|
1314
|
+
says: !classesBound ? "Records and Jobs are not bound and migrated" : exported ? `Records and Jobs, exported from ${main ?? "main"} and bound` : `Records and Jobs are bound, but ${main ?? "main"} doesn't export both`,
|
|
1315
|
+
blocks: "deploying: Git keeps its records in them"
|
|
1316
|
+
},
|
|
1317
|
+
{
|
|
1318
|
+
check: "Entry",
|
|
1319
|
+
ok: routed,
|
|
1320
|
+
says: routed ? `${main ?? "main"} answers Git's URLs first` : `${main ?? "main"} doesn't send Git's URLs to src/git.ts: add the lines init printed`,
|
|
1321
|
+
blocks: "serving Git: every request reaches the Worker instead"
|
|
1322
|
+
},
|
|
1323
|
+
...packs ? [{
|
|
1324
|
+
check: "Bucket",
|
|
1325
|
+
ok: bucketBound,
|
|
1326
|
+
says: bucketBound ? "PACKS, an R2 bucket" : "PACKS is not bound to an R2 bucket",
|
|
1327
|
+
blocks: "pushing: Git keeps its packs there"
|
|
1328
|
+
}] : [],
|
|
1329
|
+
...chosen.app === "ref0" ? [{
|
|
1330
|
+
check: "Auth",
|
|
1331
|
+
ok: databases.includes(people.binding),
|
|
1332
|
+
says: databases.includes(people.binding) ? `${people.binding}, a D1 database, with its migrations` : `${people.binding} is not bound to a D1 database with its migrations_dir`,
|
|
1333
|
+
blocks: "signing in: the app keeps its people there"
|
|
1334
|
+
}] : [],
|
|
1335
|
+
installedFinding(project, disk),
|
|
1336
|
+
...taken.length > 0 ? [{
|
|
1337
|
+
check: "Routes",
|
|
1338
|
+
ok: false,
|
|
1339
|
+
says: `The app's ${taken.map((route) => `src/routes/${route}`).join(", ")} take the drop-in's paths`,
|
|
1340
|
+
blocks: "gh and Octokit, which look for the drop-in there"
|
|
1341
|
+
}] : [],
|
|
1342
|
+
{
|
|
1343
|
+
check: "Secret",
|
|
1344
|
+
ok: true,
|
|
1345
|
+
says: unset.length === 0 ? `${secrets.join(" and ")} ${secrets.length === 1 ? "is" : "are"} set in .dev.vars` : `${unset.join(" and ")} ${unset.length === 1 ? "is" : "are"} not in .dev.vars: set ${unset.length === 1 ? "it" : "each"} with \`wrangler secret put\` before deploying`
|
|
1346
|
+
},
|
|
1347
|
+
...packs ? [{
|
|
1348
|
+
check: "Signed links",
|
|
1349
|
+
ok: true,
|
|
1350
|
+
says: signs ? "On: large pushes upload to the bucket in parts" : "Off: LFS streams through the Worker, up to 100 MB a request on Free"
|
|
1351
|
+
}] : []
|
|
1352
|
+
];
|
|
1353
|
+
};
|
|
1354
|
+
/** The setup group's commands, at the top of the tree. */
|
|
1355
|
+
const setupCommands = [init, Command.make("doctor", {
|
|
1356
|
+
dir: dirArgument("The folder to check: the current one when left out"),
|
|
1357
|
+
verify: Flag.Boolean("verify").pipe(Flag.withDescription("Instead of this folder's config, create, push, read, clone and delete a scratch repo on the host"), Flag.withDefault(false)),
|
|
1358
|
+
host: hostFlag
|
|
1359
|
+
}, Effect.fnUntraced(function* ({ dir, verify: verifying, host }) {
|
|
1360
|
+
if (verifying) return yield* verify(host);
|
|
1361
|
+
if (Option.isSome(host)) return yield* usageFailure("host_without_verify", "--host names the host --verify checks", {
|
|
1362
|
+
says: "Check that host end to end",
|
|
1363
|
+
run: [[
|
|
1364
|
+
"doctor",
|
|
1365
|
+
"--verify",
|
|
1366
|
+
"--host",
|
|
1367
|
+
host.value
|
|
1368
|
+
]]
|
|
1369
|
+
});
|
|
1370
|
+
const folder = yield* folderOf(dir);
|
|
1371
|
+
const view = yield* viewOf(folder.path);
|
|
1372
|
+
const project = yield* projectIn(view);
|
|
1373
|
+
const source = yield* sourceOf(void 0, project.held?.app === "ref0");
|
|
1374
|
+
const chosen = chosenOf(project);
|
|
1375
|
+
const disk = yield* diskOf(folder.path, project, chosen);
|
|
1376
|
+
const found = findingsOf(view, project, chosen, disk, source);
|
|
1377
|
+
const blocking = found.filter((finding) => !finding.ok);
|
|
1378
|
+
const mode = yield* CliModes;
|
|
1379
|
+
if (!mode.json) yield* answer(found.map((finding) => field([finding.check, finding.says])).join("\n"));
|
|
1380
|
+
if (blocking.length > 0) return yield* failure("not_ready", blocking.map((finding) => `${finding.check}: ${finding.says}, which blocks ${finding.blocks ?? "deploying"}`).join("; "), {
|
|
1381
|
+
says: "Add what's missing, then check again",
|
|
1382
|
+
run: [["init", ...folder.argv]]
|
|
1383
|
+
}, found);
|
|
1384
|
+
const vercel = withDefaults(project.held ?? {}, project.project).platform === "vercel";
|
|
1385
|
+
const starter = project.framework === void 0 ? void 0 : startersOf(project.framework);
|
|
1386
|
+
const base = (project.held?.basePath ?? "/").replace(/\/+$/, "");
|
|
1387
|
+
const served = platformOf(project.detected) === "node" && starter === void 0 && !routed(project.framework) && project.layout.kind !== "mount" ? project.held?.app === "ref0" ? startOrigin : mainOrigin : void 0;
|
|
1388
|
+
const signIn = served === void 0 ? "sign in to it with its admin token, <host> being where it's served" : "sign in to it with its admin token";
|
|
1389
|
+
const tokenFiles = secretFilesOf(withDefaults(project.held ?? {}, project.project));
|
|
1390
|
+
const next = {
|
|
1391
|
+
says: platformOf(project.detected) === "node" ? starter !== void 0 ? `Build it with \`${project.packageManager.value} run build\`, start it with ${starter.start(project.packageManager.value)}, ${signIn}, then push a scratch repo through it` : routed(project.framework) ? `Build it with \`${project.packageManager.value} run build\`, start it with ${routedStart(project.framework, project.packageManager.value)}, ${signIn}, then push a scratch repo through it` : project.layout.kind === "mount" ? `Start your server with \`node --env-file-if-exists=.env\`, which loads what src/git.ts reads, ${signIn}, then push a scratch repo through it` : `Start it with \`${project.packageManager.value} start\`, ${project.held?.app === "ref0" ? "sign up on it, setting APP_ORIGIN to where it's served first" : signIn}, then push a scratch repo through it` : vercel ? `Check Production has each variable with \`vercel env ls production\`, deploy it with Vercel's CLI or a Git import, ${signIn}, then push a scratch repo through it` : `${project.held?.app === "ref0" ? "Set APP_ORIGIN to where it's served, make AUTH_DB and its tables with `wrangler d1`, deploy" : "Deploy"} it with \`wrangler deploy\`, set ${secretsOf(withDefaults(project.held ?? {}, project.project)).join(" and ")} with \`wrangler secret put\`, ${signIn}, then push a scratch repo through it`,
|
|
1392
|
+
run: [[
|
|
1393
|
+
"login",
|
|
1394
|
+
`${served ?? "<host>"}${base}`,
|
|
1395
|
+
"--with-token"
|
|
1396
|
+
], ["doctor", "--verify"]],
|
|
1397
|
+
stdinFrom: "ADMIN_TOKEN"
|
|
1398
|
+
};
|
|
1399
|
+
if (mode.json) return yield* cliDocument(doctorJson, {
|
|
1400
|
+
ready: true,
|
|
1401
|
+
findings: found,
|
|
1402
|
+
nextStep: nextDocument(next)
|
|
1403
|
+
});
|
|
1404
|
+
yield* receipt({
|
|
1405
|
+
done: "Ready to deploy",
|
|
1406
|
+
fields: [["Admin token", `ADMIN_TOKEN, in ${tokenFiles.join(" or ")} locally, or the host's secret`]],
|
|
1407
|
+
next
|
|
1408
|
+
});
|
|
1409
|
+
})).pipe(Command.withDescription("Check a folder's Git setup, or with --verify a host end to end (experimental)"))];
|
|
1410
|
+
export { setupCommands };
|