From ff635551436123022ba3980b39580d53973c80a2 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sat, 24 Jun 2023 06:02:16 -0700 Subject: Rewrite Bun's runtime CommonJS loader (#3379) * wip changes for CommonJS * this rewrite is almost complete * even more code * wip * Remove usages of `import.meta.require` from builtins * Remove usages of require * Regenerate * :scissors: builtin rewrite commonjs in printer * Use lazy custom getters for import.meta * fixups * Remove depd * ugh * still crashing * fixup undici * comment out import.meta.require.resolve temporarily not a real solution but it stops the crashes * Redo import.meta.primordials * Builtins now have a `builtin://` protocol in source origin * Seems to work? * Finsih getting rid of primordials * switcharoo * No more function * just one more bug * Update launch.json * Implement `require.main` * :scissors: * Bump WebKit * Fixup import cycles * Fixup improt cycles * export more things * Implement `createCommonJSModule` builtin * More exports * regenerate * i broke some stuff * some of these tests work now * We lost the encoding * Sort of fix zlib * Sort of fix util * Update events.js * bump * bump * bump * Fix missing export in fs * fix some bugs with builtin esm modules (stream, worker_threads, events). its not perfect yet. * fix some other internal module bugs * oops * fix some extra require default stuff * uncomment this file but it crsahes on my machine * tidy code here * fixup tls exports * make simdutf happier * Add hasPrefix binding * Add test for `require.main` * Fix CommonJS evaluation order race condition * Make node:http load faster * Add missing exports to tls.js * Use the getter * Regenerate builtins * Fix assertion failure in Bun.write() * revamp dotEnv parser (#3347) - fixes `strings.indexOfAny()` - fixes OOB array access fixes #411 fixes #2823 fixes #3042 * fix tests for `expect()` (#3384) - extend test job time-out for `darwin-aarch64` * `expect().resolves` and `expect().rejects` (#3318) * Move expect and snapshots to their own files * expect().resolves and expect().rejects * Fix promise being added to unhandled rejection list * Handle timeouts in expect() * wip merge * Fix merge issue --------- Co-authored-by: Jarred Sumner Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> * fixup min/memcopy (#3388) * Fix crash in builtins * Don't attempt to evaluate modules with no source code * Update WebCoreJSBuiltins.cpp * Update WebCoreJSBuiltins.cpp * Update WebCoreJSBuiltins.cpp * Fix crash * cleanup * Fix test cc @paperdave * Fixup Undici * Fix issue in node:http * Create util-deprecate.mjs * Fix several bugs * Use the identifier * Support error.code in `util.deprecate` * make the CJs loader slightly more resilient * Update WebCoreJSBuiltins.cpp * Fix macros --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: dave caruso Co-authored-by: Alex Lam S.L Co-authored-by: Ashcon Partovi Co-authored-by: Ciro Spaciari --- src/js/node/zlib.js | 110 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 71 insertions(+), 39 deletions(-) (limited to 'src/js/node/zlib.js') diff --git a/src/js/node/zlib.js b/src/js/node/zlib.js index 1414f4664..77a9e8089 100644 --- a/src/js/node/zlib.js +++ b/src/js/node/zlib.js @@ -3,6 +3,41 @@ // This is a very slow module! // It should really be fixed. It will show up in benchmarking. It also loads // slowly. We need to fix it! +import { default as assert } from "node:assert"; +import * as AssertModule from "node:assert"; +import * as BufferModule from "node:buffer"; +import * as StreamModule from "node:stream"; +import * as Util from "node:util"; + +export var Deflate, + Inflate, + Gzip, + Gunzip, + DeflateRaw, + InflateRaw, + Unzip, + createDeflate, + createInflate, + createDeflateRaw, + createInflateRaw, + createGzip, + createGunzip, + createUnzip, + deflate, + deflateSync, + gzip, + gzipSync, + deflateRaw, + deflateRawSync, + unzip, + unzipSync, + inflate, + inflateSync, + gunzip, + gunzipSync, + inflateRaw, + inflateRawSync, + constants; var __create = Object.create; var __defProp = Object.defineProperty; @@ -38,8 +73,6 @@ var __toESM = (mod, isNodeMode, target) => ( ); var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: true }), mod); -const require = id => import.meta.require(id); - // node_modules/pako/lib/zlib/zstream.js var require_zstream = __commonJS({ "node_modules/pako/lib/zlib/zstream.js"(exports, module2) { @@ -3593,7 +3626,7 @@ var require_constants = __commonJS({ var require_binding = __commonJS({ "node_modules/browserify-zlib/lib/binding.js"(exports) { "use strict"; - var assert = require("assert"); + var Zstream = require_zstream(); var zlib_deflate = require_deflate(); var zlib_inflate = require_inflate(); @@ -3937,12 +3970,12 @@ var require_binding = __commonJS({ var require_lib = __commonJS({ "node_modules/browserify-zlib/lib/index.js"(exports) { "use strict"; - var Buffer2 = require("buffer").Buffer; - var Transform = require("stream").Transform; + var Buffer2 = BufferModule.Buffer; + var Transform = StreamModule.Transform; var binding = require_binding(); - var util = require("util"); - var assert = require("assert").ok; - var kMaxLength = require("buffer").kMaxLength; + var util = Util; + var assert = AssertModule.ok; + var kMaxLength = BufferModule.kMaxLength; var kRangeErrorMessage = "Cannot create final Buffer. It would be larger than 0x" + kMaxLength.toString(16) + " bytes"; binding.Z_MIN_WINDOWBITS = 8; @@ -4437,36 +4470,35 @@ var require_lib = __commonJS({ // zlib.js var zlib_exports = require_lib(); zlib_exports[Symbol.for("CommonJS")] = 0; + export default zlib_exports; -export var { - Deflate, - Inflate, - Gzip, - Gunzip, - DeflateRaw, - InflateRaw, - Unzip, - createDeflate, - createInflate, - createDeflateRaw, - createInflateRaw, - createGzip, - createGunzip, - createUnzip, - deflate, - deflateSync, - gzip, - gzipSync, - deflateRaw, - deflateRawSync, - unzip, - unzipSync, - inflate, - inflateSync, - gunzip, - gunzipSync, - inflateRaw, - inflateRawSync, - constants, -} = zlib_exports; +Deflate = zlib_exports.Deflate; +Inflate = zlib_exports.Inflate; +Gzip = zlib_exports.Gzip; +Gunzip = zlib_exports.Gunzip; +DeflateRaw = zlib_exports.DeflateRaw; +InflateRaw = zlib_exports.InflateRaw; +Unzip = zlib_exports.Unzip; +createDeflate = zlib_exports.createDeflate; +createInflate = zlib_exports.createInflate; +createDeflateRaw = zlib_exports.createDeflateRaw; +createInflateRaw = zlib_exports.createInflateRaw; +createGzip = zlib_exports.createGzip; +createGunzip = zlib_exports.createGunzip; +createUnzip = zlib_exports.createUnzip; +deflate = zlib_exports.deflate; +deflateSync = zlib_exports.deflateSync; +gzip = zlib_exports.gzip; +gzipSync = zlib_exports.gzipSync; +deflateRaw = zlib_exports.deflateRaw; +deflateRawSync = zlib_exports.deflateRawSync; +unzip = zlib_exports.unzip; +unzipSync = zlib_exports.unzipSync; +inflate = zlib_exports.inflate; +inflateSync = zlib_exports.inflateSync; +gunzip = zlib_exports.gunzip; +gunzipSync = zlib_exports.gunzipSync; +inflateRaw = zlib_exports.inflateRaw; +inflateRawSync = zlib_exports.inflateRawSync; +constants = zlib_exports.constants; -- cgit v1.2.3