Remove all Loader.registry.delete lines

This commit is contained in:
Benjamin Toby 2026-07-29 14:05:12 +01:00
parent 45509deff8
commit 88ead3b3d6
10 changed files with 9 additions and 147 deletions

View File

@ -24,7 +24,7 @@ export default async function grabFilePathModule({ file_path, out_file, }) {
jsx: "automatic", jsx: "automatic",
outfile: target_cache_file_path, 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()}`); const module = await import(`${target_cache_file_path}?t=${Date.now()}`);
return module; return module;
} }

View File

@ -9,7 +9,7 @@ export default async function grabPageBundledReactComponent({ file_path, return_
try { try {
if (global.SSR_BUNDLER_CTX_MAP?.[file_path]) { if (global.SSR_BUNDLER_CTX_MAP?.[file_path]) {
const abs = path.join(ROOT_DIR, global.SSR_BUNDLER_CTX_MAP[file_path].path); const abs = path.join(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 mod = await import(`${abs}?t=${Date.now()}`);
const Main = mod.default; const Main = mod.default;
return { component: Main }; return { component: Main };

View File

@ -17,7 +17,7 @@ export default async function grabPageCombinedServerRes({ file_path, debug, url,
? path.join(ROOT_DIR, root_server_ctx_map.path) ? path.join(ROOT_DIR, root_server_ctx_map.path)
: root_server_file_path; : root_server_file_path;
if (final_root_server_path) { if (final_root_server_path) {
Loader.registry.delete(final_root_server_path); // Loader.registry.delete(final_root_server_path);
} }
const root_server_module = final_root_server_path const root_server_module = final_root_server_path
? await import(`${final_root_server_path}?t=${now}`) ? await import(`${final_root_server_path}?t=${now}`)
@ -38,7 +38,7 @@ export default async function grabPageCombinedServerRes({ file_path, debug, url,
? path.join(ROOT_DIR, page_server_ctx.path) ? path.join(ROOT_DIR, page_server_ctx.path)
: server_file_path; : server_file_path;
if (final_page_server_path) { if (final_page_server_path) {
Loader.registry.delete(final_page_server_path); // Loader.registry.delete(final_page_server_path);
} }
const server_module = final_page_server_path const server_module = final_page_server_path
? await import(`${final_page_server_path}?t=${now}`) ? await import(`${final_page_server_path}?t=${now}`)

View File

@ -1 +0,0 @@
export default function registerDevPlugin(): void;

View File

@ -1,69 +0,0 @@
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) };
});
},
});
}

View File

@ -1,6 +1,6 @@
{ {
"name": "@moduletrace/bunext", "name": "@moduletrace/bunext",
"version": "1.0.98", "version": "1.0.99",
"main": "dist/index.js", "main": "dist/index.js",
"module": "index.ts", "module": "index.ts",
"dependencies": { "dependencies": {

View File

@ -38,7 +38,7 @@ export default async function grabFilePathModule<T extends any = any>({
outfile: target_cache_file_path, 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()}`); const module = await import(`${target_cache_file_path}?t=${Date.now()}`);
return module as T; return module as T;

View File

@ -24,7 +24,7 @@ export default async function grabPageBundledReactComponent({
ROOT_DIR, ROOT_DIR,
global.SSR_BUNDLER_CTX_MAP[file_path].path, 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 mod = await import(`${abs}?t=${Date.now()}`);
const Main = mod.default as FC; const Main = mod.default as FC;

View File

@ -41,7 +41,7 @@ export default async function grabPageCombinedServerRes({
: root_server_file_path; : root_server_file_path;
if (final_root_server_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 const root_server_module: BunextPageServerModule = final_root_server_path
? await import(`${final_root_server_path}?t=${now}`) ? await import(`${final_root_server_path}?t=${now}`)
@ -69,7 +69,7 @@ export default async function grabPageCombinedServerRes({
: server_file_path; : server_file_path;
if (final_page_server_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 const server_module: BunextPageServerModule = final_page_server_path
? await import(`${final_page_server_path}?t=${now}`) ? await import(`${final_page_server_path}?t=${now}`)

View File

@ -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) };
});
},
});
}