thread-stream 2.0.0 → 2.0.1
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/lib/worker.js +3 -0
- package/package.json +2 -2
- package/test/bundlers.test.js +28 -1
package/lib/worker.js
CHANGED
|
@@ -44,6 +44,9 @@ async function start () {
|
|
|
44
44
|
if ((error.code === 'ENOTDIR' || error.code === 'ERR_MODULE_NOT_FOUND') &&
|
|
45
45
|
filename.startsWith('file://')) {
|
|
46
46
|
fn = realRequire(decodeURIComponent(filename.replace('file://', '')))
|
|
47
|
+
} else if (error.code === undefined) {
|
|
48
|
+
// When bundled with pkg, an undefined error is thrown when called with realImport
|
|
49
|
+
fn = realRequire(decodeURIComponent(filename.replace(process.platform === 'win32' ? 'file:///' : 'file://', '')))
|
|
47
50
|
} else {
|
|
48
51
|
throw error
|
|
49
52
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "thread-stream",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A streaming way to send data to a Node.js Worker Thread",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"real-require": "^0.
|
|
8
|
+
"real-require": "^0.2.0"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@types/node": "^18.0.0",
|
package/test/bundlers.test.js
CHANGED
|
@@ -5,7 +5,7 @@ const { join } = require('path')
|
|
|
5
5
|
const { file } = require('./helper')
|
|
6
6
|
const ThreadStream = require('..')
|
|
7
7
|
|
|
8
|
-
test('bundlers support', function (t) {
|
|
8
|
+
test('bundlers support with .js file', function (t) {
|
|
9
9
|
t.plan(1)
|
|
10
10
|
|
|
11
11
|
globalThis.__bundlerPathsOverrides = {
|
|
@@ -31,3 +31,30 @@ test('bundlers support', function (t) {
|
|
|
31
31
|
|
|
32
32
|
stream.end()
|
|
33
33
|
})
|
|
34
|
+
|
|
35
|
+
test('bundlers support with .mjs file', function (t) {
|
|
36
|
+
t.plan(1)
|
|
37
|
+
|
|
38
|
+
globalThis.__bundlerPathsOverrides = {
|
|
39
|
+
'thread-stream-worker': join(__dirname, 'custom-worker.js')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const dest = file()
|
|
43
|
+
|
|
44
|
+
process.on('uncaughtException', error => {
|
|
45
|
+
console.log(error)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const stream = new ThreadStream({
|
|
49
|
+
filename: join(__dirname, 'to-file.mjs'),
|
|
50
|
+
workerData: { dest },
|
|
51
|
+
sync: true
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
stream.worker.removeAllListeners('message')
|
|
55
|
+
stream.worker.once('message', message => {
|
|
56
|
+
t.equal(message.code, 'CUSTOM-WORKER-CALLED')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
stream.end()
|
|
60
|
+
})
|