aboutsummaryrefslogtreecommitdiff
path: root/src/node-fallbacks
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-07-11 19:14:34 -0700
committerGravatar GitHub <noreply@github.com> 2023-07-11 19:14:34 -0700
commitcbb88672f217a90db1aa1eb29cd92d5d9035b22b (patch)
tree43a00501f3cde495967e116f0b660777051551f8 /src/node-fallbacks
parent1f900cff453700b19bca2acadfe26da4468c1282 (diff)
parent34b0e7a2bbd8bf8097341cdb0075d0908283e834 (diff)
downloadbun-cbb88672f217a90db1aa1eb29cd92d5d9035b22b.tar.gz
bun-cbb88672f217a90db1aa1eb29cd92d5d9035b22b.tar.zst
bun-cbb88672f217a90db1aa1eb29cd92d5d9035b22b.zip
Merge branch 'main' into jarred/esm-conditionsjarred/esm-conditions
Diffstat (limited to 'src/node-fallbacks')
-rw-r--r--src/node-fallbacks/@vercel_fetch.js2
-rw-r--r--src/node-fallbacks/buffer.js1
-rw-r--r--src/node-fallbacks/console.js2
-rw-r--r--src/node-fallbacks/crypto.js33
-rw-r--r--src/node-fallbacks/domain.js4
-rw-r--r--src/node-fallbacks/http.js14
-rw-r--r--src/node-fallbacks/https.js1
-rw-r--r--src/node-fallbacks/node-fetch.js1
-rw-r--r--src/node-fallbacks/os.js21
-rw-r--r--src/node-fallbacks/package.json4
-rw-r--r--src/node-fallbacks/path.js1
-rw-r--r--src/node-fallbacks/process.js1
-rw-r--r--src/node-fallbacks/querystring.js3
-rw-r--r--src/node-fallbacks/stream.js1
-rw-r--r--src/node-fallbacks/string_decoder.js1
-rw-r--r--src/node-fallbacks/sys.js1
-rw-r--r--src/node-fallbacks/timers.js1
-rw-r--r--src/node-fallbacks/tsconfig.json2
-rw-r--r--src/node-fallbacks/tty.js1
-rw-r--r--src/node-fallbacks/util.js1
-rw-r--r--src/node-fallbacks/zlib.js1
21 files changed, 88 insertions, 9 deletions
diff --git a/src/node-fallbacks/@vercel_fetch.js b/src/node-fallbacks/@vercel_fetch.js
index a8de45222..276b4bc9f 100644
--- a/src/node-fallbacks/@vercel_fetch.js
+++ b/src/node-fallbacks/@vercel_fetch.js
@@ -1,5 +1,5 @@
// This is just a no-op. Intent is to prevent importing a bunch of stuff that isn't relevant.
-module.exports = (wrapper = "Bun" in globalThis ? Bun.fetch : globalThis.fetch) => {
+export default (wrapper = "Bun" in globalThis ? Bun.fetch : globalThis.fetch) => {
async function vercelFetch(url, opts = {}) {
// Convert Object bodies to JSON if they are JS objects
if (
diff --git a/src/node-fallbacks/buffer.js b/src/node-fallbacks/buffer.js
index 9984aef87..aa0065398 100644
--- a/src/node-fallbacks/buffer.js
+++ b/src/node-fallbacks/buffer.js
@@ -1 +1,2 @@
export * from "buffer";
+export { Buffer as default } from "buffer";
diff --git a/src/node-fallbacks/console.js b/src/node-fallbacks/console.js
index 5cb1dfa10..34cc54b56 100644
--- a/src/node-fallbacks/console.js
+++ b/src/node-fallbacks/console.js
@@ -1 +1 @@
-module.exports = console;
+export default console;
diff --git a/src/node-fallbacks/crypto.js b/src/node-fallbacks/crypto.js
index 8c83b6c87..65ae2f5b3 100644
--- a/src/node-fallbacks/crypto.js
+++ b/src/node-fallbacks/crypto.js
@@ -1,4 +1,5 @@
export * from "crypto-browserify";
+import * as cryptoBrowserify from "crypto-browserify";
export var DEFAULT_ENCODING = "buffer";
@@ -11,6 +12,27 @@ export const randomUUID = () => {
return crypto.randomUUID();
};
+const harcoded_curves = [
+ "p192",
+ "p224",
+ "p256",
+ "p384",
+ "p521",
+ "curve25519",
+ "ed25519",
+ "secp256k1",
+ "secp224r1",
+ "prime256v1",
+ "prime192v1",
+ "ed25519",
+ "secp384r1",
+ "secp521r1",
+];
+
+export function getCurves() {
+ return harcoded_curves;
+}
+
export const timingSafeEqual =
"timingSafeEqual" in crypto
? (a, b) => {
@@ -79,3 +101,14 @@ if (timingSafeEqual) {
}
export const webcrypto = crypto;
+
+export default {
+ ...cryptoBrowserify,
+ getRandomValues,
+ randomUUID,
+ timingSafeEqual,
+ scryptSync,
+ scrypt,
+ webcrypto,
+ getCurves,
+};
diff --git a/src/node-fallbacks/domain.js b/src/node-fallbacks/domain.js
index 9fe768097..af37e7059 100644
--- a/src/node-fallbacks/domain.js
+++ b/src/node-fallbacks/domain.js
@@ -1 +1,3 @@
-export * from "domain-browser";
+import domain from "domain-browser";
+export default domain;
+export var { create, createDomain } = domain;
diff --git a/src/node-fallbacks/http.js b/src/node-fallbacks/http.js
index 3f025710f..4bb5b4a0d 100644
--- a/src/node-fallbacks/http.js
+++ b/src/node-fallbacks/http.js
@@ -1 +1,13 @@
-export * from "stream-http";
+import http from "stream-http";
+export default http;
+export var {
+ //
+ request,
+ get,
+ ClientRequest,
+ IncomingMessage,
+ Agent,
+ globalAgent,
+ STATUS_CODES,
+ METHIDS,
+} = http;
diff --git a/src/node-fallbacks/https.js b/src/node-fallbacks/https.js
index a5f405a5a..d1de96beb 100644
--- a/src/node-fallbacks/https.js
+++ b/src/node-fallbacks/https.js
@@ -1 +1,2 @@
export * from "https-browserify";
+export * as default from "https-browserify";
diff --git a/src/node-fallbacks/node-fetch.js b/src/node-fallbacks/node-fetch.js
index f124e6461..c65d4f6ed 100644
--- a/src/node-fallbacks/node-fetch.js
+++ b/src/node-fallbacks/node-fetch.js
@@ -70,6 +70,7 @@ export default Object.assign(fetch, {
fileFrom,
fileFromSync,
isRedirect,
+ default: fetch,
[Symbol.for("CommonJS")]: 0,
});
diff --git a/src/node-fallbacks/os.js b/src/node-fallbacks/os.js
index c5bef4cf0..df0a41fd2 100644
--- a/src/node-fallbacks/os.js
+++ b/src/node-fallbacks/os.js
@@ -1 +1,20 @@
-export * from "os-browserify/browser";
+import os from "os-browserify/browser";
+export default os;
+export var {
+ endianness,
+ hostname,
+ loadavg,
+ uptime,
+ freemem,
+ totalmem,
+ cpus,
+ type,
+ release,
+ arch,
+ platform,
+ tmpdir,
+ EOL,
+ homedir,
+ networkInterfaces,
+ getNetworkInterfaces,
+} = os;
diff --git a/src/node-fallbacks/package.json b/src/node-fallbacks/package.json
index 144f553c0..3d48960c5 100644
--- a/src/node-fallbacks/package.json
+++ b/src/node-fallbacks/package.json
@@ -5,8 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
- "build-gen": "esbuild --bundle *.js --outdir=bun --format=cjs --platform=browser --external:buffer --external:stream --external:util --external:util/ --external:assert",
- "build": "esbuild --bundle *.js --outdir=out --format=cjs --minify --platform=browser"
+ "build-gen": "esbuild --bundle *.js --outdir=bun --format=esm --platform=browser --external:buffer --external:stream --external:util --external:util/ --external:assert",
+ "build": "esbuild --bundle *.js --outdir=out --format=esm --minify --platform=browser"
},
"author": "",
"license": "ISC",
diff --git a/src/node-fallbacks/path.js b/src/node-fallbacks/path.js
index 558f820cc..a582c6d0f 100644
--- a/src/node-fallbacks/path.js
+++ b/src/node-fallbacks/path.js
@@ -1 +1,2 @@
export * from "path-browserify";
+export * as default from "path-browserify";
diff --git a/src/node-fallbacks/process.js b/src/node-fallbacks/process.js
index 74190ab67..fec4e652f 100644
--- a/src/node-fallbacks/process.js
+++ b/src/node-fallbacks/process.js
@@ -1 +1,2 @@
export * from "process/browser";
+export * as default from "process/browser";
diff --git a/src/node-fallbacks/querystring.js b/src/node-fallbacks/querystring.js
index ad7fd038d..00404cc1b 100644
--- a/src/node-fallbacks/querystring.js
+++ b/src/node-fallbacks/querystring.js
@@ -1 +1,2 @@
-export * from "querystring-es3";
+export { unescapeBuffer, unescape, escape, stringify, encode, parse, decode } from "querystring-es3";
+export { default } from "querystring-es3";
diff --git a/src/node-fallbacks/stream.js b/src/node-fallbacks/stream.js
index 381cbc761..bee941be1 100644
--- a/src/node-fallbacks/stream.js
+++ b/src/node-fallbacks/stream.js
@@ -1 +1,2 @@
export * from "readable-stream";
+export * as default from "readable-stream";
diff --git a/src/node-fallbacks/string_decoder.js b/src/node-fallbacks/string_decoder.js
index 90487c47e..c6fd8a2fd 100644
--- a/src/node-fallbacks/string_decoder.js
+++ b/src/node-fallbacks/string_decoder.js
@@ -1 +1,2 @@
export * from "string_decoder";
+export * as default from "string_decoder";
diff --git a/src/node-fallbacks/sys.js b/src/node-fallbacks/sys.js
index 4b20b6354..99f15c638 100644
--- a/src/node-fallbacks/sys.js
+++ b/src/node-fallbacks/sys.js
@@ -1 +1,2 @@
export * from "util";
+export * as default from "util";
diff --git a/src/node-fallbacks/timers.js b/src/node-fallbacks/timers.js
index a02f00701..c69274eef 100644
--- a/src/node-fallbacks/timers.js
+++ b/src/node-fallbacks/timers.js
@@ -1 +1,2 @@
export * from "timers-browserify";
+export * as default from "timers-browserify";
diff --git a/src/node-fallbacks/tsconfig.json b/src/node-fallbacks/tsconfig.json
index d1c7e7a71..1228b6423 100644
--- a/src/node-fallbacks/tsconfig.json
+++ b/src/node-fallbacks/tsconfig.json
@@ -12,7 +12,7 @@
"https": ["node_modules/https-browserify"],
"os": ["node_modules/os-browserify/browser"],
"path": ["node_modules/path-browserify"],
- "punycode": ["node_modules/punycode"],
+ "punycode": ["node_modules/punycode/punycode.es6.js"],
"process": ["node_modules/process/browser"],
"querystring": ["node_modules/querystring-es3"],
"stream": ["node_modules/stream-browserify"],
diff --git a/src/node-fallbacks/tty.js b/src/node-fallbacks/tty.js
index 49efb472e..727bdc5c6 100644
--- a/src/node-fallbacks/tty.js
+++ b/src/node-fallbacks/tty.js
@@ -1 +1,2 @@
export * from "tty-browserify";
+export * as default from "tty-browserify";
diff --git a/src/node-fallbacks/util.js b/src/node-fallbacks/util.js
index 3bd55da0a..1ad352a2a 100644
--- a/src/node-fallbacks/util.js
+++ b/src/node-fallbacks/util.js
@@ -4,3 +4,4 @@ const TextEncoder = globalThis.TextEncoder;
const TextDecoder = globalThis.TextDecoder;
export { TextEncoder, TextDecoder };
+export default { TextEncoder, TextDecoder };
diff --git a/src/node-fallbacks/zlib.js b/src/node-fallbacks/zlib.js
index 4af7ab847..093367e29 100644
--- a/src/node-fallbacks/zlib.js
+++ b/src/node-fallbacks/zlib.js
@@ -1 +1,2 @@
export * from "browserify-zlib";
+export * as default from "browserify-zlib";