thread-stream 0.15.1 → 1.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.
@@ -1,4 +1,5 @@
1
1
  name: CI
2
+
2
3
  on:
3
4
  push:
4
5
  paths-ignore:
@@ -8,32 +9,53 @@ on:
8
9
  paths-ignore:
9
10
  - 'docs/**'
10
11
  - '*.md'
12
+
13
+ # This allows a subsequently queued workflow run to interrupt previous runs
14
+ concurrency:
15
+ group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
16
+ cancel-in-progress: true
17
+
11
18
  jobs:
19
+ dependency-review:
20
+ name: Dependency Review
21
+ if: github.event_name == 'pull_request'
22
+ runs-on: ubuntu-latest
23
+ permissions:
24
+ contents: read
25
+ steps:
26
+ - name: Check out repo
27
+ uses: actions/checkout@v3
28
+ with:
29
+ persist-credentials: false
30
+
31
+ - name: Dependency review
32
+ uses: actions/dependency-review-action@v1
33
+
12
34
  test:
35
+ name: Test
13
36
  runs-on: ${{ matrix.os }}
14
-
37
+ permissions:
38
+ contents: read
15
39
  strategy:
16
40
  matrix:
17
- node-version: [12, 14, 16]
41
+ node-version: [14, 16, 18]
18
42
  os: [macos-latest, ubuntu-latest, windows-latest]
19
-
20
43
  steps:
44
+ - name: Check out repo
45
+ uses: actions/checkout@v3
46
+ with:
47
+ persist-credentials: false
21
48
 
22
- - uses: actions/checkout@v3
23
-
24
- - name: Use Node.js
49
+ - name: Setup Node ${{ matrix.node-version }}
25
50
  uses: actions/setup-node@v3
26
51
  with:
27
52
  node-version: ${{ matrix.node-version }}
28
53
 
29
- - name: Install
30
- run: |
31
- npm install --ignore-scripts
54
+ - name: Install dependencies
55
+ run: npm i --ignore-scripts
32
56
 
33
57
  - name: Run tests
34
- shell: bash
35
- run: |
36
- npm run test:ci
58
+ run: npm run test:ci
37
59
 
38
60
  - name: Coveralls Parallel
39
61
  uses: coverallsapp/github-action@1.1.3
@@ -53,9 +75,16 @@ jobs:
53
75
  parallel-finished: true
54
76
 
55
77
  automerge:
78
+ name: Automerge Dependabot PRs
79
+ if: >
80
+ github.event_name == 'pull_request' &&
81
+ github.event.pull_request.user.login == 'dependabot[bot]'
56
82
  needs: test
83
+ permissions:
84
+ pull-requests: write
85
+ contents: write
57
86
  runs-on: ubuntu-latest
58
87
  steps:
59
- - uses: fastify/github-action-merge-dependabot@v3.0.2
88
+ - uses: fastify/github-action-merge-dependabot@v3
60
89
  with:
61
90
  github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -15,7 +15,7 @@ jobs:
15
15
  strategy:
16
16
  matrix:
17
17
  os: [macOS-latest, windows-latest]
18
- node-version: [12, 14, 16]
18
+ node-version: [14, 16, 18]
19
19
  steps:
20
20
  - uses: actions/checkout@v3
21
21
  - name: Use Node.js ${{ matrix.node-version }}
@@ -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.1
26
+ uses: pnpm/action-setup@v2.2.2
27
27
  with:
28
28
  version: ^6.0.0
29
29
  - name: Install dependancies
@@ -38,7 +38,7 @@ jobs:
38
38
  strategy:
39
39
  matrix:
40
40
  os: [macOS-latest]
41
- node-version: [12, 14, 16]
41
+ node-version: [14, 16, 18]
42
42
  steps:
43
43
  - uses: actions/checkout@v3
44
44
  - name: Use Node.js ${{ matrix.node-version }}
@@ -51,6 +51,7 @@ jobs:
51
51
  yarn set version berry
52
52
  echo "nodeLinker: pnp" >> .yarnrc.yml
53
53
  echo "pnpMode: loose" >> .yarnrc.yml
54
+ echo "pnpEnableEsmLoader: false" >> .yarnrc.yml
54
55
  yarn add -D pino-elasticsearch@^6.0.0
55
56
  yarn install
