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: php command doesn't work for relative path #16

Closed
wojtekn opened this issue May 22, 2023 · 1 comment · Fixed by #75
Closed

wp-now: php command doesn't work for relative path #16

wojtekn opened this issue May 22, 2023 · 1 comment · Fixed by #75
Assignees
Labels
Bug Something isn't working wp-now

Comments

@wojtekn
Copy link
Collaborator

wojtekn commented May 22, 2023

When I use wp-now in development mode, symlinked using npm link, and I try executing PHP script in the current directory, I get an error:

$ wp-now php test.php 
[...nx build output here...]
Error: Could not open input file: /Volumes/Sites/wordpress-playground/test.php
    at executePHPFile (file:///Volumes/Sites/wordpress-playground/dist/packages/wp-now/main.js:797:11)
    at async Object.handler (file:///Volumes/Sites/wordpress-playground/dist/packages/wp-now/main.js:895:9)

When I use an absolute path, it works:

$ wp-now php /Volumes/Sites/vip-directory/test.php
[...nx build output here...]
Hello World!

When I install it using npm, it works in both cases:

$ wp-now php test.php                                     
Hello World!

Done is

  • I can use relative path parameter in both development and compiled modes
@adamziel
Copy link
Collaborator

good catch!

@danielbachhuber danielbachhuber transferred this issue from WordPress/wordpress-playground May 31, 2023
@wojtekn wojtekn self-assigned this Jun 8, 2023
wojtekn added a commit that referenced this issue Jun 23, 2023
<!-- Thanks for contributing to WordPress Playground Tools! -->
Fixes #16

## What?

<!-- In a few words, what is the PR actually doing? Include screenshots
or screencasts if applicable -->

I get an error when I use wp-now in development mode, symlinked using
the `npm link`, and try executing the PHP script in the current
directory.

## Why?

<!-- Why is this PR necessary? What problem is it solving? Reference any
existing previous issue(s) or PR(s), but please add a short summary
here, too -->

`wp-now php` should work in both cases consistently.

## How?

<!-- How is your PR addressing the issue at hand? What are the
implementation details? -->
PR adds a code that replaces the second argument with its absolute
version if the absolute version exists in the filesystem.

## Testing Instructions

1. Create a hello world PHP script
2. Run it with an absolute path
```
$ wp-now php /Volumes/Sites/vip-directory/test.php
```
3. Run it using the relative path
```
$ wp-now php test.php
```

Test both cases for wp-now installed using npm and for wp-now symlinked
using `npm link`.
johnhooks pushed a commit to johnhooks/playground-tools that referenced this issue 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
Labels
Bug Something isn't working wp-now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants