Skip to content

Commit 0cf99be

Browse files
committed
Use requireFunction
1 parent fb54ff6 commit 0cf99be

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/master/implementation.node.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,9 @@ function resolveScriptPath(scriptPath: string, baseURL?: string | undefined) {
9696

9797
function initWorkerThreadsWorker(): ImplementationExport {
9898
// Webpack hack
99-
const NativeWorker = typeof __non_webpack_require__ === "function"
100-
? __non_webpack_require__("worker_threads").Worker
101-
: eval("require")("worker_threads").Worker
99+
const NativeWorker = (requireFunction("worker_threads") as typeof import("worker_threads")).Worker
102100

103-
let allWorkers: Array<typeof NativeWorker> = []
101+
let allWorkers: Array<Worker> = []
104102

105103
class Worker extends NativeWorker {
106104
private mappedEventListeners: WeakMap<EventListener, EventListener>
@@ -278,9 +276,7 @@ export function isWorkerRuntime() {
278276
return typeof self !== "undefined" && self.postMessage ? true : false
279277
} else {
280278
// Webpack hack
281-
const isMainThread = typeof __non_webpack_require__ === "function"
282-
? __non_webpack_require__("worker_threads").isMainThread
283-
: eval("require")("worker_threads").isMainThread
279+
const isMainThread = (requireFunction("worker_threads") as typeof import("worker_threads")).isMainThread
284280
return !isMainThread
285281
}
286282
}

0 commit comments

Comments
 (0)