@eggjs/typings
Advanced tools
+2
-1
@@ -1,2 +0,2 @@ | ||
| import { BundleModuleLoader } from "./index.js"; | ||
| import { BundleModuleLoader, ModuleImporter } from "./index.js"; | ||
@@ -6,2 +6,3 @@ //#region src/global.d.ts | ||
| var __EGG_BUNDLE_MODULE_LOADER__: BundleModuleLoader | undefined; | ||
| var __EGG_MODULE_IMPORTER__: ModuleImporter | undefined; | ||
| } |
+17
-1
@@ -8,3 +8,19 @@ //#region src/index.d.ts | ||
| type BundleModuleLoader = (filepath: string) => unknown; | ||
| /** | ||
| * Async module importer override for the tegg loader's file loading. | ||
| * | ||
| * When set, the loader delegates module loading to this importer instead of the | ||
| * built-in `await import(filePath)`. Its main use is testing with a bundler-based | ||
| * test runner (e.g. Vitest): when an app's egg modules are loaded by the loader | ||
| * via the native `import()` while the test file imports the same source through | ||
| * the runner's module graph, the two resolve to *different* module instances — | ||
| * so a class decorated as an egg proto by the loader is not the same class the | ||
| * test references, and `ctx.getEggObject(ClassRef)` fails with "can not get proto". | ||
| * | ||
| * A test runner can inject an importer that routes loading through its own module | ||
| * graph (e.g. `filePath => import(filePath)` evaluated inside the runner context), | ||
| * keeping a single module instance. Return value mirrors `await import()`. | ||
| */ | ||
| type ModuleImporter = (filePath: string) => Promise<unknown>; | ||
| //#endregion | ||
| export { BundleModuleLoader }; | ||
| export { BundleModuleLoader, ModuleImporter }; |
+2
-2
| { | ||
| "name": "@eggjs/typings", | ||
| "version": "4.1.2-beta.11", | ||
| "version": "4.1.2-beta.12", | ||
| "description": "Shared typings for egg projects", | ||
@@ -39,3 +39,3 @@ "keywords": [ | ||
| "typescript": "^5.9.3", | ||
| "@eggjs/tsconfig": "3.1.2-beta.11" | ||
| "@eggjs/tsconfig": "3.1.2-beta.12" | ||
| }, | ||
@@ -42,0 +42,0 @@ "engines": { |
3667
39.54%29
141.67%