Bundle and minify .exports.js files. (#3036)

* move all exports.js into src/js

* finalize the sort of this

* and it works

* add test.ts to gitignore

* okay

* convert some to ts just to show

* finish up

* fixup makefile

* minify syntax in dev

* finish rebase

* dont minify all modules

* merge

* finish rebase merge

* flaky test that hangs
This commit is contained in:
dave caruso
2023-06-01 21:16:47 -04:00
committed by GitHub
parent 03ffd1c732
commit 4df1d37ddc
250 changed files with 49064 additions and 1298 deletions

2
.gitignore vendored
View File

@@ -119,3 +119,5 @@ myscript.sh
cold-jsc-start
cold-jsc-start.d
/test.ts

View File

@@ -1,6 +1,6 @@
src/fallback.html
src/bun.js/WebKit
src/bun.js/builtins/js/*.js
src/js/out
src/*.out.js
src/*out.*.js
src/deps
@@ -11,4 +11,3 @@ test/snapshots-no-hmr
test/js/deno/*.test.ts
test/js/deno/**/*.test.ts
bench/react-hello-world/react-hello-world.node.js
src/bun.js/builtins/WebCoreJSBuiltins.d.ts

View File

@@ -15,8 +15,8 @@
"${workspaceFolder}/src/bun.js/bindings/webcore/",
"${workspaceFolder}/src/bun.js/bindings/sqlite/",
"${workspaceFolder}/src/bun.js/bindings/webcrypto/",
"${workspaceFolder}/src/bun.js/builtins/",
"${workspaceFolder}/src/bun.js/builtins/cpp",
"${workspaceFolder}/src/js/builtins/",
"${workspaceFolder}/src/js/out",
"${workspaceFolder}/src/deps/boringssl/include/",
"${workspaceFolder}/src/deps",
"${workspaceFolder}/src/deps/uws/uSockets/src"
@@ -34,8 +34,8 @@
"${workspaceFolder}/src/bun.js/bindings/sqlite/",
"${workspaceFolder}/src/bun.js/bindings/webcrypto/",
"${workspaceFolder}/src/bun.js/bindings/webcore/",
"${workspaceFolder}/src/bun.js/builtins/*",
"${workspaceFolder}/src/bun.js/builtins/cpp/*",
"${workspaceFolder}/src/js/builtins/*",
"${workspaceFolder}/src/js/out/*",
"${workspaceFolder}/src/bun.js/modules/*",
"${workspaceFolder}/src/deps",
"${workspaceFolder}/src/deps/boringssl/include/",

19
.vscode/settings.json vendored
View File

@@ -37,8 +37,6 @@
"[yaml]": {
"editor.formatOnSave": true
},
"zig.beforeDebugCmd": "make build-unit ${file} ${filter} ${bin}",
"zig.testCmd": "make test ${file} ${filter} ${bin}",
"[markdown]": {
"editor.unicodeHighlight.ambiguousCharacters": false,
"editor.unicodeHighlight.invisibleCharacters": false,
@@ -78,7 +76,8 @@
"src/deps/c-ares": true,
"src/deps/tinycc": true,
"src/deps/zstd": true,
"test/snippets/package-json-exports/_node_modules_copy": true
"test/snippets/package-json-exports/_node_modules_copy": true,
"src/js/out": true
},
"C_Cpp.files.exclude": {
"**/.vscode": true,
@@ -108,11 +107,6 @@
"editor.defaultFormatter": "xaver.clang-format"
},
"files.associations": {
"*.{setting,comp,fuse,fu}": "lua",
"*.ctk": "json",
"*.json5": "json5",
"*.json": "jsonc",
"*.scriptlib": "lua",
"*.lock": "yarnlock",
"*.idl": "cpp",
"memory": "cpp",
@@ -221,14 +215,7 @@
"regex": "cpp",
"span": "cpp",
"valarray": "cpp",
"codecvt": "cpp",
"hash_map": "cpp",
"source_location": "cpp",
"numbers": "cpp",
"semaphore": "cpp",
"stdfloat": "cpp",
"stop_token": "cpp",
"cfenv": "cpp"
"codecvt": "cpp"
},
"cmake.configureOnOpen": false,
"C_Cpp.errorSquiggles": "enabled",

View File

@@ -59,7 +59,9 @@ The module loader is in [`src/bun.js/module_loader.zig`](src/bun.js/module_loade
### JavaScript Builtins
JavaScript builtins are located in [`src/bun.js/builtins/*.js`](src/bun.js/builtins).
TODO: update this with the new build process that uses TypeScript and `$` instead of `@`.
JavaScript builtins are located in [`src/js/builtins/*.ts`](src/js/builtins).
These files support a JavaScriptCore-only syntax for internal slots. `@` is used to access an internal slot. For example: `new @Array(123)` will create a new `Array` similar to `new Array(123)`, except if a library modifies the `Array` global, it will not affect the internal slot (`@Array`). These names must be allow-listed in `BunBuiltinNames.h` (though JavaScriptCore allowlists some names by default).

View File

@@ -293,14 +293,14 @@ SRC_WEBCORE_FILES := $(wildcard $(SRC_DIR)/webcore/*.cpp)
SRC_SQLITE_FILES := $(wildcard $(SRC_DIR)/sqlite/*.cpp)
SRC_NODE_OS_FILES := $(wildcard $(SRC_DIR)/node_os/*.cpp)
SRC_IO_FILES := $(wildcard src/io/*.cpp)
SRC_BUILTINS_FILES := $(wildcard src/bun.js/builtins/*.cpp)
SRC_BUILTINS_FILES := $(wildcard src/js/out/*.cpp)
SRC_WEBCRYPTO_FILES := $(wildcard $(SRC_DIR)/webcrypto/*.cpp)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRC_FILES))
WEBCORE_OBJ_FILES := $(patsubst $(SRC_DIR)/webcore/%.cpp,$(OBJ_DIR)/%.o,$(SRC_WEBCORE_FILES))
SQLITE_OBJ_FILES := $(patsubst $(SRC_DIR)/sqlite/%.cpp,$(OBJ_DIR)/%.o,$(SRC_SQLITE_FILES))
NODE_OS_OBJ_FILES := $(patsubst $(SRC_DIR)/node_os/%.cpp,$(OBJ_DIR)/%.o,$(SRC_NODE_OS_FILES))
BUILTINS_OBJ_FILES := $(patsubst src/bun.js/builtins/%.cpp,$(OBJ_DIR)/%.o,$(SRC_BUILTINS_FILES))
BUILTINS_OBJ_FILES := $(patsubst src/js/out/%.cpp,$(OBJ_DIR)/%.o,$(SRC_BUILTINS_FILES))
IO_FILES := $(patsubst src/io/%.cpp,$(OBJ_DIR)/%.o,$(SRC_IO_FILES))
MODULES_OBJ_FILES := $(patsubst $(MODULES_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(MODULES_FILES))
WEBCRYPTO_OBJ_FILES := $(patsubst $(SRC_DIR)/webcrypto/%.cpp,$(OBJ_DIR)/%.o,$(SRC_WEBCRYPTO_FILES))
@@ -309,7 +309,7 @@ DEBUG_OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp,$(DEBUG_OBJ_DIR)/%.o,$(SRC_FILES)
DEBUG_WEBCORE_OBJ_FILES := $(patsubst $(SRC_DIR)/webcore/%.cpp,$(DEBUG_OBJ_DIR)/%.o,$(SRC_WEBCORE_FILES))
DEBUG_SQLITE_OBJ_FILES := $(patsubst $(SRC_DIR)/sqlite/%.cpp,$(DEBUG_OBJ_DIR)/%.o,$(SRC_SQLITE_FILES))
DEBUG_NODE_OS_OBJ_FILES := $(patsubst $(SRC_DIR)/node_os/%.cpp,$(DEBUG_OBJ_DIR)/%.o,$(SRC_NODE_OS_FILES))
DEBUG_BUILTINS_OBJ_FILES := $(patsubst src/bun.js/builtins/%.cpp,$(DEBUG_OBJ_DIR)/%.o,$(SRC_BUILTINS_FILES))
DEBUG_BUILTINS_OBJ_FILES := $(patsubst src/js/out/%.cpp,$(DEBUG_OBJ_DIR)/%.o,$(SRC_BUILTINS_FILES))
DEBUG_IO_FILES := $(patsubst src/io/%.cpp,$(DEBUG_OBJ_DIR)/%.o,$(SRC_IO_FILES))
DEBUG_MODULES_OBJ_FILES := $(patsubst $(MODULES_DIR)/%.cpp,$(DEBUG_OBJ_DIR)/%.o,$(MODULES_FILES))
DEBUG_WEBCRYPTO_OBJ_FILES := $(patsubst $(SRC_DIR)/webcrypto/%.cpp, $(DEBUG_OBJ_DIR)/%.o, $(SRC_WEBCRYPTO_FILES))
@@ -330,12 +330,12 @@ ALL_JSC_INCLUDE_DIRS := -I$(WEBKIT_RELEASE_DIR)/WTF/Headers \
-I$(WEBKIT_RELEASE_DIR)/WTF/PrivateHeaders
SHARED_INCLUDE_DIR = -I$(realpath src/bun.js/bindings)/ \
-I$(realpath src/bun.js/builtins/) \
-I$(realpath src/js/builtins/) \
-I$(realpath src/js/out/) \
-I$(realpath src/bun.js/bindings) \
-I$(realpath src/bun.js/bindings/webcore) \
-I$(realpath src/bun.js/bindings/webcrypto) \
-I$(realpath src/bun.js/bindings/sqlite) \
-I$(realpath src/bun.js/builtins/cpp) \
-I$(realpath src/bun.js/bindings/node_os) \
-I$(realpath src/bun.js/modules) \
-I$(JSC_INCLUDE_DIR)
@@ -555,7 +555,11 @@ PYTHON=$(shell which python 2>/dev/null || which python3 2>/dev/null || which py
.PHONY: builtins
builtins:
bun src/bun.js/builtins/codegen/index.ts --minify
NODE_ENV=production bun src/js/builtins/codegen/index.ts --minify
.PHONY: hardcoded
hardcoded:
NODE_ENV=production bun src/js/build-hardcoded.ts
.PHONY: generate-builtins
generate-builtins: builtins
@@ -1532,7 +1536,7 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/node_os/%.cpp
$(EMIT_LLVM) \
-c -o $@ $<
$(OBJ_DIR)/%.o: src/bun.js/builtins/%.cpp
$(OBJ_DIR)/%.o: src/js/out/%.cpp
$(CXX_WITH_CCACHE) $(CLANG_FLAGS) \
$(MACOS_MIN_FLAG) \
$(OPTIMIZATION_LEVEL) \
@@ -1631,8 +1635,8 @@ $(DEBUG_OBJ_DIR)/%.o: $(SRC_DIR)/node_os/%.cpp
# $(DEBUG_OBJ_DIR) is not included here because it breaks
# detecting if a file needs to be rebuilt
.PHONY: src/bun.js/builtins/%.cpp
$(DEBUG_OBJ_DIR)/%.o: src/bun.js/builtins/%.cpp
.PHONY: src/js/out/builtins/%.cpp
$(DEBUG_OBJ_DIR)/%.o: src/js/out/%.cpp
$(CXX_WITH_CCACHE) $(CLANG_FLAGS) \
$(MACOS_MIN_FLAG) \
$(DEBUG_OPTIMIZATION_LEVEL) \
@@ -1875,7 +1879,7 @@ regenerate-bindings:
@make bindings -j$(CPU_COUNT)
.PHONY: setup
setup: vendor-dev builtins identifier-cache clean-bindings
setup: vendor-dev identifier-cache clean-bindings
make jsc-check
make bindings -j$(CPU_COUNT)
@echo ""

View File

@@ -104,13 +104,13 @@ VSCode is the recommended IDE for working on Bun, as it has been configured. Onc
## JavaScript builtins
When you change anything in `src/bun.js/builtins/js/*` or switch branches, run this:
When you change anything in `src/js/builtins/*` or switch branches, run this:
```bash
$ make regenerate-bindings
```
That inlines the JavaScript code into C++ headers using the same builtins generator script that Safari uses.
That inlines the TypeScript code into C++ headers.
{% callout %}
Make sure you have `ccache` installed, otherwise regeneration will take much longer than it should.

View File

@@ -222,7 +222,7 @@ pub const ResolvedSource = extern struct {
@"node:buffer" = 1024,
@"node:process" = 1025,
@"bun:events_native" = 1026,
@"bun:events_native" = 1026, // native version of EventEmitter used for streams
@"node:string_decoder" = 1027,
@"node:module" = 1028,
@"node:tty" = 1029,

View File

@@ -1,199 +0,0 @@
// Generated by `bun src/bun.js/builtins/codegen/index.js`
// Do not edit by hand.
type RemoveThis<F> = F extends (this: infer T, ...args: infer A) => infer R ? (...args: A) => R : F;
// WritableStreamInternals.ts
declare const $isWritableStream: RemoveThis<typeof import("./ts/WritableStreamInternals")["isWritableStream"]>;
declare const $isWritableStreamDefaultWriter: RemoveThis<typeof import("./ts/WritableStreamInternals")["isWritableStreamDefaultWriter"]>;
declare const $acquireWritableStreamDefaultWriter: RemoveThis<typeof import("./ts/WritableStreamInternals")["acquireWritableStreamDefaultWriter"]>;
declare const $createWritableStream: RemoveThis<typeof import("./ts/WritableStreamInternals")["createWritableStream"]>;
declare const $createInternalWritableStreamFromUnderlyingSink: RemoveThis<typeof import("./ts/WritableStreamInternals")["createInternalWritableStreamFromUnderlyingSink"]>;
declare const $initializeWritableStreamSlots: RemoveThis<typeof import("./ts/WritableStreamInternals")["initializeWritableStreamSlots"]>;
declare const $writableStreamCloseForBindings: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamCloseForBindings"]>;
declare const $writableStreamAbortForBindings: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamAbortForBindings"]>;
declare const $isWritableStreamLocked: RemoveThis<typeof import("./ts/WritableStreamInternals")["isWritableStreamLocked"]>;
declare const $setUpWritableStreamDefaultWriter: RemoveThis<typeof import("./ts/WritableStreamInternals")["setUpWritableStreamDefaultWriter"]>;
declare const $writableStreamAbort: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamAbort"]>;
declare const $writableStreamClose: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamClose"]>;
declare const $writableStreamAddWriteRequest: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamAddWriteRequest"]>;
declare const $writableStreamCloseQueuedOrInFlight: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamCloseQueuedOrInFlight"]>;
declare const $writableStreamDealWithRejection: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDealWithRejection"]>;
declare const $writableStreamFinishErroring: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamFinishErroring"]>;
declare const $writableStreamFinishInFlightClose: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamFinishInFlightClose"]>;
declare const $writableStreamFinishInFlightCloseWithError: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamFinishInFlightCloseWithError"]>;
declare const $writableStreamFinishInFlightWrite: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamFinishInFlightWrite"]>;
declare const $writableStreamFinishInFlightWriteWithError: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamFinishInFlightWriteWithError"]>;
declare const $writableStreamHasOperationMarkedInFlight: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamHasOperationMarkedInFlight"]>;
declare const $writableStreamMarkCloseRequestInFlight: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamMarkCloseRequestInFlight"]>;
declare const $writableStreamMarkFirstWriteRequestInFlight: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamMarkFirstWriteRequestInFlight"]>;
declare const $writableStreamRejectCloseAndClosedPromiseIfNeeded: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamRejectCloseAndClosedPromiseIfNeeded"]>;
declare const $writableStreamStartErroring: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamStartErroring"]>;
declare const $writableStreamUpdateBackpressure: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamUpdateBackpressure"]>;
declare const $writableStreamDefaultWriterAbort: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultWriterAbort"]>;
declare const $writableStreamDefaultWriterClose: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultWriterClose"]>;
declare const $writableStreamDefaultWriterCloseWithErrorPropagation: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultWriterCloseWithErrorPropagation"]>;
declare const $writableStreamDefaultWriterEnsureClosedPromiseRejected: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultWriterEnsureClosedPromiseRejected"]>;
declare const $writableStreamDefaultWriterEnsureReadyPromiseRejected: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultWriterEnsureReadyPromiseRejected"]>;
declare const $writableStreamDefaultWriterGetDesiredSize: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultWriterGetDesiredSize"]>;
declare const $writableStreamDefaultWriterRelease: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultWriterRelease"]>;
declare const $writableStreamDefaultWriterWrite: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultWriterWrite"]>;
declare const $setUpWritableStreamDefaultController: RemoveThis<typeof import("./ts/WritableStreamInternals")["setUpWritableStreamDefaultController"]>;
declare const $writableStreamDefaultControllerStart: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultControllerStart"]>;
declare const $setUpWritableStreamDefaultControllerFromUnderlyingSink: RemoveThis<typeof import("./ts/WritableStreamInternals")["setUpWritableStreamDefaultControllerFromUnderlyingSink"]>;
declare const $writableStreamDefaultControllerAdvanceQueueIfNeeded: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultControllerAdvanceQueueIfNeeded"]>;
declare const $isCloseSentinel: RemoveThis<typeof import("./ts/WritableStreamInternals")["isCloseSentinel"]>;
declare const $writableStreamDefaultControllerClearAlgorithms: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultControllerClearAlgorithms"]>;
declare const $writableStreamDefaultControllerClose: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultControllerClose"]>;
declare const $writableStreamDefaultControllerError: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultControllerError"]>;
declare const $writableStreamDefaultControllerErrorIfNeeded: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultControllerErrorIfNeeded"]>;
declare const $writableStreamDefaultControllerGetBackpressure: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultControllerGetBackpressure"]>;
declare const $writableStreamDefaultControllerGetChunkSize: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultControllerGetChunkSize"]>;
declare const $writableStreamDefaultControllerGetDesiredSize: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultControllerGetDesiredSize"]>;
declare const $writableStreamDefaultControllerProcessClose: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultControllerProcessClose"]>;
declare const $writableStreamDefaultControllerProcessWrite: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultControllerProcessWrite"]>;
declare const $writableStreamDefaultControllerWrite: RemoveThis<typeof import("./ts/WritableStreamInternals")["writableStreamDefaultControllerWrite"]>;
// TransformStreamInternals.ts
declare const $isTransformStream: RemoveThis<typeof import("./ts/TransformStreamInternals")["isTransformStream"]>;
declare const $isTransformStreamDefaultController: RemoveThis<typeof import("./ts/TransformStreamInternals")["isTransformStreamDefaultController"]>;
declare const $createTransformStream: RemoveThis<typeof import("./ts/TransformStreamInternals")["createTransformStream"]>;
declare const $initializeTransformStream: RemoveThis<typeof import("./ts/TransformStreamInternals")["initializeTransformStream"]>;
declare const $transformStreamError: RemoveThis<typeof import("./ts/TransformStreamInternals")["transformStreamError"]>;
declare const $transformStreamErrorWritableAndUnblockWrite: RemoveThis<typeof import("./ts/TransformStreamInternals")["transformStreamErrorWritableAndUnblockWrite"]>;
declare const $transformStreamSetBackpressure: RemoveThis<typeof import("./ts/TransformStreamInternals")["transformStreamSetBackpressure"]>;
declare const $setUpTransformStreamDefaultController: RemoveThis<typeof import("./ts/TransformStreamInternals")["setUpTransformStreamDefaultController"]>;
declare const $setUpTransformStreamDefaultControllerFromTransformer: RemoveThis<typeof import("./ts/TransformStreamInternals")["setUpTransformStreamDefaultControllerFromTransformer"]>;
declare const $transformStreamDefaultControllerClearAlgorithms: RemoveThis<typeof import("./ts/TransformStreamInternals")["transformStreamDefaultControllerClearAlgorithms"]>;
declare const $transformStreamDefaultControllerEnqueue: RemoveThis<typeof import("./ts/TransformStreamInternals")["transformStreamDefaultControllerEnqueue"]>;
declare const $transformStreamDefaultControllerError: RemoveThis<typeof import("./ts/TransformStreamInternals")["transformStreamDefaultControllerError"]>;
declare const $transformStreamDefaultControllerPerformTransform: RemoveThis<typeof import("./ts/TransformStreamInternals")["transformStreamDefaultControllerPerformTransform"]>;
declare const $transformStreamDefaultControllerTerminate: RemoveThis<typeof import("./ts/TransformStreamInternals")["transformStreamDefaultControllerTerminate"]>;
declare const $transformStreamDefaultSinkWriteAlgorithm: RemoveThis<typeof import("./ts/TransformStreamInternals")["transformStreamDefaultSinkWriteAlgorithm"]>;
declare const $transformStreamDefaultSinkAbortAlgorithm: RemoveThis<typeof import("./ts/TransformStreamInternals")["transformStreamDefaultSinkAbortAlgorithm"]>;
declare const $transformStreamDefaultSinkCloseAlgorithm: RemoveThis<typeof import("./ts/TransformStreamInternals")["transformStreamDefaultSinkCloseAlgorithm"]>;
declare const $transformStreamDefaultSourcePullAlgorithm: RemoveThis<typeof import("./ts/TransformStreamInternals")["transformStreamDefaultSourcePullAlgorithm"]>;
// ReadableStreamInternals.ts
declare const $readableStreamReaderGenericInitialize: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamReaderGenericInitialize"]>;
declare const $privateInitializeReadableStreamDefaultController: RemoveThis<typeof import("./ts/ReadableStreamInternals")["privateInitializeReadableStreamDefaultController"]>;
declare const $readableStreamDefaultControllerError: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamDefaultControllerError"]>;
declare const $readableStreamPipeTo: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamPipeTo"]>;
declare const $acquireReadableStreamDefaultReader: RemoveThis<typeof import("./ts/ReadableStreamInternals")["acquireReadableStreamDefaultReader"]>;
declare const $setupReadableStreamDefaultController: RemoveThis<typeof import("./ts/ReadableStreamInternals")["setupReadableStreamDefaultController"]>;
declare const $createReadableStreamController: RemoveThis<typeof import("./ts/ReadableStreamInternals")["createReadableStreamController"]>;
declare const $readableStreamDefaultControllerStart: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamDefaultControllerStart"]>;
declare const $readableStreamPipeToWritableStream: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamPipeToWritableStream"]>;
declare const $pipeToLoop: RemoveThis<typeof import("./ts/ReadableStreamInternals")["pipeToLoop"]>;
declare const $pipeToDoReadWrite: RemoveThis<typeof import("./ts/ReadableStreamInternals")["pipeToDoReadWrite"]>;
declare const $pipeToErrorsMustBePropagatedForward: RemoveThis<typeof import("./ts/ReadableStreamInternals")["pipeToErrorsMustBePropagatedForward"]>;
declare const $pipeToErrorsMustBePropagatedBackward: RemoveThis<typeof import("./ts/ReadableStreamInternals")["pipeToErrorsMustBePropagatedBackward"]>;
declare const $pipeToClosingMustBePropagatedForward: RemoveThis<typeof import("./ts/ReadableStreamInternals")["pipeToClosingMustBePropagatedForward"]>;
declare const $pipeToClosingMustBePropagatedBackward: RemoveThis<typeof import("./ts/ReadableStreamInternals")["pipeToClosingMustBePropagatedBackward"]>;
declare const $pipeToShutdownWithAction: RemoveThis<typeof import("./ts/ReadableStreamInternals")["pipeToShutdownWithAction"]>;
declare const $pipeToShutdown: RemoveThis<typeof import("./ts/ReadableStreamInternals")["pipeToShutdown"]>;
declare const $pipeToFinalize: RemoveThis<typeof import("./ts/ReadableStreamInternals")["pipeToFinalize"]>;
declare const $readableStreamTee: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamTee"]>;
declare const $readableStreamTeePullFunction: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamTeePullFunction"]>;
declare const $readableStreamTeeBranch1CancelFunction: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamTeeBranch1CancelFunction"]>;
declare const $readableStreamTeeBranch2CancelFunction: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamTeeBranch2CancelFunction"]>;
declare const $isReadableStream: RemoveThis<typeof import("./ts/ReadableStreamInternals")["isReadableStream"]>;
declare const $isReadableStreamDefaultReader: RemoveThis<typeof import("./ts/ReadableStreamInternals")["isReadableStreamDefaultReader"]>;
declare const $isReadableStreamDefaultController: RemoveThis<typeof import("./ts/ReadableStreamInternals")["isReadableStreamDefaultController"]>;
declare const $readDirectStream: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readDirectStream"]>;
declare const $assignToStream: RemoveThis<typeof import("./ts/ReadableStreamInternals")["assignToStream"]>;
declare const $readStreamIntoSink: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readStreamIntoSink"]>;
declare const $handleDirectStreamError: RemoveThis<typeof import("./ts/ReadableStreamInternals")["handleDirectStreamError"]>;
declare const $handleDirectStreamErrorReject: RemoveThis<typeof import("./ts/ReadableStreamInternals")["handleDirectStreamErrorReject"]>;
declare const $onPullDirectStream: RemoveThis<typeof import("./ts/ReadableStreamInternals")["onPullDirectStream"]>;
declare const $noopDoneFunction: RemoveThis<typeof import("./ts/ReadableStreamInternals")["noopDoneFunction"]>;
declare const $onReadableStreamDirectControllerClosed: RemoveThis<typeof import("./ts/ReadableStreamInternals")["onReadableStreamDirectControllerClosed"]>;
declare const $onCloseDirectStream: RemoveThis<typeof import("./ts/ReadableStreamInternals")["onCloseDirectStream"]>;
declare const $onFlushDirectStream: RemoveThis<typeof import("./ts/ReadableStreamInternals")["onFlushDirectStream"]>;
declare const $createTextStream: RemoveThis<typeof import("./ts/ReadableStreamInternals")["createTextStream"]>;
declare const $initializeTextStream: RemoveThis<typeof import("./ts/ReadableStreamInternals")["initializeTextStream"]>;
declare const $initializeArrayStream: RemoveThis<typeof import("./ts/ReadableStreamInternals")["initializeArrayStream"]>;
declare const $initializeArrayBufferStream: RemoveThis<typeof import("./ts/ReadableStreamInternals")["initializeArrayBufferStream"]>;
declare const $readableStreamError: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamError"]>;
declare const $readableStreamDefaultControllerShouldCallPull: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamDefaultControllerShouldCallPull"]>;
declare const $readableStreamDefaultControllerCallPullIfNeeded: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamDefaultControllerCallPullIfNeeded"]>;
declare const $isReadableStreamLocked: RemoveThis<typeof import("./ts/ReadableStreamInternals")["isReadableStreamLocked"]>;
declare const $readableStreamDefaultControllerGetDesiredSize: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamDefaultControllerGetDesiredSize"]>;
declare const $readableStreamReaderGenericCancel: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamReaderGenericCancel"]>;
declare const $readableStreamCancel: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamCancel"]>;
declare const $readableStreamDefaultControllerCancel: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamDefaultControllerCancel"]>;
declare const $readableStreamDefaultControllerPull: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamDefaultControllerPull"]>;
declare const $readableStreamDefaultControllerClose: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamDefaultControllerClose"]>;
declare const $readableStreamClose: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamClose"]>;
declare const $readableStreamFulfillReadRequest: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamFulfillReadRequest"]>;
declare const $readableStreamDefaultControllerEnqueue: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamDefaultControllerEnqueue"]>;
declare const $readableStreamDefaultReaderRead: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamDefaultReaderRead"]>;
declare const $readableStreamAddReadRequest: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamAddReadRequest"]>;
declare const $isReadableStreamDisturbed: RemoveThis<typeof import("./ts/ReadableStreamInternals")["isReadableStreamDisturbed"]>;
declare const $readableStreamReaderGenericRelease: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamReaderGenericRelease"]>;
declare const $readableStreamDefaultControllerCanCloseOrEnqueue: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamDefaultControllerCanCloseOrEnqueue"]>;
declare const $lazyLoadStream: RemoveThis<typeof import("./ts/ReadableStreamInternals")["lazyLoadStream"]>;
declare const $readableStreamIntoArray: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamIntoArray"]>;
declare const $readableStreamIntoText: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamIntoText"]>;
declare const $readableStreamToArrayBufferDirect: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamToArrayBufferDirect"]>;
declare const $readableStreamToTextDirect: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamToTextDirect"]>;
declare const $readableStreamToArrayDirect: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamToArrayDirect"]>;
declare const $readableStreamDefineLazyIterators: RemoveThis<typeof import("./ts/ReadableStreamInternals")["readableStreamDefineLazyIterators"]>;
// StreamInternals.ts
declare const $markPromiseAsHandled: RemoveThis<typeof import("./ts/StreamInternals")["markPromiseAsHandled"]>;
declare const $shieldingPromiseResolve: RemoveThis<typeof import("./ts/StreamInternals")["shieldingPromiseResolve"]>;
declare const $promiseInvokeOrNoopMethodNoCatch: RemoveThis<typeof import("./ts/StreamInternals")["promiseInvokeOrNoopMethodNoCatch"]>;
declare const $promiseInvokeOrNoopNoCatch: RemoveThis<typeof import("./ts/StreamInternals")["promiseInvokeOrNoopNoCatch"]>;
declare const $promiseInvokeOrNoopMethod: RemoveThis<typeof import("./ts/StreamInternals")["promiseInvokeOrNoopMethod"]>;
declare const $promiseInvokeOrNoop: RemoveThis<typeof import("./ts/StreamInternals")["promiseInvokeOrNoop"]>;
declare const $promiseInvokeOrFallbackOrNoop: RemoveThis<typeof import("./ts/StreamInternals")["promiseInvokeOrFallbackOrNoop"]>;
declare const $validateAndNormalizeQueuingStrategy: RemoveThis<typeof import("./ts/StreamInternals")["validateAndNormalizeQueuingStrategy"]>;
declare const $createFIFO: RemoveThis<typeof import("./ts/StreamInternals")["createFIFO"]>;
declare const $newQueue: RemoveThis<typeof import("./ts/StreamInternals")["newQueue"]>;
declare const $dequeueValue: RemoveThis<typeof import("./ts/StreamInternals")["dequeueValue"]>;
declare const $enqueueValueWithSize: RemoveThis<typeof import("./ts/StreamInternals")["enqueueValueWithSize"]>;
declare const $peekQueueValue: RemoveThis<typeof import("./ts/StreamInternals")["peekQueueValue"]>;
declare const $resetQueue: RemoveThis<typeof import("./ts/StreamInternals")["resetQueue"]>;
declare const $extractSizeAlgorithm: RemoveThis<typeof import("./ts/StreamInternals")["extractSizeAlgorithm"]>;
declare const $extractHighWaterMark: RemoveThis<typeof import("./ts/StreamInternals")["extractHighWaterMark"]>;
declare const $extractHighWaterMarkFromQueuingStrategyInit: RemoveThis<typeof import("./ts/StreamInternals")["extractHighWaterMarkFromQueuingStrategyInit"]>;
declare const $createFulfilledPromise: RemoveThis<typeof import("./ts/StreamInternals")["createFulfilledPromise"]>;
declare const $toDictionary: RemoveThis<typeof import("./ts/StreamInternals")["toDictionary"]>;
// ReadableByteStreamInternals.ts
declare const $privateInitializeReadableByteStreamController: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["privateInitializeReadableByteStreamController"]>;
declare const $readableStreamByteStreamControllerStart: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableStreamByteStreamControllerStart"]>;
declare const $privateInitializeReadableStreamBYOBRequest: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["privateInitializeReadableStreamBYOBRequest"]>;
declare const $isReadableByteStreamController: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["isReadableByteStreamController"]>;
declare const $isReadableStreamBYOBRequest: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["isReadableStreamBYOBRequest"]>;
declare const $isReadableStreamBYOBReader: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["isReadableStreamBYOBReader"]>;
declare const $readableByteStreamControllerCancel: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerCancel"]>;
declare const $readableByteStreamControllerError: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerError"]>;
declare const $readableByteStreamControllerClose: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerClose"]>;
declare const $readableByteStreamControllerClearPendingPullIntos: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerClearPendingPullIntos"]>;
declare const $readableByteStreamControllerGetDesiredSize: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerGetDesiredSize"]>;
declare const $readableStreamHasBYOBReader: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableStreamHasBYOBReader"]>;
declare const $readableStreamHasDefaultReader: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableStreamHasDefaultReader"]>;
declare const $readableByteStreamControllerHandleQueueDrain: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerHandleQueueDrain"]>;
declare const $readableByteStreamControllerPull: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerPull"]>;
declare const $readableByteStreamControllerShouldCallPull: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerShouldCallPull"]>;
declare const $readableByteStreamControllerCallPullIfNeeded: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerCallPullIfNeeded"]>;
declare const $transferBufferToCurrentRealm: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["transferBufferToCurrentRealm"]>;
declare const $readableStreamReaderKind: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableStreamReaderKind"]>;
declare const $readableByteStreamControllerEnqueue: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerEnqueue"]>;
declare const $readableByteStreamControllerEnqueueChunk: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerEnqueueChunk"]>;
declare const $readableByteStreamControllerRespondWithNewView: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerRespondWithNewView"]>;
declare const $readableByteStreamControllerRespond: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerRespond"]>;
declare const $readableByteStreamControllerRespondInternal: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerRespondInternal"]>;
declare const $readableByteStreamControllerRespondInReadableState: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerRespondInReadableState"]>;
declare const $readableByteStreamControllerRespondInClosedState: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerRespondInClosedState"]>;
declare const $readableByteStreamControllerProcessPullDescriptors: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerProcessPullDescriptors"]>;
declare const $readableByteStreamControllerFillDescriptorFromQueue: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerFillDescriptorFromQueue"]>;
declare const $readableByteStreamControllerShiftPendingDescriptor: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerShiftPendingDescriptor"]>;
declare const $readableByteStreamControllerInvalidateBYOBRequest: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerInvalidateBYOBRequest"]>;
declare const $readableByteStreamControllerCommitDescriptor: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerCommitDescriptor"]>;
declare const $readableByteStreamControllerConvertDescriptor: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerConvertDescriptor"]>;
declare const $readableStreamFulfillReadIntoRequest: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableStreamFulfillReadIntoRequest"]>;
declare const $readableStreamBYOBReaderRead: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableStreamBYOBReaderRead"]>;
declare const $readableByteStreamControllerPullInto: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableByteStreamControllerPullInto"]>;
declare const $readableStreamAddReadIntoRequest: RemoveThis<typeof import("./ts/ReadableByteStreamInternals")["readableStreamAddReadIntoRequest"]>;

View File

@@ -1,7 +0,0 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"noEmit": true
},
"include": [".", "builtins.d.ts", "WebCoreJSBuiltins.d.ts", "../../../packages/bun-types/index.d.ts"]
}

View File

@@ -1,27 +0,0 @@
// bun only supports glibc at the time of writing
export function family() {
return Promise.resolve(GLIBC);
}
export function familySync() {
return GLIBC;
}
export const GLIBC = "glibc";
export const MUSL = "musl";
export function versionAsync() {
return Promise.resolve(version());
}
export function version() {
return "2.29";
}
export function isNonGlibcLinuxSync() {
return false;
}
export function isNonGlibcLinux() {
return Promise.resolve(isNonGlibcLinuxSync());
}

View File

@@ -1,46 +0,0 @@
// This is a stub! None of this is actually implemented yet.
function hideFromStack(fns) {
for (const fn of fns) {
Object.defineProperty(fn, "name", {
value: "::bunternal::",
});
}
}
class TODO extends Error {
constructor(messageName) {
const message = messageName
? `node:dgram ${messageName} is not implemented yet in Bun. Track the status and thumbs up the issue: https://github.com/oven-sh/bun/issues/1630`
: `node:dgram is not implemented yet in Bun. Track the status and thumbs up the issue: https://github.com/oven-sh/bun/issues/1630`;
super(message);
this.name = "TODO";
}
}
function notimpl(message) {
throw new TODO(message);
}
function createSocket() {
notimpl("createSocket");
}
function Socket() {
notimpl("Socket");
}
function _createSocketHandle() {
notimpl("_createSocketHandle");
}
const defaultObject = {
createSocket,
Socket,
_createSocketHandle,
[Symbol.for("CommonJS")]: 0,
};
export { defaultObject as default, Socket, createSocket, _createSocketHandle };
hideFromStack([TODO.prototype.constructor, notimpl, createSocket, Socket, _createSocketHandle]);

View File

@@ -1,57 +0,0 @@
// This is a stub! None of this is actually implemented yet.
function hideFromStack(fns) {
for (const fn of fns) {
Object.defineProperty(fn, "name", {
value: "::bunternal::",
});
}
}
class TODO extends Error {
constructor(messageName) {
const message = messageName
? `node:diagnostics_channel ${messageName} is not implemented yet in Bun.`
: `node:diagnostics_channel is not implemented yet in Bun.`;
super(message);
this.name = "TODO";
}
}
function notimpl() {
throw new TODO();
}
class Channel {
constructor(name) {
notimpl();
}
}
function channel() {
notimpl();
}
function hasSubscribers() {
notimpl();
}
function subscribe() {
notimpl();
}
function unsubscribe() {
notimpl();
}
const defaultObject = {
channel,
hasSubscribers,
subscribe,
unsubscribe,
Channel,
[Symbol.for("CommonJS")]: 0,
};
export { defaultObject as default, Channel, channel, hasSubscribers, subscribe, unsubscribe };
hideFromStack([TODO.prototype.constructor, notimpl, channel, hasSubscribers, subscribe, unsubscribe, Channel]);

View File

@@ -1,68 +0,0 @@
// This is a stub! None of this is actually implemented yet.
function hideFromStack(fns) {
for (const fn of fns) {
Object.defineProperty(fn, "name", {
value: "::bunternal::",
});
}
}
class TODO extends Error {
constructor(messageName) {
const message = messageName
? `node:inspector ${messageName} is not implemented yet in Bun. Track the status & thumbs up the issue: https://github.com/oven-sh/bun/issues/2445`
: `node:inspector is not implemented yet in Bun. Track the status & thumbs up the issue: https://github.com/oven-sh/bun/issues/2445`;
super(message);
this.name = "TODO";
}
}
function notimpl(message) {
throw new TODO(message);
}
const { EventEmitter } = import.meta.require("node:events");
function open() {
notimpl("open");
}
function close() {
notimpl("close");
}
function url() {
notimpl("url");
}
function waitForDebugger() {
notimpl("waitForDebugger");
}
class Session extends EventEmitter {
constructor() {
super();
notimpl("Session");
}
}
const console = {
...globalThis.console,
context: {
console: globalThis.console,
},
};
var defaultObject = {
console,
open,
close,
url,
waitForDebugger,
Session,
[Symbol.for("CommonJS")]: 0,
};
export { console, open, close, url, waitForDebugger, Session, defaultObject as default };
hideFromStack([notimpl, TODO.prototype.constructor, open, close, url, waitForDebugger, Session.prototype.constructor]);

View File

@@ -86,22 +86,25 @@ const PackageManager = @import("../install/install.zig").PackageManager;
const Install = @import("../install/install.zig");
const VirtualMachine = JSC.VirtualMachine;
const Dependency = @import("../install/dependency.zig");
// This exists to make it so we can reload these quicker in development
// Setting BUN_OVERRIDE_MODULE_PATH to the path to the bun repo will make it so modules are loaded
// from there instead of the ones embedded into the binary.
// In debug mode, this is set automatically for you, using the path relative to this file.
fn jsModuleFromFile(from_path: string, comptime input: string) string {
const absolute_path = comptime (bun.Environment.base_path ++ std.fs.path.dirname(@src().file).?) ++ "/" ++ input;
// `modules_dev` is not minified or committed. Later we could also try loading source maps for it too.
const moduleFolder = if (comptime Environment.isDebug) "modules_dev" else "modules";
const Holder = struct {
pub const file = @embedFile(input);
pub const file = @embedFile("../js/out/" ++ moduleFolder ++ "/" ++ input);
};
if (comptime !Environment.allow_assert) {
if (from_path.len == 0) {
return Holder.file;
}
if ((comptime !Environment.allow_assert) and from_path.len == 0) {
return Holder.file;
}
var file: std.fs.File = undefined;
if (comptime Environment.allow_assert) {
if ((comptime Environment.allow_assert) and from_path.len == 0) {
const absolute_path = comptime (Environment.base_path ++ (std.fs.path.dirname(std.fs.path.dirname(@src().file).?).?) ++ "/js/out/" ++ moduleFolder ++ "/" ++ input);
file = std.fs.openFileAbsoluteZ(absolute_path, .{ .mode = .read_only }) catch {
const WarnOnce = struct {
pub var warned = false;
@@ -113,7 +116,7 @@ fn jsModuleFromFile(from_path: string, comptime input: string) string {
return Holder.file;
};
} else {
var parts = [_]string{ from_path, input };
var parts = [_]string{ from_path, "src/js/out/" ++ moduleFolder ++ "/" ++ input };
var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var absolute_path_to_use = Fs.FileSystem.instance.absBuf(&parts, &buf);
buf[absolute_path_to_use.len] = 0;
@@ -129,10 +132,8 @@ fn jsModuleFromFile(from_path: string, comptime input: string) string {
};
}
var contents = file.readToEndAlloc(bun.default_allocator, std.math.maxInt(usize)) catch @panic("Cannot read file: " ++ absolute_path);
if (comptime !Environment.allow_assert) {
file.close();
}
var contents = file.readToEndAlloc(bun.default_allocator, std.math.maxInt(usize)) catch @panic("Cannot read file " ++ input);
file.close();
return contents;
}
@@ -1275,8 +1276,8 @@ pub const ModuleLoader = struct {
strings.append3(
bun.default_allocator,
JSC.Node.fs.constants_string,
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "./wasi.exports.js")),
jsModuleFromFile(jsc_vm.load_builtins_from_path, "wasi-runner.js"),
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "node/wasi.js")),
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "bun/wasi-runner.js")),
) catch unreachable,
),
.specifier = ZigString.init(display_specifier),
@@ -1593,8 +1594,6 @@ pub const ModuleLoader = struct {
return globalObject.runOnLoadPlugins(ZigString.init(namespace), ZigString.init(after_namespace), .bun) orelse return JSValue.zero;
}
const shared_library_suffix = if (Environment.isMac) "dylib" else if (Environment.isLinux) "so" else "";
pub fn fetchBuiltinModule(jsc_vm: *VirtualMachine, specifier: string, log: *logger.Log, comptime disable_transpilying: bool) !?ResolvedSource {
if (jsc_vm.node_modules != null and strings.eqlComptime(specifier, JSC.bun_file_import_path)) {
// We kind of need an abstraction around this.
@@ -1707,411 +1706,86 @@ pub const ModuleLoader = struct {
.hash = 0,
};
},
.@"bun:jsc" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "bun-jsc.exports.js")),
.specifier = ZigString.init("bun:jsc"),
.source_url = ZigString.init("bun:jsc"),
.hash = 0,
};
},
.@"bun:events_native" => return jsSyntheticModule(.@"bun:events_native"),
.@"node:child_process" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "child_process.exports.js")),
.specifier = ZigString.init("node:child_process"),
.source_url = ZigString.init("node:child_process"),
.hash = 0,
};
},
.@"node:net" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "net.exports.js")),
.specifier = ZigString.init("node:net"),
.source_url = ZigString.init("node:net"),
.hash = 0,
};
},
.@"node:fs" => {
if (comptime Environment.isDebug) {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "fs.exports.js")),
.specifier = ZigString.init("node:fs"),
.source_url = ZigString.init("node:fs"),
.hash = 0,
};
} else if (jsc_vm.load_builtins_from_path.len != 0) {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "fs.exports.js")),
.specifier = ZigString.init("node:fs"),
.source_url = ZigString.init("node:fs"),
.hash = 0,
};
}
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(@embedFile("fs.exports.js")),
.specifier = ZigString.init("node:fs"),
.source_url = ZigString.init("node:fs"),
.hash = 0,
};
},
.@"node:buffer" => return jsSyntheticModule(.@"node:buffer"),
.@"node:string_decoder" => return jsSyntheticModule(.@"node:string_decoder"),
.@"node:module" => return jsSyntheticModule(.@"node:module"),
.@"node:events" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "events.exports.js")),
.specifier = ZigString.init("node:events"),
.source_url = ZigString.init("node:events"),
.hash = 0,
};
},
.@"node:process" => return jsSyntheticModule(.@"node:process"),
.@"node:tty" => return jsSyntheticModule(.@"node:tty"),
.@"node:util/types" => return jsSyntheticModule(.@"node:util/types"),
.@"node:stream" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "streams.exports.js")),
.specifier = ZigString.init("node:stream"),
.source_url = ZigString.init("node:stream"),
.hash = 0,
};
},
.@"node:zlib" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "zlib.exports.js")),
.specifier = ZigString.init("node:zlib"),
.source_url = ZigString.init("node:zlib"),
.hash = 0,
};
},
.@"node:async_hooks" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "async_hooks.exports.js")),
.specifier = ZigString.init("node:async_hooks"),
.source_url = ZigString.init("node:async_hooks"),
.hash = 0,
};
},
.@"bun:events_native" => return jsSyntheticModule(.@"bun:events_native"),
.@"node:fs/promises" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(JSC.Node.fs.constants_string ++ @embedFile("fs_promises.exports.js")),
.source_code = ZigString.init(JSC.Node.fs.constants_string ++ @embedFile("../js/out/modules/node/fs.promises.js")),
.specifier = ZigString.init("node:fs/promises"),
.source_url = ZigString.init("node:fs/promises"),
.hash = 0,
};
},
.@"node:path" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "path.exports.js")),
.specifier = ZigString.init("node:path"),
.source_url = ZigString.init("node:path"),
.hash = 0,
};
},
.@"node:dns" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "node-dns.exports.js")),
.specifier = ZigString.init("node:dns"),
.source_url = ZigString.init("node:dns"),
.hash = 0,
};
},
.@"node:tls" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "node-tls.exports.js")),
.specifier = ZigString.init("node:tls"),
.source_url = ZigString.init("node:tls"),
.hash = 0,
};
},
.@"node:dns/promises" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "node-dns_promises.exports.js")),
.specifier = ZigString.init("node:dns/promises"),
.source_url = ZigString.init("node:dns/promises"),
.hash = 0,
};
},
.@"node:path/win32" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "path-win32.exports.js")),
.specifier = ZigString.init("node:path/win32"),
.source_url = ZigString.init("node:path/win32"),
.hash = 0,
};
},
.@"node:path/posix" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "path-posix.exports.js")),
.specifier = ZigString.init("node:path/posix"),
.source_url = ZigString.init("node:path/posix"),
.hash = 0,
};
},
.@"node:os" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "os.exports.js")),
.specifier = ZigString.init("node:os"),
.source_url = ZigString.init("node:os"),
.hash = 0,
};
},
.@"node:crypto" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "crypto.exports.js")),
.specifier = ZigString.init("node:crypto"),
.source_url = ZigString.init("node:crypto"),
.hash = 0,
};
},
.@"node:readline" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "readline.exports.js")),
.specifier = ZigString.init("node:readline"),
.source_url = ZigString.init("node:readline"),
.hash = 0,
};
},
.@"node:readline/promises" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(jsc_vm.load_builtins_from_path, "readline_promises.exports.js")),
.specifier = ZigString.init("node:readline/promises"),
.source_url = ZigString.init("node:readline/promises"),
.hash = 0,
};
},
.@"bun:ffi" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
"export const FFIType = " ++
"export const FFIType=" ++
JSC.FFI.ABIType.map_to_js_object ++
";\n\n" ++
"export const suffix = '" ++ shared_library_suffix ++ "';\n\n" ++
@embedFile("ffi.exports.js") ++
"\n",
";" ++
@embedFile("../js/out/modules/bun/ffi.js"),
),
.specifier = ZigString.init("bun:ffi"),
.source_url = ZigString.init("bun:ffi"),
.hash = 0,
};
},
.@"detect-libc" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
@as(string, @embedFile(if (Environment.isLinux) "detect-libc.linux.js" else "detect-libc.js")),
),
.specifier = ZigString.init("detect-libc"),
.source_url = ZigString.init("detect-libc"),
.hash = 0,
};
},
.@"node:url" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "url.exports.js")),
),
.specifier = ZigString.init("node:url"),
.source_url = ZigString.init("node:url"),
.hash = 0,
};
},
.@"node:assert" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "assert.exports.js")),
),
.specifier = ZigString.init("node:assert"),
.source_url = ZigString.init("node:assert"),
.hash = 0,
};
},
.@"bun:sqlite" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "./bindings/sqlite/sqlite.exports.js")),
),
.specifier = ZigString.init("bun:sqlite"),
.source_url = ZigString.init("bun:sqlite"),
.hash = 0,
};
},
.@"node:perf_hooks" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "./perf_hooks.exports.js")),
),
.specifier = ZigString.init("node:perf_hooks"),
.source_url = ZigString.init("node:perf_hooks"),
.hash = 0,
};
},
.ws => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "./ws.exports.js")),
),
.specifier = ZigString.init("ws"),
.source_url = ZigString.init("ws"),
.hash = 0,
};
},
.@"node:timers" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "./node_timers.exports.js")),
),
.specifier = ZigString.init("node:timers"),
.source_url = ZigString.init("node:timers"),
.hash = 0,
};
},
.@"node:timers/promises" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "./node_timers_promises.exports.js")),
),
.specifier = ZigString.init("node:timers/promises"),
.source_url = ZigString.init("node:timers/promises"),
.hash = 0,
};
},
.@"node:stream/web" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "./node_streams_web.exports.js")),
),
.specifier = ZigString.init("node:stream/web"),
.source_url = ZigString.init("node:stream/web"),
.hash = 0,
};
},
.@"node:stream/consumers" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "./node_streams_consumer.exports.js")),
),
.specifier = ZigString.init("node:stream/consumers"),
.source_url = ZigString.init("node:stream/consumers"),
.hash = 0,
};
},
.@"node:util" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "./util.exports.js")),
),
.specifier = ZigString.init("node:util"),
.source_url = ZigString.init("node:util"),
.hash = 0,
};
},
.undici => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "./undici.exports.js")),
),
.specifier = ZigString.init("undici"),
.source_url = ZigString.init("undici"),
.hash = 0,
};
},
.@"node:wasi" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
strings.append(
bun.default_allocator,
JSC.Node.fs.constants_string,
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "./wasi.exports.js")),
) catch unreachable,
),
.specifier = ZigString.init("node:wasi"),
.source_url = ZigString.init("node:wasi"),
.hash = 0,
};
},
.@"node:http" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "./http.exports.js")),
),
.specifier = ZigString.init("node:http"),
.source_url = ZigString.init("node:http"),
.hash = 0,
};
},
.@"node:https" => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "./https.exports.js")),
),
.specifier = ZigString.init("node:https"),
.source_url = ZigString.init("node:https"),
.hash = 0,
};
},
.depd => {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(
@as(string, jsModuleFromFile(jsc_vm.load_builtins_from_path, "./depd.exports.js")),
),
.specifier = ZigString.init("depd"),
.source_url = ZigString.init("depd"),
.hash = 0,
};
},
.@"node:stream/promises" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:stream/promises", "node_streams_promises.exports.js"),
.@"node:vm" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:vm", "vm.exports.js"),
.@"node:assert/strict" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:assert/strict", "assert_strict.exports.js"),
.@"node:v8" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:v8", "v8.exports.js"),
.@"node:trace_events" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:trace_events", "trace_events.exports.js"),
.@"node:repl" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:repl", "repl.exports.js"),
.@"node:inspector" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:inspector", "inspector.exports.js"),
.@"node:http2" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:http2", "http2.exports.js"),
.@"node:diagnostics_channel" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:diagnostics_channel", "diagnostics_channel.exports.js"),
.@"node:dgram" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:dgram", "dgram.exports.js"),
.@"node:cluster" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:cluster", "cluster.exports.js"),
.@"bun:jsc" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"bun:jsc", "bun/jsc.js"),
.@"bun:sqlite" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"bun:sqlite", "bun/sqlite.js"),
.@"node:assert" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:assert", "node/assert.js"),
.@"node:assert/strict" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:assert/strict", "node/assert.strict.js"),
.@"node:async_hooks" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:async_hooks", "node/async_hooks.js"),
.@"node:child_process" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:child_process", "node/child_process.js"),
.@"node:crypto" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:crypto", "node/crypto.js"),
.@"node:dns" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:dns", "node/dns.js"),
.@"node:dns/promises" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:dns/promises", "node/dns.promises.js"),
.@"node:events" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:child_process", "node/events.js"),
.@"node:fs" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:fs", "node/fs.js"),
.@"node:http" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:http", "node/http.js"),
.@"node:https" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:https", "node/https.js"),
.@"node:net" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:net", "node/net.js"),
.@"node:os" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:os", "node/os.js"),
.@"node:path" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:path", "node/path.js"),
.@"node:path/posix" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:path/posix", "node/path.posix.js"),
.@"node:path/win32" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:path/win32", "node/path.win32.js"),
.@"node:perf_hooks" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:perf_hooks", "node/perf_hooks.js"),
.@"node:readline" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:readline", "node/readline.js"),
.@"node:readline/promises" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:readline/promises", "node/readline.promises.js"),
.@"node:stream" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:stream", "node/stream.js"),
.@"node:stream/consumers" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:stream/consumers", "node/stream.consumers.js"),
.@"node:stream/promises" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:stream/promises", "node/stream.promises.js"),
.@"node:stream/web" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:stream/web", "node/stream.web.js"),
.@"node:timers" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:timers", "node/timers.js"),
.@"node:timers/promises" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:timers/promises", "node/timers.promises.js"),
.@"node:tls" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:tls", "node/tls.js"),
.@"node:url" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:url", "node/url.js"),
.@"node:util" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:util", "node/util.js"),
.@"node:vm" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:vm", "node/vm.js"),
.@"node:wasi" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:wasi", "node/wasi.js"),
.@"node:zlib" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:zlib", "node/zlib.js"),
.@"detect-libc" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"detect-libc", "thirdparty/detect-libc.js"),
.depd => return jsResolvedSource(jsc_vm.load_builtins_from_path, .depd, "thirdparty/depd.js"),
.undici => return jsResolvedSource(jsc_vm.load_builtins_from_path, .undici, "thirdparty/undici.js"),
.ws => return jsResolvedSource(jsc_vm.load_builtins_from_path, .ws, "thirdparty/ws.js"),
.@"node:cluster" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:cluster", "node/cluster.js"),
.@"node:dgram" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:dgram", "node/dgram.js"),
.@"node:diagnostics_channel" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:diagnostics_channel", "node/diagnostics_channel.js"),
.@"node:http2" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:http2", "node/http2.js"),
.@"node:inspector" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:inspector", "node/inspector.js"),
.@"node:repl" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:repl", "node/repl.js"),
.@"node:trace_events" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:trace_events", "node/trace_events.js"),
.@"node:v8" => return jsResolvedSource(jsc_vm.load_builtins_from_path, .@"node:v8", "node/v8.js"),
}
} else if (strings.hasPrefixComptime(specifier, js_ast.Macro.namespaceWithColon)) {
if (jsc_vm.macro_entry_points.get(MacroEntryPoint.generateIDFromSpecifier(specifier))) |entry| {
@@ -2513,7 +2187,7 @@ pub const DisabledModule = bun.ComptimeStringMap(
},
);
fn jsResolvedSource(builtins: []const u8, comptime module: HardcodedModule, comptime input: []const u8) ResolvedSource {
inline fn jsResolvedSource(builtins: []const u8, comptime module: HardcodedModule, comptime input: []const u8) ResolvedSource {
return ResolvedSource{
.allocator = null,
.source_code = ZigString.init(jsModuleFromFile(builtins, input)),

View File

@@ -37,7 +37,7 @@ pub const ImportKind = enum(u8) {
pub const Label = std.EnumArray(ImportKind, []const u8);
pub const all_labels: Label = brk: {
// If these are changed, make sure to update
// - src/bun.js/builtins/builtins-codegen.ts
// - src/js/builtins/codegen/replacements.ts
// - packages/bun-types/bun.d.ts
var labels = Label.initFill("");
labels.set(ImportKind.entry_point, "entry-point");

4
src/js/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# we need to commit output files because CI does not have `bun` to build these files.
!out
out/modules_dev
tmp

30
src/js/README.md Normal file
View File

@@ -0,0 +1,30 @@
# JS Modules
- `./node` contains all `node:*` modules
- `./bun` contains all `bun:*` modules
- `./thirdparty` contains npm modules we replace like `ws`
When you change any of those folders, run this to bundle and minify them:
```bash
$ make hardcoded
```
These modules are bundled into the binary, but in debug mode they are loaded from the filesystem, so you do not need to rerun `make dev`. If you want to override the modules in a release build, you can set `BUN_OVERRIDE_MODULE_PATH` to the path to the repo:
```bash
$ BUN_OVERRIDE_MODULE_PATH=/path/to/bun-repo bun ...
```
For any private types like `Bun.fs()`, add them to `./private.d.ts`
# Builtins
- `./builtins` contains builtins that use intrinsics. They're inlined into generated C++ code. It's a separate system, see the readme in that folder.
When anything in that is changed, run this to regenerate the code:
```make
$ make regenerate-bindings
$ make bun-link-lld-debug
```

1
src/js/build-builtins.ts Normal file
View File

@@ -0,0 +1 @@
import "./builtins/codegen";

113
src/js/build-hardcoded.ts Normal file
View File

@@ -0,0 +1,113 @@
import { BuildConfig } from "bun";
import fs from "fs";
import path from "path";
const OUT_DIR = path.join(import.meta.dir, "out/");
const TMP_DIR = path.join(import.meta.dir, "out/tmp");
// Because we do not load sourcemaps, we are not enabling identifiers + whitespace
// minification on all files, just on the ones without logic or were already bundled
const minifyList = [
"node/stream.js",
"node/crypto.js",
"node/assert.js",
"node/assert.strict.js",
"node/fs.promises.ts",
"node/path.js",
"node/path.posix.js",
"node/path.win32.js",
"node/stream.promises.js",
"node/stream.consumers.js",
"node/stream.web.js",
];
if (fs.existsSync(OUT_DIR + "/modules")) {
fs.rmSync(OUT_DIR + "/modules", { recursive: true });
}
if (fs.existsSync(OUT_DIR + "/modules_dev")) {
fs.rmSync(OUT_DIR + "/modules_dev", { recursive: true });
}
function readdirRecursive(root: string): string[] {
const files = fs.readdirSync(root, { withFileTypes: true });
return files.flatMap(file => {
const fullPath = path.join(root, file.name);
return file.isDirectory() ? readdirRecursive(fullPath) : fullPath;
});
}
const entrypoints = ["./bun", "./node", "./thirdparty"]
.flatMap(dir => readdirRecursive(path.join(import.meta.dir, dir)))
.filter(file => file.endsWith(".js") || (file.endsWith(".ts") && !file.endsWith(".d.ts")));
const opts = {
target: "bun",
naming: {
entry: "[dir]/[name].[ext]",
},
root: import.meta.dir,
define: {
"process.platform": JSON.stringify(process.platform),
"process.arch": JSON.stringify(process.arch),
},
} as const;
const build_prod_minified = await Bun.build({
entrypoints: entrypoints.filter(file => minifyList.includes(file.slice(import.meta.dir.length + 1))),
minify: true,
...opts,
});
const build_prod_unminified = await Bun.build({
entrypoints: entrypoints.filter(file => !minifyList.includes(file.slice(import.meta.dir.length + 1))),
minify: { syntax: true },
...opts,
});
const build_dev = await Bun.build({
entrypoints: entrypoints,
minify: { syntax: true },
sourcemap: "external",
...opts,
});
for (const [build, outdir] of [
[build_dev, path.join(OUT_DIR, "modules_dev")],
[build_prod_minified, path.join(OUT_DIR, "modules")],
[build_prod_unminified, path.join(OUT_DIR, "modules")],
] as const) {
if (!build.success) {
console.error("Build failed");
throw new AggregateError(build.logs);
}
if (build.logs.length) {
console.log("Build has warnings:");
for (const log of build.logs) {
console.log(log);
}
}
for (const output of build.outputs) {
fs.mkdirSync(path.join(outdir, path.dirname(output.path)), { recursive: true });
if (output.kind === "entry-point" || output.kind === "chunk") {
const transformedOutput = (await output.text()).replace(/^(\/\/.*?\n)+/g, "");
if (transformedOutput.includes("$bundleError")) {
// attempt to find the string that was passed to $bundleError
const match = transformedOutput.match(/(?<=\$bundleError\(")(?:[^"\\]|\\.)*?(?="\))/);
console.error(`Build ${output.path} $bundleError: ${match?.[0] ?? "unknown"}`);
console.error(`DCE should have removed this function call, but it was not.`);
process.exit(1);
}
Bun.write(path.join(outdir, output.path), transformedOutput);
} else {
Bun.write(path.join(outdir, output.path), output);
}
}
}
console.log(`Took ${performance.now().toFixed(2)}ms`);

View File

@@ -479,47 +479,6 @@ declare function notImplementedIssueFn(issueNumber: number, description: string)
declare type JSCSourceCodeObject = unique symbol;
declare var Loader: {
registry: Map<string, LoaderEntry>;
parseModule(key: string, sourceCodeObject: JSCSourceCodeObject): Promise<LoaderModule> | LoaderModule;
linkAndEvaluateModule(resolvedSpecifier: string, unknown: any);
getModuleNamespaceObject(module: LoaderModule): any;
requestedModules(module: LoaderModule): string[];
dependencyKeysIfEvaluated(specifier: string): string[];
resolve(specifier: string, referrer: string): string;
ensureRegistered(key: string): LoaderEntry;
};
interface LoaderEntry {
key: string;
state: number;
fetch: Promise<JSCSourceCodeObject>;
instantiate: Promise<any>;
satisfy: Promise<any>;
dependencies: string[];
module: LoaderModule;
linkError?: any;
linkSucceeded: boolean;
evaluated: boolean;
then?: any;
isAsync: boolean;
}
interface LoaderModule {
dependenciesMap: Map<string, LoaderEntry>;
}
declare module "bun" {
var TOML: {
parse(contents: string): any;
};
function fs(): typeof import("node:fs");
function _Os(): typeof import("node:os");
var main: string;
var tty: Array<{ hasColors: boolean }>;
}
declare interface Function {
path: string;
}

View File

@@ -10,9 +10,9 @@ const MINIFY = process.argv.includes("--minify") || process.argv.includes("-m");
const PARALLEL = process.argv.includes("--parallel") || process.argv.includes("-p");
const KEEP_TMP = process.argv.includes("--keep-tmp") || process.argv.includes("-k");
const SRC_DIR = path.join(import.meta.dir, "../ts");
const OUT_DIR = path.join(import.meta.dir, "../");
const TMP_DIR = path.join(import.meta.dir, "../out");
const SRC_DIR = path.join(import.meta.dir, "../");
const OUT_DIR = path.join(SRC_DIR, "../out");
const TMP_DIR = path.join(SRC_DIR, "../out/tmp");
if (existsSync(TMP_DIR)) rmSync(TMP_DIR, { recursive: true });
mkdirSync(TMP_DIR);
@@ -225,7 +225,7 @@ $$capture_start$$(${fn.async ? "async " : ""}${
};
}
const filesToProcess = readdirSync(SRC_DIR).filter(x => x.endsWith(".ts"));
const filesToProcess = readdirSync(SRC_DIR).filter(x => x.endsWith(".ts") && !x.endsWith(".d.ts"));
const files: Array<{ basename: string; functions: BundledBuiltin[]; internal: boolean }> = [];
async function processFile(x: string) {
@@ -252,7 +252,7 @@ if (PARALLEL) {
}
// C++ codegen
let bundledCPP = `// Generated by \`bun src/bun.js/builtins/codegen/index.js\`
let bundledCPP = `// Generated by \`bun src/js/builtins/codegen\`
// Do not edit by hand.
namespace Zig { class GlobalObject; }
#include "root.h"
@@ -363,7 +363,7 @@ bundledCPP += `
`;
// C++ Header codegen
let bundledHeader = `// Generated by \`bun src/bun.js/builtins/codegen/index.js\`
let bundledHeader = `// Generated by \`bun src/js/builtins/codegen\`
// Do not edit by hand.
#pragma once
namespace Zig { class GlobalObject; }
@@ -590,7 +590,7 @@ await Bun.write(path.join(OUT_DIR, "WebCoreJSBuiltins.h"), bundledHeader);
await Bun.write(path.join(OUT_DIR, "WebCoreJSBuiltins.cpp"), bundledCPP);
// Generate TS types
let dts = `// Generated by \`bun src/bun.js/builtins/codegen/index.js\`
let dts = `// Generated by \`bun src/js/builtins/codegen\`
// Do not edit by hand.
type RemoveThis<F> = F extends (this: infer T, ...args: infer A) => infer R ? (...args: A) => R : F;
`;
@@ -599,7 +599,10 @@ for (const { basename, functions, internal } of files) {
if (internal) {
dts += `\n// ${basename}.ts\n`;
for (const fn of functions) {
dts += `declare const \$${fn.name}: RemoveThis<typeof import("./ts/${basename}")[${JSON.stringify(fn.name)}]>;\n`;
dts += `declare const \$${fn.name}: RemoveThis<typeof import("${path.relative(
OUT_DIR,
path.join(SRC_DIR, basename),
)}")[${JSON.stringify(fn.name)}]>;\n`;
}
}
}

View File

@@ -0,0 +1,7 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"noEmit": true
},
"include": [".", "../private.d.ts", "builtins.d.ts", "../generated/builtins/WebCoreJSBuiltins.d.ts", "../../../packages/bun-types/index.d.ts"]
}

View File

@@ -1,4 +1,14 @@
// --- FFIType ---
// FFIType is injected in this file
declare const FFIType: typeof import("bun:ffi").FFIType;
export const suffix =
process.platform === "darwin"
? "dylib"
: process.platform === "linux"
? "so"
: process.platform === "win32"
? "dll"
: $bundleError("Unsupported platform");
var ffi = globalThis.Bun.FFI;
export const ptr = (arg1, arg2) => (typeof arg2 === "undefined" ? ffi.ptr(arg1) : ffi.ptr(arg1, arg2));

View File

@@ -1,3 +1,4 @@
// Hardcoded module "bun:jsc"
const jsc = globalThis[Symbol.for("Bun.lazy")]("bun:jsc");
export const callerSourceOrigin = jsc.callerSourceOrigin;

View File

@@ -1,3 +1,4 @@
// Hardcoded module "sqlite"
var symbolFor = Symbol.for;
const lazy = globalThis[symbolFor("Bun.lazy")];

View File

@@ -1,5 +1,6 @@
/** --- WASI */
// wasi is imported into the top of this file
/** This file is used when a .wasm file is ran.
* The contents of `../node/wasi.js` is pasted into the top of this file.
*/
const filePath = process.argv.at(1);
if (!filePath) {

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:assert"
var { Bun } = import.meta.primordials;
var isDeepEqual = Bun.deepEquals;
var __create = Object.create;

View File

@@ -1,4 +1,5 @@
var { strict: strictBase } = import.meta.require("node:assert");
// Hardcoded module "node:assert/strict"
import { strict as strictBase } from "node:assert";
export var {
fail,

View File

@@ -1,10 +1,11 @@
// Hardcoded module "node:async_hooks"
var drainMicrotasks = () => {
({ drainMicrotasks } = import.meta.require("bun:jsc"));
drainMicrotasks();
};
var notImplemented = () => {
console.warn("[bun]: async_hooks has not been implemented yet :(");
console.warn("[bun]: async_hooks has not been implemented yet. See https://github.com/oven-sh/bun/issues/1832");
notImplemented = () => {};
};

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:child_process"
const EventEmitter = import.meta.require("node:events");
const {
Readable: { fromWeb: ReadableFromWeb },

View File

@@ -1,15 +1,9 @@
// Hardcoded module "node:cluster"
// This is a stub
// We leave it in here to provide a better error message
// TODO: implement node cluster
const { EventEmitter } = import.meta.require("node:events");
class TODO extends Error {
constructor(
message = "node:cluster is not implemented yet in Bun. Track the status: https://github.com/oven-sh/bun/issues/2428",
) {
super(message);
this.name = "TODO";
}
}
import EventEmitter from "node:events";
import { throwNotImplemented } from "../shared";
export var SCHED_NONE = 0,
SCHED_RR = 1,
@@ -21,7 +15,7 @@ export var SCHED_NONE = 0,
cluster;
Worker = function Worker() {
throw new TODO("Worker is not implemented yet in Bun");
throwNotImplemented("node:cluster Worker", 2428);
};
// TODO: is it okay for this to be a class?
@@ -33,15 +27,15 @@ class Cluster extends EventEmitter {
static Worker = Worker;
fork() {
throw new TODO();
throwNotImplemented("node:cluster", 2428);
}
disconnect() {
throw new TODO();
throwNotImplemented("node:cluster", 2428);
}
setupMaster() {
throw new TODO();
throwNotImplemented("node:cluster", 2428);
}
settings = {};
@@ -49,6 +43,7 @@ class Cluster extends EventEmitter {
SCHED_NONE = 0;
SCHED_RR = 1;
schedulingPolicy = 2;
// @ts-expect-error
[Symbol.for("CommonJS")] = 0;
}

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:crypto"
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;

26
src/js/node/dgram.ts Normal file
View File

@@ -0,0 +1,26 @@
// Hardcoded module "node:dgram"
// This is a stub! None of this is actually implemented yet.
import { hideFromStack, throwNotImplemented } from "../shared";
function createSocket() {
throwNotImplemented("node:dgram createSocket", 1630);
}
function Socket() {
throwNotImplemented("node:dgram Socket", 1630);
}
function _createSocketHandle() {
throwNotImplemented("node:dgram _createSocketHandle", 1630);
}
const defaultObject = {
createSocket,
Socket,
_createSocketHandle,
[Symbol.for("CommonJS")]: 0,
};
export { defaultObject as default, Socket, createSocket, _createSocketHandle };
hideFromStack(createSocket, Socket, _createSocketHandle);

View File

@@ -0,0 +1,38 @@
// Hardcoded module "node:diagnostics_channel"
// This is a stub! None of this is actually implemented yet.
import { hideFromStack, throwNotImplemented } from "../shared";
class Channel {
constructor(name) {
throwNotImplemented("node:diagnostics_channel", 2688);
}
}
function channel() {
throwNotImplemented("node:diagnostics_channel", 2688);
}
function hasSubscribers() {
throwNotImplemented("node:diagnostics_channel", 2688);
}
function subscribe() {
throwNotImplemented("node:diagnostics_channel", 2688);
}
function unsubscribe() {
throwNotImplemented("node:diagnostics_channel", 2688);
}
const defaultObject = {
channel,
hasSubscribers,
subscribe,
unsubscribe,
Channel,
[Symbol.for("CommonJS")]: 0,
};
export { defaultObject as default, Channel, channel, hasSubscribers, subscribe, unsubscribe };
hideFromStack([channel, hasSubscribers, subscribe, unsubscribe, Channel]);

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:dns"
// only resolve4, resolve, lookup, resolve6 and resolveSrv are implemented.
const { dns } = globalThis.Bun;

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:dns/promises"
const { promises } = import.meta.require("node:dns");
export const {

View File

@@ -1,5 +1,6 @@
// Reimplementation of https://nodejs.org/api/events.html
// Reference: https://github.com/nodejs/node/blob/main/lib/events.js
import { throwNotImplemented } from "../shared";
var { isPromise, Array, Object } = import.meta.primordials;
const SymbolFor = Symbol.for;
const ObjectDefineProperty = Object.defineProperty;
@@ -310,15 +311,13 @@ EventEmitter.once = once;
function on(emitter, type, options) {
var { signal, close, highWatermark = Number.MAX_SAFE_INTEGER, lowWatermark = 1 } = options || {};
throw new Error("events.on is not implemented. See https://github.com/oven-sh/bun/issues/2679");
throwNotImplemented("events.on", 2679);
}
EventEmitter.on = on;
function getEventListeners(emitter, type) {
if (emitter instanceof EventTarget) {
throw new Error(
"getEventListeners with an EventTarget is not implemented. See https://github.com/oven-sh/bun/issues/2678",
);
throwNotImplemented("getEventListeners with an EventTarget", 2678);
}
return emitter.listeners(type);
}
@@ -457,7 +456,7 @@ function checkListener(listener) {
export class EventEmitterAsyncResource extends EventEmitter {
constructor(options = undefined) {
throw new Error("EventEmitterAsyncResource is not implemented. See https://github.com/oven-sh/bun/issues/2681");
throwNotImplemented("EventEmitterAsyncResource", 1832);
}
}

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:fs"
var { direct, isPromise, isCallable } = import.meta.primordials;
var promises = import.meta.require("node:fs/promises");

View File

@@ -1,3 +1,7 @@
// Hardcoded module "node:fs/promises"
// Note: `constants` is injected into the top of this file
declare var constants: typeof import("node:fs/promises").constants;
var fs = Bun.fs();
// note: this is not quite the same as how node does it

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:http"
const { EventEmitter } = import.meta.require("node:events");
const { isIPv6 } = import.meta.require("node:net");
const { Readable, Writable, Duplex } = import.meta.require("node:stream");

View File

@@ -1,29 +1,9 @@
// Hardcoded module "node:http2"
// This is a stub! None of this is actually implemented yet.
function hideFromStack(fns) {
for (const fn of fns) {
Object.defineProperty(fn, "name", {
value: "::bunternal::",
});
}
}
class TODO extends Error {
constructor(messageName) {
const message = messageName
? `node:http2 ${messageName} is not implemented yet in Bun. Track the status and thumbs up the issue: https://github.com/oven-sh/bun/issues/887`
: `node:http2 is not implemented yet in Bun. Track the status and thumbs up the issue: https://github.com/oven-sh/bun/issues/887`;
super(message);
this.name = "TODO";
}
}
function notimpl(message) {
throw new TODO(message);
}
import { hideFromStack, throwNotImplemented } from "../shared";
function connect() {
notimpl("connect");
throwNotImplemented("node:http2 connect", 887);
}
const constants = {
NGHTTP2_ERR_FRAME_SIZE_ERROR: -522,
@@ -269,10 +249,10 @@ const constants = {
};
function createServer() {
notimpl("createServer");
throwNotImplemented("node:http2 createServer", 887);
}
function createSecureServer() {
notimpl("createSecureServer");
throwNotImplemented("node:http2 createSecureServer", 887);
}
function getDefaultSettings() {
return {
@@ -294,10 +274,10 @@ function getUnpackedSettings() {
}
const sensitiveHeaders = Symbol.for("nodejs.http2.sensitiveHeaders");
function Http2ServerRequest() {
notimpl("Http2ServerRequest");
throwNotImplemented("node:http2 Http2ServerRequest", 887);
}
function Http2ServerResponse() {
notimpl("Http2ServerResponse");
throwNotImplemented("node:http2 Http2ServerResponse", 887);
}
const defaultObject = {
@@ -329,9 +309,7 @@ export {
};
hideFromStack([
TODO.prototype.constructor,
Http2ServerRequest,
notimpl,
Http2ServerResponse,
connect,
createServer,

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:https"
export * from "node:http";
const HTTP = import.meta.require("node:http");
export default HTTP;

47
src/js/node/inspector.ts Normal file
View File

@@ -0,0 +1,47 @@
// Hardcoded module "node:inspector" and "node:inspector/promises"
// This is a stub! None of this is actually implemented yet.
import { hideFromStack, throwNotImplemented } from "../shared";
import EventEmitter from "node:events";
function open() {
throwNotImplemented("node:inspector open", 2445);
}
function close() {
throwNotImplemented("node:inspector close", 2445);
}
function url() {
throwNotImplemented("node:inspector url", 2445);
}
function waitForDebugger() {
throwNotImplemented("node:inspector waitForDebugger", 2445);
}
class Session extends EventEmitter {
constructor() {
super();
throwNotImplemented("node:inspector Session", 2445);
}
}
const console = {
...globalThis.console,
context: {
console: globalThis.console,
},
};
var defaultObject = {
console,
open,
close,
url,
waitForDebugger,
Session,
[Symbol.for("CommonJS")]: 0,
};
export { console, open, close, url, waitForDebugger, Session, defaultObject as default };
hideFromStack(open, close, url, waitForDebugger, Session.prototype.constructor);

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:net"
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:os"
function bound(obj) {
return {
arch: obj.arch.bind(obj),

View File

@@ -1,5 +1,5 @@
// Utils to extract later
const createModule = obj => Object.assign(Object.create(null), obj);
// Hardcoded module "node:path"
export const createModule = obj => Object.assign(Object.create(null), obj);
function bound(obj) {
var result = createModule({

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:path/posix"
function bound(obj) {
return {
basename: obj.basename.bind(obj),

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:path/win32"
function bound(obj) {
return {
basename: obj.basename.bind(obj),

View File

@@ -1,14 +1,17 @@
// Hardcoded module "node:perf_hooks"
import { throwNotImplemented } from "../shared";
export var performance = globalThis.performance;
export class PerformanceObserver {
constructor() {
throw new Error("PerformanceEntry is not implemented yet");
throwNotImplemented("PerformanceObserver");
}
}
export class PerformanceEntry {
constructor() {
throw new Error("PerformanceEntry is not implemented yet");
throwNotImplemented("PerformanceEntry");
}
}
export class PerformanceNodeTiming {

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:readline"
// Attribution: Some parts of of this module are derived from code originating from the Node.js
// readline module which is licensed under an MIT license:
//

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:readline/promises"
var {
promises: { Readline, Interface, createInterface },
} = import.meta.require("node:readline");

View File

@@ -1,26 +1,21 @@
// Hardcoded module "node:repl"
// This is a stub! None of this is actually implemented yet.
// It only exists to make some packages which import this module work.
class NotImplementedYet extends Error {
constructor(message = "node:repl is not implemented yet in Bun") {
super(message);
this.name = "NotImplementedYet";
}
}
import { throwNotImplemented } from "../shared";
function REPLServer() {
throw new NotImplementedYet("REPLServer is not implemented yet in Bun");
throwNotImplemented("node:repl REPLServer");
}
function Recoverable() {
throw new NotImplementedYet("Recoverable is not implemented yet in Bun");
throwNotImplemented("node:repl Recoverable");
}
var REPL_MODE_SLOPPY = 0,
REPL_MODE_STRICT = 1;
function start() {
throw new NotImplementedYet();
throwNotImplemented("node:repl");
}
var repl = {
@@ -33,7 +28,7 @@ var repl = {
removeHistoryDuplicates: false,
crlfDelay: 100,
completer: () => {
throw new NotImplementedYet();
throwNotImplemented("node:repl");
},
history: [],
_initialPrompt: "> ",
@@ -42,19 +37,19 @@ var repl = {
{},
{
get() {
throw new NotImplementedYet();
throwNotImplemented("node:repl");
},
has: () => false,
ownKeys: () => [],
getOwnPropertyDescriptor: () => undefined,
set() {
throw new NotImplementedYet();
throwNotImplemented("node:repl");
},
},
),
line: "",
eval: () => {
throw new NotImplementedYet();
throwNotImplemented("node:repl");
},
isCompletionEnabled: true,
escapeCodeTimeout: 500,
@@ -70,13 +65,13 @@ var repl = {
{},
{
get() {
throw new NotImplementedYet();
throwNotImplemented("node:repl");
},
has: () => false,
ownKeys: () => [],
getOwnPropertyDescriptor: () => undefined,
set() {
throw new NotImplementedYet();
throwNotImplemented("node:repl");
},
},
),

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:stream/consumers" / "readable-stream/consumer"
const { Bun } = import.meta.primordials;
export const arrayBuffer = Bun.readableStreamToArrayBuffer;

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:stream" / "readable-stream"
// "readable-stream" npm package
// just transpiled
var { isPromise, isCallable, direct, Object } = import.meta.primordials;

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:stream"
var { promises } = import.meta.require("node:stream");
export var { pipeline, finished } = promises;

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:stream/web" / "readable-stream/web"
export const {
ReadableStream,
ReadableStreamDefaultController,

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:timers"
// This implementation isn't 100% correct
// Ref/unref does not impact whether the process is kept alive

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:timers/promises"
// https://github.com/niksy/isomorphic-timers-promises/blob/master/index.js
const symbolAsyncIterator = Symbol.asyncIterator;

View File

@@ -1,7 +1,8 @@
const { isTypedArray } = import.meta.require("util/types");
// Hardcoded module "node:tls"
import { isTypedArray } from "util/types";
function parseCertString() {
throw Error("Not implemented");
throwNotImplemented("Not implemented");
}
function isValidTLSArray(obj) {

View File

@@ -1,5 +1,5 @@
// Hardcoded module "node:trace_events"
// This is a stub! This is not actually implemented yet.
class Tracing {
enabled = false;
categories = "";

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:url"
"use strict";
const { URL: F, URLSearchParams: M, [Symbol.for("Bun.lazy")]: S } = globalThis;
function it(s) {

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:util"
var __getOwnPropNames = Object.getOwnPropertyNames;
var __commonJS = (cb, mod) =>
function __require() {

View File

@@ -1,42 +1,26 @@
// Hardcoded module "node:v8"
// This is a stub! None of this is actually implemented yet.
class TODO extends Error {
constructor(messageName) {
const message = messageName
? `node:v8 ${messageName} is not implemented yet in Bun. `
: `node:v8 is not implemented yet in Bun`;
super(message);
this.name = "TODO";
}
}
function hideFromStack(fns) {
for (const fn of fns) {
Object.defineProperty(fn, "name", {
value: "::bunternal::",
});
}
}
import { hideFromStack, throwNotImplemented } from "../shared";
function notimpl(message) {
throw new TODO(message);
throwNotImplemented("node:v8 " + message);
}
class Deserializer {
constructor() {
notimpl();
notimpl("Deserializer");
}
}
class Serializer {
constructor() {
notimpl();
notimpl("Serializer");
}
}
class DefaultDeserializer extends Deserializer {}
class DefaultSerializer extends Serializer {}
class GCProfiler {
constructor() {
notimpl();
notimpl("GCProfiler");
}
}
@@ -143,8 +127,7 @@ export {
defaultObject as default,
};
hideFromStack([
TODO.prototype.constructor,
hideFromStack(
notimpl,
cachedDataVersionTag,
getHeapSnapshot,
@@ -163,4 +146,4 @@ hideFromStack([
DefaultDeserializer,
DefaultSerializer,
GCProfiler,
]);
);

View File

@@ -1,23 +1,12 @@
// Hardcoded module "node:vm"
import { throwNotImplemented } from "../shared";
const lazy = globalThis[Symbol.for("Bun.lazy")];
if (!lazy || typeof lazy !== "function") {
throw new Error("Something went wrong while loading Bun. Expected 'Bun.lazy' to be defined.");
}
const vm = lazy("vm");
class TODO extends Error {
constructor(messageName) {
const message = messageName
? `node:vm ${messageName} is not implemented yet in Bun. Track the status & thumbs up the issue: https://github.com/oven-sh/bun/issues/401`
: `node:vm is not implemented yet in Bun. Track the status & thumbs up the issue: https://github.com/oven-sh/bun/issues/401`;
super(message);
this.name = "TODO";
}
}
function notimpl(message) {
throw new TODO(message);
}
const { createContext, isContext, Script, runInNewContext, runInThisContext } = vm;
function runInContext(code, context, options) {
@@ -25,10 +14,10 @@ function runInContext(code, context, options) {
}
function compileFunction() {
notimpl("compileFunction");
throwNotImplemented("node:vm compileFunction", 401);
}
function measureMemory() {
notimpl("measureMemory");
throwNotImplemented("node:vm measureMemory", 401);
}
const defaultObject = {

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:wasi"
// HUGE thanks to:
// - @williamstein and https://github.com/sagemathinc/cowasm/tree/main/core/wasi-js
// - @syrusakbary for wasmer-js https://github.com/wasmerio/wasmer-js

View File

@@ -1,3 +1,4 @@
// Hardcoded module "node:zlib"
// TODO: **use a native binding from Bun for this!!**
// This is a very slow module!
// It should really be fixed. It will show up in benchmarking. It also loads

199
src/js/out/WebCoreJSBuiltins.d.ts vendored Normal file
View File

@@ -0,0 +1,199 @@
// Generated by `bun src/js/builtins/codegen`
// Do not edit by hand.
type RemoveThis<F> = F extends (this: infer T, ...args: infer A) => infer R ? (...args: A) => R : F;
// WritableStreamInternals.ts
declare const $isWritableStream: RemoveThis<typeof import("../builtins/WritableStreamInternals")["isWritableStream"]>;
declare const $isWritableStreamDefaultWriter: RemoveThis<typeof import("../builtins/WritableStreamInternals")["isWritableStreamDefaultWriter"]>;
declare const $acquireWritableStreamDefaultWriter: RemoveThis<typeof import("../builtins/WritableStreamInternals")["acquireWritableStreamDefaultWriter"]>;
declare const $createWritableStream: RemoveThis<typeof import("../builtins/WritableStreamInternals")["createWritableStream"]>;
declare const $createInternalWritableStreamFromUnderlyingSink: RemoveThis<typeof import("../builtins/WritableStreamInternals")["createInternalWritableStreamFromUnderlyingSink"]>;
declare const $initializeWritableStreamSlots: RemoveThis<typeof import("../builtins/WritableStreamInternals")["initializeWritableStreamSlots"]>;
declare const $writableStreamCloseForBindings: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamCloseForBindings"]>;
declare const $writableStreamAbortForBindings: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamAbortForBindings"]>;
declare const $isWritableStreamLocked: RemoveThis<typeof import("../builtins/WritableStreamInternals")["isWritableStreamLocked"]>;
declare const $setUpWritableStreamDefaultWriter: RemoveThis<typeof import("../builtins/WritableStreamInternals")["setUpWritableStreamDefaultWriter"]>;
declare const $writableStreamAbort: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamAbort"]>;
declare const $writableStreamClose: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamClose"]>;
declare const $writableStreamAddWriteRequest: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamAddWriteRequest"]>;
declare const $writableStreamCloseQueuedOrInFlight: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamCloseQueuedOrInFlight"]>;
declare const $writableStreamDealWithRejection: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDealWithRejection"]>;
declare const $writableStreamFinishErroring: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamFinishErroring"]>;
declare const $writableStreamFinishInFlightClose: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamFinishInFlightClose"]>;
declare const $writableStreamFinishInFlightCloseWithError: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamFinishInFlightCloseWithError"]>;
declare const $writableStreamFinishInFlightWrite: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamFinishInFlightWrite"]>;
declare const $writableStreamFinishInFlightWriteWithError: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamFinishInFlightWriteWithError"]>;
declare const $writableStreamHasOperationMarkedInFlight: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamHasOperationMarkedInFlight"]>;
declare const $writableStreamMarkCloseRequestInFlight: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamMarkCloseRequestInFlight"]>;
declare const $writableStreamMarkFirstWriteRequestInFlight: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamMarkFirstWriteRequestInFlight"]>;
declare const $writableStreamRejectCloseAndClosedPromiseIfNeeded: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamRejectCloseAndClosedPromiseIfNeeded"]>;
declare const $writableStreamStartErroring: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamStartErroring"]>;
declare const $writableStreamUpdateBackpressure: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamUpdateBackpressure"]>;
declare const $writableStreamDefaultWriterAbort: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultWriterAbort"]>;
declare const $writableStreamDefaultWriterClose: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultWriterClose"]>;
declare const $writableStreamDefaultWriterCloseWithErrorPropagation: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultWriterCloseWithErrorPropagation"]>;
declare const $writableStreamDefaultWriterEnsureClosedPromiseRejected: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultWriterEnsureClosedPromiseRejected"]>;
declare const $writableStreamDefaultWriterEnsureReadyPromiseRejected: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultWriterEnsureReadyPromiseRejected"]>;
declare const $writableStreamDefaultWriterGetDesiredSize: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultWriterGetDesiredSize"]>;
declare const $writableStreamDefaultWriterRelease: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultWriterRelease"]>;
declare const $writableStreamDefaultWriterWrite: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultWriterWrite"]>;
declare const $setUpWritableStreamDefaultController: RemoveThis<typeof import("../builtins/WritableStreamInternals")["setUpWritableStreamDefaultController"]>;
declare const $writableStreamDefaultControllerStart: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultControllerStart"]>;
declare const $setUpWritableStreamDefaultControllerFromUnderlyingSink: RemoveThis<typeof import("../builtins/WritableStreamInternals")["setUpWritableStreamDefaultControllerFromUnderlyingSink"]>;
declare const $writableStreamDefaultControllerAdvanceQueueIfNeeded: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultControllerAdvanceQueueIfNeeded"]>;
declare const $isCloseSentinel: RemoveThis<typeof import("../builtins/WritableStreamInternals")["isCloseSentinel"]>;
declare const $writableStreamDefaultControllerClearAlgorithms: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultControllerClearAlgorithms"]>;
declare const $writableStreamDefaultControllerClose: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultControllerClose"]>;
declare const $writableStreamDefaultControllerError: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultControllerError"]>;
declare const $writableStreamDefaultControllerErrorIfNeeded: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultControllerErrorIfNeeded"]>;
declare const $writableStreamDefaultControllerGetBackpressure: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultControllerGetBackpressure"]>;
declare const $writableStreamDefaultControllerGetChunkSize: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultControllerGetChunkSize"]>;
declare const $writableStreamDefaultControllerGetDesiredSize: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultControllerGetDesiredSize"]>;
declare const $writableStreamDefaultControllerProcessClose: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultControllerProcessClose"]>;
declare const $writableStreamDefaultControllerProcessWrite: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultControllerProcessWrite"]>;
declare const $writableStreamDefaultControllerWrite: RemoveThis<typeof import("../builtins/WritableStreamInternals")["writableStreamDefaultControllerWrite"]>;
// TransformStreamInternals.ts
declare const $isTransformStream: RemoveThis<typeof import("../builtins/TransformStreamInternals")["isTransformStream"]>;
declare const $isTransformStreamDefaultController: RemoveThis<typeof import("../builtins/TransformStreamInternals")["isTransformStreamDefaultController"]>;
declare const $createTransformStream: RemoveThis<typeof import("../builtins/TransformStreamInternals")["createTransformStream"]>;
declare const $initializeTransformStream: RemoveThis<typeof import("../builtins/TransformStreamInternals")["initializeTransformStream"]>;
declare const $transformStreamError: RemoveThis<typeof import("../builtins/TransformStreamInternals")["transformStreamError"]>;
declare const $transformStreamErrorWritableAndUnblockWrite: RemoveThis<typeof import("../builtins/TransformStreamInternals")["transformStreamErrorWritableAndUnblockWrite"]>;
declare const $transformStreamSetBackpressure: RemoveThis<typeof import("../builtins/TransformStreamInternals")["transformStreamSetBackpressure"]>;
declare const $setUpTransformStreamDefaultController: RemoveThis<typeof import("../builtins/TransformStreamInternals")["setUpTransformStreamDefaultController"]>;
declare const $setUpTransformStreamDefaultControllerFromTransformer: RemoveThis<typeof import("../builtins/TransformStreamInternals")["setUpTransformStreamDefaultControllerFromTransformer"]>;
declare const $transformStreamDefaultControllerClearAlgorithms: RemoveThis<typeof import("../builtins/TransformStreamInternals")["transformStreamDefaultControllerClearAlgorithms"]>;
declare const $transformStreamDefaultControllerEnqueue: RemoveThis<typeof import("../builtins/TransformStreamInternals")["transformStreamDefaultControllerEnqueue"]>;
declare const $transformStreamDefaultControllerError: RemoveThis<typeof import("../builtins/TransformStreamInternals")["transformStreamDefaultControllerError"]>;
declare const $transformStreamDefaultControllerPerformTransform: RemoveThis<typeof import("../builtins/TransformStreamInternals")["transformStreamDefaultControllerPerformTransform"]>;
declare const $transformStreamDefaultControllerTerminate: RemoveThis<typeof import("../builtins/TransformStreamInternals")["transformStreamDefaultControllerTerminate"]>;
declare const $transformStreamDefaultSinkWriteAlgorithm: RemoveThis<typeof import("../builtins/TransformStreamInternals")["transformStreamDefaultSinkWriteAlgorithm"]>;
declare const $transformStreamDefaultSinkAbortAlgorithm: RemoveThis<typeof import("../builtins/TransformStreamInternals")["transformStreamDefaultSinkAbortAlgorithm"]>;
declare const $transformStreamDefaultSinkCloseAlgorithm: RemoveThis<typeof import("../builtins/TransformStreamInternals")["transformStreamDefaultSinkCloseAlgorithm"]>;
declare const $transformStreamDefaultSourcePullAlgorithm: RemoveThis<typeof import("../builtins/TransformStreamInternals")["transformStreamDefaultSourcePullAlgorithm"]>;
// ReadableStreamInternals.ts
declare const $readableStreamReaderGenericInitialize: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamReaderGenericInitialize"]>;
declare const $privateInitializeReadableStreamDefaultController: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["privateInitializeReadableStreamDefaultController"]>;
declare const $readableStreamDefaultControllerError: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamDefaultControllerError"]>;
declare const $readableStreamPipeTo: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamPipeTo"]>;
declare const $acquireReadableStreamDefaultReader: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["acquireReadableStreamDefaultReader"]>;
declare const $setupReadableStreamDefaultController: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["setupReadableStreamDefaultController"]>;
declare const $createReadableStreamController: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["createReadableStreamController"]>;
declare const $readableStreamDefaultControllerStart: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamDefaultControllerStart"]>;
declare const $readableStreamPipeToWritableStream: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamPipeToWritableStream"]>;
declare const $pipeToLoop: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["pipeToLoop"]>;
declare const $pipeToDoReadWrite: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["pipeToDoReadWrite"]>;
declare const $pipeToErrorsMustBePropagatedForward: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["pipeToErrorsMustBePropagatedForward"]>;
declare const $pipeToErrorsMustBePropagatedBackward: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["pipeToErrorsMustBePropagatedBackward"]>;
declare const $pipeToClosingMustBePropagatedForward: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["pipeToClosingMustBePropagatedForward"]>;
declare const $pipeToClosingMustBePropagatedBackward: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["pipeToClosingMustBePropagatedBackward"]>;
declare const $pipeToShutdownWithAction: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["pipeToShutdownWithAction"]>;
declare const $pipeToShutdown: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["pipeToShutdown"]>;
declare const $pipeToFinalize: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["pipeToFinalize"]>;
declare const $readableStreamTee: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamTee"]>;
declare const $readableStreamTeePullFunction: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamTeePullFunction"]>;
declare const $readableStreamTeeBranch1CancelFunction: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamTeeBranch1CancelFunction"]>;
declare const $readableStreamTeeBranch2CancelFunction: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamTeeBranch2CancelFunction"]>;
declare const $isReadableStream: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["isReadableStream"]>;
declare const $isReadableStreamDefaultReader: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["isReadableStreamDefaultReader"]>;
declare const $isReadableStreamDefaultController: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["isReadableStreamDefaultController"]>;
declare const $readDirectStream: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readDirectStream"]>;
declare const $assignToStream: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["assignToStream"]>;
declare const $readStreamIntoSink: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readStreamIntoSink"]>;
declare const $handleDirectStreamError: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["handleDirectStreamError"]>;
declare const $handleDirectStreamErrorReject: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["handleDirectStreamErrorReject"]>;
declare const $onPullDirectStream: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["onPullDirectStream"]>;
declare const $noopDoneFunction: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["noopDoneFunction"]>;
declare const $onReadableStreamDirectControllerClosed: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["onReadableStreamDirectControllerClosed"]>;
declare const $onCloseDirectStream: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["onCloseDirectStream"]>;
declare const $onFlushDirectStream: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["onFlushDirectStream"]>;
declare const $createTextStream: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["createTextStream"]>;
declare const $initializeTextStream: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["initializeTextStream"]>;
declare const $initializeArrayStream: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["initializeArrayStream"]>;
declare const $initializeArrayBufferStream: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["initializeArrayBufferStream"]>;
declare const $readableStreamError: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamError"]>;
declare const $readableStreamDefaultControllerShouldCallPull: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamDefaultControllerShouldCallPull"]>;
declare const $readableStreamDefaultControllerCallPullIfNeeded: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamDefaultControllerCallPullIfNeeded"]>;
declare const $isReadableStreamLocked: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["isReadableStreamLocked"]>;
declare const $readableStreamDefaultControllerGetDesiredSize: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamDefaultControllerGetDesiredSize"]>;
declare const $readableStreamReaderGenericCancel: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamReaderGenericCancel"]>;
declare const $readableStreamCancel: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamCancel"]>;
declare const $readableStreamDefaultControllerCancel: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamDefaultControllerCancel"]>;
declare const $readableStreamDefaultControllerPull: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamDefaultControllerPull"]>;
declare const $readableStreamDefaultControllerClose: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamDefaultControllerClose"]>;
declare const $readableStreamClose: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamClose"]>;
declare const $readableStreamFulfillReadRequest: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamFulfillReadRequest"]>;
declare const $readableStreamDefaultControllerEnqueue: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamDefaultControllerEnqueue"]>;
declare const $readableStreamDefaultReaderRead: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamDefaultReaderRead"]>;
declare const $readableStreamAddReadRequest: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamAddReadRequest"]>;
declare const $isReadableStreamDisturbed: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["isReadableStreamDisturbed"]>;
declare const $readableStreamReaderGenericRelease: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamReaderGenericRelease"]>;
declare const $readableStreamDefaultControllerCanCloseOrEnqueue: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamDefaultControllerCanCloseOrEnqueue"]>;
declare const $lazyLoadStream: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["lazyLoadStream"]>;
declare const $readableStreamIntoArray: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamIntoArray"]>;
declare const $readableStreamIntoText: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamIntoText"]>;
declare const $readableStreamToArrayBufferDirect: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamToArrayBufferDirect"]>;
declare const $readableStreamToTextDirect: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamToTextDirect"]>;
declare const $readableStreamToArrayDirect: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamToArrayDirect"]>;
declare const $readableStreamDefineLazyIterators: RemoveThis<typeof import("../builtins/ReadableStreamInternals")["readableStreamDefineLazyIterators"]>;
// StreamInternals.ts
declare const $markPromiseAsHandled: RemoveThis<typeof import("../builtins/StreamInternals")["markPromiseAsHandled"]>;
declare const $shieldingPromiseResolve: RemoveThis<typeof import("../builtins/StreamInternals")["shieldingPromiseResolve"]>;
declare const $promiseInvokeOrNoopMethodNoCatch: RemoveThis<typeof import("../builtins/StreamInternals")["promiseInvokeOrNoopMethodNoCatch"]>;
declare const $promiseInvokeOrNoopNoCatch: RemoveThis<typeof import("../builtins/StreamInternals")["promiseInvokeOrNoopNoCatch"]>;
declare const $promiseInvokeOrNoopMethod: RemoveThis<typeof import("../builtins/StreamInternals")["promiseInvokeOrNoopMethod"]>;
declare const $promiseInvokeOrNoop: RemoveThis<typeof import("../builtins/StreamInternals")["promiseInvokeOrNoop"]>;
declare const $promiseInvokeOrFallbackOrNoop: RemoveThis<typeof import("../builtins/StreamInternals")["promiseInvokeOrFallbackOrNoop"]>;
declare const $validateAndNormalizeQueuingStrategy: RemoveThis<typeof import("../builtins/StreamInternals")["validateAndNormalizeQueuingStrategy"]>;
declare const $createFIFO: RemoveThis<typeof import("../builtins/StreamInternals")["createFIFO"]>;
declare const $newQueue: RemoveThis<typeof import("../builtins/StreamInternals")["newQueue"]>;
declare const $dequeueValue: RemoveThis<typeof import("../builtins/StreamInternals")["dequeueValue"]>;
declare const $enqueueValueWithSize: RemoveThis<typeof import("../builtins/StreamInternals")["enqueueValueWithSize"]>;
declare const $peekQueueValue: RemoveThis<typeof import("../builtins/StreamInternals")["peekQueueValue"]>;
declare const $resetQueue: RemoveThis<typeof import("../builtins/StreamInternals")["resetQueue"]>;
declare const $extractSizeAlgorithm: RemoveThis<typeof import("../builtins/StreamInternals")["extractSizeAlgorithm"]>;
declare const $extractHighWaterMark: RemoveThis<typeof import("../builtins/StreamInternals")["extractHighWaterMark"]>;
declare const $extractHighWaterMarkFromQueuingStrategyInit: RemoveThis<typeof import("../builtins/StreamInternals")["extractHighWaterMarkFromQueuingStrategyInit"]>;
declare const $createFulfilledPromise: RemoveThis<typeof import("../builtins/StreamInternals")["createFulfilledPromise"]>;
declare const $toDictionary: RemoveThis<typeof import("../builtins/StreamInternals")["toDictionary"]>;
// ReadableByteStreamInternals.ts
declare const $privateInitializeReadableByteStreamController: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["privateInitializeReadableByteStreamController"]>;
declare const $readableStreamByteStreamControllerStart: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableStreamByteStreamControllerStart"]>;
declare const $privateInitializeReadableStreamBYOBRequest: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["privateInitializeReadableStreamBYOBRequest"]>;
declare const $isReadableByteStreamController: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["isReadableByteStreamController"]>;
declare const $isReadableStreamBYOBRequest: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["isReadableStreamBYOBRequest"]>;
declare const $isReadableStreamBYOBReader: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["isReadableStreamBYOBReader"]>;
declare const $readableByteStreamControllerCancel: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerCancel"]>;
declare const $readableByteStreamControllerError: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerError"]>;
declare const $readableByteStreamControllerClose: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerClose"]>;
declare const $readableByteStreamControllerClearPendingPullIntos: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerClearPendingPullIntos"]>;
declare const $readableByteStreamControllerGetDesiredSize: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerGetDesiredSize"]>;
declare const $readableStreamHasBYOBReader: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableStreamHasBYOBReader"]>;
declare const $readableStreamHasDefaultReader: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableStreamHasDefaultReader"]>;
declare const $readableByteStreamControllerHandleQueueDrain: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerHandleQueueDrain"]>;
declare const $readableByteStreamControllerPull: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerPull"]>;
declare const $readableByteStreamControllerShouldCallPull: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerShouldCallPull"]>;
declare const $readableByteStreamControllerCallPullIfNeeded: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerCallPullIfNeeded"]>;
declare const $transferBufferToCurrentRealm: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["transferBufferToCurrentRealm"]>;
declare const $readableStreamReaderKind: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableStreamReaderKind"]>;
declare const $readableByteStreamControllerEnqueue: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerEnqueue"]>;
declare const $readableByteStreamControllerEnqueueChunk: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerEnqueueChunk"]>;
declare const $readableByteStreamControllerRespondWithNewView: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerRespondWithNewView"]>;
declare const $readableByteStreamControllerRespond: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerRespond"]>;
declare const $readableByteStreamControllerRespondInternal: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerRespondInternal"]>;
declare const $readableByteStreamControllerRespondInReadableState: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerRespondInReadableState"]>;
declare const $readableByteStreamControllerRespondInClosedState: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerRespondInClosedState"]>;
declare const $readableByteStreamControllerProcessPullDescriptors: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerProcessPullDescriptors"]>;
declare const $readableByteStreamControllerFillDescriptorFromQueue: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerFillDescriptorFromQueue"]>;
declare const $readableByteStreamControllerShiftPendingDescriptor: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerShiftPendingDescriptor"]>;
declare const $readableByteStreamControllerInvalidateBYOBRequest: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerInvalidateBYOBRequest"]>;
declare const $readableByteStreamControllerCommitDescriptor: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerCommitDescriptor"]>;
declare const $readableByteStreamControllerConvertDescriptor: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerConvertDescriptor"]>;
declare const $readableStreamFulfillReadIntoRequest: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableStreamFulfillReadIntoRequest"]>;
declare const $readableStreamBYOBReaderRead: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableStreamBYOBReaderRead"]>;
declare const $readableByteStreamControllerPullInto: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableByteStreamControllerPullInto"]>;
declare const $readableStreamAddReadIntoRequest: RemoveThis<typeof import("../builtins/ReadableByteStreamInternals")["readableStreamAddReadIntoRequest"]>;

View File

@@ -1,4 +1,4 @@
// Generated by `bun src/bun.js/builtins/codegen/index.js`
// Generated by `bun src/js/builtins/codegen`
// Do not edit by hand.
#pragma once
namespace Zig { class GlobalObject; }

View File

@@ -0,0 +1,269 @@
var cstringReturnType = function(val) {
return new __GlobalBunCString(val);
}, FFIBuilder = function(params, returnType, functionToCall, name) {
const hasReturnType = typeof FFIType[returnType] === "number" && FFIType[returnType] !== FFIType.void;
var paramNames = new Array(params.length), args = new Array(params.length);
for (let i = 0;i < params.length; i++) {
paramNames[i] = `p${i}`;
const wrapper = ffiWrappers[FFIType[params[i]]];
if (wrapper)
args[i] = `(${wrapper.toString()})(p${i})`;
else
throw new TypeError(`Unsupported type ${params[i]}. Must be one of: ${Object.keys(FFIType).sort().join(", ")}`);
}
var code = `functionToCall(${args.join(", ")})`;
if (hasReturnType)
if (FFIType[returnType] === FFIType.cstring)
code = `return (${cstringReturnType.toString()})(${code})`;
else
code = `return ${code}`;
var func = new Function("functionToCall", ...paramNames, code);
Object.defineProperty(func, "name", {
value: name
});
var wrap;
switch (paramNames.length) {
case 0:
wrap = () => func(functionToCall);
break;
case 1:
wrap = (arg1) => func(functionToCall, arg1);
break;
case 2:
wrap = (arg1, arg2) => func(functionToCall, arg1, arg2);
break;
case 3:
wrap = (arg1, arg2, arg3) => func(functionToCall, arg1, arg2, arg3);
break;
case 4:
wrap = (arg1, arg2, arg3, arg4) => func(functionToCall, arg1, arg2, arg3, arg4);
break;
case 5:
wrap = (arg1, arg2, arg3, arg4, arg5) => func(functionToCall, arg1, arg2, arg3, arg4, arg5);
break;
case 6:
wrap = (arg1, arg2, arg3, arg4, arg5, arg6) => func(functionToCall, arg1, arg2, arg3, arg4, arg5, arg6);
break;
case 7:
wrap = (arg1, arg2, arg3, arg4, arg5, arg6, arg7) => func(functionToCall, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
break;
case 8:
wrap = (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) => func(functionToCall, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
break;
case 9:
wrap = (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) => func(functionToCall, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
break;
default: {
wrap = (...args2) => func(functionToCall, ...args2);
break;
}
}
return wrap.native = functionToCall, wrap.ptr = functionToCall.ptr, wrap;
};
function dlopen(path, options) {
const result = nativeDLOpen(path, options);
for (let key in result.symbols) {
var symbol = result.symbols[key];
if (options[key]?.args?.length || FFIType[options[key]?.returns] === FFIType.cstring)
result.symbols[key] = FFIBuilder(options[key].args ?? [], options[key].returns ?? FFIType.void, symbol, path.includes("/") ? `${key} (${path.split("/").pop()})` : `${key} (${path})`);
else
result.symbols[key].native = result.symbols[key];
}
return result;
}
function linkSymbols(options) {
const result = nativeLinkSymbols(options);
for (let key in result.symbols) {
var symbol = result.symbols[key];
if (options[key]?.args?.length || FFIType[options[key]?.returns] === FFIType.cstring)
result.symbols[key] = FFIBuilder(options[key].args ?? [], options[key].returns ?? FFIType.void, symbol, key);
else
result.symbols[key].native = result.symbols[key];
}
return result;
}
var onCloseCFunction = function(close) {
close();
};
function CFunction(options) {
const identifier = `CFunction${cFunctionI++}`;
var result = linkSymbols({
[identifier]: options
}), hasClosed = !1, close = result.close;
return result.symbols[identifier].close = () => {
if (hasClosed || !close)
return;
hasClosed = !0, close(), close = void 0;
}, cFunctionRegistry ||= new FinalizationRegistry(onCloseCFunction), cFunctionRegistry.register(result.symbols[identifier], result.symbols[identifier].close), result.symbols[identifier];
}
var suffix = "dylib", ffi = globalThis.Bun.FFI, ptr = (arg1, arg2) => typeof arg2 === "undefined" ? ffi.ptr(arg1) : ffi.ptr(arg1, arg2), toBuffer = ffi.toBuffer, toArrayBuffer = ffi.toArrayBuffer, viewSource = ffi.viewSource, BunCString = ffi.CString, nativeLinkSymbols = ffi.linkSymbols, nativeDLOpen = ffi.dlopen, nativeCallback = ffi.callback, closeCallback = ffi.closeCallback;
delete ffi.callback;
delete ffi.closeCallback;
class JSCallback {
constructor(cb, options) {
const { ctx, ptr: ptr2 } = nativeCallback(options, cb);
this.#ctx = ctx, this.ptr = ptr2, this.#threadsafe = !!options?.threadsafe;
}
ptr;
#ctx;
#threadsafe;
get threadsafe() {
return this.#threadsafe;
}
[Symbol.toPrimitive]() {
const { ptr: ptr2 } = this;
return typeof ptr2 === "number" ? ptr2 : 0;
}
close() {
const ctx = this.#ctx;
if (this.ptr = null, this.#ctx = null, ctx)
closeCallback(ctx);
}
}
class CString extends String {
constructor(ptr2, byteOffset, byteLength) {
super(ptr2 ? typeof byteLength === "number" && Number.isSafeInteger(byteLength) ? new BunCString(ptr2, byteOffset || 0, byteLength) : new BunCString(ptr2) : "");
if (this.ptr = typeof ptr2 === "number" ? ptr2 : 0, typeof byteOffset !== "undefined")
this.byteOffset = byteOffset;
if (typeof byteLength !== "undefined")
this.byteLength = byteLength;
}
ptr;
byteOffset;
byteLength;
#cachedArrayBuffer;
get arrayBuffer() {
if (this.#cachedArrayBuffer)
return this.#cachedArrayBuffer;
if (!this.ptr)
return this.#cachedArrayBuffer = new ArrayBuffer(0);
return this.#cachedArrayBuffer = toArrayBuffer(this.ptr, this.byteOffset, this.byteLength);
}
}
Object.defineProperty(globalThis, "__GlobalBunCString", {
value: CString,
enumerable: !1,
configurable: !1
});
var ffiWrappers = new Array(18), char = (val) => val | 0;
ffiWrappers.fill(char);
ffiWrappers[FFIType.uint8_t] = function uint8(val) {
return val < 0 ? 0 : val >= 255 ? 255 : val | 0;
};
ffiWrappers[FFIType.int16_t] = function int16(val) {
return val <= -32768 ? -32768 : val >= 32768 ? 32768 : val | 0;
};
ffiWrappers[FFIType.uint16_t] = function uint16(val) {
return val <= 0 ? 0 : val >= 65536 ? 65536 : val | 0;
};
ffiWrappers[FFIType.int32_t] = function int32(val) {
return val | 0;
};
ffiWrappers[FFIType.uint32_t] = function uint32(val) {
return val <= 0 ? 0 : val >= 4294967295 ? 4294967295 : +val || 0;
};
ffiWrappers[FFIType.i64_fast] = function int64(val) {
if (typeof val === "bigint") {
if (val <= BigInt(Number.MAX_SAFE_INTEGER) && val >= BigInt(-Number.MAX_SAFE_INTEGER))
return Number(val).valueOf() || 0;
return val;
}
return !val ? 0 : +val || 0;
};
ffiWrappers[FFIType.u64_fast] = function u64_fast(val) {
if (typeof val === "bigint") {
if (val <= BigInt(Number.MAX_SAFE_INTEGER) && val >= 0)
return Number(val).valueOf() || 0;
return val;
}
return !val ? 0 : +val || 0;
};
ffiWrappers[FFIType.int64_t] = function int642(val) {
if (typeof val === "bigint")
return val;
if (typeof val === "number")
return BigInt(val || 0);
return BigInt(+val || 0);
};
ffiWrappers[FFIType.uint64_t] = function uint64(val) {
if (typeof val === "bigint")
return val;
if (typeof val === "number")
return val <= 0 ? BigInt(0) : BigInt(val || 0);
return BigInt(+val || 0);
};
ffiWrappers[FFIType.u64_fast] = function u64_fast2(val) {
if (typeof val === "bigint") {
if (val <= BigInt(Number.MAX_SAFE_INTEGER) && val >= BigInt(0))
return Number(val);
return val;
}
return typeof val === "number" ? val <= 0 ? 0 : +val || 0 : +val || 0;
};
ffiWrappers[FFIType.uint16_t] = function uint162(val) {
const ret = (typeof val === "bigint" ? Number(val) : val) | 0;
return ret <= 0 ? 0 : ret > 65535 ? 65535 : ret;
};
ffiWrappers[FFIType.double] = function double(val) {
if (typeof val === "bigint") {
if (val.valueOf() < BigInt(Number.MAX_VALUE))
return Math.abs(Number(val).valueOf()) + 0.00000000000001 - 0.00000000000001;
}
if (!val)
return 0;
return val + 0.00000000000001 - 0.00000000000001;
};
ffiWrappers[FFIType.float] = ffiWrappers[10] = function float(val) {
return Math.fround(val);
};
ffiWrappers[FFIType.bool] = function bool(val) {
return !!val;
};
Object.defineProperty(globalThis, "__GlobalBunFFIPtrFunctionForWrapper", {
value: ptr,
enumerable: !1,
configurable: !0
});
ffiWrappers[FFIType.cstring] = ffiWrappers[FFIType.pointer] = function pointer(val) {
if (typeof val === "number")
return val;
if (!val)
return null;
if (ArrayBuffer.isView(val) || val instanceof ArrayBuffer)
return __GlobalBunFFIPtrFunctionForWrapper(val);
if (typeof val === "string")
throw new TypeError("To convert a string to a pointer, encode it as a buffer");
throw new TypeError(`Unable to convert ${val} to a pointer`);
};
ffiWrappers[FFIType.function] = function functionType(val) {
if (typeof val === "number")
return val;
if (typeof val === "bigint")
return Number(val);
var ptr2 = val && val.ptr;
if (!ptr2)
throw new TypeError("Expected function to be a JSCallback or a number");
return ptr2;
};
var native = {
dlopen: nativeDLOpen,
callback: () => {
throw new Error("Deprecated. Use new JSCallback(options, fn) instead");
}
}, cFunctionI = 0, cFunctionRegistry, read = ffi.read;
export {
viewSource,
toBuffer,
toArrayBuffer,
suffix,
read,
ptr,
native,
linkSymbols,
dlopen,
JSCallback,
CString,
CFunction
};

Some files were not shown because too many files have changed in this diff Show More