bun-types 1.3.6-canary.20260106T140718 → 1.3.6-canary.20260108T140918

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
@@ -1952,6 +1952,38 @@ declare module "bun" {
1952
1952
  */
1953
1953
  reactFastRefresh?: boolean;
1954
1954
 
1955
+ /**
1956
+ * Generate a JSON file containing metadata about the build.
1957
+ *
1958
+ * The metafile contains information about inputs, outputs, imports, and exports
1959
+ * which can be used for bundle analysis, visualization, or integration with
1960
+ * other tools.
1961
+ *
1962
+ * When `true`, the metafile JSON string is included in the {@link BuildOutput.metafile} property.
1963
+ *
1964
+ * @default false
1965
+ *
1966
+ * @example
1967
+ * ```ts
1968
+ * const result = await Bun.build({
1969
+ * entrypoints: ['./src/index.ts'],
1970
+ * outdir: './dist',
1971
+ * metafile: true,
1972
+ * });
1973
+ *
1974
+ * // Write metafile to disk for analysis
1975
+ * if (result.metafile) {
1976
+ * await Bun.write('./dist/meta.json', result.metafile);
1977
+ * }
1978
+ *
1979
+ * // Parse and analyze the metafile
1980
+ * const meta = JSON.parse(result.metafile!);
1981
+ * console.log('Input files:', Object.keys(meta.inputs));
1982
+ * console.log('Output files:', Object.keys(meta.outputs));
1983
+ * ```
1984
+ */
1985
+ metafile?: boolean;
1986
+
1955
1987
  outdir?: string;
1956
1988
  }
1957
1989
 
@@ -2603,6 +2635,106 @@ declare module "bun" {
2603
2635
  outputs: BuildArtifact[];
2604
2636
  success: boolean;
2605
2637
  logs: Array<BuildMessage | ResolveMessage>;
2638
+ /**
2639
+ * Metadata about the build including inputs, outputs, and their relationships.
2640
+ *
2641
+ * Only present when {@link BuildConfig.metafile} is `true`.
2642
+ *
2643
+ * The metafile contains detailed information about:
2644
+ * - **inputs**: All source files that were bundled, their byte sizes, imports, and format
2645
+ * - **outputs**: All generated output files, their byte sizes, which inputs contributed to each output, imports between chunks, and exports
2646
+ *
2647
+ * This can be used for:
2648
+ * - Bundle size analysis and visualization
2649
+ * - Detecting unused code or dependencies
2650
+ * - Understanding the dependency graph
2651
+ * - Integration with bundle analyzer tools
2652
+ *
2653
+ * @example
2654
+ * ```ts
2655
+ * const result = await Bun.build({
2656
+ * entrypoints: ['./src/index.ts'],
2657
+ * outdir: './dist',
2658
+ * metafile: true,
2659
+ * });
2660
+ *
2661
+ * if (result.metafile) {
2662
+ * // Analyze input files
2663
+ * for (const [path, input] of Object.entries(result.metafile.inputs)) {
2664
+ * console.log(`${path}: ${input.bytes} bytes, ${input.imports.length} imports`);
2665
+ * }
2666
+ *
2667
+ * // Analyze output files
2668
+ * for (const [path, output] of Object.entries(result.metafile.outputs)) {
2669
+ * console.log(`${path}: ${output.bytes} bytes`);
2670
+ * for (const [inputPath, info] of Object.entries(output.inputs)) {
2671
+ * console.log(` - ${inputPath}: ${info.bytesInOutput} bytes`);
2672
+ * }
2673
+ * }
2674
+ *
2675
+ * // Write to disk for external analysis tools
2676
+ * await Bun.write('./dist/meta.json', JSON.stringify(result.metafile));
2677
+ * }
2678
+ * ```
2679
+ */
2680
+ metafile?: BuildMetafile;
2681
+ }
2682
+
2683
+ /**
2684
+ * Metafile structure containing build metadata for analysis.
2685
+ *
2686
+ * @category Bundler
2687
+ */
2688
+ interface BuildMetafile {
2689
+ /** Information about all input source files */
2690
+ inputs: {
2691
+ [path: string]: {
2692
+ /** Size of the input file in bytes */
2693
+ bytes: number;
2694
+ /** List of imports from this file */
2695
+ imports: Array<{
2696
+ /** Resolved path of the imported file */
2697
+ path: string;
2698
+ /** Type of import statement */
2699
+ kind: ImportKind;
2700
+ /** Original import specifier before resolution (if different from path) */
2701
+ original?: string;
2702
+ /** Whether this import is external to the bundle */
2703
+ external?: boolean;
2704
+ /** Import attributes (e.g., `{ type: "json" }`) */
2705
+ with?: Record<string, string>;
2706
+ }>;
2707
+ /** Module format of the input file */
2708
+ format?: "esm" | "cjs" | "json" | "css";
2709
+ };
2710
+ };
2711
+ /** Information about all output files */
2712
+ outputs: {
2713
+ [path: string]: {
2714
+ /** Size of the output file in bytes */
2715
+ bytes: number;
2716
+ /** Map of input files to their contribution in this output */
2717
+ inputs: {
2718
+ [path: string]: {
2719
+ /** Number of bytes this input contributed to the output */
2720
+ bytesInOutput: number;
2721
+ };
2722
+ };
2723
+ /** List of imports to other chunks */
2724
+ imports: Array<{
2725
+ /** Path to the imported chunk */
2726
+ path: string;
2727
+ /** Type of import */
2728
+ kind: ImportKind;
2729
+ }>;
2730
+ /** List of exported names from this output */
2731
+ exports: string[];
2732
+ /** Entry point path if this output is an entry point */
2733
+ entryPoint?: string;
2734
+ /** Path to the associated CSS bundle (for JS entry points with CSS) */
2735
+ cssBundle?: string;
2736
+ };
2737
+ };
2606
2738
  }
