Fix memory leak in dev server
This commit is contained in:
Vendored
+21
-4
@@ -1,7 +1,24 @@
|
||||
/**
|
||||
* Dev: bypass Bun's module registry so rebuilt files are picked up.
|
||||
* Prod: import by stable path so each module is loaded (and kept) once.
|
||||
* A unique `?t=` per call creates a new, never-evicted module record, so
|
||||
* using it in production leaks memory on every request.
|
||||
* Imports a module by its stable path.
|
||||
*
|
||||
* Dev: when the file changed since it was last imported, its registry
|
||||
* entry is evicted first so the new version is evaluated and the old one
|
||||
* can be garbage collected. A cache-busting `?t=` query would instead
|
||||
* create a new, never-evicted module record on every call.
|
||||
*
|
||||
* Prod: plain import, so each module is loaded (and kept) once.
|
||||
*/
|
||||
export default function importFresh<T = any>(file_path: string): Promise<T>;
|
||||
/**
|
||||
* Drops a module from Bun's registry so its memory can be reclaimed and the
|
||||
* next import re-evaluates it. Only the module itself is evicted, not the
|
||||
* modules it imports.
|
||||
*/
|
||||
export declare function evictModule(file_path: string): void;
|
||||
/**
|
||||
* Evicts every registry entry under `dir` whose file no longer exists. Bundle
|
||||
* outputs (entries and shared chunks) are content-hashed and esbuild deletes
|
||||
* the superseded ones on rebuild, so a missing file means no current module
|
||||
* imports it anymore.
|
||||
*/
|
||||
export declare function evictDeletedModules(dir: string): void;
|
||||
|
||||
Reference in New Issue
Block a user