bun-dev-server 0.7.1 → 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 +5 -0
- package/dist/index.js +21 -13
- 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;
|
package/dist/index.js
CHANGED
|
@@ -968,6 +968,7 @@ var indexHTMLTemplate_default = `<!DOCTYPE html>\r
|
|
|
968
968
|
|
|
969
969
|
// src/server.ts
|
|
970
970
|
import { watch, readdir, access, readFile as readFile2, constants } from "fs/promises";
|
|
971
|
+
import { resolve } from "path";
|
|
971
972
|
|
|
972
973
|
// src/bunClientHmr.ts
|
|
973
974
|
function hotReload() {
|
|
@@ -1115,10 +1116,10 @@ function writeManifest(output, outdir, withHash = false, manifestName = "bunmani
|
|
|
1115
1116
|
// src/tsChecker.ts
|
|
1116
1117
|
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
1117
1118
|
var {$ } = globalThis.Bun;
|
|
1118
|
-
async function performTSC(finalConfig) {
|
|
1119
|
+
async function performTSC(finalConfig, importMeta) {
|
|
1119
1120
|
if (finalConfig.enableTSC) {
|
|
1120
1121
|
console.log("Performing TSC check");
|
|
1121
|
-
const tsc = await $`tsc`.
|
|
1122
|
+
const tsc = await $`tsc --noEmit --noErrorTruncation -p ${finalConfig.tscConfigPath}`.cwd(importMeta.dir).quiet().nothrow();
|
|
1122
1123
|
if (tsc.exitCode === 0) {
|
|
1123
1124
|
console.log(import_picocolors.default.bgGreen("\u2714 [SUCCESS]"), "TSC check passed");
|
|
1124
1125
|
return true;
|
|
@@ -1134,26 +1135,33 @@ ${tsc.stdout.toString()}`);
|
|
|
1134
1135
|
// src/server.ts
|
|
1135
1136
|
var import_debounce = __toESM(require_debounce(), 1);
|
|
1136
1137
|
var watchDelay = 1000;
|
|
1137
|
-
async function startBunDevServer(serverConfig) {
|
|
1138
|
+
async function startBunDevServer(serverConfig, importMeta) {
|
|
1138
1139
|
const defaultConfig = {
|
|
1139
1140
|
port: 3000,
|
|
1140
1141
|
websocketPath: DEFAULT_HMR_PATH,
|
|
1141
1142
|
serveOutputEjs: serveOutputTemplate_default,
|
|
1142
1143
|
serveOutputHtml: indexHTMLTemplate_default,
|
|
1143
|
-
createDefaultIndexHTML: true
|
|
1144
|
+
createDefaultIndexHTML: true,
|
|
1145
|
+
tscConfigPath: resolve(importMeta.dir, "./tsconfig.json")
|
|
1144
1146
|
};
|
|
1145
1147
|
const finalConfig = { ...defaultConfig, ...serverConfig };
|
|
1146
1148
|
if (finalConfig.watchDelay) {
|
|
1147
1149
|
watchDelay = finalConfig.watchDelay;
|
|
1148
1150
|
}
|
|
1151
|
+
if (serverConfig.tscConfigPath) {
|
|
1152
|
+
finalConfig.tscConfigPath = resolve(importMeta.dir, serverConfig.tscConfigPath);
|
|
1153
|
+
}
|
|
1149
1154
|
if (!finalConfig.watchDir) {
|
|
1150
1155
|
throw new Error("watchDir must be set");
|
|
1151
1156
|
}
|
|
1152
|
-
const
|
|
1153
|
-
const
|
|
1154
|
-
const
|
|
1155
|
-
const
|
|
1156
|
-
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;
|
|
1157
1165
|
try {
|
|
1158
1166
|
await readdir(destinationPath);
|
|
1159
1167
|
} catch (e) {
|
|
@@ -1217,13 +1225,13 @@ async function startBunDevServer(serverConfig) {
|
|
|
1217
1225
|
sendPings: true
|
|
1218
1226
|
}
|
|
1219
1227
|
});
|
|
1220
|
-
debouncedbuildAndNotify(finalConfig, destinationPath, buildCfg, bunServer, { filename: "Initial", eventType: "change" });
|
|
1228
|
+
debouncedbuildAndNotify(importMeta, finalConfig, destinationPath, buildCfg, bunServer, { filename: "Initial", eventType: "change" });
|
|
1221
1229
|
const watcher = watch(srcWatch, { recursive: true });
|
|
1222
1230
|
for await (const event of watcher) {
|
|
1223
|
-
debouncedbuildAndNotify(finalConfig, destinationPath, buildCfg, bunServer, event);
|
|
1231
|
+
debouncedbuildAndNotify(importMeta, finalConfig, destinationPath, buildCfg, bunServer, event);
|
|
1224
1232
|
}
|
|
1225
1233
|
}
|
|
1226
|
-
var debouncedbuildAndNotify = import_debounce.default(async (finalConfig, destinationPath, buildCfg, bunServer, event) => {
|
|
1234
|
+
var debouncedbuildAndNotify = import_debounce.default(async (importerMeta, finalConfig, destinationPath, buildCfg, bunServer, event) => {
|
|
1227
1235
|
if (finalConfig.cleanServePath) {
|
|
1228
1236
|
await cleanDirectory(destinationPath);
|
|
1229
1237
|
}
|
|
@@ -1235,7 +1243,7 @@ var debouncedbuildAndNotify = import_debounce.default(async (finalConfig, destin
|
|
|
1235
1243
|
if (finalConfig.writeManifest) {
|
|
1236
1244
|
writeManifest(output, destinationPath, finalConfig.manifestWithHash, finalConfig.manifestName);
|
|
1237
1245
|
}
|
|
1238
|
-
const tscSuccess = await performTSC(finalConfig);
|
|
1246
|
+
const tscSuccess = await performTSC(finalConfig, importerMeta);
|
|
1239
1247
|
if (finalConfig.reloadOnChange && tscSuccess) {
|
|
1240
1248
|
bunServer.publish("message", JSON.stringify({ type: "reload" }));
|
|
1241
1249
|
}
|
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>;
|