CLI: Add jetpack playground command for quick WordPress Playground sessions#47597
CLI: Add jetpack playground command for quick WordPress Playground sessions#47597
jetpack playground command for quick WordPress Playground sessions#47597Conversation
…sessions Adds a new `jetpack playground <plugin>` command that spins up a local WordPress Playground instance with the specified plugin mounted. This provides a fast, Docker-free alternative for quick plugin testing. The command: - Uses `jetpack rsync` to create a resolved copy (fixing monorepo symlinks) - Auto-discovers blueprints at `.wordpress-org/blueprints/blueprint.json` - Injects JETPACK_DEV_DEBUG for offline mode (no WP.com connection needed) - Auto-runs install/build if the plugin hasn't been built yet - Cleans up temp files on exit Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
jetpack playground command for quick WordPress Playground sessions
|
@claude review this PR |
|
Claude finished @enejb's task in 2m 1s —— View job PR Review: CLI: Add
|
There was a problem hiding this comment.
Pull request overview
Adds a new jetpack playground <plugin> CLI subcommand to spin up a WordPress Playground instance with a monorepo plugin mounted, including optional custom blueprint and port selection.
Changes:
- Introduces
tools/cli/commands/playground.jsimplementing the Playground command flow (build check, rsync to temp dir, generate/merge blueprint, run Playground server). - Registers the new
playgroundsubcommand in the CLI router.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| tools/cli/commands/playground.js | New CLI subcommand to run WP Playground with a mounted plugin and merged blueprint generation. |
| tools/cli/cliRouter.js | Wires the new playground command into the main jetpack CLI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tools/cli/commands/playground.js
Outdated
| const install = child_process.spawnSync( | ||
| 'jetpack', | ||
| [ 'install', `plugins/${ options.plugin }` ], | ||
| { shell: true, stdio: 'inherit' } | ||
| ); |
tools/cli/commands/playground.js
Outdated
| const pluginPath = path.resolve( `projects/plugins/${ options.plugin }` ); | ||
|
|
||
| // Validate that the plugin exists. | ||
| if ( ! fs.existsSync( pluginPath ) ) { | ||
| const available = dirs( './projects/plugins' ); | ||
| console.error( chalk.red( `Plugin "${ options.plugin }" not found.` ) ); | ||
| if ( available.length > 0 ) { | ||
| console.error( `\nAvailable plugins: ${ available.join( ', ' ) }` ); | ||
| } | ||
| process.exit( 1 ); | ||
| } | ||
|
|
tools/cli/commands/playground.js
Outdated
| console.log( chalk.gray( 'Syncing plugin files (resolving monorepo symlinks)...' ) ); | ||
|
|
||
| const rsyncResult = child_process.spawnSync( | ||
| 'jetpack', | ||
| [ 'rsync', options.plugin, mountPath, '--non-interactive' ], | ||
| { shell: true, stdio: 'inherit' } | ||
| ); | ||
| if ( rsyncResult.status !== 0 ) { | ||
| console.error( chalk.red( 'Failed to sync plugin files.' ) ); | ||
| fs.rmSync( tmpDir, { recursive: true, force: true } ); | ||
| process.exit( 1 ); | ||
| } | ||
|
|
||
| // Build the blueprint. We always inject a step to enable Jetpack offline mode | ||
| // (JETPACK_DEV_DEBUG) so the plugin works without a WordPress.com connection. | ||
| const blueprintPath = buildBlueprint( pluginPath, mountPath, options ); | ||
|
|
||
| console.log( | ||
| chalkJetpackGreen( `Starting WordPress Playground with plugins/${ options.plugin }...` ) | ||
| ); | ||
|
|
||
| const args = [ '@wp-playground/cli', 'server', '--auto-mount', `--blueprint=${ blueprintPath }` ]; | ||
|
|
||
| if ( options.port ) { | ||
| args.push( `--port=${ options.port }` ); | ||
| } | ||
|
|
||
| if ( options.verbose ) { | ||
| console.log( chalk.gray( `Running: npx ${ args.join( ' ' ) }` ) ); | ||
| console.log( chalk.gray( `Synced copy: ${ mountPath }` ) ); | ||
| } | ||
|
|
||
| try { |
| if ( sourceBlueprint ) { | ||
| console.log( chalk.gray( `Using blueprint: ${ path.relative( '.', sourceBlueprint ) }` ) ); | ||
| const custom = JSON.parse( fs.readFileSync( sourceBlueprint, 'utf8' ) ); | ||
| blueprint = { | ||
| ...blueprint, | ||
| ...custom, | ||
| // Merge steps — custom steps run first, then ours. | ||
| steps: [ ...( custom.steps || [] ) ], | ||
| }; |
tools/cli/commands/playground.js
Outdated
|
|
||
| const args = [ '@wp-playground/cli', 'server', '--auto-mount', `--blueprint=${ blueprintPath }` ]; | ||
|
|
||
| if ( options.port ) { |
anomiex
left a comment
There was a problem hiding this comment.
Uses
jetpack rsyncto create a temporary copy with monorepo symlinks resolved (vendor/jetpack_vendor symlinks point outside the plugin directory and break in Playground's sandbox)
Does Playground's --follow-symlinks option not work for you? It seems to work for me locally if I do like
npx @wp-playground/cli server --mount=projects/plugins/beta:/wordpress/wp-content/plugins/jetpack-beta --follow-symlinks
And that also means I can edit code in projects/plugins/beta and have Playground pick up the change immediately, while the rsync as you've coded it won't do that.
And if that doesn't work, it also seems to work to do like
npx @wp-playground/cli server --mount=.:/srv/jetpack-monorepo --blueprint=/path/to/blueprint.json
where the blueprint includes a step
{
"step": "runPHP",
"code": "<?php symlink( '/srv/jetpack-monorepo/projects/plugins/beta', '/wordpress/wp-content/plugins/jetpack-beta' ); ?>"
}
tools/cli/commands/playground.js
Outdated
| * @param {object} yargs - The Yargs dependency. | ||
| * @return {object} Yargs with the playground commands defined. | ||
| */ | ||
| export function playgroundDefine( yargs ) { |
There was a problem hiding this comment.
I note this is the older style of making a subcommand module. It works, but you might consider changing it to the newer module style.
tools/cli/commands/playground.js
Outdated
| landingPage: '/wp-admin/', | ||
| login: true, | ||
| preferredVersions: { | ||
| php: '8.0', |
There was a problem hiding this comment.
No good reason. I think 8.3 works better.
- Convert to newer module style (command/describe/builder/handler exports) - Use `projectDir()` and `maybePromptForPlugin()` from existing helpers - Remove `shell: true` from all subprocess calls - Remove hardcoded PHP 8.0, use Playground default - Fix blueprint step merging to actually merge both arrays - Read wp-plugin-slug from composer.json for correct mount paths - Mount plugin + packages dirs so vendor symlinks resolve correctly - Add mu-plugin to fix plugins_url() for symlink-resolved paths - Auto-detect and activate the plugin's main PHP file - Auto-build if plugin hasn't been built yet - Validate port range and blueprint file existence - Wrap temp dir in try/finally for cleanup on failure - Show admin URL, login credentials, and quit instructions after startup - Warn on first run if @wp-playground/cli needs downloading Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Thanks for all the feedback @anomiex! Can do you mind taking another look? I think next would be to add more helpful blueprint files. ( for example right now when you enable jetpack the form module is not enabled but that could be fixed with the blueprint file. |
This PR make it possible to quickly spin up a playground instance. This could be useful for LLM agents to check their work.
The initial step might
See
Screen.Recording.2026-03-16.at.2.54.34.PM.mov
Proposed changes
jetpack playground <plugin>CLI command that starts a local WordPress Playground instance with the specified plugin mountedjetpack rsyncto create a temporary copy with monorepo symlinks resolved (vendor/jetpack_vendor symlinks point outside the plugin directory and break in Playground's sandbox)JETPACK_DEV_DEBUGvia a blueprint step so Jetpack runs in offline mode without requiring a WordPress.com connection.wordpress-org/blueprints/blueprint.json(e.g., CRM already has one)jetpack install+jetpack buildautomatically if the plugin hasn't been built yetOther information
Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
jetpack cli link)jetpack playground jetpackjetpack playground crmprojects/plugins/crm/.wordpress-org/blueprints/blueprint.jsonjetpack playground nonexistentjetpack playground jetpack -p 9999