interface CommonJSModuleRecord { $require(id: string, mod: any): any; children: CommonJSModuleRecord[]; exports: any; id: string; loaded: boolean; parent: undefined; path: string; paths: string[]; require: typeof require; } $getter; export function main() { return $requireMap.$get(Bun.main); } export function require(this: CommonJSModuleRecord, id: string) { const existing = $requireMap.$get(id) || $requireMap.$get((id = $resolveSync(id, this.path, false))); if (existing) { // Scenario where this is necessary: // // In an ES Module, we have: // // import "react-dom/server" // import "react" // // Synchronously, the "react" import is created first, and then the // "react-dom/server" import is created. Then, at ES Module link time, they // are evaluated. The "react-dom/server" import is evaluated first, and // require("react") was previously created as an ESM module, so we wait // for the ESM module to load // // ...and then when this code is reached, unless // we evaluate it "early", we'll get an empty object instead of the module // exports. // $evaluateCommonJSModule(existing); return existing.exports; } if (id.endsWith(".node")) { return $internalRequire(id); } // To handle import/export cycles, we need to create a module object and put // it into the map before we import it. const mod = $createCommonJSModule(id, {}, false); $requireMap.$set(id, mod); // This is where we load the module. We will see if Module._load and // Module._compile are actually important for compatibility. // // Note: we do not need to wrap this in a try/catch, if it throws the C++ code will // clear the module from the map. // var out = this.$require(id, mod); // -1 means we need to lookup the module from the ESM registry. if (out === -1) { try { out = $requireESM(id); } catch (exception) { // Since the ESM code is mostly JS, we need to handle exceptions here. $requireMap.$delete(id); throw exception; } const esm = Loader.registry.$get(id); // If we can pull out a ModuleNamespaceObject, let's do it. if (esm?.evaluated && (esm.state ?? 0) >= $ModuleReady) { const namespace = Loader.getModuleNamespaceObject(esm!.module); return (mod.exports = // if they choose a module namespace.__esModule ? namespace : Object.create(namespace, { __esModule: { value: true } })); } } $evaluateCommonJSModule(mod); return mod.exports; } export function requireResolve(this: string | { path: string }, id: string) { return $resolveSync(id, typeof this === "string" ? this : this?.path, false); } export function requireNativeModule(id: string) { let esm = Loader.registry.$get(id); if (esm?.evaluated && (esm.state ?? 0) >= $ModuleReady) { const exports = Loader.getModuleNamespaceObject(esm.module); return exports.default; } return $requireESM(id).default; } Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/integration/bunjs-only-snippets/fs-stream.js (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-02-27[JS Parser] Fix bug with unicode identifiersGravatar Jarred Sumner 2-31/+142
2022-02-27[JS Parser] #privateIdentifiersGravatar Jarred Sumner 1-105/+279
2022-02-27[JS Parser] Class Static Initialization BlocksGravatar Jarred Sumner 1-0/+62
2022-02-27[TS Parser] Support `export {type Foo}`Gravatar Jarred Sumner 6-26/+114
2022-02-25be more carefulGravatar Jarred Sumner 3-6/+11
2022-02-25Update cli.zigbun-v0.0.71Gravatar Jarred Sumner 1-2/+2
2022-02-25bump target nextjs versionGravatar Jarred Sumner 1-1/+1
2022-02-25[bun pm] add help menuGravatar Jarred Sumner 1-4/+22
2022-02-25Fix alignment bug with `bun --help`Gravatar Jarred Sumner 1-1/+1
2022-02-25hopefully no more unnecessary git statusGravatar Jarred Sumner 6-1/+1
2022-02-25Update bun-install-lockfile-status.shGravatar Jarred Sumner 1-9/+2
2022-02-25[bun install] Add metadata hashGravatar Jarred Sumner 9-19/+277
2022-02-25Update README.md (#119)Gravatar Evan Boehs 1-1/+0
2022-02-24[bun install] Skip saving the lockfile if there are no changesGravatar Jarred Sumner 3-12/+97
2022-02-24Update MakefileGravatar Jarred Sumner 1-1/+1
2022-02-24Update MakefileGravatar Jarred Sumner 1-1/+0
2022-02-24Update WebKitGravatar Jarred Sumner 1-0/+0
2022-02-24Update generated versionsGravatar Jarred Sumner 1-2/+2
2022-02-24Update MakefileGravatar Jarred Sumner 1-1/+3
2022-02-24miscGravatar Jarred Sumner 2-4/+4
2022-02-24[bun dev] Don't log errors twiceGravatar Jarred Sumner 1-1/+0
2022-02-24Add a simple HMR testGravatar Jarred Sumner 1-2/+40
2022-02-24Make alignment more consitentGravatar Jarred Sumner 3-4/+56
2022-02-24[bun dev] Fix bug with not transpiling files at the rootGravatar Jarred Sumner 2-21/+47
2022-02-24slightly clean up react exampleGravatar Jarred Sumner 5-55/+2
2022-02-24[bun-framework-next] Support Next.js 12.1Gravatar Jarred Sumner 6-25/+46
2022-02-24[bun.js] Implement `process.exit` (no callbacks yet)Gravatar Jarred Sumner 2-0/+29
2022-02-24[bun install] Print correct bin nameGravatar Jarred Sumner 1-1/+1
2022-02-24[bun install] Add integration test for bin linksGravatar Jarred Sumner 1-1/+7
2022-02-24Add WASM modules but disable it for nowGravatar Jarred Sumner 28-134/+530
2022-02-24bump build idGravatar Jarred Sumner 1-1/+1
2022-02-24fix test failure in path.resolveGravatar Jarred Sumner 1-2/+6
2022-02-24Ensure we run the process testGravatar Jarred Sumner 2-48/+54
2022-02-24Update javascript.zigGravatar Jarred Sumner 1-1/+110
2022-02-24[bun.js] Add `ShadowRealm`Gravatar Jarred Sumner 7-18/+70
2022-02-24[bun-framework-next] Remove TextEncoder & TextDecoder polyfillsGravatar Jarred Sumner 3-340/+19
2022-02-24Use a JSFinalobject for PathGravatar Jarred Sumner 2-81/+42
2022-02-24Expose TextEncoder & TextDecoder globallyGravatar Jarred Sumner 3-20/+750
2022-02-24[Web Platform] Implement TextEncoder & TextDecoderGravatar Jarred Sumner 12-358/+1044
2022-02-24move GCDeferralContextGravatar Jarred Sumner 2-18/+24
2022-02-24[JS Parser] ensure assertions are never run at runtimeGravatar Jarred Sumner 1-13/+18
2022-02-24misc cleanupGravatar Jarred Sumner 2-7/+18
2022-02-22Make format consistent with WebKitGravatar Jarred Sumner 20-3596/+4110
2022-02-22import assertion testGravatar Jarred Sumner 1-0/+33
2022-02-22snaspshotsGravatar Jarred Sumner 42-94/+113