@eggjs/tegg-config 4.0.0-beta.6 → 4.0.0-beta.8

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.
@@ -0,0 +1,38 @@
1
+ import { debuglog } from "node:util";
2
+ import { ModuleConfigUtil } from "@eggjs/tegg-common-util";
3
+ import path from "node:path";
4
+ import { readFileSync } from "node:fs";
5
+ import { importResolve } from "@eggjs/utils";
6
+
7
+ //#region src/lib/ModuleScanner.ts
8
+ const debug = debuglog("tegg/plugin/config/ModuleScanner");
9
+ var ModuleScanner = class {
10
+ baseDir;
11
+ readModuleOptions;
12
+ constructor(baseDir, readModuleOptions) {
13
+ this.baseDir = baseDir;
14
+ this.readModuleOptions = readModuleOptions;
15
+ }
16
+ /**
17
+ * - load module references from config or scan from baseDir
18
+ * - load framework module as optional module reference
19
+ */
20
+ loadModuleReferences() {
21
+ const moduleReferences = ModuleConfigUtil.readModuleReference(this.baseDir, this.readModuleOptions || {});
22
+ const framework = JSON.parse(readFileSync(path.join(this.baseDir, "package.json"), "utf-8")).egg?.framework;
23
+ if (!framework) return moduleReferences;
24
+ const frameworkPkg = importResolve(`${framework}/package.json`, { paths: [this.baseDir] });
25
+ const frameworkDir = path.dirname(frameworkPkg);
26
+ debug("loadModuleReferences from framework:%o, frameworkDir:%o", framework, frameworkDir);
27
+ const optionalModuleReferences = ModuleConfigUtil.readModuleReference(frameworkDir, this.readModuleOptions || {});
28
+ const result = [...moduleReferences];
29
+ for (const optionalModuleReference of optionalModuleReferences) if (!result.some((t) => t.path === optionalModuleReference.path)) result.push({
30
+ ...optionalModuleReference,
31
+ optional: true
32
+ });
33
+ return result;
34
+ }
35
+ };
36
+
37
+ //#endregion
38
+ export { ModuleScanner };
package/dist/agent.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import App from "./app.js";
1
+ import { App } from "./app-DV97Jgvz.js";
2
2
  export { App as default };
package/dist/agent.js CHANGED
@@ -1,4 +1,5 @@
1
- import App from "./app.js";
1
+ import "./ModuleScanner-bAAIC9jB.js";
2
+ import { App } from "./app-CK_mbdMb.js";
2
3
 
3
4
  //#region src/agent.ts
4
5
  var agent_default = App;
@@ -0,0 +1,41 @@
1
+ import { ModuleScanner } from "./ModuleScanner-bAAIC9jB.js";
2
+ import { debuglog } from "node:util";
3
+ import { ModuleConfigUtil } from "@eggjs/tegg-common-util";
4
+
5
+ //#region src/app.ts
6
+ const debug = debuglog("tegg/plugin/config/app");
7
+ var App = class {
8
+ app;
9
+ constructor(app) {
10
+ this.app = app;
11
+ const configNames = this.app.loader.getTypeFiles("module");
12
+ ModuleConfigUtil.setConfigNames(configNames);
13
+ }
14
+ configWillLoad() {
15
+ const { readModuleOptions } = this.app.config.tegg;
16
+ const moduleScanner = new ModuleScanner(this.app.baseDir, readModuleOptions);
17
+ this.app.moduleReferences = moduleScanner.loadModuleReferences();
18
+ debug("load moduleReferences: %o", this.app.moduleReferences);
19
+ this.app.moduleConfigs = {};
20
+ for (const reference of this.app.moduleReferences) {
21
+ const absoluteRef = {
22
+ path: ModuleConfigUtil.resolveModuleDir(reference.path, this.app.baseDir),
23
+ name: reference.name,
24
+ optional: reference.optional
25
+ };
26
+ const moduleName = ModuleConfigUtil.readModuleNameSync(absoluteRef.path);
27
+ this.app.moduleConfigs[moduleName] = {
28
+ name: moduleName,
29
+ reference: absoluteRef,
30
+ config: ModuleConfigUtil.loadModuleConfigSync(absoluteRef.path)
31
+ };
32
+ }
33
+ debug("load moduleConfigs: %o", this.app.moduleConfigs);
34
+ }
35
+ async beforeClose() {
36
+ ModuleConfigUtil.setConfigNames(void 0);
37
+ }
38
+ };
39
+
40
+ //#endregion
41
+ export { App };
@@ -0,0 +1,19 @@
1
+ import { ModuleConfigHolder, ModuleReference } from "@eggjs/tegg-common-util";
2
+ import { Application, ILifecycleBoot } from "egg";
3
+
4
+ //#region src/app.d.ts
5
+ declare class App implements ILifecycleBoot {
6
+ private readonly app;
7
+ constructor(app: Application);
8
+ configWillLoad(): void;
9
+ beforeClose(): Promise<void>;
10
+ }
11
+ declare module 'egg' {
12
+ interface ModuleConfig {}
13
+ interface EggApplicationCore {
14
+ moduleReferences: readonly ModuleReference[];
15
+ moduleConfigs: Record<string, ModuleConfigHolder>;
16
+ }
17
+ }
18
+ //#endregion
19
+ export { App };
package/dist/app.d.ts CHANGED
@@ -1,19 +1,2 @@
1
- import { ModuleConfigHolder, ModuleReference } from "@eggjs/tegg-common-util";
2
- import { Application, ILifecycleBoot } from "egg";
3
-
4
- //#region src/app.d.ts
5
- declare class App implements ILifecycleBoot {
6
- private readonly app;
7
- constructor(app: Application);
8
- configWillLoad(): void;
9
- beforeClose(): Promise<void>;
10
- }
11
- declare module 'egg' {
12
- interface ModuleConfig {}
13
- interface EggApplicationCore {
14
- moduleReferences: readonly ModuleReference[];
15
- moduleConfigs: Record<string, ModuleConfigHolder>;
16
- }
17
- }
18
- //#endregion
1
+ import { App } from "./app-DV97Jgvz.js";
19
2
  export { App as default };
