mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
### What does this PR do?
Currently bundling and running projects with cyclic async module
dependencies will hang due to module promises never resolving. This PR
unblocks these projects by outputting `await Promise.all` with these
dependencies.
Before (will hang with bun, or error with unsettled top level await with
node):
```js
var __esm = (fn, res) => () => (fn && (res = fn((fn = 0))), res);
var init_mod3 = __esm(async () => {
await init_mod1();
});
var init_mod2 = __esm(async () => {
await init_mod1();
});
var init_mod1 = __esm(async () => {
await init_mod2();
await init_mod3();
});
await init_mod1();
```
After:
```js
var __esm = (fn, res) => () => (fn && (res = fn((fn = 0))), res);
var __promiseAll = Promise.all.bind(Promise);
var init_mod3 = __esm(async () => {
await init_mod1();
});
var init_mod2 = __esm(async () => {
await init_mod1();
});
var init_mod1 = __esm(async () => {
await __promiseAll([init_mod2(), init_mod3()]);
});
await init_mod1();
```
### How did you verify your code works?
Manually and tests
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
180 lines
6.0 KiB
JavaScript
180 lines
6.0 KiB
JavaScript
// Since runtime.js loads first in the bundler, Ref.none will point at this
|
|
// value. And since it isnt exported, it will always be tree-shaken away.
|
|
var __INVALID__REF__;
|
|
|
|
// This ordering is deliberate so that the printer optimizes
|
|
// them into a single destructuring assignment.
|
|
var __create = Object.create;
|
|
var __descs = Object.getOwnPropertyDescriptors;
|
|
var __getProtoOf = Object.getPrototypeOf;
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
|
// This is used to implement "export * from" statements. It copies properties
|
|
// from the imported module to the current module's ESM export object. If the
|
|
// current module is an entry point and the target format is CommonJS, we
|
|
// also copy the properties to "module.exports" in addition to our module's
|
|
// internal ESM export object.
|
|
export var __reExport = (target, mod, secondTarget) => {
|
|
for (let key of __getOwnPropNames(mod))
|
|
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
__defProp(target, key, {
|
|
get: () => mod[key],
|
|
enumerable: true,
|
|
});
|
|
|
|
if (secondTarget) {
|
|
for (let key of __getOwnPropNames(mod))
|
|
if (!__hasOwnProp.call(secondTarget, key) && key !== "default")
|
|
__defProp(secondTarget, key, {
|
|
get: () => mod[key],
|
|
enumerable: true,
|
|
});
|
|
|
|
return secondTarget;
|
|
}
|
|
};
|
|
|
|
// Converts the module from CommonJS to ESM. When in node mode (i.e. in an
|
|
// ".mjs" file, package.json has "type: module", or the "__esModule" export
|
|
// in the CommonJS file is falsy or missing), the "default" property is
|
|
// overridden to point to the original CommonJS exports object instead.
|
|
export var __toESM = (mod, isNodeMode, target) => {
|
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
const to =
|
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
|
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
// file that has been converted to a CommonJS file using a Babel-
|
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
for (let key of __getOwnPropNames(mod))
|
|
if (!__hasOwnProp.call(to, key))
|
|
__defProp(to, key, {
|
|
get: () => mod[key],
|
|
enumerable: true,
|
|
});
|
|
|
|
return to;
|
|
};
|
|
|
|
// Converts the module from ESM to CommonJS. This clones the input module
|
|
// object with the addition of a non-enumerable "__esModule" property set
|
|
// to "true", which overwrites any existing export named "__esModule".
|
|
var __moduleCache = /* @__PURE__ */ new WeakMap();
|
|
export var __toCommonJS = /* @__PURE__ */ from => {
|
|
var entry = __moduleCache.get(from),
|
|
desc;
|
|
if (entry) return entry;
|
|
entry = __defProp({}, "__esModule", { value: true });
|
|
if ((from && typeof from === "object") || typeof from === "function")
|
|
__getOwnPropNames(from).map(
|
|
key =>
|
|
!__hasOwnProp.call(entry, key) &&
|
|
__defProp(entry, key, {
|
|
get: () => from[key],
|
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
}),
|
|
);
|
|
__moduleCache.set(from, entry);
|
|
return entry;
|
|
};
|
|
|
|
// When you do know the module is CJS
|
|
export var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
|
|
export var __name = (target, name) => {
|
|
Object.defineProperty(target, "name", {
|
|
value: name,
|
|
enumerable: false,
|
|
configurable: true,
|
|
});
|
|
|
|
return target;
|
|
};
|
|
|
|
// ESM export -> CJS export
|
|
// except, writable incase something re-exports
|
|
|
|
export var __export = /* @__PURE__ */ (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, {
|
|
get: all[name],
|
|
enumerable: true,
|
|
configurable: true,
|
|
set: newValue => (all[name] = () => newValue),
|
|
});
|
|
};
|
|
|
|
export var __exportValue = (target, all) => {
|
|
for (var name in all) {
|
|
__defProp(target, name, {
|
|
get: () => all[name],
|
|
set: newValue => (all[name] = newValue),
|
|
enumerable: true,
|
|
configurable: true,
|
|
});
|
|
}
|
|
};
|
|
|
|
export var __exportDefault = (target, value) => {
|
|
__defProp(target, "default", {
|
|
get: () => value,
|
|
set: newValue => (value = newValue),
|
|
enumerable: true,
|
|
configurable: true,
|
|
});
|
|
};
|
|
|
|
function __hasAnyProps(obj) {
|
|
for (let key in obj) return true;
|
|
return false;
|
|
}
|
|
|
|
function __mergeDefaultProps(props, defaultProps) {
|
|
var result = __create(defaultProps, __descs(props));
|
|
|
|
for (let key in defaultProps) {
|
|
if (result[key] !== undefined) continue;
|
|
|
|
result[key] = defaultProps[key];
|
|
}
|
|
return result;
|
|
}
|
|
export var __merge = (props, defaultProps) => {
|
|
return !__hasAnyProps(defaultProps)
|
|
? props
|
|
: !__hasAnyProps(props)
|
|
? defaultProps
|
|
: __mergeDefaultProps(props, defaultProps);
|
|
};
|
|
|
|
export var __legacyDecorateClassTS = function (decorators, target, key, desc) {
|
|
var c = arguments.length,
|
|
r = c < 3 ? target : desc === null ? (desc = Object.getOwnPropertyDescriptor(target, key)) : desc,
|
|
d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
else
|
|
for (var i = decorators.length - 1; i >= 0; i--)
|
|
if ((d = decorators[i])) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return (c > 3 && r && Object.defineProperty(target, key, r), r);
|
|
};
|
|
|
|
export var __legacyDecorateParamTS = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
|
|
export var __legacyMetadataTS = (k, v) => {
|
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
};
|
|
|
|
export var __esm = (fn, res) => () => (fn && (res = fn((fn = 0))), res);
|
|
|
|
// This is used for JSX inlining with React.
|
|
export var $$typeof = /* @__PURE__ */ Symbol.for("react.element");
|
|
|
|
export var __jsonParse = /* @__PURE__ */ a => JSON.parse(a);
|
|
|
|
export var __promiseAll = args => Promise.all(args);
|