aboutsummaryrefslogtreecommitdiff
path: root/src/js/builtins/ProcessObjectInternals.ts
diff options
context:
space:
mode:
authorGravatar dave caruso <me@paperdave.net> 2023-08-02 16:27:36 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-02 16:27:36 -0700
commitc2a77cf7ec9de9eadf938046bdf78e58561c8a6d (patch)
tree0f90f1b323061455875333c9f40592b303585973 /src/js/builtins/ProcessObjectInternals.ts
parent7656b4b17e91f15b58eeab8f45b78c416ec6a045 (diff)
downloadbun-c2a77cf7ec9de9eadf938046bdf78e58561c8a6d.tar.gz
bun-c2a77cf7ec9de9eadf938046bdf78e58561c8a6d.tar.zst
bun-c2a77cf7ec9de9eadf938046bdf78e58561c8a6d.zip
Rewrite built-in modules to use CommonJS over ESM (#3814)
* stfdsafsd sadffdsa stuff finish commonjs stuff asdf not done but work not done but work not done yet but this is how far i am remove files lol update built files uncomment everything in events lol export default stuff * afdsafsd * its not perfect but almost done * okay * cool * remove temp file * finish rebase * revert settings.json * a * ch-ch-ch-ch-changes * okay * remove this check in release for now * sxdcfghnjm, * lkjhgf * fmt * filename can be null * Update NodeModuleModule.h * weee * fmt --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/js/builtins/ProcessObjectInternals.ts')
-rw-r--r--src/js/builtins/ProcessObjectInternals.ts53
1 files changed, 17 insertions, 36 deletions
diff --git a/src/js/builtins/ProcessObjectInternals.ts b/src/js/builtins/ProcessObjectInternals.ts
index f6990dc5e..fc6b3800f 100644
--- a/src/js/builtins/ProcessObjectInternals.ts
+++ b/src/js/builtins/ProcessObjectInternals.ts
@@ -23,38 +23,29 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+// TODO: move this to native code?
export function binding(bindingName) {
- if (bindingName !== "constants")
- throw new TypeError(
- "process.binding() is not supported in Bun. If that breaks something, please file an issue and include a reproducible code sample.",
+ if (bindingName === "constants") {
+ return $processBindingConstants;
+ }
+ const issue = {
+ fs: 3546,
+ buffer: 2020,
+ natives: 2254,
+ uv: 2891,
+ }[bindingName];
+ if (issue) {
+ throw new Error(
+ `process.binding("${bindingName}") is not implemented in Bun. Track the status & thumbs up the issue: https://github.com/oven-sh/bun/issues/${issue}`,
);
-
- var cache = globalThis.Symbol.for("process.bindings.constants");
- var constants = globalThis[cache];
- if (!constants) {
- // TODO: make this less hacky.
- // This calls require("node:fs").constants
- // except, outside an ESM module.
- const { constants: fs } = $lazy("createImportMeta", "node:process").require("node:fs");
- constants = {
- fs,
- zlib: {},
- crypto: {},
- os: Bun._Os().constants,
- };
- globalThis[cache] = constants;
}
- return constants;
+ throw new TypeError(
+ `process.binding("${bindingName}") is not implemented in Bun. If that breaks something, please file an issue and include a reproducible code sample.`,
+ );
}
export function getStdioWriteStream(fd_, getWindowSize) {
- var require = path => {
- var existing = $requireMap.get(path);
- if (existing) return existing.exports;
-
- return $internalRequire(path);
- };
- var module = { path: "node:process", require };
+ var EventEmitter = require("node:events");
function createStdioWriteStream(fd_) {
var { Duplex, eos, destroy } = require("node:stream");
@@ -213,8 +204,6 @@ export function getStdioWriteStream(fd_, getWindowSize) {
return new StdioWriteStream(fd_);
}
- var { EventEmitter } = require("node:events");
-
function isFastEncoding(encoding) {
if (!encoding) return true;
@@ -499,14 +488,6 @@ export function getStdioWriteStream(fd_, getWindowSize) {
}
export function getStdinStream(fd_) {
- var require = path => {
- var existing = $requireMap.get(path);
- if (existing) return existing.exports;
-
- return $internalRequire(path);
- };
-
- var module = { path: "node:process", require: require };
var { Duplex, eos, destroy } = require("node:stream");
var StdinStream = class StdinStream extends Duplex {