package/dist/app.js CHANGED
@@ -1,41 +1,4 @@
1
- import { ModuleScanner } from "./lib/ModuleScanner.js";
2
- import { debuglog } from "node:util";
3
- import { ModuleConfigUtil } from "@eggjs/tegg-common-util";
1
+ import "./ModuleScanner-bAAIC9jB.js";
2
+ import { App } from "./app-CK_mbdMb.js";
4
3
 
5
- //#region src/app.ts
6
- const debug = debuglog("tegg/plugin/config/app");
7
- var App = class {
8
- app;
9
- constructor(app) {
10
- this.app = app;
11
- const configNames = this.app.loader.getTypeFiles("module");
12
- ModuleConfigUtil.setConfigNames(configNames);
13
- }
14
- configWillLoad() {
15
- const { readModuleOptions } = this.app.config.tegg;
16
- const moduleScanner = new ModuleScanner(this.app.baseDir, readModuleOptions);
17
- this.app.moduleReferences = moduleScanner.loadModuleReferences();
18
- debug("load moduleReferences: %o", this.app.moduleReferences);
19
- this.app.moduleConfigs = {};
20
- for (const reference of this.app.moduleReferences) {
21
- const absoluteRef = {
22
- path: ModuleConfigUtil.resolveModuleDir(reference.path, this.app.baseDir),
23
- name: reference.name,
24
- optional: reference.optional
25
- };
26
- const moduleName = ModuleConfigUtil.readModuleNameSync(absoluteRef.path);
27
- this.app.moduleConfigs[moduleName] = {
28
- name: moduleName,
29
- reference: absoluteRef,
30
- config: ModuleConfigUtil.loadModuleConfigSync(absoluteRef.path)
31
- };
32
- }
33
- debug("load moduleConfigs: %o", this.app.moduleConfigs);
34
- }
35
- async beforeClose() {
36
- ModuleConfigUtil.setConfigNames(void 0);
37
- }
38
- };
39
-
40
- //#endregion
41
4
  export { App as default };
@@ -1,17 +1,2 @@
1
- import { ReadModuleReferenceOptions } from "@eggjs/tegg-common-util";
2
- import * as egg0 from "egg";
3
-
4
- //#region src/config/config.default.d.ts
5
- declare const _default: egg0.EggConfigFactory;
6
- declare module 'egg' {
7
- interface EggAppConfig {
8
- /**
9
- * tegg config
10
- */
11
- tegg: {
12
- readModuleOptions: ReadModuleReferenceOptions;
13
- };
14
- }
15
- }
16
- //#endregion
1
+ import { _default } from "../config.default-DDmvKpMT.js";
17
2
  export { _default as default };
@@ -1,13 +1,3 @@
1
- import "@eggjs/tegg-common-util";
2
- import { defineConfigFactory } from "egg";
1
+ import { config_default_default } from "../config.default-DePuDzML.js";
3
2
 
4
- //#region src/config/config.default.ts
5
- var config_default_default = defineConfigFactory((appInfo) => {
6
- return { tegg: { readModuleOptions: {
7
- deep: 10,
8
- cwd: appInfo.baseDir
9
- } } };
10
- });
11
-
12
- //#endregion
13
3
  export { config_default_default as default };
