Skip to content

Commit

Permalink
Monorepo (WordPress#57)
Browse files Browse the repository at this point in the history
Restructures the repository as monorepo and separates the PHP implementation from the WordPress-specific bits. The new packages:

* **php-wasm** – low-level WASM PHP primitives
    * A configurable PHP build pipeline for different targets (web, node.js, standalone)
    * A low-level `PHP` JavaScript class with `eval` for executing PHP code and FS utils like `writeFile` for runtime managing the
    * A `PHPServer` JavaScript class for dispatching HTTP requests – both to run the PHP files AND to download static files
    * A `PHPBrowser` JavaScript class to consume the above using an iframe
* **php-wasm-browser** – a high-level layer to efficiently run `php-wasm` in the browser
    * `service-worker` utilities to redirect the browser traffic to `PHPServer`
    * `worker-thread` utilities to offload the `PHPServer` to a separate process. Three backends are available: Iframe, Webworker, SharedWorker.
    * A messaging layer and setup helpers to connect the above.
    * Server utilities to serve the correct headers for the `wasm` files via `.htaccess`.
* **wordpress-wasm** – WordPress-specific WASM PHP bindings for web and node.js
    * The required WordPress-specific setup like constants and filters
    * `wp.data` bundling pipeline for the web configurable to bundle custom code
    * WordPress API to ease common tasks like login, install a plugin, start a block editor with specific settings and content
    * A `fetch`-based transport for HTTP requests
    * An example app demonstrating WordPress in the browser. Let's eventually extract it into a separate package or at least a directory.

Other, general notes:

* Pre-built binaries are shipped in the global `build` directory – it would be nice to either move them to their specific packages, or remove them from the repo completely and download them from somewhere on the initial build.
* `esbuild` is used to build each packages and then the entire app.
* Gulp is used for orchestration. Perhaps https://nx.dev/ would make a good replacement in the future.
* There is no package publishing process yet. Perhaps Lerna would make a good one?

Solves WordPress#51 and WordPress#16
  • Loading branch information
adamziel authored Oct 22, 2022
1 parent 228ccc3 commit e45cbf1
Show file tree
Hide file tree
Showing 7,570 changed files with 6,870 additions and 1,591,834 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
7 changes: 2 additions & 5 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
node_modules/**/*
wasm-build/**/*
dist-web/**/*
dist-node/**/*
src/node/wordpress/**/*
node-php.js
build/*
packages/*/build*/*
24 changes: 12 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.DS_Store
.idea
.local
node_modules
package-lock.json
wasm-build/php/docker-output/*
!wasm-build/php/docker-output/.gitkeep
wasm-build/wordpress-data/docker-output/*
!wasm-build/wordpress-data/docker-output/.gitkeep
wasm-build/wordpress-data/preload/wordpress*
dist-web/wp-lazy-files.js
dist-web/service-worker.js
dist-web/wasm-worker.js
dist-web/app.js
dist-web/*.html
dist-web/wp-lazy-files.js

build/*
!build/wp-admin
!build/wp-content
!build/wp-includes
!build/php.wasm
!build/php-web.js
!build/php-webworker.js
!build/wp.data
!build/wp.js
packages/*/build*
packages/*/build*/*
7 changes: 2 additions & 5 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
node_modules/**/*
wasm-build/**/*
dist-web/**/*
dist-node/**/*
src/node/wordpress/**/*
node-php.js
build/*
packages/*/build*/*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ npm run build:php:node
## Building custom WordPress bundle

If you'd like to customize the packaged WordPress installation, update
the build script at `wasm-build/wordpress-data/prepare-wordpress.sh`. It generates a bundle called `wp.data`.
the build script at `packages/wordpress-wasm/wordpress/prepare-wordpress.sh`. It generates a bundle called `wp.data`.

For example, before the comment "Prepare WordPress static files":

Expand Down
158 changes: 0 additions & 158 deletions build.js

This file was deleted.

11 changes: 11 additions & 0 deletions build/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
AddType application/wasm .wasm

RewriteEngine on
RewriteRule ^scope:.*?/(.*)$ $1 [NC]

<FilesMatch "iframe-worker.html$">
Header set Origin-Agent-Cluster: ?1
</FilesMatch>

RewriteEngine on
RewriteRule ^plugin-proxy$ plugin-proxy.php [NC]
21 changes: 21 additions & 0 deletions build/php-web.js

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions build/php-webworker.js

Large diffs are not rendered by default.

Binary file added build/php.wasm
Binary file not shown.
Loading

0 comments on commit e45cbf1

Please sign in to comment.