bun-types 1.3.6-canary.20260107T140751 → 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,97 @@ 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
+
2069
+ /**
2070
+ * Generate a JSON file containing metadata about the build.
2071
+ *
2072
+ * The metafile contains information about inputs, outputs, imports, and exports
2073
+ * which can be used for bundle analysis, visualization, or integration with
2074
+ * other tools.
2075
+ *
2076
+ * When `true`, the metafile JSON string is included in the {@link BuildOutput.metafile} property.
2077
+ *
2078
+ * @default false
2079
+ *
2080
+ * @example
2081
+ * ```ts
2082
+ * const result = await Bun.build({
2083
+ * entrypoints: ['./src/index.ts'],
2084
+ * outdir: './dist',
2085
+ * metafile: true,
2086
+ * });
2087
+ *
2088
+ * // Write metafile to disk for analysis
2089
+ * if (result.metafile) {
2090
+ * await Bun.write('./dist/meta.json', result.metafile);
2091
+ * }
2092
+ *
2093
+ * // Parse and analyze the metafile
2094
+ * const meta = JSON.parse(result.metafile!);
2095
+ * console.log('Input files:', Object.keys(meta.inputs));
2096
+ * console.log('Output files:', Object.keys(meta.outputs));
2097
+ * ```
2098
+ */
2099
+ metafile?: boolean;
2100
+
1955
2101
  outdir?: string;
1956
2102
  }
1957
2103
 
@@ -2603,6 +2749,106 @@ declare module "bun" {
2603
2749
  outputs: BuildArtifact[];
2604
2750
  success: boolean;
2605
2751
  logs: Array<BuildMessage | ResolveMessage>;
2752
+ /**
2753
+ * Metadata about the build including inputs, outputs, and their relationships.
2754
+ *
2755
+ * Only present when {@link BuildConfig.metafile} is `true`.
2756
+ *
2757
+ * The metafile contains detailed information about:
2758
+ * - **inputs**: All source files that were bundled, their byte sizes, imports, and format
2759
+ * - **outputs**: All generated output files, their byte sizes, which inputs contributed to each output, imports between chunks, and exports
2760
+ *
2761
+ * This can be used for:
2762
+ * - Bundle size analysis and visualization
2763
+ * - Detecting unused code or dependencies
2764
+ * - Understanding the dependency graph
2765
+ * - Integration with bundle analyzer tools
2766
+ *
2767
+ * @example
2768
+ * ```ts
2769
+ * const result = await Bun.build({
2770
+ * entrypoints: ['./src/index.ts'],
2771
+ * outdir: './dist',
2772
+ * metafile: true,
2773
+ * });
2774
+ *
2775
+ * if (result.metafile) {
2776
+ * // Analyze input files
2777
+ * for (const [path, input] of Object.entries(result.metafile.inputs)) {
2778
+ * console.log(`${path}: ${input.bytes} bytes, ${input.imports.length} imports`);
2779
+ * }
2780
+ *
2781
+ * // Analyze output files
2782
+ * for (const [path, output] of Object.entries(result.metafile.outputs)) {
2783
+ * console.log(`${path}: ${output.bytes} bytes`);
2784
+ * for (const [inputPath, info] of Object.entries(output.inputs)) {
2785
+ * console.log(` - ${inputPath}: ${info.bytesInOutput} bytes`);
2786
+ * }
2787
+ * }
2788
+ *
2789
+ * // Write to disk for external analysis tools
2790
+ * await Bun.write('./dist/meta.json', JSON.stringify(result.metafile));
2791
+ * }
2792
+ * ```
2793
+ */
2794
+ metafile?: BuildMetafile;
2795
+ }
2796
+
2797
+ /**
2798
+ * Metafile structure containing build metadata for analysis.
2799
+ *
2800
+ * @category Bundler
2801
+ */
2802
+ interface BuildMetafile {
2803
+ /** Information about all input source files */
2804
+ inputs: {
2805
+ [path: string]: {
2806
+ /** Size of the input file in bytes */
2807
+ bytes: number;
2808
+ /** List of imports from this file */
2809
+ imports: Array<{
2810
+ /** Resolved path of the imported file */
2811
+ path: string;
2812
+ /** Type of import statement */
2813
+ kind: ImportKind;
2814
+ /** Original import specifier before resolution (if different from path) */
2815
+ original?: string;
2816
+ /** Whether this import is external to the bundle */
2817
+ external?: boolean;
2818
+ /** Import attributes (e.g., `{ type: "json" }`) */
2819
+ with?: Record<string, string>;
2820
+ }>;
2821
+ /** Module format of the input file */
2822
+ format?: "esm" | "cjs" | "json" | "css";
2823
+ };
2824
+ };
2825
+ /** Information about all output files */
2826
+ outputs: {
2827
+ [path: string]: {
2828
+ /** Size of the output file in bytes */
2829
+ bytes: number;
2830
+ /** Map of input files to their contribution in this output */
2831
+ inputs: {
2832
+ [path: string]: {
2833
+ /** Number of bytes this input contributed to the output */
2834
+ bytesInOutput: number;
2835
+ };
2836
+ };
2837
+ /** List of imports to other chunks */
2838
+ imports: Array<{
2839
+ /** Path to the imported chunk */
2840
+ path: string;
2841
+ /** Type of import */
2842
+ kind: ImportKind;
2843
+ }>;
2844
+ /** List of exported names from this output */
2845
+ exports: string[];
2846
+ /** Entry point path if this output is an entry point */
2847
+ entryPoint?: string;
2848
+ /** Path to the associated CSS bundle (for JS entry points with CSS) */
2849
+ cssBundle?: string;
2850
+ };
2851
+ };
2606
2852
  }
