bun-types 1.3.6-canary.20260108T140918 → 1.3.6-canary.20260109T140758

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/bun.d.ts CHANGED
@@ -625,6 +625,33 @@ declare module "bun" {
625
625
  export function parse(input: string): object;
626
626
  }
627
627
 
628
+ /**
629
+ * JSONC related APIs
630
+ */
631
+ namespace JSONC {
632
+ /**
633
+ * Parse a JSONC (JSON with Comments) string into a JavaScript value.
634
+ *
635
+ * Supports both single-line (`//`) and block comments (`/* ... *\/`), as well as
636
+ * trailing commas in objects and arrays.
637
+ *
638
+ * @category Utilities
639
+ *
640
+ * @param input The JSONC string to parse
641
+ * @returns A JavaScript value
642
+ *
643
+ * @example
644
+ * ```js
645
+ * const result = Bun.JSONC.parse(`{
646
+ * // This is a comment
647
+ * "name": "my-app",
648
+ * "version": "1.0.0", // trailing comma is allowed
649
+ * }`);
650
+ * ```
651
+ */
652
+ export function parse(input: string): unknown;
653
+ }
654
+
628
655
  /**
629
656
  * YAML related APIs
630
657
  */
@@ -815,6 +842,20 @@ declare module "bun" {
815
842
  destination: BunFile,
816
843
  input: BunFile,
817
844
  options?: {
845
+ /**
846
+ * Set the file permissions of the destination when it is created or overwritten.
847
+ *
848
+ * Must be a valid Unix permission mode (0 to 0o777 / 511 in decimal).
849
+ * If omitted, defaults to the system default based on umask (typically 0o644).
850
+ *
851
+ * @throws {RangeError} If the mode is outside the valid range (0 to 0o777).
852
+ *
853
+ * @example
854
+ * ```ts
855
+ * await Bun.write(Bun.file("./secret.txt"), Bun.file("./source.txt"), { mode: 0o600 });
856
+ * ```
857
+ */
858
+ mode?: number;
818
859
  /**
819
860
  * If `true`, create the parent directory if it doesn't exist. By default, this is `true`.
820
861
  *
@@ -848,6 +889,20 @@ declare module "bun" {
848
889
  destinationPath: PathLike,
849
890
  input: BunFile,
850
891
  options?: {
892
+ /**
893
+ * Set the file permissions of the destination when it is created or overwritten.
894
+ *
895
+ * Must be a valid Unix permission mode (0 to 0o777 / 511 in decimal).
896
+ * If omitted, defaults to the system default based on umask (typically 0o644).
897
+ *
898
+ * @throws {RangeError} If the mode is outside the valid range (0 to 0o777).
899
+ *
900
+ * @example
901
+ * ```ts
902
+ * await Bun.write("./secret.txt", Bun.file("./source.txt"), { mode: 0o600 });
903
+ * ```
904
+ */
905
+ mode?: number;
851
906
  /**
852
907
  * If `true`, create the parent directory if it doesn't exist. By default, this is `true`.
853
908
  *
@@ -1952,6 +2007,65 @@ declare module "bun" {
1952
2007
  */
1953
2008
  reactFastRefresh?: boolean;
1954
2009
 
2010
+ /**
2011
+ * A map of file paths to their contents for in-memory bundling.
2012
+ *
2013
+ * This allows you to bundle virtual files that don't exist on disk, or override
2014
+ * the contents of files that do exist on disk. The keys are file paths (which should
2015
+ * match how they're imported) and the values are the file contents.
2016
+ *
2017
+ * File contents can be provided as:
2018
+ * - `string` - The source code as a string
2019
+ * - `Blob` - A Blob containing the source code
2020
+ * - `NodeJS.TypedArray` - A typed array (e.g., `Uint8Array`) containing the source code
2021
+ * - `ArrayBufferLike` - An ArrayBuffer containing the source code
2022
+ *
2023
+ * @example
2024
+ * ```ts
2025
+ * // Bundle entirely from memory (no files on disk needed)
2026
+ * await Bun.build({
2027
+ * entrypoints: ["/app/index.ts"],
2028
+ * files: {
2029
+ * "/app/index.ts": `
2030
+ * import { helper } from "./helper.ts";
2031
+ * console.log(helper());
2032
+ * `,
2033
+ * "/app/helper.ts": `
2034
+ * export function helper() {
2035
+ * return "Hello from memory!";
2036
+ * }
2037
+ * `,
2038
+ * },
2039
+ * });
2040
+ * ```
2041
+ *
2042
+ * @example
2043
+ * ```ts
2044
+ * // Override a file on disk with in-memory contents
2045
+ * await Bun.build({
2046
+ * entrypoints: ["./src/index.ts"],
2047
+ * files: {
2048
+ * // This will be used instead of the actual ./src/config.ts file
2049
+ * "./src/config.ts": `export const API_URL = "https://production.api.com";`,
2050
+ * },
2051
+ * });
2052
+ * ```
2053
+ *
2054
+ * @example
2055
+ * ```ts
2056
+ * // Mix disk files with in-memory files
2057
+ * // Entry point is on disk, but imports a virtual file
2058
+ * await Bun.build({
2059
+ * entrypoints: ["./src/index.ts"], // Real file on disk
2060
+ * files: {
2061
+ * // Virtual file that ./src/index.ts can import via "./generated.ts"
2062
+ * "./src/generated.ts": `export const BUILD_TIME = ${Date.now()};`,
2063
+ * },
2064
+ * });
2065
+ * ```
2066
+ */
2067
+ files?: Record<string, string | Blob | NodeJS.TypedArray | ArrayBufferLike>;
2068
+
1955
2069
  /**
1956
2070
  * Generate a JSON file containing metadata about the build.
1957
2071
  *
@@ -3204,16 +3318,29 @@ declare module "bun" {
3204
3318
 
3205
3319
  type WebSocketOptionsTLS = {
3206
3320
  /**
3207
- * Options for the TLS connection
3321
+ * Options for the TLS connection.
3322
+ *
3323
+ * Supports full TLS configuration including custom CA certificates,
3324
+ * client certificates, and other TLS settings (same as fetch).
3325
+ *
3326
+ * @example
3327
+ * ```ts
3328
+ * // Using BunFile for certificates
3329
+ * const ws = new WebSocket("wss://example.com", {
3330
+ * tls: {
3331
+ * ca: Bun.file("./ca.pem")
3332
+ * }
3333
+ * });
3334
+ *
3335
+ * // Using Buffer
3336
+ * const ws = new WebSocket("wss://example.com", {
3337
+ * tls: {
3338
+ * ca: fs.readFileSync("./ca.pem")
3339
+ * }
3340
+ * });
3341
+ * ```
3208
3342
  */
3209
- tls?: {
3210
- /**
3211
- * Whether to reject the connection if the certificate is not valid
3212
- *
3213
- * @default true
3214
- */
3215
- rejectUnauthorized?: boolean;
3216
- };
3343
+ tls?: TLSOptions;
3217
3344
  };
3218
3345
 
3219
3346
  type WebSocketOptionsHeaders = {
@@ -3223,10 +3350,57 @@ declare module "bun" {
3223
3350
  headers?: import("node:http").OutgoingHttpHeaders;
3224
3351
  };
3225
3352
 
3353
+ type WebSocketOptionsProxy = {
3354
+ /**
3355
+ * HTTP proxy to use for the WebSocket connection.
3356
+ *
3357
+ * Can be a string URL or an object with `url` and optional `headers`.
3358
+ *
3359
+ * @example
3360
+ * ```ts
3361
+ * // String format
3362
+ * const ws = new WebSocket("wss://example.com", {
3363
+ * proxy: "http://proxy.example.com:8080"
3364
+ * });
3365
+ *
3366
+ * // With credentials
3367
+ * const ws = new WebSocket("wss://example.com", {
3368
+ * proxy: "http://user:pass@proxy.example.com:8080"
3369
+ * });
3370
+ *
3371
+ * // Object format with custom headers
3372
+ * const ws = new WebSocket("wss://example.com", {
3373
+ * proxy: {
3374
+ * url: "http://proxy.example.com:8080",
3375
+ * headers: {
3376
+ * "Proxy-Authorization": "Bearer token"
3377
+ * }
3378
+ * }
3379
+ * });
3380
+ * ```
3381
+ */
3382
+ proxy?:
3383
+ | string
3384
+ | {
3385
+ /**
3386
+ * The proxy URL (http:// or https://)
3387
+ */
3388
+ url: string;
3389
+ /**
3390
+ * Custom headers to send to the proxy server.
3391
+ * Supports plain objects or Headers class instances.
3392
+ */
3393
+ headers?: import("node:http").OutgoingHttpHeaders | Headers;
3394
+ };
3395
+ };
3396
+
3226
3397
  /**
3227
3398
  * Constructor options for the `Bun.WebSocket` client
3228
3399
  */
3229
- type WebSocketOptions = WebSocketOptionsProtocolsOrProtocol & WebSocketOptionsTLS & WebSocketOptionsHeaders;
3400
+ type WebSocketOptions = WebSocketOptionsProtocolsOrProtocol &
3401
+ WebSocketOptionsTLS &
3402
+ WebSocketOptionsHeaders &
3403
+ WebSocketOptionsProxy;
3230
3404
 
3231
3405
  interface WebSocketEventMap {
3232
3406
  close: CloseEvent;
@@ -220,6 +220,78 @@ An array of paths corresponding to the entrypoints of our application. One bundl
220
220
  </Tab>
221
221
  </Tabs>
222
222
 
223
+ ### files
224
+
225
+ A map of file paths to their contents for in-memory bundling. This allows you to bundle virtual files that don't exist on disk, or override the contents of files that do exist. This option is only available in the JavaScript API.
226
+
227
+ File contents can be provided as a `string`, `Blob`, `TypedArray`, or `ArrayBuffer`.
228
+
229
+ #### Bundle entirely from memory
230
+
231
+ You can bundle code without any files on disk by providing all sources via `files`:
232
+
233
+ ```ts title="build.ts" icon="/icons/typescript.svg"
234
+ const result = await Bun.build({
235
+ entrypoints: ["/app/index.ts"],
236
+ files: {
237
+ "/app/index.ts": `
238
+ import { greet } from "./greet.ts";
239
+ console.log(greet("World"));
240
+ `,
241
+ "/app/greet.ts": `
242
+ export function greet(name: string) {
243
+ return "Hello, " + name + "!";
244
+ }
245
+ `,
246
+ },
247
+ });
248
+
249
+ const output = await result.outputs[0].text();
250
+ console.log(output);
251
+ ```
252
+
253
+ When all entrypoints are in the `files` map, the current working directory is used as the root.
254
+
255
+ #### Override files on disk
256
+
257
+ In-memory files take priority over files on disk. This lets you override specific files while keeping the rest of your codebase unchanged:
258
+
259
+ ```ts title="build.ts" icon="/icons/typescript.svg"
260
+ // Assume ./src/config.ts exists on disk with development settings
261
+ await Bun.build({
262
+ entrypoints: ["./src/index.ts"],
263
+ files: {
264
+ // Override config.ts with production values
265
+ "./src/config.ts": `
266
+ export const API_URL = "https://api.production.com";
267
+ export const DEBUG = false;
268
+ `,
269
+ },
270
+ outdir: "./dist",
271
+ });
272
+ ```
273
+
274
+ #### Mix disk and virtual files
275
+
276
+ Real files on disk can import virtual files, and virtual files can import real files:
277
+
278
+ ```ts title="build.ts" icon="/icons/typescript.svg"
279
+ // ./src/index.ts exists on disk and imports "./generated.ts"
280
+ await Bun.build({
281
+ entrypoints: ["./src/index.ts"],
282
+ files: {
283
+ // Provide a virtual file that index.ts imports
284
+ "./src/generated.ts": `
285
+ export const BUILD_ID = "${crypto.randomUUID()}";
286
+ export const BUILD_TIME = ${Date.now()};
287
+ `,
288
+ },
289
+ outdir: "./dist",
290
+ });
291
+ ```
292
+
293
+ This is useful for code generation, injecting build-time constants, or testing with mock modules.
294
+
223
295
  ### outdir
224
296
 
225
297
  The directory where output files will be written.
package/package.json CHANGED
@@ -33,5 +33,5 @@
33
33
  "bun.js",
34
34
  "types"
35
35
  ],
36
- "version": "1.3.6-canary.20260108T140918"
36
+ "version": "1.3.6-canary.20260109T140758"
37
37
  }