[Bun.js] Fix entry point to only call default if it was a CommonJS transformed function

This commit is contained in:
Jarred Sumner
2021-10-30 03:11:58 -07:00
parent f8f85430c0
commit 65ea1e4647
4 changed files with 10 additions and 2 deletions

View File

@@ -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();
\\}}
,

View File

@@ -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;

View File

@@ -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])

View File

@@ -1 +1 @@
7be53da538434cb0
c6d7615ce951f3ae