-
Notifications
You must be signed in to change notification settings - Fork 511
feat(cli): add supabase workers new #6261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # `supabase workers new [name]` | ||
|
|
||
| > **TS-only command.** `supabase workers` has no Go counterpart — there is no | ||
| > `apps/cli-go/internal/workers` to match, and nothing is proxied. See | ||
| > `docs/go-cli-divergences.md`. | ||
|
|
||
| ## Files Read | ||
|
|
||
| | Path | Format | When | | ||
| | -------------------------------- | ------ | ----------------------------------------------------------- | | ||
| | `<workdir>/supabase/config.toml` | TOML | always, for `[workers]` root and any existing entry | | ||
| | `<destination>/` | dir | always, to refuse a non-empty destination without `--force` | | ||
|
|
||
| ## Files Written | ||
|
|
||
| | Path | Format | When | | ||
| | ------------------------------------ | ------ | ------------------------------------------------------------------------- | | ||
| | `<workdir>/supabase/config.toml` | TOML | always — appends/updates `[workers.<name>]` in place, preserving comments | | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The handler always flushes AGENTS.md reference: apps/cli/AGENTS.md:L387-L394 Useful? React with 👍 / 👎. |
||
| | `<workdir>/supabase/<root>/<name>/*` | varies | always, unless `--source` names another directory | | ||
| | `<workdir>/<source>/*` | varies | when `--source` is given | | ||
|
|
||
| Existing files at the destination are **deleted** when `--force` is passed. | ||
| `--source` is refused when it resolves to the project root, `supabase/`, | ||
| `supabase/functions/`, `supabase/migrations/`, or outside the project. | ||
|
|
||
| ## API Routes | ||
|
|
||
| | Method | Path | Auth | Request body | Response (used fields) | | ||
| | ------ | ---- | ---- | ------------ | ---------------------- | | ||
| | — | — | — | — | — | | ||
|
|
||
| ## Exit Codes | ||
|
|
||
| | Code | Condition | | ||
| | ---- | --------------------------------------------------------------------- | | ||
| | `0` | success | | ||
| | `1` | invalid or reserved worker name, unknown runtime/size, bad `--source` | | ||
| | `1` | destination exists and is not empty without `--force` | | ||
| | `1` | `config.toml` records a worker in a form that cannot be edited safely | | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| | Variable | Purpose | Required? | | ||
| | ----------------------- | ---------------------------------------------------- | ------------------------------------------------------- | | ||
| | `SUPABASE_ACCESS_TOKEN` | auth token (bypasses credential file/keyring lookup) | no (falls back to keyring → `~/.supabase/access-token`) | | ||
| | `SUPABASE_PROFILE` | built-in profile name or YAML file path | no (falls back to `~/.supabase/profile` -> `supabase`) | | ||
| | `SUPABASE_WORKDIR` | project directory the command acts on | no (falls back to `--workdir`, then the ancestor walk) | | ||
|
|
||
| ## Telemetry Events Fired | ||
|
|
||
| | Event | When | Notable properties / groups | | ||
| | ---------------------- | ------------------------------------------ | ----------------------------------- | | ||
| | `cli_command_executed` | post-run, success or failure (via wrapper) | `exit_code`, `duration_ms`, `flags` | | ||
|
|
||
| No custom events. `workers` has no Go counterpart, so there is no | ||
| `phtelemetry.*` call to reproduce. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { Layer } from "effect"; | ||
| import { Argument, Command, Flag } from "effect/unstable/cli"; | ||
| import type * as CliCommand from "effect/unstable/cli/Command"; | ||
| import { withJsonErrorHandling } from "../../../../shared/output/json-error-handling.ts"; | ||
| import { commandRuntimeLayer } from "../../../../shared/runtime/command-runtime.layer.ts"; | ||
| import { randomLayer } from "../../../../shared/runtime/random.layer.ts"; | ||
| import { WORKER_RUNTIMES, WORKER_SIZES } from "../../../../shared/workers/worker-runtimes.ts"; | ||
| import { legacyCliConfigLayer } from "../../../config/legacy-cli-config.layer.ts"; | ||
| import { legacyDebugLoggerLayer } from "../../../shared/legacy-debug-logger.layer.ts"; | ||
| import { legacyTelemetryStateLayer } from "../../../telemetry/legacy-telemetry-state.layer.ts"; | ||
| import { withLegacyCommandInstrumentation } from "../../../telemetry/legacy-command-instrumentation.ts"; | ||
| import { legacyWorkersNew } from "./new.handler.ts"; | ||
|
|
||
| const config = { | ||
| name: Argument.string("name").pipe( | ||
| Argument.withDescription("Worker name. Doubles as its directory; generated when omitted."), | ||
| Argument.optional, | ||
| ), | ||
| runtime: Flag.choice("runtime", WORKER_RUNTIMES).pipe( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When users pass Useful? React with 👍 / 👎. |
||
| Flag.withDescription( | ||
| "Runtime to scaffold and record in supabase/config.toml. Prompted when omitted.", | ||
| ), | ||
| Flag.optional, | ||
| ), | ||
| size: Flag.choice("size", WORKER_SIZES).pipe( | ||
| Flag.withDescription( | ||
| "Instance size to record in supabase/config.toml. Each size implies its own vCPU count, so there is no separate --cpu. Prompted when omitted.", | ||
| ), | ||
| Flag.optional, | ||
| ), | ||
| source: Flag.string("source").pipe( | ||
| Flag.withDescription( | ||
| "Scaffold the worker here instead of the default workers directory, recorded as `source` in supabase/config.toml.", | ||
| ), | ||
| Flag.optional, | ||
| ), | ||
| force: Flag.boolean("force").pipe( | ||
| Flag.withDescription("Replace the destination if it already exists and is not empty."), | ||
| ), | ||
| } as const; | ||
|
|
||
| export type LegacyWorkersNewFlags = CliCommand.Command.Config.Infer<typeof config>; | ||
|
|
||
| const cliConfig = legacyCliConfigLayer.pipe(Layer.provide(legacyDebugLoggerLayer)); | ||
|
|
||
| /** Local-disk only: no Management API, so no platform stack is built. */ | ||
| const legacyWorkersNewRuntimeLayer = Layer.mergeAll( | ||
| cliConfig, | ||
| legacyTelemetryStateLayer, | ||
| randomLayer, | ||
| commandRuntimeLayer(["workers", "new"]), | ||
| ); | ||
|
|
||
| export const legacyWorkersNewCommand = Command.make("new", config).pipe( | ||
| Command.withDescription( | ||
| "Scaffold a worker directory from a runtime's starter files and record the choice in supabase/config.toml. Nothing is deployed.", | ||
| ), | ||
| Command.withShortDescription("Scaffold a worker locally"), | ||
| Command.withExamples([ | ||
| { | ||
| command: "supabase workers new", | ||
| description: "Scaffold a worker, prompting for runtime and size", | ||
| }, | ||
| { | ||
| command: "supabase workers new api --runtime node", | ||
| description: "Scaffold supabase/workers/api on the node runtime", | ||
| }, | ||
| { | ||
| command: "supabase workers new api --source packages/api", | ||
| description: "Scaffold the worker outside the workers directory", | ||
| }, | ||
| ]), | ||
| Command.withHandler((flags) => | ||
| legacyWorkersNew(flags).pipe( | ||
| withLegacyCommandInstrumentation({ flags, config }), | ||
| withJsonErrorHandling, | ||
| ), | ||
| ), | ||
| Command.provide(legacyWorkersNewRuntimeLayer), | ||
| ); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds a new feature entry to
go-cli-divergences.md, even though that file is explicitly frozen and new features must instead be documented through help text, tests, andSIDE_EFFECTS.md. Keeping this entry also reintroduces the Go-parity framing that the current legacy-shell guidance retired.AGENTS.md reference: apps/cli/AGENTS.md:L513-L516
Useful? React with 👍 / 👎.