@@ -0,0 +1,17 @@
1
+ import { ReadModuleReferenceOptions } from "@eggjs/tegg-common-util";
2
+ import * as egg0 from "egg";
3
+
4
+ //#region src/config/config.default.d.ts
5
+ declare const _default: egg0.EggConfigFactory;
6
+ declare module 'egg' {
7
+ interface EggAppConfig {
8
+ /**
9
+ * tegg config
10
+ */
11
+ tegg: {
12
+ readModuleOptions: ReadModuleReferenceOptions;
13
+ };
14
+ }
15
+ }
16
+ //#endregion
17
+ export { _default };
@@ -0,0 +1,13 @@
1
+ import "@eggjs/tegg-common-util";
2
+ import { defineConfigFactory } from "egg";
3
+
4
+ //#region src/config/config.default.ts
5
+ var config_default_default = defineConfigFactory((appInfo) => {
6
+ return { tegg: { readModuleOptions: {
7
+ deep: 10,
8
+ cwd: appInfo.baseDir
9
+ } } };
10
+ });
11
+
12
+ //#endregion
13
+ export { config_default_default };
package/dist/index.d.ts CHANGED
@@ -1 +1,3 @@
1
- export { };
1
+ import "./app-DV97Jgvz.js";
2
+ import "./config.default-DDmvKpMT.js";
3
+ import "./types-DZQk5nVn.js";
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
- import "./types.js";
1
+ import "./ModuleScanner-bAAIC9jB.js";
2
+ import "./app-CK_mbdMb.js";
3
+ import "./config.default-DePuDzML.js";
4
+ import "./types-DtTnp0o0.js";
2
5
 
3
6
  export { };
@@ -1,38 +1,3 @@
1
- import { debuglog } from "node:util";
2
- import { ModuleConfigUtil } from "@eggjs/tegg-common-util";
3
- import path from "node:path";
4
- import { readFileSync } from "node:fs";
5
- import { importResolve } from "@eggjs/utils";
1
+ import { ModuleScanner } from "../ModuleScanner-bAAIC9jB.js";
6
2
 
7
- //#region src/lib/ModuleScanner.ts
8
- const debug = debuglog("tegg/plugin/config/ModuleScanner");
9
- var ModuleScanner = class {
10
- baseDir;
11
- readModuleOptions;
12
- constructor(baseDir, readModuleOptions) {
13
- this.baseDir = baseDir;
14
- this.readModuleOptions = readModuleOptions;
15
- }
16
- /**
17
- * - load module references from config or scan from baseDir
18
- * - load framework module as optional module reference
19
- */
20
- loadModuleReferences() {
21
- const moduleReferences = ModuleConfigUtil.readModuleReference(this.baseDir, this.readModuleOptions || {});
22
- const framework = JSON.parse(readFileSync(path.join(this.baseDir, "package.json"), "utf-8")).egg?.framework;
23
- if (!framework) return moduleReferences;
24
- const frameworkPkg = importResolve(`${framework}/package.json`, { paths: [this.baseDir] });
25
- const frameworkDir = path.dirname(frameworkPkg);
26
- debug("loadModuleReferences from framework:%o, frameworkDir:%o", framework, frameworkDir);
27
- const optionalModuleReferences = ModuleConfigUtil.readModuleReference(frameworkDir, this.readModuleOptions || {});
28
- const result = [...moduleReferences];
29
- for (const optionalModuleReference of optionalModuleReferences) if (!result.some((t) => t.path === optionalModuleReference.path)) result.push({
30
- ...optionalModuleReference,
31
- optional: true
32
- });
33
- return result;
34
- }
35
- };
36
-
37
- //#endregion
38
3
  export { ModuleScanner };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
package/dist/types.d.ts CHANGED
@@ -1 +1,3 @@
1
- export { };
1
+ import "./app-DV97Jgvz.js";
2
+ import "./config.default-DDmvKpMT.js";
3
+ import "./types-DZQk5nVn.js";
package/dist/types.js CHANGED
@@ -1,4 +1,6 @@
1
- import "./app.js";
2
- import "./config/config.default.js";
1
+ import "./ModuleScanner-bAAIC9jB.js";
2
+ import "./app-CK_mbdMb.js";
3
+ import "./config.default-DePuDzML.js";
4
+ import "./types-DtTnp0o0.js";
3
5
 
4
6
  export { };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "eggPlugin": {
4
4
  "name": "teggConfig"
5
5
  },
6
- "version": "4.0.0-beta.6",
6
+ "version": "4.0.0-beta.8",
7
7
  "description": "module config plugin for egg",
8
8
  "keywords": [
9
9
  "egg",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@eggjs/utils": "beta",
43
- "@eggjs/tegg-common-util": "4.0.0-beta.6"
43
+ "@eggjs/tegg-common-util": "4.0.0-beta.8"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "egg": "beta"