bun-types 1.1.42 → 1.1.43-canary.20250103T140555
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 +289 -7
- package/docs/api/cc.md +3 -3
- package/docs/bundler/html.md +110 -0
- package/docs/bundler/loaders.md +76 -1
- package/docs/guides/ecosystem/nextjs.md +8 -0
- package/docs/install/cache.md +1 -1
- package/docs/install/lockfile.md +2 -2
- package/docs/runtime/nodejs-apis.md +3 -3
- package/globals.d.ts +6 -0
- package/html-rewriter.d.ts +2 -0
- package/package.json +1 -1
package/bun.d.ts
CHANGED
|
@@ -539,7 +539,7 @@ declare module "bun" {
|
|
|
539
539
|
*/
|
|
540
540
|
// tslint:disable-next-line:unified-signatures
|
|
541
541
|
function write(
|
|
542
|
-
destination: BunFile | Bun.PathLike,
|
|
542
|
+
destination: BunFile | S3File | Bun.PathLike,
|
|
543
543
|
input: Blob | NodeJS.TypedArray | ArrayBufferLike | string | Bun.BlobPart[],
|
|
544
544
|
options?: {
|
|
545
545
|
/** If writing to a PathLike, set the permissions of the file. */
|
|
@@ -1234,6 +1234,243 @@ declare module "bun" {
|
|
|
1234
1234
|
* For empty Blob, this always returns true.
|
|
1235
1235
|
*/
|
|
1236
1236
|
exists(): Promise<boolean>;
|
|
1237
|
+
|
|
1238
|
+
/**
|
|
1239
|
+
* Write data to the file. This is equivalent to using {@link Bun.write} with a {@link BunFile}.
|
|
1240
|
+
* @param data - The data to write.
|
|
1241
|
+
* @param options - The options to use for the write.
|
|
1242
|
+
*/
|
|
1243
|
+
write(
|
|
1244
|
+
data:
|
|
1245
|
+
| string
|
|
1246
|
+
| ArrayBufferView
|
|
1247
|
+
| ArrayBuffer
|
|
1248
|
+
| SharedArrayBuffer
|
|
1249
|
+
| Request
|
|
1250
|
+
| Response
|
|
1251
|
+
| BunFile,
|
|
1252
|
+
options?: { highWaterMark?: number },
|
|
1253
|
+
): Promise<number>;
|
|
1254
|
+
|
|
1255
|
+
/**
|
|
1256
|
+
* Deletes the file.
|
|
1257
|
+
*/
|
|
1258
|
+
unlink(): Promise<void>;
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
interface S3FileOptions extends BlobPropertyBag {
|
|
1262
|
+
/**
|
|
1263
|
+
* The bucket to use for the S3 client. by default will use the `S3_BUCKET` and `AWS_BUCKET` environment variable, or deduce as first part of the path.
|
|
1264
|
+
*/
|
|
1265
|
+
bucket?: string;
|
|
1266
|
+
/**
|
|
1267
|
+
* The region to use for the S3 client. By default, it will use the `S3_REGION` and `AWS_REGION` environment variable.
|
|
1268
|
+
*/
|
|
1269
|
+
region?: string;
|
|
1270
|
+
/**
|
|
1271
|
+
* The access key ID to use for the S3 client. By default, it will use the `S3_ACCESS_KEY_ID` and `AWS_ACCESS_KEY_ID` environment variable.
|
|
1272
|
+
*/
|
|
1273
|
+
accessKeyId?: string;
|
|
1274
|
+
/**
|
|
1275
|
+
* The secret access key to use for the S3 client. By default, it will use the `S3_SECRET_ACCESS_KEY and `AWS_SECRET_ACCESS_KEY` environment variable.
|
|
1276
|
+
*/
|
|
1277
|
+
secretAccessKey?: string;
|
|
1278
|
+
|
|
1279
|
+
/**
|
|
1280
|
+
* The endpoint to use for the S3 client. Defaults to `https://s3.{region}.amazonaws.com`, it will also use the `S3_ENDPOINT` and `AWS_ENDPOINT` environment variable.
|
|
1281
|
+
*/
|
|
1282
|
+
endpoint?: string;
|
|
1283
|
+
|
|
1284
|
+
/**
|
|
1285
|
+
* The size of each part in MiB. Minimum and Default is 5 MiB and maximum is 5120 MiB.
|
|
1286
|
+
*/
|
|
1287
|
+
partSize?: number;
|
|
1288
|
+
/**
|
|
1289
|
+
* The number of parts to upload in parallel. Default is 5 and maximum is 255. This can speed up the upload of large files but will also use more memory.
|
|
1290
|
+
*/
|
|
1291
|
+
queueSize?: number;
|
|
1292
|
+
/**
|
|
1293
|
+
* The number of times to retry the upload if it fails. Default is 3 and maximum is 255.
|
|
1294
|
+
*/
|
|
1295
|
+
retry?: number;
|
|
1296
|
+
|
|
1297
|
+
/**
|
|
1298
|
+
* The Content-Type of the file. If not provided, it is automatically set based on the file extension when possible.
|
|
1299
|
+
*/
|
|
1300
|
+
type?: string;
|
|
1301
|
+
|
|
1302
|
+
/**
|
|
1303
|
+
* @deprecated The size of the internal buffer in bytes. Defaults to 5 MiB. use `partSize` and `queueSize` instead.
|
|
1304
|
+
*/
|
|
1305
|
+
highWaterMark?: number;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
interface S3FilePresignOptions extends S3FileOptions {
|
|
1309
|
+
/**
|
|
1310
|
+
* The number of seconds the presigned URL will be valid for. Defaults to 86400 (1 day).
|
|
1311
|
+
*/
|
|
1312
|
+
expiresIn?: number;
|
|
1313
|
+
/**
|
|
1314
|
+
* The HTTP method to use for the presigned URL. Defaults to GET.
|
|
1315
|
+
*/
|
|
1316
|
+
method?: string;
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
interface S3File extends BunFile {
|
|
1320
|
+
/**
|
|
1321
|
+
* @param path - The path to the file. If bucket options is not provided or set in the path, it will be deduced from the path.
|
|
1322
|
+
* @param options - The options to use for the S3 client.
|
|
1323
|
+
*/
|
|
1324
|
+
new (path: string | URL, options?: S3FileOptions): S3File;
|
|
1325
|
+
/**
|
|
1326
|
+
* The size of the file in bytes.
|
|
1327
|
+
*/
|
|
1328
|
+
size: Promise<number>;
|
|
1329
|
+
/**
|
|
1330
|
+
* Offset any operation on the file starting at `begin` and ending at `end`. `end` is relative to 0
|
|
1331
|
+
*
|
|
1332
|
+
* Similar to [`TypedArray.subarray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray). Does not copy the file, open the file, or modify the file.
|
|
1333
|
+
*
|
|
1334
|
+
* It will use [`range`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range) to download only the bytes you need.
|
|
1335
|
+
*
|
|
1336
|
+
* @param begin - start offset in bytes
|
|
1337
|
+
* @param end - absolute offset in bytes (relative to 0)
|
|
1338
|
+
* @param contentType - MIME type for the new S3File
|
|
1339
|
+
*/
|
|
1340
|
+
slice(begin?: number, end?: number, contentType?: string): S3File;
|
|
1341
|
+
|
|
1342
|
+
/** */
|
|
1343
|
+
/**
|
|
1344
|
+
* Offset any operation on the file starting at `begin`
|
|
1345
|
+
*
|
|
1346
|
+
* Similar to [`TypedArray.subarray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray). Does not copy the file, open the file, or modify the file.
|
|
1347
|
+
*
|
|
1348
|
+
* It will use [`range`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range) to download only the bytes you need.
|
|
1349
|
+
*
|
|
1350
|
+
* @param begin - start offset in bytes
|
|
1351
|
+
* @param contentType - MIME type for the new S3File
|
|
1352
|
+
*/
|
|
1353
|
+
slice(begin?: number, contentType?: string): S3File;
|
|
1354
|
+
|
|
1355
|
+
/**
|
|
1356
|
+
* @param contentType - MIME type for the new S3File
|
|
1357
|
+
*/
|
|
1358
|
+
slice(contentType?: string): S3File;
|
|
1359
|
+
|
|
1360
|
+
/**
|
|
1361
|
+
* Incremental writer to stream writes to S3, this is equivalent of using MultipartUpload and is suitable for large files.
|
|
1362
|
+
*/
|
|
1363
|
+
writer(options?: S3FileOptions): FileSink;
|
|
1364
|
+
|
|
1365
|
+
/**
|
|
1366
|
+
* The readable stream of the file.
|
|
1367
|
+
*/
|
|
1368
|
+
readonly readable: ReadableStream;
|
|
1369
|
+
|
|
1370
|
+
/**
|
|
1371
|
+
* Get a readable stream of the file.
|
|
1372
|
+
*/
|
|
1373
|
+
stream(): ReadableStream;
|
|
1374
|
+
|
|
1375
|
+
/**
|
|
1376
|
+
* The name or path of the file, as specified in the constructor.
|
|
1377
|
+
*/
|
|
1378
|
+
readonly name?: string;
|
|
1379
|
+
|
|
1380
|
+
/**
|
|
1381
|
+
* The bucket name of the file.
|
|
1382
|
+
*/
|
|
1383
|
+
readonly bucket?: string;
|
|
1384
|
+
|
|
1385
|
+
/**
|
|
1386
|
+
* Does the file exist?
|
|
1387
|
+
* It will use [`head`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD) to check if the file exists.
|
|
1388
|
+
*/
|
|
1389
|
+
exists(): Promise<boolean>;
|
|
1390
|
+
|
|
1391
|
+
/**
|
|
1392
|
+
* Uploads the data to S3. This is equivalent of using {@link S3File.upload} with a {@link S3File}.
|
|
1393
|
+
* @param data - The data to write.
|
|
1394
|
+
* @param options - The options to use for the S3 client.
|
|
1395
|
+
*/
|
|
1396
|
+
write(
|
|
1397
|
+
data:
|
|
1398
|
+
| string
|
|
1399
|
+
| ArrayBufferView
|
|
1400
|
+
| ArrayBuffer
|
|
1401
|
+
| SharedArrayBuffer
|
|
1402
|
+
| Request
|
|
1403
|
+
| Response
|
|
1404
|
+
| BunFile
|
|
1405
|
+
| S3File
|
|
1406
|
+
| Blob,
|
|
1407
|
+
options?: S3FileOptions,
|
|
1408
|
+
): Promise<number>;
|
|
1409
|
+
|
|
1410
|
+
/**
|
|
1411
|
+
* Returns a presigned URL for the file.
|
|
1412
|
+
* @param options - The options to use for the presigned URL.
|
|
1413
|
+
*/
|
|
1414
|
+
presign(options?: S3FilePresignOptions): string;
|
|
1415
|
+
|
|
1416
|
+
/**
|
|
1417
|
+
* Deletes the file from S3.
|
|
1418
|
+
*/
|
|
1419
|
+
unlink(): Promise<void>;
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
namespace S3File {
|
|
1423
|
+
/**
|
|
1424
|
+
* Uploads the data to S3.
|
|
1425
|
+
* @param data - The data to write.
|
|
1426
|
+
* @param options - The options to use for the S3 client.
|
|
1427
|
+
*/
|
|
1428
|
+
function upload(
|
|
1429
|
+
path: string | S3File,
|
|
1430
|
+
data:
|
|
1431
|
+
| string
|
|
1432
|
+
| ArrayBufferView
|
|
1433
|
+
| ArrayBuffer
|
|
1434
|
+
| SharedArrayBuffer
|
|
1435
|
+
| Request
|
|
1436
|
+
| Response
|
|
1437
|
+
| BunFile
|
|
1438
|
+
| S3File,
|
|
1439
|
+
options?: S3FileOptions,
|
|
1440
|
+
): Promise<number>;
|
|
1441
|
+
|
|
1442
|
+
/**
|
|
1443
|
+
* Returns a presigned URL for the file.
|
|
1444
|
+
* @param options - The options to use for the presigned URL.
|
|
1445
|
+
*/
|
|
1446
|
+
function presign(
|
|
1447
|
+
path: string | S3File,
|
|
1448
|
+
options?: S3FilePresignOptions,
|
|
1449
|
+
): string;
|
|
1450
|
+
|
|
1451
|
+
/**
|
|
1452
|
+
* Deletes the file from S3.
|
|
1453
|
+
*/
|
|
1454
|
+
function unlink(
|
|
1455
|
+
path: string | S3File,
|
|
1456
|
+
options?: S3FileOptions,
|
|
1457
|
+
): Promise<void>;
|
|
1458
|
+
|
|
1459
|
+
/**
|
|
1460
|
+
* The size of the file in bytes.
|
|
1461
|
+
*/
|
|
1462
|
+
function size(
|
|
1463
|
+
path: string | S3File,
|
|
1464
|
+
options?: S3FileOptions,
|
|
1465
|
+
): Promise<number>;
|
|
1466
|
+
|
|
1467
|
+
/**
|
|
1468
|
+
* The size of the file in bytes.
|
|
1469
|
+
*/
|
|
1470
|
+
function exists(
|
|
1471
|
+
path: string | S3File,
|
|
1472
|
+
options?: S3FileOptions,
|
|
1473
|
+
): Promise<boolean>;
|
|
1237
1474
|
}
|
|
1238
1475
|
|
|
1239
1476
|
/**
|
|
@@ -1682,10 +1919,28 @@ declare module "bun" {
|
|
|
1682
1919
|
/**
|
|
1683
1920
|
* **Experimental**
|
|
1684
1921
|
*
|
|
1685
|
-
*
|
|
1922
|
+
* Bundle CSS files.
|
|
1923
|
+
*
|
|
1924
|
+
* This will be enabled by default in Bun v1.2.
|
|
1925
|
+
*
|
|
1926
|
+
* @default false (until Bunv 1.2)
|
|
1686
1927
|
*/
|
|
1687
1928
|
experimentalCss?: boolean;
|
|
1688
1929
|
|
|
1930
|
+
/**
|
|
1931
|
+
* **Experimental**
|
|
1932
|
+
*
|
|
1933
|
+
* Bundle JavaScript & CSS files from HTML files. JavaScript & CSS files
|
|
1934
|
+
* from non-external <script> or <link> tags will be bundled.
|
|
1935
|
+
*
|
|
1936
|
+
* Underneath, this works similarly to HTMLRewriter.
|
|
1937
|
+
*
|
|
1938
|
+
* This will be enabled by default in Bun v1.2.
|
|
1939
|
+
*
|
|
1940
|
+
* @default false (until Bun v1.2)
|
|
1941
|
+
*/
|
|
1942
|
+
html?: boolean;
|
|
1943
|
+
|
|
1689
1944
|
/**
|
|
1690
1945
|
* Drop function calls to matching property accesses.
|
|
1691
1946
|
*/
|
|
@@ -3111,7 +3366,7 @@ declare module "bun" {
|
|
|
3111
3366
|
* "Hello, world!"
|
|
3112
3367
|
* );
|
|
3113
3368
|
* ```
|
|
3114
|
-
* @param path The path to the file (lazily loaded)
|
|
3369
|
+
* @param path The path to the file (lazily loaded) if the path starts with `s3://` it will behave like {@link S3File}
|
|
3115
3370
|
*/
|
|
3116
3371
|
// tslint:disable-next-line:unified-signatures
|
|
3117
3372
|
function file(path: string | URL, options?: BlobPropertyBag): BunFile;
|
|
@@ -3137,7 +3392,7 @@ declare module "bun" {
|
|
|
3137
3392
|
* console.log(file.type); // "application/json"
|
|
3138
3393
|
* ```
|
|
3139
3394
|
*
|
|
3140
|
-
* @param path The path to the file as a byte buffer (the buffer is copied)
|
|
3395
|
+
* @param path The path to the file as a byte buffer (the buffer is copied) if the path starts with `s3://` it will behave like {@link S3File}
|
|
3141
3396
|
*/
|
|
3142
3397
|
// tslint:disable-next-line:unified-signatures
|
|
3143
3398
|
function file(
|
|
@@ -3162,6 +3417,17 @@ declare module "bun" {
|
|
|
3162
3417
|
// tslint:disable-next-line:unified-signatures
|
|
3163
3418
|
function file(fileDescriptor: number, options?: BlobPropertyBag): BunFile;
|
|
3164
3419
|
|
|
3420
|
+
/**
|
|
3421
|
+
* Lazily load/upload a file from S3.
|
|
3422
|
+
* @param path - The path to the file. If bucket options is not provided or set in the path, it will be deduced from the path.
|
|
3423
|
+
* @param options - The options to use for the S3 client.
|
|
3424
|
+
*/
|
|
3425
|
+
function s3(path: string | URL, options?: S3FileOptions): S3File;
|
|
3426
|
+
/**
|
|
3427
|
+
* The S3 file class.
|
|
3428
|
+
*/
|
|
3429
|
+
const S3: typeof S3File;
|
|
3430
|
+
|
|
3165
3431
|
/**
|
|
3166
3432
|
* Allocate a new [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) without zeroing the bytes.
|
|
3167
3433
|
*
|
|
@@ -3483,9 +3749,24 @@ declare module "bun" {
|
|
|
3483
3749
|
function nanoseconds(): number;
|
|
3484
3750
|
|
|
3485
3751
|
/**
|
|
3486
|
-
*
|
|
3752
|
+
* Show precise statistics about memory usage of your application
|
|
3753
|
+
*
|
|
3754
|
+
* Generate a heap snapshot in JavaScriptCore's format that can be viewed with `bun --inspect` or Safari's Web Inspector
|
|
3755
|
+
*/
|
|
3756
|
+
function generateHeapSnapshot(format?: "jsc"): HeapSnapshot;
|
|
3757
|
+
|
|
3758
|
+
/**
|
|
3759
|
+
* Show precise statistics about memory usage of your application
|
|
3760
|
+
*
|
|
3761
|
+
* Generate a V8 Heap Snapshot that can be used with Chrome DevTools & Visual Studio Code
|
|
3762
|
+
*
|
|
3763
|
+
* This is a JSON string that can be saved to a file.
|
|
3764
|
+
* ```ts
|
|
3765
|
+
* const snapshot = Bun.generateHeapSnapshot("v8");
|
|
3766
|
+
* await Bun.write("heap.heapsnapshot", snapshot);
|
|
3767
|
+
* ```
|
|
3487
3768
|
*/
|
|
3488
|
-
function generateHeapSnapshot():
|
|
3769
|
+
function generateHeapSnapshot(format: "v8"): string;
|
|
3489
3770
|
|
|
3490
3771
|
/**
|
|
3491
3772
|
* The next time JavaScriptCore is idle, clear unused memory and attempt to reduce the heap size.
|
|
@@ -3979,7 +4260,8 @@ declare module "bun" {
|
|
|
3979
4260
|
| "napi"
|
|
3980
4261
|
| "wasm"
|
|
3981
4262
|
| "text"
|
|
3982
|
-
| "css"
|
|
4263
|
+
| "css"
|
|
4264
|
+
| "html";
|
|
3983
4265
|
|
|
3984
4266
|
interface PluginConstraints {
|
|
3985
4267
|
/**
|
package/docs/api/cc.md
CHANGED
|
@@ -179,16 +179,16 @@ type Flags = string | string[];
|
|
|
179
179
|
|
|
180
180
|
These are flags like `-I` for include directories and `-D` for preprocessor definitions.
|
|
181
181
|
|
|
182
|
-
#### `
|
|
182
|
+
#### `define: Record<string, string>`
|
|
183
183
|
|
|
184
|
-
The `
|
|
184
|
+
The `define` is an optional object that should be passed to the TinyCC compiler.
|
|
185
185
|
|
|
186
186
|
```ts
|
|
187
187
|
type Defines = Record<string, string>;
|
|
188
188
|
|
|
189
189
|
cc({
|
|
190
190
|
source: "hello.c",
|
|
191
|
-
|
|
191
|
+
define: {
|
|
192
192
|
"NDEBUG": "1",
|
|
193
193
|
},
|
|
194
194
|
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
As of Bun v1.1.43, Bun's bundler now has first-class support for HTML. Build static sites, landing pages, and web applications with zero configuration. Just point Bun at your HTML file and it handles everything else.
|
|
2
|
+
|
|
3
|
+
```html#index.html
|
|
4
|
+
<!doctype html>
|
|
5
|
+
<html>
|
|
6
|
+
<head>
|
|
7
|
+
<link rel="stylesheet" href="./styles.css" />
|
|
8
|
+
<script src="./app.ts" type="module"></script>
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<img src="./logo.png" />
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
One command is all you need (won't be experimental after Bun v1.2):
|
|
17
|
+
|
|
18
|
+
{% codetabs %}
|
|
19
|
+
|
|
20
|
+
```bash#CLI
|
|
21
|
+
$ bun build --experimental-html --experimental-css ./index.html --outdir=dist
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```ts#API
|
|
25
|
+
Bun.build({
|
|
26
|
+
entrypoints: ["./index.html"],
|
|
27
|
+
outdir: "./dist",
|
|
28
|
+
|
|
29
|
+
// On by default in Bun v1.2+
|
|
30
|
+
html: true,
|
|
31
|
+
experimentalCss: true,
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
{% /codetabs %}
|
|
36
|
+
|
|
37
|
+
Bun automatically:
|
|
38
|
+
|
|
39
|
+
- Bundles, tree-shakes, and optimizes your JavaScript, JSX and TypeScript
|
|
40
|
+
- Bundles and optimizes your CSS
|
|
41
|
+
- Copies & hashes images and other assets
|
|
42
|
+
- Updates all references to local files or packages in your HTML
|
|
43
|
+
|
|
44
|
+
## Zero Config, Maximum Performance
|
|
45
|
+
|
|
46
|
+
The HTML bundler is enabled by default after Bun v1.2+. Drop in your existing HTML files and Bun will handle:
|
|
47
|
+
|
|
48
|
+
- **TypeScript & JSX** - Write modern JavaScript for browsers without the setup
|
|
49
|
+
- **CSS** - Bundle CSS stylesheets directly from `<link rel="stylesheet">` or `@import`
|
|
50
|
+
- **Images & Assets** - Automatic copying & hashing & rewriting of assets in JavaScript, CSS, and HTML
|
|
51
|
+
|
|
52
|
+
## Watch mode
|
|
53
|
+
|
|
54
|
+
You can run `bun build --watch` to watch for changes and rebuild automatically.
|
|
55
|
+
|
|
56
|
+
You've never seen a watch mode this fast.
|
|
57
|
+
|
|
58
|
+
## Plugin API
|
|
59
|
+
|
|
60
|
+
Need more control? Configure the bundler through the JavaScript API and use Bun's builtin `HTMLRewriter` to preprocess HTML.
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
await Bun.build({
|
|
64
|
+
entrypoints: ["./index.html"],
|
|
65
|
+
outdir: "./dist",
|
|
66
|
+
html: true,
|
|
67
|
+
experimentalCss: true,
|
|
68
|
+
minify: true,
|
|
69
|
+
|
|
70
|
+
plugins: [
|
|
71
|
+
{
|
|
72
|
+
// A plugin that makes every HTML tag lowercase
|
|
73
|
+
name: "lowercase-html-plugin",
|
|
74
|
+
setup({ onLoad }) {
|
|
75
|
+
const rewriter = new HTMLRewriter().on("*", {
|
|
76
|
+
element(element) {
|
|
77
|
+
element.tagName = element.tagName.toLowerCase();
|
|
78
|
+
},
|
|
79
|
+
text(element) {
|
|
80
|
+
element.replace(element.text.toLowerCase());
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
onLoad({ filter: /\.html$/ }, async args => {
|
|
85
|
+
const html = await Bun.file(args.path).text();
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
// Bun's bundler will scan the HTML for <script> tags, <link rel="stylesheet"> tags, and other assets
|
|
89
|
+
// and bundle them automatically
|
|
90
|
+
contents: rewriter.transform(html),
|
|
91
|
+
loader: "html",
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## What Gets Processed?
|
|
101
|
+
|
|
102
|
+
Bun automatically handles all common web assets:
|
|
103
|
+
|
|
104
|
+
- Scripts (`<script src>`) are run through Bun's JavaScript/TypeScript/JSX bundler
|
|
105
|
+
- Stylesheets (`<link rel="stylesheet">`) are run through Bun's CSS parser & bundler
|
|
106
|
+
- Images (`<img>`, `<picture>`) are copied and hashed
|
|
107
|
+
- Media (`<video>`, `<audio>`, `<source>`) are copied and hashed
|
|
108
|
+
- Any `<link>` tag with an `href` attribute pointing to a local file is rewritten to the new path, and hashed
|
|
109
|
+
|
|
110
|
+
All paths are resolved relative to your HTML file, making it easy to organize your project however you want.
|
package/docs/bundler/loaders.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The Bun bundler implements a set of default loaders out of the box. As a rule of thumb, the bundler and the runtime both support the same set of file types out of the box.
|
|
2
2
|
|
|
3
|
-
`.js` `.cjs` `.mjs` `.mts` `.cts` `.ts` `.tsx` `.jsx` `.toml` `.json` `.txt` `.wasm` `.node`
|
|
3
|
+
`.js` `.cjs` `.mjs` `.mts` `.cts` `.ts` `.tsx` `.jsx` `.toml` `.json` `.txt` `.wasm` `.node` `.html`
|
|
4
4
|
|
|
5
5
|
Bun uses the file extension to determine which built-in _loader_ should be used to parse the file. Every loader has a name, such as `js`, `tsx`, or `json`. These names are used when building [plugins](https://bun.sh/docs/bundler/plugins) that extend Bun with custom loaders.
|
|
6
6
|
|
|
@@ -203,6 +203,81 @@ When using a [standalone executable](https://bun.sh/docs/bundler/executables), t
|
|
|
203
203
|
|
|
204
204
|
Otherwise, the database to embed is copied into the `outdir` with a hashed filename.
|
|
205
205
|
|
|
206
|
+
### `html`
|
|
207
|
+
|
|
208
|
+
**HTML loader**. Default for `.html` after Bun v1.2.0.
|
|
209
|
+
|
|
210
|
+
To enable the html loader:
|
|
211
|
+
|
|
212
|
+
- For `Bun.build`: set `html: true`
|
|
213
|
+
- For `bun build`: `--experimental-html` CLI flag
|
|
214
|
+
|
|
215
|
+
You most likely want to use the `html` loader in conjunction with `experimentalCss: true` or `--experimental-css`.
|
|
216
|
+
|
|
217
|
+
The html loader processes HTML files and bundles any referenced assets. It will:
|
|
218
|
+
|
|
219
|
+
- Bundle and hash referenced JavaScript files (`<script src="...">`)
|
|
220
|
+
- Bundle and hash referenced CSS files (`<link rel="stylesheet" href="...">`)
|
|
221
|
+
- Hash referenced images (`<img src="...">`)
|
|
222
|
+
- Preserve external URLs (by default, anything starting with `http://` or `https://`)
|
|
223
|
+
|
|
224
|
+
For example, given this HTML file:
|
|
225
|
+
|
|
226
|
+
{% codetabs %}
|
|
227
|
+
|
|
228
|
+
```html#src/index.html
|
|
229
|
+
<!DOCTYPE html>
|
|
230
|
+
<html>
|
|
231
|
+
<body>
|
|
232
|
+
<img src="./image.jpg" alt="Local image">
|
|
233
|
+
<img src="https://example.com/image.jpg" alt="External image">
|
|
234
|
+
<script type="module" src="./script.js"></script>
|
|
235
|
+
</body>
|
|
236
|
+
</html>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
{% /codetabs %}
|
|
240
|
+
|
|
241
|
+
It will output a new HTML file with the bundled assets:
|
|
242
|
+
|
|
243
|
+
{% codetabs %}
|
|
244
|
+
|
|
245
|
+
```html#dist/output.html
|
|
246
|
+
<!DOCTYPE html>
|
|
247
|
+
<html>
|
|
248
|
+
<body>
|
|
249
|
+
<img src="./image-HASHED.jpg" alt="Local image">
|
|
250
|
+
<img src="https://example.com/image.jpg" alt="External image">
|
|
251
|
+
<script type="module" src="./output-ALSO-HASHED.js"></script>
|
|
252
|
+
</body>
|
|
253
|
+
</html>
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
{% /codetabs %}
|
|
257
|
+
|
|
258
|
+
Under the hood, it uses [`lol-html`](https://github.com/cloudflare/lol-html) to extract script and link tags as entrypoints, and other assets as external.
|
|
259
|
+
|
|
260
|
+
Currently, the list of selectors is:
|
|
261
|
+
|
|
262
|
+
- `audio[src]`
|
|
263
|
+
- `iframe[src]`
|
|
264
|
+
- `img[src]`
|
|
265
|
+
- `img[srcset]`
|
|
266
|
+
- `link:not([rel~='stylesheet']):not([rel~='modulepreload']):not([rel~='manifest']):not([rel~='icon']):not([rel~='apple-touch-icon'])[href]`
|
|
267
|
+
- `link[as='font'][href], link[type^='font/'][href]`
|
|
268
|
+
- `link[as='image'][href]`
|
|
269
|
+
- `link[as='style'][href]`
|
|
270
|
+
- `link[as='video'][href], link[as='audio'][href]`
|
|
271
|
+
- `link[as='worker'][href]`
|
|
272
|
+
- `link[rel='icon'][href], link[rel='apple-touch-icon'][href]`
|
|
273
|
+
- `link[rel='manifest'][href]`
|
|
274
|
+
- `link[rel='stylesheet'][href]`
|
|
275
|
+
- `script[src]`
|
|
276
|
+
- `source[src]`
|
|
277
|
+
- `source[srcset]`
|
|
278
|
+
- `video[poster]`
|
|
279
|
+
- `video[src]`
|
|
280
|
+
|
|
206
281
|
### `sh` loader
|
|
207
282
|
|
|
208
283
|
**Bun Shell loader**. Default for `.sh` files
|
|
@@ -15,6 +15,14 @@ $ bun create next-app
|
|
|
15
15
|
Creating a new Next.js app in /path/to/my-app.
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
You can specify a starter template using the `--example` flag.
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
$ bun create next-app --example with-supabase
|
|
22
|
+
✔ What is your project named? … my-app
|
|
23
|
+
...
|
|
24
|
+
```
|
|
25
|
+
|
|
18
26
|
---
|
|
19
27
|
|
|
20
28
|
To start the dev server with Bun, run `bun --bun run dev` from the project root.
|
package/docs/install/cache.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
All packages downloaded from the registry are stored in a global cache at `~/.bun/install/cache`. They are stored in subdirectories named like `${name}@${version}`, so multiple versions of a package can be cached.
|
|
1
|
+
All packages downloaded from the registry are stored in a global cache at `~/.bun/install/cache`, or the path defined by the environment variable `BUN_INSTALL_CACHE_DIR`. They are stored in subdirectories named like `${name}@${version}`, so multiple versions of a package can be cached.
|
|
2
2
|
|
|
3
3
|
{% details summary="Configuring cache behavior (bunfig.toml)" %}
|
|
4
4
|
|
package/docs/install/lockfile.md
CHANGED
|
@@ -72,6 +72,8 @@ $ bun install --yarn
|
|
|
72
72
|
print = "yarn"
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
+
{% /codetabs %}
|
|
76
|
+
|
|
75
77
|
### Text-based lockfile
|
|
76
78
|
|
|
77
79
|
Bun v1.1.39 introduced `bun.lock`, a JSONC formatted lockfile. `bun.lock` is human-readable and git-diffable without configuration, at [no cost to performance](https://bun.sh/blog/bun-lock-text-lockfile#cached-bun-install-gets-30-faster).
|
|
@@ -90,8 +92,6 @@ Once `bun.lock` is generated, Bun will use it for all subsequent installs and up
|
|
|
90
92
|
|
|
91
93
|
Bun v1.2.0 will switch the default lockfile format to `bun.lock`.
|
|
92
94
|
|
|
93
|
-
{% /codetabs %}
|
|
94
|
-
|
|
95
95
|
{% details summary="Configuring lockfile" %}
|
|
96
96
|
|
|
97
97
|
```toml
|
|
@@ -53,7 +53,7 @@ Some methods are not optimized yet.
|
|
|
53
53
|
|
|
54
54
|
### [`node:events`](https://nodejs.org/api/events.html)
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
🟢 Fully implemented. `EventEmitterAsyncResource` uses `AsyncResource` underneath.
|
|
57
57
|
|
|
58
58
|
### [`node:fs`](https://nodejs.org/api/fs.html)
|
|
59
59
|
|
|
@@ -157,11 +157,11 @@ Some methods are not optimized yet.
|
|
|
157
157
|
|
|
158
158
|
### [`node:v8`](https://nodejs.org/api/v8.html)
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
🟡 `writeHeapSnapshot` and `getHeapSnapshot` are implemented. `serialize` and `deserialize` use JavaScriptCore's wire format instead of V8's. Other methods are not implemented. For profiling, use [`bun:jsc`](https://bun.sh/docs/project/benchmarking#bunjsc) instead.
|
|
161
161
|
|
|
162
162
|
### [`node:vm`](https://nodejs.org/api/vm.html)
|
|
163
163
|
|
|
164
|
-
🟡 Core functionality works, but experimental VM ES modules are not implemented, including `vm.Module`, `vm.SourceTextModule`, `vm.SyntheticModule`,`importModuleDynamically`, and `vm.measureMemory`. Options like `timeout`, `breakOnSigint`, `cachedData` are not implemented yet.
|
|
164
|
+
🟡 Core functionality works, but experimental VM ES modules are not implemented, including `vm.Module`, `vm.SourceTextModule`, `vm.SyntheticModule`,`importModuleDynamically`, and `vm.measureMemory`. Options like `timeout`, `breakOnSigint`, `cachedData` are not implemented yet.
|
|
165
165
|
|
|
166
166
|
### [`node:wasi`](https://nodejs.org/api/wasi.html)
|
|
167
167
|
|
package/globals.d.ts
CHANGED
|
@@ -137,6 +137,7 @@ type _Body = typeof globalThis extends { onerror: any }
|
|
|
137
137
|
readonly text: () => Promise<string>;
|
|
138
138
|
};
|
|
139
139
|
|
|
140
|
+
import { S3FileOptions } from "bun";
|
|
140
141
|
import type {
|
|
141
142
|
TextDecoder as NodeTextDecoder,
|
|
142
143
|
TextEncoder as NodeTextEncoder,
|
|
@@ -896,6 +897,11 @@ declare global {
|
|
|
896
897
|
rejectUnauthorized?: boolean | undefined; // Defaults to true
|
|
897
898
|
checkServerIdentity?: any; // TODO: change `any` to `checkServerIdentity`
|
|
898
899
|
};
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* Override the default S3 options
|
|
903
|
+
*/
|
|
904
|
+
s3?: S3FileOptions;
|
|
899
905
|
}
|
|
900
906
|
|
|
901
907
|
/**
|
package/html-rewriter.d.ts
CHANGED
package/package.json
CHANGED