@xylabs/threads 3.6.5 → 3.6.7

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.
@@ -35,11 +35,10 @@ function detectTsNode() {
35
35
  return tsNodeAvailable;
36
36
  }
37
37
  function createTsNodeModule(scriptPath) {
38
- const content = `
38
+ return `
39
39
  require("ts-node/register/transpile-only");
40
40
  require(${JSON.stringify(scriptPath)});
41
41
  `;
42
- return content;
43
42
  }
44
43
  function rebaseScriptPath(scriptPath, ignoreRegex) {
45
44
  const parentCallSite = (0, callsites_3_1_0_1.default)().find((callsite) => {
@@ -51,17 +50,15 @@ function rebaseScriptPath(scriptPath, ignoreRegex) {
51
50
  if (callerPath && callerPath.startsWith('file:')) {
52
51
  callerPath = (0, node_url_1.fileURLToPath)(callerPath);
53
52
  }
54
- const rebasedScriptPath = callerPath ? node_path_1.default.join(node_path_1.default.dirname(callerPath), scriptPath) : scriptPath;
55
- return rebasedScriptPath;
53
+ return callerPath ? node_path_1.default.join(node_path_1.default.dirname(callerPath), scriptPath) : scriptPath;
56
54
  }
57
55
  function resolveScriptPath(scriptPath, baseURL) {
58
56
  const makeRelative = (filePath) => {
59
57
  return node_path_1.default.isAbsolute(filePath) ? filePath : node_path_1.default.join(baseURL || eval('__dirname'), filePath);
60
58
  };
61
- const workerFilePath = typeof __non_webpack_require__ === 'function' ?
59
+ return typeof __non_webpack_require__ === 'function' ?
62
60
  __non_webpack_require__.resolve(makeRelative(scriptPath))
63
61
  : eval('require').resolve(makeRelative(rebaseScriptPath(scriptPath, /[/\\]worker_threads[/\\]/)));
64
- return workerFilePath;
65
62
  }
66
63
  function initWorkerThreadsWorker() {
67
64
  const NativeWorker = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__('worker_threads').Worker : eval('require')('worker_threads').Worker;
@@ -35,11 +35,10 @@ function detectTsNode() {
35
35
  return tsNodeAvailable;
36
36
  }
37
37
  function createTsNodeModule(scriptPath) {
38
- const content = `
38
+ return `
39
39
  require("ts-node/register/transpile-only");
40
40
  require(${JSON.stringify(scriptPath)});
41
41
  `;
42
- return content;
43
42
  }
