aboutsummaryrefslogtreecommitdiff
path: root/src/node-fallbacks
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-03-02 19:02:10 -0800
committerGravatar GitHub <noreply@github.com> 2023-03-02 19:02:10 -0800
commit9388b3f8257bc2e580deaece4cd2677928104fc6 (patch)
tree3f6aff2009cef69897f599fe51305b894f81a376 /src/node-fallbacks
parentb469e5035161286abeb1a7726518d1afcc163a51 (diff)
downloadbun-9388b3f8257bc2e580deaece4cd2677928104fc6.tar.gz
bun-9388b3f8257bc2e580deaece4cd2677928104fc6.tar.zst
bun-9388b3f8257bc2e580deaece4cd2677928104fc6.zip
Add a zig fmt action (#2277)
* Add a zig fmt action * add failing file * Setup prettier better * Update prettier-fmt.yml * Fail on error * Update prettier-fmt.yml * boop * boop2 * tar.gz * Update zig-fmt.yml * Update zig-fmt.yml * Update zig-fmt.yml * Update zig-fmt.yml * Update zig-fmt.yml * boop * Update prettier-fmt.yml * tag * newlines * multiline * fixup * Update zig-fmt.yml * update it * fixup * both * w * Update prettier-fmt.yml * prettier all the things * Update package.json * zig fmt * ❌ ✅ * bump * . * quotes * fix prettier ignore * once more * Update prettier-fmt.yml * Update fallback.ts * consistentcy --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/node-fallbacks')
-rw-r--r--src/node-fallbacks/@vercel_fetch.js8
-rw-r--r--src/node-fallbacks/crypto.js15
-rw-r--r--src/node-fallbacks/events.js71
-rw-r--r--src/node-fallbacks/url.js81
4 files changed, 39 insertions, 136 deletions
diff --git a/src/node-fallbacks/@vercel_fetch.js b/src/node-fallbacks/@vercel_fetch.js
index f75604b2b..a8de45222 100644
--- a/src/node-fallbacks/@vercel_fetch.js
+++ b/src/node-fallbacks/@vercel_fetch.js
@@ -1,15 +1,11 @@
// 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,
-) => {
+module.exports = (wrapper = "Bun" in globalThis ? Bun.fetch : globalThis.fetch) => {
async function vercelFetch(url, opts = {}) {
// Convert Object bodies to JSON if they are JS objects
if (
opts.body &&
typeof opts.body === "object" &&
- (!("buffer" in opts.body) ||
- typeof opts.body.buffer !== "object" ||
- !(opts.body.buffer instanceof ArrayBuffer))
+ (!("buffer" in opts.body) || typeof opts.body.buffer !== "object" || !(opts.body.buffer instanceof ArrayBuffer))
) {
opts.body = JSON.stringify(opts.body);
// Content length will automatically be set
diff --git a/src/node-fallbacks/crypto.js b/src/node-fallbacks/crypto.js
index 4a0e4c735..8c83b6c87 100644
--- a/src/node-fallbacks/crypto.js
+++ b/src/node-fallbacks/crypto.js
@@ -3,7 +3,7 @@ export * from "crypto-browserify";
export var DEFAULT_ENCODING = "buffer";
// we deliberately reference crypto. directly here because we want to preserve the This binding
-export const getRandomValues = (array) => {
+export const getRandomValues = array => {
return crypto.getRandomValues(array);
};
@@ -16,10 +16,7 @@ export const timingSafeEqual =
? (a, b) => {
const { byteLength: byteLengthA } = a;
const { byteLength: byteLengthB } = b;
- if (
- typeof byteLengthA !== "number" ||
- typeof byteLengthB !== "number"
- ) {
+ if (typeof byteLengthA !== "number" || typeof byteLengthB !== "number") {
throw new TypeError("Input must be an array buffer view");
}
@@ -37,9 +34,7 @@ export const scryptSync =
"scryptSync" in crypto
? (password, salt, keylen, options) => {
const res = crypto.scryptSync(password, salt, keylen, options);
- return DEFAULT_ENCODING !== "buffer"
- ? new Buffer(res).toString(DEFAULT_ENCODING)
- : new Buffer(res);
+ return DEFAULT_ENCODING !== "buffer" ? new Buffer(res).toString(DEFAULT_ENCODING) : new Buffer(res);
}
: undefined;
@@ -62,9 +57,7 @@ export const scrypt =
process.nextTick(
callback,
null,
- DEFAULT_ENCODING !== "buffer"
- ? new Buffer(result).toString(DEFAULT_ENCODING)
- : new Buffer(result),
+ DEFAULT_ENCODING !== "buffer" ? new Buffer(result).toString(DEFAULT_ENCODING) : new Buffer(result),
);
} catch (err) {
throw err;
diff --git a/src/node-fallbacks/events.js b/src/node-fallbacks/events.js
index 738bf1f15..70f47eb53 100644
--- a/src/node-fallbacks/events.js
+++ b/src/node-fallbacks/events.js
@@ -34,9 +34,7 @@ if (R && typeof R.ownKeys === "function") {
ReflectOwnKeys = R.ownKeys;
} else if (Object.getOwnPropertySymbols) {
ReflectOwnKeys = function ReflectOwnKeys(target) {
- return Object.getOwnPropertyNames(target).concat(
- Object.getOwnPropertySymbols(target),
- );
+ return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target));
};
} else {
ReflectOwnKeys = function ReflectOwnKeys(target) {
@@ -71,10 +69,7 @@ var defaultMaxListeners = 10;
function checkListener(listener) {
if (typeof listener !== "function") {
- throw new TypeError(
- 'The "listener" argument must be of type Function. Received type ' +
- typeof listener,
- );
+ throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
}
}
@@ -86,9 +81,7 @@ Object.defineProperty(EventEmitter, "defaultMaxListeners", {
set: function (arg) {
if (typeof arg !== "number" || arg < 0 || NumberIsNaN(arg)) {
throw new RangeError(
- 'The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' +
- arg +
- ".",
+ 'The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + ".",
);
}
defaultMaxListeners = arg;
@@ -96,10 +89,7 @@ Object.defineProperty(EventEmitter, "defaultMaxListeners", {
});
EventEmitter.init = function () {
- if (
- this._events === undefined ||
- this._events === Object.getPrototypeOf(this)._events
- ) {
+ if (this._events === undefined || this._events === Object.getPrototypeOf(this)._events) {
this._events = Object.create(null);
this._eventsCount = 0;
}
@@ -111,11 +101,7 @@ EventEmitter.init = function () {
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
if (typeof n !== "number" || n < 0 || NumberIsNaN(n)) {
- throw new RangeError(
- 'The value of "n" is out of range. It must be a non-negative number. Received ' +
- n +
- ".",
- );
+ throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + ".");
}
this._maxListeners = n;
return this;
@@ -149,9 +135,7 @@ EventEmitter.prototype.emit = function emit(type) {
throw er; // Unhandled 'error' event
}
// At least give some kind of context to the user
- var err = new Error(
- "Unhandled error." + (er ? " (" + er.message + ")" : ""),
- );
+ var err = new Error("Unhandled error." + (er ? " (" + er.message + ")" : ""));
err.context = er;
throw err; // Unhandled 'error' event
}
@@ -186,11 +170,7 @@ function _addListener(target, type, listener, prepend) {
// To avoid recursion in the case that type === "newListener"! Before
// adding it to the listeners, first emit "newListener".
if (events.newListener !== undefined) {
- target.emit(
- "newListener",
- type,
- listener.listener ? listener.listener : listener,
- );
+ target.emit("newListener", type, listener.listener ? listener.listener : listener);
// Re-assign `events` because a newListener handler could have caused the
// this._events to be assigned to a new object
@@ -206,9 +186,7 @@ function _addListener(target, type, listener, prepend) {
} else {
if (typeof existing === "function") {
// Adding the second element, need to change to array.
- existing = events[type] = prepend
- ? [listener, existing]
- : [existing, listener];
+ existing = events[type] = prepend ? [listener, existing] : [existing, listener];
// If we've already got an array, just append.
} else if (prepend) {
existing.unshift(listener);
@@ -248,10 +226,7 @@ EventEmitter.prototype.addListener = function addListener(type, listener) {
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
-EventEmitter.prototype.prependListener = function prependListener(
- type,
- listener,
-) {
+EventEmitter.prototype.prependListener = function prependListener(type, listener) {
return _addListener(this, type, listener, true);
};
@@ -284,20 +259,14 @@ EventEmitter.prototype.once = function once(type, listener) {
return this;
};
-EventEmitter.prototype.prependOnceListener = function prependOnceListener(
- type,
- listener,
-) {
+EventEmitter.prototype.prependOnceListener = function prependOnceListener(type, listener) {
checkListener(listener);
this.prependListener(type, _onceWrap(this, type, listener));
return this;
};
// Emits a 'removeListener' event if and only if the listener was removed.
-EventEmitter.prototype.removeListener = function removeListener(
- type,
- listener,
-) {
+EventEmitter.prototype.removeListener = function removeListener(type, listener) {
var list, events, position, i, originalListener;
checkListener(listener);
@@ -312,8 +281,7 @@ EventEmitter.prototype.removeListener = function removeListener(
if (--this._eventsCount === 0) this._events = Object.create(null);
else {
delete events[type];
- if (events.removeListener)
- this.emit("removeListener", type, list.listener || listener);
+ if (events.removeListener) this.emit("removeListener", type, list.listener || listener);
}
} else if (typeof list !== "function") {
position = -1;
@@ -335,8 +303,7 @@ EventEmitter.prototype.removeListener = function removeListener(
if (list.length === 1) events[type] = list[0];
- if (events.removeListener !== undefined)
- this.emit("removeListener", type, originalListener || listener);
+ if (events.removeListener !== undefined) this.emit("removeListener", type, originalListener || listener);
}
return this;
@@ -399,12 +366,9 @@ function _listeners(target, type, unwrap) {
var evlistener = events[type];
if (evlistener === undefined) return [];
- if (typeof evlistener === "function")
- return unwrap ? [evlistener.listener || evlistener] : [evlistener];
+ if (typeof evlistener === "function") return unwrap ? [evlistener.listener || evlistener] : [evlistener];
- return unwrap
- ? unwrapListeners(evlistener)
- : arrayClone(evlistener, evlistener.length);
+ return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
}
EventEmitter.prototype.listeners = function listeners(type) {
@@ -509,10 +473,7 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
listener(arg);
});
} else {
- throw new TypeError(
- 'The "emitter" argument must be of type EventEmitter. Received type ' +
- typeof emitter,
- );
+ throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
}
}
diff --git a/src/node-fallbacks/url.js b/src/node-fallbacks/url.js
index 10f1b889a..81c78001d 100644
--- a/src/node-fallbacks/url.js
+++ b/src/node-fallbacks/url.js
@@ -203,10 +203,7 @@ Url.prototype.parse = function (url, parseQueryString, slashesDenoteHost) {
}
}
- if (
- !hostlessProtocol[proto] &&
- (slashes || (proto && !slashedProtocol[proto]))
- ) {
+ if (!hostlessProtocol[proto] && (slashes || (proto && !slashedProtocol[proto]))) {
// there's a hostname.
// the first instance of /, ?, ;, or # ends the host.
//
@@ -270,9 +267,7 @@ Url.prototype.parse = function (url, parseQueryString, slashesDenoteHost) {
// if hostname begins with [ and ends with ]
// assume that it's an IPv6 address.
- var ipv6Hostname =
- this.hostname[0] === "[" &&
- this.hostname[this.hostname.length - 1] === "]";
+ var ipv6Hostname = this.hostname[0] === "[" && this.hostname[this.hostname.length - 1] === "]";
// validate a little.
if (!ipv6Hostname) {
@@ -423,21 +418,13 @@ Url.prototype.format = function () {
if (this.host) {
host = auth + this.host;
} else if (this.hostname) {
- host =
- auth +
- (this.hostname.indexOf(":") === -1
- ? this.hostname
- : "[" + this.hostname + "]");
+ host = auth + (this.hostname.indexOf(":") === -1 ? this.hostname : "[" + this.hostname + "]");
if (this.port) {
host += ":" + this.port;
}
}
- if (
- this.query &&
- util_isObject(this.query) &&
- Object.keys(this.query).length
- ) {
+ if (this.query && util_isObject(this.query) && Object.keys(this.query).length) {
query = querystring.stringify(this.query);
}
@@ -447,10 +434,7 @@ Url.prototype.format = function () {
// only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
// unless they had them to begin with.
- if (
- this.slashes ||
- ((!protocol || slashedProtocol[protocol]) && host !== false)
- ) {
+ if (this.slashes || ((!protocol || slashedProtocol[protocol]) && host !== false)) {
host = "//" + (host || "");
if (pathname && pathname.charAt(0) !== "/") pathname = "/" + pathname;
} else if (!host) {
@@ -515,11 +499,7 @@ Url.prototype.resolveObject = function (relative) {
}
//urlParse appends trailing / to urls like http://www.example.com
- if (
- slashedProtocol[result.protocol] &&
- result.hostname &&
- !result.pathname
- ) {
+ if (slashedProtocol[result.protocol] && result.hostname && !result.pathname) {
result.path = result.pathname = "/";
}
@@ -576,9 +556,7 @@ Url.prototype.resolveObject = function (relative) {
}
var isSourceAbs = result.pathname && result.pathname.charAt(0) === "/",
- isRelAbs =
- relative.host ||
- (relative.pathname && relative.pathname.charAt(0) === "/"),
+ isRelAbs = relative.host || (relative.pathname && relative.pathname.charAt(0) === "/"),
mustEndAbs = isRelAbs || isSourceAbs || (result.host && relative.pathname),
removeAllDots = mustEndAbs,
srcPath = (result.pathname && result.pathname.split("/")) || [],
@@ -612,12 +590,8 @@ Url.prototype.resolveObject = function (relative) {
if (isRelAbs) {
// it's absolute.
- result.host =
- relative.host || relative.host === "" ? relative.host : result.host;
- result.hostname =
- relative.hostname || relative.hostname === ""
- ? relative.hostname
- : result.hostname;
+ result.host = relative.host || relative.host === "" ? relative.host : result.host;
+ result.hostname = relative.hostname || relative.hostname === "" ? relative.hostname : result.hostname;
result.search = relative.search;
result.query = relative.query;
srcPath = relPath;
@@ -639,10 +613,7 @@ Url.prototype.resolveObject = function (relative) {
//occationaly the auth can get stuck only in host
//this especially happens in cases like
//url.resolveObject('mailto:local1@domain1', 'local2@domain2')
- var authInHost =
- result.host && result.host.indexOf("@") > 0
- ? result.host.split("@")
- : false;
+ var authInHost = result.host && result.host.indexOf("@") > 0 ? result.host.split("@") : false;
if (authInHost) {
result.auth = authInHost.shift();
result.host = result.hostname = authInHost.shift();
@@ -652,9 +623,7 @@ Url.prototype.resolveObject = function (relative) {
result.query = relative.query;
//to support http.request
if (!util_isNull(result.pathname) || !util_isNull(result.search)) {
- result.path =
- (result.pathname ? result.pathname : "") +
- (result.search ? result.search : "");
+ result.path = (result.pathname ? result.pathname : "") + (result.search ? result.search : "");
}
result.href = result.format();
return result;
@@ -679,9 +648,7 @@ Url.prototype.resolveObject = function (relative) {
// then it must NOT get a trailing slash.
var last = srcPath.slice(-1)[0];
var hasTrailingSlash =
- ((result.host || relative.host || srcPath.length > 1) &&
- (last === "." || last === "..")) ||
- last === "";
+ ((result.host || relative.host || srcPath.length > 1) && (last === "." || last === "..")) || last === "";
// strip single dots, resolve double dots to parent dir
// if the path tries to go above the root, `up` ends up > 0
@@ -706,11 +673,7 @@ Url.prototype.resolveObject = function (relative) {
}
}
- if (
- mustEndAbs &&
- srcPath[0] !== "" &&
- (!srcPath[0] || srcPath[0].charAt(0) !== "/")
- ) {
+ if (mustEndAbs && srcPath[0] !== "" && (!srcPath[0] || srcPath[0].charAt(0) !== "/")) {
srcPath.unshift("");
}
@@ -718,23 +681,15 @@ Url.prototype.resolveObject = function (relative) {
srcPath.push("");
}
- var isAbsolute =
- srcPath[0] === "" || (srcPath[0] && srcPath[0].charAt(0) === "/");
+ var isAbsolute = srcPath[0] === "" || (srcPath[0] && srcPath[0].charAt(0) === "/");
// put the host back
if (psychotic) {
- result.hostname = result.host = isAbsolute
- ? ""
- : srcPath.length
- ? srcPath.shift()
- : "";
+ result.hostname = result.host = isAbsolute ? "" : srcPath.length ? srcPath.shift() : "";
//occationaly the auth can get stuck only in host
//this especially happens in cases like
//url.resolveObject('mailto:local1@domain1', 'local2@domain2')
- var authInHost =
- result.host && result.host.indexOf("@") > 0
- ? result.host.split("@")
- : false;
+ var authInHost = result.host && result.host.indexOf("@") > 0 ? result.host.split("@") : false;
if (authInHost) {
result.auth = authInHost.shift();
result.host = result.hostname = authInHost.shift();
@@ -756,9 +711,7 @@ Url.prototype.resolveObject = function (relative) {
//to support request.http
if (!util_isNull(result.pathname) || !util_isNull(result.search)) {
- result.path =
- (result.pathname ? result.pathname : "") +
- (result.search ? result.search : "");
+ result.path = (result.pathname ? result.pathname : "") + (result.search ? result.search : "");
}
result.auth = relative.auth || result.auth;
result.slashes = result.slashes || relative.slashes;