Update dist
This commit is contained in:
Vendored
+2
-1
@@ -1,4 +1,5 @@
|
||||
import { log } from "./log";
|
||||
export default function exitWithError(msg, code) {
|
||||
console.error(msg);
|
||||
log.error(msg);
|
||||
process.exit(code || 1);
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -2,6 +2,7 @@ const AppNames = {
|
||||
defaultPort: 7000,
|
||||
defaultAssetPrefix: "_bunext/static",
|
||||
name: "Bunext",
|
||||
version: "1.0.1",
|
||||
defaultDistDir: ".bunext",
|
||||
RootPagesComponentName: "__root",
|
||||
};
|
||||
|
||||
Vendored
+2
@@ -11,6 +11,7 @@ export default function grabDirNames() {
|
||||
const HYDRATION_DST_DIR_MAP_JSON_FILE = path.join(HYDRATION_DST_DIR, "map.json");
|
||||
const CONFIG_FILE = path.join(ROOT_DIR, "bunext.config.ts");
|
||||
const BUNX_CWD_DIR = path.resolve(ROOT_DIR, ".bunext");
|
||||
const BUNX_CWD_MODULE_CACHE_DIR = path.resolve(BUNX_CWD_DIR, "module-cache");
|
||||
const BUNX_TMP_DIR = path.resolve(BUNX_CWD_DIR, ".tmp");
|
||||
const BUNX_HYDRATION_SRC_DIR = path.resolve(BUNX_CWD_DIR, "client", "hydration-src");
|
||||
const BUNX_ROOT_DIR = path.resolve(__dirname, "../../");
|
||||
@@ -39,5 +40,6 @@ export default function grabDirNames() {
|
||||
BUNX_ROOT_404_FILE_NAME,
|
||||
HYDRATION_DST_DIR_MAP_JSON_FILE,
|
||||
BUNEXT_CACHE_DIR,
|
||||
BUNX_CWD_MODULE_CACHE_DIR,
|
||||
};
|
||||
}
|
||||
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
import chalk from "chalk";
|
||||
import AppNames from "./grab-app-names";
|
||||
const prefix = {
|
||||
info: chalk.cyan.bold("ℹ"),
|
||||
success: chalk.green.bold("✓"),
|
||||
error: chalk.red.bold("✗"),
|
||||
warn: chalk.yellow.bold("⚠"),
|
||||
build: chalk.magenta.bold("⚙"),
|
||||
watch: chalk.blue.bold("◉"),
|
||||
};
|
||||
export const log = {
|
||||
info: (msg) => console.log(`${prefix.info} ${chalk.white(msg)}`),
|
||||
success: (msg) => console.log(`${prefix.success} ${chalk.green(msg)}`),
|
||||
error: (msg) => console.error(`${prefix.error} ${chalk.red(String(msg))}`),
|
||||
warn: (msg) => console.warn(`${prefix.warn} ${chalk.yellow(msg)}`),
|
||||
build: (msg) => console.log(`${prefix.build} ${chalk.magenta(msg)}`),
|
||||
watch: (msg) => console.log(`${prefix.watch} ${chalk.blue(msg)}`),
|
||||
server: (url) => console.log(`${prefix.success} ${chalk.white("Server running on")} ${chalk.cyan.underline(url)}`),
|
||||
banner: () => console.log(`\n ${chalk.cyan.bold(AppNames.name)} ${chalk.gray(`v${AppNames.version}`)}\n`),
|
||||
};
|
||||
Vendored
+69
@@ -0,0 +1,69 @@
|
||||
import { resolve, dirname, extname } from "path";
|
||||
import { existsSync } from "fs";
|
||||
const SOURCE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
|
||||
function getLoader(filePath) {
|
||||
const ext = extname(filePath).slice(1);
|
||||
return SOURCE_EXTENSIONS.map((e) => e.slice(1)).includes(ext) ? ext : "js";
|
||||
}
|
||||
function tryResolveSync(absPath) {
|
||||
if (existsSync(absPath))
|
||||
return absPath;
|
||||
for (const ext of SOURCE_EXTENSIONS) {
|
||||
const p = absPath + ext;
|
||||
if (existsSync(p))
|
||||
return p;
|
||||
}
|
||||
for (const ext of SOURCE_EXTENSIONS) {
|
||||
const p = resolve(absPath, "index" + ext);
|
||||
if (existsSync(p))
|
||||
return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
export default function registerDevPlugin() {
|
||||
Bun.plugin({
|
||||
name: "bunext-dev-hmr",
|
||||
setup(build) {
|
||||
// Intercept absolute-path imports that already carry ?t= (our dynamic imports)
|
||||
build.onResolve({ filter: /\?t=\d+$/ }, (args) => {
|
||||
if (args.path.includes("node_modules"))
|
||||
return undefined;
|
||||
const cleanPath = args.path.replace(/\?t=\d+$/, "");
|
||||
const resolved = tryResolveSync(cleanPath);
|
||||
if (!resolved)
|
||||
return undefined;
|
||||
if (!SOURCE_EXTENSIONS.some((e) => resolved.endsWith(e)))
|
||||
return undefined;
|
||||
return {
|
||||
path: `${resolved}?t=${global.LAST_BUILD_TIME ?? 0}`,
|
||||
namespace: "bunext-dev",
|
||||
};
|
||||
});
|
||||
// Intercept relative imports from within bunext-dev modules
|
||||
build.onResolve({ filter: /^\./ }, (args) => {
|
||||
if (!/\?t=\d+/.test(args.importer))
|
||||
return undefined;
|
||||
// Strip "namespace:" prefix (e.g. "bunext-dev:") Bun prepends to importer
|
||||
const cleanImporter = args.importer
|
||||
.replace(/^[^/]+:(?=\/)/, "")
|
||||
.replace(/\?t=\d+$/, "");
|
||||
const base = resolve(dirname(cleanImporter), args.path);
|
||||
const resolved = tryResolveSync(base);
|
||||
if (!resolved)
|
||||
return undefined;
|
||||
if (!SOURCE_EXTENSIONS.some((e) => resolved.endsWith(e)))
|
||||
return undefined;
|
||||
return {
|
||||
path: `${resolved}?t=${global.LAST_BUILD_TIME ?? 0}`,
|
||||
namespace: "bunext-dev",
|
||||
};
|
||||
});
|
||||
// Load files in the bunext-dev namespace from disk (async is fine in onLoad)
|
||||
build.onLoad({ filter: /.*/, namespace: "bunext-dev" }, async (args) => {
|
||||
const realPath = args.path.replace(/\?t=\d+$/, "");
|
||||
const source = await Bun.file(realPath).text();
|
||||
return { contents: source, loader: getLoader(realPath) };
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user