promise-worker-bi 5.0.2 → 6.0.0-beta.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.
- package/README.md +58 -48
- package/dist/index.d.ts +62 -35
- package/dist/index.js +295 -373
- package/package.json +19 -32
package/README.md
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
# promise-worker-bi
|
|
1
|
+
# promise-worker-bi
|
|
2
|
+
|
|
3
|
+
[](https://github.com/dumbmatter/promise-worker-bi/actions/workflows/nodejs.yml)
|
|
4
|
+
[](https://github.com/dumbmatter/promise-worker-bi)
|
|
5
|
+
[](https://github.com/dumbmatter/promise-worker-bi)
|
|
6
|
+
[](https://www.npmjs.com/package/promise-worker-bi)
|
|
7
|
+
[](https://www.npmjs.com/package/promise-worker-bi)
|
|
2
8
|
|
|
3
9
|
A small (~2 kB min+gz) and performant library for communicating with web workers and shared workers, using promises. Post a message from the browser to the worker, get a promise that resolves to the response. Post a message from the worker to the browser, get a promise that resolves to the response. And with shared workers, you can either broadcast to all browser tabs or send a message to a specific tab.
|
|
4
10
|
|
|
@@ -21,14 +27,14 @@ const promiseWorker = new PWBHost(worker);
|
|
|
21
27
|
|
|
22
28
|
// Only needed if you send messages from the worker to the host
|
|
23
29
|
promiseWorker.register((message) => {
|
|
24
|
-
|
|
30
|
+
return "pong2";
|
|
25
31
|
});
|
|
26
32
|
|
|
27
33
|
try {
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
const response = await promiseWorker.postMessage("ping");
|
|
35
|
+
// handle response 'pong'
|
|
30
36
|
} catch (error) {
|
|
31
|
-
|
|
37
|
+
// handle error
|
|
32
38
|
}
|
|
33
39
|
```
|
|
34
40
|
|
|
@@ -42,14 +48,14 @@ const promiseWorker = new PWBWorker();
|
|
|
42
48
|
|
|
43
49
|
// Only needed if you send messages from the host to the worker
|
|
44
50
|
promiseWorker.register((message) => {
|
|
45
|
-
|
|
51
|
+
return "pong";
|
|
46
52
|
});
|
|
47
53
|
|
|
48
54
|
try {
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
const response = await promiseWorker.postMessage("ping2");
|
|
56
|
+
// handle response 'pong2'
|
|
51
57
|
} catch (error) {
|
|
52
|
-
|
|
58
|
+
// handle error
|
|
53
59
|
}
|
|
54
60
|
```
|
|
55
61
|
|
|
@@ -61,15 +67,15 @@ The message you send can be any object, array, string, number, etc. - anything t
|
|
|
61
67
|
|
|
62
68
|
```js
|
|
63
69
|
await promiseWorker.postMessage({
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
hello: "world",
|
|
71
|
+
answer: 42,
|
|
72
|
+
"this is fun": true,
|
|
67
73
|
});
|
|
68
74
|
```
|
|
69
75
|
|
|
70
76
|
```js
|
|
71
77
|
promiseWorker.register((message) => {
|
|
72
|
-
|
|
78
|
+
console.log(message); // { hello: 'world', answer: 42, 'this is fun': true }
|
|
73
79
|
});
|
|
74
80
|
```
|
|
75
81
|
|
|
@@ -79,7 +85,7 @@ The registered handler can return either a Promise or a normal value:
|
|
|
79
85
|
|
|
80
86
|
```js
|
|
81
87
|
promiseWorker.register(async () => {
|
|
82
|
-
|
|
88
|
+
"much async, very promise";
|
|
83
89
|
});
|
|
84
90
|
```
|
|
85
91
|
|
|
@@ -94,15 +100,15 @@ Any thrown errors or asynchronous rejections during a response will be propagate
|
|
|
94
100
|
|
|
95
101
|
```js
|
|
96
102
|
promiseWorker.register((message) => {
|
|
97
|
-
|
|
103
|
+
throw new Error("naughty!");
|
|
98
104
|
});
|
|
99
105
|
```
|
|
100
106
|
|
|
101
107
|
```js
|
|
102
108
|
try {
|
|
103
|
-
|
|
109
|
+
await promiseWorker.postMessage("whoops");
|
|
104
110
|
} catch (error) {
|
|
105
|
-
|
|
111
|
+
console.log(error.message); // 'naughty!'
|
|
106
112
|
}
|
|
107
113
|
```
|
|
108
114
|
|
|
@@ -113,8 +119,8 @@ For a Web Worker, we could just use [the normal `error` event](https://developer
|
|
|
113
119
|
Therefore, promise-worker-bi includes a unified API that works in Web Workers and Shared Workers. Include some code like this in your host:
|
|
114
120
|
|
|
115
121
|
```js
|
|
116
|
-
promiseWorker.
|
|
117
|
-
|
|
122
|
+
promiseWorker.addEventListener("error", (errorError) => {
|
|
123
|
+
console.log("Error inside worker!", errorError.error);
|
|
118
124
|
});
|
|
119
125
|
```
|
|
120
126
|
|
|
@@ -130,21 +136,21 @@ If you need to send messages of multiple types to the worker, just add some type
|
|
|
130
136
|
|
|
131
137
|
```js
|
|
132
138
|
const response1 = await promiseWorker.postMessage({
|
|
133
|
-
|
|
139
|
+
type: "en",
|
|
134
140
|
});
|
|
135
141
|
|
|
136
142
|
const response2 = await promiseWorker.postMessage({
|
|
137
|
-
|
|
143
|
+
type: "fr",
|
|
138
144
|
});
|
|
139
145
|
```
|
|
140
146
|
|
|
141
147
|
```js
|
|
142
148
|
promiseWorker.register((message) => {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
149
|
+
if (message.type === "en") {
|
|
150
|
+
return "Hello!";
|
|
151
|
+
} else if (message.type === "fr") {
|
|
152
|
+
return "Bonjour!";
|
|
153
|
+
}
|
|
148
154
|
});
|
|
149
155
|
```
|
|
150
156
|
|
|
@@ -162,14 +168,14 @@ const worker = new SharedWorker("worker.js");
|
|
|
162
168
|
const promiseWorker = new PWBHost(worker);
|
|
163
169
|
|
|
164
170
|
promiseWorker.register((message) => {
|
|
165
|
-
|
|
171
|
+
console.log(message);
|
|
166
172
|
});
|
|
167
173
|
|
|
168
174
|
// setTimeout is just to give you enough time to open main.js and main2.js in
|
|
169
175
|
// two separate tabs.
|
|
170
176
|
setTimeout(async () => {
|
|
171
|
-
|
|
172
|
-
|
|
177
|
+
const response = await promiseWorker.postMessage("broadcast");
|
|
178
|
+
console.log("Echoed response:", response);
|
|
173
179
|
}, 1000);
|
|
174
180
|
```
|
|
175
181
|
|
|
@@ -199,13 +205,13 @@ import { PWBWorker } from "promise-worker-bi";
|
|
|
199
205
|
const promiseWorker = new PWBWorker();
|
|
200
206
|
|
|
201
207
|
promiseWorker.register((message, hostID) => {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
208
|
+
if (message === "broadcast") {
|
|
209
|
+
promiseWorker.postMessage("to all tabs");
|
|
210
|
+
} else {
|
|
211
|
+
promiseWorker.postMessage(`hello host ${hostID}`, hostID);
|
|
212
|
+
}
|
|
207
213
|
|
|
208
|
-
|
|
214
|
+
return message;
|
|
209
215
|
});
|
|
210
216
|
```
|
|
211
217
|
|
|
@@ -244,12 +250,12 @@ If you want to respond to a message by sending a transferable object back, such
|
|
|
244
250
|
|
|
245
251
|
```js
|
|
246
252
|
promiseWorker.register(async (message) => {
|
|
247
|
-
|
|
253
|
+
const processedMessage = await processMessage(message);
|
|
248
254
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
255
|
+
return {
|
|
256
|
+
message: processedMessage,
|
|
257
|
+
_PWB_TRANSFER: [processedMessage.someTransferableProprty],
|
|
258
|
+
};
|
|
253
259
|
});
|
|
254
260
|
```
|
|
255
261
|
|
|
@@ -279,13 +285,17 @@ Create a new instance of `PWBHost`, using the given worker.
|
|
|
279
285
|
|
|
280
286
|
- `worker` - the `Worker`, `SharedWorker` or [PseudoWorker](https://github.com/nolanlawson/pseudo-worker) to use.
|
|
281
287
|
|
|
282
|
-
#### `promiseWorker.
|
|
288
|
+
#### `promiseWorker.addEventListener("error", (event: ErrorEvent) => void)`
|
|
289
|
+
|
|
290
|
+
When an error in your web/shared worker process occurs that is _not_ directly in response to a `promiseWorker.postMessage` call, you can see it by listening to the "error" event here.
|
|
291
|
+
|
|
292
|
+
`promiseWorker` is EventTarget so you can use `addEventListener`, `removeEventListener`, and all their normal options.
|
|
283
293
|
|
|
284
|
-
|
|
294
|
+
#### `promiseWorker.addEventListener("close", (event: Event) => void)`
|
|
285
295
|
|
|
286
|
-
|
|
296
|
+
There is no built-in API to listen for when a web/shared worker closes, which can happen in various situations such as the OS killing it to free up memory. promise-worker-bi includes a "close" event you can use for this purpose.
|
|
287
297
|
|
|
288
|
-
|
|
298
|
+
`promiseWorker` is EventTarget so you can use `addEventListener`, `removeEventListener`, and all their normal options.
|
|
289
299
|
|
|
290
300
|
### Worker bundle
|
|
291
301
|
|
|
@@ -295,17 +305,17 @@ Create a new instance of `PWBWorker`.
|
|
|
295
305
|
|
|
296
306
|
### Both bundles
|
|
297
307
|
|
|
298
|
-
#### `promiseWorker.register((message:
|
|
308
|
+
#### `promiseWorker.register((message: unknown, hostID?: number) => unknown)`
|
|
299
309
|
|
|
300
310
|
Register a message handler wherever you will be receiving messages: in the worker, in the browser, or both. Your handler consumes a message and returns a promise or value.
|
|
301
311
|
|
|
302
312
|
The `hostID` parameter is only defined inside a shared worker, in which case it is a unique number identifying the host that the message came from.
|
|
303
313
|
|
|
304
|
-
The return value of the callback function (shown above as `
|
|
314
|
+
The return value of the callback function (shown above as `unknown`) must resolve to something [structured cloneable](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm).
|
|
305
315
|
|
|
306
|
-
If you want to [transfer an object](https://developer.mozilla.org/en-US/docs/Glossary/Transferable_objects) in the return value of the callback, then the return type should be `{ message:
|
|
316
|
+
If you want to [transfer an object](https://developer.mozilla.org/en-US/docs/Glossary/Transferable_objects) in the return value of the callback, then the return type should be `{ message: unknown, _PWB_TRANSFER: Transferable[] }` rather than just `unknown`.
|
|
307
317
|
|
|
308
|
-
#### `promiseWorker.postMessage(message:
|
|
318
|
+
#### `promiseWorker.postMessage(message: unknown, hostID?: number, transfer?: Transferable[]): Promise<unknown>`
|
|
309
319
|
|
|
310
320
|
Send a message to the browser or worker and return a Promise. `message` must resolve to something [structured cloneable](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm).
|
|
311
321
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,38 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
//#region src/message.d.ts
|
|
2
|
+
declare const MSGTYPE_QUERY = 0;
|
|
3
|
+
declare const MSGTYPE_RESPONSE = 1;
|
|
4
|
+
declare const MSGTYPE_HOST_ID = 2;
|
|
5
|
+
declare const MSGTYPE_HOST_LOCK = 3;
|
|
6
|
+
declare const MSGTYPE_WORKER_LOCK = 4;
|
|
7
|
+
declare const MSGTYPE_WORKER_ERROR = 5;
|
|
8
|
+
type QueryMessage = [type: typeof MSGTYPE_QUERY, messageId: number, query: unknown] | [type: typeof MSGTYPE_QUERY, messageId: number, query: unknown, hostId: number | undefined];
|
|
9
|
+
type ResponseMessage = [type: typeof MSGTYPE_RESPONSE, messageId: number, error: Error] | [type: typeof MSGTYPE_RESPONSE, messageId: number, error: null, result: unknown];
|
|
10
|
+
type HostIdMessage = [type: typeof MSGTYPE_HOST_ID, hostId: number] | [type: typeof MSGTYPE_HOST_ID, hostId: number, workerLockId: string];
|
|
11
|
+
type HostLockMessage = [type: typeof MSGTYPE_HOST_LOCK, hostID: number, hostLockId: string];
|
|
12
|
+
type WorkerLockMessage = [type: typeof MSGTYPE_WORKER_LOCK, workerLockId: string];
|
|
13
|
+
type WorkerErrorMessage = [type: typeof MSGTYPE_WORKER_ERROR, error: Error];
|
|
14
|
+
type Message = QueryMessage | ResponseMessage | HostIdMessage | HostLockMessage | WorkerLockMessage | WorkerErrorMessage;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/PWBBase.d.ts
|
|
17
|
+
type QueryCallback = (a: unknown, b: number | undefined) => unknown;
|
|
18
|
+
type EventMap = Record<string, Event>;
|
|
19
|
+
declare abstract class PWBBase<Events extends EventMap> extends EventTarget {
|
|
20
|
+
protected _callbacks: Map<number, (a: Error | null, b: unknown) => void>;
|
|
21
|
+
protected _queryCallback: QueryCallback;
|
|
22
|
+
constructor();
|
|
23
|
+
addEventListener<K extends keyof Events>(type: K, listener: ((event: Events[K]) => void) | {
|
|
24
|
+
handleEvent(object: Events[K]): void;
|
|
25
|
+
} | null, options?: AddEventListenerOptions | boolean): void;
|
|
26
|
+
dispatchEvent<K extends keyof Events>(event: Events[K]): boolean;
|
|
27
|
+
removeEventListener<K extends keyof Events>(type: K, listener: ((event: Events[K]) => void) | {
|
|
28
|
+
handleEvent(object: Events[K]): void;
|
|
29
|
+
} | null, options?: EventListenerOptions | boolean): void;
|
|
30
|
+
register(cb: QueryCallback): void;
|
|
31
|
+
protected abstract _postMessage(obj: Message, hostID?: number | undefined, transfer?: Transferable[] | undefined): void;
|
|
32
|
+
private _postResponse;
|
|
33
|
+
private _handleQuery;
|
|
34
|
+
protected _onMessageCommon(e: MessageEvent): [type: 2, hostId: number] | [type: 2, hostId: number, workerLockId: string] | HostLockMessage | WorkerLockMessage | WorkerErrorMessage | undefined;
|
|
16
35
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/PWBHost.d.ts
|
|
38
|
+
type HostEvents = {
|
|
39
|
+
close: Event;
|
|
40
|
+
error: ErrorEvent;
|
|
41
|
+
};
|
|
42
|
+
export declare class PWBHost extends PWBBase<HostEvents> {
|
|
43
|
+
private _hostID;
|
|
44
|
+
private _hostIDQueue;
|
|
45
|
+
private _worker;
|
|
46
|
+
constructor(worker: SharedWorker | Worker);
|
|
47
|
+
protected _postMessage(obj: QueryMessage | ResponseMessage | HostLockMessage, _hostID?: unknown, transfer?: Transferable[] | undefined): void;
|
|
48
|
+
postMessage(userMessage: unknown, _hostID?: undefined, transfer?: Transferable[] | undefined): Promise<any>;
|
|
49
|
+
private handleWorkerLock;
|
|
50
|
+
private _onMessage;
|
|
27
51
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/PWBWorker.d.ts
|
|
54
|
+
type WorkerEvents = Record<string, Event>;
|
|
55
|
+
export declare class PWBWorker extends PWBBase<WorkerEvents> {
|
|
56
|
+
private _hosts;
|
|
57
|
+
private _maxHostID;
|
|
58
|
+
private _sharedWorker;
|
|
59
|
+
private _workerLockAcquired;
|
|
60
|
+
constructor();
|
|
61
|
+
protected _postMessage(message: QueryMessage | ResponseMessage | HostIdMessage | WorkerLockMessage | WorkerErrorMessage, targetHostID?: number | undefined, transfer?: Transferable[] | undefined): void;
|
|
62
|
+
postMessage(userMessage: unknown, targetHostID?: number | undefined, transfer?: Transferable[] | undefined): Promise<unknown>;
|
|
63
|
+
private _onMessage;
|
|
37
64
|
}
|
|
38
|
-
|
|
65
|
+
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -1,377 +1,299 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const MSGTYPE_HOST_ID = 2;
|
|
5
|
-
const MSGTYPE_HOST_CLOSE = 3;
|
|
6
|
-
const MSGTYPE_WORKER_ERROR = 4;
|
|
7
|
-
const MSGTYPES = [MSGTYPE_QUERY, MSGTYPE_RESPONSE, MSGTYPE_HOST_ID, MSGTYPE_HOST_CLOSE, MSGTYPE_WORKER_ERROR];
|
|
8
|
-
|
|
9
|
-
// Inlined from https://github.com/then/is-promise
|
|
10
|
-
const isPromise = obj => !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
|
|
11
|
-
const toFakeError = error => {
|
|
12
|
-
const fakeError = {
|
|
13
|
-
name: error.name,
|
|
14
|
-
message: error.message
|
|
15
|
-
};
|
|
16
|
-
if (typeof error.stack === "string") {
|
|
17
|
-
fakeError.stack = error.stack;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// These are non-standard properties, I think only in some versions of Firefox
|
|
21
|
-
// @ts-expect-error
|
|
22
|
-
if (typeof error.fileName === "string") {
|
|
23
|
-
// @ts-expect-error
|
|
24
|
-
fakeError.fileName = error.fileName;
|
|
25
|
-
}
|
|
26
|
-
// @ts-expect-error
|
|
27
|
-
if (typeof error.columnNumber === "number") {
|
|
28
|
-
// @ts-expect-error
|
|
29
|
-
fakeError.columnNumber = error.columnNumber;
|
|
30
|
-
}
|
|
31
|
-
// @ts-expect-error
|
|
32
|
-
if (typeof error.lineNumber === "number") {
|
|
33
|
-
// @ts-expect-error
|
|
34
|
-
fakeError.lineNumber = error.lineNumber;
|
|
35
|
-
}
|
|
36
|
-
return fakeError;
|
|
1
|
+
const isError = (error) => {
|
|
2
|
+
if (Error.isError) return Error.isError(error);
|
|
3
|
+
return true;
|
|
37
4
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
5
|
+
const parseMessage = (message) => {
|
|
6
|
+
if (!Array.isArray(message) || message.length < 2 || message.length > 4) return;
|
|
7
|
+
const type = message[0];
|
|
8
|
+
if (type === 0) {
|
|
9
|
+
if (typeof message[1] !== "number") throw new Error("Invalid messageID");
|
|
10
|
+
if (message[3] !== void 0 && typeof message[3] !== "number") throw new Error("Invalid hostID");
|
|
11
|
+
return message;
|
|
12
|
+
}
|
|
13
|
+
if (type === 1) {
|
|
14
|
+
if (typeof message[1] !== "number") throw new Error("Invalid messageID");
|
|
15
|
+
if (message[2] !== null && !isError(message[2])) throw new Error("Invalid error");
|
|
16
|
+
return message;
|
|
17
|
+
}
|
|
18
|
+
if (type === 2) {
|
|
19
|
+
if (typeof message[1] !== "number") throw new Error("Invalid hostID");
|
|
20
|
+
if (message[2] !== void 0 && typeof message[2] !== "string") throw new Error("Invalid workerLockId");
|
|
21
|
+
return message;
|
|
22
|
+
}
|
|
23
|
+
if (type === 3) {
|
|
24
|
+
if (typeof message[1] !== "number") throw new Error("Invalid hostID");
|
|
25
|
+
if (typeof message[2] !== "string") throw new Error("Invalid hostLockId");
|
|
26
|
+
return message;
|
|
27
|
+
}
|
|
28
|
+
if (type === 4) {
|
|
29
|
+
if (typeof message[1] !== "string") throw new Error("Invalid workerLockId");
|
|
30
|
+
return message;
|
|
31
|
+
}
|
|
32
|
+
if (type === 5) {
|
|
33
|
+
if (!isError(message[1])) throw new Error("Invalid error");
|
|
34
|
+
return message;
|
|
35
|
+
}
|
|
36
|
+
throw new Error("Invalid message type");
|
|
43
37
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/PWBBase.ts
|
|
40
|
+
const isPromise = (obj) => !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
|
|
41
|
+
const logError = (err) => {
|
|
42
|
+
console.error("Error in worker:");
|
|
43
|
+
console.error(err);
|
|
48
44
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
this._postMessage([MSGTYPE_WORKER_ERROR, -1, toFakeError(e.error)], hostID);
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
} else {
|
|
307
|
-
this._workerType = "Worker";
|
|
308
|
-
self.addEventListener("message", this._onMessage);
|
|
309
|
-
|
|
310
|
-
// Since this is not a Shared Worker, hostID is always 0 so it's not strictly required to
|
|
311
|
-
// send this back, but it makes the API a bit more consistent if there is the same
|
|
312
|
-
// initialization handshake in both cases.
|
|
313
|
-
this._postMessage([MSGTYPE_HOST_ID, -1, 0], 0);
|
|
314
|
-
self.addEventListener("error", e => {
|
|
315
|
-
logError(e.error);
|
|
316
|
-
this._postMessage([MSGTYPE_WORKER_ERROR, -1, toFakeError(e.error)]);
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
_postMessage(obj, targetHostID, transfer) {
|
|
321
|
-
// console.log('_postMessage', obj, targetHostID);
|
|
322
|
-
if (this._workerType === "SharedWorker") {
|
|
323
|
-
// If targetHostID has been deleted, this will do nothing, which is fine I think
|
|
324
|
-
this._hosts.forEach(({
|
|
325
|
-
port
|
|
326
|
-
}, hostID) => {
|
|
327
|
-
if (targetHostID === undefined || targetHostID === hostID) {
|
|
328
|
-
// @ts-expect-error TypeScript thinks transfer can't be undefined
|
|
329
|
-
port.postMessage(obj, transfer);
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
} else if (this._workerType === "Worker") {
|
|
333
|
-
// @ts-expect-error TypeScript thinks self is window, which has a different postMessage call signature. In a worker, this is correct.
|
|
334
|
-
self.postMessage(obj, transfer);
|
|
335
|
-
} else {
|
|
336
|
-
throw new Error("WTF");
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
postMessage(userMessage, targetHostID, transfer) {
|
|
340
|
-
// console.log('postMessage', userMessage, targetHostID);
|
|
341
|
-
const actuallyPostMessage = (resolve, reject) => {
|
|
342
|
-
const messageID = messageIDs;
|
|
343
|
-
messageIDs += 1;
|
|
344
|
-
const messageToSend = [MSGTYPE_QUERY, messageID, userMessage];
|
|
345
|
-
this._callbacks.set(messageID, (error, result) => {
|
|
346
|
-
if (error) {
|
|
347
|
-
reject(error);
|
|
348
|
-
} else {
|
|
349
|
-
resolve(result);
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
this._postMessage(messageToSend, targetHostID, transfer);
|
|
353
|
-
};
|
|
354
|
-
return new Promise((resolve, reject) => {
|
|
355
|
-
actuallyPostMessage(resolve, reject);
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
_onMessage(e) {
|
|
359
|
-
const common = this._onMessageCommon(e);
|
|
360
|
-
if (!common) {
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
const {
|
|
364
|
-
message,
|
|
365
|
-
type
|
|
366
|
-
} = common;
|
|
367
|
-
if (type === MSGTYPE_HOST_CLOSE) {
|
|
368
|
-
if (typeof message[2] !== "number") {
|
|
369
|
-
throw new Error("Invalid hostID");
|
|
370
|
-
}
|
|
371
|
-
const hostID = message[2];
|
|
372
|
-
this._hosts.delete(hostID);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
45
|
+
const isSharedWorker = (worker) => {
|
|
46
|
+
return worker.port !== void 0;
|
|
47
|
+
};
|
|
48
|
+
var PWBBase = class extends EventTarget {
|
|
49
|
+
_callbacks;
|
|
50
|
+
_queryCallback;
|
|
51
|
+
constructor() {
|
|
52
|
+
super();
|
|
53
|
+
this._callbacks = /* @__PURE__ */ new Map();
|
|
54
|
+
this._queryCallback = () => {};
|
|
55
|
+
this._onMessage = this._onMessage.bind(this);
|
|
56
|
+
}
|
|
57
|
+
addEventListener(type, listener, options) {
|
|
58
|
+
super.addEventListener(type, listener, options);
|
|
59
|
+
}
|
|
60
|
+
dispatchEvent(event) {
|
|
61
|
+
return super.dispatchEvent(event);
|
|
62
|
+
}
|
|
63
|
+
removeEventListener(type, listener, options) {
|
|
64
|
+
super.removeEventListener(type, listener, options);
|
|
65
|
+
}
|
|
66
|
+
register(cb) {
|
|
67
|
+
this._queryCallback = cb;
|
|
68
|
+
}
|
|
69
|
+
_postResponse(messageID, error, result, hostID) {
|
|
70
|
+
if (error) {
|
|
71
|
+
logError(error);
|
|
72
|
+
this._postMessage([
|
|
73
|
+
1,
|
|
74
|
+
messageID,
|
|
75
|
+
error
|
|
76
|
+
], hostID);
|
|
77
|
+
} else if (typeof result === "object" && result !== null && Object.hasOwn(result, "message") && Object.hasOwn(result, "_PWB_TRANSFER")) this._postMessage([
|
|
78
|
+
1,
|
|
79
|
+
messageID,
|
|
80
|
+
null,
|
|
81
|
+
result.message
|
|
82
|
+
], hostID, result._PWB_TRANSFER);
|
|
83
|
+
else this._postMessage([
|
|
84
|
+
1,
|
|
85
|
+
messageID,
|
|
86
|
+
null,
|
|
87
|
+
result
|
|
88
|
+
], hostID);
|
|
89
|
+
}
|
|
90
|
+
_handleQuery(message) {
|
|
91
|
+
const messageID = message[1];
|
|
92
|
+
const query = message[2];
|
|
93
|
+
const hostID = message[3];
|
|
94
|
+
try {
|
|
95
|
+
const result = this._queryCallback(query, hostID);
|
|
96
|
+
if (!isPromise(result)) this._postResponse(messageID, null, result, hostID);
|
|
97
|
+
else result.then((finalResult) => {
|
|
98
|
+
this._postResponse(messageID, null, finalResult, hostID);
|
|
99
|
+
}, (finalError) => {
|
|
100
|
+
this._postResponse(messageID, finalError, void 0, hostID);
|
|
101
|
+
});
|
|
102
|
+
} catch (err) {
|
|
103
|
+
this._postResponse(messageID, err);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
_onMessageCommon(e) {
|
|
107
|
+
const message = parseMessage(e.data);
|
|
108
|
+
if (!message) return;
|
|
109
|
+
if (message[0] === 0) {
|
|
110
|
+
this._handleQuery(message);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (message[0] === 1) {
|
|
114
|
+
const messageID = message[1];
|
|
115
|
+
const error = message[2] === null ? null : message[2];
|
|
116
|
+
const callback = this._callbacks.get(messageID);
|
|
117
|
+
if (callback === void 0) return;
|
|
118
|
+
this._callbacks.delete(messageID);
|
|
119
|
+
callback(error, message[3]);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
return message;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/PWBHost.ts
|
|
127
|
+
let nextMessageID$1 = 0;
|
|
128
|
+
var PWBHost = class extends PWBBase {
|
|
129
|
+
_hostID;
|
|
130
|
+
_hostIDQueue;
|
|
131
|
+
_worker;
|
|
132
|
+
constructor(worker) {
|
|
133
|
+
super();
|
|
134
|
+
if (!isSharedWorker(worker)) worker.addEventListener("message", this._onMessage);
|
|
135
|
+
else {
|
|
136
|
+
worker.port.addEventListener("message", this._onMessage);
|
|
137
|
+
worker.port.start();
|
|
138
|
+
}
|
|
139
|
+
this._worker = worker;
|
|
140
|
+
this._hostIDQueue = [];
|
|
141
|
+
}
|
|
142
|
+
_postMessage(obj, _hostID, transfer) {
|
|
143
|
+
if (isSharedWorker(this._worker)) {
|
|
144
|
+
if (transfer) this._worker.port.postMessage(obj, transfer);
|
|
145
|
+
else this._worker.port.postMessage(obj);
|
|
146
|
+
} else if (transfer) this._worker.postMessage(obj, transfer);
|
|
147
|
+
else this._worker.postMessage(obj);
|
|
148
|
+
}
|
|
149
|
+
postMessage(userMessage, _hostID, transfer) {
|
|
150
|
+
const actuallyPostMessage = (resolve, reject) => {
|
|
151
|
+
const messageID = nextMessageID$1;
|
|
152
|
+
nextMessageID$1 += 1;
|
|
153
|
+
const messageToSend = [
|
|
154
|
+
0,
|
|
155
|
+
messageID,
|
|
156
|
+
userMessage,
|
|
157
|
+
this._hostID
|
|
158
|
+
];
|
|
159
|
+
this._callbacks.set(messageID, (error, result) => {
|
|
160
|
+
if (error) reject(error);
|
|
161
|
+
else resolve(result);
|
|
162
|
+
});
|
|
163
|
+
this._postMessage(messageToSend, void 0, transfer);
|
|
164
|
+
};
|
|
165
|
+
return new Promise((resolve, reject) => {
|
|
166
|
+
if (this._hostIDQueue !== void 0) this._hostIDQueue.push(() => {
|
|
167
|
+
actuallyPostMessage(resolve, reject);
|
|
168
|
+
});
|
|
169
|
+
else actuallyPostMessage(resolve, reject);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
handleWorkerLock(workerLockId) {
|
|
173
|
+
navigator.locks.request(workerLockId, { mode: "shared" }, async () => {
|
|
174
|
+
this.dispatchEvent(new Event("close"));
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
_onMessage(e) {
|
|
178
|
+
const message = this._onMessageCommon(e);
|
|
179
|
+
if (!message) return;
|
|
180
|
+
if (message[0] === 2) {
|
|
181
|
+
if (this._hostID !== void 0) throw new Error("Received duplicate hostID message");
|
|
182
|
+
const hostID = message[1];
|
|
183
|
+
this._hostID = hostID;
|
|
184
|
+
if (this._hostIDQueue !== void 0) {
|
|
185
|
+
for (const cb of this._hostIDQueue) setTimeout(() => {
|
|
186
|
+
cb();
|
|
187
|
+
}, 0);
|
|
188
|
+
this._hostIDQueue = void 0;
|
|
189
|
+
}
|
|
190
|
+
if (message[2] !== void 0) this.handleWorkerLock(message[2]);
|
|
191
|
+
const hostLockId = `pwb-host-${Math.random()}`;
|
|
192
|
+
navigator.locks.request(hostLockId, async () => {
|
|
193
|
+
this._postMessage([
|
|
194
|
+
3,
|
|
195
|
+
hostID,
|
|
196
|
+
hostLockId
|
|
197
|
+
]);
|
|
198
|
+
return new Promise(() => {});
|
|
199
|
+
});
|
|
200
|
+
} else if (message[0] === 5) {
|
|
201
|
+
const error = message[1];
|
|
202
|
+
this.dispatchEvent(new ErrorEvent("error", { error }));
|
|
203
|
+
} else if (message[0] === 4) this.handleWorkerLock(message[1]);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/PWBWorker.ts
|
|
208
|
+
let nextMessageID = 0;
|
|
209
|
+
var PWBWorker = class extends PWBBase {
|
|
210
|
+
_hosts = /* @__PURE__ */ new Map();
|
|
211
|
+
_maxHostID = -1;
|
|
212
|
+
_sharedWorker;
|
|
213
|
+
_workerLockAcquired = false;
|
|
214
|
+
constructor() {
|
|
215
|
+
super();
|
|
216
|
+
const workerLockId = `pwb-worker-${Math.random()}`;
|
|
217
|
+
navigator.locks.request(workerLockId, async () => {
|
|
218
|
+
this._workerLockAcquired = true;
|
|
219
|
+
this._postMessage([4, workerLockId]);
|
|
220
|
+
return new Promise(() => {});
|
|
221
|
+
});
|
|
222
|
+
if (typeof SharedWorkerGlobalScope !== "undefined" && self instanceof SharedWorkerGlobalScope) {
|
|
223
|
+
this._sharedWorker = true;
|
|
224
|
+
const _self = self;
|
|
225
|
+
_self.addEventListener("connect", (e) => {
|
|
226
|
+
const port = e.ports[0];
|
|
227
|
+
port.addEventListener("message", (e2) => this._onMessage(e2));
|
|
228
|
+
port.start();
|
|
229
|
+
this._maxHostID += 1;
|
|
230
|
+
const hostID = this._maxHostID;
|
|
231
|
+
this._hosts.set(hostID, { port });
|
|
232
|
+
let message;
|
|
233
|
+
if (this._workerLockAcquired) message = [
|
|
234
|
+
2,
|
|
235
|
+
hostID,
|
|
236
|
+
workerLockId
|
|
237
|
+
];
|
|
238
|
+
else message = [2, hostID];
|
|
239
|
+
this._postMessage(message, hostID);
|
|
240
|
+
});
|
|
241
|
+
_self.addEventListener("error", (e) => {
|
|
242
|
+
logError(e.error);
|
|
243
|
+
e.preventDefault();
|
|
244
|
+
const hostID = this._hosts.keys().next().value;
|
|
245
|
+
if (hostID !== void 0) this._postMessage([5, e.error], hostID);
|
|
246
|
+
});
|
|
247
|
+
} else {
|
|
248
|
+
this._sharedWorker = false;
|
|
249
|
+
const _self = self;
|
|
250
|
+
_self.addEventListener("message", this._onMessage);
|
|
251
|
+
this._postMessage([2, 0], 0);
|
|
252
|
+
_self.addEventListener("error", (e) => {
|
|
253
|
+
logError(e.error);
|
|
254
|
+
e.preventDefault();
|
|
255
|
+
this._postMessage([5, e.error]);
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
_postMessage(message, targetHostID, transfer) {
|
|
260
|
+
if (this._sharedWorker) {
|
|
261
|
+
for (const [hostID, { port }] of this._hosts) if (targetHostID === void 0 || targetHostID === hostID) {
|
|
262
|
+
if (transfer) port.postMessage(message, transfer);
|
|
263
|
+
else port.postMessage(message);
|
|
264
|
+
}
|
|
265
|
+
} else {
|
|
266
|
+
const _self = self;
|
|
267
|
+
if (transfer) _self.postMessage(message, transfer);
|
|
268
|
+
else _self.postMessage(message);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
postMessage(userMessage, targetHostID, transfer) {
|
|
272
|
+
const actuallyPostMessage = (resolve, reject) => {
|
|
273
|
+
const messageID = nextMessageID;
|
|
274
|
+
nextMessageID += 1;
|
|
275
|
+
const messageToSend = [
|
|
276
|
+
0,
|
|
277
|
+
messageID,
|
|
278
|
+
userMessage
|
|
279
|
+
];
|
|
280
|
+
this._callbacks.set(messageID, (error, result) => {
|
|
281
|
+
if (error) reject(error);
|
|
282
|
+
else resolve(result);
|
|
283
|
+
});
|
|
284
|
+
this._postMessage(messageToSend, targetHostID, transfer);
|
|
285
|
+
};
|
|
286
|
+
return new Promise((resolve, reject) => {
|
|
287
|
+
actuallyPostMessage(resolve, reject);
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
_onMessage(e) {
|
|
291
|
+
const message = this._onMessageCommon(e);
|
|
292
|
+
if (!message) return;
|
|
293
|
+
if (message[0] === 3) navigator.locks.request(message[2], () => {
|
|
294
|
+
if (this._hosts.size > 1) this._hosts.delete(message[1]);
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
//#endregion
|
|
377
299
|
export { PWBHost, PWBWorker };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "promise-worker-bi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-beta.1",
|
|
4
4
|
"description": "Promise-based messaging for Web Workers and Shared Workers",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -12,13 +12,10 @@
|
|
|
12
12
|
},
|
|
13
13
|
"type": "module",
|
|
14
14
|
"scripts": {
|
|
15
|
-
"prepack": "
|
|
16
|
-
"build": "
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"prettier": "prettier --write 'src/*.ts' && prettier --write 'test/*.js' && prettier --write 'scripts/*.js'",
|
|
20
|
-
"karma": "node --run build-test && karma start",
|
|
21
|
-
"test": "tsc --noEmit && node --run lint && node --run karma",
|
|
15
|
+
"prepack": "pnpm run build",
|
|
16
|
+
"build": "tsdown",
|
|
17
|
+
"lint": "pnpm run build && tsc && eslint .",
|
|
18
|
+
"test": "pnpm run build && vitest run",
|
|
22
19
|
"prepare": "husky"
|
|
23
20
|
},
|
|
24
21
|
"repository": {
|
|
@@ -40,36 +37,26 @@
|
|
|
40
37
|
},
|
|
41
38
|
"homepage": "https://github.com/dumbmatter/promise-worker-bi",
|
|
42
39
|
"devDependencies": {
|
|
43
|
-
"@babel/core": "^7.29.0",
|
|
44
|
-
"@babel/preset-typescript": "^7.28.5",
|
|
45
40
|
"@eslint/js": "^10.0.1",
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
49
|
-
"
|
|
50
|
-
"eslint": "^
|
|
51
|
-
"
|
|
52
|
-
"globals": "^17.4.0",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^8.69.0",
|
|
42
|
+
"@typescript-eslint/parser": "^8.69.0",
|
|
43
|
+
"@vitest/browser-playwright": "^5.0.0",
|
|
44
|
+
"eslint": "^10.10.0",
|
|
45
|
+
"eslint-plugin-import-x": "^4.17.1",
|
|
46
|
+
"globals": "^17.12.0",
|
|
53
47
|
"husky": "^9.1.7",
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"prettier": "^3.8.1",
|
|
62
|
-
"rollup": "^4.59.0",
|
|
63
|
-
"rollup-plugin-node-builtins": "^2.1.2",
|
|
64
|
-
"rollup-plugin-node-globals": "^1.4.0",
|
|
65
|
-
"tinyglobby": "^0.2.15",
|
|
66
|
-
"typescript": "^5.9.3",
|
|
67
|
-
"typescript-eslint": "^8.56.1"
|
|
48
|
+
"lint-staged": "^17.5.0",
|
|
49
|
+
"oxfmt": "^0.66.0",
|
|
50
|
+
"playwright": "^1.63.0",
|
|
51
|
+
"tsdown": "^0.23.0",
|
|
52
|
+
"typescript": "^6.0.3",
|
|
53
|
+
"typescript-eslint": "^8.69.0",
|
|
54
|
+
"vitest": "^5.0.0"
|
|
68
55
|
},
|
|
69
56
|
"files": [
|
|
70
57
|
"dist"
|
|
71
58
|
],
|
|
72
59
|
"lint-staged": {
|
|
73
|
-
"
|
|
60
|
+
"*": "oxfmt --no-error-on-unmatched-pattern"
|
|
74
61
|
}
|
|
75
62
|
}
|