bun-types 1.1.44-canary.20250110T140547 → 1.1.44-canary.20250112T140558
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 +10 -0
- package/docs/api/file-io.md +8 -0
- package/docs/cli/install.md +3 -3
- package/docs/guides/ecosystem/discordjs.md +7 -7
- package/docs/guides/ecosystem/hono.md +2 -2
- package/docs/guides/ecosystem/mongoose.md +6 -6
- package/docs/guides/ecosystem/nextjs.md +2 -0
- package/docs/guides/ecosystem/render.md +9 -9
- package/docs/guides/ecosystem/sentry.md +2 -2
- package/docs/guides/http/hot.md +6 -2
- package/docs/guides/install/add-peer.md +29 -2
- package/docs/guides/install/add.md +1 -1
- package/docs/guides/install/cicd.md +3 -3
- package/docs/guides/install/git-diff-bun-lockfile.md +6 -0
- package/docs/guides/install/trusted.md +0 -2
- package/docs/guides/install/yarnlock.md +6 -0
- package/docs/guides/process/argv.md +3 -1
- package/docs/guides/runtime/define-constant.md +15 -15
- package/docs/guides/write-file/unlink.md +5 -12
- package/docs/install/cache.md +4 -2
- package/docs/install/lockfile.md +1 -1
- package/docs/runtime/env.md +2 -2
- package/html-rewriter.d.ts +1 -1
- package/package.json +1 -1
package/bun.d.ts
CHANGED
|
@@ -1261,6 +1261,16 @@ declare module "bun" {
|
|
|
1261
1261
|
* Deletes the file.
|
|
1262
1262
|
*/
|
|
1263
1263
|
unlink(): Promise<void>;
|
|
1264
|
+
|
|
1265
|
+
/**
|
|
1266
|
+
* Deletes the file. ( same as unlink )
|
|
1267
|
+
*/
|
|
1268
|
+
delete(): Promise<void>;
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
* Provides useful information about the file.
|
|
1272
|
+
*/
|
|
1273
|
+
stat(): Promise<Stats>;
|
|
1264
1274
|
}
|
|
1265
1275
|
interface NetworkSink extends FileSink {
|
|
1266
1276
|
/**
|
package/docs/api/file-io.md
CHANGED
|
@@ -62,6 +62,14 @@ Bun.stdout;
|
|
|
62
62
|
Bun.stderr;
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
+
### Deleting files (`file.delete()`)
|
|
66
|
+
|
|
67
|
+
You can delete a file by calling the `.delete()` function.
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
await Bun.file("logs.json").delete()
|
|
71
|
+
```
|
|
72
|
+
|
|
65
73
|
## Writing files (`Bun.write()`)
|
|
66
74
|
|
|
67
75
|
`Bun.write(destination, data): Promise<number>`
|
package/docs/cli/install.md
CHANGED
|
@@ -15,10 +15,10 @@ If you're using Ubuntu 20.04, here's how to install a [newer kernel](https://wik
|
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
17
|
# If this returns a version >= 5.6, you don't need to do anything
|
|
18
|
-
uname -r
|
|
18
|
+
$ uname -r
|
|
19
19
|
|
|
20
20
|
# Install the official Ubuntu hardware enablement kernel
|
|
21
|
-
sudo apt install --install-recommends linux-generic-hwe-20.04
|
|
21
|
+
$ sudo apt install --install-recommends linux-generic-hwe-20.04
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
{% /details %}
|
|
@@ -229,7 +229,7 @@ jobs:
|
|
|
229
229
|
- name: Checkout repo
|
|
230
230
|
uses: actions/checkout@v4
|
|
231
231
|
- name: Install bun
|
|
232
|
-
uses: oven-sh/setup-bun@
|
|
232
|
+
uses: oven-sh/setup-bun@v2
|
|
233
233
|
- name: Install dependencies
|
|
234
234
|
run: bun install
|
|
235
235
|
- name: Build app
|
|
@@ -4,18 +4,18 @@ name: Create a Discord bot
|
|
|
4
4
|
|
|
5
5
|
Discord.js works out of the box with Bun. Let's write a simple bot. First create a directory and initialize it with `bun init`.
|
|
6
6
|
|
|
7
|
-
```
|
|
8
|
-
mkdir my-bot
|
|
9
|
-
cd my-bot
|
|
10
|
-
bun init
|
|
7
|
+
```sh
|
|
8
|
+
$ mkdir my-bot
|
|
9
|
+
$ cd my-bot
|
|
10
|
+
$ bun init
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
Now install Discord.js.
|
|
16
16
|
|
|
17
|
-
```
|
|
18
|
-
bun add discord.js
|
|
17
|
+
```sh
|
|
18
|
+
$ bun add discord.js
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
---
|
|
@@ -67,7 +67,7 @@ client.login(process.env.DISCORD_TOKEN);
|
|
|
67
67
|
|
|
68
68
|
Now we can run our bot with `bun run`. It may take a several seconds for the client to initialize the first time you run the file.
|
|
69
69
|
|
|
70
|
-
```
|
|
70
|
+
```sh
|
|
71
71
|
$ bun run bot.ts
|
|
72
72
|
Ready! Logged in as my-bot#1234
|
|
73
73
|
```
|
|
@@ -17,7 +17,7 @@ export default app;
|
|
|
17
17
|
|
|
18
18
|
Use `create-hono` to get started with one of Hono's project templates. Select `bun` when prompted for a template.
|
|
19
19
|
|
|
20
|
-
```
|
|
20
|
+
```sh
|
|
21
21
|
$ bun create hono myapp
|
|
22
22
|
✔ Which template do you want to use? › bun
|
|
23
23
|
cloned honojs/starter#main to /path/to/myapp
|
|
@@ -30,7 +30,7 @@ $ bun install
|
|
|
30
30
|
|
|
31
31
|
Then start the dev server and visit [localhost:3000](http://localhost:3000).
|
|
32
32
|
|
|
33
|
-
```
|
|
33
|
+
```sh
|
|
34
34
|
$ bun run dev
|
|
35
35
|
```
|
|
36
36
|
|
|
@@ -8,18 +8,18 @@ MongoDB and Mongoose work out of the box with Bun. This guide assumes you've alr
|
|
|
8
8
|
|
|
9
9
|
Once MongoDB is running, create a directory and initialize it with `bun init`.
|
|
10
10
|
|
|
11
|
-
```
|
|
12
|
-
mkdir mongoose-app
|
|
13
|
-
cd mongoose-app
|
|
14
|
-
bun init
|
|
11
|
+
```sh
|
|
12
|
+
$ mkdir mongoose-app
|
|
13
|
+
$ cd mongoose-app
|
|
14
|
+
$ bun init
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
---
|
|
18
18
|
|
|
19
19
|
Then add Mongoose as a dependency.
|
|
20
20
|
|
|
21
|
-
```
|
|
22
|
-
bun add mongoose
|
|
21
|
+
```sh
|
|
22
|
+
$ bun add mongoose
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
---
|
|
@@ -16,17 +16,17 @@ As an example, let's deploy a simple Express HTTP server to Render.
|
|
|
16
16
|
|
|
17
17
|
Create a new GitHub repo named `myapp`. Git clone it locally.
|
|
18
18
|
|
|
19
|
-
```
|
|
20
|
-
git clone git@github.com:my-github-username/myapp.git
|
|
21
|
-
cd myapp
|
|
19
|
+
```sh
|
|
20
|
+
$ git clone git@github.com:my-github-username/myapp.git
|
|
21
|
+
$ cd myapp
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
---
|
|
25
25
|
|
|
26
26
|
Add the Express library.
|
|
27
27
|
|
|
28
|
-
```
|
|
29
|
-
bun add express
|
|
28
|
+
```sh
|
|
29
|
+
$ bun add express
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
---
|
|
@@ -52,10 +52,10 @@ app.listen(port, () => {
|
|
|
52
52
|
|
|
53
53
|
Commit your changes and push to GitHub.
|
|
54
54
|
|
|
55
|
-
```
|
|
56
|
-
git add app.ts bun.lockb package.json
|
|
57
|
-
git commit -m "Create simple Express app"
|
|
58
|
-
git push origin main
|
|
55
|
+
```sh
|
|
56
|
+
$ git add app.ts bun.lockb package.json
|
|
57
|
+
$ git commit -m "Create simple Express app"
|
|
58
|
+
$ git push origin main
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
---
|
package/docs/guides/http/hot.md
CHANGED
|
@@ -5,18 +5,22 @@ name: Hot reload an HTTP server
|
|
|
5
5
|
Bun supports the [`--hot`](https://bun.sh/docs/runtime/hot#hot-mode) flag to run a file with hot reloading enabled. When any module or file changes, Bun re-runs the file.
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
bun --hot run index.ts
|
|
8
|
+
$ bun --hot run index.ts
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
13
|
Bun detects when you are running an HTTP server with `Bun.serve()`. It reloads your fetch handler when source files change, _without_ restarting the `bun` process. This makes hot reloads nearly instantaneous.
|
|
14
14
|
|
|
15
|
+
{% callout %}
|
|
16
|
+
Note that this doesn't reload the page on your browser.
|
|
17
|
+
{% /callout %}
|
|
18
|
+
|
|
15
19
|
```ts
|
|
16
20
|
Bun.serve({
|
|
17
21
|
port: 3000,
|
|
18
22
|
fetch(req) {
|
|
19
|
-
return new Response(
|
|
23
|
+
return new Response("Hello world");
|
|
20
24
|
},
|
|
21
25
|
});
|
|
22
26
|
```
|
|
@@ -2,16 +2,43 @@
|
|
|
2
2
|
name: Add a peer dependency
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
To add an npm package as a peer dependency, use the `--peer` flag.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
$ bun add @types/bun --peer
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
This will add the package to `peerDependencies` in `package.json`.
|
|
6
15
|
|
|
7
16
|
```json-diff
|
|
8
17
|
{
|
|
9
18
|
"peerDependencies": {
|
|
10
|
-
+ "
|
|
19
|
+
+ "@types/bun": "^1.0.0"
|
|
11
20
|
}
|
|
12
21
|
}
|
|
13
22
|
```
|
|
14
23
|
|
|
15
24
|
---
|
|
16
25
|
|
|
26
|
+
Running `bun install` will install peer dependencies by default, unless marked optional in `peerDependenciesMeta`.
|
|
27
|
+
|
|
28
|
+
```json-diff
|
|
29
|
+
{
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@types/bun": "^1.0.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependenciesMeta": {
|
|
34
|
+
+ "@types/bun": {
|
|
35
|
+
+ "optional": true
|
|
36
|
+
+ }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
17
44
|
See [Docs > Package manager](https://bun.sh/docs/cli/install) for complete documentation of Bun's package manager.
|
|
@@ -22,7 +22,7 @@ This will add the package to `dependencies` in `package.json`. By default, the `
|
|
|
22
22
|
|
|
23
23
|
---
|
|
24
24
|
|
|
25
|
-
To "pin" to
|
|
25
|
+
To "pin" to an exact version of the package, use `--exact`. This will add the package to `dependencies` without the `^`, pinning your project to the exact version you installed.
|
|
26
26
|
|
|
27
27
|
```sh
|
|
28
28
|
$ bun add zod --exact
|
|
@@ -13,7 +13,7 @@ jobs:
|
|
|
13
13
|
steps:
|
|
14
14
|
# ...
|
|
15
15
|
- uses: actions/checkout@v4
|
|
16
|
-
+ - uses: oven-sh/setup-bun@
|
|
16
|
+
+ - uses: oven-sh/setup-bun@v2
|
|
17
17
|
|
|
18
18
|
# run any `bun` or `bunx` command
|
|
19
19
|
+ - run: bun install
|
|
@@ -31,9 +31,9 @@ jobs:
|
|
|
31
31
|
runs-on: ubuntu-latest
|
|
32
32
|
steps:
|
|
33
33
|
# ...
|
|
34
|
-
- uses: oven-sh/setup-bun@
|
|
34
|
+
- uses: oven-sh/setup-bun@v2
|
|
35
35
|
+ with:
|
|
36
|
-
+ version:
|
|
36
|
+
+ version: "latest" # or "canary"
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
---
|
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
name: Configure git to diff Bun's lockb lockfile
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
{% callout %}
|
|
6
|
+
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. [**Learn more.**](https://bun.sh/docs/install/lockfile#text-based-lockfile)
|
|
7
|
+
{% /callout %}
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
5
11
|
To teach `git` how to generate a human-readable diff of Bun's binary lockfile format (`.lockb`), add the following to your local or global `.gitattributes` file:
|
|
6
12
|
|
|
7
13
|
```js
|
|
@@ -23,8 +23,6 @@ To allow Bun to execute lifecycle scripts for a specific package, add the packag
|
|
|
23
23
|
Note that this only allows lifecycle scripts for the specific package listed in `trustedDependencies`, _not_ the dependencies of that dependency!
|
|
24
24
|
{% /callout %}
|
|
25
25
|
|
|
26
|
-
<!-- Bun maintains an allow-list of popular packages containing `postinstall` scripts that are known to be safe. To run lifecycle scripts for packages that aren't on this list, add the package to `trustedDependencies` in your package.json. -->
|
|
27
|
-
|
|
28
26
|
```json-diff
|
|
29
27
|
{
|
|
30
28
|
"name": "my-app",
|
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
name: Generate a human-readable lockfile
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
{% callout %}
|
|
6
|
+
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. [**Learn more.**](https://bun.sh/docs/install/lockfile#text-based-lockfile)
|
|
7
|
+
{% /callout %}
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
5
11
|
By default Bun generates a binary `bun.lockb` file when you run `bun install`. In some cases, it's preferable to generate a human-readable lockfile instead.
|
|
6
12
|
|
|
7
13
|
---
|
|
@@ -4,9 +4,9 @@ name: Define and replace static globals & constants
|
|
|
4
4
|
|
|
5
5
|
The `--define` flag lets you declare statically-analyzable constants and globals. It replace all usages of an identifier or property in a JavaScript or TypeScript file with a constant value. This feature is supported at runtime and also in `bun build`. This is sort of similar to `#define` in C/C++, except for JavaScript.
|
|
6
6
|
|
|
7
|
-
```
|
|
8
|
-
bun --define process.env.NODE_ENV="'production'" src/index.ts # Runtime
|
|
9
|
-
bun build --define process.env.NODE_ENV="'production'" src/index.ts # Build
|
|
7
|
+
```sh
|
|
8
|
+
$ bun --define process.env.NODE_ENV="'production'" src/index.ts # Runtime
|
|
9
|
+
$ bun build --define process.env.NODE_ENV="'production'" src/index.ts # Build
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
---
|
|
@@ -25,12 +25,12 @@ if (process.env.NODE_ENV === "production") {
|
|
|
25
25
|
|
|
26
26
|
Before the code reaches the JavaScript engine, Bun replaces `process.env.NODE_ENV` with `"production"`.
|
|
27
27
|
|
|
28
|
-
```ts
|
|
29
|
-
if ("production" === "production") {
|
|
30
|
-
|
|
31
|
-
} else {
|
|
32
|
-
|
|
33
|
-
}
|
|
28
|
+
```ts-diff
|
|
29
|
+
+ if ("production" === "production") {
|
|
30
|
+
console.log("Production mode");
|
|
31
|
+
} else {
|
|
32
|
+
console.log("Development mode");
|
|
33
|
+
}
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
---
|
|
@@ -39,12 +39,12 @@ It doesn't stop there. Bun's optimizing transpiler is smart enough to do some ba
|
|
|
39
39
|
|
|
40
40
|
Since `"production" === "production"` is always `true`, Bun replaces the entire expression with the `true` value.
|
|
41
41
|
|
|
42
|
-
```ts
|
|
43
|
-
if (true) {
|
|
44
|
-
|
|
45
|
-
} else {
|
|
46
|
-
|
|
47
|
-
}
|
|
42
|
+
```ts-diff
|
|
43
|
+
+ if (true) {
|
|
44
|
+
console.log("Production mode");
|
|
45
|
+
} else {
|
|
46
|
+
console.log("Development mode");
|
|
47
|
+
}
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
---
|
|
@@ -2,22 +2,15 @@
|
|
|
2
2
|
name: Delete a file
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The `Bun.file()` function accepts a path and returns a `BunFile` instance. Use the `.delete()` method to delete the file.
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
|
-
import { unlinkSync } from "node:fs";
|
|
9
|
-
|
|
10
8
|
const path = "/path/to/file.txt";
|
|
11
|
-
|
|
9
|
+
const file = Bun.file(path);
|
|
10
|
+
|
|
11
|
+
await file.delete();
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
```ts
|
|
19
|
-
import { unlink } from "node:fs/promises";
|
|
20
|
-
|
|
21
|
-
const path = "/path/to/file.txt";
|
|
22
|
-
await unlink(path);
|
|
23
|
-
```
|
|
16
|
+
See [Docs > API > File I/O](https://bun.sh/docs/api/file-io#reading-files-bun-file) for complete documentation of `Bun.file()`.
|
package/docs/install/cache.md
CHANGED
|
@@ -15,6 +15,8 @@ disable = false
|
|
|
15
15
|
disableManifest = false
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
{% /details %}
|
|
19
|
+
|
|
18
20
|
## Minimizing re-downloads
|
|
19
21
|
|
|
20
22
|
Bun strives to avoid re-downloading packages multiple times. When installing a package, if the cache already contains a version in the range specified by `package.json`, Bun will use the cached package instead of downloading it again.
|
|
@@ -33,14 +35,14 @@ Once a package is downloaded into the cache, Bun still needs to copy those files
|
|
|
33
35
|
|
|
34
36
|
## Saving disk space
|
|
35
37
|
|
|
36
|
-
Since Bun uses hardlinks to "copy" a module into a project's `node_modules` directory on Linux, the contents of the package only exist in a single location on disk, greatly reducing the amount of disk space dedicated to `node_modules`.
|
|
38
|
+
Since Bun uses hardlinks to "copy" a module into a project's `node_modules` directory on Linux and Windows, the contents of the package only exist in a single location on disk, greatly reducing the amount of disk space dedicated to `node_modules`.
|
|
37
39
|
|
|
38
40
|
This benefit also applies to macOS, but there are exceptions. It uses `clonefile` which is copy-on-write, meaning it will not occupy disk space, but it will count towards drive's limit. This behavior is useful if something attempts to patch `node_modules/*`, so it's impossible to affect other installations.
|
|
39
41
|
|
|
40
42
|
{% details summary="Installation strategies" %}
|
|
41
43
|
This behavior is configurable with the `--backend` flag, which is respected by all of Bun's package management commands.
|
|
42
44
|
|
|
43
|
-
- **`hardlink`**: Default on Linux.
|
|
45
|
+
- **`hardlink`**: Default on Linux and Windows.
|
|
44
46
|
- **`clonefile`** Default on macOS.
|
|
45
47
|
- **`clonefile_each_dir`**: Similar to `clonefile`, except it clones each file individually per directory. It is only available on macOS and tends to perform slower than `clonefile`.
|
|
46
48
|
- **`copyfile`**: The fallback used when any of the above fail. It is the slowest option. On macOS, it uses `fcopyfile()`; on Linux it uses `copy_file_range()`.
|
package/docs/install/lockfile.md
CHANGED
package/docs/runtime/env.md
CHANGED
|
@@ -30,9 +30,9 @@ process.env.FOO = "hello";
|
|
|
30
30
|
Bun supports `--env-file` to override which specific `.env` file to load. You can use `--env-file` when running scripts in bun's runtime, or when running package.json scripts.
|
|
31
31
|
|
|
32
32
|
```sh
|
|
33
|
-
bun --env-file=.env.1 src/index.ts
|
|
33
|
+
$ bun --env-file=.env.1 src/index.ts
|
|
34
34
|
|
|
35
|
-
bun --env-file=.env.abc --env-file=.env.def run build
|
|
35
|
+
$ bun --env-file=.env.abc --env-file=.env.def run build
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
### Quotation marks
|
package/html-rewriter.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ declare namespace HTMLRewriterTypes {
|
|
|
50
50
|
|
|
51
51
|
interface Element {
|
|
52
52
|
tagName: string;
|
|
53
|
-
readonly attributes: IterableIterator<string
|
|
53
|
+
readonly attributes: IterableIterator<[string, string]>;
|
|
54
54
|
readonly removed: boolean;
|
|
55
55
|
/** Whether the element is explicitly self-closing, e.g. `<foo />` */
|
|
56
56
|
readonly selfClosing: boolean;
|
package/package.json
CHANGED