Remove all Loader.registry.delete lines
This commit is contained in:
@@ -38,7 +38,7 @@ export default async function grabFilePathModule<T extends any = any>({
|
||||
outfile: target_cache_file_path,
|
||||
});
|
||||
|
||||
Loader.registry.delete(target_cache_file_path);
|
||||
// Loader.registry.delete(target_cache_file_path);
|
||||
const module = await import(`${target_cache_file_path}?t=${Date.now()}`);
|
||||
|
||||
return module as T;
|
||||
|
||||
@@ -24,7 +24,7 @@ export default async function grabPageBundledReactComponent({
|
||||
ROOT_DIR,
|
||||
global.SSR_BUNDLER_CTX_MAP[file_path].path,
|
||||
);
|
||||
Loader.registry.delete(abs);
|
||||
// Loader.registry.delete(abs);
|
||||
const mod = await import(`${abs}?t=${Date.now()}`);
|
||||
|
||||
const Main = mod.default as FC;
|
||||
|
||||
@@ -41,7 +41,7 @@ export default async function grabPageCombinedServerRes({
|
||||
: root_server_file_path;
|
||||
|
||||
if (final_root_server_path) {
|
||||
Loader.registry.delete(final_root_server_path);
|
||||
// Loader.registry.delete(final_root_server_path);
|
||||
}
|
||||
const root_server_module: BunextPageServerModule = final_root_server_path
|
||||
? await import(`${final_root_server_path}?t=${now}`)
|
||||
@@ -69,7 +69,7 @@ export default async function grabPageCombinedServerRes({
|
||||
: server_file_path;
|
||||
|
||||
if (final_page_server_path) {
|
||||
Loader.registry.delete(final_page_server_path);
|
||||
// Loader.registry.delete(final_page_server_path);
|
||||
}
|
||||
const server_module: BunextPageServerModule = final_page_server_path
|
||||
? await import(`${final_page_server_path}?t=${now}`)
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
import { resolve, dirname, extname } from "path";
|
||||
import { existsSync } from "fs";
|
||||
|
||||
const SOURCE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
|
||||
|
||||
function getLoader(filePath: string) {
|
||||
const ext = extname(filePath).slice(1) as any;
|
||||
return SOURCE_EXTENSIONS.map((e) => e.slice(1)).includes(ext) ? ext : "js";
|
||||
}
|
||||
|
||||
function tryResolveSync(absPath: string): string | null {
|
||||
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