thread-stream 2.6.0 → 2.7.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/lib/worker.js +3 -1
- package/package.json +4 -3
- package/test/pkg/index.js +37 -0
- package/test/pkg/pkg.config.json +15 -0
- package/test/pkg/pkg.test.js +44 -0
- package/.github/workflows/package-manager-ci.yml +0 -62
package/.github/workflows/ci.yml
CHANGED
|
@@ -38,11 +38,15 @@ jobs:
|
|
|
38
38
|
contents: read
|
|
39
39
|
strategy:
|
|
40
40
|
matrix:
|
|
41
|
-
node-version: [14, 16, 18]
|
|
41
|
+
node-version: [14, 16, 18, 20]
|
|
42
42
|
os: [macos-latest, ubuntu-latest, windows-latest]
|
|
43
43
|
exclude:
|
|
44
44
|
- os: windows-latest
|
|
45
45
|
node-version: 14
|
|
46
|
+
- os: macos-latest
|
|
47
|
+
node-version: 14
|
|
48
|
+
- os: macos-latest
|
|
49
|
+
node-version: 16
|
|
46
50
|
|
|
47
51
|
steps:
|
|
48
52
|
- 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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "thread-stream",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.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",
|
|
@@ -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,44 @@
|
|
|
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
|
+
const { stderr } = await exec(`npx pkg ${filePath} --config ${configPath}`)
|
|
18
|
+
|
|
19
|
+
// there should be no error when packaging
|
|
20
|
+
t.equal(stderr, '')
|
|
21
|
+
|
|
22
|
+
// pkg outputs files in the following format by default: {filename}-{node version}
|
|
23
|
+
for (const target of config.pkg.targets) {
|
|
24
|
+
// execute the packaged test
|
|
25
|
+
let executablePath = `${join(config.pkg.outputPath, packageName)}-${target}`
|
|
26
|
+
|
|
27
|
+
// when on windows, we need the .exe extension
|
|
28
|
+
if (platform === 'win32') {
|
|
29
|
+
executablePath = `${executablePath}.exe`
|
|
30
|
+
} else {
|
|
31
|
+
executablePath = `./${executablePath}`
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const { stderr } = await exec(executablePath)
|
|
35
|
+
|
|
36
|
+
// check if there were no errors
|
|
37
|
+
t.equal(stderr, '')
|
|
38
|
+
|
|
39
|
+
// clean up afterwards
|
|
40
|
+
await unlink(executablePath)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
t.end()
|
|
44
|
+
})
|
|
@@ -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'
|