Comparing version 1.3.1 to 1.4.0-error-reporting-fix
@@ -1,2 +0,2 @@ | ||
// tslint:disable function-constructor no-eval max-classes-per-file | ||
// tslint:disable function-constructor no-eval no-duplicate-super max-classes-per-file | ||
import getCallsites from "callsites"; | ||
@@ -41,3 +41,6 @@ import EventEmitter from "events"; | ||
const filename = callsite.getFileName(); | ||
return Boolean(filename && !filename.match(ignoreRegex) && !filename.match(/[\/\\]master[\/\\]implementation/)); | ||
return Boolean(filename && | ||
!filename.match(ignoreRegex) && | ||
!filename.match(/[\/\\]master[\/\\]implementation/) && | ||
!filename.match(/^internal\/process/)); | ||
}); | ||
@@ -48,7 +51,10 @@ const callerPath = parentCallSite ? parentCallSite.getFileName() : null; | ||
} | ||
function resolveScriptPath(scriptPath) { | ||
// eval() hack is also webpack-related | ||
function resolveScriptPath(scriptPath, baseURL) { | ||
const makeRelative = (filePath) => { | ||
// eval() hack is also webpack-related | ||
return path.isAbsolute(filePath) ? filePath : path.join(baseURL || eval("__dirname"), filePath); | ||
}; | ||
const workerFilePath = typeof __non_webpack_require__ === "function" | ||
? __non_webpack_require__.resolve(path.join(eval("__dirname"), scriptPath)) | ||
: require.resolve(rebaseScriptPath(scriptPath, /[\/\\]worker_threads[\/\\]/)); | ||
? __non_webpack_require__.resolve(makeRelative(scriptPath)) | ||
: require.resolve(makeRelative(rebaseScriptPath(scriptPath, /[\/\\]worker_threads[\/\\]/))); | ||
return workerFilePath; | ||
@@ -64,6 +70,15 @@ } | ||
constructor(scriptPath, options) { | ||
const resolvedScriptPath = resolveScriptPath(scriptPath); | ||
const resolvedScriptPath = resolveScriptPath(scriptPath, (options || {})._baseURL); | ||
if (resolvedScriptPath.match(/\.tsx?$/i) && detectTsNode()) { | ||
super(createTsNodeModule(resolvedScriptPath), { eval: true }); | ||
super(createTsNodeModule(resolvedScriptPath), Object.assign(Object.assign({}, options), { eval: true })); | ||
} | ||
else if (resolvedScriptPath.match(/\.asar[\/\\]/)) { | ||
try { | ||
super(resolvedScriptPath, options); | ||
} | ||
catch (_a) { | ||
// See <https://github.com/andywer/threads-plugin/issues/17> | ||
super(resolvedScriptPath.replace(/\.asar([\/\\])/, ".asar.unpacked$1"), options); | ||
} | ||
} | ||
else { | ||
@@ -110,2 +125,11 @@ super(resolvedScriptPath, options); | ||
} | ||
else if (resolvedScriptPath.match(/\.asar[\/\\]/)) { | ||
try { | ||
super(resolvedScriptPath, [], { esm: true }); | ||
} | ||
catch (_a) { | ||
// See <https://github.com/andywer/threads-plugin/issues/17> | ||
super(resolvedScriptPath.replace(/\.asar([\/\\])/, ".asar.unpacked$1"), [], { esm: true }); | ||
} | ||
} | ||
else { | ||
@@ -112,0 +136,0 @@ super(resolvedScriptPath, [], { esm: true }); |
@@ -88,4 +88,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
// tslint:disable-next-line no-console | ||
console.error("Not reporting uncaught error back to master thread as it occured while " + | ||
"reporting an uncaught error already. Latest error:", subError); | ||
console.error("Not reporting uncaught error back to master thread as it " + | ||
"occured while reporting an uncaught error already." + | ||
"\nLatest error:", subError, "\nOriginal error:", error); | ||
} | ||
@@ -92,0 +93,0 @@ } |
"use strict"; | ||
// tslint:disable function-constructor no-eval max-classes-per-file | ||
// tslint:disable function-constructor no-eval no-duplicate-super max-classes-per-file | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -53,3 +53,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const filename = callsite.getFileName(); | ||
return Boolean(filename && !filename.match(ignoreRegex) && !filename.match(/[\/\\]master[\/\\]implementation/)); | ||
return Boolean(filename && | ||
!filename.match(ignoreRegex) && | ||
!filename.match(/[\/\\]master[\/\\]implementation/) && | ||
!filename.match(/^internal\/process/)); | ||
}); | ||
@@ -60,7 +63,10 @@ const callerPath = parentCallSite ? parentCallSite.getFileName() : null; | ||
} | ||
function resolveScriptPath(scriptPath) { | ||
// eval() hack is also webpack-related | ||
function resolveScriptPath(scriptPath, baseURL) { | ||
const makeRelative = (filePath) => { | ||
// eval() hack is also webpack-related | ||
return path.isAbsolute(filePath) ? filePath : path.join(baseURL || eval("__dirname"), filePath); | ||
}; | ||
const workerFilePath = typeof __non_webpack_require__ === "function" | ||
? __non_webpack_require__.resolve(path.join(eval("__dirname"), scriptPath)) | ||
: require.resolve(rebaseScriptPath(scriptPath, /[\/\\]worker_threads[\/\\]/)); | ||
? __non_webpack_require__.resolve(makeRelative(scriptPath)) | ||
: require.resolve(makeRelative(rebaseScriptPath(scriptPath, /[\/\\]worker_threads[\/\\]/))); | ||
return workerFilePath; | ||
@@ -76,6 +82,15 @@ } | ||
constructor(scriptPath, options) { | ||
const resolvedScriptPath = resolveScriptPath(scriptPath); | ||
const resolvedScriptPath = resolveScriptPath(scriptPath, (options || {})._baseURL); | ||
if (resolvedScriptPath.match(/\.tsx?$/i) && detectTsNode()) { | ||
super(createTsNodeModule(resolvedScriptPath), { eval: true }); | ||
super(createTsNodeModule(resolvedScriptPath), Object.assign(Object.assign({}, options), { eval: true })); | ||
} | ||
else if (resolvedScriptPath.match(/\.asar[\/\\]/)) { | ||
try { | ||
super(resolvedScriptPath, options); | ||
} | ||
catch (_a) { | ||
// See <https://github.com/andywer/threads-plugin/issues/17> | ||
super(resolvedScriptPath.replace(/\.asar([\/\\])/, ".asar.unpacked$1"), options); | ||
} | ||
} | ||
else { | ||
@@ -122,2 +137,11 @@ super(resolvedScriptPath, options); | ||
} | ||
else if (resolvedScriptPath.match(/\.asar[\/\\]/)) { | ||
try { | ||
super(resolvedScriptPath, [], { esm: true }); | ||
} | ||
catch (_a) { | ||
// See <https://github.com/andywer/threads-plugin/issues/17> | ||
super(resolvedScriptPath.replace(/\.asar([\/\\])/, ".asar.unpacked$1"), [], { esm: true }); | ||
} | ||
} | ||
else { | ||
@@ -124,0 +148,0 @@ super(resolvedScriptPath, [], { esm: true }); |
@@ -95,4 +95,5 @@ "use strict"; | ||
// tslint:disable-next-line no-console | ||
console.error("Not reporting uncaught error back to master thread as it occured while " + | ||
"reporting an uncaught error already. Latest error:", subError); | ||
console.error("Not reporting uncaught error back to master thread as it " + | ||
"occured while reporting an uncaught error already." + | ||
"\nLatest error:", subError, "\nOriginal error:", error); | ||
} | ||
@@ -99,0 +100,0 @@ } |
{ | ||
"name": "threads", | ||
"version": "1.3.1", | ||
"version": "1.4.0-error-reporting-fix", | ||
"description": "Web workers & worker threads as simple as a function call", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
157796
3592
1