@xylabs/threads 3.6.5 → 3.6.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/threads",
3
- "version": "3.6.5",
3
+ "version": "3.6.6",
4
4
  "description": "Web workers & worker threads as simple as a function call",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -83,9 +83,9 @@
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
  },
@@ -95,7 +95,7 @@
95
95
  "@types/chai": "^4.3.16",
96
96
  "@types/debug": "^4.1.12",
97
97
  "@types/execa": "^2.0.0",
98
- "@types/node": "^20.14.12",
98
+ "@types/node": "^22.0.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.1",
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"
@@ -1,3 +1,5 @@
1
+ /* eslint-disable unicorn/no-process-exit */
2
+ /* eslint-disable sonarjs/no-identical-functions */
1
3
  /* eslint-disable unicorn/prefer-logical-operator-over-ternary */
2
4
  /* eslint-disable unicorn/prefer-regexp-test */
3
5
  /* eslint-disable @typescript-eslint/no-var-requires */
@@ -5,7 +7,6 @@
5
7
  /* eslint-disable unicorn/prefer-event-target */
6
8
  /* eslint-disable @typescript-eslint/no-explicit-any */
7
9
  /* eslint-disable unicorn/text-encoding-identifier-case */
8
- /* eslint-disable unicorn/no-process-exit */
9
10
  /// <reference lib="dom" />
10
11
 
11
12
  import { EventEmitter } from 'node:events'
@@ -56,11 +57,10 @@ function detectTsNode() {
56
57
  }
57
58
 
