@xylabs/threads 4.0.10 → 4.1.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/esm/master/implementation.browser.js +4 -4
- package/dist/esm/master/register.js +2 -2
- package/dist/esm/worker/bundle-entry.js +4 -4
- package/dist/esm/worker/implementation.tiny-worker.js +2 -2
- package/dist/esm/worker/index.js +1 -1
- package/dist/master/implementation.browser.js +4 -4
- package/dist/master/register.js +2 -2
- package/dist/worker/bundle-entry.js +4 -4
- package/dist/worker/implementation.tiny-worker.js +2 -2
- package/dist/worker/index.js +1 -1
- package/package.json +10 -10
- package/src/master/implementation.browser.ts +4 -4
- package/src/master/register.ts +2 -2
- package/src/worker/bundle-entry.ts +4 -4
- package/src/worker/implementation.tiny-worker.ts +2 -2
- package/src/worker/index.ts +1 -1
- package/test/spawn.chromium.mocha.ts +1 -1
|
@@ -39,11 +39,11 @@ function selectWorkerImplementation() {
|
|
|
39
39
|
}
|
|
40
40
|
class BlobWorker extends WebWorker {
|
|
41
41
|
constructor(blob, options) {
|
|
42
|
-
const url =
|
|
42
|
+
const url = globalThis.URL.createObjectURL(blob);
|
|
43
43
|
super(url, options);
|
|
44
44
|
}
|
|
45
45
|
static fromText(source, options) {
|
|
46
|
-
const blob = new
|
|
46
|
+
const blob = new globalThis.Blob([source], { type: 'text/javascript' });
|
|
47
47
|
return new BlobWorker(blob, options);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -60,6 +60,6 @@ function getWorkerImplementation() {
|
|
|
60
60
|
return implementation;
|
|
61
61
|
}
|
|
62
62
|
function isWorkerRuntime() {
|
|
63
|
-
const isWindowContext = typeof
|
|
64
|
-
return typeof
|
|
63
|
+
const isWindowContext = typeof globalThis !== 'undefined' && typeof Window !== 'undefined' && globalThis instanceof Window;
|
|
64
|
+
return typeof globalThis !== 'undefined' && self['postMessage'] && !isWindowContext ? true : false;
|
|
65
65
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const index_1 = require("./index");
|
|
4
|
-
if (typeof
|
|
4
|
+
if (typeof globalThis !== 'undefined') {
|
|
5
5
|
;
|
|
6
|
-
|
|
6
|
+
globalThis.Worker = index_1.Worker;
|
|
7
7
|
}
|
|
8
8
|
else if (window !== undefined) {
|
|
9
9
|
;
|
|
@@ -16,11 +16,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
const index_1 = require("./index");
|
|
18
18
|
__exportStar(require("./index"), exports);
|
|
19
|
-
if (typeof
|
|
19
|
+
if (typeof globalThis !== 'undefined') {
|
|
20
20
|
;
|
|
21
|
-
|
|
21
|
+
globalThis.expose = index_1.expose;
|
|
22
22
|
}
|
|
23
|
-
if (typeof
|
|
23
|
+
if (typeof globalThis !== 'undefined') {
|
|
24
24
|
;
|
|
25
|
-
|
|
25
|
+
globalThis.expose = index_1.expose;
|
|
26
26
|
}
|
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
try {
|
|
4
4
|
if (self === undefined) {
|
|
5
5
|
;
|
|
6
|
-
|
|
6
|
+
globalThis.self = globalThis;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
catch {
|
|
10
10
|
;
|
|
11
|
-
|
|
11
|
+
globalThis.self = globalThis;
|
|
12
12
|
}
|
|
13
13
|
const isWorkerRuntime = function isWorkerRuntime() {
|
|
14
14
|
return self !== undefined && self['postMessage'] ? true : false;
|
package/dist/esm/worker/index.js
CHANGED
|
@@ -151,7 +151,7 @@ function expose(exposed) {
|
|
|
151
151
|
}
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
|
-
if (typeof
|
|
154
|
+
if (typeof globalThis !== 'undefined' && typeof self.addEventListener === 'function' && implementation_1.default.isWorkerRuntime()) {
|
|
155
155
|
self.addEventListener('error', (event) => {
|
|
156
156
|
setTimeout(() => postUncaughtErrorMessage(event.error || event), 250);
|
|
157
157
|
});
|
|
@@ -39,11 +39,11 @@ function selectWorkerImplementation() {
|
|
|
39
39
|
}
|
|
40
40
|
class BlobWorker extends WebWorker {
|
|
41
41
|
constructor(blob, options) {
|
|
42
|
-
const url =
|
|
42
|
+
const url = globalThis.URL.createObjectURL(blob);
|
|
43
43
|
super(url, options);
|
|
44
44
|
}
|
|
45
45
|
static fromText(source, options) {
|
|
46
|
-
const blob = new
|
|
46
|
+
const blob = new globalThis.Blob([source], { type: 'text/javascript' });
|
|
47
47
|
return new BlobWorker(blob, options);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -60,6 +60,6 @@ function getWorkerImplementation() {
|
|
|
60
60
|
return implementation;
|
|
61
61
|
}
|
|
62
62
|
function isWorkerRuntime() {
|
|
63
|
-
const isWindowContext = typeof
|
|
64
|
-
return typeof
|
|
63
|
+
const isWindowContext = typeof globalThis !== 'undefined' && typeof Window !== 'undefined' && globalThis instanceof Window;
|
|
64
|
+
return typeof globalThis !== 'undefined' && self['postMessage'] && !isWindowContext ? true : false;
|
|
65
65
|
}
|
package/dist/master/register.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const index_1 = require("./index");
|
|
4
|
-
if (typeof
|
|
4
|
+
if (typeof globalThis !== 'undefined') {
|
|
5
5
|
;
|
|
6
|
-
|
|
6
|
+
globalThis.Worker = index_1.Worker;
|
|
7
7
|
}
|
|
8
8
|
else if (window !== undefined) {
|
|
9
9
|
;
|
|
@@ -16,11 +16,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
const index_1 = require("./index");
|
|
18
18
|
__exportStar(require("./index"), exports);
|
|
19
|
-
if (typeof
|
|
19
|
+
if (typeof globalThis !== 'undefined') {
|
|
20
20
|
;
|
|
21
|
-
|
|
21
|
+
globalThis.expose = index_1.expose;
|
|
22
22
|
}
|
|
23
|
-
if (typeof
|
|
23
|
+
if (typeof globalThis !== 'undefined') {
|
|
24
24
|
;
|
|
25
|
-
|
|
25
|
+
globalThis.expose = index_1.expose;
|
|
26
26
|
}
|
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
try {
|
|
4
4
|
if (self === undefined) {
|
|
5
5
|
;
|
|
6
|
-
|
|
6
|
+
globalThis.self = globalThis;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
catch {
|
|
10
10
|
;
|
|
11
|
-
|
|
11
|
+
globalThis.self = globalThis;
|
|
12
12
|
}
|
|
13
13
|
const isWorkerRuntime = function isWorkerRuntime() {
|
|
14
14
|
return self !== undefined && self['postMessage'] ? true : false;
|
package/dist/worker/index.js
CHANGED
|
@@ -151,7 +151,7 @@ function expose(exposed) {
|
|
|
151
151
|
}
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
|
-
if (typeof
|
|
154
|
+
if (typeof globalThis !== 'undefined' && typeof self.addEventListener === 'function' && implementation_1.default.isWorkerRuntime()) {
|
|
155
155
|
self.addEventListener('error', (event) => {
|
|
156
156
|
setTimeout(() => postUncaughtErrorMessage(event.error || event), 250);
|
|
157
157
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/threads",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Web workers & worker threads as simple as a function call",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -91,32 +91,32 @@
|
|
|
91
91
|
"observable-fns": "^0.6.1"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
|
-
"@rollup/plugin-commonjs": "^
|
|
95
|
-
"@rollup/plugin-node-resolve": "^15.
|
|
96
|
-
"@types/chai": "^
|
|
94
|
+
"@rollup/plugin-commonjs": "^28.0.0",
|
|
95
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
96
|
+
"@types/chai": "^5.0.0",
|
|
97
97
|
"@types/debug": "^4.1.12",
|
|
98
98
|
"@types/execa": "^2.0.0",
|
|
99
|
-
"@types/node": "^22.5
|
|
99
|
+
"@types/node": "^22.7.5",
|
|
100
100
|
"@types/webpack": "^5.28.5",
|
|
101
|
-
"@xylabs/ts-scripts-yarn3": "^4.0
|
|
101
|
+
"@xylabs/ts-scripts-yarn3": "^4.1.0",
|
|
102
102
|
"ava": "^6.1.3",
|
|
103
103
|
"chai": "^5.1.1",
|
|
104
104
|
"cross-env": "^7.0.3",
|
|
105
|
-
"execa": "^9.
|
|
105
|
+
"execa": "^9.4.0",
|
|
106
106
|
"mocha": "^10.7.3",
|
|
107
107
|
"puppet-run": "^0.11.4",
|
|
108
108
|
"puppet-run-plugin-mocha": "^0.1.1",
|
|
109
109
|
"raw-loader": "^4.0.2",
|
|
110
110
|
"rimraf": "^5.0.10",
|
|
111
|
-
"rollup": "^4.
|
|
111
|
+
"rollup": "^4.24.0",
|
|
112
112
|
"threads-plugin": "^1.4.0",
|
|
113
113
|
"tiny-worker": "^2.3.0",
|
|
114
114
|
"ts-loader": "^9.5.1",
|
|
115
115
|
"ts-node": "^10.9.2",
|
|
116
|
-
"typescript": "^5.
|
|
116
|
+
"typescript": "^5.6.2",
|
|
117
117
|
"undici-types": "^6.19.8",
|
|
118
118
|
"wavy": "^1.0.4",
|
|
119
|
-
"webpack": "^5.
|
|
119
|
+
"webpack": "^5.95.0",
|
|
120
120
|
"worker-plugin": "^5.0.1"
|
|
121
121
|
},
|
|
122
122
|
"optionalDependencies": {
|
|
@@ -51,12 +51,12 @@ function selectWorkerImplementation(): ImplementationExport {
|
|
|
51
51
|
|
|
52
52
|
class BlobWorker extends WebWorker {
|
|
53
53
|
constructor(blob: Blob, options?: ThreadsWorkerOptions) {
|
|
54
|
-
const url =
|
|
54
|
+
const url = globalThis.URL.createObjectURL(blob)
|
|
55
55
|
super(url, options)
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
static fromText(source: string, options?: ThreadsWorkerOptions): WebWorker {
|
|
59
|
-
const blob = new
|
|
59
|
+
const blob = new globalThis.Blob([source], { type: 'text/javascript' })
|
|
60
60
|
return new BlobWorker(blob, options)
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -77,6 +77,6 @@ export function getWorkerImplementation(): ImplementationExport {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
export function isWorkerRuntime() {
|
|
80
|
-
const isWindowContext = typeof
|
|
81
|
-
return typeof
|
|
80
|
+
const isWindowContext = typeof globalThis !== 'undefined' && typeof Window !== 'undefined' && globalThis instanceof Window
|
|
81
|
+
return typeof globalThis !== 'undefined' && self['postMessage'] && !isWindowContext ? true : false
|
|
82
82
|
}
|
package/src/master/register.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { Worker as WorkerImplementation } from './index'
|
|
|
3
3
|
|
|
4
4
|
declare const window: any
|
|
5
5
|
|
|
6
|
-
if (typeof
|
|
7
|
-
;(
|
|
6
|
+
if (typeof globalThis !== 'undefined') {
|
|
7
|
+
;(globalThis as any).Worker = WorkerImplementation
|
|
8
8
|
} else if (window !== undefined) {
|
|
9
9
|
;(window as any).Worker = WorkerImplementation
|
|
10
10
|
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { expose } from './index'
|
|
3
3
|
export * from './index'
|
|
4
4
|
|
|
5
|
-
if (typeof
|
|
6
|
-
;(
|
|
5
|
+
if (typeof globalThis !== 'undefined') {
|
|
6
|
+
;(globalThis as any).expose = expose
|
|
7
7
|
}
|
|
8
|
-
if (typeof
|
|
9
|
-
;(
|
|
8
|
+
if (typeof globalThis !== 'undefined') {
|
|
9
|
+
;(globalThis as any).expose = expose
|
|
10
10
|
}
|
|
@@ -14,10 +14,10 @@ interface WorkerGlobalScope {
|
|
|
14
14
|
declare const self: WorkerGlobalScope
|
|
15
15
|
try {
|
|
16
16
|
if (self === undefined) {
|
|
17
|
-
;(
|
|
17
|
+
;(globalThis as any).self = globalThis
|
|
18
18
|
}
|
|
19
19
|
} catch {
|
|
20
|
-
;(
|
|
20
|
+
;(globalThis as any).self = globalThis
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const isWorkerRuntime: AbstractedWorkerAPI['isWorkerRuntime'] = function isWorkerRuntime() {
|
package/src/worker/index.ts
CHANGED
|
@@ -202,7 +202,7 @@ export function expose(exposed: WorkerFunction | WorkerModule<any>) {
|
|
|
202
202
|
})
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
if (typeof
|
|
205
|
+
if (typeof globalThis !== 'undefined' && typeof self.addEventListener === 'function' && Implementation.isWorkerRuntime()) {
|
|
206
206
|
self.addEventListener('error', (event) => {
|
|
207
207
|
// Post with some delay, so the master had some time to subscribe to messages
|
|
208
208
|
setTimeout(() => postUncaughtErrorMessage(event.error || event), 250)
|
|
@@ -31,7 +31,7 @@ describe('threads in browser', function () {
|
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
it('can spawn and use a blob worker', async function () {
|
|
34
|
-
const baseUrl = new URL(
|
|
34
|
+
const baseUrl = new URL(globalThis.location.href).origin
|
|
35
35
|
const workerSource = `
|
|
36
36
|
// Makes expose() available on global scope
|
|
37
37
|
importScripts(${JSON.stringify(baseUrl + '/worker.js')})
|