Skip to content

Commit 2cb1c48

Browse files
authored
[CLI] Move Blueprints v2 to Playground CLI package (#2364)
## Motivation for the change, related issues Moves Blueprints v2 `.phar` file and the TypeScript module into the `@wp-playground/cli` package and brushes up its logic. This PR only moves dead code around. However, it also changes the dependency graph of the project and affects the computed package.json files, as in `@wp-playground/cli` now depends on `fs-ext`. For that reason, there's also a change in the build machinery. Also, `v2.spec.ts` uncovered a piping issue where polling after closing the pipe caused a fatal error. Therefore, this PR adds an FS.isClosed() check. A part of #2281 ## Testing plan CI
1 parent 4b1532b commit 2cb1c48

File tree

19 files changed

+478
-470
lines changed

19 files changed

+478
-470
lines changed

packages/php-wasm/compile/php/php_wasm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ EM_JS(int, wasm_poll_socket, (php_socket_t socketd, int events, int timeout), {
235235
while (true) {
236236
var mask = POLLNVAL;
237237
mask = SYSCALLS.DEFAULT_POLLMASK;
238+
if (FS.isClosed(stream)) {
239+
return ERRNO_CODES.EBADF;
240+
}
238241
if (stream.stream_ops?.poll) {
239242
mask = stream.stream_ops.poll(stream, -1);
240243
}

packages/php-wasm/node/asyncify/php_7_2.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31943,6 +31943,9 @@ export function init(RuntimeName, PHPLoader) {
3194331943
while (true) {
3194431944
var mask = POLLNVAL;
3194531945
mask = SYSCALLS.DEFAULT_POLLMASK;
31946+
if (FS.isClosed(stream)) {
31947+
return ERRNO_CODES.EBADF;
31948+
}
3194631949
if (stream.stream_ops?.poll) {
3194731950
mask = stream.stream_ops.poll(stream, -1);
3194831951
}

packages/php-wasm/node/asyncify/php_7_3.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31943,6 +31943,9 @@ export function init(RuntimeName, PHPLoader) {
3194331943
while (true) {
3194431944
var mask = POLLNVAL;
3194531945
mask = SYSCALLS.DEFAULT_POLLMASK;
31946+
if (FS.isClosed(stream)) {
31947+
return ERRNO_CODES.EBADF;
31948+
}
3194631949
if (stream.stream_ops?.poll) {
3194731950
mask = stream.stream_ops.poll(stream, -1);
3194831951
}

packages/php-wasm/node/asyncify/php_7_4.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31943,6 +31943,9 @@ export function init(RuntimeName, PHPLoader) {
3194331943
while (true) {
3194431944
var mask = POLLNVAL;
3194531945
mask = SYSCALLS.DEFAULT_POLLMASK;
31946+
if (FS.isClosed(stream)) {
31947+
return ERRNO_CODES.EBADF;
31948+
}
3194631949
if (stream.stream_ops?.poll) {
3194731950
mask = stream.stream_ops.poll(stream, -1);
3194831951
}

packages/php-wasm/node/asyncify/php_8_0.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8078,6 +8078,9 @@ export function init(RuntimeName, PHPLoader) {
80788078
if ((stream.flags & 2097155) === 1) {
80798079
return 256 | 4;
80808080
}
8081+
if (!pipe.buckets) {
8082+
return 0;
8083+
}
80818084
for (var bucket of pipe.buckets) {
80828085
if (bucket.offset - bucket.roffset > 0) {
80838086
return 64 | 1;
@@ -31943,6 +31946,9 @@ export function init(RuntimeName, PHPLoader) {
3194331946
while (true) {
3194431947
var mask = POLLNVAL;
3194531948
mask = SYSCALLS.DEFAULT_POLLMASK;
31949+
if (FS.isClosed(stream)) {
31950+
return ERRNO_CODES.EBADF;
31951+
}
3194631952
if (stream.stream_ops?.poll) {
3194731953
mask = stream.stream_ops.poll(stream, -1);
3194831954
}
@@ -31961,8 +31967,9 @@ export function init(RuntimeName, PHPLoader) {
3196131967
if (
3196231968
typeof FS == 'undefined' ||
3196331969
!(e.name === 'ErrnoError')
31964-
)
31970+
) {
3196531971
throw e;
31972+
}
3196631973
return -e.errno;
3196731974
}
3196831975
}

packages/php-wasm/node/asyncify/php_8_1.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31943,6 +31943,9 @@ export function init(RuntimeName, PHPLoader) {
3194331943
while (true) {
3194431944
var mask = POLLNVAL;
3194531945
mask = SYSCALLS.DEFAULT_POLLMASK;
31946+
if (FS.isClosed(stream)) {
31947+
return ERRNO_CODES.EBADF;
31948+
}
3194631949
if (stream.stream_ops?.poll) {
3194731950
mask = stream.stream_ops.poll(stream, -1);
3194831951
}

packages/php-wasm/node/asyncify/php_8_2.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31943,6 +31943,9 @@ export function init(RuntimeName, PHPLoader) {
3194331943
while (true) {
3194431944
var mask = POLLNVAL;
3194531945
mask = SYSCALLS.DEFAULT_POLLMASK;
31946+
if (FS.isClosed(stream)) {
31947+
return ERRNO_CODES.EBADF;
31948+
}
3194631949
if (stream.stream_ops?.poll) {
3194731950
mask = stream.stream_ops.poll(stream, -1);
3194831951
}

packages/php-wasm/node/asyncify/php_8_3.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31943,6 +31943,9 @@ export function init(RuntimeName, PHPLoader) {
3194331943
while (true) {
3194431944
var mask = POLLNVAL;
3194531945
mask = SYSCALLS.DEFAULT_POLLMASK;
31946+
if (FS.isClosed(stream)) {
31947+
return ERRNO_CODES.EBADF;
31948+
}
3194631949
if (stream.stream_ops?.poll) {
3194731950
mask = stream.stream_ops.poll(stream, -1);
3194831951
}

packages/php-wasm/node/asyncify/php_8_4.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31943,6 +31943,9 @@ export function init(RuntimeName, PHPLoader) {
3194331943
while (true) {
3194431944
var mask = POLLNVAL;
3194531945
mask = SYSCALLS.DEFAULT_POLLMASK;
31946+
if (FS.isClosed(stream)) {
31947+
return ERRNO_CODES.EBADF;
31948+
}
3194631949
if (stream.stream_ops?.poll) {
3194731950
mask = stream.stream_ops.poll(stream, -1);
3194831951
}

packages/php-wasm/universal/src/lib/sandboxed-spawn-handler-factory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function sandboxedSpawnHandlerFactory(
4545
processApi.exit(0);
4646
} else if (binaryName === 'less') {
4747
processApi.on('stdin', (data: Uint8Array) => {
48-
processApi.stdout(data.buffer as ArrayBuffer);
48+
processApi.stdout(data);
4949
});
5050
processApi.exit(0);
5151
} else if (binaryName === 'php') {
@@ -70,14 +70,14 @@ export function sandboxedSpawnHandlerFactory(
7070
result.stdout.pipeTo(
7171
new WritableStream({
7272
write(chunk) {
73-
processApi.stdout(chunk.buffer as ArrayBuffer);
73+
processApi.stdout(chunk);
7474
},
7575
})
7676
);
7777
result.stderr.pipeTo(
7878
new WritableStream({
7979
write(chunk) {
80-
processApi.stderr(chunk.buffer as ArrayBuffer);
80+
processApi.stderr(chunk);
8181
},
8282
})
8383
);

0 commit comments

Comments
 (0)