Skip to content

[CLI] Use one worker for Blueprint v1 and v2 - #4227

Open
adamziel wants to merge 1 commit into
WordPress:trunkfrom
articles-adamziel-com:adamziel/unify-blueprint-workers
Open

[CLI] Use one worker for Blueprint v1 and v2#4227
adamziel wants to merge 1 commit into
WordPress:trunkfrom
articles-adamziel-com:adamziel/unify-blueprint-workers

Conversation

@adamziel

Copy link
Copy Markdown
Collaborator

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.js and one worker-thread.cjs. WorkerType is removed, and spawnWorkerThread() no longer accepts a Blueprint version.

Testing Instructions (or ideally a Blueprint)

  1. Run npm exec nx test-playground-cli playground-cli.
  2. Run npm exec nx build playground-cli.
  3. Confirm the package contains worker-thread.js and worker-thread.cjs, with no versioned worker artifacts.

Copilot AI review requested due to automatic review settings July 31, 2026 15:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 WorkerType and updates spawnWorkerThread() 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));
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.

2 participants