@php-wasm/node 0.1.61 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +56 -29
- package/index.d.ts +2 -2
- package/package.json +8 -4
package/index.cjs
CHANGED
|
@@ -66724,6 +66724,14 @@ Object.defineProperty(ErrorEvent2.prototype, "error", { enumerable: true });
|
|
|
66724
66724
|
Object.defineProperty(ErrorEvent2.prototype, "message", { enumerable: true });
|
|
66725
66725
|
var ErrorEvent = typeof globalThis.ErrorEvent === "function" ? globalThis.ErrorEvent : ErrorEvent2;
|
|
66726
66726
|
|
|
66727
|
+
// packages/php-wasm/universal/src/lib/is-exit-code-zero.ts
|
|
66728
|
+
function isExitCodeZero(e) {
|
|
66729
|
+
if (!(e instanceof Error)) {
|
|
66730
|
+
return false;
|
|
66731
|
+
}
|
|
66732
|
+
return "exitCode" in e && e?.exitCode === 0 || e?.name === "ExitStatus" && "status" in e && e.status === 0;
|
|
66733
|
+
}
|
|
66734
|
+
|
|
66727
66735
|
// packages/php-wasm/universal/src/lib/wasm-error-reporting.ts
|
|
66728
66736
|
var UnhandledRejectionsTarget = class extends EventTarget {
|
|
66729
66737
|
listenersCount = 0;
|
|
@@ -66754,9 +66762,6 @@ function improveWASMErrorReporting(runtime) {
|
|
|
66754
66762
|
if (!(e instanceof Error)) {
|
|
66755
66763
|
throw e;
|
|
66756
66764
|
}
|
|
66757
|
-
if ("exitCode" in e && e?.exitCode === 0) {
|
|
66758
|
-
return;
|
|
66759
|
-
}
|
|
66760
66765
|
const clearMessage = clarifyErrorMessage(
|
|
66761
66766
|
e,
|
|
66762
66767
|
runtime.lastAsyncifyStackSource?.stack
|
|
@@ -66764,16 +66769,19 @@ function improveWASMErrorReporting(runtime) {
|
|
|
66764
66769
|
if (runtime.lastAsyncifyStackSource) {
|
|
66765
66770
|
e.cause = runtime.lastAsyncifyStackSource;
|
|
66766
66771
|
}
|
|
66767
|
-
if (
|
|
66772
|
+
if (target.hasListeners()) {
|
|
66773
|
+
target.dispatchEvent(
|
|
66774
|
+
new ErrorEvent("error", {
|
|
66775
|
+
error: e,
|
|
66776
|
+
message: clearMessage
|
|
66777
|
+
})
|
|
66778
|
+
);
|
|
66779
|
+
return;
|
|
66780
|
+
}
|
|
66781
|
+
if (!isExitCodeZero(e)) {
|
|
66768
66782
|
showCriticalErrorBox(clearMessage);
|
|
66769
|
-
throw e;
|
|
66770
66783
|
}
|
|
66771
|
-
|
|
66772
|
-
new ErrorEvent("error", {
|
|
66773
|
-
error: e,
|
|
66774
|
-
message: clearMessage
|
|
66775
|
-
})
|
|
66776
|
-
);
|
|
66784
|
+
throw e;
|
|
66777
66785
|
}
|
|
66778
66786
|
};
|
|
66779
66787
|
}
|
|
@@ -67482,16 +67490,12 @@ function rethrowFileSystemError(messagePrefix = "") {
|
|
|
67482
67490
|
|
|
67483
67491
|
// packages/php-wasm/universal/src/lib/load-php-runtime.ts
|
|
67484
67492
|
async function loadPHPRuntime(phpLoaderModule, phpModuleArgs = {}, dataDependenciesModules = []) {
|
|
67485
|
-
|
|
67486
|
-
const depsReady =
|
|
67487
|
-
resolveDepsReady = resolve;
|
|
67488
|
-
});
|
|
67489
|
-
const phpReady = new Promise((resolve) => {
|
|
67490
|
-
resolvePhpReady = resolve;
|
|
67491
|
-
});
|
|
67493
|
+
const [phpReady, resolvePHP, rejectPHP] = makePromise();
|
|
67494
|
+
const [depsReady, resolveDeps] = makePromise();
|
|
67492
67495
|
const PHPRuntime = phpLoaderModule.init(currentJsRuntime, {
|
|
67493
67496
|
onAbort(reason) {
|
|
67494
|
-
|
|
67497
|
+
rejectPHP(reason);
|
|
67498
|
+
resolveDeps();
|
|
67495
67499
|
console.error(reason);
|
|
67496
67500
|
},
|
|
67497
67501
|
ENV: {},
|
|
@@ -67505,20 +67509,22 @@ async function loadPHPRuntime(phpLoaderModule, phpModuleArgs = {}, dataDependenc
|
|
|
67505
67509
|
if (phpModuleArgs.onRuntimeInitialized) {
|
|
67506
67510
|
phpModuleArgs.onRuntimeInitialized();
|
|
67507
67511
|
}
|
|
67508
|
-
|
|
67512
|
+
resolvePHP();
|
|
67509
67513
|
},
|
|
67510
67514
|
monitorRunDependencies(nbLeft) {
|
|
67511
67515
|
if (nbLeft === 0) {
|
|
67512
67516
|
delete PHPRuntime.monitorRunDependencies;
|
|
67513
|
-
|
|
67517
|
+
resolveDeps();
|
|
67514
67518
|
}
|
|
67515
67519
|
}
|
|
67516
67520
|
});
|
|
67517
|
-
|
|
67518
|
-
|
|
67519
|
-
|
|
67521
|
+
await Promise.all(
|
|
67522
|
+
dataDependenciesModules.map(
|
|
67523
|
+
({ default: dataModule }) => dataModule(PHPRuntime)
|
|
67524
|
+
)
|
|
67525
|
+
);
|
|
67520
67526
|
if (!dataDependenciesModules.length) {
|
|
67521
|
-
|
|
67527
|
+
resolveDeps();
|
|
67522
67528
|
}
|
|
67523
67529
|
await depsReady;
|
|
67524
67530
|
await phpReady;
|
|
@@ -67540,6 +67546,14 @@ var currentJsRuntime = function() {
|
|
|
67540
67546
|
return "NODE";
|
|
67541
67547
|
}
|
|
67542
67548
|
}();
|
|
67549
|
+
var makePromise = () => {
|
|
67550
|
+
const methods = [];
|
|
67551
|
+
const promise = new Promise((resolve, reject) => {
|
|
67552
|
+
methods.push(resolve, reject);
|
|
67553
|
+
});
|
|
67554
|
+
methods.unshift(promise);
|
|
67555
|
+
return methods;
|
|
67556
|
+
};
|
|
67543
67557
|
|
|
67544
67558
|
// packages/php-wasm/universal/src/lib/base-php.ts
|
|
67545
67559
|
var STRING = "string";
|
|
@@ -68442,7 +68456,7 @@ var _NodePHP = class extends BasePHP2 {
|
|
|
68442
68456
|
* @param argv - The arguments to pass to the CLI.
|
|
68443
68457
|
* @returns The exit code of the CLI session.
|
|
68444
68458
|
*/
|
|
68445
|
-
cli(argv) {
|
|
68459
|
+
async cli(argv) {
|
|
68446
68460
|
for (const arg of argv) {
|
|
68447
68461
|
this[__private__dont__use].ccall(
|
|
68448
68462
|
"wasm_add_cli_arg",
|
|
@@ -68451,9 +68465,22 @@ var _NodePHP = class extends BasePHP2 {
|
|
|
68451
68465
|
[arg]
|
|
68452
68466
|
);
|
|
68453
68467
|
}
|
|
68454
|
-
|
|
68455
|
-
|
|
68456
|
-
|
|
68468
|
+
try {
|
|
68469
|
+
return await this[__private__dont__use].ccall(
|
|
68470
|
+
"run_cli",
|
|
68471
|
+
null,
|
|
68472
|
+
[],
|
|
68473
|
+
[],
|
|
68474
|
+
{
|
|
68475
|
+
async: true
|
|
68476
|
+
}
|
|
68477
|
+
);
|
|
68478
|
+
} catch (error) {
|
|
68479
|
+
if (isExitCodeZero(error)) {
|
|
68480
|
+
return 0;
|
|
68481
|
+
}
|
|
68482
|
+
throw error;
|
|
68483
|
+
}
|
|
68457
68484
|
}
|
|
68458
68485
|
setSkipShebang(shouldSkip) {
|
|
68459
68486
|
this[__private__dont__use].ccall(
|
package/index.d.ts
CHANGED
|
@@ -120,7 +120,7 @@ export interface RequestHandler {
|
|
|
120
120
|
* }
|
|
121
121
|
* })
|
|
122
122
|
* php.writeFile("/www/index.php", `<?php echo file_get_contents("php://input");`);
|
|
123
|
-
* const result = await php.
|
|
123
|
+
* const result = await php.request({
|
|
124
124
|
* method: "GET",
|
|
125
125
|
* headers: {
|
|
126
126
|
* "Content-Type": "text/plain"
|
|
@@ -358,7 +358,7 @@ export interface IsomorphicLocalPHP extends RequestHandler {
|
|
|
358
358
|
* post_message_to_js(string $data)
|
|
359
359
|
*
|
|
360
360
|
* Arguments:
|
|
361
|
-
* $data –
|
|
361
|
+
* $data (string) – Data to pass to JavaScript.
|
|
362
362
|
*
|
|
363
363
|
* @example
|
|
364
364
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "PHP.wasm for Node.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,13 +28,17 @@
|
|
|
28
28
|
"license": "GPL-2.0-or-later",
|
|
29
29
|
"main": "index.cjs",
|
|
30
30
|
"types": "index.d.ts",
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "cd4062de74f7f18058d3f962e124d0fdff78b5a7",
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=16.15.1",
|
|
34
|
+
"npm": ">=8.11.0"
|
|
35
|
+
},
|
|
32
36
|
"dependencies": {
|
|
33
37
|
"comlink": "^4.4.1",
|
|
34
38
|
"express": "4.18.2",
|
|
35
39
|
"ws": "8.13.0",
|
|
36
40
|
"yargs": "17.7.2",
|
|
37
|
-
"@php-wasm/universal": "0.
|
|
38
|
-
"@php-wasm/util": "0.
|
|
41
|
+
"@php-wasm/universal": "0.2.0",
|
|
42
|
+
"@php-wasm/util": "0.2.0"
|
|
39
43
|
}
|
|
40
44
|
}
|