PHP.wasm: Load correct php.wasm paths in the built Node.js packages #1877
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Gets
@php-wasm/node
and all the other CLI packages to load the .wasmbinaries from the correct path after #1867 introduced JSPI and #1873 made
it pass all the tests in Node.js
Technical details
In the repo, php.js files are stored in php_wasm/node/jspi or php_wasm/node/asyncify.
They start with a line like this:
const dependencyFilename = __dirname + '/8_0_30/php_8_0.wasm';
After the build, the contents are concatenated into a single file, which
breaks the dependencyFilename variable. This plugin corrects that by
replacing __dirname with the correct value such as 'jspi' or 'asyncify'.
The implementation is naive and assumes the substrings __dirname is only used
as a variable, are not a part of any other name, and is not seen in any string
literals.
Test plan
Build the production packages with
nx build php-wasm-node
and run the PHP CLI package to confirm it doesn't crash. I couldn't get npm link to work so I created adist/packages/php-wasm/node_modules/@php-wasm
directory and linked all the built packages there withln -s
.