feat: add experimental API to expose Wrangler command tree structure#10242
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
🦋 Changeset detectedLatest commit: 7d48ad5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
- Remove unnecessary experimental_getCommandsForDocs() method from CommandRegistry - Refactor experimental API to use createCLIParser and existing registry - Eliminate command registration duplication in experimental-commands-api.ts - Use existing getDefinitionTreeRoot() method instead of duplicate implementation Addresses feedback from @penalosa on PR #10242 Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com>
74742b3 to
a7a7566
Compare
|
@penalosa - can you try to get the CI green? |
- Add experimental_getCommandsForDocs() method to CommandRegistry - Create experimental_getWranglerCommands() function in new experimental-commands-api.ts - Export experimental API from cli.ts following existing patterns - Add comprehensive tests for the new experimental API - Include changeset for minor version bump This API exposes the raw command tree structure with all metadata for cloudflare-docs to consume for documentation generation. Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com>
- Remove unnecessary experimental_getCommandsForDocs() method from CommandRegistry - Refactor experimental API to use createCLIParser and existing registry - Eliminate command registration duplication in experimental-commands-api.ts - Use existing getDefinitionTreeRoot() method instead of duplicate implementation Addresses feedback from @penalosa on PR #10242 Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com>
…rors build failure - Add createCLIParser export to cli.ts to make it available to external packages - Maintain backward compatibility while exposing experimental API functionality - Fixes CI failures in format-errors package build Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com>
- Replace globalRegistry variable with createCommandRegistry function - Address GitHub PR comment from penalosa about avoiding global variables - Maintain backward compatibility for createCLIParser function - All experimental API tests continue to pass Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com>
- Remove createCLIParser export from cli.ts as requested - Remove duplicative createCommandRegistry function from index.ts - Modify createCLIParser to attach registry via Object.defineProperty - Update experimental API to access registry from attached property - Maintain backward compatibility for existing createCLIParser callers - All experimental API tests continue to pass Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com>
…stry }
Address PR feedback by modifying createCLIParser() to return an object
with named properties instead of using Object.defineProperty. This
provides cleaner access to both wrangler and registry while maintaining
backward compatibility for all existing callers.
- Update createCLIParser() to return { wrangler, registry }
- Update all callers to destructure the new return type
- Maintain functionality for main(), build command, and check command
- Update experimental API to use new structure directly
Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com>
…tibility - E2E tests import from CLI module via WRANGLER_IMPORT - Adding export ensures backward compatibility while maintaining refactored signature - All experimental API tests pass locally (6/6 tests) Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com>
e74f592 to
7d48ad5
Compare
|
@petebacondarwin CI is green, so this should be ready for a review |
There was a problem hiding this comment.
It might be nice to JSON stringify the tree for these tests, then you could use snapshot matchers.
|
Congratulations @devin-ai-integration[bot], the maintainer of this repository has issued you a holobyte! Here it is: https://holopin.io/holobyte/cme723jvj080407jmfg397nh5 This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account. |
… matchers - Replace individual assertions with comprehensive snapshot testing - Add serializeCommandTree helper to convert Maps to plain objects - Use proper TypeScript types (unknown instead of any) - Addresses petebacondarwin's feedback on PR #10242 Co-Authored-By: smacleod@cloudflare.com <smacleod@cloudflare.com>
Summary
This PR adds a new experimental API
experimental_getWranglerCommands()to expose Wrangler's complete command tree structure with metadata for cloudflare-docs consumption. The API leverages the existingCommandRegistryinfrastructure to provide programmatic access to all registered commands, their hierarchical relationships, and associated metadata.Link to Devin run: https://app.devin.ai/sessions/e7ce795996a34292a84d4aabe9ec9f92
Requested by: @penalosa
Key Changes
CommandRegistry.ts: Addedexperimental_getCommandsForDocs()to expose the internal command treeexperimental-commands-api.ts: Containsexperimental_getWranglerCommands()function that registers all Wrangler commands and returns the tree structurecli.tsfollowing existing experimental API patternsImportant Review Areas
index.ts, creating a maintenance burden. Consider whether this approach is sustainable or if a more automated solution is needed.Testing
The new API has been tested to ensure:
All tests pass locally and verify the basic structure, though human verification of complete command coverage is recommended.