@eggjs/typings 4.1.2-beta.16 → 4.1.2-beta.17

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
@@ -4,4 +4,11 @@ import { BundleModuleLoader, ModuleImporter } from "./index.js";
4
4
  declare global {
5
5
  var __EGG_BUNDLE_MODULE_LOADER__: BundleModuleLoader | undefined;
6
6
  var __EGG_MODULE_IMPORTER__: ModuleImporter | undefined;
7
+ /**
8
+ * Synchronous require bound to the bundle output directory, installed by the
9
+ * snapshot restore main function. The snapshot prelude / lazy mechanism uses it
10
+ * to pull in modules through `require()` (Node 22+ can `require()` ESM) because a
11
+ * deserialized snapshot process has no dynamic `import()` callback.
12
+ */
13
+ var __RUNTIME_REQUIRE: ((id: string) => unknown) | undefined;
7
14
  }
package/dist/index.d.ts CHANGED
@@ -1,24 +1,56 @@
1
1
  //#region src/index.d.ts
2
2
  /**
3
- * Module loader for bundled Egg apps. Called with the `importModule()` filepath
4
- * after POSIX path normalization. Return `undefined` to fall through to the
5
- * standard import path.
3
+ * Module loader for bundled Egg apps, registered on `globalThis` as
4
+ * `__EGG_BUNDLE_MODULE_LOADER__` (use `setBundleModuleLoader()` from
5
+ * `@eggjs/utils`). This is the highest-priority hook: it runs before on-disk
6
+ * resolution in both `importModule()` / `importResolve()` (`@eggjs/utils`) and
7
+ * the loaders in `@eggjs/core` and the tegg loader.
8
+ *
9
+ * It is called with the `importModule()` filepath (or a virtual specifier)
10
+ * after POSIX path normalization, and is meant to return a module already
11
+ * inlined into the bundle — typically a lookup into a static bundle map emitted
12
+ * by `egg-bundler`. Return `undefined` to fall through to the next hook (the
13
+ * snapshot loader registered via `setSnapshotModuleLoader()`, then
14
+ * `__EGG_MODULE_IMPORTER__`) or the standard `import()` / `require()` path.
15
+ *
16
+ * The non-undefined return value follows the same default-export unwrapping
17
+ * rules as a native import (double-default `__esModule` compatibility plus the
18
+ * caller's `importDefaultOnly` option).
6
19
  */
7
20
  type BundleModuleLoader = (filepath: string) => unknown;
8
21
  /**
9
- * Async module importer override for the tegg loader's file loading.
22
+ * Async module importer override, registered on `globalThis` as
23
+ * `__EGG_MODULE_IMPORTER__`. When set (and neither the bundle loader nor a
24
+ * snapshot loader registered via `setSnapshotModuleLoader()` already resolved
25
+ * the path), `importModule()` / the loaders delegate module loading to this
26
+ * importer instead of the built-in `await import(filePath)`. The return value
27
+ * is awaited and mirrors `await import()` (default unwrapping and
28
+ * `importDefaultOnly` apply); because it is awaited, a synchronous return value
29
+ * such as the result of `require()` is also valid.
30
+ *
31
+ * The path passed in depends on the caller: `@eggjs/utils` `importModule()`
32
+ * passes the resolved module path from `importResolve()` (OS-native separators,
33
+ * not normalized), while the tegg loader passes the original loader filepath
34
+ * with separators normalized to POSIX. Importers that care about separators
35
+ * should normalize defensively.
36
+ *
37
+ * Two main uses:
10
38
  *
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".
39
+ * 1. Testing with a bundler-based test runner (e.g. Vitest): when an app's egg
40
+ * modules are loaded by the loader via the native `import()` while the test
41
+ * file imports the same source through the runner's module graph, the two
42
+ * resolve to *different* module instances so a class decorated as an egg
43
+ * proto by the loader is not the same class the test references, and
44
+ * `ctx.getEggObject(ClassRef)` fails with "can not get proto". A test runner
45
+ * injects an importer that routes loading through its own module graph
46
+ * (e.g. `filePath => import(filePath)` evaluated inside the runner context),
47
+ * keeping a single module instance.
18
48
  *
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()`.
49
+ * 2. V8 startup-snapshot restore: the deserialized main function runs without a
50
+ * host dynamic-import callback, so native `import()` throws. The snapshot
51
+ * entry generated by `egg-bundler` installs a synchronous `require()`-based
52
+ * importer (`createRequire()` over the bundle output dir); `require()` can
53
+ * load ESM on Node >= 22, so modules resolve without dynamic import.
22
54
  */
23
55
  type ModuleImporter = (filePath: string) => Promise<unknown>;
24
56
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eggjs/typings",
3
- "version": "4.1.2-beta.16",
3
+ "version": "4.1.2-beta.17",
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.16"
39
+ "@eggjs/tsconfig": "3.1.2-beta.17"
40
40
  },
41
41
  "engines": {
42
42
  "node": ">=22.18.0"