2607
2853
 
2608
2854
  /**
@@ -3072,16 +3318,29 @@ declare module "bun" {
3072
3318
 
3073
3319
  type WebSocketOptionsTLS = {
3074
3320
  /**
3075
- * 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
+ * ```
3076
3342
  */
3077
- tls?: {
3078
- /**
3079
- * Whether to reject the connection if the certificate is not valid
3080
- *
3081
- * @default true
3082
- */
3083
- rejectUnauthorized?: boolean;
3084
- };
3343
+ tls?: TLSOptions;
3085
3344
  };
3086
3345
 
3087
3346
  type WebSocketOptionsHeaders = {
@@ -3091,10 +3350,57 @@ declare module "bun" {
3091
3350
  headers?: import("node:http").OutgoingHttpHeaders;
3092
3351
  };
3093
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
+
3094
3397
  /**
3095
3398
  * Constructor options for the `Bun.WebSocket` client
3096
3399
  */
3097
- type WebSocketOptions = WebSocketOptionsProtocolsOrProtocol & WebSocketOptionsTLS & WebSocketOptionsHeaders;
3400
+ type WebSocketOptions = WebSocketOptionsProtocolsOrProtocol &
3401
+ WebSocketOptionsTLS &
3402
+ WebSocketOptionsHeaders &
3403
+ WebSocketOptionsProxy;
3098
3404
 
3099
3405
  interface WebSocketEventMap {
3100
3406
  close: CloseEvent;
@@ -5338,6 +5644,67 @@ declare module "bun" {
5338
5644
  ref(): void;
5339
5645
  unref(): void;
5340
5646
  close(): void;
5647
+ /**
5648
+ * Enable or disable SO_BROADCAST socket option.
5649
+ * @param enabled Whether to enable broadcast
5650
+ * @returns The enabled value
5651
+ */
5652
+ setBroadcast(enabled: boolean): boolean;
5653
+ /**
5654
+ * Set the IP_TTL socket option.
5655
+ * @param ttl Time to live value
5656
+ * @returns The TTL value
5657
+ */
5658
+ setTTL(ttl: number): number;
5659
+ /**
5660
+ * Set the IP_MULTICAST_TTL socket option.
5661
+ * @param ttl Time to live value for multicast packets
5662
+ * @returns The TTL value
5663
+ */
5664
+ setMulticastTTL(ttl: number): number;
5665
+ /**
5666
+ * Enable or disable IP_MULTICAST_LOOP socket option.
5667
+ * @param enabled Whether to enable multicast loopback
5668
+ * @returns The enabled value
5669
+ */
5670
+ setMulticastLoopback(enabled: boolean): boolean;
5671
+ /**
5672
+ * Set the IP_MULTICAST_IF socket option to specify the outgoing interface
5673
+ * for multicast packets.
5674
+ * @param interfaceAddress The address of the interface to use
5675
+ * @returns true on success
5676
+ */
5677
+ setMulticastInterface(interfaceAddress: string): boolean;
5678
+ /**
5679
+ * Join a multicast group.
5680
+ * @param multicastAddress The multicast group address
5681
+ * @param interfaceAddress Optional interface address to use
5682
+ * @returns true on success
5683
+ */
5684
+ addMembership(multicastAddress: string, interfaceAddress?: string): boolean;
5685
+ /**
5686
+ * Leave a multicast group.
5687
+ * @param multicastAddress The multicast group address
5688
+ * @param interfaceAddress Optional interface address to use
5689
+ * @returns true on success
5690
+ */
5691
+ dropMembership(multicastAddress: string, interfaceAddress?: string): boolean;
5692
+ /**
5693
+ * Join a source-specific multicast group.
5694
+ * @param sourceAddress The source address
5695
+ * @param groupAddress The multicast group address
5696
+ * @param interfaceAddress Optional interface address to use
5697
+ * @returns true on success
5698
+ */
5699
+ addSourceSpecificMembership(sourceAddress: string, groupAddress: string, interfaceAddress?: string): boolean;
5700
+ /**
5701
+ * Leave a source-specific multicast group.
5702
+ * @param sourceAddress The source address
5703
+ * @param groupAddress The multicast group address
5704
+ * @param interfaceAddress Optional interface address to use
5705
+ * @returns true on success
5706
+ */
5707
+ dropSourceSpecificMembership(sourceAddress: string, groupAddress: string, interfaceAddress?: string): boolean;
5341
5708
  }
5342
5709
 
5343
5710
  export interface ConnectedSocket<DataBinaryType extends BinaryType> extends BaseUDPSocket {
@@ -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.
@@ -1219,6 +1291,79 @@ declare module "bun:bundle" {
1219
1291
 
1220
1292
  Ensure the file is included in your `tsconfig.json` (e.g., `"include": ["src", "env.d.ts"]`). Now `feature()` only accepts those flags, and invalid strings like `feature("TYPO")` become type errors.
1221
1293
 
1294
+ ### metafile
1295
+
1296
+ Generate metadata about the build in a structured format. The metafile contains information about all input files, output files, their sizes, imports, and exports. This is useful for:
1297
+
1298
+ - **Bundle analysis**: Understand what's contributing to bundle size
1299
+ - **Visualization**: Feed into tools like [esbuild's bundle analyzer](https://esbuild.github.io/analyze/) or other visualization tools
1300
+ - **Dependency tracking**: See the full import graph of your application
1301
+ - **CI integration**: Track bundle size changes over time
1302
+
1303
+ <Tabs>
1304
+ <Tab title="JavaScript">
1305
+ ```ts title="build.ts" icon="/icons/typescript.svg"
1306
+ const result = await Bun.build({
1307
+ entrypoints: ['./src/index.ts'],
1308
+ outdir: './dist',
1309
+ metafile: true,
1310
+ });
1311
+
1312
+ if (result.metafile) {
1313
+ // Analyze inputs
1314
+ for (const [path, meta] of Object.entries(result.metafile.inputs)) {
1315
+ console.log(`${path}: ${meta.bytes} bytes`);
1316
+ }
1317
+
1318
+ // Analyze outputs
1319
+ for (const [path, meta] of Object.entries(result.metafile.outputs)) {
1320
+ console.log(`${path}: ${meta.bytes} bytes`);
1321
+ }
1322
+
1323
+ // Save for external analysis tools
1324
+ await Bun.write('./dist/meta.json', JSON.stringify(result.metafile));
1325
+ }
1326
+ ```
1327
+
1328
+ </Tab>
1329
+ <Tab title="CLI">
1330
+ ```bash terminal icon="terminal"
1331
+ bun build ./src/index.ts --outdir ./dist --metafile ./dist/meta.json
1332
+ ```
1333
+ </Tab>
1334
+ </Tabs>
1335
+
1336
+ The metafile structure contains:
1337
+
1338
+ ```ts
1339
+ interface BuildMetafile {
1340
+ inputs: {
1341
+ [path: string]: {
1342
+ bytes: number;
1343
+ imports: Array<{
1344
+ path: string;
1345
+ kind: ImportKind;
1346
+ original?: string; // Original specifier before resolution
1347
+ external?: boolean;
1348
+ }>;
1349
+ format?: "esm" | "cjs" | "json" | "css";
1350
+ };
1351
+ };
1352
+ outputs: {
1353
+ [path: string]: {
1354
+ bytes: number;
1355
+ inputs: {
1356
+ [path: string]: { bytesInOutput: number };
1357
+ };
1358
+ imports: Array<{ path: string; kind: ImportKind }>;
1359
+ exports: string[];
1360
+ entryPoint?: string;
1361
+ cssBundle?: string; // Associated CSS file for JS entry points
1362
+ };
1363
+ };
1364
+ }
1365
+ ```
1366
+
1222
1367
  ## Outputs
1223
1368
 
1224
1369
  The `Bun.build` function returns a `Promise<BuildOutput>`, defined as:
@@ -1228,6 +1373,7 @@ interface BuildOutput {
1228
1373
  outputs: BuildArtifact[];
1229
1374
  success: boolean;
1230
1375
  logs: Array<object>; // see docs for details
1376
+ metafile?: BuildMetafile; // only when metafile: true
1231
1377
  }
1232
1378
 
1233
1379
  interface BuildArtifact extends Blob {
@@ -127,3 +127,54 @@ const socket = await Bun.udpSocket({
127
127
  },
128
128
  });
129
129
  ```
130
+
131
+ ### Socket options
132
+
133
+ UDP sockets support setting various socket options:
134
+
135
+ ```ts
136
+ const socket = await Bun.udpSocket({});
137
+
138
+ // Enable broadcasting to send packets to a broadcast address
139
+ socket.setBroadcast(true);
140
+
141
+ // Set the IP TTL (time to live) for outgoing packets
142
+ socket.setTTL(64);
143
+ ```
144
+
145
+ ### Multicast
146
+
147
+ Bun supports multicast operations for UDP sockets. Use `addMembership` and `dropMembership` to join and leave multicast groups:
148
+
149
+ ```ts
150
+ const socket = await Bun.udpSocket({});
151
+
152
+ // Join a multicast group
153
+ socket.addMembership("224.0.0.1");
154
+
155
+ // Join with a specific interface
156
+ socket.addMembership("224.0.0.1", "192.168.1.100");
157
+
158
+ // Leave a multicast group
159
+ socket.dropMembership("224.0.0.1");
160
+ ```
161
+
162
+ Additional multicast options:
163
+
164
+ ```ts
165
+ // Set TTL for multicast packets (number of network hops)
166
+ socket.setMulticastTTL(2);
167
+
168
+ // Control whether multicast packets loop back to the local socket
169
+ socket.setMulticastLoopback(true);
170
+
171
+ // Specify which interface to use for outgoing multicast packets
172
+ socket.setMulticastInterface("192.168.1.100");
173
+ ```
174
+
175
+ For source-specific multicast (SSM), use `addSourceSpecificMembership` and `dropSourceSpecificMembership`:
176
+
177
+ ```ts
178
+ socket.addSourceSpecificMembership("10.0.0.1", "232.0.0.1");
179
+ socket.dropSourceSpecificMembership("10.0.0.1", "232.0.0.1");
180
+ ```
package/package.json CHANGED
@@ -33,5 +33,5 @@
33
33
  "bun.js",
34
34
  "types"
35
35
  ],
36
- "version": "1.3.6-canary.20260107T140751"
36
+ "version": "1.3.6-canary.20260109T140758"
37
37
  }