|
| 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 | + ``` |
0 commit comments