@eggjs/typings 4.1.2-beta.11 → 4.1.2-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/global.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { BundleModuleLoader } from "./index.js";
1
+ import { BundleModuleLoader, ModuleImporter } from "./index.js";
2
2
 
3
3
  //#region src/global.d.ts
4
4
  declare global {
5
5
  var __EGG_BUNDLE_MODULE_LOADER__: BundleModuleLoader | undefined;
6
+ var __EGG_MODULE_IMPORTER__: ModuleImporter | undefined;
6
7
  }
package/dist/index.d.ts CHANGED
@@ -5,5 +5,21 @@
5
5
  * standard import path.
6
6
  */
7
7
  type BundleModuleLoader = (filepath: string) => unknown;
8
+ /**
9
+ * Async module importer override for the tegg loader's file loading.
10
+ *
11
+ * When set, the loader delegates module loading to this importer instead of the
12
+ * built-in `await import(filePath)`. Its main use is testing with a bundler-based
13
+ * test runner (e.g. Vitest): when an app's egg modules are loaded by the loader
14
+ * via the native `import()` while the test file imports the same source through
15
+ * the runner's module graph, the two resolve to *different* module instances —
16
+ * so a class decorated as an egg proto by the loader is not the same class the
17
+ * test references, and `ctx.getEggObject(ClassRef)` fails with "can not get proto".
18
+ *
19
+ * A test runner can inject an importer that routes loading through its own module
20
+ * graph (e.g. `filePath => import(filePath)` evaluated inside the runner context),
21
+ * keeping a single module instance. Return value mirrors `await import()`.
22
+ */
23
+ type ModuleImporter = (filePath: string) => Promise<unknown>;
8
24
  //#endregion
9
- export { BundleModuleLoader };
25
+ export { BundleModuleLoader, ModuleImporter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eggjs/typings",
3
- "version": "4.1.2-beta.11",
3
+ "version": "4.1.2-beta.13",
4
4
  "description": "Shared typings for egg projects",
5
5
  "keywords": [
6
6
  "egg",
@@ -36,7 +36,7 @@
36
36
  "dependencies": {},
37
37
  "devDependencies": {
38
38
  "typescript": "^5.9.3",
39
- "@eggjs/tsconfig": "3.1.2-beta.11"
39
+ "@eggjs/tsconfig": "3.1.2-beta.13"
40
40
  },
41
41
  "engines": {
42
42
  "node": ">=22.18.0"