@eggjs/core 7.0.2-beta.25 → 7.0.2-beta.26

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/egg.d.ts CHANGED
@@ -4,12 +4,12 @@ import { Timing } from "./utils/timing.js";
4
4
  import { Lifecycle } from "./lifecycle.js";
5
5
  import { EggAppConfig } from "./types.js";
6
6
  import { EggLoader } from "./loader/egg_loader.js";
7
- import { LoaderFS } from "./loader/loader_fs.js";
8
7
  import { SingletonCreateMethod } from "./singleton.js";
9
8
  import { Application as KoaApplication, Context as KoaContext, MiddlewareFunc as KoaMiddlewareFunc, Next, Request as KoaRequest, Response as KoaResponse } from "@eggjs/koa";
10
9
  import { EggRouter as Router, RegisterOptions, ResourcesController } from "@eggjs/router";
11
10
  import { EggConsoleLogger, Logger } from "egg-logger";
12
11
  import { ReadyFunctionArg } from "get-ready";
12
+ import { LoaderFS } from "@eggjs/loader-fs";
13
13
 
14
14
  //#region src/egg.d.ts
15
15
  declare const EGG_LOADER: symbol;
package/dist/index.d.ts CHANGED
@@ -7,10 +7,9 @@ import { ManifestGenerateOptions, ManifestInvalidation, ManifestStore, StartupMa
7
7
  import { CaseStyle, CaseStyleFunction, EXPORTS, FULLPATH, FileLoader, FileLoaderFilter, FileLoaderInitializer, FileLoaderOptions, FileLoaderParseItem } from "./loader/file_loader.js";
8
8
  import { ClassLoader, ClassLoaderOptions, ContextLoader, ContextLoaderOptions } from "./loader/context_loader.js";
9
9
  import { EggDirInfo, EggDirInfoType, EggLoader, EggLoaderOptions } from "./loader/egg_loader.js";
10
- import { ManifestLoaderFS } from "./loader/loader_fs.js";
11
10
  import { Singleton, SingletonCreateMethod, SingletonOptions } from "./singleton.js";
12
11
  import { Context, EGG_LOADER, EggCore, EggCoreInitOptions, EggCoreOptions, KoaApplication, KoaContext, KoaMiddlewareFunc, KoaRequest, KoaResponse, MiddlewareFunc, Next, Request, Response, Router } from "./egg.js";
13
12
  import { SequencifyResult, SequencifyTask, sequencify } from "./utils/sequencify.js";
14
13
  import "@eggjs/typings/global";
15
14
  export * from "@eggjs/loader-fs";
16
- export { BaseContextClass, BootImplClass, CaseStyle, CaseStyleFunction, ClassLoader, ClassLoaderOptions, Context, ContextLoader, ContextLoaderOptions, CustomLoaderConfigItem, EGG_LOADER, EXPORTS, EggAppConfig, EggAppInfo, EggCore, EggCoreInitOptions, EggCoreOptions, EggDirInfo, EggDirInfoType, EggLoader, EggLoaderOptions, EggPluginInfo, FULLPATH, FileLoader, FileLoaderFilter, FileLoaderInitializer, FileLoaderOptions, FileLoaderParseItem, FunWithFullPath, ILifecycleBoot, KoaApplication, KoaContext, KoaMiddlewareFunc, KoaRequest, KoaResponse, Lifecycle, LifecycleOptions, ManifestGenerateOptions, ManifestInvalidation, ManifestLoaderFS, ManifestStore, MiddlewareFunc, Next, Request, Response, Router, SequencifyResult, SequencifyTask, Singleton, SingletonCreateMethod, SingletonOptions, StartupManifest, Timing, TimingItem, sequencify, utils };
15
+ export { BaseContextClass, BootImplClass, CaseStyle, CaseStyleFunction, ClassLoader, ClassLoaderOptions, Context, ContextLoader, ContextLoaderOptions, CustomLoaderConfigItem, EGG_LOADER, EXPORTS, EggAppConfig, EggAppInfo, EggCore, EggCoreInitOptions, EggCoreOptions, EggDirInfo, EggDirInfoType, EggLoader, EggLoaderOptions, EggPluginInfo, FULLPATH, FileLoader, FileLoaderFilter, FileLoaderInitializer, FileLoaderOptions, FileLoaderParseItem, FunWithFullPath, ILifecycleBoot, KoaApplication, KoaContext, KoaMiddlewareFunc, KoaRequest, KoaResponse, Lifecycle, LifecycleOptions, ManifestGenerateOptions, ManifestInvalidation, ManifestStore, MiddlewareFunc, Next, Request, Response, Router, SequencifyResult, SequencifyTask, Singleton, SingletonCreateMethod, SingletonOptions, StartupManifest, Timing, TimingItem, sequencify, utils };
package/dist/index.js CHANGED
@@ -9,9 +9,8 @@ import { ManifestStore } from "./loader/manifest.js";
9
9
  import { EggLoader } from "./loader/egg_loader.js";
10
10
  import { Singleton } from "./singleton.js";
11
11
  import { Context, EGG_LOADER, EggCore, KoaApplication, KoaContext, KoaRequest, KoaResponse, Request, Response, Router } from "./egg.js";
12
- import { ManifestLoaderFS } from "./loader/loader_fs.js";
13
12
  import "@eggjs/typings/global";
14
13
 
15
14
  export * from "@eggjs/loader-fs"
16
15
 
17
- export { BaseContextClass, CaseStyle, ClassLoader, Context, ContextLoader, EGG_LOADER, EXPORTS, EggCore, EggLoader, FULLPATH, FileLoader, KoaApplication, KoaContext, KoaRequest, KoaResponse, Lifecycle, ManifestLoaderFS, ManifestStore, Request, Response, Router, Singleton, Timing, sequencify, utils_default as utils };
16
+ export { BaseContextClass, CaseStyle, ClassLoader, Context, ContextLoader, EGG_LOADER, EXPORTS, EggCore, EggLoader, FULLPATH, FileLoader, KoaApplication, KoaContext, KoaRequest, KoaResponse, Lifecycle, ManifestStore, Request, Response, Router, Singleton, Timing, sequencify, utils_default as utils };
@@ -46,7 +46,7 @@ declare class EggLoader {
46
46
  dirs?: EggDirInfo[];
47
47
  /** Startup manifest — loaded from cache or collecting for generation */
48
48
  readonly manifest: ManifestStore;
49
- readonly loaderFS: LoaderFS;
49
+ loaderFS: LoaderFS;
50
50
  /**
51
51
  * @class
52
52
  * @param {Object} options - options
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eggjs/core",
3
- "version": "7.0.2-beta.25",
3
+ "version": "7.0.2-beta.26",
4
4
  "description": "A core plugin framework based on @eggjs/koa",
5
5
  "keywords": [
6
6
  "egg",
@@ -39,18 +39,17 @@
39
39
  "typecheck": "tsgo --noEmit"
40
40
  },
41
41
  "dependencies": {
42
- "@eggjs/extend2": "5.0.2-beta.25",
43
- "@eggjs/koa": "3.1.2-beta.25",
44
- "@eggjs/loader-fs": "1.0.0-beta.25",
45
- "@eggjs/path-matching": "3.0.2-beta.25",
46
- "@eggjs/router": "4.0.2-beta.25",
47
- "@eggjs/typings": "4.1.2-beta.25",
48
- "@eggjs/utils": "5.0.2-beta.25",
42
+ "@eggjs/extend2": "5.0.2-beta.26",
43
+ "@eggjs/koa": "3.1.2-beta.26",
44
+ "@eggjs/loader-fs": "1.0.0-beta.26",
45
+ "@eggjs/path-matching": "3.0.2-beta.26",
46
+ "@eggjs/router": "4.0.2-beta.26",
47
+ "@eggjs/typings": "4.1.2-beta.26",
48
+ "@eggjs/utils": "5.0.2-beta.26",
49
49
  "egg-logger": "^3.5.0",
50
50
  "get-ready": "^3.1.0",
51
51
  "globby": "^11.0.2",
52
52
  "is-type-of": "^2.2.0",
53
- "multimatch": "^7.0.0",
54
53
  "node-homedir": "^2.0.0",
55
54
  "performance-ms": "^1.1.0",
56
55
  "ready-callback": "^4.0.0",
@@ -58,9 +57,9 @@
58
57
  "utility": "^2.5.0"
59
58
  },
60
59
  "devDependencies": {
61
- "@eggjs/mock": "7.0.2-beta.25",
62
- "@eggjs/supertest": "9.0.2-beta.25",
63
- "@eggjs/tsconfig": "3.1.2-beta.25",
60
+ "@eggjs/mock": "7.0.2-beta.26",
61
+ "@eggjs/supertest": "9.0.2-beta.26",
62
+ "@eggjs/tsconfig": "3.1.2-beta.26",
64
63
  "@types/js-yaml": "^4.0.9",
65
64
  "await-event": "2",
66
65
  "coffee": "5",
@@ -1,17 +0,0 @@
1
- import { ManifestStore } from "./manifest.js";
2
- import { Stats } from "node:fs";
3
- import { LoaderFS as LoaderFS$1, LoaderFSGlobOptions } from "@eggjs/loader-fs";
4
-
5
- //#region src/loader/loader_fs.d.ts
6
- declare class ManifestLoaderFS implements LoaderFS$1 {
7
- #private;
8
- constructor(manifest: ManifestStore, fallback?: LoaderFS$1);
9
- exists(filepath: string): boolean;
10
- stat(filepath: string): Stats;
11
- realpath(filepath: string): string;
12
- readJSON<T = unknown>(filepath: string): T;
13
- glob(patterns: string | string[], options?: LoaderFSGlobOptions): string[];
14
- loadFile(filepath: string): Promise<unknown>;
15
- }
16
- //#endregion
17
- export { type LoaderFS$1 as LoaderFS, ManifestLoaderFS };
@@ -1,271 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { RealLoaderFS as RealLoaderFS$1 } from "@eggjs/loader-fs";
4
- import multimatch from "multimatch";
5
-
6
- //#region src/loader/loader_fs.ts
7
- var ManifestLoaderFS = class {
8
- #manifest;
9
- #fallback;
10
- #manifestFiles;
11
- #manifestDirectories;
12
- #resolveCacheTargets;
13
- constructor(manifest, fallback = new RealLoaderFS$1()) {
14
- this.#manifest = manifest;
15
- this.#fallback = fallback;
16
- this.#resolveCacheTargets = new Set(Object.values(manifest.data.resolveCache).filter((target) => typeof target === "string"));
17
- const manifestFiles = /* @__PURE__ */ new Set();
18
- const manifestDirectories = /* @__PURE__ */ new Set();
19
- for (const [dir, files] of Object.entries(manifest.data.fileDiscovery)) {
20
- addManifestDirectory(manifestDirectories, dir);
21
- for (const file of files) {
22
- const fullRel = path.posix.join(dir, file);
23
- manifestFiles.add(fullRel);
24
- addManifestDirectory(manifestDirectories, path.posix.dirname(fullRel));
25
- }
26
- }
27
- for (const target of this.#resolveCacheTargets) {
28
- manifestFiles.add(target);
29
- addManifestDirectory(manifestDirectories, path.posix.dirname(target));
30
- }
31
- this.#manifestFiles = manifestFiles;
32
- this.#manifestDirectories = manifestDirectories;
33
- }
34
- exists(filepath) {
35
- const entry = this.#getManifestEntry(filepath);
36
- if (entry) return entry.type !== "missing";
37
- return this.#fallback.exists(filepath);
38
- }
39
- stat(filepath) {
40
- const entry = this.#getManifestEntry(filepath);
41
- if (entry?.type === "file" || entry?.type === "directory") return createVirtualStats(entry.type);
42
- if (entry?.type === "missing") throw createNotFoundError("stat", filepath);
43
- return this.#fallback.stat(filepath);
44
- }
45
- realpath(filepath) {
46
- const entry = this.#getManifestEntry(filepath);
47
- if (entry?.type === "file" || entry?.type === "directory") return this.#toAbsolute(entry.rel);
48
- if (entry?.type === "missing") throw createNotFoundError("realpath", filepath);
49
- return this.#fallback.realpath(filepath);
50
- }
51
- readJSON(filepath) {
52
- const entry = this.#getManifestEntry(filepath);
53
- if (entry?.type === "file") {
54
- const bundled = this.#loadBundledModule(entry.rel);
55
- if (bundled !== void 0) return unwrapDefaultExport(bundled);
56
- }
57
- if (entry?.type === "missing") throw createNotFoundError("open", filepath);
58
- return this.#fallback.readJSON(filepath);
59
- }
60
- glob(patterns, options) {
61
- const cwd = options?.cwd === void 0 ? process.cwd() : String(options.cwd);
62
- const absoluteCwd = path.resolve(cwd);
63
- const cwdRel = this.#toRelative(absoluteCwd);
64
- const manifestFiles = this.#listManifestFilesUnder(cwdRel);
65
- if (manifestFiles === void 0) return this.#fallback.glob(patterns, options);
66
- const matched = filterManifestGlob(manifestFiles, patterns, options);
67
- if (options?.absolute) return matched.map((file) => path.join(absoluteCwd, file));
68
- return matched;
69
- }
70
- async loadFile(filepath) {
71
- const entry = this.#getManifestEntry(filepath);
72
- if (entry?.type === "file") {
73
- const bundled = this.#loadBundledModule(entry.rel);
74
- if (bundled !== void 0) return unwrapDefaultExport(bundled);
75
- }
76
- if (entry?.type === "missing") throw createNotFoundError("open", filepath);
77
- return this.#fallback.loadFile(filepath);
78
- }
79
- #getManifestEntry(filepath) {
80
- const rel = this.#toRelative(filepath);
81
- const resolved = this.#resolveManifestFile(rel);
82
- if (resolved?.type === "file") return {
83
- type: "file",
84
- rel: resolved.rel
85
- };
86
- if (resolved?.type === "missing") return {
87
- type: "missing",
88
- rel
89
- };
90
- if (this.#isManifestDirectory(rel)) return {
91
- type: "directory",
92
- rel
93
- };
94
- }
95
- #resolveManifestFile(rel) {
96
- const cache = this.#manifest.data.resolveCache;
97
- if (Object.hasOwn(cache, rel)) {
98
- const cached = cache[rel];
99
- return cached === null ? { type: "missing" } : {
100
- type: "file",
101
- rel: cached
102
- };
103
- }
104
- if (this.#isManifestFile(rel)) return {
105
- type: "file",
106
- rel
107
- };
108
- const discovered = this.#resolveFromFileDiscovery(rel);
109
- if (discovered) return {
110
- type: "file",
111
- rel: discovered
112
- };
113
- }
114
- #resolveFromFileDiscovery(rel) {
115
- const matchedDir = this.#nearestManifestDiscoveryDir(rel);
116
- if (matchedDir === void 0 || rel === matchedDir) return;
117
- const request = matchedDir === "" ? rel : rel.slice(matchedDir.length + 1);
118
- for (const file of this.#manifest.data.fileDiscovery[matchedDir]) {
119
- if (file === request) return path.posix.join(matchedDir, file);
120
- const ext = path.posix.extname(file);
121
- if (!ext || ext === ".map") continue;
122
- const extensionlessFile = file.slice(0, -ext.length);
123
- if (extensionlessFile === request || extensionlessFile === `${request}/index`) return path.posix.join(matchedDir, file);
124
- }
125
- }
126
- #nearestManifestDiscoveryDir(rel) {
127
- let current = path.posix.dirname(rel);
128
- while (true) {
129
- const dir = current === "." ? "" : current;
130
- if (Object.hasOwn(this.#manifest.data.fileDiscovery, dir)) return dir;
131
- if (dir === "") return;
132
- current = path.posix.dirname(dir);
133
- }
134
- }
135
- #isManifestFile(rel) {
136
- return this.#manifestFiles.has(rel);
137
- }
138
- #isManifestDirectory(rel) {
139
- return this.#manifestDirectories.has(rel);
140
- }
141
- #listManifestFilesUnder(cwdRel) {
142
- if (!this.#isManifestDirectory(cwdRel)) return;
143
- const files = /* @__PURE__ */ new Set();
144
- for (const [dir, entries] of Object.entries(this.#manifest.data.fileDiscovery)) {
145
- const prefix = dir === cwdRel ? "" : relativePrefix(cwdRel, dir);
146
- if (prefix === void 0) continue;
147
- for (const entry of entries) files.add(path.posix.join(prefix, entry));
148
- }
149
- for (const target of Object.values(this.#manifest.data.resolveCache)) {
150
- if (!target) continue;
151
- const prefix = relativePrefix(cwdRel, path.posix.dirname(target));
152
- if (prefix !== void 0) files.add(path.posix.join(prefix, path.posix.basename(target)));
153
- }
154
- return [...files].sort();
155
- }
156
- #loadBundledModule(rel) {
157
- const loader = globalThis.__EGG_BUNDLE_MODULE_LOADER__;
158
- if (!loader) return void 0;
159
- for (const key of this.#bundleKeys(rel)) {
160
- const loaded = loader(key);
161
- if (loaded !== void 0) return loaded;
162
- }
163
- }
164
- #bundleKeys(rel) {
165
- const abs = this.#toAbsolute(rel);
166
- return [...new Set([rel, normalizePath(abs)])];
167
- }
168
- #toRelative(filepath) {
169
- return normalizePath(path.relative(this.#manifest.baseDir, path.resolve(filepath)));
170
- }
171
- #toAbsolute(rel) {
172
- return path.isAbsolute(rel) ? rel : path.join(this.#manifest.baseDir, rel);
173
- }
174
- };
175
- function normalizePath(filepath) {
176
- return filepath.replaceAll(path.sep, "/");
177
- }
178
- function addManifestDirectory(directories, dir) {
179
- let current = dir === "." ? "" : dir;
180
- while (true) {
181
- directories.add(current);
182
- if (current === "") return;
183
- const parent = path.posix.dirname(current);
184
- current = parent === "." ? "" : parent;
185
- }
186
- }
187
- function relativePrefix(cwdRel, dirRel) {
188
- if (cwdRel === "") return dirRel;
189
- if (dirRel === cwdRel) return "";
190
- if (dirRel.startsWith(cwdRel + "/")) return dirRel.slice(cwdRel.length + 1);
191
- }
192
- function filterManifestGlob(files, patterns, options) {
193
- const patternList = Array.isArray(patterns) ? patterns : [patterns];
194
- if (!patternList.some((pattern) => !pattern.startsWith("!"))) return [];
195
- const ignoreList = Array.isArray(options?.ignore) ? options.ignore.map(String) : options?.ignore ? [String(options.ignore)] : [];
196
- return multimatch(files, patternList.map(normalizeAlternationGroups).concat(ignoreList.map((pattern) => `!${normalizeAlternationGroups(pattern)}`)), toMultimatchOptions(options));
197
- }
198
- function toMultimatchOptions(options) {
199
- return {
200
- ...options?.dot !== void 0 ? { dot: options.dot } : {},
201
- ...options?.caseSensitiveMatch !== void 0 ? { nocase: !options.caseSensitiveMatch } : {},
202
- ...options?.braceExpansion !== void 0 ? { nobrace: !options.braceExpansion } : {},
203
- ...options?.extglob !== void 0 ? { noext: !options.extglob } : {},
204
- ...options?.globstar !== void 0 ? { noglobstar: !options.globstar } : {},
205
- ...options?.baseNameMatch !== void 0 ? { matchBase: options.baseNameMatch } : {}
206
- };
207
- }
208
- function normalizeAlternationGroups(pattern) {
209
- let normalized = "";
210
- for (let index = 0; index < pattern.length; index++) {
211
- const char = pattern[index];
212
- if (char !== "(" || isExtglobPrefix(pattern[index - 1])) {
213
- normalized += char;
214
- continue;
215
- }
216
- const end = pattern.indexOf(")", index + 1);
217
- if (end === -1) {
218
- normalized += char;
219
- continue;
220
- }
221
- const group = pattern.slice(index + 1, end);
222
- if (group.includes("|")) {
223
- normalized += `{${group.replaceAll("|", ",")}}`;
224
- index = end;
225
- } else normalized += char;
226
- }
227
- return normalized;
228
- }
229
- function isExtglobPrefix(char) {
230
- return char === "@" || char === "!" || char === "?" || char === "+" || char === "*";
231
- }
232
- function unwrapDefaultExport(value) {
233
- let unwrapped = value;
234
- if (isRecord(unwrapped) && isRecord(unwrapped.default) && unwrapped.default.__esModule === true) unwrapped = unwrapped.default;
235
- if (isRecord(unwrapped) && "default" in unwrapped) return unwrapped.default;
236
- return unwrapped;
237
- }
238
- function isRecord(value) {
239
- return value !== null && typeof value === "object";
240
- }
241
- function createVirtualStats(type) {
242
- const stat = Object.create(fs.Stats.prototype);
243
- const isFile = type === "file";
244
- const timestamp = /* @__PURE__ */ new Date(0);
245
- Object.defineProperties(stat, {
246
- size: { value: 0 },
247
- atimeMs: { value: 0 },
248
- mtimeMs: { value: 0 },
249
- ctimeMs: { value: 0 },
250
- birthtimeMs: { value: 0 },
251
- atime: { value: timestamp },
252
- mtime: { value: timestamp },
253
- ctime: { value: timestamp },
254
- birthtime: { value: timestamp },
255
- isFile: { value: () => isFile },
256
- isDirectory: { value: () => !isFile },
257
- isSymbolicLink: { value: () => false }
258
- });
259
- return stat;
260
- }
261
- function createNotFoundError(syscall, filepath) {
262
- const err = /* @__PURE__ */ new Error(`ENOENT: no such file or directory, ${syscall} '${filepath}'`);
263
- err.code = "ENOENT";
264
- err.errno = -2;
265
- err.syscall = syscall;
266
- err.path = filepath;
267
- return err;
268
- }
269
-
270
- //#endregion
271
- export { ManifestLoaderFS };