From 65ea1e464755a165a29680f12f02eb37ccfd8ecf Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sat, 30 Oct 2021 03:11:58 -0700 Subject: [PATCH] [Bun.js] Fix entry point to only call default if it was a CommonJS transformed function --- src/bundler.zig | 2 +- src/runtime.footer.js | 3 +++ src/runtime.js | 5 +++++ src/runtime.version | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/bundler.zig b/src/bundler.zig index 35c078759f..44feeb7491 100644 --- a/src/bundler.zig +++ b/src/bundler.zig @@ -3482,7 +3482,7 @@ pub const ServerEntryPoint = struct { \\//Auto-generated file \\import * as start from '{s}{s}'; \\export * from '{s}{s}'; - \\if ('default' in start && typeof start.default == 'function') {{ + \\if ('default' in start && "__internalIsCommonJSNamespace" in globalThis && __internalIsCommonJSNamespace(start)) {{ \\ start.default(); \\}} , diff --git a/src/runtime.footer.js b/src/runtime.footer.js index 9bea7273d4..334efb92a0 100644 --- a/src/runtime.footer.js +++ b/src/runtime.footer.js @@ -19,6 +19,9 @@ export var regeneratorRuntime = BUN_RUNTIME.regeneratorRuntime; export var __exportValue = BUN_RUNTIME.__exportValue; export var __exportDefault = BUN_RUNTIME.__exportDefault; export var $$bun_runtime_json_parse = JSON.parse; +export var __internalIsCommonJSNamespace = + BUN_RUNTIME.__internalIsCommonJSNamespace; +globalThis.__internalIsCommonJSNamespace ||= __internalIsCommonJSNamespace; globalThis.require ||= BUN_RUNTIME.__require; globalThis.self ||= globalThis; diff --git a/src/runtime.js b/src/runtime.js index 0c4f539309..07219436db 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -136,6 +136,11 @@ export var __commonJS = (cb, name) => { export var __cJS2eSM = __commonJS; +export var __internalIsCommonJSNamespace = (namespace) => + typeof namespace === "object" && + "default" in namespace && + namespace.default[cjsRequireSymbol]; + export var __require = (namespace) => { const namespaceType = typeof namespace; if (namespaceType === "function" && namespace[cjsRequireSymbol]) diff --git a/src/runtime.version b/src/runtime.version index ccfdfb532e..6fda31b516 100644 --- a/src/runtime.version +++ b/src/runtime.version @@ -1 +1 @@ -7be53da538434cb0 \ No newline at end of file +c6d7615ce951f3ae \ No newline at end of file