bun-dev-server 0.9.4 → 0.9.6
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/README.md +26 -23
- package/dist/bunServeConfig.d.ts +21 -1
- package/dist/index.js +35 -12
- package/dist/tsChecker.d.ts +4 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -51,26 +51,29 @@ bun run devserver.ts
|
|
|
51
51
|
Options that are available for configuration
|
|
52
52
|
| **Option** | **Required** | **Default** | **Description** |
|
|
53
53
|
|------------------------|--------------|--------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
54
|
-
| port
|
|
55
|
-
| buildConfig
|
|
56
|
-
| watchDir
|
|
57
|
-
| watchDelay
|
|
58
|
-
| enableTSC
|
|
59
|
-
| tscConfigPath
|
|
60
|
-
| writeManifest
|
|
61
|
-
| manifestName
|
|
62
|
-
| manifestWithHash| false
|
|
63
|
-
| hotReload
|
|
64
|
-
| reloadOnChange
|
|
65
|
-
| logRequests
|
|
66
|
-
| servePath
|
|
67
|
-
| cleanServePath
|
|
68
|
-
| serveOutputEjs
|
|
69
|
-
| serveIndexHtmlEjs
|
|
70
|
-
| createIndexHTML | false
|
|
71
|
-
| beforeBuild
|
|
72
|
-
| afterBuild
|
|
73
|
-
| tls
|
|
74
|
-
| websocketPath
|
|
75
|
-
| static
|
|
76
|
-
|
|
54
|
+
| port | true | N/A | The port to run the server on. |
|
|
55
|
+
| buildConfig | true | N/A | The build configuration to use for the server. |
|
|
56
|
+
| watchDir | true | N/A | The directory to watch for changes. |
|
|
57
|
+
| watchDelay | false | 1000 | The delay in milliseconds to wait before starting <br> a new build once a file has changed.<br> Used in debounce function, in case many changes <br>happen in file system at once. |
|
|
58
|
+
| enableTSC | false | false | Whether to enable TypeScript checking <br>it will use `tscConfigPath` in your project directory. |
|
|
59
|
+
| tscConfigPath | false | `./tsconfig.json` | The path to the TypeScript configuration file. |
|
|
60
|
+
| writeManifest | false | false | Whether to write the manifest file. |
|
|
61
|
+
| manifestName | false | `bun_server_manifest.json`| The name of the manifest file. |
|
|
62
|
+
| manifestWithHash| false | false | Whether to include the hash with the entrypoints in the manifest file. |
|
|
63
|
+
| hotReload | false | none | Where to place hot reload script. Available values: "plugin" | "footer" | "none" |
|
|
64
|
+
| reloadOnChange | false | false | Whether to reload the page when a file changes. <br> This requires property `hotReload` to be set<br> to `"plugin"` or `"footer"`. |
|
|
65
|
+
| logRequests | false | false | Whether to log HTTP requests to the console. |
|
|
66
|
+
| servePath | false | `outdir` in build config or `./dist` | The path to the directory to serve files from.<br> Takes precedence over `buildConfig.outdir`. |
|
|
67
|
+
| cleanServePath | false | false | Whether to clean the `servePath` before building a new batch. |
|
|
68
|
+
| serveOutputEjs | false | Built-in template | The EJS template used for <br> the output of the `/` path on the server. <br> When supplying your own template,<br> the properties that are provided during rendering <br>are `files` and `dirs` both are arrays. |
|
|
69
|
+
| serveIndexHtmlEjs | false | Built-in template | The EJS template used for the output of the `/index.html` path on the server. <br> When supplying your own template, <br>the property that is provided during rendering <br>is `hashedImports` that is an array of strings. |
|
|
70
|
+
| createIndexHTML | false | true | Whether to create index.html using `serveIndexHtmlEjs` template. |
|
|
71
|
+
| beforeBuild | false | undefined | Event listener to execute before Bun builds |
|
|
72
|
+
| afterBuild | false | undefined | Event listener to execute after Bun builds |
|
|
73
|
+
| tls | false | undefined | Secure options for the server. Forwards buns `TLSOptions` |
|
|
74
|
+
| websocketPath | false | `/hmr-ws` | The websocket path to use for the server. |
|
|
75
|
+
| static | false | undefined | Static bun responses, can be used for things like `/favicon.ico` etc. |
|
|
76
|
+
| waitForTSCSuccessBeforeReload | false | undefined | Whether to wait for the TypeScript check to finish before reloading the page. |
|
|
77
|
+
| broadcastBuildOutputToClient | false | `true` | Whether to broadcast the build output to the browser.
|
|
78
|
+
| broadcastBuildOutputToConsole | false | `true` | Whether to broadcast the build output to the console.
|
|
79
|
+
| broadcastTSCErrorToClient | false | undefined | Whether to broadcast the TypeScript check error to the client.
|
package/dist/bunServeConfig.d.ts
CHANGED
|
@@ -32,6 +32,11 @@ export interface BunDevServerConfig extends Partial<BunServeConfig> {
|
|
|
32
32
|
* @default false
|
|
33
33
|
*/
|
|
34
34
|
enableTSC?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Whether to broadcast the TypeScript check error to the client.
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
broadcastTSCErrorToClient?: boolean;
|
|
35
40
|
/**
|
|
36
41
|
* The path to the TypeScript configuration file.
|
|
37
42
|
* @default "./tsconfig.json".
|
|
@@ -57,6 +62,21 @@ export interface BunDevServerConfig extends Partial<BunServeConfig> {
|
|
|
57
62
|
* @default "none"
|
|
58
63
|
*/
|
|
59
64
|
hotReload?: "plugin" | "footer" | "none";
|
|
65
|
+
/**
|
|
66
|
+
* Whether to wait for the TypeScript check to finish before reloading the page.
|
|
67
|
+
* @default false
|
|
68
|
+
*/
|
|
69
|
+
waitForTSCSuccessBeforeReload?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Whether to broadcast the build output to the browser.
|
|
72
|
+
* @default true
|
|
73
|
+
*/
|
|
74
|
+
broadcastBuildOutputToClient?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Whether to broadcast the build output to the console.
|
|
77
|
+
* @default true
|
|
78
|
+
*/
|
|
79
|
+
broadcastBuildOutputToConsole?: boolean;
|
|
60
80
|
/**
|
|
61
81
|
* Whether to reload the page when a file changes.
|
|
62
82
|
* This requires property `hotReload` to be set to `"plugin"` or `"footer"`.
|
|
@@ -119,5 +139,5 @@ export interface BunServeConfig {
|
|
|
119
139
|
/**
|
|
120
140
|
* Static bun responses
|
|
121
141
|
*/
|
|
122
|
-
|
|
142
|
+
routes?: Record<`/${string}`, Response>;
|
|
123
143
|
}
|
package/dist/index.js
CHANGED
|
@@ -1006,6 +1006,9 @@ function hotReload() {
|
|
|
1006
1006
|
window.location.reload();
|
|
1007
1007
|
return;
|
|
1008
1008
|
}
|
|
1009
|
+
if (parsed?.type === "tscerror") {
|
|
1010
|
+
console.error(parsed.message);
|
|
1011
|
+
}
|
|
1009
1012
|
if (parsed?.type === "error") {
|
|
1010
1013
|
console.error(parsed.message);
|
|
1011
1014
|
let newDiv = window.document.getElementById("bun-hmr-error");
|
|
@@ -1114,20 +1117,28 @@ function writeManifest(output, outdir, withHash = false, manifestName = "bun_ser
|
|
|
1114
1117
|
// src/tsChecker.ts
|
|
1115
1118
|
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
1116
1119
|
var {$ } = globalThis.Bun;
|
|
1120
|
+
var success = {
|
|
1121
|
+
error: false,
|
|
1122
|
+
message: ""
|
|
1123
|
+
};
|
|
1117
1124
|
async function performTSC(finalConfig, importMeta) {
|
|
1118
1125
|
if (finalConfig.enableTSC) {
|
|
1119
1126
|
console.log("Performing TSC check");
|
|
1120
1127
|
const tsc = await $`tsc --noEmit --noErrorTruncation -p ${finalConfig.tscConfigPath}`.cwd(importMeta.dir).quiet().nothrow();
|
|
1121
1128
|
if (tsc.exitCode === 0) {
|
|
1122
1129
|
console.log(import_picocolors.default.bgGreen("\u2714 [SUCCESS]"), "TSC check passed");
|
|
1123
|
-
return
|
|
1130
|
+
return success;
|
|
1124
1131
|
} else {
|
|
1132
|
+
const errOutput = tsc.stdout.toString();
|
|
1125
1133
|
console.log(import_picocolors.default.bgRed("\u2718 [ERROR]"), `\r
|
|
1126
|
-
${
|
|
1127
|
-
return
|
|
1134
|
+
${errOutput}`);
|
|
1135
|
+
return {
|
|
1136
|
+
error: true,
|
|
1137
|
+
message: errOutput
|
|
1138
|
+
};
|
|
1128
1139
|
}
|
|
1129
1140
|
}
|
|
1130
|
-
return
|
|
1141
|
+
return success;
|
|
1131
1142
|
}
|
|
1132
1143
|
|
|
1133
1144
|
// src/server.ts
|
|
@@ -1140,7 +1151,9 @@ async function startBunDevServer(serverConfig, importMeta) {
|
|
|
1140
1151
|
serveOutputEjs: serveOutputTemplate_default,
|
|
1141
1152
|
serveIndexHtmlEjs: indexHTMLTemplate_default,
|
|
1142
1153
|
createIndexHTML: true,
|
|
1143
|
-
tscConfigPath: resolve(importMeta.dir, "./tsconfig.json")
|
|
1154
|
+
tscConfigPath: resolve(importMeta.dir, "./tsconfig.json"),
|
|
1155
|
+
broadcastBuildOutputToConsole: true,
|
|
1156
|
+
broadcastBuildOutputToClient: true
|
|
1144
1157
|
};
|
|
1145
1158
|
const finalConfig = { ...defaultConfig, ...serverConfig };
|
|
1146
1159
|
if (finalConfig.watchDelay) {
|
|
@@ -1195,9 +1208,9 @@ async function startBunDevServer(serverConfig, importMeta) {
|
|
|
1195
1208
|
port: finalConfig.port,
|
|
1196
1209
|
development: true,
|
|
1197
1210
|
tls: finalConfig.tls,
|
|
1198
|
-
|
|
1211
|
+
routes: {
|
|
1199
1212
|
"/favicon.ico": withCORSHeaders(new Response("", { status: 404 })),
|
|
1200
|
-
...finalConfig.
|
|
1213
|
+
...finalConfig.routes
|
|
1201
1214
|
},
|
|
1202
1215
|
async fetch(req, server) {
|
|
1203
1216
|
if (req.method === "OPTIONS") {
|
|
@@ -1244,7 +1257,7 @@ var debouncedbuildAndNotify = import_debounce.default(async (importerMeta, final
|
|
|
1244
1257
|
finalConfig.beforeBuild?.(buildEnv);
|
|
1245
1258
|
try {
|
|
1246
1259
|
const output = await Bun.build(buildCfg);
|
|
1247
|
-
publishOutputLogs(bunServer, output, event);
|
|
1260
|
+
publishOutputLogs(bunServer, output, finalConfig, event);
|
|
1248
1261
|
if (finalConfig.createIndexHTML) {
|
|
1249
1262
|
publishIndexHTML(destinationPath, finalConfig.serveIndexHtmlEjs, output, event);
|
|
1250
1263
|
}
|
|
@@ -1252,10 +1265,16 @@ var debouncedbuildAndNotify = import_debounce.default(async (importerMeta, final
|
|
|
1252
1265
|
writeManifest(output, destinationPath, finalConfig.manifestWithHash, finalConfig.manifestName);
|
|
1253
1266
|
}
|
|
1254
1267
|
finalConfig.afterBuild?.(output, buildEnv);
|
|
1268
|
+
if (finalConfig.reloadOnChange && !finalConfig.waitForTSCSuccessBeforeReload) {
|
|
1269
|
+
bunServer.publish("message", JSON.stringify({ type: "reload" }));
|
|
1270
|
+
}
|
|
1255
1271
|
const tscSuccess = await performTSC(finalConfig, importerMeta);
|
|
1256
|
-
if (finalConfig.reloadOnChange && tscSuccess) {
|
|
1272
|
+
if (finalConfig.reloadOnChange && finalConfig.waitForTSCSuccessBeforeReload && !tscSuccess.error) {
|
|
1257
1273
|
bunServer.publish("message", JSON.stringify({ type: "reload" }));
|
|
1258
1274
|
}
|
|
1275
|
+
if (tscSuccess.error && finalConfig.broadcastTSCErrorToClient) {
|
|
1276
|
+
bunServer.publish("message", JSON.stringify({ type: "tscerror", message: tscSuccess.message }));
|
|
1277
|
+
}
|
|
1259
1278
|
} catch (e) {
|
|
1260
1279
|
console.error(e);
|
|
1261
1280
|
}
|
|
@@ -1265,7 +1284,7 @@ function handleErrorResponse(req, err) {
|
|
|
1265
1284
|
console.error(msg, err);
|
|
1266
1285
|
return withCORSHeaders(new Response(msg, { status: 500 }), req);
|
|
1267
1286
|
}
|
|
1268
|
-
function publishOutputLogs(bunServer, output, event) {
|
|
1287
|
+
function publishOutputLogs(bunServer, output, config, event) {
|
|
1269
1288
|
output.logs.forEach(console.log);
|
|
1270
1289
|
bunServer.publish("message", JSON.stringify({ type: "message", message: `[Bun HMR] ${event.filename} ${event.eventType}` }));
|
|
1271
1290
|
const outTable = output.outputs.filter((o) => o.kind !== "sourcemap").map((o) => {
|
|
@@ -1277,8 +1296,12 @@ function publishOutputLogs(bunServer, output, event) {
|
|
|
1277
1296
|
size: convertBytes(o.size)
|
|
1278
1297
|
};
|
|
1279
1298
|
});
|
|
1280
|
-
|
|
1281
|
-
|
|
1299
|
+
if (config.broadcastBuildOutputToConsole) {
|
|
1300
|
+
console.table(outTable);
|
|
1301
|
+
}
|
|
1302
|
+
if (config.broadcastBuildOutputToClient) {
|
|
1303
|
+
bunServer.publish("message", JSON.stringify({ type: "output", message: outTable }));
|
|
1304
|
+
}
|
|
1282
1305
|
}
|
|
1283
1306
|
function publishIndexHTML(destinationPath, template, output, _event) {
|
|
1284
1307
|
const eps = output.outputs.filter((o) => o.kind === "entry-point");
|
package/dist/tsChecker.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { BunDevServerConfig } from "./bunServeConfig";
|
|
2
|
-
export declare function performTSC(finalConfig: BunDevServerConfig, importMeta: ImportMeta): Promise<
|
|
2
|
+
export declare function performTSC(finalConfig: BunDevServerConfig, importMeta: ImportMeta): Promise<{
|
|
3
|
+
error: boolean;
|
|
4
|
+
message: string;
|
|
5
|
+
}>;
|
package/package.json
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"exports": {
|
|
25
25
|
".": "./dist/index.js"
|
|
26
26
|
},
|
|
27
|
-
"version": "0.9.
|
|
27
|
+
"version": "0.9.6",
|
|
28
28
|
"module": "index.ts",
|
|
29
29
|
"type": "module",
|
|
30
30
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"build": "bun run ./build.ts"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@types/bun": "^1.2.
|
|
35
|
+
"@types/bun": "^1.2.4"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"typescript": "^5.7.3"
|