Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions blueprint-test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"steps": [
{
"step": "mkdir",
"path": "wordpress/wp-content/mu-plugins"
},
{
"step": "writeFile",
"path": "wordpress/wp-content/mu-plugins/load.php",
"data": "<?php var_dump( get_class($GLOBALS['wpdb']->dbh));"
}
],
"login": true,
"preferredVersions": {
"php": "8.3",
"wp": "latest"
},
"features": {}
}
4 changes: 4 additions & 0 deletions blueprint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"login": true,
"steps": []
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,9 @@
},
"optionalDependencies": {
"fs-ext": "2.1.1"
},
"volta": {
"node": "23.10.0",
"npm": "10.9.0"
}
}
9 changes: 9 additions & 0 deletions packages/php-wasm/logger/src/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ export class Logger extends EventTarget {
}
}

/**
* Get the current severity filter level.
*
* @returns LogSeverity
*/
public getSeverityFilterLevel(): LogSeverity {
return this.severity;
}

/**
* Filter message based on severity
* @param severity LogSeverity
Expand Down
21 changes: 19 additions & 2 deletions packages/playground/cli/src/blueprints-v1/worker-thread-v1.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { logger } from '@php-wasm/logger';
import type { FileLockManager } from '@php-wasm/node';
import { loadNodeRuntime } from '@php-wasm/node';
import { EmscriptenDownloadMonitor } from '@php-wasm/progress';
Expand All @@ -18,9 +19,14 @@ import {
} from '@wp-playground/wordpress';
import { rootCertificates } from 'tls';
import { jspi } from 'wasm-feature-detect';
import { MessageChannel, type MessagePort, parentPort } from 'worker_threads';
import {
MessageChannel,
type MessagePort,
parentPort,
workerData,
} from 'worker_threads';
import { mountResources } from '../mounts';
import { logger } from '@php-wasm/logger';
import { LogVerbosity, type WorkerData } from '../run-cli';

export interface Mount {
hostPath: string;
Expand Down Expand Up @@ -311,6 +317,17 @@ export class PlaygroundCliBlueprintV1Worker extends PHPWorker {
}
}

// Configure logger verbosity from workerData
if (typeof workerData === 'object') {
const verbosity = (workerData as WorkerData).verbosity;
const severity = Object.values(LogVerbosity).find(
(v) => v.name === verbosity
)?.severity;
if (severity) {
logger.setSeverityFilterLevel(severity);
}
}

process.on('unhandledRejection', (e: any) => {
logger.error('Unhandled rejection:', e);
});
Expand Down
20 changes: 18 additions & 2 deletions packages/playground/cli/src/blueprints-v2/worker-thread-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ import { bootRequestHandler } from '@wp-playground/wordpress';
import { existsSync } from 'fs';
import path from 'path';
import { rootCertificates } from 'tls';
import { MessageChannel, type MessagePort, parentPort } from 'worker_threads';
import {
MessageChannel,
type MessagePort,
parentPort,
workerData,
} from 'worker_threads';
import type { Mount } from '../mounts';
import { type RunCLIArgs, LogVerbosity, type WorkerData } from '../run-cli';
import { jspi } from 'wasm-feature-detect';
import { type RunCLIArgs } from '../run-cli';
import type {
PhpIniOptions,
PHPInstanceCreatedHook,
Expand Down Expand Up @@ -484,6 +489,17 @@ export class PlaygroundCliBlueprintV2Worker extends PHPWorker {
}
}

// Configure logger verbosity from workerData
if (typeof workerData === 'object') {
const verbosity = (workerData as WorkerData).verbosity;
const severity = Object.values(LogVerbosity).find(
(v) => v.name === verbosity
)?.severity;
if (severity) {
logger.setSeverityFilterLevel(severity);
}
}

process.on('unhandledRejection', (e: any) => {
logger.error('Unhandled rejection:', e);
});
Expand Down
20 changes: 18 additions & 2 deletions packages/playground/cli/src/run-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,10 @@ export type SpawnedWorker = {
phpPort: NodeMessagePort;
};

export type WorkerData = {
verbosity: LogVerbosity;
};

async function spawnWorkerThreads(
count: number,
workerType: WorkerType,
Expand Down Expand Up @@ -1139,10 +1143,22 @@ async function spawnWorkerThread(workerType: 'v1' | 'v2') {
// @ts-expect-error
globalThis['__WORKER_V2_URL__'] = './blueprints-v2/worker-thread-v2.ts';
}

// Pass logger verbosity to the worker thread.
const currentSeverity = logger.getSeverityFilterLevel();
const verbosity = Object.values(LogVerbosity).find(
(v) => v.severity === currentSeverity
)?.name;

// Prepare worker options.
const options = {
workerData: { verbosity },
} as const;

if (workerType === 'v1') {
return new Worker(new URL(__WORKER_V1_URL__, import.meta.url));
return new Worker(new URL(__WORKER_V1_URL__, import.meta.url), options);
} else {
return new Worker(new URL(__WORKER_V2_URL__, import.meta.url));
return new Worker(new URL(__WORKER_V2_URL__, import.meta.url), options);
}
}

Expand Down
13 changes: 13 additions & 0 deletions packages/playground/plugin-stats/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# WordPress Playground Plugin Compatibility Stats CLI

This is a simple CLI script that evaluates basic WordPress Playground plugin
compatibility with top N plugins from the WordPress.org plugin repository.

Usage:

```bash
npx nx start playground-plugin-stats --top=10
```

At the moment, the script evaluates whether each of the plugins successfully
activates in WordPress Playground without crashing and logging any errors.
4 changes: 4 additions & 0 deletions packages/playground/plugin-stats/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"private": true,
"type": "module"
}
Loading
Loading