@php-wasm/node 0.2.0 → 0.3.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/README.md +4 -0
- package/index.cjs +23 -12
- package/index.d.ts +0 -5
- package/package.json +4 -4
- package/packages/php-wasm/node/README.md +4 -0
package/README.md
CHANGED
|
@@ -34,3 +34,7 @@ const response = await php.request({
|
|
|
34
34
|
});
|
|
35
35
|
console.log(response.text);
|
|
36
36
|
```
|
|
37
|
+
|
|
38
|
+
## Attribution
|
|
39
|
+
|
|
40
|
+
`@php-wasm/node` started as a fork of the original PHP to WebAssembly build published by Oraoto in https://github.com/oraoto/pib and modified by Sean Morris in https://github.com/seanmorris/php-wasm.
|
package/index.cjs
CHANGED
|
@@ -67115,7 +67115,6 @@ var PHPRequestHandler = class {
|
|
|
67115
67115
|
* The PHP instance
|
|
67116
67116
|
*/
|
|
67117
67117
|
php;
|
|
67118
|
-
#isStaticFilePath;
|
|
67119
67118
|
/**
|
|
67120
67119
|
* @param php - The PHP instance.
|
|
67121
67120
|
* @param config - Request Handler configuration.
|
|
@@ -67124,12 +67123,10 @@ var PHPRequestHandler = class {
|
|
|
67124
67123
|
this.#semaphore = new Semaphore({ concurrency: 1 });
|
|
67125
67124
|
const {
|
|
67126
67125
|
documentRoot = "/www/",
|
|
67127
|
-
absoluteUrl = typeof location === "object" ? location?.href : ""
|
|
67128
|
-
isStaticFilePath = () => false
|
|
67126
|
+
absoluteUrl = typeof location === "object" ? location?.href : ""
|
|
67129
67127
|
} = config;
|
|
67130
67128
|
this.php = php;
|
|
67131
67129
|
this.#DOCROOT = documentRoot;
|
|
67132
|
-
this.#isStaticFilePath = isStaticFilePath;
|
|
67133
67130
|
const url = new URL(absoluteUrl);
|
|
67134
67131
|
this.#HOSTNAME = url.hostname;
|
|
67135
67132
|
this.#PORT = url.port ? Number(url.port) : url.protocol === "https:" ? 443 : 80;
|
|
@@ -67176,27 +67173,31 @@ var PHPRequestHandler = class {
|
|
|
67176
67173
|
request.url,
|
|
67177
67174
|
isAbsolute ? void 0 : DEFAULT_BASE_URL
|
|
67178
67175
|
);
|
|
67179
|
-
const
|
|
67176
|
+
const normalizedRequestedPath = removePathPrefix(
|
|
67180
67177
|
requestedUrl.pathname,
|
|
67181
67178
|
this.#PATHNAME
|
|
67182
67179
|
);
|
|
67183
|
-
|
|
67184
|
-
|
|
67180
|
+
const fsPath = `${this.#DOCROOT}${normalizedRequestedPath}`;
|
|
67181
|
+
if (seemsLikeAPHPRequestHandlerPath(fsPath)) {
|
|
67182
|
+
return await this.#dispatchToPHP(request, requestedUrl);
|
|
67185
67183
|
}
|
|
67186
|
-
return
|
|
67184
|
+
return this.#serveStaticFile(fsPath);
|
|
67187
67185
|
}
|
|
67188
67186
|
/**
|
|
67189
67187
|
* Serves a static file from the PHP filesystem.
|
|
67190
67188
|
*
|
|
67191
|
-
* @param
|
|
67189
|
+
* @param fsPath - Absolute path of the static file to serve.
|
|
67192
67190
|
* @returns The response.
|
|
67193
67191
|
*/
|
|
67194
|
-
#serveStaticFile(
|
|
67195
|
-
const fsPath = `${this.#DOCROOT}${path}`;
|
|
67192
|
+
#serveStaticFile(fsPath) {
|
|
67196
67193
|
if (!this.php.fileExists(fsPath)) {
|
|
67197
67194
|
return new PHPResponse(
|
|
67198
67195
|
404,
|
|
67199
|
-
|
|
67196
|
+
// Let the service worker know that no static file was found
|
|
67197
|
+
// and that it's okay to issue a real fetch() to the server.
|
|
67198
|
+
{
|
|
67199
|
+
"x-file-type": ["static"]
|
|
67200
|
+
},
|
|
67200
67201
|
new TextEncoder().encode("404 File not found")
|
|
67201
67202
|
);
|
|
67202
67203
|
}
|
|
@@ -67385,6 +67386,16 @@ function inferMimeType(path) {
|
|
|
67385
67386
|
return "application-octet-stream";
|
|
67386
67387
|
}
|
|
67387
67388
|
}
|
|
67389
|
+
function seemsLikeAPHPRequestHandlerPath(path) {
|
|
67390
|
+
return seemsLikeAPHPFile(path) || seemsLikeADirectoryRoot(path);
|
|
67391
|
+
}
|
|
67392
|
+
function seemsLikeAPHPFile(path) {
|
|
67393
|
+
return path.endsWith(".php") || path.includes(".php/");
|
|
67394
|
+
}
|
|
67395
|
+
function seemsLikeADirectoryRoot(path) {
|
|
67396
|
+
const lastSegment = path.split("/").pop();
|
|
67397
|
+
return !lastSegment.includes(".");
|
|
67398
|
+
}
|
|
67388
67399
|
|
|
67389
67400
|
// packages/php-wasm/universal/src/lib/rethrow-file-system-error.ts
|
|
67390
67401
|
var FileErrorCodes = {
|
package/index.d.ts
CHANGED
|
@@ -497,11 +497,6 @@ export interface PHPRequestHandlerConfiguration {
|
|
|
497
497
|
* Request Handler URL. Used to populate $_SERVER details like HTTP_HOST.
|
|
498
498
|
*/
|
|
499
499
|
absoluteUrl?: string;
|
|
500
|
-
/**
|
|
501
|
-
* Callback used by the PHPRequestHandler to decide whether
|
|
502
|
-
* the requested path refers to a PHP file or a static file.
|
|
503
|
-
*/
|
|
504
|
-
isStaticFilePath?: (path: string) => boolean;
|
|
505
500
|
}
|
|
506
501
|
declare class PHPRequestHandler implements RequestHandler {
|
|
507
502
|
#private;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "PHP.wasm for Node.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"license": "GPL-2.0-or-later",
|
|
29
29
|
"main": "index.cjs",
|
|
30
30
|
"types": "index.d.ts",
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "6890ff9243f9a10f0b86755fead101647a8c8535",
|
|
32
32
|
"engines": {
|
|
33
33
|
"node": ">=16.15.1",
|
|
34
34
|
"npm": ">=8.11.0"
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"express": "4.18.2",
|
|
39
39
|
"ws": "8.13.0",
|
|
40
40
|
"yargs": "17.7.2",
|
|
41
|
-
"@php-wasm/universal": "0.
|
|
42
|
-
"@php-wasm/util": "0.
|
|
41
|
+
"@php-wasm/universal": "0.3.0",
|
|
42
|
+
"@php-wasm/util": "0.3.0"
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -34,3 +34,7 @@ const response = await php.request({
|
|
|
34
34
|
});
|
|
35
35
|
console.log(response.text);
|
|
36
36
|
```
|
|
37
|
+
|
|
38
|
+
## Attribution
|
|
39
|
+
|
|
40
|
+
`@php-wasm/node` started as a fork of the original PHP to WebAssembly build published by Oraoto in https://github.com/oraoto/pib and modified by Sean Morris in https://github.com/seanmorris/php-wasm.
|