@bytecodealliance/preview2-shim 0.20.1 → 0.21.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/dist/browser/filesystem.d.ts +1 -1
- package/dist/io/calls.d.ts +11 -0
- package/dist/io/calls.js +12 -0
- package/dist/io/worker-filesystem.d.ts +29 -0
- package/dist/io/worker-filesystem.js +116 -0
- package/dist/io/worker-http.d.ts +2 -2
- package/dist/io/worker-socket-tcp.d.ts +5 -2
- package/dist/io/worker-socket-tcp.js +121 -95
- package/dist/io/worker-sockets.d.ts +4 -4
- package/dist/io/worker-thread.bundle.js +283 -97
- package/dist/io/worker-thread.d.ts +1 -0
- package/dist/io/worker-thread.js +44 -7
- package/dist/nodejs/filesystem.d.ts +6 -9
- package/dist/nodejs/filesystem.js +37 -26
- package/package.json +6 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { types as TypesNamespace, preopens as PreopensNamespace } from "../../types/filesystem.js";
|
|
2
|
-
import type { Descriptor as IDescriptor, DirectoryEntryStream as IDirectoryEntryStream } from "../../types/interfaces/wasi-filesystem-types.js";
|
|
2
|
+
import type { Descriptor as IDescriptor, DescriptorType, DirectoryEntryStream as IDirectoryEntryStream } from "../../types/interfaces/wasi-filesystem-types.js";
|
|
3
3
|
declare const symbolDispose: symbol;
|
|
4
4
|
/**
|
|
5
5
|
* @implements {DescriptorProps}
|
|
@@ -9,14 +9,14 @@ declare class Descriptor implements IDescriptor {
|
|
|
9
9
|
[symbolDispose]: () => void;
|
|
10
10
|
private _id;
|
|
11
11
|
static _createPreopen(hostPreopen: any): Descriptor;
|
|
12
|
-
static _create(
|
|
12
|
+
static _create(fileResourceId: any, mode: any, fullPath: any): Descriptor;
|
|
13
13
|
readViaStream(offset: any): any;
|
|
14
14
|
writeViaStream(offset: any): any;
|
|
15
15
|
appendViaStream(): any;
|
|
16
16
|
advise(_offset: any, _length: any, _advice: any): void;
|
|
17
17
|
syncData(): void;
|
|
18
18
|
getFlags(): any;
|
|
19
|
-
getType():
|
|
19
|
+
getType(): any;
|
|
20
20
|
setSize(size: any): void;
|
|
21
21
|
setTimes(dataAccessTimestamp: any, dataModificationTimestamp: any): void;
|
|
22
22
|
read(length: any, offset: any): [Uint8Array, boolean];
|
|
@@ -25,7 +25,7 @@ declare class Descriptor implements IDescriptor {
|
|
|
25
25
|
sync(): void;
|
|
26
26
|
createDirectoryAt(path: any): void;
|
|
27
27
|
stat(): {
|
|
28
|
-
type:
|
|
28
|
+
type: any;
|
|
29
29
|
linkCount: any;
|
|
30
30
|
size: any;
|
|
31
31
|
dataAccessTimestamp: {
|
|
@@ -42,7 +42,7 @@ declare class Descriptor implements IDescriptor {
|
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
44
|
statAt(pathFlags: any, path: any): {
|
|
45
|
-
type:
|
|
45
|
+
type: DescriptorType;
|
|
46
46
|
linkCount: any;
|
|
47
47
|
size: any;
|
|
48
48
|
dataAccessTimestamp: {
|
|
@@ -67,10 +67,7 @@ declare class Descriptor implements IDescriptor {
|
|
|
67
67
|
symlinkAt(target: any, path: any): void;
|
|
68
68
|
unlinkFileAt(path: any): void;
|
|
69
69
|
isSameObject(other: any): boolean;
|
|
70
|
-
metadataHash():
|
|
71
|
-
upper: bigint;
|
|
72
|
-
lower: bigint;
|
|
73
|
-
};
|
|
70
|
+
metadataHash(): any;
|
|
74
71
|
metadataHashAt(pathFlags: any, path: any): {
|
|
75
72
|
upper: bigint;
|
|
76
73
|
lower: bigint;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { earlyDispose, inputStreamCreate, ioCall, outputStreamCreate, registerDispose, } from "../io/worker-io.js";
|
|
2
|
-
import { FILE, INPUT_STREAM_CREATE, OUTPUT_STREAM_CREATE } from "../io/calls.js";
|
|
3
|
-
import {
|
|
2
|
+
import { FILE, FILESYSTEM_DESCRIPTOR_CLOSE, FILESYSTEM_DESCRIPTOR_GET_TYPE, FILESYSTEM_DESCRIPTOR_METADATA_HASH, FILESYSTEM_DESCRIPTOR_OPEN, FILESYSTEM_DESCRIPTOR_READ, FILESYSTEM_DESCRIPTOR_SET_SIZE, FILESYSTEM_DESCRIPTOR_SET_TIMES, FILESYSTEM_DESCRIPTOR_STAT, FILESYSTEM_DESCRIPTOR_SYNC, FILESYSTEM_DESCRIPTOR_SYNC_DATA, FILESYSTEM_DESCRIPTOR_WRITE, INPUT_STREAM_CREATE, OUTPUT_STREAM_CREATE, } from "../io/calls.js";
|
|
3
|
+
import { constants, linkSync, lstatSync, lutimesSync, mkdirSync, opendirSync, readlinkSync, renameSync, rmdirSync, statSync, symlinkSync, unlinkSync, utimesSync, } from "node:fs";
|
|
4
4
|
import { platform } from "node:process";
|
|
5
5
|
const symbolDispose = Symbol.dispose || Symbol.for("dispose");
|
|
6
6
|
const isWindows = platform === "win32";
|
|
@@ -35,6 +35,9 @@ function lookupType(obj) {
|
|
|
35
35
|
}
|
|
36
36
|
return "unknown";
|
|
37
37
|
}
|
|
38
|
+
function closeFileResource(id) {
|
|
39
|
+
ioCall(FILESYSTEM_DESCRIPTOR_CLOSE, id);
|
|
40
|
+
}
|
|
38
41
|
// Note: This should implement per-segment semantics of openAt, but we cannot
|
|
39
42
|
// currently due to the lack of support for openat() in Node.js.
|
|
40
43
|
// Tracking issue: https://github.com/libuv/libuv/issues/4167
|
|
@@ -43,7 +46,7 @@ function lookupType(obj) {
|
|
|
43
46
|
*/
|
|
44
47
|
class Descriptor {
|
|
45
48
|
#hostPreopen;
|
|
46
|
-
#
|
|
49
|
+
#fileResourceId;
|
|
47
50
|
#finalizer;
|
|
48
51
|
#mode;
|
|
49
52
|
#fullPath;
|
|
@@ -62,10 +65,10 @@ class Descriptor {
|
|
|
62
65
|
}
|
|
63
66
|
return descriptor;
|
|
64
67
|
}
|
|
65
|
-
static _create(
|
|
68
|
+
static _create(fileResourceId, mode, fullPath) {
|
|
66
69
|
const descriptor = new Descriptor();
|
|
67
|
-
descriptor.#
|
|
68
|
-
descriptor.#finalizer = registerDispose(descriptor, null,
|
|
70
|
+
descriptor.#fileResourceId = fileResourceId;
|
|
71
|
+
descriptor.#finalizer = registerDispose(descriptor, null, fileResourceId, closeFileResource);
|
|
69
72
|
descriptor.#mode = mode;
|
|
70
73
|
descriptor.#fullPath = fullPath;
|
|
71
74
|
return descriptor;
|
|
@@ -81,7 +84,7 @@ class Descriptor {
|
|
|
81
84
|
throw "is-directory";
|
|
82
85
|
}
|
|
83
86
|
return inputStreamCreate(FILE, ioCall(INPUT_STREAM_CREATE | FILE, null, {
|
|
84
|
-
|
|
87
|
+
descriptorId: this.#fileResourceId,
|
|
85
88
|
offset,
|
|
86
89
|
}));
|
|
87
90
|
}
|
|
@@ -89,7 +92,10 @@ class Descriptor {
|
|
|
89
92
|
if (this.#hostPreopen) {
|
|
90
93
|
throw "is-directory";
|
|
91
94
|
}
|
|
92
|
-
return outputStreamCreate(FILE, ioCall(OUTPUT_STREAM_CREATE | FILE, null, {
|
|
95
|
+
return outputStreamCreate(FILE, ioCall(OUTPUT_STREAM_CREATE | FILE, null, {
|
|
96
|
+
descriptorId: this.#fileResourceId,
|
|
97
|
+
offset,
|
|
98
|
+
}));
|
|
93
99
|
}
|
|
94
100
|
appendViaStream() {
|
|
95
101
|
return this.writeViaStream(this.stat().size);
|
|
@@ -104,7 +110,7 @@ class Descriptor {
|
|
|
104
110
|
throw "invalid";
|
|
105
111
|
}
|
|
106
112
|
try {
|
|
107
|
-
|
|
113
|
+
ioCall(FILESYSTEM_DESCRIPTOR_SYNC_DATA, this.#fileResourceId);
|
|
108
114
|
}
|
|
109
115
|
catch (e) {
|
|
110
116
|
if (e.code === "EPERM") {
|
|
@@ -120,15 +126,14 @@ class Descriptor {
|
|
|
120
126
|
if (this.#hostPreopen) {
|
|
121
127
|
return "directory";
|
|
122
128
|
}
|
|
123
|
-
|
|
124
|
-
return lookupType(stats);
|
|
129
|
+
return ioCall(FILESYSTEM_DESCRIPTOR_GET_TYPE, this.#fileResourceId);
|
|
125
130
|
}
|
|
126
131
|
setSize(size) {
|
|
127
132
|
if (this.#hostPreopen) {
|
|
128
133
|
throw "is-directory";
|
|
129
134
|
}
|
|
130
135
|
try {
|
|
131
|
-
|
|
136
|
+
ioCall(FILESYSTEM_DESCRIPTOR_SET_SIZE, this.#fileResourceId, Number(size));
|
|
132
137
|
}
|
|
133
138
|
catch (e) {
|
|
134
139
|
if (isWindows && e.code === "EPERM") {
|
|
@@ -149,7 +154,7 @@ class Descriptor {
|
|
|
149
154
|
const atime = this.#getNewTimestamp(dataAccessTimestamp, dataAccessTimestamp.tag === "no-change" && stats.dataAccessTimestamp);
|
|
150
155
|
const mtime = this.#getNewTimestamp(dataModificationTimestamp, dataModificationTimestamp.tag === "no-change" && stats.dataModificationTimestamp);
|
|
151
156
|
try {
|
|
152
|
-
|
|
157
|
+
ioCall(FILESYSTEM_DESCRIPTOR_SET_TIMES, this.#fileResourceId, { atime, mtime });
|
|
153
158
|
}
|
|
154
159
|
catch (e) {
|
|
155
160
|
throw convertFsError(e);
|
|
@@ -169,16 +174,20 @@ class Descriptor {
|
|
|
169
174
|
if (!this.#fullPath) {
|
|
170
175
|
throw "bad-descriptor";
|
|
171
176
|
}
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
177
|
+
const { bytes, eof } = ioCall(FILESYSTEM_DESCRIPTOR_READ, this.#fileResourceId, {
|
|
178
|
+
length: Number(length),
|
|
179
|
+
offset: Number(offset),
|
|
180
|
+
});
|
|
181
|
+
return [bytes, eof];
|
|
176
182
|
}
|
|
177
183
|
write(buffer, offset) {
|
|
178
184
|
if (!this.#fullPath) {
|
|
179
185
|
throw "bad-descriptor";
|
|
180
186
|
}
|
|
181
|
-
return BigInt(
|
|
187
|
+
return BigInt(ioCall(FILESYSTEM_DESCRIPTOR_WRITE, this.#fileResourceId, {
|
|
188
|
+
buffer,
|
|
189
|
+
offset: Number(offset),
|
|
190
|
+
}));
|
|
182
191
|
}
|
|
183
192
|
readDirectory() {
|
|
184
193
|
if (!this.#fullPath) {
|
|
@@ -197,7 +206,7 @@ class Descriptor {
|
|
|
197
206
|
throw "invalid";
|
|
198
207
|
}
|
|
199
208
|
try {
|
|
200
|
-
|
|
209
|
+
ioCall(FILESYSTEM_DESCRIPTOR_SYNC, this.#fileResourceId);
|
|
201
210
|
}
|
|
202
211
|
catch (e) {
|
|
203
212
|
if (e.code === "EPERM") {
|
|
@@ -221,12 +230,12 @@ class Descriptor {
|
|
|
221
230
|
}
|
|
222
231
|
let stats;
|
|
223
232
|
try {
|
|
224
|
-
stats =
|
|
233
|
+
stats = ioCall(FILESYSTEM_DESCRIPTOR_STAT, this.#fileResourceId);
|
|
225
234
|
}
|
|
226
235
|
catch (e) {
|
|
227
236
|
throw convertFsError(e);
|
|
228
237
|
}
|
|
229
|
-
const type =
|
|
238
|
+
const type = stats.type;
|
|
230
239
|
return {
|
|
231
240
|
type,
|
|
232
241
|
linkCount: stats.nlink,
|
|
@@ -361,9 +370,12 @@ class Descriptor {
|
|
|
361
370
|
}
|
|
362
371
|
}
|
|
363
372
|
try {
|
|
364
|
-
const
|
|
365
|
-
|
|
366
|
-
|
|
373
|
+
const { id, type } = ioCall(FILESYSTEM_DESCRIPTOR_OPEN, null, {
|
|
374
|
+
path: fullPath.endsWith("/") ? fullPath.slice(0, -1) : fullPath,
|
|
375
|
+
flags: fsOpenFlags,
|
|
376
|
+
});
|
|
377
|
+
const descriptor = descriptorCreate(id, descriptorFlags, fullPath);
|
|
378
|
+
if (fullPath.endsWith("/") && type !== "directory") {
|
|
367
379
|
descriptor[symbolDispose]();
|
|
368
380
|
throw "not-directory";
|
|
369
381
|
}
|
|
@@ -475,8 +487,7 @@ class Descriptor {
|
|
|
475
487
|
return { upper: 0n, lower: BigInt(this._id) };
|
|
476
488
|
}
|
|
477
489
|
try {
|
|
478
|
-
|
|
479
|
-
return { upper: stats.mtimeNs, lower: stats.ino };
|
|
490
|
+
return ioCall(FILESYSTEM_DESCRIPTOR_METADATA_HASH, this.#fileResourceId);
|
|
480
491
|
}
|
|
481
492
|
catch (e) {
|
|
482
493
|
throw convertFsError(e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytecodealliance/preview2-shim",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "WASI Preview2 shim for JS environments",
|
|
5
5
|
"homepage": "https://github.com/bytecodealliance/jco#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -62,9 +62,9 @@
|
|
|
62
62
|
"@types/node": "^24.12.4",
|
|
63
63
|
"mime": "^4.0.7",
|
|
64
64
|
"puppeteer": "^25.1.0",
|
|
65
|
-
"rolldown": "^1.2.
|
|
66
|
-
"typescript": "
|
|
67
|
-
"vitest": "^4.
|
|
65
|
+
"rolldown": "^1.2.4",
|
|
66
|
+
"typescript": "7.0.2",
|
|
67
|
+
"vitest": "^4.1.10"
|
|
68
68
|
},
|
|
69
69
|
"scripts": {
|
|
70
70
|
"build": "tsc --project tsconfig.build.json && node scripts/build-worker.mjs",
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
"fmt:check": "oxfmt --check",
|
|
75
75
|
"lint": "oxlint",
|
|
76
76
|
"lint:fix": "oxlint --fix",
|
|
77
|
-
"test": "vitest run -c test/vitest.ts"
|
|
77
|
+
"test": "vitest run -c test/vitest.ts",
|
|
78
|
+
"test:deno": "deno test --no-check -A test/deno/*.mjs"
|
|
78
79
|
}
|
|
79
80
|
}
|