thread-stream 2.2.0 → 2.4.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 +5 -1
- package/.github/workflows/package-manager-ci.yml +9 -9
- package/bench.js +1 -1
- package/index.js +4 -0
- package/lib/worker.js +16 -0
- package/package.json +8 -3
- package/test/event.test.js +1 -2
- package/test/helper.js +4 -2
- package/test/never-drain.test.js +55 -0
- package/test/to-next.js +9 -0
- package/test/ts/transpile.sh +7 -7
- package/test/yarnrc.yml +7 -0
package/.github/workflows/ci.yml
CHANGED
|
@@ -29,7 +29,7 @@ jobs:
|
|
|
29
29
|
persist-credentials: false
|
|
30
30
|
|
|
31
31
|
- name: Dependency review
|
|
32
|
-
uses: actions/dependency-review-action@
|
|
32
|
+
uses: actions/dependency-review-action@v3
|
|
33
33
|
|
|
34
34
|
test:
|
|
35
35
|
name: Test
|
|
@@ -40,6 +40,10 @@ jobs:
|
|
|
40
40
|
matrix:
|
|
41
41
|
node-version: [14, 16, 18]
|
|
42
42
|
os: [macos-latest, ubuntu-latest, windows-latest]
|
|
43
|
+
exclude:
|
|
44
|
+
- os: windows-latest
|
|
45
|
+
node-version: 14
|
|
46
|
+
|
|
43
47
|
steps:
|
|
44
48
|
- name: Check out repo
|
|
45
49
|
uses: actions/checkout@v3
|
|
@@ -2,12 +2,12 @@ name: package-manager-ci
|
|
|
2
2
|
on:
|
|
3
3
|
push:
|
|
4
4
|
paths-ignore:
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
- 'docs/**'
|
|
6
|
+
- '*.md'
|
|
7
7
|
pull_request:
|
|
8
8
|
paths-ignore:
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
- 'docs/**'
|
|
10
|
+
- '*.md'
|
|
11
11
|
jobs:
|
|
12
12
|
pnpm:
|
|
13
13
|
name: pnpm package manager on ${{ matrix.node-version }} ${{ matrix.os }}
|
|
@@ -23,7 +23,7 @@ jobs:
|
|
|
23
23
|
with:
|
|
24
24
|
node-version: ${{ matrix.node-version }}
|
|
25
25
|
- name: Use pnpm
|
|
26
|
-
uses: pnpm/action-setup@v2.2.
|
|
26
|
+
uses: pnpm/action-setup@v2.2.4
|
|
27
27
|
with:
|
|
28
28
|
version: ^6.0.0
|
|
29
29
|
- name: Install dependancies
|
|
@@ -49,14 +49,14 @@ jobs:
|
|
|
49
49
|
run: |
|
|
50
50
|
npm install -g yarn
|
|
51
51
|
yarn set version berry
|
|
52
|
-
|
|
53
|
-
echo "pnpMode: loose" >> .yarnrc.yml
|
|
54
|
-
echo "pnpEnableEsmLoader: false" >> .yarnrc.yml
|
|
52
|
+
cat test/yarnrc.yml >> .yarnrc.yml
|
|
55
53
|
yarn add -D pino-elasticsearch@^6.0.0
|
|
56
54
|
yarn install
|
|
57
55
|
env:
|
|
58
56
|
# needed due the yarn.lock file in repository's .gitignore
|
|
59
|
-
YARN_ENABLE_IMMUTABLE_INSTALLS: false
|
|
57
|
+
YARN_ENABLE_IMMUTABLE_INSTALLS: 'false'
|
|
60
58
|
- name: Tests
|
|
61
59
|
shell: bash
|
|
62
60
|
run: yarn run test:yarn
|
|
61
|
+
env:
|
|
62
|
+
SKIP_PROCESS_EXIT_CHECK: 'true'
|
package/bench.js
CHANGED
package/index.js
CHANGED
|
@@ -51,6 +51,7 @@ function createWorker (stream, opts) {
|
|
|
51
51
|
|
|
52
52
|
const worker = new Worker(toExecute, {
|
|
53
53
|
...opts.workerOpts,
|
|
54
|
+
trackUnmanagedFds: false,
|
|
54
55
|
workerData: {
|
|
55
56
|
filename: filename.indexOf('file://') === 0
|
|
56
57
|
? filename
|
|
@@ -177,6 +178,9 @@ function onWorkerMessage (msg) {
|
|
|
177
178
|
stream.emit(msg.name, msg.args)
|
|
178
179
|
}
|
|
179
180
|
break
|
|
181
|
+
case 'WARNING':
|
|
182
|
+
process.emitWarning(msg.err)
|
|
183
|
+
break
|
|
180
184
|
default:
|
|
181
185
|
destroy(stream, new Error('this should not happen: ' + msg.code))
|
|
182
186
|
}
|
package/lib/worker.js
CHANGED
|
@@ -151,3 +151,19 @@ process.on('uncaughtException', function (err) {
|
|
|
151
151
|
})
|
|
152
152
|
process.exit(1)
|
|
153
153
|
})
|
|
154
|
+
|
|
155
|
+
process.once('exit', exitCode => {
|
|
156
|
+
if (exitCode !== 0) {
|
|
157
|
+
process.exit(exitCode)
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (destination?.writableNeedDrain && !destination?.writableEnded) {
|
|
162
|
+
parentPort.postMessage({
|
|
163
|
+
code: 'WARNING',
|
|
164
|
+
err: new Error('ThreadStream: process exited before destination stream was drained. this may indicate that the destination stream try to write to a another missing stream')
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
process.exit(0)
|
|
169
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "thread-stream",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.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",
|
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
"real-require": "^0.2.0"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@types/node": "^
|
|
11
|
+
"@types/node": "^20.1.0",
|
|
12
12
|
"@types/tap": "^15.0.0",
|
|
13
13
|
"desm": "^1.3.0",
|
|
14
14
|
"fastbench": "^1.0.1",
|
|
15
15
|
"husky": "^8.0.1",
|
|
16
|
+
"pino-elasticsearch": "^6.0.0",
|
|
16
17
|
"sonic-boom": "^3.0.0",
|
|
17
18
|
"standard": "^17.0.0",
|
|
18
19
|
"tap": "^16.2.0",
|
|
@@ -29,7 +30,11 @@
|
|
|
29
30
|
"transpile": "sh ./test/ts/transpile.sh",
|
|
30
31
|
"prepare": "husky install"
|
|
31
32
|
},
|
|
32
|
-
"standard": {
|
|
33
|
+
"standard": {
|
|
34
|
+
"ignore": [
|
|
35
|
+
"test/ts/**/*"
|
|
36
|
+
]
|
|
37
|
+
},
|
|
33
38
|
"repository": {
|
|
34
39
|
"type": "git",
|
|
35
40
|
"url": "git+https://github.com/mcollina/thread-stream.git"
|
package/test/event.test.js
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
const { test } = require('tap')
|
|
4
4
|
const { join } = require('path')
|
|
5
5
|
const ThreadStream = require('..')
|
|
6
|
-
require('why-is-node-running')
|
|
7
6
|
|
|
8
|
-
test('event propagate',
|
|
7
|
+
test('event propagate', t => {
|
|
9
8
|
const stream = new ThreadStream({
|
|
10
9
|
filename: join(__dirname, 'emit-event.js'),
|
|
11
10
|
workerData: {},
|
package/test/helper.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
const { join } = require('path')
|
|
4
4
|
const { tmpdir } = require('os')
|
|
5
5
|
const { unlinkSync } = require('fs')
|
|
6
|
-
const why = require('why-is-node-running')
|
|
7
6
|
const t = require('tap')
|
|
8
7
|
|
|
9
8
|
const files = []
|
|
@@ -30,4 +29,7 @@ process.on('beforeExit', () => {
|
|
|
30
29
|
|
|
31
30
|
module.exports.file = file
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
if (process.env.SKIP_PROCESS_EXIT_CHECK !== 'true') {
|
|
33
|
+
const why = require('why-is-node-running')
|
|
34
|
+
setInterval(why, 10000).unref()
|
|
35
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const { test } = require('tap')
|
|
2
|
+
const ThreadStream = require('../index')
|
|
3
|
+
const { join } = require('path')
|
|
4
|
+
|
|
5
|
+
function retryUntilTimeout (fn, timeout) {
|
|
6
|
+
const start = Date.now()
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
async function run () {
|
|
9
|
+
if (fn()) {
|
|
10
|
+
resolve()
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (Date.now() - start >= timeout) {
|
|
15
|
+
reject(new Error('timeout'))
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
setTimeout(run, 10)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
run()
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
test('emit warning when the worker gracefully exit without the stream ended', async function (t) {
|
|
26
|
+
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
|
+
const stream = new ThreadStream({
|
|
28
|
+
filename: join(__dirname, 'to-next.js')
|
|
29
|
+
})
|
|
30
|
+
stream.unref()
|
|
31
|
+
|
|
32
|
+
let streamWarning
|
|
33
|
+
function saveWarning (e) {
|
|
34
|
+
if (e.message === expectedWarning) {
|
|
35
|
+
streamWarning = e
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
process.on('warning', saveWarning)
|
|
39
|
+
|
|
40
|
+
const data = 'hello'.repeat(10)
|
|
41
|
+
for (let i = 0; i < 1000; i++) {
|
|
42
|
+
if (streamWarning?.message === expectedWarning) {
|
|
43
|
+
break
|
|
44
|
+
}
|
|
45
|
+
stream.write(data)
|
|
46
|
+
await new Promise((resolve) => {
|
|
47
|
+
setTimeout(resolve, 1)
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
process.off('warning', saveWarning)
|
|
52
|
+
t.equal(streamWarning?.message, expectedWarning)
|
|
53
|
+
|
|
54
|
+
await retryUntilTimeout(() => stream.worker.exited === true, 3000)
|
|
55
|
+
})
|
package/test/to-next.js
ADDED
package/test/ts/transpile.sh
CHANGED
|
@@ -10,10 +10,10 @@ else
|
|
|
10
10
|
export RUNNER="npx";
|
|
11
11
|
fi
|
|
12
12
|
|
|
13
|
-
test ./to-file.ts -ot ./to-file.es5.cjs || ("${RUNNER}" tsc --target es5 ./to-file.ts && mv ./to-file.js ./to-file.es5.cjs);
|
|
14
|
-
test ./to-file.ts -ot ./to-file.es6.mjs || ("${RUNNER}" tsc --target es6 ./to-file.ts && mv ./to-file.js ./to-file.es6.mjs);
|
|
15
|
-
test ./to-file.ts -ot ./to-file.es6.cjs || ("${RUNNER}" tsc --target es6 --module commonjs ./to-file.ts && mv ./to-file.js ./to-file.es6.cjs);
|
|
16
|
-
test ./to-file.ts -ot ./to-file.es2017.mjs || ("${RUNNER}" tsc --target es2017 ./to-file.ts && mv ./to-file.js ./to-file.es2017.mjs);
|
|
17
|
-
test ./to-file.ts -ot ./to-file.es2017.cjs || ("${RUNNER}" tsc --target es2017 --module commonjs ./to-file.ts && mv ./to-file.js ./to-file.es2017.cjs);
|
|
18
|
-
test ./to-file.ts -ot ./to-file.esnext.mjs || ("${RUNNER}" tsc --target esnext --module esnext ./to-file.ts && mv ./to-file.js ./to-file.esnext.mjs);
|
|
19
|
-
test ./to-file.ts -ot ./to-file.esnext.cjs || ("${RUNNER}" tsc --target esnext --module commonjs ./to-file.ts && mv ./to-file.js ./to-file.esnext.cjs);
|
|
13
|
+
test ./to-file.ts -ot ./to-file.es5.cjs || ("${RUNNER}" tsc --skipLibCheck --target es5 ./to-file.ts && mv ./to-file.js ./to-file.es5.cjs);
|
|
14
|
+
test ./to-file.ts -ot ./to-file.es6.mjs || ("${RUNNER}" tsc --skipLibCheck --target es6 ./to-file.ts && mv ./to-file.js ./to-file.es6.mjs);
|
|
15
|
+
test ./to-file.ts -ot ./to-file.es6.cjs || ("${RUNNER}" tsc --skipLibCheck --target es6 --module commonjs ./to-file.ts && mv ./to-file.js ./to-file.es6.cjs);
|
|
16
|
+
test ./to-file.ts -ot ./to-file.es2017.mjs || ("${RUNNER}" tsc --skipLibCheck --target es2017 ./to-file.ts && mv ./to-file.js ./to-file.es2017.mjs);
|
|
17
|
+
test ./to-file.ts -ot ./to-file.es2017.cjs || ("${RUNNER}" tsc --skipLibCheck --target es2017 --module commonjs ./to-file.ts && mv ./to-file.js ./to-file.es2017.cjs);
|
|
18
|
+
test ./to-file.ts -ot ./to-file.esnext.mjs || ("${RUNNER}" tsc --skipLibCheck --target esnext --module esnext ./to-file.ts && mv ./to-file.js ./to-file.esnext.mjs);
|
|
19
|
+
test ./to-file.ts -ot ./to-file.esnext.cjs || ("${RUNNER}" tsc --skipLibCheck --target esnext --module commonjs ./to-file.ts && mv ./to-file.js ./to-file.esnext.cjs);
|