feat(cli): add compute new --template - #6572
Draft
johnstonmatt wants to merge 6 commits into
Draft
Conversation
The parameter was typed Stream<Uint8Array, unknown>, so folding a child process's stderr widened PlatformError to unknown and carried it into every caller's error channel. Making it generic infers the stream's own failure type instead; no call site changes.
Nothing about the destination depends on the runtime, size or exposure, so resolving --source and refusing an occupied directory after those three prompts asked the user to answer them for a run that was already going to be refused. Both checks now run first.
Stages a starter tree with git, the way degit does: a depth-1 clone into a scoped temporary directory whose .git is then removed, so a template is a starting point rather than a checkout. Cloning rather than reading a host's archive API is what keeps it host-agnostic -- anything git can clone works, private repositories included, since the user's own credential helper answers for them. Accepts a GitHub owner/repo slug with optional subdirectory and #ref, a github.com URL including the /tree/<ref>/<subdir> form a browser produces, or any other repository URL. A ref is fetched by name rather than through clone --branch, so a commit SHA works as well as a branch or tag. A subdirectory is only read out of a GitHub slug or URL, where the repository boundary is part of the syntax. Since the cloned tree decides what it resolves to, a subdirectory that links outside the repository is refused rather than staged. GIT_TERMINAL_PROMPT=0 keeps git from blocking on a password prompt drawn over the CLI's own output. No command consumes it yet.
Wires the git template fetcher into the scaffold: --template makes a repository the compute's entire contents. No starter files are written alongside it -- the starters are what a compute with no code yet needs, and writing both would leave behind whichever the template happened not to name. That is not merely untidy, because the catalog runtimes load a fixed entry file: a node template whose entry is src/server.js would be shadowed by the starter's index.mjs and never run. An omitted --runtime is defaulted from the template's own marker files, by the same classifier push uses on an unconfigured directory, so a template shipping a Dockerfile is not recorded as deno and then deployed as a base image that never reads it. It stays a default: --runtime wins, and an interactive run is still asked with the inference pre-selected. Reading that default means cloning before the dials resolve, which is why the refusals that do not depend on them run first -- the clone is wasted work for a run that was never going to scaffold anything. It stages into a temporary directory either way, so a bad ref, an absent repository or a missing git leaves the destination untouched and config.toml unwritten, the same way a cancelled prompt does.
Wires the git template fetcher into the scaffold: --template makes a repository the compute's entire contents. No starter files are written alongside it -- the starters are what a compute with no code yet needs, and writing both would leave behind whichever the template happened not to name. That is not merely untidy, because the catalog runtimes load a fixed entry file: a node template whose entry is src/server.js would be shadowed by the starter's index.mjs and never run. An omitted --runtime is defaulted from the template's own marker files, by the same classifier push uses on an unconfigured directory, so a template shipping a Dockerfile is not recorded as deno and then deployed as a base image that never reads it. It stays a default: --runtime wins, and an interactive run is still asked with the inference pre-selected. Reading that default means cloning before the dials resolve, which is why the refusals that do not depend on them run first -- the clone is wasted work for a run that was never going to scaffold anything. It stages into a temporary directory either way, so a bad ref, an absent repository or a missing git leaves the destination untouched and config.toml unwritten, the same way a cancelled prompt does.
…/supabase/cli into feat/compute/template-flag-degit # Conflicts: # apps/cli/src/commands/experimental/compute/new/new.command.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
--templateflag tocompute newthat bootstraps the compute directory from a git repository instead of the runtime's starter files, using a degit-style depth-1 clone with its.gitremoved.compute-template.ts, parsing a GitHubowner/reposlug (with optional subdirectory and#ref), a github.com URL including the/tree/<ref>/<subdir>browser form, or any other cloneable repository URL, then staging it viagit clone/fetch+checkoutinto a scoped temp directory; refuses a subdirectory that escapes the repository or a tree with no filescompute new --template: a template replaces the runtime's starter files entirely rather than layering over them, since the catalog runtimes load a fixed entry file that a leftover starter would shadow--runtimefrom the staged template's own marker files (via the same classifierpushuses), while still letting--runtimeand interactive prompts override the inferencecompute newso destination validation runs before the runtime/size/exposure prompts and before the template clone, since none of those depend on the destination and the clone is otherwise wasted work on a run that was always going to be refusedcollectTextto be generic over the stream's failure type so folding a child process's stderr no longer widensPlatformErrortounknowntests/helpers/git-repo.tsfixture for creating real local git repos in tests, plus unit and integration coverage for the template parser and fetcher