56
57
  env:
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # thread-stream
2
2
  [![npm version](https://img.shields.io/npm/v/thread-stream)](https://www.npmjs.com/package/thread-stream)
3
3
  [![Build Status](https://img.shields.io/github/workflow/status/pinojs/thread-stream/CI)](https://github.com/pinojs/thread-stream/actions)
4
- [![Known Vulnerabilities](https://snyk.io/test/github/pinojs/thread-stream/badge.svg)](https://snyk.io/test/github/pinojs/thread-stream)
5
4
  [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
6
5
 
7
6
  A streaming way to send data to a Node.js Worker Thread.
package/lib/worker.js CHANGED
@@ -19,25 +19,19 @@ const data = Buffer.from(dataBuf)
19
19
  async function start () {
20
20
  let fn
21
21
  try {
22
- // TODO: fix loading .ts files in Windows. See: ../test/ts.test.ts
23
22
  if (filename.endsWith('.ts') || filename.endsWith('.cts')) {
24
23
  // TODO: add support for the TSM modules loader ( https://github.com/lukeed/tsm ).
25
- if (process[Symbol.for('ts-node.register.instance')]) {
24
+ if (!process[Symbol.for('ts-node.register.instance')]) {
26
25
  realRequire('ts-node/register')
27
26
  } else if (process.env.TS_NODE_DEV) {
28
27
  realRequire('ts-node-dev')
29
28
  }
30
29
  // TODO: Support ES imports once tsc, tap & ts-node provide better compatibility guarantees.
31
- fn = realRequire(decodeURIComponent(filename.replace('file://', '')))
30
+ // Remove extra forwardslash on Windows
31
+ fn = realRequire(decodeURIComponent(filename.replace(process.platform === 'win32' ? 'file:///' : 'file://', '')))
32
32
  } else {
33
33
  fn = (await realImport(filename))
34
34
  }
35
-
36
- // Depending on how the default export is performed, and on how the code is
37
- // transpiled, we may find cases of two nested "default" objects.
38
- // See https://github.com/pinojs/pino/issues/1243#issuecomment-982774762
39
- if (typeof fn === 'object') fn = fn.default
40
- if (typeof fn === 'object') fn = fn.default
41
35
  } catch (error) {
42
36
  // A yarn user that tries to start a ThreadStream for an external module
43
37
  // provides a filename pointing to a zip file.
@@ -54,6 +48,13 @@ async function start () {
54
48
  throw error
55
49
  }
56
50
  }
51
+
52
+ // Depending on how the default export is performed, and on how the code is
53
+ // transpiled, we may find cases of two nested "default" objects.
54
+ // See https://github.com/pinojs/pino/issues/1243#issuecomment-982774762
55
+ if (typeof fn === 'object') fn = fn.default
56
+ if (typeof fn === 'object') fn = fn.default
57
+
57
58
  destination = await fn(workerData.workerData)
58
59
 
59
60
  destination.on('error', function (err) {
package/package.json CHANGED
@@ -1,23 +1,24 @@
1
1
  {
2
2
  "name": "thread-stream",
3
- "version": "0.15.1",
3
+ "version": "1.0.1",
4
4
  "description": "A streaming way to send data to a Node.js Worker Thread",
5
5
  "main": "index.js",
6
+ "types": "index.d.ts",
6
7
  "dependencies": {
7
8
  "real-require": "^0.1.0"
8
9
  },
9
10
  "devDependencies": {
10
- "@types/node": "^12.0.0",
11
+ "@types/node": "^18.0.0",
11
12
  "@types/tap": "^15.0.0",
12
- "desm": "^1.1.0",
13
+ "desm": "^1.3.0",
13
14
  "fastbench": "^1.0.1",
14
- "husky": "^7.0.0",
15
- "sonic-boom": "^2.0.1",
16
- "standard": "^16.0.3",
17
- "tap": "^16.0.0",
18
- "ts-node": "^10.7.0",
19
- "typescript": "^4.6.0",
20
- "why-is-node-running": "^2.2.0"
15
+ "husky": "^8.0.1",
16
+ "sonic-boom": "^3.0.0",
17
+ "standard": "^17.0.0",
18
+ "tap": "^16.2.0",
19
+ "ts-node": "^10.8.0",
20
+ "typescript": "^4.7.2",
21
+ "why-is-node-running": "^2.2.2"
21
22
  },
22
23
  "scripts": {
23
24
  "test": "standard && npm run transpile && tap test/*.test.*js && tap --ts test/*.test.*ts",
@@ -54,3 +54,27 @@ test('yarn module resolution for directories with special characters', { skip: !
54
54
 
55
55
  t.equal(strings, 'hello world\nsomething else\n')
56
56
  })
57
+
58
+ test('yarn module resolution for typescript commonjs modules', { skip: !isYarnPnp }, async t => {
59
+ t.plan(3)
60
+
61
+ const { port1, port2 } = new MessageChannel()
62
+ const stream = new ThreadStream({
63
+ filename: join(__dirname, 'ts-commonjs-default-export.zip', 'worker.js'),
64
+ workerData: { port: port1 },
65
+ workerOpts: {
66
+ transferList: [port1]
67
+ },
68
+ sync: false
69
+ })
70
+ t.teardown(() => {
71
+ stream.end()
72
+ })
73
+
74
+ t.ok(stream.write('hello world\n'))
75
+ t.ok(stream.write('something else\n'))
76
+
77
+ const [strings] = await once(port2, 'message')
78
+
79
+ t.equal(strings, 'hello world\nsomething else\n')
80
+ })
package/test/ts.test.ts CHANGED
@@ -6,12 +6,6 @@ import { file } from './helper.js'
6
6
 
7
7
 
8
8
  test('typescript module', function (t) {
9
- if (process.platform === 'win32') {
10
- // TODO: Implement .ts files loading support for Windows
11
- t.plan(0)
12
- return
13
- }
14
-
15
9
  t.plan(5)
16
10
 
17
11
  const dest = file()