bun-dev-server 0.7.1 → 0.9.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 +6 -1
- package/dist/index.js +25 -17
- 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,10 +10,15 @@ 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;
|
|
16
|
-
hotReload?: "plugin" | "footer";
|
|
21
|
+
hotReload?: "plugin" | "footer" | "none";
|
|
17
22
|
logRequests?: boolean;
|
|
18
23
|
reloadOnChange?: boolean;
|
|
19
24
|
/**
|
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 =
|
|
202
|
-
var 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;
|
|
@@ -968,6 +967,7 @@ var indexHTMLTemplate_default = `<!DOCTYPE html>\r
|
|
|
968
967
|
|
|
969
968
|
// src/server.ts
|
|
970
969
|
import { watch, readdir, access, readFile as readFile2, constants } from "fs/promises";
|
|
970
|
+
import { resolve } from "path";
|
|
971
971
|
|
|
972
972
|
// src/bunClientHmr.ts
|
|
973
973
|
function hotReload() {
|
|
@@ -1115,10 +1115,10 @@ function writeManifest(output, outdir, withHash = false, manifestName = "bunmani
|
|
|
1115
1115
|
// src/tsChecker.ts
|
|
1116
1116
|
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
1117
1117
|
var {$ } = globalThis.Bun;
|
|
1118
|
-
async function performTSC(finalConfig) {
|
|
1118
|
+
async function performTSC(finalConfig, importMeta) {
|
|
1119
1119
|
if (finalConfig.enableTSC) {
|
|
1120
1120
|
console.log("Performing TSC check");
|
|
1121
|
-
const tsc = await $`tsc`.
|
|
1121
|
+
const tsc = await $`tsc --noEmit --noErrorTruncation -p ${finalConfig.tscConfigPath}`.cwd(importMeta.dir).quiet().nothrow();
|
|
1122
1122
|
if (tsc.exitCode === 0) {
|
|
1123
1123
|
console.log(import_picocolors.default.bgGreen("\u2714 [SUCCESS]"), "TSC check passed");
|
|
1124
1124
|
return true;
|
|
@@ -1134,26 +1134,33 @@ ${tsc.stdout.toString()}`);
|
|
|
1134
1134
|
// src/server.ts
|
|
1135
1135
|
var import_debounce = __toESM(require_debounce(), 1);
|
|
1136
1136
|
var watchDelay = 1000;
|
|
1137
|
-
async function startBunDevServer(serverConfig) {
|
|
1137
|
+
async function startBunDevServer(serverConfig, importMeta) {
|
|
1138
1138
|
const defaultConfig = {
|
|
1139
1139
|
port: 3000,
|
|
1140
1140
|
websocketPath: DEFAULT_HMR_PATH,
|
|
1141
1141
|
serveOutputEjs: serveOutputTemplate_default,
|
|
1142
1142
|
serveOutputHtml: indexHTMLTemplate_default,
|
|
1143
|
-
createDefaultIndexHTML: true
|
|
1143
|
+
createDefaultIndexHTML: true,
|
|
1144
|
+
tscConfigPath: resolve(importMeta.dir, "./tsconfig.json")
|
|
1144
1145
|
};
|
|
1145
1146
|
const finalConfig = { ...defaultConfig, ...serverConfig };
|
|
1146
1147
|
if (finalConfig.watchDelay) {
|
|
1147
1148
|
watchDelay = finalConfig.watchDelay;
|
|
1148
1149
|
}
|
|
1150
|
+
if (serverConfig.tscConfigPath) {
|
|
1151
|
+
finalConfig.tscConfigPath = resolve(importMeta.dir, serverConfig.tscConfigPath);
|
|
1152
|
+
}
|
|
1149
1153
|
if (!finalConfig.watchDir) {
|
|
1150
1154
|
throw new Error("watchDir must be set");
|
|
1151
1155
|
}
|
|
1152
|
-
const
|
|
1153
|
-
const
|
|
1154
|
-
const
|
|
1155
|
-
const
|
|
1156
|
-
const
|
|
1156
|
+
const servePart = finalConfig.buildConfig.outdir ?? finalConfig.servePath ?? "./dist";
|
|
1157
|
+
const serveDestination = resolve(importMeta.dir, servePart);
|
|
1158
|
+
const watchDestination = resolve(importMeta.dir, finalConfig.watchDir);
|
|
1159
|
+
const allEntries = serverConfig.buildConfig.entrypoints.splice(0, serverConfig.buildConfig.entrypoints.length);
|
|
1160
|
+
const resolvedEntries = allEntries.map((e) => resolve(importMeta.dir, e));
|
|
1161
|
+
serverConfig.buildConfig.entrypoints = resolvedEntries;
|
|
1162
|
+
const destinationPath = serveDestination;
|
|
1163
|
+
const srcWatch = watchDestination;
|
|
1157
1164
|
try {
|
|
1158
1165
|
await readdir(destinationPath);
|
|
1159
1166
|
} catch (e) {
|
|
@@ -1164,7 +1171,7 @@ async function startBunDevServer(serverConfig) {
|
|
|
1164
1171
|
throw e;
|
|
1165
1172
|
}
|
|
1166
1173
|
}
|
|
1167
|
-
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 };
|
|
1168
1175
|
const buildCfg = {
|
|
1169
1176
|
...serverConfig.buildConfig,
|
|
1170
1177
|
outdir: destinationPath
|
|
@@ -1217,13 +1224,13 @@ async function startBunDevServer(serverConfig) {
|
|
|
1217
1224
|
sendPings: true
|
|
1218
1225
|
}
|
|
1219
1226
|
});
|
|
1220
|
-
debouncedbuildAndNotify(finalConfig, destinationPath, buildCfg, bunServer, { filename: "Initial", eventType: "change" });
|
|
1227
|
+
debouncedbuildAndNotify(importMeta, finalConfig, destinationPath, buildCfg, bunServer, { filename: "Initial", eventType: "change" });
|
|
1221
1228
|
const watcher = watch(srcWatch, { recursive: true });
|
|
1222
1229
|
for await (const event of watcher) {
|
|
1223
|
-
debouncedbuildAndNotify(finalConfig, destinationPath, buildCfg, bunServer, event);
|
|
1230
|
+
debouncedbuildAndNotify(importMeta, finalConfig, destinationPath, buildCfg, bunServer, event);
|
|
1224
1231
|
}
|
|
1225
1232
|
}
|
|
1226
|
-
var debouncedbuildAndNotify = import_debounce.default(async (finalConfig, destinationPath, buildCfg, bunServer, event) => {
|
|
1233
|
+
var debouncedbuildAndNotify = import_debounce.default(async (importerMeta, finalConfig, destinationPath, buildCfg, bunServer, event) => {
|
|
1227
1234
|
if (finalConfig.cleanServePath) {
|
|
1228
1235
|
await cleanDirectory(destinationPath);
|
|
1229
1236
|
}
|
|
@@ -1235,7 +1242,7 @@ var debouncedbuildAndNotify = import_debounce.default(async (finalConfig, destin
|
|
|
1235
1242
|
if (finalConfig.writeManifest) {
|
|
1236
1243
|
writeManifest(output, destinationPath, finalConfig.manifestWithHash, finalConfig.manifestName);
|
|
1237
1244
|
}
|
|
1238
|
-
const tscSuccess = await performTSC(finalConfig);
|
|
1245
|
+
const tscSuccess = await performTSC(finalConfig, importerMeta);
|
|
1239
1246
|
if (finalConfig.reloadOnChange && tscSuccess) {
|
|
1240
1247
|
bunServer.publish("message", JSON.stringify({ type: "reload" }));
|
|
1241
1248
|
}
|
|
@@ -1275,6 +1282,7 @@ function withCORSHeaders(response, request) {
|
|
|
1275
1282
|
response.headers.set("Access-Control-Allow-Origin", request?.headers.get("origin") ?? "*");
|
|
1276
1283
|
response.headers.set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
|
|
1277
1284
|
response.headers.set("Access-Control-Allow-Credentials", "true");
|
|
1285
|
+
response.headers.set("Cache-Control", "no-store, no-cache, must-revalidate");
|
|
1278
1286
|
return response;
|
|
1279
1287
|
}
|
|
1280
1288
|
async function cleanDirectory(dst) {
|
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>;
|