bun-dev-server 0.0.2 → 0.0.4
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/@types/windowExtensions.ts +6 -0
- package/bunClientHmr.ts +4 -0
- package/bunHmrPlugin.ts +4 -0
- package/index.ts +12 -4
- package/package.json +3 -3
- package/test/bun.lockb +0 -0
- package/test/bunrun.ts +3 -2
- package/test/package.json +5 -5
- package/test/src/@types/filetypes.d.ts +1 -1
- package/test/tsconfig.json +2 -1
- package/tsconfig.json +2 -1
- package/bun.lockb +0 -0
package/bunClientHmr.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type BunDevServerSocketConfig } from "./bunServeConfig";
|
|
2
2
|
|
|
3
3
|
function hotReload() {
|
|
4
|
+
if (window.BUN_HMR_INITED) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
window.BUN_HMR_INITED = true;
|
|
4
8
|
const hmrSock = new WebSocket("[REPLACE_ENDPOINT]");
|
|
5
9
|
hmrSock.addEventListener("error", (err) => {
|
|
6
10
|
console.error("HMR ERROR", err);
|
package/bunHmrPlugin.ts
CHANGED
package/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import indexTemplate from "./indexHTMLTemplate.ejs" with { type: "text" };
|
|
|
6
6
|
import { watch, readdir, exists, readFile } from "fs/promises";
|
|
7
7
|
import { type FileChangeInfo } from "fs/promises";
|
|
8
8
|
import { startTSWatcher } from "./bunTSWatcher";
|
|
9
|
-
import {
|
|
9
|
+
import { getBunHMRFooter } from "./bunHmrPlugin";
|
|
10
10
|
import { type BunDevServerConfig } from "./bunServeConfig";
|
|
11
11
|
|
|
12
12
|
|
|
@@ -32,21 +32,29 @@ export async function startBunDevServer(serverConfig: BunDevServerConfig) {
|
|
|
32
32
|
throw e;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
const buncfg = { port: finalConfig.port, tls: finalConfig.tls, websocketPath: finalConfig.websocketPath };
|
|
35
36
|
const buildCfg: Bun.BuildConfig = {
|
|
36
37
|
...serverConfig.buildConfig,
|
|
37
38
|
outdir: dst,
|
|
38
|
-
plugins: [...serverConfig.buildConfig.plugins ?? []
|
|
39
|
+
plugins: [...(serverConfig.buildConfig.plugins ?? [])],
|
|
40
|
+
footer: getBunHMRFooter(buncfg),
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
if (serverConfig.cleanServePath) {
|
|
42
44
|
await cleanDirectory(dst);
|
|
43
45
|
}
|
|
44
|
-
|
|
46
|
+
console.log("Starting Bun Dev Server on port", finalConfig.port);
|
|
45
47
|
const bunServer = Bun.serve({
|
|
46
48
|
port: finalConfig.port,
|
|
47
49
|
development: true,
|
|
48
50
|
tls: finalConfig.tls,
|
|
49
51
|
async fetch(req, server) {
|
|
52
|
+
if(req.method === "OPTIONS") {
|
|
53
|
+
const response = new Response("", { status: 200 });
|
|
54
|
+
response.headers.set("Access-Control-Allow-Origin", "*");
|
|
55
|
+
response.headers.set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
|
56
|
+
return response;
|
|
57
|
+
}
|
|
50
58
|
if (req.url.toLowerCase().endsWith("/favicon.ico")) {
|
|
51
59
|
return new Response("", { status: 404 });
|
|
52
60
|
}
|
|
@@ -122,7 +130,7 @@ export async function startBunDevServer(serverConfig: BunDevServerConfig) {
|
|
|
122
130
|
// });
|
|
123
131
|
|
|
124
132
|
if (finalConfig.enableTypeScriptWatch) {
|
|
125
|
-
if(!finalConfig.watchDir) {
|
|
133
|
+
if (!finalConfig.watchDir) {
|
|
126
134
|
throw new Error("watchDir must be set to enable TypeScript watch");
|
|
127
135
|
}
|
|
128
136
|
const watchDir = Bun.pathToFileURL(finalConfig.watchDir);
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/SPWizard01/bun-dev-server"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.4",
|
|
10
10
|
"module": "index.ts",
|
|
11
11
|
"type": "module",
|
|
12
12
|
"license": "MIT",
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
"serve": "bun --hot ./serve.ts"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@types/bun": "
|
|
17
|
+
"@types/bun": "^1.1.11",
|
|
18
18
|
"@types/ejs": "^3.1.5"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"typescript": "^5.
|
|
21
|
+
"typescript": "^5.6.3"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"ejs": "^3.1.10"
|
package/test/bun.lockb
CHANGED
|
Binary file
|
package/test/bunrun.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { startBunDevServer } from "../index"
|
|
1
|
+
import { startBunDevServer } from "../index";
|
|
2
2
|
|
|
3
3
|
startBunDevServer({
|
|
4
4
|
buildConfig: {
|
|
@@ -8,7 +8,8 @@ startBunDevServer({
|
|
|
8
8
|
naming: {
|
|
9
9
|
asset: "assets/[name]-[hash].[ext]",
|
|
10
10
|
chunk: "chunks/[name]-[hash].[ext]",
|
|
11
|
-
}
|
|
11
|
+
},
|
|
12
|
+
sourcemap: "linked"
|
|
12
13
|
},
|
|
13
14
|
cleanServePath: true,
|
|
14
15
|
port: 4567,
|
package/test/package.json
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
"module": "app.ts",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"devDependencies": {
|
|
6
|
-
"@types/bun": "^1.1.
|
|
6
|
+
"@types/bun": "^1.1.11"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
|
-
"typescript": "^5.
|
|
9
|
+
"typescript": "^5.6.3"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@pnp/queryable": "^4.
|
|
13
|
-
"@pnp/sp": "^4.
|
|
14
|
-
"bun": "^1.1.
|
|
12
|
+
"@pnp/queryable": "^4.6.0",
|
|
13
|
+
"@pnp/sp": "^4.6.0",
|
|
14
|
+
"bun": "^1.1.31"
|
|
15
15
|
}
|
|
16
16
|
}
|
package/test/tsconfig.json
CHANGED
package/tsconfig.json
CHANGED
package/bun.lockb
DELETED
|
Binary file
|