@php-wasm/node 0.6.6 → 0.6.7
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 +100 -76
- package/package.json +5 -5
package/index.cjs
CHANGED
|
@@ -71491,90 +71491,114 @@ __export(src_exports, {
|
|
|
71491
71491
|
});
|
|
71492
71492
|
module.exports = __toCommonJS(src_exports);
|
|
71493
71493
|
|
|
71494
|
+
// packages/php-wasm/node-polyfills/src/lib/current-js-runtime.ts
|
|
71495
|
+
var currentJsRuntime = function() {
|
|
71496
|
+
if (typeof process !== "undefined" && process.release?.name === "node") {
|
|
71497
|
+
return "NODE";
|
|
71498
|
+
} else if (typeof window !== "undefined") {
|
|
71499
|
+
return "WEB";
|
|
71500
|
+
} else if (
|
|
71501
|
+
// @ts-ignore
|
|
71502
|
+
typeof WorkerGlobalScope !== "undefined" && // @ts-ignore
|
|
71503
|
+
self instanceof WorkerGlobalScope
|
|
71504
|
+
) {
|
|
71505
|
+
return "WORKER";
|
|
71506
|
+
} else {
|
|
71507
|
+
return "NODE";
|
|
71508
|
+
}
|
|
71509
|
+
}();
|
|
71510
|
+
|
|
71494
71511
|
// packages/php-wasm/node-polyfills/src/lib/blob.ts
|
|
71495
|
-
if (
|
|
71496
|
-
|
|
71497
|
-
|
|
71498
|
-
|
|
71499
|
-
|
|
71500
|
-
|
|
71501
|
-
|
|
71502
|
-
|
|
71503
|
-
|
|
71504
|
-
|
|
71512
|
+
if (currentJsRuntime === "NODE") {
|
|
71513
|
+
let asPromise = function(obj) {
|
|
71514
|
+
return new Promise(function(resolve, reject) {
|
|
71515
|
+
obj.onload = obj.onerror = function(event) {
|
|
71516
|
+
obj.onload = obj.onerror = null;
|
|
71517
|
+
if (event.type === "load") {
|
|
71518
|
+
resolve(obj.result);
|
|
71519
|
+
} else {
|
|
71520
|
+
reject(new Error("Failed to read the blob/file"));
|
|
71521
|
+
}
|
|
71522
|
+
};
|
|
71523
|
+
});
|
|
71524
|
+
}, isByobSupported = function() {
|
|
71525
|
+
const inputBytes = new Uint8Array([1, 2, 3, 4]);
|
|
71526
|
+
const file = new File([inputBytes], "test");
|
|
71527
|
+
const stream = file.stream();
|
|
71528
|
+
try {
|
|
71529
|
+
stream.getReader({ mode: "byob" });
|
|
71530
|
+
return true;
|
|
71531
|
+
} catch (e) {
|
|
71532
|
+
return false;
|
|
71533
|
+
}
|
|
71534
|
+
};
|
|
71535
|
+
asPromise2 = asPromise, isByobSupported2 = isByobSupported;
|
|
71536
|
+
if (typeof File === "undefined") {
|
|
71537
|
+
class File2 extends Blob {
|
|
71538
|
+
constructor(sources, fileName, options) {
|
|
71539
|
+
super(sources);
|
|
71540
|
+
let date;
|
|
71541
|
+
if (options?.lastModified) {
|
|
71542
|
+
date = /* @__PURE__ */ new Date();
|
|
71543
|
+
}
|
|
71544
|
+
if (!date || isNaN(date.getFullYear())) {
|
|
71545
|
+
date = /* @__PURE__ */ new Date();
|
|
71546
|
+
}
|
|
71547
|
+
this.lastModifiedDate = date;
|
|
71548
|
+
this.lastModified = date.getMilliseconds();
|
|
71549
|
+
this.name = fileName || "";
|
|
71505
71550
|
}
|
|
71506
|
-
this.lastModifiedDate = date;
|
|
71507
|
-
this.lastModified = date.getMilliseconds();
|
|
71508
|
-
this.name = fileName || "";
|
|
71509
71551
|
}
|
|
71552
|
+
global.File = File2;
|
|
71510
71553
|
}
|
|
71511
|
-
|
|
71512
|
-
|
|
71513
|
-
|
|
71514
|
-
|
|
71515
|
-
|
|
71516
|
-
obj.onload = obj.onerror = null;
|
|
71517
|
-
if (event.type === "load") {
|
|
71518
|
-
resolve(obj.result);
|
|
71519
|
-
} else {
|
|
71520
|
-
reject(new Error("Failed to read the blob/file"));
|
|
71521
|
-
}
|
|
71554
|
+
if (typeof Blob.prototype.arrayBuffer === "undefined") {
|
|
71555
|
+
Blob.prototype.arrayBuffer = function arrayBuffer() {
|
|
71556
|
+
const reader = new FileReader();
|
|
71557
|
+
reader.readAsArrayBuffer(this);
|
|
71558
|
+
return asPromise(reader);
|
|
71522
71559
|
};
|
|
71523
|
-
});
|
|
71524
|
-
}
|
|
71525
|
-
if (typeof Blob.prototype.arrayBuffer === "undefined") {
|
|
71526
|
-
Blob.prototype.arrayBuffer = function arrayBuffer() {
|
|
71527
|
-
const reader = new FileReader();
|
|
71528
|
-
reader.readAsArrayBuffer(this);
|
|
71529
|
-
return asPromise(reader);
|
|
71530
|
-
};
|
|
71531
|
-
}
|
|
71532
|
-
if (typeof Blob.prototype.text === "undefined") {
|
|
71533
|
-
Blob.prototype.text = function text() {
|
|
71534
|
-
const reader = new FileReader();
|
|
71535
|
-
reader.readAsText(this);
|
|
71536
|
-
return asPromise(reader);
|
|
71537
|
-
};
|
|
71538
|
-
}
|
|
71539
|
-
function isByobSupported() {
|
|
71540
|
-
const inputBytes = new Uint8Array([1, 2, 3, 4]);
|
|
71541
|
-
const file = new File([inputBytes], "test");
|
|
71542
|
-
const stream = file.stream();
|
|
71543
|
-
try {
|
|
71544
|
-
stream.getReader({ mode: "byob" });
|
|
71545
|
-
return true;
|
|
71546
|
-
} catch (e) {
|
|
71547
|
-
return false;
|
|
71548
71560
|
}
|
|
71549
|
-
|
|
71550
|
-
|
|
71551
|
-
|
|
71552
|
-
|
|
71553
|
-
|
|
71554
|
-
|
|
71555
|
-
|
|
71556
|
-
|
|
71557
|
-
|
|
71558
|
-
|
|
71559
|
-
|
|
71560
|
-
|
|
71561
|
-
|
|
71562
|
-
|
|
71563
|
-
|
|
71564
|
-
|
|
71565
|
-
|
|
71566
|
-
|
|
71567
|
-
|
|
71568
|
-
|
|
71569
|
-
|
|
71561
|
+
if (typeof Blob.prototype.text === "undefined") {
|
|
71562
|
+
Blob.prototype.text = function text() {
|
|
71563
|
+
const reader = new FileReader();
|
|
71564
|
+
reader.readAsText(this);
|
|
71565
|
+
return asPromise(reader);
|
|
71566
|
+
};
|
|
71567
|
+
}
|
|
71568
|
+
if (typeof Blob.prototype.stream === "undefined" || !isByobSupported()) {
|
|
71569
|
+
Blob.prototype.stream = function() {
|
|
71570
|
+
let position = 0;
|
|
71571
|
+
const blob = this;
|
|
71572
|
+
return new ReadableStream({
|
|
71573
|
+
type: "bytes",
|
|
71574
|
+
// 0.5 MB seems like a reasonable chunk size, let's adjust
|
|
71575
|
+
// this if needed.
|
|
71576
|
+
autoAllocateChunkSize: 512 * 1024,
|
|
71577
|
+
async pull(controller) {
|
|
71578
|
+
const view = controller.byobRequest.view;
|
|
71579
|
+
const chunk = blob.slice(
|
|
71580
|
+
position,
|
|
71581
|
+
position + view.byteLength
|
|
71582
|
+
);
|
|
71583
|
+
const buffer = await chunk.arrayBuffer();
|
|
71584
|
+
const uint8array = new Uint8Array(buffer);
|
|
71585
|
+
new Uint8Array(view.buffer).set(uint8array);
|
|
71586
|
+
const bytesRead = uint8array.byteLength;
|
|
71587
|
+
controller.byobRequest.respond(bytesRead);
|
|
71588
|
+
position += bytesRead;
|
|
71589
|
+
if (position >= blob.size) {
|
|
71590
|
+
controller.close();
|
|
71591
|
+
}
|
|
71570
71592
|
}
|
|
71571
|
-
}
|
|
71572
|
-
}
|
|
71573
|
-
}
|
|
71593
|
+
});
|
|
71594
|
+
};
|
|
71595
|
+
}
|
|
71574
71596
|
}
|
|
71597
|
+
var asPromise2;
|
|
71598
|
+
var isByobSupported2;
|
|
71575
71599
|
|
|
71576
71600
|
// packages/php-wasm/node-polyfills/src/lib/custom-event.ts
|
|
71577
|
-
if (typeof CustomEvent === "undefined") {
|
|
71601
|
+
if (currentJsRuntime === "NODE" && typeof CustomEvent === "undefined") {
|
|
71578
71602
|
class CustomEvent2 extends Event {
|
|
71579
71603
|
constructor(name, options = {}) {
|
|
71580
71604
|
super(name, options);
|
|
@@ -72631,7 +72655,7 @@ var loadedRuntimes = /* @__PURE__ */ new Map();
|
|
|
72631
72655
|
var lastRuntimeId = 0;
|
|
72632
72656
|
async function loadPHPRuntime(phpLoaderModule, phpModuleArgs = {}) {
|
|
72633
72657
|
const [phpReady, resolvePHP, rejectPHP] = makePromise();
|
|
72634
|
-
const PHPRuntime = phpLoaderModule.init(
|
|
72658
|
+
const PHPRuntime = phpLoaderModule.init(currentJsRuntime2, {
|
|
72635
72659
|
onAbort(reason) {
|
|
72636
72660
|
rejectPHP(reason);
|
|
72637
72661
|
console.error(reason);
|
|
@@ -72665,7 +72689,7 @@ async function loadPHPRuntime(phpLoaderModule, phpModuleArgs = {}) {
|
|
|
72665
72689
|
function getLoadedRuntime(id) {
|
|
72666
72690
|
return loadedRuntimes.get(id);
|
|
72667
72691
|
}
|
|
72668
|
-
var
|
|
72692
|
+
var currentJsRuntime2 = function() {
|
|
72669
72693
|
if (typeof process !== "undefined" && process.release?.name === "node") {
|
|
72670
72694
|
return "NODE";
|
|
72671
72695
|
} else if (typeof window !== "undefined") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/node",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
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": "c4c52563eee8997b94cd4a0875e10fb5d8ccda42",
|
|
32
32
|
"engines": {
|
|
33
33
|
"node": ">=18.18.2",
|
|
34
34
|
"npm": ">=8.11.0"
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"express": "4.18.2",
|
|
39
39
|
"ws": "8.13.0",
|
|
40
40
|
"yargs": "17.7.2",
|
|
41
|
-
"@php-wasm/node-polyfills": "0.6.
|
|
42
|
-
"@php-wasm/universal": "0.6.
|
|
43
|
-
"@php-wasm/util": "0.6.
|
|
41
|
+
"@php-wasm/node-polyfills": "0.6.7",
|
|
42
|
+
"@php-wasm/universal": "0.6.7",
|
|
43
|
+
"@php-wasm/util": "0.6.7"
|
|
44
44
|
}
|
|
45
45
|
}
|