bun-types 1.2.5-canary.20250306T140602 → 1.2.5-canary.20250308T140614

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/devserver.d.ts CHANGED
@@ -3,22 +3,134 @@ export {};
3
3
  declare global {
4
4
  interface ImportMeta {
5
5
  /**
6
- * Hot module replacement
6
+ * Hot module replacement APIs. This value is `undefined` in production and
7
+ * can be used in an `if` statement to check if HMR APIs are available
7
8
  *
8
- * https://bun.sh/docs/bundler/fullstack
9
+ * ```ts
10
+ * if (import.meta.hot) {
11
+ * // HMR APIs are available
12
+ * }
13
+ * ```
14
+ *
15
+ * However, this check is usually not needed as Bun will dead-code-eliminate
16
+ * calls to all of the HMR APIs in production builds.
17
+ *
18
+ * https://bun.sh/docs/bundler/hmr
9
19
  */
10
20
  hot: {
11
21
  /**
12
- * import.meta.hot.data maintains state between module instances during hot replacement, enabling data transfer from previous to new versions.
22
+ * `import.meta.hot.data` maintains state between module instances during
23
+ * hot replacement, enabling data transfer from previous to new versions.
24
+ * When `import.meta.hot.data` is written to, Bun will mark this module as
25
+ * capable of self-accepting (equivalent of calling `accept()`).
13
26
  *
14
27
  * @example
15
28
  * ```ts
16
- * import.meta.hot.data = {
17
- * bun: 'is cool',
18
- * };
29
+ * const root = import.meta.hot.data.root ??= createRoot(elem);
30
+ * root.render(<App />); // re-use an existing root
19
31
  * ```
32
+ *
33
+ * In production, `data` is inlined to be `{}`. This is handy because Bun
34
+ * knows it can minify `{}.prop ??= value` into `value` in production.
35
+ *
36
+ *
20
37
  */
21
38
  data: any;
39
+
40
+ /**
41
+ * Indicate that this module can be replaced simply by re-evaluating the
42
+ * file. After a hot update, importers of this module will be
43
+ * automatically patched.
44
+ *
45
+ * When `import.meta.hot.accept` is not used, the page will reload when
46
+ * the file updates, and a console message shows which files were checked.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * import { getCount } from "./foo";
51
+ *
52
+ * console.log("count is ", getCount());
53
+ *
54
+ * import.meta.hot.accept();
55
+ * ```
56
+ */
57
+ accept(): void;
58
+
59
+ /**
60
+ * Indicate that this module can be replaced by evaluating the new module,
61
+ * and then calling the callback with the new module. In this mode, the
62
+ * importers do not get patched. This is to match Vite, which is unable
63
+ * to patch their import statements. Prefer using `import.meta.hot.accept()`
64
+ * without an argument as it usually makes your code easier to understand.
65
+ *
66
+ * When `import.meta.hot.accept` is not used, the page will reload when
67
+ * the file updates, and a console message shows which files were checked.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * export const count = 0;
72
+ *
73
+ * import.meta.hot.accept((newModule) => {
74
+ * if (newModule) {
75
+ * // newModule is undefined when SyntaxError happened
76
+ * console.log('updated: count is now ', newModule.count)
77
+ * }
78
+ * });
79
+ * ```
80
+ *
81
+ * In production, calls to this are dead-code-eliminated.
82
+ */
83
+ accept(cb: (newModule: any | undefined) => void): void;
84
+
85
+ /**
86
+ * Indicate that a dependency's module can be accepted. When the dependency
87
+ * is updated, the callback will be called with the new module.
88
+ *
89
+ * When `import.meta.hot.accept` is not used, the page will reload when
90
+ * the file updates, and a console message shows which files were checked.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * import.meta.hot.accept('./foo', (newModule) => {
95
+ * if (newModule) {
96
+ * // newModule is undefined when SyntaxError happened
97
+ * console.log('updated: count is now ', newModule.count)
98
+ * }
99
+ * });
100
+ * ```
101
+ */
102
+ accept(specifier: string, callback: (newModule: any) => void): void;
103
+
104
+ /**
105
+ * Indicate that a dependency's module can be accepted. This variant
106
+ * accepts an array of dependencies, where the callback will receive
107
+ * the one updated module, and `undefined` for the rest.
108
+ *
109
+ * When `import.meta.hot.accept` is not used, the page will reload when
110
+ * the file updates, and a console message shows which files were checked.
111
+ */
112
+ accept(
113
+ specifiers: string[],
114
+ callback: (newModules: (any | undefined)[]) => void,
115
+ ): void;
116
+
117
+ /**
118
+ * Attach an on-dispose callback. This is called:
119
+ * - Just before the module is replaced with another copy (before the next is loaded)
120
+ * - After the module is detached (removing all imports to this module)
121
+ *
122
+ * This callback is not called on route navigation or when the browser tab closes.
123
+ *
124
+ * Returning a promise will delay module replacement until the module is
125
+ * disposed. All dispose callbacks are called in parallel.
126
+ */
127
+ dispose(cb: (data: any) => void | Promise<void>): void;
128
+
129
+ /**
130
+ * No-op
131
+ * @deprecated
132
+ */
133
+ decline(): void;
22
134
  };
23
135
  }
24
136
  }
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.5-canary.20250306T140602
340
+ [fetch] > User-Agent: Bun/1.2.5-canary.20250308T140614
341
341
  [fetch] > Accept: */*
342
342
  [fetch] > Host: example.com
343
343
  [fetch] > Accept-Encoding: gzip, deflate, br
package/docs/api/spawn.md CHANGED
@@ -110,7 +110,7 @@ You can read results from the subprocess via the `stdout` and `stderr` propertie
110
110
  ```ts
111
111
  const proc = Bun.spawn(["bun", "--version"]);
112
112
  const text = await new Response(proc.stdout).text();
113
- console.log(text); // => "1.2.5-canary.20250306T140602"
113
+ console.log(text); // => "1.2.5-canary.20250308T140614"
114
114
  ```
115
115
 
116
116
  Configure the output stream by passing one of the following values to `stdout/stderr`: