@b9g/platform-bun 0.1.6 → 0.1.8
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/package.json +3 -3
- package/src/index.d.ts +2 -1
- package/src/index.js +19 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b9g/platform-bun",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Bun platform adapter for Shovel with hot reloading and built-in TypeScript/JSX support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shovel",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"jsx"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@b9g/platform": "^0.1.
|
|
16
|
-
"@b9g/assets": "^0.1.
|
|
15
|
+
"@b9g/platform": "^0.1.10",
|
|
16
|
+
"@b9g/assets": "^0.1.13"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@b9g/libuild": "^0.1.11",
|
package/src/index.d.ts
CHANGED
|
@@ -47,8 +47,9 @@ export declare class BunPlatform extends BasePlatform {
|
|
|
47
47
|
loadServiceWorker(entrypoint: string, options?: ServiceWorkerOptions): Promise<ServiceWorkerInstance>;
|
|
48
48
|
/**
|
|
49
49
|
* Reload workers for hot reloading (called by CLI)
|
|
50
|
+
* @param entrypoint - Path to the new entrypoint (hashed filename)
|
|
50
51
|
*/
|
|
51
|
-
reloadWorkers(
|
|
52
|
+
reloadWorkers(entrypoint: string): Promise<void>;
|
|
52
53
|
/**
|
|
53
54
|
* Dispose of platform resources
|
|
54
55
|
*/
|
package/src/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
createCacheFactory
|
|
9
9
|
} from "@b9g/platform";
|
|
10
10
|
import { CustomCacheStorage } from "@b9g/cache";
|
|
11
|
+
import { InternalServerError, isHTTPError } from "@b9g/http-errors";
|
|
11
12
|
import * as Path from "path";
|
|
12
13
|
import { getLogger } from "@logtape/logtape";
|
|
13
14
|
var logger = getLogger(["platform-bun"]);
|
|
@@ -62,7 +63,18 @@ var BunPlatform = class extends BasePlatform {
|
|
|
62
63
|
port,
|
|
63
64
|
hostname,
|
|
64
65
|
async fetch(request) {
|
|
65
|
-
|
|
66
|
+
try {
|
|
67
|
+
return await handler(request);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
70
|
+
logger.error("Request error", {
|
|
71
|
+
error: err.message,
|
|
72
|
+
stack: err.stack
|
|
73
|
+
});
|
|
74
|
+
const httpError = isHTTPError(error) ? error : new InternalServerError(err.message, { cause: err });
|
|
75
|
+
const isDev = import.meta.env?.MODE !== "production";
|
|
76
|
+
return httpError.toResponse(isDev);
|
|
77
|
+
}
|
|
66
78
|
}
|
|
67
79
|
});
|
|
68
80
|
return {
|
|
@@ -116,8 +128,7 @@ var BunPlatform = class extends BasePlatform {
|
|
|
116
128
|
config: this.#config
|
|
117
129
|
});
|
|
118
130
|
await this.#singleThreadedRuntime.init();
|
|
119
|
-
|
|
120
|
-
await this.#singleThreadedRuntime.loadEntrypoint(entryPath, version);
|
|
131
|
+
await this.#singleThreadedRuntime.loadEntrypoint(entryPath);
|
|
121
132
|
const runtime = this.#singleThreadedRuntime;
|
|
122
133
|
const platform = this;
|
|
123
134
|
const instance = {
|
|
@@ -178,8 +189,7 @@ var BunPlatform = class extends BasePlatform {
|
|
|
178
189
|
this.#config
|
|
179
190
|
);
|
|
180
191
|
await this.#workerPool.init();
|
|
181
|
-
|
|
182
|
-
await this.#workerPool.reloadWorkers(version);
|
|
192
|
+
await this.#workerPool.reloadWorkers(entryPath);
|
|
183
193
|
const workerPool = this.#workerPool;
|
|
184
194
|
const platform = this;
|
|
185
195
|
const instance = {
|
|
@@ -214,12 +224,13 @@ var BunPlatform = class extends BasePlatform {
|
|
|
214
224
|
}
|
|
215
225
|
/**
|
|
216
226
|
* Reload workers for hot reloading (called by CLI)
|
|
227
|
+
* @param entrypoint - Path to the new entrypoint (hashed filename)
|
|
217
228
|
*/
|
|
218
|
-
async reloadWorkers(
|
|
229
|
+
async reloadWorkers(entrypoint) {
|
|
219
230
|
if (this.#workerPool) {
|
|
220
|
-
await this.#workerPool.reloadWorkers(
|
|
231
|
+
await this.#workerPool.reloadWorkers(entrypoint);
|
|
221
232
|
} else if (this.#singleThreadedRuntime) {
|
|
222
|
-
await this.#singleThreadedRuntime.reloadWorkers(
|
|
233
|
+
await this.#singleThreadedRuntime.reloadWorkers(entrypoint);
|
|
223
234
|
}
|
|
224
235
|
}
|
|
225
236
|
/**
|