async-transforms
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -8,11 +8,11 @@ import worker from 'worker_threads'; | ||
*/ | ||
function scriptDir() { | ||
function getScriptContext() { | ||
try { | ||
const absolutePath = String(import.meta.url).replace(/^file:\/\//, ''); | ||
return path.dirname(absolutePath); | ||
return {dirname: __dirname, module: false}; | ||
} catch (e) { | ||
// try __dirname | ||
// We have to try __dirname first, as this way we can detect module mode correctly. | ||
} | ||
try { | ||
return __dirname; | ||
const absolutePath = String(import.meta.url).replace(/^file:\/\//, ''); | ||
return {dirname: path.dirname(absolutePath), module: true}; | ||
} catch (e) { | ||
@@ -23,4 +23,6 @@ throw new Error(`could not resolve __dirname or import.meta.url`); | ||
const {dirname: scriptDir, module: isModule} = getScriptContext(); | ||
const cpuCount = os.cpus().length || 4; | ||
const workerTarget = path.join(scriptDir(), './internal-worker.js'); | ||
const workerTarget = path.join(scriptDir, './internal-worker.' + (isModule ? 'js' : 'cjs')); | ||
@@ -59,3 +61,7 @@ export function pool(dep, options) { | ||
} else if (activeWorkers < options.tasks) { | ||
w = new worker.Worker(workerTarget, {workerData: {dep}}); | ||
// In commonJS mode, we have to _again_ require the script, as the Worker ctor incorrectly | ||
// only allows ".js" (run as modules because of `type: module`) or ".mjs" extensions. | ||
// This will probably be fixed in a future Node. Sounds like a bug. | ||
const code = isModule ? workerTarget : `require(${JSON.stringify(workerTarget)});`; | ||
w = new worker.Worker(code, {workerData: {dep}, eval: !isModule}); | ||
++activeWorkers; | ||
@@ -62,0 +68,0 @@ } else { |
{ | ||
"name": "async-transforms", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Asynchronous stream transforms", | ||
@@ -9,4 +9,6 @@ "type": "module", | ||
"exports": { | ||
"import": "./lib/transforms.js", | ||
"require": "./require/transforms.cjs", | ||
".": { | ||
"import": "./lib/transforms.js", | ||
"require": "./require/transforms.cjs" | ||
}, | ||
"./worker": { | ||
@@ -13,0 +15,0 @@ "import": "./lib/worker.js", |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
35815
10
623
0
4