@php-wasm/node 0.1.45 → 0.1.46

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.
Files changed (2) hide show
  1. package/index.cjs +25 -19
  2. package/package.json +5 -5
package/index.cjs CHANGED
@@ -67117,6 +67117,16 @@ var PHPRequestHandler = class {
67117
67117
  } else {
67118
67118
  body = request.body;
67119
67119
  }
67120
+ let scriptPath;
67121
+ try {
67122
+ scriptPath = this.#resolvePHPFilePath(requestedUrl.pathname);
67123
+ } catch (error) {
67124
+ return new PHPResponse(
67125
+ 404,
67126
+ {},
67127
+ new TextEncoder().encode("404 File not found")
67128
+ );
67129
+ }
67120
67130
  return await this.php.run({
67121
67131
  relativeUri: ensurePathPrefix(
67122
67132
  toRelativeUrl(requestedUrl),
@@ -67126,7 +67136,7 @@ var PHPRequestHandler = class {
67126
67136
  method: request.method || preferredMethod,
67127
67137
  body,
67128
67138
  fileInfos,
67129
- scriptPath: this.#resolvePHPFilePath(requestedUrl.pathname),
67139
+ scriptPath,
67130
67140
  headers
67131
67141
  });
67132
67142
  } finally {
@@ -67139,6 +67149,7 @@ var PHPRequestHandler = class {
67139
67149
  * Fall back to index.php as if there was a url rewriting rule in place.
67140
67150
  *
67141
67151
  * @param requestedPath - The requested pathname.
67152
+ * @throws {Error} If the requested path doesn't exist.
67142
67153
  * @returns The resolved filesystem path.
67143
67154
  */
67144
67155
  #resolvePHPFilePath(requestedPath) {
@@ -67157,6 +67168,9 @@ var PHPRequestHandler = class {
67157
67168
  if (this.php.fileExists(resolvedFsPath)) {
67158
67169
  return resolvedFsPath;
67159
67170
  }
67171
+ if (!this.php.fileExists(`${this.#DOCROOT}/index.php`)) {
67172
+ throw new Error(`File not found: ${resolvedFsPath}`);
67173
+ }
67160
67174
  return `${this.#DOCROOT}/index.php`;
67161
67175
  }
67162
67176
  };
@@ -67691,7 +67705,7 @@ var BasePHP2 = class {
67691
67705
  let exitCode;
67692
67706
  let errorListener;
67693
67707
  try {
67694
- exitCode = await new Promise(async (resolve, reject) => {
67708
+ exitCode = await new Promise((resolve, reject) => {
67695
67709
  errorListener = (e) => {
67696
67710
  const rethrown = new Error("Rethrown");
67697
67711
  rethrown.cause = e.error;
@@ -67702,24 +67716,16 @@ var BasePHP2 = class {
67702
67716
  "error",
67703
67717
  errorListener
67704
67718
  );
67705
- try {
67706
- resolve(
67707
- /**
67708
- * This is awkward, but Asyncify makes wasm_sapi_handle_request return
67709
- * Promise<Promise<number>>.
67710
- *
67711
- * @TODO: Determine whether this is a bug in emscripten or in our code.
67712
- */
67713
- await await this[__private__dont__use].ccall(
67714
- "wasm_sapi_handle_request",
67715
- NUMBER,
67716
- [],
67717
- []
67718
- )
67719
- );
67720
- } catch (e) {
67721
- reject(e);
67719
+ const response = this[__private__dont__use].ccall(
67720
+ "wasm_sapi_handle_request",
67721
+ NUMBER,
67722
+ [],
67723
+ []
67724
+ );
67725
+ if (response instanceof Promise) {
67726
+ return response.then(resolve, reject);
67722
67727
  }
67728
+ return resolve(response);
67723
67729
  });
67724
67730
  } catch (e) {
67725
67731
  for (const name in this) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/node",
3
- "version": "0.1.45",
3
+ "version": "0.1.46",
4
4
  "description": "PHP.wasm for Node.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,13 +28,13 @@
28
28
  "license": "GPL-2.0-or-later",
29
29
  "main": "index.cjs",
30
30
  "types": "index.d.ts",
31
- "gitHead": "ca75514c17b912dc8b5dc529f6d123295671320a",
31
+ "gitHead": "b1e1b4b57b00fb52429f0490af4ccb943f496f74",
32
32
  "dependencies": {
33
- "comlink": "4.4.1",
33
+ "comlink": "^4.4.1",
34
34
  "express": "4.18.2",
35
35
  "ws": "8.13.0",
36
36
  "yargs": "17.7.2",
37
- "@php-wasm/universal": "0.1.45",
38
- "@php-wasm/util": "0.1.45"
37
+ "@php-wasm/universal": "0.1.46",
38
+ "@php-wasm/util": "0.1.46"
39
39
  }
40
40
  }