Skip to content

feat(cli): add compute new --template - #6572

Draft
johnstonmatt wants to merge 6 commits into
developfrom
feat/compute/template-flag-degit
Draft

feat(cli): add compute new --template#6572
johnstonmatt wants to merge 6 commits into
developfrom
feat/compute/template-flag-degit

Conversation

@johnstonmatt

Copy link
Copy Markdown
Contributor

Adds a --template flag to compute new that bootstraps the compute directory from a git repository instead of the runtime's starter files, using a degit-style depth-1 clone with its .git removed.

  • Add compute-template.ts, parsing a GitHub owner/repo slug (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 via git clone/fetch+checkout into a scoped temp directory; refuses a subdirectory that escapes the repository or a tree with no files
  • Wire the fetcher into compute 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
  • Default an omitted --runtime from the staged template's own marker files (via the same classifier push uses), while still letting --runtime and interactive prompts override the inference
  • Reorder compute new so 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 refused
  • Widen collectText to be generic over the stream's failure type so folding a child process's stderr no longer widens PlatformError to unknown
  • Add a tests/helpers/git-repo.ts fixture for creating real local git repos in tests, plus unit and integration coverage for the template parser and fetcher

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant