@bytecodealliance/preview2-shim 0.19.0 → 0.20.1

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.
@@ -444,7 +444,8 @@ function handle(call, id, payload) {
444
444
  if (stream.flushPromise) {
445
445
  return stream.flushPromise.then(() => handle(call, id, payload));
446
446
  }
447
- if (payload.byteLength > stream.stream.writableHighWaterMark - stream.stream.writableLength) {
447
+ if (payload.byteLength >
448
+ stream.stream.writableHighWaterMark - stream.stream.writableLength) {
448
449
  throw new Error("wasi-io trap: Cannot write more than permitted writable length");
449
450
  }
450
451
  stream.pollState.ready = false;
@@ -570,7 +571,9 @@ function handle(call, id, payload) {
570
571
  let resolve, reject;
571
572
  if (outputStream.stream.writableNeedDrain) {
572
573
  promise = new Promise((_resolve, _reject) => {
573
- outputStream.stream.once("drain", (resolve = _resolve)).once("error", (reject = _reject));
574
+ outputStream.stream
575
+ .once("drain", (resolve = _resolve))
576
+ .once("error", (reject = _reject));
574
577
  }).then(() => {
575
578
  outputStream.stream.off("error", reject);
576
579
  }, (err) => {
@@ -142,7 +142,8 @@ class Descriptor {
142
142
  throw "invalid";
143
143
  }
144
144
  let stats;
145
- if (dataAccessTimestamp.tag === "no-change" || dataModificationTimestamp.tag === "no-change") {
145
+ if (dataAccessTimestamp.tag === "no-change" ||
146
+ dataModificationTimestamp.tag === "no-change") {
146
147
  stats = this.stat();
147
148
  }
148
149
  const atime = this.#getNewTimestamp(dataAccessTimestamp, dataAccessTimestamp.tag === "no-change" && stats.dataAccessTimestamp);
@@ -259,7 +260,8 @@ class Descriptor {
259
260
  setTimesAt(pathFlags, path, dataAccessTimestamp, dataModificationTimestamp) {
260
261
  const fullPath = this.#getFullPath(path, false);
261
262
  let stats;
262
- if (dataAccessTimestamp.tag === "no-change" || dataModificationTimestamp.tag === "no-change") {
263
+ if (dataAccessTimestamp.tag === "no-change" ||
264
+ dataModificationTimestamp.tag === "no-change") {
263
265
  stats = this.stat();
264
266
  }
265
267
  const atime = this.#getNewTimestamp(dataAccessTimestamp, dataAccessTimestamp.tag === "no-change" && stats.dataAccessTimestamp);
@@ -519,7 +521,8 @@ class Descriptor {
519
521
  // new segment - check if it is relative
520
522
  else if (subpath[i] === ".") {
521
523
  // ../ segment
522
- if (subpath[i + 1] === "." && (subpath[i + 2] === "/" || i + 2 === subpath.length)) {
524
+ if (subpath[i + 1] === "." &&
525
+ (subpath[i + 2] === "/" || i + 2 === subpath.length)) {
523
526
  if (segments.pop() === undefined) {
524
527
  throw "not-permitted";
525
528
  }
@@ -1,6 +1,6 @@
1
1
  import { FUTURE_DISPOSE, FUTURE_SUBSCRIBE, FUTURE_TAKE_VALUE, HTTP_CREATE_REQUEST, HTTP_OUTGOING_BODY_DISPOSE, HTTP_OUTPUT_STREAM_FINISH, HTTP_SERVER_CLEAR_OUTGOING_RESPONSE, HTTP_SERVER_SET_OUTGOING_RESPONSE, HTTP_SERVER_START, HTTP_SERVER_STOP, HTTP_SERVER_GET_ADDRESS, OUTPUT_STREAM_CREATE, OUTPUT_STREAM_DISPOSE, } from "../io/calls.js";
2
- import { earlyDispose, inputStreamCreate, ioCall, outputStreamCreate, pollableCreate, registerDispose, registerIncomingHttpHandler, } from "../io/worker-io.js";
3
- import { HTTP } from "../io/calls.js";
2
+ import { earlyDispose, inputStreamCreate, ioCall, outputStreamCreate, pollableCreate, createPoll, registerDispose, registerIncomingHttpHandler, } from "../io/worker-io.js";
3
+ import { CLOCKS_DURATION_SUBSCRIBE, HTTP } from "../io/calls.js";
4
4
  import * as http from "node:http";
5
5
  const { validateHeaderName = () => { }, validateHeaderValue = () => { } } = http;
6
6
  const symbolDispose = Symbol.dispose || Symbol.for("dispose");
@@ -76,7 +76,7 @@ delete IncomingRequest._create;
76
76
  class FutureTrailers {
77
77
  #requested = false;
78
78
  subscribe() {
79
- return pollableCreate(0, this);
79
+ return createPoll(CLOCKS_DURATION_SUBSCRIBE, null, 0n);
80
80
  }
81
81
  get() {
82
82
  if (this.#requested) {
@@ -87,7 +87,7 @@ class FutureTrailers {
87
87
  tag: "ok",
88
88
  val: {
89
89
  tag: "ok",
90
- val: undefined,
90
+ val: fieldsLock(fieldsFromEntriesChecked([])),
91
91
  },
92
92
  };
93
93
  }
@@ -1,2 +1,2 @@
1
- export declare function createSyncFn(workerPath: any, debug: any, callbackHandler: any): (...args: any[]) => any;
1
+ export declare function createSyncFn(createWorker: any, debug: any, callbackHandler: any): (...args: any[]) => any;
2
2
  export declare function runAsWorker(fn: any): any;
@@ -1,29 +1,28 @@
1
1
  // Based on: https://github.com/un-ts/synckit
2
2
  /*
3
- MIT License
3
+ MIT License
4
4
 
5
- Copyright (c) 2021 UnTS
5
+ Copyright (c) 2021 UnTS
6
6
 
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated documentation files (the "Software"), to deal
9
- in the Software without restriction, including without limitation the rights
10
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom the Software is
12
- furnished to do so, subject to the following conditions:
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
13
 
14
- The above copyright notice and this permission notice shall be included in all
15
- copies or substantial portions of the Software.
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
16
 
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- SOFTWARE.
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
24
  */
25
- import path from "node:path";
26
- import { MessageChannel, Worker, receiveMessageOnPort, workerData, parentPort, } from "node:worker_threads";
25
+ import { MessageChannel, receiveMessageOnPort, workerData, parentPort } from "node:worker_threads";
27
26
  const DEFAULT_WORKER_BUFFER_SIZE = 1024;
28
27
  function extractProperties(object) {
29
28
  if (object && typeof object === "object") {
@@ -35,12 +34,9 @@ function extractProperties(object) {
35
34
  }
36
35
  }
37
36
  const CALL_TIMEOUT = undefined;
38
- export function createSyncFn(workerPath, debug, callbackHandler) {
39
- if (!path.isAbsolute(workerPath)) {
40
- throw new Error("`workerPath` must be absolute");
41
- }
37
+ export function createSyncFn(createWorker, debug, callbackHandler) {
42
38
  const { port1: mainPort, port2: workerPort } = new MessageChannel();
43
- const worker = new Worker(workerPath, {
39
+ const worker = createWorker({
44
40
  workerData: { workerPort, debug },
45
41
  transferList: [workerPort],
46
42
  execArgv: [],
@@ -62,7 +58,7 @@ export function createSyncFn(workerPath, debug, callbackHandler) {
62
58
  if (!["ok", "not-equal"].includes(status)) {
63
59
  throw new Error("Internal error: Atomics.wait() failed: " + status);
64
60
  }
65
- const { cid: cid2, result, error, properties } = receiveMessageOnPort(mainPort)?.message ?? {};
61
+ const { cid: cid2, result, error, properties, } = receiveMessageOnPort(mainPort)?.message ?? {};
66
62
  if (cid !== cid2) {
67
63
  throw new Error(`Internal error: Expected id ${cid} but got id ${cid2}`);
68
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytecodealliance/preview2-shim",
3
- "version": "0.19.0",
3
+ "version": "0.20.1",
4
4
  "description": "WASI Preview2 shim for JS environments",
5
5
  "homepage": "https://github.com/bytecodealliance/jco#readme",
6
6
  "bugs": {
@@ -48,7 +48,7 @@
48
48
  "default": "./dist/browser/*.js"
49
49
  },
50
50
  "./instantiation": {
51
- "types": "./types/instantiation.d.ts",
51
+ "types": "./dist/common/*.d.ts",
52
52
  "node": "./dist/common/instantiation.js",
53
53
  "default": "./dist/common/instantiation.js"
54
54
  },
@@ -57,16 +57,17 @@
57
57
  }
58
58
  },
59
59
  "devDependencies": {
60
- "@bytecodealliance/componentize-js": "0.21.0",
61
- "@bytecodealliance/jco": "1.20.0",
60
+ "@bytecodealliance/componentize-js": "0.22.0",
61
+ "@bytecodealliance/jco": "1.25.2",
62
62
  "@types/node": "^24.12.4",
63
63
  "mime": "^4.0.7",
64
64
  "puppeteer": "^25.1.0",
65
+ "rolldown": "^1.2.0",
65
66
  "typescript": "^6.0.3",
66
67
  "vitest": "^4.0.8"
67
68
  },
68
69
  "scripts": {
69
- "build": "tsc --project tsconfig.build.json",
70
+ "build": "tsc --project tsconfig.build.json && node scripts/build-worker.mjs",
70
71
  "build:watch": "tsc --watch",
71
72
  "types:check": "tsc --noEmit",
72
73
  "fmt": "oxfmt",