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.
@@ -0,0 +1,6 @@
1
+ declare global {
2
+ interface Window {
3
+ BUN_HMR_INITED: boolean;
4
+ }
5
+ }
6
+ export {};
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
@@ -26,4 +26,8 @@ export function getBunHMRPlugin(config: BunDevServerSocketConfig) {
26
26
  },
27
27
  }
28
28
  return bunHMRPlugin;
29
+ }
30
+
31
+ export function getBunHMRFooter(config: BunDevServerSocketConfig) {
32
+ return `(${bunHotReload(config)})()`;
29
33
  }
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 { getBunHMRPlugin } from "./bunHmrPlugin";
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 ?? [], getBunHMRPlugin({ port: finalConfig.port, tls: finalConfig.tls, websocketPath: finalConfig.websocketPath })]
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.2",
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": "latest",
17
+ "@types/bun": "^1.1.11",
18
18
  "@types/ejs": "^3.1.5"
19
19
  },
20
20
  "peerDependencies": {
21
- "typescript": "^5.5.4"
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.8"
6
+ "@types/bun": "^1.1.11"
7
7
  },
8
8
  "peerDependencies": {
9
- "typescript": "^5.0.0"
9
+ "typescript": "^5.6.3"
10
10
  },
11
11
  "dependencies": {
12
- "@pnp/queryable": "^4.4.0",
13
- "@pnp/sp": "^4.4.0",
14
- "bun": "^1.1.27"
12
+ "@pnp/queryable": "^4.6.0",
13
+ "@pnp/sp": "^4.6.0",
14
+ "bun": "^1.1.31"
15
15
  }
16
16
  }
@@ -1,4 +1,4 @@
1
1
  declare module "*.svg" {
2
2
  const template: string;
3
3
  export default template;
4
- }
4
+ }
@@ -22,6 +22,7 @@
22
22
  // Some stricter flags (disabled by default)
23
23
  "noUnusedLocals": false,
24
24
  "noUnusedParameters": false,
25
- "noPropertyAccessFromIndexSignature": false
25
+ "noPropertyAccessFromIndexSignature": false,
26
+ "sourceMap": true
26
27
  }
27
28
  }
package/tsconfig.json CHANGED
@@ -23,5 +23,6 @@
23
23
  "noUnusedLocals": false,
24
24
  "noUnusedParameters": false,
25
25
  "noPropertyAccessFromIndexSignature": false
26
- }
26
+ },
27
+ "exclude": ["node_modules"]
27
28
  }
package/bun.lockb DELETED
Binary file