Skip to content

Conversation

@bgrgicak
Copy link
Collaborator

@bgrgicak bgrgicak commented Nov 5, 2025

Motivation for the change, related issues

In the past when we had only JSON Blueprints v1 it was easy download and customize a Blueprint with vanilla JS, but today we have Blueprints v1 and v2, JSON Blueprints, and bundles.

For a site that uses the @wp-playground/client package, there's currently no easy way to download a Blueprint and adjust it, but the Playground website has helper functions that enable the query API to fetch and override a Blueprint.

This PR moves the resolveBlueprintFromURL, applyQueryOverrides, parseBlueprint functions, and related types to the @wp-playground/blueprints package, so users can import and use these helper functions.

We had to move the code out of the website package because it isn't public, while the Blueprint package is.

The PR also moves the base64 related helpers to @wp-playground/common as this seemed like a appropriate place for these helpers.

Implementation details

  • Move apply-query-overrides.ts from the website package to the blueprints package
  • Split apply-query-overrides.ts and pesolve-blueprint-from-url.ts
  • Move base64.ts from the website package to the common package
  • Add Node support to decodeBase64ToUint8Array and encodeUint8ArrayAsBase64
  • Add tests for moved functions

Testing Instructions (or ideally a Blueprint)

  • CI

…parseBlueprint functions in the @wp-playground/blueprints package
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the codebase to consolidate base64 utilities and blueprint resolution logic by moving them from website-specific code into shared packages. The changes improve code reusability and better organize the codebase structure.

  • Moved base64 encoding/decoding utilities from packages/playground/website to @wp-playground/common with improved cross-environment support
  • Moved blueprint parsing and URL resolution logic from packages/playground/website to @wp-playground/blueprints
  • Added comprehensive test coverage for the newly relocated functionality

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/playground/website/src/lib/base64.ts Removed file - base64 utilities moved to @wp-playground/common
packages/playground/website/src/lib/state/url/router.ts Removed parseBlueprint function and base64 import, now using blueprints package
packages/playground/website/src/components/site-manager/site-info-panel/index.tsx Updated import to use encodeStringAsBase64 from @wp-playground/common
packages/playground/website/src/lib/state/redux/slice-sites.ts Consolidated imports to use blueprint utilities from @wp-playground/blueprints
packages/playground/common/src/base64.ts Added base64 utilities with Node.js/browser compatibility
packages/playground/common/src/index.ts Exported base64 utilities
packages/playground/common/src/test/base64.spec.ts Added comprehensive tests for base64 utilities
packages/playground/blueprints/src/lib/utils/parse-blueprint.ts New file with parseBlueprint function and documentation
packages/playground/blueprints/src/lib/utils/parse-blueprint.spec.ts Added tests for parseBlueprint function
packages/playground/blueprints/src/lib/resolve-blueprint-from-url.ts Moved blueprint URL resolution logic from website package
packages/playground/blueprints/src/test/resolve-blueprint-from-url.spec.ts Added comprehensive tests for URL resolution
packages/playground/blueprints/src/lib/apply-query-overrides.ts Refactored to separate concerns and use dynamic imports
packages/playground/blueprints/src/test/apply-query-overrides.spec.ts Added comprehensive tests for query overrides
packages/playground/blueprints/src/index.ts Exported new blueprint utilities

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@adamziel
Copy link
Collaborator

adamziel commented Nov 5, 2025

What is the use-case for this? All these functions will either change or be removed to integrate Blueprints v2. In v2, all the logic runs in PHP.

@bgrgicak
Copy link
Collaborator Author

bgrgicak commented Nov 6, 2025

What is the use-case for this?

When using the @wp-playground/client package to run Playground on a site, users sometimes need to override Blueprints. Exporting resolveBlueprintFromURL and applyQueryOverrides will provide an easy way for developers to modify Blueprints (especially bundles).

Here's an example from Calypso where we want to support both JSON Blueprints and bundles, but need the ability to override some Blueprint arguments.
Having access to resolveBlueprintFromURL and applyQueryOverrides would allow us to easily support both types.

Is there a better way to achieve this?

All these functions will either change or be removed to integrate Blueprints v2. In v2, all the logic runs in PHP.

I don't want to export functions that we will plan to remove soon, but the use case I explained here also applies to Blueprints v2. Ideally, a developer should just update Playground packages to the latest version and get Blueprint v2 support alongside v1 support without doing any custom work in their project.

@bgrgicak bgrgicak marked this pull request as ready for review November 6, 2025 07:18
@bgrgicak bgrgicak requested a review from a team November 6, 2025 07:18
@adamziel
Copy link
Collaborator

adamziel commented Nov 6, 2025

need the ability to override some Blueprint arguments.

Which ones? Query API can do it

@bgrgicak
Copy link
Collaborator Author

bgrgicak commented Nov 6, 2025

Which ones?

In my case, we need to set the PHP and WP versions. Also, we need to ensure that login and networking are true.

Query API can do it

Exactly, but before this PR, the Query API was limited to the Playground Website, and now by exporting these functions, it can be used outside of the website. In my case, together with startPlaygroundWeb from the @wp-playground/client package.

Sorry if I'm missing something obvious, but I don't think that there's a way to use the Query API together with startPlaygroundWeb today.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants