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

Playground CLI #1289

Merged
merged 72 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
950d3ee
Try: PHPPool with just acquire(), release(), and grow() mechanics. Sp…
adamziel Apr 20, 2024
68fc634
Self-request prototype
adamziel Apr 20, 2024
b1ea077
Remvoe WebPHPEndpoint methods that wouldn't work anyway
adamziel Apr 21, 2024
01e095f
Replace PHPPool with PHPProcessManager
adamziel Apr 21, 2024
ead4e03
Adjust TypeScript types
adamziel Apr 21, 2024
1212345
Restore the serverOptions argument for PHP
adamziel Apr 21, 2024
648c3ed
EmscriptenDownloadMonitor: Restore the original WebAssembly.instantia…
adamziel Apr 21, 2024
713e030
Clean up PHPRequestHandler
adamziel Apr 21, 2024
038f2a1
Clean up worker-thread-utils
adamziel Apr 21, 2024
acbe5ce
Restore the original rotate-php-runtime.spec.ts
adamziel Apr 21, 2024
a07c05d
Only download the .wasm file once and then reuse the response on subs…
adamziel Apr 21, 2024
12b6730
Document setting the "url" property
adamziel Apr 21, 2024
3f9cbf4
Compose fetch middlewares
adamziel Apr 21, 2024
d56f881
Document why we need primary PHP and replicas instead of giving all P…
adamziel Apr 21, 2024
bbe673c
Move 502 error handling to WebPHPEndpoint for now
adamziel Apr 21, 2024
edbd99f
createCachedFetch: Write to cache synchronously to avoid duplicate re…
adamziel Apr 21, 2024
764c55e
Document memoizedFetch(), reorder functions in worker-utils.ts
adamziel Apr 21, 2024
ce117f2
Spawn new PHP instances for handling requests in PHPRequestHandler
adamziel Apr 22, 2024
ebc18fe
Resolve type errors
adamziel Apr 22, 2024
f299fb3
Remove php.request() calls from unit tests
adamziel Apr 22, 2024
87a1326
Adjust unit tests
adamziel Apr 22, 2024
6271d2b
Actually use PHPProcessManager constructor args :)
adamziel Apr 22, 2024
82eff10
Remove PHPBrowser class, manage cookies in PHPRequestHandler
adamziel Apr 22, 2024
9ab8a04
Fix typo
adamziel Apr 22, 2024
af8cd9d
Fix type errors
adamziel Apr 22, 2024
c63bbcb
Null check in rememberCookiesFromResponse
adamziel Apr 22, 2024
3250aec
Simplify WebPHPEndpoint
adamziel Apr 22, 2024
277974e
Provide DOCUMENT_ROOT in php.run() tests
adamziel Apr 22, 2024
0e28d97
Fix unit tests
adamziel Apr 22, 2024
bd5bde6
PHPProcessManager: Wait up to a timeout before giving up on spawning …
adamziel Apr 22, 2024
7c32081
Explore: PHP server
adamziel Apr 21, 2024
048ede5
Compat with the new PHPProcessManager API
adamziel Apr 22, 2024
8235d27
Fix ts lint errpr
adamziel Apr 22, 2024
4cd619d
Support --login option, add a bun-server.sh script for testing
adamziel Apr 22, 2024
a28a2ac
Download WordPress, SQLite plugin, pre-install WordPress, store it in…
adamziel Apr 22, 2024
d884281
Start cli.ts by inferring a Blueprint from CLi args
adamziel Apr 23, 2024
c4402da
Document the used bun extension
adamziel Apr 23, 2024
16dbba8
Document the Bun plugin
adamziel Apr 23, 2024
ce58605
Remove the old main.ts file
adamziel Apr 23, 2024
375d836
Document parts of Playground CLI
adamziel Apr 23, 2024
b00bc28
Expect the WordPress zip file to either contain a "wordpress" directo…
adamziel Apr 23, 2024
898af44
Simoplify the regexp
adamziel Apr 23, 2024
6026d5f
Add a "build" command to allow just building a Blueprint to zip
adamziel Apr 24, 2024
3b3d309
Add a TODO to buildCommandHandler
adamziel Apr 24, 2024
3c49b1d
Show help message when missing command
adamziel Apr 24, 2024
5e0cb9f
Bundle Playground CLI with Bun
adamziel Apr 24, 2024
b5e10ce
Better document the mount option
adamziel Apr 24, 2024
b8ce8ba
Redirect /wp-admin to /wp-admin/
adamziel Apr 24, 2024
dd53b5f
Remove the 'PHP.request() is deprecated. Please use new PHPRequest…
adamziel Apr 24, 2024
9f5cf3a
Add Usage, wrap yargs to terminal width
adamziel Apr 24, 2024
581c53c
Fix whitespace in log messages
adamziel Apr 24, 2024
0b77fc3
BasePHP: Check if (this[__private__dont__use]) before deleting the on…
adamziel Apr 25, 2024
8a86d12
Merge trunk
adamziel Apr 25, 2024
8410258
getInstance -> acquirePHPInstance
adamziel Apr 25, 2024
86c0898
Bring trunk chnges
adamziel Apr 25, 2024
3e8c938
Rm playground node
adamziel Apr 25, 2024
004910a
Merge branch 'trunk' into node-server
adamziel Apr 25, 2024
2b3806e
Merge branch 'trunk' into node-server
adamziel Apr 29, 2024
d8109d9
Run server before start executing blueprint
adamziel Apr 29, 2024
80ae10f
Always run the PHP server, add a "run-blueprint" command
adamziel Apr 29, 2024
d694350
Lint, typecheck
adamziel Apr 29, 2024
4c5916f
Fix php-wasm-node build
adamziel Apr 29, 2024
5009c02
Remove dev artifacts
adamziel Apr 29, 2024
5011abe
Fix build
adamziel Apr 29, 2024
680e63d
Add wasm loader for vire
adamziel Apr 29, 2024
2103da4
Add viteWasmLoader to remaining vite configs
adamziel Apr 29, 2024
9a34b72
Adjust package.json entries to get playground-cli to load in Node
adamziel Apr 29, 2024
1260c28
Remove unnecessary php.ini
adamziel Apr 29, 2024
d5da691
Remove dev artifacts
adamziel Apr 29, 2024
809767f
Rename the CLI build script to wp-playground
adamziel Apr 29, 2024
0dfb89b
Add `--quiet` CLI arg, silence the .request() warning when needed
adamziel Apr 29, 2024
917f99e
v0.7.2
adamziel Apr 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
preload = ["./packages/bun-extensions/src/import-files-as-text.ts"]
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useWorkspaces": true,
"version": "0.7.1",
"version": "0.7.2",
"useNx": true
}
44 changes: 26 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions packages/bun-extensions/src/import-files-as-text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { plugin, BunPlugin } from 'bun';

