bun-types 0.0.78 → 0.0.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/types.d.ts +961 -12
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ declare module "bun" {
|
|
|
66
66
|
* });
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
|
-
export function serve(options: Serve):
|
|
69
|
+
export function serve(options: Serve): Server;
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
72
|
* Synchronously resolve a `moduleId` as though it were imported from `parent`
|
|
@@ -521,9 +521,10 @@ declare module "bun" {
|
|
|
521
521
|
* Respond to {@link Request} objects with a {@link Response} object.
|
|
522
522
|
*
|
|
523
523
|
*/
|
|
524
|
-
fetch(request: Request): Response | Promise<Response>;
|
|
524
|
+
fetch(this: Server, request: Request): Response | Promise<Response>;
|
|
525
525
|
|
|
526
526
|
error?: (
|
|
527
|
+
this: Server,
|
|
527
528
|
request: Errorlike
|
|
528
529
|
) => Response | Promise<Response> | undefined | Promise<undefined>;
|
|
529
530
|
}
|
|
@@ -571,6 +572,41 @@ declare module "bun" {
|
|
|
571
572
|
serverNames: Record<string, SSLOptions & SSLAdvancedOptions>;
|
|
572
573
|
};
|
|
573
574
|
|
|
575
|
+
/**
|
|
576
|
+
* HTTP & HTTPS Server
|
|
577
|
+
*
|
|
578
|
+
* To start the server, see {@link serve}
|
|
579
|
+
*
|
|
580
|
+
* Often, you don't need to interact with this object directly. It exists to help you with the following tasks:
|
|
581
|
+
* - Stop the server
|
|
582
|
+
* - How many requests are currently being handled?
|
|
583
|
+
*
|
|
584
|
+
* For performance, Bun pre-allocates most of the data for 2048 concurrent requests.
|
|
585
|
+
* That means starting a new server allocates about 500 KB of memory. Try to
|
|
586
|
+
* avoid starting and stopping the server often (unless it's a new instance of bun).
|
|
587
|
+
*
|
|
588
|
+
* Powered by a fork of [uWebSockets](https://github.com/uNetworking/uWebSockets). Thank you @alexhultman.
|
|
589
|
+
*
|
|
590
|
+
*/
|
|
591
|
+
interface Server {
|
|
592
|
+
/**
|
|
593
|
+
* Stop listening to prevent new connections from being accepted.
|
|
594
|
+
*
|
|
595
|
+
* It does not close existing connections.
|
|
596
|
+
*
|
|
597
|
+
* It may take a second or two to actually stop.
|
|
598
|
+
*/
|
|
599
|
+
stop(): void;
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* How many requests are in-flight right now?
|
|
603
|
+
*/
|
|
604
|
+
readonly pendingRequests: number;
|
|
605
|
+
readonly port: number;
|
|
606
|
+
readonly hostname: string;
|
|
607
|
+
readonly development: boolean;
|
|
608
|
+
}
|
|
609
|
+
|
|
574
610
|
export type Serve = SSLServeOptions | ServeOptions;
|
|
575
611
|
|
|
576
612
|
/**
|
|
@@ -730,6 +766,8 @@ declare module "bun" {
|
|
|
730
766
|
}
|
|
731
767
|
export const unsafe: unsafe;
|
|
732
768
|
|
|
769
|
+
type DigestEncoding = "hex" | "base64";
|
|
770
|
+
|
|
733
771
|
/**
|
|
734
772
|
* Are ANSI colors enabled for stdin and stdout?
|
|
735
773
|
*
|
|
@@ -779,6 +817,16 @@ declare module "bun" {
|
|
|
779
817
|
edgeNames: string[];
|
|
780
818
|
}
|
|
781
819
|
|
|
820
|
+
/**
|
|
821
|
+
* Nanoseconds since Bun.js was started as an integer.
|
|
822
|
+
*
|
|
823
|
+
* This uses a high-resolution monotonic system timer.
|
|
824
|
+
*
|
|
825
|
+
* After 14 weeks of consecutive uptime, this function
|
|
826
|
+
* returns a `bigint` to prevent overflow
|
|
827
|
+
*/
|
|
828
|
+
export function nanoseconds(): number | bigint;
|
|
829
|
+
|
|
782
830
|
/**
|
|
783
831
|
* Generate a heap snapshot for seeing where the heap is being used
|
|
784
832
|
*/
|
|
@@ -801,6 +849,163 @@ declare module "bun" {
|
|
|
801
849
|
line?: number;
|
|
802
850
|
column?: number;
|
|
803
851
|
}
|
|
852
|
+
|
|
853
|
+
/**
|
|
854
|
+
* This class only exists in types
|
|
855
|
+
*/
|
|
856
|
+
abstract class CryptoHashInterface<T> {
|
|
857
|
+
/**
|
|
858
|
+
* Update the hash with data
|
|
859
|
+
*
|
|
860
|
+
* @param data
|
|
861
|
+
*/
|
|
862
|
+
update(data: StringOrBuffer): T;
|
|
863
|
+
|
|
864
|
+
/**
|
|
865
|
+
* Finalize the hash
|
|
866
|
+
*
|
|
867
|
+
* @param encoding `DigestEncoding` to return the hash in. If none is provided, it will return a `Uint8Array`.
|
|
868
|
+
*/
|
|
869
|
+
digest(encoding: DigestEncoding): string;
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* Finalize the hash
|
|
873
|
+
*
|
|
874
|
+
* @param hashInto `TypedArray` to write the hash into. Faster than creating a new one each time
|
|
875
|
+
*/
|
|
876
|
+
digest(hashInto?: TypedArray): TypedArray;
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* Run the hash over the given data
|
|
880
|
+
*
|
|
881
|
+
* @param input `string`, `Uint8Array`, or `ArrayBuffer` to hash. `Uint8Array` or `ArrayBuffer` is faster.
|
|
882
|
+
*
|
|
883
|
+
* @param hashInto `TypedArray` to write the hash into. Faster than creating a new one each time
|
|
884
|
+
*/
|
|
885
|
+
static hash(input: StringOrBuffer, hashInto?: TypedArray): TypedArray;
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Run the hash over the given data
|
|
889
|
+
*
|
|
890
|
+
* @param input `string`, `Uint8Array`, or `ArrayBuffer` to hash. `Uint8Array` or `ArrayBuffer` is faster.
|
|
891
|
+
*
|
|
892
|
+
* @param encoding `DigestEncoding` to return the hash in
|
|
893
|
+
*/
|
|
894
|
+
static hash(input: StringOrBuffer, encoding: DigestEncoding): string;
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
/**
|
|
898
|
+
*
|
|
899
|
+
* Hash `input` using [SHA-2 512/256](https://en.wikipedia.org/wiki/SHA-2#Comparison_of_SHA_functions)
|
|
900
|
+
*
|
|
901
|
+
* @param input `string`, `Uint8Array`, or `ArrayBuffer` to hash. `Uint8Array` or `ArrayBuffer` will be faster
|
|
902
|
+
* @param hashInto optional `Uint8Array` to write the hash to. 32 bytes minimum.
|
|
903
|
+
*
|
|
904
|
+
* This hashing function balances speed with cryptographic strength. This does not encrypt or decrypt data.
|
|
905
|
+
*
|
|
906
|
+
* The implementation uses [BoringSSL](https://boringssl.googlesource.com/boringssl) (used in Chromium & Go)
|
|
907
|
+
*
|
|
908
|
+
* The equivalent `openssl` command is:
|
|
909
|
+
*
|
|
910
|
+
* ```bash
|
|
911
|
+
* # You will need OpenSSL 3 or later
|
|
912
|
+
* openssl sha512-256 /path/to/file
|
|
913
|
+
*```
|
|
914
|
+
*/
|
|
915
|
+
export function sha(input: StringOrBuffer, hashInto?: Uint8Array): Uint8Array;
|
|
916
|
+
|
|
917
|
+
/**
|
|
918
|
+
*
|
|
919
|
+
* Hash `input` using [SHA-2 512/256](https://en.wikipedia.org/wiki/SHA-2#Comparison_of_SHA_functions)
|
|
920
|
+
*
|
|
921
|
+
* @param input `string`, `Uint8Array`, or `ArrayBuffer` to hash. `Uint8Array` or `ArrayBuffer` will be faster
|
|
922
|
+
* @param encoding `DigestEncoding` to return the hash in
|
|
923
|
+
*
|
|
924
|
+
* This hashing function balances speed with cryptographic strength. This does not encrypt or decrypt data.
|
|
925
|
+
*
|
|
926
|
+
* The implementation uses [BoringSSL](https://boringssl.googlesource.com/boringssl) (used in Chromium & Go)
|
|
927
|
+
*
|
|
928
|
+
* The equivalent `openssl` command is:
|
|
929
|
+
*
|
|
930
|
+
* ```bash
|
|
931
|
+
* # You will need OpenSSL 3 or later
|
|
932
|
+
* openssl sha512-256 /path/to/file
|
|
933
|
+
*```
|
|
934
|
+
*/
|
|
935
|
+
export function sha(input: StringOrBuffer, encoding: DigestEncoding): string;
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
* This is not the default because it's not cryptographically secure and it's slower than {@link SHA512}
|
|
939
|
+
*
|
|
940
|
+
* Consider using the ugly-named {@link SHA512_256} instead
|
|
941
|
+
*/
|
|
942
|
+
export class SHA1 extends CryptoHashInterface<SHA1> {
|
|
943
|
+
constructor();
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* The number of bytes the hash will produce
|
|
947
|
+
*/
|
|
948
|
+
static readonly byteLength: 20;
|
|
949
|
+
}
|
|
950
|
+
export class MD5 extends CryptoHashInterface<MD5> {
|
|
951
|
+
constructor();
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* The number of bytes the hash will produce
|
|
955
|
+
*/
|
|
956
|
+
static readonly byteLength: 16;
|
|
957
|
+
}
|
|
958
|
+
export class MD4 extends CryptoHashInterface<MD4> {
|
|
959
|
+
constructor();
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* The number of bytes the hash will produce
|
|
963
|
+
*/
|
|
964
|
+
static readonly byteLength: 16;
|
|
965
|
+
}
|
|
966
|
+
export class SHA224 extends CryptoHashInterface<SHA224> {
|
|
967
|
+
constructor();
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* The number of bytes the hash will produce
|
|
971
|
+
*/
|
|
972
|
+
static readonly byteLength: 28;
|
|
973
|
+
}
|
|
974
|
+
export class SHA512 extends CryptoHashInterface<SHA512> {
|
|
975
|
+
constructor();
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* The number of bytes the hash will produce
|
|
979
|
+
*/
|
|
980
|
+
static readonly byteLength: 64;
|
|
981
|
+
}
|
|
982
|
+
export class SHA384 extends CryptoHashInterface<SHA384> {
|
|
983
|
+
constructor();
|
|
984
|
+
|
|
985
|
+
/**
|
|
986
|
+
* The number of bytes the hash will produce
|
|
987
|
+
*/
|
|
988
|
+
static readonly byteLength: 48;
|
|
989
|
+
}
|
|
990
|
+
export class SHA256 extends CryptoHashInterface<SHA256> {
|
|
991
|
+
constructor();
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* The number of bytes the hash will produce
|
|
995
|
+
*/
|
|
996
|
+
static readonly byteLength: 32;
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* See also {@link sha}
|
|
1000
|
+
*/
|
|
1001
|
+
export class SHA512_256 extends CryptoHashInterface<SHA512_256> {
|
|
1002
|
+
constructor();
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* The number of bytes the hash will produce
|
|
1006
|
+
*/
|
|
1007
|
+
static readonly byteLength: 32;
|
|
1008
|
+
}
|
|
804
1009
|
}
|
|
805
1010
|
|
|
806
1011
|
type TypedArray =
|
|
@@ -836,6 +1041,645 @@ interface BufferEncodingOption {
|
|
|
836
1041
|
declare var Bun: typeof import("bun");
|
|
837
1042
|
|
|
838
1043
|
|
|
1044
|
+
// ./ffi.d.ts
|
|
1045
|
+
|
|
1046
|
+
/**
|
|
1047
|
+
* `bun:ffi` lets you efficiently call C functions & FFI functions from JavaScript
|
|
1048
|
+
* without writing bindings yourself.
|
|
1049
|
+
*
|
|
1050
|
+
* ```js
|
|
1051
|
+
* import {dlopen, CString, ptr} from 'bun:ffi';
|
|
1052
|
+
*
|
|
1053
|
+
* const lib = dlopen('libsqlite3', {
|
|
1054
|
+
* });
|
|
1055
|
+
* ```
|
|
1056
|
+
*
|
|
1057
|
+
* This is powered by just-in-time compiling C wrappers
|
|
1058
|
+
* that convert JavaScript types to C types and back. Internally,
|
|
1059
|
+
* bun uses [tinycc](https://github.com/TinyCC/tinycc), so a big thanks
|
|
1060
|
+
* goes to Fabrice Bellard and TinyCC maintainers for making this possible.
|
|
1061
|
+
*
|
|
1062
|
+
*/
|
|
1063
|
+
declare module "bun:ffi" {
|
|
1064
|
+
export enum FFIType {
|
|
1065
|
+
char = 0,
|
|
1066
|
+
/**
|
|
1067
|
+
* 8-bit signed integer
|
|
1068
|
+
*
|
|
1069
|
+
* Must be a value between -127 and 127
|
|
1070
|
+
*
|
|
1071
|
+
* When passing to a FFI function (C ABI), type coercsion is not performed.
|
|
1072
|
+
*
|
|
1073
|
+
* In C:
|
|
1074
|
+
* ```c
|
|
1075
|
+
* signed char
|
|
1076
|
+
* char // on x64 & aarch64 macOS
|
|
1077
|
+
* ```
|
|
1078
|
+
*
|
|
1079
|
+
* In JavaScript:
|
|
1080
|
+
* ```js
|
|
1081
|
+
* var num = 0;
|
|
1082
|
+
* ```
|
|
1083
|
+
*/
|
|
1084
|
+
int8_t = 1,
|
|
1085
|
+
/**
|
|
1086
|
+
* 8-bit signed integer
|
|
1087
|
+
*
|
|
1088
|
+
* Must be a value between -127 and 127
|
|
1089
|
+
*
|
|
1090
|
+
* When passing to a FFI function (C ABI), type coercsion is not performed.
|
|
1091
|
+
*
|
|
1092
|
+
* In C:
|
|
1093
|
+
* ```c
|
|
1094
|
+
* signed char
|
|
1095
|
+
* char // on x64 & aarch64 macOS
|
|
1096
|
+
* ```
|
|
1097
|
+
*
|
|
1098
|
+
* In JavaScript:
|
|
1099
|
+
* ```js
|
|
1100
|
+
* var num = 0;
|
|
1101
|
+
* ```
|
|
1102
|
+
*/
|
|
1103
|
+
i8 = 1,
|
|
1104
|
+
|
|
1105
|
+
/**
|
|
1106
|
+
* 8-bit unsigned integer
|
|
1107
|
+
*
|
|
1108
|
+
* Must be a value between 0 and 255
|
|
1109
|
+
*
|
|
1110
|
+
* When passing to a FFI function (C ABI), type coercsion is not performed.
|
|
1111
|
+
*
|
|
1112
|
+
* In C:
|
|
1113
|
+
* ```c
|
|
1114
|
+
* unsigned char
|
|
1115
|
+
* ```
|
|
1116
|
+
*
|
|
1117
|
+
* In JavaScript:
|
|
1118
|
+
* ```js
|
|
1119
|
+
* var num = 0;
|
|
1120
|
+
* ```
|
|
1121
|
+
*/
|
|
1122
|
+
uint8_t = 2,
|
|
1123
|
+
/**
|
|
1124
|
+
* 8-bit unsigned integer
|
|
1125
|
+
*
|
|
1126
|
+
* Must be a value between 0 and 255
|
|
1127
|
+
*
|
|
1128
|
+
* When passing to a FFI function (C ABI), type coercsion is not performed.
|
|
1129
|
+
*
|
|
1130
|
+
* In C:
|
|
1131
|
+
* ```c
|
|
1132
|
+
* unsigned char
|
|
1133
|
+
* ```
|
|
1134
|
+
*
|
|
1135
|
+
* In JavaScript:
|
|
1136
|
+
* ```js
|
|
1137
|
+
* var num = 0;
|
|
1138
|
+
* ```
|
|
1139
|
+
*/
|
|
1140
|
+
u8 = 2,
|
|
1141
|
+
|
|
1142
|
+
/**
|
|
1143
|
+
* 16-bit signed integer
|
|
1144
|
+
*
|
|
1145
|
+
* Must be a value between -32768 and 32767
|
|
1146
|
+
*
|
|
1147
|
+
* When passing to a FFI function (C ABI), type coercsion is not performed.
|
|
1148
|
+
*
|
|
1149
|
+
* In C:
|
|
1150
|
+
* ```c
|
|
1151
|
+
* in16_t
|
|
1152
|
+
* short // on arm64 & x64
|
|
1153
|
+
* ```
|
|
1154
|
+
*
|
|
1155
|
+
* In JavaScript:
|
|
1156
|
+
* ```js
|
|
1157
|
+
* var num = 0;
|
|
1158
|
+
* ```
|
|
1159
|
+
*/
|
|
1160
|
+
int16_t = 3,
|
|
1161
|
+
/**
|
|
1162
|
+
* 16-bit signed integer
|
|
1163
|
+
*
|
|
1164
|
+
* Must be a value between -32768 and 32767
|
|
1165
|
+
*
|
|
1166
|
+
* When passing to a FFI function (C ABI), type coercsion is not performed.
|
|
1167
|
+
*
|
|
1168
|
+
* In C:
|
|
1169
|
+
* ```c
|
|
1170
|
+
* in16_t
|
|
1171
|
+
* short // on arm64 & x64
|
|
1172
|
+
* ```
|
|
1173
|
+
*
|
|
1174
|
+
* In JavaScript:
|
|
1175
|
+
* ```js
|
|
1176
|
+
* var num = 0;
|
|
1177
|
+
* ```
|
|
1178
|
+
*/
|
|
1179
|
+
i16 = 3,
|
|
1180
|
+
|
|
1181
|
+
/**
|
|
1182
|
+
* 16-bit unsigned integer
|
|
1183
|
+
*
|
|
1184
|
+
* Must be a value between 0 and 65535, inclusive.
|
|
1185
|
+
*
|
|
1186
|
+
* When passing to a FFI function (C ABI), type coercsion is not performed.
|
|
1187
|
+
*
|
|
1188
|
+
* In C:
|
|
1189
|
+
* ```c
|
|
1190
|
+
* uint16_t
|
|
1191
|
+
* unsigned short // on arm64 & x64
|
|
1192
|
+
* ```
|
|
1193
|
+
*
|
|
1194
|
+
* In JavaScript:
|
|
1195
|
+
* ```js
|
|
1196
|
+
* var num = 0;
|
|
1197
|
+
* ```
|
|
1198
|
+
*/
|
|
1199
|
+
uint16_t = 4,
|
|
1200
|
+
/**
|
|
1201
|
+
* 16-bit unsigned integer
|
|
1202
|
+
*
|
|
1203
|
+
* Must be a value between 0 and 65535, inclusive.
|
|
1204
|
+
*
|
|
1205
|
+
* When passing to a FFI function (C ABI), type coercsion is not performed.
|
|
1206
|
+
*
|
|
1207
|
+
* In C:
|
|
1208
|
+
* ```c
|
|
1209
|
+
* uint16_t
|
|
1210
|
+
* unsigned short // on arm64 & x64
|
|
1211
|
+
* ```
|
|
1212
|
+
*
|
|
1213
|
+
* In JavaScript:
|
|
1214
|
+
* ```js
|
|
1215
|
+
* var num = 0;
|
|
1216
|
+
* ```
|
|
1217
|
+
*/
|
|
1218
|
+
u16 = 4,
|
|
1219
|
+
|
|
1220
|
+
/**
|
|
1221
|
+
* 32-bit signed integer
|
|
1222
|
+
*
|
|
1223
|
+
*/
|
|
1224
|
+
int32_t = 5,
|
|
1225
|
+
|
|
1226
|
+
/**
|
|
1227
|
+
* 32-bit signed integer
|
|
1228
|
+
*
|
|
1229
|
+
* Alias of {@link FFIType.int32_t}
|
|
1230
|
+
*/
|
|
1231
|
+
i32 = 5,
|
|
1232
|
+
/**
|
|
1233
|
+
* 32-bit signed integer
|
|
1234
|
+
*
|
|
1235
|
+
* The same as `int` in C
|
|
1236
|
+
*
|
|
1237
|
+
* ```c
|
|
1238
|
+
* int
|
|
1239
|
+
* ```
|
|
1240
|
+
*/
|
|
1241
|
+
int = 5,
|
|
1242
|
+
|
|
1243
|
+
/**
|
|
1244
|
+
* 32-bit unsigned integer
|
|
1245
|
+
*
|
|
1246
|
+
* The same as `unsigned int` in C (on x64 & arm64)
|
|
1247
|
+
*
|
|
1248
|
+
* C:
|
|
1249
|
+
* ```c
|
|
1250
|
+
* unsigned int
|
|
1251
|
+
* ```
|
|
1252
|
+
* JavaScript:
|
|
1253
|
+
* ```js
|
|
1254
|
+
* ptr(new Uint32Array(1))
|
|
1255
|
+
* ```
|
|
1256
|
+
*/
|
|
1257
|
+
uint32_t = 6,
|
|
1258
|
+
/**
|
|
1259
|
+
* 32-bit unsigned integer
|
|
1260
|
+
*
|
|
1261
|
+
* Alias of {@link FFIType.uint32_t}
|
|
1262
|
+
*/
|
|
1263
|
+
u32 = 6,
|
|
1264
|
+
|
|
1265
|
+
/**
|
|
1266
|
+
* int64 is a 64-bit signed integer
|
|
1267
|
+
*
|
|
1268
|
+
* This is not implemented yet!
|
|
1269
|
+
*/
|
|
1270
|
+
int64_t = 7,
|
|
1271
|
+
/**
|
|
1272
|
+
* i64 is a 64-bit signed integer
|
|
1273
|
+
*
|
|
1274
|
+
* This is not implemented yet!
|
|
1275
|
+
*/
|
|
1276
|
+
i64 = 7,
|
|
1277
|
+
|
|
1278
|
+
/**
|
|
1279
|
+
* 64-bit unsigned integer
|
|
1280
|
+
*
|
|
1281
|
+
* This is not implemented yet!
|
|
1282
|
+
*/
|
|
1283
|
+
uint64_t = 8,
|
|
1284
|
+
/**
|
|
1285
|
+
* 64-bit unsigned integer
|
|
1286
|
+
*
|
|
1287
|
+
* This is not implemented yet!
|
|
1288
|
+
*/
|
|
1289
|
+
u64 = 8,
|
|
1290
|
+
|
|
1291
|
+
/**
|
|
1292
|
+
* Doubles are not supported yet!
|
|
1293
|
+
*/
|
|
1294
|
+
double = 9,
|
|
1295
|
+
/**
|
|
1296
|
+
* Doubles are not supported yet!
|
|
1297
|
+
*/
|
|
1298
|
+
f64 = 9,
|
|
1299
|
+
/**
|
|
1300
|
+
* Floats are not supported yet!
|
|
1301
|
+
*/
|
|
1302
|
+
float = 10,
|
|
1303
|
+
/**
|
|
1304
|
+
* Floats are not supported yet!
|
|
1305
|
+
*/
|
|
1306
|
+
f32 = 10,
|
|
1307
|
+
|
|
1308
|
+
/**
|
|
1309
|
+
* Booelan value
|
|
1310
|
+
*
|
|
1311
|
+
* Must be `true` or `false`. `0` and `1` type coercion is not supported.
|
|
1312
|
+
*
|
|
1313
|
+
* In C, this corresponds to:
|
|
1314
|
+
* ```c
|
|
1315
|
+
* bool
|
|
1316
|
+
* _Bool
|
|
1317
|
+
* ```
|
|
1318
|
+
*
|
|
1319
|
+
*
|
|
1320
|
+
*/
|
|
1321
|
+
bool = 11,
|
|
1322
|
+
|
|
1323
|
+
/**
|
|
1324
|
+
* Pointer value
|
|
1325
|
+
*
|
|
1326
|
+
* See {@link Bun.FFI.ptr} for more information
|
|
1327
|
+
*
|
|
1328
|
+
* In C:
|
|
1329
|
+
* ```c
|
|
1330
|
+
* void*
|
|
1331
|
+
* ```
|
|
1332
|
+
*
|
|
1333
|
+
* In JavaScript:
|
|
1334
|
+
* ```js
|
|
1335
|
+
* ptr(new Uint8Array(1))
|
|
1336
|
+
* ```
|
|
1337
|
+
*/
|
|
1338
|
+
ptr = 12,
|
|
1339
|
+
/**
|
|
1340
|
+
* Pointer value
|
|
1341
|
+
*
|
|
1342
|
+
* alias of {@link FFIType.ptr}
|
|
1343
|
+
*/
|
|
1344
|
+
pointer = 12,
|
|
1345
|
+
|
|
1346
|
+
/**
|
|
1347
|
+
* void value
|
|
1348
|
+
*
|
|
1349
|
+
* void arguments are not supported
|
|
1350
|
+
*
|
|
1351
|
+
* void return type is the default return type
|
|
1352
|
+
*
|
|
1353
|
+
* In C:
|
|
1354
|
+
* ```c
|
|
1355
|
+
* void
|
|
1356
|
+
* ```
|
|
1357
|
+
*
|
|
1358
|
+
*/
|
|
1359
|
+
void = 13,
|
|
1360
|
+
|
|
1361
|
+
/**
|
|
1362
|
+
* When used as a `returns`, this will automatically become a {@link CString}.
|
|
1363
|
+
*
|
|
1364
|
+
* When used in `args` it is equivalent to {@link FFIType.pointer}
|
|
1365
|
+
*
|
|
1366
|
+
*/
|
|
1367
|
+
cstring = 14,
|
|
1368
|
+
|
|
1369
|
+
/**
|
|
1370
|
+
* Attempt to coerce `BigInt` into a `Number` if it fits. This improves performance
|
|
1371
|
+
* but means you might get a `BigInt` or you might get a `number`.
|
|
1372
|
+
*
|
|
1373
|
+
* In C, this always becomes `int64_t`
|
|
1374
|
+
*
|
|
1375
|
+
* In JavaScript, this could be number or it could be BigInt, depending on what
|
|
1376
|
+
* value is passed in.
|
|
1377
|
+
*
|
|
1378
|
+
*/
|
|
1379
|
+
i64_fast = 15,
|
|
1380
|
+
|
|
1381
|
+
/**
|
|
1382
|
+
* Attempt to coerce `BigInt` into a `Number` if it fits. This improves performance
|
|
1383
|
+
* but means you might get a `BigInt` or you might get a `number`.
|
|
1384
|
+
*
|
|
1385
|
+
* In C, this always becomes `uint64_t`
|
|
1386
|
+
*
|
|
1387
|
+
* In JavaScript, this could be number or it could be BigInt, depending on what
|
|
1388
|
+
* value is passed in.
|
|
1389
|
+
*
|
|
1390
|
+
*/
|
|
1391
|
+
u64_fast = 16,
|
|
1392
|
+
}
|
|
1393
|
+
export type FFITypeOrString =
|
|
1394
|
+
| FFIType
|
|
1395
|
+
| "char"
|
|
1396
|
+
| "int8_t"
|
|
1397
|
+
| "i8"
|
|
1398
|
+
| "uint8_t"
|
|
1399
|
+
| "u8"
|
|
1400
|
+
| "int16_t"
|
|
1401
|
+
| "i16"
|
|
1402
|
+
| "uint16_t"
|
|
1403
|
+
| "u16"
|
|
1404
|
+
| "int32_t"
|
|
1405
|
+
| "i32"
|
|
1406
|
+
| "int"
|
|
1407
|
+
| "uint32_t"
|
|
1408
|
+
| "u32"
|
|
1409
|
+
| "int64_t"
|
|
1410
|
+
| "i64"
|
|
1411
|
+
| "uint64_t"
|
|
1412
|
+
| "u64"
|
|
1413
|
+
| "double"
|
|
1414
|
+
| "f64"
|
|
1415
|
+
| "float"
|
|
1416
|
+
| "f32"
|
|
1417
|
+
| "bool"
|
|
1418
|
+
| "ptr"
|
|
1419
|
+
| "pointer"
|
|
1420
|
+
| "void"
|
|
1421
|
+
| "cstring";
|
|
1422
|
+
|
|
1423
|
+
interface FFIFunction {
|
|
1424
|
+
/**
|
|
1425
|
+
* Arguments to a FFI function (C ABI)
|
|
1426
|
+
*
|
|
1427
|
+
* Defaults to an empty array, which means no arguments.
|
|
1428
|
+
*
|
|
1429
|
+
* To pass a pointer, use "ptr" or "pointer" as the type name. To get a pointer, see {@link ptr}.
|
|
1430
|
+
*
|
|
1431
|
+
* @example
|
|
1432
|
+
* From JavaScript:
|
|
1433
|
+
* ```js
|
|
1434
|
+
* const lib = dlopen('add', {
|
|
1435
|
+
* // FFIType can be used or you can pass string labels.
|
|
1436
|
+
* args: [FFIType.i32, "i32"],
|
|
1437
|
+
* returns: "i32",
|
|
1438
|
+
* });
|
|
1439
|
+
* lib.symbols.add(1, 2)
|
|
1440
|
+
* ```
|
|
1441
|
+
* In C:
|
|
1442
|
+
* ```c
|
|
1443
|
+
* int add(int a, int b) {
|
|
1444
|
+
* return a + b;
|
|
1445
|
+
* }
|
|
1446
|
+
* ```
|
|
1447
|
+
*/
|
|
1448
|
+
args?: FFITypeOrString[];
|
|
1449
|
+
/**
|
|
1450
|
+
* Return type to a FFI function (C ABI)
|
|
1451
|
+
*
|
|
1452
|
+
* Defaults to {@link FFIType.void}
|
|
1453
|
+
*
|
|
1454
|
+
* To pass a pointer, use "ptr" or "pointer" as the type name. To get a pointer, see {@link ptr}.
|
|
1455
|
+
*
|
|
1456
|
+
* @example
|
|
1457
|
+
* From JavaScript:
|
|
1458
|
+
* ```js
|
|
1459
|
+
* const lib = dlopen('z', {
|
|
1460
|
+
* version: {
|
|
1461
|
+
* returns: "ptr",
|
|
1462
|
+
* }
|
|
1463
|
+
* });
|
|
1464
|
+
* console.log(new CString(lib.symbols.version()));
|
|
1465
|
+
* ```
|
|
1466
|
+
* In C:
|
|
1467
|
+
* ```c
|
|
1468
|
+
* char* version()
|
|
1469
|
+
* {
|
|
1470
|
+
* return "1.0.0";
|
|
1471
|
+
* }
|
|
1472
|
+
* ```
|
|
1473
|
+
*/
|
|
1474
|
+
returns?: FFITypeOrString;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
type Symbols = Record<string, FFIFunction>;
|
|
1478
|
+
|
|
1479
|
+
// /**
|
|
1480
|
+
// * Compile a callback function
|
|
1481
|
+
// *
|
|
1482
|
+
// * Returns a function pointer
|
|
1483
|
+
// *
|
|
1484
|
+
// */
|
|
1485
|
+
// export function callback(ffi: FFIFunction, cb: Function): number;
|
|
1486
|
+
|
|
1487
|
+
export interface Library {
|
|
1488
|
+
symbols: Record<
|
|
1489
|
+
string,
|
|
1490
|
+
CallableFunction & {
|
|
1491
|
+
/**
|
|
1492
|
+
* The function without a wrapper
|
|
1493
|
+
*/
|
|
1494
|
+
native: CallableFunction;
|
|
1495
|
+
}
|
|
1496
|
+
>;
|
|
1497
|
+
|
|
1498
|
+
/**
|
|
1499
|
+
* `dlclose` the library, unloading the symbols and freeing allocated memory.
|
|
1500
|
+
*
|
|
1501
|
+
* Once called, the library is no longer usable.
|
|
1502
|
+
*
|
|
1503
|
+
* Calling a function from a library that has been closed is undefined behavior.
|
|
1504
|
+
*/
|
|
1505
|
+
close(): void;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
export function dlopen(libraryName: string, symbols: Symbols): Library;
|
|
1509
|
+
|
|
1510
|
+
/**
|
|
1511
|
+
* Read a pointer as a {@link Buffer}
|
|
1512
|
+
*
|
|
1513
|
+
* If `byteLength` is not provided, the pointer is assumed to be 0-terminated.
|
|
1514
|
+
*
|
|
1515
|
+
* @param ptr The memory address to read
|
|
1516
|
+
* @param byteOffset bytes to skip before reading
|
|
1517
|
+
* @param byteLength bytes to read
|
|
1518
|
+
*
|
|
1519
|
+
* While there are some checks to catch invalid pointers, this is a difficult
|
|
1520
|
+
* thing to do safely. Passing an invalid pointer can crash the program and
|
|
1521
|
+
* reading beyond the bounds of the pointer will crash the program or cause
|
|
1522
|
+
* undefined behavior. Use with care!
|
|
1523
|
+
*
|
|
1524
|
+
*/
|
|
1525
|
+
export function toBuffer(
|
|
1526
|
+
ptr: number,
|
|
1527
|
+
byteOffset?: number,
|
|
1528
|
+
byteLength?: number
|
|
1529
|
+
): Buffer;
|
|
1530
|
+
|
|
1531
|
+
/**
|
|
1532
|
+
* Read a pointer as an {@link ArrayBuffer}
|
|
1533
|
+
*
|
|
1534
|
+
* If `byteLength` is not provided, the pointer is assumed to be 0-terminated.
|
|
1535
|
+
*
|
|
1536
|
+
* @param ptr The memory address to read
|
|
1537
|
+
* @param byteOffset bytes to skip before reading
|
|
1538
|
+
* @param byteLength bytes to read
|
|
1539
|
+
*
|
|
1540
|
+
* While there are some checks to catch invalid pointers, this is a difficult
|
|
1541
|
+
* thing to do safely. Passing an invalid pointer can crash the program and
|
|
1542
|
+
* reading beyond the bounds of the pointer will crash the program or cause
|
|
1543
|
+
* undefined behavior. Use with care!
|
|
1544
|
+
*/
|
|
1545
|
+
export function toArrayBuffer(
|
|
1546
|
+
ptr: number,
|
|
1547
|
+
byteOffset?: number,
|
|
1548
|
+
byteLength?: number
|
|
1549
|
+
): ArrayBuffer;
|
|
1550
|
+
|
|
1551
|
+
/**
|
|
1552
|
+
* Get the pointer backing a {@link TypedArray} or {@link ArrayBuffer}
|
|
1553
|
+
*
|
|
1554
|
+
* Use this to pass {@link TypedArray} or {@link ArrayBuffer} to C functions.
|
|
1555
|
+
*
|
|
1556
|
+
* This is for use with FFI functions. For performance reasons, FFI will
|
|
1557
|
+
* not automatically convert typed arrays to C pointers.
|
|
1558
|
+
*
|
|
1559
|
+
* @param {TypedArray|ArrayBuffer|DataView} view the typed array or array buffer to get the pointer for
|
|
1560
|
+
* @param {number} byteOffset optional offset into the view in bytes
|
|
1561
|
+
*
|
|
1562
|
+
* @example
|
|
1563
|
+
*
|
|
1564
|
+
* From JavaScript:
|
|
1565
|
+
* ```js
|
|
1566
|
+
* const array = new Uint8Array(10);
|
|
1567
|
+
* const rawPtr = ptr(array);
|
|
1568
|
+
* myFFIFunction(rawPtr);
|
|
1569
|
+
* ```
|
|
1570
|
+
* To C:
|
|
1571
|
+
* ```c
|
|
1572
|
+
* void myFFIFunction(char* rawPtr) {
|
|
1573
|
+
* // Do something with rawPtr
|
|
1574
|
+
* }
|
|
1575
|
+
* ```
|
|
1576
|
+
*
|
|
1577
|
+
*/
|
|
1578
|
+
export function ptr(
|
|
1579
|
+
view: TypedArray | ArrayBufferLike | DataView,
|
|
1580
|
+
byteOffset?: number
|
|
1581
|
+
): number;
|
|
1582
|
+
|
|
1583
|
+
/**
|
|
1584
|
+
* Get a string from a UTF-8 encoded C string
|
|
1585
|
+
* If `byteLength` is not provided, the string is assumed to be null-terminated.
|
|
1586
|
+
*
|
|
1587
|
+
* @example
|
|
1588
|
+
* ```js
|
|
1589
|
+
* var ptr = lib.symbols.getVersion();
|
|
1590
|
+
* console.log(new CString(ptr));
|
|
1591
|
+
* ```
|
|
1592
|
+
*
|
|
1593
|
+
* @example
|
|
1594
|
+
* ```js
|
|
1595
|
+
* var ptr = lib.symbols.getVersion();
|
|
1596
|
+
* // print the first 4 characters
|
|
1597
|
+
* console.log(new CString(ptr, 0, 4));
|
|
1598
|
+
* ```
|
|
1599
|
+
*
|
|
1600
|
+
* While there are some checks to catch invalid pointers, this is a difficult
|
|
1601
|
+
* thing to do safely. Passing an invalid pointer can crash the program and
|
|
1602
|
+
* reading beyond the bounds of the pointer will crash the program or cause
|
|
1603
|
+
* undefined behavior. Use with care!
|
|
1604
|
+
*/
|
|
1605
|
+
|
|
1606
|
+
export class CString extends String {
|
|
1607
|
+
/**
|
|
1608
|
+
* Get a string from a UTF-8 encoded C string
|
|
1609
|
+
* If `byteLength` is not provided, the string is assumed to be null-terminated.
|
|
1610
|
+
*
|
|
1611
|
+
* @param ptr The pointer to the C string
|
|
1612
|
+
* @param byteOffset bytes to skip before reading
|
|
1613
|
+
* @param byteLength bytes to read
|
|
1614
|
+
*
|
|
1615
|
+
*
|
|
1616
|
+
* @example
|
|
1617
|
+
* ```js
|
|
1618
|
+
* var ptr = lib.symbols.getVersion();
|
|
1619
|
+
* console.log(new CString(ptr));
|
|
1620
|
+
* ```
|
|
1621
|
+
*
|
|
1622
|
+
* @example
|
|
1623
|
+
* ```js
|
|
1624
|
+
* var ptr = lib.symbols.getVersion();
|
|
1625
|
+
* // print the first 4 characters
|
|
1626
|
+
* console.log(new CString(ptr, 0, 4));
|
|
1627
|
+
* ```
|
|
1628
|
+
*
|
|
1629
|
+
* While there are some checks to catch invalid pointers, this is a difficult
|
|
1630
|
+
* thing to do safely. Passing an invalid pointer can crash the program and
|
|
1631
|
+
* reading beyond the bounds of the pointer will crash the program or cause
|
|
1632
|
+
* undefined behavior. Use with care!
|
|
1633
|
+
*/
|
|
1634
|
+
constructor(ptr: number, byteOffset?: number, byteLength?: number);
|
|
1635
|
+
|
|
1636
|
+
/**
|
|
1637
|
+
* The ptr to the C string
|
|
1638
|
+
*
|
|
1639
|
+
* This `CString` instance is a clone of the string, so it
|
|
1640
|
+
* is safe to continue using this instance after the `ptr` has been
|
|
1641
|
+
* freed.
|
|
1642
|
+
*/
|
|
1643
|
+
ptr: number;
|
|
1644
|
+
byteOffset?: number;
|
|
1645
|
+
byteLength?: number;
|
|
1646
|
+
|
|
1647
|
+
/**
|
|
1648
|
+
* Get the {@link ptr} as an `ArrayBuffer`
|
|
1649
|
+
*
|
|
1650
|
+
* `null` or empty ptrs returns an `ArrayBuffer` with `byteLength` 0
|
|
1651
|
+
*/
|
|
1652
|
+
get arrayBuffer(): ArrayBuffer;
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
/**
|
|
1656
|
+
* View the generated C code for FFI bindings
|
|
1657
|
+
*
|
|
1658
|
+
* You probably won't need this unless there's a bug in the FFI bindings
|
|
1659
|
+
* generator or you're just curious.
|
|
1660
|
+
*/
|
|
1661
|
+
export function viewSource(symbols: Symbols, is_callback?: false): string[];
|
|
1662
|
+
export function viewSource(callback: FFIFunction, is_callback: true): string;
|
|
1663
|
+
|
|
1664
|
+
/**
|
|
1665
|
+
* Platform-specific file extension name for dynamic libraries
|
|
1666
|
+
*
|
|
1667
|
+
* "." is not included
|
|
1668
|
+
*
|
|
1669
|
+
* @example
|
|
1670
|
+
* ```js
|
|
1671
|
+
* "dylib" // macOS
|
|
1672
|
+
* ```
|
|
1673
|
+
*
|
|
1674
|
+
* @example
|
|
1675
|
+
* ```js
|
|
1676
|
+
* "so" // linux
|
|
1677
|
+
* ```
|
|
1678
|
+
*/
|
|
1679
|
+
export const suffix: string;
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
|
|
839
1683
|
// ./fs.d.ts
|
|
840
1684
|
|
|
841
1685
|
/**
|
|
@@ -4724,7 +5568,7 @@ interface Process {
|
|
|
4724
5568
|
setuid(id: number | string): void;
|
|
4725
5569
|
}
|
|
4726
5570
|
|
|
4727
|
-
declare
|
|
5571
|
+
declare var process: Process;
|
|
4728
5572
|
|
|
4729
5573
|
interface BlobInterface {
|
|
4730
5574
|
text(): Promise<string>;
|
|
@@ -4765,7 +5609,7 @@ interface Headers {
|
|
|
4765
5609
|
): void;
|
|
4766
5610
|
}
|
|
4767
5611
|
|
|
4768
|
-
declare
|
|
5612
|
+
declare var Headers: {
|
|
4769
5613
|
prototype: Headers;
|
|
4770
5614
|
new (init?: HeadersInit): Headers;
|
|
4771
5615
|
};
|
|
@@ -5223,7 +6067,7 @@ interface Crypto {
|
|
|
5223
6067
|
randomUUID(): string;
|
|
5224
6068
|
}
|
|
5225
6069
|
|
|
5226
|
-
declare
|
|
6070
|
+
declare var crypto: Crypto;
|
|
5227
6071
|
|
|
5228
6072
|
/**
|
|
5229
6073
|
* [`atob`](https://developer.mozilla.org/en-US/docs/Web/API/atob) converts ascii text into base64.
|
|
@@ -5603,7 +6447,7 @@ interface EventTarget {
|
|
|
5603
6447
|
): void;
|
|
5604
6448
|
}
|
|
5605
6449
|
|
|
5606
|
-
declare
|
|
6450
|
+
declare var EventTarget: {
|
|
5607
6451
|
prototype: EventTarget;
|
|
5608
6452
|
new (): EventTarget;
|
|
5609
6453
|
};
|
|
@@ -5707,7 +6551,7 @@ interface Event {
|
|
|
5707
6551
|
readonly NONE: number;
|
|
5708
6552
|
}
|
|
5709
6553
|
|
|
5710
|
-
declare
|
|
6554
|
+
declare var Event: {
|
|
5711
6555
|
prototype: Event;
|
|
5712
6556
|
new (type: string, eventInitDict?: EventInit): Event;
|
|
5713
6557
|
readonly AT_TARGET: number;
|
|
@@ -5727,7 +6571,7 @@ interface ErrorEvent extends Event {
|
|
|
5727
6571
|
readonly message: string;
|
|
5728
6572
|
}
|
|
5729
6573
|
|
|
5730
|
-
declare
|
|
6574
|
+
declare var ErrorEvent: {
|
|
5731
6575
|
prototype: ErrorEvent;
|
|
5732
6576
|
new (type: string, eventInitDict?: ErrorEventInit): ErrorEvent;
|
|
5733
6577
|
};
|
|
@@ -5775,7 +6619,7 @@ interface URLSearchParams {
|
|
|
5775
6619
|
): void;
|
|
5776
6620
|
}
|
|
5777
6621
|
|
|
5778
|
-
declare
|
|
6622
|
+
declare var URLSearchParams: {
|
|
5779
6623
|
prototype: URLSearchParams;
|
|
5780
6624
|
new (
|
|
5781
6625
|
init?: string[][] | Record<string, string> | string | URLSearchParams
|
|
@@ -5783,7 +6627,7 @@ declare let URLSearchParams: {
|
|
|
5783
6627
|
toString(): string;
|
|
5784
6628
|
};
|
|
5785
6629
|
|
|
5786
|
-
declare
|
|
6630
|
+
declare var URL: {
|
|
5787
6631
|
prototype: URL;
|
|
5788
6632
|
new (url: string | URL, base?: string | URL): URL;
|
|
5789
6633
|
/** Not implemented yet */
|
|
@@ -5802,7 +6646,7 @@ interface EventListenerObject {
|
|
|
5802
6646
|
handleEvent(object: Event): void;
|
|
5803
6647
|
}
|
|
5804
6648
|
|
|
5805
|
-
declare
|
|
6649
|
+
declare var AbortController: {
|
|
5806
6650
|
prototype: AbortController;
|
|
5807
6651
|
new (): AbortController;
|
|
5808
6652
|
};
|
|
@@ -5859,7 +6703,7 @@ interface AbortSignal extends EventTarget {
|
|
|
5859
6703
|
): void;
|
|
5860
6704
|
}
|
|
5861
6705
|
|
|
5862
|
-
declare
|
|
6706
|
+
declare var AbortSignal: {
|
|
5863
6707
|
prototype: AbortSignal;
|
|
5864
6708
|
new (): AbortSignal;
|
|
5865
6709
|
};
|
|
@@ -5878,6 +6722,111 @@ type DOMHighResTimeStamp = number;
|
|
|
5878
6722
|
// type EpochTimeStamp = number;
|
|
5879
6723
|
type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
|
|
5880
6724
|
|
|
6725
|
+
/**
|
|
6726
|
+
* Low-level JavaScriptCore API for accessing the native ES Module loader (not a Bun API)
|
|
6727
|
+
*
|
|
6728
|
+
* Before using this, be aware of a few things:
|
|
6729
|
+
*
|
|
6730
|
+
* **Using this incorrectly will crash your application**.
|
|
6731
|
+
*
|
|
6732
|
+
* This API may change any time JavaScriptCore is updated.
|
|
6733
|
+
*
|
|
6734
|
+
* Bun may rewrite ESM import specifiers to point to bundled code. This will
|
|
6735
|
+
* be confusing when using this API, as it will return a string like
|
|
6736
|
+
* "/node_modules.server.bun".
|
|
6737
|
+
*
|
|
6738
|
+
* Bun may inject additional imports into your code. This usually has a `bun:` prefix.
|
|
6739
|
+
*
|
|
6740
|
+
*/
|
|
6741
|
+
declare var Loader: {
|
|
6742
|
+
/**
|
|
6743
|
+
* ESM module registry
|
|
6744
|
+
*
|
|
6745
|
+
* This lets you implement live reload in Bun. If you
|
|
6746
|
+
* delete a module specifier from this map, the next time it's imported, it
|
|
6747
|
+
* will be re-transpiled and loaded again.
|
|
6748
|
+
*
|
|
6749
|
+
* The keys are the module specifiers and the
|
|
6750
|
+
* values are metadata about the module.
|
|
6751
|
+
*
|
|
6752
|
+
* The keys are an implementation detail for Bun that will change between
|
|
6753
|
+
* versions.
|
|
6754
|
+
*
|
|
6755
|
+
* - Userland modules are an absolute file path
|
|
6756
|
+
* - Virtual modules have a `bun:` prefix or `node:` prefix
|
|
6757
|
+
* - JS polyfills start with `"/bun-vfs/"`. `"buffer"` is an example of a JS polyfill
|
|
6758
|
+
* - If you have a `node_modules.bun` file, many modules will point to that file
|
|
6759
|
+
*
|
|
6760
|
+
* Virtual modules and JS polyfills are embedded in bun's binary. They don't
|
|
6761
|
+
* point to anywhere in your local filesystem.
|
|
6762
|
+
*
|
|
6763
|
+
*
|
|
6764
|
+
*/
|
|
6765
|
+
registry: Map<
|
|
6766
|
+
string,
|
|
6767
|
+
{
|
|
6768
|
+
/**
|
|
6769
|
+
* This refers to the state the ESM module is in
|
|
6770
|
+
*
|
|
6771
|
+
* TODO: make an enum for this number
|
|
6772
|
+
*
|
|
6773
|
+
*
|
|
6774
|
+
*/
|
|
6775
|
+
state: number;
|
|
6776
|
+
dependencies: string[];
|
|
6777
|
+
/**
|
|
6778
|
+
* Your application will probably crash if you mess with this.
|
|
6779
|
+
*/
|
|
6780
|
+
module: any;
|
|
6781
|
+
}
|
|
6782
|
+
>;
|
|
6783
|
+
/**
|
|
6784
|
+
* For an already-evaluated module, return the dependencies as module specifiers
|
|
6785
|
+
*
|
|
6786
|
+
* This list is already sorted and uniqued.
|
|
6787
|
+
*
|
|
6788
|
+
* @example
|
|
6789
|
+
*
|
|
6790
|
+
* For this code:
|
|
6791
|
+
* ```js
|
|
6792
|
+
* // /foo.js
|
|
6793
|
+
* import classNames from 'classnames';
|
|
6794
|
+
* import React from 'react';
|
|
6795
|
+
* import {createElement} from 'react';
|
|
6796
|
+
* ```
|
|
6797
|
+
*
|
|
6798
|
+
* This would return:
|
|
6799
|
+
* ```js
|
|
6800
|
+
* Loader.dependencyKeysIfEvaluated("/foo.js")
|
|
6801
|
+
* ["bun:wrap", "/path/to/node_modules/classnames/index.js", "/path/to/node_modules/react/index.js"]
|
|
6802
|
+
* ```
|
|
6803
|
+
*
|
|
6804
|
+
* @param specifier - module specifier as it appears in transpiled source code
|
|
6805
|
+
*
|
|
6806
|
+
*/
|
|
6807
|
+
dependencyKeysIfEvaluated: (specifier: string) => string[];
|
|
6808
|
+
/**
|
|
6809
|
+
* The function JavaScriptCore internally calls when you use an import statement.
|
|
6810
|
+
*
|
|
6811
|
+
* This may return a path to `node_modules.server.bun`, which will be confusing.
|
|
6812
|
+
*
|
|
6813
|
+
* Consider {@link Bun.resolve} or {@link ImportMeta.resolve}
|
|
6814
|
+
* instead.
|
|
6815
|
+
*
|
|
6816
|
+
* @param specifier - module specifier as it appears in transpiled source code
|
|
6817
|
+
*/
|
|
6818
|
+
resolve: (specifier: string) => Promise<string>;
|
|
6819
|
+
/**
|
|
6820
|
+
* Synchronously resolve a module specifier
|
|
6821
|
+
*
|
|
6822
|
+
* This may return a path to `node_modules.server.bun`, which will be confusing.
|
|
6823
|
+
*
|
|
6824
|
+
* Consider {@link Bun.resolveSync}
|
|
6825
|
+
* instead.
|
|
6826
|
+
*/
|
|
6827
|
+
resolveSync: (specifier: string, from: string) => string;
|
|
6828
|
+
};
|
|
6829
|
+
|
|
5881
6830
|
|
|
5882
6831
|
// ./path.d.ts
|
|
5883
6832
|
|