thread-stream
Advanced tools
Comparing version 0.11.0 to 0.11.1
@@ -18,3 +18,21 @@ 'use strict' | ||
async function start () { | ||
const fn = (await import(workerData.filename)).default | ||
let fn | ||
try { | ||
fn = (await import(workerData.filename)).default | ||
} catch (error) { | ||
// A yarn user that tries to start a ThreadStream for an external module | ||
// provides a filename pointing to a zip file. | ||
// eg. require.resolve('pino-elasticsearch') // returns /foo/pino-elasticsearch-npm-6.1.0-0c03079478-6915435172.zip/bar.js | ||
// The `import` will fail to try to load it. | ||
// This catch block executes the `require` fallback to load the module correctly. | ||
// In fact, yarn modifies the `require` function to manage the zipped path. | ||
// More details at https://github.com/pinojs/pino/pull/1113 | ||
// The error codes may change based on the node.js version (ENOTDIR > 12, ERR_MODULE_NOT_FOUND <= 12 ) | ||
if ((error.code === 'ENOTDIR' || error.code === 'ERR_MODULE_NOT_FOUND') && | ||
workerData.filename.startsWith('file://')) { | ||
fn = require(workerData.filename.replace('file://', '')) | ||
} else { | ||
throw error | ||
} | ||
} | ||
destination = await fn(workerData.workerData) | ||
@@ -21,0 +39,0 @@ |
{ | ||
"name": "thread-stream", | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"description": "A streaming way to send data to a Node.js Worker Thread", | ||
@@ -17,2 +17,3 @@ "main": "index.js", | ||
"test:ci": "standard && tap \"test/**/*.test.*js\" --no-check-coverage --coverage-report=lcovonly", | ||
"test:yarn": "tap \"test/**/*.test.js\" --no-check-coverage", | ||
"prepare": "husky install" | ||
@@ -19,0 +20,0 @@ }, |
@@ -67,4 +67,26 @@ # thread-stream | ||
### External modules | ||
You may use this module within compatible external modules, that exports the `worker.js` interface. | ||
```js | ||
const ThreadStream = require('thread-stream') | ||
const modulePath = require.resolve('pino-elasticsearch') | ||
const stream = new ThreadStream({ | ||
filename: modulePath, | ||
workerData: { node: 'http://localhost:9200' } | ||
}) | ||
stream.write('log to elasticsearch!') | ||
stream.flushSync() | ||
stream.end() | ||
``` | ||
This module works with `yarn` in PnP (plug'n play) mode too! | ||
## License | ||
MIT |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44979
32
1402
92
12