2607
2739
 
2608
2740
  /**
@@ -5338,6 +5470,67 @@ declare module "bun" {
5338
5470
  ref(): void;
5339
5471
  unref(): void;
5340
5472
  close(): void;
5473
+ /**
5474
+ * Enable or disable SO_BROADCAST socket option.
5475
+ * @param enabled Whether to enable broadcast
5476
+ * @returns The enabled value
5477
+ */
5478
+ setBroadcast(enabled: boolean): boolean;
5479
+ /**
5480
+ * Set the IP_TTL socket option.
5481
+ * @param ttl Time to live value
5482
+ * @returns The TTL value
5483
+ */
5484
+ setTTL(ttl: number): number;
5485
+ /**
5486
+ * Set the IP_MULTICAST_TTL socket option.
5487
+ * @param ttl Time to live value for multicast packets
5488
+ * @returns The TTL value
5489
+ */
5490
+ setMulticastTTL(ttl: number): number;
5491
+ /**
5492
+ * Enable or disable IP_MULTICAST_LOOP socket option.
5493
+ * @param enabled Whether to enable multicast loopback
5494
+ * @returns The enabled value
5495
+ */
5496
+ setMulticastLoopback(enabled: boolean): boolean;
5497
+ /**
5498
+ * Set the IP_MULTICAST_IF socket option to specify the outgoing interface
5499
+ * for multicast packets.
5500
+ * @param interfaceAddress The address of the interface to use
5501
+ * @returns true on success
5502
+ */
5503
+ setMulticastInterface(interfaceAddress: string): boolean;
5504
+ /**
5505
+ * Join a multicast group.
5506
+ * @param multicastAddress The multicast group address
5507
+ * @param interfaceAddress Optional interface address to use
5508
+ * @returns true on success
5509
+ */
5510
+ addMembership(multicastAddress: string, interfaceAddress?: string): boolean;
5511
+ /**
5512
+ * Leave a multicast group.
5513
+ * @param multicastAddress The multicast group address
5514
+ * @param interfaceAddress Optional interface address to use
5515
+ * @returns true on success
5516
+ */
5517
+ dropMembership(multicastAddress: string, interfaceAddress?: string): boolean;
5518
+ /**
5519
+ * Join a source-specific multicast group.
5520
+ * @param sourceAddress The source address
5521
+ * @param groupAddress The multicast group address
5522
+ * @param interfaceAddress Optional interface address to use
5523
+ * @returns true on success
5524
+ */
5525
+ addSourceSpecificMembership(sourceAddress: string, groupAddress: string, interfaceAddress?: string): boolean;
5526
+ /**
5527
+ * Leave a source-specific multicast group.
5528
+ * @param sourceAddress The source address
5529
+ * @param groupAddress The multicast group address
5530
+ * @param interfaceAddress Optional interface address to use
5531
+ * @returns true on success
5532
+ */
5533
+ dropSourceSpecificMembership(sourceAddress: string, groupAddress: string, interfaceAddress?: string): boolean;
5341
5534
  }
