bun-dev-server 0.8.0 → 0.9.1

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.
@@ -1,4 +1,13 @@
1
- import { type BuildConfig, type TLSOptions } from "bun";
1
+ import { type BuildConfig, type TLSOptions, type Server, type BuildOutput } from "bun";
2
+ import type { FileChangeInfo } from "fs/promises";
3
+ export interface BuildEnv {
4
+ importerMeta: ImportMeta;
5
+ finalConfig: BunDevServerConfig;
6
+ destinationPath: string;
7
+ buildCfg: BuildConfig;
8
+ bunServer: Server;
9
+ event: FileChangeInfo<any>;
10
+ }
2
11
  export interface BunDevServerConfig extends Partial<BunServeConfig> {
3
12
  port: number;
4
13
  buildConfig: BuildConfig;
@@ -18,7 +27,7 @@ export interface BunDevServerConfig extends Partial<BunServeConfig> {
18
27
  writeManifest?: boolean;
19
28
  manifestName?: string;
20
29
  manifestWithHash?: boolean;
21
- hotReload?: "plugin" | "footer";
30
+ hotReload?: "plugin" | "footer" | "none";
22
31
  logRequests?: boolean;
23
32
  reloadOnChange?: boolean;
24
33
  /**
@@ -35,6 +44,8 @@ export interface BunDevServerConfig extends Partial<BunServeConfig> {
35
44
  * Defaults to true.
36
45
  */
37
46
  createDefaultIndexHTML?: boolean;
47
+ beforeBuild?: (env: BuildEnv) => void;
48
+ afterBuild?: (outpug: BuildOutput, env: BuildEnv) => void;
38
49
  }
39
50
  export interface BunServeConfig {
40
51
  port: number;
package/dist/index.js CHANGED
@@ -16,7 +16,6 @@ var __toESM = (mod, isNodeMode, target) => {
16
16
  return to;
17
17
  };
18
18
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
19
- var __require = import.meta.require;
20
19
 
21
20
  // node_modules/ejs/lib/utils.js
22
21
  var require_utils = __commonJS((exports) => {
@@ -198,8 +197,8 @@ var require_package = __commonJS((exports, module) => {
198
197
 
199
198
  // node_modules/ejs/lib/ejs.js
200
199
  var require_ejs = __commonJS((exports) => {
201
- var fs = __require("fs");
202
- var path = __require("path");
200
+ var fs = import.meta.require("fs");
201
+ var path = import.meta.require("path");
203
202
  var utils = require_utils();
204
203
  var scopeOptionWarned = false;
205
204
  var _VERSION_STRING = require_package().version;
@@ -1099,7 +1098,7 @@ function getBunHMRFooter(config) {
1099
1098
 
1100
1099
  // src/bunManifest.ts
1101
1100
  var {write, pathToFileURL } = globalThis.Bun;
1102
- function writeManifest(output, outdir, withHash = false, manifestName = "bunmanifest.txt") {
1101
+ function writeManifest(output, outdir, withHash = false, manifestName = "bun_server_manifest.json") {
1103
1102
  const entryPoints = output.outputs.filter((o) => o.kind === "entry-point");
1104
1103
  const epTable = [];
1105
1104
  for (const ep of entryPoints) {
@@ -1172,7 +1171,7 @@ async function startBunDevServer(serverConfig, importMeta) {
1172
1171
  throw e;
1173
1172
  }
1174
1173
  }
1175
- const buncfg = { port: finalConfig.port, tls: finalConfig.tls, websocketPath: finalConfig.websocketPath };
1174
+ const buncfg = { port: finalConfig.port, tls: finalConfig.tls, websocketPath: finalConfig.websocketPath, secure: finalConfig.tls !== undefined };
1176
1175
  const buildCfg = {
1177
1176
  ...serverConfig.buildConfig,
1178
1177
  outdir: destinationPath
@@ -1235,6 +1234,15 @@ var debouncedbuildAndNotify = import_debounce.default(async (importerMeta, final
1235
1234
  if (finalConfig.cleanServePath) {
1236
1235
  await cleanDirectory(destinationPath);
1237
1236
  }
1237
+ const buildEnv = {
1238
+ importerMeta,
1239
+ finalConfig,
1240
+ destinationPath,
1241
+ buildCfg,
1242
+ bunServer,
1243
+ event
1244
+ };
1245
+ finalConfig.beforeBuild?.(buildEnv);
1238
1246
  const output = await Bun.build(buildCfg);
1239
1247
  publishOutputLogs(bunServer, output, event);
1240
1248
  if (finalConfig.createDefaultIndexHTML) {
@@ -1243,6 +1251,7 @@ var debouncedbuildAndNotify = import_debounce.default(async (importerMeta, final
1243
1251
  if (finalConfig.writeManifest) {
1244
1252
  writeManifest(output, destinationPath, finalConfig.manifestWithHash, finalConfig.manifestName);
1245
1253
  }
1254
+ finalConfig.afterBuild?.(output, buildEnv);
1246
1255
  const tscSuccess = await performTSC(finalConfig, importerMeta);
1247
1256
  if (finalConfig.reloadOnChange && tscSuccess) {
1248
1257
  bunServer.publish("message", JSON.stringify({ type: "reload" }));
@@ -1283,6 +1292,7 @@ function withCORSHeaders(response, request) {
1283
1292
  response.headers.set("Access-Control-Allow-Origin", request?.headers.get("origin") ?? "*");
1284
1293
  response.headers.set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
1285
1294
  response.headers.set("Access-Control-Allow-Credentials", "true");
1295
+ response.headers.set("Cache-Control", "no-store, no-cache, must-revalidate");
1286
1296
  return response;
1287
1297
  }
1288
1298
  async function cleanDirectory(dst) {
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "exports": {
22
22
  ".": "./dist/index.js"
23
23
  },
24
- "version": "0.8.0",
24
+ "version": "0.9.1",
25
25
  "module": "index.ts",
26
26
  "type": "module",
27
27
  "license": "MIT",
@@ -29,7 +29,7 @@
29
29
  "build": "bun run ./build.ts"
30
30
  },
31
31
  "devDependencies": {
32
- "@types/bun": "latest"
32
+ "@types/bun": "^1.2.2"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "typescript": "^5.7.3"