Skip to content

[blueprints] Implement blueprints v2 runner in TypeScript#3447

Draft
brandonpayton wants to merge 16 commits intotrunkfrom
feature/blueprints-v2-ts-runner
Draft

[blueprints] Implement blueprints v2 runner in TypeScript#3447
brandonpayton wants to merge 16 commits intotrunkfrom
feature/blueprints-v2-ts-runner

Conversation

@brandonpayton
Copy link
Copy Markdown
Member

Summary

Replaces the PHP .phar-based Blueprints V2 runner with a pure TypeScript compilation and execution pipeline. This enables blueprint execution without shelling out to a PHP CLI process, improving debuggability, type safety, and integration with the existing Playground infrastructure.

  • New compilation pipeline (compileBlueprintV2()): Validates, extracts runtime config, transpiles declarative properties to steps, resolves data references, and returns a CompiledBlueprintV2 with a run(php) method
  • 15 step handlers: installPlugin, installTheme, activatePlugin, activateTheme, setSiteLanguage, unzip, importContent, importMedia, importThemeStarterContent, filesystem ops (cp/mv/mkdir/rm/rmdir), defineConstants, setSiteOptions, runPHP, wpCLI, writeFiles, runSQL
  • V1 to V2 transpiler: Auto-converts V1 blueprints (no version property) to V2 format using spec-defined mapping tables
  • Blueprint merge algorithm: Composes multiple V2 blueprints with per-property merge strategies and conflict detection
  • Integration: CLI worker and website remote worker updated to use the new TS runner; client handler unchanged (same event format)
  • Cleanup: PHP runner files (getV2Runner, runBlueprintV2) emptied and legacy exports removed

Breaking Changes

  • getV2Runner() and runBlueprintV2() exports are removed from @wp-playground/blueprints
  • BlueprintMessage type export is removed (the event format is unchanged, just not exported as a type)

New exports from @wp-playground/blueprints

  • compileBlueprintV2(), extractRuntimeConfig()
  • transpileV1toV2(), mergeBlueprintsV2()
  • validateBlueprintV2(), KNOWN_V2_STEP_NAMES
  • v2StepHandlers, registerV2StepHandler()
  • Types: CompiledBlueprintV2, CompileBlueprintV2Options, V2RuntimeConfig, V2StepHandler, StepExecutionContext, etc.

Test plan

  • 113 unit tests passing across 6 test files (validation, transpilation, V1-to-V2 transpiler, merge, step handlers, compilation)
  • Manual: npm run dev and load a V2 blueprint in browser (?experimental-blueprints-v2-runner&blueprint={"version":2,"plugins":["hello-dolly"]})
  • Manual: npx nx dev playground-cli server --blueprint='{"version":2,"plugins":["hello-dolly"]}'
  • Verify V1 blueprints still work (auto-transpiled to V2)
  • CI passes

🤖 Generated with Claude Code

Add DataReferenceResolverImpl that resolves V2 data references into
concrete file and directory contents. Supports inline files/directories,
HTTP(S) URLs with CORS proxy and semaphore-based concurrency limiting,
execution context paths, and WordPress.org plugin/theme slug resolution.
Add validateBlueprintV2() that performs structural validation of V2
blueprint declarations, including version check, property type checks,
step name validation with fuzzy matching (Levenshtein distance) for
suggesting corrections to misspelled step names. Export the validator
and known step names from the V2 module index.
Fill in extractRuntimeConfig() to read phpVersion, wordpressVersion, and
applicationOptions from the blueprint declaration. String versions are
wrapped as V2VersionConstraint with preferred set. Object constraints map
min/max/preferred (or recommended) fields accordingly.
Wire the compilation pipeline together:
- Add validation via validateBlueprintV2() at the start of compileBlueprintV2()
- Import transpileDeclarativeToSteps from ./transpile-declarative (stub placeholder for Task 8)
- Implement executeSteps() with data reference resolver creation, progress tracking, step handler dispatch, and error wrapping
…options, runPHP, wp-cli, writeFiles)

Implement six V2 step handler modules:

- filesystem.ts: cp, mv, mkdir, rm, rmdir handlers with site: path
  resolution
- define-constants.ts: defineConstants handler using
  WP_Config_Transformer to safely modify wp-config.php
- set-site-options.ts: setSiteOptions handler calling update_option()
  with rewrite rule flushing for permalink_structure
- run-php.ts: runPHP handler that resolves data references to PHP
  source, supports env variables, writes to temp file and executes
- wp-cli.ts: wp-cli handler reusing V1 shell command parsing and
  WP-CLI bootstrap pattern
- write-files.ts: writeFiles handler resolving data references and
  writing to site: prefixed target paths

All handlers self-register via registerV2StepHandler() and are
loaded through side-effect imports in steps/index.ts.
Adds transpileV1toV2() which converts V1 blueprints (no version
property) into V2 format following the spec's mapping tables:

- Top-level: preferredVersions → phpVersion/wordpressVersion,
  landingPage/login/features → applicationOptions, meta → blueprintMeta
- Declarative: constants/siteOptions/plugins → additionalSteps
- Per-step rewrites: field renaming, step name mapping
- Resource → DataReference conversion (url, literal, vfs, bundled, git)
- /wordpress/ path translation

Wired into compileBlueprintV2() for automatic V1 detection and
transpilation before validation. 57 tests.
Adds mergeBlueprintsV2() which merges multiple V2 blueprint
declarations following the spec's composition rules:

- Scalar exclusives (siteLanguage, activeTheme): conflict detection
- Key-value maps (constants, siteOptions, postTypes, fonts): append
  with key conflict detection
- Version constraints: range intersection
- Array by slug (plugins, themes, muPlugins): deduplication
- Append arrays (steps, content, media)
- Users/roles: merge with conflict detection
- applicationOptions: shallow merge per app key

30 tests covering all merge strategies and conflict scenarios.
…te workers

Replace the PHP .phar-based runBlueprintV2() with the new TypeScript
compileBlueprintV2() + compiled.run() pattern in both the CLI worker
and the website remote worker. Progress reporting now uses
ProgressTracker events instead of the old onMessage callback.
The PHP .phar-based runBlueprintV2() and getV2Runner() have been
replaced by the TypeScript compilation pipeline. Empty these files
and remove their exports from the package barrel.
@brandonpayton brandonpayton changed the title feat(blueprints): implement V2 TypeScript blueprint runner [blueprints] Implement blueprints v2 runner in TypeScript Mar 30, 2026
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