@b9g/platform-bun 0.1.0 → 0.1.2
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 +4 -4
- package/src/platform.d.ts +2 -7
- package/src/platform.js +37 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b9g/platform-bun",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Bun platform adapter for Shovel with hot reloading and built-in TypeScript/JSX support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shovel",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"jsx"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@b9g/platform": "
|
|
16
|
-
"@b9g/cache": "
|
|
17
|
-
"@b9g/assets": "
|
|
15
|
+
"@b9g/platform": "^0.1.1",
|
|
16
|
+
"@b9g/cache": "^0.1.1",
|
|
17
|
+
"@b9g/assets": "^0.1.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@b9g/libuild": "^0.1.10",
|
package/src/platform.d.ts
CHANGED
|
@@ -23,18 +23,17 @@ export interface BunPlatformOptions extends PlatformConfig {
|
|
|
23
23
|
export declare class BunPlatform extends BasePlatform {
|
|
24
24
|
readonly name = "bun";
|
|
25
25
|
private options;
|
|
26
|
-
private _dist?;
|
|
27
26
|
constructor(options?: BunPlatformOptions);
|
|
28
27
|
/**
|
|
29
28
|
* Build artifacts filesystem (install-time only)
|
|
30
29
|
*/
|
|
31
|
-
|
|
30
|
+
getDirectoryHandle(name: string): Promise<FileSystemDirectoryHandle>;
|
|
32
31
|
/**
|
|
33
32
|
* Get platform-specific default cache configuration for Bun
|
|
34
33
|
*/
|
|
35
34
|
protected getDefaultCacheConfig(): CacheConfig;
|
|
36
35
|
/**
|
|
37
|
-
* Override cache creation to use
|
|
36
|
+
* Override cache creation to use appropriate cache type for Bun
|
|
38
37
|
*/
|
|
39
38
|
createCaches(config?: CacheConfig): Promise<CustomCacheStorage>;
|
|
40
39
|
/**
|
|
@@ -45,10 +44,6 @@ export declare class BunPlatform extends BasePlatform {
|
|
|
45
44
|
* Load and run a ServiceWorker-style entrypoint with Bun
|
|
46
45
|
*/
|
|
47
46
|
loadServiceWorker(entrypoint: string, options?: ServiceWorkerOptions): Promise<ServiceWorkerInstance>;
|
|
48
|
-
/**
|
|
49
|
-
* Get filesystem root for File System Access API
|
|
50
|
-
*/
|
|
51
|
-
getFileSystemRoot(name?: string): Promise<FileSystemDirectoryHandle>;
|
|
52
47
|
/**
|
|
53
48
|
* Dispose of platform resources
|
|
54
49
|
*/
|
package/src/platform.js
CHANGED
|
@@ -4,15 +4,14 @@ import {
|
|
|
4
4
|
BasePlatform,
|
|
5
5
|
ServiceWorkerRuntime,
|
|
6
6
|
createServiceWorkerGlobals,
|
|
7
|
-
|
|
7
|
+
createBucketStorage
|
|
8
8
|
} from "@b9g/platform";
|
|
9
9
|
import { CustomCacheStorage, PostMessageCache } from "@b9g/cache";
|
|
10
|
-
import { FileSystemRegistry,
|
|
10
|
+
import { FileSystemRegistry, MemoryBucket, LocalBucket } from "@b9g/filesystem";
|
|
11
11
|
import * as Path from "path";
|
|
12
12
|
var BunPlatform = class extends BasePlatform {
|
|
13
13
|
name = "bun";
|
|
14
14
|
options;
|
|
15
|
-
_dist;
|
|
16
15
|
constructor(options = {}) {
|
|
17
16
|
super(options);
|
|
18
17
|
this.options = {
|
|
@@ -22,8 +21,8 @@ var BunPlatform = class extends BasePlatform {
|
|
|
22
21
|
cwd: process.cwd(),
|
|
23
22
|
...options
|
|
24
23
|
};
|
|
25
|
-
FileSystemRegistry.register("memory", new
|
|
26
|
-
FileSystemRegistry.register("node", new
|
|
24
|
+
FileSystemRegistry.register("memory", new MemoryBucket());
|
|
25
|
+
FileSystemRegistry.register("node", new LocalBucket({
|
|
27
26
|
rootPath: Path.join(this.options.cwd, "dist")
|
|
28
27
|
}));
|
|
29
28
|
try {
|
|
@@ -38,12 +37,10 @@ var BunPlatform = class extends BasePlatform {
|
|
|
38
37
|
/**
|
|
39
38
|
* Build artifacts filesystem (install-time only)
|
|
40
39
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
return this._dist;
|
|
40
|
+
async getDirectoryHandle(name) {
|
|
41
|
+
const distPath = Path.resolve(this.options.cwd, "dist");
|
|
42
|
+
const adapter = new LocalBucket({ rootPath: distPath });
|
|
43
|
+
return await adapter.getDirectoryHandle(name);
|
|
47
44
|
}
|
|
48
45
|
/**
|
|
49
46
|
* Get platform-specific default cache configuration for Bun
|
|
@@ -57,15 +54,25 @@ var BunPlatform = class extends BasePlatform {
|
|
|
57
54
|
};
|
|
58
55
|
}
|
|
59
56
|
/**
|
|
60
|
-
* Override cache creation to use
|
|
57
|
+
* Override cache creation to use appropriate cache type for Bun
|
|
61
58
|
*/
|
|
62
59
|
async createCaches(config) {
|
|
60
|
+
const { MemoryCache } = await import("@b9g/cache");
|
|
61
|
+
const { isMainThread } = await import("worker_threads");
|
|
63
62
|
return new CustomCacheStorage((name) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
if (isMainThread) {
|
|
64
|
+
return new MemoryCache(name, {
|
|
65
|
+
maxEntries: 1e3,
|
|
66
|
+
maxSize: 50 * 1024 * 1024
|
|
67
|
+
// 50MB
|
|
68
|
+
});
|
|
69
|
+
} else {
|
|
70
|
+
return new PostMessageCache(name, {
|
|
71
|
+
maxEntries: 1e3,
|
|
72
|
+
maxSize: 50 * 1024 * 1024
|
|
73
|
+
// 50MB
|
|
74
|
+
});
|
|
75
|
+
}
|
|
69
76
|
});
|
|
70
77
|
}
|
|
71
78
|
/**
|
|
@@ -83,15 +90,19 @@ var BunPlatform = class extends BasePlatform {
|
|
|
83
90
|
development: this.options.hotReload
|
|
84
91
|
});
|
|
85
92
|
return {
|
|
86
|
-
listen
|
|
93
|
+
async listen() {
|
|
87
94
|
console.info(`\u{1F956} Bun server running at http://${hostname}:${port}`);
|
|
88
|
-
return Promise.resolve();
|
|
89
95
|
},
|
|
90
|
-
close
|
|
96
|
+
async close() {
|
|
91
97
|
server.stop();
|
|
92
|
-
return Promise.resolve();
|
|
93
98
|
},
|
|
94
|
-
address: () => ({ port, host: hostname })
|
|
99
|
+
address: () => ({ port, host: hostname }),
|
|
100
|
+
get url() {
|
|
101
|
+
return `http://${hostname}:${port}`;
|
|
102
|
+
},
|
|
103
|
+
get ready() {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
95
106
|
};
|
|
96
107
|
}
|
|
97
108
|
/**
|
|
@@ -101,7 +112,8 @@ var BunPlatform = class extends BasePlatform {
|
|
|
101
112
|
const runtime = new ServiceWorkerRuntime();
|
|
102
113
|
const entryPath = Path.resolve(this.options.cwd, entrypoint);
|
|
103
114
|
const caches = await this.createCaches(options.caches);
|
|
104
|
-
const
|
|
115
|
+
const distPath = Path.resolve(this.options.cwd, "dist");
|
|
116
|
+
const buckets = createBucketStorage(distPath);
|
|
105
117
|
const instance = {
|
|
106
118
|
runtime,
|
|
107
119
|
handleRequest: (request) => runtime.handleRequest(request),
|
|
@@ -120,7 +132,7 @@ var BunPlatform = class extends BasePlatform {
|
|
|
120
132
|
const loadModule = async () => {
|
|
121
133
|
try {
|
|
122
134
|
runtime.reset();
|
|
123
|
-
createServiceWorkerGlobals(runtime, { caches,
|
|
135
|
+
createServiceWorkerGlobals(runtime, { caches, buckets });
|
|
124
136
|
globalThis.self = runtime;
|
|
125
137
|
globalThis.addEventListener = runtime.addEventListener.bind(runtime);
|
|
126
138
|
globalThis.removeEventListener = runtime.removeEventListener.bind(runtime);
|
|
@@ -136,7 +148,7 @@ var BunPlatform = class extends BasePlatform {
|
|
|
136
148
|
};
|
|
137
149
|
await loadModule();
|
|
138
150
|
} else {
|
|
139
|
-
createServiceWorkerGlobals(runtime, { caches,
|
|
151
|
+
createServiceWorkerGlobals(runtime, { caches, buckets });
|
|
140
152
|
globalThis.self = runtime;
|
|
141
153
|
globalThis.addEventListener = runtime.addEventListener.bind(runtime);
|
|
142
154
|
globalThis.removeEventListener = runtime.removeEventListener.bind(runtime);
|
|
@@ -147,12 +159,6 @@ var BunPlatform = class extends BasePlatform {
|
|
|
147
159
|
}
|
|
148
160
|
return instance;
|
|
149
161
|
}
|
|
150
|
-
/**
|
|
151
|
-
* Get filesystem root for File System Access API
|
|
152
|
-
*/
|
|
153
|
-
async getFileSystemRoot(name = "default") {
|
|
154
|
-
return await getFileSystemRoot(name);
|
|
155
|
-
}
|
|
156
162
|
/**
|
|
157
163
|
* Dispose of platform resources
|
|
158
164
|
*/
|