Skip to content

Commit 4a7c181

Browse files
authored
Add documentation for testing with local Playground packages (#2144)
1 parent 11530fc commit 4a7c181

3 files changed

Lines changed: 118 additions & 7 deletions

File tree

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ If you find a bug or have a feature request, please [open an issue](https://gith
2222

2323
For information on setting up your development environment for contributing code, see the [Code Contributions](./docs/code-contributions.md).
2424

25+
For testing Studio with local WordPress Playground packages, see [Testing with Local Playground](./docs/testing-with-local-playground.md).
26+
2527
We are truly grateful for any pull requests you open, and we assure you of our welcoming and respectful approach. We will review and consider all pull requests, valuing the diverse contributions, but we don’t guarantee that all proposed changes will be merged into the core.
2628

2729
The most desirable pull requests are:
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Testing with Local Playground Packages
2+
3+
When developing features that require changes to WordPress Playground packages (`@wp-playground/*` or `@php-wasm/*`), you can test Studio with locally built Playground packages.
4+
5+
## Prerequisites
6+
7+
Clone the WordPress Playground repository alongside the Studio repository:
8+
9+
```
10+
Code/
11+
├── studio/
12+
└── wordpress-playground/
13+
```
14+
15+
**Important:** Make sure to initialize git submodules:
16+
17+
```bash
18+
cd /path/to/wordpress-playground
19+
git submodule update --init --recursive
20+
```
21+
22+
## Setup Steps
23+
24+
### 1. Build Playground packages
25+
26+
```bash
27+
cd /path/to/wordpress-playground
28+
npm install
29+
npm run build
30+
```
31+
32+
### 2. Update Studio's package.json
33+
34+
Replace the existing Playground dependencies with local file references. These packages are grouped together at the end of `dependencies` in `package.json` for easier replacement:
35+
36+
```json
37+
{
38+
"dependencies": {
39+
"@php-wasm/node": "file:../wordpress-playground/dist/packages/php-wasm/node",
40+
"@php-wasm/scopes": "file:../wordpress-playground/dist/packages/php-wasm/scopes",
41+
"@php-wasm/universal": "file:../wordpress-playground/dist/packages/php-wasm/universal",
42+
"@wp-playground/blueprints": "file:../wordpress-playground/dist/packages/playground/blueprints",
43+
"@wp-playground/cli": "file:../wordpress-playground/dist/packages/playground/cli",
44+
"@wp-playground/wordpress": "file:../wordpress-playground/dist/packages/playground/wordpress"
45+
}
46+
}
47+
```
48+
49+
### 3. Update Playground's node_modules symlinks
50+
51+
Playground's built packages import other packages from `node_modules`. By default, these point to source directories, but we need them to point to the built `dist/` packages.
52+
53+
Run this from the wordpress-playground root:
54+
55+
```bash
56+
cd /path/to/wordpress-playground
57+
58+
for pkg in node-polyfills logger util progress fs-journal stream-compression scopes universal node web web-service-worker cli xdebug-bridge; do
59+
if [ -d "dist/packages/php-wasm/$pkg" ]; then
60+
rm -rf "node_modules/@php-wasm/$pkg" && ln -s "../../dist/packages/php-wasm/$pkg" "node_modules/@php-wasm/$pkg"
61+
fi
62+
done
63+
64+
for pkg in cli blueprints wordpress common storage client remote components wordpress-builds; do
65+
if [ -d "dist/packages/playground/$pkg" ]; then
66+
rm -rf "node_modules/@wp-playground/$pkg" && ln -s "../../dist/packages/playground/$pkg" "node_modules/@wp-playground/$pkg"
67+
fi
68+
done
69+
```
70+
71+
### 4. Install dependencies in Studio
72+
73+
```bash
74+
cd /path/to/studio
75+
npm install
76+
```
77+
78+
### 5. Start Studio
79+
80+
```bash
81+
npm start
82+
```
83+
84+
## Development Workflow
85+
86+
After making changes to Playground:
87+
88+
1. Rebuild the changed package(s):
89+
```bash
90+
cd /path/to/wordpress-playground
91+
npx nx build playground-cli # or other package name
92+
```
93+
94+
2. Restart Studio (restart `npm start`)
95+
96+
## Reverting to npm Packages
97+
98+
To go back to using the published npm packages:
99+
100+
1. Restore both `package.json` and `package-lock.json`:
101+
```bash
102+
git checkout package.json package-lock.json
103+
```
104+
2. Run `npm install`
105+
3. In the Playground repo, restore the original `node_modules` symlinks:
106+
```bash
107+
cd /path/to/wordpress-playground
108+
npm install
109+
```

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@
109109
"@formatjs/intl-locale": "^3.4.5",
110110
"@formatjs/intl-localematcher": "^0.5.4",
111111
"@inquirer/prompts": "^7.10.1",
112-
"@php-wasm/node": "^3.0.22",
113-
"@php-wasm/scopes": "^3.0.22",
114-
"@php-wasm/universal": "^3.0.22",
115112
"@reduxjs/toolkit": "^2.7.0",
116113
"@rive-app/react-canvas": "^4.12.0",
117114
"@sentry/electron": "^6.5.0",
@@ -122,9 +119,6 @@
122119
"@wordpress/dataviews": "^10.2.0",
123120
"@wordpress/i18n": "^6.1.0",
124121
"@wordpress/icons": "^11.1.0",
125-
"@wp-playground/blueprints": "^3.0.22",
126-
"@wp-playground/cli": "^3.0.22",
127-
"@wp-playground/wordpress": "^3.0.22",
128122
"archiver": "^6.0.1",
129123
"atomically": "^2.0.3",
130124
"cli-table3": "^0.6.5",
@@ -158,7 +152,13 @@
158152
"wpcom-xhr-request": "^1.3.0",
159153
"yargs": "^18.0.0",
160154
"yauzl": "^3.2.0",
161-
"zod": "^3.24.3"
155+
"zod": "^3.24.3",
156+
"@php-wasm/node": "^3.0.22",
157+
"@php-wasm/scopes": "^3.0.22",
158+
"@php-wasm/universal": "^3.0.22",
159+
"@wp-playground/blueprints": "^3.0.22",
160+
"@wp-playground/cli": "^3.0.22",
161+
"@wp-playground/wordpress": "^3.0.22"
162162
},
163163
"optionalDependencies": {
164164
"appdmg": "^0.6.6"

0 commit comments

Comments
 (0)