/**
* Adds support for `import contents from "file.php?raw"`.
*
* It matches Vite's behavior, which is to read the file as text
* and return its textual content. This allows us to run Bun and
* Vite on the same codebase.
*/
export const ImportFilesAsTextPlugin: BunPlugin = {
name: 'ImportFilesAsTextPlugin',
setup(build) {
build.onLoad(
{
// Looks for paths with a `raw` query parameter.
filter: /[?&]raw(?:[&=]|$)/,
},
async (args) => {
const path = args.path.split('?')[0];
// Use Bun.file to read the .php file as text
const text = await Bun.file(path).text();

// Return the file content as a module exporting the text
return {
contents: `export default ${JSON.stringify(text)};`,
loader: 'js', // Treat the content as JavaScript
};
}
);
},
};

plugin(ImportFilesAsTextPlugin);
2 changes: 1 addition & 1 deletion packages/php-wasm/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@php-wasm/cli",
"version": "0.7.1",
"version": "0.7.2",
"description": "PHP.wasm CLI for node.js",
"repository": {
"type": "git",
Expand Down
6 changes: 1 addition & 5 deletions packages/php-wasm/compile/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -1023,11 +1023,7 @@ RUN set -euxo pipefail; \
# Turn the php.js file into an ES module
# Manually turn the output into a esm module instead of relying on -s MODULARIZE=1.
# which pollutes the global namespace and does not play well with import() mechanics.
if [ "$EMSCRIPTEN_ENVIRONMENT" = "node" ]; then \
echo "const dependencyFilename = __dirname + '/${PHP_VERSION_ESCAPED}/$WASM_FILENAME'; " >> /root/output/php-module.js; \
else \
echo "import dependencyFilename from './${PHP_VERSION_ESCAPED}/$WASM_FILENAME'; " >> /root/output/php-module.js; \
fi; \
echo "import dependencyFilename from './${PHP_VERSION_ESCAPED}/$WASM_FILENAME'; " >> /root/output/php-module.js; \
echo "export { dependencyFilename }; " >> /root/output/php-module.js && \
echo "export const dependenciesTotalSize = $FILE_SIZE; " >> /root/output/php-module.js && \
cat /root/esm-prefix.js >> /root/output/php-module.js && \
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/fs-journal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@php-wasm/fs-journal",
"version": "0.7.1",
"version": "0.7.2",
"description": "Bindings to journal the PHP filesystem",
"repository": {
"type": "git",
Expand Down
5 changes: 5 additions & 0 deletions packages/php-wasm/fs-journal/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { join } from 'path';
// eslint-disable-next-line @nx/enforce-module-boundaries
import { viteTsConfigPaths } from '../../vite-ts-config-paths';

// eslint-disable-next-line @nx/enforce-module-boundaries
import { viteWasmLoader } from '../../vite-wasm-loader';

export default defineConfig({
cacheDir: '../../../node_modules/.vite/php-wasm-fs-journal',

Expand All @@ -19,6 +22,8 @@ export default defineConfig({
viteTsConfigPaths({
root: '../../../',
}),

viteWasmLoader,
],

// Configuration for building your library.
Expand Down
5 changes: 3 additions & 2 deletions packages/php-wasm/logger/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@php-wasm/logger",
"version": "0.7.1",
"version": "0.7.2",
"description": "A logger for PHP-wasm clients like Playground and WP-now.",
"repository": {
"type": "git",
Expand All @@ -19,7 +19,8 @@
"directory": "../../../dist/packages/php-wasm/logger"
},
"license": "GPL-2.0-or-later",
"main": "index.cjs",
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"engines": {
"node": ">=18.18.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node-polyfills/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@php-wasm/node-polyfills",
"version": "0.7.1",
"version": "0.7.2",
"description": "PHP.wasm – polyfills for Node.js",
"repository": {
"type": "git",
Expand Down
37 changes: 37 additions & 0 deletions packages/php-wasm/node/bin/postprocess-php-modules.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Replaces `import dependencyFilename from ` with `const dependencyFilename = __dirName + `
* in all files matching glob `php_*.js` in directory specified by argv[0].
*
* We need this to:
*
* * Produce a CommonJS and ESM-compliant module using Vite
* * Make the uncompiled source compatible with Bun
*/
const fs = require('fs');
const glob = require('glob');

const directory = process.argv[2];

const files = glob.globSync(`${directory}/php_*.js`);
files.forEach((file) => {
fs.readFile(file, 'utf8', (err, data) => {
if (err) {
console.error(err);
return;
}

const updatedData = data.replace(
'import dependencyFilename from ',
'const dependencyFilename = __dirname + '
);

fs.writeFile(file, updatedData, 'utf8', (err) => {
if (err) {
console.error(err);
return;
}

console.log(`Updated file: ${file}`);
});
});
});
2 changes: 1 addition & 1 deletion packages/php-wasm/node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@php-wasm/node",
"version": "0.7.1",
"version": "0.7.2",
"description": "PHP.wasm for Node.js",
"repository": {
"type": "git",
Expand Down
4 changes: 3 additions & 1 deletion packages/php-wasm/node/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"executor": "nx:run-commands",
"options": {
"commands": [
"cp -rf packages/php-wasm/node/public/* dist/packages/php-wasm/node"
"cp -rf packages/php-wasm/node/public/* dist/packages/php-wasm/node",
"node packages/php-wasm/node/bin/postprocess-php-modules.cjs dist/packages/php-wasm/node",
"rm -rf dist/packages/php-wasm/node/*.wasm"
],
"parallel": false
},
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_7_0.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const dependencyFilename = __dirname + '/7_0_33/php_7_0.wasm';
import dependencyFilename from './7_0_33/php_7_0.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 13118939;
export function init(RuntimeName, PHPLoader) {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_7_1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const dependencyFilename = __dirname + '/7_1_30/php_7_1.wasm';
import dependencyFilename from './7_1_30/php_7_1.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 13643181;
export function init(RuntimeName, PHPLoader) {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_7_2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const dependencyFilename = __dirname + '/7_2_34/php_7_2.wasm';
import dependencyFilename from './7_2_34/php_7_2.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 14335706;
export function init(RuntimeName, PHPLoader) {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_7_3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const dependencyFilename = __dirname + '/7_3_33/php_7_3.wasm';
import dependencyFilename from './7_3_33/php_7_3.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 14441796;
export function init(RuntimeName, PHPLoader) {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_7_4.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const dependencyFilename = __dirname + '/7_4_33/php_7_4.wasm';
import dependencyFilename from './7_4_33/php_7_4.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 14675209;
export function init(RuntimeName, PHPLoader) {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_8_0.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const dependencyFilename = __dirname + '/8_0_30/php_8_0.wasm';
import dependencyFilename from './8_0_30/php_8_0.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 13904218;
export function init(RuntimeName, PHPLoader) {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_8_1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const dependencyFilename = __dirname + '/8_1_23/php_8_1.wasm';
import dependencyFilename from './8_1_23/php_8_1.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 13884035;
export function init(RuntimeName, PHPLoader) {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_8_2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const dependencyFilename = __dirname + '/8_2_10/php_8_2.wasm';
import dependencyFilename from './8_2_10/php_8_2.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 14143340;
export function init(RuntimeName, PHPLoader) {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_8_3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const dependencyFilename = __dirname + '/8_3_0/php_8_3.wasm';
import dependencyFilename from './8_3_0/php_8_3.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 14523141;
export function init(RuntimeName, PHPLoader) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function initOutboundWebsocketProxyServer(

// Handle new WebSocket client
async function onWsConnect(client: any, request: http.IncomingMessage) {
const clientAddr = client._socket.remoteAddress;
const clientAddr = client?._socket?.remoteAddress || client.url;
const clientLog = function (...args: any[]) {
log(' ' + clientAddr + ': ', ...args);
};
Expand Down
7 changes: 6 additions & 1 deletion packages/php-wasm/node/src/lib/node-php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ export class NodePHP extends BasePHP {
*/
@rethrowFileSystemError('Could not mount {path}')
mount(localPath: string | MountSettings, virtualFSPath: string) {
if (!this.fileExists(virtualFSPath)) {
const localRoot =
typeof localPath === 'object' ? localPath.root : localPath;
if (
!this.fileExists(virtualFSPath) &&
lstatSync(localRoot).isDirectory()
) {
this.mkdirTree(virtualFSPath);
}
this[__private__dont__use].FS.mount(
Expand Down
Loading
Loading