Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const { version } = require('./package.json')
const { EventEmitter } = require('events')
const { Worker } = require('worker_threads')
const { join } = require('path')
const { pathToFileURL } = require('url')
const { wait } = require('./lib/wait')
const {
Expand All @@ -12,6 +11,7 @@ const {
} = require('./lib/indexes')
const buffer = require('buffer')
const assert = require('assert')
const { getWorkerPath } = require('./lib/workerLoader')

const kImpl = Symbol('kImpl')

Expand Down Expand Up @@ -52,7 +52,7 @@ function createWorker (stream, opts) {
const { filename, workerData } = opts

const bundlerOverrides = '__bundlerPathsOverrides' in globalThis ? globalThis.__bundlerPathsOverrides : {}
const toExecute = bundlerOverrides['thread-stream-worker'] || join(__dirname, 'lib', 'worker.js')
const toExecute = bundlerOverrides['thread-stream-worker'] || getWorkerPath()

const worker = new Worker(toExecute, {
...opts.workerOpts,
Expand Down
12 changes: 12 additions & 0 deletions lib/workerLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict'

const { isMainThread } = require('worker_threads')
Comment thread
mbrevda marked this conversation as resolved.

// Only runs when spawned as a Worker
if (!isMainThread) require('./worker.js')

function getWorkerPath () {
return __filename
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires a lot of explanation, can you add some comments?

Note that this value will be incorrect if we are not bundling.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this value will be incorrect if we are not bundling.

Not sure I follow - wouldn't it return the path of lib/workerLoader.js, which would then require ./worker.js?

Copy link
Copy Markdown
Author

@mbrevda mbrevda May 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed you commented here, but still not sure why this would be incorrect when not bundling?

}

module.exports = { getWorkerPath }
Loading