bun-dev-server 0.9.0 → 0.9.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.
@@ -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;
@@ -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
@@ -1098,7 +1098,7 @@ function getBunHMRFooter(config) {
1098
1098
 
1099
1099
  // src/bunManifest.ts
1100
1100
  var {write, pathToFileURL } = globalThis.Bun;
1101
- function writeManifest(output, outdir, withHash = false, manifestName = "bunmanifest.txt") {
1101
+ function writeManifest(output, outdir, withHash = false, manifestName = "bun_server_manifest.json") {
1102
1102
  const entryPoints = output.outputs.filter((o) => o.kind === "entry-point");
1103
1103
  const epTable = [];
1104
1104
  for (const ep of entryPoints) {
@@ -1234,17 +1234,31 @@ var debouncedbuildAndNotify = import_debounce.default(async (importerMeta, final
1234
1234
  if (finalConfig.cleanServePath) {
1235
1235
  await cleanDirectory(destinationPath);
1236
1236
  }
1237
- const output = await Bun.build(buildCfg);
1238
- publishOutputLogs(bunServer, output, event);
1239
- if (finalConfig.createDefaultIndexHTML) {
1240
- publishIndexHTML(destinationPath, finalConfig.serveOutputHtml, output, event);
1241
- }
1242
- if (finalConfig.writeManifest) {
1243
- writeManifest(output, destinationPath, finalConfig.manifestWithHash, finalConfig.manifestName);
1244
- }
1245
- const tscSuccess = await performTSC(finalConfig, importerMeta);
1246
- if (finalConfig.reloadOnChange && tscSuccess) {
1247
- bunServer.publish("message", JSON.stringify({ type: "reload" }));
1237
+ const buildEnv = {
1238
+ importerMeta,
1239
+ finalConfig,
1240
+ destinationPath,
1241
+ buildCfg,
1242
+ bunServer,
1243
+ event
1244
+ };
1245
+ finalConfig.beforeBuild?.(buildEnv);
1246
+ try {
1247
+ const output = await Bun.build(buildCfg);
1248
+ publishOutputLogs(bunServer, output, event);
1249
+ if (finalConfig.createDefaultIndexHTML) {
1250
+ publishIndexHTML(destinationPath, finalConfig.serveOutputHtml, output, event);
1251
+ }
1252
+ if (finalConfig.writeManifest) {
1253
+ writeManifest(output, destinationPath, finalConfig.manifestWithHash, finalConfig.manifestName);
1254
+ }
1255
+ finalConfig.afterBuild?.(output, buildEnv);
1256
+ const tscSuccess = await performTSC(finalConfig, importerMeta);
1257
+ if (finalConfig.reloadOnChange && tscSuccess) {
1258
+ bunServer.publish("message", JSON.stringify({ type: "reload" }));
1259
+ }
1260
+ } catch (e) {
1261
+ console.error(e);
1248
1262
  }
1249
1263
  }, watchDelay, { immediate: true });
1250
1264
  function handleErrorResponse(req, err) {
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "exports": {
22
22
  ".": "./dist/index.js"
23
23
  },
24
- "version": "0.9.0",
24
+ "version": "0.9.2",
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"