bun-types 1.2.18-canary.20250702T140635 → 1.2.18
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 +51 -0
- package/docs/api/fetch.md +1 -1
- package/docs/api/spawn.md +1 -1
- package/docs/cli/pm.md +41 -0
- package/docs/cli/publish.md +1 -1
- package/docs/guides/ecosystem/nuxt.md +1 -1
- package/docs/guides/install/add-peer.md +2 -2
- package/docs/guides/install/from-npm-install-to-bun-install.md +1 -1
- package/docs/guides/test/run-tests.md +3 -3
- package/docs/guides/test/snapshot.md +3 -3
- package/docs/guides/test/update-snapshots.md +1 -1
- package/docs/guides/util/version.md +1 -1
- package/docs/installation.md +4 -4
- package/docs/runtime/debugger.md +3 -3
- package/docs/test/dom.md +1 -1
- package/experimental.d.ts +276 -0
- package/index.d.ts +1 -0
- package/package.json +5 -1
package/bun.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ declare module "bun" {
|
|
|
45
45
|
type DOMHighResTimeStamp = number;
|
|
46
46
|
type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
|
|
47
47
|
type BlobOrStringOrBuffer = string | NodeJS.TypedArray | ArrayBufferLike | Blob;
|
|
48
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
48
49
|
|
|
49
50
|
namespace __internal {
|
|
50
51
|
type LibDomIsLoaded = typeof globalThis extends { onabort: any } ? true : false;
|
|
@@ -7716,6 +7717,56 @@ declare module "bun" {
|
|
|
7716
7717
|
timestamp?: number | Date,
|
|
7717
7718
|
): Buffer;
|
|
7718
7719
|
|
|
7720
|
+
/**
|
|
7721
|
+
* Generate a UUIDv5, which is a name-based UUID based on the SHA-1 hash of a namespace UUID and a name.
|
|
7722
|
+
*
|
|
7723
|
+
* @param name The name to use for the UUID
|
|
7724
|
+
* @param namespace The namespace to use for the UUID
|
|
7725
|
+
* @param encoding The encoding to use for the UUID
|
|
7726
|
+
*
|
|
7727
|
+
*
|
|
7728
|
+
* @example
|
|
7729
|
+
* ```js
|
|
7730
|
+
* import { randomUUIDv5 } from "bun";
|
|
7731
|
+
* const uuid = randomUUIDv5("www.example.com", "dns");
|
|
7732
|
+
* console.log(uuid); // "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
|
|
7733
|
+
* ```
|
|
7734
|
+
*
|
|
7735
|
+
* ```js
|
|
7736
|
+
* import { randomUUIDv5 } from "bun";
|
|
7737
|
+
* const uuid = randomUUIDv5("www.example.com", "url");
|
|
7738
|
+
* console.log(uuid); // "6ba7b811-9dad-11d1-80b4-00c04fd430c8"
|
|
7739
|
+
* ```
|
|
7740
|
+
*/
|
|
7741
|
+
function randomUUIDv5(
|
|
7742
|
+
name: string | BufferSource,
|
|
7743
|
+
namespace: string | BufferSource | "dns" | "url" | "oid" | "x500",
|
|
7744
|
+
/**
|
|
7745
|
+
* @default "hex"
|
|
7746
|
+
*/
|
|
7747
|
+
encoding?: "hex" | "base64" | "base64url",
|
|
7748
|
+
): string;
|
|
7749
|
+
|
|
7750
|
+
/**
|
|
7751
|
+
* Generate a UUIDv5 as a Buffer
|
|
7752
|
+
*
|
|
7753
|
+
* @param name The name to use for the UUID
|
|
7754
|
+
* @param namespace The namespace to use for the UUID
|
|
7755
|
+
* @param encoding The encoding to use for the UUID
|
|
7756
|
+
*
|
|
7757
|
+
* @example
|
|
7758
|
+
* ```js
|
|
7759
|
+
* import { randomUUIDv5 } from "bun";
|
|
7760
|
+
* const uuid = randomUUIDv5("www.example.com", "url", "buffer");
|
|
7761
|
+
* console.log(uuid); // <Buffer 6b a7 b8 11 9d ad 11 d1 80 b4 00 c0 4f d4 30 c8>
|
|
7762
|
+
* ```
|
|
7763
|
+
*/
|
|
7764
|
+
function randomUUIDv5(
|
|
7765
|
+
name: string | BufferSource,
|
|
7766
|
+
namespace: string | BufferSource | "dns" | "url" | "oid" | "x500",
|
|
7767
|
+
encoding: "buffer",
|
|
7768
|
+
): Buffer;
|
|
7769
|
+
|
|
7719
7770
|
/**
|
|
7720
7771
|
* Types for `bun.lock`
|
|
7721
7772
|
*/
|
package/docs/api/fetch.md
CHANGED
|
@@ -337,7 +337,7 @@ This will print the request and response headers to your terminal:
|
|
|
337
337
|
```sh
|
|
338
338
|
[fetch] > HTTP/1.1 GET http://example.com/
|
|
339
339
|
[fetch] > Connection: keep-alive
|
|
340
|
-
[fetch] > User-Agent: Bun/1.2.18
|
|
340
|
+
[fetch] > User-Agent: Bun/1.2.18
|
|
341
341
|
[fetch] > Accept: */*
|
|
342
342
|
[fetch] > Host: example.com
|
|
343
343
|
[fetch] > Accept-Encoding: gzip, deflate, br
|
package/docs/api/spawn.md
CHANGED
|
@@ -140,7 +140,7 @@ You can read results from the subprocess via the `stdout` and `stderr` propertie
|
|
|
140
140
|
```ts
|
|
141
141
|
const proc = Bun.spawn(["bun", "--version"]);
|
|
142
142
|
const text = await proc.stdout.text();
|
|
143
|
-
console.log(text); // => "1.2.18
|
|
143
|
+
console.log(text); // => "1.2.18\n"
|
|
144
144
|
```
|
|
145
145
|
|
|
146
146
|
Configure the output stream by passing one of the following values to `stdout/stderr`:
|
package/docs/cli/pm.md
CHANGED
|
@@ -151,3 +151,44 @@ $ bun pm default-trusted
|
|
|
151
151
|
```
|
|
152
152
|
|
|
153
153
|
see the current list on GitHub [here](https://github.com/oven-sh/bun/blob/main/src/install/default-trusted-dependencies.txt)
|
|
154
|
+
|
|
155
|
+
## version
|
|
156
|
+
|
|
157
|
+
To display current package version and help:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
$ bun pm version
|
|
161
|
+
bun pm version v1.2.18 (ca7428e9)
|
|
162
|
+
Current package version: v1.0.0
|
|
163
|
+
|
|
164
|
+
Increment:
|
|
165
|
+
patch 1.0.0 → 1.0.1
|
|
166
|
+
minor 1.0.0 → 1.1.0
|
|
167
|
+
major 1.0.0 → 2.0.0
|
|
168
|
+
prerelease 1.0.0 → 1.0.1-0
|
|
169
|
+
prepatch 1.0.0 → 1.0.1-0
|
|
170
|
+
preminor 1.0.0 → 1.1.0-0
|
|
171
|
+
premajor 1.0.0 → 2.0.0-0
|
|
172
|
+
from-git Use version from latest git tag
|
|
173
|
+
1.2.3 Set specific version
|
|
174
|
+
|
|
175
|
+
Options:
|
|
176
|
+
--no-git-tag-version Skip git operations
|
|
177
|
+
--allow-same-version Prevents throwing error if version is the same
|
|
178
|
+
--message=<val>, -m Custom commit message
|
|
179
|
+
--preid=<val> Prerelease identifier
|
|
180
|
+
|
|
181
|
+
Examples:
|
|
182
|
+
$ bun pm version patch
|
|
183
|
+
$ bun pm version 1.2.3 --no-git-tag-version
|
|
184
|
+
$ bun pm version prerelease --preid beta
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
To bump the version in `package.json`:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
$ bun pm version patch
|
|
191
|
+
v1.0.1
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Supports `patch`, `minor`, `major`, `premajor`, `preminor`, `prepatch`, `prerelease`, `from-git`, or specific versions like `1.2.3`. By default creates git commit and tag unless `--no-git-tag-version` was used to skip.
|
package/docs/cli/publish.md
CHANGED
|
@@ -9,7 +9,7 @@ $ bunx nuxi init my-nuxt-app
|
|
|
9
9
|
✔ Which package manager would you like to use?
|
|
10
10
|
bun
|
|
11
11
|
◐ Installing dependencies...
|
|
12
|
-
bun install v1.2.18
|
|
12
|
+
bun install v1.2.18 (16b4bf34)
|
|
13
13
|
+ @nuxt/devtools@0.8.2
|
|
14
14
|
+ nuxt@3.7.0
|
|
15
15
|
785 packages installed [2.67s]
|
|
@@ -15,7 +15,7 @@ This will add the package to `peerDependencies` in `package.json`.
|
|
|
15
15
|
```json-diff
|
|
16
16
|
{
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
+ "@types/bun": "^1.2.18
|
|
18
|
+
+ "@types/bun": "^1.2.18"
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
```
|
|
@@ -27,7 +27,7 @@ Running `bun install` will install peer dependencies by default, unless marked o
|
|
|
27
27
|
```json-diff
|
|
28
28
|
{
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@types/bun": "^1.2.18
|
|
30
|
+
"@types/bun": "^1.2.18"
|
|
31
31
|
},
|
|
32
32
|
"peerDependenciesMeta": {
|
|
33
33
|
+ "@types/bun": {
|
|
@@ -97,7 +97,7 @@ $ bun update
|
|
|
97
97
|
$ bun update @types/bun --latest
|
|
98
98
|
|
|
99
99
|
# Update a dependency to a specific version
|
|
100
|
-
$ bun update @types/bun@1.2.18
|
|
100
|
+
$ bun update @types/bun@1.2.18
|
|
101
101
|
|
|
102
102
|
# Update all dependencies to the latest versions
|
|
103
103
|
$ bun update --latest
|
|
@@ -21,7 +21,7 @@ Here's what the output of a typical test run looks like. In this case, there are
|
|
|
21
21
|
|
|
22
22
|
```sh
|
|
23
23
|
$ bun test
|
|
24
|
-
bun test v1.2.18
|
|
24
|
+
bun test v1.2.18 (9c68abdb)
|
|
25
25
|
|
|
26
26
|
test.test.js:
|
|
27
27
|
✓ add [0.87ms]
|
|
@@ -47,7 +47,7 @@ To only run certain test files, pass a positional argument to `bun test`. The ru
|
|
|
47
47
|
|
|
48
48
|
```sh
|
|
49
49
|
$ bun test test3
|
|
50
|
-
bun test v1.2.18
|
|
50
|
+
bun test v1.2.18 (9c68abdb)
|
|
51
51
|
|
|
52
52
|
test3.test.js:
|
|
53
53
|
✓ add [1.40ms]
|
|
@@ -85,7 +85,7 @@ Adding `-t add` will only run tests with "add" in the name. This works with test
|
|
|
85
85
|
|
|
86
86
|
```sh
|
|
87
87
|
$ bun test -t add
|
|
88
|
-
bun test v1.2.18
|
|
88
|
+
bun test v1.2.18 (9c68abdb)
|
|
89
89
|
|
|
90
90
|
test.test.js:
|
|
91
91
|
✓ add [1.79ms]
|
|
@@ -18,7 +18,7 @@ The first time this test is executed, Bun will evaluate the value passed into `e
|
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
20
|
$ bun test test/snap
|
|
21
|
-
bun test v1.2.18
|
|
21
|
+
bun test v1.2.18 (9c68abdb)
|
|
22
22
|
|
|
23
23
|
test/snap.test.ts:
|
|
24
24
|
✓ snapshot [1.48ms]
|
|
@@ -61,7 +61,7 @@ Later, when this test file is executed again, Bun will read the snapshot file an
|
|
|
61
61
|
|
|
62
62
|
```sh
|
|
63
63
|
$ bun test
|
|
64
|
-
bun test v1.2.18
|
|
64
|
+
bun test v1.2.18 (9c68abdb)
|
|
65
65
|
|
|
66
66
|
test/snap.test.ts:
|
|
67
67
|
✓ snapshot [1.05ms]
|
|
@@ -78,7 +78,7 @@ To update snapshots, use the `--update-snapshots` flag.
|
|
|
78
78
|
|
|
79
79
|
```sh
|
|
80
80
|
$ bun test --update-snapshots
|
|
81
|
-
bun test v1.2.18
|
|
81
|
+
bun test v1.2.18 (9c68abdb)
|
|
82
82
|
|
|
83
83
|
test/snap.test.ts:
|
|
84
84
|
✓ snapshot [0.86ms]
|
package/docs/installation.md
CHANGED
|
@@ -14,7 +14,7 @@ Kernel version 5.6 or higher is strongly recommended, but the minimum is 5.1. Us
|
|
|
14
14
|
```bash#macOS/Linux_(curl)
|
|
15
15
|
$ curl -fsSL https://bun.sh/install | bash # for macOS, Linux, and WSL
|
|
16
16
|
# to install a specific version
|
|
17
|
-
$ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.18
|
|
17
|
+
$ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.18"
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
```bash#npm
|
|
@@ -189,10 +189,10 @@ Since Bun is a single binary, you can install older versions of Bun by re-runnin
|
|
|
189
189
|
|
|
190
190
|
### Installing a specific version of Bun on Linux/Mac
|
|
191
191
|
|
|
192
|
-
To install a specific version of Bun, you can pass the git tag of the version you want to install to the install script, such as `bun-v1.2.0` or `bun-v1.2.18
|
|
192
|
+
To install a specific version of Bun, you can pass the git tag of the version you want to install to the install script, such as `bun-v1.2.0` or `bun-v1.2.18`.
|
|
193
193
|
|
|
194
194
|
```sh
|
|
195
|
-
$ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.18
|
|
195
|
+
$ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.18"
|
|
196
196
|
```
|
|
197
197
|
|
|
198
198
|
### Installing a specific version of Bun on Windows
|
|
@@ -201,7 +201,7 @@ On Windows, you can install a specific version of Bun by passing the version num
|
|
|
201
201
|
|
|
202
202
|
```sh
|
|
203
203
|
# PowerShell:
|
|
204
|
-
$ iex "& {$(irm https://bun.sh/install.ps1)} -Version 1.2.18
|
|
204
|
+
$ iex "& {$(irm https://bun.sh/install.ps1)} -Version 1.2.18"
|
|
205
205
|
```
|
|
206
206
|
|
|
207
207
|
## Downloading Bun binaries directly
|
package/docs/runtime/debugger.md
CHANGED
|
@@ -124,11 +124,11 @@ await fetch("https://example.com", {
|
|
|
124
124
|
This prints the `fetch` request as a single-line `curl` command to let you copy-paste into your terminal to replicate the request.
|
|
125
125
|
|
|
126
126
|
```sh
|
|
127
|
-
[fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.2.18
|
|
127
|
+
[fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.2.18" -H "Accept: */*" -H "Host: example.com" -H "Accept-Encoding: gzip, deflate, br" --compressed -H "Content-Length: 13" --data-raw "{\"foo\":\"bar\"}"
|
|
128
128
|
[fetch] > HTTP/1.1 POST https://example.com/
|
|
129
129
|
[fetch] > content-type: application/json
|
|
130
130
|
[fetch] > Connection: keep-alive
|
|
131
|
-
[fetch] > User-Agent: Bun/1.2.18
|
|
131
|
+
[fetch] > User-Agent: Bun/1.2.18
|
|
132
132
|
[fetch] > Accept: */*
|
|
133
133
|
[fetch] > Host: example.com
|
|
134
134
|
[fetch] > Accept-Encoding: gzip, deflate, br
|
|
@@ -170,7 +170,7 @@ This prints the following to the console:
|
|
|
170
170
|
[fetch] > HTTP/1.1 POST https://example.com/
|
|
171
171
|
[fetch] > content-type: application/json
|
|
172
172
|
[fetch] > Connection: keep-alive
|
|
173
|
-
[fetch] > User-Agent: Bun/1.2.18
|
|
173
|
+
[fetch] > User-Agent: Bun/1.2.18
|
|
174
174
|
[fetch] > Accept: */*
|
|
175
175
|
[fetch] > Host: example.com
|
|
176
176
|
[fetch] > Accept-Encoding: gzip, deflate, br
|
package/docs/test/dom.md
CHANGED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
declare module "bun" {
|
|
2
|
+
export namespace __experimental {
|
|
3
|
+
/**
|
|
4
|
+
* Base interface for static site generation route parameters.
|
|
5
|
+
*
|
|
6
|
+
* Supports both single string values and arrays of strings for dynamic route segments.
|
|
7
|
+
* This is typically used for route parameters like `[slug]`, `[...rest]`, or `[id]`.
|
|
8
|
+
*
|
|
9
|
+
* @warning These APIs are experimental and might be moved/changed in future releases.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* // Simple slug parameter
|
|
14
|
+
* type BlogParams = { slug: string };
|
|
15
|
+
*
|
|
16
|
+
* // Multiple parameters
|
|
17
|
+
* type ProductParams = {
|
|
18
|
+
* category: string;
|
|
19
|
+
* id: string;
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* // Catch-all routes with string arrays
|
|
23
|
+
* type DocsParams = {
|
|
24
|
+
* path: string[];
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export interface SSGParamsLike {
|
|
29
|
+
[key: string]: string | string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Configuration object for a single static route to be generated.
|
|
34
|
+
*
|
|
35
|
+
* Each path object contains the parameters needed to render a specific
|
|
36
|
+
* instance of a dynamic route at build time.
|
|
37
|
+
*
|
|
38
|
+
* @warning These APIs are experimental and might be moved/changed in future releases.
|
|
39
|
+
*
|
|
40
|
+
* @template Params - The shape of route parameters for this path
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* // Single blog post path
|
|
45
|
+
* const blogPath: SSGPath<{ slug: string }> = {
|
|
46
|
+
* params: { slug: "my-first-post" }
|
|
47
|
+
* };
|
|
48
|
+
*
|
|
49
|
+
* // Product page with multiple params
|
|
50
|
+
* const productPath: SSGPath<{ category: string; id: string }> = {
|
|
51
|
+
* params: {
|
|
52
|
+
* category: "electronics",
|
|
53
|
+
* id: "laptop-123"
|
|
54
|
+
* }
|
|
55
|
+
* };
|
|
56
|
+
*
|
|
57
|
+
* // Documentation with catch-all route
|
|
58
|
+
* const docsPath: SSGPath<{ path: string[] }> = {
|
|
59
|
+
* params: { path: ["getting-started", "installation"] }
|
|
60
|
+
* };
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export interface SSGPath<Params extends SSGParamsLike = SSGParamsLike> {
|
|
64
|
+
params: Params;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Array of static paths to be generated at build time.
|
|
69
|
+
*
|
|
70
|
+
* This type represents the collection of all route configurations
|
|
71
|
+
* that should be pre-rendered for a dynamic route.
|
|
72
|
+
*
|
|
73
|
+
* @warning These APIs are experimental and might be moved/changed in future releases.
|
|
74
|
+
*
|
|
75
|
+
* @template Params - The shape of route parameters for these paths
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```tsx
|
|
79
|
+
* // Array of blog post paths
|
|
80
|
+
* const blogPaths: SSGPaths<{ slug: string }> = [
|
|
81
|
+
* { params: { slug: "introduction-to-bun" } },
|
|
82
|
+
* { params: { slug: "performance-benchmarks" } },
|
|
83
|
+
* { params: { slug: "getting-started-guide" } }
|
|
84
|
+
* ];
|
|
85
|
+
*
|
|
86
|
+
* // Mixed parameter types
|
|
87
|
+
* const productPaths: SSGPaths<{ category: string; id: string }> = [
|
|
88
|
+
* { params: { category: "books", id: "javascript-guide" } },
|
|
89
|
+
* { params: { category: "electronics", id: "smartphone-x" } }
|
|
90
|
+
* ];
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export type SSGPaths<Params extends SSGParamsLike = SSGParamsLike> = SSGPath<Params>[];
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Props interface for SSG page components.
|
|
97
|
+
*
|
|
98
|
+
* This interface defines the shape of props that will be passed to your
|
|
99
|
+
* static page components during the build process. The `params` object
|
|
100
|
+
* contains the route parameters extracted from the URL pattern.
|
|
101
|
+
*
|
|
102
|
+
* @warning These APIs are experimental and might be moved/changed in future releases.
|
|
103
|
+
*
|
|
104
|
+
* @template Params - The shape of route parameters for this page
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```tsx
|
|
108
|
+
* // Blog post component props
|
|
109
|
+
* interface BlogPageProps extends SSGPageProps<{ slug: string }> {
|
|
110
|
+
* // params: { slug: string } is automatically included
|
|
111
|
+
* }
|
|
112
|
+
*
|
|
113
|
+
* // Product page component props
|
|
114
|
+
* interface ProductPageProps extends SSGPageProps<{
|
|
115
|
+
* category: string;
|
|
116
|
+
* id: string;
|
|
117
|
+
* }> {
|
|
118
|
+
* // params: { category: string; id: string } is automatically included
|
|
119
|
+
* }
|
|
120
|
+
*
|
|
121
|
+
* // Usage in component
|
|
122
|
+
* function BlogPost({ params }: BlogPageProps) {
|
|
123
|
+
* const { slug } = params; // TypeScript knows slug is a string
|
|
124
|
+
* return <h1>Blog post: {slug}</h1>;
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export interface SSGPageProps<Params extends SSGParamsLike = SSGParamsLike> {
|
|
129
|
+
params: Params;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* React component type for SSG pages that can be statically generated.
|
|
134
|
+
*
|
|
135
|
+
* This type represents a React component that receives SSG page props
|
|
136
|
+
* and can be rendered at build time. The component can be either a regular
|
|
137
|
+
* React component or an async React Server Component for advanced use cases
|
|
138
|
+
* like data fetching during static generation.
|
|
139
|
+
*
|
|
140
|
+
* @warning These APIs are experimental and might be moved/changed in future releases.
|
|
141
|
+
*
|
|
142
|
+
* @template Params - The shape of route parameters for this page component
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```tsx
|
|
146
|
+
* // Regular synchronous SSG page component
|
|
147
|
+
* const BlogPost: SSGPage<{ slug: string }> = ({ params }) => {
|
|
148
|
+
* return (
|
|
149
|
+
* <article>
|
|
150
|
+
* <h1>Blog Post: {params.slug}</h1>
|
|
151
|
+
* <p>This content was generated at build time!</p>
|
|
152
|
+
* </article>
|
|
153
|
+
* );
|
|
154
|
+
* };
|
|
155
|
+
*
|
|
156
|
+
* // Async React Server Component for data fetching
|
|
157
|
+
* const AsyncBlogPost: SSGPage<{ slug: string }> = async ({ params }) => {
|
|
158
|
+
* // Fetch data during static generation
|
|
159
|
+
* const post = await fetchBlogPost(params.slug);
|
|
160
|
+
* const author = await fetchAuthor(post.authorId);
|
|
161
|
+
*
|
|
162
|
+
* return (
|
|
163
|
+
* <article>
|
|
164
|
+
* <h1>{post.title}</h1>
|
|
165
|
+
* <p>By {author.name}</p>
|
|
166
|
+
* <div dangerouslySetInnerHTML={{ __html: post.content }} />
|
|
167
|
+
* </article>
|
|
168
|
+
* );
|
|
169
|
+
* };
|
|
170
|
+
*
|
|
171
|
+
* // Product page with multiple params and async data fetching
|
|
172
|
+
* const ProductPage: SSGPage<{ category: string; id: string }> = async ({ params }) => {
|
|
173
|
+
* const [product, reviews] = await Promise.all([
|
|
174
|
+
* fetchProduct(params.category, params.id),
|
|
175
|
+
* fetchProductReviews(params.id)
|
|
176
|
+
* ]);
|
|
177
|
+
*
|
|
178
|
+
* return (
|
|
179
|
+
* <div>
|
|
180
|
+
* <h1>{product.name}</h1>
|
|
181
|
+
* <p>Category: {params.category}</p>
|
|
182
|
+
* <p>Price: ${product.price}</p>
|
|
183
|
+
* <div>
|
|
184
|
+
* <h2>Reviews ({reviews.length})</h2>
|
|
185
|
+
* {reviews.map(review => (
|
|
186
|
+
* <div key={review.id}>{review.comment}</div>
|
|
187
|
+
* ))}
|
|
188
|
+
* </div>
|
|
189
|
+
* </div>
|
|
190
|
+
* );
|
|
191
|
+
* };
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export type SSGPage<Params extends SSGParamsLike = SSGParamsLike> = React.ComponentType<SSGPageProps<Params>>;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* getStaticPaths is Bun's implementation of SSG (Static Site Generation) path determination.
|
|
198
|
+
*
|
|
199
|
+
* This function is called at your app's build time to determine which
|
|
200
|
+
* dynamic routes should be pre-rendered as static pages. It returns an
|
|
201
|
+
* array of path parameters that will be used to generate static pages for
|
|
202
|
+
* dynamic routes (e.g., [slug].tsx, [category]/[id].tsx).
|
|
203
|
+
*
|
|
204
|
+
* The function can be either synchronous or asynchronous, allowing you to
|
|
205
|
+
* fetch data from APIs, databases, or file systems to determine which paths
|
|
206
|
+
* should be statically generated.
|
|
207
|
+
*
|
|
208
|
+
* @warning These APIs are experimental and might be moved/changed in future releases.
|
|
209
|
+
*
|
|
210
|
+
* @template Params - The shape of route parameters for the dynamic route
|
|
211
|
+
*
|
|
212
|
+
* @returns An object containing an array of paths to be statically generated
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```tsx
|
|
216
|
+
* // In pages/blog/[slug].tsx ———————————————————╮
|
|
217
|
+
* export const getStaticPaths: GetStaticPaths<{ slug: string }> = async () => {
|
|
218
|
+
* // Fetch all blog posts from your CMS or API at build time
|
|
219
|
+
* const posts = await fetchBlogPosts();
|
|
220
|
+
*
|
|
221
|
+
* return {
|
|
222
|
+
* paths: posts.map((post) => ({
|
|
223
|
+
* params: { slug: post.slug }
|
|
224
|
+
* }))
|
|
225
|
+
* };
|
|
226
|
+
* };
|
|
227
|
+
*
|
|
228
|
+
* // In pages/products/[category]/[id].tsx
|
|
229
|
+
* export const getStaticPaths: GetStaticPaths<{
|
|
230
|
+
* category: string;
|
|
231
|
+
* id: string;
|
|
232
|
+
* }> = async () => {
|
|
233
|
+
* // Fetch products from database
|
|
234
|
+
* const products = await db.products.findMany({
|
|
235
|
+
* select: { id: true, category: { slug: true } }
|
|
236
|
+
* });
|
|
237
|
+
*
|
|
238
|
+
* return {
|
|
239
|
+
* paths: products.map(product => ({
|
|
240
|
+
* params: {
|
|
241
|
+
* category: product.category.slug,
|
|
242
|
+
* id: product.id
|
|
243
|
+
* }
|
|
244
|
+
* }))
|
|
245
|
+
* };
|
|
246
|
+
* };
|
|
247
|
+
*
|
|
248
|
+
* // In pages/docs/[...path].tsx (catch-all route)
|
|
249
|
+
* export const getStaticPaths: GetStaticPaths<{ path: string[] }> = async () => {
|
|
250
|
+
* // Read documentation structure from file system
|
|
251
|
+
* const docPaths = await getDocumentationPaths('./content/docs');
|
|
252
|
+
*
|
|
253
|
+
* return {
|
|
254
|
+
* paths: docPaths.map(docPath => ({
|
|
255
|
+
* params: { path: docPath.split('/') }
|
|
256
|
+
* }))
|
|
257
|
+
* };
|
|
258
|
+
* };
|
|
259
|
+
*
|
|
260
|
+
* // Synchronous example with static data
|
|
261
|
+
* export const getStaticPaths: GetStaticPaths<{ id: string }> = () => {
|
|
262
|
+
* const staticIds = ['1', '2', '3', '4', '5'];
|
|
263
|
+
*
|
|
264
|
+
* return {
|
|
265
|
+
* paths: staticIds.map(id => ({
|
|
266
|
+
* params: { id }
|
|
267
|
+
* }))
|
|
268
|
+
* };
|
|
269
|
+
* };
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
export type GetStaticPaths<Params extends SSGParamsLike = SSGParamsLike> = () => MaybePromise<{
|
|
273
|
+
paths: SSGPaths<Params>;
|
|
274
|
+
}>;
|
|
275
|
+
}
|
|
276
|
+
}
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.2.18
|
|
2
|
+
"version": "1.2.18",
|
|
3
3
|
"name": "bun-types",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"types": "./index.d.ts",
|
|
@@ -20,7 +20,11 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@types/node": "*"
|
|
22
22
|
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@types/react": "^19"
|
|
25
|
+
},
|
|
23
26
|
"devDependencies": {
|
|
27
|
+
"@types/react": "^19",
|
|
24
28
|
"typescript": "^5.0.2"
|
|
25
29
|
},
|
|
26
30
|
"scripts": {
|