Skip to content

refactor(wrangler): organize command files as a tree in src/commands#12349

Draft
vicb wants to merge 9 commits intomainfrom
vicb/command-tree
Draft

refactor(wrangler): organize command files as a tree in src/commands#12349
vicb wants to merge 9 commits intomainfrom
vicb/command-tree

Conversation

@vicb
Copy link
Contributor

@vicb vicb commented Feb 1, 2026

TL;DR: it took me > 10s (like way longer) to find in what file a command was implemented. We need to fix this.

Still in draft while being discussed

Commands are central to wrangler and should be grouped in a logical way so that it's easy to find where they are implemented. The current status is that command files are not well organized and mixed with utility code.

IMO the commands and utility code should be well separated, commands should be organized as a tree.

Note that this PR is a first step in that direction and we decide that's something we want to pursue, I'll follow up with more PR.

As wrangler grows in scope, I believe the change proposed here will become more relevant.

I believe have enough tests to have confidence we're not breaking too many things 😰

I worked on a plan with Claude. They then implemented the changes.

Summary

Reorganize wrangler's command files from scattered src// locations into a structured src/commands/ directory that mirrors the CLI hierarchy, making commands easy to find by name.
For example: wrangler r2 bucket create → src/commands/r2/bucket/index.ts

File Moves

Phase 1: Standalone Commands

Before After
src/docs/ src/commands/docs/
src/tail/ src/commands/tail/
src/type-generation/ src/commands/types/
src/user/commands.ts src/commands/user/index.ts
src/metrics/commands.ts src/commands/telemetry/index.ts
src/secret/ src/commands/secret/
src/triggers/ src/commands/triggers/
src/versions/ src/commands/versions/
src/deploy/index.ts src/commands/deploy/index.ts
src/complete.ts src/commands/complete.ts
src/setup.ts src/commands/setup.ts
src/delete.ts src/commands/delete.ts
src/init.ts src/commands/init.ts
src/dev.ts src/commands/dev.ts

Phase 2: Feature Namespaces

Before After
src/kv/ src/commands/kv/
src/d1/ src/commands/d1/
src/r2/ src/commands/r2/
src/queues/ src/commands/queues/
src/pages/ src/commands/pages/
src/vectorize/ src/commands/vectorize/
src/ai/ src/commands/ai/
src/build/ src/commands/build/
src/cert/ src/commands/cert/
src/check/ src/commands/check/
src/cloudchamber/ src/commands/cloudchamber/
src/containers/ src/commands/containers/
src/hello-world/ src/commands/hello-world/
src/hyperdrive/ src/commands/hyperdrive/
src/mtls-certificate/ src/commands/mtls-certificate/
src/pipelines/ src/commands/pipelines/
src/secrets-store/ src/commands/secrets-store/
src/vpc/ src/commands/vpc/
src/workflows/ src/commands/workflows/

What's NOT Changing

  • Command behavior (no logic changes)
  • Export names (still using existing names like r2BucketCreateCommand, etc.)
  • Registration pattern (still using registry.define() in src/index.ts)
  • Test logic (only import paths updated)
  • CLI output or user experience

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: no user facing changes

A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

vicb added 9 commits February 1, 2026 15:50
Move standalone commands and simple namespaces into the new src/commands/
directory structure. This is the first step in reorganizing wrangler's
command files to mirror the CLI hierarchy.

Commands moved:
- docs, init, dev, deploy, delete, setup, tail, complete
- types (from type-generation)
- user (login, logout, whoami, auth)
- telemetry (from metrics/commands)
- secret, triggers
- versions (with deployments, rollback, secrets sub-namespaces)

No logic changes - only file moves and import updates.
All 2827 tests pass.
Move KV namespace commands into the src/commands/ directory structure.

Files moved:
- src/kv/index.ts → src/commands/kv/index.ts
- src/kv/helpers.ts → src/commands/kv/helpers.ts

Imports updated in:
- src/index.ts
- src/sites.ts
- src/deployment-bundle/bindings.ts
- src/commands/delete.ts
- src/__tests__/kv/*.test.ts
- src/__tests__/delete.test.ts
- src/__tests__/helpers/mock-kv.ts

No logic changes - only file moves and import updates.
All 2827 tests pass.
Move D1 database commands into the src/commands/ directory structure.

Files moved (26 files):
- src/d1/*.ts → src/commands/d1/*.ts
- src/d1/migrations/*.ts → src/commands/d1/migrations/*.ts
- src/d1/timeTravel/*.ts → src/commands/d1/timeTravel/*.ts

Imports updated in:
- src/index.ts
- src/cli.ts
- src/deployment-bundle/bindings.ts
- src/__tests__/d1/*.ts
- src/__tests__/provision.test.ts

No logic changes - only file moves and import updates.
All 2827 tests pass.
Move R2 storage commands into the src/commands/ directory structure.

Files moved (23 files):
- src/r2/*.ts → src/commands/r2/*.ts
- src/r2/helpers/*.ts → src/commands/r2/helpers/*.ts

Imports updated in:
- src/index.ts
- src/deployment-bundle/bindings.ts
- src/pipelines/client.ts
- src/__tests__/r2/*.ts

No logic changes - only file moves and import updates.
All 2827 tests pass.
Moved: ai, build, cert, check, cloudchamber, containers, hello-world, hyperdrive, mtls-certificate, pipelines, secrets-store, vpc, workflows
@vicb vicb requested review from a team as code owners February 1, 2026 16:42
@changeset-bot
Copy link

changeset-bot bot commented Feb 1, 2026

⚠️ No Changeset found

Latest commit: a80ba25

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Feb 1, 2026
@vicb vicb marked this pull request as draft February 1, 2026 16:43
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 1, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12349

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12349

miniflare

npm i https://pkg.pr.new/miniflare@12349

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12349

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12349

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12349

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12349

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12349

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@12349

wrangler

npm i https://pkg.pr.new/wrangler@12349

commit: a80ba25

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

View issues and 2 additional flags in Devin Review.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

1 participant