bun-types 1.1.42 → 1.1.43-canary.20250104T140550
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 +873 -7
- package/docs/api/cc.md +3 -3
- package/docs/api/s3.md +549 -0
- 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/index.md +7 -1
- package/docs/install/lockfile.md +14 -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/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/index.md
CHANGED
|
@@ -62,12 +62,18 @@ To exclude dependency types from installing, use `--omit` with `dev`, `optional`
|
|
|
62
62
|
$ bun install --omit=dev --omit=optional
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
To perform a dry run (i.e. don't actually install anything):
|
|
65
|
+
To perform a dry run (i.e. don't actually install anything or update the lockfile):
|
|
66
66
|
|
|
67
67
|
```bash
|
|
68
68
|
$ bun install --dry-run
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
To generate a lockfile without install packages:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
$ bun install --lockfile-only
|
|
75
|
+
```
|
|
76
|
+
|
|
71
77
|
To modify logging verbosity:
|
|
72
78
|
|
|
73
79
|
```bash
|
package/docs/install/lockfile.md
CHANGED
|
@@ -49,6 +49,18 @@ Packages, metadata for those packages, the hoisted install order, dependencies f
|
|
|
49
49
|
|
|
50
50
|
It uses linear arrays for all data. [Packages](https://github.com/oven-sh/bun/blob/be03fc273a487ac402f19ad897778d74b6d72963/src/install/install.zig#L1825) are referenced by an auto-incrementing integer ID or a hash of the package name. Strings longer than 8 characters are de-duplicated. Prior to saving on disk, the lockfile is garbage-collected & made deterministic by walking the package tree and cloning the packages in dependency order.
|
|
51
51
|
|
|
52
|
+
#### Generate a lockfile without installing?
|
|
53
|
+
|
|
54
|
+
To generate a lockfile without installing to `node_modules` you can use the `--lockfile-only` flag. The lockfile will always be saved to disk, even if it is up-to-date with the `package.json`(s) for your project.
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
$ bun install --lockfile-only
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
{% callout %}
|
|
61
|
+
**Note** - using `--lockfile-only` will still populate the global install cache with registry metadata and git/tarball dependencies.
|
|
62
|
+
{% endcallout %}
|
|
63
|
+
|
|
52
64
|
#### Can I opt out?
|
|
53
65
|
|
|
54
66
|
To install without creating a lockfile:
|
|
@@ -72,6 +84,8 @@ $ bun install --yarn
|
|
|
72
84
|
print = "yarn"
|
|
73
85
|
```
|
|
74
86
|
|
|
87
|
+
{% /codetabs %}
|
|
88
|
+
|
|
75
89
|
### Text-based lockfile
|
|
76
90
|
|
|
77
91
|
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 +104,6 @@ Once `bun.lock` is generated, Bun will use it for all subsequent installs and up
|
|
|
90
104
|
|
|
91
105
|
Bun v1.2.0 will switch the default lockfile format to `bun.lock`.
|
|
92
106
|
|
|
93
|
-
{% /codetabs %}
|
|
94
|
-
|
|
95
107
|
{% details summary="Configuring lockfile" %}
|
|
96
108
|
|
|
97
109
|
```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