58
59
  function createTsNodeModule(scriptPath: string) {
59
- const content = `
60
+ return `
60
61
  require("ts-node/register/transpile-only");
61
62
  require(${JSON.stringify(scriptPath)});
62
63
  `
63
- return content
64
64
  }
65
65
 
66
66
  function rebaseScriptPath(scriptPath: string, ignoreRegex: RegExp) {
@@ -76,9 +76,7 @@ function rebaseScriptPath(scriptPath: string, ignoreRegex: RegExp) {
76
76
  if (callerPath && callerPath.startsWith('file:')) {
77
77
  callerPath = fileURLToPath(callerPath)
78
78
  }
79
- const rebasedScriptPath = callerPath ? path.join(path.dirname(callerPath), scriptPath) : scriptPath
80
-
81
- return rebasedScriptPath
79
+ return callerPath ? path.join(path.dirname(callerPath), scriptPath) : scriptPath
82
80
  }
83
81
 
84
82
  function resolveScriptPath(scriptPath: string, baseURL?: string | undefined) {
@@ -87,12 +85,9 @@ function resolveScriptPath(scriptPath: string, baseURL?: string | undefined) {
87
85
  return path.isAbsolute(filePath) ? filePath : path.join(baseURL || eval('__dirname'), filePath)
88
86
  }
89
87
 
90
- const workerFilePath =
91
- typeof __non_webpack_require__ === 'function' ?
88
+ return typeof __non_webpack_require__ === 'function' ?
92
89
  __non_webpack_require__.resolve(makeRelative(scriptPath))
93
90
  : eval('require').resolve(makeRelative(rebaseScriptPath(scriptPath, /[/\\]worker_threads[/\\]/)))
94
-
95
- return workerFilePath
96
91
  }
97
92
 
98
93
  function initWorkerThreadsWorker(): ImplementationExport {
@@ -1,3 +1,4 @@
1
+ /* eslint-disable sonarjs/no-all-duplicated-branches */
1
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
3
  /*
3
4
  * 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 */
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 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 sonarjs/prefer-immediate-return */
1
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
3
  /// <reference lib="dom" />
3
4
  // tslint:disable no-shadowed-variable
@@ -1,3 +1,4 @@
1
+ /* eslint-disable sonarjs/no-duplicate-string */
1
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
3
  import test from 'ava'
3
4
  import { Observable } from 'observable-fns'
package/test/pool.test.ts CHANGED
@@ -8,6 +8,9 @@ import test from 'ava'
8
8
  import { Pool, spawn, Worker } from '../src/index'
9
9
  import { PoolEventType, QueuedTask } from '../src/master/pool'
10
10
 
11
+ const workerPath = './workers/hello-world'
12
+ const HELLO_WORLD = 'Hello World'
13
+
11
14
  test.serial('thread pool basics work and events are emitted', async (t) => {
12
15
  const events: Pool.Event[] = []
13
16
  let spawnCalled = 0
@@ -15,7 +18,7 @@ test.serial('thread pool basics work and events are emitted', async (t) => {
15
18
 
16
19
  const spawnHelloWorld = () => {
17
20
  spawnCalled++
18
- return spawn<() => string>(new Worker('./workers/hello-world'))
21
+ return spawn<() => string>(new Worker(workerPath))
19
22
  }
20
23
  const pool = Pool(spawnHelloWorld, 3)
21
24
  pool.events().subscribe((event) => events.push(event))
@@ -32,7 +35,7 @@ test.serial('thread pool basics work and events are emitted', async (t) => {
32
35
  await pool.queue(async (helloWorld) => {
33
36
  taskFnCalled++
34
37
  const result = await helloWorld()
35
- t.is(result, 'Hello World')
38
+ t.is(result, HELLO_WORLD)
36
39
  return result
37
40
  })
38
41
 
@@ -55,7 +58,7 @@ test.serial('thread pool basics work and events are emitted', async (t) => {
55
58
  workerID: 1,
56
59
  },
57
60
  {
58
- returnValue: 'Hello World',
61
+ returnValue: HELLO_WORLD,
59
62
  taskID: 1,
60
63
  type: Pool.EventType.taskCompleted,
61
64
  workerID: 1,
@@ -73,7 +76,7 @@ test.serial('thread pool basics work and events are emitted', async (t) => {
73
76
  test.serial('pool.completed() works', async (t) => {
74
77
  const returned: any[] = []
75
78
 
76
- const spawnHelloWorld = () => spawn(new Worker('./workers/hello-world'))
79
+ const spawnHelloWorld = () => spawn(new Worker(workerPath))
77
80
  const pool = Pool(spawnHelloWorld, 2)
78
81
 
79
82
  for (let i = 0; i < 3; i++) {
@@ -84,11 +87,11 @@ test.serial('pool.completed() works', async (t) => {
84
87
 
85
88
  await pool.completed()
86
89
 
87
- t.deepEqual(returned, ['Hello World', 'Hello World', 'Hello World'])
90
+ t.deepEqual(returned, [HELLO_WORLD, HELLO_WORLD, HELLO_WORLD])
88
91
  })
89
92
 
90
93
  test.serial('pool.completed() proxies errors', async (t) => {
91
- const spawnHelloWorld = () => spawn(new Worker('./workers/hello-world'))
94
+ const spawnHelloWorld = () => spawn(new Worker(workerPath))
92
95
  const pool = Pool(spawnHelloWorld, 2)
93
96
 
94
97
  pool.queue(async () => {
@@ -100,7 +103,7 @@ test.serial('pool.completed() proxies errors', async (t) => {
100
103
  })
101
104
 
102
105
  test.serial('pool.completed(true) works', async (t) => {
103
- const spawnHelloWorld = () => spawn(new Worker('./workers/hello-world'))
106
+ const spawnHelloWorld = () => spawn(new Worker(workerPath))
104
107
  const pool = Pool(spawnHelloWorld, 2)
105
108
 
106
109
  await pool.completed(true)
@@ -108,9 +111,10 @@ test.serial('pool.completed(true) works', async (t) => {
108
111
  })
109
112
 
110
113
  test.serial('pool.settled() does not reject on task failure', async (t) => {
114
+ // eslint-disable-next-line sonarjs/no-unused-collection
111
115
  const returned: any[] = []
112
116
 
113
- const spawnHelloWorld = () => spawn(new Worker('./workers/hello-world'))
117
+ const spawnHelloWorld = () => spawn(new Worker(workerPath))
114
118
  const pool = Pool(spawnHelloWorld, 2)
115
119
 
116
120
  pool.queue(async (helloWorld) => {
@@ -129,7 +133,7 @@ test.serial('pool.settled() does not reject on task failure', async (t) => {
129
133
  })
130
134
 
131
135
  test.serial('pool.settled(true) works', async (t) => {
132
- const spawnHelloWorld = () => spawn(new Worker('./workers/hello-world'))
136
+ const spawnHelloWorld = () => spawn(new Worker(workerPath))
133
137
  const pool = Pool(spawnHelloWorld, 2)
134
138
 
135
139
  await pool.settled(true)
@@ -138,7 +142,7 @@ test.serial('pool.settled(true) works', async (t) => {
138
142
 
139
143
  test.serial('task.cancel() works', async (t) => {
140
144
  const events: Pool.Event[] = []
141
- const spawnHelloWorld = () => spawn(new Worker('./workers/hello-world'))
145
+ const spawnHelloWorld = () => spawn(new Worker(workerPath))
142
146
  const pool = Pool(spawnHelloWorld, 1)
143
147
 
144
148
  pool.events().subscribe((event) => events.push(event))
@@ -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'