bun-dev-server 0.0.9 → 0.2.0

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/bunClientHmr.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { type BunDevServerSocketConfig } from "./bunServeConfig";
2
2
 
3
3
  function hotReload() {
4
- if (window.BUN_HMR_INITED) {
4
+ if ((window as any).BUN_HMR_INITED) {
5
5
  return;
6
6
  }
7
- window.BUN_HMR_INITED = true;
7
+ (window as any).BUN_HMR_INITED = true;
8
8
  const hmrSock = new WebSocket("[REPLACE_ENDPOINT]");
9
9
  hmrSock.addEventListener("error", (err) => {
10
10
  console.error("HMR ERROR", err);
package/bunManifest.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  import { type BuildOutput, write, pathToFileURL } from "bun";
2
- export function writeManifest(output: BuildOutput, outdir: string, manifestName = "manifest.txt") {
2
+ export function writeManifest(output: BuildOutput, outdir: string, withHash = false, manifestName = "bunmanifest.txt") {
3
3
  const entryPoints = output.outputs.filter(o => o.kind === "entry-point");
4
- const epTable = [];
4
+ const epTable: string[] = [];
5
5
  for (const ep of entryPoints) {
6
6
  const basePathUrl = pathToFileURL(outdir);
7
7
  const epUrl = pathToFileURL(ep.path);
8
8
  const relativePath = epUrl.href.replace(`${basePathUrl.href}/`, "");
9
- const nameNoJs = relativePath.replace(".js", "");
10
- const hashedImport = `${relativePath}?${ep.hash}`;
11
- epTable.push({ name: nameNoJs, path: hashedImport });
12
- }
13
- const outObj = {};
14
- for (const element of epTable) {
15
- Object.assign(outObj, { [element.name]: { js: [`${element.path}`] } });
9
+ // const nameNoJs = relativePath.replace(".js", "");
10
+ const hashedImport = `${relativePath}${withHash ? `?${ep.hash}` : ``}`;
11
+ epTable.push(hashedImport);
16
12
  }
13
+ const outObj = { js: epTable };
14
+ // for (const element of epTable) {
15
+ // Object.assign(outObj, { [element.name]: { js: [`${element.path}`] } });
16
+ // }
17
17
  write(`${outdir}/${manifestName}`, JSON.stringify(outObj));
18
18
  }
package/bunServeConfig.ts CHANGED
@@ -7,6 +7,7 @@ export interface BunDevServerConfig extends Partial<BunDevServerSocketConfig> {
7
7
  enableTypeScriptWatch?: boolean;
8
8
  writeManifest?: boolean;
9
9
  manifestName?: string;
10
+ manifestWithHash?: boolean;
10
11
  reloadOnChange?: boolean;
11
12
  /**
12
13
  * The path to the directory to serve files from.
package/bunTSWatcher.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { $, type Server, type Subprocess, resolve } from "bun";
2
2
  export async function startTSWatcher(server: Server, watchDir: URL) {
3
- let dstcwd: string | undefined;
3
+ let dstcwd = process.cwd();
4
4
  if (watchDir) {
5
5
  dstcwd = process.platform === "win32" ? watchDir.pathname.substring(1) : watchDir.pathname;
6
6
  }
@@ -10,7 +10,7 @@ export async function startTSWatcher(server: Server, watchDir: URL) {
10
10
  //const tsc = await $`bun run ${tscResolved} --noEmit --watch ${dstcwd}/*.ts`.quiet().arrayBuffer();
11
11
  let tsc: Subprocess | undefined;
12
12
  try {
13
- tsc = Bun.spawn(["tsc", "--watch", "--project", `${import.meta.dir}/tsconfig.json`], { stdout: "pipe", stderr: "pipe" });
13
+ tsc = Bun.spawn(["tsc", "--watch", "--project", `${process.cwd()}/tsconfig.json`], { stdout: "pipe", stderr: "pipe", cwd: dstcwd });
14
14
  } catch (e) {
15
15
  console.error("TSC not found have you installed it globally?");
16
16
  return;
package/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- /// <reference path="./@types/serve.ts" />
1
+ /// <reference path="./@types/fileTypes.d.ts" />
2
2
  import { render } from "ejs";
3
3
  import Bun, { $, ShellError } from "bun";
4
4
  import serveTemplate from "./serveOutputTemplate.ejs" with { type: "text" };
@@ -151,7 +151,7 @@ export async function startBunDevServer(serverConfig: BunDevServerConfig) {
151
151
  publishOutputLogs(output, { filename: "Initial", eventType: "change" });
152
152
  publishIndexHTML(output, { filename: "Initial", eventType: "change" });
153
153
  if (finalConfig.writeManifest) {
154
- writeManifest(output, dst, finalConfig.manifestName);
154
+ writeManifest(output, dst, finalConfig.manifestWithHash, finalConfig.manifestName);
155
155
  }
156
156
  // $`tsc --watch`.then((tsc) => {
157
157
  // console.log("ASDASD");
@@ -173,7 +173,7 @@ export async function startBunDevServer(serverConfig: BunDevServerConfig) {
173
173
  publishOutputLogs(output, event);
174
174
  publishIndexHTML(output, event);
175
175
  if (finalConfig.writeManifest) {
176
- writeManifest(output, dst, finalConfig.manifestName);
176
+ writeManifest(output, dst, finalConfig.manifestWithHash, finalConfig.manifestName);
177
177
  }
178
178
  if (finalConfig.reloadOnChange) {
179
179
  bunServer.publish("message", JSON.stringify({ type: "reload" }));
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",
9
+ "version": "0.2.0",
10
10
  "module": "index.ts",
11
11
  "type": "module",
12
12
  "license": "MIT",
@@ -1,6 +0,0 @@
1
- declare global {
2
- interface Window {
3
- BUN_HMR_INITED: boolean;
4
- }
5
- }
6
- export {};
File without changes