@eggjs/typings 4.1.2-beta.16 → 4.1.2-beta.19
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 +22 -0
- package/dist/index.d.ts +46 -14
- package/package.json +13 -8
- package/LICENSE +0 -21
package/dist/global.d.ts
CHANGED
|
@@ -4,4 +4,26 @@ 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. It also carries
|
|
12
|
+
* a `resolve` (the underlying `createRequire(...).resolve`) so the web globals
|
|
13
|
+
* re-installer can locate `undici` through the app dependency tree.
|
|
14
|
+
*/
|
|
15
|
+
var __RUNTIME_REQUIRE: (((id: string) => unknown) & {
|
|
16
|
+
resolve?: (id: string, options?: {
|
|
17
|
+
paths?: string[];
|
|
18
|
+
}) => string;
|
|
19
|
+
}) | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Re-install the web globals (`fetch`/`Headers`/.../`Blob`/`File`) that the snapshot
|
|
22
|
+
* prelude replaces with stubs at build time, as lazy accessors backed by `undici`
|
|
23
|
+
* (the fetch family) and `node:buffer` (`Blob`/`File`). Defined by the snapshot
|
|
24
|
+
* prelude and serialized into the blob; the snapshot restore main calls it once
|
|
25
|
+
* `__RUNTIME_REQUIRE` is installed, so an app that uses `globalThis.fetch` keeps
|
|
26
|
+
* working after a restore.
|
|
27
|
+
*/
|
|
28
|
+
var __installWebGlobalsLazy: (() => void) | undefined;
|
|
7
29
|
}
|
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
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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
|
|
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
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* the
|
|
16
|
-
*
|
|
17
|
-
*
|
|
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
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
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.
|
|
3
|
+
"version": "4.1.2-beta.19",
|
|
4
4
|
"description": "Shared typings for egg projects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"egg",
|
|
@@ -31,17 +31,22 @@
|
|
|
31
31
|
"./package.json": "./package.json"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
|
-
"access": "public"
|
|
34
|
+
"access": "public",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": "./dist/index.js",
|
|
37
|
+
"./global": "./dist/global.js",
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"typecheck": "tsgo --noEmit"
|
|
35
43
|
},
|
|
36
44
|
"dependencies": {},
|
|
37
45
|
"devDependencies": {
|
|
38
|
-
"
|
|
39
|
-
"
|
|
46
|
+
"@eggjs/tsconfig": "3.1.2-beta.19",
|
|
47
|
+
"typescript": "^5.9.3"
|
|
40
48
|
},
|
|
41
49
|
"engines": {
|
|
42
50
|
"node": ">=22.18.0"
|
|
43
|
-
},
|
|
44
|
-
"scripts": {
|
|
45
|
-
"typecheck": "tsgo --noEmit"
|
|
46
51
|
}
|
|
47
|
-
}
|
|
52
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2017-present Alibaba Group Holding Limited and other contributors.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|