bun-dev-server 0.7.0 → 0.8.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/dist/bunServeConfig.d.ts +10 -0
- package/dist/index.js +36 -22
- package/dist/server.d.ts +1 -1
- package/dist/tsChecker.d.ts +1 -1
- package/package.json +1 -1
package/dist/bunServeConfig.d.ts
CHANGED
|
@@ -10,6 +10,11 @@ export interface BunDevServerConfig extends Partial<BunServeConfig> {
|
|
|
10
10
|
*/
|
|
11
11
|
watchDelay?: number;
|
|
12
12
|
enableTSC?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The path to the TypeScript configuration file.
|
|
15
|
+
* Defaults to "./tsconfig.json".
|
|
16
|
+
*/
|
|
17
|
+
tscConfigPath?: string;
|
|
13
18
|
writeManifest?: boolean;
|
|
14
19
|
manifestName?: string;
|
|
15
20
|
manifestWithHash?: boolean;
|
|
@@ -25,6 +30,11 @@ export interface BunDevServerConfig extends Partial<BunServeConfig> {
|
|
|
25
30
|
cleanServePath?: boolean;
|
|
26
31
|
serveOutputEjs?: string;
|
|
27
32
|
serveOutputHtml?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Using EJS Index HTML template.
|
|
35
|
+
* Defaults to true.
|
|
36
|
+
*/
|
|
37
|
+
createDefaultIndexHTML?: boolean;
|
|
28
38
|
}
|
|
29
39
|
export interface BunServeConfig {
|
|
30
40
|
port: number;
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ 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;
|
|
19
20
|
|
|
20
21
|
// node_modules/ejs/lib/utils.js
|
|
21
22
|
var require_utils = __commonJS((exports) => {
|
|
@@ -197,8 +198,8 @@ var require_package = __commonJS((exports, module) => {
|
|
|
197
198
|
|
|
198
199
|
// node_modules/ejs/lib/ejs.js
|
|
199
200
|
var require_ejs = __commonJS((exports) => {
|
|
200
|
-
var fs =
|
|
201
|
-
var path =
|
|
201
|
+
var fs = __require("fs");
|
|
202
|
+
var path = __require("path");
|
|
202
203
|
var utils = require_utils();
|
|
203
204
|
var scopeOptionWarned = false;
|
|
204
205
|
var _VERSION_STRING = require_package().version;
|
|
@@ -967,6 +968,7 @@ var indexHTMLTemplate_default = `<!DOCTYPE html>\r
|
|
|
967
968
|
|
|
968
969
|
// src/server.ts
|
|
969
970
|
import { watch, readdir, access, readFile as readFile2, constants } from "fs/promises";
|
|
971
|
+
import { resolve } from "path";
|
|
970
972
|
|
|
971
973
|
// src/bunClientHmr.ts
|
|
972
974
|
function hotReload() {
|
|
@@ -1114,10 +1116,10 @@ function writeManifest(output, outdir, withHash = false, manifestName = "bunmani
|
|
|
1114
1116
|
// src/tsChecker.ts
|
|
1115
1117
|
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
1116
1118
|
var {$ } = globalThis.Bun;
|
|
1117
|
-
async function performTSC(finalConfig) {
|
|
1119
|
+
async function performTSC(finalConfig, importMeta) {
|
|
1118
1120
|
if (finalConfig.enableTSC) {
|
|
1119
1121
|
console.log("Performing TSC check");
|
|
1120
|
-
const tsc = await $`tsc`.
|
|
1122
|
+
const tsc = await $`tsc --noEmit --noErrorTruncation -p ${finalConfig.tscConfigPath}`.cwd(importMeta.dir).quiet().nothrow();
|
|
1121
1123
|
if (tsc.exitCode === 0) {
|
|
1122
1124
|
console.log(import_picocolors.default.bgGreen("\u2714 [SUCCESS]"), "TSC check passed");
|
|
1123
1125
|
return true;
|
|
@@ -1133,25 +1135,33 @@ ${tsc.stdout.toString()}`);
|
|
|
1133
1135
|
// src/server.ts
|
|
1134
1136
|
var import_debounce = __toESM(require_debounce(), 1);
|
|
1135
1137
|
var watchDelay = 1000;
|
|
1136
|
-
async function startBunDevServer(serverConfig) {
|
|
1138
|
+
async function startBunDevServer(serverConfig, importMeta) {
|
|
1137
1139
|
const defaultConfig = {
|
|
1138
1140
|
port: 3000,
|
|
1139
1141
|
websocketPath: DEFAULT_HMR_PATH,
|
|
1140
1142
|
serveOutputEjs: serveOutputTemplate_default,
|
|
1141
|
-
serveOutputHtml: indexHTMLTemplate_default
|
|
1143
|
+
serveOutputHtml: indexHTMLTemplate_default,
|
|
1144
|
+
createDefaultIndexHTML: true,
|
|
1145
|
+
tscConfigPath: resolve(importMeta.dir, "./tsconfig.json")
|
|
1142
1146
|
};
|
|
1143
1147
|
const finalConfig = { ...defaultConfig, ...serverConfig };
|
|
1144
1148
|
if (finalConfig.watchDelay) {
|
|
1145
1149
|
watchDelay = finalConfig.watchDelay;
|
|
1146
1150
|
}
|
|
1151
|
+
if (serverConfig.tscConfigPath) {
|
|
1152
|
+
finalConfig.tscConfigPath = resolve(importMeta.dir, serverConfig.tscConfigPath);
|
|
1153
|
+
}
|
|
1147
1154
|
if (!finalConfig.watchDir) {
|
|
1148
1155
|
throw new Error("watchDir must be set");
|
|
1149
1156
|
}
|
|
1150
|
-
const
|
|
1151
|
-
const
|
|
1152
|
-
const
|
|
1153
|
-
const
|
|
1154
|
-
const
|
|
1157
|
+
const servePart = finalConfig.buildConfig.outdir ?? finalConfig.servePath ?? "./dist";
|
|
1158
|
+
const serveDestination = resolve(importMeta.dir, servePart);
|
|
1159
|
+
const watchDestination = resolve(importMeta.dir, finalConfig.watchDir);
|
|
1160
|
+
const allEntries = serverConfig.buildConfig.entrypoints.splice(0, serverConfig.buildConfig.entrypoints.length);
|
|
1161
|
+
const resolvedEntries = allEntries.map((e) => resolve(importMeta.dir, e));
|
|
1162
|
+
serverConfig.buildConfig.entrypoints = resolvedEntries;
|
|
1163
|
+
const destinationPath = serveDestination;
|
|
1164
|
+
const srcWatch = watchDestination;
|
|
1155
1165
|
try {
|
|
1156
1166
|
await readdir(destinationPath);
|
|
1157
1167
|
} catch (e) {
|
|
@@ -1204,9 +1214,6 @@ async function startBunDevServer(serverConfig) {
|
|
|
1204
1214
|
}
|
|
1205
1215
|
const url = new URL(req.url);
|
|
1206
1216
|
let requestPath = url.pathname;
|
|
1207
|
-
if (requestPath.toLowerCase() === "/index.html") {
|
|
1208
|
-
requestPath = "/";
|
|
1209
|
-
}
|
|
1210
1217
|
return handlePathRequest(requestPath, req, finalConfig, destinationPath);
|
|
1211
1218
|
},
|
|
1212
1219
|
websocket: {
|
|
@@ -1218,23 +1225,25 @@ async function startBunDevServer(serverConfig) {
|
|
|
1218
1225
|
sendPings: true
|
|
1219
1226
|
}
|
|
1220
1227
|
});
|
|
1221
|
-
debouncedbuildAndNotify(finalConfig, destinationPath, buildCfg, bunServer, { filename: "Initial", eventType: "change" });
|
|
1228
|
+
debouncedbuildAndNotify(importMeta, finalConfig, destinationPath, buildCfg, bunServer, { filename: "Initial", eventType: "change" });
|
|
1222
1229
|
const watcher = watch(srcWatch, { recursive: true });
|
|
1223
1230
|
for await (const event of watcher) {
|
|
1224
|
-
debouncedbuildAndNotify(finalConfig, destinationPath, buildCfg, bunServer, event);
|
|
1231
|
+
debouncedbuildAndNotify(importMeta, finalConfig, destinationPath, buildCfg, bunServer, event);
|
|
1225
1232
|
}
|
|
1226
1233
|
}
|
|
1227
|
-
var debouncedbuildAndNotify = import_debounce.default(async (finalConfig, destinationPath, buildCfg, bunServer, event) => {
|
|
1234
|
+
var debouncedbuildAndNotify = import_debounce.default(async (importerMeta, finalConfig, destinationPath, buildCfg, bunServer, event) => {
|
|
1228
1235
|
if (finalConfig.cleanServePath) {
|
|
1229
1236
|
await cleanDirectory(destinationPath);
|
|
1230
1237
|
}
|
|
1231
1238
|
const output = await Bun.build(buildCfg);
|
|
1232
1239
|
publishOutputLogs(bunServer, output, event);
|
|
1233
|
-
|
|
1240
|
+
if (finalConfig.createDefaultIndexHTML) {
|
|
1241
|
+
publishIndexHTML(destinationPath, finalConfig.serveOutputHtml, output, event);
|
|
1242
|
+
}
|
|
1234
1243
|
if (finalConfig.writeManifest) {
|
|
1235
1244
|
writeManifest(output, destinationPath, finalConfig.manifestWithHash, finalConfig.manifestName);
|
|
1236
1245
|
}
|
|
1237
|
-
const tscSuccess = await performTSC(finalConfig);
|
|
1246
|
+
const tscSuccess = await performTSC(finalConfig, importerMeta);
|
|
1238
1247
|
if (finalConfig.reloadOnChange && tscSuccess) {
|
|
1239
1248
|
bunServer.publish("message", JSON.stringify({ type: "reload" }));
|
|
1240
1249
|
}
|
|
@@ -1299,7 +1308,7 @@ function convertBytes(bytes) {
|
|
|
1299
1308
|
return (bytes / Math.pow(1024, i)).toFixed(1) + " " + sizes[i];
|
|
1300
1309
|
}
|
|
1301
1310
|
async function handlePathRequest(requestPath, req, finalConfig, destinationPath) {
|
|
1302
|
-
|
|
1311
|
+
let fsPath = destinationPath + requestPath;
|
|
1303
1312
|
const objThere = await checkObjectExists(fsPath, req);
|
|
1304
1313
|
let isDirectory = false;
|
|
1305
1314
|
if (objThere) {
|
|
@@ -1313,8 +1322,13 @@ async function handlePathRequest(requestPath, req, finalConfig, destinationPath)
|
|
|
1313
1322
|
}
|
|
1314
1323
|
}
|
|
1315
1324
|
} else {
|
|
1316
|
-
|
|
1317
|
-
|
|
1325
|
+
if (requestPath.toLowerCase() !== "/index.html") {
|
|
1326
|
+
finalConfig.logRequests && console.log(`${404} ${req.url}`);
|
|
1327
|
+
return withCORSHeaders(new Response("", { status: 404 }), req);
|
|
1328
|
+
}
|
|
1329
|
+
requestPath = "/";
|
|
1330
|
+
isDirectory = true;
|
|
1331
|
+
fsPath = destinationPath + requestPath;
|
|
1318
1332
|
}
|
|
1319
1333
|
if (!isDirectory) {
|
|
1320
1334
|
try {
|
package/dist/server.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type BunDevServerConfig } from "./bunServeConfig";
|
|
2
|
-
export declare function startBunDevServer(serverConfig: BunDevServerConfig): Promise<void>;
|
|
2
|
+
export declare function startBunDevServer(serverConfig: BunDevServerConfig, importMeta: ImportMeta): Promise<void>;
|
package/dist/tsChecker.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { BunDevServerConfig } from "./bunServeConfig";
|
|
2
|
-
export declare function performTSC(finalConfig: BunDevServerConfig): Promise<boolean>;
|
|
2
|
+
export declare function performTSC(finalConfig: BunDevServerConfig, importMeta: ImportMeta): Promise<boolean>;
|