diff options
author | Vedant Pandey <vedantpandey46@gmail.com> | 2023-06-15 20:30:30 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-15 17:00:30 +0200 |
commit | 0c50c39c35f1c92bbb96bc3e101e2c446256cb7b (patch) | |
tree | 568d0f393997a7c4dab9665e7a20e10a5af2187d /ext/node/polyfills/worker_threads.ts | |
parent | f145cbfaccd9f3b251b2f80690ad7c68b26d924b (diff) |
fix(node): Worker constructor doesn't check type: module of package.json (#19480)
Diffstat (limited to 'ext/node/polyfills/worker_threads.ts')
-rw-r--r-- | ext/node/polyfills/worker_threads.ts | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/ext/node/polyfills/worker_threads.ts b/ext/node/polyfills/worker_threads.ts index 8005506bb..32f9885af 100644 --- a/ext/node/polyfills/worker_threads.ts +++ b/ext/node/polyfills/worker_threads.ts @@ -9,6 +9,7 @@ import { MessageChannel, MessagePort } from "ext:deno_web/13_message_port.js"; let environmentData = new Map(); let threads = 0; +const { core } = globalThis.__bootstrap; export interface WorkerOptions { // only for typings @@ -53,7 +54,16 @@ class _Worker extends EventEmitter { specifier = `data:text/javascript,${specifier}`; } else if (typeof specifier === "string") { specifier = resolve(specifier); - if (!specifier.toString().endsWith(".mjs")) { + let pkg; + try { + pkg = core.ops.op_require_read_closest_package_json(specifier); + } catch (_) { + // empty catch block when package json might not be present + } + if ( + !(specifier.toString().endsWith(".mjs") || + (pkg && pkg.exists && pkg.typ == "module")) + ) { const cwdFileUrl = toFileUrl(Deno.cwd()); specifier = `data:text/javascript,(async function() {const { createRequire } = await import("node:module");const require = createRequire("${cwdFileUrl}");require("${specifier}");})();`; |