44
43
  function rebaseScriptPath(scriptPath, ignoreRegex) {
45
44
  const parentCallSite = (0, callsites_3_1_0_1.default)().find((callsite) => {
@@ -51,17 +50,15 @@ function rebaseScriptPath(scriptPath, ignoreRegex) {
51
50
  if (callerPath && callerPath.startsWith('file:')) {
52
51
  callerPath = (0, node_url_1.fileURLToPath)(callerPath);
53
52
  }
54
- const rebasedScriptPath = callerPath ? node_path_1.default.join(node_path_1.default.dirname(callerPath), scriptPath) : scriptPath;
55
- return rebasedScriptPath;
53
+ return callerPath ? node_path_1.default.join(node_path_1.default.dirname(callerPath), scriptPath) : scriptPath;
56
54
  }
57
55
  function resolveScriptPath(scriptPath, baseURL) {
58
56
  const makeRelative = (filePath) => {
59
57
  return node_path_1.default.isAbsolute(filePath) ? filePath : node_path_1.default.join(baseURL || eval('__dirname'), filePath);
60
58
  };
61
- const workerFilePath = typeof __non_webpack_require__ === 'function' ?
59
+ return typeof __non_webpack_require__ === 'function' ?
62
60
  __non_webpack_require__.resolve(makeRelative(scriptPath))
63
61
  : eval('require').resolve(makeRelative(rebaseScriptPath(scriptPath, /[/\\]worker_threads[/\\]/)));
64
- return workerFilePath;
65
62
  }
66
63
  function initWorkerThreadsWorker() {
67
64
  const NativeWorker = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__('worker_threads').Worker : eval('require')('worker_threads').Worker;
package/observable.d.ts CHANGED
@@ -1 +1,2 @@
1
+ // eslint-disable-next-line import/no-internal-modules
1
2
  export * from './dist/observable'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/threads",
3
- "version": "3.6.5",
3
+ "version": "3.6.7",
4
4
  "description": "Web workers & worker threads as simple as a function call",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -83,19 +83,19 @@
83
83
  "worker_threads"
84
84
  ],
85
85
  "dependencies": {
86
- "@babel/types": "^7.24.9",
86
+ "@babel/types": "^7.25.2",
87
87
  "callsites-3-1-0": "npm:callsites@3.1.0",
88
- "debug": "^4.3.5",
88
+ "debug": "^4.3.6",
89
89
  "is-observable-2-1-0": "npm:is-observable@2.1.0",
90
90
  "observable-fns": "^0.6.1"
91
91
  },
92
92
  "devDependencies": {
93
93
  "@rollup/plugin-commonjs": "^26.0.1",
94
94
  "@rollup/plugin-node-resolve": "^15.2.3",
95
- "@types/chai": "^4.3.16",
95
+ "@types/chai": "^4.3.17",
96
96
  "@types/debug": "^4.1.12",
97
97
  "@types/execa": "^2.0.0",
98
- "@types/node": "^20.14.12",
98
+ "@types/node": "^22.1.0",
99
99
  "@types/webpack": "^5.28.5",
100
100
  "ava": "^6.1.3",
101
101
  "chai": "^5.1.1",
@@ -105,14 +105,14 @@
105
105
  "puppet-run": "^0.11.4",
106
106
  "puppet-run-plugin-mocha": "^0.1.1",
107
107
  "raw-loader": "^4.0.2",
108
- "rimraf": "^5.0.9",
109
- "rollup": "^4.19.0",
108
+ "rimraf": "^4.4.1",
109
+ "rollup": "^4.19.2",
110
110
  "threads-plugin": "^1.4.0",
111
111
  "tiny-worker": "^2.3.0",
112
112
  "ts-loader": "^9.5.1",
113
113
  "ts-node": "^10.9.2",
114
114
  "typescript": "^5.5.4",
115
- "undici-types": "^6.19.4",
115
+ "undici-types": "^6.19.5",
116
116
  "wavy": "^1.0.4",
117
117
  "webpack": "^5.93.0",
118
118
  "worker-plugin": "^5.0.1"
package/register.d.ts CHANGED
@@ -1 +1,2 @@
1
+ // eslint-disable-next-line import/no-internal-modules
1
2
  export * from './dist/master/register'
package/rollup.config.js CHANGED
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-var-requires */
2
1
  const commonjs = require('@rollup/plugin-commonjs')
3
2
  const { nodeResolve } = require('@rollup/plugin-node-resolve')
4
3
 
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  export { registerSerializer } from './common'
2
3
  export * from './master/index'
3
4
  export { QueuedTask } from './master/pool'
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  // tslint:disable max-classes-per-file
2
3
 
3
4
  import { ImplementationExport, ThreadsWorkerOptions } from '../types/master'
@@ -1,3 +1,6 @@
1
+ /* eslint-disable import/no-internal-modules */
2
+ /* eslint-disable unicorn/no-process-exit */
3
+ /* eslint-disable sonarjs/no-identical-functions */
1
4
  /* eslint-disable unicorn/prefer-logical-operator-over-ternary */
2
5
  /* eslint-disable unicorn/prefer-regexp-test */
3
6
  /* eslint-disable @typescript-eslint/no-var-requires */
@@ -5,7 +8,6 @@
5
8
  /* eslint-disable unicorn/prefer-event-target */
6
9
  /* eslint-disable @typescript-eslint/no-explicit-any */
7
10
  /* eslint-disable unicorn/text-encoding-identifier-case */
8
- /* eslint-disable unicorn/no-process-exit */
9
11
  /// <reference lib="dom" />
10
12
 
11
13
  import { EventEmitter } from 'node:events'
@@ -56,11 +58,10 @@ function detectTsNode() {
56
58
  }
57
59
 
58
60
  function createTsNodeModule(scriptPath: string) {
59
- const content = `
61
+ return `
60
62
  require("ts-node/register/transpile-only");
61
63
  require(${JSON.stringify(scriptPath)});
62
64
  `
63
- return content
64
65
  }
65
66
 
66
67
  function rebaseScriptPath(scriptPath: string, ignoreRegex: RegExp) {
@@ -76,9 +77,7 @@ function rebaseScriptPath(scriptPath: string, ignoreRegex: RegExp) {
76
77
  if (callerPath && callerPath.startsWith('file:')) {
77
78
  callerPath = fileURLToPath(callerPath)
78
79
  }
79
- const rebasedScriptPath = callerPath ? path.join(path.dirname(callerPath), scriptPath) : scriptPath
80
-
81
- return rebasedScriptPath
80
+ return callerPath ? path.join(path.dirname(callerPath), scriptPath) : scriptPath
82
81
  }
83
82
 
84
83
  function resolveScriptPath(scriptPath: string, baseURL?: string | undefined) {
@@ -87,12 +86,9 @@ function resolveScriptPath(scriptPath: string, baseURL?: string | undefined) {
87
86
  return path.isAbsolute(filePath) ? filePath : path.join(baseURL || eval('__dirname'), filePath)
88
87
  }
89
88
 
90
- const workerFilePath =
91
- typeof __non_webpack_require__ === 'function' ?
89
+ return typeof __non_webpack_require__ === 'function' ?
92
90
  __non_webpack_require__.resolve(makeRelative(scriptPath))
93
91
  : eval('require').resolve(makeRelative(rebaseScriptPath(scriptPath, /[/\\]worker_threads[/\\]/)))
94
-
95
- return workerFilePath
96
92
  }
97
93
 
98
94
  function initWorkerThreadsWorker(): ImplementationExport {
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  // tslint:disable no-duplicate-imports
2
3
  import type { BlobWorker as BlobWorkerClass } from '../types/master'
3
4
  import { Worker as WorkerType } from '../types/master'
@@ -1,3 +1,5 @@
1
+ /* eslint-disable import/no-internal-modules */
2
+ /* eslint-disable sonarjs/no-all-duplicated-branches */
1
3
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
4
  /*
3
5
  * This source file contains the code for proxying calls in the master thread to calls in the workers
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/export */
1
2
  /* eslint-disable unicorn/no-thenable */
2
3
 
3
4
  /* eslint-disable require-await */
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
3
  /* eslint-disable @typescript-eslint/no-floating-promises */
3
4
  import DebugLogger from 'debug'
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  import { Observable } from 'observable-fns'
2
3
 
3
4
  import { $errors, $events, $terminate } from '../symbols'
package/src/observable.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable sonarjs/prefer-immediate-return */
1
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
3
  import { Observable, ObservableLike, SubscriptionObserver } from 'observable-fns'
3
4
 
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
3
  import { SerializedError } from './types/messages'
3
4
 
@@ -1,3 +1,4 @@
1
+ /* eslint-disable sonarjs/prefer-single-boolean-return */
1
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
3
  import { $transferable } from './symbols'
3
4
 
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
3
  /// <reference lib="dom" />
3
4
  // tslint:disable no-shadowed-variable
@@ -1,3 +1,5 @@
1
+ /* eslint-disable import/no-internal-modules */
2
+ /* eslint-disable sonarjs/prefer-immediate-return */
1
3
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
4
  /// <reference lib="dom" />
3
5
  // tslint:disable no-shadowed-variable
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  // tslint:disable no-var-requires
2
3
  /*
3
4
  * This file is only a stub to make './implementation' resolve to the right module.
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
3
  // tslint:disable no-shadowed-variable
3
4
  import { MessagePort } from 'node:worker_threads'
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
3
  /* eslint-disable @typescript-eslint/no-floating-promises */
3
4
  import isSomeObservable from 'is-observable-2-1-0'
@@ -1,3 +1,5 @@
1
+ /* eslint-disable import/no-internal-modules */
2
+ /* eslint-disable sonarjs/no-duplicate-string */
1
3
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
4
  import test from 'ava'
3
5
  import { Observable } from 'observable-fns'
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  /* eslint-disable require-await */
2
3
 
3
4
  import test from 'ava'
package/test/pool.test.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  /* eslint-disable @typescript-eslint/no-floating-promises */
2
3
  /* eslint-disable require-await */
3
4
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -8,6 +9,9 @@ import test from 'ava'
8
9
  import { Pool, spawn, Worker } from '../src/index'
9
10
  import { PoolEventType, QueuedTask } from '../src/master/pool'
10
11
 
12
+ const workerPath = './workers/hello-world'
13
+ const HELLO_WORLD = 'Hello World'
14
+
11
15
  test.serial('thread pool basics work and events are emitted', async (t) => {
12
16
  const events: Pool.Event[] = []
13
17
  let spawnCalled = 0
@@ -15,7 +19,7 @@ test.serial('thread pool basics work and events are emitted', async (t) => {
15
19
 
16
20
  const spawnHelloWorld = () => {
17
21
  spawnCalled++
18
- return spawn<() => string>(new Worker('./workers/hello-world'))
22
+ return spawn<() => string>(new Worker(workerPath))
19
23
  }
20
24
  const pool = Pool(spawnHelloWorld, 3)
21
25
  pool.events().subscribe((event) => events.push(event))
@@ -32,7 +36,7 @@ test.serial('thread pool basics work and events are emitted', async (t) => {
32
36
  await pool.queue(async (helloWorld) => {
33
37
  taskFnCalled++
34
38
  const result = await helloWorld()
35
- t.is(result, 'Hello World')
39
+ t.is(result, HELLO_WORLD)
36
40
  return result
37
41
  })
38
42
 
@@ -55,7 +59,7 @@ test.serial('thread pool basics work and events are emitted', async (t) => {
55
59
  workerID: 1,
56
60
  },
57
61
  {
58
- returnValue: 'Hello World',
62
+ returnValue: HELLO_WORLD,
59
63
  taskID: 1,
60
64
  type: Pool.EventType.taskCompleted,
61
65
  workerID: 1,
@@ -73,7 +77,7 @@ test.serial('thread pool basics work and events are emitted', async (t) => {
73
77
  test.serial('pool.completed() works', async (t) => {
74
78
  const returned: any[] = []
75
79
 
76
- const spawnHelloWorld = () => spawn(new Worker('./workers/hello-world'))
80
+ const spawnHelloWorld = () => spawn(new Worker(workerPath))
77
81
  const pool = Pool(spawnHelloWorld, 2)
78
82
 
79
83
  for (let i = 0; i < 3; i++) {
@@ -84,11 +88,11 @@ test.serial('pool.completed() works', async (t) => {
84
88
 
85
89
  await pool.completed()
86
90
 
87
- t.deepEqual(returned, ['Hello World', 'Hello World', 'Hello World'])
91
+ t.deepEqual(returned, [HELLO_WORLD, HELLO_WORLD, HELLO_WORLD])
88
92
  })
89
93
 
90
94
  test.serial('pool.completed() proxies errors', async (t) => {
91
- const spawnHelloWorld = () => spawn(new Worker('./workers/hello-world'))
95
+ const spawnHelloWorld = () => spawn(new Worker(workerPath))
92
96
  const pool = Pool(spawnHelloWorld, 2)
93
97
 
94
98
  pool.queue(async () => {
@@ -100,7 +104,7 @@ test.serial('pool.completed() proxies errors', async (t) => {
100
104
  })
101
105
 
102
106
  test.serial('pool.completed(true) works', async (t) => {
103
- const spawnHelloWorld = () => spawn(new Worker('./workers/hello-world'))
107
+ const spawnHelloWorld = () => spawn(new Worker(workerPath))
104
108
  const pool = Pool(spawnHelloWorld, 2)
105
109
 
106
110
  await pool.completed(true)
@@ -108,9 +112,10 @@ test.serial('pool.completed(true) works', async (t) => {
108
112
  })
109
113
 
110
114
  test.serial('pool.settled() does not reject on task failure', async (t) => {
115
+ // eslint-disable-next-line sonarjs/no-unused-collection
111
116
  const returned: any[] = []
112
117
 
113
- const spawnHelloWorld = () => spawn(new Worker('./workers/hello-world'))
118
+ const spawnHelloWorld = () => spawn(new Worker(workerPath))
114
119
  const pool = Pool(spawnHelloWorld, 2)
115
120
 
116
121
  pool.queue(async (helloWorld) => {
@@ -129,7 +134,7 @@ test.serial('pool.settled() does not reject on task failure', async (t) => {
129
134
  })
130
135
 
131
136
  test.serial('pool.settled(true) works', async (t) => {
132
- const spawnHelloWorld = () => spawn(new Worker('./workers/hello-world'))
137
+ const spawnHelloWorld = () => spawn(new Worker(workerPath))
133
138
  const pool = Pool(spawnHelloWorld, 2)
134
139
 
135
140
  await pool.settled(true)
@@ -138,7 +143,7 @@ test.serial('pool.settled(true) works', async (t) => {
138
143
 
139
144
  test.serial('task.cancel() works', async (t) => {
140
145
  const events: Pool.Event[] = []
141
- const spawnHelloWorld = () => spawn(new Worker('./workers/hello-world'))
146
+ const spawnHelloWorld = () => spawn(new Worker(workerPath))
142
147
  const pool = Pool(spawnHelloWorld, 1)
143
148
 
144
149
  pool.events().subscribe((event) => events.push(event))
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  import test from 'ava'
2
3
 
3
4
  import { registerSerializer, spawn, Thread, Worker } from '../src/index'
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  /* eslint-disable no-restricted-imports */
2
3
  /*
3
4
  * This code here will be run in a headless Chromium browser using `puppet-run`.
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  /* eslint-disable @typescript-eslint/no-var-requires */
2
3
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
4
  import test from 'ava'
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  /* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
2
3
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
4
 
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  import { Observable, Subject } from '../../src/observable'
2
3
  import { expose } from '../../src/worker'
3
4
 
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  /* eslint-disable require-await */
2
3
 
3
4
  import { expose, registerSerializer } from '../../src/worker'
@@ -1,3 +1,4 @@
1
+ /* eslint-disable import/no-unresolved */
1
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
3
 
3
4
  /// <reference types="./raw-loader" />
@@ -1,3 +1,4 @@
1
+ /* eslint-disable sonarjs/no-use-of-empty-return-value */
1
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
3
 
3
4
  import { isWorkerRuntime, Pool, spawn, Worker } from '../../src/index'
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-var-requires */
2
1
  const path = require('node:path')
3
2
  const ThreadsPlugin = require('threads-plugin')
4
3
 
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-var-requires */
2
1
  const path = require('node:path')
3
2
  const ThreadsPlugin = require('threads-plugin')
4
3
 
package/worker.d.ts CHANGED
@@ -1 +1,2 @@
1
+ /* eslint-disable import/no-internal-modules */
1
2
  export * from './dist/worker/index'