[CLI] Use one worker for Blueprint v1 and v2 - #4227
Open
adamziel wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Consolidates Blueprint v1 and v2 CLI worker threads into a single shared worker implementation, removing duplicated lifecycle code and simplifying the build outputs.
Changes:
- Build emits a single worker entrypoint (
worker-thread.js/worker-thread.cjs) and updates Vite macro replacement accordingly. - Removes
WorkerTypeand updatesspawnWorkerThread()to no longer require a Blueprint version. - Updates handlers and tests to target the unified
PlaygroundCliWorker.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/playground/cli/vite.config.ts | Updates macro/token replacement and entrypoints to generate a single worker artifact. |
| packages/playground/cli/tests/worker-thread-events.spec.ts | Refactors tests to use the unified worker class and removes v1/v2-specific coverage. |
| packages/playground/cli/tests/blueprints-v1-handler.spec.ts | Updates expectations for v1 handler boot options. |
| packages/playground/cli/src/worker-thread.ts | Renames/unifies the worker implementation and updates imports + worker spawning to the new API. |
| packages/playground/cli/src/run-cli.ts | Removes worker type selection and simplifies worker spawning API + macro usage. |
| packages/playground/cli/src/blueprints-v2/blueprints-v2-handler.ts | Switches v2 handler to consume the unified worker API and removes worker-type plumbing. |
| packages/playground/cli/src/blueprints-v1/worker-thread-v1.ts | Deletes the old v1-specific worker implementation. |
| packages/playground/cli/src/blueprints-v1/blueprints-v1-handler.ts | Switches v1 handler to consume the unified worker API and removes worker-type plumbing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+132
to
136
| await (playground as unknown as PlaygroundCliWorker).bootWordPress( | ||
| { | ||
| phpVersion: runtimeConfiguration.phpVersion, | ||
| wpVersion: runtimeConfiguration.wpVersion, | ||
| siteUrl: this.siteUrl, | ||
| wordpressInstallMode: |
Comment on lines
+62
to
66
| describe('Playground CLI worker', () => { | ||
| test('listeners receive events from every PHP instance', async () => { | ||
| const worker = new TestableWorker(); | ||
| const phpA = createMockPHP(); | ||
| const phpB = createMockPHP(); |
Comment on lines
+2046
to
+2057
| export function spawnWorkerThread({ | ||
| onExit, | ||
| }: { onExit?: (code: number) => void } = {}) { | ||
| /** | ||
| * When running the CLI from source via `node cli.ts`, the Vite-provided | ||
| * __WORKER_V1_URL__ and __WORKER_V2_URL__ are undefined. Let's set them to | ||
| * the correct paths. | ||
| * __WORKER_URL__ is undefined. Let's set it to the correct path. | ||
| */ | ||
| if (typeof __WORKER_V1_URL__ === 'undefined') { | ||
| // @ts-expect-error | ||
| globalThis['__WORKER_V1_URL__'] = './blueprints-v1/worker-thread-v1.ts'; | ||
| } | ||
| if (typeof __WORKER_V2_URL__ === 'undefined') { | ||
| if (typeof __WORKER_URL__ === 'undefined') { | ||
| // @ts-expect-error | ||
| globalThis['__WORKER_V2_URL__'] = './blueprints-v2/worker-thread-v2.ts'; | ||
| } | ||
| let worker: Worker; | ||
| if (workerType === 'v1') { | ||
| worker = new Worker(new URL(__WORKER_V1_URL__, import.meta.url)); | ||
| } else { | ||
| worker = new Worker(new URL(__WORKER_V2_URL__, import.meta.url)); | ||
| globalThis['__WORKER_URL__'] = './worker-thread.ts'; | ||
| } | ||
| const worker = new Worker(new URL(__WORKER_URL__, import.meta.url)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation for the change, related issues
Blueprint v1 and v2 used separate CLI worker classes even though the handlers only differ in Blueprint compilation and runtime configuration. The duplicated worker lifecycle had to stay aligned and produced two package entrypoints.
Implementation details
Both handlers now boot the same
PlaygroundCliWorker. The worker owns PHP and WordPress booting, mounts, subprocesses, file locking, event forwarding, and disposal; each handler still owns its version-specific compilation and options.The CLI build now emits one
worker-thread.jsand oneworker-thread.cjs.WorkerTypeis removed, andspawnWorkerThread()no longer accepts a Blueprint version.Testing Instructions (or ideally a Blueprint)
npm exec nx test-playground-cli playground-cli.npm exec nx build playground-cli.worker-thread.jsandworker-thread.cjs, with no versioned worker artifacts.