@eggjs/tegg-config 4.0.0-beta.7 → 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.
- package/dist/ModuleScanner-bAAIC9jB.js +38 -0
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +2 -1
- package/dist/app-CK_mbdMb.js +41 -0
- package/dist/app-DV97Jgvz.d.ts +19 -0
- package/dist/app.d.ts +1 -18
- package/dist/app.js +2 -39
- package/dist/config/config.default.d.ts +1 -16
- package/dist/config/config.default.js +1 -11
- package/dist/config.default-DDmvKpMT.d.ts +17 -0
- package/dist/config.default-DePuDzML.js +13 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -1
- package/dist/lib/ModuleScanner.js +1 -36
- package/dist/types-DZQk5nVn.d.ts +1 -0
- package/dist/types-DtTnp0o0.js +1 -0
- package/dist/types.d.ts +3 -1
- package/dist/types.js +4 -2
- package/package.json +2 -2
|
@@ -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
|
@@ -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 {
|
|
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
|
|
2
|
-
import {
|
|
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 {
|
|
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 "
|
|
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
package/dist/index.js
CHANGED
|
@@ -1,38 +1,3 @@
|
|
|
1
|
-
import {
|
|
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
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"eggPlugin": {
|
|
4
4
|
"name": "teggConfig"
|
|
5
5
|
},
|
|
6
|
-
"version": "4.0.0-beta.
|
|
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.
|
|
43
|
+
"@eggjs/tegg-common-util": "4.0.0-beta.8"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"egg": "beta"
|