thread-stream 2.6.0 → 3.0.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.
package/.github/workflows/ci.yml
CHANGED
|
@@ -38,11 +38,11 @@ jobs:
|
|
|
38
38
|
contents: read
|
|
39
39
|
strategy:
|
|
40
40
|
matrix:
|
|
41
|
-
node-version: [
|
|
41
|
+
node-version: [18, 20, 22]
|
|
42
42
|
os: [macos-latest, ubuntu-latest, windows-latest]
|
|
43
43
|
exclude:
|
|
44
44
|
- os: windows-latest
|
|
45
|
-
node-version:
|
|
45
|
+
node-version: 22
|
|
46
46
|
|
|
47
47
|
steps:
|
|
48
48
|
- name: Check out repo
|
package/lib/worker.js
CHANGED
|
@@ -44,8 +44,10 @@ async function start () {
|
|
|
44
44
|
if ((error.code === 'ENOTDIR' || error.code === 'ERR_MODULE_NOT_FOUND') &&
|
|
45
45
|
filename.startsWith('file://')) {
|
|
46
46
|
worker = realRequire(decodeURIComponent(filename.replace('file://', '')))
|
|
47
|
-
} else if (error.code === undefined) {
|
|
47
|
+
} else if (error.code === undefined || error.code === 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING') {
|
|
48
48
|
// When bundled with pkg, an undefined error is thrown when called with realImport
|
|
49
|
+
// When bundled with pkg and using node v20, an ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING error is thrown when called with realImport
|
|
50
|
+
// More info at: https://github.com/pinojs/thread-stream/issues/143
|
|
49
51
|
worker = realRequire(decodeURIComponent(filename.replace(process.platform === 'win32' ? 'file:///' : 'file://', '')))
|
|
50
52
|
} else {
|
|
51
53
|
throw error
|
|
@@ -157,7 +159,6 @@ process.once('exit', exitCode => {
|
|
|
157
159
|
process.exit(exitCode)
|
|
158
160
|
return
|
|
159
161
|
}
|
|
160
|
-
|
|
161
162
|
if (destination?.writableNeedDrain && !destination?.writableEnded) {
|
|
162
163
|
parentPort.postMessage({
|
|
163
164
|
code: 'WARNING',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "thread-stream",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
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",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@types/node": "^20.1.0",
|
|
12
12
|
"@types/tap": "^15.0.0",
|
|
13
|
+
"@yao-pkg/pkg": "^5.11.5",
|
|
13
14
|
"desm": "^1.3.0",
|
|
14
15
|
"fastbench": "^1.0.1",
|
|
15
16
|
"husky": "^9.0.6",
|
|
@@ -22,9 +23,9 @@
|
|
|
22
23
|
"why-is-node-running": "^2.2.2"
|
|
23
24
|
},
|
|
24
25
|
"scripts": {
|
|
25
|
-
"test": "standard && npm run transpile && tap test
|
|
26
|
+
"test": "standard && npm run transpile && tap \"test/**/*.test.*js\" && tap --ts test/*.test.*ts",
|
|
26
27
|
"test:ci": "standard && npm run transpile && npm run test:ci:js && npm run test:ci:ts",
|
|
27
|
-
"test:ci:js": "tap --no-check-coverage --coverage-report=lcovonly \"test/**/*.test.*js\"",
|
|
28
|
+
"test:ci:js": "tap --no-check-coverage --timeout=120 --coverage-report=lcovonly \"test/**/*.test.*js\"",
|
|
28
29
|
"test:ci:ts": "tap --ts --no-check-coverage --coverage-report=lcovonly \"test/**/*.test.*ts\"",
|
|
29
30
|
"test:yarn": "npm run transpile && tap \"test/**/*.test.js\" --no-check-coverage",
|
|
30
31
|
"transpile": "sh ./test/ts/transpile.sh",
|
package/test/never-drain.test.js
CHANGED
|
@@ -22,7 +22,9 @@ function retryUntilTimeout (fn, timeout) {
|
|
|
22
22
|
})
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const isNode18 = process.version.indexOf('v18') === 0
|
|
26
|
+
|
|
27
|
+
test('emit warning when the worker gracefully exit without the stream ended', { skip: !isNode18 }, async function (t) {
|
|
26
28
|
const expectedWarning = 'ThreadStream: process exited before destination stream was drained. this may indicate that the destination stream try to write to a another missing stream'
|
|
27
29
|
const stream = new ThreadStream({
|
|
28
30
|
filename: join(__dirname, 'to-next.js')
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file is packaged using pkg in order to test if worker.js works in that context
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { test } = require('tap')
|
|
8
|
+
const { join } = require('path')
|
|
9
|
+
const { file } = require('../helper')
|
|
10
|
+
const ThreadStream = require('../..')
|
|
11
|
+
|
|
12
|
+
test('bundlers support with .js file', function (t) {
|
|
13
|
+
t.plan(1)
|
|
14
|
+
|
|
15
|
+
globalThis.__bundlerPathsOverrides = {
|
|
16
|
+
'thread-stream-worker': join(__dirname, '..', 'custom-worker.js')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const dest = file()
|
|
20
|
+
|
|
21
|
+
process.on('uncaughtException', (error) => {
|
|
22
|
+
console.log(error)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const stream = new ThreadStream({
|
|
26
|
+
filename: join(__dirname, '..', 'to-file.js'),
|
|
27
|
+
workerData: { dest },
|
|
28
|
+
sync: true
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
stream.worker.removeAllListeners('message')
|
|
32
|
+
stream.worker.once('message', (message) => {
|
|
33
|
+
t.equal(message.code, 'CUSTOM-WORKER-CALLED')
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
stream.end()
|
|
37
|
+
})
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('tap')
|
|
4
|
+
const config = require('./pkg.config.json')
|
|
5
|
+
const { promisify } = require('util')
|
|
6
|
+
const { unlink } = require('fs/promises')
|
|
7
|
+
const { join } = require('path')
|
|
8
|
+
const { platform } = require('process')
|
|
9
|
+
const exec = promisify(require('child_process').exec)
|
|
10
|
+
|
|
11
|
+
test('worker test when packaged into executable using pkg', async (t) => {
|
|
12
|
+
const packageName = 'index'
|
|
13
|
+
|
|
14
|
+
// package the app into several node versions, check config for more info
|
|
15
|
+
const filePath = `${join(__dirname, packageName)}.js`
|
|
16
|
+
const configPath = join(__dirname, 'pkg.config.json')
|
|
17
|
+
process.env.NODE_OPTIONS ||= ''
|
|
18
|
+
process.env.NODE_OPTIONS = '--no-warnings'
|
|
19
|
+
const { stderr } = await exec(`npx pkg ${filePath} --config ${configPath}`)
|
|
20
|
+
|
|
21
|
+
// there should be no error when packaging
|
|
22
|
+
t.equal(stderr, '')
|
|
23
|
+
|
|
24
|
+
// pkg outputs files in the following format by default: {filename}-{node version}
|
|
25
|
+
for (const target of config.pkg.targets) {
|
|
26
|
+
// execute the packaged test
|
|
27
|
+
let executablePath = `${join(config.pkg.outputPath, packageName)}-${target}`
|
|
28
|
+
|
|
29
|
+
// when on windows, we need the .exe extension
|
|
30
|
+
if (platform === 'win32') {
|
|
31
|
+
executablePath = `${executablePath}.exe`
|
|
32
|
+
} else {
|
|
33
|
+
executablePath = `./${executablePath}`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const { stderr } = await exec(executablePath)
|
|
37
|
+
|
|
38
|
+
// check if there were no errors
|
|
39
|
+
t.equal(stderr, '')
|
|
40
|
+
|
|
41
|
+
// clean up afterwards
|
|
42
|
+
await unlink(executablePath)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
t.end()
|
|
46
|
+
})
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
name: package-manager-ci
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
paths-ignore:
|
|
5
|
-
- 'docs/**'
|
|
6
|
-
- '*.md'
|
|
7
|
-
pull_request:
|
|
8
|
-
paths-ignore:
|
|
9
|
-
- 'docs/**'
|
|
10
|
-
- '*.md'
|
|
11
|
-
jobs:
|
|
12
|
-
pnpm:
|
|
13
|
-
name: pnpm package manager on ${{ matrix.node-version }} ${{ matrix.os }}
|
|
14
|
-
runs-on: ${{ matrix.os }}
|
|
15
|
-
strategy:
|
|
16
|
-
matrix:
|
|
17
|
-
os: [ubuntu-latest]
|
|
18
|
-
node-version: [14, 16, 18]
|
|
19
|
-
steps:
|
|
20
|
-
- uses: actions/checkout@v3
|
|
21
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
22
|
-
uses: actions/setup-node@v4
|
|
23
|
-
with:
|
|
24
|
-
node-version: ${{ matrix.node-version }}
|
|
25
|
-
- name: Use pnpm
|
|
26
|
-
uses: pnpm/action-setup@v3.0.0
|
|
27
|
-
with:
|
|
28
|
-
version: ^6.0.0
|
|
29
|
-
- name: Install dependancies
|
|
30
|
-
run: pnpm install
|
|
31
|
-
- name: Tests
|
|
32
|
-
shell: bash
|
|
33
|
-
run: pnpm run test:ci
|
|
34
|
-
|
|
35
|
-
yarn-pnp:
|
|
36
|
-
name: yarn-pnp package manager on ${{ matrix.node-version }} ${{ matrix.os }}
|
|
37
|
-
runs-on: ${{ matrix.os }}
|
|
38
|
-
strategy:
|
|
39
|
-
matrix:
|
|
40
|
-
os: [ubuntu-latest]
|
|
41
|
-
node-version: [14, 16, 18]
|
|
42
|
-
steps:
|
|
43
|
-
- uses: actions/checkout@v3
|
|
44
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
45
|
-
uses: actions/setup-node@v4
|
|
46
|
-
with:
|
|
47
|
-
node-version: ${{ matrix.node-version }}
|
|
48
|
-
- name: Use yarn
|
|
49
|
-
run: |
|
|
50
|
-
npm install -g yarn
|
|
51
|
-
yarn set version berry
|
|
52
|
-
cat test/yarnrc.yml >> .yarnrc.yml
|
|
53
|
-
yarn add -D pino-elasticsearch@^6.0.0
|
|
54
|
-
yarn install
|
|
55
|
-
env:
|
|
56
|
-
# needed due the yarn.lock file in repository's .gitignore
|
|
57
|
-
YARN_ENABLE_IMMUTABLE_INSTALLS: 'false'
|
|
58
|
-
- name: Tests
|
|
59
|
-
shell: bash
|
|
60
|
-
run: yarn run test:yarn
|
|
61
|
-
env:
|
|
62
|
-
SKIP_PROCESS_EXIT_CHECK: 'true'
|