5342
5535
 
5343
5536
  export interface ConnectedSocket<DataBinaryType extends BinaryType> extends BaseUDPSocket {
@@ -1219,6 +1219,79 @@ declare module "bun:bundle" {
1219
1219
 
1220
1220
  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
1221
 
1222
+ ### metafile
1223
+
1224
+ 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:
1225
+
1226
+ - **Bundle analysis**: Understand what's contributing to bundle size
1227
+ - **Visualization**: Feed into tools like [esbuild's bundle analyzer](https://esbuild.github.io/analyze/) or other visualization tools
1228
+ - **Dependency tracking**: See the full import graph of your application
1229
+ - **CI integration**: Track bundle size changes over time
1230
+
1231
+ <Tabs>
1232
+ <Tab title="JavaScript">
1233
+ ```ts title="build.ts" icon="/icons/typescript.svg"
1234
+ const result = await Bun.build({
1235
+ entrypoints: ['./src/index.ts'],
1236
+ outdir: './dist',
1237
+ metafile: true,
1238
+ });
1239
+
1240
+ if (result.metafile) {
1241
+ // Analyze inputs
1242
+ for (const [path, meta] of Object.entries(result.metafile.inputs)) {
1243
+ console.log(`${path}: ${meta.bytes} bytes`);
1244
+ }
1245
+
1246
+ // Analyze outputs
1247
+ for (const [path, meta] of Object.entries(result.metafile.outputs)) {
1248
+ console.log(`${path}: ${meta.bytes} bytes`);
1249
+ }
1250
+
1251
+ // Save for external analysis tools
1252
+ await Bun.write('./dist/meta.json', JSON.stringify(result.metafile));
1253
+ }
1254
+ ```
1255
+
1256
+ </Tab>
1257
+ <Tab title="CLI">
1258
+ ```bash terminal icon="terminal"
1259
+ bun build ./src/index.ts --outdir ./dist --metafile ./dist/meta.json
1260
+ ```
1261
+ </Tab>
1262
+ </Tabs>
1263
+
1264
+ The metafile structure contains:
1265
+
1266
+ ```ts
1267
+ interface BuildMetafile {
1268
+ inputs: {
1269
+ [path: string]: {
1270
+ bytes: number;
1271
+ imports: Array<{
1272
+ path: string;
1273
+ kind: ImportKind;
1274
+ original?: string; // Original specifier before resolution
1275
+ external?: boolean;
1276
+ }>;
1277
+ format?: "esm" | "cjs" | "json" | "css";
1278
+ };
1279
+ };
1280
+ outputs: {
1281
+ [path: string]: {
1282
+ bytes: number;
1283
+ inputs: {
1284
+ [path: string]: { bytesInOutput: number };
1285
+ };
1286
+ imports: Array<{ path: string; kind: ImportKind }>;
1287
+ exports: string[];
1288
+ entryPoint?: string;
1289
+ cssBundle?: string; // Associated CSS file for JS entry points
1290
+ };
1291
+ };
1292
+ }
1293
+ ```
1294
+
1222
1295
  ## Outputs
1223
1296
 
1224
1297
  The `Bun.build` function returns a `Promise<BuildOutput>`, defined as:
@@ -1228,6 +1301,7 @@ interface BuildOutput {
1228
1301
  outputs: BuildArtifact[];
1229
1302
  success: boolean;
1230
1303
  logs: Array<object>; // see docs for details
1304
+ metafile?: BuildMetafile; // only when metafile: true
1231
1305
  }
1232
1306
 
1233
1307
  interface BuildArtifact extends Blob {
@@ -33,7 +33,7 @@ Alternatively, you can create a PM2 configuration file. Create a file named `pm2
33
33
 
34
34
  ```js pm2.config.js icon="file-code"
35
35
  module.exports = {
36
- title: "app", // Name of your application
36
+ name: "app", // Name of your application
37
37
  script: "index.ts", // Entry point of your application
38
38
  interpreter: "bun", // Bun interpreter
39
39
  env: {
@@ -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.20260106T140718"
36
+ "version": "1.3.6-canary.20260108T140918"
37
37
  }