@xylabs/threads 4.0.10 → 4.2.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.
@@ -39,11 +39,11 @@ function selectWorkerImplementation() {
39
39
  }
40
40
  class BlobWorker extends WebWorker {
41
41
  constructor(blob, options) {
42
- const url = window.URL.createObjectURL(blob);
42
+ const url = globalThis.URL.createObjectURL(blob);
43
43
  super(url, options);
44
44
  }
45
45
  static fromText(source, options) {
46
- const blob = new window.Blob([source], { type: 'text/javascript' });
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 self !== 'undefined' && typeof Window !== 'undefined' && self instanceof Window;
64
- return typeof self !== 'undefined' && self['postMessage'] && !isWindowContext ? true : false;
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 global !== 'undefined') {
4
+ if (typeof globalThis !== 'undefined') {
5
5
  ;
6
- global.Worker = index_1.Worker;
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 global !== 'undefined') {
19
+ if (typeof globalThis !== 'undefined') {
20
20
  ;
21
- global.expose = index_1.expose;
21
+ globalThis.expose = index_1.expose;
22
22
  }
23
- if (typeof self !== 'undefined') {
23
+ if (typeof globalThis !== 'undefined') {
24
24
  ;
25
- self.expose = index_1.expose;
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
- global.self = global;
6
+ globalThis.self = globalThis;
7
7
  }
8
8
  }
9
9
  catch {
10
10
  ;
11
- global.self = global;
11
+ globalThis.self = globalThis;
12
12
  }
13
13
  const isWorkerRuntime = function isWorkerRuntime() {
14
14
  return self !== undefined && self['postMessage'] ? true : false;
@@ -151,7 +151,7 @@ function expose(exposed) {
151
151
  }
152
152
  });
153
153
  }
154
- if (typeof self !== 'undefined' && typeof self.addEventListener === 'function' && implementation_1.default.isWorkerRuntime()) {
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 = window.URL.createObjectURL(blob);
42
+ const url = globalThis.URL.createObjectURL(blob);
43
43
  super(url, options);
44
44
  }
45
45
  static fromText(source, options) {
46
- const blob = new window.Blob([source], { type: 'text/javascript' });
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 self !== 'undefined' && typeof Window !== 'undefined' && self instanceof Window;
64
- return typeof self !== 'undefined' && self['postMessage'] && !isWindowContext ? true : false;
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 global !== 'undefined') {
4
+ if (typeof globalThis !== 'undefined') {
5
5
  ;
6
- global.Worker = index_1.Worker;
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 global !== 'undefined') {
19
+ if (typeof globalThis !== 'undefined') {
20
20
  ;
21
- global.expose = index_1.expose;
21
+ globalThis.expose = index_1.expose;
22
22
  }
23
- if (typeof self !== 'undefined') {
23
+ if (typeof globalThis !== 'undefined') {
24
24
  ;
25
- self.expose = index_1.expose;
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
- global.self = global;
6
+ globalThis.self = globalThis;
7
7
  }
8
8
  }
9
9
  catch {
10
10
  ;
11
- global.self = global;
11
+ globalThis.self = globalThis;
12
12
  }
13
13
  const isWorkerRuntime = function isWorkerRuntime() {
14
14
  return self !== undefined && self['postMessage'] ? true : false;
@@ -151,7 +151,7 @@ function expose(exposed) {
151
151
  }
152
152
  });
153
153
  }
154
- if (typeof self !== 'undefined' && typeof self.addEventListener === 'function' && implementation_1.default.isWorkerRuntime()) {
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.10",
3
+ "version": "4.2.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": "^26.0.1",
95
- "@rollup/plugin-node-resolve": "^15.2.3",
96
- "@types/chai": "^4.3.19",
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.4",
99
+ "@types/node": "^22.7.5",
100
100
  "@types/webpack": "^5.28.5",
101
- "@xylabs/ts-scripts-yarn3": "^4.0.7",
101
+ "@xylabs/ts-scripts-yarn3": "^4.2.0",
102
102
  "ava": "^6.1.3",
103
103
  "chai": "^5.1.1",
104
104
  "cross-env": "^7.0.3",
105
- "execa": "^9.3.1",
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.21.2",
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.5.4",
117
- "undici-types": "^6.19.8",
116
+ "typescript": "^5.6.3",
117
+ "undici-types": "^6.20.0",
118
118
  "wavy": "^1.0.4",
119
- "webpack": "^5.94.0",
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 = window.URL.createObjectURL(blob)
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 window.Blob([source], { type: 'text/javascript' })
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 self !== 'undefined' && typeof Window !== 'undefined' && self instanceof Window
81
- return typeof self !== 'undefined' && self['postMessage'] && !isWindowContext ? true : false
80
+ const isWindowContext = typeof globalThis !== 'undefined' && typeof Window !== 'undefined' && globalThis instanceof Window
81
+ return typeof globalThis !== 'undefined' && self['postMessage'] && !isWindowContext ? true : false
82
82
  }
@@ -3,8 +3,8 @@ import { Worker as WorkerImplementation } from './index'
3
3
 
4
4
  declare const window: any
5
5
 
6
- if (typeof global !== 'undefined') {
7
- ;(global as any).Worker = WorkerImplementation
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 global !== 'undefined') {
6
- ;(global as any).expose = expose
5
+ if (typeof globalThis !== 'undefined') {
6
+ ;(globalThis as any).expose = expose
7
7
  }
8
- if (typeof self !== 'undefined') {
9
- ;(self as any).expose = expose
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
- ;(global as any).self = global
17
+ ;(globalThis as any).self = globalThis
18
18
  }
19
19
  } catch {
20
- ;(global as any).self = global
20
+ ;(globalThis as any).self = globalThis
21
21
  }
22
22
 
23
23
  const isWorkerRuntime: AbstractedWorkerAPI['isWorkerRuntime'] = function isWorkerRuntime() {
@@ -202,7 +202,7 @@ export function expose(exposed: WorkerFunction | WorkerModule<any>) {
202
202
  })
203
203
  }
204
204
 
205
- if (typeof self !== 'undefined' && typeof self.addEventListener === 'function' && Implementation.isWorkerRuntime()) {
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(window.location.href).origin
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')})