Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp-now: Treat wp-content in a subdirectory as 'wp-content' mode #51

Closed
wants to merge 4 commits into from

Conversation

danielbachhuber
Copy link
Member

See #39 (comment)
Related #26

What?

Treats a repository structure like https://github.com/WordPress/Learn as 'wp-content' mode:

image

Specifically, in the Learn repository, the wp-content directory is a subdirectory of the repository, and contains plugins and themes directories.

Why?

  • We want to support the Learn repository structure.
  • We don't want to introduce a new mode.
  • Our 'wordpress' mode is described as Runs the directory as a WordPress installation when WordPress files are detected, so it's not appropriate.

How?

  • Adapts isWpContentDirectory() to first look in the immediate directory for plugins or themes, and then also look in a wp-content subdirectory (if one exists) for plugins or themes too.
  • Updates runWpContentMode() to handle both variations of directory structures.

Testing Instructions

  1. Set up the WordPress/Learn repository:
git clone [email protected]:WordPress/Learn.git wordpress-learn
cd wordpress-learn
yarn
composer install
yarn workspaces run build
  1. Run nx preview wp-now start --path=/path/to/learn-repository
  2. Verify plugins and themes are mounted as expected.
  3. Test nx preview wp-now start against a few other modes and verify it works as expected.

php.mount(projectPath, `${documentRoot}/wp-content`);
} else {
php.mount(projectPath, documentRoot);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

@sejas Any ideas why the Learn wp-content directory isn't being mounted correctly?

image

Copy link
Member Author

@danielbachhuber danielbachhuber Jun 1, 2023

Choose a reason for hiding this comment

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

As it turns out, it was following the first part of the conditional because there were some hidden directories (#32):

image

The hidden directories existed because I previously ran wp-now start in the directory.

When I remove the hidden directories, I see this crash:

Error: Could not mount /Users/danielbachhuber/projects/wordpress-learn: Device or resource busy.
    at _NodePHP.descriptor.value (/Users/danielbachhuber/projects/playground-tools/node_modules/@php-wasm/node/index.cjs:67405:17)
    at runWpContentMode (file:///Users/danielbachhuber/projects/playground-tools/dist/packages/wp-now/main.js:590:9)
    at async file:///Users/danielbachhuber/projects/playground-tools/dist/packages/wp-now/main.js:535:9
    at async applyToInstances (file:///Users/danielbachhuber/projects/playground-tools/dist/packages/wp-now/main.js:481:5)
    at async startWPNow (file:///Users/danielbachhuber/projects/playground-tools/dist/packages/wp-now/main.js:532:3)
    at async startServer (file:///Users/danielbachhuber/projects/playground-tools/dist/packages/wp-now/main.js:780:42)
    at async Object.handler (file:///Users/danielbachhuber/projects/playground-tools/dist/packages/wp-now/main.js:925:25) {

However, if wp-now creates hidden directories each time it starts, we'll revert to the first behavior after it starts...

Copy link
Member Author

Choose a reason for hiding this comment

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

With more reflection, I kinda think this particular scenario would be better solved by #19

Copy link
Collaborator

@sejas sejas Jun 2, 2023

Choose a reason for hiding this comment

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

@sejas Any ideas why the Learn wp-content directory isn't being mounted correctly?
@danielbachhuber , I debugged the code and php.mount(projectPath, documentRoot); is trying to mount twice the same destinationdocumentRoot. This directory was already mounted with the WordPress latest files.

A simple suggestion would be mounting the wp-content folders.

- php.mount(projectPath, documentRoot);
+ php.mount(`${projectPath}/wp-content`, `${documentRoot}/wp-content`);

But this approach would be "similar" as running wp-now directly from inside the wp-content folder.

A more elaborated approach would be mounting each subfolder/file independently resulting on a "merge" between core and the plugin, maybe even recursively if we want that themes folder contains twentytwentythree.

This is what I see with the simple approach:

Themes:

Screenshot 2023-06-02 at 19 22 32

Plugins:

Screenshot 2023-06-02 at 19 22 47

Copy link
Collaborator

Choose a reason for hiding this comment

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

I already pushed the simple fix: 1b2260f

Copy link
Member Author

Choose a reason for hiding this comment

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

@sejas Thanks for taking a look at this!

I think I'm leaning towards not shipping this pull request, and instead solving this with #19

I'm not strongly opinionated about it, though. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Mapping folders is a more general fix, let's go for it. 👍

@danielbachhuber danielbachhuber deleted the improve/wp-now-wp-content-v2 branch June 6, 2023 10:10
johnhooks pushed a commit to johnhooks/playground-tools that referenced this pull request Oct 11, 2024
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
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